示例#1
0
        }   //  getAccount

        /**
         *  Get MCharge from Cache
         *	@param ctx context
         *	@param C_Charge_ID id
         *	@return MCharge
         */
        public static MCharge Get(Ctx ctx, int C_Charge_ID)
        {
            int     key      = C_Charge_ID;
            MCharge retValue = _cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MCharge(ctx, C_Charge_ID, null);
            if (retValue.Get_ID() != 0)
            {
                _cache.Add(key, retValue);
            }
            return(retValue);
        }       //	get
示例#2
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            string Sql   = "";
            int    count = 0;

            if (GetC_Invoice_ID() > 0)
            {
                if (newRecord)
                {
                    Sql = "SELECT COUNT(*) FROM c_paymentallocate WHERE IsActive='Y' AND C_Payment_ID=" + GetC_Payment_ID() + @"
                            AND C_Invoice_ID=" + GetC_Invoice_ID() + " AND C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " ";
                }
                else
                {
                    Sql = "SELECT COUNT(*) FROM c_paymentallocate WHERE IsActive='Y' AND C_Payment_ID=" + GetC_Payment_ID() + @"
                            AND C_Invoice_ID=" + GetC_Invoice_ID() + " AND C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " AND c_paymentallocate_ID!=" + GetC_PaymentAllocate_ID() + "";
                }
                count = Util.GetValueOfInt(DB.ExecuteScalar(Sql));
                if (count > 0)
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "INT13_SchedAlrdySel"), "");
                    return(false);
                }

                Sql   = @"SELECT COUNT(*) 
                            FROM c_paymentallocate payall 
                            INNER JOIN C_Charge chg 
                            ON (payall.c_charge_ID =chg.C_Charge_ID)
                            WHERE payall.INT13_AllocateType='C'
                            AND payall.isactive            ='Y'
                            AND payall.C_Payment_ID        =" + GetC_Payment_ID() + @"
                            AND chg.isadvancecharge        ='Y'";
                count = Util.GetValueOfInt(DB.ExecuteScalar(Sql));
                if (count > 0)
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoInvAdvCharge"), "");
                    return(false);
                }
            }
            else if (GetC_Charge_ID() > 0)
            {
                MCharge charge = new MCharge(GetCtx(), GetC_Charge_ID(), null);
                if (charge.IsAdvanceCharge())
                {
                    if (newRecord)
                    {
                        Sql = @"SELECT COUNT(*) 
                            FROM c_paymentallocate payall 
                            INNER JOIN C_Charge chg 
                            ON (payall.c_charge_ID =chg.C_Charge_ID)
                            WHERE payall.INT13_AllocateType='C'
                            AND payall.isactive            ='Y'
                            AND payall.C_Payment_ID        =" + GetC_Payment_ID() + @"
                            AND chg.isadvancecharge        ='N' ";
                    }
                    else
                    {
                        Sql = @"SELECT COUNT(*) 
                            FROM c_paymentallocate payall 
                            INNER JOIN C_Charge chg 
                            ON (payall.c_charge_ID =chg.C_Charge_ID)
                            WHERE payall.INT13_AllocateType='C'
                            AND payall.isactive            ='Y'
                            AND payall.C_Payment_ID        =" + GetC_Payment_ID() + @"
                            AND chg.isadvancecharge        ='N' AND payall.c_paymentallocate_ID!= " + GetC_PaymentAllocate_ID();
                    }


                    count = Util.GetValueOfInt(DB.ExecuteScalar(Sql));
                    if (count > 0)
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoAdvChgOnCharge"), "");
                        return(false);
                    }

                    Sql   = "SELECT COUNT(*) FROM C_PaymentAllocate  WHERE IsActive='Y' AND INT13_AllocateType='I' AND C_Payment_ID=" + GetC_Payment_ID();
                    count = Util.GetValueOfInt(DB.ExecuteScalar(Sql));
                    if (count > 0)
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoAdvChgOnInv"), "");
                        return(false);
                    }
                }
                else
                {
                    if (newRecord)
                    {
                        Sql = @"SELECT COUNT(*) 
                            FROM c_paymentallocate payall 
                            INNER JOIN C_Charge chg 
                            ON (payall.c_charge_ID =chg.C_Charge_ID)
                            WHERE payall.INT13_AllocateType='C'
                            AND payall.isactive            ='Y'
                            AND payall.C_Payment_ID        =" + GetC_Payment_ID() + @"
                            AND chg.isadvancecharge        ='Y' ";
                    }
                    else
                    {
                        Sql = @"SELECT COUNT(*) 
                            FROM c_paymentallocate payall 
                            INNER JOIN C_Charge chg 
                            ON (payall.c_charge_ID =chg.C_Charge_ID)
                            WHERE payall.INT13_AllocateType='C'
                            AND payall.isactive            ='Y'
                            AND payall.C_Payment_ID        =" + GetC_Payment_ID() + @"
                            AND chg.isadvancecharge        ='Y' AND payall.c_paymentallocate_ID != " + GetC_PaymentAllocate_ID();
                    }
                    count = Util.GetValueOfInt(DB.ExecuteScalar(Sql));
                    if (count > 0)
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoChgLnAdvChg"), "");
                        return(false);
                    }
                }
            }


            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);
            }

            if (GetC_Invoice_ID() > 0 && GetC_InvoicePaySchedule_ID() > 0)
            {
                string allocatesql = "Select Count(PA.C_Payment_ID) From C_PaymentAllocate PA Inner Join C_Payment Pay on Pay.C_Payment_ID=PA.C_Payment_ID Where PA.C_Invoice_ID=" + GetC_Invoice_ID() + " And "
                                     + "PA.C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " And pay.Docstatus IN ('DR','IP')";
                int countPaymentAllocate = Util.GetValueOfInt(DB.ExecuteScalar(allocatesql));
                if (countPaymentAllocate > 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "INT15_PaymentAllocateExist"));
                    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)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord"));
                    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);
        }