static void TEC_UploadInventPL(Args _args)
{
InventJournalTrans trans;
InventDim inventDim;
InventColor inventColor;
InventSize inventSize;
InventDimCombination inventDimCombination;
InventTrans inventTrans;
CommaIO io;
Container con;
Filename fileName;
str val, qtyStr, priceStr;
real i = 1.0;
;
fileName = "C:\\Temp\\InventoryOnHand_1.csv";
io = new CommaIO(fileName, "r");
io.read();
io.inFieldDelimiter(";");
try
{
ttsBegin;
while(io.status()==IO_Status::Ok){
con = io.read();
trans.JournalType = InventJournalType::Movement;
trans.JournalId = conPeek(con, 1);
trans.ItemId = conPeek(con, 2);
qtyStr = conPeek(con, 3);
if (strfind(qtyStr, ",",1,strlen(qtyStr)))
qtyStr = strrem(qtyStr, ',');
trans.Qty = str2num(qtyStr);//conPeek(con, 3);
trans.PriceUnit = 1;
priceStr = conPeek(con, 4);
if (strFind(priceStr, ",",1, strLen(priceStr)))
priceStr = strRem(priceStr, ",");
trans.CostPrice = str2Num(priceStr);
trans.CostAmount = DecRound(trans.Qty*trans.CostPrice, 0);
trans.LedgerAccountIdOffset = "411101";
trans.TransDate = mkDate(30, 11, 2007); // Should careful with this field
//trans.TransDate = str2date(conPeek(con, 5), 123);
trans.Dimension[2] = "050";
if(trans.JournalId == "" || trans.JournalId == "0" || trans.Qty == 0) break; //EOF
trans.LineNum = i;
i++;
inventDim.InventLocationId = conPeek(con, 5); //Warehouse
inventDim.wMSLocationId = "050"; //conPeek(con, 6);
inventDim.InventSizeId = conPeek(con, 6);
inventDim.InventColorId = conPeek(con, 7);
if (!inventDim.InventColorId || strrtrim(inventDim.InventColorId) == "0")
{
select inventColor where inventColor.ItemId == trans.ItemId && inventColor.ItemId != "0";
if (!inventColor)
{
try
{
ttsbegin;
inventColor.ItemId = trans.ItemId;
inventColor.InventColorId = "Def";
inventColor.Name = "Default Color";
inventColor.insert();
ttscommit;
inventDim.InventColorId = "Def";
}
catch
{
ttsabort;
Error("Error");
}
}
else
inventDim.InventColorId = inventColor.InventColorId;
}
trans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
select forupdate inventDimCombination
where inventDimCombination.ItemId == trans.ItemId
&& inventDimCombination.InventSizeId == inventDim.InventSizeId
&& inventDimCombination.InventColorId == inventDim.InventColorId;
if (!inventDimCombination)
{
inventDimCombination.ItemId = trans.ItemId;
inventDimCombination.InventSizeId = inventDim.InventSizeId;
inventDimCombination.InventColorId = inventDim.InventColorId;
inventDimCombination.InventDimId = inventDim.inventDimId;
inventDimCombination.insert();
}
trans.insert(NoYes::Yes);
//Insert InventTrans
inventTrans.ItemId = trans.ItemId;
inventTrans.Qty = trans.Qty;
inventTrans.TransType = InventTransType::InventTransaction;
inventTrans.TransRefId = trans.JournalId;
inventTrans.DateExpected = trans.TransDate;
inventTrans.InventTransId = trans.InventTransId;
inventTrans.StatusReceipt = StatusReceipt::Ordered;
inventTrans.ValueOpen = InventTransOpen::Yes;
inventTrans.Direction = InventDirection::Receipt;
inventTrans.DateStatus = trans.TransDate;
inventTrans.inventDimId = trans.inventDimId;
inventTrans.insert(NoYes::Yes);
info(strfmt("%1 %2 %3 -- %4", trans.ItemId, trans.Qty, trans.CostAmount, inventDim.InventColorId));
}
ttscommit;
info("Complete");
}
catch
{
ttsabort;
Error("Error");
Info(strfmt("%1 %2 %3 -- %4 ", trans.ItemId, trans.Qty, inventDim.InventSizeId, inventDim.InventColorId));
}
}
No comments:
Post a Comment