PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stock/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 550 lines | 378 code | 97 blank | 75 comment | 60 complexity | fdf20d3d9dbcc2a0ece84e067ffa7a5f MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2009 Regis Houssin <regis.houssin@capnetworks.com>
  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 <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/product/stock/fiche.php
  22. * \ingroup stock
  23. * \brief Page fiche entrepot
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. $langs->load("products");
  32. $langs->load("stocks");
  33. $langs->load("companies");
  34. $action=GETPOST('action');
  35. $sortfield = GETPOST("sortfield",'alpha');
  36. $sortorder = GETPOST("sortorder",'alpha');
  37. if (! $sortfield) $sortfield="p.ref";
  38. if (! $sortorder) $sortorder="DESC";
  39. $mesg = '';
  40. /*
  41. * Actions
  42. */
  43. // Ajout entrepot
  44. if ($action == 'add' && $user->rights->stock->creer)
  45. {
  46. $object = new Entrepot($db);
  47. $object->ref = $_POST["ref"];
  48. $object->libelle = $_POST["libelle"];
  49. $object->description = $_POST["desc"];
  50. $object->statut = $_POST["statut"];
  51. $object->lieu = $_POST["lieu"];
  52. $object->address = $_POST["address"];
  53. $object->cp = $_POST["zipcode"];
  54. $object->ville = $_POST["town"];
  55. $object->pays_id = $_POST["country_id"];
  56. $object->zip = $_POST["zipcode"];
  57. $object->town = $_POST["town"];
  58. $object->country_id = $_POST["country_id"];
  59. if ($object->libelle) {
  60. $id = $object->create($user);
  61. if ($id > 0)
  62. {
  63. header("Location: fiche.php?id=".$id);
  64. exit;
  65. }
  66. $action = 'create';
  67. $mesg='<div class="error">'.$object->error.'</div>';
  68. }
  69. else {
  70. $mesg='<div class="error">'.$langs->trans("ErrorWarehouseRefRequired").'</div>';
  71. $action="create"; // Force retour sur page creation
  72. }
  73. }
  74. // Delete warehouse
  75. if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->stock->supprimer)
  76. {
  77. $object = new Entrepot($db);
  78. $object->fetch($_REQUEST["id"]);
  79. $result=$object->delete($user);
  80. if ($result > 0)
  81. {
  82. header("Location: ".DOL_URL_ROOT.'/product/stock/liste.php');
  83. exit;
  84. }
  85. else
  86. {
  87. $mesg='<div class="error">'.$object->error.'</div>';
  88. $action='';
  89. }
  90. }
  91. // Modification entrepot
  92. if ($action == 'update' && $_POST["cancel"] <> $langs->trans("Cancel"))
  93. {
  94. $object = new Entrepot($db);
  95. if ($object->fetch($_POST["id"]))
  96. {
  97. $object->libelle = $_POST["libelle"];
  98. $object->description = $_POST["desc"];
  99. $object->statut = $_POST["statut"];
  100. $object->lieu = $_POST["lieu"];
  101. $object->address = $_POST["address"];
  102. $object->cp = $_POST["zipcode"];
  103. $object->ville = $_POST["town"];
  104. $object->pays_id = $_POST["country_id"];
  105. $object->zip = $_POST["zipcode"];
  106. $object->town = $_POST["town"];
  107. $object->country_id = $_POST["country_id"];
  108. if ( $object->update($_POST["id"], $user) > 0)
  109. {
  110. $action = '';
  111. $_GET["id"] = $_POST["id"];
  112. //$mesg = '<div class="ok">Fiche mise a jour</div>';
  113. }
  114. else
  115. {
  116. $action = 'edit';
  117. $_GET["id"] = $_POST["id"];
  118. $mesg = '<div class="error">'.$object->error.'</div>';
  119. }
  120. }
  121. else
  122. {
  123. $action = 'edit';
  124. $_GET["id"] = $_POST["id"];
  125. $mesg = '<div class="error">'.$object->error.'</div>';
  126. }
  127. }
  128. if ($_POST["cancel"] == $langs->trans("Cancel"))
  129. {
  130. $action = '';
  131. $_GET["id"] = $_POST["id"];
  132. }
  133. /*
  134. * View
  135. */
  136. $productstatic=new Product($db);
  137. $form=new Form($db);
  138. $formcompany=new FormCompany($db);
  139. llxHeader("",$langs->trans("WarehouseCard"));
  140. if ($action == 'create')
  141. {
  142. print_fiche_titre($langs->trans("NewWarehouse"));
  143. print "<form action=\"fiche.php\" method=\"post\">\n";
  144. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  145. print '<input type="hidden" name="action" value="add">';
  146. print '<input type="hidden" name="type" value="'.$type.'">'."\n";
  147. dol_htmloutput_mesg($mesg);
  148. print '<table class="border" width="100%">';
  149. // Ref
  150. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="libelle" size="20" value=""></td></tr>';
  151. print '<tr><td >'.$langs->trans("LocationSummary").'</td><td colspan="3"><input name="lieu" size="40" value="'.$object->lieu.'"></td></tr>';
  152. // Description
  153. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  154. // Editeur wysiwyg
  155. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  156. $doleditor=new DolEditor('desc',$object->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70);
  157. $doleditor->Create();
  158. print '</td></tr>';
  159. print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="60" rows="3" wrap="soft">';
  160. print $object->address;
  161. print '</textarea></td></tr>';
  162. // Zip / Town
  163. print '<tr><td>'.$langs->trans('Zip').'</td><td>';
  164. print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
  165. print '</td><td>'.$langs->trans('Town').'</td><td>';
  166. print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','departement_id'));
  167. print '</td></tr>';
  168. // Country
  169. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
  170. print $form->select_country($object->country_id?$object->country_id:$mysoc->country_code,'country_id');
  171. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  172. print '</td></tr>';
  173. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
  174. print '<select name="statut" class="flat">';
  175. print '<option value="0">'.$langs->trans("WarehouseClosed").'</option>';
  176. print '<option value="1" selected="selected">'.$langs->trans("WarehouseOpened").'</option>';
  177. print '</select>';
  178. print '</td></tr>';
  179. print '</table>';
  180. print '<center><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
  181. print '</form>';
  182. }
  183. else
  184. {
  185. if ($_GET["id"])
  186. {
  187. dol_htmloutput_mesg($mesg);
  188. $object = new Entrepot($db);
  189. $result = $object->fetch($_GET["id"]);
  190. if ($result < 0)
  191. {
  192. dol_print_error($db);
  193. }
  194. /*
  195. * Affichage fiche
  196. */
  197. if ($action <> 'edit' && $action <> 're-edit')
  198. {
  199. $head = stock_prepare_head($object);
  200. dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock');
  201. // Confirm delete third party
  202. if ($action == 'delete')
  203. {
  204. $form = new Form($db);
  205. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$object->libelle),"confirm_delete",'',0,2);
  206. if ($ret == 'html') print '<br>';
  207. }
  208. print '<table class="border" width="100%">';
  209. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/liste.php">'.$langs->trans("BackToList").'</a>';
  210. // Ref
  211. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  212. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'libelle');
  213. print '</td>';
  214. print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$object->lieu.'</td></tr>';
  215. // Description
  216. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($object->description).'</td></tr>';
  217. // Address
  218. print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
  219. print $object->address;
  220. print '</td></tr>';
  221. // Ville
  222. print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$object->zip.'</td>';
  223. print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$object->town.'</td></tr>';
  224. // Country
  225. print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
  226. $img=picto_from_langcode($object->country_code);
  227. print ($img?$img.' ':'');
  228. print $object->country;
  229. print '</td></tr>';
  230. // Statut
  231. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  232. $calcproducts=$object->nb_products();
  233. // Nb of products
  234. print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
  235. print empty($calcproducts['nb'])?'0':$calcproducts['nb'];
  236. print "</td></tr>";
  237. // Value
  238. print '<tr><td valign="top">'.$langs->trans("EstimatedStockValueShort").'</td><td colspan="3">';
  239. print empty($calcproducts['value'])?'0':$calcproducts['value'];
  240. print "</td></tr>";
  241. // Last movement
  242. $sql = "SELECT max(m.datem) as datem";
  243. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  244. $sql .= " WHERE m.fk_entrepot = '".$object->id."'";
  245. $resqlbis = $db->query($sql);
  246. if ($resqlbis)
  247. {
  248. $obj = $db->fetch_object($resqlbis);
  249. $lastmovementdate=$db->jdate($obj->datem);
  250. }
  251. else
  252. {
  253. dol_print_error($db);
  254. }
  255. print '<tr><td valign="top">'.$langs->trans("LastMovement").'</td><td colspan="3">';
  256. if ($lastmovementdate)
  257. {
  258. print dol_print_date($lastmovementdate,'dayhour').' ';
  259. print '(<a href="'.DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$object->id.'">'.$langs->trans("FullList").'</a>)';
  260. }
  261. else
  262. {
  263. print $langs->trans("None");
  264. }
  265. print "</td></tr>";
  266. print "</table>";
  267. print '</div>';
  268. /* ************************************************************************** */
  269. /* */
  270. /* Barre d'action */
  271. /* */
  272. /* ************************************************************************** */
  273. print "<div class=\"tabsAction\">\n";
  274. if ($action == '')
  275. {
  276. if ($user->rights->stock->creer)
  277. print "<a class=\"butAction\" href=\"fiche.php?action=edit&id=".$object->id."\">".$langs->trans("Modify")."</a>";
  278. else
  279. print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Modify")."</a>";
  280. if ($user->rights->stock->supprimer)
  281. print "<a class=\"butActionDelete\" href=\"fiche.php?action=delete&id=".$object->id."\">".$langs->trans("Delete")."</a>";
  282. else
  283. print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>";
  284. }
  285. print "</div>";
  286. /* ************************************************************************** */
  287. /* */
  288. /* Affichage de la liste des produits de l'entrepot */
  289. /* */
  290. /* ************************************************************************** */
  291. print '<br>';
  292. print '<table class="noborder" width="100%">';
  293. print "<tr class=\"liste_titre\">";
  294. print_liste_field_titre($langs->trans("Product"),"", "p.ref","&amp;id=".$_GET['id'],"","",$sortfield,$sortorder);
  295. print_liste_field_titre($langs->trans("Label"),"", "p.label","&amp;id=".$_GET['id'],"","",$sortfield,$sortorder);
  296. print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&amp;id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
  297. print_liste_field_titre($langs->trans("AverageUnitPricePMPShort"),"", "ps.pmp","&amp;id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
  298. print_liste_field_titre($langs->trans("EstimatedStockValueShort"),"", "","&amp;id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
  299. if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellPriceMin"),"", "p.price","&amp;id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
  300. if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("EstimatedStockValueSellShort"),"", "","&amp;id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
  301. if ($user->rights->stock->mouvement->creer) print '<td>&nbsp;</td>';
  302. if ($user->rights->stock->creer) print '<td>&nbsp;</td>';
  303. print "</tr>";
  304. $totalunit=0;
  305. $totalvalue=$totalvaluesell=0;
  306. $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc,";
  307. $sql.= " ps.pmp, ps.reel as value";
  308. $sql.= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p";
  309. $sql.= " WHERE ps.fk_product = p.rowid";
  310. $sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
  311. $sql.= " AND ps.fk_entrepot = ".$object->id;
  312. $sql.= $db->order($sortfield,$sortorder);
  313. dol_syslog('List products sql='.$sql);
  314. $resql = $db->query($sql);
  315. if ($resql)
  316. {
  317. $num = $db->num_rows($resql);
  318. $i = 0;
  319. $var=True;
  320. while ($i < $num)
  321. {
  322. $objp = $db->fetch_object($resql);
  323. // Multilangs
  324. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  325. {
  326. $sql = "SELECT label";
  327. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  328. $sql.= " WHERE fk_product=".$objp->rowid;
  329. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  330. $sql.= " LIMIT 1";
  331. $result = $db->query($sql);
  332. if ($result)
  333. {
  334. $objtp = $db->fetch_object($result);
  335. if ($objtp->label != '') $objp->produit = $objtp->label;
  336. }
  337. }
  338. $var=!$var;
  339. //print '<td>'.dol_print_date($objp->datem).'</td>';
  340. print "<tr ".$bc[$var].">";
  341. print "<td>";
  342. $productstatic->id=$objp->rowid;
  343. $productstatic->ref=$objp->ref;
  344. $productstatic->type=$objp->type;
  345. print $productstatic->getNomUrl(1,'stock',16);
  346. print '</td>';
  347. print '<td>'.$objp->produit.'</td>';
  348. print '<td align="right">'.$objp->value.'</td>';
  349. $totalunit+=$objp->value;
  350. // Price buy PMP
  351. print '<td align="right">'.price(price2num($objp->pmp,'MU')).'</td>';
  352. // Total PMP
  353. print '<td align="right">'.price(price2num($objp->pmp*$objp->value,'MT')).'</td>';
  354. $totalvalue+=price2num($objp->pmp*$objp->value,'MT');
  355. // Price sell min
  356. if (empty($conf->global->PRODUIT_MULTIPRICES))
  357. {
  358. $pricemin=$objp->price;
  359. print '<td align="right">';
  360. print price(price2num($pricemin,'MU'));
  361. print '</td>';
  362. // Total sell min
  363. print '<td align="right">';
  364. print price(price2num($pricemin*$objp->value,'MT'));
  365. print '</td>';
  366. }
  367. $totalvaluesell+=price2num($pricemin*$objp->value,'MT');
  368. if ($user->rights->stock->mouvement->creer)
  369. {
  370. print '<td align="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&amp;id='.$objp->rowid.'&amp;action=transfert">';
  371. print img_picto($langs->trans("StockMovement"),'uparrow.png').' '.$langs->trans("StockMovement");
  372. print "</a></td>";
  373. }
  374. if ($user->rights->stock->creer)
  375. {
  376. print '<td align="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&amp;id='.$objp->rowid.'&amp;action=correction">';
  377. print $langs->trans("StockCorrection");
  378. print "</a></td>";
  379. }
  380. print "</tr>";
  381. $i++;
  382. }
  383. $db->free($resql);
  384. print '<tr class="liste_total"><td class="liste_total" colspan="2">'.$langs->trans("Total").'</td>';
  385. print '<td class="liste_total" align="right">'.$totalunit.'</td>';
  386. print '<td class="liste_total">&nbsp;</td>';
  387. print '<td class="liste_total" align="right">'.price(price2num($totalvalue,'MT')).'</td>';
  388. if (empty($conf->global->PRODUIT_MULTIPRICES))
  389. {
  390. print '<td class="liste_total">&nbsp;</td>';
  391. print '<td class="liste_total" align="right">'.price(price2num($totalvaluesell,'MT')).'</td>';
  392. }
  393. print '<td class="liste_total">&nbsp;</td>';
  394. print '<td class="liste_total">&nbsp;</td>';
  395. print '</tr>';
  396. }
  397. else
  398. {
  399. dol_print_error($db);
  400. }
  401. print "</table>\n";
  402. }
  403. /*
  404. * Edition fiche
  405. */
  406. if (($action == 'edit' || $action == 're-edit') && 1)
  407. {
  408. print_fiche_titre($langs->trans("WarehouseEdit"), $mesg);
  409. print '<form action="fiche.php" method="POST">';
  410. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  411. print '<input type="hidden" name="action" value="update">';
  412. print '<input type="hidden" name="id" value="'.$object->id.'">';
  413. print '<table class="border" width="100%">';
  414. // Ref
  415. print '<tr><td width="20%" class="fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="libelle" size="20" value="'.$object->libelle.'"></td></tr>';
  416. print '<tr><td width="20%">'.$langs->trans("LocationSummary").'</td><td colspan="3"><input name="lieu" size="40" value="'.$object->lieu.'"></td></tr>';
  417. // Description
  418. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  419. // Editeur wysiwyg
  420. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  421. $doleditor=new DolEditor('desc',$object->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70);
  422. $doleditor->Create();
  423. print '</td></tr>';
  424. print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="60" rows="3" wrap="soft">';
  425. print $object->address;
  426. print '</textarea></td></tr>';
  427. // Zip / Town
  428. print '<tr><td>'.$langs->trans('Zip').'</td><td>';
  429. print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
  430. print '</td><td>'.$langs->trans('Town').'</td><td>';
  431. print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','departement_id'));
  432. print '</td></tr>';
  433. // Country
  434. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
  435. print $form->select_country($object->country_id?$object->country_id:$mysoc->country_code,'country_id');
  436. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  437. print '</td></tr>';
  438. print '<tr><td width="20%">'.$langs->trans("Status").'</td><td colspan="3">';
  439. print '<select name="statut" class="flat">';
  440. print '<option value="0" '.($object->statut == 0?'selected="selected"':'').'>'.$langs->trans("WarehouseClosed").'</option>';
  441. print '<option value="1" '.($object->statut == 0?'':'selected="selected"').'>'.$langs->trans("WarehouseOpened").'</option>';
  442. print '</select>';
  443. print '</td></tr>';
  444. print '</table>';
  445. print '<center><br><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
  446. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
  447. print '</form>';
  448. }
  449. }
  450. }
  451. llxFooter();
  452. $db->close();
  453. ?>