dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
5  * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
38 // Load translation files required by the page
39 $langs->loadLangs(array('products', 'stocks', 'companies', 'categories'));
40 
41 $action = GETPOST('action', 'aZ09');
42 $cancel = GETPOST('cancel', 'alpha');
43 $confirm = GETPOST('confirm');
44 
45 $id = GETPOST('id', 'int');
46 $ref = GETPOST('ref', 'alpha');
47 
48 $sortfield = GETPOST("sortfield", 'alpha');
49 $sortorder = GETPOST("sortorder", 'alpha');
50 if (!$sortfield) $sortfield = "p.ref";
51 if (!$sortorder) $sortorder = "DESC";
52 
53 $backtopage = GETPOST('backtopage', 'alpha');
54 
55 // Security check
56 //$result=restrictedArea($user,'stock', $id, 'entrepot&stock');
57 $result = restrictedArea($user, 'stock');
58 
59 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
60 $hookmanager->initHooks(array('warehousecard', 'globalcard'));
61 
62 $object = new Entrepot($db);
63 $extrafields = new ExtraFields($db);
64 
65 // fetch optionals attributes and labels
66 $extrafields->fetch_name_optionals_label($object->table_element);
67 
68 // Load object
69 if ($id > 0 || !empty($ref)) {
70  $ret = $object->fetch($id, $ref);
71  if ($ret <= 0) {
72  setEventMessages($object->error, $object->errors, 'errors');
73  $action = '';
74  }
75 }
76 
77 
78 /*
79  * Actions
80  */
81 
82 $error = 0;
83 
84 $usercanread = (($user->rights->stock->lire));
85 $usercancreate = (($user->rights->stock->creer));
86 $usercandelete = (($user->rights->stock->supprimer));
87 
88 $parameters = array('id'=>$id, 'ref'=>$ref);
89 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 if (empty($reshook))
92 {
93  // Ajout entrepot
94  if ($action == 'add' && $user->rights->stock->creer)
95  {
96  $object->ref = (string) GETPOST("ref", "alpha");
97  $object->fk_parent = (int) GETPOST("fk_parent", "int");
98  $object->label = (string) GETPOST("libelle", "alpha");
99  $object->description = (string) GETPOST("desc", "alpha");
100  $object->statut = GETPOST("statut");
101  $object->lieu = (string) GETPOST("lieu", "alpha");
102  $object->address = (string) GETPOST("address", "alpha");
103  $object->zip = (string) GETPOST("zipcode", "alpha");
104  $object->town = (string) GETPOST("town", "alpha");
105  $object->country_id = GETPOST("country_id");
106  $object->phone = (string) GETPOST("phone", "alpha");
107  $object->fax = (string) GETPOST("fax", "alpha");
108 
109  if (!empty($object->label)) {
110  // Fill array 'array_options' with data from add form
111  $ret = $extrafields->setOptionalsFromPost(null, $object);
112  if ($ret < 0) {
113  $error++;
114  $action = 'create';
115  }
116 
117  if (!$error) {
118  $id = $object->create($user);
119  if ($id > 0) {
120  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
121 
122  $categories = GETPOST('categories', 'array');
123  $object->setCategories($categories);
124  if (!empty($backtopage)) {
125  header("Location: ".$backtopage);
126  exit;
127  } else {
128  header("Location: card.php?id=".$id);
129  exit;
130  }
131  } else {
132  $action = 'create';
133  setEventMessages($object->error, $object->errors, 'errors');
134  }
135  }
136  } else {
137  setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors');
138  $action = "create"; // Force retour sur page creation
139  }
140  }
141 
142  // Delete warehouse
143  if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer)
144  {
145  $object->fetch(GETPOST('id', 'int'));
146  $result = $object->delete($user);
147  if ($result > 0)
148  {
149  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
150  header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1');
151  exit;
152  } else {
153  setEventMessages($object->error, $object->errors, 'errors');
154  $action = '';
155  }
156  }
157 
158  // Modification entrepot
159  if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
160  {
161  if ($object->fetch($id))
162  {
163  $object->label = GETPOST("libelle");
164  $object->fk_parent = GETPOST("fk_parent");
165  $object->description = GETPOST("desc");
166  $object->statut = GETPOST("statut");
167  $object->lieu = GETPOST("lieu");
168  $object->address = GETPOST("address");
169  $object->zip = GETPOST("zipcode");
170  $object->town = GETPOST("town");
171  $object->country_id = GETPOST("country_id");
172  $object->phone = GETPOST("phone");
173  $object->fax = GETPOST("fax");
174 
175  // Fill array 'array_options' with data from add form
176  $ret = $extrafields->setOptionalsFromPost(null, $object);
177  if ($ret < 0) $error++;
178 
179  if (!$error) {
180  $ret = $object->update($id, $user);
181  if ($ret < 0) $error++;
182  }
183 
184  if ($error) {
185  $action = 'edit';
186  setEventMessages($object->error, $object->errors, 'errors');
187  } else {
188  $categories = GETPOST('categories', 'array');
189  $object->setCategories($categories);
190  $action = '';
191  }
192  } else {
193  $action = 'edit';
194  setEventMessages($object->error, $object->errors, 'errors');
195  }
196  } elseif ($action == 'update_extras') {
197  $object->oldcopy = dol_clone($object);
198 
199  // Fill array 'array_options' with data from update form
200  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
201  if ($ret < 0) $error++;
202  if (!$error) {
203  $result = $object->insertExtraFields();
204  if ($result < 0) {
205  setEventMessages($object->error, $object->errors, 'errors');
206  $error++;
207  }
208  }
209  if ($error) $action = 'edit_extras';
210  }
211 
212  if ($cancel == $langs->trans("Cancel"))
213  {
214  $action = '';
215  }
216 
217 
218  // Actions to build doc
219  $upload_dir = $conf->stock->dir_output;
220  $permissiontoadd = $user->rights->stock->creer;
221  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
222 }
223 
224 
225 /*
226  * View
227  */
228 
229 $productstatic = new Product($db);
230 $form = new Form($db);
231 $formproduct = new FormProduct($db);
232 $formcompany = new FormCompany($db);
233 $formfile = new FormFile($db);
234 
235 $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
236 llxHeader("", $langs->trans("WarehouseCard"), $help_url);
237 
238 
239 if ($action == 'create')
240 {
241  print load_fiche_titre($langs->trans("NewWarehouse"), '', 'stock');
242 
243  dol_set_focus('input[name="libelle"]');
244 
245  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
246  print '<input type="hidden" name="token" value="'.newToken().'">';
247  print '<input type="hidden" name="action" value="add">';
248  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
249 
251 
252  print '<table class="border centpercent">';
253 
254  // Ref
255  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input name="libelle" size="20" value=""></td></tr>';
256 
257  print '<tr><td>'.$langs->trans("LocationSummary").'</td><td><input name="lieu" size="40" value="'.(!empty($object->lieu) ? $object->lieu : '').'"></td></tr>';
258 
259  // Parent entrepot
260  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
261  print img_picto('', 'stock').$formproduct->selectWarehouses((GETPOSTISSET('fk_parent') ? GETPOST('fk_parent', 'int') : 'ifone'), 'fk_parent', '', 1);
262  print '</td></tr>';
263 
264  // Description
265  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
266  // Editeur wysiwyg
267  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
268  $doleditor = new DolEditor('desc', (!empty($object->description) ? $object->description : ''), '', 180, 'dolibarr_notes', 'In', false, true, $conf->fckeditor->enabled, ROWS_5, '90%');
269  $doleditor->Create();
270  print '</td></tr>';
271 
272  print '<tr><td>'.$langs->trans('Address').'</td><td><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
273  print (!empty($object->address) ? $object->address : '');
274  print '</textarea></td></tr>';
275 
276  // Zip / Town
277  print '<tr><td>'.$langs->trans('Zip').'</td><td>';
278  print $formcompany->select_ziptown((!empty($object->zip) ? $object->zip : ''), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
279  print '</td></tr>';
280  print '<tr><td>'.$langs->trans('Town').'</td><td>';
281  print $formcompany->select_ziptown((!empty($object->town) ? $object->town : ''), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
282  print '</td></tr>';
283 
284  // Country
285  print '<tr><td>'.$langs->trans('Country').'</td><td>';
286  print img_picto('', 'globe-americas', 'class="paddingright"');
287  print $form->select_country((!empty($object->country_id) ? $object->country_id : $mysoc->country_code), 'country_id');
288  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
289  print '</td></tr>';
290 
291  // Phone / Fax
292  print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td><td>';
293  print img_picto('', 'object_phoning', 'class="paddingright"');
294  print '<input name="phone" size="20" value="'.$object->phone.'"></td></tr>';
295  print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
296  print '<td>';
297  print img_picto('', 'object_phoning_fax', 'class="paddingright"');
298  print '<input name="fax" size="20" value="'.$object->fax.'"></td></tr>';
299 
300  // Status
301  print '<tr><td>'.$langs->trans("Status").'</td><td>';
302  print '<select name="statut" class="flat">';
303  foreach ($object->statuts as $key => $value)
304  {
305  if ($key == 1)
306  {
307  print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
308  } else {
309  print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
310  }
311  }
312  print '</select>';
313  print '</td></tr>';
314 
315  // Other attributes
316  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
317 
318  if ($conf->categorie->enabled) {
319  // Categories
320  print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
321  $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1);
322  print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
323  print "</td></tr>";
324  }
325  print '</table>';
326 
327  print dol_get_fiche_end();
328 
329  print '<div class="center">';
330  print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
331  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
332  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
333  print '</div>';
334 
335  print '</form>';
336 } else {
337  $id = GETPOST("id", 'int');
338  if ($id > 0 || $ref)
339  {
340  $object = new Entrepot($db);
341  $result = $object->fetch($id, $ref);
342  if ($result <= 0)
343  {
344  print 'No record found';
345  exit;
346  }
347 
348  /*
349  * Affichage fiche
350  */
351  if ($action <> 'edit' && $action <> 're-edit')
352  {
353  $head = stock_prepare_head($object);
354 
355  print dol_get_fiche_head($head, 'card', $langs->trans("Warehouse"), -1, 'stock');
356 
357  $formconfirm = '';
358 
359  // Confirm delete warehouse
360  if ($action == 'delete')
361  {
362  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAWarehouse"), $langs->trans("ConfirmDeleteWarehouse", $object->label), "confirm_delete", '', 0, 2);
363  }
364 
365  // Call Hook formConfirm
366  $parameters = array('formConfirm' => $formconfirm);
367  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
368  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
369  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
370 
371  // Print form confirm
372  print $formconfirm;
373 
374  // Warehouse card
375  $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
376 
377  $morehtmlref = '<div class="refidno">';
378  $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
379  $morehtmlref .= '</div>';
380 
381  $shownav = 1;
382  if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
383 
384  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
385 
386  print '<div class="fichecenter">';
387  print '<div class="fichehalfleft">';
388  print '<div class="underbanner clearboth"></div>';
389 
390  print '<table class="border centpercent tableforfield">';
391 
392  // Parent entrepot
393  $parentwarehouse = new Entrepot($db);
394  if (!empty($object->fk_parent) && $parentwarehouse->fetch($object->fk_parent) > 0) {
395  print '<tr><td>'.$langs->trans("ParentWarehouse").'</td><td>';
396  print $parentwarehouse->getNomUrl(3);
397  print '</td></tr>';
398  }
399 
400  // Description
401  print '<tr><td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.nl2br($object->description).'</td></tr>';
402 
403  $calcproductsunique = $object->nb_different_products();
404  $calcproducts = $object->nb_products();
405 
406  // Total nb of different products
407  print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
408  print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb'];
409  print "</td></tr>";
410 
411  // Nb of products
412  print '<tr><td>'.$langs->trans("NumberOfProducts").'</td><td>';
413  $valtoshow = price2num($calcproducts['nb'], 'MS');
414  print empty($valtoshow) ? '0' : $valtoshow;
415  print "</td></tr>";
416 
417  print '</table>';
418 
419  print '</div>';
420  print '<div class="fichehalfright">';
421  print '<div class="ficheaddleft">';
422  print '<div class="underbanner clearboth"></div>';
423 
424  print '<table class="border centpercent tableforfield">';
425 
426  // Value
427  print '<tr><td class="titlefield">'.$langs->trans("EstimatedStockValueShort").'</td><td>';
428  print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency);
429  print "</td></tr>";
430 
431  // Last movement
432  if (!empty($user->rights->stock->mouvement->lire)) {
433  $sql = "SELECT max(m.datem) as datem";
434  $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
435  $sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
436  $resqlbis = $db->query($sql);
437  if ($resqlbis) {
438  $obj = $db->fetch_object($resqlbis);
439  $lastmovementdate = $db->jdate($obj->datem);
440  } else {
441  dol_print_error($db);
442  }
443  print '<tr><td>'.$langs->trans("LastMovement").'</td><td>';
444  if ($lastmovementdate) {
445  print dol_print_date($lastmovementdate, 'dayhour').' ';
446  print '(<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?id='.$object->id.'">'.$langs->trans("FullList").'</a>)';
447  } else {
448  print $langs->trans("None");
449  }
450  print "</td></tr>";
451  }
452 
453  // Other attributes
454  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
455 
456  // Categories
457  if ($conf->categorie->enabled) {
458  print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
459  print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1);
460  print "</td></tr>";
461  }
462 
463  print "</table>";
464 
465  print '</div>';
466  print '</div>';
467  print '</div>';
468 
469  print '<div class="clearboth"></div>';
470 
471  print dol_get_fiche_end();
472 
473 
474  /* ************************************************************************** */
475  /* */
476  /* Barre d'action */
477  /* */
478  /* ************************************************************************** */
479 
480  print "<div class=\"tabsAction\">\n";
481 
482  $parameters = array();
483  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
484  if (empty($reshook))
485  {
486  if (empty($action))
487  {
488  if ($user->rights->stock->creer) {
489  print '<a class="butAction" href="card.php?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
490  }
491  else {
492  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Modify").'</a>';
493  }
494 
495  if ($user->rights->stock->supprimer) {
496  print '<a class="butActionDelete" href="card.php?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
497  }
498  else {
499  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Delete").'</a>';
500  }
501  }
502  }
503 
504  print "</div>";
505 
506 
507  /* ************************************************************************** */
508  /* */
509  /* Affichage de la liste des produits de l'entrepot */
510  /* */
511  /* ************************************************************************** */
512  print '<br>';
513 
514  print '<table class="noborder centpercent">';
515  print "<tr class=\"liste_titre\">";
516  print_liste_field_titre("Product", "", "p.ref", "&amp;id=".$id, "", "", $sortfield, $sortorder);
517  print_liste_field_titre("Label", "", "p.label", "&amp;id=".$id, "", "", $sortfield, $sortorder);
518  print_liste_field_titre("Units", "", "ps.reel", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
519  if (!empty($conf->global->PRODUCT_USE_UNITS)) print_liste_field_titre("Unit", "", "p.fk_unit", "&amp;id=".$id, "", 'align="left"', $sortfield, $sortorder);
520  print_liste_field_titre("AverageUnitPricePMPShort", "", "p.pmp", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
521  print_liste_field_titre("EstimatedStockValueShort", "", "", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
522  if (empty($conf->global->PRODUIT_MULTIPRICES)) {
523  print_liste_field_titre("SellPriceMin", "", "p.price", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
524  }
525  if (empty($conf->global->PRODUIT_MULTIPRICES)) {
526  print_liste_field_titre("EstimatedStockValueSellShort", "", "", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
527  }
528  if ($user->rights->stock->mouvement->creer) {
530  }
531  if ($user->rights->stock->creer) {
533  }
534  print "</tr>\n";
535 
536  $totalunit = 0;
537  $totalvalue = $totalvaluesell = 0;
538 
539  $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
540  $sql .= " ps.reel as value";
541  if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= ",fk_unit";
542  $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
543  $sql .= " WHERE ps.fk_product = p.rowid";
544  $sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
545  $sql .= " AND ps.fk_entrepot = ".$object->id;
546  $sql .= $db->order($sortfield, $sortorder);
547 
548  dol_syslog('List products', LOG_DEBUG);
549  $resql = $db->query($sql);
550  if ($resql)
551  {
552  $num = $db->num_rows($resql);
553  $i = 0;
554  while ($i < $num)
555  {
556  $objp = $db->fetch_object($resql);
557 
558  // Multilangs
559  if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
560  {
561  $sql = "SELECT label";
562  $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
563  $sql .= " WHERE fk_product=".$objp->rowid;
564  $sql .= " AND lang='".$db->escape($langs->getDefaultLang())."'";
565  $sql .= " LIMIT 1";
566 
567  $result = $db->query($sql);
568  if ($result)
569  {
570  $objtp = $db->fetch_object($result);
571  if ($objtp->label != '') $objp->produit = $objtp->label;
572  }
573  }
574 
575 
576  //print '<td>'.dol_print_date($objp->datem).'</td>';
577  print '<tr class="oddeven">';
578  print "<td>";
579  $productstatic->id = $objp->rowid;
580  $productstatic->ref = $objp->ref;
581  $productstatic->label = $objp->produit;
582  $productstatic->type = $objp->type;
583  $productstatic->entity = $objp->entity;
584  $productstatic->status_batch = $objp->tobatch;
585  $productstatic->fk_unit = $objp->fk_unit;
586  print $productstatic->getNomUrl(1, 'stock', 16);
587  print '</td>';
588 
589  // Label
590  print '<td>'.$objp->produit.'</td>';
591 
592  print '<td class="right">';
593  $valtoshow = price(price2num($objp->value, 'MS'), 0, '', 0, 0); // TODO replace with a qty() function
594  print empty($valtoshow) ? '0' : $valtoshow;
595  print '</td>';
596  $totalunit += $objp->value;
597 
598  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
599  // Units
600  print '<td align="left">';
601  if (is_null($productstatic->fk_unit))$productstatic->fk_unit = 1;
602  print $langs->trans($productstatic->getLabelOfUnit());
603  print '</td>';
604  }
605  // Price buy PMP
606  print '<td class="right">'.price(price2num($objp->ppmp, 'MU')).'</td>';
607 
608  // Total PMP
609  print '<td class="right">'.price(price2num($objp->ppmp * $objp->value, 'MT')).'</td>';
610  $totalvalue += price2num($objp->ppmp * $objp->value, 'MT');
611 
612  // Price sell min
613  if (empty($conf->global->PRODUIT_MULTIPRICES))
614  {
615  $pricemin = $objp->price;
616  print '<td class="right">';
617  print price(price2num($pricemin, 'MU'), 1);
618  print '</td>';
619  // Total sell min
620  print '<td class="right">';
621  print price(price2num($pricemin * $objp->value, 'MT'), 1);
622  print '</td>';
623  }
624  $totalvaluesell += price2num($pricemin * $objp->value, 'MT');
625 
626  if ($user->rights->stock->mouvement->creer)
627  {
628  print '<td class="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&id='.$objp->rowid.'&action=transfert&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id).'">';
629  print img_picto($langs->trans("StockMovement"), 'uparrow.png', 'class="hideonsmartphone"').' '.$langs->trans("StockMovement");
630  print "</a></td>";
631  }
632 
633  if ($user->rights->stock->creer)
634  {
635  print '<td class="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&id='.$objp->rowid.'&action=correction&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id).'">';
636  print $langs->trans("StockCorrection");
637  print "</a></td>";
638  }
639  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
640  if ($i == 0) $units = $productstatic->fk_unit;
641  elseif ($productstatic->fk_unit != $units) $sameunits = false;
642  }
643  print "</tr>";
644  $i++;
645  }
646  $db->free($resql);
647 
648  print '<tr class="liste_total"><td class="liste_total" colspan="2">'.$langs->trans("Total").'</td>';
649  print '<td class="liste_total right">';
650  $valtoshow = price2num($totalunit, 'MS');
651  if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) print empty($valtoshow) ? '0' : $valtoshow;
652  print '</td>';
653  print '<td class="liste_total">';
654  if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) print $langs->trans($productstatic->getLabelOfUnit());
655  print '</td>';
656  print '<td class="liste_total right">'.price(price2num($totalvalue, 'MT')).'</td>';
657  if (empty($conf->global->PRODUIT_MULTIPRICES))
658  {
659  print '<td class="liste_total">&nbsp;</td>';
660  print '<td class="liste_total right">'.price(price2num($totalvaluesell, 'MT')).'</td>';
661  }
662  print '<td class="liste_total">&nbsp;</td>';
663  print '<td class="liste_total">&nbsp;</td>';
664  print '</tr>';
665  } else {
666  dol_print_error($db);
667  }
668  print "</table>\n";
669  }
670 
671 
672  /*
673  * Edition fiche
674  */
675  if ($action == 'edit' || $action == 're-edit')
676  {
677  $langs->trans("WarehouseEdit");
678 
679  print '<form action="card.php" method="POST">';
680  print '<input type="hidden" name="token" value="'.newToken().'">';
681  print '<input type="hidden" name="action" value="update">';
682  print '<input type="hidden" name="id" value="'.$object->id.'">';
683 
684  $head = stock_prepare_head($object);
685 
686  print dol_get_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock');
687 
688  print '<table class="border centpercent">';
689 
690  // Ref
691  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input name="libelle" size="20" value="'.$object->label.'"></td></tr>';
692 
693  print '<tr><td>'.$langs->trans("LocationSummary").'</td><td><input name="lieu" class="minwidth300" value="'.$object->lieu.'"></td></tr>';
694 
695  // Parent entrepot
696  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
697  print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1);
698  print '</td></tr>';
699 
700  // Description
701  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
702  // Editeur wysiwyg
703  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
704  $doleditor = new DolEditor('desc', $object->description, '', 180, 'dolibarr_notes', 'In', false, true, $conf->fckeditor->enabled, ROWS_5, '90%');
705  $doleditor->Create();
706  print '</td></tr>';
707 
708  print '<tr><td>'.$langs->trans('Address').'</td><td><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
709  print $object->address;
710  print '</textarea></td></tr>';
711 
712  // Zip / Town
713  print '<tr><td>'.$langs->trans('Zip').'</td><td>';
714  print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
715  print '</td></tr>';
716  print '<tr><td>'.$langs->trans('Town').'</td><td>';
717  print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
718  print '</td></tr>';
719 
720  // Country
721  print '<tr><td>'.$langs->trans('Country').'</td><td>';
722  print img_picto('', 'globe-americas', 'class="paddingright"');
723  print $form->select_country($object->country_id ? $object->country_id : $mysoc->country_code, 'country_id');
724  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
725  print '</td></tr>';
726 
727  // Phone / Fax
728  print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td><td>';
729  print img_picto('', 'object_phoning', 'class="paddingright"');
730  print '<input name="phone" size="20" value="'.$object->phone.'"></td></tr>';
731  print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td><td>';
732  print img_picto('', 'object_phoning_fax', 'class="paddingright"');
733  print '<input name="fax" size="20" value="'.$object->fax.'"></td></tr>';
734 
735  // Status
736  print '<tr><td>'.$langs->trans("Status").'</td><td>';
737  print '<select name="statut" class="flat">';
738  foreach ($object->statuts as $key => $value)
739  {
740  if ($key == $object->statut)
741  {
742  print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
743  } else {
744  print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
745  }
746  }
747  print '</select>';
748  print '</td></tr>';
749 
750  // Other attributes
751  $parameters = array('colspan' => ' colspan="3"', 'cols' => '3');
752  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
753  print $hookmanager->resPrint;
754  if (empty($reshook))
755  {
756  print $object->showOptionals($extrafields, 'edit', $parameters);
757  }
758 
759  // Tags-Categories
760  if ($conf->categorie->enabled)
761  {
762  print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td colspan="3">';
763  $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1);
764  $c = new Categorie($db);
765  $cats = $c->containing($object->id, Categorie::TYPE_WAREHOUSE);
766  $arrayselected = array();
767  foreach ($cats as $cat) {
768  $arrayselected[] = $cat->id;
769  }
770  print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
771  print "</td></tr>";
772  }
773 
774  print '</table>';
775 
776  print dol_get_fiche_end();
777 
778  print '<div class="center">';
779  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
780  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
781  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
782  print '</div>';
783 
784  print '</form>';
785  }
786  }
787 }
788 
789 /*
790  * Documents generated
791  */
792 
793 $modulepart = 'stock';
794 
795 if ($action != 'create' && $action != 'edit' && $action != 'delete')
796 {
797  print '<br>';
798  print '<div class="fichecenter"><div class="fichehalfleft">';
799  print '<a name="builddoc"></a>'; // ancre
800 
801  // Documents
802  $objectref = dol_sanitizeFileName($object->ref);
803  $relativepath = $object->ref.'/'.$objectref.'.pdf';
804  $filedir = $conf->stock->dir_output.'/'.$objectref;
805  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
806  $genallowed = $usercanread;
807  $delallowed = $usercancreate;
808  $modulepart = 'stock';
809 
810  print $formfile->showdocuments($modulepart, $object->ref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object);
811  $somethingshown = $formfile->numoffiles;
812 
813  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
814 
815  $MAXEVENT = 10;
816 
817  $morehtmlright = '<a href="'.DOL_URL_ROOT.'/product/agenda.php?id='.$object->id.'">';
818  $morehtmlright .= $langs->trans("SeeAll");
819  $morehtmlright .= '</a>';
820 
821  // List of actions on element
822  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
823  $formactions = new FormActions($db);
824  $somethingshown = $formactions->showactions($object, 'stock', 0, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for product
825 
826  print '</div></div></div>';
827 }
828 
829 // End of page
830 llxFooter();
831 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
Class to manage building of HTML components.
Class to manage products or services.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
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...
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage categories.
stock_prepare_head($object)
Prepare array with list of tabs.
Definition: stock.lib.php:30
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of &#39;autofocus&#39; HTML5 tag)
Class to manage warehouses.