AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE
AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE
class VIK_SalesMaster_ExcelImport extends RunBaseBatch
{
DialogField dialogfile;
FilenameOpen fileName;
localmacro.CurrentList
fileName
endmacro
}
dialog
protected Object dialog()
{
DialogRunbase _dialog = super();
_dialog.caption("Sales : Trade Aggrement Upload");
dialogfile = _dialog.addField("FilenameOpen","Enter file path : ");
dialogfile.value(fileName);
return _dialog;
}
getFromDialog
public boolean getFromDialog()
{
;
fileName = dialogfile.value();
return true;
}
run
public void run()
{
SysExcelApplication excel;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row =1;
int _noofprints;
CustName name;
int i,j;
//sales price upload
str queryPricingMaster,itemId,existingItemIdsList,tempValue;
ResultSet resultSet;
InventTable inventTable;
AifEntityKeyList keys;
DD_HI_RRP_Staging RRPStaging;
PricePriceDiscJournalService PriceDiscSvc;
PricePriceDiscJournal PriceDiscJour;
PricePriceDiscJournal_PriceDiscAdmTrans PriceDiscJourAdmTrans;
PricePriceDiscJournal_InventDim PriceDiscJourDim;
PriceDiscAdmTrans _PriceDiscAdmTrans;
//vikas
PriceDiscAdmTable priceDiscAdmTable;
PriceDiscAdmTrans PriceDiscAdmTrans;
PriceDiscAdmName PriceDiscAdmName;
PriceDiscJournalName pricediscjournalName;
NumberSeq journalNum;
//sales price upload//
str _relation,_accountcode,_accountselection,_itemcode,_temrelation,_unit,_curcode;
real _from,_amtincur;
date _todate,_fromdate;
PriceType _pricetype;
itemId tempItemId;
AviFiles
SysOperationProgress progress1 = new SysOperationProgress();
;
//excel
define.filename(fileName)
excel = SysExcelApplication::construct();
workbooks = excel.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
type = cells.item(row+1, 1).value().variantType();
//progress1.setCaption("Updation of pricing master is in progress…");
//progress1.setAnimation(AviUpdate);
ttsBegin;
Select firstOnly PriceDiscAdmName;
priceDiscAdmTable.clear();
priceDiscAdmTable.initFromPriceDiscAdmName(PriceDiscAdmName);
journalNum = NumberSeq::newGetNum(SalesParameters::numRefPriceDiscJournalNum());
pricediscjournalName = journalNum.num();
priceDiscAdmTable.JournalNum = pricediscjournalName;
priceDiscAdmTable.insert();
while (type != COMVariantType::VT_EMPTY)
{
row++;
tempItemId = cells.item(Row,5).value().bStr();
// Set PriceDiscJourAdmTrans
while select forUpdate * from inventTable where inventTable.ItemId == tempItemId
{
// progress1.setText(strfmt("Item ID %1", tempItemId));
PriceDiscAdmTrans.clear();
PriceDiscAdmTrans.JournalNum = pricediscjournalName;
PriceDiscAdmTrans.relation = real2int(cells.item(Row,1).value().double()) ;//relation
PriceDiscAdmTrans.InventDimId = "Allblank";
PriceDiscAdmTrans.DisregardLeadTime = NoYes::Yes;
PriceDiscAdmTrans.AccountCode = real2int(cells.item(Row,2).value().double()) ; //account code
PriceDiscAdmTrans.AccountRelation = cells.item(Row,3).value().bStr(); //account relation
PriceDiscAdmTrans.ItemCode = real2int(cells.item(Row,4).value().double());
PriceDiscAdmTrans.ItemRelation = cells.item(Row,5).value().bStr(); //item realtaion item id
PriceDiscAdmTrans.QuantityAmountFrom= cells.item(Row,6).value().double(); //from quantity
PriceDiscAdmTrans.UnitId = cells.item(Row,7).value().bStr(); //unit id
PriceDiscAdmTrans.Amount = cells.item(Row,8).value().double(); //Amount in Curr
PriceDiscAdmTrans.Currency = cells.item(Row,9).value().bStr(); //currency code
PriceDiscAdmTrans.FromDate = cells.item(Row,10).value().date(); //from date
PriceDiscAdmTrans.ToDate = cells.item(Row,11).value().date(); //todate
PriceDiscAdmTrans.insert();
itemId=inventTable.ItemId;
}
type = cells.item(row+1, 1).value().variantType();
}
ttsCommit;
excel.quit();
}
main
public static void main(Args _args)
{
VIK_SalesMaster_ExcelImport VIK_SalesMaster_ExcelImport = new VIK_SalesMaster_ExcelImport();
if(VIK_SalesMaster_ExcelImport.prompt())
VIK_SalesMaster_ExcelImport.run();
}
No comments:
Post a Comment