Thursday, 20 April 2017

Vendor Integrations

Vendor     Integrations


class AifVendorService
{
}



[SysEntryPointAttribute(true), AifCollectionTypeAttribute('vendContract',Types::Class)]
public void SaveVendor(AifVendorContract _vendContract)
{
    VendTable                   vendTable;
    //NumberSeq                   numberSeq;
    str                         ErrorMessage;
    DirParty                    dirParty;
    DirPartyTable               dirPartyTable;
    DirPerson                   dirPerson;
    DirPersonName               dirPersonName;
    Company                     company;
    VendBankAccount             VendBankAccount;
    VendBankAccount              expiryDate;
    utcdatetime                 activedate  ;



        ErrorMessage = this.Validatevendor(_vendContract);
        if(ErrorMessage != "")
        {
            throw Error(strFmtLB(ErrorMessage));
        }
    try
        changeCompany (_vendContract.Company())

        {
            ttsBegin;
            vendTable = vendTable::find(_vendContract.AccountNum(), true);
            if(!vendTable.RecId)  //If vendor is not existing the initialize
            {
                vendTable.initValue();
                vendTable.AccountNum    = _vendContract.AccountNum();
                vendTable.vendGroup     = _vendContract.vendGroup();
                vendTable.Currency      = _vendContract.Currency();
                vendTable.DlvMode       = _vendContract.DlvMode();
                vendTable.SegmentId     = _vendContract.segmentId();
                vendTable.SubsegmentId  = _vendContract.subsegmentId();
                dirParty = DirParty::constructFromCommon(vendTable);

                dirPartyTable = DirPartyTable::createNew(_vendContract.PartyType(),_vendContract.Name());
                dirPartyTable.Name  = _vendContract.Name();
                dirPartyTable.NameAlias  = _vendContract.Name();
                vendTable.Party = dirPartyTable.RecId;
                vendTable.insert();

            }
            else
            {
                vendTable.AccountNum    = _vendContract.AccountNum();
                vendTable.vendGroup     = _vendContract.vendGroup();
                vendTable.Currency      = _vendContract.Currency();
                vendTable.DlvMode       = _vendContract.DlvMode();
                vendTable.SegmentId     = _vendContract.segmentId();
                vendTable.SubsegmentId  = _vendContract.subsegmentId();
                vendTable.update();
            }

             // fill Names
            if(!vendTable.Party)
            {
              vendTable.Party         = DirPartyTable::createNew(_vendContract.PartyType(), _vendContract.Name()).RecId;
            }

            dirPartyTable = DirPartyTable::findRec(vendTable.Party, true, _vendContract.PartyType());
            // For Updating Person Name if the Party Type is Organization.
            if (dirPartyTable.RecId && _vendContract.PartyType() == DirPartyType::Organization)
            {
                dirPartyTable.Name      = _vendContract.Name();
                dirPartyTable.NameAlias = _vendContract.Name();
                dirPartyTable.update();
            }
            // For Updating Person Name if the Party Type is Person.
            else if (dirPartyTable.RecId && _vendContract.PartyType() == DirPartyType::Person)
           {
                dirPerson = DirPerson::find(dirPartyTable.RecId,true);
                dirPerson.Name = _vendContract.Name();
                dirPerson.NameAlias = _vendContract.Name();
                dirPerson.update();

                //Update Person Name individually
                dirPersonName =  DirPersonName::find(dirPerson.RecId,true);
                [dirPersonName.FirstName, dirPersonName.MiddleName, dirPersonName.LastName] = DirPerson::splitNameParts(_vendContract.Name());
                dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                dirPersonName.ValidFrom = DirUtility::getCurrentDateTime();
                dirPersonName.ValidTo = DateTimeUtil::maxValue();
                if (dirPersonName.validateWrite())
                {
                    dirPersonName.update();
                }
            }

                // vendoer Bank Account Detailes  create and update
                    select VendBankAccount;
                     if(!VendBankAccount.VendAccount)
                {
                        VendBankAccount.AccountID = _vendContract.VendAccountID();
                        VendBankAccount.AccountNum = _vendContract.VendAccount();
                        VendBankAccount.BankIBAN    = _vendContract.BankIBAN();
                        VendBankAccount.Name        = _vendContract.VendName();
                        VendBankAccount.SWIFTNo     = _vendContract.SWIFTNo();
                        VendBankAccount.ActiveDate     = DateTimeUtil::newDateTime(today(),0);
                        VendBankAccount.ExpiryDate       = DateTimeUtil::maxValue();
                        VendBankAccount.VendAccount =  vendtable.AccountNum;
                        VendBankAccount.insert();
                }

                else
                {
                    select  forUpdate vendBankAccount
                    where  vendBankAccount.VendAccount ==  _vendContract.VendAccount();
                        //&& vendBankAccount.AccountID == _vendContract.vendAccountID();
                    if(vendBankAccount.VendAccount)
                {

                        VendBankAccount.AccountID = _vendContract.VendAccountID();
                        VendBankAccount.AccountNum = _vendContract.VendAccount();
                        VendBankAccount.BankIBAN    = _vendContract.BankIBAN();
                        VendBankAccount.Name        = _vendContract.VendName();
                        VendBankAccount.SWIFTNo     = _vendContract.SWIFTNo();
                        VendBankAccount.VendAccount =  vendtable.AccountNum;
                        VendBankAccount.update();

                }
            }

            ttsCommit;

            this.VendorAddress(_vendContract);
        }
//}
    catch (Exception::Error)
    {
        ttsAbort;
        throw Exception::Error;
    }
}






 vendor  Address 
[SysEntryPointAttribute(true), AifCollectionTypeAttribute('vendContract',Types::Class)]
public void VendorAddress(AifVendorContract _vendContract)
{



        VendTable                   vendTable;

        str                         ErrorMessage;
        DirParty                    dirParty;
        DirPartyPostalAddressView   dirPartyPostalAddressView;
        DirPartyContactInfoView     dirPartyContactInfo;
        DirPartyTable               dirPartyTable;


             try
         {
             ttsBegin;
            vendTable = vendTable::find(_vendContract.AccountNum(), true);
            if(!vendTable.RecId)
            {
                vendTable.initValue();
            }

            dirParty = DirParty::constructFromCommon(vendTable);
             // Fill address
            select dirPartyPostalAddressView
            where  dirPartyPostalAddressView.IsPrimary   == NoYes::Yes
                && dirPartyPostalAddressView.CountryRegionId == _vendContract.CountryCode()
                && dirPartyPostalAddressView.Party == vendTable.Party;


            dirPartyPostalAddressView.LocationName      = _vendContract.Name();
            dirPartyPostalAddressView.City              = _vendContract.City();
            dirPartyPostalAddressView.Street            = _vendContract.Street();
            dirPartyPostalAddressView.StreetNumber      = _vendContract.StreetNumber();
            dirPartyPostalAddressView.CountryRegionId   = _vendContract.CountryCode();
            dirPartyPostalAddressView.Party             = vendTable.Party;

            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

            // Fill Phone Number
            dirPartyContactInfo.clear();
              select dirPartyContactInfo
            where dirPartyContactInfo.IsPrimary       == NoYes::Yes
                && dirPartyContactInfo.Type            == LogisticsElectronicAddressMethodType::Phone
                && dirPartyContactInfo.Party == vendTable.Party;

            dirPartyContactInfo.LocationName    =_vendContract.Name();
            dirPartyContactInfo.Locator         =_vendContract.Phone();
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Party             =vendTable.Party;
            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

            //Fill EmailId
            dirPartyContactInfo.clear();
            select dirPartyContactInfo
            where dirPartyContactInfo.IsPrimary == NoYes::Yes
                && dirPartyContactInfo.Type     == LogisticsElectronicAddressMethodType::Email
                && dirPartyContactInfo.Party    == vendTable.Party
                ;
            dirPartyContactInfo.LocationName    = _vendContract.Name();
            dirPartyContactInfo.Locator         = _vendContract.EmailID();
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Party           = vendTable.Party;
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
            // Marks the end of transaction.
            ttsCommit;

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


}

//}


Validatevendor

private str Validatevendor(AifVendorContract _vendContract)
{
    boolean valid = true;

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

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

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

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

    if(!LogisticsAddressCountryRegion::exist(_vendContract.CountryCode()))
    {
        Message = Message + "CountryCode does not exits!\n";
        valid = false;
    }

    if(!VendGroup::exist(_vendContract.VendGroup()))
    {
        Message = Message + "Vendor group does not exits!\n";
        valid = false;
    }

    return Message;
}

calling Job

static void job_vendorInsert(Args _args)
{
    AifVendorContract     aifVendorContract;
    AifVendorService      aifVendorService;

    aifVendorContract = new AifVendorContract();
    aifVendorService  = new AifVendorService();



    aifVendorContract.AccountNum('QAT11250124');
    aifVendorContract.vendGroup ('EM');
    aifVendorContract.Currency('INR');
    aifVendorContract.Name('pramod Kn kumar1');
    aifVendorContract.DeliveryMode('1');
    aifVendorContract.DeliveryTerm('1');
    aifVendorContract.DlvMode('1');
    aifVendorContract.identificationNumber('2');
    aifVendorContract.lineOfBusinessId('1');
    aifVendorContract.segmentId('1');
    aifVendorContract.subsegmentId('1');
    aifVendorContract.CountryCode('IND');
    aifVendorContract.Street('Kerala1');
    aifVendorContract.City('Tellicherry');
    aifVendorContract.StreetNumber("30th Street");
    aifVendorContract.Phone("1234567");
    aifVendorContract.EmailID('"');
    aifVendorContract.vendAccountID("QAT11250122");
    aifVendorContract.vendName      (" ");
    aifVendorContract.VendAccount("1241571118");
    aifVendorContract.vendAccountNum("1241151178");
    aifVendorContract.SWIFTNo("12411115178");
    aifVendorContract.BankIBAN("12431111578");


    aifVendorContract.Company("QAT");
    aifVendorContract.PartyType(DirPartyType::Person);

    AifVendorService.SaveVendor(aifVendorContract);
    //AifVendorService.VendorBank(aifVendorContract);
   // AifVendorService.VendorAddress(aifVendorContract);
    info(aifVendorContract.AccountNum());

}




No comments:

Post a Comment