Generate batch numbers from chosen number sequence

Pievienoja Džordžs Bārens Ce, 03.06.2021 - 11:44

In form's ProdTable create button Generate batch under Functions and put following code in clicked method:

void clicked()
{
Dialog d;
DialogField df;
FormBuildComboBoxControl comboBox;
NumberSeq numberSeq;
InventBatch inventBatch;
;
if (prodTable.ProdStatus == ProdStatus::StartedUp)
{
if (InventTable::find(prodTable.ItemId).DimGroupId == "LOT/Batch")
{
if (!inventDim.inventBatchId)
{
d = new Dialog("Select number sequence");
df = d.addField(typeid(ABC));
comboBox = df.control();
comboBox.enumType(0);
comboBox.label("Choose batch number sequence");
comboBox.items(2);
comboBox.item(1);
comboBox.text("Sequence 1");
comboBox.item(2);
comboBox.text("Sequence 2");
if (d.run())
{
switch (df.value())
{
case 0:
numberSeq = NumberSeq::newGetNumFromCode("NUM1");
break;
case 1:
numberSeq = NumberSeq::newGetNumFromCode("NUM2");
break;
default:
break;
}
if (numberSeq)
{
inventDim.inventBatchId = numberSeq.num();
inventDim.inventDimId = InventDim::findOrCreate(inventDim).inventDimId;
inventBatch.itemId = prodTable.ItemId;
inventBatch.inventBatchId = inventDim.inventBatchId;
inventBatch.prodDate = systemDateGet();
inventBatch.insert();
info(strfmt("New number generated %1", inventDim.inventBatchId));
}
}
else
{
info("Cancelled");
}
}
else
{
info(strfmt("There is batch number assigned: %1", prodTable.inventDim().inventBatchId));
}
}
else
{
info("The item is not LOT/Batch");
}
}
else
{
info(strfmt("The order %1 is not in started state", prodTable.ProdId));
}
super();
}