mouvement.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  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/mouvement.php
  22. * \ingroup stock
  23. * \brief Page to list stock movements
  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/stock/class/mouvementstock.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. $langs->load("products");
  35. $langs->load("stocks");
  36. // Security check
  37. $result=restrictedArea($user,'stock');
  38. $id=GETPOST('id','int');
  39. $product_id=GETPOST("product_id");
  40. $action=GETPOST('action');
  41. $cancel=GETPOST('cancel');
  42. $idproduct = GETPOST('idproduct','int');
  43. $year = GETPOST("year");
  44. $month = GETPOST("month");
  45. $search_movement = GETPOST("search_movement");
  46. $search_product_ref = trim(GETPOST("search_product_ref"));
  47. $search_product = trim(GETPOST("search_product"));
  48. $search_warehouse = trim(GETPOST("search_warehouse"));
  49. $search_inventorycode = trim(GETPOST("search_inventorycode"));
  50. $search_user = trim(GETPOST("search_user"));
  51. $search_batch = trim(GETPOST("search_batch"));
  52. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  53. $page = GETPOST("page",'int');
  54. $sortfield = GETPOST("sortfield",'alpha');
  55. $sortorder = GETPOST("sortorder",'alpha');
  56. if ($page < 0) $page = 0;
  57. $offset = $limit * $page;
  58. if (! $sortfield) $sortfield="m.datem";
  59. if (! $sortorder) $sortorder="DESC";
  60. $pdluoid=GETPOST('pdluoid','int');
  61. // Initialize context for list
  62. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'movementlist';
  63. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  64. $hookmanager->initHooks(array($contextpage));
  65. $extrafields = new ExtraFields($db);
  66. // fetch optionals attributes and labels
  67. $extralabels = $extrafields->fetch_name_optionals_label('movement');
  68. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  69. /*
  70. * Actions
  71. */
  72. if ($cancel) $action=''; // Protection to avoid action for all cancel buttons
  73. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  74. // Do we click on purge search criteria ?
  75. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  76. {
  77. $year='';
  78. $month='';
  79. $search_movement="";
  80. $search_product_ref="";
  81. $search_product="";
  82. $search_warehouse="";
  83. $search_user="";
  84. $search_batch="";
  85. $sall="";
  86. $search_array_options=array();
  87. }
  88. // Correct stock
  89. if ($action == "correct_stock")
  90. {
  91. $product = new Product($db);
  92. if (! empty($product_id)) $result=$product->fetch($product_id);
  93. $error=0;
  94. if (empty($product_id))
  95. {
  96. $error++;
  97. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  98. $action='correction';
  99. }
  100. if (! is_numeric($_POST["nbpiece"]))
  101. {
  102. $error++;
  103. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  104. $action='correction';
  105. }
  106. if (! $error)
  107. {
  108. if ($product->hasbatch())
  109. {
  110. $batch=GETPOST('batch_number');
  111. //$eatby=GETPOST('eatby');
  112. //$sellby=GETPOST('sellby');
  113. $eatby=dol_mktime(12, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear'));
  114. $sellby=dol_mktime(12, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear'));
  115. $result=$product->correct_stock_batch(
  116. $user,
  117. $id,
  118. GETPOST("nbpiece",'int'),
  119. GETPOST("mouvement"),
  120. GETPOST("label",'san_alpha'),
  121. GETPOST('unitprice'),
  122. $eatby,$sellby,$batch,
  123. GETPOST('inventorycode')
  124. ); // We do not change value of stock for a correction
  125. }
  126. else
  127. {
  128. $result=$product->correct_stock(
  129. $user,
  130. $id,
  131. GETPOST("nbpiece",'int'),
  132. GETPOST("mouvement"),
  133. GETPOST("label",'san_alpha'),
  134. GETPOST('unitprice'),
  135. GETPOST('inventorycode')
  136. ); // We do not change value of stock for a correction
  137. }
  138. if ($result > 0)
  139. {
  140. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  141. exit;
  142. }
  143. else
  144. {
  145. $error++;
  146. setEventMessages($product->error, $product->errors, 'errors');
  147. $action='correction';
  148. }
  149. }
  150. if (! $error) $action='';
  151. }
  152. // Transfer stock from a warehouse to another warehouse
  153. if ($action == "transfert_stock" && ! $cancel)
  154. {
  155. $product = new Product($db);
  156. if (! empty($product_id)) $result=$product->fetch($product_id);
  157. if (! (GETPOST("id_entrepot_destination",'int') > 0))
  158. {
  159. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  160. $error++;
  161. $action='transfert';
  162. }
  163. if (empty($product_id))
  164. {
  165. $error++;
  166. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  167. $action='transfert';
  168. }
  169. if (! GETPOST("nbpiece",'int'))
  170. {
  171. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  172. $error++;
  173. $action='transfert';
  174. }
  175. if ($id == GETPOST("id_entrepot_destination",'int'))
  176. {
  177. setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
  178. $error++;
  179. $action='transfert';
  180. }
  181. if (! empty($conf->productbatch->enabled))
  182. {
  183. $product = new Product($db);
  184. $result=$product->fetch($product_id);
  185. if ($product->hasbatch() && ! GETPOST("batch_number"))
  186. {
  187. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
  188. $error++;
  189. $action='transfert';
  190. }
  191. }
  192. if (! $error)
  193. {
  194. if ($id)
  195. {
  196. $object = new Entrepot($db);
  197. $result=$object->fetch($id);
  198. $db->begin();
  199. $product->load_stock('novirtual'); // Load array product->stock_warehouse
  200. // Define value of products moved
  201. $pricesrc=0;
  202. if (isset($product->pmp)) $pricesrc=$product->pmp;
  203. $pricedest=$pricesrc;
  204. if ($product->hasbatch())
  205. {
  206. $pdluo = new Productbatch($db);
  207. if ($pdluoid > 0)
  208. {
  209. $result=$pdluo->fetch($pdluoid);
  210. if ($result)
  211. {
  212. $srcwarehouseid=$pdluo->warehouseid;
  213. $batch=$pdluo->batch;
  214. $eatby=$pdluo->eatby;
  215. $sellby=$pdluo->sellby;
  216. }
  217. else
  218. {
  219. setEventMessages($pdluo->error, $pdluo->errors, 'errors');
  220. $error++;
  221. }
  222. }
  223. else
  224. {
  225. $srcwarehouseid=$id;
  226. $batch=GETPOST('batch_number');
  227. $eatby=$d_eatby;
  228. $sellby=$d_sellby;
  229. }
  230. if (! $error)
  231. {
  232. // Remove stock
  233. $result1=$product->correct_stock_batch(
  234. $user,
  235. $srcwarehouseid,
  236. GETPOST("nbpiece",'int'),
  237. 1,
  238. GETPOST("label",'san_alpha'),
  239. $pricesrc,
  240. $eatby,$sellby,$batch,
  241. GETPOST('inventorycode')
  242. );
  243. // Add stock
  244. $result2=$product->correct_stock_batch(
  245. $user,
  246. GETPOST("id_entrepot_destination",'int'),
  247. GETPOST("nbpiece",'int'),
  248. 0,
  249. GETPOST("label",'san_alpha'),
  250. $pricedest,
  251. $eatby,$sellby,$batch,
  252. GETPOST('inventorycode')
  253. );
  254. }
  255. }
  256. else
  257. {
  258. // Remove stock
  259. $result1=$product->correct_stock(
  260. $user,
  261. $id,
  262. GETPOST("nbpiece"),
  263. 1,
  264. GETPOST("label"),
  265. $pricesrc,
  266. GETPOST('inventorycode')
  267. );
  268. // Add stock
  269. $result2=$product->correct_stock(
  270. $user,
  271. GETPOST("id_entrepot_destination"),
  272. GETPOST("nbpiece"),
  273. 0,
  274. GETPOST("label"),
  275. $pricedest,
  276. GETPOST('inventorycode')
  277. );
  278. }
  279. if (! $error && $result1 >= 0 && $result2 >= 0)
  280. {
  281. $db->commit();
  282. if ($backtopage)
  283. {
  284. header("Location: ".$backtopage);
  285. exit;
  286. }
  287. else
  288. {
  289. header("Location: mouvement.php?id=".$object->id);
  290. exit;
  291. }
  292. }
  293. else
  294. {
  295. setEventMessages($product->error, $product->errors, 'errors');
  296. $db->rollback();
  297. $action='transfert';
  298. }
  299. }
  300. }
  301. }
  302. /*
  303. * View
  304. */
  305. $productstatic=new Product($db);
  306. $warehousestatic=new Entrepot($db);
  307. $movement=new MouvementStock($db);
  308. $userstatic=new User($db);
  309. $form=new Form($db);
  310. $formother=new FormOther($db);
  311. $formproduct=new FormProduct($db);
  312. $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type, p.entity,";
  313. $sql.= " e.label as stock, e.rowid as entrepot_id, e.lieu,";
  314. $sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
  315. $sql.= " m.batch,m.eatby,m.sellby,";
  316. $sql.= " u.login";
  317. $sql.= " FROM (".MAIN_DB_PREFIX."entrepot as e,";
  318. $sql.= " ".MAIN_DB_PREFIX."product as p,";
  319. $sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m)";
  320. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
  321. $sql.= " WHERE m.fk_product = p.rowid";
  322. $sql.= " AND m.fk_entrepot = e.rowid";
  323. $sql.= " AND e.entity IN (".getEntity('stock', 1).")";
  324. if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0";
  325. if ($id > 0) $sql.= " AND e.rowid ='".$id."'";
  326. if ($month > 0)
  327. {
  328. if ($year > 0)
  329. $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  330. else
  331. $sql.= " AND date_format(m.datem, '%m') = '$month'";
  332. }
  333. else if ($year > 0)
  334. {
  335. $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  336. }
  337. if ($idproduct > 0) $sql.= " AND p.rowid = '".$idproduct."'";
  338. if (! empty($search_movement)) $sql.= natural_search('m.label', $search_movement);
  339. if (! empty($search_inventorycode)) $sql.= natural_search('m.inventorycode', $search_inventorycode);
  340. if (! empty($search_product_ref)) $sql.= natural_search('p.ref', $search_product_ref);
  341. if (! empty($search_product)) $sql.= natural_search('p.label', $search_product);
  342. if ($search_warehouse > 0) $sql.= " AND e.rowid = '".$db->escape($search_warehouse)."'";
  343. if (! empty($search_user)) $sql.= natural_search('u.login', $search_user);
  344. if (! empty($search_batch)) $sql.= natural_search('m.batch', $search_batch);
  345. $nbtotalofrecords = 0;
  346. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  347. {
  348. $result = $db->query($sql);
  349. $nbtotalofrecords = $db->num_rows($result);
  350. }
  351. $sql.= $db->order($sortfield,$sortorder);
  352. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  353. //print $sql;
  354. $resql = $db->query($sql);
  355. if ($resql)
  356. {
  357. $num = $db->num_rows($resql);
  358. if ($idproduct)
  359. {
  360. $product = new Product($db);
  361. $product->fetch($idproduct);
  362. }
  363. if ($id > 0)
  364. {
  365. $entrepot = new Entrepot($db);
  366. $result = $entrepot->fetch($id);
  367. if ($result < 0)
  368. {
  369. dol_print_error($db);
  370. }
  371. }
  372. $i = 0;
  373. $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  374. $texte = $langs->trans("ListOfStockMovements");
  375. if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
  376. llxHeader("",$texte,$help_url);
  377. /*
  378. * Show tab only if we ask a particular warehouse
  379. */
  380. if ($id)
  381. {
  382. $head = stock_prepare_head($entrepot);
  383. dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), 0, 'stock');
  384. print '<table class="border" width="100%">';
  385. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">'.$langs->trans("BackToList").'</a>';
  386. // Ref
  387. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  388. print $form->showrefnav($entrepot, 'id', $linkback, 1, 'rowid', 'libelle');
  389. print '</td>';
  390. print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
  391. // Description
  392. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.dol_htmlentitiesbr($entrepot->description).'</td></tr>';
  393. // Address
  394. print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
  395. print $entrepot->address;
  396. print '</td></tr>';
  397. // Town
  398. print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->zip.'</td>';
  399. print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->town.'</td></tr>';
  400. // Country
  401. print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
  402. if (! empty($entrepot->country_code))
  403. {
  404. $img=picto_from_langcode($entrepot->country_code);
  405. print ($img?$img.' ':'');
  406. print $entrepot->country;
  407. }
  408. print '</td></tr>';
  409. // Status
  410. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
  411. $calcproductsunique=$entrepot->nb_different_products();
  412. $calcproducts=$entrepot->nb_products();
  413. // Total nb of different products
  414. print '<tr><td valign="top">'.$langs->trans("NumberOfDifferentProducts").'</td><td colspan="3">';
  415. print empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb'];
  416. print "</td></tr>";
  417. // Nb of products
  418. print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
  419. print empty($calcproducts['nb'])?'0':$calcproducts['nb'];
  420. print "</td></tr>";
  421. // Value
  422. print '<tr><td valign="top">'.$langs->trans("EstimatedStockValueShort").'</td><td colspan="3">';
  423. print price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency);
  424. print "</td></tr>";
  425. // Last movement
  426. $sql = "SELECT MAX(m.datem) as datem";
  427. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  428. $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'";
  429. $resqlbis = $db->query($sql);
  430. if ($resqlbis)
  431. {
  432. $obj = $db->fetch_object($resqlbis);
  433. $lastmovementdate=$db->jdate($obj->datem);
  434. }
  435. else
  436. {
  437. dol_print_error($db);
  438. }
  439. print '<tr><td valign="top">'.$langs->trans("LastMovement").'</td><td colspan="3">';
  440. if ($lastmovementdate)
  441. {
  442. print dol_print_date($lastmovementdate,'dayhour');
  443. }
  444. else
  445. {
  446. print $langs->trans("None");
  447. }
  448. print "</td></tr>";
  449. print "</table>";
  450. dol_fiche_end();
  451. }
  452. /*
  453. * Correct stock
  454. */
  455. if ($action == "correction")
  456. {
  457. if ($id) $object=$entrepot;
  458. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
  459. print '<br>';
  460. }
  461. /*
  462. * Transfer of units
  463. */
  464. if ($action == "transfert")
  465. {
  466. if ($id) $object=$entrepot;
  467. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
  468. print '<br>';
  469. }
  470. /* ************************************************************************** */
  471. /* */
  472. /* Barre d'action */
  473. /* */
  474. /* ************************************************************************** */
  475. if (empty($action) && $id > 0)
  476. {
  477. print "<div class=\"tabsAction\">\n";
  478. if ($user->rights->stock->mouvement->creer)
  479. {
  480. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("StockCorrection").'</a>';
  481. }
  482. if ($user->rights->stock->mouvement->creer)
  483. {
  484. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("StockTransfer").'</a>';
  485. }
  486. print '</div><br>';
  487. }
  488. $param='';
  489. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  490. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  491. if ($id > 0) $param.='&id='.$id;
  492. if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
  493. if ($search_inventorycode) $param.='&search_inventorycode='.urlencode($search_inventorycode);
  494. if ($search_product_ref) $param.='&search_product_ref='.urlencode($search_product_ref);
  495. if ($search_product) $param.='&search_product='.urlencode($search_product);
  496. if ($search_warehouse > 0) $param.='&search_warehouse='.urlencode($search_warehouse);
  497. if (!empty($sref)) $param.='&sref='.urlencode($sref); // FIXME $sref is not defined
  498. if (!empty($snom)) $param.='&snom='.urlencode($snom); // FIXME $snom is not defined
  499. if ($search_user) $param.='&search_user='.urlencode($search_user);
  500. if ($idproduct > 0) $param.='&idproduct='.$idproduct;
  501. // Add $param from extra fields
  502. foreach ($search_array_options as $key => $val)
  503. {
  504. $crit=$val;
  505. $tmpkey=preg_replace('/search_options_/','',$key);
  506. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  507. }
  508. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  509. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  510. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  511. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  512. print '<input type="hidden" name="action" value="list">';
  513. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  514. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  515. print '<input type="hidden" name="type" value="'.$type.'">';
  516. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  517. if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
  518. if ($id > 0) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $nbtotalofrecords, '', 0, '', '', $limit);
  519. else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit);
  520. print '<table class="noborder" width="100%">';
  521. print "<tr class=\"liste_titre\">";
  522. //print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"], "m.rowid","",$param,"",$sortfield,$sortorder);
  523. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"], "m.datem","",$param,"",$sortfield,$sortorder);
  524. print_liste_field_titre($langs->trans("ProductRef"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
  525. print_liste_field_titre($langs->trans("ProductLabel"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
  526. if (! empty($conf->productbatch->enabled))
  527. {
  528. $langs->load("productbatch");
  529. print_liste_field_titre($langs->trans("BatchNumberShort"),$_SERVER["PHP_SELF"],'m.batch','',$param,'align="center"',$sortfield,$sortorder);
  530. print_liste_field_titre($langs->trans("l_eatby"),$_SERVER["PHP_SELF"],'m.eatby','',$param,'align="center"',$sortfield,$sortorder);
  531. print_liste_field_titre($langs->trans("l_sellby"),$_SERVER["PHP_SELF"],'m.sellby','',$param,'align="center"',$sortfield,$sortorder);
  532. }
  533. if (! $id > 0) print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible
  534. print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
  535. print_liste_field_titre($langs->trans("InventoryCodeShort"),$_SERVER["PHP_SELF"], "m.inventorycode","",$param,"",$sortfield,$sortorder);
  536. print_liste_field_titre($langs->trans("LabelMovement"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder);
  537. print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder);
  538. print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder);
  539. print_liste_field_titre("");
  540. print "</tr>\n";
  541. // Lignes des champs de filtre
  542. print '<tr class="liste_titre">';
  543. print '<td class="liste_titre" valign="right">';
  544. print '<input class="flat" type="text" size="2" maxlength="2" placeholder="'.dol_escape_htmltag($langs->trans("Month")).'" name="month" value="'.$month.'">';
  545. if (empty($conf->productbatch->enabled)) print '&nbsp;';
  546. //else print '<br>';
  547. $syear = $year?$year:-1;
  548. print '<input class="flat" type="text" size="3" maxlength="4" placeholder="'.dol_escape_htmltag($langs->trans("Year")).'" name="year" value="'.($syear > 0 ? $syear : '').'">';
  549. //print $formother->selectyear($syear,'year',1, 20, 5);
  550. print '</td>';
  551. // Product Ref
  552. print '<td class="liste_titre" align="left">';
  553. print '<input class="flat" type="text" size="6" name="search_product_ref" value="'.($idproduct?$product->ref:$search_product_ref).'">';
  554. print '</td>';
  555. // Product label
  556. print '<td class="liste_titre" align="left">';
  557. print '<input class="flat" type="text" size="10" name="search_product" value="'.($idproduct?$product->label:$search_product).'">';
  558. print '</td>';
  559. // Batch
  560. if (! empty($conf->productbatch->enabled))
  561. {
  562. print '<td align="center"><input class="flat" type="text" size="5" name="search_batch" value="'.($search_batch).'"></td>';
  563. print '<td></td>';
  564. print '<td></td>';
  565. }
  566. // Warehouse
  567. if (! $id > 0)
  568. {
  569. print '<td class="liste_titre" align="left">';
  570. //print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
  571. print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1);
  572. print '</td>';
  573. }
  574. // Author
  575. print '<td class="liste_titre" align="left">';
  576. print '<input class="flat" type="text" size="6" name="search_user" value="'.($search_user).'">';
  577. print '</td>';
  578. // Inventory code
  579. print '<td class="liste_titre" align="left">';
  580. print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.$search_inventorycode.'">';
  581. print '</td>';
  582. // Label of movement
  583. print '<td class="liste_titre" align="left">';
  584. print '<input class="flat" type="text" size="8" name="search_movement" value="'.$search_movement.'">';
  585. print '</td>';
  586. // Origin of movement
  587. print '<td class="liste_titre" align="left">';
  588. print '&nbsp; ';
  589. print '</td>';
  590. // Qty
  591. print '<td class="liste_titre" align="left">';
  592. print '&nbsp; ';
  593. print '</td>';
  594. // Actions
  595. print '<td class="liste_titre" align="right">';
  596. $searchpitco=$form->showFilterAndCheckAddButtons(0);
  597. print $searchpitco;
  598. print '</td>';
  599. print "</tr>\n";
  600. $arrayofuniqueproduct=array();
  601. $var=True;
  602. while ($i < min($num,$limit))
  603. {
  604. $objp = $db->fetch_object($resql);
  605. $arrayofuniqueproduct[$objp->rowid]=$objp->produit;
  606. if(!empty($objp->fk_origin)) {
  607. $origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
  608. } else {
  609. $origin = '';
  610. }
  611. $var=!$var;
  612. print "<tr ".$bc[$var].">";
  613. // Id movement
  614. //print '<td>'.$objp->mid.'</td>'; // This is primary not movement id
  615. // Date
  616. print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
  617. // Product ref
  618. print '<td>';
  619. $productstatic->id=$objp->rowid;
  620. $productstatic->ref=$objp->product_ref;
  621. $productstatic->label=$objp->produit;
  622. $productstatic->type=$objp->type;
  623. $productstatic->entity=$objp->entity;
  624. print $productstatic->getNomUrl(1,'stock',16);
  625. print "</td>\n";
  626. // Product label
  627. print '<td>';
  628. /*$productstatic->id=$objp->rowid;
  629. $productstatic->ref=$objp->produit;
  630. $productstatic->type=$objp->type;
  631. print $productstatic->getNomUrl(1,'',16);*/
  632. print $productstatic->label;
  633. print "</td>\n";
  634. // Batch
  635. if (! empty($conf->productbatch->enabled))
  636. {
  637. print '<td align="center">'.$objp->batch.'</td>';
  638. print '<td align="center">'. dol_print_date($objp->eatby,'day') .'</td>';
  639. print '<td align="center">'. dol_print_date($objp->sellby,'day') .'</td>';
  640. }
  641. // Warehouse
  642. if (! $id > 0)
  643. {
  644. print '<td>';
  645. $warehousestatic->id=$objp->entrepot_id;
  646. $warehousestatic->libelle=$objp->stock;
  647. $warehousestatic->lieu=$objp->lieu;
  648. print $warehousestatic->getNomUrl(1);
  649. print "</td>\n";
  650. }
  651. // Author
  652. print '<td>';
  653. $userstatic->id=$objp->fk_user_author;
  654. $userstatic->lastname=$objp->login;
  655. print $userstatic->getNomUrl(1);
  656. print "</td>\n";
  657. // Inventory code
  658. print '<td>'.$objp->inventorycode.'</td>';
  659. // Label of movement
  660. print '<td>'.$objp->label.'</td>';
  661. // Origin of movement
  662. print '<td>'.$origin.'</td>';
  663. // Value
  664. print '<td align="right">';
  665. if ($objp->value > 0) print '+';
  666. print $objp->value.'</td>';
  667. print '<td></td>';
  668. print "</tr>\n";
  669. $i++;
  670. }
  671. $db->free($resql);
  672. print "</table></form><br>";
  673. // Add number of product when there is a filter on period
  674. if (count($arrayofuniqueproduct) == 1 && is_numeric($year))
  675. {
  676. $productidselected=0;
  677. foreach ($arrayofuniqueproduct as $key => $val)
  678. {
  679. $productidselected=$key;
  680. $productlabelselected=$val;
  681. }
  682. $datebefore=dol_get_first_day($year?$year:strftime("%Y",time()), $month?$month:1, true);
  683. $dateafter=dol_get_last_day($year?$year:strftime("%Y",time()), $month?$month:12, true);
  684. $balancebefore=$movement->calculateBalanceForProductBefore($productidselected, $datebefore);
  685. $balanceafter=$movement->calculateBalanceForProductBefore($productidselected, $dateafter);
  686. //print '<tr class="total"><td class="liste_total">';
  687. print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt'));
  688. //print '</td>';
  689. //print '<td class="liste_total" colspan="6" align="right">';
  690. print ': '.$balancebefore;
  691. print "<br>\n";
  692. //print '</td></tr>';
  693. //print '<tr class="total"><td class="liste_total">';
  694. print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt'));
  695. //print '</td>';
  696. //print '<td class="liste_total" colspan="6" align="right">';
  697. print ': '.$balanceafter;
  698. print "<br>\n";
  699. //print '</td></tr>';
  700. }
  701. }
  702. else
  703. {
  704. dol_print_error($db);
  705. }
  706. llxFooter();
  707. $db->close();