Nghia Song - Microsoft Dynamics 365 Technical Consultant
Nghia Song
Tel - WhatsApp: +84967324794
Email: songnghia.uit@gmail.com
public void VtvCreateInventJournalTrans(ItemId itemId, InventBatchId batchId, InventUnitId scanUnitId, VtvOftionScan scanMode)Nghia Song
Tel - WhatsApp: +84967324794
Email: songnghia.uit@gmail.com
{
JournalTableMap journalTableMap;
InventJournalTable inventJournalTable;
boolean refreshForm;
InventDim newInventDim;
RecId fromUnitRecId;
RecId toUnitRecId;
InventUnitId inventUnitId;
InventQtyJournal convertionQty;
InventTable inventTable;
JournalId JournalId;
InventJournalTrans inventJournalTransNew, inventJournalTransExisted, inventJournalTransFocus;
var journalFormTrans = this.journalForm() as JournalFormTrans;
JournalId = journalFormTrans.getJournalFormTable().journalTable().JournalId;
inventJournalTransNew.clear();
inventJournalTransNew.initValue();
inventJournalTransNew.ItemId = itemId;
inventJournalTransNew.initFromInventJournalTable(InventJournalTable::find(JournalId));
inventJournalTransNew.initFromInventTable(InventTable::find(itemId));
newInventDim = InventDim::find(inventJournalTransNew.InventDimId);
newInventDim.inventBatchId = batchId;
newInventDim = InventDim::findOrCreate(newInventDim);
inventJournalTransNew.InventDimId = newInventDim.inventDimId;
inventJournalTransNew.setInventDimId(newInventDim.inventDimId,newInventDim);
inventTable = InventTable::find(itemId);
//Convert quantity if scan unit id != inventory unit id
inventUnitId = inventJournalTransNew.unitId();
convertionQty = this.VtvSetQuantity(1, scanMode);
if((inventUnitId != scanUnitId) && (scanUnitId != ""))
{
fromUnitRecId = UnitOfMeasure::findBySymbol(scanUnitId).RecId;
toUnitRecId = UnitOfMeasure::findBySymbol(inventUnitId).RecId;
if (UnitOfMeasureConverter::canBeConverted(fromUnitRecId, toUnitRecId, inventTable.Product)) // can be converted to invent unit
{
inventJournalTransNew.Qty = UnitOfMeasureConverter::convert(convertionQty,
fromUnitRecId,
toUnitRecId,
NoYes::Yes,
inventTable.Product,
NoYes::No);
inventJournalTransNew.modifiedField(fieldNum(InventJournalTrans,Qty));
}
else
{
throw error(strFmt("@SYS28690", scanUnitId, inventUnitId));
}
}
else
{
inventJournalTransNew.Qty = this.VtvSetQuantity(1, scanMode);
}
//Check existed line
select firstOnly forUpdate inventJournalTransExisted
where inventJournalTransExisted.ItemId == inventJournalTransNew.ItemId &&
inventJournalTransExisted.InventDimId == inventJournalTransNew.InventDimId &&
inventJournalTransExisted.TransDate == inventJournalTransNew.TransDate &&
inventJournalTransExisted.JournalId == inventJournalTransNew.JournalId &&
inventJournalTransExisted.JournalType == inventJournalTransNew.JournalType;
if(inventJournalTransExisted)
{
inventJournalTransExisted.Qty += inventJournalTransNew.Qty;
inventJournalTransExisted.modifiedField(fieldNum(InventJournalTrans,Qty));
inventJournalTransExisted.setCostPrice(inventJournalTransExisted.InventDimId,inventJournalTransExisted.inventDim());
if(inventJournalTransExisted.Qty == 0)
inventJournalTransExisted.delete();
else
inventJournalTransExisted.update();
inventJournalTransFocus = inventJournalTransExisted;
refreshForm = true;
}
else
{
if(inventJournalTransNew.validateWrite())
{
inventJournalTransNew.setCostPrice(inventJournalTransNew.InventDimId,inventJournalTransNew.inventDim());
inventJournalTransNew.insert();
inventJournalTransFocus = inventJournalTransNew;
refreshForm = true;
}
}
//refresh from
if(refreshForm)
{
InventJournalTrans_DS.research();
InventJournalTrans_DS.executeQuery();
InventJournalTrans_DS.findRecord(inventJournalTransFocus);
//update num of line
inventJournalTransFocus.clear();
select count(RecId)
from inventJournalTransFocus
where inventJournalTransFocus.JournalId == journalId;
journalTableMap = journalFormTrans.journalTableData().journalTable();
journalTableMap.NumOfLines = any2int(inventJournalTransFocus.RecId);
journalFormTrans.journalTableData().journalTable(journalTableMap);
}
}
No comments:
Post a Comment