/// <summary> /// Function to save stockjournal /// </summary> public void Save() { try { StockJournalMasterInfo infoStockJournalMaster = new StockJournalMasterInfo(); StockJournalMasterSP spStockJournalMaster = new StockJournalMasterSP(); StockJournalDetailsInfo infoStockJournalDetails = new StockJournalDetailsInfo(); StockJournalDetailsSP spStockJournalDetails = new StockJournalDetailsSP(); LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo(); LedgerPostingSP spLedgerPosting = new LedgerPostingSP(); AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo(); AdditionalCostSP spAdditionalCost = new AdditionalCostSP(); UnitConvertionSP SPUnitConversion = new UnitConvertionSP(); if (isAutomatic == true) { infoStockJournalMaster.SuffixPrefixId = decSuffixPrefixId; infoStockJournalMaster.VoucherNo = strVoucherNo; } else { infoStockJournalMaster.SuffixPrefixId = 0; infoStockJournalMaster.VoucherNo = strVoucherNo; } infoStockJournalMaster.ExtraDate = DateTime.Now; infoStockJournalMaster.InvoiceNo = txtVoucherNo.Text.Trim(); infoStockJournalMaster.Date = Convert.ToDateTime(txtDate.Text); infoStockJournalMaster.AdditionalCost = Convert.ToDecimal(lblAdditionalCostAmount.Text); infoStockJournalMaster.VoucherNo = strVoucherNo; infoStockJournalMaster.VoucherTypeId = decVoucherTypeId; infoStockJournalMaster.Narration = txtNarration.Text.Trim(); infoStockJournalMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockJournalMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue); if (rbtnManufacturing.Checked) { infoStockJournalMaster.Extra1 = "Manufacturing"; } if (rbtnTransfer.Checked) { infoStockJournalMaster.Extra1 = "Transfer"; } if (rbtnStockOut.Checked) { infoStockJournalMaster.Extra1 = "Stock Out"; } infoStockJournalMaster.Extra2 = string.Empty; if (btnSave.Text == "Save") { decStockMasterId = spStockJournalMaster.StockJournalMasterAdd(infoStockJournalMaster); } else { infoStockJournalMaster.StockJournalMasterId = decStockJournalMasterIdForEdit; spStockJournalMaster.StockJournalMasterEdit(infoStockJournalMaster); RemoveRowStockJournalConsumptionDetails(); RemoveRowStockJournalProductionDetails(); if (rbtnManufacturing.Checked) { //if (cmbFinishedGoods.SelectedIndex != 0 && txtQty.Text != string.Empty) //{ // txtQty_Leave(sender,e); //} } RemoveRowStockJournalAdditionalCostDetails(); spStockPosting.DeleteStockPostingForStockJournalEdit(strVoucherNo, decVoucherTypeId); } if (dgvConsumption.Rows.Count > 0) { int inCount = dgvConsumption.Rows.Count; for (int i = 0; i < inCount - 1; i++) { if (btnSave.Text == "Save") { infoStockJournalDetails.StockJournalMasterId = decStockMasterId; } else { infoStockJournalMaster.StockJournalMasterId = decStockJournalMasterIdForEdit; } infoStockJournalDetails.Extra1 = string.Empty; infoStockJournalDetails.Extra2 = string.Empty; infoStockJournalDetails.ExtraDate = DateTime.Now; infoStockJournalDetails.ProductId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionProductId"].Value); infoStockJournalDetails.Qty = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionQty"].Value); infoStockJournalDetails.Rate = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionRate"].Value); infoStockJournalDetails.UnitId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionunitId"].Value); infoStockJournalDetails.UnitConversionId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionunitConversionId"].Value); if (btnSave.Text == "Update") { infoStockJournalDetails.StockJournalMasterId = decStockJournalMasterIdForEdit; if (dgvConsumption.Rows[i].Cells["dgvtxtConsumptionStockJournalDetailsId"].Value == null || dgvConsumption.Rows[i].Cells["dgvtxtConsumptionStockJournalDetailsId"].Value.ToString() == string.Empty) { if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value.ToString() != string.Empty) { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value); } else { infoStockJournalDetails.BatchId = 0; } if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value.ToString() != string.Empty) { infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value); } else { infoStockJournalDetails.GodownId = 0; } if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value.ToString() != string.Empty) { infoStockJournalDetails.RackId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value); } else { infoStockJournalDetails.RackId = 0; } infoStockJournalDetails.Amount = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Consumption"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionSlNo"].Value); spStockJournalDetails.StockJournalDetailsAdd(infoStockJournalDetails); } else { infoStockJournalDetails.StockJournalDetailsId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionStockJournalDetailsId"].Value); if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value.ToString() != string.Empty) { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value); } else { infoStockJournalDetails.BatchId = 0; } if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value.ToString() != string.Empty) { infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value); } else { infoStockJournalDetails.GodownId = 0; } if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value != null && dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value.ToString() != string.Empty) { infoStockJournalDetails.RackId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value); } else { infoStockJournalDetails.RackId = 0; } infoStockJournalDetails.Amount = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Consumption"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionSlNo"].Value); spStockJournalDetails.StockJournalDetailsEdit(infoStockJournalDetails); } } else { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value); infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value); infoStockJournalDetails.RackId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value); infoStockJournalDetails.Amount = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Consumption"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionSlNo"].Value); spStockJournalDetails.StockJournalDetailsAdd(infoStockJournalDetails); } //Stock Posting Add if (btnSave.Text == "Update") { infoStockPosting.BatchId = infoStockJournalDetails.BatchId; infoStockPosting.Date = Convert.ToDateTime(txtDate.Text); infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockPosting.GodownId = infoStockJournalDetails.GodownId; infoStockPosting.InwardQty = 0; infoStockPosting.OutwardQty = infoStockJournalDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(infoStockJournalDetails.UnitConversionId); infoStockPosting.ProductId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionProductId"].Value); infoStockPosting.RackId = infoStockJournalDetails.RackId; infoStockPosting.Rate = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionRate"].Value); infoStockPosting.UnitId = infoStockJournalDetails.UnitId; infoStockPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.VoucherTypeId = decVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.AgainstInvoiceNo = "NA"; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; spStockPosting.StockPostingAdd(infoStockPosting); } else { infoStockPosting.BatchId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionBatch"].Value); infoStockPosting.Date = Convert.ToDateTime(txtDate.Text); infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockPosting.GodownId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value); infoStockPosting.InwardQty = 0; infoStockPosting.OutwardQty = infoStockJournalDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(infoStockJournalDetails.UnitConversionId); infoStockPosting.ProductId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionProductId"].Value); infoStockPosting.RackId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionRack"].Value); infoStockPosting.Rate = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionRate"].Value); infoStockPosting.UnitId = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvcmbConsumptionunitId"].Value); infoStockPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.VoucherTypeId = decVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.AgainstInvoiceNo = "NA"; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; spStockPosting.StockPostingAdd(infoStockPosting); } } } if (dgvProduction.Rows.Count > 0) { int inCount = dgvProduction.Rows.Count; for (int i = 0; i < inCount - 1; i++) { if (btnSave.Text == "Update") { infoStockJournalMaster.StockJournalMasterId = decStockJournalMasterIdForEdit; } else { infoStockJournalDetails.StockJournalMasterId = decStockMasterId; } infoStockJournalDetails.Extra1 = string.Empty; infoStockJournalDetails.Extra2 = string.Empty; infoStockJournalDetails.ExtraDate = DateTime.Now; infoStockJournalDetails.ProductId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionProductId"].Value); infoStockJournalDetails.Qty = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionQty"].Value); infoStockJournalDetails.Rate = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionRate"].Value); infoStockJournalDetails.UnitId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionunitId"].Value); infoStockJournalDetails.UnitConversionId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionunitConversionId"].Value); if (btnSave.Text == "Update") { infoStockJournalDetails.StockJournalMasterId = decStockJournalMasterIdForEdit; if (dgvProduction.Rows[i].Cells["dgvtxtProductionStockJournalDetailsId"].Value == null || dgvProduction.Rows[i].Cells["dgvtxtProductionStockJournalDetailsId"].Value.ToString() == string.Empty) { if (dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value.ToString() != string.Empty) { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value); } else { infoStockJournalDetails.BatchId = 0; } if (dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value.ToString() != string.Empty) { infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value); } else { infoStockJournalDetails.GodownId = 0; } if (dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value.ToString() != string.Empty) { infoStockJournalDetails.RackId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value); } else { infoStockJournalDetails.RackId = 0; } infoStockJournalDetails.Amount = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Production"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvProduction.Rows[i].Cells["dgvtxtProductionSlNo"].Value); spStockJournalDetails.StockJournalDetailsAdd(infoStockJournalDetails); } else { infoStockJournalDetails.StockJournalDetailsId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionStockJournalDetailsId"].Value); if (dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value.ToString() != string.Empty) { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value); } else { infoStockJournalDetails.BatchId = 0; } if (dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value.ToString() != string.Empty) { infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value); } else { infoStockJournalDetails.GodownId = 0; } if (dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value != null && dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value.ToString() != string.Empty) { infoStockJournalDetails.RackId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value); } else { infoStockJournalDetails.RackId = 0; } infoStockJournalDetails.Amount = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Production"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvProduction.Rows[i].Cells["dgvtxtProductionSlNo"].Value); spStockJournalDetails.StockJournalDetailsEdit(infoStockJournalDetails); } } else { infoStockJournalDetails.BatchId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value); infoStockJournalDetails.GodownId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value); infoStockJournalDetails.RackId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value); infoStockJournalDetails.Amount = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionAmount"].Value); infoStockJournalDetails.ConsumptionOrProduction = "Production"; infoStockJournalDetails.Slno = Convert.ToInt32(dgvProduction.Rows[i].Cells["dgvtxtProductionSlNo"].Value); spStockJournalDetails.StockJournalDetailsAdd(infoStockJournalDetails); } //Stock Posting Add if (btnSave.Text == "Save") { infoStockPosting.BatchId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionBatch"].Value); infoStockPosting.Date = Convert.ToDateTime(txtDate.Text); infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockPosting.GodownId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value); infoStockPosting.InwardQty = infoStockJournalDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(infoStockJournalDetails.UnitConversionId); infoStockPosting.OutwardQty = 0; infoStockPosting.ProductId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionProductId"].Value); infoStockPosting.RackId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionRack"].Value); infoStockPosting.Rate = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionRate"].Value); infoStockPosting.UnitId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvcmbProductionunitId"].Value); infoStockPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.VoucherTypeId = decVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.AgainstInvoiceNo = "NA"; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; spStockPosting.StockPostingAdd(infoStockPosting); } else { infoStockPosting.BatchId = infoStockJournalDetails.BatchId; infoStockPosting.Date = Convert.ToDateTime(txtDate.Text); infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockPosting.GodownId = infoStockJournalDetails.GodownId; infoStockPosting.InwardQty = infoStockJournalDetails.Qty / SPUnitConversion.UnitConversionRateByUnitConversionId(infoStockJournalDetails.UnitConversionId); infoStockPosting.OutwardQty = 0; infoStockPosting.ProductId = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionProductId"].Value); infoStockPosting.RackId = infoStockJournalDetails.RackId; infoStockPosting.Rate = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionRate"].Value); infoStockPosting.UnitId = infoStockJournalDetails.UnitId; infoStockPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.VoucherTypeId = decVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.AgainstInvoiceNo = "NA"; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; spStockPosting.StockPostingAdd(infoStockPosting); } } } //....Additional Cost Add...//// if (btnSave.Text == "Update") { spLedgerPosting.DeleteLedgerPostingForStockJournalEdit(strVoucherNo, decVoucherTypeId);//Delete spAdditionalCost.DeleteAdditionalCostForStockJournalEdit(strVoucherNo, decVoucherTypeId);//Delete } decimal decGrandTotal = 0; decimal decRate = 0; ExchangeRateSP spExchangeRate = new ExchangeRateSP(); if (dgvAdditionalCost.Rows.Count > 1) { infoAdditionalCost.Credit = Convert.ToDecimal(lblAdditionalCostAmount.Text); infoAdditionalCost.Debit = 0; infoAdditionalCost.LedgerId = Convert.ToDecimal(cmbCashOrBank.SelectedValue); infoAdditionalCost.VoucherNo = strVoucherNo; infoAdditionalCost.VoucherTypeId = decVoucherTypeId; infoAdditionalCost.Extra1 = string.Empty; infoAdditionalCost.Extra2 = string.Empty; infoAdditionalCost.ExtraDate = DateTime.Now; spAdditionalCost.AdditionalCostAdd(infoAdditionalCost); //....Ledger Posting Add.../// //------------------- Currency Conversion----------------------------- decGrandTotal = Convert.ToDecimal(lblAdditionalCostAmount.Text.Trim()); decRate = spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString())); decGrandTotal = decGrandTotal * decRate; //--------------------------------------------------------------- infoLedgerPosting.Credit = decGrandTotal; infoLedgerPosting.Debit = 0; infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate); infoLedgerPosting.DetailsId = 0; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbCashOrBank.SelectedValue); infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.VoucherTypeId = decVoucherTypeId; infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId; infoLedgerPosting.ChequeDate = DateTime.Now; infoLedgerPosting.ChequeNo = string.Empty; infoLedgerPosting.Extra1 = string.Empty; infoLedgerPosting.Extra2 = string.Empty; if (btnSave.Text == "Save") { infoLedgerPosting.ExtraDate = DateTime.Now; } spLedgerPosting.LedgerPostingAdd(infoLedgerPosting); foreach (DataGridViewRow dgvrow in dgvAdditionalCost.Rows) { if (dgvrow.Cells["dgvcmbAdditionalCostLedger"].Value != null) { if (dgvrow.Cells["dgvcmbAdditionalCostLedger"].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["dgvcmbAdditionalCostLedger"].Value.ToString()); infoAdditionalCost.VoucherNo = strVoucherNo; infoAdditionalCost.VoucherTypeId = decVoucherTypeId; infoAdditionalCost.Extra1 = string.Empty; infoAdditionalCost.Extra2 = string.Empty; infoAdditionalCost.ExtraDate = DateTime.Now; spAdditionalCost.AdditionalCostAdd(infoAdditionalCost); /*-----------------------------------------Additional Cost Ledger Posting----------------------------------------------------*/ decimal decTotal = 0; //------------------- Currency Conversion------------------------ decTotal = Convert.ToDecimal(infoAdditionalCost.Debit); decRate = spExchangeRate.ExchangeRateViewByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString())); decTotal = decTotal * decRate; //--------------------------------------------------------------- infoLedgerPosting.Credit = 0; infoLedgerPosting.Debit = decTotal; infoLedgerPosting.Date = Convert.ToDateTime(PublicVariables._dtCurrentDate); infoLedgerPosting.DetailsId = 0; infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim(); infoLedgerPosting.LedgerId = Convert.ToDecimal(dgvrow.Cells["dgvcmbAdditionalCostLedger"].Value.ToString()); infoLedgerPosting.VoucherNo = strVoucherNo; infoLedgerPosting.VoucherTypeId = decVoucherTypeId; 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 (btnSave.Text == "Save") { Messages.SavedMessage(); if (cbxPrintAfterSave.Checked) { Print(decStockMasterId); } Clear(); } else { Messages.UpdatedMessage(); if (cbxPrintAfterSave.Checked) { Print(decStockJournalMasterIdForEdit); } this.Close(); } } catch (Exception ex) { MessageBox.Show("SJ:36" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Save function /// </summary> public void SaveFunction() { SalesMasterSP spSalesMaster = new SalesMasterSP(); SalesDetailsSP spSalesDetails = new SalesDetailsSP(); StockPostingInfo infoStockPosting = new StockPostingInfo(); SalesMasterInfo InfoSalesMaster = new SalesMasterInfo(); SalesDetailsInfo InfoSalesDetails = new SalesDetailsInfo(); StockPostingSP spStockPosting = new StockPostingSP(); AdditionalCostInfo infoAdditionalCost = new AdditionalCostInfo(); AdditionalCostSP spAdditionalCost = new AdditionalCostSP(); SalesBillTaxInfo infoSalesBillTax = new SalesBillTaxInfo(); SalesBillTaxSP spSalesBillTax = new SalesBillTaxSP(); UnitConvertionSP SPUnitConversion = new UnitConvertionSP(); try { InfoSalesMaster.AdditionalCost = Convert.ToDecimal(lblLedgerTotalAmount.Text); InfoSalesMaster.BillDiscount = Convert.ToDecimal(txtBillDiscount.Text.Trim()); InfoSalesMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text.Trim().ToString()); InfoSalesMaster.CustomerName = txtCustomer.Text.Trim(); InfoSalesMaster.Date = Convert.ToDateTime(txtDate.Text.ToString()); InfoSalesMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()); InfoSalesMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString()); InfoSalesMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; InfoSalesMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text.Trim()); InfoSalesMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()); InfoSalesMaster.VoucherTypeId = DecSalesInvoiceVoucherTypeId; if (isAutomatic) { InfoSalesMaster.InvoiceNo = txtInvoiceNo.Text.Trim(); InfoSalesMaster.VoucherNo = strVoucherNo; InfoSalesMaster.SuffixPrefixId = decSalseInvoiceSuffixPrefixId; } else { InfoSalesMaster.InvoiceNo = txtInvoiceNo.Text.Trim(); InfoSalesMaster.VoucherNo = strVoucherNo; InfoSalesMaster.SuffixPrefixId = 0; } if (cmbSalesMode.Text == "Against SalesOrder") { InfoSalesMaster.OrderMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()); } else { InfoSalesMaster.OrderMasterId = 0; } if (cmbSalesMode.Text == "Against Delivery Note") { InfoSalesMaster.DeliveryNoteMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()); } else { InfoSalesMaster.DeliveryNoteMasterId = 0; } if (cmbSalesMode.Text == "Against Quotation") { InfoSalesMaster.QuotationMasterId = Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()); } else { InfoSalesMaster.QuotationMasterId = 0; } InfoSalesMaster.Narration = txtNarration.Text.Trim(); InfoSalesMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString()); InfoSalesMaster.SalesAccount = Convert.ToDecimal(cmbSalesAccount.SelectedValue.ToString()); InfoSalesMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text.Trim()); if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible) { InfoSalesMaster.TaxAmount = Convert.ToDecimal(lblTaxTotalAmount.Text.Trim()); } else { InfoSalesMaster.TaxAmount = 0; } InfoSalesMaster.UserId = PublicVariables._decCurrentUserId; InfoSalesMaster.LrNo = txtVehicleNo.Text; InfoSalesMaster.TransportationCompany = txtTransportCompany.Text.Trim(); InfoSalesMaster.POS = false; InfoSalesMaster.CounterId = 0; InfoSalesMaster.ExtraDate = DateTime.Now; InfoSalesMaster.Extra1 = string.Empty; InfoSalesMaster.Extra2 = string.Empty; decimal decSalesMasterId = spSalesMaster.SalesMasterAdd(InfoSalesMaster); int inRowCount = dgvSalesInvoice.RowCount; InfoSalesDetails.SalesMasterId = decSalesMasterId; InfoSalesDetails.ExtraDate = DateTime.Now; InfoSalesDetails.Extra1 = string.Empty; InfoSalesDetails.Extra2 = string.Empty; string strAgainstInvoiceN0 = txtInvoiceNo.Text.Trim(); for (int inI = 0; inI < inRowCount - 1; inI++) { 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 (cmbSalesMode.Text == "Against SalesOrder") { InfoSalesDetails.OrderDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSISalesOrderDetailsId"].Value.ToString()); } else { InfoSalesDetails.OrderDetailsId = 0; } if (cmbSalesMode.Text == "Against Delivery Note") { InfoSalesDetails.DeliveryNoteDetailsId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString()); } else { InfoSalesDetails.DeliveryNoteDetailsId = 0; } if (cmbSalesMode.Text == "Against Quotation") { 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()); 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()); InfoSalesDetails.BatchId = Convert.ToDecimal(dgvSalesInvoice.Rows[inI].Cells["dgvcmbSalesInvoiceBatch"].Value.ToString()); 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; } 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 = 1; InfoSalesDetails.TaxAmount = 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); 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; } 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 = InfoSalesMaster.VoucherNo; ; infoStockPosting.VoucherTypeId = DecSalesInvoiceVoucherTypeId; infoStockPosting.InvoiceNo = InfoSalesMaster.InvoiceNo; infoStockPosting.AgainstInvoiceNo = "NA"; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; spStockPosting.StockPostingAdd(infoStockPosting); } } } if (dgvSalesInvoice.Columns["dgvcmbSalesInvoiceTaxName"].Visible) { int inTaxRowCount = dgvSalesInvoiceTax.RowCount; infoSalesBillTax.SalesMasterId = decSalesMasterId; infoSalesBillTax.ExtraDate = DateTime.Now; infoSalesBillTax.Extra1 = string.Empty; infoSalesBillTax.Extra2 = string.Empty; for (int inI = 0; inI < inTaxRowCount; inI++) { if (dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value != null && dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value.ToString() != string.Empty) { if (dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value != null && dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value.ToString() != string.Empty) { decimal decAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value); if (decAmount > 0) { infoSalesBillTax.TaxId = Convert.ToInt32(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxId"].Value.ToString()); infoSalesBillTax.TaxAmount = Convert.ToDecimal(dgvSalesInvoiceTax.Rows[inI].Cells["dgvtxtTtaxAmount"].Value.ToString()); spSalesBillTax.SalesBillTaxAdd(infoSalesBillTax); } } } } } int inAddRowCount = dgvSalesInvoiceLedger.RowCount; infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId; infoAdditionalCost.VoucherNo = strVoucherNo; infoAdditionalCost.ExtraDate = DateTime.Now; infoAdditionalCost.Extra1 = string.Empty; infoAdditionalCost.Extra2 = string.Empty; for (int inI = 0; inI < inAddRowCount; inI++) { if (dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value != null && dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString() != string.Empty) { if (dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value != null && dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString() != string.Empty) { infoAdditionalCost.LedgerId = Convert.ToInt32(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvCmbAdditionalCostledgerName"].Value.ToString()); if (!cmbCashOrbank.Visible) { infoAdditionalCost.Debit = 0; infoAdditionalCost.Credit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString()); } else { infoAdditionalCost.Debit = Convert.ToDecimal(dgvSalesInvoiceLedger.Rows[inI].Cells["dgvtxtAdditionalCoastledgerAmount"].Value.ToString()); infoAdditionalCost.Credit = 0; } spAdditionalCost.AdditionalCostAdd(infoAdditionalCost); } } } if (!cmbCashOrbank.Visible) { decimal decCAshOrBankId = 0; decCAshOrBankId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()); decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString()); if (decTotalAddAmount > 0) { infoAdditionalCost.Debit = decTotalAddAmount; infoAdditionalCost.Credit = 0; infoAdditionalCost.LedgerId = decCAshOrBankId; infoAdditionalCost.VoucherTypeId = DecSalesInvoiceVoucherTypeId; infoAdditionalCost.VoucherNo = strVoucherNo; infoAdditionalCost.ExtraDate = DateTime.Now; infoAdditionalCost.Extra1 = string.Empty; infoAdditionalCost.Extra2 = string.Empty; spAdditionalCost.AdditionalCostAdd(infoAdditionalCost); } } else { if (cmbCashOrbank.Visible) { decimal decCAshOrBankId = 0; decCAshOrBankId = Convert.ToDecimal(cmbCashOrbank.SelectedValue.ToString()); decimal decTotalAddAmount = Convert.ToDecimal(lblLedgerTotalAmount.Text.Trim().ToString()); if (decTotalAddAmount > 0) { 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.AdditionalCostAdd(infoAdditionalCost); } } } ledgerPostingAdd(); if (spSalesMaster.SalesInvoiceInvoicePartyCheckEnableBillByBillOrNot(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()))) { partyBalanceAdd(); } Messages.SavedMessage(); if (cbxPrintAfterSave.Checked == true) { SettingsSP spSettings = new SettingsSP(); if (spSettings.SettingsStatusCheck("Printer") == "Dot Matrix") { PrintForDotMatrix(decSalesMasterId); } else { Print(decSalesMasterId); } } Clear(); } catch (Exception ex) { MessageBox.Show("SI: 70" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <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 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); } }