/// <summary>
 /// Function to fill AccountLedger combobox
 /// </summary>
 public void AccountLedgerComboFill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         ListObj = BllPDCPayable.AccountLedgerComboFill(false);
         DataRow dr = ListObj[0].NewRow();
         dr["ledgerId"] = 0;
         dr["ledgerName"] = "All";
         ListObj[0].Rows.InsertAt(dr, 0);
         cmbAccountLedger.DataSource = ListObj[0];
         cmbAccountLedger.ValueMember = "ledgerId";
         cmbAccountLedger.DisplayMember = "ledgerName";
         cmbAccountLedger.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         MessageBox.Show("PRREG1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the grid
 /// </summary>
 public void ChequeReportFillGrid()
 {
     try
     {
         if (rbtnPayed.Checked)
         {
             isIssued = true;
         }
         else if (rbtnReceived.Checked)
         {
             isIssued = false;
         }
         decimal decTotalAmount = 0;
         string strTotalAmount = Math.Round(decTotalAmount, PublicVariables._inNoOfDecimalPlaces).ToString();
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         List<DataTable> ListObj = new List<DataTable>();
         decimal decParty = decimal.Parse(cmbParty.SelectedValue.ToString());
         ListObj = BllPDCPayable.ChequeReportGridFill(decParty, txtChequeNo.Text, dtpIssueFromDate.Value, dtpIssueToDate.Value, dtpChequeFromDate.Value, dtpChequeToDate.Value, isIssued);
         if (ListObj[0].Rows.Count > 0)
         {
             strTotalAmount = ListObj[0].Compute("Sum(Amount)", string.Empty).ToString();
             ListObj[0].Rows.Add();
             ListObj[0].Rows[ListObj[0].Rows.Count - 1]["Amount"] = strTotalAmount;
             ListObj[0].Rows[ListObj[0].Rows.Count - 1]["Party"] = "Total :";
         }
         dgvChequeReport.DataSource = ListObj[0];
         dgvChequeReport.ClearSelection();
         if (dgvChequeReport.Rows.Count > 0)
         {
             dgvChequeReport.Columns["ledgerId"].Visible = false;
             dgvChequeReport.Rows[dgvChequeReport.Rows.Count - 1].DefaultCellStyle.Font = new Font(dgvChequeReport.Font, FontStyle.Bold);
             dgvChequeReport.Rows[dgvChequeReport.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Red;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("RCR:1" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill Bank combobox
        /// </summary>
        public void cmbBankAccountFill()
        {

            try
            {
                PDCPayableBll BllPDCPayable = new PDCPayableBll();
                cmbBank.DataSource = null;
                List<DataTable> ListBank = BllPDCPayable.BankAccountComboFill();
                DataRow dr = ListBank[0].NewRow();
                dr["ledgerId"] = 0;
                dr["ledgerName"] = "All";
                ListBank[0].Rows.InsertAt(dr, 0);
                cmbBank.DataSource = ListBank[0];
                cmbBank.DisplayMember = "ledgerName";
                cmbBank.ValueMember = "ledgerId";
                cmbBank.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show("PCREG3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill party combobox
 /// </summary>
 public void PartyComboFill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         ListObj = BllPDCPayable.ChequeReportPartyComboFill();
         DataRow dr = ListObj[0].NewRow();
         dr[0] = "All";
         dr[1] = 0;
         ListObj[0].Rows.InsertAt(dr, 0);
         cmbParty.DataSource = ListObj[0];
         cmbParty.DisplayMember = "ledgerName";
         cmbParty.ValueMember = "ledgerId";
         cmbParty.SelectedValue = 0;
     }
     catch (Exception ex)
     {
         MessageBox.Show("RCR:2" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Save Or edit function, here checking the invalid entries
        /// </summary>
        public void SaveOrEditFunction()
        {
            try
            {
                bool isOk = true;
                if (isOk)
                    if (txtvoucherNo.Text == string.Empty)
                    {
                        Messages.InformationMessage("Enter voucher no");
                        txtvoucherNo.Focus();
                    }
                    else if (txtVoucherDate.Text == string.Empty)
                    {
                        Messages.InformationMessage("Select date");
                        txtVoucherDate.Focus();
                    }
                    else if (cmbvouchertype.SelectedValue == null)
                    {
                        Messages.InformationMessage("Select voucher type");
                        cmbvouchertype.Focus();
                    }
                    else if (cmbInvoiceNo.SelectedValue == null)
                    {
                        Messages.InformationMessage("Select against invoice no");
                        cmbInvoiceNo.Focus();
                    }
                    else if (cmbStatus.Text == string.Empty)
                    {
                        Messages.InformationMessage("Select status");
                        cmbStatus.Focus();
                    }
                    else
                    {
                        if (PublicVariables.isMessageAdd)
                        {
                            isOk = false;
                            PDCClearanceBll BllPdcClearance = new PDCClearanceBll();
                            if (!isInEditMode)
                            {
                                if (Messages.SaveMessage())
                                    if (!BllPdcClearance.PDCclearanceCheckExistence(txtvoucherNo.Text.Trim(), decPDCclearanceVoucherTypeId, 0))
                                    {
                                        SaveFunction();
                                    }
                                    else
                                    {
                                        Messages.InformationMessage("Voucher number already exist");
                                    }
                            }
                            else if (isInEditMode)
                            {
                                if (Messages.UpdateMessage())
                                {
                                    SaveFunction();
                                }
                            }
                        }
                        if (isOk)
                        {
                            if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text))
                            {
                                PDCPayableBll BllPDCPayable = new PDCPayableBll();

                                if (isInEditMode)
                                {
                                    SaveFunction();
                                }
                                else
                                {
                                    SaveFunction();
                                }
                            }
                            else
                            {
                                Messages.NoPrivillageMessage();
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PC10:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Ledger Posting Function, here saving the curresponding details into the ledger
        /// </summary>
        public void LedgerPostingAdd()
        {
            try
            {
                string strstatus = cmbStatus.Text.ToString();
                LedgerPostingInfo InfoPosting = new LedgerPostingInfo();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                PDCClearanceBll BllPdcClearance = new PDCClearanceBll();
                PDCPayableMasterInfo infoPDCPayable = new PDCPayableMasterInfo();
                PDCPayableBll BllPDCPayable = new PDCPayableBll();
                PDCReceivableMasterInfo infoPDCReceivable = new PDCReceivableMasterInfo();
                PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                strVoucherType = BllPdcClearance.TypeOfVoucherReturnUnderVoucherName(cmbvouchertype.Text.ToString());
                if (strVoucherType == "PDC Payable")
                {
                    infoPDCPayable = BllPDCPayable.PDCPayableMasterView(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = Convert.ToDateTime(txtVoucherDate.Text.ToString());
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text.ToString());
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    if (strstatus == "Cleared")
                    {

                        infoLedgerPosting.LedgerId = infoPDCPayable.BankId;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    }
                    else if (strstatus == "Bounced")
                    {
                        infoLedgerPosting.LedgerId = infoPDCPayable.LedgerId;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    }
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.VoucherNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = Convert.ToDateTime(txtVoucherDate.Text.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.LedgerId = 6;
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
                else if (strVoucherType == "PDC Receivable")
                {
                    infoPDCReceivable = BllPDCReciveble.PDCReceivableMasterView(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = 7;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text.ToString());
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    if (strstatus == "Cleared")
                    {
                        infoLedgerPosting.LedgerId = infoPDCReceivable.BankId;
                    }
                    else if (strstatus == "Bounced")
                    {
                        infoLedgerPosting.LedgerId = infoPDCReceivable.LedgerId;
                    }
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PC12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Save or edit function, its for checking the invalid entries
 /// </summary>
 public void SaveOrEditFunction()
 {
     try
     {
         txtVoucherDate.Text = txtVoucherDate.Text.Trim();
         cmbAccountLedger.Text = cmbAccountLedger.Text.Trim();
         txtAmount.Text = txtAmount.Text.Trim();
         cmbBank.Text = cmbBank.Text.Trim();
         txtChequeDate.Text = txtChequeDate.Text.Trim();
         txtcheckNo.Text = txtcheckNo.Text.Trim();
         txtNarration.Text = txtNarration.Text.Trim();
         bool isOk = true;
         bool isAmountOk = false;
         try
         {
             if (decimal.Parse(txtAmount.Text) > 0)
                 isAmountOk = true;
         }
         catch
         {
             txtAmount.Text = string.Empty;
         }
         if (isOk)
         {
             if (txtvoucherNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter voucher no");
                 txtvoucherNo.Focus();
             }
             else if (txtVoucherDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select date");
                 txtVoucherDate.Focus();
             }
             else if (cmbAccountLedger.SelectedValue == null)
             {
                 Messages.InformationMessage("Select account ledger");
                 cmbAccountLedger.Focus();
             }
             else if (!isAmountOk)
             {
                 Messages.InformationMessage("Select amount");
                 txtAmount.Focus();
             }
             else if (cmbBank.SelectedValue == null)
             {
                 Messages.InformationMessage("Select bank ");
                 cmbBank.Focus();
             }
             else if (txtcheckNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter cheque no");
                 txtcheckNo.Focus();
             }
             else if (txtChequeDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select cheque date");
                 txtChequeDate.Focus();
             }
             else
             {
                 if (PublicVariables.isMessageAdd)
                 {
                     isOk = false;
                     PDCPayableBll BllPdcpayable = new PDCPayableBll();
                     if (!isInEditMode)
                     {
                         if (Messages.SaveMessage())
                             if (!BllPdcpayable.PDCpayableCheckExistence(txtvoucherNo.Text.Trim(), decPDCpayableVoucherTypeId, 0))
                             {
                                 SaveFunction();
                             }
                             else
                             {
                                 Messages.InformationMessage("Voucher number already exist");
                             }
                     }
                     else
                     {
                         if (Messages.UpdateMessage())
                             if (isInEditMode && BllPdcpayable.PDCPayableVoucherCheckRreference(decPDCpayableEditId, decPDCpayableVoucherTypeId))
                             {
                                 MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 SaveFunction();
                             }
                         if (BillallocationObj != null)
                         {
                             this.Close();
                             BillallocationObj.Enabled = true;
                             BillallocationObj.BillAllocationGridFill();
                         }
                     }
                 }
                 if (isOk)
                 {
                     if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text))
                     {
                         PDCPayableBll BllPdcpayable = new PDCPayableBll();
                         if (isInEditMode && BllPdcpayable.PDCPayableVoucherCheckRreference(decPDCpayableEditId, decPDCpayableVoucherTypeId))
                         {
                             MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         }
                         else
                         {
                             SaveFunction();
                         }
                     }
                     else
                     {
                         Messages.NoPrivillageMessage();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// CashorBank Account ComboFill
 /// </summary>
 public void cmbBankAccountFill()
 {
     try
     {
         PDCPayableBll BllPdcPayable = new PDCPayableBll();
         cmbBank.DataSource = null;
         List<DataTable> listObjBank = BllPdcPayable.BankAccountComboFill();
         cmbBank.DataSource = listObjBank[0];
         cmbBank.DisplayMember = "ledgerName";
         cmbBank.ValueMember = "ledgerId";
         cmbBank.SelectedIndex = -1;
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill Datagridview
 /// </summary>
 public void GridSearchRegister()
 {
     try
     {
         if (cmbAccountLedger.Text.Trim() == string.Empty)
         {
             cmbAccountLedger.Text = "ALL";
         }
         List<DataTable> ListObj = new List<DataTable>();
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         ListObj = BllPDCPayable.PDCpayableRegisterSearch(Convert.ToDateTime(dtpfromDate.Value.ToString()), Convert.ToDateTime(dtpTodate.Value.ToString()), txtvoucherNo.Text.Trim(), cmbAccountLedger.Text.ToString());
         dgvpdcPayableRegister.DataSource = ListObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("PPREG1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Print function
 /// </summary>
 /// <param name="decMasterId"></param>
 public void Print(decimal decMasterId)
 {
     try
     {
         DataSet dsPdcPayable = new DataSet();
         PDCPayableBll BllPdcpayable = new PDCPayableBll();
         dsPdcPayable = BllPdcpayable.PDCpayableVoucherPrinting(decMasterId, 1);
         frmReport frmreport = new frmReport();
         frmreport.MdiParent = formMDI.MDIObj;
         frmreport.PDCpayableReportPrinting(dsPdcPayable);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Ledger posting edit function
        /// </summary>
        /// <param name="decpdcMasterId"></param>
        public void LedgerPostingEdit(decimal decpdcMasterId)
        {
            PDCPayableBll BllPdcpayable = new PDCPayableBll();
            List<DataTable> listObjLedgerPostingId = new List<DataTable>();
            LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
            LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
            decimal decOldExchange = 0;
            decimal decNewExchangeRate = 0;
            decimal decNewExchangeRateId = 0;
            decimal decSelectedCurrencyRate = 0;
            decimal decAmount = 0;
            decimal decConvertRate = 0;
            string strReferenceType = string.Empty;
            decimal decOldExchangeId = 0;
            try
            {

                listObjLedgerPostingId = BllPdcpayable.LedgerPostingIdByPDCpayableId(decpdcMasterId);
                decimal decledgerpostingId1 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[0]["ledgerPostingId"].ToString());
                decimal decLedgerPostingId2 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[1]["ledgerPostingId"].ToString());
                if (!btnAgainstRef.Enabled)
                {
                    infoLedgerPosting.LedgerPostingId = decledgerpostingId1;
                    infoLedgerPosting.VoucherTypeId = decPDCpayableVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);

                }
                else
                {
                    infoLedgerPosting.LedgerPostingId = decledgerpostingId1;
                    infoLedgerPosting.VoucherTypeId = decPDCpayableVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Credit = 0;
                    foreach (DataRow dr in dtblPartyBalance.Rows)
                    {
                        if (infoLedgerPosting.LedgerId == Convert.ToDecimal(dr["LedgerId"].ToString()))
                        {
                            decOldExchange = Convert.ToDecimal(dr["OldExchangeRate"].ToString());
                            decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString());
                            decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchange);
                            decAmount = Convert.ToDecimal(dr["Amount"].ToString());
                            decConvertRate = decConvertRate + (decAmount * decSelectedCurrencyRate);

                        }
                    }
                    infoLedgerPosting.Debit = decConvertRate;

                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);
                    infoLedgerPosting.LedgerId = 12;
                    foreach (DataRow dr in dtblPartyBalance.Rows)
                    {
                        if (Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString()) == Convert.ToDecimal(dr["LedgerId"].ToString()))
                        {
                            if (dr["ReferenceType"].ToString() == "Against")
                            {
                                decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString());
                                decNewExchangeRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decNewExchangeRateId);
                                decOldExchangeId = Convert.ToDecimal(dr["OldExchangeRate"].ToString());
                                decOldExchange = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchangeId);
                                decAmount = Convert.ToDecimal(dr["Amount"].ToString());
                                decimal decForexAmount = (decAmount * decNewExchangeRate) - (decAmount * decOldExchange);
                                if (decForexAmount >= 0)
                                {

                                    infoLedgerPosting.Debit = decForexAmount;
                                    infoLedgerPosting.Credit = 0;
                                }
                                else
                                {
                                    infoLedgerPosting.Credit = -1 * decForexAmount;
                                    infoLedgerPosting.Debit = 0;
                                }
                                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                            }
                        }

                    }
                }

                infoLedgerPosting.LedgerPostingId = decLedgerPostingId2;
                infoLedgerPosting.VoucherNo = strVoucherNo;
                infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                infoLedgerPosting.LedgerId = 6;
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.Debit = 0;
                infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
                infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;
                BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);
            }
            catch (Exception ex)
            {
                MessageBox.Show("PP15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Fill function for updation
 /// </summary>
 public void FillFunction()
 {
     try
     {
         PDCPayableMasterInfo infopdcpayable = new PDCPayableMasterInfo();
         PDCPayableBll BllPdcPayable = new PDCPayableBll();
         infopdcpayable = BllPdcPayable.PDCPayableMasterView(decPDCpayableEditId);
         txtvoucherNo.ReadOnly = false;
         strVoucherNo = infopdcpayable.VoucherNo;
         strInvoiceNo = infopdcpayable.InvoiceNo;
         txtvoucherNo.Text = strInvoiceNo;
         decSufixprefixPdcpayableID = infopdcpayable.SuffixPrefixId;
         decPDCpayableVoucherTypeId = infopdcpayable.VoucherTypeId;
         VoucherTypeBll BllVOucherType = new VoucherTypeBll();
         isAutomatic = BllVOucherType.CheckMethodOfVoucherNumbering(decPDCpayableVoucherTypeId);
         if (isAutomatic)
         {
             txtvoucherNo.ReadOnly = true;
         }
         else
         {
             txtvoucherNo.ReadOnly = false;
         }
         if (infopdcpayable.PdcPayableMasterId != 0)
         {
             txtvoucherNo.Text = infopdcpayable.InvoiceNo;
             dtpVoucherDate.Value = infopdcpayable.Date;
             txtVoucherDate.Text = dtpVoucherDate.Value.ToString("dd-MMM-yyyy");
             txtNarration.Text = infopdcpayable.Narration;
             cmbAccountLedger.SelectedValue = infopdcpayable.LedgerId;
             txtAmount.Text = infopdcpayable.Amount.ToString();
             if (infopdcpayable.BankId != 0)
                 cmbBank.SelectedValue = infopdcpayable.BankId;
             else
                 cmbBank.SelectedValue = string.Empty;
             txtcheckNo.Text = infopdcpayable.ChequeNo;
             txtChequeDate.Text = infopdcpayable.ChequeDate.ToString("dd-MMM-yyyy");
             btnSave.Text = "Update";
             PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
             List<DataTable> listObj = new List<DataTable>();
             listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPDCpayableVoucherTypeId, strVoucherNo, infopdcpayable.Date);
             dtblPartyBalance = listObj[0];
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP22:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Delete function
 /// </summary>
 /// <param name="decPDCpayableMasterId"></param>
 public void DeleteFunction(decimal decPDCpayableMasterId)
 {
     try
     {
         PDCPayableBll BllPdcPayable = new PDCPayableBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         if (!BllPartyBalance.PartyBalanceCheckReference(decPDCpayableVoucherTypeId, strVoucherNo))
         {
             BllPdcPayable.PDCPayableMasterDelete(decPDCpayableMasterId, decPDCpayableVoucherTypeId, strVoucherNo);
             Messages.DeletedMessage();
         }
         else
         {
             Messages.InformationMessage("Reference exist. Cannot delete");
             txtVoucherDate.Focus();
         }
         if (PDCPayableRegisterObj != null)
         {
             this.Close();
             PDCPayableRegisterObj.Enabled = true;
         }
         else if (PDCpayableReportObj != null)
         {
             this.Close();
             PDCpayableReportObj.Enabled = true;
         }
         else if (frmVoucherSearch != null)
         {
             this.Close();
             frmVoucherSearch.GridFill();
         }
         else if (frmLedgerDetailsObj != null)
         {
             this.Close();
         }
         else if (frmDayBookObj != null)
         {
             this.Close();
         }
         else if (BillallocationObj != null)
         {
             this.Close();
         }
         else
         {
             ClearFunction();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP23:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Delete button click, check the user privilage, references and call the delete function
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnDelete.Text))
         {
             if (PublicVariables.isMessageDelete)
             {
                 if (Messages.DeleteMessage())
                 {
                     if (isInEditMode && BllPDCPayable.PDCPayableReferenceCheck(decPDCpayableEditId, decPDCpayableVoucherTypeId))
                     {
                         Messages.ReferenceExistsMessage();
                     }
                     else
                     {
                         DeleteFunction(decPDCpayableEditId);
                         txtvoucherNo.Focus();
                     }
                 }
             }
             else
             {
                 if (isInEditMode && BllPDCPayable.PDCPayableReferenceCheck(decPDCpayableEditId, decPDCpayableVoucherTypeId))
                 {
                     Messages.ReferenceExistsMessage();
                 }
                 DeleteFunction(decPDCpayableEditId);
                 txtvoucherNo.Focus();
             }
         }
         else
         {
             Messages.NoPrivillageMessage();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP40:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Voucher no generation function based on the settings
 /// </summary>
 public void VoucherNumberGeneration()
 {
     try
     {
         if (isAutomatic == true)
         {
             TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
             PDCPayableBll BllPdcpayable = new PDCPayableBll();
             if (strVoucherNo == string.Empty)
             {
                 strVoucherNo = "0";
             }
             strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCpayableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
             if (Convert.ToDecimal(strVoucherNo) != BllPdcpayable.PDCPayableMaxUnderVoucherTypePlusOne(decPDCpayableVoucherTypeId) + 1)
             {
                 strVoucherNo = BllPdcpayable.PDCPayableMaxUnderVoucherTypePlusOne(decPDCpayableVoucherTypeId).ToString();
                 strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCpayableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
                 if (BllPdcpayable.PDCPayableMaxUnderVoucherTypePlusOne(decPDCpayableVoucherTypeId) == 0)
                 {
                     strVoucherNo = "0";
                     strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCpayableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
                 }
             }
             SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();
            // SuffixPrefixSP spSuffisprefix = new SuffixPrefixSP();
             SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
             infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decPDCpayableVoucherTypeId, dtpVoucherDate.Value);
             strPrefix = infoSuffixPrefix.Prefix;
             strSuffix = infoSuffixPrefix.Suffix;
             decSufixprefixPdcpayableID = infoSuffixPrefix.SuffixprefixId;
             strInvoiceNo = strPrefix + strVoucherNo + strSuffix;
             txtvoucherNo.Text = strInvoiceNo;
             txtvoucherNo.ReadOnly = true;
         }
         else
         {
             txtvoucherNo.ReadOnly = false;
             txtvoucherNo.Text = string.Empty;
             lblVoucherNoManualValidator.Visible = true;
             strInvoiceNo = txtvoucherNo.Text.Trim();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to print the details
 /// </summary>
 public void Print()
 {
     try
     {
         string strFromDate = txtFromDate.Text.ToString();
         string strToDate = txtTodate.Text.ToString();
         decimal decVoucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decimal decLedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         DataSet dsPdcPayableReport = BllPDCPayable.PdcpayableReportPrinting(Convert.ToDateTime(dtpFrmDate.Value.ToString()), Convert.ToDateTime(dtpTodate.Value.ToString()), cmbVoucherType.Text.ToString(), cmbAccountLedger.Text.ToString(), Convert.ToDateTime(dtpCheckDateFrom.Value.ToString()), Convert.ToDateTime(dtpCheckdateTo.Value.ToString()), txtcheckNo.Text.Trim(), txtVoucherNo.Text.Trim(), cmbStatus.Text.Trim(), 1);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.PdcpayablereportReportPrinting(dsPdcPayableReport);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PPREP6:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// On double clicking the cell in grid, it loads the corresponding Voucher to update or delete the entries
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvBillAllocation_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    decVoucherTypeId = Convert.ToDecimal(dgvBillAllocation.CurrentRow.Cells["voucherTypeId"].Value.ToString());

                    strTypeOfVoucher = dgvBillAllocation.CurrentRow.Cells["typeOfVoucher"].Value.ToString();
                    strVoucherNo = dgvBillAllocation.CurrentRow.Cells["voucherNo"].Value.ToString();
                    if (strTypeOfVoucher == "PDC Payable")
                    {
                        PDCPayableBll BllPDCPayable = new PDCPayableBll();
                        decimal decMasterId = BllPDCPayable.PdcPayableMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPdcPayable frmpdcPayableObj = new frmPdcPayable();
                        frmpdcPayableObj = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;

                        if (frmpdcPayableObj == null)
                        {
                            frmpdcPayableObj = new frmPdcPayable();
                            frmpdcPayableObj.MdiParent = formMDI.MDIObj;

                            frmpdcPayableObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "PDC Receivable")
                    {
                        PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                        decimal decMasterId = BllPDCReciveble.PdcReceivableMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPdcReceivable frmPdcReceivableObj = new frmPdcReceivable();
                        frmPdcReceivableObj = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                        if (frmPdcReceivableObj == null)
                        {
                            frmPdcReceivableObj = new frmPdcReceivable();
                            frmPdcReceivableObj.MdiParent = formMDI.MDIObj;
                            frmPdcReceivableObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Payment Voucher")
                    {
                        PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                        decimal decMasterId = BllPaymentVoucher.paymentMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPaymentVoucher frmPaymentVoucherObj = new frmPaymentVoucher();
                        frmPaymentVoucherObj = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                        if (frmPaymentVoucherObj == null)
                        {
                            frmPaymentVoucherObj = new frmPaymentVoucher();
                            frmPaymentVoucherObj.MdiParent = formMDI.MDIObj;

                            frmPaymentVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Receipt Voucher")
                    {

                        RecieptVoucherBll bllRecieptVoucherBll = new RecieptVoucherBll();
                        decimal decMasterId = bllRecieptVoucherBll.ReceiptMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmReceiptVoucher frmReceiptVoucherObj = new frmReceiptVoucher();
                        frmReceiptVoucherObj = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                        if (frmReceiptVoucherObj == null)
                        {
                            frmReceiptVoucherObj = new frmReceiptVoucher();
                            frmReceiptVoucherObj.MdiParent = formMDI.MDIObj;

                            frmReceiptVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Journal Voucher")
                    {
                        JournalVoucherBll JournalVoucherbll = new JournalVoucherBll();
                        decimal decMasterId = JournalVoucherbll.JournalMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmJournalVoucher frmJournalVoucherObj = new frmJournalVoucher();
                        frmJournalVoucherObj = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                        if (frmJournalVoucherObj == null)
                        {
                            frmJournalVoucherObj = new frmJournalVoucher();
                            frmJournalVoucherObj.MdiParent = formMDI.MDIObj;

                            frmJournalVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Credit Note")
                    {
                        CreditNoteBll BllCreditNoteMaster = new CreditNoteBll();
                        decimal decMasterId = BllCreditNoteMaster.CreditNoteMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmCreditNote frmCreditNoteObj = new frmCreditNote();
                        frmCreditNoteObj = Application.OpenForms["frmCreditNote"] as frmCreditNote;
                        if (frmCreditNoteObj == null)
                        {
                            frmCreditNoteObj = new frmCreditNote();
                            frmCreditNoteObj.MdiParent = formMDI.MDIObj;

                            frmCreditNoteObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Debit Note")
                    {
                        //DebitNoteMasterSP sp = new DebitNoteMasterSP();
                        DebitNoteBll bll = new DebitNoteBll();
                        decimal decMasterId = bll.DebitNoteMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmDebitNote frmDebitNoteObj = new frmDebitNote();
                        frmDebitNoteObj = Application.OpenForms["frmDebitNote"] as frmDebitNote;
                        if (frmDebitNoteObj == null)
                        {
                            frmDebitNoteObj = new frmDebitNote();
                            frmDebitNoteObj.MdiParent = formMDI.MDIObj;

                            frmDebitNoteObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("BA:15" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to search the details
 /// </summary>
 public void Search()
 {
     try
     {
         if (cmbAccountLedger.Text.Trim() == string.Empty)
         {
             cmbAccountLedger.Text = "All";
         }
         else if (cmbVoucherType.Text.Trim() == string.Empty)
         {
             cmbVoucherType.Text = "All";
         }
         else if (cmbStatus.Text.Trim() == string.Empty)
         {
             cmbStatus.Text = "All";
         }
         List<DataTable> ListObj = new List<DataTable>();
         PDCPayableBll BllPDCPayable = new PDCPayableBll();
         ListObj = BllPDCPayable.PdcPayableReportSearch(Convert.ToDateTime(dtpFrmDate.Value.ToString()), Convert.ToDateTime(dtpTodate.Value.ToString()), cmbVoucherType.Text.ToString(), cmbAccountLedger.Text.ToString(), Convert.ToDateTime(dtpCheckDateFrom.Value.ToString()), Convert.ToDateTime(dtpCheckdateTo.Value.ToString()), txtcheckNo.Text.Trim(), txtVoucherNo.Text.Trim(), cmbStatus.Text.Trim());
         dgvPDCPayableReport.DataSource = ListObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("PPREP5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// When doubleclicking on the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvReport_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            decimal decVouchertypeId = 0;
            string strVoucherNo = string.Empty;
            try
            {
                if (dgvReport.CurrentRow.Index == e.RowIndex)
                {
                    if ((dgvReport.CurrentRow.Cells["voucherTypeId"].Value != null && dgvReport.CurrentRow.Cells["voucherTypeId"].Value.ToString() != string.Empty))
                    {
                        int inI = dgvReport.CurrentCell.RowIndex;
                        foreach (DataGridViewRow dgv in dgvReport.Rows)
                        {
                            if (dgv.Cells["VoucherNo"].Value != null && dgv.Cells["VoucherNo"].Value.ToString() != string.Empty &&
                                   dgv.Cells["voucherTypeId"].Value != null && dgv.Cells["voucherTypeId"].Value.ToString() != string.Empty)
                            {
                                strVoucherType = dgv.Cells["VoucherType"].Value.ToString();
                                decVouchertypeId = Convert.ToDecimal(dgv.Cells["voucherTypeId"].Value.ToString());
                                strVoucherNo = dgv.Cells["VoucherNo"].Value.ToString();
                            }
                            else
                            {
                                if (dgv.Cells["ledgerId"].Value.ToString() != string.Empty)
                                {
                                    decledgerId = decimal.Parse(dgv.Cells["ledgerId"].Value.ToString());
                                    strVoucherType = dgv.Cells["Account Ledger"].Value.ToString();
                                    frmLedgerDetails frmLedger = new frmLedgerDetails();
                                    frmLedger = Application.OpenForms["frmLedgerDetails"] as frmLedgerDetails;
                                    if (frmLedger == null)
                                    {
                                        frmLedger = new frmLedgerDetails();
                                        frmLedger.MdiParent = formMDI.MDIObj;
                                        frmLedger.callFromAgeing(this, decledgerId);
                                        this.Enabled = false;
                                    }
                                }

                            }
                            if (dgv.Index == inI)
                            {
                                break;
                            }
                        }
                        if (strVoucherType == "Payment Voucher")
                        {
                            PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                            decMasterId = BllPaymentVoucher.paymentMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPaymentVoucher frmPaymentVoucher = new frmPaymentVoucher();
                            frmPaymentVoucher = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                            if (frmPaymentVoucher == null)
                            {
                                frmPaymentVoucher = new frmPaymentVoucher();
                                frmPaymentVoucher.MdiParent = formMDI.MDIObj;
                                frmPaymentVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Receipt Voucher")
                        {
                            RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();
                            //ReceiptMasterSP spRecieptMaster = new ReceiptMasterSP();
                            decMasterId = bllRecieptVoucher.ReceiptMasterIdView(decVouchertypeId, strVoucherNo);
                            frmReceiptVoucher frmReceiptVoucher = new frmReceiptVoucher();
                            frmReceiptVoucher = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                            if (frmReceiptVoucher == null)
                            {
                                frmReceiptVoucher = new frmReceiptVoucher();
                                frmReceiptVoucher.MdiParent = formMDI.MDIObj;
                                frmReceiptVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Journal Voucher")
                        {
                            JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                            decMasterId = bllJournalMaster.JournalMasterIdView(decVouchertypeId, strVoucherNo);
                            frmJournalVoucher frmJournalVoucher = new frmJournalVoucher();
                            frmJournalVoucher = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                            if (frmJournalVoucher == null)
                            {
                                frmJournalVoucher = new frmJournalVoucher();
                                frmJournalVoucher.MdiParent = formMDI.MDIObj;
                                frmJournalVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Receivable")
                        {
                            PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                            decMasterId = BllPDCReciveble.PdcReceivableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcReceivable frmPdcReceivable = new frmPdcReceivable();
                            frmPdcReceivable = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                            if (frmPdcReceivable == null)
                            {
                                frmPdcReceivable = new frmPdcReceivable();
                                frmPdcReceivable.MdiParent = formMDI.MDIObj;
                                frmPdcReceivable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Payable")
                        {
                            PDCPayableBll BllPDCPayable = new PDCPayableBll();
                            decMasterId = BllPDCPayable.PdcPayableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcPayable frmPdcPayable = new frmPdcPayable();
                            frmPdcPayable = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;
                            if (frmPdcPayable == null)
                            {
                                frmPdcPayable = new frmPdcPayable();
                                frmPdcPayable.MdiParent = formMDI.MDIObj;
                                frmPdcPayable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Sales Invoice")
                        {
                            //SalesMasterSP spMaster = new SalesMasterSP();
                            SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                            decMasterId = BllSalesInvoice.SalesMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            //SalesMasterSP spSalesMaster = new SalesMasterSP();
                            bool blPOS = BllSalesInvoice.DayBookSalesInvoiceOrPOS(decMasterId, decVouchertypeId);
                            frmSalesInvoice frmSalesInvoice = new frmSalesInvoice();
                            frmPOS frmPOS = new frmPOS();
                            if (blPOS == true)
                            {
                                frmPOS = Application.OpenForms["frmPOS"] as frmPOS;
                                if (frmPOS == null)
                                {
                                    frmPOS = new frmPOS();
                                    frmPOS.MdiParent = formMDI.MDIObj;
                                    frmPOS.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                            else
                            {
                                frmSalesInvoice = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                                if (frmSalesInvoice == null)
                                {
                                    frmSalesInvoice = new frmSalesInvoice();
                                    frmSalesInvoice.MdiParent = formMDI.MDIObj;
                                    frmSalesInvoice.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                        }
                        else if (strVoucherType == "Purchase Invoice")
                        {
                            PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
                            decMasterId = BllPurchaseInvoice.PurchaseMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            frmPurchaseInvoice objpurchase = new frmPurchaseInvoice();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Credit Note")
                        {
                            CreditNoteBll BllCreditNoteMaster = new CreditNoteBll();
                            decMasterId = BllCreditNoteMaster.CreditNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmCreditNote objpurchase = new frmCreditNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Debit Note")
                        {
                            //DebitNoteMasterSP spDebitNote = new DebitNoteMasterSP();
                            DebitNoteBll bllDebitNote = new DebitNoteBll();
                            decMasterId = bllDebitNote.DebitNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmDebitNote objpurchase = new frmDebitNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AR17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Save function
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         SettingsBll BllSettings = new SettingsBll();
         DateValidation Objdatevalidation = new DateValidation();
         OtherDateValidationFunction ObjotherdateValidation = new OtherDateValidationFunction();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         Objdatevalidation.DateValidationFunction(txtVoucherDate);
         ObjotherdateValidation.DateValidationFunction(txtChequeDate, false);
         DataTable dtblMaster = new DataTable();
         PDCPayableMasterInfo InfoPayable = new PDCPayableMasterInfo();
         PDCPayableBll BllPdcpayable = new PDCPayableBll();
         InfoPayable.VoucherNo = strVoucherNo;
         InfoPayable.InvoiceNo = txtvoucherNo.Text.Trim();
         InfoPayable.Date = DateTime.Parse(txtVoucherDate.Text);
         InfoPayable.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
         InfoPayable.Amount = decimal.Parse(txtAmount.Text);
         InfoPayable.Narration = txtNarration.Text;
         InfoPayable.ChequeNo = txtcheckNo.Text;
         if (txtChequeDate.Text != string.Empty)
             InfoPayable.ChequeDate = Convert.ToDateTime(txtChequeDate.Text);
         else
             InfoPayable.ChequeDate = DateTime.Now;
         InfoPayable.UserId = PublicVariables._decCurrentUserId;
         InfoPayable.VoucherTypeId = decPDCpayableVoucherTypeId;
         if (cmbBank.SelectedValue != null && cmbBank.SelectedValue.ToString() != string.Empty)
         {
             InfoPayable.BankId = Convert.ToDecimal(cmbBank.SelectedValue.ToString());
         }
         else
             InfoPayable.ExtraDate = DateTime.Now;
         InfoPayable.Extra1 = string.Empty;
         InfoPayable.Extra2 = string.Empty;
         if (!isInEditMode)
         {
             decimal decIdentity = BllPdcpayable.PDCPayableMasterAdd(InfoPayable);
             LedgerPosting();
             PartyBalanceAddOrEdit();
             Messages.SavedMessage();
             if (cbxPrint.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decIdentity);
                 }
                 else
                 {
                     Print(decIdentity);
                 }
             }
             ClearFunction();
         }
         else
         {
             decimal decIdentity = decPDCpayableEditId;
             InfoPayable.PdcPayableMasterId = decPDCpayableEditId;
             BllPdcpayable.PDCPayableMasterEdit(InfoPayable);
             LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
             BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPDCpayableVoucherTypeId, 12);
             BllPartyBalance.PartyBalanceDeleteByVoucherTypeAndVoucherNo(decPDCpayableVoucherTypeId, strVoucherNo);
             PartyBalanceAddOrEdit();
             LedgerPostingEdit(decPDCpayableEditId);
             Messages.UpdatedMessage();
             if (cbxPrint.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decIdentity);
                 }
                 else
                 {
                     Print(decIdentity);
                 }
             }
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP7:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }