コード例 #1
0
        /** Generate Payment for Multi Cheque Details  */
        public string GenratePaymentLine(Ctx ctx, int Record_Id, int paymentDocumentTypeId, Trx trxName)
        {
            StringBuilder        _sql = new StringBuilder();
            MVA027PostDatedCheck _pdc = new MVA027PostDatedCheck(ctx, Record_Id, trxName);
            String  sql = "SELECT * FROM VA027_ChequeDetails WHERE VA027_PostDatedCheck_ID=" + Record_Id;
            DataSet _ds = new DataSet();

            ViennaAdvantage.Model.MPayment _payment = null;
            _ds = DB.ExecuteDataset(sql.ToString(), null, trxName);
            int _count = _ds.Tables[0].Rows.Count;

            if (_ds != null && _ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                {
                    MVA027ChequeDetails cd = new MVA027ChequeDetails(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), Get_Trx());
                    if (cd.IsVA027_DiscountingPDC())
                    {
                        if (Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_Payment_ID"]) == 0)
                        {
                            _sql.Clear();
                            _payment = new ViennaAdvantage.Model.MPayment(ctx, 0, trxName);
                            _payment.SetAD_Client_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Client_ID"]));
                            _payment.SetAD_Org_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Org_ID"]));
                            if (c_BankAccount_ID == 0)
                            {
                                _payment.SetC_BankAccount_ID(_pdc.GetC_BankAccount_ID());
                            }
                            else
                            {
                                _payment.SetC_BankAccount_ID(c_BankAccount_ID);
                            }
                            _payment.SetDateTrx(_sysDate);
                            _payment.SetDateAcct(cd.GetVA027_CheckDate());
                            _payment.SetDescription(_pdc.GetVA027_Description());
                            _payment.SetIsPrepayment(_pdc.IsVA027_IsPrepayment());
                            if (_pdc.GetC_Charge_ID() > 0)
                            {
                                _payment.SetC_Charge_ID(_pdc.GetC_Charge_ID());
                            }
                            _payment.SetVA027_DiscountingPDC(true);

                            if (_pdc.GetVA027_Payee() != null)
                            {
                                _payment.SetDescription(_pdc.GetVA027_Payee());
                            }
                            //added by arpit
                            if (_pdc.GetC_BPartner_ID() > 0)
                            {
                                _payment.SetC_BPartner_ID(_pdc.GetC_BPartner_ID());
                                if (_pdc.GetC_BPartner_Location_ID() > 0)
                                {
                                    _payment.SetC_BPartner_Location_ID(_pdc.GetC_BPartner_Location_ID());
                                }
                            }
                            //end here
                            _payment.SetC_Tax_ID(_pdc.GetC_Tax_ID());
                            _payment.SetPayAmt(Math.Round(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), 2));
                            _payment.SetC_Currency_ID(_pdc.GetC_Currency_ID());
                            _payment.SetDiscountAmt(Math.Round(_pdc.GetVA027_DiscountAmt(), 2));
                            _payment.SetWriteOffAmt(Math.Round(_pdc.GetVA027_WriteoffAmt(), 2));
                            _payment.SetVA009_PaymentMethod_ID(_pdc.GetVA009_PaymentMethod_ID());
                            _payment.SetCheckNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_CheckNo"]));
                            _payment.SetCheckDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]));
                            _payment.SetValidMonths(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ValidMonth"]));
                            _payment.SetMicr(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_MICR"]));
                            _payment.SetAccountNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountNo"]));
                            _payment.SetA_Name(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountName"]));
                            _payment.SetPDCType(_pdc.GetPDCType());
                            //_sql.Append("select docbasetype,c_doctype_id from C_doctype where c_doctype_id=" + _pdc.GetC_DocType_ID());
                            //_docBaseType = Util.GetValueOfString(DB.ExecuteScalar(_sql.ToString()));
                            _sql.Clear();
                            //if (_docBaseType == "PDR")
                            //{
                            //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='ARR' AND AD_Client_ID=" + ctx.GetAD_Client_ID());

                            //    int _docuType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                            //    _payment.SetC_DocType_ID(_docuType);
                            //    _sql.Clear();
                            //}
                            //else
                            //{
                            //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='APP' AND AD_Client_ID=" + ctx.GetAD_Client_ID());
                            //    int _documentType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, trxName));
                            //    _payment.SetC_DocType_ID(_documentType);
                            //    _sql.Clear();
                            //}
                            _payment.SetC_DocType_ID(paymentDocumentTypeId);
                            _exeStatus = _payment.GetVA009_ExecutionStatus();
                            _payment.SetVA009_ExecutionStatus(_exeStatus = "I");
                            if (_payment.Save(trxName))
                            {
                                _status = null;
                                _status = _payment.CompleteIt();
                            }
                            else
                            {
                                return("F");
                            }
                            if (_status == "CO")
                            {
                                _payment.SetDocStatus("CO");
                                _payment.Set_Value("VA027_PostDatedCheck_ID", _pdc.GetVA027_PostDatedCheck_ID());
                                if (_payment.Save(trxName))
                                {
                                    cqd = new MVA027ChequeDetails(ctx, Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), trxName);
                                    cqd.SetC_Payment_ID(_payment.GetC_Payment_ID());
                                    cqd.SetVA027_PaymentStatus("1");
                                    if (cqd.Save(trxName))
                                    {
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Convert.ToDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]) <= _sysDate)
                        {
                            if (Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_Payment_ID"]) == 0)
                            {
                                _sql.Clear();
                                _payment = new ViennaAdvantage.Model.MPayment(ctx, 0, trxName);
                                _payment.SetAD_Client_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Client_ID"]));
                                _payment.SetAD_Org_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Org_ID"]));
                                if (c_BankAccount_ID == 0)
                                {
                                    _payment.SetC_BankAccount_ID(_pdc.GetC_BankAccount_ID());
                                }
                                else
                                {
                                    _payment.SetC_BankAccount_ID(c_BankAccount_ID);
                                }
                                _payment.SetDateTrx(_sysDate);
                                _payment.SetDateAcct(cd.GetVA027_CheckDate());
                                _payment.SetDescription(_pdc.GetVA027_Description());
                                _payment.SetIsPrepayment(_pdc.IsVA027_IsPrepayment());
                                if (_pdc.GetC_Charge_ID() > 0)
                                {
                                    _payment.SetC_Charge_ID(_pdc.GetC_Charge_ID());
                                }
                                if (_pdc.GetVA027_Payee() != null)
                                {
                                    _payment.SetDescription(_pdc.GetVA027_Payee());
                                }
                                //added by arpit
                                if (_pdc.GetC_BPartner_ID() > 0)
                                {
                                    _payment.SetC_BPartner_ID(_pdc.GetC_BPartner_ID());
                                    if (_pdc.GetC_BPartner_Location_ID() > 0)
                                    {
                                        _payment.SetC_BPartner_Location_ID(_pdc.GetC_BPartner_Location_ID());
                                    }
                                }
                                //end here
                                _payment.SetC_Tax_ID(_pdc.GetC_Tax_ID());
                                _payment.SetPayAmt(Math.Round(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), 2));
                                _payment.SetC_Currency_ID(_pdc.GetC_Currency_ID());
                                _payment.SetDiscountAmt(Math.Round(_pdc.GetVA027_DiscountAmt(), 2));
                                _payment.SetWriteOffAmt(Math.Round(_pdc.GetVA027_WriteoffAmt(), 2));
                                _payment.SetVA009_PaymentMethod_ID(_pdc.GetVA009_PaymentMethod_ID());
                                _payment.SetCheckNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_CheckNo"]));
                                _payment.SetCheckDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]));
                                _payment.SetValidMonths(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ValidMonth"]));
                                _payment.SetMicr(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_MICR"]));
                                _payment.SetAccountNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountNo"]));
                                _payment.SetA_Name(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountName"]));
                                _payment.SetPDCType(_pdc.GetPDCType());
                                //_sql.Append("select docbasetype,c_doctype_id from C_doctype where c_doctype_id=" + _pdc.GetC_DocType_ID());
                                //_docBaseType = Util.GetValueOfString(DB.ExecuteScalar(_sql.ToString()));
                                _sql.Clear();
                                //if (_docBaseType == "PDR")
                                //{
                                //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='ARR' AND AD_Client_ID=" + ctx.GetAD_Client_ID());

                                //    int _docuType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                                //    _payment.SetC_DocType_ID(_docuType);
                                //    _sql.Clear();
                                //}
                                //else
                                //{
                                //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='APP' AND AD_Client_ID=" + ctx.GetAD_Client_ID());
                                //    int _documentType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, trxName));
                                //    _payment.SetC_DocType_ID(_documentType);
                                //    _sql.Clear();
                                //}
                                _payment.SetC_DocType_ID(paymentDocumentTypeId);
                                _exeStatus = _payment.GetVA009_ExecutionStatus();
                                _payment.SetVA009_ExecutionStatus(_exeStatus = "I");
                                if (_payment.Save(trxName))
                                {
                                    _status = null;
                                    _status = _payment.CompleteIt();
                                }
                                else
                                {
                                    return("F");
                                }
                                if (_status == "CO")
                                {
                                    _payment.SetDocStatus("CO");
                                    _payment.Set_Value("VA027_PostDatedCheck_ID", _pdc.GetVA027_PostDatedCheck_ID());
                                    if (_payment.Save(trxName))
                                    {
                                        cqd = new MVA027ChequeDetails(ctx, Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), trxName);
                                        cqd.SetC_Payment_ID(_payment.GetC_Payment_ID());
                                        cqd.SetVA027_PaymentStatus("1");
                                        if (cqd.Save(trxName))
                                        {
                                        }
                                    }
                                }
                            }
                            else
                            {
                                return("E");
                            }
                        }
                        else
                        {
                            return("F");
                        }
                    }
                }
            }
            if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT Count(VA027_ChequeDetails_ID) From VA027_ChequeDetails Where VA027_PostDatedCheck_ID=" + Record_Id
                                                    + " AND VA027_PaymentStatus='1'", null, trxName)) == _count)
            {
                _pdc.SetVA027_PaymentStatus("1");
                _pdc.SetVA027_PaymentGenerated(true);
                _pdc.SetVA027_GeneratePayment("Y");
                if (!_pdc.Save(trxName))
                {
                    return("E");
                }
            }
            return("Success");
        }
コード例 #2
0
        /** Generate Payment for Multi Cheque Details  */
        public string GenratePaymentLine(Ctx ctx, int Record_Id, int paymentDocumentTypeId, Trx trxName)
        {
            int     stdprecision = 0;
            Decimal surchargeAmt = Env.ZERO;
            Decimal TaxAmt       = Env.ZERO;

            StringBuilder        _sql = new StringBuilder();
            MVA027PostDatedCheck _pdc = new MVA027PostDatedCheck(ctx, Record_Id, trxName);
            String   sql      = "SELECT * FROM VA027_ChequeDetails WHERE VA027_PostDatedCheck_ID= " + Record_Id + " AND NVL(C_Payment_ID,0)=0 ORDER BY Va027_CheckDate";
            DataSet  _ds      = new DataSet();
            MPayment _payment = null;

            _ds = DB.ExecuteDataset(sql.ToString(), null, trxName);
            int _count = _ds.Tables[0].Rows.Count;

            if (_ds != null && _ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                {
                    MVA027ChequeDetails cd = new MVA027ChequeDetails(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), Get_Trx());
                    if (cd.IsVA027_DiscountingPDC())
                    {
                        if (Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_Payment_ID"]) == 0)
                        {
                            _sql.Clear();
                            _payment = new MPayment(ctx, 0, trxName);
                            _payment.SetAD_Client_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Client_ID"]));
                            _payment.SetAD_Org_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Org_ID"]));
                            if (c_BankAccount_ID == 0)
                            {
                                _payment.SetC_BankAccount_ID(_pdc.GetC_BankAccount_ID());
                            }
                            else
                            {
                                _payment.SetC_BankAccount_ID(c_BankAccount_ID);
                            }
                            _payment.SetDateTrx(_sysDate);
                            _payment.SetDateAcct(_sysDate);                       //cd.GetVA027_CheckDate());
                            _payment.SetDescription(_pdc.GetVA027_Description());
                            _payment.SetIsPrepayment(_pdc.IsVA027_IsPrepayment());
                            if (_pdc.GetC_Charge_ID() > 0)
                            {
                                _payment.SetC_Charge_ID(_pdc.GetC_Charge_ID());
                            }
                            _payment.SetVA027_DiscountingPDC(true);
                            if (_pdc.GetVA027_Payee() != null)
                            {
                                _payment.SetDescription(_pdc.GetVA027_Payee());
                            }
                            //added by arpit
                            if (_pdc.GetC_BPartner_ID() > 0)
                            {
                                _payment.SetC_BPartner_ID(_pdc.GetC_BPartner_ID());
                                if (_pdc.GetC_BPartner_Location_ID() > 0)
                                {
                                    _payment.SetC_BPartner_Location_ID(_pdc.GetC_BPartner_Location_ID());
                                }
                            }
                            //end here
                            _payment.SetC_Tax_ID(_pdc.GetC_Tax_ID());
                            _payment.SetPayAmt(Math.Round(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), 2));
                            _payment.SetC_Currency_ID(_pdc.GetC_Currency_ID());
                            _payment.SetDiscountAmt(Math.Round(_pdc.GetVA027_DiscountAmt(), 2));
                            _payment.SetWriteOffAmt(Math.Round(_pdc.GetVA027_WriteoffAmt(), 2));
                            _payment.SetVA009_PaymentMethod_ID(_pdc.GetVA009_PaymentMethod_ID());
                            _payment.SetCheckNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_CheckNo"]));
                            _payment.SetCheckDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]));
                            _payment.SetValidMonths(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ValidMonth"]));
                            _payment.SetMicr(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_MICR"]));
                            _payment.SetAccountNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountNo"]));
                            _payment.SetA_Name(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountName"]));
                            _payment.SetPDCType(_pdc.GetPDCType());
                            //calculate Tax Amount
                            if (_pdc.GetC_Tax_ID() > 0)
                            {
                                sql = "SELECT StdPrecision FROM VA027_PostDatedCheck i INNER JOIN C_Currency c ON i.C_Currency_ID = c.C_Currency_ID " +
                                      "WHERE VA027_PostDatedCheck_ID = " + _pdc.GetVA027_PostDatedCheck_ID();
                                stdprecision = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                                MTax tax = new MTax(GetCtx(), _pdc.GetC_Tax_ID(), null);
                                if (tax.Get_ColumnIndex("Surcharge_Tax_ID") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                                {
                                    TaxAmt = tax.CalculateSurcharge(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), true, stdprecision, out surchargeAmt);
                                }
                                else
                                {
                                    TaxAmt = tax.CalculateTax(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), true, stdprecision);
                                }
                                _payment.SetTaxAmount(TaxAmt);
                                _payment.Set_Value("SurchargeAmt", surchargeAmt);
                            }

                            //_sql.Append("select docbasetype,c_doctype_id from C_doctype where c_doctype_id=" + _pdc.GetC_DocType_ID());
                            //_docBaseType = Util.GetValueOfString(DB.ExecuteScalar(_sql.ToString()));
                            _sql.Clear();
                            //if (_docBaseType == "PDR")
                            //{
                            //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='ARR' AND AD_Client_ID=" + ctx.GetAD_Client_ID());

                            //    int _docuType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                            //    _payment.SetC_DocType_ID(_docuType);
                            //    _sql.Clear();
                            //}
                            //else
                            //{
                            //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='APP' AND AD_Client_ID=" + ctx.GetAD_Client_ID());
                            //    int _documentType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, trxName));
                            //    _payment.SetC_DocType_ID(_documentType);
                            //    _sql.Clear();
                            //}
                            _payment.SetC_DocType_ID(paymentDocumentTypeId);
                            _exeStatus = _payment.GetVA009_ExecutionStatus();
                            _payment.SetVA009_ExecutionStatus(_exeStatus = "I");
                            if (_payment.Save(trxName))
                            {
                                //payment will get completed only if PaymentAllocate is generated.
                                if (GenratePaymentAllocate(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), _payment.GetC_Payment_ID(), Get_TrxName()))
                                {
                                    _status = null;
                                    _status = _payment.CompleteIt();
                                }
                                else
                                {
                                    return("N");
                                }
                            }
                            else
                            {
                                return("F");
                            }
                            if (_status == "CO")
                            {
                                _payment.SetDocStatus("CO");
                                _payment.Set_Value("VA027_PostDatedCheck_ID", _pdc.GetVA027_PostDatedCheck_ID());
                                if (_payment.Save(trxName))
                                {
                                    cqd = new MVA027ChequeDetails(ctx, Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), trxName);
                                    cqd.SetC_Payment_ID(_payment.GetC_Payment_ID());
                                    cqd.SetVA027_PaymentStatus("1");
                                    if (!cqd.Save(trxName))
                                    {
                                        trxName.Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        log.Info("Error Saving Chequedetails : " + pp.GetValue() + "  , Error Name : " + pp.GetName());
                                        _msg = Msg.GetMsg(ctx, "ChequedetailsNotSaved") + ", " + (pp != null ? pp.GetName() : "");

                                        return("N");
                                    }
                                }
                                documentno += _payment.GetDocumentNo() + ",";
                            }
                        }
                    }
                    else
                    {
                        if (Convert.ToDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]) <= _sysDate)
                        {
                            if (Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_Payment_ID"]) == 0)
                            {
                                _sql.Clear();
                                _payment = new MPayment(ctx, 0, trxName);
                                _payment.SetAD_Client_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Client_ID"]));
                                _payment.SetAD_Org_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_Org_ID"]));
                                if (c_BankAccount_ID == 0)
                                {
                                    _payment.SetC_BankAccount_ID(_pdc.GetC_BankAccount_ID());
                                }
                                else
                                {
                                    _payment.SetC_BankAccount_ID(c_BankAccount_ID);
                                }
                                _payment.SetDateTrx(_sysDate);
                                _payment.SetDateAcct(cd.GetVA027_CheckDate());
                                _payment.SetDescription(_pdc.GetVA027_Description());
                                _payment.SetIsPrepayment(_pdc.IsVA027_IsPrepayment());
                                if (_pdc.GetC_Charge_ID() > 0)
                                {
                                    _payment.SetC_Charge_ID(_pdc.GetC_Charge_ID());
                                }
                                if (_pdc.GetVA027_Payee() != null)
                                {
                                    _payment.SetDescription(_pdc.GetVA027_Payee());
                                }
                                //added by arpit
                                if (_pdc.GetC_BPartner_ID() > 0)
                                {
                                    _payment.SetC_BPartner_ID(_pdc.GetC_BPartner_ID());
                                    if (_pdc.GetC_BPartner_Location_ID() > 0)
                                    {
                                        _payment.SetC_BPartner_Location_ID(_pdc.GetC_BPartner_Location_ID());
                                    }
                                }
                                //end here
                                _payment.SetC_Tax_ID(_pdc.GetC_Tax_ID());
                                _payment.SetPayAmt(Math.Round(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), 2));
                                _payment.SetC_Currency_ID(_pdc.GetC_Currency_ID());
                                _payment.SetDiscountAmt(Math.Round(_pdc.GetVA027_DiscountAmt(), 2));
                                _payment.SetWriteOffAmt(Math.Round(_pdc.GetVA027_WriteoffAmt(), 2));
                                _payment.SetVA009_PaymentMethod_ID(_pdc.GetVA009_PaymentMethod_ID());
                                _payment.SetCheckNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_CheckNo"]));
                                _payment.SetCheckDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["VA027_CheckDate"]));
                                _payment.SetValidMonths(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ValidMonth"]));
                                _payment.SetMicr(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_MICR"]));
                                _payment.SetAccountNo(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountNo"]));
                                _payment.SetA_Name(Util.GetValueOfString(_ds.Tables[0].Rows[i]["VA027_AccountName"]));
                                _payment.SetPDCType(_pdc.GetPDCType());

                                //calculate Tax Amount
                                if (_pdc.GetC_Tax_ID() > 0)
                                {
                                    sql = "SELECT StdPrecision FROM VA027_PostDatedCheck i INNER JOIN C_Currency c ON i.C_Currency_ID = c.C_Currency_ID " +
                                          "WHERE VA027_PostDatedCheck_ID = " + _pdc.GetVA027_PostDatedCheck_ID();
                                    stdprecision = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                                    MTax tax = new MTax(GetCtx(), _pdc.GetC_Tax_ID(), null);
                                    if (tax.Get_ColumnIndex("Surcharge_Tax_ID") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                                    {
                                        TaxAmt = tax.CalculateSurcharge(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), true, stdprecision, out surchargeAmt);
                                    }
                                    else
                                    {
                                        TaxAmt = tax.CalculateTax(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["VA027_ChequeAmount"]), true, stdprecision);
                                    }
                                    _payment.SetTaxAmount(TaxAmt);
                                    _payment.Set_Value("SurchargeAmt", surchargeAmt);
                                }
                                //_sql.Append("select docbasetype,c_doctype_id from C_doctype where c_doctype_id=" + _pdc.GetC_DocType_ID());
                                //_docBaseType = Util.GetValueOfString(DB.ExecuteScalar(_sql.ToString()));
                                _sql.Clear();
                                //if (_docBaseType == "PDR")
                                //{
                                //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='ARR' AND AD_Client_ID=" + ctx.GetAD_Client_ID());

                                //    int _docuType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                                //    _payment.SetC_DocType_ID(_docuType);
                                //    _sql.Clear();
                                //}
                                //else
                                //{
                                //    _sql.Append("SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType='APP' AND AD_Client_ID=" + ctx.GetAD_Client_ID());
                                //    int _documentType = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, trxName));
                                //    _payment.SetC_DocType_ID(_documentType);
                                //    _sql.Clear();
                                //}
                                _payment.SetC_DocType_ID(paymentDocumentTypeId);
                                _exeStatus = _payment.GetVA009_ExecutionStatus();
                                _payment.SetVA009_ExecutionStatus(_exeStatus = "I");
                                if (_payment.Save(trxName))
                                {
                                    //payment will get completed only if PaymentAllocate is generated.
                                    if (GenratePaymentAllocate(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), _payment.GetC_Payment_ID(), Get_TrxName()))
                                    {
                                        _status = null;
                                        _status = _payment.CompleteIt();
                                    }
                                    else
                                    {
                                        return("N");
                                    }
                                }
                                else
                                {
                                    return("F");
                                }
                                if (_status == "CO")
                                {
                                    _payment.SetDocStatus("CO");
                                    _payment.Set_Value("VA027_PostDatedCheck_ID", _pdc.GetVA027_PostDatedCheck_ID());
                                    if (_payment.Save(trxName))
                                    {
                                        cqd = new MVA027ChequeDetails(ctx, Util.GetValueOfInt(_ds.Tables[0].Rows[i]["VA027_ChequeDetails_ID"]), trxName);
                                        cqd.SetC_Payment_ID(_payment.GetC_Payment_ID());
                                        cqd.SetVA027_PaymentStatus("1");
                                        if (!cqd.Save(trxName))
                                        {
                                            trxName.Rollback();
                                            ValueNamePair pp = VLogger.RetrieveError();
                                            log.Info("Error Saving Chequedetails : " + pp.GetValue() + "  , Error Name : " + pp.GetName());
                                            _msg = Msg.GetMsg(ctx, "ChequedetailsNotSaved") + ", " + (pp != null ? pp.GetName() : "");
                                            return("N");
                                        }
                                    }
                                    documentno += _payment.GetDocumentNo() + ",";
                                }
                            }
                            else
                            {
                                return("E");
                            }
                        }
                        else
                        {
                            return("F");
                        }
                    }
                }
            }
            if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT Count(VA027_ChequeDetails_ID) From VA027_ChequeDetails Where VA027_PostDatedCheck_ID=" + Record_Id
                                                    + " AND VA027_PaymentStatus!='1'", null, trxName)) == 0)
            {
                _pdc.SetVA027_PaymentStatus("1");
                _pdc.SetVA027_PaymentGenerated(true);
                _pdc.SetVA027_GeneratePayment("Y");
                if (!_pdc.Save(trxName))
                {
                    return("E");
                }
            }

            return("Success");
        }