Beispiel #1
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);
            }
        }
Beispiel #2
0
        /// <summary>
        ///FunctionToFill ProductDetales
        /// </summary>
        /// <param name="strProduct"></param>
        /// <param name="inRowIndex"></param>
        /// <param name="strFillMode"></param>
        public void ProductDetailsFill(string strProduct, int inRowIndex, string strFillMode)
        {
            try
            {
                string barcode = string.Empty;
                decimal decCurrentConversionRate = 0;
                DataTable dtbl = new DataTable();
                UnitConvertionSP spUnitConversion = new UnitConvertionSP();
                SalesReturnDetailsSP spdetailes = new SalesReturnDetailsSP();
                BatchSP spbatch = new BatchSP();
                ProductSP spproduct = new ProductSP();
                if (strFillMode == "dgvTextBarcode")
                {
                    dtbl = spdetailes.productviewbybarcodeforSR(strProduct, decSalesReturnVoucherTypeId);
                }
                if (strFillMode == "dgvTextProductName")
                {
                    dtbl = spproduct.ProductCodeViewByProductName(strProduct, decSalesReturnVoucherTypeId);
                }
                if (strFillMode == "dgvTextProductCode")
                {
                    dtbl = spproduct.ProductNameViewByProductCode(strProduct, decSalesReturnVoucherTypeId);
                }
                if (dtbl.Rows.Count != 0)
                {
                    DGVGodownComboFill();

                    //  SerialNo();
                    dgvSalesReturn.Rows[inRowIndex].Cells["productId"].Value = dtbl.Rows[0]["productId"];
                    decimal decProductId = Convert.ToDecimal(dgvSalesReturn.Rows[inRowIndex].Cells["productId"].Value.ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextBarcode"].Value = dtbl.Rows[0]["barcode"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductCode"].Value = dtbl.Rows[0]["productCode"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductName"].Value = dtbl.Rows[0]["productName"];
                    // dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = dtbl.Rows[0]["qty"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = string.Empty;
                    UnitComboFill(decProductId, inRowIndex, dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(dtbl.Rows[0]["unitId"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["unitConversionId"].Value = dtbl.Rows[0]["unitConversionId"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(dtbl.Rows[0]["godownId"].ToString());
                    RackComboFill(Convert.ToDecimal(dtbl.Rows[0]["godownId"].ToString()), inRowIndex, dgvSalesReturn.CurrentRow.Cells["dgvCmbRack"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(dtbl.Rows[0]["rackId"].ToString());
                    BatchComboFill(decProductId, inRowIndex, dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].ColumnIndex);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(dtbl.Rows[0]["batchId"].ToString());
                    decimal decBatchId = Convert.ToDecimal(dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value.ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextRate"].Value = Math.Round(Convert.ToDecimal(dtbl.Rows[0]["salesRate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                    getProductRate(inRowIndex, decProductId, decBatchId);
                    TaxGridFill();
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbTax"].Value = Convert.ToDecimal(dtbl.Rows[0]["taxId"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].Cells["conversionRate"].Value = dtbl.Rows[0]["conversionRate"];
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountPercentage"].Value = dtbl.Rows[0]["discountPercent"].ToString();
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(dtbl.Rows[0]["discount"]), PublicVariables._inNoOfDecimalPlaces);
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].ReadOnly = true;
                    dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(dtbl.Rows[0]["netvalue"]), PublicVariables._inNoOfDecimalPlaces);
                    GrossValueCalculation(inRowIndex);
                    DiscountCalculationfordiscountpercentage(inRowIndex, 12);
                    DiscountCalculation(inRowIndex, 13);
                    TotalAmountCalculation();
                    TaxAmountCalculation(inRowIndex);
                    taxamountfill();
                    CessTaxamountCalculation();
                    TotalBillTaxCalculation();
                    TotalTaxAmtCalculation();
                    GrandTotalCalculation();
                    taxAndGridTotalAmountCalculation(inRowIndex);
                    decCurrentConversionRate = Convert.ToDecimal(dtbl.Rows[0]["conversionRate"].ToString());
                    dgvSalesReturn.Rows[inRowIndex].HeaderCell.Value = "X";
                    dgvSalesReturn.Rows[inRowIndex].HeaderCell.Style.ForeColor = Color.Red;
                }
                else
                {
                    if (dgvSalesReturn.CurrentRow.Index < dgvSalesReturn.RowCount - 1)
                    {
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextBarcode"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductCode"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextProductName"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextQty"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbUnit"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbGodown"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbBatch"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbRack"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextRate"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvCmbTax"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountPercentage"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextDiscountAmount"].Value = string.Empty;
                        dgvSalesReturn.Rows[inRowIndex].Cells["dgvTextNetValue"].Value = string.Empty;
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("SR74" + ex.Message, "openmiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #3
0
        /// <summary>
        /// FunctionToreturn fromregisterclick
        /// </summary>
        public void FillRegisterOrReport()
        {
            SalesReturnMasterSP spSalesReturnMaster = new SalesReturnMasterSP();
            SalesReturnDetailsSP spSalesReturnDetails = new SalesReturnDetailsSP();
            try
            {
                isFromOther = true;
                btnSave.Text = "Update";
                btnDelete.Enabled = true;
                CashOrPartyUnderSundryDebitorComboFill(cmbCashOrParty);
                DataTable dtblSalesMaster = new DataTable();
                DataTable dtblSalesReturnMaster = new DataTable();
                dtblSalesReturnMaster = spSalesReturnMaster.SalesReturnMasterViewBySalesReturnMasterId(salesReturnMasterId);
                decSalesReturnMasterId = salesReturnMasterId;
                DecSalesReturnVoucherTypeId = Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString());
                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                infoVoucherType = spVoucherType.VoucherTypeView(DecSalesReturnVoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;
                if (infoVoucherType.MethodOfVoucherNumbering == "Manual")
                {
                    txtReturnNo.Text = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    ManualReturnNo = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = true;
                }
                else
                {
                    txtReturnNo.Text = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = false;
                }
                if (dtblSalesReturnMaster.Rows.Count > 0)
                {
                    txtDate.Text = dtblSalesReturnMaster.Rows[0]["date"].ToString();
                    dtpDate.Value = Convert.ToDateTime(txtDate.Text);
                    if (dtblSalesReturnMaster.Rows[0]["grandTotal"].ToString() != string.Empty)
                    {
                        txtGrandTotal.Text = dtblSalesReturnMaster.Rows[0]["grandTotal"].ToString();
                    }
                    strVoucherNo = dtblSalesReturnMaster.Rows[0]["voucherNo"].ToString();
                    if (dtblSalesReturnMaster.Rows[0]["ledgerId"].ToString() != string.Empty)
                    {
                        cmbCashOrParty.SelectedValue = dtblSalesReturnMaster.Rows[0]["ledgerId"].ToString();
                    }
                    cmbVoucherTypeComboFill();
                    if (dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                    {
                        cmbVoucherType.SelectedValue = dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString();
                    }
                    else
                    {
                        cmbVoucherType.SelectedValue = 0;
                    }
                    cmbInvoiceComboFill();
                    if (dtblSalesReturnMaster.Rows[0]["pricingLevelId"].ToString() != string.Empty)
                    {
                        cmbPricingLevel.SelectedValue = dtblSalesReturnMaster.Rows[0]["pricingLevelId"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["salesAccount"].ToString() != string.Empty)
                    {
                        cmbSalesAccount.SelectedValue = dtblSalesReturnMaster.Rows[0]["salesAccount"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["employeeId"].ToString() != string.Empty)
                    {
                        cmbSalesMan.SelectedValue = dtblSalesReturnMaster.Rows[0]["employeeId"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["exchangeRateId"].ToString() != string.Empty)
                    {
                        cmbCurrency.SelectedValue = dtblSalesReturnMaster.Rows[0]["exchangeRateId"].ToString();
                    }
                    txtNarration.Text = dtblSalesReturnMaster.Rows[0]["narration"].ToString();
                    txtLRNo.Text = dtblSalesReturnMaster.Rows[0]["lrNo"].ToString();
                    txtTransportationComp.Text = dtblSalesReturnMaster.Rows[0]["transportationCompany"].ToString();
                    if (dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString() != string.Empty && Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString()) != 0)
                    {
                        cmbInvoiceNo.SelectedValue = dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString();
                        decinvoiceno = Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString());
                        dtblSalesReturnMasterViewBySMID = spSalesReturnMaster.SalesReturnMasterViewBySalesMasterId(Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString()));
                    }
                    isInvoiceFill = false;
                    if (dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString() != string.Empty)
                    {
                        decSalesReturnVoucherTypeId = Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString());
                    }
                    TaxGridFill();
                    if (cmbInvoiceNo.SelectedValue != null)
                    {
                        infoSalesMaster = spSalesMaster.SalesMasterViewBySalesMasterId(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    }
                    DataTable dtblSalesReturnDetails = new DataTable();
                    dtblSalesReturnDetails = spSalesReturnDetails.SalesReturnDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                    dtblSalesInvoice = dtblSalesReturnDetails;
                    foreach (DataRow drowDetails in dtblSalesReturnDetails.Rows)
                    {
                        dgvSalesReturn.Rows.Add();
                        if (drowDetails["salesReturnDetailsId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesReturnDetailsId"].Value = Convert.ToDecimal(drowDetails["salesReturnDetailsId"].ToString());
                        }
                        if (drowDetails["salesDetailsId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = drowDetails["salesDetailsId"].ToString();
                        }
                        else
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = 0;
                        }
                        if (drowDetails["productId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = drowDetails["productId"].ToString();
                            DataTable dtbl = spSalesDetails.SalesReturnGrideFillNewByProductId(Convert.ToDecimal(drowDetails["productId"].ToString()));
                            foreach (DataRow drowDetails1 in dtbl.Rows)
                            {
                                if (drowDetails1["barcode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].Value = drowDetails1["barcode"].ToString();
                                }
                                if (drowDetails1["productCode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].Value = drowDetails1["productCode"].ToString();
                                }
                                if (drowDetails1["productName"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].Value = drowDetails1["productName"].ToString();
                                }
                                if (cmbInvoiceNo.Visible == true)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                }
                                if (drowDetails["unitId"].ToString() != string.Empty)
                                {
                                    decProductId = decimal.Parse(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value.ToString());
                                    UnitComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = 1;
                                }
                                if (drowDetails["goDownId"].ToString() != string.Empty)
                                {
                                    DGVGodownComboFill();
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(drowDetails["goDownId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = 1;
                                }
                                if (drowDetails["rackId"].ToString() != string.Empty)
                                {
                                    RackComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value.ToString()), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = 1;
                                }
                                if (drowDetails["batchId"].ToString() != string.Empty)
                                {
                                    BatchComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                                }
                                if (drowDetails["unitConversionId"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = 0;
                                }
                                if (dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ReadOnly = true;
                                }
                                if (drowDetails["taxId"].ToString() != string.Empty)
                                {
                                    if (Convert.ToDecimal(drowDetails["taxId"].ToString()) != 0)
                                    {
                                        dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                        dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                        strTaxRate = spSalesReturnMaster.TaxRateFindForTaxAmmountCalByTaxId(Convert.ToDecimal(drowDetails["taxId"].ToString()));
                                    }
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = 1;
                                }
                                if (drowDetails["qty"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    decQty = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = 0.00;
                                    decQty = 0;
                                }
                                if (drowDetails["rate"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = Math.Round(Convert.ToDecimal(drowDetails["rate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    decRate = Convert.ToDecimal(drowDetails["rate"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = 0.00;
                                    decRate = 0;
                                }
                                if (drowDetails["grossAmount"].ToString() != string.Empty)
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["grossAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    // dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                }
                                else
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = 0.00;
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                }
                                if (drowDetails["discount"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                }
                                if (drowDetails["netAmount"].ToString() != string.Empty)
                                {
                                    // dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["netAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    //  dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                }
                                if (drowDetails["taxAmount"].ToString() != string.Empty)
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                }
                                if (drowDetails["amount"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = Math.Round(Convert.ToDecimal(drowDetails["amount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                }
                                if (cmbInvoiceNo.Visible == true)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextBarcode"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductCode"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductName"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextQty"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbUnit"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbGodown"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbRack"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbBatch"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextRate"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextDiscountPercentage"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbTax"].ReadOnly = true;
                                }
                                dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["conversionRate"].Value = drowDetails["conversionRate"].ToString();
                                foreach (DataGridViewRow item1 in dgvSalesReturn2.Rows)
                                {
                                    if (item1.Cells["dgvTextTaxId"].Value != null)
                                    {
                                        if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() == item1.Cells["dgvTextTaxId"].Value.ToString())
                                        {
                                            item1.Cells["dgvTextAmount"].Value = dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = 0;
                        }
                        TotalAmountCalculation();
                    }
                    if (!isSalesReturnFormActive)
                    {
                        dtblTaxGride = spSalesReturnBillTax.TaxDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                        foreach (DataRow item1 in dtblTaxGride.Rows)
                        {
                            dgvSalesReturn2.Rows.Add();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxName"].Value = item1["taxName"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextAmount"].Value = Math.Round(Convert.ToDecimal(item1["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvRate"].Value = item1["rate"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxId"].Value = item1["taxId"].ToString();
                        }
                    }
                    txtBillDiscount.Text = Convert.ToString(Math.Round(Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces));
                    SerialNo2();

                    TotalBillTaxCalculation();
                    CessTaxamountCalculation();
                    TotalTaxAmtCalculation();
                    if (txtBillDiscount.Text != string.Empty)
                    {
                        decimal decDiscount = Convert.ToDecimal(txtBillDiscount.Text);
                        decimal decTotalAmt = Convert.ToDecimal(txtTotalAmount.Text);
                        if (decTotalAmt > decDiscount)
                        {
                            decimal decGrandTotal = decTotalAmt + decTotalBillTaxAmount + decTotalCessTaxamount - decDiscount;
                            decGrandTotal = Math.Round(decGrandTotal, PublicVariables._inNoOfDecimalPlaces);
                            txtGrandTotal.Text = decGrandTotal.ToString();
                        }
                    }
                    // SerialNo();
                }
                else
                {
                    MessageBox.Show("No record exists", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR28:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }