mouvement.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. $page = GETPOST("page",'int');
  53. $sortfield = GETPOST("sortfield",'alpha');
  54. $sortorder = GETPOST("sortorder",'alpha');
  55. if ($page < 0) $page = 0;
  56. $offset = $conf->liste_limit * $page;
  57. if (! $sortfield) $sortfield="m.datem";
  58. if (! $sortorder) $sortorder="DESC";
  59. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  60. {
  61. $year='';
  62. $month='';
  63. $search_movement="";
  64. $search_product_ref="";
  65. $search_product="";
  66. $search_warehouse="";
  67. $search_user="";
  68. $search_batch="";
  69. $sall="";
  70. }
  71. /*
  72. * Actions
  73. */
  74. if ($cancel) $action=''; // Protection to avoid action for all cancel buttons
  75. // Correct stock
  76. if ($action == "correct_stock")
  77. {
  78. $product = new Product($db);
  79. if (! empty($product_id)) $result=$product->fetch($product_id);
  80. $error=0;
  81. if (empty($product_id))
  82. {
  83. $error++;
  84. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), 'errors');
  85. $action='correction';
  86. }
  87. if (! is_numeric($_POST["nbpiece"]))
  88. {
  89. $error++;
  90. setEventMessage($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), 'errors');
  91. $action='correction';
  92. }
  93. if (! $error)
  94. {
  95. if ($product->hasbatch())
  96. {
  97. $batch=GETPOST('batch_number');
  98. $eatby=GETPOST('eatby');
  99. $sellby=GETPOST('sellby');
  100. $result=$product->correct_stock_batch(
  101. $user,
  102. $id,
  103. GETPOST("nbpiece",'int'),
  104. GETPOST("mouvement"),
  105. GETPOST("label",'san_alpha'),
  106. GETPOST('unitprice'),
  107. $eatby,$sellby,$batch,
  108. GETPOST('inventorycode')
  109. ); // We do not change value of stock for a correction
  110. }
  111. else
  112. {
  113. $result=$product->correct_stock(
  114. $user,
  115. $id,
  116. GETPOST("nbpiece",'int'),
  117. GETPOST("mouvement"),
  118. GETPOST("label",'san_alpha'),
  119. GETPOST('unitprice'),
  120. GETPOST('inventorycode')
  121. ); // We do not change value of stock for a correction
  122. }
  123. if ($result > 0)
  124. {
  125. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  126. exit;
  127. }
  128. else
  129. {
  130. $error++;
  131. setEventMessages($product->error, $product->errors, 'errors');
  132. $action='correction';
  133. }
  134. }
  135. if (! $error) $action='';
  136. }
  137. /*
  138. * View
  139. */
  140. $productstatic=new Product($db);
  141. $warehousestatic=new Entrepot($db);
  142. $movement=new MouvementStock($db);
  143. $userstatic=new User($db);
  144. $form=new Form($db);
  145. $formother=new FormOther($db);
  146. $formproduct=new FormProduct($db);
  147. $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type,";
  148. $sql.= " e.label as stock, e.rowid as entrepot_id, e.lieu,";
  149. $sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
  150. $sql.= " m.batch,m.eatby,m.sellby,";
  151. $sql.= " u.login";
  152. $sql.= " FROM (".MAIN_DB_PREFIX."entrepot as e,";
  153. $sql.= " ".MAIN_DB_PREFIX."product as p,";
  154. $sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m)";
  155. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
  156. $sql.= " WHERE m.fk_product = p.rowid";
  157. $sql.= " AND m.fk_entrepot = e.rowid";
  158. $sql.= " AND e.entity IN (".getEntity('stock', 1).")";
  159. if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0";
  160. if ($id)
  161. {
  162. $sql.= " AND e.rowid ='".$id."'";
  163. }
  164. if ($month > 0)
  165. {
  166. if ($year > 0)
  167. $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  168. else
  169. $sql.= " AND date_format(m.datem, '%m') = '$month'";
  170. }
  171. else if ($year > 0)
  172. {
  173. $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  174. }
  175. if ($idproduct > 0)
  176. {
  177. $sql.= " AND p.rowid = '".$idproduct."'";
  178. }
  179. if (! empty($search_movement)) $sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
  180. if (! empty($search_inventorycode)) $sql.= " AND m.inventorycode LIKE '%".$db->escape($search_inventorycode)."%'";
  181. if (! empty($search_product_ref)) $sql.= " AND p.ref LIKE '%".$db->escape($search_product_ref)."%'";
  182. if (! empty($search_product)) $sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'";
  183. if (! empty($search_warehouse)) $sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'";
  184. if (! empty($search_user)) $sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'";
  185. if (! empty($search_batch)) $sql.= " AND m.batch LIKE '%".$db->escape($search_batch)."%'";
  186. $sql.= $db->order($sortfield,$sortorder);
  187. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  188. //print $sql;
  189. $resql = $db->query($sql);
  190. if ($resql)
  191. {
  192. $num = $db->num_rows($resql);
  193. if ($idproduct)
  194. {
  195. $product = new Product($db);
  196. $product->fetch($idproduct);
  197. }
  198. if ($id > 0)
  199. {
  200. $entrepot = new Entrepot($db);
  201. $result = $entrepot->fetch($id);
  202. if ($result < 0)
  203. {
  204. dol_print_error($db);
  205. }
  206. }
  207. $i = 0;
  208. $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  209. $texte = $langs->trans("ListOfStockMovements");
  210. if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
  211. llxHeader("",$texte,$help_url);
  212. /*
  213. * Show tab only if we ask a particular warehouse
  214. */
  215. if ($id)
  216. {
  217. $head = stock_prepare_head($entrepot);
  218. dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), 0, 'stock');
  219. print '<table class="border" width="100%">';
  220. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php">'.$langs->trans("BackToList").'</a>';
  221. // Ref
  222. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  223. print $form->showrefnav($entrepot, 'id', $linkback, 1, 'rowid', 'libelle');
  224. print '</td>';
  225. print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
  226. // Description
  227. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.dol_htmlentitiesbr($entrepot->description).'</td></tr>';
  228. // Address
  229. print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
  230. print $entrepot->address;
  231. print '</td></tr>';
  232. // Town
  233. print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->zip.'</td>';
  234. print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->town.'</td></tr>';
  235. // Country
  236. print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
  237. if (! empty($entrepot->country_code))
  238. {
  239. $img=picto_from_langcode($entrepot->country_code);
  240. print ($img?$img.' ':'');
  241. print $entrepot->country;
  242. }
  243. print '</td></tr>';
  244. // Status
  245. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
  246. $calcproductsunique=$entrepot->nb_different_products();
  247. $calcproducts=$entrepot->nb_products();
  248. // Total nb of different products
  249. print '<tr><td valign="top">'.$langs->trans("NumberOfDifferentProducts").'</td><td colspan="3">';
  250. print empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb'];
  251. print "</td></tr>";
  252. // Nb of products
  253. print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
  254. print empty($calcproducts['nb'])?'0':$calcproducts['nb'];
  255. print "</td></tr>";
  256. // Value
  257. print '<tr><td valign="top">'.$langs->trans("EstimatedStockValueShort").'</td><td colspan="3">';
  258. print price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency);
  259. print "</td></tr>";
  260. // Last movement
  261. $sql = "SELECT MAX(m.datem) as datem";
  262. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  263. $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'";
  264. $resqlbis = $db->query($sql);
  265. if ($resqlbis)
  266. {
  267. $obj = $db->fetch_object($resqlbis);
  268. $lastmovementdate=$db->jdate($obj->datem);
  269. }
  270. else
  271. {
  272. dol_print_error($db);
  273. }
  274. print '<tr><td valign="top">'.$langs->trans("LastMovement").'</td><td colspan="3">';
  275. if ($lastmovementdate)
  276. {
  277. print dol_print_date($lastmovementdate,'dayhour');
  278. }
  279. else
  280. {
  281. print $langs->trans("None");
  282. }
  283. print "</td></tr>";
  284. print "</table>";
  285. dol_fiche_end();
  286. }
  287. /*
  288. * Correct stock
  289. */
  290. if ($action == "correction")
  291. {
  292. if ($id) $object=$entrepot;
  293. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
  294. print '<br>';
  295. }
  296. /*
  297. * Transfer of units
  298. */
  299. if ($action == "transfert")
  300. {
  301. if ($id) $object=$entrepot;
  302. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
  303. print '<br>';
  304. }
  305. /*
  306. * Correct stock
  307. */
  308. /*
  309. if ($action == "correction")
  310. {
  311. print_titre($langs->trans("StockCorrection"));
  312. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  313. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  314. print '<input type="hidden" name="action" value="correct_stock">';
  315. print '<table class="border" width="100%">';
  316. // Product
  317. print '<tr>';
  318. print '<td width="20%">'.$langs->trans("Product").'</td>';
  319. print '<td width="20%">';
  320. print $form->select_produits(GETPOST('productid'),'product_id',(empty($conf->global->STOCK_SUPPORTS_SERVICES)?'0':''));
  321. print '</td>';
  322. print '<td width="20%">';
  323. print '<select name="mouvement" class="flat">';
  324. print '<option value="0">'.$langs->trans("Add").'</option>';
  325. print '<option value="1">'.$langs->trans("Delete").'</option>';
  326. print '</select></td>';
  327. print '<td width="20%">'.$langs->trans("NumberOfUnit").'</td><td width="20%"><input class="flat" name="nbpiece" size="10" value=""></td>';
  328. print '</tr>';
  329. // Label
  330. print '<tr>';
  331. print '<td width="20%">'.$langs->trans("Label").'</td>';
  332. print '<td colspan="4">';
  333. print '<input type="text" name="label" size="40" value="">';
  334. print '</td>';
  335. print '</tr>';
  336. print '</table>';
  337. print '<div class="center">';
  338. print '<input type="submit" class="button" value="'.$langs->trans('Save').'">';
  339. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  340. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  341. print '</div>';
  342. print '</form>';
  343. }
  344. if ($action == "transfert")
  345. {
  346. print_titre($langs->trans("Transfer"));
  347. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  348. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  349. print '<input type="hidden" name="action" value="transfert_stock">';
  350. print '<table class="border" width="100%">';
  351. print '<tr>';
  352. print '<td width="20%">'.$langs->trans("Product").'</td>';
  353. print '<td width="20%">';
  354. print $form->select_produits(GETPOST('productid'),'product_id');
  355. print '</td>';
  356. print '<td width="20%">'.$langs->trans("WarehouseTarget").'</td><td width="20%">';
  357. print $formproduct->selectWarehouses('','id_entrepot_destination','',1);
  358. print '</td>';
  359. print '<td width="20%">'.$langs->trans("NumberOfUnit").'</td><td width="20%"><input name="nbpiece" size="10" value=""></td>';
  360. print '</tr>';
  361. // Label
  362. print '<tr>';
  363. print '<td width="20%">'.$langs->trans("Label").'</td>';
  364. print '<td colspan="5">';
  365. print '<input type="text" name="label" size="40" value="">';
  366. print '</td>';
  367. print '</tr>';
  368. print '</table>';
  369. print '<div class="center">';
  370. print '<input type="submit" class="button" value="'.$langs->trans('Save').'">';
  371. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  372. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  373. print '</div>';
  374. print '</form>';
  375. }
  376. */
  377. /* ************************************************************************** */
  378. /* */
  379. /* Barre d'action */
  380. /* */
  381. /* ************************************************************************** */
  382. if (empty($action) && $id)
  383. {
  384. print "<div class=\"tabsAction\">\n";
  385. if ($user->rights->stock->mouvement->creer)
  386. {
  387. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("StockCorrection").'</a>';
  388. }
  389. /*if ($user->rights->stock->mouvement->creer)
  390. {
  391. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("StockMovement").'</a>';
  392. }*/
  393. print '</div><br>';
  394. }
  395. $param='';
  396. if ($id) $param.='&id='.$id;
  397. if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
  398. if ($search_inventorycode) $param.='&search_inventorycode='.urlencode($search_inventorycode);
  399. if ($search_product_ref) $param.='&search_product_ref='.urlencode($search_product_ref);
  400. if ($search_product) $param.='&search_product='.urlencode($search_product);
  401. if ($search_warehouse) $param.='&search_warehouse='.urlencode($search_warehouse);
  402. if (!empty($sref)) $param.='&sref='.urlencode($sref); // FIXME $sref is not defined
  403. if (!empty($snom)) $param.='&snom='.urlencode($snom); // FIXME $snom is not defined
  404. if ($search_user) $param.='&search_user='.urlencode($search_user);
  405. if ($idproduct > 0) $param.='&idproduct='.$idproduct;
  406. if ($id) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num,0,'');
  407. else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num);
  408. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  409. if ($id) print '<input type="hidden" name="id" value="'.$id.'">';
  410. print '<table class="noborder" width="100%">';
  411. print "<tr class=\"liste_titre\">";
  412. //print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"], "m.rowid","",$param,"",$sortfield,$sortorder);
  413. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"], "m.datem","",$param,"",$sortfield,$sortorder);
  414. print_liste_field_titre($langs->trans("ProductRef"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
  415. print_liste_field_titre($langs->trans("ProductLabel"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
  416. if (! empty($conf->productbatch->enabled))
  417. {
  418. $langs->load("productbatch");
  419. print_liste_field_titre($langs->trans("BatchNumberShort"),$_SERVER["PHP_SELF"],'m.batch','',$param,'align="center"',$sortfield,$sortorder);
  420. print_liste_field_titre($langs->trans("l_eatby"),$_SERVER["PHP_SELF"],'m.eatby','',$param,'align="center"',$sortfield,$sortorder);
  421. print_liste_field_titre($langs->trans("l_sellby"),$_SERVER["PHP_SELF"],'m.sellby','',$param,'align="center"',$sortfield,$sortorder);
  422. }
  423. 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
  424. print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
  425. print_liste_field_titre($langs->trans("InventoryCodeShort"),$_SERVER["PHP_SELF"], "m.inventorycode","",$param,"",$sortfield,$sortorder);
  426. print_liste_field_titre($langs->trans("LabelMovement"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder);
  427. print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder);
  428. print_liste_field_titre($langs->trans("Units"),$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder);
  429. print "</tr>\n";
  430. // Lignes des champs de filtre
  431. print '<tr class="liste_titre">';
  432. print '<td class="liste_titre" valign="right">';
  433. print '<input class="flat" type="text" size="2" maxlength="2" placeholder="'.dol_escape_htmltag($langs->trans("Month")).'" name="month" value="'.$month.'">';
  434. if (empty($conf->productbatch->enabled)) print '&nbsp;';
  435. //else print '<br>';
  436. $syear = $year?$year:-1;
  437. print '<input class="flat" type="text" size="2" maxlength="4" placeholder="'.dol_escape_htmltag($langs->trans("Year")).'" name="year" value="'.($syear > 0 ? $syear : '').'">';
  438. //print $formother->selectyear($syear,'year',1, 20, 5);
  439. print '</td>';
  440. // Product Ref
  441. print '<td class="liste_titre" align="left">';
  442. print '<input class="flat" type="text" size="6" name="search_product_ref" value="'.($idproduct?$product->ref:$search_product_ref).'">';
  443. print '</td>';
  444. // Product label
  445. print '<td class="liste_titre" align="left">';
  446. print '<input class="flat" type="text" size="10" name="search_product" value="'.($idproduct?$product->label:$search_product).'">';
  447. print '</td>';
  448. // Batch
  449. if (! empty($conf->productbatch->enabled))
  450. {
  451. print '<td align="center"><input class="flat" type="text" size="5" name="search_batch" value="'.($search_batch).'"></td>';
  452. print '<td></td>';
  453. print '<td></td>';
  454. }
  455. // Warehouse
  456. print '<td class="liste_titre" align="left">';
  457. print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
  458. print '</td>';
  459. // Author
  460. print '<td class="liste_titre" align="left">';
  461. print '<input class="flat" type="text" size="6" name="search_user" value="'.($search_user).'">';
  462. print '</td>';
  463. // Inventory code
  464. print '<td class="liste_titre" align="left">';
  465. print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.$search_inventorycode.'">';
  466. print '</td>';
  467. // Label of movement
  468. print '<td class="liste_titre" align="left">';
  469. print '<input class="flat" type="text" size="8" name="search_movement" value="'.$search_movement.'">';
  470. print '</td>';
  471. // Origin of movement
  472. print '<td class="liste_titre" align="left">';
  473. print '&nbsp; ';
  474. print '</td>';
  475. print '<td class="liste_titre" align="right">';
  476. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  477. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  478. print '</td>';
  479. print "</tr>\n";
  480. $arrayofuniqueproduct=array();
  481. $var=True;
  482. while ($i < min($num,$conf->liste_limit))
  483. {
  484. $objp = $db->fetch_object($resql);
  485. $arrayofuniqueproduct[$objp->rowid]=$objp->produit;
  486. if(!empty($objp->fk_origin)) {
  487. $origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
  488. } else {
  489. $origin = '';
  490. }
  491. $var=!$var;
  492. print "<tr ".$bc[$var].">";
  493. // Id movement
  494. //print '<td>'.$objp->mid.'</td>'; // This is primary not movement id
  495. // Date
  496. print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
  497. // Product ref
  498. print '<td>';
  499. $productstatic->id=$objp->rowid;
  500. $productstatic->ref=$objp->product_ref;
  501. $productstatic->label=$objp->produit;
  502. $productstatic->type=$objp->type;
  503. print $productstatic->getNomUrl(1,'',16);
  504. print "</td>\n";
  505. // Product label
  506. print '<td>';
  507. $productstatic->id=$objp->rowid;
  508. $productstatic->ref=$objp->produit;
  509. $productstatic->type=$objp->type;
  510. print $productstatic->getNomUrl(1,'',16);
  511. print "</td>\n";
  512. // Batch
  513. if (! empty($conf->productbatch->enabled))
  514. {
  515. print '<td align="center">'.$objp->batch.'</td>';
  516. print '<td align="center">'. dol_print_date($objp->eatby,'day') .'</td>';
  517. print '<td align="center">'. dol_print_date($objp->sellby,'day') .'</td>';
  518. }
  519. // Warehouse
  520. print '<td>';
  521. $warehousestatic->id=$objp->entrepot_id;
  522. $warehousestatic->libelle=$objp->stock;
  523. $warehousestatic->lieu=$objp->lieu;
  524. print $warehousestatic->getNomUrl(1);
  525. print "</td>\n";
  526. // Author
  527. print '<td>';
  528. $userstatic->id=$objp->fk_user_author;
  529. $userstatic->lastname=$objp->login;
  530. print $userstatic->getNomUrl(1);
  531. print "</td>\n";
  532. // Inventory code
  533. print '<td>'.$objp->inventorycode.'</td>';
  534. // Label of movement
  535. print '<td>'.$objp->label.'</td>';
  536. // Origin of movement
  537. print '<td>'.$origin.'</td>';
  538. // Value
  539. print '<td align="right">';
  540. if ($objp->value > 0) print '+';
  541. print $objp->value.'</td>';
  542. print "</tr>\n";
  543. $i++;
  544. }
  545. $db->free($resql);
  546. print "</table></form><br>";
  547. // Add number of product when there is a filter on period
  548. if (count($arrayofuniqueproduct) == 1 && is_numeric($year))
  549. {
  550. $productidselected=0;
  551. foreach ($arrayofuniqueproduct as $key => $val)
  552. {
  553. $productidselected=$key;
  554. $productlabelselected=$val;
  555. }
  556. $datebefore=dol_get_first_day($year?$year:strftime("%Y",time()), $month?$month:1, true);
  557. $dateafter=dol_get_last_day($year?$year:strftime("%Y",time()), $month?$month:12, true);
  558. $balancebefore=$movement->calculateBalanceForProductBefore($productidselected, $datebefore);
  559. $balanceafter=$movement->calculateBalanceForProductBefore($productidselected, $dateafter);
  560. //print '<tr class="total"><td class="liste_total">';
  561. print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt'));
  562. //print '</td>';
  563. //print '<td class="liste_total" colspan="6" align="right">';
  564. print ': '.$balancebefore;
  565. print "<br>\n";
  566. //print '</td></tr>';
  567. //print '<tr class="total"><td class="liste_total">';
  568. print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt'));
  569. //print '</td>';
  570. //print '<td class="liste_total" colspan="6" align="right">';
  571. print ': '.$balanceafter;
  572. print "<br>\n";
  573. //print '</td></tr>';
  574. }
  575. }
  576. else
  577. {
  578. dol_print_error($db);
  579. }
  580. llxFooter();
  581. $db->close();