Search in sources :

Example 1 with MHRMovement

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

the class ImportPayrollMovement method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message
	 *  @throws Exception
	 */
protected String doIt() throws Exception {
    StringBuffer sql = null;
    int no = 0;
    String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
    //	Delete Old Imported
    if (m_deleteOldImported) {
        sql = new StringBuffer("DELETE I_HR_Movement " + "WHERE I_IsImported='Y'").append(clientCheck);
        no = DB.executeUpdate(sql.toString(), get_TrxName());
        log.info("Delete Old Imported =" + no);
    }
    //	Set Client, Org, IsActive, Created/Updated
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append(")," + " AD_Org_ID = COALESCE (AD_Org_ID, 0)," + " IsActive = COALESCE (IsActive, 'Y')," + " Created = COALESCE (Created, SysDate)," + " CreatedBy = COALESCE (CreatedBy, 0)," + " Updated = COALESCE (Updated, SysDate)," + " UpdatedBy = COALESCE (UpdatedBy, 0)," + " I_ErrorMsg = ' '," + " I_IsImported = 'N' " + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.info("Reset=" + no);
    //	Set Mandatory Process
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET HR_Process_ID=(SELECT HR_Process_ID FROM HR_Process p" + " WHERE I_HR_Movement.ProcessName=p.Name AND p.DocStatus IN ('DR', 'IP') AND I_HR_Movement.AD_Client_ID=p.AD_Client_ID) " + "WHERE HR_Process_ID IS NULL AND ProcessName IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.info("HR_Process=" + no);
    //
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid HR Process,' " + "WHERE HR_Process_ID IS NULL AND ProcessName IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid HR Process=" + no);
    //	Set Mandatory BPartner
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner bp" + " WHERE I_HR_Movement.BPartner_Value=bp.Value AND bp.IsEmployee = 'Y' AND I_HR_Movement.AD_Client_ID=bp.AD_Client_ID) " + "WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.info("BPartner=" + no);
    //
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner,' " + "WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid BPartner=" + no);
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory BPartner Value,' " + "WHERE BPartner_Value IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("No Mandatory BPartner Value=" + no);
    //	Concept
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET HR_Concept_ID=(SELECT HR_Concept_ID FROM HR_Concept c" + " WHERE I_HR_Movement.ConceptValue=c.Value AND c.IsManual='Y' AND c.IsActive='Y' AND c.Type!='E' AND I_HR_Movement.AD_Client_ID=c.AD_Client_ID) " + "WHERE HR_Concept_ID IS NULL AND ConceptValue IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.fine("Set Concept from Value=" + no);
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Concept, ' " + "WHERE HR_Concept_ID IS NULL AND ConceptValue IS NOT NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid Concept=" + no);
    //	Mandatories
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory Process Name,' " + "WHERE ProcessName IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("No Mandatory Process Name=" + no);
    //
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory Concept Value,' " + "WHERE ConceptValue IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("No Mandatory Concept Value=" + no);
    //
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory ValidFrom,' " + "WHERE ValidFrom IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("No Mandatory ValidFrom=" + no);
    //
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory BPartner Value,' " + "WHERE BPartner_Value IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("No Mandatory BPartner Value=" + no);
    // seek already existing movements -> key process+bpartner+concept+validfrom
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET HR_Movement_ID=(SELECT HR_Movement_ID FROM HR_Movement m" + " WHERE m.HR_Process_ID=I_HR_Movement.HR_Process_ID AND" + " m.C_BPartner_ID=I_HR_Movement.C_BPartner_ID AND" + " m.HR_Concept_ID=I_HR_Movement.HR_Concept_ID AND" + " TRUNC(m.ValidFrom)=TRUNC(I_HR_Movement.ValidFrom))" + "WHERE HR_Movement_ID IS NULL" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.fine("Set current existing movements=" + no);
    commitEx();
    //	-------------------------------------------------------------------
    int noInserthrm = 0;
    int noUpdatehrm = 0;
    //	Go through Records
    log.fine("start inserting/updating ...");
    sql = new StringBuffer("SELECT * FROM I_HR_Movement WHERE I_IsImported='N'").append(clientCheck);
    PreparedStatement pstmt_setImported = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        //	Set Imported = Y
        pstmt_setImported = DB.prepareStatement("UPDATE I_HR_Movement SET I_IsImported='Y', HR_Movement_ID=?, " + "Updated=SysDate, Processed='Y' WHERE I_HR_Movement_ID=?", get_TrxName());
        //
        pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            X_I_HR_Movement importMovement = new X_I_HR_Movement(getCtx(), rs, get_TrxName());
            int I_HR_Movement_ID = importMovement.getI_HR_Movement_ID();
            int HR_Movement_ID = importMovement.getHR_Movement_ID();
            boolean newPayrollMovement = HR_Movement_ID == 0;
            log.fine("I_HR_Movement_ID=" + I_HR_Movement_ID + ", HR_Movement_ID=" + HR_Movement_ID);
            MHRMovement payrollMovement = null;
            //	HR Movement
            if (//	Insert new HR Movement
            newPayrollMovement) {
                payrollMovement = new MHRMovement(importMovement);
                if (payrollMovement.save()) {
                    HR_Movement_ID = payrollMovement.getHR_Movement_ID();
                    log.finer("Insert HR Movement");
                    noInserthrm++;
                } else {
                    StringBuffer sql0 = new StringBuffer("UPDATE I_HR_Movement i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert HR Movement failed")).append("WHERE I_HR_Movement_ID=").append(I_HR_Movement_ID);
                    DB.executeUpdate(sql0.toString(), get_TrxName());
                    continue;
                }
            } else {
                payrollMovement = new MHRMovement(getCtx(), HR_Movement_ID, get_TrxName());
                MHRConcept payrollConcept = new MHRConcept(getCtx(), payrollMovement.getHR_Concept_ID(), get_TrxName());
                // set corresponding values
                payrollMovement.setSeqNo(payrollConcept.getSeqNo());
                payrollMovement.setDescription(importMovement.getDescription());
                payrollMovement.setReferenceNo(importMovement.getReferenceNo());
                payrollMovement.setAmount(null);
                payrollMovement.setQty(null);
                payrollMovement.setServiceDate(null);
                payrollMovement.setTextMsg(null);
                if (payrollConcept.getColumnType().equals(MHRConcept.COLUMNTYPE_Quantity)) {
                    // Concept Type
                    payrollMovement.setQty(importMovement.getQty());
                } else if (payrollConcept.getColumnType().equals(MHRConcept.COLUMNTYPE_Amount)) {
                    payrollMovement.setAmount(importMovement.getAmount());
                } else if (payrollConcept.getColumnType().equals(MHRConcept.COLUMNTYPE_Date)) {
                    payrollMovement.setServiceDate(importMovement.getServiceDate());
                } else if (payrollConcept.getColumnType().equals(MHRConcept.COLUMNTYPE_Text)) {
                    payrollMovement.setTextMsg(importMovement.getTextMsg());
                }
                if (payrollMovement.save()) {
                    noUpdatehrm++;
                } else {
                    StringBuffer sql0 = new StringBuffer("UPDATE I_HR_Movement i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update HR Movement failed")).append("WHERE I_HR_Movement_ID=").append(I_HR_Movement_ID);
                    DB.executeUpdate(sql0.toString(), get_TrxName());
                    continue;
                }
            }
            //	Update I_HR_Movement
            pstmt_setImported.setInt(1, HR_Movement_ID);
            pstmt_setImported.setInt(2, I_HR_Movement_ID);
            no = pstmt_setImported.executeUpdate();
            //
            commitEx();
        }
    //	for all I_HR_Movement
    //
    } catch (SQLException e) {
        throw e;
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
        DB.close(pstmt_setImported);
        pstmt_setImported = null;
    }
    //	Set Error to indicator to not imported
    sql = new StringBuffer("UPDATE I_HR_Movement " + "SET I_IsImported='N', Updated=SysDate " + "WHERE I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    addLog(0, null, new BigDecimal(no), "@Errors@");
    addLog(0, null, new BigDecimal(noInserthrm), "@HR_Movement_ID@: @Inserted@");
    addLog(0, null, new BigDecimal(noUpdatehrm), "@HR_Movement_ID@: @Updated@");
    return "";
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) X_I_HR_Movement(org.eevolution.model.X_I_HR_Movement) BigDecimal(java.math.BigDecimal) MHRMovement(org.eevolution.model.MHRMovement) MHRConcept(org.eevolution.model.MHRConcept)

Example 2 with MHRMovement

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

the class WHRActionNotice method onEvent.

/**************************************************************************
	 * Action Listener. - MultiCurrency - Allocate
	 * 
	 * @param e
	 *            event
	 */
@Override
public void onEvent(Event e) {
    KeyNamePair processKeyNamePair = (KeyNamePair) fieldProcess.getSelectedItem().getValue();
    if (e.getTarget() == fieldProcess && processKeyNamePair != null && processKeyNamePair.getKey() > 0) {
        payrollProcess = new MHRProcess(Env.getCtx(), processKeyNamePair.getKey(), null);
        payrollProcessId = payrollProcess.getHR_Process_ID();
        if (payrollProcess.getHR_Period_ID() > 0) {
            MHRPeriod period = MHRPeriod.get(Env.getCtx(), payrollProcess.getHR_Period_ID());
            dateStart = period.getStartDate();
            dateEnd = period.getEndDate();
        } else {
            dateEnd = payrollProcess.getDateAcct();
        }
        fieldEmployee.removeAllItems();
        KeyNamePair[] employeeData = getEmployeeValid(payrollProcess);
        for (KeyNamePair vp : employeeData) {
            fieldEmployee.appendItem(vp.getName(), vp);
        }
    }
    //	
    if (e.getTarget() == fieldEmployee) {
        partnerId = ((KeyNamePair) fieldEmployee.getSelectedItem().getValue()).getKey();
        //	Validate
        if (partnerId > 0) {
            fieldValidFrom.setValue(dateEnd);
            fieldConcept.removeAllItems();
            KeyNamePair[] conceptData = getConcept(getPayrollProcess(), fieldProcess != null);
            for (KeyNamePair vp : conceptData) {
                fieldConcept.appendItem(vp.getName(), vp);
            }
        }
    }
    if (e.getTarget() == fieldConcept) {
        KeyNamePair valueNamePair = (KeyNamePair) fieldConcept.getSelectedItem().getValue();
        if (valueNamePair != null) {
            conceptId = ((KeyNamePair) fieldConcept.getSelectedItem().getValue()).getKey();
        }
        //	
        if (conceptId > 0) {
            MHRConcept concept = MHRConcept.get(Env.getCtx(), conceptId);
            //	Load Data Combo Box
            loadTextMsgLookup(concept.getAD_Reference_ID());
            //	
            String columnType = MRefList.getListName(Env.getCtx(), MHRConcept.COLUMNTYPE_AD_Reference_ID, concept.getColumnType());
            fieldColumnType.setValue(columnType);
            fieldColumnType.setVisible(true);
            movementId = seekMovement((Timestamp) fieldValidFrom.getValue());
            if (movementId > 0) {
                MHRMovement movementFound = new MHRMovement(Env.getCtx(), movementId, null);
                fieldDescription.setValue(movementFound.getDescription());
                fieldText.setValue("");
                fieldDate.setValue(null);
                fieldQty.setValue(Env.ZERO);
                fieldAmount.setValue(Env.ZERO);
                if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Quantity)) {
                    // Quantity
                    fieldQty.setValue(movementFound.getQty());
                } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Amount)) {
                    // Amount
                    fieldAmount.setValue(movementFound.getAmount());
                } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Text)) {
                    //	Verify Reference
                    if (isLookupTextMsg) {
                        fieldTextLookup.setValue(movementFound.getTextMsg());
                    } else {
                        fieldText.setValue(movementFound.getTextMsg());
                    }
                } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Date)) {
                    // Date
                    fieldDate.setValue(movementFound.getServiceDate());
                }
            }
            if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Quantity)) {
                // Concept Type
                fieldQty.setVisible(true);
                fieldQty.setReadWrite(true);
                fieldAmount.setVisible(false);
                fieldDate.setVisible(false);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
            } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Amount)) {
                fieldQty.setVisible(false);
                fieldAmount.setVisible(true);
                fieldAmount.setReadWrite(true);
                fieldDate.setVisible(false);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
            } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Date)) {
                fieldQty.setVisible(false);
                fieldAmount.setVisible(false);
                fieldDate.setVisible(true);
                fieldDate.setReadWrite(true);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
            } else if (concept.getColumnType().equals(X_HR_Concept.COLUMNTYPE_Text)) {
                //	Verify Reference
                if (isLookupTextMsg) {
                    fieldText.setVisible(false);
                    fieldText.setReadWrite(false);
                    fieldTextLookup.setVisible(true);
                } else {
                    fieldTextLookup.setVisible(false);
                    fieldText.setVisible(true);
                    fieldText.setReadWrite(true);
                }
                fieldAmount.setVisible(false);
                fieldDate.setVisible(false);
            }
        }
    }
    if (e.getTarget() == bOk) {
        if (fieldConcept.getSelectedItem() != null)
            conceptId = ((KeyNamePair) fieldConcept.getSelectedItem().getValue()).getKey();
        partnerId = ((KeyNamePair) fieldEmployee.getSelectedItem().getValue()).getKey();
        payrollId = getPayrollProcess().getHR_Payroll_ID();
        if (payrollProcess.getHR_Period_ID() > 0) {
            MHRPeriod period = MHRPeriod.get(Env.getCtx(), payrollProcess.getHR_Period_ID());
            dateStart = period.getStartDate();
            dateEnd = period.getEndDate();
        } else {
            dateEnd = payrollProcess.getDateAcct();
        }
        quantity = (BigDecimal) fieldQty.getValue();
        amount = (BigDecimal) fieldAmount.getValue();
        //	Get from List
        if (isLookupTextMsg) {
            text = (String) ((ValueNamePair) fieldTextLookup.getSelectedItem().getValue()).getValue();
        } else {
            text = (String) fieldText.getValue();
        }
        serviceDate = (Timestamp) fieldDate.getValue();
        description = (String) fieldDescription.getValue();
        validFrom = (Timestamp) fieldValidFrom.getValue();
        validTo = (Timestamp) fieldValidFrom.getValue();
        if (conceptId <= 0 || fieldProcess.getSelectedItem().getValue() == null || ((KeyNamePair) fieldProcess.getSelectedItem().getValue()).getKey() <= 0 || fieldEmployee.getSelectedItem().getValue() == null || ((KeyNamePair) fieldEmployee.getSelectedItem().getValue()).getKey() <= 0) {
        // required fields
        } else {
            saveMovement();
        }
    }
    //	
    executeQuery();
    return;
}
Also used : MHRProcess(org.eevolution.model.MHRProcess) MHRPeriod(org.eevolution.model.MHRPeriod) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) Timestamp(java.sql.Timestamp) MHRConcept(org.eevolution.model.MHRConcept) MHRMovement(org.eevolution.model.MHRMovement)

Example 3 with MHRMovement

use of org.eevolution.model.MHRMovement 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 4 with MHRMovement

use of org.eevolution.model.MHRMovement 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 5 with MHRMovement

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

the class Doc_HRProcess method createFacts.

//  getBalance
@Override
public ArrayList<Fact> createFacts(MAcctSchema as) {
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    final String sql = // 1,2,3,4
    "SELECT m.HR_Concept_id, MAX(c.Name) As Name, SUM(m.Amount) As Amount, MAX(c.AccountSign) As AccountSign, " + // 5,6,7
    " MAX(CA.IsBalancing) As IsBalancing, e.AD_Org_ID As AD_Org_ID, m.C_Activity_ID, bp.C_BPartner_ID, m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID " + " FROM HR_Movement m" + " INNER JOIN HR_Concept_Acct ca ON (ca.HR_Concept_ID=m.HR_Concept_ID AND ca.AD_Client_ID = m.AD_Client_ID AND ca.IsActive = 'Y')" + " INNER JOIN HR_Concept      c  ON (c.HR_Concept_ID=m.HR_Concept_ID AND c.IsActive = 'Y')" + " INNER JOIN C_BPartner      bp ON (bp.C_BPartner_ID = m.C_BPartner_ID)" + " INNER JOIN HR_Employee	 e  ON (bp.C_BPartner_ID=e.C_BPartner_ID)" + " INNER JOIN HR_Department   d  ON (d.HR_Department_ID=e.HR_Department_ID)" + " WHERE m.HR_Process_ID=? AND (m.Qty <> 0 OR m.Amount <> 0) AND c.AccountSign != 'N'" + " GROUP BY m.HR_Concept_ID,e.AD_Org_ID,m.C_Activity_ID , bp.C_BPartner_ID , m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID  " + " ORDER BY e.AD_Org_ID,m.C_Activity_ID,bp.C_BPartner_ID, m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID ";
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        BigDecimal totalDebit = Env.ZERO;
        BigDecimal totalCredit = Env.ZERO;
        pstmt = DB.prepareStatement(sql, getTrxName());
        pstmt.setInt(1, process.getHR_Process_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int HR_Concept_ID = rs.getInt("HR_Concept_ID");
            BigDecimal sumAmount = rs.getBigDecimal("Amount");
            // round amount according to currency
            sumAmount = sumAmount.setScale(as.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
            String AccountSign = rs.getString("AccountSign");
            boolean isBalancing = "Y".equals(rs.getString("IsBalancing"));
            int AD_OrgTrx_ID = rs.getInt("AD_Org_ID");
            int C_Activity_ID = rs.getInt("C_Activity_ID");
            int C_BPartner_ID = rs.getInt("C_BPartner_ID");
            int user1Id = rs.getInt("User1_ID");
            int user2Id = rs.getInt("User3_ID");
            int user3Id = rs.getInt("User4_ID");
            int user4Id = rs.getInt("User5_ID");
            MHRMovement movement = new MHRMovement(getCtx(), 0, getTrxName());
            movement.setC_BPartner_ID(C_BPartner_ID);
            movement.setHR_Concept_ID(HR_Concept_ID);
            movement.setAccountSign(AccountSign);
            movement.setAD_OrgTrx_ID(AD_OrgTrx_ID);
            movement.setC_Activity_ID(C_Activity_ID);
            movement.setAmount(sumAmount);
            movement.setUser1_ID(user1Id);
            movement.setUser2_ID(user2Id);
            movement.setUser3_ID(user3Id);
            movement.setUser4_ID(user4Id);
            DocLine_Payroll docLine = new DocLine_Payroll(movement, this);
            //
            if (AccountSign != null && AccountSign.length() > 0 && (MHRConcept.ACCOUNTSIGN_Debit.equals(AccountSign) || MHRConcept.ACCOUNTSIGN_Credit.equals(AccountSign))) {
                if (isBalancing) {
                    MAccount accountBPD = MAccount.get(getCtx(), getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Debit));
                    FactLine debit = fact.createLine(docLine, accountBPD, as.getC_Currency_ID(), sumAmount, null);
                    debit.saveEx();
                    MAccount accountBPC = MAccount.get(getCtx(), this.getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Credit));
                    FactLine credit = fact.createLine(docLine, accountBPC, as.getC_Currency_ID(), null, sumAmount);
                    credit.saveEx();
                } else {
                    if (MHRConcept.ACCOUNTSIGN_Debit.equals(AccountSign)) {
                        MAccount accountBPD = MAccount.get(getCtx(), getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Debit));
                        FactLine debit = fact.createLine(docLine, accountBPD, as.getC_Currency_ID(), sumAmount, null);
                        debit.saveEx();
                        totalDebit = totalDebit.add(sumAmount);
                    } else if (MHRConcept.ACCOUNTSIGN_Credit.equals(AccountSign)) {
                        MAccount accountBPC = MAccount.get(getCtx(), this.getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Credit));
                        FactLine credit = fact.createLine(docLine, accountBPC, as.getC_Currency_ID(), null, sumAmount);
                        credit.saveEx();
                        totalCredit = totalCredit.add(sumAmount);
                    }
                }
            }
            movement = null;
        }
        if (totalDebit.signum() != 0 || totalCredit.signum() != 0) {
            int C_Charge_ID = process.getHR_Payroll().getC_Charge_ID();
            if (C_Charge_ID > 0) {
                MAccount acct = MCharge.getAccount(C_Charge_ID, as, totalDebit.subtract(totalCredit));
                FactLine regTotal = null;
                if (totalDebit.abs().compareTo(totalCredit.abs()) > 0)
                    regTotal = fact.createLine(null, acct, as.getC_Currency_ID(), null, totalDebit.subtract(totalCredit));
                else
                    regTotal = fact.createLine(null, acct, as.getC_Currency_ID(), totalCredit.abs().subtract(totalDebit.abs()), null);
                regTotal.setAD_Org_ID(getAD_Org_ID());
                regTotal.saveEx();
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
        p_Error = e.getLocalizedMessage();
        return null;
    } finally {
        DB.close(rs, pstmt);
        pstmt = null;
        rs = null;
    }
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) MHRMovement(org.eevolution.model.MHRMovement) ResultSet(java.sql.ResultSet)

Aggregations

MHRMovement (org.eevolution.model.MHRMovement)7 BigDecimal (java.math.BigDecimal)5 Timestamp (java.sql.Timestamp)3 MHRConcept (org.eevolution.model.MHRConcept)3 MHRProcess (org.eevolution.model.MHRProcess)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 I_C_BPartner (org.compiere.model.I_C_BPartner)2 Query (org.compiere.model.Query)2 KeyNamePair (org.compiere.util.KeyNamePair)2 MHREmployee (org.eevolution.model.MHREmployee)2 MHRPeriod (org.eevolution.model.MHRPeriod)2 ActionEvent (java.awt.event.ActionEvent)1 SQLException (java.sql.SQLException)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