reception.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/product/stock/stats/reception.php
  24. * \ingroup product service facture
  25. * \brief Page of reception statistics for a batch
  26. */
  27. // Load Dolibarr environment
  28. require '../../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('companies', 'bills', 'products', 'supplier_proposal', 'productbatch'));
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $batch = GETPOST('batch', 'alpha');
  39. $objectid = GETPOST('productid', 'int');
  40. // Security check
  41. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  42. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  43. $socid = '';
  44. if (!empty($user->socid)) {
  45. $socid = $user->socid;
  46. }
  47. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  48. $hookmanager->initHooks(array('batchproductstatsreception'));
  49. $showmessage = GETPOST('showmessage');
  50. // Load variable for pagination
  51. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (!$sortorder) {
  62. $sortorder = "DESC";
  63. }
  64. if (!$sortfield) {
  65. $sortfield = "recep.date_creation";
  66. }
  67. $search_month = GETPOST('search_month', 'int');
  68. $search_year = GETPOST('search_year', 'int');
  69. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  70. $search_month = '';
  71. $search_year = '';
  72. }
  73. if (!$user->hasRight('produit', 'lire')) accessforbidden();
  74. /*
  75. * View
  76. */
  77. $receptionstatic = new Reception($db);
  78. $societestatic = new Societe($db);
  79. $form = new Form($db);
  80. $formother = new FormOther($db);
  81. if ($id > 0 || !empty($ref)) {
  82. $object = new Productlot($db);
  83. if ($ref) {
  84. $tmp = explode('_', $ref);
  85. $objectid = $tmp[0];
  86. $batch = $tmp[1];
  87. }
  88. $result = $object->fetch($id, $objectid, $batch);
  89. $parameters = array('id'=>$id);
  90. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  91. if ($reshook < 0) {
  92. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  93. }
  94. $title = $langs->trans('ProductServiceCard');
  95. $helpurl = '';
  96. $shortlabel = dol_trunc($object->batch, 16);
  97. $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
  98. llxHeader('', $title, $helpurl);
  99. if ($result > 0) {
  100. $head = productlot_prepare_head($object);
  101. $titre = $langs->trans("CardProduct".$object->type);
  102. $picto = 'lot';
  103. print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
  104. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  105. print $hookmanager->resPrint;
  106. if ($reshook < 0) {
  107. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  108. }
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  110. $shownav = 1;
  111. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  112. $shownav = 0;
  113. }
  114. dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
  115. print '<div class="fichecenter">';
  116. print '<div class="underbanner clearboth"></div>';
  117. print '<table class="border centpercent tableforfield" width="100%">';
  118. // Product
  119. print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
  120. $producttmp = new Product($db);
  121. $producttmp->fetch($object->fk_product);
  122. print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
  123. print '</td></tr>';
  124. print "</table>";
  125. echo '<br>';
  126. // // Sell by
  127. // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  128. // print '<tr><td>';
  129. // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
  130. // print '</td><td>';
  131. // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
  132. // print '</td>';
  133. // print '</tr>';
  134. // }
  135. //
  136. // // Eat by
  137. // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  138. // print '<tr><td>';
  139. // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
  140. // print '</td><td>';
  141. // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
  142. // print '</td>';
  143. // print '</tr>';
  144. // }
  145. //
  146. // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) {
  147. // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
  148. // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  149. // print '</tr>';
  150. // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
  151. // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  152. // // print '</tr>';
  153. // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
  154. // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  155. // print '</tr>';
  156. // }
  157. //
  158. // // Quality control
  159. // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
  160. // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
  161. // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  162. // print '</tr>';
  163. // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
  164. // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
  165. // print '</tr>';
  166. // }
  167. //
  168. // // Other attributes
  169. // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  170. print '<table class="border centpercent tableforfield" width="100%">';
  171. $nboflines = show_stats_for_batch($object, $socid);
  172. print "</table>";
  173. print '</div>';
  174. print '<div class="clearboth"></div>';
  175. print dol_get_fiche_end();
  176. if ($showmessage && $nboflines > 1) {
  177. print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
  178. } elseif ($user->hasRight('reception', 'lire')) {
  179. $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
  180. $sql .= " recep.ref, recep.date_creation, recep.fk_statut as statut, recep.rowid as facid,";
  181. $sql .= " d.qty";
  182. // $sql.= ", d.total_ht as total_ht"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used
  183. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  184. $sql .= ", sc.fk_soc, sc.fk_user ";
  185. }
  186. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  187. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as recep ON (recep.fk_soc = s.rowid)";
  188. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as d ON (d.fk_reception = recep.rowid)";
  189. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  190. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  191. }
  192. $sql .= " WHERE recep.entity IN (".getEntity('product').")";
  193. $sql .= " AND d.batch = '".($db->escape($object->batch))."'";
  194. if (!empty($search_month)) {
  195. $sql .= ' AND MONTH(recep.date_creation) IN ('.$db->sanitize($search_month).')';
  196. }
  197. if (!empty($search_year)) {
  198. $sql .= ' AND YEAR(recep.date_creation) IN ('.$db->sanitize($search_year).')';
  199. }
  200. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  201. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  202. }
  203. if ($socid) {
  204. $sql .= " AND recep.fk_soc = ".((int) $socid);
  205. }
  206. $sql .= $db->order($sortfield, $sortorder);
  207. // Calcul total qty and amount for global if full scan list
  208. $total_ht = 0;
  209. $total_qty = 0;
  210. // Count total nb of records
  211. $totalofrecords = '';
  212. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  213. $result = $db->query($sql);
  214. $totalofrecords = $db->num_rows($result);
  215. }
  216. $sql .= $db->plimit($limit + 1, $offset);
  217. $result = $db->query($sql);
  218. if ($result) {
  219. $num = $db->num_rows($result);
  220. $option .= '&id='.$object->id;
  221. if ($limit > 0 && $limit != $conf->liste_limit) {
  222. $option .= '&limit='.((int) $limit);
  223. }
  224. if (!empty($search_month)) {
  225. $option .= '&search_month='.urlencode($search_month);
  226. }
  227. if (!empty($search_year)) {
  228. $option .= '&search_year='.urlencode($search_year);
  229. }
  230. print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
  231. print '<input type="hidden" name="token" value="'.newToken().'">';
  232. if (!empty($sortfield)) {
  233. print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
  234. }
  235. if (!empty($sortorder)) {
  236. print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
  237. }
  238. print_barre_liste($langs->trans("Receptions"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
  239. if (!empty($page)) {
  240. $option .= '&page='.urlencode($page);
  241. }
  242. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  243. print '<div class="divsearchfield">';
  244. print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
  245. print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
  246. print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
  247. print '<div style="vertical-align: middle; display: inline-block">';
  248. print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  249. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  250. print '</div>';
  251. print '</div>';
  252. print '</div>';
  253. $i = 0;
  254. print '<div class="div-table-responsive">';
  255. print '<table class="tagtable liste listwithfilterbefore" width="100%">';
  256. print '<tr class="liste_titre">';
  257. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
  258. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
  259. print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
  260. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "recep.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
  261. print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
  262. // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
  263. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "recep.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
  264. print "</tr>\n";
  265. if ($num > 0) {
  266. while ($i < min($num, $limit)) {
  267. $objp = $db->fetch_object($result);
  268. $total_ht += $objp->total_ht;
  269. $total_qty += $objp->qty;
  270. $receptionstatic->id = $objp->facid;
  271. $receptionstatic->ref = $objp->ref;
  272. $societestatic->fetch($objp->socid);
  273. // $paiement = $receptionstatic->getSommePaiement();
  274. print '<tr class="oddeven">';
  275. print '<td>';
  276. print $receptionstatic->getNomUrl(1);
  277. print "</td>\n";
  278. print '<td>'.$societestatic->getNomUrl(1).'</td>';
  279. print "<td>".$objp->code_fournisseur."</td>\n";
  280. print '<td class="center">';
  281. print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
  282. print '<td class="center">'.$objp->qty."</td>\n";
  283. // print '<td align="right">'.price($objp->total_ht)."</td>\n";
  284. print '<td align="right">'.$receptionstatic->LibStatut($objp->statut, 5).'</td>';
  285. print "</tr>\n";
  286. $i++;
  287. }
  288. }
  289. print '<tr class="liste_total">';
  290. if ($num < $limit) {
  291. print '<td class="left">'.$langs->trans("Total").'</td>';
  292. } else {
  293. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  294. }
  295. print '<td colspan="2"></td>';
  296. print '<td></td>';
  297. print '<td class="center">'.$total_qty.'</td>';
  298. print '<td></td>';
  299. print "</table>";
  300. print '</div>';
  301. print '</form>';
  302. } else {
  303. dol_print_error($db);
  304. }
  305. $db->free($result);
  306. }
  307. }
  308. } else {
  309. dol_print_error();
  310. }
  311. // End of page
  312. llxFooter();
  313. $db->close();