Skip to content

Commit cb42f53

Browse files
author
Mplus Software
committed
v1.7.0
- New function getExchangeRateHistory - New function getInterbranchOrders - Decimal numbers with up to 6 decimals supported - Fixed a bug in cancelOrder
1 parent cecca53 commit cb42f53

File tree

1 file changed

+181
-12
lines changed

1 file changed

+181
-12
lines changed

Mplusqapiclient.php

Lines changed: 181 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class MplusQAPIclient
44
{
5-
const CLIENT_VERSION = '1.6.0';
5+
const CLIENT_VERSION = '1.7.0';
66

77

88
var $MIN_API_VERSION_MAJOR = 0;
@@ -1096,6 +1096,26 @@ public function getRetailSpaceRentals($attempts=0)
10961096

10971097
//----------------------------------------------------------------------------
10981098

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+
10991119
public function getProducts($articleNumbers = array(), $groupNumbers = array(), $pluNumbers = array(), $changedSinceTimestamp = null, $changedSinceBranchNumber = null, $syncMarker = null, $onlyWebshop = null, $onlyActive = null, $syncMarkerLimit = null, $attempts = 0)
11001120
{
11011121
try {
@@ -1478,16 +1498,16 @@ public function deliverOrder($orderId)
14781498

14791499
//----------------------------------------------------------------------------
14801500

1481-
public function deliverOrderV2($order, $attempts=0)
1501+
public function deliverOrderV2($orderDelivery, $attempts=0)
14821502
{
14831503
try {
1484-
$result = $this->client->deliverOrderV2($this->parser->convertDeliverOrderV2Request($order));
1504+
$result = $this->client->deliverOrderV2($this->parser->convertDeliverOrderV2Request($orderDelivery));
14851505
return $this->parser->parseDeliverOrderV2Result($result);
14861506
} catch (SoapFault $e) {
14871507
$msg = $e->getMessage();
14881508
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
14891509
sleep(1);
1490-
return $this->deliverOrderV2($order, $attempts+1);
1510+
return $this->deliverOrderV2($orderDelivery, $attempts+1);
14911511
} else {
14921512
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
14931513
}
@@ -1632,6 +1652,26 @@ public function getOrderCategories($attempts=0)
16321652

16331653
//----------------------------------------------------------------------------
16341654

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+
16351675
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)
16361676
{
16371677
try {
@@ -2100,7 +2140,7 @@ public function saveOrder($order)
21002140
public function queueBranchOrder($order, $attempts=0)
21012141
{
21022142
try {
2103-
if (false !== ($result = $this->client->queueBranchOrder($this->parser->convertOrder($orderId)))) {
2143+
if (false !== ($result = $this->client->queueBranchOrder($this->parser->convertOrder($order)))) {
21042144
return $this->parser->parseQueueBranchOrderResult($result);
21052145
}
21062146
} catch (SoapFault $e) {
@@ -2121,7 +2161,7 @@ public function queueBranchOrder($order, $attempts=0)
21212161
public function cancelOrder($orderId, $attempts=0)
21222162
{
21232163
try {
2124-
if (false !== ($result = $this->client->cancelOrder($this->parser->convertOrder($orderId)))) {
2164+
if (false !== ($result = $this->client->cancelOrder($this->parser->convertOrderId($orderId)))) {
21252165
return $this->parser->parseCancelOrderResult($result);
21262166
}
21272167
} catch (SoapFault $e) {
@@ -2964,6 +3004,14 @@ public function parseProducts($soapProducts)
29643004
if (isset($article['customFieldList']['customField'])) {
29653005
$article['customFieldList'] = $article['customFieldList']['customField'];
29663006
}
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+
}
29673015
$product['articleList'][$idx] = $article;
29683016
}
29693017
}
@@ -3248,7 +3296,8 @@ public function parseShifts($soapShifts) {
32483296

32493297
public function parseOrderResult($soapOrderResult)
32503298
{
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') {
32523301
if (isset($soapOrderResult->order)) {
32533302
$soapOrder = $soapOrderResult->order;
32543303
$order = objectToArray($soapOrder);
@@ -3264,8 +3313,12 @@ public function parseOrderResult($soapOrderResult)
32643313
}
32653314
return $order;
32663315
}
3316+
} else {
3317+
throw new MplusQAPIException($soapOrderResult->result);
3318+
}
3319+
} else {
3320+
throw new MplusQAPIException('No valid order result');
32673321
}
3268-
return false;
32693322
} // END parseOrderResult()
32703323

32713324
//----------------------------------------------------------------------------
@@ -3577,6 +3630,32 @@ public function parseGetOrdersResult($soapOrdersResult)
35773630

35783631
//----------------------------------------------------------------------------
35793632

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+
35803659
public function parseGetPackingSlipsByOrderResult($soapPackingSlipsByOrdersResult)
35813660
{
35823661
$packing_slips = array();
@@ -3777,6 +3856,33 @@ public function parseGetRetailSpaceRentalsResult($soapGetRetailSpaceRentalResult
37773856

37783857
//----------------------------------------------------------------------------
37793858

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+
37803886
public function parseGetAllergensResult($soapGetAllergensResult) {
37813887
$allergens = array();
37823888
if (isset($soapGetAllergensResult->allergens->allergen)) {
@@ -4899,6 +5005,21 @@ public function convertGetOrdersRequest($syncMarker, $fromFinancialDate, $throug
48995005

49005006
//----------------------------------------------------------------------------
49015007

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+
49025023
public function convertGetPackingSlipsByOrderRequest($orderId)
49035024
{
49045025
$array = array(
@@ -5145,10 +5266,10 @@ public function convertDeliverOrderRequest($orderId)
51455266

51465267
//----------------------------------------------------------------------------
51475268

5148-
public function convertDeliverOrderV2Request($order)
5269+
public function convertDeliverOrderV2Request($orderDelivery)
51495270
{
51505271
$array = array('request'=>array(
5151-
'order'=>$this->convertOrder($order, true),
5272+
'orderDelivery'=>$this->convertOrderDelivery($orderDelivery, true),
51525273
));
51535274
$object = arrayToObject($array);
51545275
return $object;
@@ -5327,6 +5448,18 @@ public function convertGetStockHistoryRequest($branchNumber, $articleNumbers, $s
53275448

53285449
//----------------------------------------------------------------------------
53295450

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+
53305463
public function convertUpdateStockRequest($branchNumber, $articleNumber, $amountChanged)
53315464
{
53325465
list($amountChanged, $decimalPlaces) = get_quantity_and_decimal_places($amountChanged);
@@ -5599,6 +5732,12 @@ public function convertProduct($product, $add_default_fields=false)
55995732
// Andere indexing levert problemen op met PHP SOAP client
56005733
$article['barcodeList']['barcode'] = array_values($article['barcodeList']['barcode']);
56015734
}
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+
}
56025741
$product['articleList']['article'][$idx] = $article;
56035742
}
56045743
// 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)
57525891

57535892
//----------------------------------------------------------------------------
57545893

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+
57555910
public function convertInvoice($invoice)
57565911
{
57575912
if ( ! isset($invoice['invoiceId'])) {
@@ -5993,6 +6148,17 @@ public function convertLineList($lineList, $is_preparationList=false)
59936148

59946149
//----------------------------------------------------------------------------
59956150

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+
59966162
public function convertPurchaseOrderLineList($lineList)
59976163
{
59986164
if ( ! isset($lineList['line']) and ! empty($lineList)) {
@@ -6331,14 +6497,14 @@ class MplusQAPIException extends Exception
63316497
function get_quantity_and_decimal_places($input)
63326498
{
63336499
$input = str_replace(',', '.', $input);
6334-
$input = round($input, 5);
6500+
$input = round($input, 6);
63356501
$orig_input = $input;
63366502
$decimalPlaces = -1;
63376503
do {
63386504
$int_part = (int)$input;
63396505
$input -= $int_part;
63406506
$input *= 10;
6341-
$input = round($input, 5);
6507+
$input = round($input, 6);
63426508
$decimalPlaces++;
63436509
} while ($input >= 0.0000001);
63446510
$quantity = (int)($orig_input * pow(10, $decimalPlaces));
@@ -6463,6 +6629,9 @@ function arrayToObject($d, $leave_as_array=null, $debug=false) {
64636629
elseif (is_array($d) and isset($d[0]) and is_array($d[0]) and isset($d[0]['id'])) {
64646630
return array_map(__FUNCTION__, $d);
64656631
}
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+
}
64666635
elseif (is_array($d) and isset($d[0]) and is_array($d[0]) and isset($d[0]['group'])) {
64676636
return array_map(__FUNCTION__, $d);
64686637
}

0 commit comments

Comments
 (0)