Esempio n. 1
0
        }       //	invalidateIt

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

            //	Std Period open? - AP (Reimbursement) Invoice
            if (!MPeriod.IsOpen(GetCtx(), GetDateReport(), VAdvantage.Model.MDocBaseType.DOCBASETYPE_APINVOICE))
            {
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateReport(), GetAD_Org_ID()))
            {
                m_processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }


            MTimeExpenseLine[] lines = GetLines(false);
            if (lines.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Add up Amounts
            Decimal amt = Env.ZERO;

            for (int i = 0; i < lines.Length; i++)
            {
                MTimeExpenseLine line = lines[i];
                //amt = amt.add(line.GetApprovalAmt());
                amt = Decimal.Add(amt, line.GetApprovalAmt());// amt.add(line.GetApprovalAmt());
            }
            SetApprovalAmt(amt);

            //	Invoiced but no BP
            for (int i = 0; i < lines.Length; i++)
            {
                MTimeExpenseLine line = lines[i];
                if (line.IsInvoiced() && line.GetC_BPartner_ID() == 0)
                {
                    m_processMsg = "@Line@ " + line.GetLine() + ": Invoiced, but no Business Partner";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }

            m_justPrepared = true;
            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// Reverse Allocation.
        /// Period needs to be open
        /// </summary>
        /// <returns>true if reversed</returns>
        private bool ReverseIt()
        {
            if (!IsActive())
            {
                throw new Exception("Allocation already reversed (not active)");
            }

            //	Can we delete posting
            if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_PAYMENTALLOCATION))
            {
                throw new Exception("@PeriodClosed@");
            }
            // is Non Business Day?
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateTrx()))
            {
                throw new Exception(Common.Common.NONBUSINESSDAY);
            }

            //	Set Inactive
            SetIsActive(false);
            SetDocumentNo(GetDocumentNo() + "^");
            SetDocStatus(DOCSTATUS_Reversed);   //	for direct calls
            if (!Save() || IsActive())
            {
                throw new Exception("Cannot de-activate allocation");
            }

            //	Delete Posting
            String sql = "DELETE FROM Fact_Acct WHERE AD_Table_ID=" + MAllocationHdr.Table_ID
                         + " AND Record_ID=" + GetC_AllocationHdr_ID();
            int no = DataBase.DB.ExecuteQuery(sql, null, Get_TrxName());

            log.Fine("Fact_Acct deleted #" + no);

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

            for (int i = 0; i < _lines.Length; i++)
            {
                MAllocationLine line = _lines[i];
                line.SetIsActive(false);
                line.Save();
                bps.Add(line.ProcessIt(true));  //	reverse
            }
            UpdateBP(bps);
            return(true);
        }
Esempio n. 4
0
        public String PrepareIt()
        {
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

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

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

            return(DocActionVariables.STATUS_INPROGRESS);
        }
Esempio n. 5
0
        public string PrepareIt()
        {
            log.Info(ToString());
            _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            //SetIsReturnTrx(dt.IsReturnTrx());
            //SetIsSOTrx(dt.IsSOTrx());

            //	Std Period open?
            if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType()))
            {
                _processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

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


            //	Lines
            MProfitLossLines[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                _processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            ////	Convert DocType to Target
            //if (GetC_DocType_ID() != GetC_DocTypeTarget_ID())
            //{
            //    //	Cannot change Std to anything else if different warehouses
            //    if (GetC_DocType_ID() != 0)
            //    {
            //        MDocType dtOld = MDocType.Get(GetCtx(), GetC_DocType_ID());
            //        if (MDocType.DOCSUBTYPESO_StandardOrder.Equals(dtOld.GetDocSubTypeSO())		//	From SO
            //            && !MDocType.DOCSUBTYPESO_StandardOrder.Equals(dt.GetDocSubTypeSO()))	//	To !SO
            //        {
            //            for (int i = 0; i < lines.Length; i++)
            //            {
            //                if (lines[i].GetM_Warehouse_ID() != GetM_Warehouse_ID())
            //                {
            //                    log.Warning("different Warehouse " + lines[i]);
            //                    _processMsg = "@CannotChangeDocType@";
            //                    return DocActionVariables.STATUS_INVALID;
            //                }
            //            }
            //        }
            //    }

            //    //	New or in Progress/Invalid
            //    if (DOCSTATUS_Drafted.Equals(GetDocStatus())
            //        || DOCSTATUS_InProgress.Equals(GetDocStatus())
            //        || DOCSTATUS_Invalid.Equals(GetDocStatus())
            //        || GetC_DocType_ID() == 0)
            //    {
            //        SetC_DocType_ID(GetC_DocTypeTarget_ID());
            //    }
            //    else	//	convert only if offer
            //    {
            //        if (dt.IsOffer())
            //            SetC_DocType_ID(GetC_DocTypeTarget_ID());
            //        else
            //        {
            //            _processMsg = "@CannotChangeDocType@";
            //            return DocActionVariables.STATUS_INVALID;
            //        }
            //    }
            //}	//	convert DocType

            //	Mandatory Product Attribute Set Instance
            //String mandatoryType = "='Y'";	//	IN ('Y','S')
            //String sql = "SELECT COUNT(*) "
            //    + "FROM C_OrderLine ol"
            //    + " INNER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)"
            //    + " INNER JOIN M_AttributeSet pas ON (p.M_AttributeSet_ID=pas.M_AttributeSet_ID) "
            //    + "WHERE pas.MandatoryType" + mandatoryType
            //    + " AND ol.M_AttributeSetInstance_ID IS NULL"
            //    + " AND ol.C_Order_ID=" + GetC_Order_ID();
            //int no = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
            //if (no != 0)
            //{
            //    _processMsg = "@LinesWithoutProductAttribute@ (" + no + ")";
            //    return DocActionVariables.STATUS_INVALID;
            //}

            ////	Lines
            //if (ExplodeBOM())
            //    lines = GetLines(true, "M_Product_ID");
            //if (!ReserveStock(dt, lines))
            //{
            //    _processMsg = "Cannot reserve Stock";
            //    return DocActionVariables.STATUS_INVALID;
            //}
            //if (!CalculateTaxTotal())
            //{
            //    _processMsg = "Error calculating tax";
            //    return DocActionVariables.STATUS_INVALID;
            //}

            ////	Credit Check
            //if (IsSOTrx() && !IsReturnTrx())
            //{
            //    MBPartner bp = MBPartner.Get(GetCtx(), GetC_BPartner_ID());
            //    if (MBPartner.SOCREDITSTATUS_CreditStop.Equals(bp.GetSOCreditStatus()))
            //    {
            //        _processMsg = "@BPartnerCreditStop@ - @TotalOpenBalance@="
            //            + bp.GetTotalOpenBalance()
            //            + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit();
            //        return DocActionVariables.STATUS_INVALID;
            //    }
            //    if (MBPartner.SOCREDITSTATUS_CreditHold.Equals(bp.GetSOCreditStatus()))
            //    {
            //        _processMsg = "@BPartnerCreditHold@ - @TotalOpenBalance@="
            //            + bp.GetTotalOpenBalance()
            //            + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit();
            //        return DocActionVariables.STATUS_INVALID;
            //    }
            //    Decimal grandTotal = MConversionRate.ConvertBase(GetCtx(),
            //        GetGrandTotal(), GetC_Currency_ID(), GetDateOrdered(),
            //        GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID());
            //    if (MBPartner.SOCREDITSTATUS_CreditHold.Equals(bp.GetSOCreditStatus(grandTotal)))
            //    {
            //        _processMsg = "@BPartnerOverOCreditHold@ - @TotalOpenBalance@="
            //            + bp.GetTotalOpenBalance() + ", @GrandTotal@=" + grandTotal
            //            + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit();
            //        return DocActionVariables.STATUS_INVALID;
            //    }
            //}

            _justPrepared = true;
            // dont uncomment
            //if (!DOCACTION_Complete.Equals(getDocAction()))		don't set for just prepare
            //		setDocAction(DOCACTION_Complete);
            return(DocActionVariables.STATUS_INPROGRESS);
        }
Esempio n. 6
0
        /// <summary>
        /// Void Document.
        /// </summary>
        /// <returns>false</returns>
        public bool VoidIt()
        {
            log.Info(ToString());
            if (DOCSTATUS_Closed.Equals(GetDocStatus()) ||
                DOCSTATUS_Reversed.Equals(GetDocStatus()) ||
                DOCSTATUS_Voided.Equals(GetDocStatus()))
            {
                m_processMsg = "Document Closed: " + GetDocStatus();
                SetDocAction(DOCACTION_None);
                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()))
            {
                ;
            }
            //	Std Period open?
            else
            {
                if (!MPeriod.IsOpen(GetCtx(), GetStatementDate(), MDocBaseType.DOCBASETYPE_BANKSTATEMENT, GetAD_Org_ID()))
                {
                    m_processMsg = "@PeriodClosed@";
                    return(false);
                }

                // is Non Business Day?
                // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
                if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetStatementDate(), GetAD_Org_ID()))
                {
                    m_processMsg = Common.Common.NONBUSINESSDAY;
                    return(false);
                }


                if (MFactAcct.Delete(Table_ID, GetC_BankStatement_ID(), Get_TrxName()) < 0)
                {
                    return(false);       //	could not delete
                }
            }

            //	Set lines to 0
            Decimal transactionAmt = 0; //To update transaction amount in unMatched Balance in case of void

            MBankStatementLine[] lines = GetLines(true);
            for (int i = 0; i < lines.Length; i++)
            {
                MBankStatementLine line = lines[i];
                transactionAmt += line.GetTrxAmt();
                if (line.GetStmtAmt().CompareTo(Env.ZERO) != 0)
                {
                    String description = Msg.Translate(GetCtx(), "Voided") + " ("
                                         + Msg.Translate(GetCtx(), "StmtAmt") + "=" + line.GetStmtAmt();
                    if (line.GetTrxAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "TrxAmt") + "=" + line.GetTrxAmt();
                    }
                    if (line.GetChargeAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "ChargeAmt") + "=" + line.GetChargeAmt();
                    }
                    if (line.GetInterestAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "InterestAmt") + "=" + line.GetInterestAmt();
                    }
                    description += ")";
                    line.AddDescription(description);
                    line.SetStmtAmt(Env.ZERO);
                    line.SetTrxAmt(Env.ZERO);
                    line.SetChargeAmt(Env.ZERO);
                    line.SetInterestAmt(Env.ZERO);
                    line.Save(Get_TrxName());
                    if (line.GetC_Payment_ID() != 0)
                    {
                        MPayment payment = new MPayment(GetCtx(), line.GetC_Payment_ID(), Get_TrxName());
                        payment.SetIsReconciled(false);
                        payment.Save(Get_TrxName());
                    }
                }
            }
            AddDescription(Msg.Translate(GetCtx(), "Voided"));
            Decimal voidedDifference = GetStatementDifference();

            SetStatementDifference(Env.ZERO);

            //VA009----------------------------------Anuj----------------------
            //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_'  AND IsActive = 'Y'"));
            if (Env.IsModuleInstalled("VA009_"))
            {
                MBankStatementLine[] STlines = GetLines(false);
                string status = "R"; // Received
                for (int i = 0; i < STlines.Length; i++)
                {
                    MBankStatementLine line = STlines[i];
                    if (line.GetC_Payment_ID() != 0)
                    {
                        MPayment payment        = new MPayment(GetCtx(), line.GetC_Payment_ID(), Get_TrxName());
                        string   _paymentMethod = Util.GetValueOfString(DB.ExecuteScalar("Select va009_paymentbaseType from va009_paymentmethod where va009_paymentmethod_id=" + payment.GetVA009_PaymentMethod_ID() + " And IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID()));
                        if (_paymentMethod == "S") // Check
                        {
                            status = "B";          // Bounced
                        }
                        else
                        {
                            status = "C"; // Rejected
                        }
                        payment.SetVA009_ExecutionStatus(status);
                        payment.Save(Get_TrxName());

                        //MInvoicePaySchedule inp = new MInvoicePaySchedule(GetCtx(), payment.GetC_InvoicePaySchedule_ID(), Get_TrxName());
                        //inp.SetVA009_ExecutionStatus(status);
                        //inp.Save(Get_TrxName());

                        // update execution status as set on Payment on Invoice Schedule -  for those payment which are completed or closed
                        if (payment.GetDocStatus() == DOCSTATUS_Closed || payment.GetDocStatus() == DOCSTATUS_Completed)
                        {
                            int no = Util.GetValueOfInt(DB.ExecuteQuery(@"UPDATE C_InvoicePaySchedule
                                                                          SET VA009_ExecutionStatus = '" + payment.GetVA009_ExecutionStatus() + @"'  
                                                                          WHERE C_Payment_ID = " + line.GetC_Payment_ID(), null, Get_Trx()));
                        }
                    }
                }
            }
            //END----------------------------------Anuj----------------------

            //	Update Bank Account
            MBankAccount ba = MBankAccount.Get(GetCtx(), GetC_BankAccount_ID());

            ba.SetCurrentBalance(Decimal.Subtract(ba.GetCurrentBalance(), voidedDifference));
            ba.SetUnMatchedBalance(Decimal.Add(ba.GetUnMatchedBalance(), transactionAmt));   //Arpit
            ba.Save(Get_TrxName());
            SetProcessed(true);
            SetDocAction(DOCACTION_None);
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Prepare Document
        /// </summary>
        /// <returns>new status (In Progress or Invalid) </returns>
        public String PrepareIt()
        {
            log.Info(ToString());
            m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (m_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Std Period open?
            if (!MPeriod.IsOpen(GetCtx(), GetStatementDate(), MDocBaseType.DOCBASETYPE_BANKSTATEMENT, GetAD_Org_ID()))
            {
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetStatementDate(), GetAD_Org_ID()))
            {
                m_processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }

            MBankStatementLine[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Lines
            Decimal  total   = Env.ZERO;
            DateTime?minDate = GetStatementDate();
            DateTime?maxDate = minDate;

            for (int i = 0; i < lines.Length; i++)
            {
                MBankStatementLine line = lines[i];
                total = Decimal.Add(total, line.GetStmtAmt());
                if (line.GetDateAcct() < (minDate))//before
                {
                    minDate = line.GetDateAcct();
                }
                if (line.GetDateAcct() > maxDate)//after
                {
                    maxDate = line.GetDateAcct();
                }
            }
            SetStatementDifference(total);
            SetEndingBalance(Decimal.Add(GetBeginningBalance(), total));
            if (!MPeriod.IsOpen(GetCtx(), minDate, MDocBaseType.DOCBASETYPE_BANKSTATEMENT, GetAD_Org_ID()) ||
                !MPeriod.IsOpen(GetCtx(), maxDate, MDocBaseType.DOCBASETYPE_BANKSTATEMENT, GetAD_Org_ID()))
            {
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetStatementDate(), GetAD_Org_ID()))
            {
                m_processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }


            m_justPrepared = true;
            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }
Esempio n. 8
0
        /**
         *	Prepare Document
         *  @return new status (In Progress or Invalid)
         */
        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_CASHJOURNAL))
            {
                _processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

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


            MCashLine[] lines = GetLines(false);
            if (lines.Length == 0)
            {
                _processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Add up Amounts
            Decimal difference    = Env.ZERO;
            int     C_Currency_ID = GetC_Currency_ID();

            for (int i = 0; i < lines.Length; i++)
            {
                MCashLine line = lines[i];
                if (!line.IsActive())
                {
                    continue;
                }
                if (C_Currency_ID == line.GetC_Currency_ID())
                {
                    difference = Decimal.Add(difference, line.GetAmount());
                }
                else
                {
                    Decimal amt = MConversionRate.Convert(GetCtx(), line.GetAmount(),
                                                          line.GetC_Currency_ID(), C_Currency_ID, GetDateAcct(), 0,
                                                          GetAD_Client_ID(), GetAD_Org_ID());
                    if (amt == null)
                    {
                        _processMsg = "No Conversion Rate found - @C_CashLine_ID@= " + line.GetLine();
                        return(DocActionVariables.STATUS_INVALID);
                    }
                    difference = Decimal.Add(difference, amt);
                }
            }
            SetStatementDifference(difference);
            //	setEndingBalance(getBeginningBalance().add(getStatementDifference()));
            //
            _justPrepared = true;
            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }
Esempio n. 9
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(), GetUpdated(), MDocBaseType.DOCBASETYPE_MATERIALMOVEMENT))
            {
                _processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetUpdated()))
            {
                _processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }


            MMovementLineConfirm[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                _processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //Boolean difference = false;
            //for (int i = 0; i < lines.Length; i++)
            //{
            //    if (!lines[i].IsFullyConfirmed())
            //    {
            //        difference = true;
            //        break;
            //    }
            //}
            Boolean difference = false;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].GetTargetQty() != (lines[i].GetConfirmedQty() + lines[i].GetDifferenceQty() + lines[i].GetScrappedQty()))
                {
                    difference = true;
                    break;
                }
            }
            //	SetIsInDispute(difference);
            if (difference)
            {
                _processMsg = "@M_MovementLineConfirm_ID@ <> @IsFullyConfirmed@";
                return(DocActionVariables.STATUS_INVALID);
            }

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

            if (valid != null)
            {
                _processMsg = valid;
                return(DocActionVariables.STATUS_INVALID);
            }

            //
            _justPrepared = true;
            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }
Esempio n. 10
0
        /**
         *	Prepare Document
         *  @return new status (In Progress or Invalid)
         */
        public String PrepareIt()
        {
            try
            {
                log.Info(ToString());
                _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
                if (_processMsg != null)
                {
                    return(DocActionVariables.STATUS_INVALID);
                }
                MRequisitionLine[] lines = GetLines();

                //	Invalid
                if (GetAD_User_ID() == 0 ||
                    GetM_PriceList_ID() == 0 ||
                    GetM_Warehouse_ID() == 0 ||
                    lines.Length == 0)
                {
                    return(DocActionVariables.STATUS_INVALID);
                }

                //	Std Period open?
                if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), MDocBaseType.DOCBASETYPE_PURCHASEREQUISITION))
                {
                    _processMsg = "@PeriodClosed@";
                    return(DocActionVariables.STATUS_INVALID);
                }

                // is Non Business Day?
                if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateDoc()))
                {
                    _processMsg = Common.Common.NONBUSINESSDAY;
                    return(DocActionVariables.STATUS_INVALID);
                }



                //	Add up Amounts
                int     precision  = MPriceList.GetStandardPrecision(GetCtx(), GetM_PriceList_ID());
                Decimal totalLines = Env.ZERO;
                for (int i = 0; i < lines.Length; i++)
                {
                    MRequisitionLine line    = lines[i];
                    Decimal          lineNet = Decimal.Multiply(line.GetQty(), line.GetPriceActual());
                    lineNet = Decimal.Round(lineNet, precision);//, MidpointRounding.AwayFromZero);
                    if (lineNet.CompareTo(line.GetLineNetAmt()) != 0)
                    {
                        line.SetLineNetAmt(lineNet);
                        line.Save();
                    }
                    totalLines = Decimal.Add(totalLines, line.GetLineNetAmt());
                }
                if (totalLines.CompareTo(GetTotalLines()) != 0)
                {
                    SetTotalLines(totalLines);
                    Save();
                }
                _justPrepared = true;
            }
            catch (Exception ex)
            {
                // MessageBox.Show("MRequisition--PrepareIt");
                log.Severe(ex.ToString());
            }
            return(DocActionVariables.STATUS_INPROGRESS);
        }
        }       //	invalidateIt

        /// <summary>
        /// Prepare Document
        /// </summary>
        /// <returns>new status (In Progress or Invalid) </returns>
        public String PrepareIt()
        {
            log.Info(ToString());
            m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (m_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            //	Std Period open?
            if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType()))
            {
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct(), GetAD_Org_ID()))
            {
                m_processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }

            // JID_0521 - Restrict if debit and credit amount is not equal.-Mohit-12-jun-2019.
            if (GetTotalCr() != GetTotalDr())
            {
                m_processMsg = Msg.GetMsg(GetCtx(), "DBAndCRAmtNotEqual");
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Add up Amounts & prepare them
            MJournal[] journals = GetJournals(false);
            if (journals.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            Decimal TotalDr = Env.ZERO;
            Decimal TotalCr = Env.ZERO;

            for (int i = 0; i < journals.Length; i++)
            {
                MJournal journal = journals[i];
                if (!journal.IsActive())
                {
                    continue;
                }
                //	Prepare if not closed
                if (DOCSTATUS_Closed.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Voided.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Reversed.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Completed.Equals(journal.GetDocStatus()))
                {
                    ;
                }
                else
                {
                    String status = journal.PrepareIt();
                    if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                    {
                        journal.SetDocStatus(status);
                        journal.Save();
                        m_processMsg = journal.GetProcessMsg();
                        return(status);
                    }
                    journal.SetDocStatus(DOCSTATUS_InProgress);
                    journal.Save();
                }
                //
                //TotalDr = TotalDr.add(journal.getTotalDr());
                TotalDr = Decimal.Add(TotalDr, journal.GetTotalDr());
                TotalCr = Decimal.Add(TotalCr, journal.GetTotalCr());
            }
            SetTotalDr(TotalDr);
            SetTotalCr(TotalCr);

            //	Control Amount
            if (Env.ZERO.CompareTo(GetControlAmt()) != 0 &&
                GetControlAmt().CompareTo(GetTotalDr()) != 0)
            {
                m_processMsg = "@ControlAmtError@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Add up Amounts
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
Esempio n. 12
0
        /// <summary>
        /// Void Document.
        /// </summary>
        /// <returns>false</returns>
        public bool VoidIt()
        {
            log.Info(ToString());
            if (DOCSTATUS_Closed.Equals(GetDocStatus()) ||
                DOCSTATUS_Reversed.Equals(GetDocStatus()) ||
                DOCSTATUS_Voided.Equals(GetDocStatus()))
            {
                m_processMsg = "Document Closed: " + GetDocStatus();
                SetDocAction(DOCACTION_None);
                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()))
            {
                ;
            }
            //	Std Period open?
            else
            {
                if (!MPeriod.IsOpen(GetCtx(), GetStatementDate(), MDocBaseType.DOCBASETYPE_BANKSTATEMENT))
                {
                    m_processMsg = "@PeriodClosed@";
                    return(false);
                }

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


                if (MFactAcct.Delete(Table_ID, GetC_BankStatement_ID(), Get_TrxName()) < 0)
                {
                    return(false);       //	could not delete
                }
            }

            //	Set lines to 0
            MBankStatementLine[] lines = GetLines(true);
            for (int i = 0; i < lines.Length; i++)
            {
                MBankStatementLine line = lines[i];
                if (line.GetStmtAmt().CompareTo(Env.ZERO) != 0)
                {
                    String description = Msg.Translate(GetCtx(), "Voided") + " ("
                                         + Msg.Translate(GetCtx(), "StmtAmt") + "=" + line.GetStmtAmt();
                    if (line.GetTrxAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "TrxAmt") + "=" + line.GetTrxAmt();
                    }
                    if (line.GetChargeAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "ChargeAmt") + "=" + line.GetChargeAmt();
                    }
                    if (line.GetInterestAmt().CompareTo(Env.ZERO) != 0)
                    {
                        description += ", " + Msg.Translate(GetCtx(), "InterestAmt") + "=" + line.GetInterestAmt();
                    }
                    description += ")";
                    line.AddDescription(description);
                    line.SetStmtAmt(Env.ZERO);
                    line.SetTrxAmt(Env.ZERO);
                    line.SetChargeAmt(Env.ZERO);
                    line.SetInterestAmt(Env.ZERO);
                    line.Save(Get_TrxName());
                    if (line.GetC_Payment_ID() != 0)
                    {
                        MPayment payment = new MPayment(GetCtx(), line.GetC_Payment_ID(), Get_TrxName());
                        payment.SetIsReconciled(false);
                        payment.Save(Get_TrxName());
                    }
                }
            }
            AddDescription(Msg.Translate(GetCtx(), "Voided"));
            Decimal voidedDifference = GetStatementDifference();

            SetStatementDifference(Env.ZERO);

            //	Update Bank Account
            MBankAccount ba = MBankAccount.Get(GetCtx(), GetC_BankAccount_ID());

            ba.SetCurrentBalance(Decimal.Subtract(ba.GetCurrentBalance(), voidedDifference));
            ba.Save(Get_TrxName());
            SetProcessed(true);
            SetDocAction(DOCACTION_None);
            return(true);
        }
Esempio n. 13
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);
        }