Skip to content

Commit 5bb97df

Browse files
author
Mplus Software
committed
v1.1.1
New: getStockHistry() and setStock() When successful, updateStock() and setStock() now return the stockId of the stock change.
1 parent 0bb1847 commit 5bb97df

File tree

1 file changed

+117
-2
lines changed

1 file changed

+117
-2
lines changed

Mplusqapiclient.php

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

33
class MplusQAPIclient
44
{
5-
const CLIENT_VERSION = '1.1.0';
5+
const CLIENT_VERSION = '1.1.1';
66

77
var $MIN_API_VERSION_MAJOR = 0;
88
var $MIN_API_VERSION_MINOR = 9;
@@ -757,6 +757,20 @@ public function getStock($branchNumber, $articleNumbers = array(), $stockId = nu
757757

758758
//----------------------------------------------------------------------------
759759

760+
public function getStockHistory($branchNumber, $articleNumbers = array(), $sinceStockId = null, $fromFinancialDateTime = null, $throughFinancialDateTime = null)
761+
{
762+
try {
763+
$result = $this->client->getStockHistory($this->parser->convertGetStockHistoryRequest($branchNumber, $articleNumbers, $sinceStockId, $fromFinancialDateTime, $throughFinancialDateTime));
764+
return $this->parser->parseStockHistory($result);
765+
} catch (SoapFault $e) {
766+
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
767+
} catch (Exception $e) {
768+
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
769+
}
770+
} // END getStockHistory()
771+
772+
//----------------------------------------------------------------------------
773+
760774
public function updateStock($branchNumber, $articleNumber, $amountChanged)
761775
{
762776
try {
@@ -771,6 +785,21 @@ public function updateStock($branchNumber, $articleNumber, $amountChanged)
771785

772786
//----------------------------------------------------------------------------
773787

788+
public function setStock($branchNumber, $articleNumber, $amount)
789+
{
790+
try {
791+
$result = $this->client->setStock($this->parser->convertSetStockRequest($branchNumber, $articleNumber, $amount));
792+
i($result);
793+
return $this->parser->parseSetStockResult($result);
794+
} catch (SoapFault $e) {
795+
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
796+
} catch (Exception $e) {
797+
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
798+
}
799+
} // END setStock()
800+
801+
//----------------------------------------------------------------------------
802+
774803
public function getShifts($fromFinancialDate, $throughFinancialDate, $branchNumbers = array(), $employeeNumbers = array())
775804
{
776805
try {
@@ -1841,6 +1870,27 @@ public function parseStock($soapStock) {
18411870

18421871
//----------------------------------------------------------------------------
18431872

1873+
public function parseStockHistory($soapStockHistory) {
1874+
if (isset($soapStockHistory->articleStockHistory)) {
1875+
$soapArticleStockHistory = $soapStockHistory->articleStockHistory;
1876+
if ( ! is_array($soapArticleStockHistory)) {
1877+
$soapArticleStockHistory = array($soapArticleStockHistory);
1878+
}
1879+
$articleStockHistory = array();
1880+
foreach ($soapArticleStockHistory as $history) {
1881+
$history = objectToArray($history);
1882+
if (isset($history['timestamp'])) {
1883+
$history['timestamp'] = $this->parseMplusDateTime($history['timestamp']);
1884+
}
1885+
$articleStockHistory[] = $history;
1886+
}
1887+
return $articleStockHistory;
1888+
}
1889+
return false;
1890+
} // END parseStockHistory()
1891+
1892+
//----------------------------------------------------------------------------
1893+
18441894
public function parseShifts($soapShifts) {
18451895
if (isset($soapShifts->shiftList)) {
18461896
$soapShifts = $soapShifts->shiftList;
@@ -2428,14 +2478,33 @@ public function parseCancelOrderResult($soapCancelOrderResult)
24282478
public function parseUpdateStockResult($soapUpdateStockResult)
24292479
{
24302480
if (isset($soapUpdateStockResult->result) and $soapUpdateStockResult->result == 'UPDATE-STOCK-RESULT-OK') {
2431-
return true;
2481+
if (isset($soapUpdateStockResult->stockId) and ! empty($soapUpdateStockResult->stockId)) {
2482+
return $soapUpdateStockResult->stockId;
2483+
} else {
2484+
return true;
2485+
}
24322486
} else {
24332487
return false;
24342488
}
24352489
} // END parseUpdateStockResult()
24362490

24372491
//----------------------------------------------------------------------------
24382492

2493+
public function parseSetStockResult($soapSetStockResult)
2494+
{
2495+
if (isset($soapSetStockResult->result) and $soapSetStockResult->result == 'SET-STOCK-RESULT-OK') {
2496+
if (isset($soapSetStockResult->stockId) and ! empty($soapSetStockResult->stockId)) {
2497+
return $soapSetStockResult->stockId;
2498+
} else {
2499+
return true;
2500+
}
2501+
} else {
2502+
return false;
2503+
}
2504+
} // END parseSetStockResult()
2505+
2506+
//----------------------------------------------------------------------------
2507+
24392508
public function parseSaveInvoiceResult($soapSaveInvoiceResult)
24402509
{
24412510
if (isset($soapSaveInvoiceResult->result) and $soapSaveInvoiceResult->result == 'SAVE-INVOICE-RESULT-OK') {
@@ -3121,19 +3190,65 @@ public function convertGetStockRequest($branchNumber, $articleNumbers, $stockId)
31213190

31223191
//----------------------------------------------------------------------------
31233192

3193+
public function convertGetStockHistoryRequest($branchNumber, $articleNumbers, $sinceStockId, $fromFinancialDateTime, $throughFinancialDateTime)
3194+
{
3195+
if ( ! is_array($articleNumbers)) {
3196+
$articleNumbers = array($articleNumbers);
3197+
}
3198+
$array = array('request'=>array(
3199+
'branchNumber'=>$branchNumber,
3200+
'articleNumbers'=>array('articleNumbers'=>$articleNumbers)));
3201+
if ( ! is_null($sinceStockId) and ! empty($sinceStockId)) {
3202+
$array['request']['sinceStockId'] = $sinceStockId;
3203+
}
3204+
if ( ! is_null($fromFinancialDateTime) and ! empty($fromFinancialDateTime)) {
3205+
$fromFinancialDateTime = $this->convertMplusDateTime($fromFinancialDateTime, 'fromFinancialDateTime');
3206+
$array['request']['fromFinancialDateTime'] = $fromFinancialDateTime;
3207+
}
3208+
if ( ! is_null($throughFinancialDateTime) and ! empty($throughFinancialDateTime)) {
3209+
$throughFinancialDateTime = $this->convertMplusDateTime($throughFinancialDateTime, 'throughFinancialDateTime');
3210+
$array['request']['throughFinancialDateTime'] = $throughFinancialDateTime;
3211+
}
3212+
$object = arrayToObject($array);
3213+
if (empty($articleNumbers)) {
3214+
$object->request->articleNumbers = new stdClass();
3215+
$object->request->articleNumbers->articleNumbers = array();
3216+
}
3217+
return $object;
3218+
} // END convertGetStockHistoryRequest()
3219+
3220+
//----------------------------------------------------------------------------
3221+
31243222
public function convertUpdateStockRequest($branchNumber, $articleNumber, $amountChanged)
31253223
{
3224+
list($amountChanged, $decimalPlaces) = get_quantity_and_decimal_places($amountChanged);
31263225
$array = array('request'=>array(
31273226
'branchNumber'=>$branchNumber,
31283227
'articleNumber'=>$articleNumber,
31293228
'amountChanged'=>$amountChanged,
3229+
'decimalPlaces'=>$decimalPlaces,
31303230
));
31313231
$object = arrayToObject($array);
31323232
return $object;
31333233
} // END convertUpdateStockRequest()
31343234

31353235
//----------------------------------------------------------------------------
31363236

3237+
public function convertSetStockRequest($branchNumber, $articleNumber, $amount)
3238+
{
3239+
list($amount, $decimalPlaces) = get_quantity_and_decimal_places($amount);
3240+
$array = array('request'=>array(
3241+
'branchNumber'=>$branchNumber,
3242+
'articleNumber'=>$articleNumber,
3243+
'amount'=>$amount,
3244+
'decimalPlaces'=>$decimalPlaces,
3245+
));
3246+
$object = arrayToObject($array);
3247+
return $object;
3248+
} // END convertSetStockRequest()
3249+
3250+
//----------------------------------------------------------------------------
3251+
31373252
public function convertSendMessageRequest($branchNumber, $terminalNumber, $text, $sender, $messageType)
31383253
{
31393254
$request = array('text'=>$text);

0 commit comments

Comments
 (0)