2
2
3
3
class MplusQAPIclient
4
4
{
5
- const CLIENT_VERSION = '1.6 .0 ' ;
5
+ const CLIENT_VERSION = '1.7 .0 ' ;
6
6
7
7
8
8
var $ MIN_API_VERSION_MAJOR = 0 ;
@@ -1096,6 +1096,26 @@ public function getRetailSpaceRentals($attempts=0)
1096
1096
1097
1097
//----------------------------------------------------------------------------
1098
1098
1099
+ public function getExchangeRateHistory ($ sinceStockId , $ attempts =0 )
1100
+ {
1101
+ try {
1102
+ $ result = $ this ->client ->getExchangeRateHistory ($ this ->parser ->convertGetExchangeRateHistoryRequest ($ sinceStockId ));
1103
+ return $ this ->parser ->parseGetExchangeRateHistoryResult ($ result );
1104
+ } catch (SoapFault $ e ) {
1105
+ $ msg = $ e ->getMessage ();
1106
+ if (false !== stripos ($ msg , 'Could not connect to host ' ) and $ attempts < 3 ) {
1107
+ sleep (1 );
1108
+ return $ this ->getExchangeRateHistory ($ sinceStockId , $ attempts +1 );
1109
+ } else {
1110
+ throw new MplusQAPIException ('SoapFault occurred: ' .$ msg , 0 , $ e );
1111
+ }
1112
+ } catch (Exception $ e ) {
1113
+ throw new MplusQAPIException ('Exception occurred: ' .$ e ->getMessage (), 0 , $ e );
1114
+ }
1115
+ } // END getExchangeRateHistory()
1116
+
1117
+ //----------------------------------------------------------------------------
1118
+
1099
1119
public function getProducts ($ articleNumbers = array (), $ groupNumbers = array (), $ pluNumbers = array (), $ changedSinceTimestamp = null , $ changedSinceBranchNumber = null , $ syncMarker = null , $ onlyWebshop = null , $ onlyActive = null , $ syncMarkerLimit = null , $ attempts = 0 )
1100
1120
{
1101
1121
try {
@@ -1478,16 +1498,16 @@ public function deliverOrder($orderId)
1478
1498
1479
1499
//----------------------------------------------------------------------------
1480
1500
1481
- public function deliverOrderV2 ($ order , $ attempts =0 )
1501
+ public function deliverOrderV2 ($ orderDelivery , $ attempts =0 )
1482
1502
{
1483
1503
try {
1484
- $ result = $ this ->client ->deliverOrderV2 ($ this ->parser ->convertDeliverOrderV2Request ($ order ));
1504
+ $ result = $ this ->client ->deliverOrderV2 ($ this ->parser ->convertDeliverOrderV2Request ($ orderDelivery ));
1485
1505
return $ this ->parser ->parseDeliverOrderV2Result ($ result );
1486
1506
} catch (SoapFault $ e ) {
1487
1507
$ msg = $ e ->getMessage ();
1488
1508
if (false !== stripos ($ msg , 'Could not connect to host ' ) and $ attempts < 3 ) {
1489
1509
sleep (1 );
1490
- return $ this ->deliverOrderV2 ($ order , $ attempts +1 );
1510
+ return $ this ->deliverOrderV2 ($ orderDelivery , $ attempts +1 );
1491
1511
} else {
1492
1512
throw new MplusQAPIException ('SoapFault occurred: ' .$ msg , 0 , $ e );
1493
1513
}
@@ -1632,6 +1652,26 @@ public function getOrderCategories($attempts=0)
1632
1652
1633
1653
//----------------------------------------------------------------------------
1634
1654
1655
+ public function getInterbranchOrders ($ syncMarker , $ syncMarkerLimit =null , $ attempts =0 )
1656
+ {
1657
+ try {
1658
+ $ result = $ this ->client ->getInterbranchOrders ($ this ->parser ->convertGetInterbranchOrdersRequest ($ syncMarker , $ syncMarkerLimit ));
1659
+ return $ this ->parser ->parseGetInterbranchOrdersResult ($ result );
1660
+ } catch (SoapFault $ e ) {
1661
+ $ msg = $ e ->getMessage ();
1662
+ if (false !== stripos ($ msg , 'Could not connect to host ' ) and $ attempts < 3 ) {
1663
+ sleep (1 );
1664
+ return $ this ->getInterbranchOrders ($ syncMarker , $ attempts +1 );
1665
+ } else {
1666
+ throw new MplusQAPIException ('SoapFault occurred: ' .$ msg , 0 , $ e );
1667
+ }
1668
+ } catch (Exception $ e ) {
1669
+ throw new MplusQAPIException ('Exception occurred: ' .$ e ->getMessage (), 0 , $ e );
1670
+ }
1671
+ } // END getInterbranchOrders()
1672
+
1673
+ //----------------------------------------------------------------------------
1674
+
1635
1675
public function getReceipts ($ syncMarker , $ fromFinancialDate , $ throughFinancialDate , $ branchNumbers =null , $ employeeNumbers =null , $ relationNumbers =null , $ articleNumbers =null , $ articleTurnoverGroups =null , $ articlePluNumbers =null , $ articleBarcodes =null , $ supplierRelationNumbers =null , $ syncMarkerLimit =null , $ attempts =0 )
1636
1676
{
1637
1677
try {
@@ -2100,7 +2140,7 @@ public function saveOrder($order)
2100
2140
public function queueBranchOrder ($ order , $ attempts =0 )
2101
2141
{
2102
2142
try {
2103
- if (false !== ($ result = $ this ->client ->queueBranchOrder ($ this ->parser ->convertOrder ($ orderId )))) {
2143
+ if (false !== ($ result = $ this ->client ->queueBranchOrder ($ this ->parser ->convertOrder ($ order )))) {
2104
2144
return $ this ->parser ->parseQueueBranchOrderResult ($ result );
2105
2145
}
2106
2146
} catch (SoapFault $ e ) {
@@ -2121,7 +2161,7 @@ public function queueBranchOrder($order, $attempts=0)
2121
2161
public function cancelOrder ($ orderId , $ attempts =0 )
2122
2162
{
2123
2163
try {
2124
- if (false !== ($ result = $ this ->client ->cancelOrder ($ this ->parser ->convertOrder ($ orderId )))) {
2164
+ if (false !== ($ result = $ this ->client ->cancelOrder ($ this ->parser ->convertOrderId ($ orderId )))) {
2125
2165
return $ this ->parser ->parseCancelOrderResult ($ result );
2126
2166
}
2127
2167
} catch (SoapFault $ e ) {
@@ -2964,6 +3004,14 @@ public function parseProducts($soapProducts)
2964
3004
if (isset ($ article ['customFieldList ' ]['customField ' ])) {
2965
3005
$ article ['customFieldList ' ] = $ article ['customFieldList ' ]['customField ' ];
2966
3006
}
3007
+ if (isset ($ article ['exchangeRateBuyPrice ' ]) and isset ($ article ['exchangeRateBuyPriceDecimalPlaces ' ])) {
3008
+ $ article ['exchangeRateBuyPrice ' ] = from_quantity_and_decimal_places ($ article ['exchangeRateBuyPrice ' ], $ article ['exchangeRateBuyPriceDecimalPlaces ' ]);
3009
+ unset($ article ['exchangeRateBuyPriceDecimalPlaces ' ]);
3010
+ }
3011
+ if (isset ($ article ['exchangeRateSellPrice ' ]) and isset ($ article ['exchangeRateSellPriceDecimalPlaces ' ])) {
3012
+ $ article ['exchangeRateSellPrice ' ] = from_quantity_and_decimal_places ($ article ['exchangeRateSellPrice ' ], $ article ['exchangeRateSellPriceDecimalPlaces ' ]);
3013
+ unset($ article ['exchangeRateSellPriceDecimalPlaces ' ]);
3014
+ }
2967
3015
$ product ['articleList ' ][$ idx ] = $ article ;
2968
3016
}
2969
3017
}
@@ -3248,7 +3296,8 @@ public function parseShifts($soapShifts) {
3248
3296
3249
3297
public function parseOrderResult ($ soapOrderResult )
3250
3298
{
3251
- if (isset ($ soapOrderResult ->result ) and $ soapOrderResult ->result == 'GET-ORDER-RESULT-OK ' ) {
3299
+ if (isset ($ soapOrderResult ->result )) {
3300
+ if ($ soapOrderResult ->result == 'GET-ORDER-RESULT-OK ' ) {
3252
3301
if (isset ($ soapOrderResult ->order )) {
3253
3302
$ soapOrder = $ soapOrderResult ->order ;
3254
3303
$ order = objectToArray ($ soapOrder );
@@ -3264,8 +3313,12 @@ public function parseOrderResult($soapOrderResult)
3264
3313
}
3265
3314
return $ order ;
3266
3315
}
3316
+ } else {
3317
+ throw new MplusQAPIException ($ soapOrderResult ->result );
3318
+ }
3319
+ } else {
3320
+ throw new MplusQAPIException ('No valid order result ' );
3267
3321
}
3268
- return false ;
3269
3322
} // END parseOrderResult()
3270
3323
3271
3324
//----------------------------------------------------------------------------
@@ -3577,6 +3630,32 @@ public function parseGetOrdersResult($soapOrdersResult)
3577
3630
3578
3631
//----------------------------------------------------------------------------
3579
3632
3633
+ public function parseGetInterbranchOrdersResult ($ soapInterbranchOrdersResult )
3634
+ {
3635
+ $ interbranch_orders = array ();
3636
+ if (isset ($ soapInterbranchOrdersResult ->interbranchOrderList ->interbranchOrder )) {
3637
+ $ soapInterbranchOrders = $ soapInterbranchOrdersResult ->interbranchOrderList ->interbranchOrder ;
3638
+ $ interbranch_orders = objectToArray ($ soapInterbranchOrders );
3639
+ foreach ($ interbranch_orders as $ key => $ interbranch_order ) {
3640
+ /*if (isset($interbranch_order['lineList']['line'])) {
3641
+ $interbranch_order['lineList'] = $interbranch_order['lineList']['line'];
3642
+ } else {
3643
+ $interbranch_order['lineList'] = array();
3644
+ }
3645
+ foreach ($interbranch_order['lineList'] as $line_key => $line) {
3646
+ if (isset($line['preparationList']['line'])) {
3647
+ $line['preparationList'] = $line['preparationList']['line'];
3648
+ }
3649
+ $interbranch_order['lineList'][$line_key] = $line;
3650
+ }*/
3651
+ $ interbranch_orders [$ key ] = $ interbranch_order ;
3652
+ }
3653
+ }
3654
+ return $ interbranch_orders ;
3655
+ } // END parseGetInterbranchOrdersResult()
3656
+
3657
+ //----------------------------------------------------------------------------
3658
+
3580
3659
public function parseGetPackingSlipsByOrderResult ($ soapPackingSlipsByOrdersResult )
3581
3660
{
3582
3661
$ packing_slips = array ();
@@ -3777,6 +3856,33 @@ public function parseGetRetailSpaceRentalsResult($soapGetRetailSpaceRentalResult
3777
3856
3778
3857
//----------------------------------------------------------------------------
3779
3858
3859
+ public function parseGetExchangeRateHistoryResult ($ soapGetExchangeRateHistoryResult ) {
3860
+ $ exchangeRateHistory = array ();
3861
+ if (isset ($ soapGetExchangeRateHistoryResult ->exchangeRateHistoryList ->exchangeRateHistory )) {
3862
+ $ soapExchangeRateHistory = $ soapGetExchangeRateHistoryResult ->exchangeRateHistoryList ->exchangeRateHistory ;
3863
+ $ exchangeRateHistory = objectToArray ($ soapExchangeRateHistory );
3864
+ foreach ($ exchangeRateHistory as $ idx => $ erh ) {
3865
+ $ erh ['timestamp ' ] = $ this ->parseMplusDateTime ($ erh ['timestamp ' ]);
3866
+ if (isset ($ erh ['buyPriceOld ' ])) {
3867
+ $ erh ['buyPriceOld ' ] = from_quantity_and_decimal_places ($ erh ['buyPriceOld ' ], isset ($ erh ['buyPriceDecimalPlacesOld ' ])?$ erh ['buyPriceDecimalPlacesOld ' ]:0 );
3868
+ }
3869
+ if (isset ($ erh ['buyPriceNew ' ])) {
3870
+ $ erh ['buyPriceNew ' ] = from_quantity_and_decimal_places ($ erh ['buyPriceNew ' ], isset ($ erh ['buyPriceDecimalPlacesNew ' ])?$ erh ['buyPriceDecimalPlacesNew ' ]:0 );
3871
+ }
3872
+ if (isset ($ erh ['sellPriceOld ' ])) {
3873
+ $ erh ['sellPriceOld ' ] = from_quantity_and_decimal_places ($ erh ['sellPriceOld ' ], isset ($ erh ['sellPriceDecimalPlacesOld ' ])?$ erh ['sellPriceDecimalPlacesOld ' ]:0 );
3874
+ }
3875
+ if (isset ($ erh ['sellPriceNew ' ])) {
3876
+ $ erh ['sellPriceNew ' ] = from_quantity_and_decimal_places ($ erh ['sellPriceNew ' ], isset ($ erh ['sellPriceDecimalPlacesNew ' ])?$ erh ['sellPriceDecimalPlacesNew ' ]:0 );
3877
+ }
3878
+ $ exchangeRateHistory [$ idx ] = $ erh ;
3879
+ }
3880
+ }
3881
+ return $ exchangeRateHistory ;
3882
+ } // END parseGetExchangeRateHistoryResult()
3883
+
3884
+ //----------------------------------------------------------------------------
3885
+
3780
3886
public function parseGetAllergensResult ($ soapGetAllergensResult ) {
3781
3887
$ allergens = array ();
3782
3888
if (isset ($ soapGetAllergensResult ->allergens ->allergen )) {
@@ -4899,6 +5005,21 @@ public function convertGetOrdersRequest($syncMarker, $fromFinancialDate, $throug
4899
5005
4900
5006
//----------------------------------------------------------------------------
4901
5007
5008
+ public function convertGetInterbranchOrdersRequest ($ syncMarker , $ syncMarkerLimit )
5009
+ {
5010
+ $ array = array ();
5011
+ if ( ! is_null ($ syncMarker )) {
5012
+ $ array ['syncMarker ' ] = (int )$ syncMarker ;
5013
+ if ( ! is_null ($ syncMarkerLimit ) and $ syncMarkerLimit > 0 ) {
5014
+ $ array ['syncMarkerLimit ' ] = (int )$ syncMarkerLimit ;
5015
+ }
5016
+ }
5017
+ $ object = arrayToObject (array ('request ' =>$ array ));
5018
+ return $ object ;
5019
+ } // END convertGetInterbranchOrdersRequest()
5020
+
5021
+ //----------------------------------------------------------------------------
5022
+
4902
5023
public function convertGetPackingSlipsByOrderRequest ($ orderId )
4903
5024
{
4904
5025
$ array = array (
@@ -5145,10 +5266,10 @@ public function convertDeliverOrderRequest($orderId)
5145
5266
5146
5267
//----------------------------------------------------------------------------
5147
5268
5148
- public function convertDeliverOrderV2Request ($ order )
5269
+ public function convertDeliverOrderV2Request ($ orderDelivery )
5149
5270
{
5150
5271
$ array = array ('request ' =>array (
5151
- 'order ' =>$ this ->convertOrder ( $ order , true ),
5272
+ 'orderDelivery ' =>$ this ->convertOrderDelivery ( $ orderDelivery , true ),
5152
5273
));
5153
5274
$ object = arrayToObject ($ array );
5154
5275
return $ object ;
@@ -5327,6 +5448,18 @@ public function convertGetStockHistoryRequest($branchNumber, $articleNumbers, $s
5327
5448
5328
5449
//----------------------------------------------------------------------------
5329
5450
5451
+ public function convertGetExchangeRateHistoryRequest ($ sinceStockId )
5452
+ {
5453
+ $ array = array ('request ' =>array ());
5454
+ if ( ! is_null ($ sinceStockId ) and ! empty ($ sinceStockId )) {
5455
+ $ array ['request ' ]['sinceStockId ' ] = $ sinceStockId ;
5456
+ }
5457
+ $ object = arrayToObject ($ array );
5458
+ return $ object ;
5459
+ } // END convertGetExchangeRateHistoryRequest()
5460
+
5461
+ //----------------------------------------------------------------------------
5462
+
5330
5463
public function convertUpdateStockRequest ($ branchNumber , $ articleNumber , $ amountChanged )
5331
5464
{
5332
5465
list ($ amountChanged , $ decimalPlaces ) = get_quantity_and_decimal_places ($ amountChanged );
@@ -5599,6 +5732,12 @@ public function convertProduct($product, $add_default_fields=false)
5599
5732
// Andere indexing levert problemen op met PHP SOAP client
5600
5733
$ article ['barcodeList ' ]['barcode ' ] = array_values ($ article ['barcodeList ' ]['barcode ' ]);
5601
5734
}
5735
+ if (isset ($ article ['exchangeRateBuyPrice ' ]) and ! isset ($ article ['exchangeRateBuyPriceDecimalPlaces ' ])) {
5736
+ list ($ article ['exchangeRateBuyPrice ' ], $ article ['exchangeRateBuyPriceDecimalPlaces ' ]) = get_quantity_and_decimal_places ($ article ['exchangeRateBuyPrice ' ]);
5737
+ }
5738
+ if (isset ($ article ['exchangeRateSellPrice ' ]) and ! isset ($ article ['exchangeRateSellPriceDecimalPlaces ' ])) {
5739
+ list ($ article ['exchangeRateSellPrice ' ], $ article ['exchangeRateSellPriceDecimalPlaces ' ]) = get_quantity_and_decimal_places ($ article ['exchangeRateSellPrice ' ]);
5740
+ }
5602
5741
$ product ['articleList ' ]['article ' ][$ idx ] = $ article ;
5603
5742
}
5604
5743
// Hier even een array_values() om zeker te weten dat de array 0, 1, 2 geïndexeerd is
@@ -5752,6 +5891,22 @@ public function convertOrder($order, $as_array=false)
5752
5891
5753
5892
//----------------------------------------------------------------------------
5754
5893
5894
+ public function convertOrderDelivery ($ orderDelivery , $ as_array =false )
5895
+ {
5896
+ if ( ! isset ($ orderDelivery ['orderId ' ]) or is_null ($ orderDelivery ['orderId ' ])) {
5897
+ $ orderDelivery ['orderId ' ] = '' ;
5898
+ }
5899
+ $ orderDelivery ['lineList ' ] = $ this ->convertOrderDeliveryLineList ($ orderDelivery ['lineList ' ]);
5900
+ if ($ as_array ) {
5901
+ return $ orderDelivery ;
5902
+ } else {
5903
+ $ object = arrayToObject (array ('orderDelivery ' =>$ orderDelivery ));
5904
+ return $ object ;
5905
+ }
5906
+ } // END convertOrderDelivery()
5907
+
5908
+ //----------------------------------------------------------------------------
5909
+
5755
5910
public function convertInvoice ($ invoice )
5756
5911
{
5757
5912
if ( ! isset ($ invoice ['invoiceId ' ])) {
@@ -5993,6 +6148,17 @@ public function convertLineList($lineList, $is_preparationList=false)
5993
6148
5994
6149
//----------------------------------------------------------------------------
5995
6150
6151
+ public function convertOrderDeliveryLineList ($ orderDeliverylineList )
6152
+ {
6153
+ if ( ! isset ($ orderDeliverylineList ['line ' ]) and ! empty ($ orderDeliverylineList )) {
6154
+ $ orderDeliverylineList = array ('line ' =>$ orderDeliverylineList );
6155
+ }
6156
+ $ object = arrayToObject ($ orderDeliverylineList );
6157
+ return $ object ;
6158
+ } // END convertOrderDeliveryLineList()
6159
+
6160
+ //----------------------------------------------------------------------------
6161
+
5996
6162
public function convertPurchaseOrderLineList ($ lineList )
5997
6163
{
5998
6164
if ( ! isset ($ lineList ['line ' ]) and ! empty ($ lineList )) {
@@ -6331,14 +6497,14 @@ class MplusQAPIException extends Exception
6331
6497
function get_quantity_and_decimal_places ($ input )
6332
6498
{
6333
6499
$ input = str_replace (', ' , '. ' , $ input );
6334
- $ input = round ($ input , 5 );
6500
+ $ input = round ($ input , 6 );
6335
6501
$ orig_input = $ input ;
6336
6502
$ decimalPlaces = -1 ;
6337
6503
do {
6338
6504
$ int_part = (int )$ input ;
6339
6505
$ input -= $ int_part ;
6340
6506
$ input *= 10 ;
6341
- $ input = round ($ input , 5 );
6507
+ $ input = round ($ input , 6 );
6342
6508
$ decimalPlaces ++;
6343
6509
} while ($ input >= 0.0000001 );
6344
6510
$ quantity = (int )($ orig_input * pow (10 , $ decimalPlaces ));
@@ -6463,6 +6629,9 @@ function arrayToObject($d, $leave_as_array=null, $debug=false) {
6463
6629
elseif (is_array ($ d ) and isset ($ d [0 ]) and is_array ($ d [0 ]) and isset ($ d [0 ]['id ' ])) {
6464
6630
return array_map (__FUNCTION__ , $ d );
6465
6631
}
6632
+ elseif (is_array ($ d ) and isset ($ d [0 ]) and is_array ($ d [0 ]) and isset ($ d [0 ]['lineId ' ])) {
6633
+ return array_map (__FUNCTION__ , $ d );
6634
+ }
6466
6635
elseif (is_array ($ d ) and isset ($ d [0 ]) and is_array ($ d [0 ]) and isset ($ d [0 ]['group ' ])) {
6467
6636
return array_map (__FUNCTION__ , $ d );
6468
6637
}
0 commit comments