Search in sources :

Example 1 with MHRConcept

use of org.eevolution.model.MHRConcept 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 MHRConcept

use of org.eevolution.model.MHRConcept 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 MHRConcept

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

the class HRCreateConcept method createPayrollConcept.

//	doIt
/**
	 * Create Payroll Concept
	 * @param concepts
	 * @param payrollId
	 * @return
	 */
private int createPayrollConcept(List<MHRConcept> concepts, int payrollId) {
    AtomicInteger count = new AtomicInteger(0);
    concepts.stream().filter(concept -> !existsPayrollConcept(concept.getHR_Concept_ID(), payrollId)).forEach(concept -> {
        MHRPayrollConcept payrollConcept = new MHRPayrollConcept(concept, payrollId, get_TrxName());
        payrollConcept.setIsPrinted(concept.isPrinted());
        payrollConcept.setSeqNo(concept.getSeqNo());
        payrollConcept.setName(concept.getName());
        payrollConcept.saveEx();
        addLog("@SeqNo@" + payrollConcept.getSeqNo() + " @HR_PayrollConcept_ID@ : " + payrollConcept.getName());
        count.updateAndGet(no -> no + 1);
    });
    return count.get();
}
Also used : List(java.util.List) Query(org.compiere.model.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRConcept(org.eevolution.model.MHRConcept) Optional(java.util.Optional) MHRPayrollConcept(org.eevolution.model.MHRPayrollConcept) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRPayrollConcept(org.eevolution.model.MHRPayrollConcept)

Example 4 with MHRConcept

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

the class HRActionNotice method seekMovement.

/**
	 *  get record Found to Movement Payroll
	 *  parameter: 
	 */
public int seekMovement(Timestamp dt) {
    if (m_HR_Concept_ID <= 0)
        return 0;
    int HR_Movement_ID = 0;
    String date = DB.TO_DATE(dt);
    int Process_ID = m_HR_Process_ID;
    int Employee_ID = m_C_BPartner_ID;
    int Concept_ID = m_HR_Concept_ID;
    MHRConcept concept = MHRConcept.get(Env.getCtx(), Concept_ID);
    if ((Process_ID + Employee_ID + Concept_ID) > 0) {
        HR_Movement_ID = DB.getSQLValue(null, "SELECT HR_Movement_ID " + " FROM HR_Movement WHERE HR_Process_ID = " + Process_ID + " AND C_BPartner_ID =" + Employee_ID + " AND HR_Concept_ID = " + Concept_ID + " AND TRUNC(ValidFrom) = TRUNC(" + date + ")");
    }
    return HR_Movement_ID;
}
Also used : MHRConcept(org.eevolution.model.MHRConcept)

Example 5 with MHRConcept

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

the class VHRActionNotice method actionPerformed.

/**************************************************************************
	 *	Action Listener
	 *  @param e event
	 */
public void actionPerformed(ActionEvent e) {
    log.fine("Event " + e);
    log.fine("Event Source " + e.getSource());
    if (e.getSource().equals(fieldProcess)) {
        // Process
        KeyNamePair pp = (KeyNamePair) fieldProcess.getSelectedItem();
        if (pp != null) {
            payrollProcessId = pp.getKey();
            payrollProcess = new MHRProcess(Env.getCtx(), payrollProcessId, null);
            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();
            }
            payrollId = payrollProcess.getHR_Payroll_ID();
            fieldEmployee.removeAllItems();
            for (KeyNamePair ppt : getEmployeeValid(payrollProcess)) {
                fieldEmployee.addItem(ppt);
            }
            fieldEmployee.setSelectedIndex(0);
            fieldEmployee.setReadWrite(true);
        }
    } else if (e.getSource().equals(fieldEmployee)) {
        // Employee
        KeyNamePair keyNamePair = (KeyNamePair) fieldEmployee.getSelectedItem();
        if (keyNamePair != null) {
            partnerId = keyNamePair.getKey();
        }
        if (partnerId > 0) {
            fieldValidFrom.setValue(dateEnd);
            fieldValidFrom.setReadWrite(true);
            fieldConcept.removeAllItems();
            for (KeyNamePair vp : getConcept(payrollProcess, fieldProcess != null)) {
                fieldConcept.addItem(vp);
            }
            //	
            fieldConcept.setReadWrite(true);
        }
    } else if (e.getSource().equals(fieldConcept)) {
        // Concept
        KeyNamePair conceptPair = (KeyNamePair) fieldConcept.getSelectedItem();
        if (conceptPair != null) {
            conceptId = conceptPair.getKey();
        }
        //	
        if (conceptId > 0) {
            MHRConcept concept = MHRConcept.get(Env.getCtx(), conceptId);
            //	Load Data Combo Box
            loadTextMsgLookup(concept.getAD_Reference_ID());
            // Name To Type Column
            fieldColumnType.setValue(concept.getColumnType());
            fieldColumnType.setVisible(true);
            //  exist movement record to date actual
            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(MHRConcept.COLUMNTYPE_Quantity)) {
                    // Quantity
                    fieldQty.setValue(movementFound.getQty());
                } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Amount)) {
                    // Amount
                    fieldAmount.setValue(movementFound.getAmount());
                } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Text)) {
                    //	Verify Reference
                    if (isLookupTextMsg) {
                        fieldTextLookup.setValue(movementFound.getTextMsg());
                    } else {
                        fieldText.setValue(movementFound.getTextMsg());
                    }
                } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Date)) {
                    // Date
                    fieldDate.setValue(movementFound.getServiceDate());
                }
            } else {
                fieldQty.setValue(null);
                fieldAmount.setValue(null);
                fieldDescription.setValue(null);
                fieldText.setValue(null);
                fieldTextLookup.setValue(null);
                fieldDate.setValue(null);
            }
            //	
            if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Quantity)) {
                // Concept Type
                fieldQty.setVisible(true);
                fieldQty.setReadWrite(true);
                fieldAmount.setVisible(false);
                fieldDate.setVisible(false);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
                fieldRuleE.setVisible(false);
            } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Amount)) {
                fieldQty.setVisible(false);
                fieldAmount.setVisible(true);
                fieldAmount.setReadWrite(true);
                fieldDate.setVisible(false);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
                fieldRuleE.setVisible(false);
            } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Date)) {
                fieldQty.setVisible(false);
                fieldAmount.setVisible(false);
                fieldDate.setVisible(true);
                fieldDate.setReadWrite(true);
                fieldText.setVisible(false);
                fieldTextLookup.setVisible(false);
                fieldRuleE.setVisible(false);
            } else if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Text)) {
                //	Verify Reference
                if (isLookupTextMsg) {
                    fieldText.setVisible(false);
                    fieldText.setReadWrite(false);
                    fieldTextLookup.setVisible(true);
                    fieldTextLookup.setReadWrite(true);
                } else {
                    fieldTextLookup.setVisible(false);
                    fieldTextLookup.setReadWrite(false);
                    fieldText.setVisible(true);
                    fieldText.setReadWrite(true);
                }
                fieldAmount.setVisible(false);
                fieldDate.setVisible(false);
                fieldRuleE.setVisible(false);
            }
            fieldDescription.setReadWrite(true);
        }
    } else // Concept
    if (e instanceof ActionEvent && e.getSource().equals(bOk)) {
        // Movement SAVE
        conceptId = ((KeyNamePair) fieldConcept.getSelectedItem()).getKey();
        partnerId = ((KeyNamePair) fieldEmployee.getSelectedItem()).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) fieldTextLookup.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.getValue() == null || ((Integer) fieldProcess.getValue()).intValue() <= 0 || fieldEmployee.getValue() == null || ((Integer) fieldEmployee.getValue()).intValue() <= 0) {
            // required fields
            ADialog.error(m_WindowNo, this.mainPanel, Msg.translate(Env.getCtx(), "FillMandatory") + Msg.translate(Env.getCtx(), "HR_Process_ID") + ", " + Msg.translate(Env.getCtx(), "HR_Employee_ID") + ", " + Msg.translate(Env.getCtx(), "HR_Concept_ID"));
        } else {
            saveMovement();
        }
    }
    executeQuery();
    return;
}
Also used : MHRProcess(org.eevolution.model.MHRProcess) ActionEvent(java.awt.event.ActionEvent) MHRPeriod(org.eevolution.model.MHRPeriod) KeyNamePair(org.compiere.util.KeyNamePair) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MHRConcept(org.eevolution.model.MHRConcept) MHRMovement(org.eevolution.model.MHRMovement)

Aggregations

MHRConcept (org.eevolution.model.MHRConcept)6 MHRMovement (org.eevolution.model.MHRMovement)3 BigDecimal (java.math.BigDecimal)2 Timestamp (java.sql.Timestamp)2 List (java.util.List)2 Optional (java.util.Optional)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Query (org.compiere.model.Query)2 KeyNamePair (org.compiere.util.KeyNamePair)2 MHRPayrollConcept (org.eevolution.model.MHRPayrollConcept)2 MHRPeriod (org.eevolution.model.MHRPeriod)2 MHRProcess (org.eevolution.model.MHRProcess)2 ActionEvent (java.awt.event.ActionEvent)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ValueNamePair (org.compiere.util.ValueNamePair)1 X_I_HR_Movement (org.eevolution.model.X_I_HR_Movement)1