dolibarr  17.0.4
mouvementstock.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
5  * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
32 {
36  public $element = 'stockmouvement';
37 
41  public $table_element = 'stock_mouvement';
42 
43 
47  public $product_id;
48 
52  public $warehouse_id;
53  public $qty;
54 
63  public $type;
64 
65  public $tms = '';
66  public $datem = '';
67  public $price;
68 
72  public $fk_user_author;
73 
77  public $label;
78 
84  public $fk_origin;
85 
89  public $origin_id;
90 
96  public $origintype;
97 
101  public $origin_type;
102 
103 
104  public $inventorycode;
105  public $batch;
106 
107 
108  public $fields = array(
109  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10, 'showoncombobox'=>1),
110  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15),
111  'datem' =>array('type'=>'datetime', 'label'=>'Datem', 'enabled'=>1, 'visible'=>-1, 'position'=>20),
112  'fk_product' =>array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'Product', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25),
113  'fk_entrepot' =>array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
114  'value' =>array('type'=>'double', 'label'=>'Value', 'enabled'=>1, 'visible'=>-1, 'position'=>35),
115  'price' =>array('type'=>'double(24,8)', 'label'=>'Price', 'enabled'=>1, 'visible'=>-1, 'position'=>40),
116  'type_mouvement' =>array('type'=>'smallint(6)', 'label'=>'Type mouvement', 'enabled'=>1, 'visible'=>-1, 'position'=>45),
117  'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
118  'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
119  'fk_origin' =>array('type'=>'integer', 'label'=>'Fk origin', 'enabled'=>1, 'visible'=>-1, 'position'=>60),
120  'origintype' =>array('type'=>'varchar(32)', 'label'=>'Origintype', 'enabled'=>1, 'visible'=>-1, 'position'=>65),
121  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>70),
122  'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Project', 'enabled'=>'$conf->project->enabled', 'visible'=>-1, 'notnull'=>1, 'position'=>75),
123  'inventorycode' =>array('type'=>'varchar(128)', 'label'=>'InventoryCode', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
124  'batch' =>array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>-1, 'position'=>85),
125  'eatby' =>array('type'=>'date', 'label'=>'Eatby', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
126  'sellby' =>array('type'=>'date', 'label'=>'Sellby', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
127  'fk_project' =>array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Fk project', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
128  );
129 
130 
131 
137  public function __construct($db)
138  {
139  $this->db = $db;
140  }
141 
142  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
169  public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '', $eatby = '', $sellby = '', $batch = '', $skip_batch = false, $id_product_batch = 0, $disablestockchangeforsubproduct = 0, $donotcleanemptylines = 0)
170  {
171  // phpcs:enable
172  global $conf, $langs;
173 
174  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
175  require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
176 
177  $error = 0;
178  dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse_id=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode, datem=".$datem.", eatby=".$eatby.", sellby=".$sellby.", batch=".$batch.", skip_batch=".$skip_batch);
179 
180  // Call hook at beginning
181  global $action, $hookmanager;
182  $hookmanager->initHooks(array('mouvementstock'));
183 
184  if (is_object($hookmanager)) {
185  $parameters = array(
186  'currentcontext' => 'mouvementstock',
187  'user' => &$user,
188  'fk_product' => &$fk_product,
189  'entrepot_id' => &$entrepot_id,
190  'qty' => &$qty,
191  'type' => &$type,
192  'price' => &$price,
193  'label' => &$label,
194  'inventorycode' => &$inventorycode,
195  'datem' => &$datem,
196  'eatby' => &$eatby,
197  'sellby' => &$sellby,
198  'batch' => &$batch,
199  'skip_batch' => &$skip_batch,
200  'id_product_batch' => &$id_product_batch
201  );
202  $reshook = $hookmanager->executeHooks('stockMovementCreate', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
203 
204  if ($reshook < 0) {
205  if (!empty($hookmanager->resPrint)) {
206  dol_print_error('', $hookmanager->resPrint);
207  }
208  return $reshook;
209  } elseif ($reshook > 0) {
210  return $hookmanager->resPrint;
211  }
212  }
213  // end hook at beginning
214 
215  // Clean parameters
216  $price = price2num($price, 'MU'); // Clean value for the casse we receive a float zero value, to have it a real zero value.
217  if (empty($price)) $price = 0;
218  $now = (!empty($datem) ? $datem : dol_now());
219 
220  // Check parameters
221  if (!($fk_product > 0)) return 0;
222  if (!($entrepot_id > 0)) return 0;
223 
224  if (is_numeric($eatby) && $eatby < 0) {
225  dol_syslog(get_class($this)."::_create start ErrorBadValueForParameterEatBy eatby = ".$eatby);
226  $this->errors[] = 'ErrorBadValueForParameterEatBy';
227  return -1;
228  }
229  if (is_numeric($sellby) && $sellby < 0) {
230  dol_syslog(get_class($this)."::_create start ErrorBadValueForParameterSellBy sellby = ".$sellby);
231  $this->errors[] = 'ErrorBadValueForParameterSellBy';
232  return -1;
233  }
234 
235  // Set properties of movement
236  $this->product_id = $fk_product;
237  $this->entrepot_id = $entrepot_id; // deprecated
238  $this->warehouse_id = $entrepot_id;
239  $this->qty = $qty;
240  $this->type = $type;
241  $this->price = price2num($price);
242  $this->label = $label;
243  $this->inventorycode = $inventorycode;
244  $this->datem = $now;
245  $this->batch = $batch;
246 
247  $mvid = 0;
248 
249  $product = new Product($this->db);
250 
251  $result = $product->fetch($fk_product);
252  if ($result < 0) {
253  $this->error = $product->error;
254  $this->errors = $product->errors;
255  dol_print_error('', "Failed to fetch product");
256  return -1;
257  }
258  if ($product->id <= 0) { // Can happen if database is corrupted (a product id exist in stock with product that has been removed)
259  return 0;
260  }
261 
262  // Define if we must make the stock change (If product type is a service or if stock is used also for services)
263  // Only record into stock tables wil be disabled by this (the rest like writing into lot table or movement of subproucts are done)
264  $movestock = 0;
265  if ($product->type != Product::TYPE_SERVICE || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock = 1;
266 
267  $this->db->begin();
268 
269  // Set value $product->stock_reel and detail per warehouse into $product->stock_warehouse array
270  if ($movestock) {
271  $product->load_stock('novirtual');
272  }
273 
274  // Test if product require batch data. If yes, and there is not or values are not correct, we throw an error.
275  if (isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
276  if (empty($batch)) {
277  $langs->load("errors");
278  $this->errors[] = $langs->transnoentitiesnoconv("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
279  dol_syslog("Try to make a movement of a product with status_batch on without any batch data");
280 
281  $this->db->rollback();
282  return -2;
283  }
284 
285  // Check table llx_product_lot from batchnumber for same product
286  // If found and eatby/sellby defined into table and provided and differs, return error
287  // If found and eatby/sellby defined into table and not provided, we take value from table
288  // If found and eatby/sellby not defined into table and provided, we update table
289  // If found and eatby/sellby not defined into table and not provided, we do nothing
290  // If not found, we add record
291  $sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix()."product_lot as pb";
292  $sql .= " WHERE pb.fk_product = ".((int) $fk_product)." AND pb.batch = '".$this->db->escape($batch)."'";
293  dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
294  $resql = $this->db->query($sql);
295  if ($resql) {
296  $num = $this->db->num_rows($resql);
297  $i = 0;
298  if ($num > 0) {
299  while ($i < $num) {
300  $obj = $this->db->fetch_object($resql);
301  if ($obj->eatby) {
302  if ($eatby) {
303  $tmparray = dol_getdate($eatby, true);
304  $eatbywithouthour = dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year']);
305  if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) { // We test date without hours and with hours for backward compatibility
306  // If found and eatby/sellby defined into table and provided and differs, return error
307  $langs->load("stocks");
308  $this->errors[] = $langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->eatby), 'dayhour'), dol_print_date($eatbywithouthour, 'dayhour'));
309  dol_syslog("ThisSerialAlreadyExistWithDifferentDate batch=".$batch.", eatby found into product_lot = ".$obj->eatby." = ".dol_print_date($this->db->jdate($obj->eatby), 'dayhourrfc')." so eatbywithouthour = ".$eatbywithouthour." = ".dol_print_date($eatbywithouthour)." - eatby provided = ".$eatby." = ".dol_print_date($eatby, 'dayhourrfc'), LOG_ERR);
310  $this->db->rollback();
311  return -3;
312  }
313  } else {
314  $eatby = $obj->eatby; // If found and eatby/sellby defined into table and not provided, we take value from table
315  }
316  } else {
317  if ($eatby) { // If found and eatby/sellby not defined into table and provided, we update table
318  $productlot = new Productlot($this->db);
319  $result = $productlot->fetch($obj->rowid);
320  $productlot->eatby = $eatby;
321  $result = $productlot->update($user);
322  if ($result <= 0) {
323  $this->error = $productlot->error;
324  $this->errors = $productlot->errors;
325  $this->db->rollback();
326  return -5;
327  }
328  }
329  }
330  if ($obj->sellby) {
331  if ($sellby) {
332  $tmparray = dol_getdate($sellby, true);
333  $sellbywithouthour = dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year']);
334  if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) { // We test date without hours and with hours for backward compatibility
335  // If found and eatby/sellby defined into table and provided and differs, return error
336  $this->errors[] = $langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby));
337  dol_syslog($langs->transnoentities("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby)), LOG_ERR);
338  $this->db->rollback();
339  return -3;
340  }
341  } else {
342  $sellby = $obj->sellby; // If found and eatby/sellby defined into table and not provided, we take value from table
343  }
344  } else {
345  if ($sellby) { // If found and eatby/sellby not defined into table and provided, we update table
346  $productlot = new Productlot($this->db);
347  $result = $productlot->fetch($obj->rowid);
348  $productlot->sellby = $sellby;
349  $result = $productlot->update($user);
350  if ($result <= 0) {
351  $this->error = $productlot->error;
352  $this->errors = $productlot->errors;
353  $this->db->rollback();
354  return -5;
355  }
356  }
357  }
358 
359  $i++;
360  }
361  } else { // If not found, we add record
362  $productlot = new Productlot($this->db);
363  $productlot->entity = $conf->entity;
364  $productlot->fk_product = $fk_product;
365  $productlot->batch = $batch;
366  // If we are here = first time we manage this batch, so we used dates provided by users to create lot
367  $productlot->eatby = $eatby;
368  $productlot->sellby = $sellby;
369  $result = $productlot->create($user);
370  if ($result <= 0) {
371  $this->error = $productlot->error;
372  $this->errors = $productlot->errors;
373  $this->db->rollback();
374  return -4;
375  }
376  }
377  } else {
378  dol_print_error($this->db);
379  $this->db->rollback();
380  return -1;
381  }
382  }
383 
384  // Check if stock is enough when qty is < 0
385  // Note that qty should be > 0 with type 0 or 3, < 0 with type 1 or 2.
386  if ($movestock && $qty < 0 && empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {
387  if (isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
388  $foundforbatch = 0;
389  $qtyisnotenough = 0;
390 
391  foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
392  if ((string) $batch != (string) $batchcursor) { // Lot '59' must be different than lot '59c'
393  continue;
394  }
395 
396  $foundforbatch = 1;
397  if ($prodbatch->qty < abs($qty)) $qtyisnotenough = $prodbatch->qty;
398  break;
399  }
400  if (!$foundforbatch || $qtyisnotenough) {
401  $langs->load("stocks");
402  include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
403  $tmpwarehouse = new Entrepot($this->db);
404  $tmpwarehouse->fetch($entrepot_id);
405 
406  $this->error = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
407  $this->errors[] = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
408  $this->db->rollback();
409  return -8;
410  }
411  } else {
412  if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) {
413  $langs->load("stocks");
414  $this->error = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref;
415  $this->errors[] = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref;
416  $this->db->rollback();
417  return -8;
418  }
419  }
420  }
421 
422  if ($movestock) { // Change stock for current product, change for subproduct is done after
423  // Set $origin_type, origin_id and fk_project
424  $fk_project = $this->fk_project;
425  if (!empty($this->origin_type)) { // This is set by caller for tracking reason
426  $origin_type = $this->origin_type;
427  $origin_id = $this->origin_id;
428  if (empty($fk_project) && $origin_type == 'project') {
429  $fk_project = $origin_id;
430  $origin_type = '';
431  $origin_id = 0;
432  }
433  } else {
434  $fk_project = 0;
435  $origin_type = '';
436  $origin_id = 0;
437  }
438 
439  $sql = "INSERT INTO ".$this->db->prefix()."stock_mouvement(";
440  $sql .= " datem, fk_product, batch, eatby, sellby,";
441  $sql .= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet";
442  $sql .= ")";
443  $sql .= " VALUES ('".$this->db->idate($this->datem)."', ".((int) $this->product_id).", ";
444  $sql .= " ".($batch ? "'".$this->db->escape($batch)."'" : "null").", ";
445  $sql .= " ".($eatby ? "'".$this->db->idate($eatby)."'" : "null").", ";
446  $sql .= " ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", ";
447  $sql .= " ".((int) $this->entrepot_id).", ".((float) $this->qty).", ".((int) $this->type).",";
448  $sql .= " ".((int) $user->id).",";
449  $sql .= " '".$this->db->escape($label)."',";
450  $sql .= " ".($inventorycode ? "'".$this->db->escape($inventorycode)."'" : "null").",";
451  $sql .= " ".((float) price2num($price)).",";
452  $sql .= " ".((int) $origin_id).",";
453  $sql .= " '".$this->db->escape($origin_type)."',";
454  $sql .= " ".((int) $fk_project);
455  $sql .= ")";
456 
457  dol_syslog(get_class($this)."::_create insert record into stock_mouvement", LOG_DEBUG);
458  $resql = $this->db->query($sql);
459 
460  if ($resql) {
461  $mvid = $this->db->last_insert_id($this->db->prefix()."stock_mouvement");
462  $this->id = $mvid;
463  } else {
464  $this->error = $this->db->lasterror();
465  $this->errors[] = $this->error;
466  $error = -1;
467  }
468 
469  // Define current values for qty and pmp
470  $oldqty = $product->stock_reel;
471  $oldpmp = $product->pmp;
472  $oldqtywarehouse = 0;
473 
474  // Test if there is already a record for couple (warehouse / product), so later we will make an update or create.
475  $alreadyarecord = 0;
476  if (!$error) {
477  $sql = "SELECT rowid, reel FROM ".$this->db->prefix()."product_stock";
478  $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); // This is a unique key
479 
480  dol_syslog(get_class($this)."::_create check if a record already exists in product_stock", LOG_DEBUG);
481  $resql = $this->db->query($sql);
482  if ($resql) {
483  $obj = $this->db->fetch_object($resql);
484  if ($obj) {
485  $alreadyarecord = 1;
486  $oldqtywarehouse = $obj->reel;
487  $fk_product_stock = $obj->rowid;
488  }
489  $this->db->free($resql);
490  } else {
491  $this->errors[] = $this->db->lasterror();
492  $error = -2;
493  }
494  }
495 
496  // Calculate new AWP (PMP)
497  $newpmp = 0;
498  if (!$error) {
499  if ($type == 0 || $type == 3) {
500  // After a stock increase
501  // Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0.
502  // Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input)
503  if ($price > 0 || (!empty($conf->global->STOCK_UPDATE_AWP_EVEN_WHEN_ENTRY_PRICE_IS_NULL) && $price == 0)) {
504  $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
505  // We make a test on oldpmp>0 to avoid to use normal rule on old data with no pmp field defined
506  if ($oldpmp > 0) {
507  $newpmp = price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty), 'MU');
508  } else {
509  $newpmp = $price; // For this product, PMP was not yet set. We set it to input price.
510  }
511  //print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." ";
512  //print "qty=".$qty." newpmp=".$newpmp;
513  //exit;
514  } else {
515  $newpmp = $oldpmp;
516  }
517  } elseif ($type == 1 || $type == 2) {
518  // After a stock decrease, we don't change value of the AWP/PMP of a product.
519  $newpmp = $oldpmp;
520  } else {
521  // Type of movement unknown
522  $newpmp = $oldpmp;
523  }
524  }
525  // Update stock quantity
526  if (!$error) {
527  if ($alreadyarecord > 0) {
528  $sql = "UPDATE ".$this->db->prefix()."product_stock SET reel = reel + ".((float) $qty);
529  $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product);
530  } else {
531  $sql = "INSERT INTO ".$this->db->prefix()."product_stock";
532  $sql .= " (reel, fk_entrepot, fk_product) VALUES ";
533  $sql .= " (".((float) $qty).", ".((int) $entrepot_id).", ".((int) $fk_product).")";
534  }
535 
536  dol_syslog(get_class($this)."::_create update stock value", LOG_DEBUG);
537  $resql = $this->db->query($sql);
538  if (!$resql) {
539  $this->errors[] = $this->db->lasterror();
540  $error = -3;
541  } elseif (empty($fk_product_stock)) {
542  $fk_product_stock = $this->db->last_insert_id($this->db->prefix()."product_stock");
543  }
544  }
545 
546  // Update detail of stock for the lot.
547  if (!$error && isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
548  if ($id_product_batch > 0) {
549  $result = $this->createBatch($id_product_batch, $qty);
550  } else {
551  $param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
552  $result = $this->createBatch($param_batch, $qty);
553  }
554  if ($result < 0) {
555  $error++;
556  }
557  }
558 
559  // Update PMP and denormalized value of stock qty at product level
560  if (!$error) {
561  $newpmp = price2num($newpmp, 'MU');
562 
563  // $sql = "UPDATE ".$this->db->prefix()."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty;
564  // $sql.= " WHERE rowid = ".((int) $fk_product);
565  // Update pmp + denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
566  $sql = "UPDATE ".$this->db->prefix()."product as p SET pmp = ".((float) $newpmp).",";
567  $sql .= " stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)";
568  $sql .= " WHERE rowid = ".((int) $fk_product);
569 
570  dol_syslog(get_class($this)."::_create update AWP", LOG_DEBUG);
571  $resql = $this->db->query($sql);
572  if (!$resql) {
573  $this->errors[] = $this->db->lasterror();
574  $error = -4;
575  }
576  }
577 
578  if (empty($donotcleanemptylines)) {
579  // If stock is now 0, we can remove entry into llx_product_stock, but only if there is no child lines into llx_product_batch (detail of batch, because we can imagine
580  // having a lot1/qty=X and lot2/qty=-X, so 0 but we must not loose repartition of different lot.
581  $sql = "DELETE FROM ".$this->db->prefix()."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix()."product_batch as pb)";
582  $resql = $this->db->query($sql);
583  // We do not test error, it can fails if there is child in batch details
584  }
585  }
586 
587  // Add movement for sub products (recursive call)
588  if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) {
589  $error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem); // we use 0 as price, because AWP must not change for subproduct
590  }
591 
592  if ($movestock && !$error) {
593  // Call trigger
594  $result = $this->call_trigger('STOCK_MOVEMENT', $user);
595  if ($result < 0) $error++;
596  // End call triggers
597 
598  // Check unicity for serial numbered equipments once all movement were done.
599  if (!$error && isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
600  if ($product->status_batch == 2 && $qty > 0) { // We check only if we increased qty
601  if ($this->getBatchCount($fk_product, $batch) > 1) {
602  $error++;
603  $this->errors[] = $langs->trans("TooManyQtyForSerialNumber", $product->ref, $batch);
604  }
605  }
606  }
607  }
608 
609  if (!$error) {
610  $this->db->commit();
611  return $mvid;
612  } else {
613  $this->db->rollback();
614  dol_syslog(get_class($this)."::_create error code=".$error, LOG_ERR);
615  return -6;
616  }
617  }
618 
619 
620 
628  public function fetch($id)
629  {
630  dol_syslog(__METHOD__, LOG_DEBUG);
631 
632  $sql = "SELECT";
633  $sql .= " t.rowid,";
634  $sql .= " t.tms,";
635  $sql .= " t.datem,";
636  $sql .= " t.fk_product,";
637  $sql .= " t.fk_entrepot,";
638  $sql .= " t.value,";
639  $sql .= " t.price,";
640  $sql .= " t.type_mouvement,";
641  $sql .= " t.fk_user_author,";
642  $sql .= " t.label,";
643  $sql .= " t.fk_origin as origin_id,";
644  $sql .= " t.origintype as origin_type,";
645  $sql .= " t.inventorycode,";
646  $sql .= " t.batch,";
647  $sql .= " t.eatby,";
648  $sql .= " t.sellby,";
649  $sql .= " t.fk_projet as fk_project";
650  $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
651  $sql .= " WHERE t.rowid = ".((int) $id);
652 
653  $resql = $this->db->query($sql);
654  if ($resql) {
655  $numrows = $this->db->num_rows($resql);
656  if ($numrows) {
657  $obj = $this->db->fetch_object($resql);
658 
659  $this->id = $obj->rowid;
660 
661  $this->product_id = $obj->fk_product;
662  $this->warehouse_id = $obj->fk_entrepot;
663  $this->qty = $obj->value;
664  $this->type = $obj->type_mouvement;
665 
666  $this->tms = $this->db->jdate($obj->tms);
667  $this->datem = $this->db->jdate($obj->datem);
668  $this->price = $obj->price;
669  $this->fk_user_author = $obj->fk_user_author;
670  $this->label = $obj->label;
671  $this->fk_origin = $obj->origin_id; // For backward compatibility
672  $this->origintype = $obj->origin_type; // For backward compatibility
673  $this->origin_id = $obj->origin_id;
674  $this->origin_type = $obj->origin_type;
675  $this->inventorycode = $obj->inventorycode;
676  $this->batch = $obj->batch;
677  $this->eatby = $this->db->jdate($obj->eatby);
678  $this->sellby = $this->db->jdate($obj->sellby);
679  $this->fk_project = $obj->fk_project;
680  }
681 
682  // Retrieve all extrafield
683  $this->fetch_optionals();
684 
685  // $this->fetch_lines();
686 
687  $this->db->free($resql);
688 
689  if ($numrows) {
690  return 1;
691  } else {
692  return 0;
693  }
694  } else {
695  $this->errors[] = 'Error '.$this->db->lasterror();
696  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
697 
698  return -1;
699  }
700  }
701 
702 
703 
704 
719  private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '')
720  {
721  global $langs;
722 
723  $error = 0;
724  $pids = array();
725  $pqtys = array();
726 
727  $sql = "SELECT fk_product_pere, fk_product_fils, qty";
728  $sql .= " FROM ".$this->db->prefix()."product_association";
729  $sql .= " WHERE fk_product_pere = ".((int) $idProduct);
730  $sql .= " AND incdec = 1";
731 
732  dol_syslog(get_class($this)."::_createSubProduct for parent product ".$idProduct, LOG_DEBUG);
733  $resql = $this->db->query($sql);
734  if ($resql) {
735  $i = 0;
736  while ($obj = $this->db->fetch_object($resql)) {
737  $pids[$i] = $obj->fk_product_fils;
738  $pqtys[$i] = $obj->qty;
739  $i++;
740  }
741  $this->db->free($resql);
742  } else {
743  $error = -2;
744  }
745 
746  // Create movement for each subproduct
747  foreach ($pids as $key => $value) {
748  if (!$error) {
749  $tmpmove = dol_clone($this, 1);
750 
751  $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode, $datem); // This will also call _createSubProduct making this recursive
752  if ($result < 0) {
753  $this->error = $tmpmove->error;
754  $this->errors = array_merge($this->errors, $tmpmove->errors);
755  if ($result == -2) {
756  $this->errors[] = $langs->trans("ErrorNoteAlsoThatSubProductCantBeFollowedByLot");
757  }
758  $error = $result;
759  }
760  unset($tmpmove);
761  }
762  }
763 
764  return $error;
765  }
766 
767 
786  public function livraison($user, $fk_product, $entrepot_id, $qty, $price = 0, $label = '', $datem = '', $eatby = '', $sellby = '', $batch = '', $id_product_batch = 0, $inventorycode = '', $donotcleanemptylines = 0)
787  {
788  global $conf;
789 
790  $skip_batch = empty($conf->productbatch->enabled);
791 
792  return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
793  }
794 
813  public function reception($user, $fk_product, $entrepot_id, $qty, $price = 0, $label = '', $eatby = '', $sellby = '', $batch = '', $datem = '', $id_product_batch = 0, $inventorycode = '', $donotcleanemptylines = 0)
814  {
815  global $conf;
816 
817  $skip_batch = empty($conf->productbatch->enabled);
818 
819  return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
820  }
821 
829  public function calculateBalanceForProductBefore($productidselected, $datebefore)
830  {
831  $nb = 0;
832 
833  $sql = "SELECT SUM(value) as nb from ".$this->db->prefix()."stock_mouvement";
834  $sql .= " WHERE fk_product = ".((int) $productidselected);
835  $sql .= " AND datem < '".$this->db->idate($datebefore)."'";
836 
837  dol_syslog(get_class($this).__METHOD__.'', LOG_DEBUG);
838  $resql = $this->db->query($sql);
839  if ($resql) {
840  $obj = $this->db->fetch_object($resql);
841  if ($obj) $nb = $obj->nb;
842  return (empty($nb) ? 0 : $nb);
843  } else {
844  dol_print_error($this->db);
845  return -1;
846  }
847  }
848 
858  private function createBatch($dluo, $qty)
859  {
860  global $user, $langs;
861 
862  $langs->load('productbatch');
863 
864  $pdluo = new Productbatch($this->db);
865 
866  $result = 0;
867 
868  // Try to find an existing record with same batch number or id
869  if (is_numeric($dluo)) {
870  $result = $pdluo->fetch($dluo);
871  if (empty($pdluo->id)) {
872  // We didn't find the line. May be it was deleted before by a previous move in same transaction.
873  $this->error = $langs->trans('CantMoveNonExistantSerial');
874  $this->errors[] = $this->error;
875  $result = -2;
876  }
877  } elseif (is_array($dluo)) {
878  if (isset($dluo['fk_product_stock'])) {
879  $vfk_product_stock = $dluo['fk_product_stock'];
880  $vbatchnumber = $dluo['batchnumber'];
881 
882  $result = $pdluo->find($vfk_product_stock, '', '', $vbatchnumber); // Search on batch number only (eatby and sellby are deprecated here)
883  } else {
884  dol_syslog(get_class($this)."::createBatch array param dluo must contain at least key fk_product_stock", LOG_ERR);
885  $result = -1;
886  }
887  } else {
888  dol_syslog(get_class($this)."::createBatch error invalid param dluo", LOG_ERR);
889  $result = -1;
890  }
891 
892  if ($result >= 0) {
893  // No error
894  if ($pdluo->id > 0) { // product_batch record found
895  //print "Avant ".$pdluo->qty." Apres ".($pdluo->qty + $qty)."<br>";
896  $pdluo->qty += $qty;
897  if ($pdluo->qty == 0) {
898  $result = $pdluo->delete($user, 1);
899  } else {
900  $result = $pdluo->update($user, 1);
901  }
902  } else { // product_batch record not found
903  $pdluo->fk_product_stock = $vfk_product_stock;
904  $pdluo->qty = $qty;
905  $pdluo->eatby = empty($dluo['eatby']) ? '' : $dluo['eatby']; // No more used. Now eatby date is store in table of lot, no more into prouct_batch table.
906  $pdluo->sellby = empty($dluo['sellby']) ? '' : $dluo['sellby']; // No more used. Now sellby date is store in table of lot, no more into prouct_batch table.
907  $pdluo->batch = $vbatchnumber;
908 
909  $result = $pdluo->create($user, 1);
910  if ($result < 0) {
911  $this->error = $pdluo->error;
912  $this->errors = $pdluo->errors;
913  }
914  }
915  }
916 
917  return $result;
918  }
919 
920  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
928  public function get_origin($origin_id, $origin_type)
929  {
930  // phpcs:enable
931  $origin = '';
932 
933  switch ($origin_type) {
934  case 'commande':
935  require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
936  $origin = new Commande($this->db);
937  break;
938  case 'shipping':
939  require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
940  $origin = new Expedition($this->db);
941  break;
942  case 'facture':
943  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
944  $origin = new Facture($this->db);
945  break;
946  case 'order_supplier':
947  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
948  $origin = new CommandeFournisseur($this->db);
949  break;
950  case 'invoice_supplier':
951  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
952  $origin = new FactureFournisseur($this->db);
953  break;
954  case 'project':
955  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
956  $origin = new Project($this->db);
957  break;
958  case 'mo':
959  require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
960  $origin = new Mo($this->db);
961  break;
962  case 'user':
963  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
964  $origin = new User($this->db);
965  break;
966  case 'reception':
967  require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
968  $origin = new Reception($this->db);
969  break;
970  case 'inventory':
971  require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
972  $origin = new Inventory($this->db);
973  break;
974  default:
975  if ($origin_type) {
976  // Separate originetype with "@" : left part is class name, right part is module name
977  $origin_type_array = explode('@', $origin_type);
978  $classname = $origin_type_array[0];
979  $modulename = empty($origin_type_array[1]) ? strtolower($classname) : $origin_type_array[1];
980 
981  $result = dol_include_once('/'.$modulename.'/class/'.$classname.'.class.php');
982 
983  if ($result) {
984  $classname = ucfirst($classname);
985  $origin = new $classname($this->db);
986  }
987  }
988  break;
989  }
990 
991  if (empty($origin) || !is_object($origin)) {
992  return '';
993  }
994 
995  if ($origin->fetch($origin_id) > 0) {
996  return $origin->getNomUrl(1);
997  }
998 
999  return '';
1000  }
1001 
1010  public function setOrigin($origin_element, $origin_id)
1011  {
1012  $this->origin_type = $origin_element;
1013  $this->origin_id = $origin_id;
1014  // For backward compatibility
1015  $this->origintype = $origin_element;
1016  $this->fk_origin = $origin_id;
1017  }
1018 
1019 
1027  public function initAsSpecimen()
1028  {
1029  global $user, $langs, $conf, $mysoc;
1030 
1031  // Initialize parameters
1032  $this->id = 0;
1033 
1034  // There is no specific properties. All data into insert are provided as method parameter.
1035  }
1036 
1043  public function getTypeMovement($withlabel = 0)
1044  {
1045  global $langs;
1046 
1047  $s = '';
1048  switch ($this->type) {
1049  case "0":
1050  $s = '<span class="fa fa-level-down-alt stockmovemententry stockmovementtransfer" title="'.$langs->trans('StockIncreaseAfterCorrectTransfer').'"></span>';
1051  if ($withlabel) {
1052  $s .= $langs->trans('StockIncreaseAfterCorrectTransfer');
1053  }
1054  break;
1055  case "1":
1056  $s = '<span class="fa fa-level-up-alt stockmovementexit stockmovementtransfer" title="'.$langs->trans('StockDecreaseAfterCorrectTransfer').'"></span>';
1057  if ($withlabel) {
1058  $s .= $langs->trans('StockDecreaseAfterCorrectTransfer');
1059  }
1060  break;
1061  case "2":
1062  $s = '<span class="fa fa-long-arrow-alt-up stockmovementexit stockmovement" title="'.$langs->trans('StockDecrease').'"></span>';
1063  if ($withlabel) {
1064  $s .= $langs->trans('StockDecrease');
1065  }
1066  break;
1067  case "3":
1068  $s = '<span class="fa fa-long-arrow-alt-down stockmovemententry stockmovement" title="'.$langs->trans('StockIncrease').'"></span>';
1069  if ($withlabel) {
1070  $s .= $langs->trans('StockIncrease');
1071  }
1072  break;
1073  }
1074 
1075  return $s;
1076  }
1077 
1089  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
1090  {
1091  global $langs, $conf, $db;
1092 
1093  $result = '';
1094 
1095  $label = img_picto('', 'stock', 'class="pictofixedwidth"').'<u>'.$langs->trans("Movement").' '.$this->id.'</u>';
1096  $label .= '<div width="100%">';
1097  $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
1098  $label .= '<br><b>'.$langs->trans('Qty').':</b> '.($this->qty > 0 ? '+' : '').$this->qty;
1099  if ($this->batch) {
1100  $label .= '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1101  }
1102  /* TODO Get also warehouse label in a property instead of id
1103  if ($this->warehouse_id > 0) {
1104  $label .= '<br><b>'.$langs->trans('Warehouse').':</b> '.$this->warehouse_id;
1105  }*/
1106  $label .= '</div>';
1107 
1108  // Link to page of warehouse tab
1109  if ($option == 'movements') {
1110  $url = DOL_URL_ROOT.'/product/stock/movement_list.php?search_ref='.$this->id;
1111  } else {
1112  $url = DOL_URL_ROOT.'/product/stock/movement_list.php?id='.$this->warehouse_id.'&msid='.$this->id;
1113  }
1114 
1115  $link = '<a href="'.$url.'"'.($notooltip ? '' : ' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip'.($morecss ? ' '.$morecss : '').'"');
1116  $link .= '>';
1117  $linkend = '</a>';
1118 
1119  if ($withpicto) {
1120  $result .= ($link.img_object(($notooltip ? '' : $label), 'stock', ($notooltip ? '' : 'class="classfortooltip"')).$linkend);
1121  if ($withpicto != 2) {
1122  $result .= ' ';
1123  }
1124  }
1125  $result .= $link.$this->id.$linkend;
1126  return $result;
1127  }
1128 
1135  public function getLibStatut($mode = 0)
1136  {
1137  return $this->LibStatut($mode);
1138  }
1139 
1140  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1147  public function LibStatut($mode = 0)
1148  {
1149  // phpcs:enable
1150  global $langs;
1151 
1152  if ($mode == 0 || $mode == 1) {
1153  return $langs->trans('StatusNotApplicable');
1154  } elseif ($mode == 2) {
1155  return img_picto($langs->trans('StatusNotApplicable'), 'statut9').' '.$langs->trans('StatusNotApplicable');
1156  } elseif ($mode == 3) {
1157  return img_picto($langs->trans('StatusNotApplicable'), 'statut9');
1158  } elseif ($mode == 4) {
1159  return img_picto($langs->trans('StatusNotApplicable'), 'statut9').' '.$langs->trans('StatusNotApplicable');
1160  } elseif ($mode == 5) {
1161  return $langs->trans('StatusNotApplicable').' '.img_picto($langs->trans('StatusNotApplicable'), 'statut9');
1162  }
1163  }
1164 
1175  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1176  {
1177  global $conf, $user, $langs;
1178 
1179  $langs->load("stocks");
1180  $outputlangs->load("products");
1181 
1182  if (!dol_strlen($modele)) {
1183  $modele = 'stdmovement';
1184 
1185  if ($this->model_pdf) {
1186  $modele = $this->model_pdf;
1187  } elseif (!empty($conf->global->MOUVEMENT_ADDON_PDF)) {
1188  $modele = $conf->global->MOUVEMENT_ADDON_PDF;
1189  }
1190  }
1191 
1192  $modelpath = "core/modules/stock/doc/";
1193 
1194  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1195  }
1196 
1204  public function delete(User $user, $notrigger = false)
1205  {
1206  return $this->deleteCommon($user, $notrigger);
1207  //return $this->deleteCommon($user, $notrigger, 1);
1208  }
1209 
1217  private function getBatchCount($fk_product, $batch)
1218  {
1219  $cpt = 0;
1220 
1221  $sql = "SELECT sum(pb.qty) as cpt";
1222  $sql .= " FROM ".$this->db->prefix()."product_batch as pb";
1223  $sql .= " INNER JOIN ".$this->db->prefix()."product_stock as ps ON ps.rowid = pb.fk_product_stock";
1224  $sql .= " WHERE ps.fk_product = " . ((int) $fk_product);
1225  $sql .= " AND pb.batch = '" . $this->db->escape($batch) . "'";
1226 
1227  $result = $this->db->query($sql);
1228  if ($result) {
1229  if ($this->db->num_rows($result)) {
1230  $obj = $this->db->fetch_object($result);
1231  $cpt = $obj->cpt;
1232  }
1233 
1234  $this->db->free($result);
1235  } else {
1236  dol_print_error($this->db);
1237  return -1;
1238  }
1239 
1240  return $cpt;
1241  }
1242 }
Class to manage predefined suppliers products.
Class to manage customers orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage warehouses.
Class to manage shipments.
Class to manage suppliers invoices.
Class to manage invoices.
Class for Inventory.
Class for Mo.
Definition: mo.class.php:36
Class to manage stock movements.
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link (with optionaly the picto) Use this->id,this->lastname, this->firstname.
LibStatut($mode=0)
Renvoi le libelle d'un status donne.
createBatch($dluo, $qty)
Create or update batch record (update table llx_product_batch).
getBatchCount($fk_product, $batch)
Retrieve number of equipments for a product lot/serial.
get_origin($origin_id, $origin_type)
Return Url link of origin object.
livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='', $eatby='', $sellby='', $batch='', $id_product_batch=0, $inventorycode='', $donotcleanemptylines=0)
Decrease stock for product and subproducts.
fetch($id)
Load object in memory from the database.
reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $eatby='', $sellby='', $batch='', $datem='', $id_product_batch=0, $inventorycode='', $donotcleanemptylines=0)
Increase stock for product and subproducts.
_createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='')
Create movement in database for all subproducts.
_create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='', $eatby='', $sellby='', $batch='', $skip_batch=false, $id_product_batch=0, $disablestockchangeforsubproduct=0, $donotcleanemptylines=0)
Add a movement of stock (in one direction only).
initAsSpecimen()
Initialise an instance with random values.
getTypeMovement($withlabel=0)
Return html string with picto for type of movement.
setOrigin($origin_element, $origin_id)
Set attribute origin_type and fk_origin to object.
calculateBalanceForProductBefore($productidselected, $datebefore)
Count number of product in stock before a specific date.
getLibStatut($mode=0)
Return label statut.
Class to manage products or services.
const TYPE_SERVICE
Service.
Manage record for batch number management.
Class with list of lots and properties.
Class to manage projects.
Class to manage receptions.
Class to manage Dolibarr users.
Definition: user.class.php:47
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.
Definition: index.php:745
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
div float
Buy price without taxes.
Definition: style.css.php:913
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db
API class for accounts.
Definition: inc.php:41