/** * Parent Cosntructor * @param cashbook parent */ public MCashbookLine(MCashBook cashbook) : this(cashbook.GetCtx(), 0, cashbook.Get_TrxName()) { SetClientOrg(cashbook); SetC_CashBook_ID(cashbook.GetC_CashBook_ID()); _parent = cashbook; }
/** * Get CashBook for Org and Currency * @param ctx context * @param AD_Org_ID org * @param C_Currency_ID currency * @return cash book or null */ public static MCashBook Get(Ctx ctx, int AD_Org_ID, int C_Currency_ID) { // Try from cache //Iterator it = _cache.values().iterator(); IEnumerator it = _cache.Values.GetEnumerator(); while (it.MoveNext()) { MCashBook cb = (MCashBook)it.Current; if (cb.GetAD_Org_ID() == AD_Org_ID && cb.GetC_Currency_ID() == C_Currency_ID) { return(cb); } } // Get from DB //SI_0648_1 : if there are multiple "defaults / no default" with in same org and currency, system will create object of highest ID. MCashBook retValue = null; String sql = "SELECT * FROM C_CashBook " + " WHERE AD_Org_ID=" + AD_Org_ID + " AND C_Currency_ID=" + C_Currency_ID + " ORDER BY IsDefault DESC, C_CashBook_id DESC"; DataTable dt = null; IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, null); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { retValue = new MCashBook(ctx, dr, null); int key = retValue.GetC_CashBook_ID(); _cache.Add(key, retValue); break; } } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, "get", e); } finally { dt = null; } return(retValue); }
/** * Parent Constructor * @param cb cash book * @param today date - if null today */ public MCash(MCashBook cb, DateTime?today) : this(cb.GetCtx(), 0, cb.Get_TrxName()) { SetClientOrg(cb); SetC_CashBook_ID(cb.GetC_CashBook_ID()); if (today != null) { SetStatementDate(today); SetDateAcct(today); //String name = DisplayType.getDateFormat(DisplayType.Date).format(today) + " " + cb.GetName(); String name = String.Format("{0:d}", today) + " " + cb.GetName(); SetName(name); } _book = cb; }
private bool UpdateCbAndLine() { // Update Cash Journal if (!UpdateHeader()) { log.Warning("Cannot update cash journal."); return(false); } // Update Cashbook and CashbookLine MCash parent = GetParent(); MCashBook cashbook = new MCashBook(GetCtx(), parent.GetC_CashBook_ID(), Get_TrxName()); if (cashbook.GetCompletedBalance() == 0) { cashbook.SetCompletedBalance(parent.GetBeginningBalance()); } cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt)); //if (cashbook.GetRunningBalance() == 0) //{ // cashbook.SetRunningBalance // (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt),cashbook.GetCompletedBalance())); //} //else //{ // cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt)); //} if (!cashbook.Save()) { log.Warning("Cannot update running balance."); return(false); } DataTable dtCashbookLine; int C_CASHBOOKLINE_ID = 0; string sql = "SELECT C_CASHBOOKLINE_ID FROM C_CASHBOOKLINE WHERE C_CASHBOOK_ID=" + cashbook.GetC_CashBook_ID() + " AND DATEACCT=" + DB.TO_DATE(parent.GetDateAcct()) + " AND AD_ORG_ID=" + GetAD_Org_ID(); dtCashbookLine = DB.ExecuteDataset(sql, null, null).Tables[0]; if (dtCashbookLine.Rows.Count > 0) { C_CASHBOOKLINE_ID = Util.GetValueOfInt(dtCashbookLine.Rows[0] .ItemArray[0]); } MCashbookLine cashbookLine = new MCashbookLine(GetCtx(), C_CASHBOOKLINE_ID, Get_TrxName()); if (C_CASHBOOKLINE_ID == 0) { cashbookLine.SetC_CashBook_ID(cashbook.GetC_CashBook_ID()); // SI_0419 : Update org/client as on cash line cashbookLine.SetAD_Org_ID(GetAD_Org_ID()); cashbookLine.SetAD_Client_ID(GetAD_Client_ID()); cashbookLine.SetEndingBalance (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt), cashbook.GetCompletedBalance())); } else { cashbookLine.SetEndingBalance(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt)); } cashbookLine.SetDateAcct(parent.GetDateAcct()); cashbookLine.SetStatementDifference(Decimal.Add(Decimal.Subtract(cashbookLine.GetStatementDifference(), old_sdAmt), new_sdAmt)); if (!cashbookLine.Save()) { log.Warning("Cannot create/update cashbook line."); return(false); } return(true); }