コード例 #1
0
        /// <summary>
        /// Calculate Surcharge Tax
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <String, Object> CalculateSurcharge(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      C_Tax_ID;

            Dictionary <String, Object> retval = new Dictionary <String, Object>();

            //Assign parameter value
            C_Tax_ID = Util.GetValueOfInt(paramValue[0]);
            Decimal LineNetAmt    = Util.GetValueOfDecimal(paramValue[1]);
            int     StdPrecision  = Util.GetValueOfInt(paramValue[2]);
            Boolean IsTaxIncluded = true;

            if (paramValue.Length == 4)
            {
                IsTaxIncluded = Util.GetValueOfBool(paramValue[3]);
            }
            //End Assign parameter value
            MTax    tax          = new MTax(ctx, C_Tax_ID, null);
            Decimal surchargeAmt = Env.ZERO;
            Decimal TaxAmt       = Env.ZERO;

            if (tax.Get_ColumnIndex("Surcharge_Tax_ID") > 0 && tax.GetSurcharge_Tax_ID() > 0)
            {
                TaxAmt = tax.CalculateSurcharge(LineNetAmt, IsTaxIncluded, StdPrecision, out surchargeAmt);
            }
            else
            {
                TaxAmt = tax.CalculateTax(LineNetAmt, IsTaxIncluded, StdPrecision);
            }
            retval["TaxAmt"]       = TaxAmt;
            retval["SurchargeAmt"] = surchargeAmt;
            return(retval);
        }
        protected override bool AfterSave(bool newRecord, bool success)
        {
            //if (newRecord || (GetVA027_ChequeAmount() != Util.GetValueOfDecimal(Get_ValueOld("VA027_ChequeAmount"))))
            //{
            //    MVA027PostDatedCheck _PSD = new MVA027PostDatedCheck(GetCtx(), GetVA027_PostDatedCheck_ID(), null);
            //    _PSD.SetVA027_PayAmt(_PSD.GetVA027_PayAmt() + GetVA027_ChequeAmount());
            //    _PSD.Save();
            //}
            int     stdprecision = 0;
            int     C_Tax_ID     = 0;
            Decimal surchargeAmt = Env.ZERO;
            Decimal TaxAmt       = Env.ZERO;
            Decimal PayAmt       = Env.ZERO;

            string sql = "UPDATE VA027_PostDatedCheck i"
                         + " SET VA027_PayAmt="
                         + "(SELECT COALESCE(SUM(VA027_ChequeAmount),0) FROM VA027_ChequeDetails il WHERE i.VA027_PostDatedCheck_ID=il.VA027_PostDatedCheck_ID), "
                         + " VA027_ConvertedAmount = (SELECT COALESCE(SUM(VA027_ChequeAmount),0) FROM VA027_ChequeDetails il WHERE i.VA027_PostDatedCheck_ID=il.VA027_PostDatedCheck_ID) "
                         + "WHERE VA027_PostDatedCheck_ID=" + GetVA027_PostDatedCheck_ID();

            DB.ExecuteQuery(sql, null, Get_TrxName());

            sql = "SELECT StdPrecision, C_Tax_ID, VA027_PayAmt FROM VA027_PostDatedCheck i " +
                  "INNER JOIN C_Currency c ON i.C_Currency_ID = c.C_Currency_ID WHERE VA027_PostDatedCheck_ID =" + GetVA027_PostDatedCheck_ID() +
                  " AND i.C_Charge_ID > 0 AND i.C_Tax_ID > 0";

            DataSet ds = new DataSet();

            ds = DB.ExecuteDataset(sql, null, Get_Trx());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                stdprecision = Util.GetValueOfInt(ds.Tables[0].Rows[0]["StdPrecision"]);
                C_Tax_ID     = Util.GetValueOfInt(ds.Tables[0].Rows[0]["C_Tax_ID"]);
                PayAmt       = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["VA027_PayAmt"]);

                MTax tax = new MTax(GetCtx(), C_Tax_ID, null);

                if (tax.Get_ColumnIndex("Surcharge_Tax_ID") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                {
                    TaxAmt = tax.CalculateSurcharge(PayAmt, true, stdprecision, out surchargeAmt);
                }
                else
                {
                    TaxAmt = tax.CalculateTax(PayAmt, true, stdprecision);
                }

                sql = "UPDATE VA027_PostDatedCheck SET TaxAmount= " + TaxAmt + " , SurchargeAmt= " + surchargeAmt +
                      " WHERE VA027_PostDatedCheck_ID = " + GetVA027_PostDatedCheck_ID();

                DB.ExecuteQuery(sql, null, Get_TrxName());
            }
            return(true);
        }
コード例 #3
0
        protected override String DoIt()
        {
            //int C_Contract_ID = 0;
            String Sql = "SELECT C_OrderLine_ID FROM C_OrderLine WHERE C_Order_ID=" + orderID + " AND CreateServiceContract='N' AND IsContract='Y' AND IsActive='Y'";

            dr = DB.ExecuteReader(Sql);
            try
            {
                VAdvantage.Model.X_C_Order order = new VAdvantage.Model.X_C_Order(GetCtx(), orderID, Get_TrxName());
                string DocStatus = order.GetDocStatus();
                if (DocStatus != "CO")
                {
                    if (dr != null)
                    {
                        dr.Close();
                        dr = null;
                    }

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


                while (dr.Read())
                {
                    line = new VAdvantage.Model.X_C_OrderLine(GetCtx(), Util.GetValueOfInt(dr[0]), Get_TrxName());
                    if (line.IsContract() && line.GetC_Contract_ID() == 0)
                    {
                        contact = new VAdvantage.Model.X_C_Contract(GetCtx(), 0, Get_TrxName());
                        int M_PriceList_ID = Util.GetValueOfInt(order.GetM_PriceList_ID());

                        //Neha---Commented code because object created but not used in further class---04 Sep,2018

                        //VAdvantage.Model.MProductPricing pp = new VAdvantage.Model.MProductPricing(GetCtx().GetAD_Client_ID(), GetCtx().GetAD_Org_ID(),
                        //    line.GetM_Product_ID(), order.GetC_BPartner_ID(), line.GetQtyOrdered(), true);
                        //pp.SetM_PriceList_ID(M_PriceList_ID);
                        //VAdvantage.Model.MProduct prd = new VAdvantage.Model.MProduct(GetCtx(), line.GetM_Product_ID(), null);
                        //pp.SetC_UOM_ID(prd.GetC_UOM_ID());

                        string sql = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision,"
                                     + "plv.M_PriceList_Version_ID,plv.ValidFrom "
                                     + "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv "
                                     + "WHERE pl.C_Currency_ID=c.C_Currency_ID"
                                     + " AND pl.M_PriceList_ID=plv.M_PriceList_ID"
                                     + " AND pl.M_PriceList_ID=" + M_PriceList_ID                               //	1
                                     + "ORDER BY plv.ValidFrom DESC";

                        //int M_PriceList_Version_ID = 0;
                        int     C_Currency_ID = 0;
                        DataSet ds            = DB.ExecuteDataset(sql, null, Get_TrxName());
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr1 = ds.Tables[0].Rows[i];
                            //	Tax Included

                            isTaxIncluded = Util.GetValueOfString(ds.Tables[0].Rows[i]["IsTaxIncluded"]).Equals("Y");

                            //	Currency

                            C_Currency_ID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Currency_ID"]);

                            // Std Precision
                            StdPrecision = Util.GetValueOfInt(ds.Tables[0].Rows[i]["StdPrecision"]);
                            // int prislst = Util.GetValueOfInt(dr[4].ToString());
                            //	PriceList Version
                            //M_PriceList_Version_ID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_PriceList_Version_ID"]);
                        }
                        //int M_PriceList_Version_ID = GetCtx().GetContextAsInt(WindowNo, "M_PriceList_Version_ID");
                        //pp.SetM_PriceList_Version_ID(M_PriceList_Version_ID);
                        //Neha---Set Tenant,Organization from Sales Order---11 Sep,2018
                        contact.SetAD_Client_ID(order.GetAD_Client_ID());
                        contact.SetAD_Org_ID(order.GetAD_Org_ID());
                        //---------------------End ------------------
                        contact.SetDescription(order.GetDescription());
                        contact.SetC_Order_ID(order.GetC_Order_ID());
                        contact.SetC_OrderLine_ID(line.GetC_OrderLine_ID());
                        contact.SetStartDate(line.GetStartDate());
                        contact.SetBillStartDate(line.GetStartDate());
                        contact.SetEndDate(line.GetEndDate());
                        contact.SetC_BPartner_ID(order.GetC_BPartner_ID());
                        contact.SetBill_Location_ID(order.GetBill_Location_ID());
                        contact.SetBill_User_ID(order.GetBill_User_ID());
                        contact.SetSalesRep_ID(order.GetSalesRep_ID());
                        contact.SetC_Currency_ID(line.GetC_Currency_ID());
                        contact.SetC_ConversionType_ID(order.GetC_ConversionType_ID());
                        contact.SetC_PaymentTerm_ID(order.GetC_PaymentTerm_ID());
                        contact.SetM_PriceList_ID(order.GetM_PriceList_ID());
                        contact.SetC_Frequency_ID(line.GetC_Frequency_ID());

                        //Neha--Set List Price,Price,Unit Price,Discount from Order Line--4 Sep,2018

                        //contact.SetPriceList(pp.GetPriceList());
                        //contact.SetPriceActual(pp.GetPriceStd());
                        //contact.SetPriceEntered(pp.GetPriceStd());
                        contact.SetPriceList(line.GetPriceList());
                        contact.SetPriceActual(line.GetPriceActual());
                        contact.SetPriceEntered(line.GetPriceEntered());
                        contact.SetQtyEntered(line.GetQtyPerCycle());
                        //Decimal discount = Decimal.Round(Decimal.Divide(Decimal.Multiply(Decimal.Subtract(pp.GetPriceList(), pp.GetPriceStd()), new Decimal(100)), pp.GetPriceList()), 2);
                        contact.SetDiscount(line.GetDiscount());
                        //------------------End----------------------------

                        //contact.SetGrandTotal(
                        // invoice Count Start
                        //DateTime SDate = (DateTime)(line.GetStartDate());
                        //DateTime Edate = (DateTime)(line.GetEndDate());
                        //int frequency = Util.GetValueOfInt(line.GetC_Frequency_ID());
                        //string PSql = "Select NoOfDays from C_Frequency where C_Frequency_ID=" + frequency;
                        //int days = Util.GetValueOfInt(DB.ExecuteScalar(PSql, null, null));
                        //int totaldays = (Edate - SDate).Days;
                        //int count = totaldays / days;
                        contact.SetTotalInvoice(line.GetNoofCycle());
                        //invoice Count end
                        contact.SetC_Project_ID(order.GetC_Project_ID());
                        // contact.SetPriceList(line.GetPriceList());
                        //contact.SetPriceActual(line.GetPriceActual());
                        contact.SetC_UOM_ID(line.GetC_UOM_ID());
                        contact.SetM_Product_ID(line.GetM_Product_ID());
                        // Added by Vivek on 21/11/2017 asigned by Pradeep
                        contact.SetM_AttributeSetInstance_ID(line.GetM_AttributeSetInstance_ID());
                        // contact.SetPriceEntered(line.GetPriceEntered());
                        //contact.SetQtyEntered(line.GetQtyEntered());
                        // contact.SetDiscount(line.GetDiscount());
                        contact.SetC_Tax_ID(line.GetC_Tax_ID());
                        contact.SetC_Campaign_ID(order.GetC_Campaign_ID());

                        contact.SetLineNetAmt(Decimal.Multiply(line.GetQtyPerCycle(), line.GetPriceActual()));

                        // if Surcharge Tax is selected on Tax, then set value in Surcharge Amount
                        MTax tax = MTax.Get(GetCtx(), line.GetC_Tax_ID());
                        if (contact.Get_ColumnIndex("SurchargeAmt") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                        {
                            Decimal surchargeAmt = Env.ZERO;

                            // Calculate Surcharge Amount
                            Decimal TotalRate = tax.CalculateSurcharge(contact.GetLineNetAmt(), isTaxIncluded, StdPrecision, out surchargeAmt);
                            contact.SetTaxAmt(TotalRate);
                            contact.SetSurchargeAmt(surchargeAmt);
                        }
                        else
                        {
                            sql = "SELECT Rate FROM C_Tax WHERE C_Tax_ID = " + line.GetC_Tax_ID();
                            Decimal?rate = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_TrxName()));
                            //Decimal? amt = Decimal.Multiply(pp.GetPriceStd(), (Decimal.Divide(rate.Value, 100)));
                            Decimal?amt = Decimal.Multiply(line.GetPriceActual(), (Decimal.Divide(rate.Value, 100)));
                            amt = Decimal.Round(amt.Value, 2, MidpointRounding.AwayFromZero);
                            Decimal?taxAmt = Decimal.Multiply(amt.Value, line.GetQtyPerCycle());
                            contact.SetTaxAmt(taxAmt);
                        }

                        // Set Grand Total Amount
                        if (isTaxIncluded)
                        {
                            contact.SetGrandTotal(contact.GetLineNetAmt());
                        }
                        else
                        {
                            if (contact.Get_ColumnIndex("SurchargeAmt") > 0)
                            {
                                contact.SetGrandTotal(Decimal.Add(Decimal.Add(contact.GetLineNetAmt(), contact.GetTaxAmt()), contact.GetSurchargeAmt()));
                            }
                            else
                            {
                                contact.SetGrandTotal(Decimal.Add(contact.GetLineNetAmt(), contact.GetTaxAmt()));
                            }
                        }

                        //-------------------------End--------------------------
                        contact.SetDocStatus("DR");
                        contact.SetRenewContract("N");
                        if (!contact.Save())
                        {
                            //Neha----If Service Contract not saved then will show the exception---17 Sep,2018
                            ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError();
                            if (pp != null)
                            {
                                throw new ArgumentException("Cannot save Service Contract. " + pp.GetName());
                            }
                            throw new ArgumentException("Cannot save Service Contract");
                        }
                        else
                        {
                            if (!line.Save())
                            {
                                //Neha----If Order Line not saved then will show the exception---17 Sep,2018
                                ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError();
                                if (pp != null)
                                {
                                    throw new ArgumentException("Cannot save Order Line. " + pp.GetName());
                                }
                                throw new ArgumentException("Cannot save Order Line");
                            }
                            //Neha---Set CreateServiceContract,Order Line ID on Order Line tab---17 Sep,2018
                            String _qry = "UPDATE C_ORDERLINE SET C_CONTRACT_ID=" + contact.GetC_Contract_ID() + " ,CreateServiceContract='Y' WHERE C_ORDERLINE_ID=" + line.GetC_OrderLine_ID();
                            DB.ExecuteScalar(_qry, null, Get_TrxName());
                        }
                        //C_Contract_ID = contact.GetC_Contract_ID();
                        DocumntNo += contact.GetDocumentNo() + ",";
                    }
                }
                dr.Close();
                order.SetCreateServiceContract("Y");
                if (!order.Save())
                {
                }
                // Added Document No on Message
                return(Msg.GetMsg(GetCtx(), "ServiceContractGenerationDone") + DocumntNo.TrimEnd(','));
            }
            catch (Exception ex)
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
                return(Msg.GetMsg(GetCtx(), ex.Message));
            }
            // return "";
        }
コード例 #4
0
        protected override String DoIt()
        {
            StringBuilder Sql    = new StringBuilder();
            string        newcon = "";

            String       date      = string.Format("{0:dd/MM/yy}", today);
            int          Record_id = GetRecord_ID();
            X_C_Contract con       = new X_C_Contract(GetCtx(), Record_id, Get_TrxName());

            if (Record_id != 0)
            {
                Sql.Append("SELECT RenewalType FROM C_Contract WHERE C_Contract_ID = " + Record_id + " AND RenewContract = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID());
                string renewType = Util.GetValueOfString(DB.ExecuteScalar(Sql.ToString(), null, Get_TrxName()));
                if (renewType == "M")
                {
                    Sql.Clear();
                    Sql.Append("SELECT C_Contract_ID FROM C_Contract WHERE C_Contract_ID=" + Record_id + " AND RenewContract = 'N' AND AD_Client_ID = " + GetAD_Client_ID());
                }
                else
                {
                    Sql.Clear();
                    Sql.Append("SELECT C_Contract_ID FROM C_Contract WHERE (EndDate- NVL(CancelBeforeDays,0)) <= SYSDATE AND C_Contract_ID=" + Record_id
                               + " AND RenewContract = 'N' AND AD_Client_ID = " + GetAD_Client_ID());
                }
            }
            else
            {
                Sql.Clear();
                Sql.Append("SELECT C_Contract_ID FROM C_Contract WHERE (EndDate- NVL(CancelBeforeDays,0)) <= SYSDATE AND RenewalType='A' AND RenewContract = 'N' AND AD_Client_ID = " + GetAD_Client_ID());
            }

            IDataReader dr = DB.ExecuteReader(Sql.ToString(), null, Get_TrxName());
            int         count = 0;
            decimal     Listprice = 0, Stdprice = 0, TotalRate = 0;
            int         cycles = 0, duration = 0, frequency = 0, months = 0;
            DateTime?   CDate = null;
            DateTime    OldStart, Start, endDate;

            MPriceList    priceList = null;
            MTax          tax       = null;
            X_C_Contract  contact   = null;
            X_C_Contract  New       = null;
            ValueNamePair pp        = null;

            try
            {
                while (dr.Read())
                {
                    contact = new X_C_Contract(GetCtx(), Util.GetValueOfInt(dr[0]), Get_TrxName());
                    if (contact.GetRenewalType() == "M")
                    {
                        // SI_0772: By Clicking on Renew Contract, System is throwing an error as 'NoContractReNewed'.
                        CDate  = contact.GetCancellationDate();
                        cycles = Util.GetValueOfInt(contact.GetCycles());

                        if (CDate != null)
                        {
                            continue;
                        }

                        New = new X_C_Contract(GetCtx(), 0, Get_TrxName());
                        New.SetRefContract(contact.GetDocumentNo());
                        New.SetC_Order_ID(contact.GetC_Order_ID());
                        New.SetC_OrderLine_ID(contact.GetC_OrderLine_ID());
                        OldStart = (DateTime)(contact.GetStartDate());
                        Start    = (DateTime)(contact.GetEndDate());
                        New.SetStartDate(Start.AddDays(1));
                        New.SetC_BPartner_ID(contact.GetC_BPartner_ID());
                        New.SetBill_Location_ID(contact.GetBill_Location_ID());
                        New.SetBill_User_ID(contact.GetBill_User_ID());
                        New.SetSalesRep_ID(contact.GetSalesRep_ID());
                        New.SetC_ConversionType_ID(contact.GetC_ConversionType_ID());
                        New.SetC_PaymentTerm_ID(contact.GetC_PaymentTerm_ID());

                        frequency = contact.GetC_Frequency_ID();
                        New.SetC_Frequency_ID(frequency);

                        // Get No Of Months from Frequency
                        months   = Util.GetValueOfInt(DB.ExecuteScalar("SELECT NoOfMonths FROM C_Frequency WHERE C_Frequency_ID=" + frequency, null, Get_TrxName()));
                        duration = months * cycles;
                        endDate  = New.GetStartDate().Value.AddMonths(duration);
                        endDate  = endDate.AddDays(-1);
                        New.SetEndDate(endDate);
                        New.SetTotalInvoice(cycles);
                        if (Record_id != 0)
                        {
                            // JID_1124:  System has to pick the Pricelist in Service Contract as defined in Renewal Pricelist. also need to pick Price from Latest Valid From Date Version
                            New.SetM_PriceList_ID(contact.GetRef_PriceList_ID());
                            priceList = new MPriceList(GetCtx(), contact.GetRef_PriceList_ID(), Get_TrxName());
                            Sql.Clear();
                            Sql.Append("SELECT pp.PriceList, pp.PriceStd FROM M_ProductPrice pp INNER JOIN M_PriceList_Version plv ON pp.M_PriceList_Version_ID = plv.M_PriceList_Version_ID"
                                       + " WHERE pp.M_Product_ID=" + contact.GetM_Product_ID() + " AND plv.IsActive='Y' AND plv.M_PriceList_ID=" + contact.GetRef_PriceList_ID()
                                       + " AND plv.VALIDFROM <= SYSDATE ORDER BY plv.VALIDFROM DESC");
                            DataSet ds = DB.ExecuteDataset(Sql.ToString(), null, Get_TrxName());
                            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                Listprice = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["PriceList"]);
                                Stdprice  = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["PriceStd"]);
                            }
                            else
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "ProductNotOnPriceList"));
                            }
                            //int Version = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //Query = "SELECT PriceList FROM M_ProductPrice WHERE M_PriceList_Version_ID=" + Version + " AND M_Product_ID=" + contact.GetM_Product_ID();
                            //decimal Listprice = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //Query = "SELECT PriceStd FROM M_ProductPrice WHERE M_PriceList_Version_ID=" + Version + " AND M_Product_ID=" + contact.GetM_Product_ID();
                            //decimal Stdprice = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //if (Stdprice == 0 && Listprice == 0)
                            //{
                            //    dr.Close();
                            //    return Msg.GetMsg(GetCtx(), "ProductNotINPriceList");
                            //}

                            New.SetPriceEntered(Stdprice);
                            New.SetPriceActual(Stdprice);
                            New.SetPriceList(Listprice);
                        }
                        else
                        {
                            priceList = new MPriceList(GetCtx(), contact.GetM_PriceList_ID(), Get_TrxName());
                            New.SetM_PriceList_ID(contact.GetM_PriceList_ID());
                            New.SetPriceEntered(contact.GetPriceEntered());
                            New.SetPriceActual(contact.GetPriceActual());
                            New.SetPriceList(contact.GetPriceList());
                        }
                        New.SetC_Currency_ID(priceList.GetC_Currency_ID());
                        New.SetC_UOM_ID(contact.GetC_UOM_ID());
                        New.SetM_Product_ID(contact.GetM_Product_ID());
                        New.SetM_AttributeSetInstance_ID(contact.GetM_AttributeSetInstance_ID());
                        New.SetQtyEntered(contact.GetQtyEntered());
                        New.SetC_Tax_ID(contact.GetC_Tax_ID());
                        New.SetC_Campaign_ID(contact.GetC_Campaign_ID());
                        New.SetRef_Contract_ID(contact.GetC_Contract_ID());
                        New.SetC_Project_ID(contact.GetC_Project_ID());
                        New.SetDescription(contact.GetDescription());
                        //New.SetTaxAmt(contact.GetTaxAmt());
                        New.SetCancelBeforeDays(contact.GetCancelBeforeDays());
                        New.SetCycles(contact.GetCycles());
                        New.SetRenewContract("N");
                        New.SetScheduleContract("N");
                        New.SetDocStatus("DR");
                        New.SetRenewalType("M");
                        New.SetLineNetAmt(Decimal.Multiply(New.GetPriceEntered(), New.GetQtyEntered()));

                        //String sqltax = "SELECT Rate FROM C_Tax WHERE C_Tax_ID=" + contact.GetC_Tax_ID();
                        //Decimal? Rate = Util.GetValueOfDecimal(DB.ExecuteScalar(sqltax, null, Get_TrxName()));

                        //Decimal? TotalRate = Util.GetValueOfDecimal((Util.GetValueOfDecimal(New.GetLineNetAmt()) * Util.GetValueOfDecimal(Rate)) / 100);
                        //TotalRate = Decimal.Round(TotalRate.Value, 2);

                        // if Surcharge Tax is selected on Tax, then set value in Surcharge Amount
                        if (New.Get_ColumnIndex("SurchargeAmt") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                        {
                            Decimal surchargeAmt = Env.ZERO;

                            // Calculate Surcharge Amount
                            TotalRate = tax.CalculateSurcharge(New.GetLineNetAmt(), priceList.IsTaxIncluded(), priceList.GetStandardPrecision(), out surchargeAmt);
                            New.SetTaxAmt(TotalRate);
                            New.SetSurchargeAmt(surchargeAmt);
                        }
                        else
                        {
                            // Calculate Tax Amount
                            tax       = MTax.Get(GetCtx(), contact.GetC_Tax_ID());
                            TotalRate = tax.CalculateTax(New.GetLineNetAmt(), priceList.IsTaxIncluded(), priceList.GetPricePrecision());
                            New.SetTaxAmt(TotalRate);
                        }
                        // Calculate Discount %
                        Decimal?dis = Decimal.Multiply(Decimal.Divide(Decimal.Subtract(New.GetPriceList(), New.GetPriceEntered()), New.GetPriceList()), 100);
                        New.SetDiscount(dis);

                        // Set Grand Total Amount
                        if (priceList.IsTaxIncluded())
                        {
                            New.SetGrandTotal(New.GetLineNetAmt());
                        }
                        else
                        {
                            if (New.Get_ColumnIndex("SurchargeAmt") > 0)
                            {
                                New.SetGrandTotal(Decimal.Add(Decimal.Add(New.GetLineNetAmt(), New.GetTaxAmt()), New.GetSurchargeAmt()));
                            }
                            else
                            {
                                New.SetGrandTotal(Decimal.Add(New.GetLineNetAmt(), New.GetTaxAmt()));
                            }
                        }

                        if (contact.GetBillStartDate() != null)
                        {
                            New.SetBillStartDate(contact.GetBillStartDate().Value.AddMonths(contact.GetTotalInvoice()));
                        }
                        else
                        {
                            New.SetBillStartDate(New.GetStartDate());
                        }
                        if (New.Save())
                        {
                            newcon = New.GetDocumentNo();
                            count++;
                            if (Record_id != 0)
                            {
                                contact.SetRef_Contract_ID(New.GetC_Contract_ID());
                                contact.SetRenewContract("Y");
                                if (!contact.Save())
                                {
                                    dr.Close();
                                    Get_TrxName().Rollback();
                                    return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                                }
                            }
                        }
                        else
                        {
                            dr.Close();
                            Get_TrxName().Rollback();
                            pp = VLogger.RetrieveError();
                            if (pp != null)
                            {
                                return(!String.IsNullOrEmpty(pp.GetName()) ? pp.GetName() : Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                            else
                            {
                                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                        }
                    }
                    else
                    {
                        // SI_0772: By Clicking on Renew Contract, System is throwing an error as 'NoContractReNewed'.
                        CDate  = contact.GetCancellationDate();
                        cycles = contact.GetCycles();
                        if (CDate != null)
                        {
                            continue;
                        }

                        New = new X_C_Contract(GetCtx(), 0, Get_TrxName());
                        New.SetRefContract(contact.GetDocumentNo());
                        New.SetC_Order_ID(contact.GetC_Order_ID());
                        New.SetC_OrderLine_ID(contact.GetC_OrderLine_ID());
                        OldStart = (DateTime)(contact.GetStartDate());
                        Start    = (DateTime)(contact.GetEndDate());
                        New.SetStartDate(Start.AddDays(1));

                        frequency = contact.GetC_Frequency_ID();

                        // Get No Of Months from Frequency
                        months   = Util.GetValueOfInt(DB.ExecuteScalar("SELECT NoOfMonths FROM C_Frequency WHERE C_Frequency_ID=" + frequency, null, Get_TrxName()));
                        duration = months * cycles;

                        endDate = New.GetStartDate().Value.AddMonths(duration);
                        endDate = endDate.AddDays(-1);

                        New.SetEndDate(endDate);
                        New.SetC_BPartner_ID(contact.GetC_BPartner_ID());
                        New.SetBill_Location_ID(contact.GetBill_Location_ID());
                        New.SetBill_User_ID(contact.GetBill_User_ID());
                        New.SetSalesRep_ID(contact.GetSalesRep_ID());
                        New.SetC_ConversionType_ID(contact.GetC_ConversionType_ID());
                        New.SetC_PaymentTerm_ID(contact.GetC_PaymentTerm_ID());
                        New.SetC_Frequency_ID(frequency);

                        // invoice Count Start

                        if (Record_id != 0)
                        {
                            if (contact.GetRef_PriceList_ID() == 0)
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "FirstSelectPriceList"));
                            }
                            New.SetM_PriceList_ID(contact.GetRef_PriceList_ID());

                            priceList = new MPriceList(GetCtx(), contact.GetRef_PriceList_ID(), Get_TrxName());
                            Sql.Clear();
                            Sql.Append("SELECT pp.PriceList, pp.PriceStd FROM M_ProductPrice pp INNER JOIN M_PriceList_Version plv ON pp.M_PriceList_Version_ID = plv.M_PriceList_Version_ID"
                                       + " WHERE pp.M_Product_ID=" + contact.GetM_Product_ID() + " AND plv.IsActive='Y' AND plv.M_PriceList_ID=" + contact.GetRef_PriceList_ID()
                                       + " AND plv.VALIDFROM <= SYSDATE ORDER BY plv.VALIDFROM DESC");
                            DataSet ds = DB.ExecuteDataset(Sql.ToString(), null, Get_TrxName());
                            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                Listprice = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["PriceList"]);
                                Stdprice  = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["PriceStd"]);
                            }
                            else
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "ProductNotOnPriceList"));
                            }

                            //String Query = "Select M_PriceList_Version_id from M_PriceList_Version where IsActive='Y' and M_PriceList_Id=" + contact.GetRef_PriceList_ID();
                            //int Version = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //Query = "Select PriceList,PriceStd from M_ProductPrice where M_PriceList_Version_id=" + Version + " and M_Product_ID=" + contact.GetM_Product_ID();
                            //decimal Listprice = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //Query = "Select PriceList,PriceStd from M_ProductPrice where M_PriceList_Version_id=" + Version + " and M_Product_ID=" + contact.GetM_Product_ID();
                            //decimal Stdprice = Util.GetValueOfInt(DB.ExecuteScalar(Query));
                            //if (Stdprice == 0 && Listprice == 0)
                            //{
                            //    return Msg.GetMsg(GetCtx(), "ProductNotINPriceList");
                            //}

                            New.SetPriceEntered(Stdprice);
                            New.SetPriceActual(Stdprice);
                            New.SetPriceList(Listprice);
                        }
                        else
                        {
                            priceList = new MPriceList(GetCtx(), contact.GetM_PriceList_ID(), Get_TrxName());
                            New.SetM_PriceList_ID(contact.GetM_PriceList_ID());
                            New.SetPriceActual(contact.GetPriceActual());
                            New.SetPriceList(contact.GetPriceList());
                            New.SetPriceEntered(contact.GetPriceEntered());
                        }
                        New.SetTotalInvoice(contact.GetCycles());
                        New.SetC_Currency_ID(priceList.GetC_Currency_ID());
                        New.SetC_UOM_ID(contact.GetC_UOM_ID());
                        New.SetM_Product_ID(contact.GetM_Product_ID());
                        New.SetM_AttributeSetInstance_ID(contact.GetM_AttributeSetInstance_ID());
                        New.SetQtyEntered(contact.GetQtyEntered());
                        New.SetC_Tax_ID(contact.GetC_Tax_ID());
                        New.SetC_Campaign_ID(contact.GetC_Campaign_ID());
                        New.SetRef_Contract_ID(contact.GetC_Contract_ID());
                        New.SetC_Project_ID(contact.GetC_Project_ID());
                        New.SetDescription(contact.GetDescription());
                        New.SetCancelBeforeDays(contact.GetCancelBeforeDays());
                        New.SetCycles(contact.GetCycles());
                        New.SetRenewContract("N");
                        New.SetScheduleContract("Y");
                        New.SetRenewalType("A");
                        New.SetDocStatus("DR");
                        New.SetLineNetAmt(Decimal.Multiply(New.GetPriceEntered(), New.GetQtyEntered()));

                        // Calculate Tax Amount
                        tax = MTax.Get(GetCtx(), contact.GetC_Tax_ID());

                        // if Surcharge Tax is selected on Tax, then set value in Surcharge Amount
                        if (New.Get_ColumnIndex("SurchargeAmt") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                        {
                            Decimal surchargeAmt = Env.ZERO;

                            // Calculate Surcharge Amount
                            TotalRate = tax.CalculateSurcharge(New.GetLineNetAmt(), priceList.IsTaxIncluded(), priceList.GetStandardPrecision(), out surchargeAmt);
                            New.SetTaxAmt(TotalRate);
                            New.SetSurchargeAmt(surchargeAmt);
                        }
                        else
                        {
                            TotalRate = tax.CalculateTax(New.GetLineNetAmt(), priceList.IsTaxIncluded(), priceList.GetPricePrecision());
                            New.SetTaxAmt(TotalRate);
                        }
                        // Calculate Discount %
                        Decimal?dis = Decimal.Multiply(Decimal.Divide(Decimal.Subtract(New.GetPriceList(), New.GetPriceEntered()), New.GetPriceList()), 100);
                        New.SetDiscount(dis);

                        // Set Grand Total Amount
                        if (priceList.IsTaxIncluded())
                        {
                            New.SetGrandTotal(New.GetLineNetAmt());
                        }
                        else
                        {
                            if (New.Get_ColumnIndex("SurchargeAmt") > 0)
                            {
                                New.SetGrandTotal(Decimal.Add(Decimal.Add(New.GetLineNetAmt(), New.GetTaxAmt()), New.GetSurchargeAmt()));
                            }
                            else
                            {
                                New.SetGrandTotal(Decimal.Add(New.GetLineNetAmt(), New.GetTaxAmt()));
                            }
                        }

                        if (contact.GetBillStartDate() != null)
                        {
                            New.SetBillStartDate(contact.GetBillStartDate().Value.AddMonths(contact.GetTotalInvoice()));
                        }
                        else
                        {
                            New.SetBillStartDate(New.GetStartDate());
                        }

                        if (New.Save())
                        {
                            newcon = New.GetDocumentNo();
                            count++;
                            contact.SetRef_Contract_ID(New.GetC_Contract_ID());
                            contact.SetRenewContract("Y");
                            if (!contact.Save())
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                            if (!EnterSchedules(New.GetC_Contract_ID(), cycles))
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                            New.SetProcessed(true);
                            if (!New.Save())
                            {
                                dr.Close();
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                        }
                        else
                        {
                            dr.Close();
                            Get_TrxName().Rollback();
                            pp = VLogger.RetrieveError();
                            if (pp != null)
                            {
                                return(!String.IsNullOrEmpty(pp.GetName()) ? pp.GetName() : Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                            else
                            {
                                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
                            }
                        }
                    }
                }
                dr.Close();
                if (count != 0 && Record_id != 0)
                {
                    return(Msg.GetMsg(GetCtx(), "ContractReNewed") + ": " + newcon);
                }
                if (count != 0)
                {
                    return(Msg.GetMsg(GetCtx(), "ContractReNewed"));
                }
                return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
            }
            return(Msg.GetMsg(GetCtx(), "ContractNotRenew"));
        }
        /// <summary>
        /// update Amount, converted Amount , writeoff and discount amount on Cheque details and postdatedcheck with the sum of
        /// checkallocate and chequedeatils amount respectively
        /// </summary>
        /// <param name="newRecord"></param>
        /// <param name="success"></param>
        /// <returns>true</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            int     stdprecision = 0;
            int     C_Tax_ID     = 0;
            Decimal surchargeAmt = Env.ZERO;
            Decimal TaxAmt       = Env.ZERO;
            Decimal PayAmt       = Env.ZERO;

            string sql = "UPDATE VA027_ChequeDetails i "
                         + "  SET VA027_ChequeAmount ="
                         + "   (SELECT COALESCE(SUM(Amount), 0) FROM VA027_checkallocate il WHERE i.VA027_ChequeDetails_ID = il.VA027_ChequeDetails_ID), VA027_IsCheckAllocated='Y'"
                         + " WHERE VA027_ChequeDetails_ID =" + GetVA027_ChequeDetails_ID() /*+ "And AD_Org_ID=" + GetAD_Org_ID() + "AND AD_Client_ID=" + GetAD_Client_ID()*/;

            int count = Util.GetValueOfInt(DB.ExecuteQuery(sql, null, Get_TrxName()));

            if (count > 0)
            {
                sql = "UPDATE va027_postdatedcheck SET VA027_PayAmt =" +
                      " (SELECT COALESCE(SUM(il.VA027_ChequeAmount),0) FROM va027_postdatedcheck i INNER JOIN VA027_ChequeDetails il" +
                      " ON i.va027_postdatedcheck_ID = il.va027_postdatedcheck_ID WHERE il.va027_postdatedcheck_ID =" +
                      "(SELECT va027_postdatedcheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_id = " + GetVA027_ChequeDetails_ID() + ")" +
                      " AND i.AD_Org_ID = " + GetAD_Org_ID() + " AND i.AD_Client_ID = " + GetAD_Client_ID() + ")," +
                      " VA027_ConvertedAmount = (SELECT COALESCE(SUM(il.VA027_ChequeAmount),0) FROM va027_postdatedcheck i INNER JOIN VA027_ChequeDetails il" +
                      " ON i.va027_postdatedcheck_ID = il.va027_postdatedcheck_ID WHERE il.va027_postdatedcheck_ID =" +
                      " (SELECT va027_postdatedcheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_id =" + GetVA027_ChequeDetails_ID() + ")" +
                      "  AND i.AD_Org_ID = " + GetAD_Org_ID() + "  AND i.AD_Client_ID = " + GetAD_Client_ID() + ")," +
                      " va027_writeoffAmt =(SELECT COALESCE(SUM(Writeoffamt),0) FROM Va027_checkAllocate i " +
                      "INNER JOIN va027_chequedetails ii ON i.va027_chequedetails_id = ii.va027_chequedetails_id " +
                      "INNER JOIN va027_postdatedCheck iii ON ii.va027_postdatedcheck_ID = iii.va027_postdatedcheck_ID " +
                      " WHERE iii.va027_postdatedcheck_ID = (SELECT va027_postdatedcheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_id =" + GetVA027_ChequeDetails_ID() + ")" +
                      " AND i.AD_Org_ID = " + GetAD_Org_ID() + "  AND i.AD_Client_ID = " + GetAD_Client_ID() + ")," +
                      " VA027_discountAmt = (SELECT COALESCE(SUM(discountAmt),0) FROM Va027_checkAllocate i " +
                      " INNER JOIN va027_chequedetails ii ON i.va027_chequedetails_id = ii.va027_chequedetails_id " +
                      " INNER JOIN va027_postdatedCheck iii ON ii.va027_postdatedcheck_ID = iii.va027_postdatedcheck_ID " +
                      " WHERE iii.va027_postdatedcheck_ID = (SELECT va027_postdatedcheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_id =" + GetVA027_ChequeDetails_ID() + ")" +
                      " AND i.AD_Org_ID = " + GetAD_Org_ID() + "  AND i.AD_Client_ID = " + GetAD_Client_ID() + ") " +
                      "  WHERE va027_postdatedcheck_ID =" +
                      "  (SELECT va027_postdatedcheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_id =" + GetVA027_ChequeDetails_ID() +
                      ") And AD_Org_ID = " + GetAD_Org_ID() + " AND AD_Client_ID = " + GetAD_Client_ID();

                DB.ExecuteQuery(sql, null, Get_TrxName());
            }

            sql = "SELECT StdPrecision, C_Tax_ID, VA027_PayAmt FROM VA027_PostDatedCheck i INNER JOIN C_Currency c ON i.C_Currency_ID = c.C_Currency_ID " +
                  "WHERE VA027_PostDatedCheck_ID = (SELECT VA027_PostDatedCheck_ID FROM VA027_ChequeDetails " +
                  "WHERE VA027_ChequeDetails_ID = " + GetVA027_ChequeDetails_ID() + ") AND i.C_Charge_ID > 0 AND i.C_Tax_ID > 0 ";

            DataSet ds = new DataSet();

            ds = DB.ExecuteDataset(sql, null, Get_Trx());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                stdprecision = Util.GetValueOfInt(ds.Tables[0].Rows[0]["StdPrecision"]);
                C_Tax_ID     = Util.GetValueOfInt(ds.Tables[0].Rows[0]["C_Tax_ID"]);
                PayAmt       = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["VA027_PayAmt"]);

                MTax tax = new MTax(GetCtx(), C_Tax_ID, null);

                if (tax.Get_ColumnIndex("Surcharge_Tax_ID") > 0 && tax.GetSurcharge_Tax_ID() > 0)
                {
                    TaxAmt = tax.CalculateSurcharge(PayAmt, true, stdprecision, out surchargeAmt);
                }
                else
                {
                    TaxAmt = tax.CalculateTax(PayAmt, true, stdprecision);
                }

                sql = "UPDATE VA027_PostDatedCheck SET TaxAmount= " + TaxAmt + " , SurchargeAmt= " + surchargeAmt +
                      " WHERE VA027_PostDatedCheck_ID = (SELECT VA027_PostDatedCheck_ID FROM VA027_ChequeDetails WHERE VA027_ChequeDetails_ID =" + GetVA027_ChequeDetails_ID() + " )";

                DB.ExecuteQuery(sql, null, Get_TrxName());
            }
            return(true);
        }
コード例 #6
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");
        }