コード例 #1
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 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 <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);
        }
        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);
        }
コード例 #5
0
 private void NetSuiteEntityManager_addListCompleted(object sender, addListCompletedEventArgs e)
 {
     if (!e.Cancelled)
     {
         result = e.Result;
     }
     requestFinished = true;
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        /// <summary>
        /// Invokes NetSuite's asyncAddList(..) method.
        /// </summary>
        /// <param name="records">The records to be added.</param>
        /// <returns>The filter criteria for the retrieved data.</returns>
        public virtual WriteResponseList AsyncAddList(Record[] recordsList)
        {
            WriteResponseList        result     = null;
            Task <WriteResponseList> resultTask = null;

            NetSuiteHelper.TryRun(() =>
            {
                using (var proxy = NetSuiteHelper.GetProxy())
                {
                    resultTask = proxy.addListAsync(recordsList);
                    result     = resultTask.Result;
                    return(result.status.isSuccessSpecified && result.status.isSuccess);
                }
            },
                                  (message) =>
            {
                LogMessage?.Invoke(message);
            });

            return(result);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
 private void Updatedlstingredients(List <Foodics.NetSuite.Shared.Model.UnitsOfMeasure> InvoiceLst, WriteResponseList responseLst)
 {
     try
     {
         string ids = "";
         for (int counter = 0; counter < InvoiceLst.Count; counter++)
         {
             if (responseLst.writeResponse[counter].status.isSuccess)
             {
                 try
                 {
                     ids += InvoiceLst[counter].Id.ToString();
                     if (counter + 1 < InvoiceLst.Count)
                     {
                         ids += ",";
                     }
                 }
                 catch (Exception ex)
                 {
                     LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                 }
             }
         }
         if (!string.IsNullOrEmpty(ids))
         {
             new CustomDAO().UpdateUnitsOfMeasureIngredient(ids);
         }
     }
     catch (Exception ex)
     {
         LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
     }
 }
コード例 #14
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);
        }
コード例 #15
0
        private void UpdatedLst(List <Foodics.NetSuite.Shared.Model.Categories.FoodicsCategories> Lst_Items, WriteResponseList responseLst)
        {
            //List<Tuple<int, string>> iDs = new List<Tuple<int, string>>();
            //try
            //{
            //    for (int counter = 0; counter < Lst_Items.Count; counter++)
            //    {
            //        if (responseLst.writeResponse[counter].status.isSuccess)
            //        {

            //            CustomRecordRef rf = (CustomRecordRef)responseLst.writeResponse[counter].baseRef;
            //            Lst_Items[counter].Netsuite_Id = Convert.ToInt32(rf.internalId.ToString());
            //            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<Categories> objDAO = new GenericeDAO<Categories>();
            //objDAO.UpdateNetsuiteIDs(iDs, "Categories");
        }
コード例 #16
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);
            }
        }
        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);
        }
コード例 #18
0
        public override Int64 Set(string parametersArr)
        {
            List <Foodics.NetSuite.Shared.Model.PaymentMethodEntity> lstitemsAll = new CustomDAO().SelectCustomerPayment(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.PaymentMethodEntity> invoiceMethodLst = lstitemsAll.GetRange(Index, lstend);
                    try
                    {
                        if (invoiceMethodLst.Count > 0)
                        {
                            List <Record> cps      = new List <Record>();
                            bool          is_valid = false;
                            try
                            {
                                for (int f = 0; f < invoiceMethodLst.Count; f++)
                                {
                                    PaymentMethodEntity payobj = invoiceMethodLst[f];
                                    Foodics.NetSuite.Shared.Model.Invoice invoiceobj = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>().GetWhere(" Foodics_Id = '" + payobj.Foodics_Id + "'").FirstOrDefault();
                                    Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + invoiceobj.Subsidiary_Id).FirstOrDefault();
                                    #region Accept Payment
                                    CustomerPaymentApplyList    AplyList    = new CustomerPaymentApplyList();
                                    CustomerPaymentCreditList   CreditList  = new CustomerPaymentCreditList();
                                    CustomerPaymentDepositList  DepositList = new CustomerPaymentDepositList();
                                    List <CustomerPaymentApply> payApplylst = new List <CustomerPaymentApply>();
                                    CustomerPaymentApply        payApply;
                                    CustomerPayment             cp = new CustomerPayment();
                                    cp.autoApply = false;
                                    is_valid     = false;
                                    #region Payment Properties
                                    //customer
                                    RecordRef customer = new RecordRef();
                                    customer.internalId = invoiceobj.Customer_Netsuite_Id > 0 ? invoiceobj.Customer_Netsuite_Id.ToString() : objSetting.Customer_Netsuite_Id.ToString();
                                    customer.type       = RecordType.customer;
                                    cp.customer         = customer;

                                    //currency
                                    RecordRef currency = new RecordRef();
                                    currency.internalId = objSetting.Currency_Netsuite_Id.ToString();//payobj.Currency_Id.ToString();
                                    currency.type       = RecordType.currency;
                                    cp.currency         = currency;
                                    StringCustomFieldRef FoodicsRef, FoodicsNumb;

                                    // memo
                                    cp.memo = payobj.Notes;

                                    //tranDate
                                    cp.tranDate          = TimeZoneInfo.ConvertTimeToUtc(payobj.Business_Date, TimeZoneInfo.Local);
                                    cp.tranDateSpecified = true;

                                    //cp.subsidiary
                                    RecordRef subsidiary = new RecordRef();
                                    subsidiary.internalId = objSetting.Subsidiary_Netsuite_Id.ToString(); //payobj.Subsidiary_Id.ToString();
                                    subsidiary.type       = RecordType.subsidiary;
                                    cp.subsidiary         = subsidiary;

                                    //cp.location
                                    RecordRef location = new RecordRef();
                                    location.internalId = invoiceobj.Location_Id.ToString();//objSetting.Location_Netsuite_Id.ToString();//payobj.Location_Id.ToString();
                                    location.type       = RecordType.location;
                                    cp.location         = location;

                                    // payment amount
                                    cp.payment          = payobj.Amount;
                                    cp.paymentSpecified = true;



                                    #region Payment Custom Attributes

                                    DoubleCustomFieldRef payPercent = new DoubleCustomFieldRef();
                                    payPercent.scriptId = "custbody_da_payment_method_percentage";
                                    payPercent.value    = payobj.Payment_Method_Percentage;

                                    DoubleCustomFieldRef PayPercentAmount = new DoubleCustomFieldRef();
                                    PayPercentAmount.scriptId = "custbody_da_payment_method_amount";
                                    PayPercentAmount.value    = (payobj.Payment_Method_Percentage * payobj.Amount) / 100;

                                    LongCustomFieldRef trans_id = new LongCustomFieldRef();
                                    trans_id.scriptId = "custbody_da_transaction_id";
                                    trans_id.value    = invoiceobj.Netsuite_Id;

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

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

                                    CustomFieldRef[] customFieldRefArray = new CustomFieldRef[5];
                                    customFieldRefArray[0] = trans_id;
                                    customFieldRefArray[1] = payPercent;
                                    customFieldRefArray[2] = PayPercentAmount;
                                    customFieldRefArray[3] = FoodicsRef;
                                    customFieldRefArray[4] = FoodicsNumb;

                                    cp.customFieldList = customFieldRefArray;
                                    #endregion

                                    #region Apply Invoice
                                    // Invoice
                                    payApply                 = new CustomerPaymentApply();
                                    payApply.apply           = true;
                                    payApply.docSpecified    = true;
                                    payApply.amountSpecified = true;
                                    payApply.currency        = currency.internalId;
                                    payApply.type            = "Invoice";
                                    payApply.doc             = invoiceobj.Netsuite_Id;
                                    payApply.total           = payobj.Amount;
                                    payApply.amount          = payobj.Amount;
                                    payApply.applyDate       = payobj.Business_Date;

                                    payApplylst.Add(payApply);
                                    #endregion

                                    #region Invoice Custom Attributes



                                    #endregion

                                    // payment method
                                    if (payobj.Payment_Method_Id > 0)
                                    {
                                        is_valid = true;

                                        //payment method
                                        RecordRef payment_method = new RecordRef();
                                        payment_method.internalId = payobj.Payment_Method_Id.ToString();
                                        payment_method.type       = RecordType.customerPayment;
                                        cp.paymentMethod          = payment_method;
                                        cp.authCode = payobj.Ref.Length > 30 ? payobj.Ref.Substring(0, 30) : payobj.Ref;


                                        // amount
                                        cp.payment          = payobj.Amount;
                                        cp.paymentSpecified = true;
                                    }

                                    AplyList.apply = payApplylst.ToArray();
                                    cp.applyList   = AplyList;

                                    #endregion

                                    if (is_valid)
                                    {
                                        cps.Add(cp);
                                    }
                                    #endregion
                                }
                            }
                            catch (Exception ex)
                            {
                                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                            }
                            if (cps.Count > 0)
                            {
                                WriteResponseList wr = Service(true).addList(cps.ToArray());
                                bool result          = wr.status.isSuccess;

                                UpdatedLst(invoiceMethodLst, wr);

                                // return result;
                            }
                        }
                    }
                    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);
            }
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
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;
                     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);
     }
 }
コード例 #23
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);
        }
コード例 #24
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);
        }
コード例 #25
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);
            }
        }
コード例 #26
0
        public override Int64 Set(string parametersArr)
        {
            List <Foodics.NetSuite.Shared.Model.PaymentMethodEntity> lstitemsAll = new CustomDAO().SelectCustomerPayment(5).Take(2000).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.PaymentMethodEntity> returnList = lstitemsAll.GetRange(Index, lstend);
                    try
                    {
                        if (returnList.Count > 0)
                        {
                            CustomerRefund[] memoList = new CustomerRefund[returnList.Count];
                            for (int i = 0; i < returnList.Count; i++)
                            {
                                PaymentMethodEntity     invoiceReturn            = returnList[i];
                                CustomerRefund          memo                     = new CustomerRefund();
                                CustomerRefundApply[]   payApply                 = new CustomerRefundApply[1];
                                CustomerRefundApplyList AplyList                 = new CustomerRefundApplyList();
                                Foodics.NetSuite.Shared.Model.Invoice invoiceobj = new GenericeDAO <Foodics.NetSuite.Shared.Model.Invoice>().GetWhere(" Foodics_Id = '" + invoiceReturn.Foodics_Id + "'").FirstOrDefault();
                                Setting objSetting = new GenericeDAO <Setting>().GetWhere("Subsidiary_Netsuite_Id=" + invoiceobj.Subsidiary_Id).FirstOrDefault();
                                //Customer

                                RecordRef entity = new RecordRef();
                                entity.internalId = invoiceobj.Customer_Netsuite_Id > 0 ? invoiceobj.Customer_Netsuite_Id.ToString() : objSetting.Customer_Netsuite_Id.ToString();
                                entity.type       = RecordType.customer;
                                memo.customer     = 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(invoiceobj.Date, TimeZoneInfo.Local);

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

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

                                //cp.location
                                RecordRef location = new RecordRef();
                                location.internalId = invoiceobj.Location_Id.ToString();
                                location.type       = RecordType.location;
                                memo.location       = location;

                                #region Apply Invoice
                                // Invoice
                                payApply[0]                 = new CustomerRefundApply();
                                payApply[0].apply           = true;
                                payApply[0].docSpecified    = true;
                                payApply[0].amountSpecified = true;
                                payApply[0].currency        = currency.internalId;
                                payApply[0].type            = "CreditMemo";
                                payApply[0].doc             = invoiceobj.Netsuite_Id;
                                payApply[0].total           = invoiceobj.Paid;
                                payApply[0].amount          = invoiceobj.Paid;
                                payApply[0].applyDate       = invoiceobj.Date;

                                AplyList.apply = payApply;
                                memo.applyList = AplyList;
                                #endregion

                                #region payment Method
                                RecordRef payment_method = new RecordRef();
                                payment_method.internalId = invoiceReturn.Payment_Method_Id.ToString();
                                payment_method.type       = RecordType.customerPayment;
                                memo.paymentMethod        = payment_method;
                                #endregion

                                memoList[i] = memo;
                            }


                            if (memoList.Length > 0)
                            {
                                WriteResponseList wr = Service(true).addList(memoList.ToArray());
                                bool result          = wr.status.isSuccess;
                                UpdatedLst(returnList, 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)
        {
            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);
        }