示例#1
0
        /// <summary>
        /// Prepare Document
        /// </summary>
        /// <returns>new status (In Progress or Invalid)</returns>
        public String PrepareIt()
        {
            log.Info(ToString());
            _processMsg = ModelValidationEngine.Get().FireDocValidate
                              (this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Std Period open?
            if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), MDocBaseType.DOCBASETYPE_PAYMENTALLOCATION))
            {
                _processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }
            // is Non Business Day?
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct()))
            {
                _processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }

            GetLines(false);
            if (_lines.Length == 0)
            {
                _processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Add up Amounts & validate
            Decimal approval = Env.ZERO;

            for (int i = 0; i < _lines.Length; i++)
            {
                MAllocationLine line = _lines[i];
                approval = Decimal.Add(Decimal.Add(approval, line.GetWriteOffAmt()), line.GetDiscountAmt());
                //	Make sure there is BP
                if (line.GetC_BPartner_ID() == 0)
                {
                    _processMsg = "No Business Partner";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }
            SetApprovalAmt(approval);
            //
            _justPrepared = true;
            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }
示例#2
0
        /// <summary>
        /// Before Delete
        /// </summary>
        /// <returns>true if acct was deleted</returns>
        protected override bool BeforeDelete()
        {
            Trx trxName = Get_Trx();

            if (trxName == null)
            {
                log.Warning("No transaction");
            }
            if (IsPosted())
            {
                if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_PAYMENTALLOCATION))
                {
                    log.Warning("Period Closed");
                    return(false);
                }
                //// is Non Business Day?
                //if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateTrx()))
                //{
                //    log.Warning("DateIsInNonBusinessDay");
                //    return false;
                //}

                SetPosted(false);
                if (MFactAcct.Delete(Table_ID, Get_ID(), trxName) < 0)
                {
                    return(false);
                }
            }
            //	Mark as Inactive
            SetIsActive(false);         //	updated DB for line delete/process
            String sql = "UPDATE C_AllocationHdr SET IsActive='N' WHERE C_AllocationHdr_ID=" + GetC_AllocationHdr_ID();

            DataBase.DB.ExecuteQuery(sql, null, trxName);

            //	Unlink
            GetLines(true);
            HashSet <int> bps = new HashSet <int>();

            for (int i = 0; i < _lines.Length; i++)
            {
                MAllocationLine line = _lines[i];
                bps.Add(line.GetC_BPartner_ID());
                if (!line.Delete(true, trxName))
                {
                    return(false);
                }
            }
            UpdateBP(bps);
            return(true);
        }