Esempio n. 1
0
        /// <summary>
        /// Find first Year Period of DateAcct based on Client Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <returns>active first Period</returns>
        public static MPeriod GetFirstInYear(Ctx ctx, DateTime?dateAcct)
        {
            MPeriod retValue     = null;
            int     AD_Client_ID = ctx.GetAD_Client_ID();
            String  sql          = "SELECT * "
                                   + "FROM C_Period "
                                   + "WHERE C_Year_ID IN "
                                   + "(SELECT p.C_Year_ID "
                                   + "FROM AD_ClientInfo c"
                                   + " INNER JOIN C_Year y ON (c.C_Calendar_ID=y.C_Calendar_ID)"
                                   + " INNER JOIN C_Period p ON (y.C_Year_ID=p.C_Year_ID) "
                                   + "WHERE c.AD_Client_ID=@clientid"
                                   + "	AND @date BETWEEN StartDate AND EndDate)"
                                   + " AND IsActive='Y' AND PeriodType='S' "
                                   + "ORDER BY StartDate";

            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@clientid", AD_Client_ID);
                param[1] = new SqlParameter("@date", dateAcct);

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];  //	first only
                    retValue = new MPeriod(ctx, dr, null);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            return(retValue);
        }
        /// <summary>
        /// Set the document number from Completed Document Sequence after completed
        /// </summary>
        private void SetCompletedDocumentNo()
        {
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            // if Overwrite Date on Complete checkbox is true.
            if (dt.IsOverwriteDateOnComplete())
            {
                SetDateDoc(DateTime.Now.Date);

                //	Std Period open?
                if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), dt.GetDocBaseType()))
                {
                    throw new Exception("@PeriodClosed@");
                }
            }

            // if Overwrite Sequence on Complete checkbox is true.
            if (dt.IsOverwriteSeqOnComplete())
            {
                // Set Drafted Document No into Temp Document No.
                if (Get_ColumnIndex("TempDocumentNo") > 0)
                {
                    SetTempDocumentNo(GetDocumentNo());
                }

                // Get current next from Completed document sequence defined on Document type
                String value = MSequence.GetDocumentNo(GetC_DocType_ID(), Get_TrxName(), GetCtx(), true, this);
                if (value != null)
                {
                    SetDocumentNo(value);
                }
            }
        }
        /**
         *  Get the first Date From date based on Accumulation
         *	@param from date
         *	@return  first date
         */
        public DateTime?GetDateFrom(DateTime?from)
        {
            if (from == null)
            {
                return(from);
            }

            if (BALANCEACCUMULATION_CalendarMonth.Equals(GetBALANCEACCUMULATION()))
            {
                return(TimeUtil.Trunc(from, TimeUtil.TRUNC_MONTH));
            }
            else if (BALANCEACCUMULATION_CalendarWeek.Equals(GetBALANCEACCUMULATION()))
            {
                return(TimeUtil.Trunc(from, TimeUtil.TRUNC_WEEK));
            }
            else if (BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(GetBALANCEACCUMULATION()) &&
                     GetC_Calendar_ID() != 0)
            {
                MPeriod period = MPeriod.GetOfCalendar(GetCtx(), GetC_Calendar_ID(), from);
                if (period != null)
                {
                    return(period.GetStartDate());
                }
            }
            return(from);
        }
Esempio n. 4
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. 5
0
        /// <summary>
        /// Is standard Period Open for Document Base Type
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <param name="docBaseType">base type</param>
        /// <param name="AD_Org_ID">Optional Organization</param>
        /// <returns>true if open</returns>
        public static bool IsOpen(Ctx ctx, DateTime?dateAcct, String docBaseType, int AD_Org_ID)
        {
            if (dateAcct == null)
            {
                _log.Warning("No DateAcct");
                return(false);
            }
            if (docBaseType == null)
            {
                _log.Warning("No DocBaseType");
                return(false);
            }

            MPeriod period = MPeriod.Get(ctx, dateAcct, AD_Org_ID);

            if (period == null)
            {
                _log.Warning("No Period for " + dateAcct + " (" + docBaseType + ")");
                return(false);
            }
            bool open = (period.IsOpen(docBaseType, dateAcct, AD_Org_ID) == null);

            if (!open)
            {
                _log.Warning(period.GetName() + ": Not open for " + docBaseType + " (" + dateAcct + ")");
            }
            return(open);
        }
Esempio n. 6
0
        public static MPeriod[] GetAllPeriodsInRange(MPeriod startPeriod, MPeriod endPeriod, int calendar_ID, Ctx ctx, Trx trx)
        {
            if ((startPeriod.GetC_Calendar_ID() != calendar_ID) ||
                (endPeriod.GetC_Calendar_ID() != calendar_ID))
            {
                _log.SaveError("Error", "Periods do not belong to the calendar");
                return(null);
            }
            List <MPeriod> periods = new List <MPeriod>();
            String         sql     = "SELECT * FROM C_Period WHERE " +
                                     "C_Period.IsActive='Y' AND PeriodType='S' " +
                                     "AND C_Period.C_Year_ID IN " +
                                     "(SELECT C_Year_ID FROM C_Year WHERE C_Year.C_Calendar_ID = @param1 ) " + //calendar_ID
                                     "AND ((C_Period.C_Year_ID * 1000) + C_Period.PeriodNo) BETWEEN" +
                                     " (@param2 * 1000 + @param3) AND (@param4 * 1000 + @param5 )" +           //start Period year ID, Period Number , End Period Year ID, Period Number
                                     " ORDER BY C_Period.C_Year_ID ASC, C_Period.PeriodNo ASC";

            SqlParameter[] param = null;
            IDataReader    idr   = null;
            DataTable      dt    = new DataTable();

            try
            {
                param    = new SqlParameter[5];
                param[0] = new SqlParameter("@param1", calendar_ID);
                param[1] = new SqlParameter("@param2", startPeriod.GetC_Year_ID());
                param[2] = new SqlParameter("@param3", startPeriod.GetPeriodNo());
                param[3] = new SqlParameter("@param4", endPeriod.GetC_Year_ID());
                param[4] = new SqlParameter("@param5", endPeriod.GetPeriodNo());
                idr      = DB.ExecuteReader(sql, param, trx);
                dt.Load(idr);
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        periods.Add(new MPeriod(ctx, dt.Rows[i], trx));
                    }
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }

            MPeriod[] retValue = new MPeriod[periods.Count];
            retValue = periods.ToArray();
            return(retValue);
        }
Esempio n. 7
0
        /// <summary>
        /// Find first Year Period of DateAcct based on Organization Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <param name="AD_Org_ID">Organization</param>
        /// <returns>active first Period</returns>
        public static MPeriod GetFirstInYear(Ctx ctx, DateTime?dateAcct, int AD_Org_ID)
        {
            MPeriod retValue = null;

            // Get Calender ID
            string qry;
            int    AD_Client_ID = ctx.GetAD_Client_ID();
            int    Calender_ID  = 0;

            if (AD_Org_ID > 0)
            {
                MOrgInfo orgInfo = MOrgInfo.Get(ctx, AD_Org_ID, null);
                if (orgInfo.Get_ColumnIndex("C_Calendar_ID") >= 0)
                {
                    Calender_ID = orgInfo.GetC_Calendar_ID();
                }
            }

            if (Calender_ID == 0)
            {
                qry         = "SELECT C_Calendar_ID FROM AD_ClientInfo WHERE  IsActive = 'Y' AND AD_Client_ID=" + AD_Client_ID;
                Calender_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry.ToString()));
            }

            if (Calender_ID == 0)
            {
                return(null);
            }

            String sql = "SELECT * "
                         + "FROM C_Period "
                         + "WHERE C_Year_ID IN "
                         + "(SELECT C_Year_ID FROM C_Year WHERE IsActive = 'Y' AND C_Calendar_ID= @calendarID)"
                         + "	AND @date BETWEEN StartDate AND EndDate)"
                         + " AND IsActive='Y' AND PeriodType='S' "
                         + "ORDER BY StartDate";

            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@calendarID", Calender_ID);
                param[1] = new SqlParameter("@date", dateAcct);

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];  //	first only
                    retValue = new MPeriod(ctx, dr, null);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            return(retValue);
        }
        }       //	setClientOrg

        /// <summary>
        /// Get Period
        /// </summary>
        /// <returns>period or null</returns>
        public MPeriod GetPeriod()
        {
            int C_Period_ID = GetC_Period_ID();

            if (C_Period_ID != 0)
            {
                return(MPeriod.Get(GetCtx(), C_Period_ID));
            }
            return(null);
        }       //	getPeriod
Esempio n. 9
0
        /// <summary>
        /// Find valid standard Period of DateAcct based on Organization Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <param name="AD_Org_ID">organization</param>
        /// <returns>C_Period_ID or 0</returns>
        public static int GetC_Period_ID(Ctx ctx, DateTime?dateAcct, int AD_Org_ID)
        {
            MPeriod period = Get(ctx, dateAcct, AD_Org_ID);

            if (period == null)
            {
                return(0);
            }
            return(period.GetC_Period_ID());
        }
Esempio n. 10
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. 11
0
 /**
  *  Before Delete
  *	@return true if acct was deleted
  */
 protected override bool BeforeDelete()
 {
     if (IsPosted())
     {
         if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_MATCHINVOICE, GetAD_Org_ID()))
         {
             return(false);
         }
         SetPosted(false);
         return(MFactAcct.Delete(Table_ID, Get_ID(), Get_TrxName()) >= 0);
     }
     return(true);
 }
Esempio n. 12
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);
        }
Esempio n. 13
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. 14
0
        /// <summary>
        /// Get Period from Cache
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="C_Period_ID">id</param>
        /// <returns>MPeriod</returns>
        public static MPeriod Get(Ctx ctx, int C_Period_ID)
        {
            int     key      = C_Period_ID;
            MPeriod retValue = (MPeriod)cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            //
            retValue = new MPeriod(ctx, C_Period_ID, null);
            if (retValue.Get_ID() != 0)
            {
                cache.Add(key, retValue);
            }
            return(retValue);
        }
Esempio n. 15
0
        public static MPeriod GetNextPeriod(MPeriod period, Ctx ctx, Trx trx)
        {
            MPeriod newPeriod = null;
            String  sql       = "SELECT * FROM C_Period WHERE " +
                                "C_Period.IsActive='Y' AND PeriodType='S' " +
                                "AND C_Period.C_Year_ID IN " +
                                "(SELECT C_Year_ID FROM C_Year WHERE C_Year.C_Calendar_ID = @param1 ) " +
                                "AND ((C_Period.C_Year_ID * 1000) + C_Period.PeriodNo) " +
                                " > ((@param2 * 1000) + @param3) ORDER BY C_Period.C_Year_ID ASC, C_Period.PeriodNo ASC";

            IDataReader idr = null;

            SqlParameter[] param = null;
            DataTable      dt    = new DataTable();

            try
            {
                param    = new SqlParameter[3];
                param[0] = new SqlParameter("@param1", period.GetC_Calendar_ID());
                param[1] = new SqlParameter("@param2", period.GetC_Year_ID());
                param[2] = new SqlParameter("@param3", period.GetPeriodNo());
                idr      = DB.ExecuteReader(sql, param, null);
                dt.Load(idr);
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                if (dt.Rows.Count > 0)
                {
                    newPeriod = new MPeriod(ctx, dt.Rows[0], trx);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            return(newPeriod);
        }
        }       //	setDateAcct

        /// <summary>
        /// Set Period
        /// </summary>
        /// <param name="C_Period_ID">period</param>
        public new void SetC_Period_ID(int C_Period_ID)
        {
            base.SetC_Period_ID(C_Period_ID);
            if (C_Period_ID == 0)
            {
                return;
            }
            DateTime?dateAcct = GetDateAcct();
            //
            MPeriod period = GetPeriod();

            if (period != null && period.IsStandardPeriod())
            {
                if (!period.IsInPeriod(dateAcct))
                {
                    base.SetDateAcct(period.GetEndDate());
                }
            }
        }       //	setC_Period_ID
Esempio n. 17
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);
        }
        }       //	setC_Period_ID

        /// <summary>
        /// Set Accounting Date.Set also Period if not set earlier
        /// </summary>
        /// <param name="DateAcct">date</param>
        public void SetDateAcct(DateTime DateAcct)
        {
            //super.setDateAcct(DateAcct);
            base.SetDateAcct(DateAcct);
            if (GetC_Period_ID() != 0)  //	previously set
            {
                SetRate();
                return;
            }
            int C_Period_ID = MPeriod.GetC_Period_ID(GetCtx(), DateAcct);

            if (C_Period_ID == 0)
            {
                log.Warning("Period not found");
            }
            else
            {
                base.SetC_Period_ID(C_Period_ID);
                SetRate();
            }
        }       //	setDateAcct
        }       //	setC_Period_ID

        /// <summary>
        /// Set Accounting Date.Set also Period if not set earlier
        /// </summary>
        /// <param name="DateAcct">date</param>
        public new void SetDateAcct(DateTime?DateAcct)
        {
            //super.setDateAcct(DateAcct);
            base.SetDateAcct(DateAcct);
            if (DateAcct == null)
            {
                return;
            }
            if (GetC_Period_ID() != 0)
            {
                return;
            }
            int C_Period_ID = MPeriod.GetC_Period_ID(GetCtx(), DateAcct);

            if (C_Period_ID == 0)
            {
                log.Warning("Period not found");
            }
            else
            {
                base.SetC_Period_ID(C_Period_ID);
            }
        }       //	setDateAcct
Esempio n. 20
0
        /// <summary>
        /// Check trascation record for non business day
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_Calendar_ID"></param>
        /// <param name="dt"></param>
        /// <returns>true for nonbusinessday</returns>
        public static bool IsNonBusinessDay(Ctx ctx, DateTime?dt)
        {
            bool   nbDay         = false;
            int    C_Period_ID   = MPeriod.GetC_Period_ID(ctx, dt);
            string sql           = "SELECT C_CALENDAR_ID FROM C_YEAR WHERE C_YEAR_ID=(SELECT C_YEAR_ID FROM C_PERIOD  WHERE C_PERIOD_ID=" + C_Period_ID + ")";
            int    C_Calendar_ID = Convert.ToInt32(DataBase.DB.ExecuteScalar(sql, null, null));

            sql = MRole.GetDefault(ctx, false).AddAccessSQL(
                "SELECT count(*) FROM C_NONBUSINESSDAY WHERE C_CALENDAR_ID=" + C_Calendar_ID + " AND DATE1=TO_DATE('" + dt.Value.ToShortDateString() + "', 'MM-DD-YY')",
                "C_NonBusinessDay", false, false);
            try
            {
                int count = Convert.ToInt32(DataBase.DB.ExecuteScalar(sql, null, null));
                if (count > 0)
                {
                    nbDay = true;
                }
            }
            catch (Exception e)
            {
            }
            return(nbDay);
        }
        /// <summary>
        /// Check trascation record for non business day organization wise
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="dt">date</param>
        /// <param name="AD_Org_ID">optional organization</param>
        /// <returns>true for nonbusinessday</returns>
        public static bool IsNonBusinessDay(Ctx ctx, DateTime?dt, int AD_Org_ID = 0)
        {
            bool   nbDay         = false;
            int    C_Period_ID   = MPeriod.GetC_Period_ID(ctx, dt, AD_Org_ID);
            string sql           = "SELECT C_CALENDAR_ID FROM C_YEAR WHERE C_YEAR_ID=(SELECT C_YEAR_ID FROM C_PERIOD  WHERE C_PERIOD_ID=" + C_Period_ID + ")";
            int    C_Calendar_ID = Convert.ToInt32(DataBase.DB.ExecuteScalar(sql, null, null));

            sql = MRole.GetDefault(ctx, false).AddAccessSQL(
                "SELECT count(*) FROM C_NONBUSINESSDAY WHERE ISACTIVE = 'Y' AND C_CALENDAR_ID=" + C_Calendar_ID
                + (AD_Org_ID > 0 ? " AND AD_Org_ID IN (0, " + AD_Org_ID + ")" : "") + " AND DATE1=TO_DATE('" + dt.Value.ToShortDateString() + "', 'MM-DD-YY')",
                "C_NonBusinessDay", false, false);  // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            try
            {
                int count = Convert.ToInt32(DataBase.DB.ExecuteScalar(sql, null, null));
                if (count > 0)
                {
                    nbDay = true;
                }
            }
            catch (Exception e)
            {
            }
            return(nbDay);
        }
Esempio n. 22
0
        /// <summary>
        /// Before Delete
        /// </summary>
        /// <returns>true if acct was deleted</returns>
        protected override bool BeforeDelete()
        {
            if (IsPosted())
            {
                if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_MATCHPO))
                {
                    return(false);
                }
                SetPosted(false);
                return(true);// MFactAcct.Delete(Table_ID, Get_ID(), Get_Trx()) >= 0;
            }

            //JID_0162: System should allow to delete the Matched PO of PO and MR with complete status only.
            if (GetC_OrderLine_ID() != 0)
            {
                MOrderLine line = new MOrderLine(GetCtx(), GetC_OrderLine_ID(), Get_TrxName());
                MOrder     ord  = new MOrder(GetCtx(), line.GetC_Order_ID(), Get_TrxName());
                if (ord.GetDocStatus() != DocumentEngine.ACTION_COMPLETE)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "Order/ShipmentNotCompleted"));
                    return(false);
                }
            }

            if (GetM_InOutLine_ID() != 0)
            {
                MInOutLine line = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_TrxName());
                MInOut     ino  = new MInOut(GetCtx(), line.GetM_InOut_ID(), Get_TrxName());
                if (ino.GetDocStatus() != DocumentEngine.ACTION_COMPLETE)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "Order/ShipmentNotCompleted"));
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 23
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);
        }
        }       //	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());

            //	Get Period
            MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct());

            if (period == null)
            {
                log.Warning("No Period for " + GetDateAcct());
                m_processMsg = "@PeriodNotFound@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Standard Period
            if (period.GetC_Period_ID() != GetC_Period_ID() &&
                period.IsStandardPeriod())
            {
                m_processMsg = "@PeriodNotValid@";
                return(DocActionVariables.STATUS_INVALID);
            }
            Boolean open = period.IsOpen(dt.GetDocBaseType());

            if (!open)
            {
                log.Warning(period.GetName()
                            + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")");
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

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

            //Manish 18/7/2016 .. Because if line dimention (Amount) column sum is not equals to debit or credit value complete process will not done.
            int     journalDRAndCR = 0;
            string  getlinevalues  = "SELECT NVL(ElementType,null) AS ElementType,AmtSourceDr,AmtAcctCr,AmtSourceCr,GL_JournalLine_ID FROM GL_JournalLine where GL_Journal_ID=" + Get_Value("GL_Journal_ID");
            DataSet dts            = DB.ExecuteDataset(getlinevalues, null, null);

            if (dts != null && dts.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
                {
                    journalDRAndCR = 0;

                    if (dts.Tables[0].Rows[i]["ElementType"].ToString() == "")
                    {
                        continue;
                    }

                    if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]) > 0)
                    {
                        journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]);
                    }
                    else
                    {
                        if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]) > 0)
                        {
                            journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]);
                        }
                    }

                    string getlineval = "SELECT SUM(amount) FROM gl_linedimension where GL_JournalLine_ID=" + Convert.ToInt32(dts.Tables[0].Rows[i]["GL_JournalLine_ID"]);
                    int    count      = Util.GetValueOfInt(DB.ExecuteScalar(getlineval));

                    if (journalDRAndCR != count)
                    {
                        m_processMsg = "@AmountNotMatch@";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }



            //	Add up Amounts
            Decimal AmtSourceDr = Env.ZERO;
            Decimal AmtSourceCr = Env.ZERO;

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];
                if (!IsActive())
                {
                    continue;
                }
                //
                if (line.IsDocControlled())
                {
                    m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine()
                                   + " - " + line.GetAccountElementValue();
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtAcctDr());
                AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtAcctCr());
            }
            SetTotalDr(AmtSourceDr);
            SetTotalCr(AmtSourceCr);

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

            //	Unbalanced Jornal & Not Suspense
            if (AmtSourceDr.CompareTo(AmtSourceCr) != 0)
            {
                MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID());
                if (gl == null || !gl.IsUseSuspenseBalancing())
                {
                    m_processMsg = "@UnbalancedJornal@";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }

            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
Esempio n. 25
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. 26
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. 27
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);
        }
        /// <summary>
        /// Create 12 Periods On the basis of User's Choice If User select March-15 then it creates (March-15 to Feb-16).
        /// Creates also Period Control from DocType.
        /// See DocumentTypeVerify#createPeriodControls(Ctx, int, SvrProcess, String)
        /// </summary>
        /// <param name="Month_ID">Month_ID</param>
        /// <returns>true if created</returns>
        //public Boolean CreateStdPeriods(string Month_ID)
        #region Create Custom Periods
        public Boolean CreateCustomPeriods(string Month_ID)
        {
            if (Month_ID == null)
            {
                return(false);
            }

            Int32 Mnth_ID = Convert.ToInt32(Month_ID);
            Int32 count   = 1;

            String[] months = null;
            try
            {
                months = DateTimeFormatInfo.CurrentInfo.MonthNames;

                //DateFormatSymbols symbols = new DateFormatSymbols(locale);
                //months = symbols.getShortMonths();
            }
            catch (Exception e)
            {
                months = new String[] { "Jan", "Feb", "Nar",
                                        "Apr", "May", "Jun",
                                        "Jul", "Aug", "Sep",
                                        "Oct", "Nov", "Dec" };
            }
            //
            int year = GetYearAsInt();

            //CultureInfo info = Thread.CurrentThread.CurrentCulture;
            //System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.Localized);
            //
            for (int month = Mnth_ID; month < 13; month++)
            {
                DateTime start = new DateTime(year, month, 1).Date;
                String   name  = months[month - 1] + "-" + GetYY();
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year, month, 1)).Day;
                DateTime end = new DateTime(year, month, day).Date;
                //

                MPeriod period = new MPeriod(this, count, name, start, end);
                if (!period.Save(Get_TrxName())) // Creates Period Control
                {
                    return(false);
                }
                count++;
            }
            for (int month = 1; month < Mnth_ID; month++)
            {
                DateTime start    = new DateTime(year + 1, month, 1).Date;
                string   yearname = Convert.ToString(Convert.ToInt32(GetYY()) + 1);
                String   name     = months[month - 1] + "-" + yearname;
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year + 1, month, 1)).Day;
                DateTime end = new DateTime(year + 1, month, day).Date;
                //
                MPeriod period = new MPeriod(this, count, name, start, end);
                if (!period.Save(Get_TrxName())) // Creates Period Control
                {
                    return(false);
                }
                count++;
            }
            return(true);
        }
        /// <summary>
        /// Create 12 Standard (Jan-Dec) Periods.
        /// Creates also Period Control from DocType.
        /// See DocumentTypeVerify#createPeriodControls(Ctx, int, SvrProcess, String)
        /// </summary>
        /// <param name="locale">locale</param>
        /// <returns>true if created</returns>
        //public Boolean CreateStdPeriods(Locale locale)
        public Boolean CreateStdPeriods(CultureInfo locale)
        {
            if (locale == null)
            {
                //MClient client = MClient.Get(GetCtx());
                //locale = client.getLocale();

                locale = Thread.CurrentThread.CurrentCulture;
            }

            //if (locale == null && Language.getLoginLanguage() != null)
            //    locale = Language.getLoginLanguage().getLocale();
            //if (locale == null)
            //    locale = Env.getLanguage(GetCtx()).getLocale();
            //
            String[] months = null;
            try
            {
                months = DateTimeFormatInfo.CurrentInfo.MonthNames;

                //DateFormatSymbols symbols = new DateFormatSymbols(locale);
                //months = symbols.getShortMonths();
            }
            catch
            {
                months = new String[] { "Jan", "Feb", "Nar",
                                        "Apr", "May", "Jun",
                                        "Jul", "Aug", "Sep",
                                        "Oct", "Nov", "Dec" };
            }
            //
            int year = GetYearAsInt();

            //CultureInfo info = Thread.CurrentThread.CurrentCulture;
            //System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.Localized);
            //
            for (int month = 1; month < 13; month++)
            {
                DateTime start = new DateTime(year, month, 1).Date;
                String   name  = months[month - 1] + "-" + GetYY();
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year, month, 1)).Day;
                DateTime end = new DateTime(year, month, day).Date;
                //
                MPeriod period = new MPeriod(this, month, name, start, end);
                if (!period.Save(Get_TrxName()))        //	Creates Period Control
                {
                    return(false);
                }
            }

            //GregorianCalendar cal = new GregorianCalendar(locale);
            //cal.set(Calendar.HOUR_OF_DAY, 0);
            //cal.set(Calendar.MINUTE, 0);
            //cal.set(Calendar.SECOND, 0);
            //cal.set(Calendar.MILLISECOND, 0);
            ////
            //for (int month = 0; month < 12; month++)
            //{
            //    cal.set(Calendar.YEAR, year);
            //    cal.set(Calendar.MONTH, month);
            //    cal.set(Calendar.DAY_OF_MONTH, 1);
            //    DateTime start = new Timestamp(cal.getTimeInMillis());
            //    String name = months[month] + "-" + getYY();
            //    //
            //    cal.add(Calendar.MONTH, 1);
            //    cal.add(Calendar.DAY_OF_YEAR, -1);
            //    Timestamp end = new Timestamp(cal.getTimeInMillis());
            //    //
            //    MPeriod period = new MPeriod(this, month + 1, name, start, end);
            //    if (!period.Save(Get_TrxName()))	//	Creates Period Control
            //        return false;
            //}
            return(true);
        }
Esempio n. 30
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="period">parent</param>
 /// <param name="docBaseType">doc base type</param>
 public MPeriodControl(MPeriod period, String docBaseType)
     : this(period.GetCtx(), period.GetAD_Client_ID(), period.GetC_Period_ID(), docBaseType,
            period.Get_TrxName())
 {
 }