Search in sources :

Example 1 with MHRDepartment

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

the class ImportEmployee method fillIdValues.

/**
     * Fill values and validate employee data
     * This method create the dependences for Race , Department , Job , Job Type
     * Job Education , Career Level , Employee Type and Skill Type
     * @param importEmployee
     * @param trxName
     */
private void fillIdValues(X_I_HR_Employee importEmployee, String trxName) {
    StringBuffer stringError = new StringBuffer("");
    Integer orgId = 0;
    if (importEmployee.getAD_Org_ID() > 0)
        orgId = importEmployee.getAD_Org_ID();
    if (orgId <= 0)
        orgId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importEmployee.getOrgValue());
    if (orgId > 0)
        importEmployee.setAD_Org_ID(orgId);
    Integer partnerId = getId(MBPartner.Table_Name, MBPartner.COLUMNNAME_Value + "=?", trxName, importEmployee.getBPartnerValue());
    if (partnerId > 0)
        importEmployee.setC_BPartner_ID(partnerId);
    else if (isCreatedBusinessPartner()) {
        if (getBusinessPartnerGroupId() > 0) {
            MBPartner partner = createPartnerFromEmployeeData(importEmployee);
            partnerId = partner.get_ID();
            importEmployee.setC_BPartner_ID(partnerId);
        } else
            stringError.append(" @C_BP_Group_ID@ @NotFound@");
    }
    //Set Race
    MHRRace race = null;
    if (importEmployee.getHR_Race_ID() > 0)
        race = MHRRace.getById(getCtx(), importEmployee.getHR_Race_ID());
    if (race != null && race.getHR_Race_ID() < 0 && importEmployee.getRaceValue() != null)
        race = MHRRace.getByValue(getCtx(), importEmployee.getRaceValue());
    if (race == null || race.getHR_Race_ID() < 0) {
        if (importEmployee.getRaceValue() != null && importEmployee.getRaceName() != null) {
            race = new MHRRace(getCtx(), importEmployee.getRaceValue(), importEmployee.getRaceName(), trxName);
            race.saveEx();
        }
    }
    if (race != null && race.getHR_Race_ID() > 0)
        importEmployee.setHR_Race_ID(race.getHR_Race_ID());
    //Set Organization Trx
    MOrg orgTrx = null;
    if (importEmployee.getAD_OrgTrx_ID() > 0)
        orgTrx = MOrg.get(getCtx(), importEmployee.getAD_OrgTrx_ID());
    if (orgTrx == null && importEmployee.getOrgTrxValue() != null) {
        int orgTrxId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importEmployee.getOrgTrxValue());
        orgTrx = MOrg.get(getCtx(), orgTrxId);
    }
    if (orgTrx != null && orgTrx.getAD_Org_ID() > 0)
        importEmployee.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
    //Set Project
    MProject project = null;
    if (importEmployee.getC_Project_ID() > 0)
        project = MProject.getById(getCtx(), importEmployee.getC_Project_ID());
    if (project == null && importEmployee.getProjectValue() != null)
        project = MProject.getByValue(getCtx(), importEmployee.getProjectValue());
    if (project != null && project.getC_Project_ID() > 0)
        importEmployee.setC_Project_ID(project.getC_Project_ID());
    //Set Department
    MHRDepartment department = null;
    if (importEmployee.getHR_Department_ID() > 0)
        department = MHRDepartment.getById(getCtx(), importEmployee.getHR_Department_ID());
    if (department == null && importEmployee.getDepartmentValue() != null)
        department = MHRDepartment.getByValue(getCtx(), importEmployee.getDepartmentValue());
    if (department == null || department.getHR_Department_ID() < 0) {
        if (importEmployee.getDepartmentValue() != null && importEmployee.getDepartmentName() != null) {
            department = new MHRDepartment(getCtx(), importEmployee.getDepartmentValue(), importEmployee.getDepartmentName(), trxName);
            department.saveEx();
        }
    }
    if (department != null && department.getHR_Department_ID() > 0)
        importEmployee.setHR_Department_ID(department.getHR_Department_ID());
    //Set Job
    MHRJob job = null;
    if (importEmployee.getHR_Job_ID() > 0)
        job = MHRJob.getById(getCtx(), importEmployee.getHR_Job_ID());
    if (job == null && importEmployee.getJobValue() != null)
        job = MHRJob.getByValue(getCtx(), importEmployee.getJobValue());
    if (job == null || job.getHR_Job_ID() < 0) {
        if (importEmployee.getJobValue() != null && importEmployee.getJobName() != null) {
            job = new MHRJob(getCtx(), importEmployee.getJobValue(), importEmployee.getJobName(), trxName);
            job.saveEx();
        }
    }
    if (job != null && job.getHR_Job_ID() > 0)
        importEmployee.setHR_Job_ID(job.getHR_Job_ID());
    //Set Job Education
    MHRJobEducation jobEducation = null;
    if (importEmployee.getHR_JobEducation_ID() > 0)
        jobEducation = new MHRJobEducation(getCtx(), importEmployee.getHR_JobEducation_ID(), trxName);
    if (jobEducation == null && importEmployee.getJobEducationValue() != null)
        jobEducation = MHRJobEducation.getByValue(getCtx(), importEmployee.getJobEducationValue());
    if (jobEducation == null || jobEducation.getHR_JobEducation_ID() < 0) {
        if (importEmployee.getJobEducationValue() != null && importEmployee.getJobEducationName() != null) {
            jobEducation = new MHRJobEducation(getCtx(), importEmployee.getJobEducationValue(), importEmployee.getJobEducationName(), trxName);
            jobEducation.saveEx();
        }
    }
    if (jobEducation != null && jobEducation.getHR_JobEducation_ID() > 0)
        importEmployee.setHR_JobEducation_ID(jobEducation.getHR_JobEducation_ID());
    // Set Carrer Level
    MHRCareerLevel careerLevel = null;
    if (importEmployee.getHR_CareerLevel_ID() > 0)
        careerLevel = new MHRCareerLevel(getCtx(), importEmployee.getHR_CareerLevel_ID(), trxName);
    if (careerLevel == null && importEmployee.getCareerLevelValue() != null)
        careerLevel = MHRCareerLevel.getByValue(getCtx(), importEmployee.getCareerLevelValue());
    if (careerLevel == null || careerLevel.getHR_CareerLevel_ID() < 0) {
        if (importEmployee.getCareerLevelValue() != null && importEmployee.getCareerLevelName() != null) {
            careerLevel = new MHRCareerLevel(getCtx(), importEmployee.getCareerLevelValue(), importEmployee.getCareerLevelName(), trxName);
            careerLevel.saveEx();
        }
    }
    if (careerLevel != null && careerLevel.getHR_CareerLevel_ID() > 0)
        importEmployee.setHR_CareerLevel_ID(careerLevel.getHR_CareerLevel_ID());
    // Set Job Type
    MHRJobType jobType = null;
    if (importEmployee.getHR_JobType_ID() > 0)
        jobType = MHRJobType.getById(getCtx(), importEmployee.getHR_JobType_ID());
    if (jobType == null && importEmployee.getJobTypeValue() != null)
        jobType = MHRJobType.getByValue(getCtx(), importEmployee.getJobTypeValue());
    if (jobType == null || jobType.getHR_JobType_ID() < 0) {
        if (importEmployee.getJobTypeValue() != null && importEmployee.getJobTypeName() != null) {
            jobType = new MHRJobType(getCtx(), importEmployee.getJobTypeValue(), importEmployee.getJobTypeName(), trxName);
            jobType.saveEx();
        }
    }
    if (jobType != null && jobType.getHR_JobType_ID() > 0)
        importEmployee.setHR_JobType_ID(jobType.getHR_JobType_ID());
    // Set Payroll
    MHRPayroll payroll = null;
    if (importEmployee.getHR_Payroll_ID() > 0)
        payroll = MHRPayroll.getById(getCtx(), importEmployee.getHR_Job_ID());
    if (payroll == null && importEmployee.getPayrollValue() != null)
        payroll = MHRPayroll.getByValue(getCtx(), importEmployee.getPayrollValue());
    if (payroll != null && payroll.getHR_Payroll_ID() > 0)
        importEmployee.setHR_Payroll_ID(payroll.getHR_Payroll_ID());
    // Set Activity
    MActivity activity = null;
    if (importEmployee.getC_Activity_ID() > 0)
        activity = MActivity.getById(getCtx(), importEmployee.getC_Activity_ID());
    if (activity == null && importEmployee.getActivityValue() != null)
        activity = MActivity.getByValue(getCtx(), importEmployee.getActivityValue());
    if (activity != null && activity.getC_Activity_ID() > 0)
        importEmployee.setC_Activity_ID(activity.getC_Activity_ID());
    // Set Campaign
    MCampaign campaign = null;
    if (importEmployee.getC_Campaign_ID() > 0)
        campaign = MCampaign.getById(getCtx(), importEmployee.getC_Campaign_ID());
    if (campaign == null && importEmployee.getCampaignValue() != null)
        campaign = MCampaign.getByValue(getCtx(), importEmployee.getCampaignValue());
    if (campaign != null && campaign.getC_Campaign_ID() > 0)
        importEmployee.setC_Campaign_ID(campaign.getC_Campaign_ID());
    // Set Sales Region
    MSalesRegion salesRegion = null;
    if (importEmployee.getC_SalesRegion_ID() > 0)
        salesRegion = MSalesRegion.getById(getCtx(), importEmployee.getC_SalesRegion_ID());
    if (salesRegion == null && importEmployee.getSalesRegionValue() != null)
        salesRegion = MSalesRegion.getByValue(getCtx(), importEmployee.getSalesRegionValue());
    if (salesRegion != null && salesRegion.getC_SalesRegion_ID() > 0)
        importEmployee.setC_SalesRegion_ID(salesRegion.getC_SalesRegion_ID());
    // Set Work Group
    MHRWorkGroup workGroup = null;
    if (importEmployee.getHR_WorkGroup_ID() > 0)
        workGroup = MHRWorkGroup.getById(getCtx(), importEmployee.getHR_WorkGroup_ID());
    if (workGroup == null && importEmployee.getWorkGroupValue() != null)
        workGroup = MHRWorkGroup.getByValue(getCtx(), importEmployee.getWorkGroupValue());
    if (workGroup != null && workGroup.getHR_WorkGroup_ID() > 0)
        importEmployee.setHR_WorkGroup_ID(workGroup.getHR_WorkGroup_ID());
    // Set Shift Group
    MHRShiftGroup shiftGroup = null;
    if (importEmployee.getHR_ShiftGroup_ID() > 0)
        shiftGroup = MHRShiftGroup.getById(getCtx(), importEmployee.getHR_WorkGroup_ID());
    if (shiftGroup == null && importEmployee.getShiftGroupValue() != null)
        shiftGroup = MHRShiftGroup.getByValue(getCtx(), importEmployee.getWorkGroupValue());
    if (shiftGroup != null && shiftGroup.getHR_ShiftGroup_ID() > 0)
        importEmployee.setHR_ShiftGroup_ID(shiftGroup.getHR_ShiftGroup_ID());
    // Set Degree
    MHRDegree degree = null;
    if (importEmployee.getHR_Degree_ID() > 0)
        degree = MHRDegree.getById(getCtx(), importEmployee.getHR_Degree_ID());
    if (degree == null && importEmployee.getDegreeValue() != null)
        degree = MHRDegree.getByValue(getCtx(), importEmployee.getDegreeValue());
    if (degree == null || degree.getHR_Degree_ID() < 0) {
        if (importEmployee.getDegreeValue() != null && importEmployee.getDegreeName() != null) {
            degree = new MHRDegree(getCtx(), importEmployee.getDegreeValue(), importEmployee.getDegreeName(), trxName);
            degree.saveEx();
        }
    }
    //	Set it
    if (degree != null && degree.getHR_Degree_ID() > 0)
        importEmployee.setHR_Degree_ID(degree.getHR_Degree_ID());
    // Set Grade
    MHRGrade grade = null;
    if (importEmployee.getHR_Grade_ID() > 0)
        grade = MHRGrade.getById(getCtx(), importEmployee.getHR_Grade_ID());
    if (grade == null && importEmployee.getGradeValue() != null)
        grade = MHRGrade.getByValue(getCtx(), importEmployee.getGradeValue());
    if (grade == null || grade.getHR_Grade_ID() < 0) {
        if (importEmployee.getGradeValue() != null && importEmployee.getGradeName() != null) {
            grade = new MHRGrade(getCtx(), importEmployee.getGradeValue(), importEmployee.getGradeName(), trxName);
            grade.saveEx();
        }
    }
    if (grade != null && grade.getHR_Grade_ID() > 0)
        importEmployee.setHR_Grade_ID(grade.getHR_Grade_ID());
    //Set Designation
    MHRDesignation designation = null;
    if (importEmployee.getHR_Designation_ID() > 0)
        designation = MHRDesignation.getById(getCtx(), importEmployee.getHR_Designation_ID());
    if (designation == null && importEmployee.getDesignationValue() != null)
        designation = MHRDesignation.getByValue(getCtx(), importEmployee.getDesignationValue());
    if (designation != null && designation.getHR_Designation_ID() > 0)
        importEmployee.setHR_Designation_ID(designation.getHR_Designation_ID());
    //Set Salary Structure
    MHRSalaryStructure salaryStructure = null;
    if (importEmployee.getHR_SalaryRange_ID() > 0)
        salaryStructure = MHRSalaryStructure.getById(getCtx(), importEmployee.getHR_SalaryStructure_ID());
    if (salaryStructure == null && importEmployee.getSalaryStructureValue() != null)
        salaryStructure = MHRSalaryStructure.getByValue(getCtx(), importEmployee.getSalaryStructureValue());
    if (salaryStructure != null && salaryStructure.getHR_SalaryStructure_ID() > 0)
        importEmployee.setHR_SalaryRange_ID(salaryStructure.getHR_SalaryStructure_ID());
    //Set Salary Range
    MHRSalaryRange salaryRange = null;
    if (importEmployee.getHR_SalaryRange_ID() > 0)
        salaryRange = MHRSalaryRange.getById(getCtx(), importEmployee.getHR_SalaryRange_ID());
    if (salaryRange == null && importEmployee.getSalaryRangeValue() != null)
        salaryRange = MHRSalaryRange.getByValue(getCtx(), importEmployee.getSalaryRangeValue());
    if (salaryRange != null && salaryRange.getHR_SalaryRange_ID() > 0)
        importEmployee.setHR_SalaryRange_ID(salaryRange.getHR_SalaryRange_ID());
    // Set Employee Type
    MHREmployeeType employeeType = null;
    if (importEmployee.getHR_EmployeeType_ID() > 0)
        employeeType = MHREmployeeType.getById(getCtx(), importEmployee.getHR_EmployeeType_ID());
    if (employeeType == null && importEmployee.getEmployeeTypeValue() != null)
        employeeType = MHREmployeeType.getByValue(getCtx(), importEmployee.getEmployeeTypeValue());
    if (employeeType == null || employeeType.getHR_EmployeeType_ID() < 0) {
        if (importEmployee.getEmployeeTypeValue() != null && importEmployee.getEmployeeTypeName() != null && payroll != null && payroll.getHR_Payroll_ID() > 0) {
            employeeType = new MHREmployeeType(getCtx(), importEmployee.getEmployeeTypeValue(), importEmployee.getEmployeeTypeName(), MHREmployeeType.WAGELEVEL_Daily, payroll.getHR_Payroll_ID(), trxName);
            employeeType.saveEx();
        }
    }
    if (employeeType != null && employeeType.getHR_EmployeeType_ID() > 0)
        importEmployee.setHR_EmployeeType_ID(employeeType.getHR_EmployeeType_ID());
    // Set Skill Type
    MHRSkillType skillType = null;
    if (importEmployee.getHR_SkillType_ID() > 0)
        skillType = MHRSkillType.getById(getCtx(), importEmployee.getHR_SkillType_ID());
    if (skillType == null && importEmployee.getSkillTypeValue() != null)
        skillType = MHRSkillType.getByValue(getCtx(), importEmployee.getSkillTypeValue());
    if (skillType == null || skillType.getHR_SkillType_ID() < 0) {
        if (importEmployee.getSkillTypeValue() != null && importEmployee.getSkillTypeName() != null) {
            skillType = new MHRSkillType(getCtx(), importEmployee.getSkillTypeValue(), importEmployee.getSkillTypeName(), trxName);
            skillType.saveEx();
        }
    }
    if (skillType != null && skillType.getHR_SkillType_ID() > 0)
        importEmployee.setHR_SkillType_ID(skillType.getHR_SkillType_ID());
    if (importEmployee.getAD_Org_ID() <= 0)
        stringError.append(" @AD_Org_ID@ @IsMandatory@");
    if (importEmployee.getC_BPartner_ID() <= 0)
        stringError.append(" @C_BPartner_ID@ @IsMandatory@,");
    if (importEmployee.getHR_Department_ID() <= 0)
        stringError.append(" @HR_Department_ID@ @NotFound@,");
    if (importEmployee.getHR_Job_ID() <= 0)
        stringError.append(" @HR_Job_ID@ @NotFound@,");
    if (importEmployee.getStartDate() == null)
        stringError.append(" @StartDate@ @IsMandatory@ ");
    if (!stringError.toString().isEmpty() && stringError.toString().length() > 0) {
        importEmployee.setI_ErrorMsg(Msg.parseTranslation(getCtx(), stringError.toString()));
        importEmployee.saveEx();
    }
    importEmployee.saveEx();
}
Also used : MHRPayroll(org.eevolution.model.MHRPayroll) MHRGrade(org.eevolution.model.MHRGrade) MActivity(org.compiere.model.MActivity) MHRDepartment(org.eevolution.model.MHRDepartment) MHRDesignation(org.eevolution.model.MHRDesignation) MHRRace(org.eevolution.model.MHRRace) MProject(org.compiere.model.MProject) MHREmployeeType(org.eevolution.model.MHREmployeeType) MHRJob(org.eevolution.model.MHRJob) MSalesRegion(org.compiere.model.MSalesRegion) MCampaign(org.compiere.model.MCampaign) MBPartner(org.compiere.model.MBPartner) MHRSalaryRange(org.eevolution.model.MHRSalaryRange) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRShiftGroup(org.eevolution.model.MHRShiftGroup) MHRWorkGroup(org.eevolution.model.MHRWorkGroup) MHRDegree(org.eevolution.model.MHRDegree) MOrg(org.compiere.model.MOrg) MHRSalaryStructure(org.eevolution.model.MHRSalaryStructure) MHRJobEducation(org.eevolution.model.MHRJobEducation) MHRJobType(org.eevolution.model.MHRJobType) MHRSkillType(org.eevolution.model.MHRSkillType) MHRCareerLevel(org.eevolution.model.MHRCareerLevel)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MActivity (org.compiere.model.MActivity)1 MBPartner (org.compiere.model.MBPartner)1 MCampaign (org.compiere.model.MCampaign)1 MOrg (org.compiere.model.MOrg)1 MProject (org.compiere.model.MProject)1 MSalesRegion (org.compiere.model.MSalesRegion)1 MHRCareerLevel (org.eevolution.model.MHRCareerLevel)1 MHRDegree (org.eevolution.model.MHRDegree)1 MHRDepartment (org.eevolution.model.MHRDepartment)1 MHRDesignation (org.eevolution.model.MHRDesignation)1 MHREmployeeType (org.eevolution.model.MHREmployeeType)1 MHRGrade (org.eevolution.model.MHRGrade)1 MHRJob (org.eevolution.model.MHRJob)1 MHRJobEducation (org.eevolution.model.MHRJobEducation)1 MHRJobType (org.eevolution.model.MHRJobType)1 MHRPayroll (org.eevolution.model.MHRPayroll)1 MHRRace (org.eevolution.model.MHRRace)1 MHRSalaryRange (org.eevolution.model.MHRSalaryRange)1 MHRSalaryStructure (org.eevolution.model.MHRSalaryStructure)1