private void LinesView_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) { try { #region Get Full Accounts Code : string fullAccount = Account.EditValue.ToString(); string fullOffsetAccount = OffsetAccount.EditValue.ToString(); fullAccount = GetFullAccountCode(AccountDeminsions, fullAccount); fullOffsetAccount = GetFullAccountCode(OffsetDeminsions, fullOffsetAccount); if (cmbAccountType.Text == AccountsManager.AccountFilterationTypes.Customer.ToString()) { fullAccount = "1-" + fullAccount; } else if (cmbAccountType.Text == AccountsManager.AccountFilterationTypes.Vendor.ToString()) { fullAccount = "2-" + fullAccount; } if (cmbOffsetType.Text == AccountsManager.AccountFilterationTypes.Customer.ToString()) { fullOffsetAccount = "1-" + fullOffsetAccount; } else if (cmbOffsetType.Text == AccountsManager.AccountFilterationTypes.Vendor.ToString()) { fullOffsetAccount = "2-" + fullOffsetAccount; } #endregion #region Add Line To DataBase : long linecode = lines.AddTransactionLineDetails(TransactionCode, deLineDate.DateTime.Date, cmbAccountType.Text, fullAccount, spDebitAmount.Value == 0 ? null : (decimal?)spDebitAmount.Value, spCreditAmount.Value == 0 ? null : (decimal?)spCreditAmount.Value, txtDescription.Text, cmbOffsetType.Text, fullOffsetAccount); #endregion #region Add Line To GridView : GridView view = sender as GridView; view.SetRowCellValue(e.RowHandle, view.Columns[0], linecode); view.SetRowCellValue(e.RowHandle, view.Columns[1], TransactionCode); view.SetRowCellValue(e.RowHandle, view.Columns[2], deLineDate.DateTime.Date); view.SetRowCellValue(e.RowHandle, view.Columns[3], cmbAccountType.Text); view.SetRowCellValue(e.RowHandle, view.Columns[4], fullAccount); view.SetRowCellValue(e.RowHandle, view.Columns[5], spDebitAmount.Value == 0 ? null : (decimal?)spDebitAmount.Value); view.SetRowCellValue(e.RowHandle, view.Columns[6], spCreditAmount.Value == 0 ? null : (decimal?)spCreditAmount.Value); view.SetRowCellValue(e.RowHandle, view.Columns[7], txtDescription.Text); view.SetRowCellValue(e.RowHandle, view.Columns[8], cmbOffsetType.Text); view.SetRowCellValue(e.RowHandle, view.Columns[9], fullOffsetAccount); #endregion btnCancel_Click(null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void PostTransactions(int CustomerCode, DateTime Date, int UserCode, DataGridViewRow[] ProductsCollection, decimal SalesTotal, decimal SalesPaied) { TransactionHeaderManager header = new TransactionHeaderManager(); TransactionLineManager lines = new TransactionLineManager(); PostedTransactionsManager posted = new PostedTransactionsManager(); string IssueAccount, ConsumptionAccount, RevenueAccount, SalesDiscountAccount, CustomerAccount, CashAccount; CustomerPostingManager.GetCustomerPostingAccountsCode(CustomerCode, out CustomerAccount, out CashAccount); long TransactionCode = long.Parse(header.GetCode().ToString()); #region Add Transaction Header Details : header.AddHeaderDetails(TransactionCode, 3, Date, "فاتورة مبيعات", UserCode, true); #endregion for (int i = 0; i < ProductsCollection.Length; i++) { #region Variables : int PCode = int.Parse(ProductsCollection[i].Cells[0].Value.ToString()); int UCode = int.Parse(ProductsCollection[i].Cells[2].Value.ToString()); decimal UPrice = decimal.Parse(ProductsCollection[i].Cells[4].Value.ToString()); decimal PQty = decimal.Parse(ProductsCollection[i].Cells[5].Value.ToString()); decimal PQTotal = decimal.Parse(ProductsCollection[i].Cells[6].Value.ToString()); decimal AvgProductConsumption = (decimal)(OnHandProductManager.GetAvgCost(PCode) * PQty); #endregion ProductPostingManager.GetSalesPostingAccountsCode(PCode, out IssueAccount, out ConsumptionAccount, out RevenueAccount, out SalesDiscountAccount); #region Add Transaction Details : #region If Invoice is Cash Or Accrual : #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), CustomerAccount + "-1-" + CustomerCode, PQTotal, null, "من العميل للايرادات", AccountsManager.AccountFilterationTypes.Ledger.ToString(), RevenueAccount); lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), ConsumptionAccount, AvgProductConsumption, null, "من الاستهلاك للمخزون", AccountsManager.AccountFilterationTypes.Ledger.ToString(), IssueAccount); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CustomerAccount + "-1-" + CustomerCode, PQTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, RevenueAccount, null, PQTotal); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, ConsumptionAccount, AvgProductConsumption, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, IssueAccount, null, AvgProductConsumption); #endregion #endregion #endregion } #region If Invoice is Cash : if (radPaymentSystem.SelectedIndex == 0) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount, SalesTotal, null, "العميل سدد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), CustomerAccount + "-1-" + CustomerCode); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, SalesTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CustomerAccount + "-1-" + CustomerCode, null, SalesTotal); #endregion } #endregion #region If Invoice is Accrual : else if (radPaymentSystem.SelectedIndex == 1 && SalesPaied > 0) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount, SalesPaied, null, "العميل سدد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), CustomerAccount + "-1-" + CustomerCode); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, SalesPaied, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CustomerAccount + "-1-" + CustomerCode, null, SalesPaied); #endregion } #endregion }
private void btnSave_Click(object sender, EventArgs e) { try { /* * RadInvoiceType ==0 ---> مشتريات (false) * RadInvoiceType ==1 ---> مرتجع مشتريات (true) * RadPaymentSystem ==0 --->كاش (false) * RadPaymentSystem ==1 --->أجل (false) */ if (dgvProducts.Rows.Count <= 0) { return; } #region Variables : DateTime Date = DateTime.Now; int UserCode = int.Parse(Thread.CurrentPrincipal.Identity.Name); int WHCode = int.Parse(cmbWareHouse.SelectedValue.ToString()); int VendorCode = int.Parse(cmbVendor.SelectedValue.ToString()); decimal PurchaseTotal = decimal.Parse(txtInvoiceTotal.Text); decimal PurchasePaied = decimal.Parse(spInvoicePaied.Text); decimal PurchaseReminder = decimal.Parse(txtInvoiceReminder.Text); long TransactionCode = long.Parse(header.GetCode().ToString()); #endregion #region Add Invoice Header : purchase.AddInvoiceHeader(txtInvoiceCode.Text, Date, PurchaseTotal, PurchasePaied, PurchaseReminder, radInvoiceType.SelectedIndex == 0 ? false : true, WHCode, VendorCode, radPaymentSystem.SelectedIndex == 0 ? false : true, UserCode); #endregion string ProductRecieptAccount, VendorAccount, CashAccount, PurchaseDiscountAccount; VendorPostingManager.GetVendorPostingAccountsCode(VendorCode, out VendorAccount, out CashAccount); #region Add Transaction Header Details : header.AddHeaderDetails(TransactionCode, radInvoiceType.SelectedIndex == 0 ? 1 : 2, Date, radInvoiceType.SelectedIndex == 0 ? "فاتورة مشتريات" : "مرتجع مشتريات", UserCode, true); #endregion for (int i = 0; i < dgvProducts.Rows.Count; i++) { #region Variables : int PCode = int.Parse(dgvProducts.Rows[i].Cells[ProductCode.Name].Value.ToString()); int UCode = int.Parse(dgvProducts.Rows[i].Cells[UnitCode.Name].Value.ToString()); decimal UPrice = decimal.Parse(dgvProducts.Rows[i].Cells[Price.Name].Value.ToString()); decimal PQty = decimal.Parse(dgvProducts.Rows[i].Cells[Qty.Name].Value.ToString()); decimal PQTotal = decimal.Parse(dgvProducts.Rows[i].Cells[Total.Name].Value.ToString()); #endregion #region Add Purchase Details : purchase.AddInvoiceDetails(txtInvoiceCode.Text, PCode, UCode, (double)UPrice, PQty, PQTotal); #endregion #region Add OnHandProduct Details : new OnHandProductManager().AddOnHandDetails(PCode, WHCode, PQty, UCode, UPrice, radInvoiceType.SelectedIndex == 0 ? false : true, true); #endregion ProductPostingManager.GetPurchasePostingAccountsCode(PCode, out ProductRecieptAccount, out PurchaseDiscountAccount); #region Add Transaction Details : #region If Invoice is Cash Or Accrual : #region Add Transaction Line Details : if (radInvoiceType.SelectedIndex == 0) { lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), ProductRecieptAccount, PQTotal, null, "قيد مشتريات", AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode); } else if (radInvoiceType.SelectedIndex == 1) { lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode, PQTotal, null, "قيد مرتجع مشتريات", AccountsManager.AccountFilterationTypes.Ledger.ToString(), ProductRecieptAccount); } #endregion #region Add Posted Lines Details : if (radInvoiceType.SelectedIndex == 0) { posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, ProductRecieptAccount, PQTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, null, PQTotal); } else if (radInvoiceType.SelectedIndex == 1) { posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, PQTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, ProductRecieptAccount, null, PQTotal); } #endregion #endregion #endregion } #region If Invoice is Cash : if (radPaymentSystem.SelectedIndex == 0) { if (radInvoiceType.SelectedIndex == 0) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode, PurchaseTotal, null, "سداد المورد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, PurchaseTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, null, PurchaseTotal); #endregion } else if (radInvoiceType.SelectedIndex == 1) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount, PurchaseTotal, null, "سداد المورد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, PurchaseTotal, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, null, PurchaseTotal); #endregion } } #endregion #region If Invoice is Accrual : else if (radPaymentSystem.SelectedIndex == 1 && PurchasePaied > 0) { if (radInvoiceType.SelectedIndex == 0) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode, PurchasePaied, null, "سداد المورد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, PurchasePaied, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, null, PurchasePaied); #endregion } else if (radInvoiceType.SelectedIndex == 0) { #region Add Transaction Line Details : lines.AddTransactionLineDetails(TransactionCode, Date, AccountsManager.AccountFilterationTypes.Ledger.ToString(), CashAccount, PurchasePaied, null, "سداد المورد", AccountsManager.AccountFilterationTypes.Ledger.ToString(), VendorAccount + "-2-" + VendorCode); #endregion #region Add Posted Lines Details : posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, CashAccount, PurchasePaied, null); posted.AddPostedTransactionDetails(TransactionCode, Date, UserCode, VendorAccount + "-2-" + VendorCode, null, PurchasePaied); #endregion } } #endregion MessageBox.Show("Success"); btnAddNew.Enabled = true; btnSave.Enabled = false; btnPrint.Enabled = true; btnAddNew_Click(null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }