server_productorservice.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <?php
  2. /* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 JF FERRY <jfefe@aternatik.fr>
  4. * Copyright (C) 2020-2023 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * Path to WSDL is: http://localhost/dolibarr/webservices/server_productorservice.php?wsdl
  20. */
  21. /**
  22. * \file htdocs/webservices/server_productorservice.php
  23. * \brief File that is entry point to call Dolibarr WebServices
  24. */
  25. if (!defined('NOCSRFCHECK')) {
  26. define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
  27. }
  28. if (!defined('NOTOKENRENEWAL')) {
  29. define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
  30. }
  31. if (!defined('NOREQUIREMENU')) {
  32. define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  33. }
  34. if (!defined('NOREQUIREHTML')) {
  35. define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  36. }
  37. if (!defined('NOREQUIREAJAX')) {
  38. define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  39. }
  40. if (!defined("NOLOGIN")) {
  41. define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
  42. }
  43. if (!defined("NOSESSION")) {
  44. define("NOSESSION", '1');
  45. }
  46. require '../main.inc.php';
  47. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  48. require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  52. require_once DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php";
  53. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  54. dol_syslog("Call Dolibarr webservices interfaces");
  55. $langs->load("main");
  56. // Enable and test if module web services is enabled
  57. if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
  58. $langs->load("admin");
  59. dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
  60. print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
  61. print $langs->trans("ToActivateModule");
  62. exit;
  63. }
  64. // Create the soap Object
  65. $server = new nusoap_server();
  66. $server->soap_defencoding = 'UTF-8';
  67. $server->decode_utf8 = false;
  68. $ns = 'http://www.dolibarr.org/ns/';
  69. $server->configureWSDL('WebServicesDolibarrProductOrService', $ns);
  70. $server->wsdl->schemaTargetNamespace = $ns;
  71. // Define WSDL Authentication object
  72. $server->wsdl->addComplexType(
  73. 'authentication',
  74. 'complexType',
  75. 'struct',
  76. 'all',
  77. '',
  78. array(
  79. 'dolibarrkey' => array('name'=>'dolibarrkey', 'type'=>'xsd:string'),
  80. 'sourceapplication' => array('name'=>'sourceapplication', 'type'=>'xsd:string'),
  81. 'login' => array('name'=>'login', 'type'=>'xsd:string'),
  82. 'password' => array('name'=>'password', 'type'=>'xsd:string'),
  83. 'entity' => array('name'=>'entity', 'type'=>'xsd:string')
  84. )
  85. );
  86. // Define WSDL Return object
  87. $server->wsdl->addComplexType(
  88. 'result',
  89. 'complexType',
  90. 'struct',
  91. 'all',
  92. '',
  93. array(
  94. 'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
  95. 'result_label' => array('name'=>'result_label', 'type'=>'xsd:string')
  96. )
  97. );
  98. $productorservice_fields = array(
  99. 'id' => array('name'=>'id', 'type'=>'xsd:string'),
  100. 'ref' => array('name'=>'ref', 'type'=>'xsd:string'),
  101. 'ref_ext' => array('name'=>'ref_ext', 'type'=>'xsd:string'),
  102. 'type' => array('name'=>'type', 'type'=>'xsd:string'),
  103. 'label' => array('name'=>'label', 'type'=>'xsd:string'),
  104. 'description' => array('name'=>'description', 'type'=>'xsd:string'),
  105. 'date_creation' => array('name'=>'date_creation', 'type'=>'xsd:dateTime'),
  106. 'date_modification' => array('name'=>'date_modification', 'type'=>'xsd:dateTime'),
  107. 'note' => array('name'=>'note', 'type'=>'xsd:string'),
  108. 'status_tobuy' => array('name'=>'status_tobuy', 'type'=>'xsd:string'),
  109. 'status_tosell' => array('name'=>'status_tosell', 'type'=>'xsd:string'),
  110. 'barcode' => array('name'=>'barcode', 'type'=>'xsd:string'),
  111. 'barcode_type' => array('name'=>'barcode_type', 'type'=>'xsd:string'),
  112. 'country_id' => array('name'=>'country_id', 'type'=>'xsd:string'),
  113. 'country_code' => array('name'=>'country_code', 'type'=>'xsd:string'),
  114. 'customcode' => array('name'=>'customcode', 'type'=>'xsd:string'),
  115. 'price_net' => array('name'=>'price_net', 'type'=>'xsd:string'),
  116. 'price' => array('name'=>'price', 'type'=>'xsd:string'),
  117. 'price_min_net' => array('name'=>'price_min_net', 'type'=>'xsd:string'),
  118. 'price_min' => array('name'=>'price_min', 'type'=>'xsd:string'),
  119. 'price_base_type' => array('name'=>'price_base_type', 'type'=>'xsd:string'),
  120. 'vat_rate' => array('name'=>'vat_rate', 'type'=>'xsd:string'),
  121. 'vat_npr' => array('name'=>'vat_npr', 'type'=>'xsd:string'),
  122. 'localtax1_tx' => array('name'=>'localtax1_tx', 'type'=>'xsd:string'),
  123. 'localtax2_tx' => array('name'=>'localtax2_tx', 'type'=>'xsd:string'),
  124. 'stock_alert' => array('name'=>'stock_alert', 'type'=>'xsd:string'),
  125. 'stock_real' => array('name'=>'stock_real', 'type'=>'xsd:string'),
  126. 'stock_pmp' => array('name'=>'stock_pmp', 'type'=>'xsd:string'),
  127. 'warehouse_ref' => array('name'=>'warehouse_ref', 'type'=>'xsd:string'), // Used only for create or update to set which warehouse to use for stock correction if stock_real differs from database
  128. 'canvas' => array('name'=>'canvas', 'type'=>'xsd:string'),
  129. 'import_key' => array('name'=>'import_key', 'type'=>'xsd:string'),
  130. 'dir' => array('name'=>'dir', 'type'=>'xsd:string'),
  131. 'images' => array('name'=>'images', 'type'=>'tns:ImagesArray')
  132. );
  133. $elementtype = 'product';
  134. //Retrieve all extrafield for product
  135. // fetch optionals attributes and labels
  136. $extrafields = new ExtraFields($db);
  137. $extrafields->fetch_name_optionals_label($elementtype, true);
  138. $extrafield_array = null;
  139. if (is_array($extrafields) && count($extrafields) > 0) {
  140. $extrafield_array = array();
  141. }
  142. if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
  143. foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
  144. $type = $extrafields->attributes[$elementtype]['type'][$key];
  145. if ($type == 'date' || $type == 'datetime') {
  146. $type = 'xsd:dateTime';
  147. } else {
  148. $type = 'xsd:string';
  149. }
  150. $extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
  151. }
  152. }
  153. if (!empty($extrafield_array) && is_array($extrafield_array)) {
  154. $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
  155. }
  156. // Define other specific objects
  157. $server->wsdl->addComplexType(
  158. 'product',
  159. 'complexType',
  160. 'struct',
  161. 'all',
  162. '',
  163. $productorservice_fields
  164. );
  165. /*
  166. * Image of product
  167. */
  168. $server->wsdl->addComplexType(
  169. 'ImagesArray',
  170. 'complexType',
  171. 'array',
  172. 'sequence',
  173. '',
  174. array(
  175. 'image' => array(
  176. 'name' => 'image',
  177. 'type' => 'tns:image',
  178. 'minOccurs' => '0',
  179. 'maxOccurs' => 'unbounded'
  180. )
  181. )
  182. );
  183. /*
  184. * An image
  185. */
  186. $server->wsdl->addComplexType(
  187. 'image',
  188. 'complexType',
  189. 'struct',
  190. 'all',
  191. '',
  192. array(
  193. 'photo' => array('name'=>'photo', 'type'=>'xsd:string'),
  194. 'photo_vignette' => array('name'=>'photo_vignette', 'type'=>'xsd:string'),
  195. 'imgWidth' => array('name'=>'imgWidth', 'type'=>'xsd:string'),
  196. 'imgHeight' => array('name'=>'imgHeight', 'type'=>'xsd:string')
  197. )
  198. );
  199. // Define other specific objects
  200. $server->wsdl->addComplexType(
  201. 'filterproduct',
  202. 'complexType',
  203. 'struct',
  204. 'all',
  205. '',
  206. array(
  207. //'limit' => array('name'=>'limit','type'=>'xsd:string'),
  208. 'type' => array('name'=>'type', 'type'=>'xsd:string'),
  209. 'status_tobuy' => array('name'=>'status_tobuy', 'type'=>'xsd:string'),
  210. 'status_tosell' => array('name'=>'status_tosell', 'type'=>'xsd:string'),
  211. )
  212. );
  213. $server->wsdl->addComplexType(
  214. 'ProductsArray2',
  215. 'complexType',
  216. 'array',
  217. 'sequence',
  218. '',
  219. array(
  220. 'product' => array(
  221. 'name' => 'product',
  222. 'type' => 'tns:product',
  223. 'minOccurs' => '0',
  224. 'maxOccurs' => 'unbounded'
  225. )
  226. )
  227. );
  228. // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
  229. // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
  230. // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
  231. $styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
  232. $styleuse = 'encoded'; // encoded/literal/literal wrapped
  233. // Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
  234. // Register WSDL
  235. $server->register(
  236. 'getProductOrService',
  237. // Entry values
  238. array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string', 'lang'=>'xsd:string'),
  239. // Exit values
  240. array('result'=>'tns:result', 'product'=>'tns:product'),
  241. $ns,
  242. $ns.'#getProductOrService',
  243. $styledoc,
  244. $styleuse,
  245. 'WS to get product or service'
  246. );
  247. // Register WSDL
  248. $server->register(
  249. 'createProductOrService',
  250. // Entry values
  251. array('authentication'=>'tns:authentication', 'product'=>'tns:product'),
  252. // Exit values
  253. array('result'=>'tns:result', 'id'=>'xsd:string'),
  254. $ns,
  255. $ns.'#createProductOrService',
  256. $styledoc,
  257. $styleuse,
  258. 'WS to create a product or service'
  259. );
  260. // Register WSDL
  261. $server->register(
  262. 'updateProductOrService',
  263. // Entry values
  264. array('authentication'=>'tns:authentication', 'product'=>'tns:product'),
  265. // Exit values
  266. array('result'=>'tns:result', 'id'=>'xsd:string'),
  267. $ns,
  268. $ns.'#updateProductOrService',
  269. $styledoc,
  270. $styleuse,
  271. 'WS to update a product or service'
  272. );
  273. // Register WSDL
  274. $server->register(
  275. 'deleteProductOrService',
  276. // Entry values
  277. array('authentication'=>'tns:authentication', 'listofid'=>'xsd:string'),
  278. // Exit values
  279. array('result'=>'tns:result', 'nbdeleted'=>'xsd:int'),
  280. $ns,
  281. $ns.'#deleteProductOrService',
  282. $styledoc,
  283. $styleuse,
  284. 'WS to delete a product or service'
  285. );
  286. // Register WSDL
  287. $server->register(
  288. 'getListOfProductsOrServices',
  289. // Entry values
  290. array('authentication'=>'tns:authentication', 'filterproduct'=>'tns:filterproduct'),
  291. // Exit values
  292. array('result'=>'tns:result', 'products'=>'tns:ProductsArray2'),
  293. $ns,
  294. $ns.'#getListOfProductsOrServices',
  295. $styledoc,
  296. $styleuse,
  297. 'WS to get list of all products or services id and ref'
  298. );
  299. // Register WSDL
  300. $server->register(
  301. 'getProductsForCategory',
  302. // Entry values
  303. array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'lang'=>'xsd:string'),
  304. // Exit values
  305. array('result'=>'tns:result', 'products'=>'tns:ProductsArray2'),
  306. $ns,
  307. $ns.'#getProductsForCategory',
  308. $styledoc,
  309. $styleuse,
  310. 'WS to get list of all products or services for a category'
  311. );
  312. /**
  313. * Get produt or service
  314. *
  315. * @param array $authentication Array of authentication information
  316. * @param int $id Id of object
  317. * @param string $ref Ref of object
  318. * @param string $ref_ext Ref external of object
  319. * @param string $lang Lang to force
  320. * @return mixed
  321. */
  322. function getProductOrService($authentication, $id = 0, $ref = '', $ref_ext = '', $lang = '')
  323. {
  324. global $db, $conf, $langs;
  325. dol_syslog("Function: getProductOrService login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
  326. $langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
  327. $langs->setDefaultLang($langcode);
  328. if ($authentication['entity']) {
  329. $conf->entity = $authentication['entity'];
  330. }
  331. // Init and check authentication
  332. $objectresp = array();
  333. $errorcode = '';
  334. $errorlabel = '';
  335. $error = 0;
  336. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  337. // Check parameters
  338. if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
  339. $error++;
  340. $errorcode = 'BAD_PARAMETERS';
  341. $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
  342. }
  343. if (!$error) {
  344. $langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
  345. $langs->setDefaultLang($langcode);
  346. $fuser->getrights();
  347. $nbmax = 10;
  348. if ($fuser->hasRight('produit', 'lire') || $fuser->hasRight('service', 'lire')) {
  349. $product = new Product($db);
  350. $result = $product->fetch($id, $ref, $ref_ext);
  351. if ($result > 0) {
  352. $product->load_stock();
  353. $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
  354. $pdir = get_exdir($product->id, 2, 0, 0, $product, 'product').$product->ref."/";
  355. $dir = $dir.'/'.$pdir;
  356. if (!empty($product->multilangs[$langs->defaultlang]["label"])) {
  357. $product->label = $product->multilangs[$langs->defaultlang]["label"];
  358. }
  359. if (!empty($product->multilangs[$langs->defaultlang]["description"])) {
  360. $product->description = $product->multilangs[$langs->defaultlang]["description"];
  361. }
  362. if (!empty($product->multilangs[$langs->defaultlang]["note"])) {
  363. $product->note = $product->multilangs[$langs->defaultlang]["note"];
  364. }
  365. $productorservice_result_fields = array(
  366. 'id' => $product->id,
  367. 'ref' => $product->ref,
  368. 'ref_ext' => $product->ref_ext,
  369. 'label' => $product->label,
  370. 'description' => $product->description,
  371. 'date_creation' => dol_print_date($product->date_creation, 'dayhourrfc'),
  372. 'date_modification' => dol_print_date($product->date_modification, 'dayhourrfc'),
  373. 'note' => $product->note,
  374. 'status_tosell' => $product->status,
  375. 'status_tobuy' => $product->status_buy,
  376. 'type' => $product->type,
  377. 'barcode' => $product->barcode,
  378. 'barcode_type' => $product->barcode_type,
  379. 'country_id' => $product->country_id > 0 ? $product->country_id : '',
  380. 'country_code' => $product->country_code,
  381. 'custom_code' => $product->customcode,
  382. 'price_net' => $product->price,
  383. 'price' => $product->price_ttc,
  384. 'price_min_net' => $product->price_min,
  385. 'price_min' => $product->price_min_ttc,
  386. 'price_base_type' => $product->price_base_type,
  387. 'vat_rate' => $product->tva_tx,
  388. //! French VAT NPR
  389. 'vat_npr' => $product->tva_npr,
  390. //! Spanish local taxes
  391. 'localtax1_tx' => $product->localtax1_tx,
  392. 'localtax2_tx' => $product->localtax2_tx,
  393. 'stock_real' => $product->stock_reel,
  394. 'stock_virtual' => $product->stock_theorique,
  395. 'stock_alert' => $product->seuil_stock_alerte,
  396. 'pmp' => $product->pmp,
  397. 'import_key' => $product->import_key,
  398. 'dir' => $pdir,
  399. 'images' => $product->liste_photos($dir, $nbmax)
  400. );
  401. $elementtype = 'product';
  402. //Retrieve all extrafield for thirdsparty
  403. // fetch optionals attributes and labels
  404. $extrafields = new ExtraFields($db);
  405. $extrafields->fetch_name_optionals_label($elementtype, true);
  406. //Get extrafield values
  407. $product->fetch_optionals();
  408. if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
  409. foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
  410. $productorservice_result_fields = array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key]));
  411. }
  412. }
  413. // Create
  414. $objectresp = array(
  415. 'result'=>array('result_code'=>'OK', 'result_label'=>''),
  416. 'product'=>$productorservice_result_fields
  417. );
  418. } else {
  419. $error++;
  420. $errorcode = 'NOT_FOUND';
  421. $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
  422. }
  423. } else {
  424. $error++;
  425. $errorcode = 'PERMISSION_DENIED';
  426. $errorlabel = 'User does not have permission for this request';
  427. }
  428. }
  429. if ($error) {
  430. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  431. }
  432. //var_dump($objectresp);exit;
  433. return $objectresp;
  434. }
  435. /**
  436. * Create an invoice
  437. *
  438. * @param array $authentication Array of authentication information
  439. * @param Product $product Product
  440. * @return array Array result
  441. */
  442. function createProductOrService($authentication, $product)
  443. {
  444. global $db, $conf;
  445. $now = dol_now();
  446. dol_syslog("Function: createProductOrService login=".$authentication['login']);
  447. if ($authentication['entity']) {
  448. $conf->entity = $authentication['entity'];
  449. }
  450. // Init and check authentication
  451. $objectresp = array();
  452. $errorcode = '';
  453. $errorlabel = '';
  454. $error = 0;
  455. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  456. // Check parameters
  457. if (empty($product['price_base_type'])) {
  458. if (isset($product['price_net']) && $product['price_net'] > 0) {
  459. $product['price_base_type'] = 'HT';
  460. }
  461. if (isset($product['price']) && $product['price'] > 0) {
  462. $product['price_base_type'] = 'TTC';
  463. }
  464. }
  465. if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0) {
  466. $error++;
  467. $errorcode = 'KO';
  468. $errorlabel = "You must choose between price or price_net to provide price.";
  469. }
  470. if (!empty($product['barcode']) && empty($product['barcode_type'])) {
  471. $error++;
  472. $errorcode = 'KO';
  473. $errorlabel = "You must set a barcode type when setting a barcode.";
  474. }
  475. if (!$error) {
  476. include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  477. $newobject = new Product($db);
  478. $newobject->ref = $product['ref'];
  479. $newobject->ref_ext = empty($product['ref_ext']) ? '' : $product['ref_ext'];
  480. $newobject->type = empty($product['type']) ? 0 : $product['type'];
  481. $newobject->label = empty($product['label']) ? '' : $product['label'];
  482. $newobject->description = empty($product['description']) ? '' : $product['description'];
  483. $newobject->note_public = empty($product['note_public']) ? '' : $product['note_public'];
  484. $newobject->note_private = empty($product['note_private']) ? '' : $product['note_private'];
  485. $newobject->status = empty($product['status_tosell']) ? 0 : $product['status_tosell'];
  486. $newobject->status_buy = empty($product['status_tobuy']) ? 0 : $product['status_tobuy'];
  487. $newobject->price = isset($product['price_net']) ? $product['price_net'] : 0;
  488. $newobject->price_ttc = isset($product['price']) ? $product['price'] : 0;
  489. $newobject->tva_tx = empty($product['vat_rate']) ? 0 : $product['vat_rate'];
  490. $newobject->price_base_type = $product['price_base_type'];
  491. $newobject->date_creation = $now;
  492. if (!empty($product['barcode'])) {
  493. $newobject->barcode = $product['barcode'];
  494. $newobject->barcode_type = $product['barcode_type'];
  495. }
  496. $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null;
  497. $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null;
  498. $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null;
  499. $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0;
  500. if (!empty($product['country_code'])) {
  501. $newobject->country_id = getCountry($product['country_code'], 3);
  502. }
  503. $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : '';
  504. $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : '';
  505. /*foreach($product['lines'] as $line)
  506. {
  507. $newline=new FactureLigne($db);
  508. $newline->type=$line['type'];
  509. $newline->desc=$line['desc'];
  510. $newline->fk_product=$line['fk_product'];
  511. $newline->total_ht=$line['total_net'];
  512. $newline->total_vat=$line['total_vat'];
  513. $newline->total_ttc=$line['total'];
  514. $newline->vat=$line['vat_rate'];
  515. $newline->qty=$line['qty'];
  516. $newline->fk_product=$line['product_id'];
  517. }*/
  518. //var_dump($product['ref_ext']);
  519. //var_dump($product['lines'][0]['type']);
  520. $elementtype = 'product';
  521. $extrafields = new ExtraFields($db);
  522. $extrafields->fetch_name_optionals_label($elementtype, true);
  523. if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
  524. foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
  525. $key = 'options_'.$key;
  526. $newobject->array_options[$key] = $product[$key];
  527. }
  528. }
  529. $db->begin();
  530. $result = $newobject->create($fuser, 0);
  531. if ($result <= 0) {
  532. $error++;
  533. }
  534. if (!$error) {
  535. // Update stock if stock count is provided and differs from database after creation or update
  536. if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
  537. include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  538. $savstockreal = $newobject->stock_reel;
  539. $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel, surely 0 because we have just created product
  540. $getstockreal = $newobject->stock_reel;
  541. if ($savstockreal != $getstockreal) {
  542. $warehouse = new Entrepot($db);
  543. $warehouse->fetch(0, $product['warehouse_ref']);
  544. if ($warehouse->id > 0) {
  545. if (($savstockreal - $getstockreal) > 0) {
  546. $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
  547. }
  548. if (($savstockreal - $getstockreal) > 0) {
  549. $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
  550. }
  551. if ($result <= 0) {
  552. $error++;
  553. $newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
  554. }
  555. } else {
  556. $error++;
  557. $newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
  558. }
  559. }
  560. }
  561. }
  562. if (!$error) {
  563. $db->commit();
  564. $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
  565. } else {
  566. $db->rollback();
  567. $error++;
  568. $errorcode = 'KO';
  569. $errorlabel = $newobject->error;
  570. }
  571. }
  572. if ($error) {
  573. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  574. }
  575. return $objectresp;
  576. }
  577. /**
  578. * Update a product or service
  579. *
  580. * @param array $authentication Array of authentication information
  581. * @param Product $product Product
  582. * @return array Array result
  583. */
  584. function updateProductOrService($authentication, $product)
  585. {
  586. global $db, $conf;
  587. $now = dol_now();
  588. dol_syslog("Function: updateProductOrService login=".$authentication['login']);
  589. if ($authentication['entity']) {
  590. $conf->entity = $authentication['entity'];
  591. }
  592. // Init and check authentication
  593. $objectresp = array();
  594. $errorcode = '';
  595. $errorlabel = '';
  596. $error = 0;
  597. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  598. // Check parameters
  599. if ($product['price_net'] > 0) {
  600. $product['price_base_type'] = 'HT';
  601. }
  602. if ($product['price'] > 0) {
  603. $product['price_base_type'] = 'TTC';
  604. }
  605. if ($product['price_net'] > 0 && $product['price'] > 0) {
  606. $error++;
  607. $errorcode = 'KO';
  608. $errorlabel = "You must choose between price or price_net to provide price.";
  609. }
  610. if ($product['barcode'] && !$product['barcode_type']) {
  611. $error++;
  612. $errorcode = 'KO';
  613. $errorlabel = "You must set a barcode type when setting a barcode.";
  614. }
  615. if (!$error) {
  616. include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  617. $newobject = new Product($db);
  618. $newobject->fetch($product['id']);
  619. if (isset($product['ref'])) {
  620. $newobject->ref = $product['ref'];
  621. }
  622. if (isset($product['ref_ext'])) {
  623. $newobject->ref_ext = $product['ref_ext'];
  624. }
  625. $newobject->type = $product['type'];
  626. $newobject->label = $product['label'];
  627. $newobject->description = $product['description'];
  628. $newobject->note = $product['note'];
  629. $newobject->status = $product['status_tosell'];
  630. $newobject->status_buy = $product['status_tobuy'];
  631. $newobject->price = $product['price_net'];
  632. $newobject->price_ttc = $product['price'];
  633. $newobject->tva_tx = $product['vat_rate'];
  634. $newobject->price_base_type = $product['price_base_type'];
  635. $newobject->date_creation = $now;
  636. if ($product['barcode']) {
  637. $newobject->barcode = $product['barcode'];
  638. $newobject->barcode_type = $product['barcode_type'];
  639. }
  640. $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null;
  641. $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null;
  642. $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null;
  643. $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0;
  644. if (!empty($product['country_code'])) {
  645. $newobject->country_id = getCountry($product['country_code'], 3);
  646. }
  647. $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : '';
  648. $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : '';
  649. $elementtype = 'product';
  650. $extrafields = new ExtraFields($db);
  651. $extrafields->fetch_name_optionals_label($elementtype, true);
  652. if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
  653. foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
  654. $key = 'options_'.$key;
  655. $newobject->array_options[$key] = $product[$key];
  656. }
  657. }
  658. $db->begin();
  659. $result = $newobject->update($newobject->id, $fuser);
  660. if ($result <= 0) {
  661. $error++;
  662. } else {
  663. // Update stock if stock count is provided and differs from database after creation or update
  664. if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
  665. include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  666. $savstockreal = $newobject->stock_reel;
  667. $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel
  668. $getstockreal = $newobject->stock_reel;
  669. if ($savstockreal != $getstockreal) {
  670. $warehouse = new Entrepot($db);
  671. $warehouse->fetch(0, $product['warehouse_ref']);
  672. if ($warehouse->id > 0) {
  673. if (($savstockreal - $getstockreal) > 0) {
  674. $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
  675. }
  676. if (($savstockreal - $getstockreal) > 0) {
  677. $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
  678. }
  679. if ($result <= 0) {
  680. $error++;
  681. $newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
  682. }
  683. } else {
  684. $error++;
  685. $newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
  686. }
  687. }
  688. }
  689. }
  690. if (!$error) {
  691. if ($newobject->price_base_type == 'HT') {
  692. $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
  693. if ($result <= 0) {
  694. $error++;
  695. }
  696. } elseif ($newobject->price_base_type == 'TTC') {
  697. $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
  698. if ($result <= 0) {
  699. $error++;
  700. }
  701. }
  702. }
  703. if (!$error) {
  704. $db->commit();
  705. $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
  706. } else {
  707. $db->rollback();
  708. $error++;
  709. $errorcode = 'KO';
  710. $errorlabel = $newobject->error;
  711. }
  712. }
  713. if ($error) {
  714. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  715. }
  716. return $objectresp;
  717. }
  718. /**
  719. * Delete a product or service
  720. *
  721. * @param array $authentication Array of authentication information
  722. * @param string $listofidstring List of id with comma
  723. * @return array Array result
  724. */
  725. function deleteProductOrService($authentication, $listofidstring)
  726. {
  727. global $db, $conf;
  728. dol_syslog("Function: deleteProductOrService login=".$authentication['login']);
  729. if ($authentication['entity']) {
  730. $conf->entity = $authentication['entity'];
  731. }
  732. // Init and check authentication
  733. $objectresp = array();
  734. $errorcode = '';
  735. $errorlabel = '';
  736. $error = 0;
  737. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  738. // User must be defined to user authenticated
  739. global $user;
  740. $user = $fuser;
  741. $listofid = explode(',', trim($listofidstring));
  742. $listofiddeleted = array();
  743. // Check parameters
  744. if (count($listofid) == 0 || empty($listofid[0])) {
  745. $error++;
  746. $errorcode = 'KO';
  747. $errorlabel = "List of Id of products or services to delete are required.";
  748. }
  749. if (!$error) {
  750. $firsterror = '';
  751. $db->begin();
  752. foreach ($listofid as $id) {
  753. $newobject = new Product($db);
  754. $result = $newobject->fetch($id);
  755. if ($result == 0) {
  756. $error++;
  757. $firsterror = 'Product or service with id '.$id.' not found';
  758. break;
  759. } else {
  760. $result = $newobject->delete($user);
  761. if ($result <= 0) {
  762. $error++;
  763. $firsterror = $newobject->error;
  764. break;
  765. }
  766. $listofiddeleted[] = $id;
  767. }
  768. }
  769. if (!$error) {
  770. $db->commit();
  771. //$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'listofid'=>$listofiddeleted);
  772. $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'nbdeleted'=>count($listofiddeleted));
  773. } else {
  774. $db->rollback();
  775. $error++;
  776. $errorcode = 'KO';
  777. $errorlabel = $firsterror;
  778. }
  779. }
  780. if ($error) {
  781. //$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'listofid'=>$listofiddeleted);
  782. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'nbdeleted'=>0);
  783. } elseif (count($listofiddeleted) == 0) {
  784. //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted);
  785. $objectresp = array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',', $listofid).' found'), 'nbdeleted'=>0);
  786. }
  787. return $objectresp;
  788. }
  789. /**
  790. * getListOfProductsOrServices
  791. *
  792. * @param array $authentication Array of authentication information
  793. * @param array $filterproduct Filter fields
  794. * @return array Array result
  795. */
  796. function getListOfProductsOrServices($authentication, $filterproduct)
  797. {
  798. global $db, $conf;
  799. dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']);
  800. if ($authentication['entity']) {
  801. $conf->entity = $authentication['entity'];
  802. }
  803. // Init and check authentication
  804. $objectresp = array();
  805. $arrayproducts = array();
  806. $errorcode = '';
  807. $errorlabel = '';
  808. $error = 0;
  809. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  810. // Check parameters
  811. if (!$error) {
  812. $sql = "SELECT rowid, ref, ref_ext";
  813. $sql .= " FROM ".MAIN_DB_PREFIX."product";
  814. $sql .= " WHERE entity=".$conf->entity;
  815. foreach ($filterproduct as $key => $val) {
  816. if ($key == 'type' && $val >= 0) {
  817. $sql .= " AND fk_product_type = ".((int) $val);
  818. }
  819. if ($key == 'status_tosell') {
  820. $sql .= " AND tosell = ".((int) $val);
  821. }
  822. if ($key == 'status_tobuy') {
  823. $sql .= " AND tobuy = ".((int) $val);
  824. }
  825. }
  826. $resql = $db->query($sql);
  827. if ($resql) {
  828. $num = $db->num_rows($resql);
  829. $i = 0;
  830. while ($i < $num) {
  831. $obj = $db->fetch_object($resql);
  832. $arrayproducts[] = array('id'=>$obj->rowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext);
  833. $i++;
  834. }
  835. } else {
  836. $error++;
  837. $errorcode = $db->lasterrno();
  838. $errorlabel = $db->lasterror();
  839. }
  840. }
  841. if ($error) {
  842. $objectresp = array(
  843. 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
  844. 'products'=>$arrayproducts
  845. );
  846. } else {
  847. $objectresp = array(
  848. 'result'=>array('result_code' => 'OK', 'result_label' => ''),
  849. 'products'=>$arrayproducts
  850. );
  851. }
  852. return $objectresp;
  853. }
  854. /**
  855. * Get list of products for a category
  856. *
  857. * @param array $authentication Array of authentication information
  858. * @param int $id Category id
  859. * @param string $lang Force lang
  860. * @return array Array result
  861. */
  862. function getProductsForCategory($authentication, $id, $lang = '')
  863. {
  864. global $db, $conf, $langs;
  865. $langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
  866. $langs->setDefaultLang($langcode);
  867. dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id);
  868. if ($authentication['entity']) {
  869. $conf->entity = $authentication['entity'];
  870. }
  871. $objectresp = array();
  872. $errorcode = '';
  873. $errorlabel = '';
  874. $error = 0;
  875. $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
  876. if (!$error && !$id) {
  877. $error++;
  878. $errorcode = 'BAD_PARAMETERS';
  879. $errorlabel = "Parameter id must be provided.";
  880. }
  881. if (!$error) {
  882. $langcode = ($lang ? $lang : (!getDolGlobalString('MAIN_LANG_DEFAULT') ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
  883. $langs->setDefaultLang($langcode);
  884. $fuser->getrights();
  885. $nbmax = 10;
  886. if ($fuser->hasRight('produit', 'lire')) {
  887. $categorie = new Categorie($db);
  888. $result = $categorie->fetch($id);
  889. if ($result > 0) {
  890. $table = "product";
  891. $field = "product";
  892. $sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table;
  893. $sql .= " WHERE fk_categorie = ".((int) $id);
  894. $sql .= " ORDER BY fk_".$field." ASC";
  895. dol_syslog("getProductsForCategory get id of product into category", LOG_DEBUG);
  896. $res = $db->query($sql);
  897. if ($res) {
  898. $iProduct = 0;
  899. $tmpproduct = new Product($db);
  900. $products = array();
  901. while ($rec = $db->fetch_array($res)) {
  902. $tmpproduct->fetch($rec['fk_'.$field]);
  903. if ($tmpproduct->status > 0) {
  904. $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
  905. $pdir = get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct, 'product').$tmpproduct->id."/photos/";
  906. $dir = $dir.'/'.$pdir;
  907. $products[] = array(
  908. 'id' => $tmpproduct->id,
  909. 'ref' => $tmpproduct->ref,
  910. 'ref_ext' => $tmpproduct->ref_ext,
  911. 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang]["label"]) ? $tmpproduct->multilangs[$langs->defaultlang]["label"] : $tmpproduct->label,
  912. 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang]["description"]) ? $tmpproduct->multilangs[$langs->defaultlang]["description"] : $tmpproduct->description,
  913. 'date_creation' => dol_print_date($tmpproduct->date_creation, 'dayhourrfc'),
  914. 'date_modification' => dol_print_date($tmpproduct->date_modification, 'dayhourrfc'),
  915. 'note' => !empty($tmpproduct->multilangs[$langs->defaultlang]["note"]) ? $tmpproduct->multilangs[$langs->defaultlang]["note"] : $tmpproduct->note,
  916. 'status_tosell' => $tmpproduct->status,
  917. 'status_tobuy' => $tmpproduct->status_buy,
  918. 'type' => $tmpproduct->type,
  919. 'barcode' => $tmpproduct->barcode,
  920. 'barcode_type' => $tmpproduct->barcode_type,
  921. 'country_id' => $tmpproduct->country_id > 0 ? $tmpproduct->country_id : '',
  922. 'country_code' => $tmpproduct->country_code,
  923. 'custom_code' => $tmpproduct->customcode,
  924. 'price_net' => $tmpproduct->price,
  925. 'price' => $tmpproduct->price_ttc,
  926. 'vat_rate' => $tmpproduct->tva_tx,
  927. 'price_base_type' => $tmpproduct->price_base_type,
  928. 'stock_real' => $tmpproduct->stock_reel,
  929. 'stock_alert' => $tmpproduct->seuil_stock_alerte,
  930. 'pmp' => $tmpproduct->pmp,
  931. 'import_key' => $tmpproduct->import_key,
  932. 'dir' => $pdir,
  933. 'images' => $tmpproduct->liste_photos($dir, $nbmax)
  934. );
  935. $elementtype = 'product';
  936. //Retrieve all extrafield for thirdsparty
  937. // fetch optionals attributes and labels
  938. $extrafields = new ExtraFields($db);
  939. $extrafields->fetch_name_optionals_label($elementtype, true);
  940. //Get extrafield values
  941. $tmpproduct->fetch_optionals();
  942. if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
  943. foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
  944. $products[$iProduct] = array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key]));
  945. }
  946. }
  947. $iProduct++;
  948. }
  949. }
  950. // Retour
  951. $objectresp = array(
  952. 'result'=>array('result_code'=>'OK', 'result_label'=>''),
  953. 'products'=> $products
  954. );
  955. } else {
  956. $errorcode = 'NORECORDS_FOR_ASSOCIATION';
  957. $errorlabel = 'No products associated'.$sql;
  958. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  959. dol_syslog("getProductsForCategory:: ".$errorcode, LOG_DEBUG);
  960. }
  961. } else {
  962. $error++;
  963. $errorcode = 'NOT_FOUND';
  964. $errorlabel = 'Object not found for id='.$id;
  965. }
  966. } else {
  967. $error++;
  968. $errorcode = 'PERMISSION_DENIED';
  969. $errorlabel = 'User does not have permission for this request';
  970. }
  971. }
  972. if ($error) {
  973. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  974. }
  975. return $objectresp;
  976. }
  977. // Return the results.
  978. $server->service(file_get_contents("php://input"));