/// <summary> /// Function to save the voucher /// </summary> public void SaveFunction() { MaterialReceiptDetailsInfo infoMaterialReceiptDetails = new MaterialReceiptDetailsInfo(); ProductInfo infoProduct = new ProductInfo(); MaterialReceiptMasterInfo infoMaterialReceiptMaster = new MaterialReceiptMasterInfo(); StockPostingBll BllStockPosting = new StockPostingBll(); //StockPostingSP spstockposting = new StockPostingSP(); MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll(); ProductCreationBll BllProductCreation = new ProductCreationBll(); try { infoMaterialReceiptMaster.Date = Convert.ToDateTime(txtDate.Text); infoMaterialReceiptMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()); if (isAutomatic) { infoMaterialReceiptMaster.SuffixPrefixId = decMaterialReceiptSuffixPrefixId; infoMaterialReceiptMaster.VoucherNo = strVoucherNo; } else { infoMaterialReceiptMaster.SuffixPrefixId = 0; infoMaterialReceiptMaster.VoucherNo = txtReceiptNo.Text; } infoMaterialReceiptMaster.VoucherTypeId = decMaterialReceiptVoucherTypeId; infoMaterialReceiptMaster.InvoiceNo = txtReceiptNo.Text; infoMaterialReceiptMaster.UserId = PublicVariables._decCurrentUserId; infoMaterialReceiptMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoMaterialReceiptMaster.TransportationCompany = txtTransportation.Text.Trim(); infoMaterialReceiptMaster.LrNo = txtLRNo.Text.Trim(); infoMaterialReceiptMaster.Narration = txtNarration.Text.Trim(); if (cmbOrderNo.SelectedValue == null || cmbOrderNo.SelectedValue.ToString() == string.Empty) { infoMaterialReceiptMaster.OrderMasterId = 0; } else { infoMaterialReceiptMaster.OrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()); } infoMaterialReceiptMaster.exchangeRateId = Convert.ToDecimal(cmbcurrency.SelectedValue.ToString());//saving corresponding exchangeRateId as currencyId infoMaterialReceiptMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text); infoMaterialReceiptMaster.Extra1 = string.Empty; infoMaterialReceiptMaster.Extra2 = string.Empty; infoMaterialReceiptMaster.ExtraDate = Convert.ToDateTime(DateTime.Now); decMaterialReceiptMasterIdentity = Convert.ToDecimal(bllMaterialReceiptMaster.MaterialReceiptMasterAdd(infoMaterialReceiptMaster)); int inRowcount = dgvProduct.Rows.Count; for (int inI = 0; inI < inRowcount - 1; inI++) { infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterIdentity; if (dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty) { infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString()); infoMaterialReceiptDetails.ProductId = infoProduct.ProductId; } if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null) { infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString()); } else infoMaterialReceiptDetails.OrderDetailsId = 0; if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty) { infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString()); } else { infoMaterialReceiptDetails.GodownId = 1; } if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty) { infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString()); } else { infoMaterialReceiptDetails.RackId = 1; } if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value)); } else { infoMaterialReceiptDetails.BatchId = 1; } if (dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty) { infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString()); } if (dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty) { infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString()); infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString()); } infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString()); infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString()); infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString()); infoMaterialReceiptDetails.Extra1 = string.Empty; infoMaterialReceiptDetails.Exta2 = string.Empty; infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now); bllMaterialReceiptMaster.MaterialReceiptDetailsAdd(infoMaterialReceiptDetails); //-----------------Stockposting---------------------------// StockPostingInfo infoStockPosting = new StockPostingInfo(); infoStockPosting.Date = infoMaterialReceiptMaster.Date; infoStockPosting.ProductId = infoMaterialReceiptDetails.ProductId; infoStockPosting.BatchId = infoMaterialReceiptDetails.BatchId; infoStockPosting.UnitId = infoMaterialReceiptDetails.UnitId; infoStockPosting.GodownId = infoMaterialReceiptDetails.GodownId; infoStockPosting.RackId = infoMaterialReceiptDetails.RackId; if (cmbOrderNo.SelectedValue != null) { if (dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != string.Empty) { infoStockPosting.VoucherNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString()); infoStockPosting.AgainstVoucherNo = strVoucherNo; } else { infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.AgainstVoucherNo = "NA"; } if (dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != string.Empty) { infoStockPosting.InvoiceNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString()); infoStockPosting.AgainstInvoiceNo = txtReceiptNo.Text; } else { infoStockPosting.InvoiceNo = txtReceiptNo.Text; infoStockPosting.AgainstInvoiceNo = "NA"; } if (dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString() != string.Empty) { infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString()); infoStockPosting.AgainstVoucherTypeId = decMaterialReceiptVoucherTypeId; } else { infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; } } else { infoStockPosting.InvoiceNo = txtReceiptNo.Text; infoStockPosting.VoucherNo = strVoucherNo; infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId; infoStockPosting.AgainstVoucherTypeId = 0; infoStockPosting.AgainstVoucherNo = "NA"; infoStockPosting.AgainstInvoiceNo = "NA"; } infoStockPosting.InwardQty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString()) / Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value.ToString()); infoStockPosting.OutwardQty = 0; infoStockPosting.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString()); infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoStockPosting.Extra1 = string.Empty; infoStockPosting.Extra2 = string.Empty; BllStockPosting.StockPostingAdd(infoStockPosting); } Messages.SavedMessage(); if (cbxPrintAfterSave.Checked) { SettingsBll BllSettings = new SettingsBll(); if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix") { PrintForDotMatrix(decMaterialReceiptMasterIdentity); } else { Print(decMaterialReceiptMasterIdentity, infoMaterialReceiptMaster.OrderMasterId); } } Clear(); } catch (Exception ex) { MessageBox.Show("MR35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }