protected override string DoIt()
        {
            StringBuilder _sql = new StringBuilder();

            _sql.Clear();
            _sql.Append("SELECT cs.C_InvoicePaySchedule_ID,  cs.DueDate FROM C_InvoicePaySchedule cs INNER JOIN c_doctype cd ON cs.c_doctype_id=cd.c_doctype_id");
            _sql.Append(" Where cs.IsActive = 'Y' and cs.ad_client_id=" + GetAD_Client_ID());
            if (_docType > 0)
            {
                _sql.Append(" and cs.c_doctype_id=" + _docType);
            }
            if (_DateDoc_From != null && _DateDoc_To != null)
            {
                //_sql.Append(" and cs.duedate between " + _DateDoc_From + "");
                //_sql.Append(" and trunc(DueDate) between " + GlobalVariable.TO_DATE(_DateDoc_From, true) + " and " + GlobalVariable.TO_DATE(_DateDoc_To, true));
                _sql.Append(" and cs.DueDate BETWEEN ");
                _sql.Append(GlobalVariable.TO_DATE(_DateDoc_From, true) + " And ");
                _sql.Append(GlobalVariable.TO_DATE(_DateDoc_To, true));
            }
            else if (_DateDoc_From != null && _DateDoc_To == null)
            {
                _sql.Append(" and cs.DueDate >=" + GlobalVariable.TO_DATE(_DateDoc_From, true));
            }
            else if (_DateDoc_From == null && _DateDoc_To != null)
            {
                _sql.Append(" and cs.DueDate  <=" + GlobalVariable.TO_DATE(_DateDoc_To, true));
            }


            DataSet ds = new DataSet();

            ds = DB.ExecuteDataset(_sql.ToString());
            if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    _payschedule = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_InvoicePaySchedule_ID"]);
                    _duedate     = Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DueDate"]);
                    _sysdate     = System.DateTime.Now;
                    if (_duedate < _sysdate)
                    {
                        MInvoicePaySchedule PaySchedule = new MInvoicePaySchedule(GetCtx(), _payschedule, null);
                        PaySchedule.SetVA009_ExecutionStatus("O");
                        if (!PaySchedule.Save())
                        {
                        }
                    }
                }
                return(Msg.GetMsg(GetCtx(), "VA009_ShduleCrted"));
            }
            return(Msg.GetMsg(GetCtx(), "VA009_ShduleNtFound"));
        }
Beispiel #2
0
        /// <summary>
        /// Perrform Process.
        /// </summary>
        /// <returns>Message (clear text)</returns>
        protected override String DoIt()
        {
            //log.info ("C_InvoicePaySchedule_ID=" + getRecord_ID());
            MInvoicePaySchedule[] schedule = MInvoicePaySchedule.GetInvoicePaySchedule(GetCtx(), 0, GetRecord_ID(), null);
            if (schedule.Length == 0)
            {
                throw new ArgumentException("InvoicePayScheduleValidate - No Schedule");
            }
            //	Get Invoice
            MInvoice invoice = new MInvoice(GetCtx(), schedule[0].GetC_Invoice_ID(), null);

            if (invoice.Get_ID() == 0)
            {
                throw new ArgumentException("InvoicePayScheduleValidate - No Invoice");
            }
            //
            Decimal total = Env.ZERO;

            for (int i = 0; i < schedule.Length; i++)
            {
                Decimal due = schedule[i].GetDueAmt();
                if (due != 0)
                {
                    total = Decimal.Add(total, due);
                }
            }
            bool valid = invoice.GetGrandTotal().CompareTo(total) == 0;

            invoice.SetIsPayScheduleValid(valid);
            invoice.Save();
            //	Schedule
            for (int i = 0; i < schedule.Length; i++)
            {
                if (schedule[i].IsValid() != valid)
                {
                    schedule[i].SetIsValid(valid);
                    schedule[i].Save();
                }
            }
            String msg = "@OK@";

            if (!valid)
            {
                msg = "@GrandTotal@ = " + invoice.GetGrandTotal()
                      + " <> @Total@ = " + total
                      + "  - @Difference@ = " + Decimal.Subtract(invoice.GetGrandTotal(), total);
            }
            return(Msg.ParseTranslation(GetCtx(), msg));
        }
Beispiel #3
0
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message </returns>
        protected override String DoIt()
        {
            //int count = 0;
            psel = new MPaySelection(GetCtx(), _C_PaySelection_ID, Get_TrxName());

            #region Old Query
            //log.Info("C_PaySelection_ID=" + _C_PaySelection_ID
            //    + ", OnlyDiscount=" + _OnlyDiscount + ", OnlyDue=" + _OnlyDue
            //    + ", IncludeInDispute=" + _IncludeInDispute
            //    + ", MatchRequirement=" + _MatchRequirementI
            //    + ", PaymentRule=" + _PaymentRule
            //    + ", C_BP_Group_ID=" + _C_BP_Group_ID + ", C_BPartner_ID=" + _C_BPartner_ID);

            //MPaySelection psel = new MPaySelection(GetCtx(), _C_PaySelection_ID, Get_TrxName());
            //int C_CurrencyTo_ID = psel.GetC_Currency_ID();
            //if (psel.Get_ID() == 0)
            //{
            //    throw new ArgumentException("Not found C_PaySelection_ID=" + _C_PaySelection_ID);
            //}
            //if (psel.IsProcessed())
            //{
            //    throw new ArgumentException("@Processed@");
            //}
            ////	psel.getPayDate();

            //String sql = "SELECT C_Invoice_ID,"
            //    //	Open
            //    + " currencyConvert(invoiceOpen(i.C_Invoice_ID, 0)"
            //        + ",i.C_Currency_ID, " + C_CurrencyTo_ID + "," + DB.TO_DATE(psel.GetPayDate(), true) + ", i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID),"	//	##1/2 Currency_To,PayDate
            //    //	Discount
            //    + " currencyConvert(paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, " + DB.TO_DATE(psel.GetPayDate(), true) + ")"	//	##3 PayDate
            //        + ",i.C_Currency_ID," + C_CurrencyTo_ID + "," + DB.TO_DATE(psel.GetPayDate(), true) + ",i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID),"	//	##4/5 Currency_To,PayDate
            //    + " PaymentRule, IsSOTrx "		//	4..6
            //    + "FROM C_Invoice i "
            //    + "WHERE";
            ////if (_PaymentRule != null && _PaymentRule.Equals(X_C_Invoice.PAYMENTRULE_DirectDebit))
            ////{
            ////    sql += " IsSOTrx='Y'";
            ////}
            ////else
            ////{
            ////    sql += " IsSOTrx='N'";
            ////}
            //sql += " IsPaid='N' AND DocStatus IN ('CO','CL')" // ##6
            //    + " AND AD_Client_ID=" + psel.GetAD_Client_ID()				//	##7
            //    //	Existing Payments - Will reselect Invoice if prepared but not paid
            //    + " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl "
            //        + "WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.IsActive='Y'"
            //        + " AND psl.C_PaySelectionCheck_ID IS NOT NULL)";
            //count = 7;
            ////	Disputed
            //if (!_IncludeInDispute)
            //{
            //    sql += " AND i.IsInDispute='N'";
            //}
            ////	PaymentRule (optional)
            //if (_PaymentRule != null && _PaymentRule != " ")
            //{
            //    sql += " AND PaymentRule='" + _PaymentRule + "'";		//	##
            //    count += 1;
            //}
            ////	OnlyDiscount
            //if (_OnlyDiscount)
            //{
            //    if (_OnlyDue)
            //    {
            //        sql += " AND (";
            //    }
            //    else
            //    {
            //        sql += " AND ";
            //    }
            //    sql += "paymentTermDiscount(invoiceOpen(C_Invoice_ID, 0), C_Currency_ID, C_PaymentTerm_ID, DateInvoiced, " + DB.TO_DATE(psel.GetPayDate(), true) + ") > 0";	//	##
            //    count += 1;
            //}
            ////	OnlyDue
            //if (_OnlyDue)
            //{
            //    if (_OnlyDiscount)
            //    {
            //        sql += " OR ";
            //    }
            //    else
            //    {
            //        sql += " AND ";
            //    }
            //    sql += "paymentTermDueDays(C_PaymentTerm_ID, DateInvoiced, " + DB.TO_DATE(psel.GetPayDate(), true) + ") >= 0";	//	##
            //    count += 1;
            //    if (_OnlyDiscount)
            //    {
            //        sql += ")";
            //    }
            //}
            ////	Business Partner
            //if (_C_BPartner_ID != 0 && _C_BPartner_ID != -1)
            //{
            //    sql += " AND C_BPartner_ID=" + _C_BPartner_ID;	//	##
            //    count += 1;
            //}
            ////	Business Partner Group
            //else if (_C_BP_Group_ID != 0 && _C_BP_Group_ID != -1)
            //{
            //    sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
            //        + "WHERE bp.C_BPartner_ID=i.C_BPartner_ID AND bp.C_BP_Group_ID=" + _C_BP_Group_ID + ")";	//	##
            //    count += 1;
            //}
            ////	PO Matching Requiremnent
            //if (_MatchRequirementI.Equals(X_C_Invoice.MATCHREQUIREMENTI_PurchaseOrder)
            //    || _MatchRequirementI.Equals(X_C_Invoice.MATCHREQUIREMENTI_PurchaseOrderAndReceipt))
            //{
            //    sql += " AND i._MatchRequirementI NOT IN ('N','R')"
            //        + " AND EXISTS (SELECT * FROM C_InvoiceLine il "
            //        + "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
            //        + " AND QtyInvoiced IN (SELECT SUM(Qty) FROM M_MatchPO m "
            //            + "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
            //}
            ////	Receipt Matching Requiremnent
            //if (_MatchRequirementI.Equals(X_C_Invoice.MATCHREQUIREMENTI_Receipt)
            //    || _MatchRequirementI.Equals(X_C_Invoice.MATCHREQUIREMENTI_PurchaseOrderAndReceipt))
            //{
            //    sql += " AND i._MatchRequirementI NOT IN ('N','P')"
            //        + " AND EXISTS (SELECT * FROM C_InvoiceLine il "
            //        + "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
            //        + " AND QtyInvoiced IN (SELECT SUM(Qty) FROM M_MatchInv m "
            //            + "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
            //}

            ////	Document No
            //else if (_DocumentNo_From != null && _DocumentNo_To != null)
            //{
            //    sql += " AND i.DocumentNo BETWEEN "
            //        + DB.TO_STRING(_DocumentNo_From) + " AND "
            //        + DB.TO_STRING(_DocumentNo_To);
            //}
            //else if (_DocumentNo_From != null)
            //{
            //    sql += " AND ";
            //    if (_DocumentNo_From.IndexOf('%') == -1)
            //    {
            //        sql += "i.DocumentNo >= "
            //            + DB.TO_STRING(_DocumentNo_From);
            //    }
            //    else
            //    {
            //        sql += "i.DocumentNo LIKE "
            //            + DB.TO_STRING(_DocumentNo_From);
            //    }
            //}
            #endregion

            String sql = CreateQuery();
            //
            int         lines = 0;
            IDataReader idr   = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, Get_TrxName());
                while (idr.Read())
                {
                    int     C_InvoicePaySchedule_ID = Util.GetValueOfInt(idr[0]);
                    int     C_Invoice_ID            = Util.GetValueOfInt(idr[1]); //  rs.getInt(1);
                    Decimal PayAmt = Util.GetValueOfDecimal(idr[2]);              //rs.getBigDecimal(2);
                    if (C_Invoice_ID == 0 || Env.ZERO.CompareTo(PayAmt) == 0)
                    {
                        continue;
                    }

                    Decimal DiscountAmt  = Util.GetValueOfDecimal(idr[5]); //rs.getBigDecimal(5);
                    Decimal DiscountAmt2 = Util.GetValueOfDecimal(idr[6]); //rs.getBigDecimal(6);
                    // OnlyDiscount
                    if (_OnlyDiscount)
                    {
                        if (DiscountAmt == 0 && DiscountAmt2 == 0)
                        {
                            continue; //Skip this if discount is ZERO in the case of ONLY DISCOUNT
                        }
                    }

                    if (DiscountAmt2 > 0)
                    {
                        DiscountAmt = DiscountAmt2;
                    }

                    String PaymentRule = Util.GetValueOfString(idr[3]);             //rs.getString(3);
                    bool   isSOTrx     = "Y".Equals(Util.GetValueOfString(idr[4])); //rs.getString(4));
                    //
                    lines++;
                    MPaySelectionLine pselLine = new MPaySelectionLine(psel, lines * 10, PaymentRule);
                    pselLine.SetInvoice(C_Invoice_ID, isSOTrx,
                                        PayAmt, Decimal.Subtract(PayAmt, DiscountAmt), DiscountAmt);

                    if (VA009_PaymentMethod_ID == 0)
                    {
                        MInvoicePaySchedule ips = new MInvoicePaySchedule(GetCtx(), C_InvoicePaySchedule_ID, Get_TrxName());
                        pselLine.Set_Value("VA009_PaymentMethod_ID", ips.GetVA009_PaymentMethod_ID());
                        _PaymentRule = (String)(DB.ExecuteScalar("SELECT VA009_PaymentBaseType FROM VA009_PaymentMethod WHERE IsActive='Y' AND VA009_PaymentMethod_ID=" + ips.GetVA009_PaymentMethod_ID()));
                        pselLine.SetPaymentRule(_PaymentRule);
                    }
                    else
                    {
                        pselLine.Set_Value("VA009_PaymentMethod_ID", VA009_PaymentMethod_ID);
                        pselLine.SetPaymentRule(_PaymentRule);
                    }
                    pselLine.SetC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID); // Set Invoice Pay Schedule
                    if (!pselLine.Save())
                    {
                        if (idr != null)
                        {
                            idr.Close();
                            idr = null;
                        }
                        //return GetReterivedError(pselLine, "Cannot save MPaySelectionLine");
                        throw new Exception("Cannot save MPaySelectionLine");
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }

            return("@C_PaySelectionLine_ID@  - #" + lines);
        }
Beispiel #4
0
        protected override string DoIt()
        {
            batchid = GetBatchId();
            if (batchid > 0)
            {
                StringBuilder          _sql       = new StringBuilder();
                MVA009Batch            batch      = new MVA009Batch(GetCtx(), batchid, Get_TrxName());
                MBankAccount           _bankacc   = new MBankAccount(GetCtx(), batch.GetC_BankAccount_ID(), Get_TrxName());
                MVA009PaymentMethod    _paymthd   = null;
                MVA009BatchLines       line       = null;
                MVA009BatchLineDetails lineDetail = null;
                decimal dueamt = 0;
                _sql.Clear();
                _sql.Append(@"Select cp.ad_client_id, cp.ad_org_id,CI.C_Bpartner_ID, ci.c_invoice_id, cp.c_invoicepayschedule_id, cp.duedate, 
                              cp.dueamt, cp.discountdate, cp.discountamt,cp.va009_paymentmethod_id,ci.c_currency_id , doc.DocBaseType
                              From C_Invoice CI inner join C_InvoicePaySchedule CP ON CI.c_invoice_id= CP.c_invoice_id
                              INNER JOIN C_DocType doc ON doc.C_DocType_ID = CI.C_DocType_ID  Where ci.ispaid='N' AND cp.va009_ispaid='N' AND cp.C_Payment_ID IS NULL
                              AND CI.IsActive = 'Y' and ci.docstatus in ('CO','CL') AND cp.VA009_ExecutionStatus NOT IN ( 'Y','J') AND CI.AD_Client_ID = " + GetAD_Client_ID() + " AND CI.AD_Org_ID = " + GetAD_Org_ID());

                if (_C_BPartner_ID > 0)
                {
                    _sql.Append("  and CI.C_Bpartner_ID=" + _C_BPartner_ID);
                }
                if (_C_invoice_ID > 0)
                {
                    _sql.Append("  and CI.C_invoice_ID=" + _C_invoice_ID);
                }
                if (_paySchedule_ID > 0)
                {
                    _sql.Append(" AND CP.C_InvoicePaySchedule_ID=" + _paySchedule_ID);
                }
                if (_docType > 0)
                {
                    _sql.Append(" ANd CI.C_DocType_ID=" + _docType);
                }
                else
                {
                    _sql.Append(" ANd doc.DocBaseType IN ('API' , 'ARI' , 'APC' , 'ARC') ");
                }
                if (_paymentMethod > 0)
                {
                    _sql.Append(" And CP.VA009_PaymentMethod_ID=" + _paymentMethod);
                    _paymthd = new MVA009PaymentMethod(GetCtx(), _paymentMethod, Get_TrxName());
                    _trigger = _paymthd.IsVA009_IsMandate();
                }

                if (_DateDoc_From != null && _DateDoc_To != null)
                {
                    _sql.Append(" and cp.duedate BETWEEN  ");
                    _sql.Append(GlobalVariable.TO_DATE(_DateDoc_From, true) + " AND ");
                    _sql.Append(GlobalVariable.TO_DATE(_DateDoc_To, true));
                }
                else if (_DateDoc_From != null && _DateDoc_To == null)
                {
                    _sql.Append(" and cp.duedate >=" + GlobalVariable.TO_DATE(_DateDoc_From, true));
                }
                else if (_DateDoc_From == null && _DateDoc_To != null)
                {
                    _sql.Append(" and cp.duedate <=" + GlobalVariable.TO_DATE(_DateDoc_To, true));
                }
                else if (C_ConversionType_ID > 0)
                {
                    _sql.Append("  AND C_ConversionType_ID=" + C_ConversionType_ID);
                }

                if (VA009_IsSameCurrency == true)
                {
                    _sql.Append(" AND CI.C_Currency_ID =" + _bankacc.GetC_Currency_ID());
                }

                _sql.Append(" Order by CI.C_Bpartner_ID asc , doc.docbasetype ");

                DataSet ds = new DataSet();
                ds = DB.ExecuteDataset(_sql.ToString(), null, Get_TrxName());
                if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if ((Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["DueAmt"])) == 0)
                        {
                            continue;
                        }
                        // if invoice is of AP Invoice and AP Credit Memo then make a single Batch line
                        if (docBaseType == "API" || docBaseType == "APC")
                        {
                            if (_BPartner == Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_BPartner_ID"]) &&
                                ("API" == Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) || "APC" == Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"])))
                            {
                                line = new MVA009BatchLines(GetCtx(), _VA009_BatchLine_ID, Get_TrxName());
                            }
                            else
                            {
                                line = null;
                            }
                        }
                        // if invoice is of AR Invoice and AR Credit Memo then make a single Batch line
                        else if (docBaseType == "ARI" || docBaseType == "ARC")
                        {
                            if (_BPartner == Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_BPartner_ID"]) &&
                                ("ARI" == Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) || "ARC" == Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"])))
                            {
                                line = new MVA009BatchLines(GetCtx(), _VA009_BatchLine_ID, Get_TrxName());
                            }
                            else
                            {
                                line = null;
                            }
                        }
                        //if (_BPartner == Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_BPartner_ID"]) && docBaseType == Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]))
                        //{
                        //    line = new MVA009BatchLines(GetCtx(), _VA009_BatchLine_ID, null);
                        //}
                        // else
                        if (line == null)
                        {
                            line = new MVA009BatchLines(GetCtx(), 0, Get_TrxName());
                            line.SetAD_Client_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["Ad_Client_ID"]));
                            line.SetAD_Org_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["Ad_Org_ID"]));
                            line.SetVA009_Batch_ID(batch.GetVA009_Batch_ID());

                            _BPartner   = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_BPartner_ID"]);
                            docBaseType = Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]);

                            line.SetC_BPartner_ID(_BPartner);
                            if (_trigger == true)
                            {
                                _sql.Clear();
                                _sql.Append("Select VA009_BPMandate_id from C_BPartner Where C_BPartner_ID=" + _BPartner + " AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID());
                                DataSet ds1 = new DataSet();
                                ds1 = DB.ExecuteDataset(_sql.ToString(), null, Get_TrxName());
                                if (ds1.Tables != null && ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                                {
                                    line.SetVA009_BPMandate_ID(Util.GetValueOfInt(ds1.Tables[0].Rows[0]["VA009_BPMandate_id"]));
                                }
                            }
                            if (line.Save())
                            {
                                line.SetProcessed(true);
                                line.Save();
                                _VA009_BatchLine_ID = line.GetVA009_BatchLines_ID();
                            }
                            else
                            {
                                _BPartner           = 0;
                                _VA009_BatchLine_ID = 0;
                            }
                        }
                        lineDetail = new MVA009BatchLineDetails(GetCtx(), 0, Get_TrxName());
                        lineDetail.SetAD_Client_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["Ad_Client_ID"]));
                        lineDetail.SetAD_Org_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["Ad_Org_ID"]));
                        lineDetail.SetVA009_BatchLines_ID(line.GetVA009_BatchLines_ID());
                        lineDetail.SetC_Invoice_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Invoice_ID"]));
                        lineDetail.SetC_InvoicePaySchedule_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_InvoicePaySchedule_id"]));
                        lineDetail.SetDueDate(Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DueDate"]));
                        lineDetail.SetC_ConversionType_ID(C_ConversionType_ID);
                        dueamt = (Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["DueAmt"]));
                        if (Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DiscountDate"]) >= Util.GetValueOfDateTime(batch.GetVA009_DocumentDate()))
                        {
                            dueamt = dueamt - (Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["DiscountAmt"]));
                            //  145-2.88
                        }

                        bool issamme = true; decimal comvertedamt = 0;
                        if (Util.GetValueOfInt(ds.Tables[0].Rows[i]["c_currency_id"]) == _bankacc.GetC_Currency_ID())
                        {
                            issamme = true;
                        }
                        else
                        {
                            issamme = false;
                        }

                        if (Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) == "APC" || Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) == "ARC")
                        {
                            lineDetail.SetDueAmt(-1 * dueamt);
                            comvertedamt = (-1 * dueamt);
                        }
                        else
                        {
                            lineDetail.SetDueAmt(dueamt);
                            comvertedamt = (dueamt);
                        }
                        if (issamme == false)
                        {
                            comvertedamt = 0;
                            comvertedamt = MConversionRate.Convert(GetCtx(), dueamt, Util.GetValueOfInt(ds.Tables[0].Rows[i]["c_currency_id"]), _bankacc.GetC_Currency_ID(), DateTime.Now, C_ConversionType_ID, GetCtx().GetAD_Client_ID(), GetCtx().GetAD_Org_ID());
                            lineDetail.SetC_Currency_ID(_bankacc.GetC_Currency_ID());
                            if (Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) == "APC" || Util.GetValueOfString(ds.Tables[0].Rows[i]["DocBaseType"]) == "ARC")
                            {
                                comvertedamt = (-1 * comvertedamt);
                            }
                        }
                        else
                        {
                            lineDetail.SetC_Currency_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["c_currency_id"]));
                        }

                        lineDetail.SetVA009_ConvertedAmt(comvertedamt);
                        lineDetail.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["va009_paymentmethod_id"]));
                        if (Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DiscountDate"]) < Util.GetValueOfDateTime(batch.GetVA009_DocumentDate()))
                        {
                            lineDetail.SetDiscountDate(null);
                            lineDetail.SetDiscountAmt(0);
                        }
                        else if (Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DiscountDate"]) >= Util.GetValueOfDateTime(batch.GetVA009_DocumentDate()))
                        {
                            lineDetail.SetDiscountDate(Util.GetValueOfDateTime(ds.Tables[0].Rows[i]["DiscountDate"]));
                            lineDetail.SetDiscountAmt(Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["DiscountAmt"]));
                        }

                        if (!lineDetail.Save())
                        {
                            //return"BatchLine Not Saved";
                        }
                        else
                        {
                            lineDetail.SetProcessed(true);
                            MInvoicePaySchedule _invpay = new MInvoicePaySchedule(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_InvoicePaySchedule_id"]), Get_TrxName());
                            _invpay.SetVA009_ExecutionStatus("Y");
                            _invpay.Save();
                            lineDetail.Save();
                        }
                    }
                    batch.SetVA009_GenerateLines("Y");
                    batch.SetProcessed(true);
                    batch.Save();
                    if (_paymentMethod != 0)
                    {
                        //_paymthd = new MVA009PaymentMethod(GetCtx(), _paymentMethod, Get_TrxName());
                        batch.SetVA009_PaymentMethod_ID(_paymentMethod);
                        batch.SetVA009_PaymentRule(_paymthd.GetVA009_PaymentRule());
                        batch.SetVA009_PaymentTrigger(_paymthd.GetVA009_PaymentTrigger());
                        batch.Save();
                        if (_paymthd.GetVA009_PaymentRule() == "M")
                        {
                            VA009_CreatePayments payment = new VA009_CreatePayments();
                            payment.DoIt(batch.GetVA009_Batch_ID(), GetCtx(), Get_TrxName(), 0);
                        }
                        else if (_paymthd.GetVA009_PaymentRule() == "E")
                        {
                            VA009_ICICI_Snorkel _Snrkl = new VA009_ICICI_Snorkel();
                            _Snrkl.GetMethod(batch.GetVA009_Batch_ID(), GetCtx(), Get_TrxName());
                        }
                    }
                    return(Msg.GetMsg(GetCtx(), "VA009_BatchLineCrtd"));;
                }
                else
                {
                    DB.ExecuteQuery("DELETE FROM VA009_Batch WHERE VA009_Batch_ID=" + batchid, null, Get_TrxName());

                    return(Msg.GetMsg(GetCtx(), "VA009_BatchLineNotCrtd"));
                }
            }
            else
            {
                DB.ExecuteQuery("DELETE FROM VA009_Batch WHERE VA009_Batch_ID=" + batchid, null, Get_TrxName());

                return(Msg.GetMsg(GetCtx(), "VA009_BatchNotCrtd"));
            }
        }