예제 #1
0
 /// <summary>
 /// Save function Call the ledger posting function also
 /// </summary>
 public void SaveFuction()
 {
     try
     {
         decimal decContraDetailsId = 0;
         ContraMasterSP spContraMaster = new ContraMasterSP();
         ContraMasterInfo infoContraMaster = new ContraMasterInfo();
         ContraDetailsSP spContraDetails = new ContraDetailsSP();
         ContraDetailsInfo infoCOntraDetails = new ContraDetailsInfo();
         ExchangeRateSP spExchangeRate = new ExchangeRateSP();
         decimal decIdentity = 0;
         decimal decLedgerId = 0;
         decimal decDebit = 0;
         decimal decCredit = 0;
         int inCount = dgvContraVoucher.RowCount;
         int inValue = 0;
         for (int i = 0; i < inCount - 1; i++)
         {
             if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null &&
                 dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != null)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             if (Convert.ToDecimal(txtTotal.Text) != 0)
             {
                 infoContraMaster.LedgerId = Convert.ToDecimal(cmbBankAccount.SelectedValue.ToString());
                 if (isAutomatic)
                 {
                     infoContraMaster.VoucherNo = strVoucherNo;
                 }
                 else
                 {
                     decimal decVoucherNo = spContraMaster.ContraVoucherMasterGetMaxPlusOne(DecContraVoucherTypeId) + 1;
                     infoContraMaster.VoucherNo = Convert.ToString(decVoucherNo);
                 }
                 infoContraMaster.Date = Convert.ToDateTime(dtpContraVoucherDate.Text.ToString());
                 infoContraMaster.Narration = txtNarration.Text.Trim();
                 infoContraMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
                 infoContraMaster.Extra1 = string.Empty;
                 infoContraMaster.Extra2 = string.Empty;
                 if (rbtnDeposit.Checked)
                 {
                     infoContraMaster.Type = "Deposit";
                 }
                 else
                 {
                     infoContraMaster.Type = "Withdraw";
                 }
                 infoContraMaster.SuffixPrefixId = decContraSuffixPrefixId;
                 infoContraMaster.VoucherTypeId = DecContraVoucherTypeId;
                 infoContraMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoContraMaster.UserId = PublicVariables._decCurrentUserId;
                 if (isAutomatic)
                 {
                     infoContraMaster.InvoiceNo = strInvoiceNo;
                 }
                 else
                 {
                     infoContraMaster.InvoiceNo = txtVoucherNo.Text;
                 }
                 decIdentity = spContraMaster.ContraMasterAdd(infoContraMaster);
                 infoCOntraDetails.ContraMasterId = decIdentity;
                 infoCOntraDetails.Extra1 = string.Empty;
                 infoCOntraDetails.Extra2 = string.Empty;
                 int inRowCount = dgvContraVoucher.RowCount;
                 //-------------------------------Saving grid details--------------------------------------------------------------------
                 for (int i = 0; i < inRowCount - 1; i++)
                 {
                     if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != string.Empty)
                     {
                         infoCOntraDetails.LedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                     }
                     if (dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                     {
                         infoCOntraDetails.Amount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     }
                     if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                     {
                         infoCOntraDetails.ChequeNo = dgvContraVoucher.Rows[i].Cells["dgvtxtChequeNo"].Value.ToString();
                     }
                     else
                     {
                         infoCOntraDetails.ChequeNo = string.Empty;
                     }
                     if (dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                     {
                         infoCOntraDetails.ChequeDate = Convert.ToDateTime(dgvContraVoucher.Rows[i].Cells["dgvtxtChequeDate"].Value.ToString());
                     }
                     else
                     {
                         infoCOntraDetails.ChequeDate = Convert.ToDateTime("1/1/1753");
                     }
                     infoCOntraDetails.ExchangeRateId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value.ToString());
                     decContraDetailsId = spContraDetails.ContraDetailsAddReturnWithhIdentity(infoCOntraDetails);
                     //---------------------------------------------------------Ledger Posting-----------------------------------------/---------------------------------------------------/
                     if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != string.Empty)
                     {
                         decLedgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                     }
                     if (dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                     {
                         decSelectedCurrencyRate = spExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbCurrency"].Value));
                         decAmount = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                         decConvertRate = decAmount * decSelectedCurrencyRate;
                         if (rbtnDeposit.Checked)
                         {
                             decCredit = decConvertRate;
                             decDebit = 0;
                             LedgerPosting(decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                         }
                         else
                         {
                             decDebit = decConvertRate;
                             decCredit = 0;
                             LedgerPosting(decLedgerId, decCredit, decDebit, decContraDetailsId, i);
                         }
                     }
                 }
                 decAmount = Convert.ToDecimal(txtTotal.Text);
                 decContraDetailsId = 0;
                 if (rbtnDeposit.Checked)
                 {
                     decDebit = decAmount;
                     decCredit = 0;
                     LedgerPosting(infoContraMaster.LedgerId, decCredit, decDebit, decContraDetailsId, -1);
                 }
                 else
                 {
                     decCredit = decAmount;
                     decDebit = 0;
                     LedgerPosting(infoContraMaster.LedgerId, decCredit, decDebit, decContraDetailsId, -1);
                 }
                 //------------------------------------------------------------------Ledger Posting---end---------------------------------------------------------------------//
                 Messages.SavedMessage();
                 if (cbxPrintafterSave.Checked)
                 {
                     if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                     {
                         PrintForDotMatrix(decIdentity);
                     }
                     else
                     {
                         Print(decIdentity);
                     }
                 }
                 Clear();
             }
             else
             {
                 Messages.InformationMessage("Cannot save total debit and credit as 0");
                 dgvContraVoucher.Focus();
             }
         }
         else
         {
             Messages.InformationMessage("Cant save contra voucher without atleast one ledger with complete details");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("CV:16" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
예제 #2
0
 /// <summary>
 /// These function for generating the voucher no automatically if its automatic with preffix and sufix
 /// </summary>
 public void VoucherNumberGeneration()
 {
     try
     {
         TransactionsGeneralFill obj = new TransactionsGeneralFill();
         ContraMasterSP spContraMaster = new ContraMasterSP();
         if (strVoucherNo == string.Empty)
         {
             strVoucherNo = "0";
         }
         strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecContraVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpContraVoucherDate.Value, tableName);
         if (Convert.ToDecimal(strVoucherNo) != spContraMaster.ContraVoucherMasterGetMaxPlusOne(DecContraVoucherTypeId))
         {
             strVoucherNo = spContraMaster.ContraVoucherMasterGetMax(DecContraVoucherTypeId).ToString();
             strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecContraVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpContraVoucherDate.Value, tableName);
             if (spContraMaster.ContraVoucherMasterGetMax(DecContraVoucherTypeId) == "0")
             {
                 strVoucherNo = "0";
                 strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecContraVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpContraVoucherDate.Value, tableName);
             }
         }
         if (isAutomatic)
         {
             SuffixPrefixSP spSuffisprefix = new SuffixPrefixSP();
             SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
             infoSuffixPrefix = spSuffisprefix.GetSuffixPrefixDetails(DecContraVoucherTypeId, dtpContraVoucherDate.Value);
             strPrefix = infoSuffixPrefix.Prefix;
             strSuffix = infoSuffixPrefix.Suffix;
             decContraSuffixPrefixId = infoSuffixPrefix.SuffixprefixId;
             strInvoiceNo = strPrefix + strVoucherNo + strSuffix;
             txtVoucherNo.Text = strInvoiceNo;
             txtVoucherNo.ReadOnly = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("CV:08" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }