berikut ini adalah content mengenai upload purchline, melakukan customisasi di ax 2012
saya upload source code nya di sini
HpCsUploadPurchLine class HpCsUploadPurchLine { } private void UploadPurchLine(PurchTable _header) { //standard variable int _cnt, i, TType; int64 _total; str 100 _texttmp; Filename _filename; Filename filepath; Filename filename; Filename fileType; str fileNameString,fileNamePath; DialogField dialogFileName; Dialog dialog; str 100 _judul; #AviFiles SysOperationProgress progress = new SysOperationProgress(); #WinAPI #File SysExcelApplication application = SysExcelApplication::construct(); SysExcelWorkbooks workbooks = application.workbooks(); SysExcelWorkbook workbook; SysExcelWorksheets workSheets; SysExcelWorksheet workSheet; SysExcelCells cells; SysExcelCell cell; COMVariantType type; EnumId AccCode,ItemCode; InventDim _inventDim; PurchLine _line; HpgCsBOMUpload _func = new HpgCsBOMUpload(); startLengthyOperation(); dialog = new Dialog(); _judul = strFmt("Upload Purchase Line for %1", _header.PurchId); dialog.caption(strFmt("%1", _judul)); dialogFileName = dialog.addField(extendedTypeStr(FilenameOpen)); if(dialog.run()) { _filename = dialogFileName.value(); } if (!WinAPI::fileExists(_filename)) { application.quit(); throw error(strfmt("@SYS109820", _filename)); } try { workbooks.open(_filename); } catch (Exception::Error) { application.quit(); throw error(strFmt("File cannot be opened.")); } fileNamePath = _filename; [filepath, filename, fileType] = fileNameSplit(fileNamePath); fileNameString= filename + fileType; progress.setCaption("My Task"); progress.setAnimation(#AviUpdate); workbook = workbooks.item(1); worksheets = workbook.worksheets(); worksheet = worksheets.itemFromNum(1); cells = worksheet.cells(); //dia tidak akan clean, clean line harus manual //loop di sini _cnt = 3; type = cells.item(_cnt, 1).value().variantType(); ttsBegin; select forUpdate _line where _line.PurchId==_header.PurchId; i = 1; while(type != COMVariantType::VT_EMPTY) { _texttmp = _func.ConvertToStr100(cells.item(_cnt, 1).value()); //fungsi insert from excel dari sini //Order line _inventDim.clear(); _inventDim.InventSiteId = _header.InventSiteId; _inventDim.InventLocationId = _header.InventLocationId; _inventDim.inventBatchId = _func.ConvertToStr100(cells.item(_cnt, 5).value()); _inventDim.wMSLocationId = _func.ConvertToStr100(cells.item(_cnt, 6).value()); _inventDim.configId = _func.ConvertToStr100(cells.item(_cnt, 7).value()); _inventDim.InventSizeId = _func.ConvertToStr100(cells.item(_cnt, 8).value()); _inventDim.InventColorId = _func.ConvertToStr100(cells.item(_cnt, 9).value()); _line.clear(); _line.initValue(_header.PurchaseType); _line.initFromPurchTable(_header); _line.initFromInventTable(InventTable::find(_texttmp)); _line.InventDimId = InventDim::findOrCreate(_inventDim).inventDimId; _line.Name = _func.ConvertToStr100(cells.item(_cnt, 2).value()); _line.PurchQty = cells.item(_cnt, 3).value().double(); _line.RemainPurchPhysical = _line.PurchQty; _line.PurchUnit = _func.ConvertToStr100(cells.item(_cnt, 4).value()); _line.QtyOrdered = _line.calcQtyOrdered(); _line.RemainInventPhysical = _line.QtyOrdered; _line.setPriceDisc(InventDim::find(_line.InventDimId)); if (_line.validateWrite()) { _line.insert(); } else { application.quit(); endLengthyOperation(); throw error(strFmt("Order line at line %1, if you want to reupload, correct the problem on those line", i)); } //info(strFmt("%1", _texttmp)); _cnt++; i++; type = cells.item(_cnt, 1).value().variantType(); } application.quit(); ttsCommit; endLengthyOperation(); //info("done"); } public boolean Validation(PurchTable p) { boolean valid; PurchLine _line; int i; valid = true; //cek apakah po bukan draft if(p.PurchStatus != PurchStatus::Backorder) { //failed, artinya PO ini statusnya bukan draft throw error(strFmt("Purchase order ini tidak bisa diupload karena PO harus draft, saat ini po status adalah %1", p.PurchStatus)); } //cek apakah po line existing? i = 0; while select _line where _line.PurchId==p.PurchId { //jika ada receive maka tidak bisa proses lebih lanjut valid = true; i++; if(_line.PurchStatus != PurchStatus::Backorder) { valid = false; //failed, artinya sdh pernah pernah received info(strFmt("Purchase Order ini sdh pernah ada receive, proses upload tidak bisa dilakukan,periksa baris ke %1", i)); } } if (!p.validateWrite()) { throw error("Order header PO ini tidak bisa dimodif"); } if(!valid) { throw error("Periksa info di atas"); } return valid; } static void main(Args _args) { PurchTable _j; HpCsUploadPurchLine _func = new HpCsUploadPurchLine(); _j = _args.record(); //info(strFmt("%1-%2", _args.menuItemName(), _j.PurchId)); if(_func.Validation(_j)){ //info("ok"); _func.UploadPurchLine(_j); } }
HpgCsBOMUpload class HpgCsBOMUpload { } public str 100 ConvertToStr100(COMVariant value) { System.Double netDouble; anytype r1; str s1; COMVariantType valueType; s1 = value.bStr(); valueType = value.variantType(); if(valueType != COMVariantType::VT_BSTR) { switch(valueType) { case COMVariantType::VT_R8: r1 = value.double(); netDouble = Global::real2double(r1); s1 = netDouble.ToString(); break; } } return strFmt("%1", s1); }