use of org.compiere.model.MPeriod in project adempiere by adempiere.
the class A_Depreciation_Exp_Check method fixDepreciationExp.
private void fixDepreciationExp(MDepreciationExp exp, Timestamp dateAcctNew) {
if (!exp.getDateAcct().equals(dateAcctNew)) {
addLog("OLD1: " + exp);
MDepreciationEntry.deleteFacts(exp);
exp.setDateAcct(dateAcctNew);
exp.setA_Depreciation_Entry_ID(0);
exp.saveEx();
addLog("NEW1: " + exp);
}
// Check DateAcct and A_Depreciation_Entry.C_Period_ID relation:
if (exp.getA_Depreciation_Entry_ID() > 0) {
int C_Period_ID = DB.getSQLValueEx(exp.get_TrxName(), "SELECT C_Period_ID FROM A_Depreciation_Entry WHERE A_Depreciation_Entry_ID=?", exp.getA_Depreciation_Entry_ID());
MPeriod period = MPeriod.get(exp.getCtx(), C_Period_ID);
if (!period.isInPeriod(exp.getDateAcct())) {
addLog("OLD2: " + exp);
MDepreciationEntry.deleteFacts(exp);
exp.setA_Depreciation_Entry_ID(0);
exp.saveEx();
addLog("NEW2: " + exp);
}
}
}
use of org.compiere.model.MPeriod in project adempiere by adempiere.
the class MHRProcess method createMovements.
/**
* create Movements for corresponding process , period
*/
private void createMovements() throws Exception {
scriptCtx.clear();
//
logger.info("info data - " + Msg.parseTranslation(getCtx(), "@HR_Process_ID@ ") + getHR_Process_ID() + Msg.parseTranslation(getCtx(), ", @HR_Period_ID@ :") + getHR_Period_ID() + Msg.parseTranslation(getCtx(), ", @HR_Payroll_ID@ : ") + getHR_Payroll_ID() + Msg.parseTranslation(getCtx(), ", @HR_Department_ID@ : ") + getHR_Department_ID());
MHRPeriod payrollPeriod;
if (getHR_Period_ID() > 0) {
payrollPeriod = MHRPeriod.get(getCtx(), getHR_Period_ID());
} else {
payrollPeriod = new MHRPeriod(getCtx(), 0, null);
MPeriod period = MPeriod.get(getCtx(), getDateAcct(), getAD_Org_ID());
if (period != null) {
payrollPeriod.setStartDate(period.getStartDate());
payrollPeriod.setEndDate(period.getEndDate());
} else {
payrollPeriod.setStartDate(getDateAcct());
payrollPeriod.setEndDate(getDateAcct());
}
}
dateFrom = payrollPeriod.getStartDate();
dateTo = payrollPeriod.getEndDate();
MHRPayroll payroll = MHRPayroll.getById(getCtx(), getHR_Payroll_ID());
// Put variables
scriptCtx.put("process", this);
scriptCtx.put("_Process", getHR_Process_ID());
scriptCtx.put("_Period", getHR_Period_ID());
scriptCtx.put("_Payroll", getHR_Payroll_ID());
scriptCtx.put("_Department", getHR_Department_ID());
scriptCtx.put("_From", dateFrom);
scriptCtx.put("_To", dateTo);
scriptCtx.put("_Period", payrollPeriod.getPeriodNo());
scriptCtx.put("_HR_Payroll_Value", payroll.getValue());
//
if (getHR_Payroll_ID() > 0)
payrollId = getHR_Payroll_ID();
if (getHR_Department_ID() > 0)
departmentId = getHR_Department_ID();
if (getHR_Job_ID() > 0)
jobId = getHR_Job_ID();
payrollConcepts = MHRPayrollConcept.getPayrollConcepts(this);
Arrays.stream(MHREmployee.getEmployees(this)).forEach(employee -> calculateMovements(employee, payrollPeriod));
// Save period & finish
if (getHR_Period_ID() > 0) {
payrollPeriod.setProcessed(true);
payrollPeriod.saveEx();
}
}
use of org.compiere.model.MPeriod in project adempiere by adempiere.
the class Doc_BankStatement method loadLines.
// loadDocumentDetails
/**
* Load Invoice Line.
* @param bs bank statement
* 4 amounts
* AMTTYPE_Payment
* AMTTYPE_Statement2
* AMTTYPE_Charge
* AMTTYPE_Interest
* @return DocLine Array
*/
private DocLine[] loadLines(MBankStatement bs) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MBankStatementLine[] lines = bs.getLines(false);
for (int i = 0; i < lines.length; i++) {
MBankStatementLine line = lines[i];
DocLine_Bank docLine = new DocLine_Bank(line, this);
// Set Date Acct
if (i == 0)
setDateAcct(line.getDateAcct());
MPeriod period = MPeriod.get(getCtx(), line.getDateAcct(), line.getAD_Org_ID());
if (period != null && period.isOpen(DOCTYPE_BankStatement, line.getDateAcct()))
docLine.setC_Period_ID(period.getC_Period_ID());
//
list.add(docLine);
}
// Return Array
DocLine[] dls = new DocLine[list.size()];
list.toArray(dls);
return dls;
}
use of org.compiere.model.MPeriod in project adempiere by adempiere.
the class TrialBalance method createBalanceLine.
// doIt
/**
* Create Beginning Balance Line
*/
private void createBalanceLine() {
StringBuffer sql = new StringBuffer(s_insert);
// (AD_PInstance_ID, Fact_Acct_ID,
sql.append("SELECT ").append(getAD_PInstance_ID()).append(",0,");
// AD_Client_ID, AD_Org_ID, Created,CreatedBy, Updated,UpdatedBy,
sql.append(getAD_Client_ID()).append(",");
if (p_AD_Org_ID == 0)
sql.append("0");
else
sql.append(p_AD_Org_ID);
sql.append(", SysDate,").append(getAD_User_ID()).append(",SysDate,").append(getAD_User_ID()).append(",");
// C_AcctSchema_ID, Account_ID, AccountValue, DateTrx, DateAcct, C_Period_ID,
sql.append(p_C_AcctSchema_ID).append(",");
if (p_Account_ID == 0)
sql.append("null");
else
sql.append(p_Account_ID);
if (p_AccountValue_From != null)
sql.append(",").append(DB.TO_STRING(p_AccountValue_From));
else if (p_AccountValue_To != null)
sql.append(",' '");
else
sql.append(",null");
// TimeUtil.addDays(p_DateAcct_From, -1);
Timestamp balanceDay = p_DateAcct_From;
sql.append(",null,").append(DB.TO_DATE(balanceDay, true)).append(",");
if (p_C_Period_ID == 0)
sql.append("null");
else
sql.append(p_C_Period_ID);
sql.append(",");
// AD_Table_ID, Record_ID, Line_ID,
sql.append("null,null,null,");
// GL_Category_ID, GL_Budget_ID, C_Tax_ID, M_Locator_ID, PostingType,
sql.append("null,null,null,null,'").append(p_PostingType).append("',");
// C_Currency_ID, AmtSourceDr, AmtSourceCr, AmtSourceBalance,
sql.append("null,null,null,null,");
// AmtAcctDr, AmtAcctCr, AmtAcctBalance, C_UOM_ID, Qty,
sql.append(" COALESCE(SUM(AmtAcctDr),0),COALESCE(SUM(AmtAcctCr),0)," + "COALESCE(SUM(AmtAcctDr),0)-COALESCE(SUM(AmtAcctCr),0)," + " null,COALESCE(SUM(Qty),0),");
// M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID,C_LocTo_ID,
if (p_M_Product_ID == 0)
sql.append("null");
else
sql.append(p_M_Product_ID);
sql.append(",");
if (p_C_BPartner_ID == 0)
sql.append("null");
else
sql.append(p_C_BPartner_ID);
sql.append(",");
if (p_AD_OrgTrx_ID == 0)
sql.append("null");
else
sql.append(p_AD_OrgTrx_ID);
sql.append(",");
if (p_C_LocFrom_ID == 0)
sql.append("null");
else
sql.append(p_C_LocFrom_ID);
sql.append(",");
if (p_C_LocTo_ID == 0)
sql.append("null");
else
sql.append(p_C_LocTo_ID);
sql.append(",");
// C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID,
if (p_C_SalesRegion_ID == 0)
sql.append("null");
else
sql.append(p_C_SalesRegion_ID);
sql.append(",");
if (p_C_Project_ID == 0)
sql.append("null");
else
sql.append(p_C_Project_ID);
sql.append(",");
if (p_C_Campaign_ID == 0)
sql.append("null");
else
sql.append(p_C_Campaign_ID);
sql.append(",");
if (p_C_Activity_ID == 0)
sql.append("null");
else
sql.append(p_C_Activity_ID);
sql.append(",");
// User1_ID, User2_ID, A_Asset_ID, Description)
if (p_User1_ID == 0)
sql.append("null");
else
sql.append(p_User1_ID);
sql.append(",");
if (p_User2_ID == 0)
sql.append("null");
else
sql.append(p_User2_ID);
sql.append(",");
// User3_ID, User4_ID, A_Asset_ID, Description)
if (p_User3_ID == 0)
sql.append("null");
else
sql.append(p_User3_ID);
sql.append(",");
if (p_User4_ID == 0)
sql.append("null");
else
sql.append(p_User4_ID);
sql.append(", null,null");
//
sql.append(" FROM Fact_Acct WHERE AD_Client_ID=").append(getAD_Client_ID()).append(" AND ").append(m_parameterWhere).append(" AND DateAcct < ").append(DB.TO_DATE(p_DateAcct_From, true));
// Start Beginning of Year
if (p_Account_ID > 0) {
m_acct = new MElementValue(getCtx(), p_Account_ID, get_TrxName());
if (!m_acct.isBalanceSheet()) {
MPeriod first = MPeriod.getFirstInYear(getCtx(), p_DateAcct_From, p_AD_Org_ID);
if (first != null)
sql.append(" AND DateAcct >= ").append(DB.TO_DATE(first.getStartDate(), true));
else
log.log(Level.SEVERE, "first period not found");
}
}
//
int no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no == 0)
log.fine(sql.toString());
log.fine("#" + no + " (Account_ID=" + p_Account_ID + ")");
}
use of org.compiere.model.MPeriod in project adempiere by adempiere.
the class FinStatement method createBalanceLine.
// doIt
/**
* Create Beginning Balance Line
*/
private void createBalanceLine() {
StringBuffer sb = new StringBuffer("INSERT INTO T_ReportStatement " + "(AD_PInstance_ID, Fact_Acct_ID, LevelNo," + "DateAcct, Name, Description," + "AmtAcctDr, AmtAcctCr, Balance, Qty) ");
sb.append("SELECT ").append(getAD_PInstance_ID()).append(",0,0,").append(DB.TO_DATE(p_DateAcct_From, true)).append(",").append(DB.TO_STRING(Msg.getMsg(Env.getCtx(), "BeginningBalance"))).append(",NULL," + "COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(AmtAcctDr-AmtAcctCr),0), COALESCE(SUM(Qty),0) " + "FROM Fact_Acct " + "WHERE ").append(m_parameterWhere).append(" AND TRUNC(DateAcct, 'DD') < ").append(DB.TO_DATE(p_DateAcct_From));
// Start Beginning of Year
if (p_Account_ID > 0) {
m_acct = new MElementValue(getCtx(), p_Account_ID, get_TrxName());
if (!m_acct.isBalanceSheet()) {
MPeriod first = MPeriod.getFirstInYear(getCtx(), p_DateAcct_From, p_AD_Org_ID);
if (first != null)
sb.append(" AND TRUNC(DateAcct, 'DD') >= ").append(DB.TO_DATE(first.getStartDate()));
else
log.log(Level.SEVERE, "First period not found");
}
}
//
int no = DB.executeUpdate(sb.toString(), get_TrxName());
log.fine("#" + no + " (Account_ID=" + p_Account_ID + ")");
log.finest(sb.toString());
}
Aggregations