Search in sources :

Example 1 with MHREmployee

use of org.eevolution.model.MHREmployee in project adempiere by adempiere.

the class HRCreateInvoice method doIt.

//	prepare
/**
     * Process
     * @return message
     * @throws Exception
     */
protected String doIt() throws Exception {
    MHRProcess process = new MHRProcess(getCtx(), getPayrollProcessId(), get_TrxName());
    final Timestamp dateInvoice = getDateInvoiced() != null ? getDateInvoiced() : process.getHR_Period_ID() > 0 ? process.getHR_Period().getStartDate() : process.getDateAcct();
    Arrays.stream(getEmployeeIds(process)).filter(partnerId -> partnerId > 0).forEach(partnerId -> {
        Trx.run(trxName -> {
            int lastPartnerId = 0;
            MHREmployee employee = null;
            MInvoice invoice = null;
            for (MHRMovement movement : getPayrollMovement(getPayrollProcessId(), partnerId, trxName)) {
                MBPartner partner = new MBPartner(getCtx(), partnerId, trxName);
                MHRAttribute attribute = MHRAttribute.getByConceptIdAndPartnerId(movement.getCtx(), movement.getHR_Concept_ID(), movement.getC_BPartner_ID(), movement.getValidFrom(), trxName);
                if (attribute != null && attribute.getC_DocType_ID() == 0) {
                    log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
                    addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
                    continue;
                }
                if (attribute != null && attribute.getC_Charge_ID() == 0) {
                    log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
                    addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
                    continue;
                }
                if (movement.getC_BPartner_ID() != lastPartnerId) {
                    lastPartnerId = movement.getC_BPartner_ID();
                    employee = MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), trxName);
                    invoice = createInvoice(process, partner, employee, attribute.getC_DocType_ID(), dateInvoice);
                    if (invoice == null)
                        continue;
                }
                if (invoice != null)
                    createInvoiceLine(invoice, employee, movement, attribute.getC_Charge_ID());
            }
        });
    });
    return "@OK@";
}
Also used : Arrays(java.util.Arrays) MHREmployee(org.eevolution.model.MHREmployee) MHRAttribute(org.eevolution.model.MHRAttribute) Timestamp(java.sql.Timestamp) Env(org.compiere.util.Env) MPaymentTerm(org.compiere.model.MPaymentTerm) MBPartnerLocation(org.compiere.model.MBPartnerLocation) Level(java.util.logging.Level) MInvoice(org.compiere.model.MInvoice) MHRProcess(org.eevolution.model.MHRProcess) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) MHRMovement(org.eevolution.model.MHRMovement) MBPartner(org.compiere.model.MBPartner) MInvoiceLine(org.compiere.model.MInvoiceLine) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) DocAction(org.compiere.process.DocAction) I_C_BPartner(org.compiere.model.I_C_BPartner) I_C_BPartner_Location(org.compiere.model.I_C_BPartner_Location) MHRProcess(org.eevolution.model.MHRProcess) MHRAttribute(org.eevolution.model.MHRAttribute) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MHREmployee(org.eevolution.model.MHREmployee) MHRMovement(org.eevolution.model.MHRMovement)

Example 2 with MHREmployee

use of org.eevolution.model.MHREmployee 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();
}
Also used : BigDecimal(java.math.BigDecimal) java.util(java.util) Query(org.compiere.model.Query) MHREmployee(org.eevolution.model.MHREmployee) MHRMovement(org.eevolution.model.MHRMovement) MHRPaySelection(org.eevolution.model.MHRPaySelection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRPaySelectionLine(org.eevolution.model.MHRPaySelectionLine) I_C_BPartner(org.compiere.model.I_C_BPartner) MHRPaySelectionLine(org.eevolution.model.MHRPaySelectionLine) Query(org.compiere.model.Query) MHRMovement(org.eevolution.model.MHRMovement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRPaySelection(org.eevolution.model.MHRPaySelection) I_C_BPartner(org.compiere.model.I_C_BPartner) MHREmployee(org.eevolution.model.MHREmployee)

Example 3 with MHREmployee

use of org.eevolution.model.MHREmployee in project adempiere by adempiere.

the class ImportEmployee method importRecord.

/**
     * Import Record for Employee
     * @param importEmployee
     * @param trxName
     * @return
     */
private boolean importRecord(X_I_HR_Employee importEmployee, String trxName) {
    if (importEmployee.getI_ErrorMsg() != null)
        return false;
    if (!isOnlyValidateData()) {
        MHREmployee employee = MHREmployee.getByPartnerIdAndStartDate(importEmployee.getCtx(), importEmployee.getC_BPartner_ID(), importEmployee.getStartDate(), trxName);
        if (employee != null && employee.getHR_Employee_ID() <= 0) {
            importEmployeeImages(importEmployee);
            employee.updateEmployeeData(importEmployee).saveEx();
        } else {
            importEmployeeImages(importEmployee);
            employee = new MHREmployee(importEmployee);
            employee.saveEx();
            updatePartnerFromEmployeeData(importEmployee);
        }
        importEmployee.setHR_Employee_ID(employee.getHR_Employee_ID());
        importEmployee.setI_IsImported(true);
        importEmployee.setProcessed(true);
        importEmployee.saveEx();
        return true;
    } else
        return false;
}
Also used : MHREmployee(org.eevolution.model.MHREmployee)

Aggregations

MHREmployee (org.eevolution.model.MHREmployee)3 BigDecimal (java.math.BigDecimal)2 I_C_BPartner (org.compiere.model.I_C_BPartner)2 Query (org.compiere.model.Query)2 MHRMovement (org.eevolution.model.MHRMovement)2 Timestamp (java.sql.Timestamp)1 java.util (java.util)1 Arrays (java.util.Arrays)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Level (java.util.logging.Level)1 I_C_BPartner_Location (org.compiere.model.I_C_BPartner_Location)1 MBPartner (org.compiere.model.MBPartner)1 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1 MInvoice (org.compiere.model.MInvoice)1 MInvoiceLine (org.compiere.model.MInvoiceLine)1 MPaymentTerm (org.compiere.model.MPaymentTerm)1 DocAction (org.compiere.process.DocAction)1 Env (org.compiere.util.Env)1 Msg (org.compiere.util.Msg)1