Exemplo n.º 1
0
        private void DebitDGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (PrivilegesManager.GetEventStatues(Calcium_RMS.Events.EditVouchers) == EventStatus.Permit)
            {
                if (e.RowIndex < 0)
                {
                    return;
                }
                DataTable   aDataTableToPass = PurchaseVoucherDetailedMgmt.SelectVoucherByVoucherNumber(int.Parse(DebitDGView.Rows[e.RowIndex].Cells["VoucherNumber"].Value.ToString()));
                EditVoucher aEditVoucher     = new EditVoucher();
                aEditVoucher.AddDGView(aDataTableToPass);

                DataRow aGeneralVoucherDataRow = PurchaseVoucherGeneralMgmt.SelectGeneralVoucherByNumber(int.Parse(DebitDGView.Rows[e.RowIndex].Cells["VoucherNumber"].Value.ToString()));
                aEditVoucher.UpdateVariables(aGeneralVoucherDataRow);
                // aEditVoucher.MdiParent = Helper.Instance.ActiveMainWindow;
                aEditVoucher.Show();
            }
            else
            {
                MessageBox.Show(MsgTxt.PrivUserNotAllowedTxt, MsgTxt.InformationCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        private void ListVouchersDGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (PrivilegesManager.GetEventStatues(Calcium_RMS.Events.EditVouchers) == EventStatus.Permit)
            {
                if (e.RowIndex < 0)
                {
                    return;
                }

                DataTable aDataTableToPass = PurchaseVoucherDetailedMgmt.SelectVoucherByVoucherNumber(int.Parse(ListVouchersDGView.Rows[e.RowIndex].Cells["VoucherNumber"].Value.ToString()));
                if (aDataTableToPass == null)
                {
                    MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListVouchersDGView_CellDoubleClick:DB-ERROR  aDataTableToPass=null] \n  \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                DataRow aGeneralVoucherDataRow = PurchaseVoucherGeneralMgmt.SelectGeneralVoucherByNumber(int.Parse(ListVouchersDGView.Rows[e.RowIndex].Cells["VoucherNumber"].Value.ToString()));
                if (aDataTableToPass == null)
                {
                    MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListVouchersDGView_CellDoubleClick:DB-ERROR  aDataTableToPass=null] \n  \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                EditVoucher aEditVoucher = new EditVoucher();
                aEditVoucher.AddDGView(aDataTableToPass);
                aEditVoucher.UpdateVariables(aGeneralVoucherDataRow);
                //aEditVoucher.TopLevel = true;
                aEditVoucher.TopMost = true;
                aEditVoucher.Show();
            }
            else
            {
                MessageBox.Show(MsgTxt.PrivUserNotAllowedTxt, MsgTxt.InformationCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 3
0
        public static bool ItemStatusReport(int ItemID, string DateFrom, string DateTo, bool TableBorder = false, bool Preview = true, bool PrintToThermal = false, bool ExportToPdf = false, bool ExportToExcel = false, string ExportPath = "", bool colored = false)
        {
            if (!ItemsMgmt.IsItemExistByID(ItemID))
            {
                return(false);
            }
            string           EmptyNoborderRow = ReportsHelper.MANUAL_TD_OPTION_START + ReportsHelper.NOBORDER + ReportsHelper.MANUAL_TD_OPTION_END + ReportsHelper.MANUAL_TD_END;
            List <DataTable> aDTlist          = new List <DataTable>();
            DataTable        aTable1          = new DataTable();

            if (TableBorder)
            {
                aTable1.Columns.Add("[Border=true1]" + "Barcode");
            }
            else
            {
                aTable1.Columns.Add("Barcode");
            }
            aTable1.Columns.Add("Description");
            aTable1.Columns.Add("Type");
            aTable1.Columns.Add("Qty");

            DataRow aItemRow = ItemsMgmt.SelectItemRowByID(ItemID);
            bool    AddEmpty = false;
            double  NetTotal = 0.00;
            DataRow __PoorRow;

            double OnHandQty             = double.Parse(aItemRow["OnHandQty"].ToString());
            double TotalBeforeBills      = BillDetailedMgmt.SelectAllSoldQty(ItemID, DateFrom, DateTo, 0, true);
            double TotalBeforeAdjust     = AdjustInventoryDetailedMgmt.SelectAllAdjustQty(ItemID, DateFrom, DateTo, -1, true);
            double TotalBeforeDispose    = DisposalDetailedMgmt.SelectAllDisposedQty(ItemID, DateFrom, DateTo, 0, true);
            double TotalBeforePurchase   = PurchaseVoucherDetailedMgmt.SelectAllPurchaseQty(ItemID, DateFrom, DateTo, 0, true);
            double TotalBeforeCusRet     = ReturnItemsCustDetailedMGMT.SelectAllReturnedQty(ItemID, DateFrom, DateTo, 0, true);
            double TotalBeforeVenReturns = ReturnItemsVendorDetailedMgmt.SelectAllReturnedQty(ItemID, DateFrom, DateTo, 0, true);

            double BegginingQty = OnHandQty - TotalBeforeBills + TotalBeforeAdjust - TotalBeforeDispose + TotalBeforePurchase + TotalBeforeCusRet - TotalBeforeVenReturns;

            if (BegginingQty != 0)
            {
                NetTotal    += BegginingQty;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Beginning Qty";
                __PoorRow[3] = Math.Round(BegginingQty, 3);
                AddEmpty     = true;
            }

            double TotalBills         = BillDetailedMgmt.SelectAllSoldQty(ItemID, DateFrom, DateTo, -1);
            double TotalReversedBills = BillDetailedMgmt.SelectAllSoldQty(ItemID, DateFrom, DateTo, 1);

            if (TotalBills != 0)
            {
                NetTotal    -= TotalBills;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Sales";
                __PoorRow[3] = Math.Round(0.00 - TotalBills, 3);
                AddEmpty     = true;
            }
            if (TotalReversedBills != 0)
            {
                NetTotal    += TotalReversedBills;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Reversed Sales";
                __PoorRow[3] = Math.Round((TotalReversedBills), 3);
                AddEmpty     = true;
            }

            double TotalAdjust = AdjustInventoryDetailedMgmt.SelectAllAdjustQty(ItemID, DateFrom, DateTo, -1);

            if (TotalAdjust != 0)
            {
                NetTotal    += TotalAdjust;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Inventory Adjust";
                __PoorRow[3] = Math.Round(TotalAdjust, 3);
                AddEmpty     = true;
            }
            double TotalDisposed         = DisposalDetailedMgmt.SelectAllDisposedQty(ItemID, DateFrom, DateTo, -1);
            double TotalReversedDisposed = DisposalDetailedMgmt.SelectAllDisposedQty(ItemID, DateFrom, DateTo, 1);

            if (TotalDisposed != 0)
            {
                NetTotal    -= TotalDisposed;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Disposed";
                __PoorRow[3] = Math.Round(0.00 - TotalDisposed, 3);
                AddEmpty     = true;
            }
            if (TotalReversedDisposed != 0)
            {
                NetTotal    += TotalReversedDisposed;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Reversed Disposals";
                __PoorRow[3] = Math.Round((0.00 - TotalReversedDisposed), 3);
                AddEmpty     = true;
            }
            double TotalPurchase         = PurchaseVoucherDetailedMgmt.SelectAllPurchaseQty(ItemID, DateFrom, DateTo, -1);
            double TotalReversedPurchase = PurchaseVoucherDetailedMgmt.SelectAllPurchaseQty(ItemID, DateFrom, DateTo, 1);

            if (TotalPurchase != 0)
            {
                NetTotal    += TotalPurchase;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Purchase";
                __PoorRow[3] = Math.Round((TotalPurchase), 3);
                AddEmpty     = true;
            }
            if (TotalReversedPurchase != 0)
            {
                NetTotal    -= TotalReversedPurchase;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Reversed Purchase";
                __PoorRow[3] = Math.Round((0.00 - TotalReversedPurchase), 3);
                AddEmpty     = true;
            }
            double TotalCustomerReturns         = ReturnItemsCustDetailedMGMT.SelectAllReturnedQty(ItemID, DateFrom, DateTo, -1);
            double TotalReversedCustomerReturns = ReturnItemsCustDetailedMGMT.SelectAllReturnedQty(ItemID, DateFrom, DateTo, 1);

            if (TotalCustomerReturns != 0)
            {
                NetTotal    += TotalCustomerReturns;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Customer Returns";
                __PoorRow[3] = Math.Round((TotalCustomerReturns), 3);
                AddEmpty     = true;
            }
            if (TotalReversedCustomerReturns != 0)
            {
                NetTotal    -= TotalReversedCustomerReturns;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Reversed Customer Returns";
                __PoorRow[3] = Math.Round((0.00 - TotalReversedCustomerReturns), 3);
                AddEmpty     = true;
            }
            double TotalVendorReturns         = ReturnItemsVendorDetailedMgmt.SelectAllReturnedQty(ItemID, DateFrom, DateTo, -1);
            double TotalReversedVendorReturns = ReturnItemsVendorDetailedMgmt.SelectAllReturnedQty(ItemID, DateFrom, DateTo, 1);

            if (TotalVendorReturns != 0)
            {
                NetTotal    -= TotalVendorReturns;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Vendors Returns";
                __PoorRow[3] = Math.Round((0.00 - TotalVendorReturns), 3);
                AddEmpty     = true;
            }
            if (TotalReversedVendorReturns != 0)
            {
                NetTotal    += TotalReversedVendorReturns;
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = "Total Reversed Vendors Returns";
                __PoorRow[3] = Math.Round((TotalReversedVendorReturns), 3);
                AddEmpty     = true;
            }

            if (NetTotal != 0)
            {
                __PoorRow    = aTable1.Rows.Add();
                __PoorRow[0] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Barcode"].ToString();
                __PoorRow[1] = (AddEmpty) ? EmptyNoborderRow : aItemRow["Description"].ToString();
                __PoorRow[2] = ReportsHelper.MANUAL_TD_OPTION_START + ReportsHelper.UNDERLINE + ReportsHelper.MANUAL_TD_OPTION_END + "TOTAL" + ReportsHelper.MANUAL_TD_END;
                __PoorRow[3] = ReportsHelper.MANUAL_TD_OPTION_START + ReportsHelper.UNDERLINE + ReportsHelper.MANUAL_TD_OPTION_END + Math.Round((NetTotal), 3) + ReportsHelper.MANUAL_TD_END;
                AddEmpty     = true;
            }
            aDTlist.Add(aTable1);

            List <string> aHeaderList = ReportsHelper.ImportReportHeader(0, 1);
            List <string> aFooterList = ReportsHelper.ImportReportHeader(1, 1);

            aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black);
            aHeaderList.Add("<b><font size=4>" + Text.ReportsNames.ItemSymmaryStatusRepName + " </font>");
            aHeaderList.Add("<b><font size=4>" + Text.ReportsText.DateRepTxt + ": " + DateTime.Now.ToShortDateString() + " </font>");
            aHeaderList.Add("<b><font size=4>" + Text.ReportsText.FromRepTxt + ": " + DateFrom + " " + Text.ReportsText.ToRepTxt + ": " + DateTo + " </font>");
            aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black);

            if (Preview)
            {
                PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", false, "", colored);
                return(true);
            }

            else if (ExportToPdf)
            {
                PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, true, ExportPath, false, "", colored);
                return(true);
            }
            else if (ExportToExcel)
            {
                PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", true, ExportPath, colored);
                return(true);
            }
            else if (PrintToThermal)
            {
                PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, true, true, false, "", false, "", colored);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
 private void ReviseBillBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (aPurchaseDataRow["IsRevised"].ToString() == "0")
         {
             if (CashMethodComboBox.SelectedIndex == 1)//iscredit
             {
                 int     VendorID       = VendorsMgmt.SelectVendorIDByName(VendorsComboBox.Text);
                 DataRow aVendorAccount = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(VendorID);
                 double  OldAmount      = double.Parse(aVendorAccount["Amount"].ToString());
                 double  NewAmount      = OldAmount - double.Parse(TotalTxtBox.Text);
                 int     AccountID      = int.Parse(aVendorAccount["ID"].ToString());
                 VendorsAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount);
             }
             else
             {
                 int     AccountID   = int.Parse(aPurchaseDataRow["AccountID"].ToString());
                 DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(AccountID);
                 double  OldAmount   = double.Parse(aAccountRow["Amount"].ToString());
                 double  NewAmount   = OldAmount + double.Parse(TotalTxtBox.Text);;
                 AccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount);
             }
             //Mark the check (if any) as revised
             DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aPurchaseDataRow["PaymentMethodID"].ToString()));
             if (aMethodRow["IsCheck"].ToString() == "1")
             {
                 ChecksMgmt.MakeCheckRevised(int.Parse(aPurchaseDataRow["CheckNumber"].ToString()), DateTime.Now.ToShortDateString());
             }
             //Now Update AvgUnitCost
             double CostLoss = 0;
             foreach (DataGridViewRow r in TeldgView.Rows)
             {
                 if (!r.IsNewRow)
                 {
                     int    ItemID             = ItemsMgmt.SelectItemIDByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString());
                     double ItemCost           = PurchaseVoucherDetailedMgmt.SelectItemCostByNumber(ItemID, int.Parse(aPurchaseDataRow["VoucherNumber"].ToString()));
                     double ReturnQty          = double.Parse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString());
                     double CurrentAvgUnitCost = ItemsMgmt.SelectItemCostByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString());
                     double CurrentAvaQty      = ItemsMgmt.SelectItemQtyByID(ItemID);
                     double NewAvgUnitCost     = ((CurrentAvgUnitCost * CurrentAvaQty) + (ReturnQty * ItemCost)) / (ReturnQty + CurrentAvaQty);
                     ItemsMgmt.UpdateItemQtyandAvgUnitCostByID(ItemID, (ReturnQty + CurrentAvaQty), NewAvgUnitCost);
                     PurchaseVoucherDetailedMgmt.MakeItemAsRevised(int.Parse(aPurchaseDataRow["VoucherNumber"].ToString()), ItemID);
                 }
             }
             //Now we should mark the bill general as reversed
             if (!PurchaseVoucherGeneralMgmt.UpdateVoucherToRevised(TellerUserNameLbl.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), int.Parse(aPurchaseDataRow["VoucherNumber"].ToString()), CostLoss))
             {
                 MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditBill-ReviseBillBtn_Click] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 this.Close();
             }
             else
             {
                 MessageBox.Show(MsgTxt.ReversedSuccessfullyTxt, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
             }
         }
         else
         {
             MessageBox.Show(MsgTxt.AlreadyReversedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditVoucher-ReviseBillBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
         throw;
     }
 }
Exemplo n.º 5
0
        private void Add1000PurchaseVoucherBtn_Click(object sender, EventArgs e)
        {
            Random randAmount = new Random();
            int    cnt        = 1;
            var    Vendors    = VendorsMgmt.SelectAllVendors();
            int    userId     = int.Parse(UsersMgmt.SelectAllUsers().Rows[0]["ID"].ToString());

            while (cnt++ < NumberOfPurchases)
            {
                try
                {
                    PurchaseVoucherGeneral aPurchaseGeneral = new PurchaseVoucherGeneral();
                    aPurchaseGeneral.AccountID              = 1;
                    aPurchaseGeneral.Comments               = "";
                    aPurchaseGeneral.CurrencyID             = 1;
                    aPurchaseGeneral.Date                   = DateTime.Now.Subtract(TimeSpan.FromDays(randAmount.Next(1, 2000))).ToShortDateString();
                    aPurchaseGeneral.DiscountPerc           = 0;
                    aPurchaseGeneral.Fees                   = 10;
                    aPurchaseGeneral.IsCashCredit           = 0;
                    aPurchaseGeneral.IsChecked              = 0;
                    aPurchaseGeneral.IsRevised              = 0;
                    aPurchaseGeneral.PaymentMethodID        = 1;
                    aPurchaseGeneral.Subtotal               = 100;
                    aPurchaseGeneral.TellerID               = userId;
                    aPurchaseGeneral.Time                   = DateTime.Now.ToShortTimeString();
                    aPurchaseGeneral.TotalCost              = 90;
                    aPurchaseGeneral.TotalDiscount          = 0;
                    aPurchaseGeneral.TotalFreeItemsQty      = 0;
                    aPurchaseGeneral.TotalItemsDiscount     = 0;
                    aPurchaseGeneral.TotalTax               = 10;
                    aPurchaseGeneral.VendorAccountAmountOld = 0;
                    aPurchaseGeneral.VendorID               =
                        int.Parse(Vendors.Rows[(int)NumberOfPurchases % Vendors.Rows.Count]["ID"].ToString());
                    aPurchaseGeneral.VoucherNumber  = PurchaseVoucherGeneralMgmt.NextVoucherNumber();
                    aPurchaseGeneral.CreditCardInfo = "";


                    int NumofDetailed = randAmount.Next(1, 20);
                    if (PurchaseVoucherGeneralMgmt.AddVoucher(aPurchaseGeneral))
                    {
                        while (NumofDetailed > 0)
                        {
                            PurchaseVoucherDetailed aPurchaseDetailed = new PurchaseVoucherDetailed();
                            string    aBarcode = "Test Item " + randAmount.Next(1, (int)NumberOfItems).ToString();
                            DataTable aItemRow = ItemsMgmt.SelectItemByBarCode(aBarcode);
                            if (aItemRow.Rows.Count != 0)
                            {
                                aPurchaseDetailed.Purchase_Voucher_Detailed_ItemID =
                                    int.Parse(aItemRow.Rows[0]["ID"].ToString());
                                aPurchaseDetailed.Purchase_Voucher_Detailed_VoucherNumber =
                                    aPurchaseGeneral.VoucherNumber;
                                aPurchaseDetailed.Purchase_Voucher_Detailed_IsRevised = 0;
                                aPurchaseDetailed.Purchase_Voucher_Detailed_ItemCost  =
                                    double.Parse(aItemRow.Rows[0]["AvgUnitCost"].ToString());
                                aPurchaseDetailed.Purchase_Voucher_Detailed_OldAvaQty =
                                    double.Parse(aItemRow.Rows[0]["Qty"].ToString());
                                aPurchaseDetailed.Purchase_Voucher_Detailed_Qty      = NumofDetailed;
                                aPurchaseDetailed.Purchase_Voucher_Detailed_Discount = 0;
                                // = double.Parse(aItemRow.Rows[0]["SellPrice"].ToString());
                                aPurchaseDetailed.Purchase_Voucher_Detailed_FreeItemsQty = 0;
                                // aBillDetailed.Bill_Detailed_TotalPerUnit = aBillDetailed.Bill_Detailed_Qty * aBillDetailed.Bill_Detailed_SellPrice;
                                PurchaseVoucherDetailedMgmt.AddItem(aPurchaseDetailed);
                            }
                            NumofDetailed--;
                        }
                    }
                    if (cnt % 100 == 0)
                    {
                        label1.Text = $"Adding Purchase Order {cnt}/{NumberOfPurchases} ... ({(cnt / NumberOfPurchases) * 100 })%";
                        Application.DoEvents();
                    }
                }
                catch (Exception ex) { MessageBox.Show($"Error in {cnt} \n {ex}"); }
            }
        }