Sunday, October 26, 2014

All Master Data Import:



Master Data Import:

Chart of Account Import:
   ChartOfAccountsService                      chartOfAccountsService;
    MainAccountContract                         mainAccountContract;
    CommaTextIo                                 file;
    container                                   rec;
    Name                                        ledgerChartOfAccountsName;
    MainAccountNum                              mainAccountId;
    DimensionLedgerAccountType                  dimensionledgerAccountType;
    MainAccountCategory                         MainAccountCategory;
    MainAccount                                 MainAccount;
    DimensionAttribute                          mainAccountDimAttribute;
    DimensionAttributeValue                     dimensionAttributeValue;
    DimensionAttributeValueTotallingCriteria    totalCriteria;
    AccountCategory                             _accountCategory;
    str                                         strOfAccounts, fromA, toA,MainAccountName;
    int                                         sep;
    //container                                   readCon;
    //counter                                     icount,inserted;
    ;
    csvFiles = new CommaIO(filename, 'r');
    try
    {
        if (csvFiles)
        {
            ttsbegin;
            readCon = csvFiles.read();
            while (csvFiles.status() == IO_Status::OK)
            {
                readCon = csvFiles.read();
                if(readCon)
                {
                    mainAccountId = conPeek(readCon, 1);//strlrTrim(
                    mainAccountName = conPeek(readCon, 2);
                    dimensionledgerAccountType = conPeek(readCon, 3);
                    _accountCategory = conPeek(readCon,4);
                    if(!mainAccountId)
                    continue;
                    if (!mainAccount::findByMainAccountId( mainAccountId , false, LedgerChartOfAccounts::findByName(ledgerChartOfAccountsName).RecId))
                    {
                        mainAccountContract = new MainAccountContract();
                        mainAccountContract.parmMainAccountId( mainAccountId );
                        mainAccountContract.parmName(mainAccountName);
                        mainAccountContract.parmLedgerChartOfAccounts(ChartOfAccountsName);
                        mainAccountContract.parmType(enum2int(dimensionledgerAccountType::Expense));
                        select firstonly mainAccountCategory where mainAccountCategory.AccountCategory == _accountCategory;
                        MainAccountContract.parmAccountCategoryRef(mainAccountCategory.AccountCategoryRef);
                        chartOfAccountsService = new ChartOfAccountsService();
                        chartOfAccountsService.createMainAccount(mainAccountContract);
                    }
                }
            }

        }
        ttsCommit;
        icount--;//Remove header recount from total record count
        info("Succesfully imported");
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }


//
//
Bank Account Import:

BankAccountTable    bankAccountTable;
    AxBankAccountTable  header = new AxBankAccountTable();
    str 60 accountnum,accountName,BankGroupId,RegistrationNum,IBAN,SWIFTNo,currenycode,ledgerAccount,dimensn,AccountId;
    container  dimm;
    BankGroup   bankGroup;
    csvFiles = new CommaIO(filename, 'r');
    try
    {
        if (csvFiles)
        {
            ttsbegin;
            readCon = csvFiles.read();
            while (csvFiles.status() == IO_Status::OK)
            {
                readCon = csvFiles.read();
                if(readCon)
                {
                    icount++;
                    accountnum = conPeek(readCon,1);
                    accountName = conPeek(readCon,2);
                    AccountId = conPeek(readCon,3);
                    BankGroupId = conPeek(readCon,4);
                    RegistrationNum = conPeek(readCon,5);
                    IBAN = conPeek(readCon,6);
                    SWIFTNo = conPeek(readCon,7);
                    currenycode = conPeek(readCon,8);
                    ledgerAccount = conPeek(readCon,9);
                    //bankAccountTable
                    header.parmAccountID(AccountId);
                    header.parmAccountNum(AccountNum);
                    header.parmName(accountName);
                    header.parmBankGroupId(BankGroupId);
                    select bankGroup where bankGroup.BankGroupId == BankGroupId;
                    header.parmRegistrationNum(bankGroup.RegistrationNum);
                    header.parmIBAN(IBAN);
                    header.parmSWIFTNo(SWIFTNo);
                    header.parmCurrencyCode(bankGroup.CurrencyCode);
                    dimensn = strFmt("%1,%1",LedgerAccount);//strFmt("%1-%2-%3,%1,2,department,%2,costcenter,%3",ledgerAccount,department,costcenter);
                    dimm = str2con(dimensn);
                    header.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(dimm));
                    //header.parmAccountType(LedgerJournalACTypE::Ledger);
                    header.save();
                }
            }
            ttsCommit;
        }
        icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
//
//

Customer Master Import:

//CommaTextIO         csvFiles;
    //container                   readCon;
    //counter                     icount,inserted;
    Dialog                      dialog;
    DialogField               dfFileName;
    str AccountNum,CustGroup,Currency,DlvMode,PaymTermId,state,zipcode,street,countryRegionId,city,PhoneNumber,FaxNumber,Website,Email;
    //FileName                    fileName;
    Name                        name;
    DirPartyContactInfoView     contactView;
    CustTable                            CustTable;
    DirParty                               dirParty;
    DirPartyRecId                      partyRecId;
    LogisticsPostalAddress        address;
    DirPartyPostalAddressView addressView;
    inserted =0;
    #File
     csvFiles = new CommaIO(filename, 'r');
     //csvFiles.inFieldDelimiter(',');
        readCon = csvFiles.read();
    try
    {
       ttsBegin;
        while(csvFiles.status() == IO_Status::OK)
        {
            readCon = csvFiles.read();

            if(readCon)
            {
                icount++;
                //str AccountNum,CustGroup,Currency,DlvMode,PaymTermId,state,zipcode,street,countryRegionId,city,PhoneNumber,FaxNumber,Website,Email;
                AccountNum  = conPeek(readCon,1);
                name        = conPeek(readCon,2);
                CustGroup       = conPeek(readCon,3);
                Currency        = conPeek(readCon,4);
                DlvMode         = conPeek(readCon,5);
                PaymTermId      = conPeek(readCon,6);
                CountryRegionId = conPeek(readCon,7);
                State           = strLRTrim(conPeek(readCon,8));
                ZipCode         = strLRTrim(conPeek(readCon,9));
                Street          = strLRTrim(conPeek(readCon,10));
                City            = strLRTrim(conPeek(readCon,11));
                PhoneNumber     = conPeek(readCon,12);
                FaxNumber       = conPeek(readCon,13);
                Email           = conPeek(readCon,14);
                Website         = conPeek(readCon,15);
                partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
                custTable.clear();
                custTable.initValue();
                custTable.Party      = partyRecId;
                custTable.AccountNum = AccountNum;//conPeek(readCon,1);
                custTable.CustGroup  = CustGroup;//conPeek(readCon,3);
                custTable.Currency   = Currency;//conPeek(readCon,7);
                custTable.DlvMode    = DlvMode;//conPeek(readCon,8);
                custTable.PaymTermId = PaymTermId;//conPeek(readCon,9);
                custTable.insert();
                custTable = Custtable::find(AccountNum);
                partyRecId = custTable.Party;
                DirParty = DirParty::constructFromPartyRecId(partyRecId );
                address.clear();                //address.PostBox = strLRTrim(conPeek(readCon,13));
                address.CountryRegionId = CountryRegionId;//strLRTrim(conPeek(readCon,5));
                if( address.CountryRegionId != "")
                {
                    address.State = State;//strLRTrim(conPeek(readCon,15));
                    address.ZipCode = ZipCode;//strLRTrim(conPeek(readCon,15));
                    address.Street  = Street;//strLRTrim(conPeek(readCon,4));
                    address.City    = City;//strLRTrim(conPeek(readCon,18));

                    //address.Address =  conPeek(readCon,4);

                    addressView.LocationName = "Address";
                    addressView.IsPrimary = NoYes::Yes;
                    addressView.Party = partyRecId;
                    addressview.initFromPostalAddress(address);


                    DirParty = DirParty::constructFromPartyRecId(addressView.Party );
                    DirParty.createOrUpdatePostalAddress(addressView);
                }

                contactView.clear();

                if(conPeek(readCon,5) != "")
                {
                    contactView.LocationName = "Phone Number";
                    contactView.Locator      = strLRTrim(PhoneNumber);
                    contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                    contactView.Party        = partyRecId;
                    contactView.IsPrimary    = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                }

                if(conPeek(readCon,3) != "")
                {
                    contactView.LocationName = "Fax Number";
                    contactView.Locator      = strLRTrim(FaxNumber);
                    contactView.Type         = LogisticsElectronicAddressMethodType::Fax;
                    contactView.Party        = partyRecId;
                    contactView.IsPrimary    = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                }

                if(conPeek(readCon,4) != "")
                {
                    contactView.LocationName = "Website";
                    contactView.Locator      = strLRTrim(Website);
                    contactView.Type         = LogisticsElectronicAddressMethodType::URL;
                    contactView.Party        = partyRecId;
                    contactView.IsPrimary    = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                }

                if(conPeek(readCon,6) != "")
                {
                    contactView.LocationName = "Email";
                    contactView.Locator      = strLRTrim(Email);
                    contactView.Type         = LogisticsElectronicAddressMethodType::Email;
                    contactView.Party        = partyRecId;
                    contactView.IsPrimary    = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                }

            }

        }
        ttsCommit;
        icount--;
        info("Succesfully imported");

    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

//
//
Fixed Asset import:
AssetId             assetid;
    AssetBookId     bookid;
    str AssetGroup,Name,NameAlias,UnitOfMeasure,Location;
    real  Quantity,UnitCost;
    AssetTable   assettable;

    inserted =0;

    #File

    csvFiles = new CommaIO(filename, 'r');
    //csvFiles.inFieldDelimiter(',');
    readCon = csvFiles.read();

    try
    {
        ttsBegin;
        while(csvFiles.status() == IO_Status::OK)
        {
            readCon = csvFiles.read();

            if(readCon)
            {
                icount++;

                AssetId = conPeek(readCon,2);
                select assettable where assettable.AssetId == assetid;
                if(!assettable)
                {
                    icount++;
                    AssetGroup = conPeek(readCon,1);
                    Name = conPeek(readCon,3);
                    NameAlias = conPeek(readCon,4);
                    Quantity = conPeek(readCon,5);
                    UnitOfMeasure = conPeek(readCon,6);
                    UnitCost = conPeek(readCon,7);
                    Location = conPeek(readCon,8);



                    assetTable.AssetId = assetid;
                    assetTable.AssetGroup = AssetGroup;//conPeek(readCon,1);
                    assetTable.Name = Name;//conPeek(readCon,3);
                    assetTable.NameAlias = NameAlias;//conPeek(readCon,4);
                    assetTable.AssetType = AssetType::Tangible;
                    assetTable.PropertyType = AssetPropertyType::FixedAsset;
                    assetTable.Quantity = Quantity;//conPeek(readCon,5);
                    assetTable.UnitOfMeasure = UnitOfMeasure;//conPeek(readCon,6);
                    assetTable.UnitCost = UnitCost;//conPeek(readCon,7);
                    assetTable.Location = Location;//conPeek(readCon,8);
                    assettable.insert();
                }
                else
                    info(strFmt("%1",assetid));

            }

        }
        ttsCommit;
        icount--;
        info("Succesfully imported");
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
//
//
Fixed Asset Value Model:
int                         Ccount;
    Struct                      struct;
    str PostingProfile,AssetGroup,VendAccount;
    DimensionDefault            DimensionDefault;
    real    LifeTimeRest,AcquisitionPrice,ServiceLife,price;
    TransDate   DepreciationStartDate,AcquisitionDate,usedfromdate;
    TransDate  LastDepreciationDate;
    int     lifetime;
    AssetId         assetid;
    AssetBookId     bookid;
    AssetBook   assetBook;
    container   ledgerDimension;
    str Depreciation;
    int i;
    inserted =0;
    #File
    csvFiles = new CommaIO(filename, 'r');
    //csvFile.inFieldDelimiter(',');
    readCon = csvFiles.read();
    try
    {
        ttsBegin;
        while(csvFiles.status() == IO_Status::OK)
        {
            readCon = csvFiles.read();

            if(readCon)
            {
                icount++;


                assetBook.clear();
                info(assetid);


                AssetGroup = conPeek(readCon,1);
                AssetId = conPeek(readCon,2);
                BookId = conPeek(readCon,3);
                AcquisitionDate = str2Date(conpeek(readCon,4),213);
                price = (conPeek(readCon,5));
                Depreciation = conPeek(readCon,6);
                DepreciationStartDate = str2Date(conPeek(readCon,7),213);
                LastDepreciationDate  = str2Date(conPeek(readCon,8),213);
                LifeTime  = conPeek(readCon,9);
                PostingProfile  = conPeek(readCon,10);
                ServiceLife  = conPeek(readCon,11);
                UsedFromDate = str2Date(conPeek(readCon,12),213);
                LifeTimeRest = conPeek(readCon,13);
                //assetBook = AssetBook::find(assetid,bookid,true);
                //select forUpdate assetBook where assetBook.AssetId == assetid;
                if(!assetBook)
                {
                    info(strFmt("%1",assetid));
                    continue;
                }
                assetBook.AssetGroup = AssetGroup;//conPeek(readCon,3);
                assetBook.Status = AssetStatus::NoAcquisition;
                /*
                if(conPeek(readCon,5) != "")//dimension value != ""
                {
                    struct = new Struct();
                    struct.add('Sector',conPeek(readCon,5));
                    struct.add('Division', conPeek(readCon,6));
                    struct.add('SubDivision', conPeek(readCon,7));
                    struct.add('Department', conPeek(readCon,8));

                    ledgerDimension = conNull();
                    ledgerDimension += struct.fields();

                    for (i = 1; i <= struct.fields(); i++)
                    {
                        ledgerDimension += struct.fieldName(i);
                        ledgerDimension += struct.valueIndex(i);
                    }

                    DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
                    assetBook.DefaultDimension = DimensionDefault;
                }*/



                assetbook.AcquisitionDate = AcquisitionDate;//str2Date(date1,213);
                assetbook.AcquisitionPrice = price;//conPeek(rec,3);
                assetbook.Depreciation = NoYes::Yes;//conPeek(readCon,3);
                assetbook.AssetGroup = AssetGroup;//conPeek(readCon,4);
                assetbook.AssetId = AssetId;//conPeek(readCon,5);
                assetbook.BookId = BookId;//conPeek(readCon,6);
                assetbook.DepreciationStartDate = DepreciationStartDate;//str2Date(conPeek(readCon,7),213);
                assetbook.LastDepreciationDate  = LastDepreciationDate;//str2Date(conPeek(readCon,8),213);
                assetbook.LifeTime  = LifeTime;//conPeek(readCon,9);
                assetbook.PostingProfile  = PostingProfile;//conPeek(readCon,10);
                assetbook.ServiceLife  = ServiceLife;//conPeek(readCon,11);
                assetbook.UsedFromDate = UsedFromDate;//str2Date(conPeek(readCon,12),213);
                assetbook.LifeTimeRest = LifeTimeRest;//conPeek(readCon,13);
                assetbook.insert();

            }

        }
        ttsCommit;
    info("Succesfully imported");
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
//
//
Vendor master Import:
//CommaTextIO                             csvFile;
    //container                               readCon;
    //counter                                 icount,inserted;
    Dialog                                  dialog;
    DialogField                             dfFileName;
    DirPartyRecId                           partyRecId,contactPartyRecid;
    Name                                    name,contactName;
    VendTable                               vendtable;
    str                                     contactperson;
    DirPartyPostalAddressView               addressView;
    DirPartyContactInfoView                 contactView;
    ContactPerson                           contactpersonTable;
    LogisticsElectronicAddressMethodType    enumType;
    DirContactPersonsService                dirContactPersonsService;
    DirContactPersons                       dirContactPersons;
    DirContactPersons_ContactPerson         dirContactPersons_ContactPerson;
    DirContactPersons_Person                dirContactPersons_Person;
    DirContactPersons_PersonName            dirContactPersons_PersonName;
    AifEntityKeyList                        aifEntityKeyList, aifEntityKeyList_DirContactPerson;
    str                                     fName, mName, lName;
    VendAccount                             vendorAccount;
    DirParty                                dirParty;
    LogisticsPostalAddress                  address;
    LogisticsElectronicAddress              logisticsElectronicAddress;
    BinData                                 binData;
    str                                     stringImage;
    LogisticsAddressStateID                 stateId;
    str                                     accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
    ;
    csvFiles = new CommaIO(filename, 'r');
    try
    {
        if (csvFiles)
        {
            ttsbegin;
            readCon = csvFile.read();
            while (csvFiles.status() == IO_Status::OK)
            {
                readCon = csvFiles.read();
                if(readCon)
                {
                icount++;
                accountnum = conPeek(readCon,1);
                accountName = conPeek(readCon,2);
                phone = conPeek(readCon,3);
                fax = conPeek(readCon,4);
                vendgroup = conPeek(readCon,5);
                currency = conPeek(readCon,6);
                dlvmode = conPeek(readCon,7);
                paymtermid = conPeek(readCon,8);
                email = conPeek(readCon,9);
                mobile = conPeek(readCon,10);
                contactperson = conPeek(readCon,11);
                pobox = conPeek(readCon,12);
                countryid = conPeek(readCon,13);
                zipcode = conPeek(readCon,14);
                stateId = conPeek(readCon,15);
                city = conPeek(readCon,16);
                street = conPeek(readCon,17);
                ttsBegin;
                name = conPeek(readCon,2);
                if(!name)
                break;
                partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
                vendtable.clear();
                vendtable.initValue();
                vendtable.Party = partyRecId;
                vendtable.AccountNum = accountnum;
                vendtable.VendGroup  = vendgroup;
                vendtable.Currency   = currency;
                //vendtable.Blocked    =
                vendtable.DlvMode    = dlvmode;
                vendtable.PaymTermId   = paymtermid;
                if(contactperson != '')
                {
                    contactname = ContactPerson;
                    ContactPerson::findOrCreateNameParty(partyRecId,contactname);
                }
                vendtable.insert();
                ttsCommit;
                stateId = subStr(stateId,1,25);
                address.PostBox = strLRTrim(PoBox);
                address.CountryRegionId = strLRTrim(Countryid);
                address.State = stateId;
                address.ZipCode = strLRTrim(ZipCode);
                address.Street  = strLRTrim(Street);
                //address.county = strLRTrim(conPeek(readCon,17));
                address.City    = strLRTrim(City);
                addressView.LocationName = name;
                addressView.IsPrimary = NoYes::Yes;
                addressView.Party = partyRecId;
                addressview.initFromPostalAddress(address);
                DirParty = DirParty::constructFromPartyRecId(addressView.Party );
                DirParty.createOrUpdatePostalAddress(addressView);
                contactView.LocationName = "Email";
                contactView.Locator      = strLRTrim(email);
                contactView.Type         = LogisticsElectronicAddressMethodType::Email;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
                contactView.LocationName = "Mobile";
                contactView.Locator      = strLRTrim(mobile);
                contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
                contactView.LocationName = "Phone";
                contactView.Locator      = strLRTrim(Phone);
                contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
                contactView.LocationName = "Fax";
                contactView.Locator      = strLRTrim(Fax);
                contactView.Type         = LogisticsElectronicAddressMethodType::Fax;
                contactView.Party        = partyRecId;
                contactView.IsPrimary    = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
                inserted++;
                }
            }
            ttsCommit;
        }
        icount--;//Remove header recount from total record count
        info("Succesfully imported");
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
//

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...