/**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());

            if ((newRecord || Is_ValueChanged("C_Invoice_ID")) &&
                (payment.GetC_Charge_ID() != 0 ||
                 payment.GetC_Invoice_ID() != 0 ||
                 payment.GetC_Order_ID() != 0))
            {
                log.SaveError("PaymentIsAllocated", "");
                return(false);
            }

            Decimal check = Decimal.Add(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), GetOverUnderAmt());

            if (check.CompareTo(GetInvoiceAmt()) != 0)
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(),
                                                            "@InvoiceAmt@(" + GetInvoiceAmt()
                                                            + ") <> @Totals@(" + check + ")"));
                return(false);
            }

            //	Org
            if (newRecord || Is_ValueChanged("C_Invoice_ID"))
            {
                GetInvoice();
                if (_invoice != null)
                {
                    SetAD_Org_ID(_invoice.GetAD_Org_ID());
                }
            }

            return(true);
        }
        /**
         *  Get active Payment Allocation of Payment
         *	@param parent payment
         *	@return array of allocations
         */
        public static MPaymentAllocate[] Get(MPayment parent)
        {
            List <MPaymentAllocate> list = new List <MPaymentAllocate>();
            String sql = "SELECT * FROM C_PaymentAllocate WHERE C_Payment_ID=" + parent.GetC_Payment_ID() + " AND IsActive='Y'";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MPaymentAllocate(parent.GetCtx(), dr, parent.Get_TrxName()));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            MPaymentAllocate[] retValue = new MPaymentAllocate[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
        /// <summary>
        ///  Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true, on Save</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());

            if ((newRecord || Is_ValueChanged("C_Invoice_ID")) &&
                (payment.GetC_Charge_ID() != 0 ||
                 payment.GetC_Invoice_ID() != 0 ||
                 payment.GetC_Order_ID() != 0))
            {
                log.SaveError("PaymentIsAllocated", "");
                return(false);
            }

            // during saving a new record, system will check same invoice schedule reference exist on same payment or not
            if (newRecord && Get_ColumnIndex("C_InvoicePaySchedule_ID") >= 0 && GetC_InvoicePaySchedule_ID() > 0)
            {
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM C_PaymentAllocate   WHERE C_Payment_ID = " + GetC_Payment_ID() +
                                                        @" AND IsActive = 'Y' AND C_InvoicePaySchedule_ID = " + GetC_InvoicePaySchedule_ID(), null, Get_Trx())) > 0)
                {
                    //"Error" not required
                    //log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord"));
                    log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord"));
                    return(false);
                }
            }

            // check schedule is hold or not, if hold then no to save record
            if (Get_ColumnIndex("C_InvoicePaySchedule_ID") >= 0 && GetC_InvoicePaySchedule_ID() > 0)
            {
                if (payment.IsHoldpaymentSchedule(GetC_InvoicePaySchedule_ID()))
                {
                    log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_PaymentisHold"));
                    return(false);
                }
            }

            if (!Env.IsModuleInstalled("VA009_"))
            {
                Decimal check = Decimal.Add(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), GetOverUnderAmt());
                if (check.CompareTo(GetInvoiceAmt()) != 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(),
                                                                "@InvoiceAmt@(" + GetInvoiceAmt()
                                                                + ") <> @Totals@(" + check + ")"));
                    return(false);
                }
            }

            //	Org
            if (newRecord || Is_ValueChanged("C_Invoice_ID"))
            {
                GetInvoice();
                if (_invoice != null)
                {
                    SetAD_Org_ID(_invoice.GetAD_Org_ID());
                }
            }

            return(true);
        }
Example #4
0
        /**
         *  Get active Payment Allocation of Payment
         *	@param parent payment
         *	@return array of allocations
         */
        public static MPaymentAllocate[] Get(MPayment parent)
        {
            List <MPaymentAllocate> list = new List <MPaymentAllocate>();
            // Change by mohit
            String sql = "SELECT * FROM C_PaymentAllocate WHERE C_Payment_ID=" + parent.GetC_Payment_ID() + " AND  NVL(C_Invoice_ID , 0) <> 0  AND IsActive='Y'";

            //String sql = "SELECT * FROM C_PaymentAllocate WHERE C_Payment_ID=" + parent.GetC_Payment_ID() + "   AND IsActive='Y'";
            try
            {
                //DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null);
                DataSet ds = DB.ExecuteDataset(sql, null, parent.Get_TrxName()); //Arpit..Passes transction to get ALL Allocations at transction Level
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MPaymentAllocate(parent.GetCtx(), dr, parent.Get_TrxName()));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            MPaymentAllocate[] retValue = new MPaymentAllocate[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
        /// <summary>
        ///     Create Payment for BankStatement
        /// </summary>
        /// <param name="bsl">bank statement Line</param>
        /// <returns>Message</returns>
        private String CreatePayment(MBankStatementLine bsl)
        {
            if (bsl == null || bsl.GetC_Payment_ID() != 0)
            {
                return("--");
            }
            log.Fine(bsl.ToString());
            if (bsl.GetC_Invoice_ID() == 0 && bsl.GetC_BPartner_ID() == 0)
            {
                throw new Exception("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
            }
            //
            MBankStatement bs = new MBankStatement(GetCtx(), bsl.GetC_BankStatement_ID(), Get_Trx());
            //
            MPayment payment = CreatePayment(bsl.GetC_Invoice_ID(), bsl.GetC_BPartner_ID(),
                                             bsl.GetC_Currency_ID(), bsl.GetStmtAmt(), bsl.GetTrxAmt(),
                                             bs.GetC_BankAccount_ID(), bsl.GetStatementLineDate(), bsl.GetDateAcct(),
                                             bsl.GetDescription(), bsl.GetAD_Org_ID());

            if (payment == null)
            {
                throw new SystemException("Could not create Payment");
            }
            //	update statement
            bsl.SetPayment(payment);
            bsl.Save();
            //
            String retString = "@C_Payment_ID@ = " + payment.GetDocumentNo();

            if (Env.Signum(payment.GetOverUnderAmt()) != 0)
            {
                retString += " - @OverUnderAmt@=" + payment.GetOverUnderAmt();
            }
            return(retString);
        }
Example #6
0
        /// <summary>
        /// Set Statement Line
        /// </summary>
        /// <param name="payment">Payment</param>
        /// <returns>Message</returns>
        public string SetPayments(MPayment payment)
        {
            SetC_Payment_ID(payment.GetC_Payment_ID());
            //SetC_Currency_ID(payment.GetC_Currency_ID());
            Decimal amt = payment.GetPayAmt(true);

            //Currency Conversion to BankStatementLine Currency
            if (GetC_Currency_ID() != payment.GetC_Currency_ID())
            {
                int conversionType = Get_ColumnIndex("C_ConversionType_ID") > 0 ? Get_ValueAsInt("C_ConversionType_ID") : payment.GetC_ConversionType_ID();
                amt = MConversionRate.Convert(GetCtx(), amt, payment.GetC_Currency_ID(), GetC_Currency_ID(), GetValutaDate(), conversionType, GetAD_Client_ID(), GetAD_Org_ID());
            }
            if (amt != 0)
            {
                SetTrxAmt(amt);
                if (GetStmtAmt() == 0)
                {
                    SetStmtAmt(amt);
                }
                else // Incase of Uncociled StatementLine have existing Amount
                {
                    decimal _diffAmt = GetStmtAmt() - GetTrxAmt();
                    SetChargeAmt(_diffAmt - GetInterestAmt());
                }
                SetDescription(payment.GetDescription());
            }
            else
            {
                return(Msg.GetMsg(GetCtx(), "NoCurrencyConversion"));
            }
            //Set VA012_VoucherType
            if (Env.IsModuleInstalled("VA012_"))
            {
                bool _IsPaymentAllocate = false;
                int  _InvCount;
                //When Payment have Multiple InvoicePaySchedules
                if (payment.Get_ColumnIndex("IsPaymentAllocate") > 0)
                {
                    _IsPaymentAllocate = Util.GetValueOfBool(payment.Get_Value("IsPaymentAllocate"));
                }
                if (_IsPaymentAllocate)
                {
                    _InvCount = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(C_PaymentAllocate_ID) FROM C_PaymentAllocate WHERE IsActive='Y' AND C_Payment_ID=" + payment.GetC_Payment_ID(), null, null));
                }
                else
                {
                    _InvCount = payment.GetC_Invoice_ID();
                }
                if (_InvCount > 0 || payment.GetC_Order_ID() > 0)
                {
                    SetVA012_VoucherType("M"); // 'M' indicates VA012_VoucherType as Payment
                }
                else if (payment.GetC_Charge_ID() > 0)
                {
                    SetVA012_VoucherType("V"); // 'V' indicates VA012_VoucherType as Voucher
                }
            }
            return("");
        }
        //Added by Bharat on 12/May/2017
        /// <summary>
        /// GetPayment Amount
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public decimal GetPayAmt(Ctx ctx, string fields)
        {
            int C_Payment_ID;

            //Assign parameter value
            C_Payment_ID = Util.GetValueOfInt(fields);
            MPayment payment = new MPayment(ctx, C_Payment_ID, null);

            return(payment.GetPayAmt());
        }
Example #8
0
        /// <summary>
        /// Set Payment
        /// </summary>
        /// <param name="payment">Payment</param>
        public void SetPayment(MPayment payment)
        {
            SetC_Payment_ID(payment.GetC_Payment_ID());
            SetC_Currency_ID(payment.GetC_Currency_ID());
            Decimal amt = payment.GetPayAmt(true);

            SetTrxAmt(amt);
            SetStmtAmt(amt);
            SetDescription(payment.GetDescription());
        }
Example #9
0
        /// <summary>
        /// Added by Bharat to Reset IsPaymentAllocate to false on Deletion of Record..
        /// </summary>
        /// <param name="success"></param>
        /// <returns></returns>
        protected override bool AfterDelete(bool success)
        {
            if (!success)
            {
                return(success);
            }
            MPayment pay = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());

            if (pay.Get_ColumnIndex("IsPaymentAllocate") > 0)
            {
                string sql   = "SELECT Count(C_PaymentAllocate_ID) FROM C_PaymentAllocate WHERE C_Payment_ID = " + GetC_Payment_ID();
                int    count = Util.GetValueOfInt(DB.ExecuteScalar(sql));
                if (count == 0)
                {
                    String qry = "UPDATE C_Payment SET IsPaymentAllocate = 'N' WHERE C_Payment_ID=" + GetC_Payment_ID();
                    int    no  = DataBase.DB.ExecuteQuery(qry, null, Get_TrxName());
                    if (no != 1)
                    {
                        log.Warning("Payment Allocate not set");
                    }
                }
            }

            // Added bby Bharat on 31 July 2017 as Issue given by Ravikant
            //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_'  AND IsActive = 'Y'"));
            if (Env.IsModuleInstalled("VA009_"))
            {
                // consider record which are active
                String sql = "UPDATE C_Payment i"
                             + " SET PayAmt= (SELECT COALESCE(SUM(Amount),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) ,  "
                             + "     DiscountAmt= (SELECT COALESCE(SUM(DiscountAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) ,  "
                             + "     WriteOffAmt= (SELECT COALESCE(SUM(WriteOffAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) , "
                             + "     OverUnderAmt= (SELECT COALESCE(SUM(OverUnderAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID)  "
                             + (pay.Get_ColumnIndex("PaymentAmount") > 0 ? ", PaymentAmount =  (SELECT COALESCE(SUM(Amount),0) FROM C_PaymentAllocate il WHERE il.IsActive = 'Y' AND i.C_Payment_ID=il.C_Payment_ID)" : "")
                             + "WHERE C_Payment_ID=" + GetC_Payment_ID();
                int no = DataBase.DB.ExecuteQuery(sql, null, Get_TrxName());
                if (no != 1)
                {
                    log.Warning("(1) #" + no);
                }
            }

            // calculate Withholding
            if (!pay.VerifyAndCalculateWithholding(true))
            {
                log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "WrongBackupWithholding"));
            }
            else
            {
                pay._isWithholdingFromPaymentAllocate = true;
                pay.Save();
            }
            return(true);
        }
Example #10
0
 /// <summary>
 /// Get Payment
 /// </summary>
 /// <returns>Returns the payment.</returns>
 public MPayment GetPayment()
 {
     if (GetC_Payment_ID() == 0)
     {
         _payment = null;
     }
     else if (_payment == null)
     {
         _payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());
     }
     return(_payment);
 }
        /// <summary>
        /// Load Specific Document Details
        /// </summary>
        /// <returns>error message or null</returns>
        public override String LoadDocumentDetails()
        {
            MPayment pay = (MPayment)GetPO();

            SetDateDoc(pay.GetDateTrx());
            _TenderType       = pay.GetTenderType();
            _Prepayment       = pay.IsPrepayment();
            _C_BankAccount_ID = pay.GetC_BankAccount_ID();
            //	Amount
            SetAmount(Doc.AMTTYPE_Gross, pay.GetPayAmt());
            return(null);
        }
        // GET: Payment/Create
        public ActionResult Create(int pIdOrder, decimal pValueOrder)
        {
            MPayment lPayment = new MPayment();

            lPayment.LOrder = new MOrder
            {
                LIdOrder    = pIdOrder,
                LValueOrder = pValueOrder
            };
            lPayment.LIsCompleted = false;
            return(View(lPayment));
        }
        protected override bool AfterSave(bool newRecord, bool success)
        {
            // Added by Bharat on 27 june 2017 to handle Unique constraint issue
            if (!success)
            {
                return(success);
            }

            // Added by Bharat on 25 July 2017 to set IsPaymentAllocate to True.
            MPayment pay = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());

            if (pay.Get_ColumnIndex("IsPaymentAllocate") > 0)
            {
                String qry = "UPDATE C_Payment SET IsPaymentAllocate = 'Y' WHERE C_Payment_ID=" + GetC_Payment_ID();
                int    no  = DataBase.DB.ExecuteQuery(qry, null, Get_TrxName());
                if (no != 1)
                {
                    log.Warning("Payment Allocate not set");
                }
            }

            if (Env.IsModuleInstalled("VA009_"))
            {
                //changes done to avoid null Exception
                // consider record which are active
                String sql = "UPDATE C_Payment i"
                             + " SET PayAmt= ((SELECT COALESCE(SUM(Amount),0) FROM C_PaymentAllocate il WHERE il.IsActive = 'Y' AND i.C_Payment_ID=il.C_Payment_ID) "
                             + (pay.Get_ColumnIndex("PaymentAmount") > 0 ? " - (NVL(BackupWithholdingAmount,0) + NVL(WithholdingAmt,0))),  " : "), ")
                             + "     DiscountAmt= (SELECT COALESCE(SUM(DiscountAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) ,  "
                             + "     WriteOffAmt= (SELECT COALESCE(SUM(WriteOffAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) , "
                             + "     OverUnderAmt= (SELECT COALESCE(SUM(OverUnderAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID)  "
                             + (pay.Get_ColumnIndex("PaymentAmount") > 0 ? ", PaymentAmount =  (SELECT COALESCE(SUM(Amount),0) FROM C_PaymentAllocate il WHERE il.IsActive = 'Y' AND i.C_Payment_ID=il.C_Payment_ID)" : "")
                             + "WHERE C_Payment_ID=" + GetC_Payment_ID();
                int no = DataBase.DB.ExecuteQuery(sql, null, Get_TrxName());
                if (no != 1)
                {
                    log.Warning("(1) #" + no);
                }
            }

            // calculate Withholding
            if (!pay.VerifyAndCalculateWithholding(true))
            {
                log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "WrongBackupWithholding"));
            }
            else
            {
                pay._isWithholdingFromPaymentAllocate = true;
                pay.Save();// if not saved, then try to calculate on prepare
            }
            return(true);
        }
Example #14
0
        protected override string DoIt()
        {
            try
            {
                if (C_Order_ID < 1)
                {
                    return("Failed");
                }
                //int c_Order_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT C_Order_ID From C_Order WHERE DocumentNo=" + salesOrderNo));
                MOrder order        = new MOrder(GetCtx(), C_Order_ID, null);
                int    C_DocType_ID = order.GetC_DocTypeTarget_ID();
                string baseType     = DB.ExecuteScalar("SELECT DocSubTypeSO From C_DocType WHERE isactive='Y' AND C_DocType_ID=" + C_DocType_ID).ToString();

                if (!(baseType.Equals("PR") || baseType.Equals("WI")))
                {
                    return("Failed");
                }
                MPayment payment = new MPayment(GetCtx(), 0, null);
                payment.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                payment.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                //payment.SetDocumentNo(MS
                payment.SetC_BankAccount_ID(Util.GetValueOfInt(
                                                DB.ExecuteScalar("Select c_bankAccount_ID from c_bankaccount where isdefault='Y' and isactive='Y'")));
                payment.SetDateTrx(DateTime.Now);
                payment.SetDateAcct(DateTime.Now);
                payment.SetC_BPartner_ID(order.GetC_BPartner_ID());
                payment.SetPayAmt(order.GetGrandTotal());
                payment.SetC_Currency_ID(order.GetC_Currency_ID());
                payment.SetTenderType("K");
                payment.SetDocStatus("IP");


                if (baseType.Equals("PR")) //prepay Order
                {
                    payment.SetC_Order_ID(order.GetC_Order_ID());
                    payment.SetIsPrepayment(true);
                }
                else if (baseType.Equals("WI"))//OnCreditOrder
                {
                    payment.SetC_Invoice_ID(order.GetC_Invoice_ID());
                }
                payment.Save();

                return(payment.GetDocumentNo().ToString());
            }
            catch
            {
                return("Failed");
            }
        }
        /// <summary>
        /// GetPayment
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <string, string> GetPayment(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      C_Payment_ID;

            //Assign parameter value
            C_Payment_ID = Util.GetValueOfInt(paramValue[0].ToString());
            MPayment payment = new MPayment(ctx, C_Payment_ID, null);
            Dictionary <string, string> result = new Dictionary <string, string>();

            result["C_Charge_ID"]  = payment.GetC_Charge_ID().ToString();
            result["C_Invoice_ID"] = payment.GetC_Invoice_ID().ToString();
            result["C_Order_ID"]   = payment.GetC_Order_ID().ToString();
            return(result);
        }
Example #16
0
        /// <summary>
        /// Complete Document
        /// </summary>
        /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns>
        public String CompleteIt()
        {
            //	Re-Check
            if (!m_justPrepared)
            {
                String status = PrepareIt();
                if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                {
                    return(status);
                }
            }
            //	Implicit Approval
            if (!IsApproved())
            {
                ApproveIt();
            }
            log.Info("completeIt - " + ToString());

            //	Set Payment reconciled
            MBankStatementLine[] lines = GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MBankStatementLine line = lines[i];
                if (line.GetC_Payment_ID() != 0)
                {
                    MPayment payment = new MPayment(GetCtx(), line.GetC_Payment_ID(), Get_TrxName());
                    payment.SetIsReconciled(true);
                    payment.Save(Get_TrxName());
                }
            }
            //	Update Bank Account
            MBankAccount ba = MBankAccount.Get(GetCtx(), GetC_BankAccount_ID());

            ba.SetCurrentBalance(GetEndingBalance());
            ba.Save(Get_TrxName());

            //	User Validation
            String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE);

            if (valid != null)
            {
                m_processMsg = valid;
                return(DocActionVariables.STATUS_INVALID);
            }
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            return(DocActionVariables.STATUS_COMPLETED);
        }
 public ActionResult Create(MPayment pPayment)
 {
     try
     {
         var LValueTotal  = Convert.ToInt32(pPayment.LOrder.LValueOrder);
         var LIdOrder     = Convert.ToInt32(pPayment.LOrder.LIdOrder);
         var lPayments    = this.LiPaymentFacade.bll_GetPaymentByOrder(LIdOrder);
         var lSumValuePay = Convert.ToInt32(lPayments.Sum(x => x.LValuePayment));
         var lValidatesum = lSumValuePay + pPayment.LValuePayment;
         if (LValueTotal > lValidatesum)
         {
             var lMessage = this.LiPaymentFacade.bll_InsertPayment(pPayment.LOrder.LIdOrder, pPayment.LValuePayment, this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectPayment).LIdObject, this.LiUtilsLib.bll_getStatusApproByObject(this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectPayment).LIdObject).LIdStatus);
             if (string.IsNullOrEmpty(lMessage))
             {
                 return(RedirectToAction("Index", new { pIdOrder = LIdOrder, pValueOrder = LValueTotal }));
             }
             pPayment.LMessageException = lMessage;
             return(View(pPayment));
         }
         if (LValueTotal == lValidatesum)
         {
             var lMessage = this.LiPaymentFacade.bll_InsertPayment(pPayment.LOrder.LIdOrder, pPayment.LValuePayment, this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectPayment).LIdObject, this.LiUtilsLib.bll_getStatusApproByObject(this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectPayment).LIdObject).LIdStatus);
             if (string.IsNullOrEmpty(lMessage))
             {
                 var lIdInvoice       = 0;
                 var lOrder           = this.LiOrder.bll_GetOrder(pPayment.LOrder.LIdOrder);
                 var lListOrderItem   = this.LiOrderItem.bll_GetOrderItem(pPayment.LOrder.LIdOrder);
                 var lListInvoiceItem = this.LInvoiceItem.bll_ChangeOrderItemToInvoiceItem(lListOrderItem, this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectInvoiceItem));
                 var lResult          = this.LInvoice.bll_InsertInvoiceAll(lOrder.LCustomer.LIdCustomer, lOrder.LIdOrder, this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectInvoice).LIdObject, lListInvoiceItem);
                 if (int.TryParse(lResult, out lIdInvoice))
                 {
                     this.LiOrder.bll_UpdateOrder(lOrder.LIdOrder, this.LiUtilsLib.bll_getStatusApproByObject(this.LiUtilsLib.bll_GetObjectByName(MGlobalVariables.LNameObjectOrder).LIdObject).LIdStatus);
                     return(RedirectToAction("Index", new { pIdOrder = LIdOrder, pValueOrder = LValueTotal, pIdInvoice = lIdInvoice }));
                 }
                 return(RedirectToAction("Index", new { pIdOrder = LIdOrder, pValueOrder = LValueTotal }));
             }
             pPayment.LMessageException = lMessage;
             return(View(pPayment));
         }
         pPayment.LMessageException = CodesError.LMsgPaymentDenied;
         return(View(pPayment));
     }
     catch (Exception e)
     {
         pPayment.LMessageException = e.Message;
         return(View(pPayment));
     }
 }
        }       //	processAllocation

        /// <summary>
        ///	Process Payment
        /// </summary>
        /// <returns> true if processed</returns>
        private Boolean ProcessPayment()
        {
            if (_m_payment == null)
            {
                return(true);
            }
            //	Process It
            if (_m_payment.ProcessIt(DocActionVariables.ACTION_COMPLETE) && _m_payment.Save())
            {
                _m_payment = null;
                return(true);
            }
            //
            _m_payment = null;
            return(false);
        }       //	processPayment
        /**
         *  Factory
         *  @param mpp payment processor model
         *  @param mp payment model
         *  @return initialized PaymentProcessor or null
         */
        public static PaymentProcessor Create(MPaymentProcessor mpp, MPayment mp)
        {
            _log.Info("create for " + mpp);
            String className = mpp.GetPayProcessorClass();

            if (className == null || className.Length == 0)
            {
                _log.Log(Level.SEVERE, "No PaymentProcessor class name in " + mpp);
                return(null);
            }
            //
            PaymentProcessor myProcessor = null;

            try
            {
                //Class ppClass = Class.forName(className);
                //if (ppClass != null)
                //    myProcessor = (PaymentProcessor)ppClass.newInstance();

                Type ppClass = Type.GetType(className);
                if (ppClass != null)
                {
                    myProcessor = (PaymentProcessor)Activator.CreateInstance(ppClass);
                }
            }
            //catch (Error e1)    //  NoClassDefFound
            //{
            //    _log.Log(Level.SEVERE, className + " - Error=" + e1.Message);
            //    return null;
            //}
            catch (Exception e2)
            {
                _log.Log(Level.SEVERE, className, e2);
                return(null);
            }
            if (myProcessor == null)
            {
                _log.Log(Level.SEVERE, "no class");
                return(null);
            }

            //  Initialize
            myProcessor._mpp = mpp;
            myProcessor._mp  = mp;
            //
            return(myProcessor);
        }
Example #20
0
 /// <summary>
 /// Set Payment
 /// </summary>
 /// <param name="payment"></param>
 public void SetPayment(MPayment payment)
 {
     _payment = payment;
     if (payment != null)
     {
         _C_CurrencyFrom_ID = payment.GetC_Currency_ID();
         SetAmt(payment.GetPayAmt()); //	need to reverse
         SetOpenAmt(GetAmt());        //	not correct
         SetConvertedAmt(MConversionRate.Convert(GetCtx(), GetOpenAmt(),
                                                 GetC_CurrencyFrom_ID(), GetC_CurrencyTo_ID(), GetAD_Client_ID(), GetAD_Org_ID()));
     }
     else
     {
         _C_CurrencyFrom_ID = 0;
         SetAmt(Env.ZERO);
         SetConvertedAmt(Env.ZERO);
     }
 }
Example #21
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord"></param>
        /// <returns>true</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (Env.Signum(GetChargeAmt()) != 0 && GetC_Charge_ID() == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID"));
                // ErrorLog.FillErrorLog("FillMandatory", GetMessage.Translate(GetCtx(), "C_Charge_ID"), "", VAdvantage.Framework.Message.MessageType.ERROR);
                return(false);
            }

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM C_BankStatementLine WHERE C_BankStatement_ID=@param1";
                int    ii  = Convert.ToInt32(DB.GetSQLValue(Get_TrxName(), sql, GetC_BankStatement_ID()));
                SetLine(ii);
            }

            //	Set References
            if (GetC_Payment_ID() != 0 && GetC_BPartner_ID() == 0)
            {
                MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());
                SetC_BPartner_ID(payment.GetC_BPartner_ID());
                if (payment.GetC_Invoice_ID() != 0)
                {
                    SetC_Invoice_ID(payment.GetC_Invoice_ID());
                }
            }
            if (GetC_Invoice_ID() != 0 && GetC_BPartner_ID() == 0)
            {
                MInvoice invoice = new MInvoice(GetCtx(), GetC_Invoice_ID(), Get_TrxName());
                SetC_BPartner_ID(invoice.GetC_BPartner_ID());
            }
            //	Calculate Charge = Statement - trx - Interest
            Decimal amt = GetStmtAmt();

            amt = Decimal.Subtract(amt, GetTrxAmt());
            amt = Decimal.Subtract(amt, GetInterestAmt());
            if (amt.CompareTo(GetChargeAmt()) != 0)
            {
                SetChargeAmt(amt);
            }
            return(true);
        }
 public ActionResult Delete(int id, MPayment pPayment)
 {
     try
     {
         var LValueTotal = Convert.ToInt32(pPayment.LOrder.LValueOrder);
         var LIdOrder    = Convert.ToInt32(pPayment.LOrder.LIdOrder);
         // TODO: Add delete logic here
         var lMessage = this.LiPaymentFacade.bll_DeletePayment(id);
         if (string.IsNullOrEmpty(lMessage))
         {
             return(RedirectToAction("Index", new { pIdOrder = LIdOrder, pValueOrder = LValueTotal }));
         }
         pPayment.LMessageException = lMessage;
         return(View(id));
     }
     catch
     {
         return(View());
     }
 }
        public static List <MPayment> MListPayment(this List <BoPayment> pListPayment)
        {
            var lListPayment = new List <MPayment>();

            pListPayment.ForEach(x => {
                var lPayment = new MPayment
                {
                    LCreationDate     = x.LCreationDate,
                    LIdPayment        = x.LIdPayment,
                    LModificationDate = x.LModificationDate,
                    LObject           = new MObject
                    {
                        LIdObject   = x.LObject.LIdObject,
                        LNameObject = x.LObject.LNameObject
                    },
                    LValuePayment = x.LValuePayment
                };
                lListPayment.Add(lPayment);
            });
            return(lListPayment);
        }
Example #24
0
        }       //	checkBP

        /// <summary>
        /// Check Payments
        /// </summary>
        /// <param name="bp">bp business partner</param>
        private void CheckPayments(MBPartner bp)
        {
            //	See also VMerge.postMerge
            int changed = 0;

            MPayment[] payments = MPayment.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_Trx());
            for (int i = 0; i < payments.Length; i++)
            {
                MPayment payment = payments[i];
                if (payment.TestAllocation())
                {
                    payment.Save();
                    changed++;
                }
            }
            if (changed != 0)
            {
                AddLog(0, null, new Decimal(payments.Length),
                       Msg.GetElement(GetCtx(), "C_Payment_ID") + " - #" + changed);
            }
        }       //	checkPayments
        }       //	mergeTable

        /// <summary>
        /// Post Merge
        /// </summary>
        /// <param name="ColumnName">column name</param>
        /// <param name="to_ID">ID</param>
        private void PostMerge(String ColumnName, int to_ID)
        {
            if (ColumnName.Equals(AD_ORG_ID))
            {
            }
            else if (ColumnName.Equals(AD_USER_ID))
            {
            }
            else if (ColumnName.Equals(C_BPARTNER_ID))
            {
                MBPartner bp = new MBPartner(GetCtx(), to_ID, Get_TrxName());
                if (bp.Get_ID() != 0)
                {
                    MPayment[] payments = MPayment.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_TrxName());
                    for (int i = 0; i < payments.Length; i++)
                    {
                        MPayment payment = payments[i];
                        if (payment.TestAllocation())
                        {
                            payment.Save();
                        }
                    }
                    MInvoice[] invoices = MInvoice.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_TrxName());
                    for (int i = 0; i < invoices.Length; i++)
                    {
                        MInvoice invoice = invoices[i];
                        if (invoice.TestAllocation())
                        {
                            invoice.Save();
                        }
                    }
                    bp.SetTotalOpenBalance();
                    bp.SetActualLifeTimeValue();
                    bp.Save();
                }
            }
            else if (ColumnName.Equals(M_PRODUCT_ID))
            {
            }
        }       //	postMerge
Example #26
0
        private void SetPayments(int C_Payment_ID, int C_Currency_ID, string _PaymentRule)
        {
            if (pDetails == null)
            {
                pDetails = new PaymentMetohdDetails();
            }
            //  Existing Payment
            if (C_Payment_ID != 0)
            {
                if (C_Payment_ID != 0)
                {
                    _mPayment         = new MPayment(ctx, C_Payment_ID, null);
                    _mPaymentOriginal = new MPayment(ctx, _C_Payment_ID, null); //	full copy
                    //  CreditCard
                    pDetails.CCType       = _mPayment.GetCreditCardType();
                    pDetails.StrKNumber   = _mPayment.GetCreditCardNumber();
                    pDetails.StrKExp      = _mPayment.GetCreditCardExp(null);
                    pDetails.StrKApproval = _mPayment.GetVoiceAuthCode();
                    pDetails.StrKStatus   = _mPayment.GetR_PnRef();
                    pDetails.CanChange    = !_mPayment.IsApproved() || !(_PaymentRule == MOrder.PAYMENTRULE_CreditCard);
                    //	if approved/paid, don't let it change

                    //  Check
                    _C_BankAccount_ID    = _mPayment.GetC_BankAccount_ID();
                    pDetails.StrSRouting = _mPayment.GetRoutingNo();
                    pDetails.StrSNumber  = _mPayment.GetAccountNo();
                    pDetails.StrSCheck   = _mPayment.GetCheckNo();
                    pDetails.StrSStatus  = _mPayment.GetR_PnRef();
                    //  Transfer
                    pDetails.StrTStatus = _mPayment.GetR_PnRef();
                }
            }
            if (_mPayment == null)
            {
                _mPayment = new MPayment(ctx, 0, null);
                _mPayment.SetAD_Org_ID(_AD_Org_ID);
                _mPayment.SetIsReceipt(_isSOTrx);
                _mPayment.SetAmount(C_Currency_ID, _Amount);
            }
        }
Example #27
0
        protected override string DoIt()
        {
            MAllocationLine objMAllocationLine = new MAllocationLine(GetCtx(), GetRecord_ID(), Get_Trx());

            if (objMAllocationLine.GetM_CostAllocation_ID() == 0)
            {
                MPayment objMPayment  = new MPayment(GetCtx(), objMAllocationLine.GetC_Payment_ID(), Get_Trx());
                string   AlloctionMsg = "";
                //if (objMPayment.GenerateCostAllocation(objMPayment.GetDocumentNo(), GetAD_Client_ID(), Get_Trx(), GetAD_Org_ID(), out AlloctionMsg))
                //{
                //    return "Done";
                //}
                //else
                //{
                return(AlloctionMsg);
                // }
            }
            else
            {
                return("Cost Allocation record already generated");
            }
        }
Example #28
0
        protected override bool AfterSave(bool newRecord, bool success)
        {
            // Added by Bharat on 27 june 2017 to handle Unique constraint issue
            if (!success)
            {
                return(success);
            }

            // Added by Bharat on 25 July 2017 to set IsPaymentAllocate to True.
            MPayment pay = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());

            if (pay.Get_ColumnIndex("IsPaymentAllocate") > 0)
            {
                String qry = "UPDATE C_Payment SET IsPaymentAllocate = 'Y' WHERE C_Payment_ID=" + GetC_Payment_ID();
                int    no  = DB.ExecuteQuery(qry, null, Get_TrxName());
                if (no != 1)
                {
                    log.Warning("Payment Allocate not set");
                }
            }

            //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_'  AND IsActive = 'Y'"));
            if (Env.IsModuleInstalled("VA009_"))
            {
                // consider record which are active
                String sql = "UPDATE C_Payment i"
                             + " SET PayAmt= (SELECT COALESCE(SUM(Amount),0) FROM C_PaymentAllocate il WHERE il.IsActive = 'Y' AND i.C_Payment_ID=il.C_Payment_ID) ,  "
                             + "     DiscountAmt= (SELECT COALESCE(SUM(DiscountAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) ,  "
                             + "     WriteOffAmt= (SELECT COALESCE(SUM(WriteOffAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID) , "
                             + "     OverUnderAmt= (SELECT COALESCE(SUM(OverUnderAmt),0) FROM C_PaymentAllocate il WHERE  il.IsActive = 'Y' AND  i.C_Payment_ID=il.C_Payment_ID)  "
                             + "WHERE C_Payment_ID=" + GetC_Payment_ID();
                int no = DB.ExecuteQuery(sql, null, Get_TrxName());
                if (no != 1)
                {
                    log.Warning("(1) #" + no);
                }
            }
            return(true);
        }
        /// <summary>
        /// Create Payment for Import
        /// </summary>
        /// <param name="ibs">import bank statement</param>
        /// <returns></returns>
        private String CreatePayment(X_I_BankStatement ibs)
        {
            if (ibs == null || ibs.GetC_Payment_ID() != 0)
            {
                return("--");
            }
            log.Fine(ibs.ToString());
            if (ibs.GetC_Invoice_ID() == 0 && ibs.GetC_BPartner_ID() == 0)
            {
                throw new Exception("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
            }
            if (ibs.GetC_BankAccount_ID() == 0)
            {
                throw new Exception("@NotFound@ @C_BankAccount_ID@");
            }
            //
            MPayment payment = CreatePayment(ibs.GetC_Invoice_ID(), ibs.GetC_BPartner_ID(),
                                             ibs.GetC_Currency_ID(), ibs.GetStmtAmt(), ibs.GetTrxAmt(),
                                             ibs.GetC_BankAccount_ID(), Utility.Util.GetValueOfDateTime(ibs.GetStatementLineDate() == null ? ibs.GetStatementDate() : ibs.GetStatementLineDate()),
                                             Utility.Util.GetValueOfDateTime(ibs.GetDateAcct()), ibs.GetDescription(), ibs.GetAD_Org_ID(), 0, 0); //Used Zero's as parameters to Avoid throw Error

            if (payment == null)
            {
                throw new SystemException("Could not create Payment");
            }

            ibs.SetC_Payment_ID(payment.GetC_Payment_ID());
            ibs.SetC_Currency_ID(payment.GetC_Currency_ID());
            ibs.SetTrxAmt(payment.GetPayAmt());
            ibs.Save();
            //
            String retString = "@C_Payment_ID@ = " + payment.GetDocumentNo();

            if (Env.Signum(payment.GetOverUnderAmt()) != 0)
            {
                retString += " - @OverUnderAmt@=" + payment.GetOverUnderAmt();
            }
            return(retString);
        }
Example #30
0
        /// <summary>
        /// Online Payment from Server
        /// @ejb.interface-method view-type="both"
        /// Called from MPayment processOnline
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_Payment_ID"></param>
        /// <param name="C_PaymentProcessor_ID"></param>
        /// <param name="trxName"></param>
        /// <returns>true if approvedc</returns>
        public bool PaymentOnline(Ctx ctx, int C_Payment_ID, int C_PaymentProcessor_ID, Trx trxName)
        {
            MPayment          payment = new MPayment(ctx, C_Payment_ID, trxName);
            MPaymentProcessor mpp     = new MPaymentProcessor(ctx, C_PaymentProcessor_ID, null);

            log.Info("[" + _no + "] " + payment + " - " + mpp);
            _paymentCount++;
            bool approved = false;

            try
            {
                PaymentProcessor pp = PaymentProcessor.Create(mpp, payment);
                if (pp == null)
                {
                    payment.SetErrorMessage("No Payment Processor");
                }
                else
                {
                    approved = pp.ProcessCC();
                    if (approved)
                    {
                        payment.SetErrorMessage(null);
                    }
                    else
                    {
                        payment.SetErrorMessage("From " + payment.GetCreditCardName()
                                                + ": " + payment.GetR_RespMsg());
                    }
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "", e);
                payment.SetErrorMessage("Payment Processor Error");
            }
            payment.Save();
            return(approved);
        }