Wednesday, November 30, 2016

Fixed Asset Posting Profile/Disposal (Sold/Scrap) Upload in ax 2012

//Upload FA posting profile ax 2012
//FA PP
static void ImportAssetPP(Args _args)
{
    CommaTextIO                 csvFile;
    container                   readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField                 dfFileName,dfFAName;
    FileName                    fileName;
    AssetLedger                 assetLedger;
    AssetLedgerAccounts         asseteLedgerAccounts;
    AssetTransType              AssetTransType;
    TableGroupAll               TableGroupAll;
     #File
    //Function to creation Ledger dimension
    LedgerDimensionDefaultAccount CreateLedgerDimension(MainAccountNum  _Account)
    {
        return DimensionStorage::getDefaultAccount(MainAccount::findByMainAccountId(_Account).RecId);
    }
    ;
    //Template
    //1)Account Type,2)Value Model,3)Grouping,4)FA Number/Group,5)Main Accounts,6)Offset Account
    dialog = new Dialog("Pick CSV file for upload");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dfFAName = dialog.addField(extendedTypeStr("AssetPostingProfile"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if (dialog.run())
    {
        if(dfFAName.value() == "")
        {
            throw warning("Select any one of Asset POsting profile");
        }
        assetLedger = AssetLedger::find(dfFAName.value(),false);
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            if(readCon)
            {
                asseteLedgerAccounts.clear();
                asseteLedgerAccounts.BookId                 = conPeek(readCon,2);
                asseteLedgerAccounts.AccountCode            = str2enum(TableGroupAll,conPeek(readCon,3));
                asseteLedgerAccounts.PostingProfile         = assetLedger.PostingProfile;
                asseteLedgerAccounts.TransType              = str2enum(AssetTransType,conpeek(readCon,1));
                asseteLedgerAccounts.AccountRelation        = conPeek(readCon,4);
                asseteLedgerAccounts.LedgerDimension        = CreateLedgerDimension(any2str(conPeek(readCon,5)));
                asseteLedgerAccounts.OffsetLedgerDimension  = CreateLedgerDimension(any2str(conPeek(readCon,6)));                              
                asseteLedgerAccounts.insert();
                icount++;
            }
        }
        ttsCommit;
    }
    info("Import COmpleted");
}
//FA disposal
static void ImportAssetPPDisposal(Args _args)
{
    CommaTextIO                 csvFile;
    container                   readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField                 dfFileName,dfFAName,dfSoldScarp;
    FileName                    fileName;
    AssetDisposalParameters     disposalParameters;
    AssetLedger                 assetLedger;
    AssetLedgerAccounts         asseteLedgerAccounts;
    AssetPostValue              AssetPostValue;
    TableGroupAll               TableGroupAll;
    AssetSoldScrap              AssetSoldScrap;
    FormStringControl   control,Control1;
     #File
    //Function to creation Ledger dimension
    LedgerDimensionDefaultAccount CreateLedgerDimension(MainAccountNum  _Account)
    {
       return DimensionStorage::getDefaultAccount(MainAccount::findByMainAccountId(_Account).RecId);
    }
    ;
    //Template
    //1)Account Type,2)Value Model,3)Grouping,4)FA Number/Group,5)Main Accounts,6)Offset Account
    dialog = new Dialog("Pick CSV file for upload");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dfFAName = dialog.addField(extendedTypeStr("AssetPostingProfile"));
    control1 = dfFAName.fieldControl();
    control1.mandatory(true);
    dfSoldScarp = dialog.addField(enumStr(AssetSoldScrap));
    control = dfSoldScarp.fieldControl();
    control.mandatory(true);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if (dialog.run())
    {
        if(dfFAName.value() == "")
        {
            throw warning("Select any one of Asset POsting profile");
        }
        assetLedger = AssetLedger::find(dfFAName.value(),false);
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            if(readCon)
            {
                disposalParameters.clear();
                disposalParameters.BookId                 = conPeek(readCon,2);
                disposalParameters.SoldScrap              = str2enum(AssetSoldScrap,dfSoldScarp.Value());
                disposalParameters.AssetCode              = str2enum(TableGroupAll,conPeek(readCon,3));
                disposalParameters.PostingProfile         = assetLedger.PostingProfile;
                disposalParameters.PostValue              = str2enum(AssetPostValue,conpeek(readCon,1));
                disposalParameters.AssetRelation          = conPeek(readCon,4);
                disposalParameters.LedgerDimension        = CreateLedgerDimension(any2str(conPeek(readCon,5)));
                disposalParameters.OffsetLedgerDimension  = CreateLedgerDimension(any2str(conPeek(readCon,6)));                              
                disposalParameters.ValueType              = AssetPostType::All;
                disposalParameters.insert();
                icount++;
            }
        }
        ttsCommit;
    }
    info("Import COmpleted");
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...