コード例 #1
0
 /// <summary>
 /// Ledger posting edit function
 /// </summary>
 public void ledgerPostingEdit()
 {
     LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
     ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
     decimal decRate = 0;
     decimal decimalGrantTotal = 0;
     decimal decTotalAmount = 0;
     try
     {
         decimalGrantTotal = Convert.ToDecimal(txtGrandTotal.Text.Trim());
         decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         decimalGrantTotal = decimalGrantTotal * decRate;
         infoLedgerPosting.Debit = decimalGrantTotal;
         infoLedgerPosting.Credit = 0;
         infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
         infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         infoLedgerPosting.VoucherNo = strVoucherNo;
         infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
         infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
         decTotalAmount = TotalNetAmountForLedgerPosting();
         decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         decTotalAmount = decTotalAmount * decRate;
         infoLedgerPosting.Debit = 0;
         infoLedgerPosting.Credit = decTotalAmount;
         infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
         infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         infoLedgerPosting.VoucherNo = strVoucherNo;
         infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
         infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString());
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
         decimal decBillDis = 0;
         decBillDis = Convert.ToDecimal(txtBillDiscount.Text.Trim().ToString());
         decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         decBillDis = decBillDis * decRate;
         if (decBillDis > 0)
         {
             infoLedgerPosting.Debit = decBillDis;
             infoLedgerPosting.Credit = 0;
             infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
             infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoLedgerPosting.VoucherNo = strVoucherNo;
             infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
             infoLedgerPosting.LedgerId = 8;
             infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
             infoLedgerPosting.DetailsId = 0;
             infoLedgerPosting.ChequeNo = string.Empty;
             infoLedgerPosting.ChequeDate = DateTime.Now;
             infoLedgerPosting.Extra1 = string.Empty;
             infoLedgerPosting.Extra2 = string.Empty;
             BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
         }
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             foreach (DataGridViewRow dgvrow in dgvSalesInvoiceTax.Rows)
             {
                 if (dgvrow.Cells["dgvtxtTtaxId"].Value != null && dgvrow.Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty)
                 {
                     decimal decTaxAmount = 0;
                     decTaxAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtTtaxAmount"].Value.ToString());
                     decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decTaxAmount = decTaxAmount * decRate;
                     if (decTaxAmount > 0)
                     {
                         infoLedgerPosting.Debit = 0;
                         infoLedgerPosting.Credit = decTaxAmount;
                         infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
                         infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                         infoLedgerPosting.VoucherNo = strVoucherNo;
                         infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
                         infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvtxtTaxLedgerId"].Value.ToString());
                         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                         infoLedgerPosting.DetailsId = 0;
                         infoLedgerPosting.ChequeNo = string.Empty;
                         infoLedgerPosting.ChequeDate = DateTime.Now;
                         infoLedgerPosting.Extra1 = string.Empty;
                         infoLedgerPosting.Extra2 = string.Empty;
                         BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
                     }
                 }
             }
         }
         if (cmbDrorCr.SelectedItem.ToString() != "Cr")
         {
             foreach (DataGridViewRow dgvrow in dgvSalesInvoiceLedger.Rows)
             {
                 if (dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty)
                 {
                     decimal decAmount = 0;
                     decAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                     decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decAmount = decAmount * decRate;
                     if (decAmount > 0)
                     {
                         infoLedgerPosting.Debit = decAmount;
                         infoLedgerPosting.Credit = 0;
                         infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
                         infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                         infoLedgerPosting.VoucherNo = strVoucherNo;
                         infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
                         infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value.ToString());
                         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                         infoLedgerPosting.DetailsId = 0;
                         infoLedgerPosting.ChequeNo = string.Empty;
                         infoLedgerPosting.ChequeDate = DateTime.Now;
                         infoLedgerPosting.Extra1 = string.Empty;
                         infoLedgerPosting.Extra2 = string.Empty;
                         BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
                     }
                 }
             }
             if (cmbCashOrbank.Visible)
             {
                 decimal decBankOrCashId = 0;
                 decimal decAmountForCr = 0;
                 decBankOrCashId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
                 decAmountForCr = Convert.ToDecimal(lblLedgerTotalAmount.Text.ToString());
                 decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                 decAmountForCr = decAmountForCr * decRate;
                 infoLedgerPosting.Debit = 0;
                 infoLedgerPosting.Credit = decAmountForCr;
                 infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
                 infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                 infoLedgerPosting.VoucherNo = strVoucherNo;
                 infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
                 infoLedgerPosting.LedgerId = decBankOrCashId;
                 infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                 infoLedgerPosting.DetailsId = 0;
                 infoLedgerPosting.ChequeNo = string.Empty;
                 infoLedgerPosting.ChequeDate = DateTime.Now;
                 infoLedgerPosting.Extra1 = "AddCash";
                 infoLedgerPosting.Extra2 = string.Empty;
                 BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
             }
             else
             {
                 decimal decBankOrCashId = 0;
                 decimal decAmountForCr = 0;
                 decBankOrCashId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
                 decAmountForCr = Convert.ToDecimal(lblLedgerTotalAmount.Text.ToString());
                 decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                 decAmountForCr = decAmountForCr * decRate;
                 infoLedgerPosting.Debit = 0;
                 infoLedgerPosting.Credit = decAmountForCr;
                 infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
                 infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                 infoLedgerPosting.VoucherNo = strVoucherNo;
                 infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
                 infoLedgerPosting.LedgerId = decBankOrCashId;
                 infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                 infoLedgerPosting.DetailsId = 0;
                 infoLedgerPosting.ChequeNo = string.Empty;
                 infoLedgerPosting.ChequeDate = DateTime.Now;
                 infoLedgerPosting.Extra1 = "AddCash";
                 infoLedgerPosting.Extra2 = string.Empty;
                 BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
             }
         }
         else
         {
             string strVno = string.Empty;
             strVno = infoLedgerPosting.VoucherNo;
             BllLedgerPosting.LedgerPostingDeleteByVoucherTypeIdAndLedgerIdAndVoucherNoAndExtra(DecSalesInvoiceVoucherTypeId, decBankOrCashIdForEdit, strVno, "AddCash");
             foreach (DataGridViewRow dgvrow in dgvSalesInvoiceLedger.Rows)
             {
                 if (dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty)
                 {
                     decimal decAmount = 0;
                     decAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                     decRate = BllExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decAmount = decAmount * decRate;
                     if (decAmount > 0)
                     {
                         infoLedgerPosting.Debit = 0;
                         infoLedgerPosting.Credit = decAmount;
                         infoLedgerPosting.Date = Convert.ToDateTime(txtDate.Text.ToString());
                         infoLedgerPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
                         infoLedgerPosting.VoucherNo = strVoucherNo;
                         infoLedgerPosting.InvoiceNo = txtInvoiceNo.Text.Trim();
                         infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvCmbAdditionalCostledgerName"].Value.ToString());
                         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                         infoLedgerPosting.DetailsId = 0;
                         infoLedgerPosting.ChequeNo = string.Empty;
                         infoLedgerPosting.ChequeDate = DateTime.Now;
                         infoLedgerPosting.Extra1 = string.Empty;
                         infoLedgerPosting.Extra2 = string.Empty;
                         BllLedgerPosting.LedgerPostingEditByVoucherTypeAndVoucherNoAndLedgerId(infoLedgerPosting);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 82" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }