24 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
43 public $cache_warehouses = array();
44 public $cache_lot = array();
45 public $cache_workstations = array();
76 public function loadWarehouses($fk_product = 0, $batch =
'', $status =
'', $sumStock =
true, $exclude = array(), $stockMin =
false, $orderBy =
'e.ref')
80 if (empty($fk_product) && count($this->cache_warehouses)) {
84 $warehouseStatus = array();
86 if (preg_match(
'/warehouseclosed/', $status)) {
89 if (preg_match(
'/warehouseopen/', $status)) {
92 if (preg_match(
'/warehouseinternal/', $status)) {
96 $sql =
"SELECT e.rowid, e.ref as label, e.description, e.fk_parent";
97 if (!empty($fk_product) && $fk_product > 0) {
99 $sql .=
", pb.qty as stock";
101 $sql .=
", ps.reel as stock";
103 } elseif ($sumStock) {
104 $sql .=
", sum(ps.reel) as stock";
106 $sql .=
" FROM ".$this->db->prefix().
"entrepot as e";
107 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_stock as ps on ps.fk_entrepot = e.rowid";
108 if (!empty($fk_product) && $fk_product > 0) {
109 $sql .=
" AND ps.fk_product = ".((int) $fk_product);
110 if (!empty($batch)) {
111 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->
db->escape($batch).
"'";
114 $sql .=
" WHERE e.entity IN (".getEntity(
'stock').
")";
115 if (count($warehouseStatus)) {
116 $sql .=
" AND e.statut IN (".$this->db->sanitize(implode(
',', $warehouseStatus)).
")";
118 $sql .=
" AND e.statut = 1";
121 if (is_array($exclude) && !empty($exclude)) {
122 $sql .=
' AND e.rowid NOT IN('.$this->db->sanitize(implode(
',', $exclude)).
')';
126 if ($stockMin !==
false) {
127 if (!empty($fk_product) && $fk_product > 0) {
128 if (!empty($batch)) {
129 $sql .=
" AND pb.qty > ".((float) $stockMin);
131 $sql .=
" AND ps.reel > ".((float) $stockMin);
136 if ($sumStock && empty($fk_product)) {
137 $sql .=
" GROUP BY e.rowid, e.ref, e.description, e.fk_parent";
140 if ($stockMin !==
false) {
141 $sql .=
" HAVING sum(ps.reel) > ".((float) $stockMin);
144 $sql .=
" ORDER BY ".$orderBy;
146 dol_syslog(get_class($this).
'::loadWarehouses', LOG_DEBUG);
152 $obj = $this->
db->fetch_object(
$resql);
156 $this->cache_warehouses[$obj->rowid][
'id'] = $obj->rowid;
157 $this->cache_warehouses[$obj->rowid][
'label'] = $obj->label;
158 $this->cache_warehouses[$obj->rowid][
'parent_id'] = $obj->fk_parent;
159 $this->cache_warehouses[$obj->rowid][
'description'] = $obj->description;
160 $this->cache_warehouses[$obj->rowid][
'stock'] = $obj->stock;
165 foreach ($this->cache_warehouses as $obj_rowid => $tab) {
166 $this->cache_warehouses[$obj_rowid][
'full_label'] = $this->
get_parent_path($tab);
188 global $conf, $langs;
190 if (empty($fk_product) && count($this->cache_workstations)) {
194 $sql =
"SELECT w.rowid, w.ref as ref, w.label as label, w.type, w.nb_operators_required,w.thm_operator_estimated,w.thm_machine_estimated";
195 $sql .=
" FROM ".$this->db->prefix().
"workstation_workstation as w";
196 $sql .=
" WHERE 1 = 1";
197 if (!empty($fk_product) && $fk_product > 0) {
198 $sql .=
" AND w.fk_product = ".((int) $fk_product);
200 $sql .=
" AND w.entity IN (".getEntity(
'workstation').
")";
202 if (is_array($exclude) && !empty($exclude)) {
203 $sql .=
' AND w.rowid NOT IN('.$this->db->sanitize(implode(
',', $exclude)).
')';
206 $sql .=
" ORDER BY ".$orderBy;
208 dol_syslog(get_class($this).
'::loadWorkstations', LOG_DEBUG);
214 $obj = $this->
db->fetch_object(
$resql);
216 $this->cache_workstations[$obj->rowid][
'id'] = $obj->rowid;
217 $this->cache_workstations[$obj->rowid][
'ref'] = $obj->ref;
218 $this->cache_workstations[$obj->rowid][
'label'] = $obj->label;
219 $this->cache_workstations[$obj->rowid][
'type'] = $obj->type;
220 $this->cache_workstations[$obj->rowid][
'nb_operators_required'] = $obj->nb_operators_required;
221 $this->cache_workstations[$obj->rowid][
'thm_operator_estimated'] = $obj->thm_operator_estimated;
222 $this->cache_workstations[$obj->rowid][
'thm_machine_estimated'] = $obj->thm_machine_estimated;
244 if (empty($final_label)) {
245 $final_label = $tab[
'label'];
248 if (empty($tab[
'parent_id'])) {
251 if (!empty($this->cache_warehouses[$tab[
'parent_id']])) {
252 $final_label = $this->cache_warehouses[$tab[
'parent_id']][
'label'].
' >> '.$final_label;
253 return $this->
get_parent_path($this->cache_warehouses[$tab[
'parent_id']], $final_label);
285 public function selectWarehouses($selected =
'', $htmlname =
'idwarehouse', $filterstatus =
'', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label =
'', $showstock = 0, $forcecombo = 0, $events = array(), $morecss =
'minwidth200', $exclude = array(), $showfullpath = 1, $stockMin =
false, $orderBy =
'e.ref')
287 global $conf, $langs, $user, $hookmanager;
289 dol_syslog(get_class($this).
"::selectWarehouses $selected, $htmlname, $filterstatus, $empty, $disabled, $fk_product, $empty_label, $showstock, $forcecombo, $morecss", LOG_DEBUG);
292 if (empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
295 if (!empty($fk_product) && $fk_product > 0) {
296 $this->cache_warehouses = array();
299 $this->
loadWarehouses($fk_product,
'', $filterstatus,
true, $exclude, $stockMin, $orderBy);
300 $nbofwarehouses = count($this->cache_warehouses);
302 if ($conf->use_javascript_ajax && !$forcecombo) {
303 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
305 $out .= $comboenhancement;
308 if (strpos($htmlname,
'search_') !== 0) {
309 if (empty($user->fk_warehouse) || $user->fk_warehouse == -1) {
310 if (($selected ==
'-2' || $selected ==
'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
311 $selected = $conf->global->MAIN_DEFAULT_WAREHOUSE;
314 if (($selected ==
'-2' || $selected ==
'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
315 $selected = $user->fk_warehouse;
320 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled' :
'').
' id="'.$htmlname.
'" name="'.($htmlname.($disabled ?
'_disabled' :
'')).
'">';
322 $out .=
'<option value="-1">'.($empty_label ? $empty_label :
' ').
'</option>';
324 foreach ($this->cache_warehouses as $id => $arraytypes) {
327 $label .= $arraytypes[
'full_label'];
329 $label .= $arraytypes[
'label'];
331 if (($fk_product || ($showstock > 0)) && ($arraytypes[
'stock'] != 0 || ($showstock > 0))) {
332 if ($arraytypes[
'stock'] <= 0) {
333 $label .=
' <span class= \'text-warning\'>('.$langs->trans(
"Stock").
':'.$arraytypes[
'stock'].
')</span>';
335 $label .=
' <span class=\'opacitymedium\'>('.$langs->trans(
"Stock").
':'.$arraytypes[
'stock'].
')</span>';
339 $out .=
'<option value="'.$id.
'"';
340 if ($selected == $id || (preg_match(
'/^ifone/', $selected) && $nbofwarehouses == 1)) {
343 $out .=
' data-html="'.dol_escape_htmltag($label).
'"';
350 $out .=
'<input type="hidden" name="'.$htmlname.
'" value="'.(($selected > 0) ? $selected :
'').
'">';
354 'selected' => $selected,
355 'htmlname' => $htmlname,
356 'filterstatus' => $filterstatus,
358 'disabled ' => $disabled,
359 'fk_product' => $fk_product,
360 'empty_label' => $empty_label,
361 'showstock' => $showstock,
362 'forcecombo' => $forcecombo,
364 'morecss' => $morecss,
365 'exclude' => $exclude,
366 'showfullpath' => $showfullpath,
367 'stockMin' => $stockMin,
368 'orderBy' => $orderBy
371 $reshook = $hookmanager->executeHooks(
'selectWarehouses', $parameters, $this);
373 $out = $hookmanager->resPrint;
374 } elseif ($reshook == 0) {
375 $out .= $hookmanager->resPrint;
400 public function selectWorkstations($selected =
'', $htmlname =
'idworkstations', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label =
'', $forcecombo = 0, $events = array(), $morecss =
'minwidth200', $exclude = array(), $showfullpath = 1, $orderBy =
'e.ref')
402 global $conf, $langs, $user, $hookmanager;
404 dol_syslog(get_class($this).
"::selectWorkstations $selected, $htmlname, $empty, $disabled, $fk_product, $empty_label, $forcecombo, $morecss", LOG_DEBUG);
408 if (!empty($fk_product) && $fk_product > 0) {
409 $this->cache_workstations = array();
413 $nbofworkstations = count($this->cache_workstations);
415 if ($conf->use_javascript_ajax && !$forcecombo) {
416 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
418 $out .= $comboenhancement;
421 if (strpos($htmlname,
'search_') !== 0) {
422 if (empty($user->fk_workstation) || $user->fk_workstation == -1) {
423 if (($selected ==
'-2' || $selected ==
'ifone') && !empty($conf->global->MAIN_DEFAULT_WORKSTATION)) {
424 $selected = $conf->global->MAIN_DEFAULT_WORKSTATION;
427 if (($selected ==
'-2' || $selected ==
'ifone') && !empty($conf->global->MAIN_DEFAULT_WORKSTATION)) {
428 $selected = $user->fk_workstation;
433 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled' :
'').
' id="'.$htmlname.
'" name="'.($htmlname.($disabled ?
'_disabled' :
'')).
'">';
435 $out .=
'<option value="-1">'.($empty_label ? $empty_label :
' ').
'</option>';
437 foreach ($this->cache_workstations as $id => $arraytypes) {
438 $label = $arraytypes[
'label'];
440 $out .=
'<option value="'.$id.
'"';
441 if ($selected == $id || (preg_match(
'/^ifone/', $selected) && $nbofworkstations == 1)) {
444 $out .=
' data-html="'.dol_escape_htmltag($label).
'"';
451 $out .=
'<input type="hidden" name="'.$htmlname.
'" value="'.(($selected > 0) ? $selected :
'').
'">';
455 'selected' => $selected,
456 'htmlname' => $htmlname,
457 'filterstatus' => $filterstatus,
459 'disabled ' => $disabled,
460 'fk_product' => $fk_product,
461 'empty_label' => $empty_label,
462 'forcecombo' => $forcecombo,
464 'morecss' => $morecss,
465 'exclude' => $exclude,
466 'showfullpath' => $showfullpath,
467 'orderBy' => $orderBy
470 $reshook = $hookmanager->executeHooks(
'selectWorkstations', $parameters, $this);
472 $out = $hookmanager->resPrint;
473 } elseif ($reshook == 0) {
474 $out .= $hookmanager->resPrint;
492 if ($htmlname !=
"none") {
493 print
'<form method="POST" action="'.$page.
'">';
494 print
'<input type="hidden" name="action" value="setwarehouse">';
495 print
'<input type="hidden" name="token" value="'.newToken().
'">';
496 print
'<table class="nobordernopadding">';
500 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'"></td>';
501 print
'</tr></table></form>';
504 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
506 $warehousestatic->fetch($selected);
507 print $warehousestatic->getNomUrl();
527 public function select_measuring_units($name =
'measuring_units', $measuring_style =
'', $default =
'0', $adddefault = 0, $mode = 0)
545 public function selectMeasuringUnits($name =
'measuring_units', $measuring_style =
'', $default =
'0', $adddefault = 0, $mode = 0, $morecss =
'maxwidth125')
547 global $langs, $conf, $mysoc, $db;
549 $langs->load(
"other");
554 require_once DOL_DOCUMENT_ROOT.
'/core/class/cunits.class.php';
555 $measuringUnits =
new CUnits($db);
558 $filter[
't.active'] = 1;
559 if ($measuring_style) {
560 $filter[
't.unit_type'] = $measuring_style;
563 $result = $measuringUnits->fetchAll(
574 $return .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$name.
'" id="'.$name.
'">';
575 if ($adddefault || $adddefault ===
'') {
576 $return .=
'<option value="0">'.($adddefault ? $langs->trans(
"Default") :
'').
'</option>';
579 foreach ($measuringUnits->records as $lines) {
580 $return .=
'<option value="';
582 $return .= $lines->short_label;
583 } elseif ($mode == 2) {
584 $return .= $lines->scale;
586 $return .= $lines->id;
589 if ($mode == 1 && $lines->short_label == $default) {
590 $return .=
' selected';
591 } elseif ($mode == 2 && $lines->scale == $default) {
592 $return .=
' selected';
593 } elseif ($mode == 0 && $lines->id == $default) {
594 $return .=
' selected';
597 if ($measuring_style ==
'time') {
598 $return .= $langs->trans(ucfirst($lines->label));
600 $return .= $langs->trans($lines->label);
602 $return .=
'</option>';
604 $return .=
'</select>';
626 $langs->load(
'products');
631 require_once DOL_DOCUMENT_ROOT.
'/core/class/cproductnature.class.php';
635 $filter[
't.active'] = 1;
637 $result = $productNature->fetchAll(
'',
'', 0, 0, $filter);
643 $return .=
'<select class="flat" name="'.$name.
'" id="'.$name.
'">';
644 if ($showempty || ($selected ==
'' || $selected ==
'-1')) {
645 $return .=
'<option value="-1"';
646 if ($selected ==
'' || $selected ==
'-1') {
647 $return .=
' selected';
649 $return .=
'></option>';
651 if (!empty($productNature->records) && is_array($productNature->records)) {
652 foreach ($productNature->records as $lines) {
653 $return .=
'<option value="';
655 $return .= $lines->label;
657 $return .= $lines->code;
662 if ($mode == 1 && $lines->label == $selected) {
663 $return .=
' selected';
664 } elseif ($lines->code == $selected) {
665 $return .=
' selected';
669 $return .= $langs->trans($lines->label);
670 $return .=
'</option>';
673 $return .=
'</select>';
699 public function selectLotStock($selected =
'', $htmlname =
'batch_id', $filterstatus =
'', $empty = 0, $disabled = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $empty_label =
'', $forcecombo = 0, $events = array(), $morecss =
'minwidth200')
701 global $conf, $langs;
703 dol_syslog(get_class($this).
"::selectLotStock $selected, $htmlname, $filterstatus, $empty, $disabled, $fk_product, $fk_entrepot, $empty_label, $forcecombo, $morecss", LOG_DEBUG);
706 $productIdArray = array();
707 if (!is_array($objectLines) || !count($objectLines)) {
708 if (!empty($fk_product) && $fk_product > 0) {
709 $productIdArray[] = (int) $fk_product;
712 foreach ($objectLines as $line) {
713 if ($line->fk_product) {
714 $productIdArray[] = $line->fk_product;
721 if ($conf->use_javascript_ajax && !$forcecombo) {
722 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
724 $out .= $comboenhancement;
727 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled' :
'').
' id="'.$htmlname.
'" name="'.($htmlname.($disabled ?
'_disabled' :
'')).
'">';
729 $out .=
'<option value="-1">'.($empty_label ? $empty_label :
' ').
'</option>';
731 if (!empty($fk_product) && $fk_product > 0) {
732 $productIdArray = array((
int) $fk_product);
734 foreach ($this->cache_lot as $key => $value) {
735 $productIdArray[] = $key;
739 foreach ($productIdArray as $productId) {
740 foreach ($this->cache_lot[$productId] as $id => $arraytypes) {
741 if (empty($fk_entrepot) || $fk_entrepot == $arraytypes[
'entrepot_id']) {
742 $label = $arraytypes[
'entrepot_label'].
' - ';
743 $label .= $arraytypes[
'batch'];
744 if ($arraytypes[
'qty'] <= 0) {
745 $label .=
' <span class=\'text-warning\'>('.$langs->trans(
"Stock").
' '.$arraytypes[
'qty'].
')</span>';
747 $label .=
' <span class=\'opacitymedium\'>('.$langs->trans(
"Stock").
' '.$arraytypes[
'qty'].
')</span>';
750 $out .=
'<option value="'.$id.
'"';
752 if ($selected == $id || ($selected ==
'ifone' && $nboflot == 1)) {
755 $out .=
' data-html="'.dol_escape_htmltag($label).
'"';
764 $out .=
'<input type="hidden" name="'.$htmlname.
'" value="'.(($selected > 0) ? $selected :
'').
'">';
782 public function selectLotDataList($htmlname =
'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array())
784 dol_syslog(get_class($this).
"::selectLotDataList $htmlname, $empty, $fk_product, $fk_entrepot", LOG_DEBUG);
787 $productIdArray = array();
788 if (!is_array($objectLines) || !count($objectLines)) {
789 if (!empty($fk_product) && $fk_product > 0) {
790 $productIdArray[] = (int) $fk_product;
793 foreach ($objectLines as $line) {
794 if ($line->fk_product) {
795 $productIdArray[] = $line->fk_product;
802 $out .=
'<datalist id="'.$htmlname.
'" >';
804 if (!empty($fk_product) && $fk_product > 0) {
805 $productIdArray = array((
int) $fk_product);
807 foreach ($this->cache_lot as $key => $value) {
808 $productIdArray[] = $key;
812 foreach ($productIdArray as $productId) {
813 if (array_key_exists($productId, $this->cache_lot)) {
814 foreach ($this->cache_lot[$productId] as $id => $arraytypes) {
815 if (empty($fk_entrepot) || $fk_entrepot == $arraytypes[
'entrepot_id']) {
816 $label = $arraytypes[
'entrepot_label'] .
' - ';
817 $label .= $arraytypes[
'batch'];
818 $out .=
'<option data-warehouse="'.dol_escape_htmltag($label).
'">' . $arraytypes[
'batch'] .
'</option>';
823 $out .=
'</datalist>';
838 global $conf, $langs;
840 $cacheLoaded =
false;
841 if (empty($productIdArray)) {
843 $this->cache_lot = array();
846 if (count($productIdArray) && count($this->cache_lot)) {
848 foreach ($productIdArray as $productId) {
849 $cacheLoaded = !empty($this->cache_lot[$productId]) ? true :
false;
853 return count($this->cache_lot);
856 $this->cache_lot = array();
857 $productIdList = implode(
',', $productIdArray);
858 $sql =
"SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
859 $sql .=
" FROM ".$this->db->prefix().
"product_batch as pb";
860 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_stock as ps on ps.rowid = pb.fk_product_stock";
861 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
")";
862 if (!empty($productIdList)) {
863 $sql .=
" WHERE ps.fk_product IN (".$this->db->sanitize($productIdList).
")";
865 $sql .=
" ORDER BY e.ref, pb.batch";
867 dol_syslog(get_class($this).
'::loadLotStock', LOG_DEBUG);
873 $obj = $this->
db->fetch_object(
$resql);
874 $this->cache_lot[$obj->fk_product][$obj->rowid][
'id'] = $obj->rowid;
875 $this->cache_lot[$obj->fk_product][$obj->rowid][
'batch'] = $obj->batch;
876 $this->cache_lot[$obj->fk_product][$obj->rowid][
'entrepot_id'] = $obj->fk_entrepot;
877 $this->cache_lot[$obj->fk_product][$obj->rowid][
'entrepot_label'] = $obj->label;
878 $this->cache_lot[$obj->fk_product][$obj->rowid][
'qty'] = $obj->qty;
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class of dictionary of nature of product (used by imports)
Class of dictionary type of thirdparty (used by imports)
Class to manage warehouses.
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
const STATUS_CLOSED
Warehouse closed, inactive.
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.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$conf db
API class for accounts.