Really hope someone can help me with this as my head is battered trying to get this to work.
We have 2 places that we hold stock the shop (Default) and the warehouse (WH)and what we wish to do is have a script that can say where the stock is taken from to fulfil an order.
We have set up a basic rule in the RULES ENGINE that if the item is not in the UK the product location would be the warehouse and then have a script that checks the stock levels to ensure that the order can be fulfilled. However the orders are mixed and throwing all our stock levels out. The part that is winding me up is when I spot a order in the wrong location and run a test the script works and moves the order. Below is what we are trying to achieve with a chart and script and would be very grateful if anyone can help as my head is bursting.
The flow chart is this
Order destination Default WH Order Location
UK In stock In Stock Default
UK No Stock In Stock WH
UK No Stock No Stock WH
Non UK In Stock In stock WH
Non UK No Stock In Stock WH
Non UK No Stock No Stock WH
Script 1
namespace linnworks.finaware.CommonData.Objects // leave untouched { // leave untouched public class ScriptMacroClass : linnworks.scripting.core.IOrderScript // leave untouched { // leave untouched public void Initialize(linnworks.finaware.CommonData.Objects.Order order,linnworks.scripting.core.Debugger debug) // leave untouched { // leave untouched System.Collections.Generic.List<System.Guid> list = new System.Collections.Generic.List<System.Guid>(); // declare a list of unique ids
bool SufficientStockWH = true;// bool to flag if we have sufficient stock // Define Local variables string locationName = "WH"; string folderName = "Check For Location";
bool SufficientStockDefault = true;// bool to flag if we have sufficient stock // Define Local variables string locationName2 = "Default";
// lets collect all order items in to a list, so that we can bulk check the stock level for a specific location foreach(OrderItem i in order.OrderItems){ // itterate through all order items if (i.pkStockItemId != System.Guid.Empty){ // is order item linked? list.Add(i.pkStockItemId); // if yes add to the list } else if(!i.IsService && i.pkStockItemId == System.Guid.Empty) { // if not linked debug.AddEntry(i.ItemNumber + " is unlinked"); // add line to debug SufficientStockWH = false; // no sufficient stock - we have an unlinked item in the order } }
// we can get stock levels for a list of items in bulk using ListStockAvailablityInLocation method System.Collections.Generic.List<linnworks.finaware.CommonData.Inventory.StockItemAvailability> availabilityWH = linnworks.finaware.CommonData.Inventory.ListStockAvailablityInLocation(list, "WH", order.GetConnectionString); System.Collections.Generic.List<linnworks.finaware.CommonData.Inventory.StockItemAvailability> availabilityDefault = linnworks.finaware.CommonData.Inventory.ListStockAvailablityInLocation(list, "Default", order.GetConnectionString);
// iterate through the result set of ListStockAvailablityInLocation foreach(linnworks.finaware.CommonData.Inventory.StockItemAvailability aItem in availabilityWH){ debug.AddEntry(aItem.SKU + "=" + aItem.Available.ToString()); if (aItem.Available <= 0){ // if we have insufficent stock for one of the items SufficientStockWH = false; // set no Sufficient stock } }
foreach(linnworks.finaware.CommonData.Inventory.StockItemAvailability aItem in availabilityDefault){ debug.AddEntry(aItem.SKU + "=" + aItem.Available.ToString()); if (aItem.Available <= -1){ // if we have insufficent stock for one of the items SufficientStockDefault = false; // set no Sufficient stock } }
if (SufficientStockDefault == true && SufficientStockWH == false) { order.SetLocation(locationName2); debug.AddEntry("Order allocated to " + locationName2); order.Save(0); }
debug.DoNotLogScriptRun = true;
if (SufficientStockWH == false && SufficientStockDefault == false) { order.SetLocation(locationName); debug.AddEntry("Order allocated to " + locationName); order.Save(0); }
debug.DoNotLogScriptRun = true;
if (SufficientStockWH == true && SufficientStockDefault == false) { order.SetLocation(locationName); debug.AddEntry("Order allocated to " + locationName); order.Save(0); }
debug.DoNotLogScriptRun = true;
} // leave untouched
public string Filter(){ // leave untouched string query=@"SELECT o.pkOrderId FROM [Order] o INNER JOIN [OrderItem] oi on oi.fkOrderID = o.pkOrderID INNER JOIN [StockItems] sis on sis.pkStockID = oi.fkStockID INNER JOIN View_CombinedStock s on s.pkstockitemid = sis.fkStockControlStockItemId WHERE o.bProcessed =0 and o.nStatus!=0 and o.HoldOrCancel=0 and (oi.fkCompositeParentRowId is null or oi.fkCompositeParentRowId=dbo.emptyguid()) AND s.[Level]>0 GROUP BY o.pkOrderId"; return query;
Gary Langley
Hi All
Really hope someone can help me with this as my head is battered trying to get this to work.
We have 2 places that we hold stock the shop (Default) and the warehouse (WH)and what we wish to do is have a script that can say where the stock is taken from to fulfil an order.
We have set up a basic rule in the RULES ENGINE that if the item is not in the UK the product location would be the warehouse and then have a script that checks the stock levels to ensure that the order can be fulfilled. However the orders are mixed and throwing all our stock levels out. The part that is winding me up is when I spot a order in the wrong location and run a test the script works and moves the order. Below is what we are trying to achieve with a chart and script and would be very grateful if anyone can help as my head is bursting.
The flow chart is this
Order destination Default WH Order Location
UK In stock In Stock Default
UK No Stock In Stock WH
UK No Stock No Stock WH
Non UK In Stock In stock WH
Non UK No Stock In Stock WH
Non UK No Stock No Stock WH
Script 1
namespace linnworks.finaware.CommonData.Objects // leave untouched
{ // leave untouched
public class ScriptMacroClass : linnworks.scripting.core.IOrderScript // leave untouched
{ // leave untouched
public void Initialize(linnworks.finaware.CommonData.Objects.Order order,linnworks.scripting.core.Debugger debug) // leave untouched
{ // leave untouched
System.Collections.Generic.List<System.Guid> list = new System.Collections.Generic.List<System.Guid>(); // declare a list of unique ids
bool SufficientStockWH = true;// bool to flag if we have sufficient stock
// Define Local variables
string locationName = "WH";
string folderName = "Check For Location";
bool SufficientStockDefault = true;// bool to flag if we have sufficient stock
// Define Local variables
string locationName2 = "Default";
// lets collect all order items in to a list, so that we can bulk check the stock level for a specific location
foreach(OrderItem i in order.OrderItems){ // itterate through all order items
if (i.pkStockItemId != System.Guid.Empty){ // is order item linked?
list.Add(i.pkStockItemId); // if yes add to the list
}
else if(!i.IsService && i.pkStockItemId == System.Guid.Empty) { // if not linked
debug.AddEntry(i.ItemNumber + " is unlinked"); // add line to debug
SufficientStockWH = false; // no sufficient stock - we have an unlinked item in the order
}
}
// we can get stock levels for a list of items in bulk using ListStockAvailablityInLocation method
System.Collections.Generic.List<linnworks.finaware.CommonData.Inventory.StockItemAvailability> availabilityWH = linnworks.finaware.CommonData.Inventory.ListStockAvailablityInLocation(list, "WH", order.GetConnectionString);
System.Collections.Generic.List<linnworks.finaware.CommonData.Inventory.StockItemAvailability> availabilityDefault = linnworks.finaware.CommonData.Inventory.ListStockAvailablityInLocation(list, "Default", order.GetConnectionString);
// iterate through the result set of ListStockAvailablityInLocation
foreach(linnworks.finaware.CommonData.Inventory.StockItemAvailability aItem in availabilityWH){
debug.AddEntry(aItem.SKU + "=" + aItem.Available.ToString());
if (aItem.Available <= 0){ // if we have insufficent stock for one of the items
SufficientStockWH = false; // set no Sufficient stock
}
}
foreach(linnworks.finaware.CommonData.Inventory.StockItemAvailability aItem in availabilityDefault){
debug.AddEntry(aItem.SKU + "=" + aItem.Available.ToString());
if (aItem.Available <= -1){ // if we have insufficent stock for one of the items
SufficientStockDefault = false; // set no Sufficient stock
}
}
if (SufficientStockDefault == true && SufficientStockWH == false) {
order.SetLocation(locationName2);
debug.AddEntry("Order allocated to " + locationName2);
order.Save(0);
}
debug.DoNotLogScriptRun = true;
if (SufficientStockWH == false && SufficientStockDefault == false) {
order.SetLocation(locationName);
debug.AddEntry("Order allocated to " + locationName);
order.Save(0);
}
debug.DoNotLogScriptRun = true;
if (SufficientStockWH == true && SufficientStockDefault == false) {
order.SetLocation(locationName);
debug.AddEntry("Order allocated to " + locationName);
order.Save(0);
}
debug.DoNotLogScriptRun = true;
} // leave untouched
public string Filter(){ // leave untouched
string query=@"SELECT o.pkOrderId
FROM [Order] o
INNER JOIN [OrderItem] oi on oi.fkOrderID = o.pkOrderID
INNER JOIN [StockItems] sis on sis.pkStockID = oi.fkStockID
INNER JOIN View_CombinedStock s on s.pkstockitemid = sis.fkStockControlStockItemId
WHERE o.bProcessed =0 and o.nStatus!=0 and o.HoldOrCancel=0 and (oi.fkCompositeParentRowId is null or oi.fkCompositeParentRowId=dbo.emptyguid()) AND
s.[Level]>0
GROUP BY o.pkOrderId";
return query;
}
} // leave untouched
} // leave untouched