Пример #1
0
        /**
         *  Get Cash Journal for CashBook and date
         *	@param ctx context
         *	@param C_CashBook_ID cashbook
         *	@param dateAcct date
         *	@param trxName transaction
         *	@return cash
         */
        public static MCash Get(Ctx ctx, int C_CashBook_ID, DateTime?dateAcct, Trx trxName)
        {
            MCash retValue = null;
            //	Existing Journal
            String sql = "SELECT * FROM C_Cash c "
                         + "WHERE c.C_CashBook_ID=" + C_CashBook_ID             //	#1
                         + " AND TRUNC(c.StatementDate,'DD')=@sdate"            //	#2
                         + " AND c.Processed='N'";
            DataTable dt = null;

            SqlParameter[] param = null;
            IDataReader    idr   = null;

            try
            {
                param    = new SqlParameter[1];
                param[0] = new SqlParameter("@sdate", TimeUtil.GetDay(dateAcct));
                idr      = DB.ExecuteReader(sql, param, trxName);
                dt       = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MCash(ctx, dr, trxName);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            if (retValue != null)
            {
                return(retValue);
            }

            //	Get CashBook
            MCashBook cb = new MCashBook(ctx, C_CashBook_ID, trxName);

            if (cb.Get_ID() == 0)
            {
                _log.Warning("Not found C_CashBook_ID=" + C_CashBook_ID);
                return(null);
            }

            //	Create New Journal
            retValue = new MCash(cb, dateAcct);
            retValue.Save(trxName);
            return(retValue);
        }
Пример #2
0
        /**
         *  Get MCashBook from Cache
         *	@param ctx context
         *	@param C_CashBook_ID id
         *	@return MCashBook
         */
        public static MCashBook Get(Ctx ctx, int C_CashBook_ID)
        {
            int       key      = C_CashBook_ID;
            MCashBook retValue = (MCashBook)_cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MCashBook(ctx, C_CashBook_ID, null);
            if (retValue.Get_ID() != 0)
            {
                _cache.Add(key, retValue);
            }
            return(retValue);
        }