48 if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER[
"CONTEXT_DOCUMENT_ROOT"].
"/main.inc.php";
50 $tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
51 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
52 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
53 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
55 if (!$res && file_exists(
"../main.inc.php")) $res = @include
"../main.inc.php";
56 if (!$res && file_exists(
"../../main.inc.php")) $res = @include
"../../main.inc.php";
57 if (!$res && file_exists(
"../../../main.inc.php")) $res = @include
"../../../main.inc.php";
58 if (!$res) die(
"Include of main fails");
60 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
66 require_once __DIR__.
'/class/stocktransfer.class.php';
72 $langs->loadLangs(array(
"stocks",
"other"));
74 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
75 $massaction =
GETPOST(
'massaction',
'alpha');
76 $show_files =
GETPOST(
'show_files',
'int');
77 $confirm =
GETPOST(
'confirm',
'alpha');
78 $cancel =
GETPOST(
'cancel',
'alpha');
79 $toselect =
GETPOST(
'toselect',
'array');
80 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'stocktransferlist';
81 $backtopage =
GETPOST(
'backtopage',
'alpha');
82 $optioncss =
GETPOST(
'optioncss',
'aZ');
87 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
88 $sortfield =
GETPOST(
'sortfield',
'alpha');
89 $sortorder =
GETPOST(
'sortorder',
'alpha');
91 if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) { $page = 0; }
92 $offset = $limit * $page;
93 $pageprev = $page - 1;
94 $pagenext = $page + 1;
99 $diroutputmassaction = $conf->stocktransfer->dir_output.
'/temp/massgeneration/'.$user->id;
100 $hookmanager->initHooks(array(
'stocktransferlist'));
103 $extrafields->fetch_name_optionals_label($object->table_element);
106 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
109 if (!$sortfield) $sortfield =
"t.".key($object->fields);
110 if (!$sortorder) $sortorder =
"ASC";
113 $search_all =
GETPOST(
'search_all',
'alphanohtml') ? trim(
GETPOST(
'search_all',
'alphanohtml')) : trim(
GETPOST(
'sall',
'alphanohtml'));
115 foreach ($object->fields as $key => $val) {
116 if (
GETPOST(
'search_'.$key,
'alpha') !==
'') $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
120 $fieldstosearchall = array();
121 foreach ($object->fields as $key => $val) {
122 if ($val[
'searchall']) $fieldstosearchall[
't.'.$key] = $val[
'label'];
126 $arrayfields = array();
127 foreach ($object->fields as $key => $val) {
129 if (!empty($val[
'visible'])) $arrayfields[
't.'.$key] = array(
'label'=>$val[
'label'],
'checked'=>(($val[
'visible'] < 0) ? 0 : 1),
'enabled'=>(
verifCond($val[
'enabled']) && ($val[
'visible'] != 3)),
'position'=>$val[
'position']);
133 if (is_array($extrafields->attributes[$object->table_element][
'label']) && count($extrafields->attributes[$object->table_element][
'label']) > 0) {
134 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
135 if (!empty($extrafields->attributes[$object->table_element][
'list'][$key])) {
136 $arrayfields[
"ef.".$key] = array(
137 'label'=>$extrafields->attributes[$object->table_element][
'label'][$key],
138 'checked'=>(($extrafields->attributes[$object->table_element][
'list'][$key] < 0) ? 0 : 1),
139 'position'=>$extrafields->attributes[$object->table_element][
'pos'][$key],
140 'enabled'=>(abs($extrafields->attributes[$object->table_element][
'list'][$key]) != 3 && $extrafields->attributes[$object->table_element][
'perms'][$key]),
141 'langfile'=>$extrafields->attributes[$object->table_element][
'langfile'][$key]
149 $permissiontoread = $user->rights->stocktransfer->stocktransfer->read;
150 $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write;
151 $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete;
154 if (empty($conf->stocktransfer->enabled))
accessforbidden(
'Module not enabled');
156 if ($user->socid > 0) {
169 if (
GETPOST(
'cancel',
'alpha')) { $action =
'list'; $massaction =
''; }
170 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') { $massaction =
''; }
172 $parameters = array();
173 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
174 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
176 if (empty($reshook)) {
178 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
181 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
182 foreach ($object->fields as $key => $val) {
186 $search_array_options = array();
188 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')
189 ||
GETPOST(
'button_search_x',
'alpha') ||
GETPOST(
'button_search.x',
'alpha') ||
GETPOST(
'button_search',
'alpha')) {
194 $objectclass =
'StockTransfer';
195 $objectlabel =
'StockTransfer';
196 $uploaddir = $conf->stocktransfer->dir_output;
197 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
212 $title = $langs->trans(
'StockTransferList');
218 foreach ($object->fields as $key => $val) {
219 $sql .=
"t.".$key.
", ";
222 if (!empty($extrafields->attributes[$object->table_element][
'label'])) {
223 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element][
'type'][$key] !=
'separate' ?
"ef.".$key.
" as options_".$key.
', ' :
'');
226 $parameters = array();
227 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object);
228 $sql .= preg_replace(
'/^,/',
'', $hookmanager->resPrint);
229 $sql = preg_replace(
'/,\s*$/',
'', $sql);
230 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
231 if (is_array($extrafields->attributes[$object->table_element][
'label']) && count($extrafields->attributes[$object->table_element][
'label'])) $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as ef on (t.rowid = ef.fk_object)";
232 if ($object->ismultientitymanaged == 1) $sql .=
" WHERE t.entity IN (".getEntity($object->element).
")";
233 else $sql .=
" WHERE 1 = 1";
234 foreach ($search as $key => $val) {
235 if ($key ==
'status' && $search[$key] == -1)
continue;
236 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
237 if (strpos($object->fields[$key][
'type'],
'integer:') === 0) {
238 if ($search[$key] ==
'-1') $search[$key] =
'';
241 if ($search[$key] !=
'') $sql .=
natural_search($key, $search[$key], (($key ==
'status') ? 2 : $mode_search));
243 if ($search_all) $sql .=
natural_search(array_keys($fieldstosearchall), $search_all);
246 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
248 $parameters = array();
249 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
250 $sql .= $hookmanager->resPrint;
269 $sql .= $db->order($sortfield, $sortorder);
272 $nbtotalofrecords =
'';
273 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
274 $resql = $db->query($sql);
275 $nbtotalofrecords = $db->num_rows(
$resql);
276 if (($page * $limit) > $nbtotalofrecords) {
282 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
283 $num = $nbtotalofrecords;
285 if ($limit) $sql .= $db->plimit($limit + 1, $offset);
287 $resql = $db->query($sql);
293 $num = $db->num_rows(
$resql);
297 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
298 $obj = $db->fetch_object(
$resql);
300 header(
"Location: ".
dol_buildpath(
'/product/stock/stocktransfer/stocktransfer_card.php', 1).
'?id='.$id);
311 print
'<script type="text/javascript" language="javascript">
312 jQuery(document).ready(function() {
313 function init_myfunc()
315 jQuery("#myid").removeAttr(\'disabled\');
316 jQuery("#myid").attr(\'disabled\',\'disabled\');
319 jQuery("#mybutton").click(function() {
325 $arrayofselected = is_array($toselect) ? $toselect : array();
328 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
329 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
330 foreach ($search as $key => $val) {
331 if (is_array($search[$key]) && count($search[$key]))
foreach ($search[$key] as $skey) $param .=
'&search_'.$key.
'[]='.urlencode($skey);
332 else $param .=
'&search_'.$key.
'='.urlencode($search[$key]);
334 if ($optioncss !=
'') $param .=
'&optioncss='.urlencode($optioncss);
336 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
339 $arrayofmassactions = array(
345 if ($permissiontodelete) $arrayofmassactions[
'predelete'] =
'<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans(
"Delete");
346 if (
GETPOST(
'nomassaction',
'int') || in_array($massaction, array(
'presend',
'predelete'))) $arrayofmassactions = array();
347 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
349 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
350 if ($optioncss !=
'') print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
351 print
'<input type="hidden" name="token" value="'.newToken().
'">';
352 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
353 print
'<input type="hidden" name="action" value="list">';
354 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
355 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
357 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
359 $newcardbutton =
dolGetButtonTitle($langs->trans(
'New'),
'',
'fa fa-plus-circle',
dol_buildpath(
'/product/stock/stocktransfer/stocktransfer_card.php', 1).
'?action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF']),
'', $permissiontoadd);
361 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'object_'.$object->picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
364 $topicmail =
"SendStockTransferRef";
365 $modelmail =
"stocktransfer";
367 $trackid =
'xxxx'.$object->id;
368 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
371 foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
372 print
'<div class="divsearchfieldfilter">'.$langs->trans(
"FilterOnInto", $search_all).join(
', ', $fieldstosearchall).
'</div>';
380 $parameters = array();
381 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object);
382 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
383 else $moreforfilter = $hookmanager->resPrint;
385 if (!empty($moreforfilter)) {
386 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
387 print $moreforfilter;
391 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
392 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
393 $selectedfields .= (count($arrayofmassactions) ?
$form->showCheckAddButtons(
'checkforselect', 1) :
'');
395 print
'<div class="div-table-responsive">';
396 print
'<table class="tagtable nobottomiftotal liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
401 print
'<tr class="liste_titre">';
402 foreach ($object->fields as $key => $val) {
403 $cssforfield = (empty($val[
'css']) ?
'' : $val[
'css']);
404 if ($key ==
'status') $cssforfield .= ($cssforfield ?
' ' :
'').
'center';
405 elseif (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
406 elseif (in_array($val['
type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
407 elseif (in_array($val['
type'], array('
double(24,8)', '
double(6,3)', 'integer', 'real', '
price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
408 if (!empty($arrayfields['t.'.$key]['checked'])) {
409 print
'<td class="liste_titre'.($cssforfield ?
' '.$cssforfield :
'').
'">';
410 if (is_array($val[
'arrayofkeyval'])) print
$form->selectarray(
'search_'.$key, $val[
'arrayofkeyval'], $search[$key], $val[
'notnull'], 0, 0,
'', 1, 0, 0,
'',
'maxwidth75');
411 elseif (strpos($val[
'type'],
'integer:') === 0) {
412 print $object->showInputField($val, $key, $search[$key],
'',
'',
'search_',
'maxwidth150', 1);
413 } elseif (!preg_match(
'/^(date|timestamp)/', $val[
'type'])) print
'<input type="text" class="flat maxwidth75" name="search_'.$key.
'" value="'.
dol_escape_htmltag($search[$key]).
'">';
418 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_input.tpl.php';
421 $parameters = array(
'arrayfields'=>$arrayfields);
422 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object);
423 print $hookmanager->resPrint;
425 print
'<td class="liste_titre maxwidthsearch">';
426 $searchpicto =
$form->showFilterButtons();
434 print
'<tr class="liste_titre">';
435 foreach ($object->fields as $key => $val) {
436 $cssforfield = (empty($val[
'css']) ?
'' : $val[
'css']);
437 if ($key ==
'status') $cssforfield .= ($cssforfield ?
' ' :
'').
'center';
438 elseif (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
439 elseif (in_array($val['
type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
440 elseif (in_array($val['
type'], array('
double(24,8)', '
double(6,3)', 'integer', 'real', '
price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
441 if (!empty($arrayfields['t.'.$key]['checked'])) {
442 print
getTitleFieldOfList($arrayfields[
't.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'],
't.'.$key,
'', $param, ($cssforfield ?
'class="'.$cssforfield.
'"' :
''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.
' ' :
'')).
"\n";
446 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_title.tpl.php';
448 $parameters = array(
'arrayfields'=>$arrayfields,
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
449 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object);
450 print $hookmanager->resPrint;
452 print
getTitleFieldOfList($selectedfields, 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ').
"\n";
457 $needToFetchEachLine = 0;
458 if (is_array($extrafields->attributes[$object->table_element][
'computed']) && count($extrafields->attributes[$object->table_element][
'computed']) > 0) {
459 foreach ($extrafields->attributes[$object->table_element][
'computed'] as $key => $val) {
460 if (preg_match(
'/\$object/', $val)) $needToFetchEachLine++;
468 $totalarray = array();
469 while ($i < ($limit ? min($num, $limit) : $num)) {
470 $obj = $db->fetch_object(
$resql);
471 if (empty($obj))
break;
474 $object->setVarsFromFetchObj($obj);
477 print
'<tr class="oddeven">';
478 foreach ($object->fields as $key => $val) {
479 $cssforfield = (empty($val[
'css']) ?
'' : $val[
'css']);
480 if (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) $cssforfield .= ($cssforfield ?
' ' :
'').
'center';
481 elseif ($key ==
'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
483 if (in_array($val['
type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
484 elseif ($key == '
ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
486 if (in_array($val['
type'], array('
double(24,8)', '
double(6,3)', 'integer', 'real', '
price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
489 if (!empty($arrayfields['t.'.$key]['checked'])) {
490 print
'<td'.($cssforfield ?
' class="'.$cssforfield.
'"' :
'').
'>';
491 if ($key ==
'status') print $object->getLibStatut(5);
493 print $object->showOutputField($val, $key, $object->$key,
'');
494 if ($key ===
'date_prevue_depart' && $object->lead_time_for_warning > 0 && $object->$key > 0) {
495 $date_prevue_depart = $object->$key;
496 $date_prevue_depart_plus_delai = $date_prevue_depart;
497 if ($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date(
'Y-m-d', $date_prevue_depart) .
' + '.$object->lead_time_for_warning.
' day');
498 if ($date_prevue_depart_plus_delai < strtotime(date(
'Y-m-d'))) print
img_warning($langs->trans(
'Alert').
' - '.$langs->trans(
'Late'));
502 if (!$i) $totalarray[
'nbfield']++;
503 if (!empty($val[
'isameasure'])) {
504 if (!$i) $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.'.$key;
505 $totalarray[
'val'][
't.'.$key] += $object->$key;
510 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_print_fields.tpl.php';
512 $parameters = array(
'arrayfields'=>$arrayfields,
'object'=>$object,
'obj'=>$obj,
'i'=>$i,
'totalarray'=>&$totalarray);
513 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object);
514 print $hookmanager->resPrint;
516 print
'<td class="nowrap center">';
517 if ($massactionbutton || $massaction) {
519 if (in_array($object->id, $arrayofselected)) $selected = 1;
520 print
'<input id="cb'.$object->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
523 if (!$i) $totalarray[
'nbfield']++;
531 include DOL_DOCUMENT_ROOT.
'/core/tpl/list_print_total.tpl.php';
536 foreach ($arrayfields as $key => $val) {
if (!empty($val[
'checked'])) $colspan++; }
537 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
543 $parameters = array(
'arrayfields'=>$arrayfields,
'sql'=>$sql);
544 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object);
545 print $hookmanager->resPrint;
547 print
'</table>'.
"\n";
550 print
'</form>'.
"\n";
552 if (in_array(
'builddoc', $arrayofmassactions) && ($nbtotalofrecords ===
'' || $nbtotalofrecords)) {
553 $hidegeneratedfilelistifempty = 1;
554 if ($massaction ==
'builddoc' || $action ==
'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
556 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
560 $urlsource = $_SERVER[
'PHP_SELF'].
'?sortfield='.$sortfield.
'&sortorder='.$sortorder;
561 $urlsource .= str_replace(
'&',
'&', $param);
563 $filedir = $diroutputmassaction;
564 $genallowed = $permissiontoread;
565 $delallowed = $permissiontoadd;
567 print $formfile->showdocuments(
'massfilesarea_stocktransfer',
'', $filedir, $urlsource, 0, $delallowed,
'', 1, 1, 0, 48, 1, $param, $title,
'',
'',
'',
null, $hidegeneratedfilelistifempty);