示例#1
0
        /**
         *  After Save
         *	@param newRecord
         *	@param success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            if (!UpdateCbAndLine())
            {
                return(false);
            }

            if (GetVSS_PAYMENTTYPE() == X_C_CashLine.VSS_PAYMENTTYPE_Payment && GetC_BPartner_ID() > 0)
            {
                MCash   csh = new MCash(GetCtx(), GetC_Cash_ID(), Get_TrxName());
                Decimal amt = MConversionRate.ConvertBase(GetCtx(), GetAmount(),        //	CM adjusted
                                                          GetC_Currency_ID(), csh.GetDateAcct(), 0, GetAD_Client_ID(), GetAD_Org_ID());

                MBPartner bp     = new MBPartner(GetCtx(), GetC_BPartner_ID(), Get_Trx());
                string    retMsg = "";
                bool      crdAll = bp.IsCreditAllowed(GetC_BPartner_Location_ID(), Decimal.Subtract(0, amt), out retMsg);
                if (!crdAll)
                {
                    log.SaveWarning("Warning", retMsg);
                }
                else if (bp.IsCreditWatch(GetC_BPartner_Location_ID()))
                {
                    log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "VIS_BPCreditWatch"));
                }
            }

            return(true);
        }
示例#2
0
        private bool UpdateCbAndLine()
        {
            // Update Cash Journal
            if (!UpdateHeader())
            {
                log.Warning("Cannot update cash journal.");
                return(false);
            }

            // Update Cashbook and CashbookLine
            MCash     parent   = GetParent();
            MCashBook cashbook = new MCashBook(GetCtx(), parent.GetC_CashBook_ID(), Get_TrxName());

            if (cashbook.GetCompletedBalance() == 0)
            {
                cashbook.SetCompletedBalance(parent.GetBeginningBalance());
            }
            cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt));
            //if (cashbook.GetRunningBalance() == 0)
            //{
            //    cashbook.SetRunningBalance
            //        (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt),cashbook.GetCompletedBalance()));
            //}
            //else
            //{
            //    cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt));
            //}

            if (!cashbook.Save())
            {
                log.Warning("Cannot update running balance.");
                return(false);
            }

            DataTable dtCashbookLine;
            int       C_CASHBOOKLINE_ID = 0;

            string sql = "SELECT C_CASHBOOKLINE_ID FROM C_CASHBOOKLINE WHERE C_CASHBOOK_ID="
                         + cashbook.GetC_CashBook_ID() + " AND DATEACCT="
                         + DB.TO_DATE(parent.GetDateAcct()) + " AND AD_ORG_ID=" + GetAD_Org_ID();

            dtCashbookLine = DB.ExecuteDataset(sql, null, null).Tables[0];

            if (dtCashbookLine.Rows.Count > 0)
            {
                C_CASHBOOKLINE_ID = Util.GetValueOfInt(dtCashbookLine.Rows[0]
                                                       .ItemArray[0]);
            }

            MCashbookLine cashbookLine = new MCashbookLine(GetCtx(), C_CASHBOOKLINE_ID, Get_TrxName());

            if (C_CASHBOOKLINE_ID == 0)
            {
                cashbookLine.SetC_CashBook_ID(cashbook.GetC_CashBook_ID());
                // SI_0419 : Update org/client as on cash line
                cashbookLine.SetAD_Org_ID(GetAD_Org_ID());
                cashbookLine.SetAD_Client_ID(GetAD_Client_ID());
                cashbookLine.SetEndingBalance
                    (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt), cashbook.GetCompletedBalance()));
            }
            else
            {
                cashbookLine.SetEndingBalance(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt));
            }
            cashbookLine.SetDateAcct(parent.GetDateAcct());
            cashbookLine.SetStatementDifference(Decimal.Add(Decimal.Subtract(cashbookLine.GetStatementDifference(), old_sdAmt), new_sdAmt));


            if (!cashbookLine.Save())
            {
                log.Warning("Cannot create/update cashbook line.");
                return(false);
            }

            return(true);
        }