dolibarr  18.0.0
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 
19 use Luracast\Restler\RestException;
20 
21 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
22 
23 
36 class 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  $this->mo->$field = $value;
242  }
243 
244  $this->checkRefNumbering();
245 
246  if ($this->mo->update(DolibarrApiAccess::$user) > 0) {
247  return $this->get($id);
248  } else {
249  throw new RestException(500, $this->mo->error);
250  }
251  }
252 
259  public function delete($id)
260  {
261  if (!DolibarrApiAccess::$user->rights->mrp->delete) {
262  throw new RestException(401);
263  }
264  $result = $this->mo->fetch($id);
265  if (!$result) {
266  throw new RestException(404, 'MO not found');
267  }
268 
269  if (!DolibarrApi::_checkAccessToResource('mrp', $this->mo->id, 'mrp_mo')) {
270  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
271  }
272 
273  if (!$this->mo->delete(DolibarrApiAccess::$user)) {
274  throw new RestException(500, 'Error when deleting MO : '.$this->mo->error);
275  }
276 
277  return array(
278  'success' => array(
279  'code' => 200,
280  'message' => 'MO deleted'
281  )
282  );
283  }
284 
285 
305  public function produceAndConsume($id, $request_data = null)
306  {
307  global $langs;
308 
309  $error = 0;
310 
311  if (!DolibarrApiAccess::$user->rights->mrp->write) {
312  throw new RestException(401, 'Not enough permission');
313  }
314  $result = $this->mo->fetch($id);
315  if (!$result) {
316  throw new RestException(404, 'MO not found');
317  }
318 
319  if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) {
320  throw new RestException(401, 'Error bad status of MO');
321  }
322 
323  $labelmovement = '';
324  $codemovement = '';
325  $autoclose = 1;
326  $arraytoconsume = array();
327  $arraytoproduce = array();
328 
329  foreach ($request_data as $field => $value) {
330  if ($field == 'inventorylabel') {
331  $labelmovement = $value;
332  }
333  if ($field == 'inventorycode') {
334  $codemovement = $value;
335  }
336  if ($field == 'autoclose') {
337  $autoclose = $value;
338  }
339  if ($field == 'arraytoconsume') {
340  $arraytoconsume = $value;
341  }
342  if ($field == 'arraytoproduce') {
343  $arraytoproduce = $value;
344  }
345  }
346 
347  if (empty($labelmovement)) {
348  throw new RestException(500, "Field inventorylabel not provided");
349  }
350  if (empty($codemovement)) {
351  throw new RestException(500, "Field inventorycode not provided");
352  }
353 
354  // Code for consume and produce...
355  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
356  require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
357  dol_include_once('/mrp/lib/mrp_mo.lib.php');
358 
359  $stockmove = new MouvementStock($this->db);
360 
361  $consumptioncomplete = true;
362  $productioncomplete = true;
363 
364  if (!empty($arraytoconsume) && !empty($arraytoproduce)) {
365  $pos = 0;
366  $arrayofarrayname = array("arraytoconsume","arraytoproduce");
367  foreach ($arrayofarrayname as $arrayname) {
368  foreach ($arrayname as $value) {
369  $tmpproduct = new Product($this->db);
370  if (empty($value["objectid"])) {
371  throw new RestException(500, "Field objectid required in ".$arrayname);
372  }
373  $tmpproduct->fetch($value["qty"]);
374  if (empty($value["qty"])) {
375  throw new RestException(500, "Field qty required in ".$arrayname);
376  }
377  if ($value["qty"]!=0) {
378  $qtytoprocess = $value["qty"];
379  if (isset($value["fk_warehouse"])) { // If there is a warehouse to set
380  if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set.
381  $error++;
382  throw new RestException(500, "Field fk_warehouse must be > 0 in ".$arrayname);
383  }
384  if ($tmpproduct->status_batch) {
385  $error++;
386  throw new RestException(500, "Product ".$tmpproduct->ref."must be in batch");
387  }
388  }
389  $idstockmove = 0;
390  if (!$error && $value["fk_warehouse"] > 0) {
391  // Record stock movement
392  $id_product_batch = 0;
393 
394  $stockmove->setOrigin($this->mo->element, $this->mo->id);
395 
396  if ($qtytoprocess >= 0) {
397  $moline = new MoLine($this->db);
398  $moline->fk_mo = $this->mo->id;
399  $moline->position = $pos;
400  $moline->fk_product = $value["objectid"];
401  $moline->fk_warehouse = $value["fk_warehouse"];
402  $moline->qty = $qtytoprocess;
403  $moline->batch = $tmpproduct->status_batch;
404  $moline->role = 'toproduce';
405  $moline->fk_mrp_production = "";
406  $moline->fk_stock_movement = $idstockmove;
407  $moline->fk_user_creat = DolibarrApiAccess::$user->id;
408 
409  $resultmoline = $moline->create(DolibarrApiAccess::$user);
410  if ($resultmoline <= 0) {
411  $error++;
412  throw new RestException(500, $moline->error);
413  }
414  $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
415  } else {
416  $moline = new MoLine($this->db);
417  $moline->fk_mo = $this->mo->id;
418  $moline->position = $pos;
419  $moline->fk_product = $value["objectid"];
420  $moline->fk_warehouse = $value["fk_warehouse"];
421  $moline->qty = $qtytoprocess;
422  $moline->batch = $tmpproduct->status_batch;
423  $moline->role = 'toconsume';
424  $moline->fk_mrp_production = "";
425  $moline->fk_stock_movement = $idstockmove;
426  $moline->fk_user_creat = DolibarrApiAccess::$user->id;
427 
428  $resultmoline = $moline->create(DolibarrApiAccess::$user);
429  if ($resultmoline <= 0) {
430  $error++;
431  throw new RestException(500, $moline->error);
432  }
433  $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
434  }
435  if ($idstockmove < 0) {
436  $error++;
437  throw new RestException(500, $stockmove->error);
438  }
439  }
440  if (!$error) {
441  // Record consumption
442  $moline = new MoLine($this->db);
443  $moline->fk_mo = $this->mo->id;
444  $moline->position = $pos;
445  $moline->fk_product = $value["objectid"];
446  $moline->fk_warehouse = $value["fk_warehouse"];
447  $moline->qty = $qtytoprocess;
448  $moline->batch = $tmpproduct->status_batch;
449  if ($arrayname == "arraytoconsume") {
450  $moline->role = 'consumed';
451  } else {
452  $moline->role = 'produced';
453  }
454  $moline->fk_mrp_production = "";
455  $moline->fk_stock_movement = $idstockmove;
456  $moline->fk_user_creat = DolibarrApiAccess::$user->id;
457 
458  $resultmoline = $moline->create(DolibarrApiAccess::$user);
459  if ($resultmoline <= 0) {
460  $error++;
461  throw new RestException(500, $moline->error);
462  }
463 
464  $pos++;
465  }
466  }
467  }
468  }
469  if (!$error) {
470  if ($autoclose <= 0) {
471  $consumptioncomplete = false;
472  $productioncomplete = false;
473  }
474  }
475  } else {
476  $pos = 0;
477  foreach ($this->mo->lines as $line) {
478  if ($line->role == 'toconsume') {
479  $tmpproduct = new Product($this->db);
480  $tmpproduct->fetch($line->fk_product);
481  if ($line->qty != 0) {
482  $qtytoprocess = $line->qty;
483  if (isset($line->fk_warehouse)) { // If there is a warehouse to set
484  if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
485  $langs->load("errors");
486  $error++;
487  throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref));
488  }
489  if ($tmpproduct->status_batch) {
490  $langs->load("errors");
491  $error++;
492  throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref));
493  }
494  }
495  $idstockmove = 0;
496  if (!$error && $line->fk_warehouse > 0) {
497  // Record stock movement
498  $id_product_batch = 0;
499  $stockmove->origin_type = 'mo';
500  $stockmove->origin_id = $this->mo->id;
501  if ($qtytoprocess >= 0) {
502  $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
503  } else {
504  $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
505  }
506  if ($idstockmove < 0) {
507  $error++;
508  throw new RestException(500, $stockmove->error);
509  }
510  }
511  if (!$error) {
512  // Record consumption
513  $moline = new MoLine($this->db);
514  $moline->fk_mo = $this->mo->id;
515  $moline->position = $pos;
516  $moline->fk_product = $line->fk_product;
517  $moline->fk_warehouse = $line->fk_warehouse;
518  $moline->qty = $qtytoprocess;
519  $moline->batch = $tmpproduct->status_batch;
520  $moline->role = 'consumed';
521  $moline->fk_mrp_production = $line->id;
522  $moline->fk_stock_movement = $idstockmove;
523  $moline->fk_user_creat = DolibarrApiAccess::$user->id;
524 
525  $resultmoline = $moline->create(DolibarrApiAccess::$user);
526  if ($resultmoline <= 0) {
527  $error++;
528  throw new RestException(500, $moline->error);
529  }
530 
531  $pos++;
532  }
533  }
534  }
535  }
536  $pos = 0;
537  foreach ($this->mo->lines as $line) {
538  if ($line->role == 'toproduce') {
539  $tmpproduct = new Product($this->db);
540  $tmpproduct->fetch($line->fk_product);
541  if ($line->qty != 0) {
542  $qtytoprocess = $line->qty;
543  if (isset($line->fk_warehouse)) { // If there is a warehouse to set
544  if (!($line->fk_warehouse > 0)) { // If there is no warehouse set.
545  $langs->load("errors");
546  $error++;
547  throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref));
548  }
549  if ($tmpproduct->status_batch) {
550  $langs->load("errors");
551  $error++;
552  throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref));
553  }
554  }
555  $idstockmove = 0;
556  if (!$error && $line->fk_warehouse > 0) {
557  // Record stock movement
558  $id_product_batch = 0;
559  $stockmove->origin_type = 'mo';
560  $stockmove->origin_id = $this->mo->id;
561  if ($qtytoprocess >= 0) {
562  $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
563  } else {
564  $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
565  }
566  if ($idstockmove < 0) {
567  $error++;
568  throw new RestException(500, $stockmove->error);
569  }
570  }
571  if (!$error) {
572  // Record consumption
573  $moline = new MoLine($this->db);
574  $moline->fk_mo = $this->mo->id;
575  $moline->position = $pos;
576  $moline->fk_product = $line->fk_product;
577  $moline->fk_warehouse = $line->fk_warehouse;
578  $moline->qty = $qtytoprocess;
579  $moline->batch = $tmpproduct->status_batch;
580  $moline->role = 'produced';
581  $moline->fk_mrp_production = $line->id;
582  $moline->fk_stock_movement = $idstockmove;
583  $moline->fk_user_creat = DolibarrApiAccess::$user->id;
584 
585  $resultmoline = $moline->create(DolibarrApiAccess::$user);
586  if ($resultmoline <= 0) {
587  $error++;
588  throw new RestException(500, $moline->error);
589  }
590 
591  $pos++;
592  }
593  }
594  }
595  }
596 
597  if (!$error) {
598  if ($autoclose > 0) {
599  foreach ($this->mo->lines as $line) {
600  if ($line->role == 'toconsume') {
601  $arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id);
602  $alreadyconsumed = 0;
603  foreach ($arrayoflines as $line2) {
604  $alreadyconsumed += $line2['qty'];
605  }
606 
607  if ($alreadyconsumed < $line->qty) {
608  $consumptioncomplete = false;
609  }
610  }
611  if ($line->role == 'toproduce') {
612  $arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id);
613  $alreadyproduced = 0;
614  foreach ($arrayoflines as $line2) {
615  $alreadyproduced += $line2['qty'];
616  }
617 
618  if ($alreadyproduced < $line->qty) {
619  $productioncomplete = false;
620  }
621  }
622  }
623  } else {
624  $consumptioncomplete = false;
625  $productioncomplete = false;
626  }
627  }
628  }
629 
630  // Update status of MO
631  dol_syslog("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
632  //var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
633  if ($consumptioncomplete && $productioncomplete) {
634  $result = $this->mo->setStatut(self::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
635  } else {
636  $result = $this->mo->setStatut(self::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
637  }
638  if ($result <= 0) {
639  throw new RestException(500, $this->mo->error);
640  }
641 
642  return $this->mo->id;
643  }
644 
645 
646  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
653  protected function _cleanObjectDatas($object)
654  {
655  // phpcs:enable
656  $object = parent::_cleanObjectDatas($object);
657 
658  unset($object->rowid);
659  unset($object->canvas);
660 
661  unset($object->name);
662  unset($object->lastname);
663  unset($object->firstname);
664  unset($object->civility_id);
665  unset($object->statut);
666  unset($object->state);
667  unset($object->state_id);
668  unset($object->state_code);
669  unset($object->region);
670  unset($object->region_code);
671  unset($object->country);
672  unset($object->country_id);
673  unset($object->country_code);
674  unset($object->barcode_type);
675  unset($object->barcode_type_code);
676  unset($object->barcode_type_label);
677  unset($object->barcode_type_coder);
678  unset($object->total_ht);
679  unset($object->total_tva);
680  unset($object->total_localtax1);
681  unset($object->total_localtax2);
682  unset($object->total_ttc);
683  unset($object->fk_account);
684  unset($object->comments);
685  unset($object->note);
686  unset($object->mode_reglement_id);
687  unset($object->cond_reglement_id);
688  unset($object->cond_reglement);
689  unset($object->shipping_method_id);
690  unset($object->fk_incoterms);
691  unset($object->label_incoterms);
692  unset($object->location_incoterms);
693 
694  // If object has lines, remove $db property
695  if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
696  $nboflines = count($object->lines);
697  for ($i = 0; $i < $nboflines; $i++) {
698  $this->_cleanObjectDatas($object->lines[$i]);
699 
700  unset($object->lines[$i]->lines);
701  unset($object->lines[$i]->note);
702  }
703  }
704 
705  return $object;
706  }
707 
716  private function _validate($data)
717  {
718  $myobject = array();
719  foreach ($this->mo->fields as $field => $propfield) {
720  if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
721  continue; // Not a mandatory field
722  }
723  if (!isset($data[$field])) {
724  throw new RestException(400, "$field field missing");
725  }
726  $myobject[$field] = $data[$field];
727  }
728  return $myobject;
729  }
730 
736  private function checkRefNumbering(): void
737  {
738  $ref = substr($this->mo->ref, 1, 4);
739  if ($this->mo->status > 0 && $ref == 'PROV') {
740  throw new RestException(400, "Wrong naming scheme '(PROV%)' is only allowed on 'DRAFT' status. For automatic increment use 'auto' on the 'ref' field.");
741  }
742 
743  if (strtolower($this->mo->ref) == 'auto') {
744  if (empty($this->mo->id) && $this->mo->status == 0) {
745  $this->mo->ref = ''; // 'ref' will auto incremented with '(PROV' + newID + ')'
746  } else {
747  $this->mo->fetch_product();
748  $numref = $this->mo->getNextNumRef($this->mo->product);
749  $this->mo->ref = $numref;
750  }
751  }
752  }
753 }
forgeSQLFromUniversalSearchCriteria
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
Definition: functions.lib.php:11933
Mos\index
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List Mos.
Definition: api_mos.class.php:97
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1129
MoLine
Class MoLine.
Definition: mo.class.php:1736
DolibarrApi\_checkAccessToResource
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
Definition: api.class.php:282
Mos\__construct
__construct()
Constructor.
Definition: api_mos.class.php:46
Mo
Class for Mo.
Definition: mo.class.php:33
DolibarrApi
Class for API REST v1.
Definition: api.class.php:30
Mos\post
post($request_data=null)
Create MO object.
Definition: api_mos.class.php:194
Mos\_validate
_validate($data)
Validate fields before create or update object.
Definition: api_mos.class.php:716
Mos
Definition: api_mos.class.php:36
MouvementStock
Class to manage stock movements.
Definition: mouvementstock.class.php:31
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
Mos\_cleanObjectDatas
_cleanObjectDatas($object)
Clean sensible object datas.
Definition: api_mos.class.php:653
Mos\put
put($id, $request_data=null)
Update MO.
Definition: api_mos.class.php:222
$sql
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
Product
Class to manage products or services.
Definition: product.class.php:46
Mos\produceAndConsume
produceAndConsume($id, $request_data=null)
Produce and consume.
Definition: api_mos.class.php:305
Mos\checkRefNumbering
checkRefNumbering()
Validate the ref field and get the next Number if it's necessary.
Definition: api_mos.class.php:736
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056