dolibarr 18.0.6
api_mos.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use Luracast\Restler\RestException;
20
21require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
22
23
36class Mos extends DolibarrApi
37{
41 public $mo;
42
46 public function __construct()
47 {
48 global $db, $conf;
49 $this->db = $db;
50 $this->mo = new Mo($this->db);
51 }
52
64 public function get($id)
65 {
66 if (!DolibarrApiAccess::$user->rights->mrp->read) {
67 throw new RestException(401);
68 }
69
70 $result = $this->mo->fetch($id);
71 if (!$result) {
72 throw new RestException(404, 'MO not found');
73 }
74
75 if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
76 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
77 }
78
79 return $this->_cleanObjectDatas($this->mo);
80 }
81
82
97 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
98 {
99 global $db, $conf;
100
101 if (!DolibarrApiAccess::$user->rights->mrp->read) {
102 throw new RestException(401);
103 }
104
105 $obj_ret = array();
106 $tmpobject = new Mo($this->db);
107
108 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
109
110 $restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
111
112 // If the internal user must only see his customers, force searching by him
113 $search_sale = 0;
114 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
115 $search_sale = DolibarrApiAccess::$user->id;
116 }
117
118 $sql = "SELECT t.rowid";
119 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
120 $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
121 }
122 $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
123
124 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
125 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
126 }
127 $sql .= " WHERE 1 = 1";
128
129 // Example of use $mode
130 //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
131 //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
132
133 if ($tmpobject->ismultientitymanaged) {
134 $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
135 }
136 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
137 $sql .= " AND t.fk_soc = sc.fk_soc";
138 }
139 if ($restrictonsocid && $socid) {
140 $sql .= " AND t.fk_soc = ".((int) $socid);
141 }
142 if ($restrictonsocid && $search_sale > 0) {
143 $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
144 }
145 // Insert sale filter
146 if ($restrictonsocid && $search_sale > 0) {
147 $sql .= " AND sc.fk_user = ".((int) $search_sale);
148 }
149 if ($sqlfilters) {
150 $errormessage = '';
151 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
152 if ($errormessage) {
153 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
154 }
155 }
156
157 $sql .= $this->db->order($sortfield, $sortorder);
158 if ($limit) {
159 if ($page < 0) {
160 $page = 0;
161 }
162 $offset = $limit * $page;
163
164 $sql .= $this->db->plimit($limit + 1, $offset);
165 }
166
167 $result = $this->db->query($sql);
168 if ($result) {
169 $num = $this->db->num_rows($result);
170 $i = 0;
171 while ($i < $num) {
172 $obj = $this->db->fetch_object($result);
173 $tmp_object = new Mo($this->db);
174 if ($tmp_object->fetch($obj->rowid)) {
175 $obj_ret[] = $this->_cleanObjectDatas($tmp_object);
176 }
177 $i++;
178 }
179 } else {
180 throw new RestException(503, 'Error when retrieve MO list');
181 }
182 if (!count($obj_ret)) {
183 throw new RestException(404, 'No MO found');
184 }
185 return $obj_ret;
186 }
187
194 public function post($request_data = null)
195 {
196 if (!DolibarrApiAccess::$user->rights->mrp->write) {
197 throw new RestException(401);
198 }
199 // Check mandatory fields
200 $result = $this->_validate($request_data);
201
202 foreach ($request_data as $field => $value) {
203 $this->mo->$field = $value;
204 }
205
206 $this->checkRefNumbering();
207
208 if (!$this->mo->create(DolibarrApiAccess::$user)) {
209 throw new RestException(500, "Error creating MO", array_merge(array($this->mo->error), $this->mo->errors));
210 }
211 return $this->mo->id;
212 }
213
222 public function put($id, $request_data = null)
223 {
224 if (!DolibarrApiAccess::$user->rights->mrp->write) {
225 throw new RestException(401);
226 }
227
228 $result = $this->mo->fetch($id);
229 if (!$result) {
230 throw new RestException(404, 'MO not found');
231 }
232
233 if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
234 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
235 }
236
237 foreach ($request_data as $field => $value) {
238 if ($field == 'id') {
239 continue;
240 }
241 if ($field == 'array_options' && is_array($value)) {
242 foreach ($value as $index => $val) {
243 $this->mo->array_options[$index] = $this->_checkValForAPI($field, $val, $this->mo);
244 }
245 continue;
246 }
247 $this->mo->$field = $value;
248 }
249
250 $this->checkRefNumbering();
251
252 if ($this->mo->update(DolibarrApiAccess::$user) > 0) {
253 return $this->get($id);
254 } else {
255 throw new RestException(500, $this->mo->error);
256 }
257 }
258
265 public function delete($id)
266 {
267 if (!DolibarrApiAccess::$user->rights->mrp->delete) {
268 throw new RestException(401);
269 }
270 $result = $this->mo->fetch($id);
271 if (!$result) {
272 throw new RestException(404, 'MO not found');
273 }
274
275 if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
276 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
277 }
278
279 if (!$this->mo->delete(DolibarrApiAccess::$user)) {
280 throw new RestException(500, 'Error when deleting MO : '.$this->mo->error);
281 }
282
283 return array(
284 'success' => array(
285 'code' => 200,
286 'message' => 'MO deleted'
287 )
288 );
289 }
290
291
311 public function produceAndConsume($id, $request_data = null)
312 {
313 global $langs;
314
315 $error = 0;
316
317 if (!DolibarrApiAccess::$user->rights->mrp->write) {
318 throw new RestException(401, 'Not enough permission');
319 }
320 $result = $this->mo->fetch($id);
321 if (!$result) {
322 throw new RestException(404, 'MO not found');
323 }
324
325 if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) {
326 throw new RestException(401, 'Error bad status of MO');
327 }
328
329 $labelmovement = '';
330 $codemovement = '';
331 $autoclose = 1;
332 $arraytoconsume = array();
333 $arraytoproduce = array();
334
335 foreach ($request_data as $field => $value) {
336 if ($field == 'inventorylabel') {
337 $labelmovement = $value;
338 }
339 if ($field == 'inventorycode') {
340 $codemovement = $value;
341 }
342 if ($field == 'autoclose') {
343 $autoclose = $value;
344 }
345 if ($field == 'arraytoconsume') {
346 $arraytoconsume = $value;
347 }
348 if ($field == 'arraytoproduce') {
349 $arraytoproduce = $value;
350 }
351 }
352
353 if (empty($labelmovement)) {
354 throw new RestException(500, "Field inventorylabel not provided");
355 }
356 if (empty($codemovement)) {
357 throw new RestException(500, "Field inventorycode not provided");
358 }
359
360 // Code for consume and produce...
361 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
362 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
363 dol_include_once('/mrp/lib/mrp_mo.lib.php');
364
365 $stockmove = new MouvementStock($this->db);
366
367 $consumptioncomplete = true;
368 $productioncomplete = true;
369
370 if (!empty($arraytoconsume) && !empty($arraytoproduce)) {
371 $pos = 0;
372 $arrayofarrayname = array("arraytoconsume","arraytoproduce");
373 foreach ($arrayofarrayname as $arrayname) {
374 foreach ($arrayname as $value) {
375 $tmpproduct = new Product($this->db);
376 if (empty($value["objectid"])) {
377 throw new RestException(500, "Field objectid required in ".$arrayname);
378 }
379 $tmpproduct->fetch($value["qty"]);
380 if (empty($value["qty"])) {
381 throw new RestException(500, "Field qty required in ".$arrayname);
382 }
383 if ($value["qty"]!=0) {
384 $qtytoprocess = $value["qty"];
385 if (isset($value["fk_warehouse"])) { // If there is a warehouse to set
386 if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set.
387 $error++;
388 throw new RestException(500, "Field fk_warehouse must be > 0 in ".$arrayname);
389 }
390 if ($tmpproduct->status_batch) {
391 $error++;
392 throw new RestException(500, "Product ".$tmpproduct->ref."must be in batch");
393 }
394 }
395 $idstockmove = 0;
396 if (!$error && $value["fk_warehouse"] > 0) {
397 // Record stock movement
398 $id_product_batch = 0;
399
400 $stockmove->setOrigin($this->mo->element, $this->mo->id);
401
402 if ($qtytoprocess >= 0) {
403 $moline = new MoLine($this->db);
404 $moline->fk_mo = $this->mo->id;
405 $moline->position = $pos;
406 $moline->fk_product = $value["objectid"];
407 $moline->fk_warehouse = $value["fk_warehouse"];
408 $moline->qty = $qtytoprocess;
409 $moline->batch = $tmpproduct->status_batch;
410 $moline->role = 'toproduce';
411 $moline->fk_mrp_production = "";
412 $moline->fk_stock_movement = $idstockmove;
413 $moline->fk_user_creat = DolibarrApiAccess::$user->id;
414
415 $resultmoline = $moline->create(DolibarrApiAccess::$user);
416 if ($resultmoline <= 0) {
417 $error++;
418 throw new RestException(500, $moline->error);
419 }
420 $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
421 } else {
422 $moline = new MoLine($this->db);
423 $moline->fk_mo = $this->mo->id;
424 $moline->position = $pos;
425 $moline->fk_product = $value["objectid"];
426 $moline->fk_warehouse = $value["fk_warehouse"];
427 $moline->qty = $qtytoprocess;
428 $moline->batch = $tmpproduct->status_batch;
429 $moline->role = 'toconsume';
430 $moline->fk_mrp_production = "";
431 $moline->fk_stock_movement = $idstockmove;
432 $moline->fk_user_creat = DolibarrApiAccess::$user->id;
433
434 $resultmoline = $moline->create(DolibarrApiAccess::$user);
435 if ($resultmoline <= 0) {
436 $error++;
437 throw new RestException(500, $moline->error);
438 }
439 $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
440 }
441 if ($idstockmove < 0) {
442 $error++;
443 throw new RestException(500, $stockmove->error);
444 }
445 }
446 if (!$error) {
447 // Record consumption
448 $moline = new MoLine($this->db);
449 $moline->fk_mo = $this->mo->id;
450 $moline->position = $pos;
451 $moline->fk_product = $value["objectid"];
452 $moline->fk_warehouse = $value["fk_warehouse"];
453 $moline->qty = $qtytoprocess;
454 $moline->batch = $tmpproduct->status_batch;
455 if ($arrayname == "arraytoconsume") {
456 $moline->role = 'consumed';
457 } else {
458 $moline->role = 'produced';
459 }
460 $moline->fk_mrp_production = "";
461 $moline->fk_stock_movement = $idstockmove;
462 $moline->fk_user_creat = DolibarrApiAccess::$user->id;
463
464 $resultmoline = $moline->create(DolibarrApiAccess::$user);
465 if ($resultmoline <= 0) {
466 $error++;
467 throw new RestException(500, $moline->error);
468 }
469
470 $pos++;
471 }
472 }
473 }
474 }
475 if (!$error) {
476 if ($autoclose <= 0) {
477 $consumptioncomplete = false;
478 $productioncomplete = false;
479 }
480 }
481 } else {
482 $pos = 0;
483 foreach ($this->mo->lines as $line) {
484 if ($line->role == 'toconsume') {
485 $tmpproduct = new Product($this->db);
486 $tmpproduct->fetch($line->fk_product);
487 if ($line->qty != 0) {
488 $qtytoprocess = $line->qty;
489 if (isset($line->fk_warehouse)) { // If there is a warehouse to set
490 if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
491 $langs->load("errors");
492 $error++;
493 throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref));
494 }
495 if ($tmpproduct->status_batch) {
496 $langs->load("errors");
497 $error++;
498 throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref));
499 }
500 }
501 $idstockmove = 0;
502 if (!$error && $line->fk_warehouse > 0) {
503 // Record stock movement
504 $id_product_batch = 0;
505 $stockmove->origin_type = 'mo';
506 $stockmove->origin_id = $this->mo->id;
507 if ($qtytoprocess >= 0) {
508 $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
509 } else {
510 $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
511 }
512 if ($idstockmove < 0) {
513 $error++;
514 throw new RestException(500, $stockmove->error);
515 }
516 }
517 if (!$error) {
518 // Record consumption
519 $moline = new MoLine($this->db);
520 $moline->fk_mo = $this->mo->id;
521 $moline->position = $pos;
522 $moline->fk_product = $line->fk_product;
523 $moline->fk_warehouse = $line->fk_warehouse;
524 $moline->qty = $qtytoprocess;
525 $moline->batch = $tmpproduct->status_batch;
526 $moline->role = 'consumed';
527 $moline->fk_mrp_production = $line->id;
528 $moline->fk_stock_movement = $idstockmove;
529 $moline->fk_user_creat = DolibarrApiAccess::$user->id;
530
531 $resultmoline = $moline->create(DolibarrApiAccess::$user);
532 if ($resultmoline <= 0) {
533 $error++;
534 throw new RestException(500, $moline->error);
535 }
536
537 $pos++;
538 }
539 }
540 }
541 }
542 $pos = 0;
543 foreach ($this->mo->lines as $line) {
544 if ($line->role == 'toproduce') {
545 $tmpproduct = new Product($this->db);
546 $tmpproduct->fetch($line->fk_product);
547 if ($line->qty != 0) {
548 $qtytoprocess = $line->qty;
549 if (isset($line->fk_warehouse)) { // If there is a warehouse to set
550 if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
551 $langs->load("errors");
552 $error++;
553 throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref));
554 }
555 if ($tmpproduct->status_batch) {
556 $langs->load("errors");
557 $error++;
558 throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref));
559 }
560 }
561 $idstockmove = 0;
562 if (!$error && $line->fk_warehouse > 0) {
563 // Record stock movement
564 $id_product_batch = 0;
565 $stockmove->origin_type = 'mo';
566 $stockmove->origin_id = $this->mo->id;
567 if ($qtytoprocess >= 0) {
568 $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
569 } else {
570 $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
571 }
572 if ($idstockmove < 0) {
573 $error++;
574 throw new RestException(500, $stockmove->error);
575 }
576 }
577 if (!$error) {
578 // Record consumption
579 $moline = new MoLine($this->db);
580 $moline->fk_mo = $this->mo->id;
581 $moline->position = $pos;
582 $moline->fk_product = $line->fk_product;
583 $moline->fk_warehouse = $line->fk_warehouse;
584 $moline->qty = $qtytoprocess;
585 $moline->batch = $tmpproduct->status_batch;
586 $moline->role = 'produced';
587 $moline->fk_mrp_production = $line->id;
588 $moline->fk_stock_movement = $idstockmove;
589 $moline->fk_user_creat = DolibarrApiAccess::$user->id;
590
591 $resultmoline = $moline->create(DolibarrApiAccess::$user);
592 if ($resultmoline <= 0) {
593 $error++;
594 throw new RestException(500, $moline->error);
595 }
596
597 $pos++;
598 }
599 }
600 }
601 }
602
603 if (!$error) {
604 if ($autoclose > 0) {
605 foreach ($this->mo->lines as $line) {
606 if ($line->role == 'toconsume') {
607 $arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id);
608 $alreadyconsumed = 0;
609 foreach ($arrayoflines as $line2) {
610 $alreadyconsumed += $line2['qty'];
611 }
612
613 if ($alreadyconsumed < $line->qty) {
614 $consumptioncomplete = false;
615 }
616 }
617 if ($line->role == 'toproduce') {
618 $arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id);
619 $alreadyproduced = 0;
620 foreach ($arrayoflines as $line2) {
621 $alreadyproduced += $line2['qty'];
622 }
623
624 if ($alreadyproduced < $line->qty) {
625 $productioncomplete = false;
626 }
627 }
628 }
629 } else {
630 $consumptioncomplete = false;
631 $productioncomplete = false;
632 }
633 }
634 }
635
636 // Update status of MO
637 dol_syslog("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
638 //var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
639 if ($consumptioncomplete && $productioncomplete) {
640 $result = $this->mo->setStatut(Mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
641 } else {
642 $result = $this->mo->setStatut(Mo::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
643 }
644 if ($result <= 0) {
645 throw new RestException(500, $this->mo->error);
646 }
647
648 return $this->mo->id;
649 }
650
651
652 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
659 protected function _cleanObjectDatas($object)
660 {
661 // phpcs:enable
662 $object = parent::_cleanObjectDatas($object);
663
664 unset($object->rowid);
665 unset($object->canvas);
666
667 unset($object->name);
668 unset($object->lastname);
669 unset($object->firstname);
670 unset($object->civility_id);
671 unset($object->statut);
672 unset($object->state);
673 unset($object->state_id);
674 unset($object->state_code);
675 unset($object->region);
676 unset($object->region_code);
677 unset($object->country);
678 unset($object->country_id);
679 unset($object->country_code);
680 unset($object->barcode_type);
681 unset($object->barcode_type_code);
682 unset($object->barcode_type_label);
683 unset($object->barcode_type_coder);
684 unset($object->total_ht);
685 unset($object->total_tva);
686 unset($object->total_localtax1);
687 unset($object->total_localtax2);
688 unset($object->total_ttc);
689 unset($object->fk_account);
690 unset($object->comments);
691 unset($object->note);
692 unset($object->mode_reglement_id);
693 unset($object->cond_reglement_id);
694 unset($object->cond_reglement);
695 unset($object->shipping_method_id);
696 unset($object->fk_incoterms);
697 unset($object->label_incoterms);
698 unset($object->location_incoterms);
699
700 // If object has lines, remove $db property
701 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
702 $nboflines = count($object->lines);
703 for ($i = 0; $i < $nboflines; $i++) {
704 $this->_cleanObjectDatas($object->lines[$i]);
705
706 unset($object->lines[$i]->lines);
707 unset($object->lines[$i]->note);
708 }
709 }
710
711 return $object;
712 }
713
722 private function _validate($data)
723 {
724 $myobject = array();
725 foreach ($this->mo->fields as $field => $propfield) {
726 if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
727 continue; // Not a mandatory field
728 }
729 if (!isset($data[$field])) {
730 throw new RestException(400, "$field field missing");
731 }
732 $myobject[$field] = $data[$field];
733 }
734 return $myobject;
735 }
736
742 private function checkRefNumbering(): void
743 {
744 $ref = substr($this->mo->ref, 1, 4);
745 if ($this->mo->status > 0 && $ref == 'PROV') {
746 throw new RestException(400, "Wrong naming scheme '(PROV%)' is only allowed on 'DRAFT' status. For automatic increment use 'auto' on the 'ref' field.");
747 }
748
749 if (strtolower($this->mo->ref) == 'auto') {
750 if (empty($this->mo->id) && $this->mo->status == 0) {
751 $this->mo->ref = ''; // 'ref' will auto incremented with '(PROV' + newID + ')'
752 } else {
753 $this->mo->fetch_product();
754 $numref = $this->mo->getNextNumRef($this->mo->product);
755 $this->mo->ref = $numref;
756 }
757 }
758 }
759}
Class for API REST v1.
Definition api.class.php:31
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:86
Class for Mo.
Definition mo.class.php:34
Class MoLine.
produceAndConsume($id, $request_data=null)
Produce and consume.
__construct()
Constructor.
put($id, $request_data=null)
Update MO.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List Mos.
post($request_data=null)
Create MO object.
_cleanObjectDatas($object)
Clean sensible object datas.
checkRefNumbering()
Validate the ref field and get the next Number if it's necessary.
_validate($data)
Validate fields before create or update object.
Class to manage stock movements.
Class to manage products or services.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.