Satınalma sipariş satırlarını toplu aktar
Siparişlerin satırlarını toplu aktarmak için aşağıdaki kodu kullanabilirsiniz.
void MAA_Excel_PurchLine()
{
#Excel
#AviFiles
Dialog dialog = new Dialog("Veri Aktarma");
DialogField dialogPath;
FilenameFilter filter = ['Excel files 2010','*.xlsx','Excel files 2003', '*.xls' ];
FilenameOpen filePath;
SysExcelApplication application;
SysExcelWorkBooks workBooks;
SysExcelWorkBook workBook;
SysExcelWorkSheets workSheets;
SysExcelWorkSheet workSheet;
SysExcelCells cells;
SysOperationProgress progress;
Int NoofSheet,i,lastRow,sn;
PurchLine PurchLine;
InventDim tmpInventDim,tmpInventDimItem;
inventBatch inventBatch;
InventSerial InventSerial;
SysExcelRange range;
void findLastRow(SysExcelWorkSheet _workSheet)
{
#define.Star('*')
#define.Space(' ')
;
range = _workSheet.cells().range(#ExcelTotalRange);
try
{
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
}
catch (Exception::Error)
{
error("@SYS59926");
}
if (range)
{
lastRow = range.row();
}
else
{
lastRow = 0;
}
}
;
dialog.filenameLookupFilter(filter);
dialogPath = dialog.addField(typeid(FilenameOpen));
if (dialog.run())
{
if(dialog.closedOk())
{
filePath = dialogPath.value();
application = SysExcelApplication::construct();
application.visible(false);
workBooks = application.workbooks();
workBooks.open(filePath,0,true);
workSheets = workBooks.item(1).worksheets();
noOfSheet = worksheets.count();
progress = new SysOperationProgress();
progress.setCaption("Vendor Importing");
progress.setTotal(lastRow);
progress.setAnimation(#AviTransfer);
setprefix("Vendor Import");
try
{
For( i = 1; i <= noOfSheet; i++)
{
workSheet = workSheets.itemFromNum(i);
if(workSheet)
{
findLastRow(workSheet);
for(sn = 2;sn <= lastrow;sn++)
{
ttsbegin;
cells = workSheet.cells();
cells = workSheet.cells();
PurchLine.clear();
PurchLine.PurchId = cells.item(sn,1).value().bStr();
PurchLine.VendAccount = cells.item(sn,2).value().bStr();
PurchLine.ItemId = cells.item(sn,3).value().bStr();
PurchLine.PurchQty = cells.item(sn,4).value().double();
PurchLine.PurchPrice = cells.item(sn,5).value().currency();
PurchLine.LineAmount = PurchLine.PurchQty * PurchLine.PurchPrice;
PurchLine.TaxItemGroup = cells.item(sn,6).value().bStr();
PurchLine.VendGroup = "272101";
PurchLine.TaxGroup = "YURTICI";
PurchLine.CurrencyCode = "EUR";
PurchLine.ETGInventType = InventTable::find(PurchLine.ItemId).ETGInventType;
PurchLine.PurchUnit = InventTable::find(InventTableModule::find(PurchLine.ItemId, ModuleInventPurchSales::Purch).ItemId).purchUnitId();
PurchLine.PurchaseType = PurchaseType::Purch;
// tmpInventDimItem.clear();
// tmpInventDimItem = purchLine.inventDim();
// tmpInventDimItem = InventDim::findOrCreate(tmpInventDimItem);
if ( InventSite::exist(cells.item(sn,7).value().bStr()) )
tmpInventDimItem.InventSiteId = cells.item(sn,7).value().bStr();
if ( InventLocation::exist(cells.item(sn,8).value().bStr()) )
tmpInventDimItem.InventLocationId = cells.item(sn,8).value().bStr();
purchLine.InventDimId = cells.item(sn,9).value().bStr();
PurchLine.RemainPurchPhysical = PurchLine.PurchQty;
PurchLine.RemainInventPhysical = PurchLine.PurchQty;
PurchLine.QtyOrdered = PurchLine.PurchQty;
if(Dimensions::exist(SysDimension::Department,cells.item(sn,10).value().bStr()) && cells.item(sn,10).value().bStr())
{
PurchLine.Dimension[1] = cells.item(sn,10).value().bStr();
// DRT MK - KDV hesaplaması için
}
else if(cells.item(sn,10).value().bStr())
throw error(strfmt("%1 - %2 boyutu tanımlı değildir", SysDimension::Department, cells.item(sn,10).value().bStr()));
if(Dimensions::exist(SysDimension::Center,cells.item(sn,11).value().bStr()))
PurchLine.Dimension[2] = cells.item(sn,11).value().bStr();
else if(cells.item(sn,11).value().bStr())
throw error(strfmt("%1 - %2 boyutu tanımlı değildir", SysDimension::Center, cells.item(sn,11).value().bStr()));
if(Dimensions::exist(SysDimension::Purpose,cells.item(sn,12).value().bStr()))
PurchLine.Dimension[3] = cells.item(sn,12).value().bStr();
else if(cells.item(sn,12).value().bStr())
throw error(strfmt("%1 - %2 boyutu tanımlı değildir", SysDimension::Purpose, cells.item(sn,12).value().bStr()));
if(Dimensions::exist(SysDimension::Person,cells.item(sn,13).value().bStr()))
PurchLine.Dimension[4] = cells.item(sn,13).value().bStr();
else if(cells.item(sn,13).value().bStr())
throw error(strfmt("%1 - %2 boyutu tanımlı değildir", SysDimension::Person, cells.item(sn,13).value().bStr()));
if(Dimensions::exist(SysDimension::Vehicle,cells.item(sn,14).value().bStr()))
PurchLine.Dimension[5] = cells.item(sn,14).value().bStr();
else if(cells.item(sn,14).value().bStr())
throw error(strfmt("%1 - %2 boyutu tanımlı değildir", SysDimension::Vehicle, cells.item(sn,14).value().bStr()));
PurchLine.insert();
info("Aktarma tamamlandı");
ttscommit;
}
}
}
}
catch
{
ttsabort;
application.quit();
}
}
}
}
Kullandığım exel şablonunu inceleyebilirsiniz.
Excel Şablonu