Import Purchase Trade agreements in Ax 2012 using CSV file

Hi,
The below job is used to import the purchase trade agreement journal lines.

//To create the purchase trade agreement lines.
//Forthis, just create the Journal header first and import the lines by using this job
 
static void CreatePurchTradeAgreementLines(Args _args)
{
CommaIO     csvFile;
container   readCon;
counter     icount,inserted;
Dialog      dialog;
DialogField dfFileName;
FileName    fileName;
itemId      itemId;
AmountCur   amount;
str         strFromdate,strTodate,type;
TransDate   fromDate, toDate;    
PurchUnit   purchUnitId;
PriceDiscJournalNum journalNum;
TableGroupAll TableGroupAll;
   
AxPriceDiscAdmTrans axPriceDiscAdmTrans;

PriceDiscAdmTrans   priceDiscAdmTrans;
InventDim           inventDim;
InventDimId         inventDimId;
CurrencyCode        currencyCode;
 
inserted =0;
#File
dialog = new Dialog("Pick the file");

dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
dialog.filenameLookupFilter(["All files", #AllFiles]);

if(dialog.run())
{
    filename = dfFileName.value();
}
 

 csvFile = new CommaIO(filename,'r');
if(csvFile)
{
 
ttsbegin;
inventDim.clear();
inventDim.InventSiteId = "1";
inventDimId = inventDim::findOrCreate(inventDim).inventDimId;
currencyCode = Ledger::accountingCurrency(); //AED

while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read(); 
if(readCon)
{
itemId = conPeek(readCon, 1);
amount = conPeek(readCon, 2);
strFromdate = conPeek(readCon, 3);
strTodate = conPeek(readCon, 4);
type = conPeek(readCon, 5);
purchUnitId = conPeek(readCon, 6);
journalNum = conPeek(readCon, 7);
 fromDate = dateNull();
toDate = dateNull();


if (strFromdate)
fromDate = str2Date(strFromdate,123);

if (strTodate)
toDate = str2Date(strTodate,123);

axPriceDiscAdmTrans = new AxPriceDiscAdmTrans();

axPriceDiscAdmTrans.parmAccountCode(TableGroupAll::GroupId);//5
axPriceDiscAdmTrans.parmAccountRelation("ISC");


axPriceDiscAdmTrans.parmItemCode(TableGroupAll::Table);
 
axPriceDiscAdmTrans.parmItemRelation(itemId); //1

axPriceDiscAdmTrans.parmAmount(amount); //2

axPriceDiscAdmTrans.parmFromDate(fromdate);//3

axPriceDiscAdmTrans.parmToDate(todate); // 4

axPriceDiscAdmTrans.parmUnitId(purchUnitId); //6

axPriceDiscAdmTrans.parmJournalNum(journalNum); //7


axPriceDiscAdmTrans.parmrelation(PriceType::PricePurch);
 
axPriceDiscAdmTrans.parmCurrency(currencyCode); //AED

axPriceDiscAdmTrans.parmInventDimId(inventDimId);//inventDimid for site 1;

axPriceDiscAdmTrans.save();
               
icount++;

inserted++;

}

}
ttsCommit;

info(strfmt("%1 records inserted out of %2",inserted,icount));
}
 
*******************
Sample File
 
0000000007,10,01/01/2015,12/01/2015,Group,TON,SEFL-00020
0000000008,5.50,01/01/2015,12/01/2015,Group,TON,SEFL-00020
0000000010,2.5,01/01/2015,,Group,TON,SEFL-00027

 

Comments

Post a Comment

Popular posts from this blog

x++ code to Generate cheque for vendor payment journal

Copy favorites From one user to another user - Ax 2012

Import Procurement Hierarchy / Categories with out code in ax 2012