private void btnPost_ItemClick(object sender, ItemClickEventArgs e) { try { if (lines.GetAll().Where(l => l.transCode == TransactionCode).Count() > 0) { int userCode = int.Parse(Thread.CurrentPrincipal.Identity.Name.ToString()); PostedTransactionsManager postLines = new PostedTransactionsManager(); foreach (TransactionLines item in lines.GetAll().Where(l => l.transCode == TransactionCode)) { postLines.AddPostedTransactionDetails(TransactionCode, DateTime.Now, userCode, item.accCode, item.DebitAmount == null ? null : item.DebitAmount, item.CreditAmount == null ? null : item.CreditAmount); postLines.AddPostedTransactionDetails((long)item.transCode, DateTime.Now, userCode, item.offsetAccCode, item.DebitAmount == null ? item.CreditAmount : null, item.CreditAmount == null ? item.DebitAmount : null); } TransactionHeaderManager headerManager = new TransactionHeaderManager(); TransactionHeader header = headerManager.Get(TransactionCode); header.IsPosted = true; headerManager.Update(header); btnAddNew.Enabled = btnDelete.Enabled = btnPost.Enabled = false; panelControl1.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnPost_ItemClick(object sender, ItemClickEventArgs e) { if (HeaderView.FocusedRowHandle >= 0) { PostedTransactionsManager postLines = new PostedTransactionsManager(); if (lines.GetAll().Where(l => l.transCode == TransCode).Count() > 0) { foreach (TransactionLines item in lines.GetAll().Where(l => l.transCode == TransCode)) { postLines.AddPostedTransactionDetails(TransCode, DateTime.Now, UserCode, item.accCode, item.DebitAmount == null ? null : item.DebitAmount, item.CreditAmount == null ? null : item.CreditAmount); postLines.AddPostedTransactionDetails((long)item.transCode, DateTime.Now, UserCode, item.offsetAccCode, item.DebitAmount == null ? item.CreditAmount : null, item.CreditAmount == null ? item.DebitAmount : null); } TransactionHeaderManager headerManager = new TransactionHeaderManager(); TransactionHeader header = headerManager.Get(TransCode); header.IsPosted = true; headerManager.Update(header); btnPost.Enabled = btnDelete.Enabled = false; HeaderView.SetRowCellValue(HeaderView.FocusedRowHandle, HeaderView.Columns[4], true); } } }
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 }