Ejemplo n.º 1
0
        public virtual bool VoidIt()
        {
            log.Info(ToString());

            if (DOCSTATUS_Closed.Equals(GetDocStatus()) ||
                DOCSTATUS_Reversed.Equals(GetDocStatus()) ||
                DOCSTATUS_Voided.Equals(GetDocStatus()))
            {
                _processMsg = "Document Closed: " + GetDocStatus();
                return(false);
            }

            //	Not Processed
            if (DOCSTATUS_Drafted.Equals(GetDocStatus()) ||
                DOCSTATUS_Invalid.Equals(GetDocStatus()) ||
                DOCSTATUS_InProgress.Equals(GetDocStatus()) ||
                DOCSTATUS_Approved.Equals(GetDocStatus()) ||
                DOCSTATUS_NotApproved.Equals(GetDocStatus()))
            {
                //	Set lines to 0
                MCostAllocationLine[] lines = GetLines(false);
                for (int i = 0; i < lines.Length; i++)
                {
                    MCostAllocationLine line = lines[i];
                    Decimal             old  = line.GetAmount();
                    if (old != 0)
                    {
                        line.SetAmount(Env.ZERO);
                        line.Save(Get_TrxName());
                    }
                }
            }
            else
            {
                return(ReverseCorrectIt());
            }

            SetIsProcessed(true);
            SetDocAction(DOCACTION_None);
            return(true);
        }
Ejemplo n.º 2
0
        public bool ReverseCorrectIt()
        {
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType()))
            {
                _processMsg = "@PeriodClosed@";
                return(false);
            }

            // is Non Business Day?
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct()))
            {
                _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY;
                return(false);
            }

            //set delievered = true
            //int no = Util.GetValueOfInt(DB.ExecuteScalar("UPDATE VA024_t_ObsoleteInventory SET VA024_ISDELIVERED = 'Y' , VA024_REMAININGQTY=0 WHERE VA024_ObsoleteInventory_ID = " + GetVA024_ObsoleteInventory_ID(), null, Get_Trx()));

            // Create Reversal Line
            MCostAllocation reversal = new MCostAllocation(GetCtx(), 0, Get_Trx());

            CopyValues(this, reversal);
            reversal.SetClientOrg(this);
            //
            reversal.SetDocumentNo(GetDocumentNo() + REVERSE_INDICATOR);
            reversal.SetDocStatus(DOCSTATUS_Drafted);
            reversal.SetDocAction(DOCACTION_Complete);
            //
            reversal.SetIsProcessed(false);
            reversal.SetPosted(false);
            //reversal.SetProcessing(false);
            reversal.SetDescription(GetDescription());
            reversal.AddDescription("{->" + GetDocumentNo() + ")");
            reversal.SetAllocationAmt(Decimal.Negate(GetAllocationAmt()));
            reversal.Save(Get_Trx());

            // Copy lines
            MCostAllocationLine reversalLine = null;

            MCostAllocationLine[] lines = GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MCostAllocationLine line = lines[i];
                reversalLine = new MCostAllocationLine(GetCtx(), 0, Get_Trx());
                CopyValues(line, reversalLine);
                reversalLine.SetClientOrg(this);
                reversalLine.SetM_CostAllocation_ID(reversal.GetM_CostAllocation_ID());
                reversalLine.SetIsProcessed(true);
                reversalLine.SetAmount(Decimal.Negate(line.GetAmount()));
                reversalLine.Save(Get_Trx());
            }

            reversal.CloseIt();
            _processMsg = reversal.GetDocumentNo();
            reversal.SetIsProcessed(true);
            reversal.SetDocStatus(DOCSTATUS_Reversed);
            reversal.SetDocAction(DOCACTION_None);
            reversal.Save(Get_Trx());

            this.AddDescription("(" + GetDocumentNo() + "<-)");
            SetDocAction(DOCACTION_None);
            SetDocStatus(DOCSTATUS_Reversed);
            Save(Get_Trx());
            return(true);
        }