Thursday, 20 April 2017

Employee Integrations

Employee   Integrations



class AifEmployeeService
{

}




[SysEntryPointAttribute(true), AifCollectionTypeAttribute('_EMPContract',Types::Class)]
public void EmployeeSave(AifEmployeeContract _EMPContract)
{
        str                                         ErrorMessage;
        DirPerson                                   dirPerson;
        HcmEmployment                               HcmEmployment,hcmEmploymentFuture;
        Dirpersonname                               dirpersonname;
        HcmWorker                                   hcmWorker;
        Company                                     Company;
        ValidFromDateTime                           employmentStartDateTime;
        ValidToDateTime                             employmentEndDateTime;
        HcmWorkerBankAccount                        hcmWorkerBankAccount;



        ;

    try
    {
        changeCompany (_EMPContract.Company())
        {
             ErrorMessage = this.ValidateEmployee(_EMPContract);
            if(ErrorMessage != "")
            {
                throw Error(strFmtLB(ErrorMessage));
            }
            else
            {
                ttsBegin;
            // fill the worker Names

                hcmWorker = HcmWorker::findByPersonnelNumber(_EMPContract.PersonnelNumber(),true);
                if(!hcmWorker.RecId)  //If PersonnelNumber is not existing the initialize
                {
                    dirperson.Name      = _EMPContract.Name();
                    dirperson.NameAlias = _EMPContract.Name();
                    DirPerson.insert();

                    dirPersonName =  DirPersonName::find(dirPerson.RecId,true);
                    [dirPersonName.FirstName, dirPersonName.MiddleName, dirPersonName.LastName] = DirPerson::splitNameParts(_EMPContract.Name());
                    dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);


                    DirPersonName.Person        = dirPerson.RecId;
                    DirPersonName.ValidFrom     = DateTimeUtil::newDateTime(today(),0);
                    DirPersonName.ValidTo       = DateTimeUtil::maxValue();
                    dirpersonname.insert();

                    hcmWorker.PersonnelNumber = _EMPContract.PersonnelNumber();
                    hcmWorker.Person=dirPerson.RecId;
                    hcmWorker.insert();

                        // Hcm Employement Table Data
                    HcmEmployment.EmploymentType = HcmEmploymentType::Employee;
                    HcmEmployment.LegalEntity = CompanyInfo::find().RecId;
                    HcmEmployment.ValidFrom     = DateTimeUtil::newDateTime(today(),0);
                    HcmEmployment.ValidTo       = DateTimeUtil::maxValue();
                    //HcmEmployment.ValidFrom     = _EMPContract.employmentStartDateTime();
                    HcmEmployment.Worker=hcmWorker.RecId;
                    HcmEmployment.insert();
                }
                else
                {

                    dirPersonName =  DirPersonName::find(hcmWorker.Person,true);
                    [dirPersonName.FirstName, dirPersonName.MiddleName, dirPersonName.LastName] = DirPerson::splitNameParts(_EMPContract.Name());
                    dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                    DirPersonName.ValidFrom     = DateTimeUtil::newDateTime(today(),0);
                    DirPersonName.ValidTo       = DateTimeUtil::maxValue();
                    //DirPersonName.ValidFrom     = _EMPContract.();
                    dirpersonname.update();

                    dirperson           = DirPerson::find(DirPersonName.Person);
                    dirperson.Name      = _EMPContract.Name();
                    dirperson.NameAlias = _EMPContract.Name();
                    DirPerson.update();
                }



              // HcmWorker Bank Account  Details
                select hcmworkerbankaccount;
                if(!hcmworkerbankaccount.AccountId)
                {
                    hcmworkerbankaccount.AccountId  = _EMPContract.EmpAccountId();
                    hcmworkerbankaccount.AccountNum = _empcontract.EmpAccountNum();
                    hcmworkerbankaccount.name       = _empcontract.EmpName();
                    hcmworkerbankaccount.Worker     = hcmWorker.RecId;
                    hcmworkerbankaccount.insert();
                }
                else
                {
                        //update HcmWorker Bank Account  Details
                    select  forUpdate hcmworkerbankaccount
                        where  hcmworkerbankaccount.AccountId ==  _empcontract.EmpAccountId();
                    if(hcmworkerbankaccount.AccountId == _EMPContract.EmpAccountId())
                    {
                        //ttsBegin;
                        hcmworkerbankaccount.AccountId  = _EMPContract.EmpAccountId();
                        hcmworkerbankaccount.AccountNum = _empcontract.EmpAccountNum();
                        hcmworkerbankaccount.name       = _empcontract.EmpName();
                        hcmworkerbankaccount.Worker     = hcmWorker.RecId;
                        hcmworkerbankaccount.update();
                        // ttsCommit;
                    }
                }



            }
            ttsCommit;


        }
    }
    catch (Exception::Error)
    {
        ttsAbort;
        throw Exception::Error;

    }
}


private str ValidateEmployee(AifEmployeeContract _EMPContract)
{
    boolean valid = true;

    str Message = "";
    if(_EMPContract.Name() == "")
    {
        Message = Message + "Name  is required!\n";
        valid = false;
    }

    if(_EMPContract.PersonnelNumber() == "")
    {
        Message = Message + "PersonnelNumber  is required!\n";
        valid = false;
    }

    if(_EMPContract.EmpAccountNum() == "")
    {
        Message = Message + "Employee Bank AccountNumber  is required!\n";
        valid = false;
    }

     if(_EMPContract.EmpName() == "")
    {
        Message = Message + "Employee Name  is required!\n";
        valid = false;
    }


    return Message;
}

 Calling   job



static void job_Employeeinsert(Args _args)
{
    AifEmployeeContract        aifEmployeeContract;
     AifEmployeeService      aifEmployeeService;

    AifEmployeeContract = new AifEmployeeContract();
     AifEmployeeService = new AifEmployeeService();



    aifEmployeeContract.PersonnelNumber('');
    aifEmployeeContract.Name ('');
   aifEmployeeContract.EmpName("");
    aifEmployeeContract.EmpAccountNum("2");
    aifEmployeeContract.AccountId("");



    aifEmployeeContract.Company("");



     aifEmployeeService.EmployeeSave(aifEmployeeContract);
     info(aifEmployeeContract.PersonnelNumber());


}

No comments:

Post a Comment