Skip to content

Commit ac07237

Browse files
author
Rowan Drew
committed
Fixes #8
--APIv1EndpointOrgProcurePurchaseOrderFromSupplier.java Added method to be able to obtain the index of the purchase order record and line that contains the unstocked supplier products. --APIv1EndpointResponseESD.java Added property to be able to obtain unstock order lines from procurement endpoint. --APIv1ExampleRunnerProcurePurchaseOrderFromSupplier.java Modified main method to show example of how to set text line in purchase orders, as well as how to handle unstocked error exception.
1 parent e545061 commit ac07237

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

src/org/squizz/api/v1/endpoint/APIv1EndpointOrgProcurePurchaseOrderFromSupplier.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,44 @@ public static ArrayList<Pair<Integer, Integer>> getUnpricedOrderLines(ESDocument
151151

152152
return unpricedOrderLines;
153153
}
154+
155+
/**
156+
* gets a list of order indexes that contain order lines that could not be stocked for a supplier organisation's products
157+
* @param esDocument Ecommerce standards document containing configuration that specifies unpriced order lines
158+
* @return an array containing pairs. Each pair has the index of the order, and the index of the order line that could not be stocked
159+
*/
160+
public static ArrayList<Pair<Integer, Integer>> getUnstockedOrderLines(ESDocument esDocument)
161+
{
162+
ArrayList<Pair<Integer, Integer>> unstockedOrderLines = new ArrayList<>();
163+
164+
//check that the ecommerce standards document's configs contains a key specifying the unstocked order lines
165+
if(esDocument.configs.containsKey(APIv1EndpointResponseESD.ESD_CONFIG_ORDERS_WITH_UNSTOCKED_LINES))
166+
{
167+
//get comma separated list of order record indicies and line indicies that indicate the unstocked order lines
168+
String unstockedOrderLineCSV = esDocument.configs.get(APIv1EndpointResponseESD.ESD_CONFIG_ORDERS_WITH_UNSTOCKED_LINES);
169+
170+
//get the index of the order record and line that contained the unstocked product
171+
if(!unstockedOrderLineCSV.trim().isEmpty()){
172+
String[] unmappedOrderLineIndices = unstockedOrderLineCSV.trim().split(",");
173+
174+
//iterate through each order-line index
175+
for(int i=0; i < unmappedOrderLineIndices.length; i++){
176+
//get order index and line index
177+
String[] orderLineIndex = unmappedOrderLineIndices[i].split(":");
178+
if(orderLineIndex.length == 2){
179+
try{
180+
int orderIndex = Integer.parseInt(orderLineIndex[0]);
181+
int lineIndex = Integer.parseInt(orderLineIndex[1]);
182+
Pair<Integer, Integer> orderLinePair = new Pair<>(orderIndex, lineIndex);
183+
unstockedOrderLines.add(orderLinePair);
184+
185+
}catch(Exception ex){
186+
}
187+
}
188+
}
189+
}
190+
}
191+
192+
return unstockedOrderLines;
193+
}
154194
}

src/org/squizz/api/v1/endpoint/APIv1EndpointResponseESD.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class APIv1EndpointResponseESD
1717
{
1818
public static final String ESD_CONFIG_ORDERS_WITH_UNMAPPED_LINES = "orders_with_unmapped_lines";
1919
public static final String ESD_CONFIG_ORDERS_WITH_UNPRICED_LINES = "orders_with_unpriced_lines";
20+
public static final String ESD_CONFIG_ORDERS_WITH_UNSTOCKED_LINES = "orders_with_unstocked_lines";
2021

2122
//set default values for the response
2223
public String result = ENDPOINT_RESULT_FAILURE;

test/org/squizz/api/v1/example/APIv1ExampleRunnerProcurePurchaseOrderFromSupplier.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public static void main(String[] args)
9393
orderProduct.lineType = ESDocumentConstants.ORDER_LINE_TYPE_PRODUCT;
9494
orderProduct.productCode = "TEA-TOWEL-GREEN";
9595
orderProduct.productName = "Green tea towel - 30 x 6 centimetres";
96-
orderProduct.keySellUnitID = "2";
9796
orderProduct.unitName = "EACH";
9897
orderProduct.quantity = 4;
9998
orderProduct.sellUnitBaseQuantity = 4;
@@ -104,8 +103,22 @@ public static void main(String[] args)
104103
orderProduct.priceTotalIncTax = 22.00;
105104
orderProduct.priceTotalExTax = 20.00;
106105
orderProduct.priceTotalTax = 2.00;
106+
orderLines.add(orderProduct);
107+
108+
//add a 2nd purchase order line record that is a text line
109+
orderProduct = new ESDRecordOrderPurchaseLine();
110+
orderProduct.lineType = ESDocumentConstants.ORDER_LINE_TYPE_TEXT;
111+
orderProduct.productCode = "TEA-TOWEL-BLUE";
112+
orderProduct.textDescription = "Please bundle tea towels into a box";
113+
orderLines.add(orderProduct);
107114

108-
//add order line to lines list
115+
//add a 3rd purhase order line record
116+
orderProduct = new ESDRecordOrderPurchaseLine();
117+
orderProduct.lineType = ESDocumentConstants.ORDER_LINE_TYPE_PRODUCT;
118+
orderProduct.productCode = "PINKDOU";
119+
orderProduct.productName = "Blue tea towel - 30 x 6 centimetres";
120+
orderProduct.quantity = 2;
121+
orderProduct.salesOrderProductCode = "ACME-SUPPLIER-TTBLUE";
109122
orderLines.add(orderProduct);
110123

111124
//add order lines to the order
@@ -185,6 +198,27 @@ else if(endpointResponseESD.result_code.equals(APIv1EndpointResponse.ENDPOINT_RE
185198
}
186199
}
187200
}
201+
//if one or more products in the purchase order did not have stock available by the supplier organisation then find the order line that caused the problem
202+
else if(endpointResponseESD.result_code.equals(APIv1EndpointResponse.ENDPOINT_RESULT_CODE_ERROR_ORDER_MAPPED_PRODUCT_STOCK_NOT_AVAILABLE) && esDocumentOrderSale != null)
203+
{
204+
if(esDocumentOrderSale.configs.containsKey(APIv1EndpointResponseESD.ESD_CONFIG_ORDERS_WITH_UNSTOCKED_LINES))
205+
{
206+
//get a list of order lines that could not be stocked
207+
ArrayList<Pair<Integer, Integer>> unstockedLines = APIv1EndpointOrgProcurePurchaseOrderFromSupplier.getUnstockedOrderLines(esDocumentOrderSale);
208+
209+
//iterate through each unstocked order line
210+
for(Pair<Integer, Integer> unstockedLine : unstockedLines){
211+
//get the index of the purchase order and line that contained the unstocked product
212+
int orderIndex = unstockedLine.getKey();
213+
int lineIndex = unstockedLine.getValue();
214+
215+
//check that the order can be found that contains the problematic line
216+
if(orderIndex < orderPurchaseESD.dataRecords.length && lineIndex < orderPurchaseESD.dataRecords[orderIndex].lines.size()){
217+
System.out.println("For purchase order: "+ orderPurchaseESD.dataRecords[orderIndex].purchaseOrderCode + " the supplier has no stock available for line number: " + (lineIndex+1));
218+
}
219+
}
220+
}
221+
}
188222
}
189223
}
190224

0 commit comments

Comments
 (0)