public class NW_VendorHelper { public static str CreateVendor(NW_VendorReg VendorReg) { VendTable vendTable; NumberSeq numberSeq; Name name = VendorReg.CompanyName; NA_VendTableWF NA_VendTableWF; DirParty dirParty; DirPartyTable dirPartyTable; DirPartyPostalAddressView dirPartyPostalAddressView; DirPartyContactInfoView dirPartyContactInfo, _dirPartyContactInfo; ContactPerson contactPerson; ContactPersonSyncEntity contactPersonSyncEntity; NW_VendorRegContact NW_VendorRegContact; ; //container conAttribute=["BusinessUnit","CostCenter","Department"]; //container conAttributeValue=["001","007","022"]; /* Marks the beginning of a transaction. Necessary to utilize the method numRefCustAccount() */ try { //vendTable ttsBegin; vendTable.initValue(); vendTable.AccountNum = NumberSeq::newGetNum(VendParameters::numRefVendAccount()).num(); vendTable.TaxWithholdVendorType_TH =VendorReg.CompanyType; if(VendorReg.CompanyType == TaxWithholdVendorType_TH::Domestic) { vendTable.CR=VendorReg.CRNumStr; } else if(VendorReg.CompanyType == TaxWithholdVendorType_TH::Individual) { vendTable.CR=int2Str(VendorReg.LicenseNumber); } if(VendorReg.CompanyType == TaxWithholdVendorType_TH::Foreign) { vendTable.CR=VendorReg.Tin; } vendTable.VATNumber =VendorReg.VATNumStr;//int2Str(VendorReg.VATNumber); vendTable.VendGroup = "Other Supp"; vendTable.Currency ='SAR'; vendTable.PaymTermId ='1 Day'; vendTable.PaymMode ='CHECK'; vendTable.APIOfficialContactEmail =VendorReg.OfficialContactEmail; // vendTable.WorkflowStateNew = TradeWorkflowState::Completed; NA_VendTableWF.AccountNum=Vendtable.AccountNum; NA_VendTableWF.WorkflowStateNew= TradeWorkflowState::Completed; NA_VendTableWF.insert(); //vendTable.DefaultDimension=DefaultDimesnionHelper::createDefaultDimension(conAttribute,conAttributeValue); vendTable.insert(); NW_VendorRegContact = VendorReg.VendorRegContact(); dirPartyTable = DirPartyTable::findRec(vendTable.Party,true); dirPartyTable.Name = name; dirPartyTable.DEL_FirstName = NW_VendorRegContact.ContactFirstName; dirPartyTable.DEL_MiddleName = NW_VendorRegContact.ContactLastName; dirPartyTable.DEL_LastName = NW_VendorRegContact.ContactLastName; //dirPartyTable.update(); dirPartyTable.doUpdate(); contactPersonSyncEntity = ContactPersonSyncEntity::construct(contactPerson); contactPersonSyncEntity.parmFirstName(NW_VendorRegContact.ContactFirstName); //contactPersonSyncEntity.parmMiddleName(""); contactPersonSyncEntity.parmLastName(NW_VendorRegContact.ContactLastName); //contactPersonSyncEntity.parmLastNamePrefix(""); contactPersonSyncEntity.parmContactForParty(dirPartyTable.RecId); contactPersonSyncEntity.parmSensitivity(smmSensitivity::Personal); contactPersonSyncEntity.write(); //DirParty /* Creates a new instance of the DirParty class from an address book entity that is represented by the custTable parameter. */ dirParty = DirParty::constructFromCommon(vendTable); dirPartyPostalAddressView.LocationName = VendorReg.AddressName; dirPartyPostalAddressView.City = VendorReg.City; dirPartyPostalAddressView.Street = VendorReg.StreetName; //dirPartyPostalAddressView.StreetNumber = '18'; dirPartyPostalAddressView.CountryRegionId = VendorReg.Country; dirPartyPostalAddressView.ZipCode = VendorReg.ZipPostalCode; dirPartyPostalAddressView.DistrictName = VendorReg.District; dirPartyPostalAddressView.BuildingCompliment = VendorReg.BuildingNo; dirPartyPostalAddressView.Building_RU = VendorReg.BuildingNo; //dirPartyPostalAddressView.State = VendorReg; dirPartyPostalAddressView.IsPrimary = NoYes::Yes; // Fill address dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView); dirPartyContactInfo.LocationName ='Email Address'; dirPartyContactInfo.Locator =VendorReg.OffcialCompanyEmail; dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Email; dirPartyContactInfo.IsPrimary = NoYes::Yes; // Fill Contacts dirParty.createOrUpdateContactInfo(dirPartyContactInfo); _dirPartyContactInfo.LocationName ='Email Address '; _dirPartyContactInfo.Locator =VendorReg.OffcialCompanyEmail; _dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Email; _dirPartyContactInfo.IsPrimary = NoYes::Yes; contactPersonSyncEntity.createOrUpdateContactInfo(_dirPartyContactInfo); dirPartyContactInfo.clear(); _dirPartyContactInfo.clear(); dirPartyContactInfo.LocationName ='Mobile Number'; dirPartyContactInfo.Locator =VendorReg.MobileNumber; dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Phone; dirPartyContactInfo.IsPrimary = NoYes::Yes; // Fill Contacts dirParty.createOrUpdateContactInfo(dirPartyContactInfo); _dirPartyContactInfo.LocationName ='Mobile Number '; _dirPartyContactInfo.Locator =VendorReg.MobileNumber; _dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Phone; _dirPartyContactInfo.IsPrimary = NoYes::Yes; contactPersonSyncEntity.createOrUpdateContactInfo(_dirPartyContactInfo); // Marks the end of transaction. vendTable.ContactPersonId = contactPerson.ContactPersonId; vendTable.update(); VendVendorBankAccountEntity VVBE; VVBE.VendorAccountNumber = Vendtable.AccountNum; VVBE.BankName = VendorReg.BankName; VVBE.name=VendorReg.BankName; VVBE.AddressCountry = VendorReg.BankCounty; VVBE.AddressCity = VendorReg.BankCity; VVBE.AddressPostBox = VendorReg.BankPostBox; VVBE.AddressStreet = VendorReg.BankStreet ;//+" " + VendorReg.BankOther; VVBE.AddressDistrictName = VendorReg.BankDistrictName; if(VendorReg.SWIFTCode!="") { VVBE.BankGroupId = VendorReg.SWIFTCode; } VVBE.IBAN = VendorReg.IBAN; VVBE.addresstype = VendorReg.BankAddressType; VVBE.AddressDescription=VendorReg.BankAddressName; VVBE.AddressBuildingCompliment = VendorReg.BankBuildingNumber; VVBE.BankAccountNumber = VendorReg.AccountNum; VVBE.AddressZipCode = VendorReg.BankZipCode; VVBE.BeneficaryBankNb=VendorReg.IBAN; // VVBE.CurrentCurrencyCode=vr.CurrencyCode; VVBE.WorkflowState=VendBankAccountChangeProposalWorkflowState::Approved; VVBE.insert(); if(VendorReg.BankAccountDetailsStr && VendorReg.BankAccountDetailsName) { NW_AttachmentAPIHelper::AttachFileFromAPI(VendorReg.BankAccountDetailsName, VendorReg.BankAccountDetailsStr, tableNum(VendBankAccount) , VVBE.RecId); } if(VendorReg.VatCertificateStr && VendorReg.VatCertificateName ) { NW_AttachmentAPIHelper::AttachFileFromAPI(VendorReg.VatCertificateName, VendorReg.VatCertificateStr, tableNum(VendTable) , Vendtable.RecId); } if(VendorReg.CompanyRegDocumentStr && VendorReg.CompanyRegDocumentName) { NW_AttachmentAPIHelper::AttachFileFromAPI(VendorReg.CompanyRegDocumentName, VendorReg.CompanyRegDocumentStr, tableNum(VendTable), Vendtable.RecId); } if(VendorReg.OtherStr && VendorReg.OtherName) { NW_AttachmentAPIHelper::AttachFileFromAPI(VendorReg.OtherName , VendorReg.OtherStr, tableNum(VendTable) , Vendtable.RecId); } ttsCommit; return vendTable.AccountNum; } catch(Exception::Error) { ttsAbort; throw Exception::Error; } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter