Very relevant
relevant = actual, topical (sorry, google translate )
The point is that I had a problem when sambapos Inventory item was <= 0, but in fact such a inventory item was still in stock.
When the waiter added an order in which such a item was present, the cost of product was displayed incorrectly.
answer “Where current WP data stored?” was only part of the task of solving this problem.
I wanted to make it so that when the waiter added the order, the missing product was automatically added to the warehouse.
What do you mean messages from Emre?
Well, for example, in my bookmarks, I already have a message from Emre (REPORT CONSUMPTION Tag: Low Inventory Condition? - #19 by emre)
(Warehouse Report select specific warehouse - #14 by emre)
where used “:C.GetPhysicalInventory() < 5}” and “(PCW=SHOP)” expression.
it made my task much easier.
i created retarded script (I’m not a programmer) who solved the problem.
Rule “After Ticket Closing”:
{CALL:outofstock.run(“{REPORT CONSUMPTION DETAILS:I.Id,C.Inventory,C.Cost:(PCW=Local Warehouse) and C.GetPhysicalInventory() < 0}”)}
script
function run(par){
// number of data lines
var rowlen = par.split('<!rn>').length;
//split data
var row = par.split('<!rn>');
var cell1 = row[0].split('|');
var id1 = cell1[0];
if (rowlen >= 1 && id1 >= 1){
//create transaction document
var qry = "";
qry += "INSERT INTO [InventoryTransactionDocuments] ([Date],[InventoryDocumentTransactionTypeId],[TransactionAccountTransactionTypeId],[AccountTypeId],[AccountId],[Description],[ForeignCurrencyId],[Name],[AccountTransactionDocument_Id])";
qry += " VALUES (GETDATE(),'0','0','0','0',null,'0','авто надлишок',null)";
qry += " DECLARE @transactionid nvarchar(10)";
qry += " SET @transactionid = (SELECT TOP (1) [Id] FROM [InventoryTransactionDocuments] ORDER BY [ID] DESC)";
// create first transaction
var q1 = cell1[1].replace(',','.');
var cost1 = cell1[2].replace(',','.');
qry += " DECLARE @unit1 varchar(5)";
qry += " SET @unit1 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id1+"')";
qry += " INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += " VALUES (@transactionid,'1003','3','1',GETDATE(),@unit1,1,-1*"+q1+",-1*"+q1+"*"+cost1+",1,'"+id1+"')";
}
//creating second and subsequent transactions
f (rowlen >= 2){
var cell2 = row[1].split('|');
var id2 = cell2[0];
var q2 = cell2[1].replace(',','.');
var cost2 = cell2[2].replace(',','.');
qry += " DECLARE @unit2 varchar(5)";
qry += " SET @unit2 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id2+"')";
qry += " INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += " VALUES (@transactionid,'1003','3','1',GETDATE(),@unit2,1,-1*"+q2+",-1*"+q2+"*"+cost2+",1,'"+id2+"')"; }
if (rowlen >= 3){
var cell3 = row[2].split('|');
var id3 = cell3[0];
var q3 = cell3[1].replace(',','.');
var cost3 = cell3[2].replace(',','.');
qry += " DECLARE @unit3 varchar(5)";
qry += " SET @unit3 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id3+"')";
qry += " INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += " VALUES (@transactionid,'1003','3','1',GETDATE(),@unit3,1,-1*"+q3+",-1*"+q3+"*"+cost3+",1,'"+id3+"')"; }
if (rowlen >= 4){
var cell4 = row[3].split('|');
var id4 = cell4[0];
var q4 = cell4[1].replace(',','.');
var cost4 = cell4[2].replace(',','.');
qry += " DECLARE @unit4 varchar(5)";
qry += " SET @unit4 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id4+"')";
qry += " INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += " VALUES (@transactionid,'1003','3','1',GETDATE(),@unit4,1,-1*"+q4+",-1*"+q4+"*"+cost4+",1,'"+id4+"')"; }
if (rowlen >= 5){
var cell5 = row[4].split('|');
var id5 = cell5[0];
var q5 = cell5[1].replace(',','.');
var cost5 = cell5[2].replace(',','.');
qry += "DECLARE @unit5 varchar(5)";
qry += "SET @unit5 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id5+"')";
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit5,1,-1*"+q5+",-1*"+q5+"*"+cost5+",1,'"+id5+"')"; }
if (rowlen >= 6){
var cell6 = row[5].split('|');
var id6 = cell6[0];
var q6 = cell6[1].replace(',','.');
var cost6 = cell6[2].replace(',','.');
qry += "DECLARE @unit6 varchar(5)";
qry += "SET @unit6 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id6+"')";
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit6,1,-1*"+q6+",-1*"+q6+"*"+cost6+",1,'"+id6+"')"; }
if (rowlen >= 7){
var cell7 = row[6].split('|');
var id7 = cell7[0];
var q7 = cell7[1].replace(',','.');
var cost7 = cell7[2].replace(',','.');
qry += "DECLARE @unit7 varchar(5)";
qry += "SET @unit7 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id7+"')";
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit7,1,-1*"+q7+",-1*"+q7+"*"+cost7+",1,'"+id7+"')"; }
if (rowlen >= 8){
var cell8 = row[7].split('|');
var id8 = cell8[0];
var q8 = cell8[1].replace(',','.');
var cost8 = cell8[2].replace(',','.');
qry += "DECLARE @unit8 varchar(5)";
qry += "SET @unit8 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id8+"')";
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])";
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit8,1,-1*"+q8+",-1*"+q8+"*"+cost8+",1,'"+id8+"')"; }
if (rowlen >= 9){
var cell9 = row[8].split('|');
var id9 = cell9[0];
var q9 = cell9[1].replace(',','.');
var cost9 = cell9[2].replace(',','.');
qry += "DECLARE @unit9 varchar(5)"
qry += "SET @unit9 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id9+"')"
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])"
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit9,1,-1*"+q9+",-1*"+q9+"*"+cost9+",1,'"+id9+"')"; }
if (rowlen >= 10){
var cell10 = row[9].split('|');
var id10 = cell10[0];
var q10 = cell10[1].replace(',','.');
var cost10 = cell10[2].replace(',','.');
qry += "DECLARE @unit10 varchar(5)"
qry += "SET @unit10 = (SELECT [BaseUnit] FROM [InventoryItems] WHERE [Id] = '"+id10+"')"
qry += "INSERT INTO [InventoryTransactions] ([InventoryTransactionDocumentId],[InventoryTransactionTypeId],[SourceWarehouseId],[TargetWarehouseId],[Date],[Unit],[Multiplier],[Quantity],[TotalPrice],[ExchangeRate],[InventoryItem_Id])"
qry += "VALUES (@transactionid,'1003','3','1',GETDATE(),@unit10,1,-1*"+q10+",-1*"+q10+"*"+cost10+",1,'"+id10+"')"; }
// sql query
if (rowlen >= 1 && id1 > 0 ){
var sqlqry = sql.ExecSql(qry)}
return sqlqry}