6
6
7
7
class MplusQAPIclient
8
8
{
9
- const CLIENT_VERSION = '0.1 .0 ' ;
9
+ const CLIENT_VERSION = '0.3 .0 ' ;
10
10
11
11
var $ MIN_API_VERSION_MAJOR = 0 ;
12
- var $ MIN_API_VERSION_MINOR = 2 ;
12
+ var $ MIN_API_VERSION_MINOR = 3 ;
13
13
var $ MIN_API_VERSION_REVIS = 0 ;
14
14
15
15
var $ MAX_API_VERSION_MAJOR = 0 ;
16
- var $ MAX_API_VERSION_MINOR = 2 ;
16
+ var $ MAX_API_VERSION_MINOR = 3 ;
17
17
var $ MAX_API_VERSION_REVIS = 0 ;
18
18
19
19
/**
@@ -179,7 +179,7 @@ public function initClient()
179
179
throw new MplusQAPIException ('Fingerprint of SSL certificate doesn \'t match. ' );
180
180
}
181
181
182
- $ this ->client = new SoapClient ('MplusQapi.wsdl ' , $ options );
182
+ $ this ->client = new SoapClient ('https://api.mpluskassa.nl/ MplusQapi.wsdl ' , $ options );
183
183
$ this ->checkApiVersion ();
184
184
// i($this->client->__getTypes());
185
185
// $this->client = new SoapClient(null, $options);
@@ -321,6 +321,20 @@ public function getProducts($articleNumbers = array(), $groupNumbers = array(),
321
321
322
322
//----------------------------------------------------------------------------
323
323
324
+ public function getEmployees ($ employeeNumbers = array ())
325
+ {
326
+ try {
327
+ $ result = $ this ->client ->getEmployees ($ this ->parser ->convertGetEmployeesRequest ($ employeeNumbers ));
328
+ return $ this ->parser ->parseEmployees ($ result );
329
+ } catch (SoapFault $ e ) {
330
+ throw new MplusQAPIException ("SoapFault occurred: " .$ e ->getMessage (), 0 , $ e );
331
+ } catch (Exception $ e ) {
332
+ throw new MplusQAPIException ("Exception occurred: " .$ e ->getMessage (), 0 , $ e );
333
+ }
334
+ } // END getEmployees()
335
+
336
+ //----------------------------------------------------------------------------
337
+
324
338
public function createProduct ($ product )
325
339
{
326
340
try {
@@ -379,6 +393,20 @@ public function getStock($branchNumber, $articleNumbers = array())
379
393
380
394
//----------------------------------------------------------------------------
381
395
396
+ public function getShifts ($ financialDate , $ branchNumbers = array (), $ employeeNumbers = array ())
397
+ {
398
+ try {
399
+ $ result = $ this ->client ->getShifts ($ this ->parser ->convertGetShiftsRequest ($ financialDate , $ branchNumbers , $ employeeNumbers ));
400
+ return $ this ->parser ->parseShifts ($ result );
401
+ } catch (SoapFault $ e ) {
402
+ throw new MplusQAPIException ("SoapFault occurred: " .$ e ->getMessage (), 0 , $ e );
403
+ } catch (Exception $ e ) {
404
+ throw new MplusQAPIException ("Exception occurred: " .$ e ->getMessage (), 0 , $ e );
405
+ }
406
+ } // END getShifts()
407
+
408
+ //----------------------------------------------------------------------------
409
+
382
410
public function findOrder ($ extOrderId )
383
411
{
384
412
try {
@@ -722,7 +750,23 @@ public function parseProducts($soapProducts) {
722
750
return $ products ;
723
751
}
724
752
return false ;
725
- } // END parseProducts()
753
+ } // END parseProductsemployees
754
+
755
+ //----------------------------------------------------------------------------
756
+
757
+ public function parseEmployees ($ soapEmployees )
758
+ {
759
+ if (isset ($ soapEmployees ->employeeList )) {
760
+ $ soapEmployees = $ soapEmployees ->employeeList ;
761
+ $ employees = array ();
762
+ if (isset ($ soapEmployees ->employee )) {
763
+ $ soapEmployees = $ soapEmployees ->employee ;
764
+ $ employees = objectToArray ($ soapEmployees );
765
+ }
766
+ return $ employees ;
767
+ }
768
+ return false ;
769
+ } // END parseEmployees()
726
770
727
771
//----------------------------------------------------------------------------
728
772
@@ -783,7 +827,33 @@ public function parseStock($soapStock) {
783
827
return $ articleStocks ;
784
828
}
785
829
return false ;
786
- } // END parseStock();
830
+ } // END parseStock()
831
+
832
+ //----------------------------------------------------------------------------
833
+
834
+ public function parseShifts ($ soapShifts ) {
835
+ if (isset ($ soapShifts ->shiftList )) {
836
+ $ soapShifts = $ soapShifts ->shiftList ;
837
+ $ shifts = array ();
838
+ if (isset ($ soapShifts ->shift )) {
839
+ $ shifts = objectToArray ($ soapShifts ->shift );
840
+ foreach ($ shifts as $ key => $ shift ) {
841
+ if (isset ($ shift ['financialDate ' ])) {
842
+ $ shift ['financialDate ' ] = $ this ->parseMplusDate ($ shift ['financialDate ' ]);
843
+ }
844
+ if (isset ($ shift ['startTimestamp ' ])) {
845
+ $ shift ['startTimestamp ' ] = $ this ->parseMplusDateTime ($ shift ['startTimestamp ' ]);
846
+ }
847
+ if (isset ($ shift ['endTimestamp ' ])) {
848
+ $ shift ['endTimestamp ' ] = $ this ->parseMplusDateTime ($ shift ['endTimestamp ' ]);
849
+ }
850
+ $ shifts [$ key ] = $ shift ;
851
+ }
852
+ }
853
+ return $ shifts ;
854
+ }
855
+ return false ;
856
+ } // END parseShifts()
787
857
788
858
//----------------------------------------------------------------------------
789
859
@@ -1085,6 +1155,41 @@ public function convertGetProductsRequest($articleNumbers, $groupNumbers, $pluNu
1085
1155
1086
1156
//----------------------------------------------------------------------------
1087
1157
1158
+ public function convertGetEmployeesRequest ($ employeeNumbers )
1159
+ {
1160
+ if ( ! is_array ($ employeeNumbers )) {
1161
+ $ employeeNumbers = array ($ employeeNumbers );
1162
+ }
1163
+ $ object = arrayToObject (array ('request ' =>array (
1164
+ 'employeeNumbers ' =>empty ($ employeeNumbers )?null :array_values ($ employeeNumbers ),
1165
+ )));
1166
+ return $ object ;
1167
+ } // END convertGetEmployeesRequest()
1168
+
1169
+ //----------------------------------------------------------------------------
1170
+
1171
+ public function convertGetShiftsRequest ($ financialDate , $ branchNumbers , $ employeeNumbers )
1172
+ {
1173
+ if ( ! isset ($ financialDate ) or is_null ($ financialDate ) or empty ($ financialDate )) {
1174
+ $ financialDate = time ();
1175
+ }
1176
+ $ financialDate = $ this ->convertMplusDate ($ financialDate );
1177
+ if ( ! is_array ($ branchNumbers )) {
1178
+ $ branchNumbers = array ($ branchNumbers );
1179
+ }
1180
+ if ( ! is_array ($ employeeNumbers )) {
1181
+ $ employeeNumbers = array ($ employeeNumbers );
1182
+ }
1183
+ $ object = arrayToObject (array ('request ' =>array (
1184
+ 'financialDate ' =>$ financialDate ,
1185
+ 'branchNumbers ' =>empty ($ branchNumbers )?null :array_values ($ branchNumbers ),
1186
+ 'employeeNumbers ' =>empty ($ employeeNumbers )?null :array_values ($ employeeNumbers ),
1187
+ )));
1188
+ return $ object ;
1189
+ } // END convertGetShiftsRequest()
1190
+
1191
+ //----------------------------------------------------------------------------
1192
+
1088
1193
public function convertPluNumbers ($ pluNumbers )
1089
1194
{
1090
1195
$ text = array ();
@@ -1472,18 +1577,53 @@ public function convertOrderLineList($lineList, $is_preparationList=false)
1472
1577
1473
1578
public function convertMplusDateTime ($ timestamp )
1474
1579
{
1475
- return $ timestamp ;
1580
+ return array (
1581
+ 'day ' => date ('j ' , $ timestamp ),
1582
+ 'mon ' => date ('n ' , $ timestamp ),
1583
+ 'year ' => date ('Y ' , $ timestamp ),
1584
+ );
1476
1585
} // END convertMplusDateTime()
1477
1586
1478
1587
//----------------------------------------------------------------------------
1479
1588
1589
+ public function parseMplusDateTime ($ mplus_date_time )
1590
+ {
1591
+ if ($ mplus_date_time ['day ' ] == 0 || $ mplus_date_time ['mon ' ] == 0 || $ mplus_date_time ['year ' ] == 0 ) {
1592
+ return null ;
1593
+ } else {
1594
+ return mktime ($ mplus_date_time ['hour ' ], $ mplus_date_time ['min ' ], $ mplus_date_time ['sec ' ], $ mplus_date_time ['mon ' ], $ mplus_date_time ['day ' ], $ mplus_date_time ['year ' ]);
1595
+ }
1596
+ } // END parseMplusDateTime()
1597
+
1598
+ //----------------------------------------------------------------------------
1599
+
1480
1600
public function convertMplusDate ($ timestamp )
1481
1601
{
1482
- return $ timestamp ;
1602
+ return array (
1603
+ 'day ' => date ('j ' , $ timestamp ),
1604
+ 'mon ' => date ('n ' , $ timestamp ),
1605
+ 'year ' => date ('Y ' , $ timestamp ),
1606
+ 'hour ' => date ('H ' , $ timestamp ),
1607
+ 'min ' => date ('i ' , $ timestamp ),
1608
+ 'sec ' => date ('s ' , $ timestamp ),
1609
+ 'isdst ' => false ,
1610
+ 'timezone ' => 0 ,
1611
+ );
1483
1612
} // END convertMplusDate()
1484
1613
1485
1614
//----------------------------------------------------------------------------
1486
1615
1616
+ public function parseMplusDate ($ mplus_date )
1617
+ {
1618
+ if ($ mplus_date ['day ' ] == 0 || $ mplus_date ['mon ' ] == 0 || $ mplus_date ['year ' ] == 0 ) {
1619
+ return null ;
1620
+ } else {
1621
+ return mktime (0 , 0 , 0 , $ mplus_date ['mon ' ], $ mplus_date ['day ' ], $ mplus_date ['year ' ]);
1622
+ }
1623
+ } // END parseMplusDate()
1624
+
1625
+ //----------------------------------------------------------------------------
1626
+
1487
1627
public function convertYearNumber ($ year_number )
1488
1628
{
1489
1629
return $ year_number ;
@@ -1602,16 +1742,27 @@ function objectToArray($d) {
1602
1742
1603
1743
//------------------------------------------------------------------------------
1604
1744
1605
- function arrayToObject ($ d ) {
1745
+ $ global_leave_as_array = null ;
1746
+ function arrayToObject ($ d , $ leave_as_array =null ) {
1747
+ global $ global_leave_as_array ;
1748
+ if ( ! is_null ($ leave_as_array )) {
1749
+ $ global_leave_as_array = $ leave_as_array ;
1750
+ }
1606
1751
if (is_array ($ d )) {
1607
1752
/*
1608
1753
* Return array converted to object
1609
1754
* Using __FUNCTION__ (Magic constant)
1610
1755
* for recursive call
1611
1756
*/
1612
1757
if (isset ($ d ['articleNumbers ' ]) or isset ($ d ['groupNumbers ' ])) {
1758
+ if ( ! is_null ($ leave_as_array )) {
1759
+ $ global_leave_as_array = null ;
1760
+ }
1613
1761
return (object ) $ d ;
1614
1762
}
1763
+ elseif ( ! is_null ($ global_leave_as_array ) and is_array ($ d ) and isset ($ d [0 ]) and is_array ($ d [0 ]) and isset ($ d [0 ][$ global_leave_as_array ])) {
1764
+ return array_map (__FUNCTION__ , $ d );
1765
+ }
1615
1766
elseif (is_array ($ d ) and isset ($ d [0 ]) and is_array ($ d [0 ]) and isset ($ d [0 ]['text ' ])) {
1616
1767
return array_map (__FUNCTION__ , $ d );
1617
1768
}
@@ -1633,6 +1784,9 @@ function arrayToObject($d) {
1633
1784
}
1634
1785
else {
1635
1786
// Return object
1787
+ if ( ! is_null ($ leave_as_array )) {
1788
+ $ global_leave_as_array = null ;
1789
+ }
1636
1790
return $ d ;
1637
1791
}
1638
1792
} // END arrayToObject()
0 commit comments