use of org.eevolution.model.MHRPaySelectionLine in project adempiere by adempiere.
the class HRPaySelectionCreateFrom method doIt.
// prepare
/**
* Perform process.
* @return Message
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("Pay Selection Id=" + getRecord_ID() + ", Process=" + getPayrollProcessId() + ", Payroll=" + getPayrollId() + ", BP Group=" + getBusinessPartnerGroupId() + ", PaymentRule=" + getPaymentRule() + ", Concept=" + getGlobalPayrollConceptId() + ", Depatment=" + getDepartmentId() + ", Job=" + getPayrollJobId());
MHRPaySelection paySelection = (MHRPaySelection) getInstance(get_TrxName());
paySelection.setHR_Process_ID(getPayrollProcessId());
paySelection.saveEx();
List<Object> parameters = new ArrayList<Object>();
if (getRecord_ID() == 0)
throw new IllegalArgumentException("@HR_PaySelection_ID@ @Notfound@");
if (paySelection.isProcessed())
throw new IllegalArgumentException("@HR_PaySelection_ID@ @Processed@");
parameters.add(getPayrollProcessId());
parameters.add(true);
parameters.add(getRecord_ID());
StringBuilder where = new StringBuilder();
where.append(MHRMovement.COLUMNNAME_HR_Process_ID).append("=?");
// Only Concept isPaid
where.append(" AND HR_Concept_ID IN(SELECT HR_Concept_ID FROM HR_Concept WHERE IsPaid=?)");
where.append(// Not Exist in PaySelection Process or PaySelection Actual
" AND HR_Movement_ID NOT IN(SELECT HR_Movement_ID " + " FROM HR_PaySelectionLine " + " WHERE HR_PaySelectionCheck_ID > 0 OR HR_PaySelection_ID=?)");
if (getBusinessPartnerGroupId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_C_BP_Group_ID).append("=?");
parameters.add(getBusinessPartnerGroupId());
}
if (getEmployeeTypeId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_EmployeeType_ID).append("=?");
parameters.add(getEmployeeTypeId());
}
if (getBusinessPartnerId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_C_BPartner_ID).append("=?");
parameters.add(getBusinessPartnerId());
}
if (getPaymentRule() != null) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_PaymentRule).append("=?");
parameters.add(getPaymentRule());
}
if (getGlobalPayrollConceptId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Concept_ID).append("=?");
parameters.add(getGlobalPayrollConceptId());
}
if (getDepartmentId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Department_ID).append("=?");
parameters.add(getDepartmentId());
}
if (getPayrollJobId() > 0) {
where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Job_ID).append("=?");
parameters.add(getPayrollJobId());
}
List<MHRMovement> movements = new Query(getCtx(), MHRMovement.Table_Name, where.toString(), get_TrxName()).setClient_ID().setParameters(parameters).list();
AtomicInteger lineNo = new AtomicInteger();
movements.stream().filter(movement -> movement != null).forEach(movement -> {
I_C_BPartner partner = movement.getC_BPartner();
Optional<MHREmployee> employeeOption = Optional.ofNullable(MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), movement.get_TrxName()));
String paymentRule = employeeOption.flatMap(employee -> Optional.ofNullable(employee.getPaymentRule())).orElse(Optional.ofNullable(partner.getPaymentRule()).orElse(MHREmployee.PAYMENTRULE_DirectDeposit));
lineNo.updateAndGet(count -> count + 10);
MHRPaySelectionLine paySelectionLine = new MHRPaySelectionLine(getCtx(), 0, get_TrxName());
paySelectionLine.setHR_PaySelection_ID(getRecord_ID());
paySelectionLine.setHR_Movement_ID(movement.getHR_Movement_ID());
paySelectionLine.setPaymentRule(paymentRule);
paySelectionLine.setAD_Org_ID(paySelection.getAD_Org_ID());
paySelectionLine.setLine(lineNo.get());
paySelectionLine.setOpenAmt(movement.getAmount().setScale(2, BigDecimal.ROUND_HALF_DOWN));
paySelectionLine.setPayAmt(movement.getAmount().setScale(2, BigDecimal.ROUND_HALF_DOWN));
paySelectionLine.setDescription(partner.getName() + " " + partner.getName2());
paySelectionLine.setDifferenceAmt(BigDecimal.ZERO.ZERO);
paySelectionLine.setDiscountAmt(BigDecimal.ZERO);
paySelectionLine.setIsManual(false);
paySelectionLine.setIsSOTrx(false);
paySelectionLine.setIsActive(true);
paySelectionLine.saveEx();
});
return "@HR_PaySelection_ID@ - #" + lineNo.get();
}
use of org.eevolution.model.MHRPaySelectionLine in project adempiere by adempiere.
the class HRGenericPaymentExport method exportToFile.
/**************************************************************************
* Export to File
* @param checks array of checks
* @param file file to export checks
* @return number of lines
*/
public int exportToFile(List<MHRPaySelectionCheck> checks, File file, StringBuffer err) {
if (checks == null || checks.size() == 0)
return 0;
// Must be a file
if (file.isDirectory()) {
err.append("No se puede escribir, el archivo seleccionado es un directorio - " + file.getAbsolutePath());
s_log.log(Level.SEVERE, err.toString());
return -1;
}
// delete if exists
try {
if (file.exists())
file.delete();
} catch (Exception e) {
s_log.log(Level.WARNING, "Could not delete - " + file.getAbsolutePath(), e);
}
// ease
char x = '"';
int noLines = 0;
StringBuffer line = null;
try {
FileWriter fw = new FileWriter(file);
// write header
line = new StringBuffer();
line.append(x).append("Value").append(x).append(",").append(x).append("Name").append(x).append(",").append(x).append("Contact").append(x).append(",").append(x).append("Addr1").append(x).append(",").append(x).append("Addr2").append(x).append(",").append(x).append("City").append(x).append(",").append(x).append("State").append(x).append(",").append(x).append("ZIP").append(x).append(",").append(x).append("Country").append(x).append(",").append(x).append("ReferenceNo").append(x).append(",").append(x).append("DocumentNo").append(x).append(",").append(x).append("PayDate").append(x).append(",").append(x).append("Currency").append(x).append(",").append(x).append("PayAmount").append(x).append(",").append(x).append("Comment").append(x).append(Env.NL);
fw.write(line.toString());
noLines++;
// write lines
for (MHRPaySelectionCheck mpp : checks) {
if (mpp == null)
continue;
// BPartner Info
String[] bp = getBPartnerInfo(mpp.getC_BPartner_ID());
// Comment - list of invoice document no
StringBuffer comment = new StringBuffer();
List<MHRPaySelectionLine> psls = mpp.getPaySelectionLines(false);
for (MHRPaySelectionLine psl : psls) {
comment.append(psl.getHR_Movement().getHR_Concept().getName());
}
line = new StringBuffer();
// Value
line.append(x).append(bp[BP_VALUE]).append(x).append(",").append(x).append(bp[BP_NAME]).append(x).append(// Name
",").append(x).append(bp[BP_CONTACT]).append(x).append(// Contact
",").append(x).append(bp[BP_ADDR1]).append(x).append(// Addr1
",").append(x).append(bp[BP_ADDR2]).append(x).append(// Addr2
",").append(x).append(bp[BP_CITY]).append(x).append(// City
",").append(x).append(bp[BP_REGION]).append(x).append(// State
",").append(x).append(bp[BP_POSTAL]).append(x).append(// ZIP
",").append(x).append(bp[BP_COUNTRY]).append(x).append(// Country
",").append(x).append(bp[BP_REFNO]).append(x).append(// ReferenceNo
",").append(x).append(mpp.getDocumentNo()).append(x).append(// DocumentNo
",").append(mpp.getParent().getPayDate()).append(// PayDate
",").append(x).append(MCurrency.getISO_Code(Env.getCtx(), mpp.getParent().getC_Currency_ID())).append(x).append(// Currency
",").append(mpp.getPayAmt()).append(// PayAmount
",").append(x).append(comment.toString()).append(// Comment
x).append(Env.NL);
fw.write(line.toString());
noLines++;
}
// write line
fw.flush();
fw.close();
} catch (Exception e) {
err.append(e.toString());
s_log.log(Level.SEVERE, "", e);
return -1;
}
return noLines;
}
use of org.eevolution.model.MHRPaySelectionLine in project adempiere by adempiere.
the class HRPaySelectionCreateCheck method createCheck.
// doIt
/**
* Create Check from line
*
* @param paySelectionLine
*/
private void createCheck(MHRPaySelectionLine paySelectionLine) {
paySelectionChecks.stream().filter(paySelectionCheck -> paySelectionCheck.getC_BPartner_ID() == paySelectionLine.getHR_Movement().getC_BPartner_ID()).forEach(paySelectionCheck -> {
paySelectionCheck.addLine(paySelectionLine);
paySelectionCheck.saveEx();
paySelectionLine.setHR_PaySelectionCheck_ID(paySelectionCheck.getHR_PaySelectionCheck_ID());
paySelectionLine.setProcessed(true);
paySelectionCheck.saveEx();
});
Optional<String> paymentRuleOptional = Optional.of(paySelectionLine.getPaymentRule());
MHRPaySelectionCheck paySelectionCheck = new MHRPaySelectionCheck(paySelectionLine, paymentRuleOptional.orElse(MHRPaySelectionCheck.PAYMENTRULE_DirectDeposit));
paySelectionCheck.setAD_Org_ID(paySelectionLine.getHR_PaySelection().getAD_Org_ID());
paySelectionCheck.saveEx();
paySelectionLine.setHR_PaySelectionCheck_ID(paySelectionCheck.getHR_PaySelectionCheck_ID());
paySelectionLine.setProcessed(true);
paySelectionLine.saveEx();
paySelectionChecks.add(paySelectionCheck);
}
Aggregations