protected override bool BeforeSave(bool newRecord) { MJournalLine obj = new MJournalLine(GetCtx(), GetGL_JournalLine_ID(), Get_Trx()); // In Case of reversal, bypass this condition if (!(obj.Get_ColumnIndex("ReversalDoc_ID") > 0 && obj.GetReversalDoc_ID() > 0)) { string val = ""; if (obj.GetAmtSourceDr() > 0) { val = " AmtSourceDr "; } else { val = " AmtSourceCr "; } string sql = "SELECT SUM(amount) FROM Gl_Linedimension WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID") + " AND Gl_Linedimension_ID NOT IN( " + GetGL_LineDimension_ID() + ")"; Decimal count = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); count += GetAmount(); sql = "SELECT " + val + " FROM GL_JournalLine WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID"); Decimal amtcount = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); if (count > amtcount) { log.SaveWarning("AmoutCheck", ""); return(false); } } return(true); }
protected override bool BeforeSave(bool newRecord) { MJournalLine obj = new MJournalLine(GetCtx(), GetGL_JournalLine_ID(), Get_Trx()); string val = ""; if (obj.GetAmtSourceDr() > 0) { val = " AmtSourceDr "; } else { val = " AmtSourceCr "; } string sql = "SELECT SUM(amount) FROM Gl_Linedimension WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID") + " AND Gl_Linedimension_ID NOT IN( " + GetGL_LineDimension_ID() + ")"; int count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); count += GetAmount(); string sqlQry = "SELECT " + val + " FROM GL_JournalLine WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID"); int amtcount = Util.GetValueOfInt(DB.ExecuteScalar(sqlQry, null, Get_Trx())); if (count > amtcount) { log.SaveWarning("AmoutCheck", ""); return(false); } return(true); }
} // 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); } // 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.GetAmtSourceDr()); AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtSourceCr()); } 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