27 if (!defined(
"NOCSRFCHECK")) {
28 define(
"NOCSRFCHECK",
'1');
31 require
'../master.inc.php';
32 require_once NUSOAP_PATH.
'/nusoap.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.
"/categories/class/categorie.class.php";
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43 dol_syslog(
"Call Dolibarr webservices interfaces");
48 if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
49 $langs->load(
"admin");
50 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
51 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
52 print $langs->trans(
"ToActivateModule");
57 $server =
new nusoap_server();
58 $server->soap_defencoding =
'UTF-8';
59 $server->decode_utf8 =
false;
60 $ns =
'http://www.dolibarr.org/ns/';
61 $server->configureWSDL(
'WebServicesDolibarrProductOrService', $ns);
62 $server->wsdl->schemaTargetNamespace = $ns;
66 $server->wsdl->addComplexType(
73 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
74 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
75 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
76 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
77 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string')
81 $server->wsdl->addComplexType(
88 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
89 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string')
93 $productorservice_fields = array(
94 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
95 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
96 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
97 'type' => array(
'name'=>
'type',
'type'=>
'xsd:string'),
98 'label' => array(
'name'=>
'label',
'type'=>
'xsd:string'),
99 'description' => array(
'name'=>
'description',
'type'=>
'xsd:string'),
100 'date_creation' => array(
'name'=>
'date_creation',
'type'=>
'xsd:dateTime'),
101 'date_modification' => array(
'name'=>
'date_modification',
'type'=>
'xsd:dateTime'),
102 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
103 'status_tobuy' => array(
'name'=>
'status_tobuy',
'type'=>
'xsd:string'),
104 'status_tosell' => array(
'name'=>
'status_tosell',
'type'=>
'xsd:string'),
105 'barcode' => array(
'name'=>
'barcode',
'type'=>
'xsd:string'),
106 'barcode_type' => array(
'name'=>
'barcode_type',
'type'=>
'xsd:string'),
107 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
108 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
109 'customcode' => array(
'name'=>
'customcode',
'type'=>
'xsd:string'),
111 'price_net' => array(
'name'=>
'price_net',
'type'=>
'xsd:string'),
112 'price' => array(
'name'=>
'price',
'type'=>
'xsd:string'),
113 'price_min_net' => array(
'name'=>
'price_min_net',
'type'=>
'xsd:string'),
114 'price_min' => array(
'name'=>
'price_min',
'type'=>
'xsd:string'),
116 'price_base_type' => array(
'name'=>
'price_base_type',
'type'=>
'xsd:string'),
118 'vat_rate' => array(
'name'=>
'vat_rate',
'type'=>
'xsd:string'),
119 'vat_npr' => array(
'name'=>
'vat_npr',
'type'=>
'xsd:string'),
120 'localtax1_tx' => array(
'name'=>
'localtax1_tx',
'type'=>
'xsd:string'),
121 'localtax2_tx' => array(
'name'=>
'localtax2_tx',
'type'=>
'xsd:string'),
123 'stock_alert' => array(
'name'=>
'stock_alert',
'type'=>
'xsd:string'),
124 'stock_real' => array(
'name'=>
'stock_real',
'type'=>
'xsd:string'),
125 'stock_pmp' => array(
'name'=>
'stock_pmp',
'type'=>
'xsd:string'),
126 'warehouse_ref' => array(
'name'=>
'warehouse_ref',
'type'=>
'xsd:string'),
128 'canvas' => array(
'name'=>
'canvas',
'type'=>
'xsd:string'),
129 'import_key' => array(
'name'=>
'import_key',
'type'=>
'xsd:string'),
131 'dir' => array(
'name'=>
'dir',
'type'=>
'xsd:string'),
132 'images' => array(
'name'=>
'images',
'type'=>
'tns:ImagesArray')
136 $elementtype =
'product';
142 $extrafields->fetch_name_optionals_label($elementtype,
true);
143 $extrafield_array =
null;
144 if (is_array($extrafields) && count($extrafields) > 0) {
145 $extrafield_array = array();
147 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
148 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
149 $type = $extrafields->attributes[$elementtype][
'type'][$key];
150 if ($type ==
'date' || $type ==
'datetime') {
151 $type =
'xsd:dateTime';
153 $type =
'xsd:string';
156 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
160 if (!empty($extrafield_array) && is_array($extrafield_array)) {
161 $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
165 $server->wsdl->addComplexType(
171 $productorservice_fields
178 $server->wsdl->addComplexType(
187 'type' =>
'tns:image',
189 'maxOccurs' =>
'unbounded'
197 $server->wsdl->addComplexType(
204 'photo' => array(
'name'=>
'photo',
'type'=>
'xsd:string'),
205 'photo_vignette' => array(
'name'=>
'photo_vignette',
'type'=>
'xsd:string'),
206 'imgWidth' => array(
'name'=>
'imgWidth',
'type'=>
'xsd:string'),
207 'imgHeight' => array(
'name'=>
'imgHeight',
'type'=>
'xsd:string')
213 $server->wsdl->addComplexType(
221 'type' => array(
'name'=>
'type',
'type'=>
'xsd:string'),
222 'status_tobuy' => array(
'name'=>
'status_tobuy',
'type'=>
'xsd:string'),
223 'status_tosell' => array(
'name'=>
'status_tosell',
'type'=>
'xsd:string'),
227 $server->wsdl->addComplexType(
236 'type' =>
'tns:product',
238 'maxOccurs' =>
'unbounded'
248 $styleuse =
'encoded';
254 'getProductOrService',
256 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string',
'lang'=>
'xsd:string'),
258 array(
'result'=>
'tns:result',
'product'=>
'tns:product'),
260 $ns.
'#getProductOrService',
263 'WS to get product or service'
268 'createProductOrService',
270 array(
'authentication'=>
'tns:authentication',
'product'=>
'tns:product'),
272 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
274 $ns.
'#createProductOrService',
277 'WS to create a product or service'
282 'updateProductOrService',
284 array(
'authentication'=>
'tns:authentication',
'product'=>
'tns:product'),
286 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
288 $ns.
'#updateProductOrService',
291 'WS to update a product or service'
296 'deleteProductOrService',
298 array(
'authentication'=>
'tns:authentication',
'listofid'=>
'xsd:string'),
300 array(
'result'=>
'tns:result',
'nbdeleted'=>
'xsd:int'),
302 $ns.
'#deleteProductOrService',
305 'WS to delete a product or service'
310 'getListOfProductsOrServices',
312 array(
'authentication'=>
'tns:authentication',
'filterproduct'=>
'tns:filterproduct'),
314 array(
'result'=>
'tns:result',
'products'=>
'tns:ProductsArray2'),
316 $ns.
'#getListOfProductsOrServices',
319 'WS to get list of all products or services id and ref'
324 'getProductsForCategory',
326 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'lang'=>
'xsd:string'),
328 array(
'result'=>
'tns:result',
'products'=>
'tns:ProductsArray2'),
330 $ns.
'#getProductsForCategory',
333 'WS to get list of all products or services for a category'
349 global $db, $conf, $langs;
351 dol_syslog(
"Function: getProductOrService login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
353 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
354 $langs->setDefaultLang($langcode);
356 if ($authentication[
'entity']) {
357 $conf->entity = $authentication[
'entity'];
361 $objectresp = array();
367 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
369 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
373 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
374 $langs->setDefaultLang($langcode);
379 if ($fuser->rights->produit->lire || $fuser->rights->service->lire) {
381 $result = $product->fetch($id, $ref, $ref_ext);
384 $product->load_stock();
386 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
387 $pdir =
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->ref.
"/";
388 $dir = $dir.
'/'.$pdir;
390 if (!empty($product->multilangs[$langs->defaultlang][
"label"])) {
391 $product->label = $product->multilangs[$langs->defaultlang][
"label"];
393 if (!empty($product->multilangs[$langs->defaultlang][
"description"])) {
394 $product->description = $product->multilangs[$langs->defaultlang][
"description"];
396 if (!empty($product->multilangs[$langs->defaultlang][
"note"])) {
397 $product->note = $product->multilangs[$langs->defaultlang][
"note"];
400 $productorservice_result_fields = array(
401 'id' => $product->id,
402 'ref' => $product->ref,
403 'ref_ext' => $product->ref_ext,
404 'label' => $product->label,
405 'description' => $product->description,
406 'date_creation' =>
dol_print_date($product->date_creation,
'dayhourrfc'),
407 'date_modification' =>
dol_print_date($product->date_modification,
'dayhourrfc'),
408 'note' => $product->note,
409 'status_tosell' => $product->status,
410 'status_tobuy' => $product->status_buy,
411 'type' => $product->type,
412 'barcode' => $product->barcode,
413 'barcode_type' => $product->barcode_type,
414 'country_id' => $product->country_id > 0 ? $product->country_id :
'',
415 'country_code' => $product->country_code,
416 'custom_code' => $product->customcode,
418 'price_net' => $product->price,
419 'price' => $product->price_ttc,
420 'price_min_net' => $product->price_min,
421 'price_min' => $product->price_min_ttc,
422 'price_base_type' => $product->price_base_type,
423 'vat_rate' => $product->tva_tx,
425 'vat_npr' => $product->tva_npr,
427 'localtax1_tx' => $product->localtax1_tx,
428 'localtax2_tx' => $product->localtax2_tx,
430 'stock_real' => $product->stock_reel,
431 'stock_virtual' => $product->stock_theorique,
432 'stock_alert' => $product->seuil_stock_alerte,
433 'pmp' => $product->pmp,
434 'import_key' => $product->import_key,
436 'images' => $product->liste_photos($dir, $nbmax)
439 $elementtype =
'product';
444 $extrafields->fetch_name_optionals_label($elementtype,
true);
446 $product->fetch_optionals();
448 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
449 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
450 $productorservice_result_fields = array_merge($productorservice_result_fields, array(
'options_'.$key => $product->array_options[
'options_'.$key]));
456 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
457 'product'=>$productorservice_result_fields
461 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
465 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
470 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
490 dol_syslog(
"Function: createProductOrService login=".$authentication[
'login']);
492 if ($authentication[
'entity']) {
493 $conf->entity = $authentication[
'entity'];
497 $objectresp = array();
503 if (empty($product[
'price_base_type'])) {
504 if (isset($product[
'price_net']) && $product[
'price_net'] > 0) {
505 $product[
'price_base_type'] =
'HT';
507 if (isset($product[
'price']) && $product[
'price'] > 0) {
508 $product[
'price_base_type'] =
'TTC';
512 if (isset($product[
'price_net']) && $product[
'price_net'] > 0 && isset($product[
'price']) && $product[
'price'] > 0) {
513 $error++; $errorcode =
'KO'; $errorlabel =
"You must choose between price or price_net to provide price.";
516 if (!empty($product[
'barcode']) && empty($product[
'barcode_type'])) {
517 $error++; $errorcode =
'KO'; $errorlabel =
"You must set a barcode type when setting a barcode.";
521 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
524 $newobject->ref = $product[
'ref'];
525 $newobject->ref_ext = empty($product[
'ref_ext']) ?
'' : $product[
'ref_ext'];
526 $newobject->type = empty($product[
'type']) ? 0 : $product[
'type'];
527 $newobject->label = empty($product[
'label']) ?
'' : $product[
'label'];
528 $newobject->description = empty($product[
'description']) ?
'' : $product[
'description'];
529 $newobject->note_public = empty($product[
'note_public']) ?
'' : $product[
'note_public'];
530 $newobject->note_private = empty($product[
'note_private']) ?
'' : $product[
'note_private'];
531 $newobject->status = empty($product[
'status_tosell']) ? 0 : $product[
'status_tosell'];
532 $newobject->status_buy = empty($product[
'status_tobuy']) ? 0 : $product[
'status_tobuy'];
533 $newobject->price = isset($product[
'price_net']) ? $product[
'price_net'] : 0;
534 $newobject->price_ttc = isset($product[
'price']) ? $product[
'price'] : 0;
535 $newobject->tva_tx = empty($product[
'vat_rate']) ? 0 : $product[
'vat_rate'];
536 $newobject->price_base_type = $product[
'price_base_type'];
537 $newobject->date_creation = $now;
539 if (!empty($product[
'barcode'])) {
540 $newobject->barcode = $product[
'barcode'];
541 $newobject->barcode_type = $product[
'barcode_type'];
544 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
545 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
546 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
548 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
549 if (!empty($product[
'country_code'])) {
550 $newobject->country_id =
getCountry($product[
'country_code'], 3);
552 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
554 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
571 $elementtype =
'product';
574 $extrafields->fetch_name_optionals_label($elementtype,
true);
575 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
576 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
577 $key =
'options_'.$key;
578 $newobject->array_options[$key] = $product[$key];
584 $result = $newobject->create($fuser, 0);
591 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
592 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
594 $savstockreal = $newobject->stock_reel;
595 $newobject->load_stock(
'novirtual,nobatch');
596 $getstockreal = $newobject->stock_reel;
598 if ($savstockreal != $getstockreal) {
600 $warehouse->fetch(0, $product[
'warehouse_ref']);
601 if ($warehouse->id > 0) {
602 if (($savstockreal - $getstockreal) > 0) {
603 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
605 if (($savstockreal - $getstockreal) > 0) {
606 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
610 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
614 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
622 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
627 $errorlabel = $newobject->error;
632 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
652 dol_syslog(
"Function: updateProductOrService login=".$authentication[
'login']);
654 if ($authentication[
'entity']) {
655 $conf->entity = $authentication[
'entity'];
659 $objectresp = array();
665 if ($product[
'price_net'] > 0) {
666 $product[
'price_base_type'] =
'HT';
668 if ($product[
'price'] > 0) {
669 $product[
'price_base_type'] =
'TTC';
672 if ($product[
'price_net'] > 0 && $product[
'price'] > 0) {
673 $error++; $errorcode =
'KO'; $errorlabel =
"You must choose between price or price_net to provide price.";
677 if ($product[
'barcode'] && !$product[
'barcode_type']) {
678 $error++; $errorcode =
'KO'; $errorlabel =
"You must set a barcode type when setting a barcode.";
682 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
685 $newobject->fetch($product[
'id']);
687 if (isset($product[
'ref'])) {
688 $newobject->ref = $product[
'ref'];
690 if (isset($product[
'ref_ext'])) {
691 $newobject->ref_ext = $product[
'ref_ext'];
693 $newobject->type = $product[
'type'];
694 $newobject->label = $product[
'label'];
695 $newobject->description = $product[
'description'];
696 $newobject->note = $product[
'note'];
697 $newobject->status = $product[
'status_tosell'];
698 $newobject->status_buy = $product[
'status_tobuy'];
699 $newobject->price = $product[
'price_net'];
700 $newobject->price_ttc = $product[
'price'];
701 $newobject->tva_tx = $product[
'vat_rate'];
702 $newobject->price_base_type = $product[
'price_base_type'];
703 $newobject->date_creation = $now;
705 if ($product[
'barcode']) {
706 $newobject->barcode = $product[
'barcode'];
707 $newobject->barcode_type = $product[
'barcode_type'];
710 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
711 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
712 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
714 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
715 if (!empty($product[
'country_code'])) {
716 $newobject->country_id =
getCountry($product[
'country_code'], 3);
718 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
720 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
722 $elementtype =
'product';
725 $extrafields->fetch_name_optionals_label($elementtype,
true);
726 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
727 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
728 $key =
'options_'.$key;
729 $newobject->array_options[$key] = $product[$key];
735 $result = $newobject->update($newobject->id, $fuser);
740 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
741 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
743 $savstockreal = $newobject->stock_reel;
744 $newobject->load_stock(
'novirtual,nobatch');
745 $getstockreal = $newobject->stock_reel;
747 if ($savstockreal != $getstockreal) {
749 $warehouse->fetch(0, $product[
'warehouse_ref']);
750 if ($warehouse->id > 0) {
751 if (($savstockreal - $getstockreal) > 0) {
752 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
754 if (($savstockreal - $getstockreal) > 0) {
755 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
759 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
763 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
770 if ($newobject->price_base_type ==
'HT') {
771 $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
775 } elseif ($newobject->price_base_type ==
'TTC') {
776 $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
785 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
790 $errorlabel = $newobject->error;
795 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
813 dol_syslog(
"Function: deleteProductOrService login=".$authentication[
'login']);
815 if ($authentication[
'entity']) {
816 $conf->entity = $authentication[
'entity'];
820 $objectresp = array();
830 $listofid = explode(
',', trim($listofidstring));
831 $listofiddeleted = array();
834 if (count($listofid) == 0 || empty($listofid[0])) {
835 $error++; $errorcode =
'KO'; $errorlabel =
"List of Id of products or services to delete are required.";
843 foreach ($listofid as $id) {
845 $result = $newobject->fetch($id);
849 $firsterror =
'Product or service with id '.$id.
' not found';
852 $result = $newobject->delete($user);
855 $firsterror = $newobject->error;
859 $listofiddeleted[] = $id;
866 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'nbdeleted'=>count($listofiddeleted));
871 $errorlabel = $firsterror;
877 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
'nbdeleted'=>0);
878 } elseif (count($listofiddeleted) == 0) {
880 $objectresp = array(
'result'=>array(
'result_code'=>
'NOT_FOUND',
'result_label'=>
'No product or service with id '.join(
',', $listofid).
' found'),
'nbdeleted'=>0);
898 dol_syslog(
"Function: getListOfProductsOrServices login=".$authentication[
'login']);
900 if ($authentication[
'entity']) {
901 $conf->entity = $authentication[
'entity'];
905 $objectresp = array();
906 $arrayproducts = array();
914 $sql =
"SELECT rowid, ref, ref_ext";
915 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
916 $sql .=
" WHERE entity=".$conf->entity;
917 foreach ($filterproduct as $key => $val) {
918 if ($key ==
'type' && $val >= 0) {
919 $sql .=
" AND fk_product_type = ".((int) $val);
921 if ($key ==
'status_tosell') {
922 $sql .=
" AND tosell = ".((int) $val);
924 if ($key ==
'status_tobuy') {
925 $sql .=
" AND tobuy = ".((int) $val);
928 $resql = $db->query($sql);
930 $num = $db->num_rows(
$resql);
934 $obj = $db->fetch_object(
$resql);
935 $arrayproducts[] = array(
'id'=>$obj->rowid,
'ref'=>$obj->ref,
'ref_ext'=>$obj->ref_ext);
940 $errorcode = $db->lasterrno();
941 $errorlabel = $db->lasterror();
947 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
948 'products'=>$arrayproducts
952 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
953 'products'=>$arrayproducts
971 global $db, $conf, $langs;
973 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
974 $langs->setDefaultLang($langcode);
976 dol_syslog(
"Function: getProductsForCategory login=".$authentication[
'login'].
" id=".$id);
978 if ($authentication[
'entity']) {
979 $conf->entity = $authentication[
'entity'];
982 $objectresp = array();
983 $errorcode =
''; $errorlabel =
'';
989 if (!$error && !$id) {
991 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id must be provided.";
996 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
997 $langs->setDefaultLang($langcode);
1002 if ($fuser->rights->produit->lire) {
1004 $result = $categorie->fetch($id);
1008 $sql =
"SELECT fk_".$field.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$table;
1009 $sql .=
" WHERE fk_categorie = ".((int) $id);
1010 $sql .=
" ORDER BY fk_".$field.
" ASC";
1013 dol_syslog(
"getProductsForCategory get id of product into category", LOG_DEBUG);
1014 $res = $db->query($sql);
1017 $tmpproduct =
new Product($db);
1018 $products = array();
1019 while ($rec = $db->fetch_array($res)) {
1020 $tmpproduct->fetch($rec[
'fk_'.$field]);
1021 if ($tmpproduct->status > 0) {
1022 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
1023 $pdir =
get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct,
'product').$tmpproduct->id.
"/photos/";
1024 $dir = $dir.
'/'.$pdir;
1026 $products[] = array(
1027 'id' => $tmpproduct->id,
1028 'ref' => $tmpproduct->ref,
1029 'ref_ext' => $tmpproduct->ref_ext,
1030 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"label"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"label"] : $tmpproduct->label,
1031 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"description"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"description"] : $tmpproduct->description,
1032 'date_creation' =>
dol_print_date($tmpproduct->date_creation,
'dayhourrfc'),
1033 'date_modification' =>
dol_print_date($tmpproduct->date_modification,
'dayhourrfc'),
1034 'note' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"note"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"note"] : $tmpproduct->note,
1035 'status_tosell' => $tmpproduct->status,
1036 'status_tobuy' => $tmpproduct->status_buy,
1037 'type' => $tmpproduct->type,
1038 'barcode' => $tmpproduct->barcode,
1039 'barcode_type' => $tmpproduct->barcode_type,
1040 'country_id' => $tmpproduct->country_id > 0 ? $tmpproduct->country_id :
'',
1041 'country_code' => $tmpproduct->country_code,
1042 'custom_code' => $tmpproduct->customcode,
1044 'price_net' => $tmpproduct->price,
1045 'price' => $tmpproduct->price_ttc,
1046 'vat_rate' => $tmpproduct->tva_tx,
1048 'price_base_type' => $tmpproduct->price_base_type,
1050 'stock_real' => $tmpproduct->stock_reel,
1051 'stock_alert' => $tmpproduct->seuil_stock_alerte,
1052 'pmp' => $tmpproduct->pmp,
1053 'import_key' => $tmpproduct->import_key,
1055 'images' => $tmpproduct->liste_photos($dir, $nbmax)
1058 $elementtype =
'product';
1063 $extrafields->fetch_name_optionals_label($elementtype,
true);
1065 $tmpproduct->fetch_optionals();
1067 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
1068 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
1069 $products[$iProduct] = array_merge($products[$iProduct], array(
'options_'.$key => $tmpproduct->array_options[
'options_'.$key]));
1078 $objectresp = array(
1079 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
1080 'products'=> $products
1083 $errorcode =
'NORECORDS_FOR_ASSOCIATION'; $errorlabel =
'No products associated'.$sql;
1084 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1085 dol_syslog(
"getProductsForCategory:: ".$errorcode, LOG_DEBUG);
1089 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id;
1093 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
1098 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1105 $server->service(file_get_contents(
"php://input"));
Class to manage categories.
Class to manage warehouses.
Class to manage products or services.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getProductsForCategory($authentication, $id, $lang='')
Get list of products for a category.
getListOfProductsOrServices($authentication, $filterproduct)
getListOfProductsOrServices
updateProductOrService($authentication, $product)
Update a product or service.
createProductOrService($authentication, $product)
Create an invoice.
getProductOrService($authentication, $id='', $ref='', $ref_ext='', $lang='')
Get produt or service.
deleteProductOrService($authentication, $listofidstring)
Delete a product or service.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.