コード例 #1
0
        private UnitsType[] GenerateNetSuiteNewlst(List <UnitsOfMeasure> ColLst)
        {
            #region variables
            com.netsuite.webservices.UnitsType[] UnitsTypeArr = new com.netsuite.webservices.UnitsType[ColLst.Count];
            com.netsuite.webservices.UnitsType   unitsTypeobj;
            UnitsTypeUomList UnitsTypeUomLst;
            UnitsTypeUom     UnitsTypeUomobj;
            Foodics.NetSuite.Shared.Model.UnitsOfMeasure           Obj_info;
            Foodics.NetSuite.Shared.Model.UnitsOfMeasureIngredient Obj_ingredient;
            #endregion

            for (int i = 0; i < ColLst.Count; i++)
            {
                try
                {
                    Obj_info = ColLst[i];

                    UnitsTypeUomLst = new UnitsTypeUomList();
                    UnitsTypeUomobj = new UnitsTypeUom();
                    unitsTypeobj    = new UnitsType();

                    UnitsTypeUomobj.baseUnit          = Obj_info.baseUnit;
                    UnitsTypeUomobj.baseUnitSpecified = true;

                    UnitsTypeUomobj.conversionRate          = 1;
                    UnitsTypeUomobj.conversionRateSpecified = true;

                    UnitsTypeUomobj.abbreviation       = Obj_info.abbreviation;
                    UnitsTypeUomobj.pluralAbbreviation = Obj_info.pluralAbbreviation;
                    UnitsTypeUomobj.pluralName         = Obj_info.pluralName;
                    UnitsTypeUomobj.unitName           = Obj_info.unitName;

                    List <UnitsOfMeasureIngredient> Ingredientlst = new GenericeDAO <UnitsOfMeasureIngredient>().GetWhere(" UnitsOfMeasure_Id =" + Obj_info.Id);
                    UnitsTypeUom[] UnitsTypeUomarr = new UnitsTypeUom[Ingredientlst.Count + 1];
                    UnitsTypeUomarr[0] = UnitsTypeUomobj;
                    for (int x = 0; x < Ingredientlst.Count; x++)
                    {
                        Obj_ingredient = Ingredientlst[x];
                        UnitsTypeUom UnitsTypeUom_Item = new UnitsTypeUom();
                        UnitsTypeUom_Item.conversionRate          = string.IsNullOrEmpty(Obj_ingredient.Storage_To_Ingredient_Value) ? 1 : Utility.ConvertToDouble(Obj_ingredient.Storage_To_Ingredient_Value);
                        UnitsTypeUom_Item.conversionRateSpecified = true;
                        UnitsTypeUom_Item.abbreviation            = Obj_ingredient.unitName;
                        UnitsTypeUom_Item.pluralAbbreviation      = Obj_ingredient.unitName;
                        UnitsTypeUom_Item.pluralName = Obj_ingredient.unitName;
                        UnitsTypeUom_Item.unitName   = Obj_ingredient.unitName;
                        UnitsTypeUomarr[x + 1]       = UnitsTypeUom_Item;
                    }
                    UnitsTypeUomLst.uom  = UnitsTypeUomarr;
                    unitsTypeobj.uomList = UnitsTypeUomLst;
                    unitsTypeobj.name    = Obj_info.Name;
                    UnitsTypeArr[i]      = unitsTypeobj;
                }
                catch (Exception ex)
                {
                    ColLst.RemoveAt(i);
                    LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                }
            }
            return(UnitsTypeArr);
        }
        private void Generate_Save_NetSuiteLst(List <FoodicsInventoryItem> lstitems, string Subsidiary)
        {
            try
            {
                List <Item> NetSuitelst = new List <Item>();
                foreach (var Foodicsitem in lstitems)
                {
                    Item Netsuiteitem = new Item();
                    Netsuiteitem.Foodics_Id             = Foodicsitem.id;
                    Netsuiteitem.Item_Type              = (int)Item_Type.InventoryItem;
                    Netsuiteitem.Item_Type_Name         = nameof(Item_Type.InventoryItem);
                    Netsuiteitem.Foodics_Item_Type_Name = nameof(FoodicsItem_Type.InventoryItem);
                    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 != null ? true : false;
                    Netsuiteitem.UPC_Code        = Foodicsitem.sku;
                    Netsuiteitem.Storage_Unit    = Foodicsitem.storage_unit;
                    Netsuiteitem.Ingredient_Unit = Foodicsitem.ingredient_unit;
                    Netsuiteitem.storage_to_ingredient_factor = Foodicsitem.storage_to_ingredient_factor;
                    Netsuiteitem.FoodicsUpdateDate            = Foodicsitem.updated_at;
                    Netsuiteitem.Subsidiary_Id = Utility.ConvertToInt(ConfigurationManager.AppSettings[Subsidiary + "Netsuite.Subsidiary_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);
                        Netsuiteitem.Category_Id = obj.Netsuite_Id;
                    }

                    int UnitsOfMeasure_Id = 0;
                    if (!string.IsNullOrEmpty(Netsuiteitem.Ingredient_Unit))
                    {
                        UnitsOfMeasure_Id = new CustomDAO().Check_Create_unitName(Netsuiteitem.Ingredient_Unit);
                    }

                    if (UnitsOfMeasure_Id > 0 && Netsuiteitem.Storage_Unit.ToLower() != Netsuiteitem.Ingredient_Unit.ToLower())
                    {
                        UnitsOfMeasureIngredient obj = new UnitsOfMeasureIngredient();
                        obj.Storage_To_Ingredient_Value = Netsuiteitem.storage_to_ingredient_factor;
                        obj.unitName          = Netsuiteitem.Storage_Unit;
                        obj.UnitsOfMeasure_Id = UnitsOfMeasure_Id;

                        new CustomDAO().Check_Create_unitName_ingredient(obj);
                    }
                    else if (!string.IsNullOrEmpty(Netsuiteitem.Storage_Unit) && Netsuiteitem.Storage_Unit.ToLower() != Netsuiteitem.Ingredient_Unit.ToLower())
                    {
                        new CustomDAO().Check_Create_unitName(Netsuiteitem.Storage_Unit);
                    }
                    Netsuiteitem.Price = Utility.ConvertToDouble(Foodicsitem.cost);

                    NetSuitelst.Add(Netsuiteitem);
                }
                new GenericeDAO <Item>().FoodicsIntegration(NetSuitelst, false);
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
コード例 #3
0
        private void UpdatedLst(List <Item> Lst_Items, WriteResponseList responseLst)
        {
            //Tuple to hold local order ids and its corresponding Netsuite ids
            List <Tuple <int, string> > iDs = new List <Tuple <int, string> >();

            //loop to fill tuple values
            //for (int counter = 0; counter < Lst_Items.Count; counter++)
            try
            {
                for (int counter = 0; counter < Lst_Items.Count; counter++)
                {
                    //ensure that order is added to netsuite
                    if (responseLst.writeResponse[counter].status.isSuccess)
                    {
                        RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                        //update netsuiteId property
                        Lst_Items[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
                        //add item to the tuple
                        iDs.Add(new Tuple <int, string>(Convert.ToInt32(rf.internalId.ToString()), Lst_Items[counter].Foodics_Id));
                    }
                }
            }
            catch (Exception ex)
            {
            }
            GenericeDAO <Item> objDAO = new GenericeDAO <Item>();

            //updates local db
            objDAO.UpdateNetsuiteIDs(iDs, "Item", true);
        }
 private void UpdatedInvoice(List <Foodics.NetSuite.Shared.Model.Invoice> InvoiceLst, WriteResponseList responseLst)
 {
     try
     {
         //Tuple to hold local invoice ids and its corresponding Netsuite ids
         List <Tuple <int, string> > iDs = new List <Tuple <int, string> >();
         //loop to fill tuple values
         for (int counter = 0; counter < InvoiceLst.Count; counter++)
         {
             //ensure that invoice is added to netsuite
             if (responseLst.writeResponse[counter].status.isSuccess)
             {
                 try
                 {
                     RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                     iDs.Add(new Tuple <int, string>(Convert.ToInt32(rf.internalId.ToString()), InvoiceLst[counter].Foodics_Id));
                 }
                 catch (Exception ex)
                 {
                     LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                 }
             }
         }
         GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice> objDAO = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>();
         objDAO.UpdateNetsuiteIDs(iDs, "Invoice");
     }
     catch (Exception ex)
     {
         LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
     }
 }
        public override Int64 Set(string parametersArr)
        {
            List <Foodics.NetSuite.Shared.Model.Categories.FoodicsCategories> Lst_Items_New    = new GenericeDAO <Foodics.NetSuite.Shared.Model.Categories.FoodicsCategories>().GetWhere(" ISNULL(Netsuite_Id ,0) = 0 ");
            List <Foodics.NetSuite.Shared.Model.Categories.FoodicsCategories> Lst_Items_Update = new GenericeDAO <Foodics.NetSuite.Shared.Model.Categories.FoodicsCategories>().GetWhere(" ISNULL(Netsuite_Id ,0) > 0 AND ( SyncDate IS NULL OR Foodics_Updated_At >= SyncDate )   ");

            if (Lst_Items_New.Count > 0)
            {
                WriteResponseList wr = Service(true).addList(GenerateNetSuitelst(Lst_Items_New));
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_Items_New, wr);
                }
            }
            else if (Lst_Items_Update.Count > 0)
            {
                WriteResponseList wr = Service(true).updateList(GenerateNetSuitelst(Lst_Items_Update.Take(100).ToList()));
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_Items_Update, wr);
                }
            }


            new CustomDAO().InvoiceRelatedUpdate();
            new CustomDAO().SetItemClass();

            return(0);
        }
        private void UpdatedLst(List <Item> Lst_Items, WriteResponseList responseLst)
        {
            //Tuple to hold local order ids and its corresponding Netsuite ids
            List <Tuple <int, string> > iDs = new List <Tuple <int, string> >();

            //loop to fill tuple values
            //for (int counter = 0; counter < Lst_Items.Count; counter++)
            try
            {
                for (int counter = 0; counter < Lst_Items.Count; counter++)
                {
                    //ensure that order is added to netsuite
                    if (responseLst.writeResponse[counter].status.isSuccess)
                    {
                        RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                        //update netsuiteId property
                        Lst_Items[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
                        //add item to the tuple
                        iDs.Add(new Tuple <int, string>(Convert.ToInt32(rf.internalId.ToString()), Lst_Items[counter].Foodics_Id));
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            GenericeDAO <Item> objDAO = new GenericeDAO <Item>();

            //updates local db
            objDAO.UpdateNetsuiteIDs(iDs, "Item", true);
        }
        public override Int64 Set(string parametersArr)
        {
            List <Item> Lst_ItemsAll    = new GenericeDAO <Item>().GetWhere("(Netsuite_Id IS NULL or Netsuite_Id =0) and inactive=0 and  Item_Type=" + (int)Item_Type.ServiceSaleItem).Take(200).ToList();
            List <Item> Lst_ItemsUpdate = new GenericeDAO <Item>().GetWhere(" isnull(Netsuite_Id,0) >0 and FoodicsUpdateDate >= SyncDate and Item_Type=" + (int)Item_Type.ServiceSaleItem).Take(100).ToList();

            List <Item> Lst_ItemsNew = Lst_ItemsAll.Where(x => x.Netsuite_Id == 0 || x.Netsuite_Id < 0).ToList();

            if (Lst_ItemsAll.Count <= 0)
            {
                return(0);
            }

            // Send order list to netsuite
            if (Lst_ItemsNew.Count > 0)
            {
                com.netsuite.webservices.ServiceSaleItem[] ItemArrNew = GenerateNetSuitelst(Lst_ItemsNew);
                WriteResponseList wrNew = Service(true).addList(ItemArrNew);
                bool result             = wrNew.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_ItemsNew, wrNew);
                }
            }

            if (Lst_ItemsUpdate.Count > 0)
            {
                com.netsuite.webservices.ServiceSaleItem[] ItemArrAdd = GenerateNetSuitelst(Lst_ItemsUpdate);
                // Send order list to netsuite
                WriteResponseList wr = Service(true).updateList(ItemArrAdd);
            }

            return(0);
        }
コード例 #8
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                // List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere("  inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent))   and Item_Type=" + (int)Item_Type.AssemblyItem).Take(200).ToList();
                //List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere(" id >= 1238  and inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent))   and Item_Type=" + (int)Item_Type.AssemblyItem);

                List <Item> Lst_ItemsUpdateAll = new GenericeDAO <Item>().GetWhere(" isnull(Netsuite_Id,0) >0 and FoodicsUpdateDate >= SyncDate and  Item_Type=" + (int)Item_Type.AssemblyItem);
                List <Item> Lst_ItemsNew       = new GenericeDAO <Item>().GetWhere("  isnull(Netsuite_Id,0) =0 and inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent)) and  Item_Type=" + (int)Item_Type.AssemblyItem).Take(200).ToList();



                // Send order list to netsuite
                if (Lst_ItemsNew.Count > 0)
                {
                    com.netsuite.webservices.AssemblyItem[] ItemArrNew = GenerateNetSuitelst(Lst_ItemsNew);

                    WriteResponseList wrNew = Service(true).addList(ItemArrNew);
                    bool result             = wrNew.status.isSuccess;
                    if (result)
                    {
                        //Update database with returned Netsuite ids
                        UpdatedLst(Lst_ItemsNew, wrNew);
                    }
                }

                int Exe_length = 100;
                int lstend     = Exe_length;
                if (Lst_ItemsUpdateAll.Count > 0)
                {
                    for (int Index = 0; Index < Lst_ItemsUpdateAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= Lst_ItemsUpdateAll.Count)
                        {
                            lstend = Lst_ItemsUpdateAll.Count - Index;
                        }
                        List <Item> Lst_ItemsUpdate = Lst_ItemsUpdateAll.GetRange(Index, lstend);

                        // Send order list to netsuite
                        if (Lst_ItemsUpdate.Count > 0)
                        {
                            com.netsuite.webservices.AssemblyItem[] ItemArrUpdate = GenerateNetSuitelst(Lst_ItemsUpdate);

                            WriteResponseList wr = Service(true).updateList(ItemArrUpdate);
                            UpdatedLst(Lst_ItemsUpdate, wr);
                            //    bool result = wr.status.isSuccess;
                        }
                    }
                }
                new CustomDAO().UpdateProductCompnent();
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }

            return(0);
        }
コード例 #9
0
        public override Int64 Set(string parametersArr)
        {
            new CustomDAO().InvoiceRelatedUpdate();
            new CustomDAO().SetItemClass();

            //List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere(" FoodicsUpdateDate >= UpdateDate and inactive=0 and  Item_Type=" + (int)Item_Type.InventoryItem).Take(200).ToList();

            List <Item> Lst_ItemsUpdateAll = new GenericeDAO <Item>().GetWhere(" isnull(Netsuite_Id,0) >0 and FoodicsUpdateDate >= SyncDate and  Item_Type=" + (int)Item_Type.InventoryItem + " order by FoodicsUpdateDate desc");
            List <Item> Lst_ItemsNew       = new GenericeDAO <Item>().GetWhere("  isnull(Netsuite_Id,0) =0 and inactive=0 and  Item_Type=" + (int)Item_Type.InventoryItem).Take(200).ToList();

            // Send order list to netsuite
            if (Lst_ItemsNew.Count > 0)
            {
                com.netsuite.webservices.InventoryItem[] ItemArrNew = GenerateNetSuitelst(Lst_ItemsNew);
                WriteResponseList wrNew = Service(true).addList(ItemArrNew);
                bool result             = wrNew.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_ItemsNew, wrNew);
                }
            }

            int Exe_length = 100;
            int lstend     = Exe_length;

            if (Lst_ItemsUpdateAll.Count > 0)
            {
                for (int Index = 0; Index < Lst_ItemsUpdateAll.Count; Index += Exe_length)
                {
                    if (Index + Exe_length >= Lst_ItemsUpdateAll.Count)
                    {
                        lstend = Lst_ItemsUpdateAll.Count - Index;
                    }
                    List <Item> Lst_ItemsUpdate = Lst_ItemsUpdateAll.GetRange(Index, lstend);
                    if (Lst_ItemsUpdate.Count > 0)
                    {
                        com.netsuite.webservices.InventoryItem[] ItemArrAdd = GenerateNetSuitelst(Lst_ItemsUpdate);
                        WriteResponseList wrNew = Service(true).updateList(ItemArrAdd);
                        bool result             = wrNew.status.isSuccess;
                        if (result)
                        {
                            //Update database with returned Netsuite ids
                            UpdatedLst(Lst_ItemsUpdate, wrNew);
                        }
                    }
                }
            }



            return(0);
        }
コード例 #10
0
        private void Updatedlst(List <Foodics.NetSuite.Shared.Model.UnitsOfMeasure> InvoiceLst, WriteResponseList responseLst)
        {
            try
            {
                string strids = "";
                //Tuple to hold local invoice ids and its corresponding Netsuite ids
                List <Tuple <int, string> > iDs = new List <Tuple <int, string> >();
                //loop to fill tuple values
                for (int counter = 0; counter < InvoiceLst.Count; counter++)
                {
                    //ensure that invoice is added to netsuite
                    if (responseLst.writeResponse[counter].status.isSuccess)
                    {
                        try
                        {
                            RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                            //update netsuiteId property
                            InvoiceLst[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
                            //add item to the tuple
                            iDs.Add(new Tuple <int, string>(Convert.ToInt32(rf.internalId.ToString()), InvoiceLst[counter].Id.ToString()));

                            strids += InvoiceLst[counter].Id.ToString();
                            if (counter + 1 < InvoiceLst.Count)
                            {
                                strids += ",";
                            }
                        }
                        catch (Exception ex)
                        {
                            LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                        }
                    }
                }
                // NetsuiteDAO objDAO = new NetsuiteDAO();
                //updates local db
                // LogDAO.Integration_Exception(LogIntegrationType.Info, TaskRunType.POST, "InvoiceTask UpdateDB", "Updating " + iDs.Count().ToString() + " from " + InvoiceLst.Count().ToString());

                //objDAO.UpdateNetsuiteIDs(iDs, "Invoice");

                GenericeDAO <Foodics.NetSuite.Shared.Model.UnitsOfMeasure> objDAO = new GenericeDAO <Foodics.NetSuite.Shared.Model.UnitsOfMeasure>();
                objDAO.MainUpdateNetsuiteIDs(iDs, "UnitsOfMeasure");
                new CustomDAO().UpdateUnitsOfMeasureIngredient(strids);
            }

            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
コード例 #11
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                new CustomDAO().Check_PaymentCash_Exist();
                List <Foodics.NetSuite.Shared.Model.PaymentMethod> Lst_Items = new GenericeDAO <Foodics.NetSuite.Shared.Model.PaymentMethod>().GetWhere(" (Netsuite_Id IS NULL or Netsuite_Id =0)");
                if (Lst_Items.Count <= 0)
                {
                    return(0);
                }

                RecordRef[] subsidiarylst = new RecordRef[1];
                com.netsuite.webservices.PaymentMethod[] ItemArr = new com.netsuite.webservices.PaymentMethod[Lst_Items.Count];
                for (int i = 0; i < Lst_Items.Count; i++)
                {
                    Foodics.NetSuite.Shared.Model.PaymentMethod Obj           = Lst_Items[i];
                    com.netsuite.webservices.PaymentMethod      NewItemObject = new com.netsuite.webservices.PaymentMethod();
                    NewItemObject.name = Obj.Name_En.Length > 30 ? Obj.Name_En.Substring(0, 30) : Obj.Name_En;

                    NewItemObject.undepFunds          = true;
                    NewItemObject.undepFundsSpecified = true;

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

                    ItemArr[i] = NewItemObject;
                }
                // Send order list to netsuite
                WriteResponseList wr = Service(true).addList(ItemArr);
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_Items, wr);
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(0);
        }
コード例 #12
0
        public override Int64 Set(string parametersArr)
        {
            List <Foodics.NetSuite.Shared.Model.Location> Lst_Items = new GenericeDAO <Foodics.NetSuite.Shared.Model.Location>().GetWhere("Netsuite_Id IS NULL or Netsuite_Id =0");

            if (Lst_Items.Count <= 0)
            {
                return(0);
            }

            try
            {
                com.netsuite.webservices.Location[] ItemArr = new com.netsuite.webservices.Location[Lst_Items.Count];
                for (int i = 0; i < Lst_Items.Count; i++)
                {
                    Foodics.NetSuite.Shared.Model.Location Obj = Lst_Items[i];
                    RecordRef[] subsidiarylst = new RecordRef[1];
                    com.netsuite.webservices.Location NewItemObject = new com.netsuite.webservices.Location();
                    NewItemObject.name      = Obj.Name_En.Length < 30? Obj.Name_En: Obj.Name_En.Substring(0, 30);
                    NewItemObject.latitude  = Utility.ConvertToDouble(Obj.Latitude);
                    NewItemObject.longitude = Utility.ConvertToDouble(Obj.Longitude);

                    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;
                }
                WriteResponseList wr = Service(true).addList(ItemArr);
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    UpdatedLst(Lst_Items, wr);
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(0);
        }
コード例 #13
0
        private void UpdatedInvoice(List <Foodics.NetSuite.Shared.Model.Invoice> InvoiceLst, WriteResponseList responseLst)
        {
            try
            {
                //Tuple to hold local invoice ids and its corresponding Netsuite ids
                List <Tuple <int, string> > iDs = new List <Tuple <int, string> >();
                //loop to fill tuple values
                for (int counter = 0; counter < InvoiceLst.Count; counter++)
                {
                    //ensure that invoice is added to netsuite
                    if (responseLst.writeResponse[counter].status.isSuccess)
                    {
                        try
                        {
                            RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                            //update netsuiteId property
                            InvoiceLst[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
                            //add item to the tuple
                            iDs.Add(new Tuple <int, string>(Convert.ToInt32(rf.internalId.ToString()), InvoiceLst[counter].Foodics_Id));
                        }
                        catch (Exception ex)
                        {
                            //   LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask UpdateDB Counter Error", "Error " + ex.Message + " Count = " + counter.ToString());
                        }
                    }
                }
                // NetsuiteDAO objDAO = new NetsuiteDAO();
                //updates local db
                // LogDAO.Integration_Exception(LogIntegrationType.Info, TaskRunType.POST, "InvoiceTask UpdateDB", "Updating " + iDs.Count().ToString() + " from " + InvoiceLst.Count().ToString());

                //objDAO.UpdateNetsuiteIDs(iDs, "Invoice");

                GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice> objDAO = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>();
                objDAO.UpdateNetsuiteIDs(iDs, "Invoice");
            }
            catch (Exception ex) {
                // LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask UpdateDB Error", "Error " + ex.Message);
            }
        }
        private void Generate_Save_NetSuiteLst(List <FoodicsModifierOptions> 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.ServiceSaleItem;
                    Netsuiteitem.Item_Type_Name    = nameof(Item_Type.ServiceSaleItem);
                    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.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;
                    }
                    NetSuitelst.Add(Netsuiteitem);
                }

                new GenericeDAO <Item>().FoodicsIntegration(NetSuitelst, false);
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
コード例 #15
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                //get recentrly added invoices after creating the return
                List <Foodics.NetSuite.Shared.Model.UnitsOfMeasure> ColLst     = new GenericeDAO <Foodics.NetSuite.Shared.Model.UnitsOfMeasure>().GetWhere(" Netsuite_Id IS NULL or Netsuite_Id =0");
                List <Foodics.NetSuite.Shared.Model.UnitsOfMeasure> Lst_Update = new GenericeDAO <Foodics.NetSuite.Shared.Model.UnitsOfMeasure>().GetWhere(" [Id] in(select [UnitsOfMeasure_Id] from [dbo].[UnitsOfMeasureIngredient] where isnull([NetSuiteID],0) =0) ");
                if (ColLst.Count > 0)
                {
                    com.netsuite.webservices.UnitsType[] ArrNew = GenerateNetSuiteNewlst(ColLst);
                    WriteResponseList wrNew = Service(true).addList(ArrNew);
                    bool result             = wrNew.status.isSuccess;
                    if (result)
                    {
                        Updatedlst(ColLst, wrNew);
                    }
                }
                if (Lst_Update.Count > 0)
                {
                    com.netsuite.webservices.UnitsType[] ArrAdd = GenerateNetSuiteUpdatelst(Lst_Update);
                    WriteResponseList wr = Service(true).updateList(ArrAdd);
                    bool result          = wr.status.isSuccess;
                    if (result)
                    {
                        Updatedlstingredients(Lst_Update, wr);
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }



            return(0);
        }
        private void Updatedlst(List <Foodics.NetSuite.Shared.Model.AdjustmentBuild> InvoiceLst, WriteResponseList responseLst)
        {
            try
            {
                //Tuple to hold local invoice ids and its corresponding Netsuite ids
                List <Tuple <int, int, int> > iDs = new List <Tuple <int, int, int> >();
                //loop to fill tuple values
                for (int counter = 0; counter < InvoiceLst.Count; counter++)
                {
                    //ensure that invoice is added to netsuite
                    if (responseLst.writeResponse[counter].status.isSuccess)
                    {
                        try
                        {
                            RecordRef rf = (RecordRef)responseLst.writeResponse[counter].baseRef;
                            //update netsuiteId property
                            InvoiceLst[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
                            //add item to the tuple
                            iDs.Add(new Tuple <int, int, int>(Convert.ToInt32(rf.internalId.ToString()), InvoiceLst[counter].Location_Id, InvoiceLst[counter].Subsidiary_Id));
                        }
                        catch (Exception ex)
                        {
                            //   LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask UpdateDB Counter Error", "Error " + ex.Message + " Count = " + counter.ToString());
                        }
                    }
                }


                GenericeDAO <Foodics.NetSuite.Shared.Model.AssemblyBuild> objDAO = new GenericeDAO <Foodics.NetSuite.Shared.Model.AssemblyBuild>();
                objDAO.UpdateNetsuiteID_ADjustement(iDs, "AdjustmentBuild");
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
        public override void Get(string Subsidiary)
        {
            int    Subsidiary_Id = Utility.ConvertToInt(ConfigurationManager.AppSettings[Subsidiary + "Netsuite.Subsidiary_Id"]);
            object fromDateObj   = new GenericeDAO <Invoice>().GetLatestModifiedDate(Subsidiary_Id, "Date");
            //DateTime fromDateObj = Utility.ConvertToDateTime(ConfigurationManager.AppSettings["InvoiceDate"]);
            DateTime fromDate = new DateTime();

            if (fromDateObj == null)
            {
                fromDate = DateTime.Now;
            }
            else
            {
                fromDate = (DateTime)fromDateObj;
            }
            fromDate = new DateTime(fromDate.Year, fromDate.Month, fromDate.Day).AddDays(-3);
            while (fromDate <= DateTime.Now)
            //while (fromDate <= new DateTime(2021, 12, 20))
            {
                string MainURL = ConfigurationManager.AppSettings[Subsidiary + "Foodics.ResetURL"] + "orders?include=original_order,charges.charge,customer,branch,creator,discount,combos.combo_size.combo,combos.products,products.product,products.discount,products.options,products.options.modifier_option,payments.payment_method&filter[status]=4&filter[status]=5" + "&filter[business_date]=" + fromDate.ToString("yyyy-MM-dd");
                //string MainURL = ConfigurationManager.AppSettings[Subsidiary + "Foodics.ResetURL"] + "orders?include=original_order,charges.charge,customer,branch,creator,discount,combos.combo_size.combo,combos.products,products.product,products.discount,products.options,products.options.modifier_option,payments.payment_method&filter[status]=4&filter[status]=5" + "&filter[id]=b52def5c-2aef-4028-8a2f-b76b0ef48729";
                //string MainURL = ConfigurationManager.AppSettings[Subsidiary + "Foodics.ResetURL"] + "orders?include=original_order,charges.charge,customer,branch,creator,discount,combos.combo_size.combo,combos.products,products.product,products.discount,products.options,products.options.modifier_option,payments.payment_method&filter[status]=4&filter[status]=5" + "&filter[updated_after]=" + fromDate.ToString("yyyy-MM-dd");


                string NextPage = MainURL;
                do
                {
                    var client = new RestClient(NextPage);
                    //client.Timeout = -1;
                    client.Timeout = 200000;
                    var request = new RestRequest(Method.GET);
                    request.AddHeader("Authorization", "Bearer " + ConfigurationManager.AppSettings[Subsidiary + "Foodics.Token"]);
                    var response = client.Execute <Dictionary <string, List <FoodicsOrder> > >(request);
                    if (response.StatusCode == HttpStatusCode.OK && response.Data != null)
                    {
                        string content = response.Content;
                        var    Jobj    = JObject.Parse(content);
                        var    nodes   = Jobj.Descendants()
                                         .OfType <JProperty>()
                                         .Where(p => p.Name == "next")
                                         .Select(p => p.Parent)
                                         .ToList();
                        if (nodes.Count > 0)
                        {
                            FoodicsLinks objLinks = new FoodicsLinks();
                            try
                            {
                                objLinks = JsonConvert.DeserializeObject <FoodicsLinks>(JsonConvert.SerializeObject(nodes[0]));
                                NextPage = objLinks.next;
                                if (!string.IsNullOrEmpty(NextPage))
                                {
                                    int    startIndex = NextPage.LastIndexOf("?") + 1;
                                    int    endIndex   = NextPage.Length - startIndex;
                                    string page       = NextPage.Substring(startIndex, endIndex);
                                    NextPage = MainURL + "&" + page;
                                }
                                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "From Date " + fromDate.ToString("yyyy-MM-dd") + " Page:" + NextPage);
                            }
                            catch (Exception ex)
                            {
                                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message + " - Page index:" + NextPage);
                            }
                        }
                        foreach (var item in response.Data)
                        {
                            if (item.Key == "data")
                            {
                                if (item.Value.Count > 0)
                                {
                                    Generate_Save_NetSuiteLst(item.Value, Subsidiary_Id);
                                }
                            }
                        }
                    }
                } while (!string.IsNullOrEmpty(NextPage));
                fromDate = fromDate.AddDays(1);
            }
        }
        public com.netsuite.webservices.ServiceSaleItem[] GenerateNetSuitelst(List <Item> Lst_ItemsAll)
        {
            com.netsuite.webservices.ServiceSaleItem[] ItemArr = new com.netsuite.webservices.ServiceSaleItem[Lst_ItemsAll.Count];
            try
            {
                for (int i = 0; i < Lst_ItemsAll.Count; i++)
                {
                    RecordRef[] subsidiarylst = new RecordRef[1];
                    Item        Obj           = Lst_ItemsAll[i];
                    Setting     objSetting    = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Obj.Subsidiary_Id).FirstOrDefault();
                    Categories.CategoriesAccounts            objCatAccount = new Categories.CategoriesAccounts();
                    com.netsuite.webservices.ServiceSaleItem NewItemObject = new com.netsuite.webservices.ServiceSaleItem();
                    if (Obj.Netsuite_Id <= 0)
                    {
                        NewItemObject.displayName = Obj.Display_Name_En;
                        //NewItemObject.itemId = Obj.UPC_Code;
                        NewItemObject.itemId           = Obj.Display_Name_En;
                        NewItemObject.salesDescription = Obj.Display_Name_En;
                    }
                    //check if new or can be updated
                    if (Obj.Netsuite_Id > 0)
                    {
                        NewItemObject.internalId = Obj.Netsuite_Id.ToString();
                    }

                    NewItemObject.pricingMatrix = Helper.GeneratePricingMatrix(objSetting, Obj.Price);


                    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
                        new StringCustomFieldRef {
                            value    = Obj.Name_Ar != null? Obj.Name_Ar:"",
                            scriptId = "custitem_da_item_name_ar"
                        }
                    };
                    NewItemObject.customFieldList = custFieldList;


                    #region Items Account
                    RecordRef IncomAccountref = new RecordRef();
                    IncomAccountref.type        = RecordType.account;
                    NewItemObject.incomeAccount = IncomAccountref;

                    IncomAccountref.internalId = objSetting.IncomeAccount_Netsuite_Id.ToString();



                    #endregion
                    RecordRef Tax_Schedule = new RecordRef();
                    Tax_Schedule.internalId   = objSetting.TaxSchedule_Netsuite_Id.ToString();
                    Tax_Schedule.type         = RecordType.salesTaxItem;
                    NewItemObject.taxSchedule = Tax_Schedule;

                    RecordRef subsidiary = new RecordRef();
                    subsidiary.internalId        = objSetting.Subsidiary_Netsuite_Id.ToString();
                    subsidiary.type              = RecordType.subsidiary;
                    subsidiarylst[0]             = subsidiary;
                    NewItemObject.subsidiaryList = subsidiarylst;


                    NewItemObject.isInactive          = Obj.InActive;
                    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);
        }
コード例 #19
0
        private WriteResponseList CreateCreditMemo(List <Foodics.NetSuite.Shared.Model.Invoice> returnList)
        {
            //Define Array of credit Memo Then Loop
            CreditMemo[]     memoList = new CreditMemo[returnList.Count];
            CreditMemoItem[] memoitemarr;
            CreditMemoItem   invoiceItemObject;

            //add return id + return netsuite id to credit memo table, credit memo netsuite id
            #region Add Credit Memoes to CreditMemo Array

            for (int i = 0; i < returnList.Count; i++)
            {
                Foodics.NetSuite.Shared.Model.Invoice invoiceReturn   = returnList[i];
                Foodics.NetSuite.Shared.Model.Invoice invoiceoriginal = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>().GetWhere(" Foodics_Id = '" + invoiceReturn.Original_Foodics_Id + "'").FirstOrDefault();
                if (invoiceoriginal != null && invoiceoriginal.Netsuite_Id > 0)
                {
                    Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + invoiceReturn.Subsidiary_Id).FirstOrDefault();
                    StringCustomFieldRef FoodicsRef, FoodicsNumb, orderDiscount;
                    CustomFieldRef[]     customFieldRefArray;
                    CreditMemo           memo = new CreditMemo();
                    // Return
                    RecordRef returnRef = new RecordRef();
                    returnRef.internalId = invoiceoriginal.Netsuite_Id.ToString();
                    returnRef.type       = RecordType.invoice;
                    memo.createdFrom     = returnRef;


                    //Customer

                    RecordRef entity = new RecordRef();
                    entity.internalId = invoiceReturn.Customer_Netsuite_Id > 0 ? invoiceReturn.Customer_Netsuite_Id.ToString() : objSetting.Customer_Netsuite_Id.ToString();
                    entity.type       = RecordType.customer;
                    memo.entity       = entity;

                    //currency
                    RecordRef currency = new RecordRef();
                    currency.internalId = objSetting.Currency_Netsuite_Id.ToString();
                    currency.type       = RecordType.currency;
                    memo.currency       = currency;

                    //date
                    memo.tranDateSpecified = true;
                    memo.tranDate          = TimeZoneInfo.ConvertTimeToUtc(invoiceReturn.Date, TimeZoneInfo.Local);

                    //exchange rate
                    memo.exchangeRate = invoiceReturn.Exchange_Rate;

                    //subsidary
                    RecordRef subsid = new RecordRef();
                    subsid.internalId = invoiceReturn.Subsidiary_Id.ToString();
                    subsid.type       = RecordType.subsidiary;
                    memo.subsidiary   = subsid;


                    #region Item List
                    List <Foodics.NetSuite.Shared.Model.InvoiceItem> itemLst = new GenericeDAO <Foodics.NetSuite.Shared.Model.InvoiceItem>().GetWhere(" ProductStatus =6 and Invoice_Id =" + invoiceReturn.Id + " and isnull(Item_Id,0) >0 ");
                    int DiscountItems = itemLst.Where(x => x.Line_Discount_Amount > 0).Count();
                    //Define Invoice Items List
                    int totalItems = itemLst.Count + DiscountItems;
                    memoitemarr = new CreditMemoItem[totalItems];
                    if (itemLst.Count > 0)
                    {
                        CreditMemoItemList crdtmemoitmlst = new CreditMemoItemList();

                        try
                        {
                            int arr = 0;
                            for (int k = 0; k < totalItems; k++)
                            {
                                Foodics.NetSuite.Shared.Model.InvoiceItem itemDetails = itemLst[arr];
                                invoiceItemObject = CreateCreditItem(objSetting, itemDetails);
                                memoitemarr[k]    = invoiceItemObject;
                                if (itemDetails.Line_Discount_Amount > 0)
                                {
                                    float Discount = itemDetails.Line_Discount_Amount;
                                    k++;
                                    Foodics.NetSuite.Shared.Model.InvoiceItem OtherCharge = new Foodics.NetSuite.Shared.Model.InvoiceItem();
                                    OtherCharge.Item_Id   = objSetting.OtherChargeItem_Netsuite_Id;
                                    OtherCharge.Amount    = Discount * -1;
                                    OtherCharge.Quantity  = 1;
                                    OtherCharge.Item_Type = "OtherChargeResaleItem";
                                    invoiceItemObject     = CreateCreditItem(objSetting, OtherCharge);
                                    memoitemarr[k]        = invoiceItemObject;
                                }
                                arr++;
                            }
                        }
                        catch (Exception ex)
                        {
                            LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                        }


                        crdtmemoitmlst.item = memoitemarr;
                        memo.itemList       = crdtmemoitmlst;
                    }

                    #endregion

                    #region Discount
                    if (invoiceReturn.Total_Discount > 0)
                    {
                        RecordRef discountitem = new RecordRef();
                        discountitem.type = RecordType.discountItem;
                        memo.discountItem = discountitem;

                        memo.discountRate = (Math.Round((invoiceReturn.Total_Discount / 1.15), 3) * -1).ToString();
                        if (invoiceReturn.Discount_Id > 0)
                        {
                            discountitem.internalId = invoiceReturn.Discount_Id.ToString();
                        }
                        else
                        {
                            discountitem.internalId = objSetting.DiscountItem_Netsuite_Id.ToString();
                        }
                    }
                    else
                    {
                        memo.discountRate = "0";
                    }
                    if (invoiceReturn.Accounting_Discount_Item != 0)
                    {
                        RecordRef discItem = new RecordRef();
                        discItem.internalId = invoiceReturn.Accounting_Discount_Item.ToString();
                        discItem.type       = RecordType.discountItem;
                        memo.discountItem   = discItem;
                    }
                    #region Custom Attributes
                    orderDiscount          = new StringCustomFieldRef();
                    orderDiscount.scriptId = "custbody_da_invoice_discount";
                    orderDiscount.value    = invoiceReturn.Total_Discount.ToString();


                    FoodicsRef          = new StringCustomFieldRef();
                    FoodicsRef.scriptId = "custbody_da_foodics_reference";
                    FoodicsRef.value    = invoiceReturn.BarCode.ToString();

                    FoodicsNumb          = new StringCustomFieldRef();
                    FoodicsNumb.scriptId = "custbody_da_foodics_number";
                    FoodicsNumb.value    = invoiceReturn.Number.ToString();

                    customFieldRefArray    = new CustomFieldRef[3];
                    customFieldRefArray[0] = orderDiscount;
                    customFieldRefArray[1] = FoodicsRef;
                    customFieldRefArray[2] = FoodicsNumb;

                    memo.customFieldList = customFieldRefArray;
                    #endregion

                    #endregion


                    memoList[i] = memo;
                }
            }

            //Post Memos to Netsuite
            WriteResponseList memoWR = Service(true).addList(memoList);
            bool receiptresult       = memoWR.status.isSuccess;

            if (receiptresult)
            {
                UpdatedInvoice(returnList, memoWR);
            }
            #endregion
            return(memoWR);
        }
        public override Int64 Set(string parametersArr)
        {
            new CustomDAO().InvoiceRelatedUpdate();
            new CustomDAO().GenerateAssemblyBuild();

            List <Foodics.NetSuite.Shared.Model.AssemblyBuild> lstitemsAll = new GenericeDAO <Foodics.NetSuite.Shared.Model.AssemblyBuild>().GetWhere(" item_id >0 and ISNULL(Netsuite_Id,0) =0 ").Take(1000).ToList();
            int Exe_length = 200;
            int lstend     = Exe_length;

            if (lstitemsAll.Count > 0)
            {
                for (int Index = 0; Index < lstitemsAll.Count; Index += Exe_length)
                {
                    if (Index + Exe_length >= lstitemsAll.Count)
                    {
                        lstend = lstitemsAll.Count - Index;
                    }
                    List <Foodics.NetSuite.Shared.Model.AssemblyBuild> ColLst = lstitemsAll.GetRange(Index, lstend);
                    try
                    {
                        bool result = true;
                        if (ColLst.Count > 0)
                        {
                            #region variables
                            com.netsuite.webservices.AssemblyBuild[]    AssemblyArr = new com.netsuite.webservices.AssemblyBuild[ColLst.Count];
                            Foodics.NetSuite.Shared.Model.AssemblyBuild Obj_info;
                            com.netsuite.webservices.AssemblyBuild      AssemblyBuildObject;
                            RecordRef Mainitem, subsid, location;
                            #endregion
                            for (int i = 0; i < ColLst.Count; i++)
                            {
                                try
                                {
                                    Obj_info                              = ColLst[i];
                                    AssemblyBuildObject                   = new com.netsuite.webservices.AssemblyBuild();
                                    AssemblyBuildObject.quantity          = Obj_info.Quantity;
                                    AssemblyBuildObject.quantitySpecified = true;

                                    Mainitem                 = new RecordRef();
                                    Mainitem.internalId      = Obj_info.Item_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                                    Mainitem.type            = RecordType.assemblyItem;
                                    AssemblyBuildObject.item = Mainitem;

                                    AssemblyBuildObject.tranDateSpecified = true;
                                    //AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, TimeZoneInfo.Local);
                                    //AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2021, 03, 01), TimeZoneInfo.Local);
                                    AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(Utility.ConvertToDateTime(ConfigurationManager.AppSettings["InvoiceDate"]), TimeZoneInfo.Local);

                                    location                     = new RecordRef();
                                    location.internalId          = Obj_info.Location_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                                    location.type                = RecordType.location;
                                    AssemblyBuildObject.location = location;

                                    subsid            = new RecordRef();
                                    subsid.internalId = Obj_info.Subsidiary_Id.ToString();
                                    subsid.type       = RecordType.subsidiary;
                                    AssemblyBuildObject.subsidiary = subsid;

                                    AssemblyArr[i] = AssemblyBuildObject;
                                }
                                catch (Exception ex)
                                {
                                    ColLst.RemoveAt(i);
                                    LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                                }
                            }
                            // Send invoice list to netsuite
                            WriteResponseList wr = Service(true).addList(AssemblyArr);
                            result = wr.status.isSuccess;
                            if (result)
                            {
                                //Update database with returned Netsuite ids
                                Updatedlst(ColLst, wr);
                            }
                        }

                        // post customerPayment to netsuite
                        //  bool postPayments = PostCustomerPayment();
                    }
                    catch (Exception ex)
                    {
                        LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                    }
                }
            }
            return(0);
        }
コード例 #21
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);
        }
コード例 #22
0
        //protected List<Model.ItemSubsidiary> subsidiaryListLocal = new List<Model.ItemSubsidiary>();
        //protected List<Model.Item> itemWithImages = new List<Model.Item>();
        //protected List<Model.ItemOptionListValue> ItemOptionList = new List<Model.ItemOptionListValue>();
        public override Int64 Set(string parametersArr)
        {
            List <Item> Lst_Items  = new GenericeDAO <Item>().GetWhere(" (Netsuite_Id IS NULL or Netsuite_Id =0) and Item_Type=" + (int)Item_Type.GiftCertificate);
            Setting     objSetting = new GenericeDAO <Setting>().GetAll().FirstOrDefault();

            if (objSetting == null)
            {
                return(0);
            }
            if (Lst_Items.Count <= 0)
            {
                return(0);
            }



            RecordRef[] subsidiarylst = new RecordRef[1];
            Price[]     pricelst      = new Price[1];
            Pricing[]   Pricinglst    = new Pricing[1];
            // AssemblyComponentList assemplyList = new AssemblyComponentList();
            ItemMemberList memberlst = new ItemMemberList();

            ItemMember[] ItemMemberlst = new ItemMember[1];
            com.netsuite.webservices.GiftCertificateItem[] ItemArr = new com.netsuite.webservices.GiftCertificateItem[Lst_Items.Count];
            for (int i = 0; i < Lst_Items.Count; i++)
            //for (int i = 0; i < 1; i++)
            {
                Item Obj = Lst_Items[i];

                com.netsuite.webservices.GiftCertificateItem NewItemObject = new com.netsuite.webservices.GiftCertificateItem();
                NewItemObject.displayName = Obj.Display_Name_En;
                NewItemObject.itemId      = Obj.UPC_Code;

                #region Custom fields

                if (!string.IsNullOrEmpty(Obj.Storage_Unit))
                {
                    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
                        new StringCustomFieldRef {
                            value    = Obj.Storage_Unit.ToString(),
                            scriptId = "custitem_da_it_uom"
                        },
                    };
                    NewItemObject.customFieldList = custFieldList;
                }

                #endregion


                //obj.


                #region AssemblyComponent
                // AssemblyComponent obj = new AssemblyComponent();
                //obj.



                //ItemMember obj = new ItemMember();

                //RecordRef Itemref = new RecordRef();
                //Itemref.internalId = "612";//objSetting.Subsidiary_Netsuite_Id.ToString();
                //Itemref.type = RecordType.inventoryItem;

                //obj.item = Itemref;
                //obj.quantity = 1;



                //ItemMemberlst[0] = obj;


                //memberlst.itemMember = ItemMemberlst;
                //NewItemObject.memberList = memberlst;

                //NewItemObject.item
                ////NewItemObject.component
                #endregion
                RecordRef Tax_Schedule = new RecordRef();
                Tax_Schedule.internalId   = objSetting.TaxSchedule_Netsuite_Id.ToString();
                Tax_Schedule.type         = RecordType.salesTaxItem;
                NewItemObject.taxSchedule = Tax_Schedule;

                RecordRef subsidiary = new RecordRef();
                subsidiary.internalId        = objSetting.Subsidiary_Netsuite_Id.ToString();
                subsidiary.type              = RecordType.subsidiary;
                subsidiarylst[0]             = subsidiary;
                NewItemObject.subsidiaryList = subsidiarylst;


                RecordRef Liability = new RecordRef();
                Liability.internalId           = objSetting.LiabilityAccount_Netsuite_Id.ToString();
                Liability.type                 = RecordType.subsidiary;
                NewItemObject.liabilityAccount = Liability;


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

                ItemArr[i] = NewItemObject;
            }
            // Send order list to netsuite
            WriteResponseList wr = Service(true).addList(ItemArr);
            bool result          = wr.status.isSuccess;
            if (result)
            {
                //Update database with returned Netsuite ids
                UpdatedLst(Lst_Items, wr);
            }
            return(0);
        }
コード例 #23
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                bool result = true;
                new CustomDAO().InvoiceRelatedUpdate();
                new CustomDAO().SetItemClass();
                #region Check Correct Invoices

                /*
                 * SELECT      *
                 * FROM            Invoice
                 * WHERE
                 * --(Location_Id = 201) and
                 * Order_Status=4
                 * and Net_Payable + Total_Discount != (select sum( Quantity  * amount) - sum(Line_Discount_Amount) from InvoiceItem where InvoiceItem.Invoice_Id =Invoice.Id and ISNULL(Item_Id,0)>0 and ProductStatus=3 )
                 *
                 * SELECT      *
                 * FROM            Invoice
                 * WHERE
                 *
                 * Order_Status=5
                 * and Net_Payable + Total_Discount != (select sum( Quantity  * amount) - sum(Line_Discount_Amount) from InvoiceItem where InvoiceItem.Invoice_Id =Invoice.Id and ISNULL(Item_Id,0)>0 and ProductStatus=6 )
                 * select * from InvoiceItem where isnull([Item_Id], 0)=0
                 *
                 * Declare @id nvarchar(50)
                 * set @id='007f91e2-a8ad-4dab-a20a-70c90e8db6ce'
                 *              select * from Invoice
                 *              where Foodics_Id =@id
                 *              select Net_Payable,Net_Payable-((Net_Payable*15)/100) from Invoice
                 *              where Foodics_Id =@id
                 *              select * from InvoiceItem
                 *              where Foodics_Id =@id
                 */
                #endregion
                List <Foodics.NetSuite.Shared.Model.Invoice> lstitemsAll = new CustomDAO().SelectInvoice(4);
                int Exe_length = 200;
                int lstend     = Exe_length;
                if (lstitemsAll.Count > 0)
                {
                    for (int Index = 0; Index < lstitemsAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= lstitemsAll.Count)
                        {
                            lstend = lstitemsAll.Count - Index;
                        }
                        List <Foodics.NetSuite.Shared.Model.Invoice> invoiceLst = lstitemsAll.GetRange(Index, lstend);

                        if (invoiceLst.Count > 0)
                        {
                            #region variables
                            Invoice[] InvoiceArr = new Invoice[invoiceLst.Count];



                            Foodics.NetSuite.Shared.Model.Invoice     invoice_info;
                            Foodics.NetSuite.Shared.Model.InvoiceItem itemDetails;


                            DateTime        invoice_date;
                            Invoice         invoiceObject;
                            InvoiceItem     invoiceItemObject;
                            InvoiceItemList items;

                            RecordRef            subsid, currency, entity, location;
                            StringCustomFieldRef FoodicsRef, FoodicsNumb, CreatedBy, Source, orderDiscount;
                            CustomFieldRef[]     customFieldRefArray;
                            #endregion
                            for (int i = 0; i < invoiceLst.Count; i++)
                            {
                                try
                                {
                                    List <Foodics.NetSuite.Shared.Model.InvoiceItem> itemLst = new List <Foodics.NetSuite.Shared.Model.InvoiceItem>();
                                    List <InvoiceItem> invoiceItems = new List <InvoiceItem>();
                                    invoice_info = invoiceLst[i];
                                    Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + invoice_info.Subsidiary_Id).FirstOrDefault();
                                    invoiceObject = new Invoice();
                                    #region invoice items
                                    itemLst = new GenericeDAO <Foodics.NetSuite.Shared.Model.InvoiceItem>().GetWhere(" ProductStatus =3 and Invoice_Id =" + invoice_info.Id + " and isnull(Item_Id,0) >0 ");
                                    try
                                    {
                                        for (int k = 0; k < itemLst.Count; k++)
                                        {
                                            itemDetails       = itemLst[k];
                                            invoiceItemObject = CreateInvoiceItem(objSetting, itemDetails);
                                            invoiceItems.Add(invoiceItemObject);
                                            if (itemDetails.Line_Discount_Amount > 0)
                                            {
                                                float Discount = itemDetails.Line_Discount_Amount;
                                                Foodics.NetSuite.Shared.Model.InvoiceItem OtherCharge = new Foodics.NetSuite.Shared.Model.InvoiceItem();
                                                OtherCharge.Item_Id   = objSetting.OtherChargeItem_Netsuite_Id;
                                                OtherCharge.Amount    = Discount * -1;
                                                OtherCharge.Quantity  = 1;
                                                OtherCharge.Item_Type = nameof(Item_Type.OtherChargeSaleItem);
                                                invoiceItemObject     = CreateInvoiceItem(objSetting, OtherCharge);
                                                invoiceItems.Add(invoiceItemObject);
                                            }
                                        }
                                        //if (invoice_info.Total_Discount > 0)
                                        //{
                                        //    float Discount = invoice_info.Total_Discount;
                                        //    Foodics.NetSuite.Shared.Model.InvoiceItem discountItem = new Foodics.NetSuite.Shared.Model.InvoiceItem();
                                        //    if (invoice_info.Discount_Id > 0)
                                        //        discountItem.Item_Id = invoice_info.Discount_Id;
                                        //    else
                                        //        discountItem.Item_Id = objSetting.DiscountItem_Netsuite_Id;

                                        //    discountItem.Amount = Discount * -1;
                                        //    //discountItem.Quantity = 1;
                                        //    discountItem.Item_Type = nameof(Item_Type.DiscountItem);
                                        //    invoiceItemObject = CreateInvoiceItem(objSetting, discountItem);
                                        //    invoiceItems.Add(invoiceItemObject);
                                        //}
                                    }
                                    catch (Exception ex)
                                    {
                                        LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                                    }
                                    //Assign invoive items
                                    items                  = new InvoiceItemList();
                                    items.item             = invoiceItems.ToArray();
                                    invoiceObject.itemList = items;

                                    //GiftCertRedemption
                                    #endregion


                                    #region Standard Attributes
                                    invoice_date = TimeZoneInfo.ConvertTimeToUtc(invoice_info.Date, TimeZoneInfo.Local);

                                    //invoiceObject.externalId = invoice_info.BarCode;
                                    invoiceObject.tranDateSpecified = true;
                                    invoiceObject.dueDateSpecified  = true;
                                    invoiceObject.tranDate          = invoice_date;
                                    invoiceObject.dueDate           = invoice_date;
                                    invoiceObject.exchangeRate      = invoice_info.Exchange_Rate;


                                    //invoiceObject.memo = invoice_info.Notes;
                                    if (invoice_info.Subsidiary_Id > 0)
                                    {
                                        subsid                   = new RecordRef();
                                        subsid.internalId        = objSetting.Subsidiary_Netsuite_Id.ToString();
                                        subsid.type              = RecordType.subsidiary;
                                        invoiceObject.subsidiary = subsid;
                                    }
                                    currency               = new RecordRef();
                                    currency.internalId    = objSetting.Currency_Netsuite_Id.ToString();
                                    currency.type          = RecordType.currency;
                                    invoiceObject.currency = currency;
                                    entity               = new RecordRef();
                                    entity.internalId    = invoice_info.Customer_Netsuite_Id > 0 ? invoice_info.Customer_Netsuite_Id.ToString() : objSetting.Customer_Netsuite_Id.ToString();
                                    entity.type          = RecordType.customer;
                                    invoiceObject.entity = entity;

                                    location               = new RecordRef();
                                    location.internalId    = invoice_info.Location_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                                    location.type          = RecordType.location;
                                    invoiceObject.location = location;

                                    if (invoice_info.Sales_Rep_Id > 0)
                                    {
                                        RecordRef sales_rep = new RecordRef();
                                        sales_rep.internalId   = invoice_info.Sales_Rep_Id.ToString();
                                        sales_rep.type         = RecordType.employee;
                                        invoiceObject.salesRep = sales_rep;
                                    }
                                    #endregion

                                    #region Discount
                                    if (invoice_info.Total_Discount > 0)
                                    {
                                        RecordRef discountitem = new RecordRef();
                                        discountitem.type          = RecordType.discountItem;
                                        invoiceObject.discountItem = discountitem;
                                        float taxRate = 1 + (objSetting.TaxRate / 100);
                                        if (objSetting.TaxAlwaysAppliedInItems)
                                        {
                                            invoiceObject.discountRate = (Math.Round((invoice_info.Total_Discount / taxRate), 3) * -1).ToString();
                                        }
                                        else
                                        {
                                            //if (objSetting.ItemTaxInclusive)
                                            //    invoiceObject.discountRate = (Math.Round((invoice_info.Total_Discount / taxRate), 3) * -1).ToString();
                                            //else
                                            invoiceObject.discountRate = (Math.Round(invoice_info.Total_Discount, 3) * -1).ToString();
                                        }

                                        if (invoice_info.Discount_Id > 0)
                                        {
                                            discountitem.internalId = invoice_info.Discount_Id.ToString();
                                        }
                                        else
                                        {
                                            discountitem.internalId = objSetting.DiscountItem_Netsuite_Id.ToString();
                                        }
                                    }
                                    else
                                    {
                                        invoiceObject.discountRate = "0";
                                    }
                                    orderDiscount          = new StringCustomFieldRef();
                                    orderDiscount.scriptId = "custbody_da_invoice_discount";
                                    orderDiscount.value    = invoice_info.Total_Discount.ToString();

                                    //if (invoice_info.Accounting_Discount_Item != 0)
                                    //{
                                    //    RecordRef discItem = new RecordRef();
                                    //    discItem.internalId = invoice_info.Accounting_Discount_Item.ToString();
                                    //    discItem.type = RecordType.discountItem;
                                    //    invoiceObject.discountItem = discItem;
                                    //}
                                    #endregion

                                    //RecordRef Approval = new RecordRef();
                                    //Approval.internalId = "2";
                                    ////Approval.type = RecordType.;
                                    //invoiceObject.approvalStatus = Approval;

                                    #region Invoice Custom Attributes
                                    FoodicsRef          = new StringCustomFieldRef();
                                    FoodicsRef.scriptId = "custbody_da_foodics_reference";
                                    FoodicsRef.value    = invoice_info.BarCode.ToString();

                                    FoodicsNumb          = new StringCustomFieldRef();
                                    FoodicsNumb.scriptId = "custbody_da_foodics_number";
                                    FoodicsNumb.value    = invoice_info.Number.ToString();

                                    CreatedBy          = new StringCustomFieldRef();
                                    CreatedBy.scriptId = "custbody_da_foodics_createdby";
                                    CreatedBy.value    = invoice_info.CreatedBy != null?invoice_info.CreatedBy.ToString() : "";

                                    Source          = new StringCustomFieldRef();
                                    Source.scriptId = "custbody_da_foodics_source";
                                    Source.value    = invoice_info.Source.ToString();

                                    customFieldRefArray    = new CustomFieldRef[5];
                                    customFieldRefArray[0] = orderDiscount;
                                    customFieldRefArray[1] = FoodicsRef;
                                    customFieldRefArray[2] = FoodicsNumb;
                                    customFieldRefArray[3] = CreatedBy;
                                    customFieldRefArray[4] = Source;

                                    invoiceObject.customFieldList = customFieldRefArray;
                                    #endregion
                                    InvoiceArr[i] = invoiceObject;
                                }
                                catch (Exception ex)
                                {
                                    //invoiceLst.RemoveAt(i);
                                    LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                                }
                            }
                            // Send invoice list to netsuite
                            WriteResponseList wr = Service(true).addList(InvoiceArr);
                            result = wr.status.isSuccess;
                            if (result)
                            {
                                //Update database with returned Netsuite ids
                                UpdatedInvoice(invoiceLst, wr);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }



            return(0);
        }
コード例 #24
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                new CustomDAO().Check_PaymentCash_Exist();
                List <Foodics.NetSuite.Shared.Model.Discount> Lst_Items = new GenericeDAO <Foodics.NetSuite.Shared.Model.Discount>().GetWhere(" InActive = 0 and (Netsuite_Id IS NULL or Netsuite_Id =0)");
                if (Lst_Items.Count <= 0)
                {
                    return(0);
                }
                com.netsuite.webservices.DiscountItem[] ItemArr = new com.netsuite.webservices.DiscountItem[Lst_Items.Count];
                for (int i = 0; i < Lst_Items.Count; i++)
                {
                    RecordRef[] subsidiarylst = new RecordRef[1];
                    Foodics.NetSuite.Shared.Model.Discount Obj           = Lst_Items[i];
                    com.netsuite.webservices.DiscountItem  NewItemObject = new com.netsuite.webservices.DiscountItem();
                    Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Obj.Subsidiary_Id).FirstOrDefault();
                    if (objSetting != null && objSetting.Netsuite_Id <= 0)
                    {
                        return(0);
                    }

                    NewItemObject.displayName = Obj.Name_En + " - " + objSetting.Name;
                    NewItemObject.itemId      = Obj.Name_En + " - " + objSetting.Name;

                    NewItemObject.rate = Obj.Amount.ToString();
                    if (Obj.IsPercentage)
                    {
                        NewItemObject.rate += "%";
                    }

                    RecordRef subsidiary = new RecordRef();
                    subsidiary.internalId        = Obj.Subsidiary_Id.ToString();
                    subsidiary.type              = RecordType.subsidiary;
                    subsidiarylst[0]             = subsidiary;
                    NewItemObject.subsidiaryList = subsidiarylst;

                    RecordRef Accountref = new RecordRef();
                    Accountref.internalId = objSetting.DiscountAccount_Netsuite_Id.ToString();
                    Accountref.type       = RecordType.account;
                    NewItemObject.account = Accountref;
                    if (Obj.InActive)
                    {
                        NewItemObject.isInactive          = true;
                        NewItemObject.isInactiveSpecified = true;
                    }
                    ItemArr[i] = NewItemObject;
                }
                WriteResponseList wr = Service(true).addList(ItemArr);
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    UpdatedLst(Lst_Items, wr);
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(0);
        }
        public override Int64 Set(string parametersArr)
        {
            try
            {
                new CustomDAO().GenerateAdjustmentBuild();
                List <Foodics.NetSuite.Shared.Model.AdjustmentBuild> ColLstAll = new CustomDAO().SelectAdjustmentLocation();
                var ColLst =
                    ColLstAll.DistinctBy(x => new { x.Location_Id, x.Netsuite_Id }).Select(x => new AdjustmentBuild
                {
                    Location_Id   = x.Location_Id,
                    Subsidiary_Id = x.Subsidiary_Id,
                }).Distinct().ToList();
                if (ColLst.Count <= 0)
                {
                    return(0);
                }

                com.netsuite.webservices.InventoryAdjustment[] AdjustArr = new com.netsuite.webservices.InventoryAdjustment[ColLst.Count];
                for (int i = 0; i < ColLst.Count; i++)
                {
                    com.netsuite.webservices.InventoryAdjustment  AdjustBuildObject;
                    Foodics.NetSuite.Shared.Model.AdjustmentBuild Obj_info;
                    try
                    {
                        Obj_info = ColLst[i];
                        //Netsuite invoice type
                        AdjustBuildObject = new com.netsuite.webservices.InventoryAdjustment();
                        Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Obj_info.Subsidiary_Id).FirstOrDefault();

                        AdjustBuildObject.tranDateSpecified = true;
                        //AdjustBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, TimeZoneInfo.Local);
                        AdjustBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(Utility.ConvertToDateTime(ConfigurationManager.AppSettings["InvoiceDate"]), TimeZoneInfo.Local);

                        // adjustment account
                        RecordRef adjustment_account = new RecordRef();
                        adjustment_account.type          = RecordType.account;
                        adjustment_account.typeSpecified = true;
                        adjustment_account.internalId    = objSetting.AdjustmentAccount_Netsuite_Id.ToString();//"122";
                        AdjustBuildObject.account        = adjustment_account;

                        // adjustment location
                        RecordRef adjustment_location = new RecordRef();
                        adjustment_location.type          = RecordType.location;
                        adjustment_location.typeSpecified = true;
                        adjustment_location.internalId    = Obj_info.Location_Id.ToString();
                        AdjustBuildObject.location        = adjustment_location;
                        AdjustBuildObject.adjLocation     = adjustment_location;

                        // subsidiary
                        RecordRef adjustment_subsidiary = new RecordRef();
                        adjustment_subsidiary.type          = RecordType.subsidiary;
                        adjustment_subsidiary.typeSpecified = true;
                        adjustment_subsidiary.internalId    = Obj_info.Subsidiary_Id.ToString();
                        AdjustBuildObject.subsidiary        = adjustment_subsidiary;

                        List <Foodics.NetSuite.Shared.Model.AdjustmentBuild> adjustment_items = ColLstAll.Where(x => x.Subsidiary_Id == Obj_info.Subsidiary_Id && x.Location_Id == Obj_info.Location_Id).ToList();
                        InventoryAdjustmentInventory[] invadjustmentItemArray = new InventoryAdjustmentInventory[adjustment_items.Count()];
                        for (int x = 0; x < adjustment_items.Count(); x++)
                        {
                            RecordRef item = new RecordRef();
                            item.internalId = adjustment_items[x].Item_Id.ToString();

                            invadjustmentItemArray[x]                      = new InventoryAdjustmentInventory();
                            invadjustmentItemArray[x].item                 = item;
                            invadjustmentItemArray[x].location             = adjustment_location;
                            invadjustmentItemArray[x].adjustQtyBy          = (adjustment_items[x].Quantity * -1);
                            invadjustmentItemArray[x].adjustQtyBySpecified = true;
                        }

                        InventoryAdjustmentInventoryList invList = new InventoryAdjustmentInventoryList();
                        invList.inventory = invadjustmentItemArray;
                        AdjustBuildObject.inventoryList = invList;



                        AdjustArr[i] = AdjustBuildObject;
                    }
                    catch (Exception ex)
                    {
                        ColLst.RemoveAt(i);
                        LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                    }
                }

                WriteResponseList wr = Service(true).addList(AdjustArr);
                bool result          = wr.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    Updatedlst(ColLst, wr);
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }



            return(0);
        }
コード例 #26
0
        public com.netsuite.webservices.InventoryItem[] GenerateNetSuitelst(List <Item> Lst_ItemsAll)
        {
            com.netsuite.webservices.InventoryItem[] ItemArr = new com.netsuite.webservices.InventoryItem[Lst_ItemsAll.Count];
            try
            {
                for (int i = 0; i < Lst_ItemsAll.Count; i++)
                {
                    RecordRef[] subsidiarylst = new RecordRef[1];
                    Item        Obj           = Lst_ItemsAll[i];
                    Setting     objSetting    = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Obj.Subsidiary_Id).FirstOrDefault();
                    Categories.CategoriesAccounts          objCatAccount = new Categories.CategoriesAccounts();
                    com.netsuite.webservices.InventoryItem NewItemObject = new com.netsuite.webservices.InventoryItem();
                    //check if new or can be updated
                    if (Obj.Netsuite_Id > 0)
                    {
                        NewItemObject.internalId = Obj.Netsuite_Id.ToString();
                    }

                    NewItemObject.itemId           = Obj.UPC_Code;
                    NewItemObject.displayName      = Obj.Display_Name_En;
                    NewItemObject.salesDescription = Obj.Display_Name_En;

                    NewItemObject.trackLandedCost          = true;
                    NewItemObject.trackLandedCostSpecified = true;
                    if (Obj.Price > 0)
                    {
                        NewItemObject.pricingMatrix = Helper.GeneratePricingMatrix(objSetting, Obj.Price);
                    }
                    if (Obj.Category_Id > 0)
                    {
                        objCatAccount = new GenericeDAO <Categories.CategoriesAccounts>().GetWhere("Netsuite_Id=" + Obj.Category_Id).FirstOrDefault();
                        RecordRef classref = new RecordRef();
                        classref.internalId  = Obj.Category_Id.ToString();
                        classref.type        = RecordType.classification;
                        NewItemObject.@class = classref;
                    }
                    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
                        new StringCustomFieldRef {
                            value    = Obj.Name_Ar != null? Obj.Name_Ar:"",
                            scriptId = "custitem_da_item_name_ar"
                        }
                        ,
                        new StringCustomFieldRef {
                            value    = Obj.UPC_Code.ToString(),
                            scriptId = "custitem1"
                        }
                        ,
                        new StringCustomFieldRef {
                            value    = Obj.storage_to_ingredient_factor != null? Obj.storage_to_ingredient_factor:"",
                            scriptId = "custitem_da_item_ingredient"
                        }
                    };
                    NewItemObject.customFieldList = custFieldList;
                    UnitsOfMeasure objunit = new UnitsOfMeasure();
                    if (!string.IsNullOrEmpty(Obj.Ingredient_Unit))
                    {
                        List <UnitsOfMeasure> unitlst = new GenericeDAO <UnitsOfMeasure>().GetWhere("Name ='" + Obj.Ingredient_Unit + "' and abbreviation ='" + Obj.Storage_Unit + "' and conversionRate ='" + Obj.storage_to_ingredient_factor + "'");
                        if (unitlst.Count > 0)
                        {
                            objunit = unitlst[0];
                        }
                        else
                        {
                            unitlst = new GenericeDAO <UnitsOfMeasure>().GetWhere("Name ='" + Obj.Ingredient_Unit + "' and abbreviation ='" + Obj.Storage_Unit + "'");
                            if (unitlst.Count > 0)
                            {
                                objunit = unitlst[0];
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(Obj.Storage_Unit))
                    {
                        List <UnitsOfMeasure> unitlst = new GenericeDAO <UnitsOfMeasure>().GetWhere("unitName ='" + Obj.Storage_Unit + "' and abbreviation ='" + Obj.Storage_Unit + "' and conversionRate ='" + Obj.storage_to_ingredient_factor + "'");
                        if (unitlst.Count > 0)
                        {
                            objunit = unitlst[0];
                        }
                    }

                    if (objunit != null && objunit.Id > 0)
                    {
                        RecordRef unitsTyperef = new RecordRef();
                        unitsTyperef.internalId = objunit.unit_id.ToString();
                        unitsTyperef.type       = RecordType.unitsType;
                        NewItemObject.unitsType = unitsTyperef;

                        if (objunit.details_id > 0)
                        {
                            RecordRef unitsTyperefother = new RecordRef();
                            unitsTyperefother.internalId = objunit.details_id.ToString();
                            NewItemObject.saleUnit       = unitsTyperefother;
                            NewItemObject.stockUnit      = unitsTyperefother;
                            NewItemObject.purchaseUnit   = unitsTyperefother;
                        }
                    }


                    #region Items Account
                    RecordRef IncomAccountref = new RecordRef();
                    IncomAccountref.type = RecordType.account;
                    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();
                    }
                    if (!string.IsNullOrEmpty(IncomAccountref.internalId))
                    {
                        NewItemObject.incomeAccount = IncomAccountref;
                    }


                    RecordRef cogsAccountref = new RecordRef();
                    cogsAccountref.type = RecordType.account;
                    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();
                    }
                    if (!string.IsNullOrEmpty(cogsAccountref.internalId))
                    {
                        NewItemObject.cogsAccount = cogsAccountref;
                    }

                    RecordRef assetAccountref = new RecordRef();
                    assetAccountref.type = RecordType.account;
                    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();
                    }
                    if (!string.IsNullOrEmpty(assetAccountref.internalId))
                    {
                        NewItemObject.assetAccount = assetAccountref;
                    }


                    RecordRef intercoIncomeref = new RecordRef();
                    intercoIncomeref.type = RecordType.account;
                    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();
                    }

                    if (!string.IsNullOrEmpty(intercoIncomeref.internalId))
                    {
                        NewItemObject.intercoIncomeAccount = intercoIncomeref;
                    }

                    RecordRef intercoCogsAccount = new RecordRef();
                    intercoCogsAccount.type = RecordType.account;
                    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();
                    }

                    if (!string.IsNullOrEmpty(intercoCogsAccount.internalId))
                    {
                        NewItemObject.intercoCogsAccount = intercoCogsAccount;
                    }

                    RecordRef gainLossAccount = new RecordRef();
                    gainLossAccount.type = RecordType.account;
                    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 (!string.IsNullOrEmpty(gainLossAccount.internalId))
                    {
                        NewItemObject.gainLossAccount = gainLossAccount;
                    }

                    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 subsidiary = new RecordRef();
                    subsidiary.internalId        = objSetting.Subsidiary_Netsuite_Id.ToString();
                    subsidiary.type              = RecordType.subsidiary;
                    subsidiarylst[0]             = subsidiary;
                    NewItemObject.subsidiaryList = subsidiarylst;


                    NewItemObject.isInactive          = Obj.InActive;
                    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);
        }
        private static void GetProducts(Setting objSetting, List <InvoiceItem> InvoiceItemlst, FoodicsOrder Foodicsitem, Products prodobj, string ComboSize_Name, string Combo_Name)
        {
            List <Item> lstitemobj = new GenericeDAO <Item>().GetWhere("Foodics_Id = '" + prodobj.Product.id + "'").ToList();
            Item        itemobj    = new Item();

            if (lstitemobj.Count > 0)
            {
                itemobj = lstitemobj.FirstOrDefault();
            }

            InvoiceItem Netsuiteinvoiceitem = new InvoiceItem();

            Netsuiteinvoiceitem.Foodics_Id     = Foodicsitem.id;
            Netsuiteinvoiceitem.FoodicsItem_Id = prodobj.Product.id;
            Netsuiteinvoiceitem.FoodicsTax     = 0;
            Netsuiteinvoiceitem.Item_Id        = 0;
            if (itemobj != null)
            {
                Netsuiteinvoiceitem.Item_Id   = itemobj.Netsuite_Id;
                Netsuiteinvoiceitem.Item_Type = ((Item_Type)itemobj.Item_Type).ToString();
                //if (!string.IsNullOrEmpty(itemobj.Foodics_Item_Type_Name) && itemobj.Foodics_Item_Type_Name == nameof(FoodicsItem_Type.Product) && objSetting.TaxApplied)
                //if (!string.IsNullOrEmpty(itemobj.Foodics_Item_Type_Name) && itemobj.Foodics_Item_Type_Name == nameof(FoodicsItem_Type.Product) )
                if (!string.IsNullOrEmpty(itemobj.FoodicsTaxGroup_Id))
                {
                    Netsuiteinvoiceitem.FoodicsTax = objSetting.TaxRate;
                }

                //if (!string.IsNullOrEmpty(itemobj.FoodicsTaxGroup_Id))
                //Netsuiteinvoiceitem.FoodicsTax = 15;
            }
            Netsuiteinvoiceitem.Item_Name = prodobj.Product.name;
            Netsuiteinvoiceitem.Item_Code = prodobj.Product.sku;

            Netsuiteinvoiceitem.Quantity = prodobj.quantity;
            Netsuiteinvoiceitem.Amount   = (float)prodobj.unit_price;

            Netsuiteinvoiceitem.Line_Discount_Amount  = (float)prodobj.discount_amount;
            Netsuiteinvoiceitem.Is_Ingredients_Wasted = prodobj.is_ingredients_wasted;
            Netsuiteinvoiceitem.ProductStatus         = prodobj.status;
            Netsuiteinvoiceitem.ComboSize_Name        = ComboSize_Name;
            Netsuiteinvoiceitem.Combo_Name            = Combo_Name;
            InvoiceItemlst.Add(Netsuiteinvoiceitem);
            if (prodobj.options != null)
            {
                foreach (var optionitem in prodobj.options)
                {
                    Item        optionitemobj             = new GenericeDAO <Item>().GetWhere("Foodics_Id = '" + optionitem.modifier_option.id + "'").FirstOrDefault();
                    InvoiceItem NetsuiteInvoiceOptionItem = new InvoiceItem();
                    NetsuiteInvoiceOptionItem.Foodics_Id     = Foodicsitem.id;
                    NetsuiteInvoiceOptionItem.FoodicsItem_Id = optionitem.modifier_option.id;
                    if (optionitemobj != null && optionitemobj.Netsuite_Id > 0)
                    {
                        NetsuiteInvoiceOptionItem.Item_Id   = optionitemobj.Netsuite_Id;
                        NetsuiteInvoiceOptionItem.Item_Type = ((Item_Type)optionitemobj.Item_Type).ToString();
                    }
                    else
                    {
                        NetsuiteInvoiceOptionItem.Item_Id = 0;
                    }

                    if (optionitemobj != null && !string.IsNullOrEmpty(optionitemobj.FoodicsTaxGroup_Id))
                    {
                        NetsuiteInvoiceOptionItem.FoodicsTax = objSetting.TaxRate;
                    }
                    //if (objSetting.TaxOptionApplied)
                    //{
                    //    NetsuiteInvoiceOptionItem.FoodicsTax = objSetting.TaxRate;
                    //}

                    NetsuiteInvoiceOptionItem.Item_Name = optionitem.modifier_option.name;
                    NetsuiteInvoiceOptionItem.Item_Code = optionitem.modifier_option.sku;
                    NetsuiteInvoiceOptionItem.Quantity  = prodobj.quantity;
                    NetsuiteInvoiceOptionItem.Amount    = (float)optionitem.unit_price;

                    NetsuiteInvoiceOptionItem.Line_Discount_Amount  = 0;
                    NetsuiteInvoiceOptionItem.Is_Ingredients_Wasted = prodobj.is_ingredients_wasted;
                    NetsuiteInvoiceOptionItem.ProductStatus         = prodobj.status;
                    InvoiceItemlst.Add(NetsuiteInvoiceOptionItem);
                }
            }
        }
コード例 #28
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                //Set Values of Netsuite Customer ID
                //  LogDAO.Integration_Exception(LogIntegrationType.Info, TaskRunType.POST, "InvoiceTask", "Start");

                //new GenericeDAO<Foodics.NetSuite.Shared.Model.Invoice.Integrate>().GetAndUpdateCustomerIDandCreditMemo();
                //get recentrly added invoices after creating the return
                List <Foodics.NetSuite.Shared.Model.Invoice> invoiceLst = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>().GetWhere(" Netsuite_Id IS NULL or Netsuite_Id =0");
                Setting objSetting = new GenericeDAO <Setting>().GetAll().FirstOrDefault();
                // = new NetsuiteDAO().SelectInvoicesForIntegration();
                //  LogDAO.Integration_Exception(LogIntegrationType.Info, TaskRunType.POST, "InvoiceTask", "Count: " + invoiceLst.Count.ToString());
                bool result = true;
                if (invoiceLst.Count > 0)
                {
                    #region variables
                    Invoice[] InvoiceArr = new Invoice[invoiceLst.Count];

                    List <Foodics.NetSuite.Shared.Model.InvoiceItem> itemLst;
                    List <Foodics.NetSuite.Shared.Model.GiftCertificate.Integrate> giftCertificateLst;
                    //List<Foodics.NetSuite.Shared.Model.ItemLotSerial.Sales> lotSerialLst;

                    Foodics.NetSuite.Shared.Model.Invoice     invoice_info;
                    Foodics.NetSuite.Shared.Model.InvoiceItem itemDetails;

                    GiftCertRedemption[] giftRedeem;
                    InvoiceItem[]        invoiceItems;

                    DateTime                invoice_date;
                    Invoice                 invoiceObject;
                    InvoiceItem             invoiceItemObject;
                    InvoiceItemList         items;
                    InventoryAssignmentList InventoryAssignmentlst;
                    InventoryAssignment[]   assignList;
                    InventoryAssignment     assign;
                    InventoryDetail         invDetails;

                    GiftCertRedemptionList redemptionLst;

                    DateCustomFieldRef   trans_time;
                    ListOrRecordRef      emirate_region, custSelectValue, custSelectCashier;
                    SelectCustomFieldRef emirate_ref = null, terminal, cashier;
                    RecordRef            authCodeRef, taxCode, item, unit, price, itmSerial, discItem,
                                         subsid, currency, entity, location, classification, department;
                    DoubleCustomFieldRef line_total, line_discount_amount, balance, paid, lineDiscount;
                    StringCustomFieldRef trans_no, pos_id, orderDiscount;

                    CustomFieldRef[] customFieldRefArr, customFieldRefArray;

                    int item_custom_cols = 2;
                    #endregion

                    for (int i = 0; i < invoiceLst.Count; i++)
                    {
                        try
                        {
                            invoice_info = invoiceLst[i];
                            //Netsuite invoice type
                            invoiceObject = new Invoice();

                            //get invoice items
                            itemLst = new GenericeDAO <Foodics.NetSuite.Shared.Model.InvoiceItem>().GetWhere("Invoice_Id =" + invoice_info.Id);//new NetsuiteDAO().SelectInvoicItems(invoice_info.Id);

                            //get invoice gift certificates
                            #region gift certificate redemption
                            //try
                            //{
                            //    giftCertificateLst = new NetsuiteDAO().SelectEntityGiftCertificates(invoice_info.Id, 1);
                            //    if (giftCertificateLst.Count > 0)
                            //    {
                            //        redemptionLst = new GiftCertRedemptionList();
                            //        giftRedeem = new GiftCertRedemption[giftCertificateLst.Count];
                            //        for (int r = 0; r < giftCertificateLst.Count; r++)
                            //        {
                            //            GiftCertRedemption gift = new GiftCertRedemption();
                            //            authCodeRef = new RecordRef();
                            //            authCodeRef.internalId = giftCertificateLst[r].Netsuite_Id.ToString();
                            //            authCodeRef.type = RecordType.giftCertificate;
                            //            gift.authCode = authCodeRef;
                            //            gift.authCodeAppliedSpecified = true;
                            //            gift.authCodeApplied = Convert.ToDouble(giftCertificateLst[r].Amount);
                            //            giftRedeem[r] = gift;
                            //        }

                            //        redemptionLst.giftCertRedemption = giftRedeem;
                            //        invoiceObject.giftCertRedemptionList = redemptionLst;
                            //    }
                            //}
                            //catch (Exception ex)
                            //{
                            //    //LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask", "Error adding GiftCertificates: " + ex.Message + " Invoice id = " + invoiceLst[i].Id.ToString());
                            //}
                            #endregion

                            #region invoice items

                            //Define Invoice Items List
                            invoiceItems = new InvoiceItem[itemLst.Count];
                            try
                            {
                                item_custom_cols = 2;
                                for (int k = 0; k < itemLst.Count; k++)
                                {
                                    itemDetails       = itemLst[k];
                                    invoiceItemObject = new InvoiceItem();

                                    // TAX
                                    //invoiceItemObject.taxRate1Specified = true;
                                    //invoiceItemObject.taxRate1 = itemDetails.Tax_Rate;
                                    //invoiceItemObject.taxAmount = itemDetails.Tax_Amt;

                                    // tax code
                                    taxCode                   = new RecordRef();
                                    taxCode.internalId        = objSetting.TaxCode_Netsuite_Id.ToString(); //"15";//itemDetails.Tax_Code.ToString();
                                    taxCode.type              = RecordType.taxAcct;
                                    invoiceItemObject.taxCode = taxCode;

                                    // item
                                    item            = new RecordRef();
                                    item.internalId = itemDetails.Item_Id.ToString();
                                    item.type       = (RecordType)Enum.Parse(typeof(RecordType), itemDetails.Item_Type, true);
                                    //item.type = (RecordType)Enum.Parse(typeof(RecordType), "InventoryItem", true);
                                    invoiceItemObject.item = item;

                                    if (Utility.ConvertToInt(itemDetails.Units) > 0)
                                    {
                                        unit                    = new RecordRef();
                                        unit.internalId         = itemDetails.Units.ToString();
                                        unit.type               = RecordType.unitsType;
                                        invoiceItemObject.units = unit;
                                    }

                                    // price level
                                    #region price level
                                    price      = new RecordRef();
                                    price.type = RecordType.priceLevel;

                                    if (itemDetails.Amount > 0)
                                    {
                                        //if (itemDetails.Customer_Price_Level > 0)
                                        //{
                                        //    // customer price level
                                        //    price.internalId = itemDetails.Customer_Price_Level.ToString();
                                        //    invoiceItemObject.price = price;
                                        //}
                                        //else if (itemDetails.Price_Level_Id > 0)
                                        //{
                                        //    // default price level
                                        //    price.internalId = itemDetails.Price_Level_Id.ToString();
                                        //    invoiceItemObject.price = price;
                                        //}
                                        //else
                                        //{
                                        // amount
                                        invoiceItemObject.amountSpecified = true;
                                        invoiceItemObject.amount          = itemDetails.Amount;
                                        //}
                                    }

                                    #endregion

                                    // invoiceItemObject.costEstimateType = (ItemCostEstimateType)itemDetails.Cost_Estimate_Type;


                                    //if (itemDetails.Item_Type == "GiftCertificateItem")
                                    //{
                                    //    #region sell gift certificate
                                    //    try
                                    //    {
                                    //        invoiceItemObject.giftCertNumber = itemDetails.Gift_Code;
                                    //        invoiceItemObject.giftCertFrom = itemDetails.Sender;
                                    //        invoiceItemObject.giftCertMessage = itemDetails.Gift_Message;
                                    //        invoiceItemObject.giftCertRecipientName = itemDetails.Recipient_Name;
                                    //        invoiceItemObject.giftCertRecipientEmail = itemDetails.Recipient_Email;
                                    //    }
                                    //    catch { }
                                    //    #endregion
                                    //}
                                    //else
                                    //{
                                    // quantity
                                    invoiceItemObject.quantitySpecified = true;
                                    invoiceItemObject.quantity          = itemDetails.Quantity;

                                    #region serials/Lot
                                    //if (Utility.ItemTypeSerialized.Contains(itemDetails.Item_Type))
                                    //{
                                    //    lotSerialLst = new NetsuiteDAO().SelectInvoiceLotSerials(itemDetails.Id);
                                    //    InventoryAssignmentlst = new InventoryAssignmentList();
                                    //    assignList = new InventoryAssignment[lotSerialLst.Count];

                                    //    for (int z = 0; z < lotSerialLst.Count; z++)
                                    //    {
                                    //        assign = new InventoryAssignment();

                                    //        itmSerial = new RecordRef();
                                    //        itmSerial.internalId = lotSerialLst[z].Netsuite_Id.ToString();
                                    //        itmSerial.type = RecordType.lotNumberedInventoryItem;
                                    //        itmSerial.typeSpecified = true;

                                    //        if (Utility.ItemTypeLot.Contains(itemDetails.Item_Type))
                                    //        {
                                    //            assign.quantitySpecified = true;
                                    //            assign.quantity = lotSerialLst[z].Quantity;
                                    //        }
                                    //        assign.issueInventoryNumber = itmSerial;

                                    //        assignList[z] = assign;
                                    //    }

                                    //    InventoryAssignmentlst.inventoryAssignment = assignList;
                                    //    invDetails = new InventoryDetail();
                                    //    invDetails.inventoryAssignmentList = InventoryAssignmentlst;

                                    //    invoiceItemObject.inventoryDetail = invDetails;
                                    //}

                                    #endregion
                                    //  }

                                    #region custom fields

                                    try
                                    {
                                        #region line-item discount

                                        //line_total = new DoubleCustomFieldRef();
                                        //line_total.scriptId = "custcol_da_pos_line_item_total";
                                        //line_total.value = Math.Round(itemDetails.Total_Line_Amount, 3);

                                        //line_discount_amount = new DoubleCustomFieldRef();
                                        //line_discount_amount.scriptId = "custcol_da_pos_line_item_discount";
                                        //line_discount_amount.value = Math.Round(itemDetails.Line_Discount_Amount, 3);

                                        // line-item amount
                                        invoiceItemObject.amount = (itemDetails.Quantity * itemDetails.Amount);

                                        #endregion

                                        #region Transaction Region (Emirate)
                                        //item_custom_cols = 2;
                                        //if (invoice_info.Transaction_Region > 0)
                                        //{
                                        //    item_custom_cols = 3;
                                        //    emirate_region = new ListOrRecordRef();
                                        //    emirate_region.internalId = invoice_info.Transaction_Region.ToString();

                                        //    emirate_ref = new SelectCustomFieldRef();
                                        //    emirate_ref.scriptId = "custcol_emirate";
                                        //    emirate_ref.value = emirate_region;
                                        //}
                                        #endregion

                                        //customFieldRefArr = new CustomFieldRef[item_custom_cols];
                                        //customFieldRefArr[0] = line_total;
                                        //customFieldRefArr[1] = line_discount_amount;

                                        //if (item_custom_cols == 3)
                                        //    customFieldRefArr[2] = emirate_ref;

                                        //invoiceItemObject.customFieldList = customFieldRefArr;
                                    }
                                    catch (Exception ex)
                                    {
                                        //  LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask", "Error adding customField: " + ex.Message + " Invoice id = " + invoiceLst[i].Id.ToString());
                                    }
                                    #endregion

                                    invoiceItems[k] = invoiceItemObject;
                                }
                            }
                            catch (Exception ex)
                            {
                                //  LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask", "Error adding invoice: " + ex.Message + " Invoice id = " + invoiceLst[i].Id.ToString());
                            }
                            //Assign invoive items
                            items                  = new InvoiceItemList();
                            items.item             = invoiceItems;
                            invoiceObject.itemList = items;

                            //GiftCertRedemption
                            #endregion

                            #region Invoice Values

                            #region Standard Attributes
                            invoice_date = TimeZoneInfo.ConvertTimeToUtc(invoice_info.Date, TimeZoneInfo.Local);

                            invoiceObject.tranDateSpecified = true;
                            invoiceObject.dueDateSpecified  = true;
                            invoiceObject.tranDate          = invoice_date;
                            invoiceObject.dueDate           = invoice_date;
                            invoiceObject.exchangeRate      = invoice_info.Exchange_Rate;

                            invoiceObject.memo = invoice_info.Notes;

                            if (invoice_info.Subsidiary_Id > 0)
                            {
                                subsid                   = new RecordRef();
                                subsid.internalId        = objSetting.Subsidiary_Netsuite_Id.ToString();
                                subsid.type              = RecordType.subsidiary;
                                invoiceObject.subsidiary = subsid;
                            }

                            //RecordRef customForm = new RecordRef();
                            //customForm.internalId = "92";
                            //invoiceObject.customForm = customForm;

                            currency               = new RecordRef();
                            currency.internalId    = objSetting.Currency_Netsuite_Id.ToString();
                            currency.type          = RecordType.currency;
                            invoiceObject.currency = currency;

                            entity = new RecordRef();

                            entity.internalId    = invoice_info.Customer_Netsuite_Id > 0? invoice_info.Customer_Netsuite_Id.ToString(): objSetting.Customer_Netsuite_Id.ToString();
                            entity.type          = RecordType.customer;
                            invoiceObject.entity = entity;

                            location               = new RecordRef();
                            location.internalId    = invoice_info.Location_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                            location.type          = RecordType.location;
                            invoiceObject.location = location;

                            // department
                            //if (invoice_info.Department_Id > 0)
                            //{
                            //    department = new RecordRef();
                            //    department.internalId = invoice_info.Department_Id.ToString();
                            //    department.type = RecordType.department;
                            //    invoiceObject.department = department;
                            //}

                            //// class
                            //if (invoice_info.Class_Id > 0)
                            //{
                            //    classification = new RecordRef();
                            //    classification.internalId = invoice_info.Class_Id.ToString();
                            //    classification.type = RecordType.classification;
                            //    invoiceObject.@class = classification;
                            //}
                            // sales rep
                            if (invoice_info.Sales_Rep_Id > 0)
                            {
                                RecordRef sales_rep = new RecordRef();
                                sales_rep.internalId   = invoice_info.Sales_Rep_Id.ToString();
                                sales_rep.type         = RecordType.employee;
                                invoiceObject.salesRep = sales_rep;
                            }
                            #endregion

                            #region Invoice Custom Attributes

                            trans_no          = new StringCustomFieldRef();
                            trans_no.scriptId = "custbody_da_pos_trans_no";
                            trans_no.value    = invoice_info.BarCode.ToString();

                            pos_id          = new StringCustomFieldRef();
                            pos_id.scriptId = "custbody_da_pos_id";
                            pos_id.value    = invoice_info.Id.ToString();

                            custSelectValue = new ListOrRecordRef();

                            terminal = new SelectCustomFieldRef();
                            custSelectValue.internalId = invoice_info.Terminal_Id.ToString();
                            terminal.scriptId          = "custbody_da_terminal";
                            terminal.value             = custSelectValue;

                            custSelectCashier = new ListOrRecordRef();

                            cashier = new SelectCustomFieldRef();
                            custSelectCashier.internalId = invoice_info.Cashier.ToString();
                            cashier.scriptId             = "custbody_da_cashier";
                            cashier.value = custSelectCashier;

                            balance          = new DoubleCustomFieldRef();
                            balance.scriptId = "custbody_da_balance";
                            balance.value    = Math.Round(invoice_info.Balance, 3);


                            paid          = new DoubleCustomFieldRef();
                            paid.scriptId = "custbody_da_paid";
                            paid.value    = Math.Round(invoice_info.Paid, 3);

                            trans_time          = new DateCustomFieldRef();
                            trans_time.scriptId = "custbody_da_pos_trans_time";
                            trans_time.value    = invoice_date;

                            #region Discount

                            invoiceObject.discountRate = (Math.Round(invoice_info.Total_Discount, 3) * -1).ToString();

                            lineDiscount          = new DoubleCustomFieldRef();
                            lineDiscount.scriptId = "custbody_da_pos_line_item_discount";
                            lineDiscount.value    = Math.Round(invoice_info.Line_Discount_Amount, 3) * -1;


                            orderDiscount          = new StringCustomFieldRef();
                            orderDiscount.scriptId = "custbody_da_pos_order_discount";
                            orderDiscount.value    = (Math.Round(invoice_info.Invoice_Discount_Rate, 3) * -1).ToString();
                            if (invoice_info.Invoice_Discount_Type == 1)
                            {
                                orderDiscount.value = (Math.Round(invoice_info.Invoice_Discount_Rate, 3) * -1).ToString() + "%";
                            }

                            if (invoice_info.Accounting_Discount_Item != 0)
                            {
                                discItem                   = new RecordRef();
                                discItem.internalId        = invoice_info.Accounting_Discount_Item.ToString();
                                discItem.type              = RecordType.discountItem;
                                invoiceObject.discountItem = discItem;
                            }
                            #endregion

                            int length = 7;
                            if (invoice_info.Terminal_Id > 0)
                            {
                                length = 8;
                            }

                            customFieldRefArray    = new CustomFieldRef[length];
                            customFieldRefArray[0] = cashier;
                            customFieldRefArray[1] = balance;
                            customFieldRefArray[2] = paid;
                            customFieldRefArray[3] = trans_time;
                            customFieldRefArray[4] = trans_no;
                            customFieldRefArray[5] = lineDiscount;
                            customFieldRefArray[6] = orderDiscount;

                            if (invoice_info.Terminal_Id > 0)
                            {
                                customFieldRefArray[7] = terminal;
                            }

                            invoiceObject.customFieldList = customFieldRefArray;
                            #endregion

                            InvoiceArr[i] = invoiceObject;
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            invoiceLst.RemoveAt(i);
                            //  LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask", "Error adding invoice: " + ex.Message + " Invoice id = " + invoiceLst[i].Id.ToString());
                        }
                    }
                    // Send invoice list to netsuite
                    WriteResponseList wr = Service(true).addList(InvoiceArr);
                    result = wr.status.isSuccess;

                    // LogDAO.Integration_Exception(LogIntegrationType.Info, TaskRunType.POST, "InvoiceTask", "Status: " + result);
                    if (result)
                    {
                        //Update database with returned Netsuite ids
                        UpdatedInvoice(invoiceLst, wr);
                    }
                }

                // post customerPayment to netsuite
                //  bool postPayments = PostCustomerPayment();
            }
            catch (Exception ex)
            {
                //  LogDAO.Integration_Exception(LogIntegrationType.Error, TaskRunType.POST, "InvoiceTask Error", "Error " + ex.Message);
            }

            // release the the object
            //new ScheduleTaskDAO().Processing(taskType, TaskRunType.POST, false);

            return(0);
        }
        private void Generate_Save_NetSuiteLst(List <FoodicsOrder> OrderLstAll, int Subsidiary_Id)
        {
            try
            {
                int     Exe_length = 5;
                int     lstend     = Exe_length;
                Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + Subsidiary_Id).FirstOrDefault();
                if (OrderLstAll.Count > 0)
                {
                    for (int Index = 0; Index < OrderLstAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= OrderLstAll.Count)
                        {
                            lstend = OrderLstAll.Count - Index;
                        }
                        List <FoodicsOrder> OrderLst = OrderLstAll.GetRange(Index, lstend);
                        if (OrderLst.Count > 0)
                        {
                            List <PaymentMethod>       PaymentMethodLst       = new GenericeDAO <PaymentMethod>().GetAll();
                            List <Invoice>             Invoicelst             = new List <Invoice>();
                            List <InvoiceItem>         InvoiceItemlst         = new List <InvoiceItem>();
                            List <PaymentMethodEntity> PaymentMethodEntitylst = new List <PaymentMethodEntity>();
                            foreach (var Foodicsitem in OrderLst)
                            {
                                //List<Invoice> invoiceLst = new GenericeDAO<Invoice>().GetWhere(" Foodics_Id = '" + Foodicsitem.id + "' AND Date = '" + Foodicsitem.business_date.ToString("yyyy-MM-dd") + "'");
                                List <Invoice> invoiceLst = new GenericeDAO <Invoice>().GetWhere(" Foodics_Id = '" + Foodicsitem.id + "' AND ISNULL(Netsuite_Id,0) > 0");
                                if (invoiceLst.Count <= 0)
                                {
                                    Invoice Netsuiteitem = new Invoice();
                                    //barcode
                                    Netsuiteitem.Foodics_Id    = Foodicsitem.id;
                                    Netsuiteitem.Order_Status  = Foodicsitem.status;
                                    Netsuiteitem.Subsidiary_Id = Subsidiary_Id;

                                    if (Foodicsitem.original_order != null && !string.IsNullOrEmpty(Foodicsitem.original_order.id))
                                    {
                                        Netsuiteitem.Original_Foodics_Id = Foodicsitem.original_order.id;
                                    }
                                    else
                                    {
                                        Netsuiteitem.Original_Foodics_Id = "0";
                                    }

                                    if (Foodicsitem.Customer != null && !string.IsNullOrEmpty(Foodicsitem.Customer.Id))
                                    {
                                        Customer obj = new GenericeDAO <Customer>().GetByFoodicsId(Foodicsitem.Customer.Id);
                                        if (obj != null && Utility.ConvertToInt(obj.Id) > 0)
                                        {
                                            Netsuiteitem.Customer_Id          = Utility.ConvertToInt(obj.Id);
                                            Netsuiteitem.Customer_Netsuite_Id = obj.Netsuite_Id;
                                        }
                                    }
                                    else
                                    {
                                        Netsuiteitem.Customer_Id          = 0;
                                        Netsuiteitem.Customer_Netsuite_Id = 0;
                                    }


                                    if (Foodicsitem.Branch != null && !string.IsNullOrEmpty(Foodicsitem.Branch.id))
                                    {
                                        Location obj = new GenericeDAO <Location>().GetByFoodicsId(Foodicsitem.Branch.id);
                                        Netsuiteitem.Location_Id = obj.Netsuite_Id;
                                    }
                                    else
                                    {
                                        Netsuiteitem.Location_Id = 0;
                                    }

                                    //Invoice Discount
                                    if (Foodicsitem.discount != null && !string.IsNullOrEmpty(Foodicsitem.discount.id))
                                    {
                                        Discount obj = new GenericeDAO <Discount>().GetByFoodicsId(Foodicsitem.discount.id);
                                        if (obj != null && obj.Netsuite_Id > 0)
                                        {
                                            Netsuiteitem.Discount_Id = obj.Netsuite_Id;
                                        }
                                    }
                                    //Foodics Source
                                    if (Foodicsitem.source > 0)
                                    {
                                        Netsuiteitem.Source = Enum.GetName(typeof(InvoiceSource), Foodicsitem.source);
                                    }
                                    //Foodics CreatedBY
                                    if (Foodicsitem.creator != null && !string.IsNullOrEmpty(Foodicsitem.creator.id))
                                    {
                                        Netsuiteitem.CreatedBy = Foodicsitem.creator.name;
                                    }
                                    Netsuiteitem.Invoice_Discount_Type = Foodicsitem.discount_type;
                                    Netsuiteitem.Total_Discount        = (float)Foodicsitem.discount_amount;
                                    Netsuiteitem.Date     = Foodicsitem.business_date;
                                    Netsuiteitem.CreateAt = Foodicsitem.created_at;
                                    Netsuiteitem.OpenAt   = Foodicsitem.opened_at;
                                    Netsuiteitem.CloseAt  = Foodicsitem.closed_at;
                                    Netsuiteitem.UpdateAt = Foodicsitem.updated_at;

                                    Netsuiteitem.Interval_Note = Foodicsitem.kitchen_notes + Foodicsitem.customer_notes;
                                    Netsuiteitem.Notes         = Netsuiteitem.Interval_Note;

                                    Netsuiteitem.Paid        = (float)Foodicsitem.total_price;
                                    Netsuiteitem.Net_Payable = (float)Foodicsitem.subtotal_price;

                                    Netsuiteitem.BarCode = Foodicsitem.reference;
                                    Netsuiteitem.Number  = Foodicsitem.number.ToString();
                                    //Products
                                    foreach (var prodobj in Foodicsitem.Products)
                                    {
                                        GetProducts(objSetting, InvoiceItemlst, Foodicsitem, prodobj, "", "");
                                    }
                                    if (Foodicsitem.combos != null)
                                    {
                                        foreach (var Comboobj in Foodicsitem.combos)
                                        {
                                            foreach (var prodobj in Comboobj.Products)
                                            {
                                                GetProducts(objSetting, InvoiceItemlst, Foodicsitem, prodobj, Comboobj.combo_size.name, Comboobj.combo_size.combo.name);
                                            }
                                        }
                                    }
                                    if (Foodicsitem.charges != null)
                                    {
                                        foreach (var objCharges in Foodicsitem.charges)
                                        {
                                            Product  objproduct = new Product();
                                            Products objProds   = new Products();
                                            objProds.quantity   = 1;
                                            objProds.unit_price = objCharges.amount;
                                            objProds.Product    = objproduct;
                                            objProds.status     = 3;
                                            foreach (var objCharge in objCharges.charge)
                                            {
                                                objproduct.id   = objCharge.id;
                                                objproduct.name = objCharge.name;
                                                GetProducts(objSetting, InvoiceItemlst, Foodicsitem, objProds, "", "");
                                            }
                                        }
                                    }
                                    //payment methods
                                    foreach (var payobj in Foodicsitem.payments)
                                    {
                                        PaymentMethod PaymentMethodobj = PaymentMethodLst.Where(x => x.Foodics_Id == payobj.payment_method.id).FirstOrDefault();

                                        PaymentMethodEntity paymethod = new PaymentMethodEntity();

                                        paymethod.Foodics_Id = Foodicsitem.id;

                                        paymethod.Entity_Type   = 1;
                                        paymethod.Amount        = (float)payobj.amount;
                                        paymethod.Ref           = payobj.payment_method.name;
                                        paymethod.Notes         = payobj.payment_method.name;
                                        paymethod.Business_Date = payobj.Business_Date;
                                        if (PaymentMethodobj != null && PaymentMethodobj.Netsuite_Id > 0)
                                        {
                                            paymethod.Payment_Method            = PaymentMethodobj.Name_En;
                                            paymethod.Payment_Method_Id         = PaymentMethodobj.Netsuite_Id;
                                            paymethod.Payment_Method_Percentage = PaymentMethodobj.Percentage;
                                        }
                                        else
                                        {
                                            paymethod.Payment_Method            = "Cash";
                                            paymethod.Payment_Method_Id         = 1;
                                            paymethod.Payment_Method_Percentage = 0;
                                        }
                                        paymethod.Payment_Method_Type             = 0;
                                        paymethod.Payment_Method_Type_Netsuite_Id = 0;
                                        PaymentMethodEntitylst.Add(paymethod);
                                    }
                                    Invoicelst.Add(Netsuiteitem);
                                }
                            }
                            new GenericeDAO <Invoice>().InvoiceDetailsDelete(Invoicelst);
                            new GenericeDAO <Invoice>().ListInsertOnly(Invoicelst);
                            new GenericeDAO <InvoiceItem>().ListInsertOnly(InvoiceItemlst);
                            new GenericeDAO <PaymentMethodEntity>().ListInsertOnly(PaymentMethodEntitylst);
                            //new CustomDAO().InvoiceRelatedUpdate();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
        }
コード例 #30
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                List <Foodics.NetSuite.Shared.Model.Customer> Lst_CustomAll = new GenericeDAO <Foodics.NetSuite.Shared.Model.Customer>().GetWhere("Netsuite_Id IS NULL or Netsuite_Id =0").Take(2000).ToList();

                //List<Foodics.NetSuite.Shared.Model.Customer> Lst_CustomAll = new GenericeDAO<Foodics.NetSuite.Shared.Model.Customer>().GetWhere(" (Netsuite_Id IS NULL or Netsuite_Id =0) and  (Foodics_UpdateDate >= '"+ ConfigurationManager.AppSettings["InvoiceDate"] + "')").Take(2000).ToList();
                int Exe_length = 200;
                int lstend     = Exe_length;
                if (Lst_CustomAll.Count > 0)
                {
                    for (int Index = 0; Index < Lst_CustomAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= Lst_CustomAll.Count)
                        {
                            lstend = Lst_CustomAll.Count - Index;
                        }
                        List <Foodics.NetSuite.Shared.Model.Customer> Lst_Items = Lst_CustomAll.GetRange(Index, lstend);

                        List <com.netsuite.webservices.Customer> ItemArr = new List <com.netsuite.webservices.Customer>();

                        for (int i = 0; i < Lst_Items.Count; i++)
                        {
                            Foodics.NetSuite.Shared.Model.Customer Obj = Lst_Items[i];
                            try
                            {
                                CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");

                                com.netsuite.webservices.Customer NewItemObject = new com.netsuite.webservices.Customer();
                                string   Custname = Obj.name;
                                string[] Fullname = Custname.Split(' ');
                                if (Fullname.Length > 0)
                                {
                                    NewItemObject.firstName = Fullname[0];
                                }
                                else
                                {
                                    NewItemObject.firstName = Custname;
                                }
                                if (Fullname.Length > 1)
                                {
                                    string lastName = Custname.Remove(0, NewItemObject.firstName.Length);
                                    NewItemObject.lastName = lastName.Length > 30 ? lastName.Substring(0, 30) : lastName;
                                }
                                else
                                {
                                    NewItemObject.lastName = "-";
                                }


                                NewItemObject.isPerson          = true;
                                NewItemObject.isPersonSpecified = true;
                                NewItemObject.email             = Obj.email;
                                NewItemObject.phone             = Obj.phone;

                                RecordRef subsidiary = new RecordRef();
                                subsidiary.internalId    = Obj.Subsidiary_Id.ToString();
                                subsidiary.type          = RecordType.subsidiary;
                                NewItemObject.subsidiary = subsidiary;

                                if (Obj.InActive)
                                {
                                    NewItemObject.isInactive          = true;
                                    NewItemObject.isInactiveSpecified = true;
                                }
                                ItemArr.Add(NewItemObject);
                            }
                            catch (Exception ex)
                            {
                                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error in customer Name: " + Obj.name + " error: " + ex.Message);
                                Lst_Items.RemoveAt(i);
                            }
                        }
                        try
                        {
                            // Send order list to netsuite
                            WriteResponseList wr = Service(true).addList(ItemArr.ToArray());
                            bool result          = wr.status.isSuccess;
                            if (result)
                            {
                                UpdatedLst(Lst_Items, wr);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(0);
        }