Example #1
0
        /// <summary>
        /// Function to edit partybalance based on VoucherNo, VoucherTypeId And ReferenceType
        /// </summary>
        /// <param name="infoPartyBalance"></param>
        public void PartyBalanceEditByVoucherNoVoucherTypeIdAndReferenceType(PartyBalanceInfo infoPartyBalance)
        {
            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("PartyBalanceEditByVoucherNoVoucherTypeIdAndReferenceType", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();

                sprmparam       = sccmd.Parameters.Add("@date", SqlDbType.DateTime);
                sprmparam.Value = infoPartyBalance.Date;
                sprmparam       = sccmd.Parameters.Add("@ledgerId", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.LedgerId;
                sprmparam       = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.VoucherTypeId;
                sprmparam       = sccmd.Parameters.Add("@voucherNo", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.VoucherNo;
                sprmparam       = sccmd.Parameters.Add("@againstVoucherTypeId", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.AgainstVoucherTypeId;
                sprmparam       = sccmd.Parameters.Add("@againstVoucherNo", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.AgainstVoucherNo;
                sprmparam       = sccmd.Parameters.Add("@invoiceNo", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.InvoiceNo;
                sprmparam       = sccmd.Parameters.Add("@againstInvoiceNo", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.AgainstInvoiceNo;
                sprmparam       = sccmd.Parameters.Add("@referenceType", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.ReferenceType;
                sprmparam       = sccmd.Parameters.Add("@debit", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.Debit;
                sprmparam       = sccmd.Parameters.Add("@credit", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.Credit;
                sprmparam       = sccmd.Parameters.Add("@creditPeriod", SqlDbType.Int);
                sprmparam.Value = infoPartyBalance.CreditPeriod;
                sprmparam       = sccmd.Parameters.Add("@exchangeRateId", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.ExchangeRateId;
                sprmparam       = sccmd.Parameters.Add("@financialYearId", SqlDbType.Decimal);
                sprmparam.Value = infoPartyBalance.FinancialYearId;
                sprmparam       = sccmd.Parameters.Add("@extraDate", SqlDbType.DateTime);
                sprmparam.Value = infoPartyBalance.ExtraDate;
                sprmparam       = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.Extra1;
                sprmparam       = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
                sprmparam.Value = infoPartyBalance.Extra2;
                sccmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sqlcon.Close();
            }
        }
Example #2
0
 /// <summary>
 /// Function to insert values to PartyBalance Table
 /// </summary>
 /// <param name="partybalanceinfo"></param>
 public void PartyBalanceAdd(PartyBalanceInfo partybalanceinfo)
 {
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PartyBalanceAdd", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         
         sprmparam = sccmd.Parameters.Add("@date", SqlDbType.DateTime);
         sprmparam.Value = partybalanceinfo.Date;
         sprmparam = sccmd.Parameters.Add("@ledgerId", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.LedgerId;
         sprmparam = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.VoucherTypeId;
         sprmparam = sccmd.Parameters.Add("@voucherNo", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.VoucherNo;
         sprmparam = sccmd.Parameters.Add("@againstVoucherTypeId", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.AgainstVoucherTypeId;
         sprmparam = sccmd.Parameters.Add("@againstVoucherNo", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.AgainstVoucherNo;
         sprmparam = sccmd.Parameters.Add("@invoiceNo", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.InvoiceNo;
         sprmparam = sccmd.Parameters.Add("@againstInvoiceNo", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.AgainstInvoiceNo;
         sprmparam = sccmd.Parameters.Add("@referenceType", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.ReferenceType;
         sprmparam = sccmd.Parameters.Add("@debit", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.Debit;
         sprmparam = sccmd.Parameters.Add("@credit", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.Credit;
         sprmparam = sccmd.Parameters.Add("@creditPeriod", SqlDbType.Int);
         sprmparam.Value = partybalanceinfo.CreditPeriod;
         sprmparam = sccmd.Parameters.Add("@exchangeRateId", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.ExchangeRateId;
         sprmparam = sccmd.Parameters.Add("@financialYearId", SqlDbType.Decimal);
         sprmparam.Value = partybalanceinfo.FinancialYearId;
         sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.Extra1;
         sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
         sprmparam.Value = partybalanceinfo.Extra2;
         int inEffect = sccmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
 }
Example #3
0
        /// <summary>
        /// Function to get particular values from PartyBalance table based on the parameter
        /// </summary>
        /// <param name="partyBalanceId"></param>
        /// <returns></returns>
        public PartyBalanceInfo PartyBalanceView(decimal partyBalanceId)
        {
            PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
            SqlDataReader    sdrreader        = null;

            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("PartyBalanceView", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();
                sprmparam       = sccmd.Parameters.Add("@partyBalanceId", SqlDbType.Decimal);
                sprmparam.Value = partyBalanceId;
                sdrreader       = sccmd.ExecuteReader();
                while (sdrreader.Read())
                {
                    partybalanceinfo.PartyBalanceId       = decimal.Parse(sdrreader[0].ToString());
                    partybalanceinfo.Date                 = DateTime.Parse(sdrreader[1].ToString());
                    partybalanceinfo.LedgerId             = decimal.Parse(sdrreader[2].ToString());
                    partybalanceinfo.VoucherTypeId        = decimal.Parse(sdrreader[3].ToString());
                    partybalanceinfo.VoucherNo            = sdrreader[4].ToString();
                    partybalanceinfo.AgainstVoucherTypeId = decimal.Parse(sdrreader[5].ToString());
                    partybalanceinfo.AgainstVoucherNo     = sdrreader[6].ToString();
                    partybalanceinfo.InvoiceNo            = sdrreader[7].ToString();
                    partybalanceinfo.AgainstInvoiceNo     = sdrreader[8].ToString();
                    partybalanceinfo.ReferenceType        = sdrreader[9].ToString();
                    partybalanceinfo.Debit                = decimal.Parse(sdrreader[10].ToString());
                    partybalanceinfo.Credit               = decimal.Parse(sdrreader[11].ToString());
                    partybalanceinfo.CreditPeriod         = int.Parse(sdrreader[12].ToString());
                    partybalanceinfo.ExchangeRateId       = decimal.Parse(sdrreader[13].ToString());
                    partybalanceinfo.FinancialYearId      = decimal.Parse(sdrreader[14].ToString());
                    partybalanceinfo.ExtraDate            = DateTime.Parse(sdrreader[15].ToString());
                    partybalanceinfo.Extra1               = sdrreader[16].ToString();
                    partybalanceinfo.Extra2               = sdrreader[17].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sdrreader.Close();
                sqlcon.Close();
            }
            return(partybalanceinfo);
        }
Example #4
0
 /// <summary>
 /// Function to fill datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         PartyBalanceInfo infoPartyBalance     = new PartyBalanceInfo();
         PartyBalanceSP   SpPartyBalance       = new PartyBalanceSP();
         DataTable        dtbl                 = new DataTable();
         decimal          decVoucherTypeId     = 0;
         decimal          decVoucherTypeNameId = 0;
         decVoucherTypeId     = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decVoucherTypeNameId = Convert.ToDecimal(cmbVoucherTypeName.SelectedValue.ToString());
         dtbl = SpPartyBalance.AgainstBillDetailsGridViewByLedgerId(decledgerId, strDebitOrCredit, decVoucherTypeId, decVoucherTypeNameId);
         dgvAgainstBillDetails.DataSource = dtbl;
     }
     catch (Exception ex)
     {
         formMDI.infoError.ErrorString = "AB3:" + ex.Message;
     }
 }
 /// <summary>
 /// Function to fill datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         PartyBalanceInfo infoPartyBalance     = new PartyBalanceInfo();
         PartyBalanceBll  BllPartyBalance      = new PartyBalanceBll();
         List <DataTable> listObj              = new List <DataTable>();
         decimal          decVoucherTypeId     = 0;
         decimal          decVoucherTypeNameId = 0;
         decVoucherTypeId     = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decVoucherTypeNameId = Convert.ToDecimal(cmbVoucherTypeName.SelectedValue.ToString());
         listObj = BllPartyBalance.AgainstBillDetailsGridViewByLedgerId(decledgerId, strDebitOrCredit, decVoucherTypeId, decVoucherTypeNameId);
         dgvAgainstBillDetails.DataSource = listObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("AB3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #6
0
        /// <summary>
        /// Function to fill againstbill details by ledgerId
        /// </summary>
        /// <param name="decLedgerId"></param>
        /// <param name="strCrDr"></param>
        /// <param name="decVoucherTypeId"></param>
        /// <param name="decVoucherTypeNameId"></param>
        /// <returns></returns>
        public DataTable AgainstBillDetailsGridViewByLedgerId(decimal decLedgerId, string strCrDr, decimal decVoucherTypeId, decimal decVoucherTypeNameId)
        {
            PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
            DataTable        dtbl             = new DataTable();

            dtbl.Columns.Add("SL.NO", typeof(decimal));
            dtbl.Columns["SL.NO"].AutoIncrement     = true;
            dtbl.Columns["SL.NO"].AutoIncrementSeed = 1;
            dtbl.Columns["SL.NO"].AutoIncrementStep = 1;
            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("AgainstBillDetailsGridViewByLedgerId", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();
                sprmparam       = sccmd.Parameters.Add("@ledgerId", SqlDbType.Decimal);
                sprmparam.Value = decLedgerId;
                sprmparam       = sccmd.Parameters.Add("@crOrDr", SqlDbType.VarChar);
                sprmparam.Value = strCrDr;
                sprmparam       = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
                sprmparam.Value = decVoucherTypeId;
                sprmparam       = sccmd.Parameters.Add("@voucherTypeNameId", SqlDbType.Decimal);
                sprmparam.Value = decVoucherTypeNameId;
                SqlDataAdapter sdaadapter = new SqlDataAdapter();
                sdaadapter.SelectCommand = sccmd;
                sdaadapter.Fill(dtbl);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sqlcon.Close();
            }
            return(dtbl);
        }
Example #7
0
        /// <summary>
        /// Function to get particular values from PartyBalance table based on vouchertype and voucherno
        /// </summary>
        /// <param name="decVoucherTypeId"></param>
        /// <param name="strVoucherNo"></param>
        /// <returns></returns>
        public PartyBalanceInfo PartyBalanceViewByVoucherNoAndVoucherTypeId(decimal decVoucherTypeId, string strVoucherNo, DateTime dtDate)
        {
            PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
            SqlDataReader    sdrreader        = null;

            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("PartyBalanceViewByVoucherNoAndVoucherType", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();
                sprmparam       = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
                sprmparam.Value = decVoucherTypeId;
                sprmparam       = sccmd.Parameters.Add("@voucherNo", SqlDbType.VarChar);
                sprmparam.Value = strVoucherNo;
                sprmparam       = sccmd.Parameters.Add("@date", SqlDbType.DateTime);
                sprmparam.Value = dtDate;
                sdrreader       = sccmd.ExecuteReader();
                while (sdrreader.Read())
                {
                    partybalanceinfo.PartyBalanceId = decimal.Parse(sdrreader[0].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sqlcon.Close();
            }
            return(partybalanceinfo);
        }
Example #8
0
        /// <summary>
        /// Function to edit the partybalance
        /// </summary>
        /// <param name="decPartyBalanceId"></param>
        /// <param name="inRowIndex"></param>
        /// <param name="inJ"></param>
        public void PartyBalanceEdit(decimal decPartyBalanceId, int inRowIndex, int inJ)
        {

            PartyBalanceSP spPartyBalance = new PartyBalanceSP();
            PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
            try
            {

                InfopartyBalance.PartyBalanceId = decPartyBalanceId;
                InfopartyBalance.CreditPeriod = 0;//
                InfopartyBalance.Date = dtpVoucherDate.Value;
                InfopartyBalance.LedgerId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["LedgerId"].ToString());
                InfopartyBalance.ReferenceType = dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString();
                if (dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "New" || dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "OnAccount")
                {
                    InfopartyBalance.AgainstInvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                    InfopartyBalance.AgainstVoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.AgainstVoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());//decPaymentVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = decJournalVoucherTypeId;
                    InfopartyBalance.InvoiceNo = strInvoiceNo;
                    InfopartyBalance.VoucherNo = strVoucherNo;
                }
                else
                {
                    InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["OldExchangeRate"].ToString());
                    InfopartyBalance.AgainstInvoiceNo = strInvoiceNo;
                    InfopartyBalance.AgainstVoucherNo = strVoucherNo;
                    InfopartyBalance.AgainstVoucherTypeId = decJournalVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());
                    InfopartyBalance.VoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.InvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                }
                if (dgvJournalVoucher.Rows[inRowIndex].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                {
                    InfopartyBalance.Debit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                    InfopartyBalance.Credit = 0;
                }
                else
                {
                    InfopartyBalance.Credit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                    InfopartyBalance.Debit = 0;
                }
                InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["CurrencyId"].ToString());
                InfopartyBalance.Extra1 = string.Empty;
                InfopartyBalance.Extra2 = string.Empty;
                InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                spPartyBalance.PartyBalanceEdit(InfopartyBalance);

            }
            catch (Exception ex)
            {
                MessageBox.Show("JV23:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #9
0
 /// <summary>
 /// Fill function for edit
 /// </summary>
 public void SalesInvoiceDetailsEditFill()
 {
     SalesMasterSP spSalesMaster = new SalesMasterSP();
     SalesDetailsSP spSalesDetails = new SalesDetailsSP();
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     SalesDetailsInfo InfoSalesDetails = new SalesDetailsInfo();
     StockPostingInfo infoStockPosting = new StockPostingInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     StockPostingSP spStockPosting = new StockPostingSP();
     PartyBalanceSP spPartyBalance = new PartyBalanceSP();
     AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo();
     AdditionalCostSP spAdditionalCost = new AdditionalCostSP();
     SalesBillTaxSP spSalesBillTax = new SalesBillTaxSP();
     SalesBillTaxInfo infoSalesBillTax = new SalesBillTaxInfo();
     UnitConvertionSP SPUnitConversion = new UnitConvertionSP();
     try
     {
         string strAgainstInvoiceN0 = txtInvoiceNo.Text.Trim();
         for (int inI = 0; inI < dgvSalesInvoice.Rows.Count - 1; inI++)
         {
             decimal decRefStatus = spSalesMaster.SalesInvoiceReferenceCheckForEdit(decSalesInvoiceIdToEdit);
             if (decRefStatus != 0)
             {
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductCode"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceBarcode"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].ReadOnly = true;
                 dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].ReadOnly = true;
             }
             if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value == null || dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() == string.Empty || dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() == "0")   // here check the  row added or editing current row
             {
                 InfoSalesDetails.SalesMasterId = decSalesInvoiceIdToEdit;
                 InfoSalesDetails.ExtraDate = DateTime.Now;
                 InfoSalesDetails.Extra1 = string.Empty;
                 InfoSalesDetails.Extra2 = string.Empty;
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductName"].Value.ToString() != string.Empty)
                 {
                     if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty)
                     {
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value != null)
                         {
                             InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.OrderDetailsId = 0;
                         }
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
                         {
                             InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.DeliveryNoteDetailsId = 0;
                         }
                         if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value != null)
                         {
                             InfoSalesDetails.QuotationDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value.ToString());
                         }
                         else
                         {
                             InfoSalesDetails.QuotationDetailsId = 0;
                         }
                         InfoSalesDetails.SlNo = Convert.ToInt32(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSlno"].Value.ToString());
                         InfoSalesDetails.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
                         decimal decQty = spSalesMaster.SalesInvoiceQuantityDetailsAgainstSalesReturn(DecSalesInvoiceVoucherTypeId, strVoucherNo);
                         if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString()) < decQty)
                         {
                             dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value = 0;
                             decRefStatus = 1;
                             MessageBox.Show("Quantity should be greater than " + decQty, "Open_Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvSalesInvoice.Focus();
                         }
                         else
                         {
                             InfoSalesDetails.Qty = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString());
                             InfoSalesDetails.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
                             InfoSalesDetails.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
                             InfoSalesDetails.UnitConversionId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value.ToString());
                             InfoSalesDetails.Discount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value.ToString());
                             if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
                             {
                                 InfoSalesDetails.TaxId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceTaxName"].Value.ToString());
                                 InfoSalesDetails.TaxAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceTaxAmount"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.TaxId = 0;
                                 InfoSalesDetails.TaxAmount = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.BatchId = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.GodownId = 0;
                             }
                             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
                             {
                                 InfoSalesDetails.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
                             }
                             else
                             {
                                 InfoSalesDetails.RackId = 0;
                             }
                             InfoSalesDetails.GrossAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString());
                             InfoSalesDetails.NetAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceNetAmount"].Value.ToString());
                             InfoSalesDetails.Amount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceAmount"].Value.ToString());
                             spSalesDetails.SalesDetailsAdd(InfoSalesDetails);
                         }
                     }
                 }
             }
             else
             {
                 InfoSalesDetails.SalesMasterId = decSalesInvoiceIdToEdit;
                 InfoSalesDetails.SalesDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value);
                 InfoSalesDetails.SlNo = Convert.ToInt32(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceSlno"].Value.ToString());
                 InfoSalesDetails.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
                 InfoSalesDetails.Qty = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQty"].Value.ToString());
                 InfoSalesDetails.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
                 InfoSalesDetails.UnitConversionId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value.ToString());
                 InfoSalesDetails.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
                 InfoSalesDetails.Discount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value.ToString());
                 if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
                 {
                     InfoSalesDetails.TaxId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceTaxName"].Value.ToString());
                     InfoSalesDetails.TaxAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceTaxAmount"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.TaxId = 0;
                     InfoSalesDetails.TaxAmount = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.BatchId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
                     RackComboFill(InfoSalesDetails.GodownId, inI, dgvSalesInvoice.Columns["dgvcmbSalesInvoiceRack"].Index);
                 }
                 else
                 {
                     InfoSalesDetails.GodownId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
                 {
                     InfoSalesDetails.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.RackId = 0;
                 }
                 InfoSalesDetails.GrossAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString());
                 InfoSalesDetails.NetAmount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceNetAmount"].Value.ToString());
                 InfoSalesDetails.Amount = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceAmount"].Value.ToString());
                 InfoSalesDetails.ExtraDate = DateTime.Now;
                 InfoSalesDetails.Extra1 = string.Empty;
                 InfoSalesDetails.Extra2 = string.Empty;
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value != null)
                 {
                     InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.OrderDetailsId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
                 {
                     InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.DeliveryNoteDetailsId = 0;
                 }
                 if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value != null)
                 {
                     InfoSalesDetails.QuotationDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value.ToString());
                 }
                 else
                 {
                     InfoSalesDetails.QuotationDetailsId = 0;
                 }
                 spSalesDetails.SalesDetailsEdit(InfoSalesDetails);
             }
             infoStockPosting.Date = Convert.ToDateTime(txtDate.Text.Trim().ToString());
             infoStockPosting.ProductId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString());
             infoStockPosting.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString());
             infoStockPosting.UnitId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString());
             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString() != string.Empty)
             {
                 infoStockPosting.GodownId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceGodown"].Value.ToString());
             }
             else
             {
                 infoStockPosting.GodownId = 0;
             }
             if (dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value != null && dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString() != string.Empty)
             {
                 infoStockPosting.RackId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceRack"].Value.ToString());
             }
             else
             {
                 infoStockPosting.RackId = 0;
             }
             if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value) == 0)
             {
                 decimal decResult = spStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote(0, "NA", strVoucherNo, DecSalesInvoiceVoucherTypeId);
             }
             else
             {
                 decimal decResult = spStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote(DecSalesInvoiceVoucherTypeId, strVoucherNo, strVoucherNoTostockPost, decVouchertypeIdTostockPost);
             }
             infoStockPosting.Rate = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceRate"].Value.ToString());
             infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoStockPosting.ExtraDate = DateTime.Now;
             infoStockPosting.Extra1 = string.Empty;
             infoStockPosting.Extra2 = string.Empty;
             if (dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null)
             {
                 if (Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString()) != 0)
                 {
                     infoStockPosting.InwardQty = InfoSalesDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(InfoSalesDetails.UnitConversionId);
                     infoStockPosting.OutwardQty = 0;
                     infoStockPosting.VoucherNo = strVoucherNoTostockPost;
                     infoStockPosting.AgainstVoucherNo = strVoucherNo;
                     infoStockPosting.InvoiceNo = strInvoiceNoTostockPost;
                     infoStockPosting.AgainstInvoiceNo = strAgainstInvoiceN0;
                     infoStockPosting.VoucherTypeId = decVouchertypeIdTostockPost;
                     infoStockPosting.AgainstVoucherTypeId = DecSalesInvoiceVoucherTypeId;
                     spStockPosting.StockPostingAdd(infoStockPosting);
                 }
             }
             infoStockPosting.InwardQty = 0;
             infoStockPosting.OutwardQty = InfoSalesDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(InfoSalesDetails.UnitConversionId);
             infoStockPosting.VoucherNo = strVoucherNo;
             infoStockPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoStockPosting.InvoiceNo = strAgainstInvoiceN0;
             infoStockPosting.AgainstInvoiceNo = "NA";
             infoStockPosting.AgainstVoucherNo = "NA";
             infoStockPosting.AgainstVoucherTypeId = 0;
             spStockPosting.StockPostingAdd(infoStockPosting);
         }
         int inAddRowCount = dgvSalesInvoiceLedger.RowCount;
         infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         if (isAutomatic)
         {
             infoAdditionalCost.VoucherNo = strVoucherNo;
         }
         else
         {
             infoAdditionalCost.VoucherNo = txtInvoiceNo.Text;
         }
         infoAdditionalCost.ExtraDate = DateTime.Now;
         infoAdditionalCost.Extra1 = string.Empty;
         infoAdditionalCost.Extra2 = string.Empty;
         for (int inIAdc = 0; inIAdc < inAddRowCount; inIAdc++)
         {
             if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty)
             {
                 if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString() != string.Empty)
                 {
                     infoAdditionalCost.LedgerId = Convert.ToInt32(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString());
                     if (cmbDrorCr.SelectedItem.ToString() != "Dr")
                     {
                         infoAdditionalCost.Debit = 0;
                         infoAdditionalCost.Credit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                     }
                     else
                     {
                         infoAdditionalCost.Debit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString());
                         infoAdditionalCost.Credit = 0;
                     }
                     if (dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCostId"].Value != null && dgvSalesInvoiceLedger.Rows[inIAdc].Cells["dgvtxtAdditionalCostId"].Value.ToString() != string.Empty)
                     {
                         spAdditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
                     }
                     else
                     {
                         spAdditionalCost.AdditionalCostAdd(infoAdditionalCost);
                     }
                 }
             }
         }
         if (cmbDrorCr.SelectedItem.ToString() != "Dr")               // here we are debit the cash or bank
         {
             decimal decCAshOrPartyId = 0;
             decCAshOrPartyId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
             decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
             infoAdditionalCost.Debit = decTotalAddAmount;
             infoAdditionalCost.Credit = 0;
             infoAdditionalCost.LedgerId = decCAshOrPartyId;
             infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoAdditionalCost.VoucherNo = strVoucherNo;
             infoAdditionalCost.ExtraDate = DateTime.Now;
             infoAdditionalCost.Extra1 = string.Empty;
             infoAdditionalCost.Extra2 = string.Empty;
             spAdditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
         }
         else
         {
             decimal decCAshOrBankId = 0;                    // here we are credit the cash or bank
             decCAshOrBankId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString());
             decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString());
             infoAdditionalCost.Debit = 0;
             infoAdditionalCost.Credit = decTotalAddAmount;
             infoAdditionalCost.LedgerId = decCAshOrBankId;
             infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoAdditionalCost.VoucherNo = strVoucherNo;
             infoAdditionalCost.ExtraDate = DateTime.Now;
             infoAdditionalCost.Extra1 = string.Empty;
             infoAdditionalCost.Extra2 = string.Empty;
             spAdditionalCost.AdditionalCostEditByVoucherTypeIdAndVoucherNo(infoAdditionalCost);
         }
         removeSalesInvoiceAdditionalDetails();
         if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible)
         {
             int inTaxRowCount = dgvSalesInvoiceTax.RowCount;
             infoSalesBillTax.SalesMasterId = decSalesInvoiceIdToEdit;
             infoSalesBillTax.ExtraDate = DateTime.Now;
             infoSalesBillTax.Extra1 = string.Empty;
             infoSalesBillTax.Extra2 = string.Empty;
             for (int inTax = 0; inTax < inTaxRowCount; inTax++)
             {
                 if (dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value != null && dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty)
                 {
                     if (dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value != null && dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value.ToString() != string.Empty)
                     {
                         decimal decAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value);
                         if (decAmount > 0)
                         {
                             infoSalesBillTax.TaxId = Convert.ToInt32(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxId"].Value.ToString());
                             infoSalesBillTax.TaxAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inTax].Cells["dgvtxtTtaxAmount"].Value.ToString());
                             spSalesBillTax.SalesBillTaxEditBySalesMasterIdAndTaxId(infoSalesBillTax);
                         }
                     }
                 }
             }
         }
         if (spSalesMaster.SalesInvoiceInvoicePartyCheckEnableBillByBillOrNot(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString())))
         {
             infoPartyBalance.Date = Convert.ToDateTime(txtDate.Text.ToString());
             infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
             infoPartyBalance.VoucherNo = strVoucherNo;
             infoPartyBalance.InvoiceNo = txtInvoiceNo.Text.Trim();
             infoPartyBalance.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
             infoPartyBalance.AgainstVoucherTypeId = 0;
             infoPartyBalance.AgainstVoucherNo = "0";
             infoPartyBalance.AgainstInvoiceNo = "0";
             infoPartyBalance.ReferenceType = "New";
             infoPartyBalance.Debit = Convert.ToDecimal(txtGrandTotal.Text.Trim().ToString());
             decimal decBalAmount = spSalesDetails.SalesInvoiceReciptVoucherDetailsAgainstSI(DecSalesInvoiceVoucherTypeId, strVoucherNo);
             decimal decCurrentAmount = Convert.ToDecimal(txtGrandTotal.Text.ToString());
             if (decCurrentAmount < decBalAmount)
             {
                 MessageBox.Show("Amount should be greater than " + decBalAmount, "Open_Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 dgvSalesInvoice.Focus();
             }
             else
             {
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.ToString());
                 infoPartyBalance.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue);
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.ExtraDate = DateTime.Now;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 spPartyBalance.PartyBalanceEditByVoucherNoVoucherTypeIdAndReferenceType(infoPartyBalance);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 81" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
         PartyBalanceSP SpPartyBalance = new PartyBalanceSP();
         DataTable dtbl = new DataTable();
         decimal decVoucherTypeId =0;
         decimal decVoucherTypeNameId=0;
         decVoucherTypeId = Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString());
         decVoucherTypeNameId = Convert.ToDecimal(cmbVoucherTypeName.SelectedValue.ToString()); 
         dtbl = SpPartyBalance.AgainstBillDetailsGridViewByLedgerId(decledgerId, strDebitOrCredit, decVoucherTypeId, decVoucherTypeNameId);
         dgvAgainstBillDetails.DataSource = dtbl;
     }
     catch (Exception ex)
     {
         MessageBox.Show("AB3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #11
0
 /// <summary>
 /// Function to get particular values from PartyBalance table based on vouchertype and voucherno
 /// </summary>
 /// <param name="decVoucherTypeId"></param>
 /// <param name="strVoucherNo"></param>
 /// <returns></returns>
 public PartyBalanceInfo PartyBalanceViewByVoucherNoAndVoucherTypeId(decimal decVoucherTypeId, string strVoucherNo,DateTime dtDate)
 {
     PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
     SqlDataReader sdrreader = null;
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PartyBalanceViewByVoucherNoAndVoucherType", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
         sprmparam.Value = decVoucherTypeId;
         sprmparam = sccmd.Parameters.Add("@voucherNo", SqlDbType.VarChar);
         sprmparam.Value = strVoucherNo;
         sprmparam = sccmd.Parameters.Add("@date", SqlDbType.DateTime);
         sprmparam.Value = dtDate;
         sdrreader = sccmd.ExecuteReader();
         while (sdrreader.Read())
         {
             partybalanceinfo.PartyBalanceId = decimal.Parse(sdrreader[0].ToString());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
     return partybalanceinfo;
 }
Example #12
0
 /// <summary>
 /// Party balance save function
 /// </summary>
 public void partyBalanceAdd()
 {
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     SalesMasterInfo InfoSalesMaster = new SalesMasterInfo();
     PartyBalanceSP spPartyBalance = new PartyBalanceSP();
     try
     {
         infoPartyBalance.Date = Convert.ToDateTime(txtDate.Text.ToString());
         infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoPartyBalance.VoucherNo = strVoucherNo;
         infoPartyBalance.InvoiceNo = txtInvoiceNo.Text.Trim();
         infoPartyBalance.VoucherTypeId = DecSalesInvoiceVoucherTypeId;
         infoPartyBalance.AgainstVoucherTypeId = 0;
         infoPartyBalance.AgainstVoucherNo = "0";
         infoPartyBalance.AgainstInvoiceNo = "0";
         infoPartyBalance.ReferenceType = "New";
         infoPartyBalance.Debit = Convert.ToDecimal(txtGrandTotal.Text.Trim().ToString());
         infoPartyBalance.Credit = 0;
         infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.ToString());
         infoPartyBalance.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoPartyBalance.ExtraDate = DateTime.Now;
         infoPartyBalance.Extra1 = string.Empty;
         infoPartyBalance.Extra2 = string.Empty;
         spPartyBalance.PartyBalanceAdd(infoPartyBalance);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 72" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #13
0
 /// <summary>
 /// Function to save the service voucher
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceMasterSP spServiceMaster = new ServiceMasterSP();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServiceDetailsSP spServiceDetails = new ServiceDetailsSP();
         LedgerPostingSP spLedgerPosting = new LedgerPostingSP();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateSP spExchangeRate = new ExchangeRateSP();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             txtDiscount.Enabled = true;
             infoServiceMaster.InvoiceNo = txtInvoiceNumber.Text;
             if (isAutomatic)
             {
                 infoServiceMaster.VoucherNo = strVoucherNo;
             }
             else
             {
                 infoServiceMaster.VoucherNo = Convert.ToString(spServiceMaster.ServiceMasterGetMax(DecServicetVoucherTypeId) + 1);
             }
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text.Trim());
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             decServiceMasterId = spServiceMaster.ServiceMasterAddReturnWithIdentity(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     decAmount += Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                 }
                 decServiceDetailsId = spServiceDetails.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
             }
             decSelectedCurrencyRate = spExchangeRate.GetExchangeRateByExchangeRateId(infoServiceMaster.ExchangeRateId);
             decConvertRate = decAmount * decSelectedCurrencyRate;
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPosting(decLedgerId, decCredit, decDebit, decServiceDetailsId, infoServiceMaster.VoucherNo);
             AccountLedgerSP spAccountLedger = new AccountLedgerSP();
             decimal decI = Convert.ToDecimal(spAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceSP spPartyBalance = new PartyBalanceSP();
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 spPartyBalance.PartyBalanceAdd(infoPartyBalance);
             }
             Messages.SavedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             Clear();
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
             dgvServiceVoucher.ClearSelection();
             dgvServiceVoucher.CurrentCell = dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"];
             dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"].Selected = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 19 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #14
0
 /// <summary>
 /// Function to fill againstbill details by ledgerId
 /// </summary>
 /// <param name="decLedgerId"></param>
 /// <param name="strCrDr"></param>
 /// <param name="decVoucherTypeId"></param>
 /// <param name="decVoucherTypeNameId"></param>
 /// <returns></returns>
 public DataTable AgainstBillDetailsGridViewByLedgerId(decimal decLedgerId, string strCrDr, decimal decVoucherTypeId, decimal decVoucherTypeNameId)
 {
     PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
     DataTable dtbl = new DataTable();
     dtbl.Columns.Add("SL.NO", typeof(decimal));
     dtbl.Columns["SL.NO"].AutoIncrement = true;
     dtbl.Columns["SL.NO"].AutoIncrementSeed = 1;
     dtbl.Columns["SL.NO"].AutoIncrementStep = 1;
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("AgainstBillDetailsGridViewByLedgerId", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@ledgerId", SqlDbType.Decimal);
         sprmparam.Value = decLedgerId;
         sprmparam = sccmd.Parameters.Add("@crOrDr", SqlDbType.VarChar);
         sprmparam.Value = strCrDr;
         sprmparam = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
         sprmparam.Value = decVoucherTypeId;
         sprmparam = sccmd.Parameters.Add("@voucherTypeNameId", SqlDbType.Decimal);
         sprmparam.Value = decVoucherTypeNameId;
         SqlDataAdapter sdaadapter = new SqlDataAdapter();
         sdaadapter.SelectCommand = sccmd;
         sdaadapter.Fill(dtbl);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
     return dtbl;
 }
Example #15
0
 /// <summary>
 /// Function to call frmPdcPayable form to set amount for sundry creditors or sundry debtors
 /// </summary>
 /// <param name="frmPDC"></param>
 /// <param name="decId"></param>
 /// <param name="dtblPartyBalance"></param>
 /// <param name="decPdcPayableVoucherTypeId"></param>
 /// <param name="strVoucherNo"></param>
 /// <param name="date"></param>
 public void CallThisFormFromPDCPayable(frmPdcPayable frmPDC, decimal decId, DataTable dtblPartyBalance, decimal decPdcPayableVoucherTypeId, string strVoucherNo, DateTime date)
 {
     try
     {
         decVoucherTypeId = decPdcPayableVoucherTypeId;
         this.strVoucherNo = strVoucherNo;
         decLedgerId = decId;
         this.dtblPartyBalance = dtblPartyBalance;
         strDebitOrCredit = "Dr";
         base.Show();
         this.frmPdcpayableObj = frmPDC;
         frmPdcpayableObj.Enabled = false;
         int inTableRowCount = dtblPartyBalance.Rows.Count;
         PartyBalanceSP SpPartyBalance = new PartyBalanceSP();
         PartyBalanceInfo InfoPartyBalance = new PartyBalanceInfo();
         DataTable dtbl = new DataTable();
         if (inTableRowCount > 0)
         {
             int inK = 0;
             for (int inI = 0; inI < inTableRowCount; inI++)
             {
                 if (decLedgerId == Convert.ToDecimal(dtblPartyBalance.Rows[inI]["LedgerId"].ToString()))
                 {
                     if (strDebitOrCredit == dtblPartyBalance.Rows[inI]["DebitOrCredit"].ToString())
                     {
                         dgvPartyBalance.Rows.Add();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value = dtblPartyBalance.Rows[inI]["ReferenceType"].ToString();
                         if (dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value.ToString() == "Against")
                         {
                             //----------------------------------------------------------------------------//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].ReadOnly = false;
                             dtbl = SpPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                             DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbVoucherType"].Index, dgvPartyBalance.CurrentRow.Index - 1];
                             dgvccVoucherType.DataSource = dtbl;
                             dgvccVoucherType.ValueMember = "value";
                             dgvccVoucherType.DisplayMember = "display";
                             //============================================================================//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherTypeId"].ToString() + "_" + dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtVoucherNo"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtInvoiceNo"].Value = dtblPartyBalance.Rows[inI]["AgainstInvoiceNo"].ToString();
                             if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() != string.Empty)
                             {
                                 for (int inD = 0; inD < dtbl.Rows.Count; inD++)
                                 {
                                     if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() == dtbl.Rows[inD]["value"].ToString())
                                     {
                                         dgvPartyBalance.Rows[inK].Cells["dgvtxtpending"].Value = Math.Round(Convert.ToDecimal(dtbl.Rows[inD]["balance"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                         break;
                                     }
                                 }
                             }
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].ReadOnly = true;
                         }
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtAmount"].Value = Math.Round(Convert.ToDecimal(dtblPartyBalance.Rows[inI]["Amount"].ToString()), Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces)).ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtblPartyBalance.Rows[inI]["CurrencyId"].ToString());
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtPartyBalanceId"].Value = dtblPartyBalance.Rows[inI]["partyBalanceId"].ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtOldExchangeRateId"].Value = dtblPartyBalance.Rows[inI]["OldExchangeRate"].ToString();
                         inK++;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:12" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #16
0
 /// <summary>
 /// Function to get particular values from PartyBalance table based on the parameter
 /// </summary>
 /// <param name="partyBalanceId"></param>
 /// <returns></returns>
 public PartyBalanceInfo PartyBalanceView(decimal partyBalanceId)
 {
     PartyBalanceInfo partybalanceinfo = new PartyBalanceInfo();
     SqlDataReader sdrreader = null;
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PartyBalanceView", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@partyBalanceId", SqlDbType.Decimal);
         sprmparam.Value = partyBalanceId;
         sdrreader = sccmd.ExecuteReader();
         while (sdrreader.Read())
         {
             partybalanceinfo.PartyBalanceId = decimal.Parse(sdrreader[0].ToString());
             partybalanceinfo.Date = DateTime.Parse(sdrreader[1].ToString());
             partybalanceinfo.LedgerId = decimal.Parse(sdrreader[2].ToString());
             partybalanceinfo.VoucherTypeId = decimal.Parse(sdrreader[3].ToString());
             partybalanceinfo.VoucherNo = sdrreader[4].ToString();
             partybalanceinfo.AgainstVoucherTypeId = decimal.Parse(sdrreader[5].ToString());
             partybalanceinfo.AgainstVoucherNo = sdrreader[6].ToString();
             partybalanceinfo.InvoiceNo = sdrreader[7].ToString();
             partybalanceinfo.AgainstInvoiceNo = sdrreader[8].ToString();
             partybalanceinfo.ReferenceType = sdrreader[9].ToString();
             partybalanceinfo.Debit = decimal.Parse(sdrreader[10].ToString());
             partybalanceinfo.Credit = decimal.Parse(sdrreader[11].ToString());
             partybalanceinfo.CreditPeriod = int.Parse(sdrreader[12].ToString());
             partybalanceinfo.ExchangeRateId = decimal.Parse(sdrreader[13].ToString());
             partybalanceinfo.FinancialYearId = decimal.Parse(sdrreader[14].ToString());
             partybalanceinfo.ExtraDate = DateTime.Parse(sdrreader[15].ToString());
             partybalanceinfo.Extra1 = sdrreader[16].ToString();
             partybalanceinfo.Extra2 = sdrreader[17].ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sdrreader.Close();
         sqlcon.Close();
     }
     return partybalanceinfo;
 }
Example #17
0
        /// <summary>
        /// Save Function
        /// </summary>
        public void Save()
        {
            try
            {
                int inGridRowCount = dgvPaymentVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
                PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
                PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo();
                PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
                PartyBalanceSP SpPartyBalance = new PartyBalanceSP();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                DateValidation objVal = new DateValidation();
                TextBox txtDate1 = new TextBox();
                InfoPaymentMaster.Date = dtpDate.Value;
                InfoPaymentMaster.Extra1 = string.Empty;
                InfoPaymentMaster.Extra2 = string.Empty;
                InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim(); ;
                InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString());
                InfoPaymentMaster.Narration = txtNarration.Text.Trim();
                InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId;
                decimal decTotalAmount = TotalAmountCalculation();
                InfoPaymentMaster.TotalAmount = decTotalAmount;
                InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId;
                InfoPaymentMaster.VoucherNo = strVoucherNo;
                InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId;
                decimal decPaymentMasterId = SpPaymentMaster.PaymentMasterAdd(InfoPaymentMaster);
                if (decPaymentMasterId != 0)
                {
                    MasterLedgerPosting();
                }
                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                {
                    if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                    {
                        InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                        InfoPaymentDetails.Extra1 = string.Empty;
                        InfoPaymentDetails.Extra2 = string.Empty;
                        InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        InfoPaymentDetails.PaymentMasterId = decPaymentMasterId;
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        }
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();

                            if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                            {
                                InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                            }
                            else
                            {
                                InfoPaymentDetails.ChequeDate = DateTime.Now;
                            }
                        }
                        else
                        {
                            InfoPaymentDetails.ChequeNo = string.Empty;
                            InfoPaymentDetails.ChequeDate = DateTime.Now;
                        }
                        decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsAdd(InfoPaymentDetails);
                        if (decPaymentDetailsId != 0)
                        {
                            for (int inJ = 0; inJ < inTableRowCount; inJ++)
                            {
                                if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                {
                                    PartyBalanceAddOrEdit(inJ);
                                }
                            }
                            inB++;
                            DetailsLedgerPosting(inI, decPaymentDetailsId);
                        }
                    }
                }
                Messages.SavedMessage();
                if (cbxPrintafterSave.Checked)
                {
                    if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPaymentmasterId);
                    }
                    else
                    {
                        Print(decPaymentMasterId);
                    }
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #18
0
        /// <summary>
        /// Function to save an item into table
        /// </summary>
        public void Save()
        {
            ExchangeRateSP spExchangeRate = new ExchangeRateSP();
            SalesReturnMasterSP spSalesReturnMaster = new SalesReturnMasterSP();
            SalesReturnDetailsSP spSalesReturnDetails = new SalesReturnDetailsSP();
            StockPostingSP spStockPosting = new StockPostingSP();
            LedgerPostingSP spLedgerPosting = new LedgerPostingSP();
            PartyBalanceSP spPartyBalance = new PartyBalanceSP();
            UnitConvertionSP spUnitConvertion = new UnitConvertionSP();
            UnitSP spUnit = new UnitSP();
            try
            {
                if (txtReturnNo.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Enter return no", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtReturnNo.Focus();
                }
                else if (spSalesReturnMaster.SalesReturnNumberCheckExistence(txtReturnNo.Text.Trim(), 0, decSalesReturnVoucherTypeId) == true && btnSave.Text == "Save")
                {
                    Messages.InformationMessage("Return  number already exist");
                    txtReturnNo.Focus();
                }
                //else if ((txtReturnNo .Text!=ManualReturnNo)&&(spSalesReturnMaster.SalesReturnNumberCheckExistence(txtReturnNo.Text.Trim(), 0, decSalesReturnVoucherTypeId) == true && btnSave.Text == "Update"))
                //{
                //    Messages.InformationMessage("Return  number already exist");
                //    txtReturnNo.Focus();
                //}
                else if (txtDate.Text == "")
                {
                    MessageBox.Show("Select a date in between financial year", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtDate.Focus();
                }
                else if (cmbCashOrParty.SelectedValue == null)
                {
                    MessageBox.Show("Select cash/party", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbCashOrParty.Focus();
                }
                else if (cmbSalesAccount.SelectedValue == null)
                {
                    MessageBox.Show("Select sales account", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbSalesAccount.Focus();
                }
                else if (cmbCurrency.SelectedValue == null)
                {
                    MessageBox.Show("Select currency", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbCurrency.Focus();
                }
                else
                {
                    if (isAutomatic)
                    {
                        if (strVoucherNo != string.Empty)
                        {
                            infoSalesReturnMaster.VoucherNo = strVoucherNo;
                        }
                        if (txtReturnNo.Text != string.Empty)
                        {
                            infoSalesReturnMaster.InvoiceNo = txtReturnNo.Text;
                        }
                    }
                    else
                    {
                        infoSalesReturnMaster.VoucherNo = txtReturnNo.Text;
                        infoSalesReturnMaster.InvoiceNo = txtReturnNo.Text;
                    }
                    if (decSalesReturnVoucherTypeId != 0)
                    {
                        infoSalesReturnMaster.VoucherTypeId = decSalesReturnVoucherTypeId;
                    }
                    if (decSalesReturnSuffixPrefixId != 0)
                    {
                        infoSalesReturnMaster.SuffixPrefixId = decSalesReturnSuffixPrefixId;
                    }
                    if (cmbCashOrParty.SelectedValue != null)
                    {
                        infoSalesReturnMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                    }
                    if (cmbInvoiceNo.SelectedValue != null)
                    {
                        infoSalesReturnMaster.SalesMasterId = Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.SalesMasterId = 0;
                    }
                    if (cmbSalesAccount.SelectedValue != null)
                    {
                        infoSalesReturnMaster.SalesAccount = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString());
                    }
                    if (cmbPricingLevel.SelectedValue != null)
                    {
                        infoSalesReturnMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.PricinglevelId = 0;
                    }
                    if (cmbSalesMan.SelectedValue != null)
                    {
                        infoSalesReturnMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
                    }
                    else
                    {
                        infoSalesReturnMaster.EmployeeId = 0;
                    }
                    if (cmbCurrency.SelectedValue != null)
                    {
                        infoSalesReturnMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                        decExchangeRate = spExchangeRate.ExchangeRateViewByExchangeRateId(infoSalesReturnMaster.ExchangeRateId);
                    }
                    infoSalesReturnMaster.Narration = txtNarration.Text.Trim();
                    infoSalesReturnMaster.UserId = PublicVariables._decCurrentUserId;
                    infoSalesReturnMaster.LrNo = txtLRNo.Text.Trim();
                    infoSalesReturnMaster.TransportationCompany = txtTransportationComp.Text.Trim();
                    infoSalesReturnMaster.Date = Convert.ToDateTime(txtDate.Text);
                    if (txtTotalAmount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
                    }
                    if (txtGrandTotal.Text != string.Empty)
                    {
                        infoSalesReturnMaster.grandTotal = Convert.ToDecimal(txtGrandTotal.Text);
                    }
                    if (lblTaxAmount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text);
                    }
                    infoSalesReturnMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoSalesReturnMaster.Extra1 = string.Empty;
                    infoSalesReturnMaster.Extra2 = string.Empty;
                    if (txtBillDiscount.Text != string.Empty)
                    {
                        infoSalesReturnMaster.Discount = Convert.ToDecimal(txtBillDiscount.Text);
                    }
                    else
                    {
                        infoSalesReturnMaster.Discount = 0;
                    }
                    decimal decNetTotal = 0;
                    decimal decGrandTotal = 0;
                    string strQuantities = string.Empty;
                    if (btnSave.Text == "Update")
                    {
                        infoSalesReturnMaster.SalesReturnMasterId = decSalesReturnMasterId;
                        spSalesReturnMaster.SalesReturnMasterEdit(infoSalesReturnMaster);
                        spLedgerPosting.LedgerPostingAndPartyBalanceDeleteByVoucherTypeIdAndLedgerIdAndVoucherNo(decSalesReturnVoucherTypeId, strVoucherNo, txtReturnNo.Text);
                        spLedgerPosting.LedgerPostingAndPartyBalanceDeleteByVoucherTypeIdAndLedgerIdAndVoucherNo(decSalesReturnVoucherTypeId, strVoucherNo, txtReturnNo.Text);
                        spStockPosting.StockPostingDeleteByVoucherTypeAndVoucherNo(strVoucherNo, decSalesReturnVoucherTypeId);
                        spSalesReturnBillTax.SalesReturnBillTaxDeleteBySalesReturnMasterId(decSalesReturnMasterId);
                    }
                    else
                    {
                        decSalesReturnMasterId = spSalesReturnMaster.SalesReturnMasterAdd(infoSalesReturnMaster);
                    }
                    SalesReturnDetailsInfo infoSalesReturnDetailsInfo = new SalesReturnDetailsInfo();
                    infoSalesReturnDetailsInfo.Extra1 = string.Empty;
                    infoSalesReturnDetailsInfo.Extra2 = string.Empty;
                    if (btnSave.Text == "Update")
                    {
                        foreach (var strId in lstArrOfRemove)
                        {
                            decimal decDeleteId = Convert.ToDecimal(strId);
                            spSalesReturnDetails.SalesReturnDetailsDelete(decDeleteId);
                        }
                    }
                    foreach (DataGridViewRow DGVSalesReturn in dgvSalesReturn.Rows)
                    {
                        if (DGVSalesReturn.Cells["productId"].Value != null && DGVSalesReturn.Cells["productId"].Value.ToString() != string.Empty)
                        {
                            infoSalesReturnDetailsInfo.SalesReturnMasterId = decSalesReturnMasterId;
                            infoSalesReturnDetailsInfo.ProductId = Convert.ToDecimal(DGVSalesReturn.Cells["productId"].Value.ToString());
                            if (DGVSalesReturn.Cells["dgvTextQty"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Qty = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextQty"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextRate"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Rate = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextRate"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvCmbUnit"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.UnitId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbUnit"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["unitConversionId"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.UnitConversionId = Convert.ToDecimal(DGVSalesReturn.Cells["unitConversionId"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextDiscountAmount"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Discount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextDiscountAmount"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvCmbTax"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.TaxId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbTax"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.TaxId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbBatch"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.BatchId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbBatch"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.BatchId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbBatch"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.BatchId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbBatch"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.BatchId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbGodown"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.GodownId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbGodown"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.GodownId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvCmbRack"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.RackId = Convert.ToDecimal(DGVSalesReturn.Cells["dgvCmbRack"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.RackId = 0;
                            }
                            if (DGVSalesReturn.Cells["dgvTextTaxAmount"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.TaxAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextTaxAmount"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextGrossValue"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.GrossAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextGrossValue"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextNetValue"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.NetAmount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextNetValue"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvTextAmount1"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.Amount = Convert.ToDecimal(DGVSalesReturn.Cells["dgvTextAmount1"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["dgvSNo"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.SlNo = Convert.ToInt32(DGVSalesReturn.Cells["dgvSNo"].Value.ToString());
                            }
                            if (DGVSalesReturn.Cells["salesDetailsId"].Value != null && cmbInvoiceNo.SelectedValue != null)
                            {
                                infoSalesReturnDetailsInfo.SalesDetailsId = Convert.ToDecimal(DGVSalesReturn.Cells["salesDetailsId"].Value.ToString());
                            }
                            else
                            {
                                infoSalesReturnDetailsInfo.SalesDetailsId = 0;
                            }
                            if (DGVSalesReturn.Cells["salesReturnDetailsId"].Value != null)
                            {
                                infoSalesReturnDetailsInfo.SalesReturnDetailsId = Convert.ToDecimal(DGVSalesReturn.Cells["salesReturnDetailsId"].Value.ToString());
                                spSalesReturnDetails.SalesReturnDetailsEdit(infoSalesReturnDetailsInfo);
                            }
                            else
                            {
                                decSalesReturnDetailId = spSalesReturnDetails.SalesReturnDetailsAdd(infoSalesReturnDetailsInfo);
                            }
                            StockPostingInfo infoStockPosting = new StockPostingInfo();
                            infoStockPosting.Date = infoSalesReturnMaster.Date;
                            if (DGVSalesReturn.Cells["voucherTypeId"].Value != null)
                            {
                                infoStockPosting.VoucherTypeId = Convert.ToDecimal(DGVSalesReturn.Cells["voucherTypeId"].Value.ToString());
                                decAgainstVoucherTypeId = infoStockPosting.VoucherTypeId;
                                infoStockPosting.AgainstVoucherTypeId = decSalesReturnVoucherTypeId;
                            }
                            else
                            {
                                infoStockPosting.VoucherTypeId = decSalesReturnVoucherTypeId;
                                infoStockPosting.AgainstVoucherTypeId = 0;
                            }
                            if (DGVSalesReturn.Cells["voucherNo"].Value != null)
                            {
                                infoStockPosting.VoucherNo = DGVSalesReturn.Cells["voucherNo"].Value.ToString();
                                strAgainstVoucherNo = infoStockPosting.VoucherNo;
                                infoStockPosting.AgainstVoucherNo = strVoucherNo;
                            }
                            else
                            {
                                infoStockPosting.VoucherNo = strVoucherNo;
                                infoStockPosting.AgainstVoucherNo = "NA";
                            }
                            if (DGVSalesReturn.Cells["invoiceNo"].Value != null)
                            {
                                infoStockPosting.InvoiceNo = DGVSalesReturn.Cells["invoiceNo"].Value.ToString();
                                strAgainstInvoiceNo = infoStockPosting.InvoiceNo;
                                infoStockPosting.AgainstInvoiceNo = txtReturnNo.Text.Trim();
                            }
                            else
                            {
                                infoStockPosting.InvoiceNo = txtReturnNo.Text;
                                infoStockPosting.AgainstInvoiceNo = "NA";
                            }
                            infoStockPosting.ProductId = infoSalesReturnDetailsInfo.ProductId;
                            infoStockPosting.BatchId = infoSalesReturnDetailsInfo.BatchId;
                            infoStockPosting.UnitId = infoSalesReturnDetailsInfo.UnitId;
                            infoStockPosting.GodownId = infoSalesReturnDetailsInfo.GodownId;
                            infoStockPosting.RackId = infoSalesReturnDetailsInfo.RackId;
                            if (infoSalesReturnDetailsInfo.ProductId != 0 && infoSalesReturnDetailsInfo.UnitId != 0)
                            {
                                decimal decUnitConvertionRate = 0;
                                infoProduct = spProduct.ProductView(infoSalesReturnDetailsInfo.ProductId);
                                DataTable dtbl = spUnitConvertion.DGVUnitConvertionRateByUnitId(infoSalesReturnDetailsInfo.UnitId, infoProduct.ProductName);
                                foreach (DataRow drowDetails in dtbl.Rows)
                                {
                                    decUnitConvertionRate = Convert.ToDecimal(drowDetails["conversionRate"].ToString());
                                }
                                strQuantities = spUnit.UnitConversionCheck(infoSalesReturnDetailsInfo.UnitId, infoSalesReturnDetailsInfo.ProductId);
                                if (strQuantities != string.Empty)
                                {
                                    infoStockPosting.InwardQty = infoSalesReturnDetailsInfo.Qty / decUnitConvertionRate;
                                }
                                else
                                {
                                    infoStockPosting.InwardQty = infoSalesReturnDetailsInfo.Qty;
                                }
                            }
                            infoStockPosting.OutwardQty = 0;
                            infoStockPosting.Rate = infoSalesReturnDetailsInfo.Rate;
                            infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                            infoStockPosting.Extra1 = string.Empty;
                            infoStockPosting.Extra2 = string.Empty;
                            spStockPosting.StockPostingAdd(infoStockPosting);
                        }
                    }
                    decGrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
                    decNetTotal = TotalNetAmountForLedgerPosting();
                    LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                    infoLedgerPosting.Date = infoSalesReturnMaster.Date;
                    infoLedgerPosting.ChequeDate = infoSalesReturnMaster.Date;
                    infoLedgerPosting.ChequeNo = String.Empty;
                    infoLedgerPosting.VoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                    infoLedgerPosting.VoucherNo = infoSalesReturnMaster.VoucherNo;
                    infoLedgerPosting.LedgerId = infoSalesReturnMaster.LedgerId;
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = (decGrandTotal * decExchangeRate);
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.InvoiceNo = infoSalesReturnMaster.InvoiceNo;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.LedgerId = infoSalesReturnMaster.SalesAccount;
                    infoLedgerPosting.Debit = (decNetTotal * decExchangeRate);
                    infoLedgerPosting.Credit = 0;
                    spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    if (Convert.ToDecimal(txtBillDiscount.Text == string.Empty ? "0" : txtBillDiscount.Text) > 0)
                    {
                        infoLedgerPosting.LedgerId = 8;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = (Convert.ToDecimal(txtBillDiscount.Text) * decExchangeRate);
                        spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    }
                    LedegrPostingForTax();
                    PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                    infoPartyBalance.Date = infoSalesReturnMaster.Date;
                    infoPartyBalance.LedgerId = infoSalesReturnMaster.LedgerId;
                    if (decAgainstVoucherTypeId != 0)
                    {
                        infoPartyBalance.VoucherTypeId = decAgainstVoucherTypeId;
                        infoPartyBalance.VoucherNo = strAgainstVoucherNo;
                        infoPartyBalance.InvoiceNo = strAgainstInvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                        infoPartyBalance.AgainstVoucherNo = infoSalesReturnMaster.VoucherNo;
                        infoPartyBalance.AgainstInvoiceNo = infoSalesReturnMaster.InvoiceNo;
                        infoPartyBalance.ReferenceType = "Against";
                    }
                    else
                    {
                        infoPartyBalance.VoucherTypeId = infoSalesReturnMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoSalesReturnMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoSalesReturnMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = 0;
                        infoPartyBalance.AgainstVoucherNo = "NA";
                        infoPartyBalance.AgainstInvoiceNo = "NA";
                        infoPartyBalance.ReferenceType = "New";
                    }

                    infoPartyBalance.Credit = infoSalesReturnMaster.TotalAmount;
                    infoPartyBalance.Debit = 0;
                    infoPartyBalance.CreditPeriod = 0;
                    infoPartyBalance.ExchangeRateId = infoSalesReturnMaster.ExchangeRateId;
                    infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoPartyBalance.Extra1 = string.Empty;
                    infoPartyBalance.Extra2 = string.Empty;
                    spPartyBalance.PartyBalanceAdd(infoPartyBalance);
                    SalesReturnBillTaxInfo infoSalesReturnBillTax = new SalesReturnBillTaxInfo();
                    foreach (DataGridViewRow item in dgvSalesReturn2.Rows)
                    {
                        if (item.Cells["dgvTextTaxId"].Value != null)
                        {
                            infoSalesReturnBillTax.SalesReturnMasterId = decSalesReturnMasterId;
                            infoSalesReturnBillTax.TaxId = Convert.ToDecimal(item.Cells["dgvTextTaxId"].Value.ToString());
                            infoSalesReturnBillTax.TaxAmount = Convert.ToDecimal(item.Cells["dgvTextAmount"].Value.ToString());
                            infoSalesReturnBillTax.Extra1 = string.Empty;
                            infoSalesReturnBillTax.Extra2 = string.Empty;
                            spSalesReturnBillTax.SalesReturnBillTaxAdd(infoSalesReturnBillTax);
                        }
                    }
                    if (btnSave.Text == "Save")
                    {
                        Messages.SavedMessage();
                        if (cbxPrintAfterSave.Checked == true)
                        {
                            if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesReturnMasterId);
                            }
                            else
                            {
                                Print(decSalesReturnMasterId);
                            }
                        }
                        clear();
                    }
                    else
                    {
                        Messages.UpdatedMessage();
                        if (cbxPrintAfterSave.Checked == true)
                        {
                            if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesReturnMasterId);
                            }
                            else
                            {
                                Print(decSalesReturnMasterId);
                            }
                        }
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #19
0
 /// <summary>
 /// Function to edit the service voucher
 /// </summary>
 /// <param name="decServiceMasterId"></param>
 public void EditFunction(decimal decServiceMasterId)
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceMasterSP spServiceMaster = new ServiceMasterSP();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServiceDetailsSP spServiceDetails = new ServiceDetailsSP();
         LedgerPostingSP spLedgerPosting = new LedgerPostingSP();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateSP spExchangeRate = new ExchangeRateSP();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         decimal decLedgerPostingId1 = 0;
         decimal decLedgerPostingId2 = 0;
         DataTable dtblLedgerPostingId = new DataTable();
         dtblLedgerPostingId = spServiceMaster.LedgerPostingIdByServiceMaasterId(decServiceMasterId);
         decLedgerPostingId1 = Convert.ToDecimal(dtblLedgerPostingId.Rows[0]["ledgerPostingId"].ToString());
         decLedgerPostingId2 = Convert.ToDecimal(dtblLedgerPostingId.Rows[1]["ledgerPostingId"].ToString());
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             infoServiceMaster.ServiceMasterId = decServiceMasterId;
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text);
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             //------------------deleting removed rows----------------------------------------//
             BankReconciliationSP spBankReconciliation = new BankReconciliationSP();
             foreach (object obj in strArrOfRemove)
             {
                 string str = Convert.ToString(obj);
                 spServiceDetails.ServiceDetailsDelete(Convert.ToDecimal(str));
             }
             spServiceMaster.ServiceMasterEdit(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     if (dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString() != string.Empty)
                     {
                         infoServiceDetails.ServiceDetailsId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString());
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         spServiceDetails.ServiceDetailsEdit(infoServiceDetails);
                     }
                     else
                     {
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         decServiceDetailsId = spServiceDetails.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
                     }
                     decSelectedCurrencyRate = spExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decAmount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                     decConvertRate += decAmount * decSelectedCurrencyRate;
                 }
             }
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId1, decLedgerId, decCredit, decDebit);
             decCredit = decConvertRate;
             decDebit = 0;
             decLedgerId = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId2, decLedgerId, decCredit, decDebit);
             AccountLedgerSP spAccountLedger = new AccountLedgerSP();
             decimal decI = Convert.ToDecimal(spAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceSP spPartyBalance = new PartyBalanceSP();
                 infoPartyBalance.PartyBalanceId = decPartyBalanceId;
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 spPartyBalance.PartyBalanceEdit(infoPartyBalance);
             }
             Messages.UpdatedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             this.Close();
             if (frmServiceVoucherRegisterObj != null)
             {
                 frmServiceVoucherRegisterObj.Show();
                 frmServiceVoucherRegisterObj.GridFill();
             }
             else if (frmServiceReportObj != null)
             {
                 frmServiceReportObj.Show();
                 frmServiceReportObj.GridFill();
             }
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 24 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #20
0
 /// <summary>
 /// Function to save values to partyBalance table
 /// </summary>
 public void partyBalance()
 {
     try
     {
         PartyBalanceInfo infoPatryBalance = new PartyBalanceInfo();
         PartyBalanceSP spPartyBalance = new PartyBalanceSP();
         AccountLedgerSP spLedger = new AccountLedgerSP();
         ExchangeRateSP spExchangeRate = new ExchangeRateSP();
         if (decOpeningBlnc > 0)
         {
             if (cmbBillbyBill.Text == "Yes")
             {
                 infoPatryBalance.Date = PublicVariables._dtFromDate;
                 infoPatryBalance.LedgerId = decledgerid;
                 infoPatryBalance.VoucherTypeId = 1;
                 infoPatryBalance.VoucherNo = decledgerid.ToString();
                 infoPatryBalance.AgainstVoucherTypeId = 0;
                 infoPatryBalance.AgainstVoucherNo = "0";
                 infoPatryBalance.ReferenceType = "New";
                 if (cmbDrorCr.Text == "Dr")
                 {
                     infoPatryBalance.Debit = decOpeningBlnc;
                     infoPatryBalance.Credit = 0;
                 }
                 else
                 {
                     infoPatryBalance.Debit = 0;
                     infoPatryBalance.Credit = decOpeningBlnc;
                 }
                 infoPatryBalance.InvoiceNo = decledgerid.ToString();
                 infoPatryBalance.AgainstInvoiceNo = "0";
                 infoPatryBalance.CreditPeriod = 0;
                 infoPatryBalance.ExchangeRateId = spExchangeRate.ExchangerateViewByCurrencyId(PublicVariables._decCurrencyId);
                 infoPatryBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPatryBalance.Extra1 = string.Empty;
                 infoPatryBalance.Extra2 = string.Empty;
             }
             spPartyBalance.PartyBalanceAdd(infoPatryBalance);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Cus15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #21
0
        /// <summary>
        /// Function for Save and Edit
        /// </summary>  
        public void SaveOrEdit()
        {
            try
            {
                PurchaseMasterSP SPPurchaseMaster = new PurchaseMasterSP();
                PurchaseReturnMasterSP SPPurchaseReturnMaster = new PurchaseReturnMasterSP();
                PurchaseReturnDetailsSP SPPurchaseReturnDetails = new PurchaseReturnDetailsSP();
                PurchaseReturnDetailsInfo infoPurchaseReturnDetails = new PurchaseReturnDetailsInfo();
                StockPostingInfo infoStockPosting = new StockPostingInfo();
                StockPostingSP spStockPosting = new StockPostingSP();
                UnitConvertionSP SPUnitConversion = new UnitConvertionSP();
                LedgerPostingSP spLedgerPosting = new LedgerPostingSP();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                ExchangeRateSP spExchangeRate = new ExchangeRateSP();
                PartyBalanceSP spPartyBalance = new PartyBalanceSP();
                PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                AccountLedgerInfo infoAccountLedger = new AccountLedgerInfo();
                AccountLedgerSP spAccountLedger = new AccountLedgerSP();
                PurchaseReturnBilltaxInfo infoPurchaseReturnBillTax = new PurchaseReturnBilltaxInfo();
                PurchaseReturnBilltaxSP spPurchaseReturnBillTax = new PurchaseReturnBilltaxSP();
                SettingsSP spSettings = new SettingsSP();
                UnitSP spUnit = new UnitSP();
                DataTable dtblPurchaseMasterViewById = new DataTable();
                string strAgainstVoucherNo = string.Empty;
                string strAgainstInvoiceNo = string.Empty;
                decimal decPurchaseReturnMasterIds = 0;
                decimal decPurchaseMasterId = 0;
                decimal decDiscount = 0;
                decimal decExchangeRate = 0;
                decimal decDis = 0;

                if (isAutomatic)
                {
                    if (strVoucherNo != string.Empty)
                    {
                        infoPurchaseReturnMaster.VoucherNo = strVoucherNo;
                    }
                    if (txtReturnNo.Text != string.Empty)
                    {
                        infoPurchaseReturnMaster.InvoiceNo = txtReturnNo.Text;
                    }
                }
                else
                {
                    infoPurchaseReturnMaster.VoucherNo = strVoucherNo;
                    infoPurchaseReturnMaster.InvoiceNo = txtReturnNo.Text;
                }
                if (decPurchaseReturnVoucherTypeId != 0)
                {
                    infoPurchaseReturnMaster.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                }
                infoPurchaseReturnMaster.SuffixPrefixId = (decPurchaseReturnSuffixPrefixId != 0) ? decPurchaseReturnSuffixPrefixId : 0;
                infoPurchaseReturnMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                infoPurchaseReturnMaster.PurchaseAccount = Convert.ToDecimal(cmbPurchaseAccount.SelectedValue.ToString());
                if (cmbInvoiceNo.SelectedValue != null && cmbInvoiceNo.Visible == true)
                {
                    infoPurchaseReturnMaster.PurchaseMasterId = Convert.ToDecimal((cmbInvoiceNo.SelectedValue.ToString()));
                    decPurchaseMasterId = Convert.ToDecimal((cmbInvoiceNo.SelectedValue.ToString()));
                }
                else
                {
                    infoPurchaseReturnMaster.PurchaseMasterId = 0;
                }
                infoPurchaseReturnMaster.ExchangeRateId = (cmbCurrency.SelectedValue != null) ? Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()) : 0;
                infoPurchaseReturnMaster.Narration = txtNarration.Text.Trim();
                infoPurchaseReturnMaster.UserId = PublicVariables._decCurrentUserId;
                infoPurchaseReturnMaster.LrNo = txtLrlNo.Text.Trim();
                infoPurchaseReturnMaster.TransportationCompany = txtTransportationCompany.Text.Trim();
                infoPurchaseReturnMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoPurchaseReturnMaster.TotalAmount = (txtTotalAmount.Text != string.Empty) ? Convert.ToDecimal(txtTotalAmount.Text) : 0;
                infoPurchaseReturnMaster.TotalTax = (lblTaxAmount.Text != string.Empty) ? Convert.ToDecimal(lblTaxAmount.Text) : 0;
                infoPurchaseReturnMaster.Discount = (txtBillDiscount.Text != string.Empty) ? Convert.ToDecimal(txtBillDiscount.Text) : 0;
                infoPurchaseReturnMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                infoPurchaseReturnMaster.Extra1 = string.Empty;
                infoPurchaseReturnMaster.Extra2 = string.Empty;
                infoPurchaseReturnMaster.ExtraDate = DateTime.Now;
                infoPurchaseReturnMaster.GrandTotal = (txtGrandTotal.Text != string.Empty) ? Convert.ToDecimal(txtGrandTotal.Text) : 0;
                if (btnSave.Text == "Save")
                {
                    decPurchaseReturnMasterIds = SPPurchaseReturnMaster.PurchaseReturnMasterAddWithReturnIdentity(infoPurchaseReturnMaster);
                }
                else
                {
                    infoPurchaseReturnMaster.PurchaseReturnMasterId = decPurchaseReturnMasterId;
                    decExchangeRate = spExchangeRate.ExchangeRateViewByExchangeRateId(infoPurchaseReturnMaster.ExchangeRateId);
                    SPPurchaseReturnMaster.PurchaseReturnMasterEdit(infoPurchaseReturnMaster);
                    infoPurchaseMaster = SPPurchaseMaster.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                    spLedgerPosting.LedgerPostDelete(strVoucherNo, decPurchaseReturnVoucherTypeId);
                    spAccountLedger.PartyBalanceDeleteByVoucherTypeVoucherNoAndReferenceType(strVoucherNo, decPurchaseReturnVoucherTypeId);
                }

                infoLedgerPosting.Date = infoPurchaseReturnMaster.Date;
                infoLedgerPosting.VoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                infoLedgerPosting.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                infoLedgerPosting.ChequeNo = string.Empty;
                infoLedgerPosting.ChequeDate = DateTime.Now;
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;

                infoLedgerPosting.LedgerId = infoPurchaseReturnMaster.PurchaseAccount;
                infoLedgerPosting.Debit = 0;
                if (btnSave.Text == "Save")
                {
                    infoLedgerPosting.Credit = TotalNetAmountCalculation() * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                }
                else
                {
                    infoLedgerPosting.Credit = TotalNetAmountCalculation();
                }
                spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                infoLedgerPosting.LedgerId = infoPurchaseReturnMaster.LedgerId;
                if (btnSave.Text == "Save")
                {
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtGrandTotal.Text) * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                }
                else
                {
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtGrandTotal.Text);
                }
                infoLedgerPosting.Credit = 0;
                spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                foreach (DataGridViewRow dgvrow in dgvPurchaseReturnTax.Rows)
                {
                    if (dgvrow.Cells["dgvtxtTaxId"].Value != null && dgvrow.Cells["dgvtxtTaxId"].Value.ToString() != string.Empty)
                    {
                        infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvtxtledgerId"].Value.ToString());
                        infoLedgerPosting.Credit = (dgvrow.Cells["dgvtxtAmounts"].Value == null) ? 0 : Convert.ToDecimal(dgvrow.Cells["dgvtxtAmounts"].Value.ToString());
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.ExtraDate = DateTime.Now;
                        spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    }
                }

                if (txtBillDiscount.Text.Trim() != string.Empty)
                {
                    decDis = Convert.ToDecimal(txtBillDiscount.Text);
                }
                if (decDis >= 0)
                {
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = decDis;
                    infoLedgerPosting.LedgerId = 9;
                    infoLedgerPosting.ExtraDate = DateTime.Now;
                    spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }

                if (btnSave.Text == "Update")
                {
                    infoPurchaseReturnMaster = SPPurchaseReturnMaster.PurchaseReturnMasterView(decPurchaseReturnMasterId);
                    if (infoPurchaseReturnMaster.PurchaseMasterId == 0)
                    {
                        spStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(0, "NA", infoPurchaseReturnMaster.VoucherNo, infoPurchaseReturnMaster.VoucherTypeId);
                    }
                    if (infoPurchaseReturnMaster.PurchaseMasterId != 0)
                    {
                        infoPurchaseMaster = SPPurchaseMaster.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                        spStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType(infoPurchaseMaster.VoucherTypeId, strInvoiceNo, strVoucherNo, infoPurchaseReturnMaster.VoucherTypeId);
                    }
                }

                foreach (DataGridViewRow dgvrow in dgvPurchaseReturn.Rows)
                {
                    if (dgvrow.Cells["dgvtxtProductId"].Value != null && dgvrow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty)
                    {
                        infoPurchaseReturnDetails.ExtraDate = DateTime.Now;
                        infoPurchaseReturnDetails.Extra1 = string.Empty;
                        infoPurchaseReturnDetails.Extra2 = string.Empty;
                        infoPurchaseReturnDetails.PurchaseReturnMasterId = (btnSave.Text == "Save") ? decPurchaseReturnMasterIds : decPurchaseReturnMasterId;
                        infoPurchaseReturnDetails.ProductId = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtproductId"].Value));
                        infoPurchaseReturnDetails.Qty = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtqty"].Value));
                        infoPurchaseReturnDetails.Rate = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtrate"].Value));
                        if (btnSave.Text == "Save")
                        {
                            infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                            infoPurchaseReturnDetails.UnitConversionId = SPUnitConversion.UnitconversionIdViewByUnitIdAndProductId(infoPurchaseReturnDetails.UnitId, infoPurchaseReturnDetails.ProductId);
                        }
                        else
                        {
                            if (Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value) == 0)
                            {
                                try
                                {
                                    infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                                }
                                catch
                                {
                                    infoPurchaseReturnDetails.UnitId = spUnit.UnitIdByUnitName(Convert.ToString(dgvrow.Cells["dgvcmbUnit"].Value.ToString()));
                                }
                                infoPurchaseReturnDetails.UnitConversionId = SPUnitConversion.UnitconversionIdViewByUnitIdAndProductId(infoPurchaseReturnDetails.UnitId, infoPurchaseReturnDetails.ProductId);
                            }
                            else
                            {
                                try
                                {
                                    infoPurchaseReturnDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                                }
                                catch
                                {
                                    infoPurchaseReturnDetails.UnitId = spUnit.UnitIdByUnitName(Convert.ToString(dgvrow.Cells["dgvcmbUnit"].Value.ToString()));
                                }
                            }
                            infoPurchaseReturnDetails.UnitConversionId = Convert.ToDecimal(dgvrow.Cells["dgvtxtUnitConversionId"].Value);
                        }
                        infoPurchaseReturnDetails.Discount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtdiscount"].Value));
                        if (dgvrow.Cells["dgvcmbTax"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbTax"].Value) != string.Empty && dgvrow.Cells["dgvcmbTax"].Value as string != "NA")
                        {
                            infoPurchaseReturnDetails.TaxId = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvcmbTax"].Value));
                            if (strTaxComboFill != string.Empty)
                            {
                                infoPurchaseReturnDetails.TaxAmount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtTaxAmount"].Value));
                            }
                        }
                        else
                        {
                            infoPurchaseReturnDetails.TaxId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbBatch"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbBatch"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.BatchId = Convert.ToDecimal(dgvrow.Cells["dgvcmbBatch"].Value);
                        }
                        else
                        {
                            infoPurchaseReturnDetails.GodownId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbGodown"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbGodown"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.GodownId = Convert.ToDecimal(dgvrow.Cells["dgvcmbGodown"].Value);
                        }
                        else
                        {
                            infoPurchaseReturnDetails.RackId = 0;
                        }
                        if (dgvrow.Cells["dgvcmbRack"].Value != null && Convert.ToString(dgvrow.Cells["dgvcmbRack"].Value) != string.Empty)
                        {
                            infoPurchaseReturnDetails.RackId = Convert.ToDecimal(dgvrow.Cells["dgvcmbRack"].Value);
                        }
                        infoPurchaseReturnDetails.GrossAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtgrossValue"].Value.ToString());
                        infoPurchaseReturnDetails.NetAmount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtNetAmount"].Value));
                        infoPurchaseReturnDetails.Amount = Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtAmount"].Value));
                        infoPurchaseReturnDetails.SlNo = Convert.ToInt32(Convert.ToString(dgvrow.Cells["dgvtxtSlNo"].Value));
                        infoPurchaseReturnDetails.PurchaseDetailsId = (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value != null) ? Convert.ToDecimal(Convert.ToString(dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value)) : 0;
                        if (dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value != null)
                        {
                            if (dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString() == "0" || dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString() == string.Empty)
                            {
                                SPPurchaseReturnDetails.PurchaseReturnDetailsAddWithReturnIdentity(infoPurchaseReturnDetails);
                            }
                            else
                            {
                                infoPurchaseReturnDetails.PurchaseReturnDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseReturnDetailsId"].Value.ToString());
                                SPPurchaseReturnDetails.PurchaseReturnDetailsEdit(infoPurchaseReturnDetails);
                            }
                        }
                        else
                        {
                            SPPurchaseReturnDetails.PurchaseReturnDetailsAddWithReturnIdentity(infoPurchaseReturnDetails);
                        }
                 
                        if (btnSave.Text == "Save")
                        {
                            infoPurchaseMaster = SPPurchaseMaster.PurchaseMasterView(infoPurchaseReturnMaster.PurchaseMasterId);
                        }
                        infoStockPosting.Date = infoPurchaseReturnMaster.Date;
                        infoStockPosting.ProductId = infoPurchaseReturnDetails.ProductId;
                        infoStockPosting.BatchId = infoPurchaseReturnDetails.BatchId;
                        infoStockPosting.UnitId = infoPurchaseReturnDetails.UnitId;
                        infoStockPosting.GodownId = infoPurchaseReturnDetails.GodownId;
                        infoStockPosting.RackId = infoPurchaseReturnDetails.RackId;
                        decimal decConversionId = SPUnitConversion.UnitConversionRateByUnitConversionId(infoPurchaseReturnDetails.UnitConversionId);
                        //infoStockPosting.OutwardQty = infoPurchaseReturnDetails.Qty / (decConversionId == 0 ? 1 : decConversionId);
                        infoStockPosting.OutwardQty = infoPurchaseReturnDetails.Qty;
                        infoStockPosting.InwardQty = 0;
                        infoStockPosting.Rate = infoPurchaseReturnDetails.Rate;
                        infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                        infoStockPosting.Extra1 = string.Empty;
                        infoStockPosting.Extra2 = string.Empty;
                        if (infoPurchaseReturnDetails.PurchaseDetailsId != 0)
                        {
                            infoStockPosting.AgainstVoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                            infoStockPosting.AgainstVoucherNo = infoPurchaseMaster.VoucherNo;
                            infoStockPosting.AgainstInvoiceNo = infoPurchaseMaster.InvoiceNo;
                            infoStockPosting.VoucherNo = strVoucherNo;
                            infoStockPosting.InvoiceNo = txtReturnNo.Text.Trim();
                            infoStockPosting.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                            decAgainstVoucherTypeId = infoStockPosting.VoucherTypeId;
                        }
                        else
                        {
                            infoStockPosting.AgainstVoucherTypeId = 0;
                            infoStockPosting.AgainstVoucherNo = "NA";
                            infoStockPosting.AgainstInvoiceNo = "NA";
                            infoStockPosting.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                            infoStockPosting.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                            infoStockPosting.VoucherTypeId = decPurchaseReturnVoucherTypeId;
                            decAgainstVoucherTypeId = 0;
                        }
                        spStockPosting.StockPostingAdd(infoStockPosting);
                    }
                }
                if (btnSave.Text == "Update")
                {
                    removePurchaseReturnDetails();
                }
               
                infoAccountLedger = spAccountLedger.AccountLedgerView(infoPurchaseReturnMaster.LedgerId);
                if (infoAccountLedger.BillByBill == true)
                {
                    infoPartyBalance.Date = infoPurchaseReturnMaster.Date;
                    infoPartyBalance.LedgerId = infoPurchaseReturnMaster.LedgerId;
                    if (decAgainstVoucherTypeId != 0)
                    {
                        infoPartyBalance.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoPurchaseMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                        infoPartyBalance.AgainstVoucherNo = infoPurchaseReturnMaster.VoucherNo;
                        infoPartyBalance.AgainstInvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                        infoPartyBalance.ReferenceType = "Against";
                    }
                    else
                    {
                        infoPartyBalance.VoucherTypeId = infoPurchaseReturnMaster.VoucherTypeId;
                        infoPartyBalance.VoucherNo = infoPurchaseReturnMaster.VoucherNo;
                        infoPartyBalance.InvoiceNo = infoPurchaseReturnMaster.InvoiceNo;
                        infoPartyBalance.AgainstVoucherTypeId = 0;
                        infoPartyBalance.AgainstVoucherNo = "NA";
                        infoPartyBalance.AgainstInvoiceNo = "NA";
                        infoPartyBalance.ReferenceType ="New";
                    }
                    infoPartyBalance.Debit = infoPurchaseReturnMaster.TotalAmount;
                    infoPartyBalance.Credit = 0;
                    infoPartyBalance.CreditPeriod = 0;
                    infoPartyBalance.ExchangeRateId = infoPurchaseReturnMaster.ExchangeRateId;
                    infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoPartyBalance.Extra1 = string.Empty;
                    infoPartyBalance.Extra2 = string.Empty;
                    spPartyBalance.PartyBalanceAdd(infoPartyBalance);
                }
              
                foreach (DataGridViewRow item in dgvPurchaseReturnTax.Rows)
                {
                    if (item.Cells["dgvtxtTaxId"].Value != null)
                    {
                        infoPurchaseReturnBillTax.PurchaseReturnMasterId = (btnSave.Text == "Save") ? decPurchaseReturnMasterIds : decPurchaseReturnMasterIds;
                        infoPurchaseReturnBillTax.TaxId = Convert.ToDecimal(item.Cells["dgvtxtTaxId"].Value.ToString());
                        infoPurchaseReturnBillTax.TaxAmount = (item.Cells["dgvtxtAmounts"].Value == null) ? 0 : Convert.ToDecimal(item.Cells["dgvtxtAmounts"].Value.ToString());
                        infoPurchaseReturnBillTax.Extra1 = string.Empty;
                        infoPurchaseReturnBillTax.Extra2 = string.Empty;
                        spPurchaseReturnBillTax.PurchaseReturnBilltaxAdd(infoPurchaseReturnBillTax);
                    }
                }
                if (btnSave.Text == "Save")
                {
                    Messages.SavedMessage();
                    if (cbxPrintAfterSave.Checked)
                    {
                        if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decPurchaseReturnMasterIds);
                        }
                        else
                        {
                            Print(decPurchaseReturnMasterIds);
                        }
                    }
                    Clear();
                }
                else
                {
                    decDiscount = Convert.ToDecimal(txtBillDiscount.Text);
                    Messages.UpdatedMessage();
                    if (cbxPrintAfterSave.Checked)
                    {
                        if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decPurchaseReturnMasterId);
                        }
                        else
                        {
                            Print(decPurchaseReturnMasterId);
                        }
                    }
                    if (frmPurchaseReturnRegisterObj != null)
                    {
                        frmPurchaseReturnRegisterObj.GridFill();
                        frmPurchaseReturnRegisterObj.Enabled = true;
                    }

                    if (ObjPurchaseReturnReport != null)
                    {
                        ObjPurchaseReturnReport.PurchaseReturnReportGridFill();
                        ObjPurchaseReturnReport.Enabled = true;
                    }
                    if (frmLedgerDetailsObj != null)
                    {
                        frmLedgerDetailsObj.LedgerDetailsView();
                        frmLedgerDetailsObj.Enabled = true;
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR:49" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #22
0
        /// <summary>
        /// Function to Save the voucher
        /// </summary>
        public void Save()
        {
            try
            {
                decimal decTotalDebit = 0;
                decimal decTotalCredit = 0;

                decTotalDebit = Convert.ToDecimal(txtDebitTotal.Text.Trim());
                decTotalCredit = Convert.ToDecimal(txtCreditTotal.Text.Trim());

                JournalMasterSP spJournalMaster = new JournalMasterSP();
                JournalDetailsSP spJournalDetails = new JournalDetailsSP();
                JournalMasterInfo infoJournalMaster = new JournalMasterInfo();
                JournalDetailsInfo infoJournalDetails = new JournalDetailsInfo();
                PartyBalanceSP SpPartyBalance = new PartyBalanceSP();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                ExchangeRateSP spExchangeRate = new ExchangeRateSP();

                infoJournalMaster.VoucherNo = strVoucherNo;
                infoJournalMaster.InvoiceNo = txtVoucherNo.Text;
                infoJournalMaster.SuffixPrefixId = decJournalSuffixPrefixId;
                infoJournalMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoJournalMaster.Narration = txtNarration.Text.Trim();
                infoJournalMaster.UserId = PublicVariables._decCurrentUserId;
                infoJournalMaster.VoucherTypeId = decJournalVoucherTypeId;
                infoJournalMaster.FinancialYearId = Convert.ToDecimal(PublicVariables._decCurrentFinancialYearId.ToString());

                infoJournalMaster.Extra1 = string.Empty;
                infoJournalMaster.Extra2 = string.Empty;
                infoJournalMaster.ExtraDate = DateTime.Now;


                infoJournalMaster.TotalAmount = decTotalDebit;
                decimal decJournalMasterId = spJournalMaster.JournalMasterAdd(infoJournalMaster);

                /*******************JournalDetailsAdd and LedgerPosting*************************/
                infoJournalDetails.JournalMasterId = decJournalMasterId;
                infoJournalDetails.ExtraDate = DateTime.Now;
                infoJournalDetails.Extra1 = string.Empty;
                infoJournalDetails.Extra2 = string.Empty;


                decimal decLedgerId = 0;
                decimal decDebit = 0;
                decimal decCredit = 0;
                int inRowCount = dgvJournalVoucher.RowCount;
                for (int inI = 0; inI < inRowCount - 1; inI++)
                {
                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {
                        infoJournalDetails.LedgerId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        decLedgerId = infoJournalDetails.LedgerId;
                    }
                    if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() != string.Empty)
                    {
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                        {
                            //--------Currency conversion--------------//
                            decSelectedCurrencyRate = spExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()));
                            decAmount = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                            decConvertRate = decAmount * decSelectedCurrencyRate;
                            //===========================================//
                            if (dgvJournalVoucher.Rows[inI].Cells["dgvcmbDrOrCr"].Value.ToString() == "Dr")
                            {
                                infoJournalDetails.Debit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Credit = 0;
                                decDebit = decConvertRate;
                                decCredit = infoJournalDetails.Credit;
                            }
                            else
                            {
                                infoJournalDetails.Credit = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                                infoJournalDetails.Debit = 0;
                                decDebit = infoJournalDetails.Debit;
                                decCredit = decConvertRate;
                            }
                        }
                        infoJournalDetails.ExchangeRateId = Convert.ToDecimal(dgvJournalVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                        {
                            infoJournalDetails.ChequeNo = dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                        }
                        else
                        {
                            infoJournalDetails.ChequeNo = string.Empty;
                        }
                        if (dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            infoJournalDetails.ChequeDate = Convert.ToDateTime(dgvJournalVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString());
                        }
                        else
                        {
                            infoJournalDetails.ChequeDate = DateTime.Now;
                        }
                        decimal decJournalDetailsId = spJournalDetails.JournalDetailsAdd(infoJournalDetails);
                        if (decJournalDetailsId != 0)
                        {
                            PartyBalanceAddOrEdit(inI);
                            LedgerPosting(decLedgerId, decCredit, decDebit, decJournalDetailsId, inI);
                        }
                    }

                }

                Messages.SavedMessage();

                //----------------If print after save is enable-----------------------//
                if (cbxPrintAfterSave.Checked)
                {
                    if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decJournalMasterId);
                    }
                    else
                    {
                        Print(decJournalMasterId);
                    }
                }

                //===================================================================//
            }
            catch (Exception ex)
            {
                MessageBox.Show("JV14:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #23
0
 /// <summary>
 /// Party balance Add function, here adding the balance amount into the party balance table
 /// </summary>
 public void PartyBalanceAddOrEdit()
 {
     int inTableRowCount = dtblPartyBalance.Rows.Count;
     PartyBalanceSP spPartyBalance = new PartyBalanceSP();
     PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
     try
     {
         InfopartyBalance.CreditPeriod = 0;
         InfopartyBalance.Date = dtpVoucherDate.Value;
         InfopartyBalance.LedgerId = Convert.ToDecimal(strledgerId);
         InfopartyBalance.ReferenceType = "New";
         InfopartyBalance.VoucherTypeId = decPDCclearanceVoucherTypeId;
         InfopartyBalance.InvoiceNo = txtvoucherNo.Text.ToString();
         InfopartyBalance.VoucherNo = strVoucherNo;
         InfopartyBalance.AgainstInvoiceNo = "0";
         InfopartyBalance.AgainstVoucherNo = "0";
         InfopartyBalance.AgainstVoucherTypeId = 0;
         InfopartyBalance.Extra1 = string.Empty;
         InfopartyBalance.Extra2 = string.Empty;
         InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         InfopartyBalance.ExchangeRateId = 1;
         if (strVoucherType == "PDC Payable")
         {
             InfopartyBalance.Debit = 0;
             InfopartyBalance.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
             spPartyBalance.PartyBalanceAdd(InfopartyBalance);
         }
         else if (strVoucherType == "PDC Receivable")
         {
             InfopartyBalance.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
             InfopartyBalance.Credit = 0;
             spPartyBalance.PartyBalanceAdd(InfopartyBalance);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PC13:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #24
0
        /// <summary>
        /// Party balance Save Or Edit
        /// </summary>
        /// <param name="inJ"></param>
        public void PartyBalanceAddOrEdit(int inJ)
        {
            try
            {


                int inTableRowCount = dtblPartyBalance.Rows.Count;
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                PartyBalanceSP spPartyBalance = new PartyBalanceSP();
                InfopartyBalance.Credit = 0;
                InfopartyBalance.CreditPeriod = 0;
                InfopartyBalance.Date = dtpDate.Value;
                InfopartyBalance.Debit = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["Amount"].ToString());
                InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["CurrencyId"].ToString());
                InfopartyBalance.Extra1 = string.Empty;
                InfopartyBalance.Extra2 = string.Empty;
                InfopartyBalance.ExtraDate = DateTime.Now;
                InfopartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfopartyBalance.LedgerId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["LedgerId"].ToString());
                InfopartyBalance.ReferenceType = dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString();
                if (dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "New" || dtblPartyBalance.Rows[inJ]["ReferenceType"].ToString() == "OnAccount")
                {
                    InfopartyBalance.AgainstInvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                    InfopartyBalance.AgainstVoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.AgainstVoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());//decPaymentVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = decPaymentVoucherTypeId;
                    InfopartyBalance.InvoiceNo = strInvoiceNo;
                    if (!isAutomatic)
                    {
                        InfopartyBalance.VoucherNo = txtVoucherNo.Text.Trim();
                    }
                    else
                    {
                        InfopartyBalance.VoucherNo = strVoucherNo;
                    }
                }
                else
                {
                    InfopartyBalance.ExchangeRateId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["OldExchangeRate"].ToString());
                    InfopartyBalance.AgainstInvoiceNo = strInvoiceNo;
                    if (!isAutomatic)
                    {
                        InfopartyBalance.AgainstVoucherNo = txtVoucherNo.Text.Trim();
                    }
                    else
                    {
                        InfopartyBalance.AgainstVoucherNo = strVoucherNo;
                    }
                    InfopartyBalance.AgainstVoucherTypeId = decPaymentVoucherTypeId;
                    InfopartyBalance.VoucherTypeId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["AgainstVoucherTypeId"].ToString());
                    InfopartyBalance.VoucherNo = dtblPartyBalance.Rows[inJ]["AgainstVoucherNo"].ToString();
                    InfopartyBalance.InvoiceNo = dtblPartyBalance.Rows[inJ]["AgainstInvoiceNo"].ToString();
                }
                if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() == "0")
                {
                    spPartyBalance.PartyBalanceAdd(InfopartyBalance);
                }
                else
                {
                    InfopartyBalance.PartyBalanceId = Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["partyBalanceId"]);
                    spPartyBalance.PartyBalanceEdit(InfopartyBalance);
                }
            }
            catch (Exception ex)
            { 

                MessageBox.Show("PV15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #25
0
 /// <summary>
 /// Function to fill the fields for edit or delete
 /// </summary>
 public void FillFunction()
 {
     try
     {
         ServiceDetailsSP spServiceDetails = new ServiceDetailsSP();
         ServiceMasterSP spServiceMaster = new ServiceMasterSP();
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         LedgerPostingSP SpLedgerPosting = new LedgerPostingSP();
         VoucherTypeSP spVoucherType = new VoucherTypeSP();
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         PartyBalanceSP spPartyBalance = new PartyBalanceSP();
         PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
         decServiceMasterId = decMasterId;
         infoServiceMaster = spServiceMaster.ServiceMasterView(decServiceMasterId);
         infoVoucherType = spVoucherType.VoucherTypeView(infoServiceMaster.VoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         isAutomatic = spVoucherType.CheckMethodOfVoucherNumbering(infoServiceMaster.VoucherTypeId);
         txtInvoiceNumber.ReadOnly = true;
         strVoucherNo = infoServiceMaster.VoucherNo.ToString();
         txtInvoiceNumber.Text = infoServiceMaster.InvoiceNo;
         txtCreditPeriod.Text = infoServiceMaster.CreditPeriod.ToString();
         strInvoiceNo = infoServiceMaster.InvoiceNo.ToString();
         decServiceSuffixPrefixId = Convert.ToDecimal(infoServiceMaster.SuffixPrefixId.ToString());
         DecServicetVoucherTypeId = Convert.ToDecimal(infoServiceMaster.VoucherTypeId.ToString());
         int inDecimalPlace = PublicVariables._inNoOfDecimalPlaces;
         txtVoucherDate.Text = infoServiceMaster.Date.ToString("dd-MMM-yyyy");
         dtpVoucherDate.Value = Convert.ToDateTime(infoServiceMaster.Date);
         cmbCashParty.SelectedValue = infoServiceMaster.LedgerId;
         cmbServiceAC.SelectedValue = infoServiceMaster.ServiceAccount;
         cmbSalesman.SelectedValue = infoServiceMaster.EmployeeId;
         txtCustomer.Text = infoServiceMaster.Customer;
         txtNarration.Text = infoServiceMaster.Narration;
         DataTable dtblServiceDetails = new DataTable();
         dtblServiceDetails = spServiceDetails.ServiceDetailsViewWithMasterId(decServiceMasterId);
         for (int i = 0; i < dtblServiceDetails.Rows.Count; i++)
         {
             dgvServiceVoucher.Rows.Add();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value = Convert.ToDecimal(dtblServiceDetails.Rows[i]["serviceDetailsId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtServiceMasterId"].Value = Convert.ToDecimal(dtblServiceDetails.Rows[i]["serviceMasterId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value = Convert.ToDecimal(dtblServiceDetails.Rows[i]["serviceId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value = dtblServiceDetails.Rows[i]["measure"].ToString();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value = dtblServiceDetails.Rows[i]["amount"].ToString();
             decimal decDetailsId1 = Convert.ToDecimal(dtblServiceDetails.Rows[i]["serviceDetailsId"].ToString());
             decimal decLedgerPostingId = SpLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, DecServicetVoucherTypeId);
             dgvServiceVoucher.Rows[i].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
         }
         cmbCurrency.SelectedValue = infoServiceMaster.ExchangeRateId;
         txtTotalAmount.Text = infoServiceMaster.TotalAmount.ToString();
         txtDiscount.Text = infoServiceMaster.Discount.ToString();
         txtGrandTotal.Text = infoServiceMaster.GrandTotal.ToString();
         infoPartyBalance = spPartyBalance.PartyBalanceViewByVoucherNoAndVoucherTypeId(DecServicetVoucherTypeId, strVoucherNo, infoServiceMaster.Date);
         decPartyBalanceId = infoPartyBalance.PartyBalanceId;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 32 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #26
0
        /// <summary>
        /// Edit Function
        /// </summary>
        /// <param name="decMasterId"></param>
        public void Edit(decimal decMasterId)
        {
            try
            {
                int inRowCount = dgvPaymentVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
                PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
                PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo();
                PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
                LedgerPostingSP SpLedgerPosting = new LedgerPostingSP();
                LedgerPostingInfo InfoLegerPosting = new LedgerPostingInfo();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                PartyBalanceSP SpPartyBalance = new PartyBalanceSP();
                BankReconciliationSP SpBankReconcilation = new BankReconciliationSP();
                InfoPaymentMaster.Date = dtpDate.Value;
                InfoPaymentMaster.PaymentMasterId = decMasterId;
                InfoPaymentMaster.Extra1 = string.Empty;
                InfoPaymentMaster.Extra2 = string.Empty;
                InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim();
                InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString());
                InfoPaymentMaster.Narration = txtNarration.Text.Trim();
                InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId;
                decimal decTotalAmount = TotalAmountCalculation();
                InfoPaymentMaster.TotalAmount = decTotalAmount;
                InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId;

                InfoPaymentMaster.VoucherNo = strVoucherNo;

                InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId;
                decimal decPaymentMasterId = SpPaymentMaster.PaymentMasterEdit(InfoPaymentMaster);
                if (decPaymentmasterId != 0)
                {
                    MasterLedgerPostingEdit();
                }
                foreach (object obj in arrlstOfRemove)
                {
                    string str = Convert.ToString(obj);
                    SpPaymentDetails.PaymentDetailsDelete(Convert.ToDecimal(str));
                    SpLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decPaymentVoucherTypeId);
                }
                SpLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPaymentVoucherTypeId, 12);
                decimal decPaymentDetailsId1 = 0;
                for (int inI = 0; inI < inRowCount - 1; inI++)
                {
                    InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                    InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                    InfoPaymentDetails.Extra1 = string.Empty;
                    InfoPaymentDetails.Extra2 = string.Empty;
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {
                        InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                    }
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                    {
                        InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                        if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                        }
                        else
                        {
                            InfoPaymentDetails.ChequeDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        InfoPaymentDetails.ChequeNo = string.Empty;
                        InfoPaymentDetails.ChequeDate = DateTime.Now;
                    }
                    InfoPaymentDetails.PaymentMasterId = decPaymentMasterId;
                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].FormattedValue.ToString() == "0")//if new rows are added
                    {
                        if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows added which are completed
                        {
                            decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsAdd(InfoPaymentDetails);//to add new rows in payment details
                            if (decPaymentDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                DetailsLedgerPosting(inI, decPaymentDetailsId);//to add new ledger posting
                            }
                        }
                    }
                    else
                    {
                        if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows updated which are completed
                        {
                            InfoPaymentDetails.PaymentDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString());
                            decimal decPaymentDetailsId = SpPaymentDetails.PaymentDetailsEdit(InfoPaymentDetails);//to edit rows
                            if (decPaymentDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                decPaymentDetailsId1 = InfoPaymentDetails.PaymentDetailsId;
                                decimal decLedgerPostId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString());
                                DetailsLedgerPostingEdit(inI, decLedgerPostId, decPaymentDetailsId1);
                            }
                        }
                        else
                        {
                            decimal decDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString());
                            SpPaymentDetails.PaymentDetailsDelete(decDetailsId);
                            SpLedgerPosting.LedgerPostDeleteByDetailsId(decDetailsId, strVoucherNo, decPaymentVoucherTypeId);
                            for (int inJ = 0; inJ < dtblPartyBalance.Rows.Count; inJ++)
                            {
                                if (dtblPartyBalance.Rows.Count == inJ)
                                {
                                    break;
                                }
                                if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                                {
                                    if (dtblPartyBalance.Rows[inJ]["LedgerId"].ToString() == dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString())
                                    {
                                        if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0")
                                        {
                                            arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]);
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
                DeletePartyBalanceOfRemovedRow();
                isUpdated = true;
                Messages.UpdatedMessage();
                if (cbxPrintafterSave.Checked)
                {
                    if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPaymentmasterId);
                    }
                    else
                    {
                        Print(decPaymentMasterId);
                    }
                }
                if (frmPaymentRegisterObj != null)
                {
                    this.Close();
                    frmPaymentRegisterObj.CallFromPaymentVoucher(this);
                }
                if (frmPaymentReportObj != null)
                {
                    this.Close();
                    frmPaymentReportObj.CallFromPaymentVoucher(this);
                }
                if (frmDayBookObj != null)
                {
                    this.Close();
                }
                if (frmBillallocationObj != null)
                {
                    this.Close();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #27
0
 /// <summary>
 /// Function to edit purchase invoice
 /// </summary>
 public void Edit()
 {
     PurchaseMasterInfo infoPurchaseMaster = new PurchaseMasterInfo();
     PurchaseMasterSP spPurchaseMaster = new PurchaseMasterSP();
     PurchaseDetailsInfo infoPurchaseDetails = new PurchaseDetailsInfo();
     PurchaseDetailsSP spPurchaseDetails = new PurchaseDetailsSP();
     MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo();
     MaterialReceiptMasterSP spMaterialReceiptMaster = new MaterialReceiptMasterSP();
     PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
     PurchaseOrderMasterSP spPurchaseOrderMaster = new PurchaseOrderMasterSP();
     StockPostingInfo infoStockPosting = new StockPostingInfo();
     StockPostingSP spStockPosting = new StockPostingSP();
     LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
     LedgerPostingSP spLedgerPosting = new LedgerPostingSP();
     PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
     PartyBalanceSP spPartyBalance = new PartyBalanceSP();
     AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo();
     AdditionalCostSP spAdditionalCost = new AdditionalCostSP();
     PurchaseBillTaxInfo infoPurchaseBillTax = new PurchaseBillTaxInfo();
     PurchaseBillTaxSP spPurchaseBillTax = new PurchaseBillTaxSP();
     AccountLedgerInfo infoAccountLedger = new AccountLedgerInfo();
     AccountLedgerSP spAccountLedger = new AccountLedgerSP();
     UnitConvertionSP spUnitConvertion = new UnitConvertionSP();
     ExchangeRateSP spExchangeRate = new ExchangeRateSP();
     /*---------------------------------Deleting previous stock posting, Ledger posting, partybalanceposting---------------------------------------*/
     infoPurchaseMaster = spPurchaseMaster.PurchaseMasterView(decPurchaseMasterId);
     if (infoPurchaseMaster.MaterialReceiptMasterId != 0)
     {
         infoMaterialReceiptMaster = spMaterialReceiptMaster.MaterialReceiptMasterView(infoPurchaseMaster.MaterialReceiptMasterId);
         spStockPosting.StockPostingDeleteForSalesInvoiceAgainstDeliveryNote
             (infoPurchaseMaster.VoucherTypeId, infoPurchaseMaster.VoucherNo,
             infoMaterialReceiptMaster.VoucherNo, infoMaterialReceiptMaster.VoucherTypeId);
     }
     spStockPosting.StockPostingDeleteByagainstVoucherTypeIdAndagainstVoucherNoAndVoucherNoAndVoucherType
             (0, "NA", infoPurchaseMaster.VoucherNo, infoPurchaseMaster.VoucherTypeId);
     try
     {
         RemoveDelete();
         /*-----------------------------------------Purchase Master Edit----------------------------------------------------*/
         infoPurchaseMaster.AdditionalCost = Convert.ToDecimal(lblAdditionalCostAmount.Text);
         infoPurchaseMaster.BillDiscount = Convert.ToDecimal(txtBillDiscount.Text);
         infoPurchaseMaster.CreditPeriod = txtCreditPeriod.Text;
         infoPurchaseMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
         infoPurchaseMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoPurchaseMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoPurchaseMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
         infoPurchaseMaster.InvoiceNo = txtVoucherNo.Text;
         if (isAutomatic)
         {
             infoPurchaseMaster.SuffixPrefixId = decPurchaseInvoiceSuffixPrefixId;
             infoPurchaseMaster.VoucherNo = strVoucherNo;
         }
         else
         {
             infoPurchaseMaster.SuffixPrefixId = 0;
             infoPurchaseMaster.VoucherNo = strVoucherNo;
         }
         infoPurchaseMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoPurchaseMaster.LrNo = txtLRNo.Text;
         if (cmbPurchaseMode.Text == "Against MaterialReceipt")
         {
             infoPurchaseMaster.MaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         else
         {
             infoPurchaseMaster.MaterialReceiptMasterId = 0;
         }
         infoPurchaseMaster.Narration = txtNarration.Text;
         infoPurchaseMaster.PurchaseAccount = Convert.ToDecimal(cmbPurchaseAccount.SelectedValue.ToString());
         if (cmbPurchaseMode.Text == "Against PurchaseOrder")
         {
             infoPurchaseMaster.PurchaseOrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         }
         else
         {
             infoPurchaseMaster.PurchaseOrderMasterId = 0;
         }
         infoPurchaseMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
         infoPurchaseMaster.TotalTax = Convert.ToDecimal(lblTaxAmount.Text);
         infoPurchaseMaster.TransportationCompany = txtTransportationCompany.Text;
         infoPurchaseMaster.UserId = PublicVariables._decCurrentUserId;
         infoPurchaseMaster.VendorInvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text);
         infoPurchaseMaster.VendorInvoiceNo = txtVendorInvoiceNo.Text;
         infoPurchaseMaster.VoucherTypeId = decPurchaseInvoiceVoucherTypeId;
         infoPurchaseMaster.Extra1 = string.Empty;
         infoPurchaseMaster.Extra2 = string.Empty;
         infoPurchaseMaster.ExtraDate = Convert.ToDateTime(DateTime.Now);
         infoPurchaseMaster.PurchaseMasterId = decPurchaseMasterId;
         spPurchaseMaster.PurchaseMasterEdit(infoPurchaseMaster);
         infoPurchaseOrderMaster = spPurchaseOrderMaster.PurchaseOrderMasterView(infoPurchaseMaster.PurchaseOrderMasterId);
         infoMaterialReceiptMaster = spMaterialReceiptMaster.MaterialReceiptMasterView(infoPurchaseMaster.MaterialReceiptMasterId);
         spLedgerPosting.LedgerPostDelete(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
         spAccountLedger.PartyBalanceDeleteByVoucherTypeVoucherNoAndReferenceType(strVoucherNo, decPurchaseInvoiceVoucherTypeId);
         foreach (DataGridViewRow dgvrow in dgvProductDetails.Rows)
         {
             if (dgvrow.Cells["dgvtxtProductId"].Value != null)
             {
                 if (dgvrow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty)
                 {
                     /*-----------------------------------------Purchase Details Add----------------------------------------------------*/
                     infoPurchaseDetails.Amount = Convert.ToDecimal(dgvrow.Cells["dgvtxtAmount"].Value.ToString());
                     infoPurchaseDetails.BatchId = Convert.ToDecimal(dgvrow.Cells["dgvcmbBatch"].Value.ToString());
                     infoPurchaseDetails.Discount = Convert.ToDecimal(dgvrow.Cells["dgvtxtDiscount"].Value.ToString());
                     infoPurchaseDetails.GodownId = Convert.ToDecimal(dgvrow.Cells["dgvcmbGodown"].Value.ToString());
                     infoPurchaseDetails.GrossAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtGrossValue"].Value.ToString());
                     infoPurchaseDetails.NetAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtNetValue"].Value.ToString());
                     infoPurchaseDetails.OrderDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     infoPurchaseDetails.ProductId = Convert.ToDecimal(dgvrow.Cells["dgvtxtProductId"].Value.ToString());
                     infoPurchaseDetails.PurchaseMasterId = decPurchaseMasterId;
                     infoPurchaseDetails.Qty = Convert.ToDecimal(dgvrow.Cells["dgvtxtQuantity"].Value.ToString());
                     infoPurchaseDetails.RackId = Convert.ToDecimal(dgvrow.Cells["dgvcmbRack"].Value.ToString());
                     infoPurchaseDetails.Rate = Convert.ToDecimal(dgvrow.Cells["dgvtxtRate"].Value.ToString());
                     infoPurchaseDetails.ReceiptDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtMaterialReceiptDetailsId"].Value.ToString());
                     infoPurchaseDetails.SlNo = Convert.ToInt32(dgvrow.Cells["dgvtxtSlNo"].Value.ToString());
                     infoPurchaseDetails.TaxAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtTaxAmount"].Value.ToString());
                     infoPurchaseDetails.TaxId = Convert.ToDecimal(dgvrow.Cells["dgvcmbTax"].Value.ToString());
                     infoPurchaseDetails.UnitConversionId = Convert.ToDecimal(dgvrow.Cells["dgvtxtUnitConversionId"].Value.ToString());
                     infoPurchaseDetails.UnitId = Convert.ToDecimal(dgvrow.Cells["dgvcmbUnit"].Value.ToString());
                     infoPurchaseDetails.Extra1 = string.Empty;
                     infoPurchaseDetails.Extra2 = string.Empty;
                     infoPurchaseDetails.ExtraDate = Convert.ToDateTime(DateTime.Today);
                     if (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value != null)
                     {
                         if (dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString() == "0" || dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString() == string.Empty)
                         {
                             spPurchaseDetails.PurchaseDetailsAdd(infoPurchaseDetails);
                         }
                         else
                         {
                             infoPurchaseDetails.PurchaseDetailsId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseDetailsId"].Value.ToString());
                             spPurchaseDetails.PurchaseDetailsEdit(infoPurchaseDetails);
                         }
                     }
                     else
                     {
                         spPurchaseDetails.PurchaseDetailsAdd(infoPurchaseDetails);
                     }
                     infoStockPosting.BatchId = infoPurchaseDetails.BatchId;
                     infoStockPosting.Date = infoPurchaseMaster.Date;
                     infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                     infoStockPosting.GodownId = infoPurchaseDetails.GodownId;
                     infoStockPosting.InwardQty = infoPurchaseDetails.Qty; /// spUnitConvertion.UnitConversionRateByUnitConversionId(infoPurchaseDetails.UnitConversionId);
                     infoStockPosting.OutwardQty = 0;
                     infoStockPosting.ProductId = infoPurchaseDetails.ProductId;
                     infoStockPosting.RackId = infoPurchaseDetails.RackId;
                     infoStockPosting.Rate = infoPurchaseDetails.Rate;
                     infoStockPosting.UnitId = infoPurchaseDetails.UnitId;
                     if (infoPurchaseDetails.OrderDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     else if (infoPurchaseDetails.ReceiptDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     else if (infoPurchaseDetails.OrderDetailsId == 0 && infoPurchaseDetails.ReceiptDetailsId == 0)
                     {
                         infoStockPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                         infoStockPosting.AgainstVoucherNo = "NA";
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                     infoStockPosting.Extra1 = string.Empty;
                     infoStockPosting.Extra2 = string.Empty;
                     infoStockPosting.ExtraDate = Convert.ToDateTime(DateTime.Today);
                     spStockPosting.StockPostingAdd(infoStockPosting);
                     if (infoPurchaseDetails.ReceiptDetailsId != 0)
                     {
                         infoStockPosting.InvoiceNo = infoMaterialReceiptMaster.InvoiceNo;
                         infoStockPosting.VoucherNo = infoMaterialReceiptMaster.VoucherNo;
                         infoStockPosting.VoucherTypeId = infoMaterialReceiptMaster.VoucherTypeId;
                         infoStockPosting.AgainstInvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoStockPosting.AgainstVoucherNo = infoPurchaseMaster.VoucherNo;
                         infoStockPosting.AgainstVoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoStockPosting.InwardQty = 0;
                         infoStockPosting.OutwardQty = infoPurchaseDetails.Qty; /// spUnitConvertion.UnitConversionRateByUnitConversionId(infoPurchaseDetails.UnitConversionId);
                         spStockPosting.StockPostingAdd(infoStockPosting);
                     }
                 }
             }
         }
         /*-----------------------------------------Ledger Posting----------------------------------------------------*/
         infoLedgerPosting.Credit = Convert.ToDecimal(txtGrandTotal.Text) * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         infoLedgerPosting.Debit = 0;
         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
         infoLedgerPosting.LedgerId = infoPurchaseMaster.LedgerId;
         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         infoLedgerPosting.ExtraDate = DateTime.Now;
         spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         decimal DecBillDiscount = Convert.ToDecimal(txtBillDiscount.Text.Trim().ToString());
         if (DecBillDiscount > 0)
         {
             infoLedgerPosting.Credit = DecBillDiscount * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoLedgerPosting.Debit = 0;
             infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
             infoLedgerPosting.DetailsId = 0;
             infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
             infoLedgerPosting.LedgerId = 9;//ledger id of discount received ledger
             infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
             infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
             infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
             infoLedgerPosting.ChequeDate = DateTime.Now;
             infoLedgerPosting.ChequeNo = string.Empty;
             infoLedgerPosting.Extra1 = string.Empty;
             infoLedgerPosting.Extra2 = string.Empty;
             infoLedgerPosting.ExtraDate = DateTime.Now;
             spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         }
         infoLedgerPosting.Credit = 0;
         infoLedgerPosting.Debit = TotalNetAmount();// * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
         infoLedgerPosting.LedgerId = infoPurchaseMaster.PurchaseAccount;
         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         infoLedgerPosting.ExtraDate = DateTime.Now;
         spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         foreach (DataGridViewRow dgvrow in dgvAdditionalCost.Rows)
         {
             if (dgvrow.Cells["dgvcmbLedger"].Value != null)
             {
                 if (dgvrow.Cells["dgvcmbLedger"].Value.ToString() != string.Empty)
                 {
                     if (dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value != null)
                     {
                         if (dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value.ToString() != string.Empty)
                         {
                             /*-----------------------------------------Additional Cost Add----------------------------------------------------*/
                             infoAdditionalCost.Credit = 0;
                             infoAdditionalCost.Debit = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCostAmount"].Value.ToString());
                             infoAdditionalCost.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvcmbLedger"].Value.ToString());
                             infoAdditionalCost.VoucherNo = infoPurchaseMaster.VoucherNo;
                             infoAdditionalCost.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                             infoAdditionalCost.Extra1 = string.Empty;
                             infoAdditionalCost.Extra2 = string.Empty;
                             infoAdditionalCost.ExtraDate = DateTime.Now;
                             if (dgvrow.Cells["dgvtxtAdditionalCostId"].Value != null)
                             {
                                 if (dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString() != string.Empty && dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString() != string.Empty)
                                 {
                                     infoAdditionalCost.AdditionalCostId = Convert.ToDecimal(dgvrow.Cells["dgvtxtAdditionalCostId"].Value.ToString());
                                     spAdditionalCost.AdditionalCostEdit(infoAdditionalCost);
                                 }
                                 else
                                 {
                                     spAdditionalCost.AdditionalCostAdd(infoAdditionalCost);
                                 }
                             }
                             else
                             {
                                 spAdditionalCost.AdditionalCostAdd(infoAdditionalCost);
                             }
                             /*-----------------------------------------Additional Cost Ledger Posting----------------------------------------------------*/
                             infoLedgerPosting.Credit = 0;
                             infoLedgerPosting.Debit = infoAdditionalCost.Debit * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                             infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
                             infoLedgerPosting.DetailsId = 0;
                             infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                             infoLedgerPosting.LedgerId = infoAdditionalCost.LedgerId;
                             infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                             infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                             infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                             infoLedgerPosting.ChequeDate = DateTime.Now;
                             infoLedgerPosting.ChequeNo = string.Empty;
                             infoLedgerPosting.Extra1 = string.Empty;
                             infoLedgerPosting.Extra2 = string.Empty;
                             infoLedgerPosting.ExtraDate = DateTime.Now;
                             spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                         }
                     }
                 }
             }
         }
         if (dgvTax.Visible)
         {
             foreach (DataGridViewRow dgvrow in dgvTax.Rows)
             {
                 if (dgvrow.Cells["dgvtxtTaxId"].Value != null)
                 {
                     if (dgvrow.Cells["dgvtxtTaxId"].Value.ToString() != string.Empty)
                     {
                         /*-----------------------------------------PurchaseBillTax Add----------------------------------------------------*/
                         infoPurchaseBillTax.PurchaseMasterId = decPurchaseMasterId;
                         infoPurchaseBillTax.TaxAmount = Convert.ToDecimal(dgvrow.Cells["dgvtxtTotalTax"].Value.ToString());
                         infoPurchaseBillTax.TaxId = Convert.ToDecimal(dgvrow.Cells["dgvtxtTaxId"].Value.ToString());
                         infoPurchaseBillTax.Extra1 = string.Empty;
                         infoPurchaseBillTax.Extra2 = string.Empty;
                         infoPurchaseBillTax.ExtraDate = DateTime.Now;
                         if (dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value != null)
                         {
                             if (dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString() != string.Empty && dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString() != "0")
                             {
                                 infoPurchaseBillTax.PurchaseBillTaxId = Convert.ToDecimal(dgvrow.Cells["dgvtxtPurchaseBillTaxId"].Value.ToString());
                                 spPurchaseBillTax.PurchaseBillTaxEdit(infoPurchaseBillTax);
                             }
                             else
                             {
                                 spPurchaseBillTax.PurchaseBillTaxAdd(infoPurchaseBillTax);
                             }
                         }
                         else
                         {
                             spPurchaseBillTax.PurchaseBillTaxAdd(infoPurchaseBillTax);
                         }
                         /*-----------------------------------------Tax Ledger Posting----------------------------------------------------*/
                         infoLedgerPosting.Credit = 0;
                         infoLedgerPosting.Debit = infoPurchaseBillTax.TaxAmount * spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                         infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate);
                         infoLedgerPosting.DetailsId = 0;
                         infoLedgerPosting.InvoiceNo = infoPurchaseMaster.InvoiceNo;
                         infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvtxtLedgerId"].Value.ToString());
                         infoLedgerPosting.VoucherNo = infoPurchaseMaster.VoucherNo;
                         infoLedgerPosting.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
                         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                         infoLedgerPosting.ChequeDate = DateTime.Now;
                         infoLedgerPosting.ChequeNo = string.Empty;
                         infoLedgerPosting.Extra1 = string.Empty;
                         infoLedgerPosting.Extra2 = string.Empty;
                         infoLedgerPosting.ExtraDate = DateTime.Now;
                         spLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                     }
                 }
             }
         }
         /*-----------------------------------------PartyBalance Posting----------------------------------------------------*/
         infoAccountLedger = spAccountLedger.AccountLedgerView(infoPurchaseMaster.LedgerId);
         if (infoAccountLedger.BillByBill == true)
         {
             infoPartyBalance.Credit = Convert.ToDecimal(txtGrandTotal.Text);
             infoPartyBalance.Debit = 0;
             if (txtCreditPeriod.Text != string.Empty)
             {
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             }
             infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoPartyBalance.ExchangeRateId = infoPurchaseMaster.ExchangeRateId;
             infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoPartyBalance.LedgerId = infoPurchaseMaster.LedgerId;
             infoPartyBalance.ReferenceType = "New";
             infoPartyBalance.InvoiceNo = infoPurchaseMaster.InvoiceNo;
             infoPartyBalance.VoucherNo = infoPurchaseMaster.VoucherNo;
             infoPartyBalance.VoucherTypeId = infoPurchaseMaster.VoucherTypeId;
             infoPartyBalance.AgainstInvoiceNo = "NA";
             infoPartyBalance.AgainstVoucherNo = "NA";
             infoPartyBalance.AgainstVoucherTypeId = 0;
             infoPartyBalance.Extra1 = string.Empty;
             infoPartyBalance.Extra2 = string.Empty;
             infoPartyBalance.ExtraDate = DateTime.Now;
             spPartyBalance.PartyBalanceAdd(infoPartyBalance);
         }
         Messages.UpdatedMessage();
         if (cbxPrintAfterSave.Checked)
         {
             if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decPurchaseMasterId);
             }
             else
             {
                 Print(decPurchaseMasterId);
             }
         }
         Clear();
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("PI39:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }