Wednesday, 20 January 2016

MultiSalesOrdersLineImportfromExcel through Job in ax 2012

static void MultiSalesOrdersLineImportfromExcel(Args _args)



{

SalesTable salesTable;

SalesLine salesLine;

InventDim inventDim;

Dialog _dialog;

DialogField _file;

NumberSeq num;

SysExcelApplication application;

SysExcelWorkbooks workbooks;

SysExcelWorkbook workbook;

SysExcelWorksheets worksheets;

SysExcelWorksheet worksheet,worksheet1;

SysExcelCells cells,cells1;

COMVariantType type;

int row;



;

row++;

application = SysExcelApplication::construct();

workbooks = application.workbooks();

_dialog = new Dialog("Please select the file to load");





//_dialog.addText("Select file:");



_file = _dialog.addField(ExtendedTypeStr("FilenameOpen"));



_dialog.run();

if (_dialog.closedOK())



{

info(_file.value() );

workbooks.open(_file.value());

}

workbook = workbooks.item(1);



worksheets = workbook.worksheets();

worksheet1 = worksheets.itemFromName("Lines");



cells1 = worksheet1.cells();

salesTable = SalesTable::find("LAZ-000004");





do



{

row++;

inventDim.clear();

inventDim.InventSiteId =cells1.item(row,6).value().bStr();//int2str(real2int(cells1.item(row,4).value().double()));

inventDim.InventLocationId =cells1.item(row,7).value().bStr(); //int2str(real2int(cells1.item(row,5).value().double()));

inventDim.InventSizeId =cells1.item(row,3).value().bStr();

inventDim.InventColorId =cells1.item(row,4).value().bStr();

inventDim.InventStyleId =cells1.item(row,5).value().bStr();





//inventDim.InventLocationId =cells1.item(row,5).value().bStr();



salesLine.clear();

salesLine.initValue(salesTable.SalesType);

salesLine.initFromSalesTable(salesTable);

salesLine.ItemId = cells1.item(row, 1).value().bStr();

salesLine.initFromInventTable(InventTable::find(cells1.item(row, 1).value().bStr()));



salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

salesLine.RetailVariantId =cells1.item(row,2).value().bStr();

salesLine.SalesQty = any2int(cells1.item(row,8).value().toString());



salesLine.RemainSalesPhysical = salesLine.SalesQty;

salesLine.SalesUnit = cells1.item(row,9).value().bStr();



salesLine.QtyOrdered = salesLine.calcQtyOrdered();

salesLine.RemainInventPhysical = salesLine.QtyOrdered;

//salesLine.setPriceDisc(InventDim::find(salesLine.InventDimId));



salesLine.PriceUnit =any2int(cells1.item(row,10).value().toString());

salesLine.LineAmount = any2int(cells1.item(row,11).value().toString());

salesLine.MRKPCommentsLoc = cells1.item(row,12).value().bStr();

salesLine.MRKPDetails = cells1.item(row,13).value().bStr();





//salesLine.deliveryDate = cells1.item(row,14).value().date();

//salesLine.DeliveryName = cells1.item(row,15).value().bStr(); //fin dimension should come here

//salesLine.MRKPDetails = cells1.item(row,16).value().bStr();



salesLine.MRKPDetails = cells1.item(row,17).value().bStr();

type = cells1.item(row+1, 1).value().variantType();

if (salesLine.validateWrite())



{

salesLine.insert();

}

}

while (type != COMVariantType::VT_EMPTY);



workbooks.close();

application.quit();

info("Done!");



}


No comments:

Post a Comment