Ejemplo n.º 1
0
        public com.netsuite.webservices.AssemblyItem[] GenerateNetSuitelst(List <Item> Lst_Items)
        {
            Price[]   pricelst   = new Price[1];
            Pricing[] Pricinglst = new Pricing[1];
            com.netsuite.webservices.AssemblyItem[] ItemArr = new com.netsuite.webservices.AssemblyItem[Lst_Items.Count];
            try
            {
                for (int i = 0; i < Lst_Items.Count; i++)
                {
                    Item    Obj        = Lst_Items[i];
                    Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Obj.Subsidiary_Id).FirstOrDefault();
                    com.netsuite.webservices.AssemblyItem NewItemObject = new com.netsuite.webservices.AssemblyItem();
                    Categories.CategoriesAccounts         objCatAccount = new Categories.CategoriesAccounts();

                    // if (Obj.Netsuite_Id <= 0)
                    //{
                    NewItemObject.itemId      = Obj.UPC_Code;
                    NewItemObject.displayName = Obj.Display_Name_En;
                    //}


                    NewItemObject.trackLandedCost          = true;
                    NewItemObject.trackLandedCostSpecified = true;

                    if (Obj.Category_Id > 0)
                    {
                        RecordRef classref = new RecordRef();
                        classref.internalId  = Obj.Category_Id.ToString();
                        classref.type        = RecordType.classification;
                        NewItemObject.@class = classref;

                        objCatAccount = new GenericeDAO <Categories.CategoriesAccounts>().GetWhere("Netsuite_Id=" + Obj.Category_Id).FirstOrDefault();
                    }

                    #region Custom fields

                    Obj.Storage_Unit = string.IsNullOrEmpty(Obj.Storage_Unit) ? "" : Obj.Storage_Unit;

                    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
                        new StringCustomFieldRef {
                            value    = !string.IsNullOrEmpty(Obj.Name_Ar)? Obj.Name_Ar.ToString():"",
                            scriptId = "custitem_da_item_name_ar"
                        }
                        ,
                        new StringCustomFieldRef {
                            value    = Obj.UPC_Code.ToString(),
                            scriptId = "custitem1"
                        }
                    };
                    NewItemObject.customFieldList = custFieldList;
                    #endregion
                    if (Obj.Netsuite_Id > 0)
                    {
                        NewItemObject.internalId = Obj.Netsuite_Id.ToString();
                    }

                    #region pricing

                    NewItemObject.pricingMatrix = Helper.GeneratePricingMatrix(objSetting, Obj.Price);
                    #endregion
                    #region AssemblyComponent

                    List <ItemCompnent> itemCompnentslst = new GenericeDAO <ItemCompnent>().GetWhere("ItemFoodics_Id ='" + Obj.Foodics_Id + "'");
                    if (itemCompnentslst.Count > 0)
                    {
                        ItemMember[]   ItemMemberlst = new ItemMember[itemCompnentslst.Count];
                        ItemMemberList memberlst     = new ItemMemberList();
                        for (int x = 0; x < itemCompnentslst.Count; x++)
                        {
                            ItemMember   obj        = new ItemMember();
                            ItemCompnent itmcompobj = itemCompnentslst[x];
                            RecordRef    Itemref    = new RecordRef();
                            Itemref.internalId = itmcompobj.ComponentId.ToString();
                            Itemref.type       = RecordType.inventoryItem;

                            obj.item = Itemref;

                            obj.quantity          = itmcompobj.Quantity == 0 ? 1 : itmcompobj.Quantity;
                            obj.quantitySpecified = true;
                            ItemMemberlst[x]      = obj;
                        }
                        memberlst.itemMember                = ItemMemberlst;
                        NewItemObject.memberList            = memberlst;
                        NewItemObject.memberList.replaceAll = true;
                    }



                    #endregion
                    #region Items Account
                    RecordRef IncomAccountref = new RecordRef();
                    IncomAccountref.type        = RecordType.account;
                    NewItemObject.incomeAccount = IncomAccountref;
                    if (objCatAccount.income_account > 0)
                    {
                        IncomAccountref.internalId = objCatAccount.income_account.ToString();
                    }
                    else if (objSetting.IncomeAccount_Netsuite_Id > 0)
                    {
                        IncomAccountref.internalId = objSetting.IncomeAccount_Netsuite_Id.ToString();
                    }

                    RecordRef cogsAccountref = new RecordRef();
                    cogsAccountref.type       = RecordType.account;
                    NewItemObject.cogsAccount = cogsAccountref;
                    if (objCatAccount.cogs_account > 0)
                    {
                        cogsAccountref.internalId = objCatAccount.cogs_account.ToString();
                    }
                    else if (objSetting.CogsAccount_Netsuite_Id > 0)
                    {
                        cogsAccountref.internalId = objSetting.CogsAccount_Netsuite_Id.ToString();
                    }

                    RecordRef assetAccountref = new RecordRef();
                    assetAccountref.type       = RecordType.account;
                    NewItemObject.assetAccount = assetAccountref;
                    if (objCatAccount.asset_account > 0)
                    {
                        assetAccountref.internalId = objCatAccount.asset_account.ToString();
                    }
                    else if (objSetting.AssetAccount_Netsuite_Id > 0)
                    {
                        assetAccountref.internalId = objSetting.AssetAccount_Netsuite_Id.ToString();
                    }

                    RecordRef intercoIncomeref = new RecordRef();
                    intercoIncomeref.type = RecordType.account;
                    NewItemObject.intercoIncomeAccount = intercoIncomeref;
                    if (objCatAccount.income_intercompany_account > 0)
                    {
                        intercoIncomeref.internalId = objCatAccount.income_intercompany_account.ToString();
                    }
                    else if (objSetting.IntercoIncomeAccount_Netsuite_Id > 0)
                    {
                        intercoIncomeref.internalId = objSetting.IntercoIncomeAccount_Netsuite_Id.ToString();
                    }

                    RecordRef intercoCogsAccount = new RecordRef();
                    intercoCogsAccount.type          = RecordType.account;
                    NewItemObject.intercoCogsAccount = intercoCogsAccount;
                    if (objCatAccount.inter_cogs_account > 0)
                    {
                        intercoCogsAccount.internalId = objCatAccount.inter_cogs_account.ToString();
                    }
                    else if (objSetting.IntercoCogsAccount_Netsuite_Id > 0)
                    {
                        intercoCogsAccount.internalId = objSetting.IntercoCogsAccount_Netsuite_Id.ToString();
                    }

                    RecordRef gainLossAccount = new RecordRef();
                    gainLossAccount.type          = RecordType.account;
                    NewItemObject.gainLossAccount = gainLossAccount;
                    if (objCatAccount.gainloss_account > 0)
                    {
                        gainLossAccount.internalId = objCatAccount.gainloss_account.ToString();
                    }
                    else if (objSetting.GainLossAccount_Netsuite_Id > 0)
                    {
                        gainLossAccount.internalId = objSetting.GainLossAccount_Netsuite_Id.ToString();
                    }


                    if (objCatAccount.cust_qty_variance_account > 0)
                    {
                        RecordRef refgAccount = new RecordRef();
                        refgAccount.type                  = RecordType.account;
                        refgAccount.internalId            = objCatAccount.cust_qty_variance_account.ToString();
                        NewItemObject.billQtyVarianceAcct = refgAccount;
                    }

                    if (objCatAccount.cust_ex_rate_account > 0)
                    {
                        RecordRef refgAccount = new RecordRef();
                        refgAccount.type       = RecordType.account;
                        refgAccount.internalId = objCatAccount.cust_ex_rate_account.ToString();
                        NewItemObject.billExchRateVarianceAcct = refgAccount;
                    }
                    if (objCatAccount.price_variance_account > 0)
                    {
                        RecordRef refgAccount = new RecordRef();
                        refgAccount.type       = RecordType.account;
                        refgAccount.internalId = objCatAccount.price_variance_account.ToString();
                        NewItemObject.billPriceVarianceAcct = refgAccount;
                    }

                    #endregion
                    RecordRef Tax_Schedule = new RecordRef();
                    Tax_Schedule.internalId   = objSetting.TaxSchedule_Netsuite_Id.ToString();
                    Tax_Schedule.type         = RecordType.salesTaxItem;
                    NewItemObject.taxSchedule = Tax_Schedule;
                    RecordRef[] subsidiarylst = new RecordRef[1];
                    RecordRef   subsidiary    = new RecordRef();
                    subsidiary.internalId        = Obj.Subsidiary_Id.ToString();
                    subsidiary.type              = RecordType.subsidiary;
                    subsidiarylst[0]             = subsidiary;
                    NewItemObject.subsidiaryList = subsidiarylst;

                    if (Obj.InActive)
                    {
                        NewItemObject.isInactive          = true;
                        NewItemObject.isInactiveSpecified = true;
                    }

                    ItemArr[i] = NewItemObject;
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(ItemArr);
        }
Ejemplo n.º 2
0
        private void Generate_Save_NetSuiteLst(List <FoodicsProduct> lstitems, string Subsidiary)
        {
            try
            {
                List <Item>         NetSuitelst      = new List <Item>();
                List <ItemCompnent> ItemCompnentList = new List <ItemCompnent>();
                foreach (var Foodicsitem in lstitems)
                {
                    Item Netsuiteitem = new Item();
                    Item itemobj      = new GenericeDAO <Item>().GetByFoodicsId(Foodicsitem.id);
                    //barcode
                    Netsuiteitem.Foodics_Id             = Foodicsitem.id;
                    Netsuiteitem.Item_Type              = (int)Item_Type.AssemblyItem;
                    Netsuiteitem.Item_Type_Name         = nameof(Item_Type.AssemblyItem);
                    Netsuiteitem.Foodics_Item_Type_Name = nameof(FoodicsItem_Type.Product);
                    Netsuiteitem.Name_Ar           = Foodicsitem.name_localized;
                    Netsuiteitem.Name_En           = Foodicsitem.name;
                    Netsuiteitem.Display_Name_Ar   = Foodicsitem.name_localized;
                    Netsuiteitem.Display_Name_En   = Foodicsitem.name;
                    Netsuiteitem.InActive          = Foodicsitem.deleted_at.Year == 1 ? false : true;
                    Netsuiteitem.UPC_Code          = Foodicsitem.sku;
                    Netsuiteitem.Img               = Foodicsitem.image;
                    Netsuiteitem.Price             = (double)Foodicsitem.price;
                    Netsuiteitem.Subsidiary_Id     = Utility.ConvertToInt(ConfigurationManager.AppSettings[Subsidiary + "Netsuite.Subsidiary_Id"]);
                    Netsuiteitem.FoodicsUpdateDate = Foodicsitem.updated_at;
                    if (Foodicsitem.tax_group != null && !string.IsNullOrEmpty(Foodicsitem.tax_group.id))
                    {
                        Netsuiteitem.FoodicsTaxGroup_Id = Foodicsitem.tax_group.id;
                    }
                    if (Foodicsitem.category != null && !string.IsNullOrEmpty(Foodicsitem.category.id))
                    {
                        Netsuiteitem.FoodicsCategory_Id = Foodicsitem.category.id;
                        Categories.FoodicsCategories obj = new GenericeDAO <Categories.FoodicsCategories>().GetByFoodicsId(Foodicsitem.category.id);
                        if (obj != null && obj.Netsuite_Id > 0)
                        {
                            Netsuiteitem.Category_Id = obj.Netsuite_Id;
                        }
                    }
                    foreach (var ingredientsobj in Foodicsitem.ingredients)
                    {
                        Item itemcomponent = new GenericeDAO <Item>().GetByFoodicsId(ingredientsobj.id);
                        if (itemcomponent != null)//&& itemcomponent.Netsuite_Id > 0)
                        {
                            ItemCompnent objitmcom = new ItemCompnent();
                            objitmcom.UnitId   = 0;//Utility.ConvertToInt(itemobj.memberUnit);
                            objitmcom.UnitName = ingredientsobj.ingredient_unit;
                            objitmcom.Quantity = ingredientsobj.pivot.quantity;
                            if (itemcomponent.Netsuite_Id > 0)
                            {
                                objitmcom.ComponentId = itemcomponent.Netsuite_Id;
                            }
                            else
                            {
                                objitmcom.ComponentId = 0;
                            }
                            objitmcom.ItemFoodics_Id      = Foodicsitem.id;
                            objitmcom.ComponentFoodics_Id = ingredientsobj.id;

                            if (itemobj != null && itemobj.Netsuite_Id > 0)
                            {
                                objitmcom.ItemId = itemobj.Netsuite_Id;
                            }
                            else
                            {
                                objitmcom.ItemId = 0;//Utility.ConvertToInt(Assitem.internalId);
                            }
                            ItemCompnentList.Add(objitmcom);
                        }
                    }

                    NetSuitelst.Add(Netsuiteitem);
                }

                new GenericeDAO <Item>().FoodicsIntegration(NetSuitelst, false);
                new GenericeDAO <ItemCompnent>().ItemcompnentFoodicsIntegration(ItemCompnentList);
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }