private void EditBillBtn_Click(object sender, EventArgs e) { try { int TestParse = 0; if (int.TryParse(BillNumberTxtBox.Text, out TestParse)) { BillNumberTxtBox.BackColor = BillNumberBGColor; if (BillGeneralMgmt.IsBillExist(int.Parse(BillNumberTxtBox.Text))) { DataTable aDataTableToPass = BillDetailedMgmt.SelectBillByBillNumber(int.Parse(BillNumberTxtBox.Text)); if (aDataTableToPass == null) { throw new Exception("aDataTableToPass==null"); } EditBill aEditBill = new EditBill(); aEditBill.TopMost = true; aEditBill.AddDgView(aDataTableToPass); DataRow aGeneralBillDataRow = BillGeneralMgmt.SelectBillByNumber(int.Parse(BillNumberTxtBox.Text)); if (aGeneralBillDataRow == null) { aEditBill.Close(); throw new Exception("aGeneralBillDataRow==null"); } aEditBill.UpdateVariables(aGeneralBillDataRow); aEditBill.Show(); this.Close(); } else { MessageBox.Show(MsgTxt.BillNumberNotExistTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); BillNumberTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return; } } else { MessageBox.Show(MsgTxt.ErrorPleaseEnterCorrectAmount, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); BillNumberTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return; } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBillBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
private void ListBillsDGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (PrivilegesManager.GetEventStatues(Calcium_RMS.Events.EditBills) == EventStatus.Permit) { if (e.RowIndex < 0) { return; } else { DataTable aDataTableToPass = BillDetailedMgmt.SelectBillByBillNumber(int.Parse(ListBillsDGView.Rows[e.RowIndex].Cells["Number"].Value.ToString())); if (aDataTableToPass != null) { EditBill aEditBill = new EditBill(); // aEditBill.Parent = Helper.Instance.ActiveMainWindow; aEditBill.AddDgView(aDataTableToPass); DataRow aGeneralBillDataRow = BillGeneralMgmt.SelectBillByNumber(int.Parse(ListBillsDGView.Rows[e.RowIndex].Cells["Number"].Value.ToString())); if (aGeneralBillDataRow != null) { aEditBill.UpdateVariables(aGeneralBillDataRow); aEditBill.Dock = DockStyle.Fill; aEditBill.Show(); } } } } else { MessageBox.Show(MsgTxt.PrivUserNotAllowedTxt, MsgTxt.InformationCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListBills:ListBillsDGView_CellDoubleClick()] \n Exception: \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); //throw; } }
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); } }
private void Add1000Sale_Click(object sender, EventArgs e) { int cnt = 1; DateTime date = DateTime.Now; var randAmount = new Random(); int userId = int.Parse(UsersMgmt.SelectAllUsers().Rows[0]["ID"].ToString()); while (cnt++ < NumberOfBills) { try { int numofDetailed = randAmount.Next(1, 20); var aBillGeneral = new BillGeneral(); aBillGeneral.Bill_General_AccountID = 1; aBillGeneral.Bill_General_CashIn = 100; aBillGeneral.Bill_General_Currency = "JOD"; aBillGeneral.Bill_General_CurrencyID = 1; aBillGeneral.Bill_General_CustomerID = 1; aBillGeneral.Bill_General_Date = date.Subtract(TimeSpan.FromDays(randAmount.Next(1, 2000))).ToShortDateString(); aBillGeneral.Bill_General_DiscountPerc = 0; aBillGeneral.Bill_General_IsCashCredit = 0; aBillGeneral.Bill_General_NetAmount = 100; aBillGeneral.Bill_General_Number = BillGeneralMgmt.NextBillNumber(); aBillGeneral.Bill_General_PaymentMethodID = 1; aBillGeneral.Bill_General_PriceLevel = 1; aBillGeneral.Bill_General_SalesDiscount = 0; aBillGeneral.Bill_General_SubTotal = 100; aBillGeneral.Bill_General_TellerID = userId; aBillGeneral.Bill_General_Time = DateTime.Now.ToShortTimeString(); aBillGeneral.Bill_General_TotalCost = randAmount.Next(50, 99); aBillGeneral.Bill_General_TotalDiscount = 0; aBillGeneral.Bill_General_TotalItems = numofDetailed; aBillGeneral.Bill_General_TotalPrice = 100; aBillGeneral.Bill_General_TotalTax = 16; aBillGeneral.CustomerAccountAmountOld = 0; aBillGeneral.Bill_General_Comments = "Test Sale"; aBillGeneral.Bill_General_CreditCardInfo = "NotCredit"; Random aRandom = new Random(); if (BillGeneralMgmt.InsertBill(aBillGeneral)) { while (numofDetailed > 0) { BillDetailed aBillDetailed = new BillDetailed(); string aBarcode = "Test Item " + aRandom.Next(1, (int)NumberOfItems); DataTable aItemRow = ItemsMgmt.SelectItemByBarCode(aBarcode); if (aItemRow.Rows.Count != 0) { aBillDetailed.Bill_Detailed_ItemDescription = aItemRow.Rows[0]["Description"].ToString(); aBillDetailed.Bill_Detailed_ItemID = int.Parse(aItemRow.Rows[0]["ID"].ToString()); aBillDetailed.Bill_Detailed_Number = aBillGeneral.Bill_General_Number; aBillDetailed.Bill_Detailed_OldAvaQty = double.Parse(aItemRow.Rows[0]["Qty"].ToString()); aBillDetailed.Bill_Detailed_OldAvgUnitCost = double.Parse(aItemRow.Rows[0]["AvgUnitCost"].ToString()); aBillDetailed.Bill_Detailed_Qty = numofDetailed; aBillDetailed.Bill_Detailed_SellPrice = double.Parse(aItemRow.Rows[0]["SellPrice"].ToString()); aBillDetailed.Bill_Detailed_TotalPerUnit = aBillDetailed.Bill_Detailed_Qty * aBillDetailed.Bill_Detailed_SellPrice; BillDetailedMgmt.InsertItem(aBillDetailed); } numofDetailed--; } } if (cnt % 100 == 0) { label1.Text = $"Adding Bill {cnt}/{NumberOfBills} ... ({(cnt / NumberOfBills) * 100 })%"; Application.DoEvents(); } } catch (Exception ex) { MessageBox.Show($"Error in {cnt} \n {ex}"); } } }
private void ReviseBillBtn_Click(object sender, EventArgs e) { try { if (aBillGeneralRow["IsRevised"].ToString() == "0") { if (CashMethodComboBox.SelectedIndex == 1)//iscredit { int CustomerID = CustomerMgmt.SelectCustomerIDByPhone1(PhoneTxtBox.Text); DataRow aCustomerAccount = CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(CustomerID); double OldAmount = double.Parse(aCustomerAccount["Amount"].ToString()); double NewAmount = OldAmount - double.Parse(TotalTxtBox.Text); int AccountID = int.Parse(aCustomerAccount["ID"].ToString()); CustomersAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount); } else {//int.Parse(AccountComboBox.SelectedValue.ToString()); int AccountID = int.Parse(aBillGeneralRow["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(aBillGeneralRow["PaymentMethodID"].ToString())); if (aMethodRow["IsCheck"].ToString() == "1") { ChecksMgmt.MakeCheckRevised(int.Parse(aBillGeneralRow["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 OldAvgUnitCost = BillDetailedMgmt.SelectOldAvgUnitCostByID(ItemID, int.Parse(aBillGeneralRow["Number"].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; if ((ReturnQty + CurrentAvaQty) != 0) //to avoid division by zero { NewAvgUnitCost = ((CurrentAvgUnitCost * CurrentAvaQty) + (ReturnQty * OldAvgUnitCost)) / (ReturnQty + CurrentAvaQty); } CostLoss += (NewAvgUnitCost - OldAvgUnitCost) * BillDetailedMgmt.SelectAllItemsSoldAfterBillNumber(ItemID, int.Parse(aBillGeneralRow["Number"].ToString())); ItemsMgmt.UpdateItemQtyandAvgUnitCostByID(ItemID, (ReturnQty + CurrentAvaQty), NewAvgUnitCost); BillDetailedMgmt.MakeItemAsRevised(int.Parse(aBillGeneralRow["Number"].ToString()), ItemID); } } //Now we should mark the bill general as reversed if (!BillGeneralMgmt.UpdateBillToRevised(SharedFunctions.ReturnLoggedUserName(), DateTime.Now.ToShortDateString(), int.Parse(aBillGeneralRow["Number"].ToString()), CostLoss)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditBill-ReviseBillBtn_Click] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } 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 [EditBill-ReviseBillBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); throw; } }