reception.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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')) {
  74. accessforbidden();
  75. }
  76. /*
  77. * View
  78. */
  79. $receptionstatic = new Reception($db);
  80. $societestatic = new Societe($db);
  81. $form = new Form($db);
  82. $formother = new FormOther($db);
  83. if ($id > 0 || !empty($ref)) {
  84. $object = new Productlot($db);
  85. if ($ref) {
  86. $tmp = explode('_', $ref);
  87. $objectid = $tmp[0];
  88. $batch = $tmp[1];
  89. }
  90. $result = $object->fetch($id, $objectid, $batch);
  91. $parameters = array('id'=>$id);
  92. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  93. if ($reshook < 0) {
  94. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  95. }
  96. $title = $langs->trans('ProductServiceCard');
  97. $helpurl = '';
  98. $shortlabel = dol_trunc($object->batch, 16);
  99. $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
  100. llxHeader('', $title, $helpurl);
  101. if ($result > 0) {
  102. $head = productlot_prepare_head($object);
  103. $titre = $langs->trans("CardProduct".$object->type);
  104. $picto = 'lot';
  105. print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
  106. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  107. print $hookmanager->resPrint;
  108. if ($reshook < 0) {
  109. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  110. }
  111. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  112. $shownav = 1;
  113. if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
  114. $shownav = 0;
  115. }
  116. dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
  117. print '<div class="fichecenter">';
  118. print '<div class="underbanner clearboth"></div>';
  119. print '<table class="border centpercent tableforfield" width="100%">';
  120. // Product
  121. print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
  122. $producttmp = new Product($db);
  123. $producttmp->fetch($object->fk_product);
  124. print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
  125. print '</td></tr>';
  126. print "</table>";
  127. echo '<br>';
  128. // // Sell by
  129. // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  130. // print '<tr><td>';
  131. // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
  132. // print '</td><td>';
  133. // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
  134. // print '</td>';
  135. // print '</tr>';
  136. // }
  137. //
  138. // // Eat by
  139. // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  140. // print '<tr><td>';
  141. // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
  142. // print '</td><td>';
  143. // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
  144. // print '</td>';
  145. // print '</tr>';
  146. // }
  147. //
  148. // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) {
  149. // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
  150. // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  151. // print '</tr>';
  152. // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
  153. // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  154. // // print '</tr>';
  155. // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
  156. // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  157. // print '</tr>';
  158. // }
  159. //
  160. // // Quality control
  161. // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
  162. // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
  163. // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
  164. // print '</tr>';
  165. // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
  166. // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
  167. // print '</tr>';
  168. // }
  169. //
  170. // // Other attributes
  171. // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  172. print '<table class="border centpercent tableforfield" width="100%">';
  173. $nboflines = show_stats_for_batch($object, $socid);
  174. print "</table>";
  175. print '</div>';
  176. print '<div class="clearboth"></div>';
  177. print dol_get_fiche_end();
  178. if ($showmessage && $nboflines > 1) {
  179. print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
  180. } elseif ($user->hasRight('reception', 'lire')) {
  181. $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
  182. $sql .= " recep.ref, recep.date_creation, recep.fk_statut as statut, recep.rowid as facid,";
  183. $sql .= " d.qty";
  184. // $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
  185. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  186. $sql .= ", sc.fk_soc, sc.fk_user ";
  187. }
  188. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  189. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as recep ON (recep.fk_soc = s.rowid)";
  190. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as d ON (d.fk_reception = recep.rowid)";
  191. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  192. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  193. }
  194. $sql .= " WHERE recep.entity IN (".getEntity('product').")";
  195. $sql .= " AND d.batch = '".($db->escape($object->batch))."'";
  196. if (!empty($search_month)) {
  197. $sql .= ' AND MONTH(recep.date_creation) IN ('.$db->sanitize($search_month).')';
  198. }
  199. if (!empty($search_year)) {
  200. $sql .= ' AND YEAR(recep.date_creation) IN ('.$db->sanitize($search_year).')';
  201. }
  202. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  203. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  204. }
  205. if ($socid) {
  206. $sql .= " AND recep.fk_soc = ".((int) $socid);
  207. }
  208. $sql .= $db->order($sortfield, $sortorder);
  209. // Calcul total qty and amount for global if full scan list
  210. $total_ht = 0;
  211. $total_qty = 0;
  212. // Count total nb of records
  213. $totalofrecords = '';
  214. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  215. $result = $db->query($sql);
  216. $totalofrecords = $db->num_rows($result);
  217. }
  218. $sql .= $db->plimit($limit + 1, $offset);
  219. $result = $db->query($sql);
  220. if ($result) {
  221. $num = $db->num_rows($result);
  222. $option .= '&id='.$object->id;
  223. if ($limit > 0 && $limit != $conf->liste_limit) {
  224. $option .= '&limit='.((int) $limit);
  225. }
  226. if (!empty($search_month)) {
  227. $option .= '&search_month='.urlencode($search_month);
  228. }
  229. if (!empty($search_year)) {
  230. $option .= '&search_year='.urlencode($search_year);
  231. }
  232. print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
  233. print '<input type="hidden" name="token" value="'.newToken().'">';
  234. if (!empty($sortfield)) {
  235. print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
  236. }
  237. if (!empty($sortorder)) {
  238. print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
  239. }
  240. print_barre_liste($langs->trans("Receptions"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
  241. if (!empty($page)) {
  242. $option .= '&page='.urlencode($page);
  243. }
  244. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  245. print '<div class="divsearchfield">';
  246. print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
  247. print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
  248. print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
  249. print '<div style="vertical-align: middle; display: inline-block">';
  250. 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")).'">';
  251. 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")).'">';
  252. print '</div>';
  253. print '</div>';
  254. print '</div>';
  255. $i = 0;
  256. print '<div class="div-table-responsive">';
  257. print '<table class="tagtable liste listwithfilterbefore" width="100%">';
  258. print '<tr class="liste_titre">';
  259. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
  260. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
  261. print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
  262. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "recep.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
  263. print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
  264. // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
  265. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "recep.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
  266. print "</tr>\n";
  267. if ($num > 0) {
  268. while ($i < min($num, $limit)) {
  269. $objp = $db->fetch_object($result);
  270. $total_ht += $objp->total_ht;
  271. $total_qty += $objp->qty;
  272. $receptionstatic->id = $objp->facid;
  273. $receptionstatic->ref = $objp->ref;
  274. $societestatic->fetch($objp->socid);
  275. // $paiement = $receptionstatic->getSommePaiement();
  276. print '<tr class="oddeven">';
  277. print '<td>';
  278. print $receptionstatic->getNomUrl(1);
  279. print "</td>\n";
  280. print '<td>'.$societestatic->getNomUrl(1).'</td>';
  281. print "<td>".$objp->code_fournisseur."</td>\n";
  282. print '<td class="center">';
  283. print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
  284. print '<td class="center">'.$objp->qty."</td>\n";
  285. // print '<td align="right">'.price($objp->total_ht)."</td>\n";
  286. print '<td align="right">'.$receptionstatic->LibStatut($objp->statut, 5).'</td>';
  287. print "</tr>\n";
  288. $i++;
  289. }
  290. }
  291. print '<tr class="liste_total">';
  292. if ($num < $limit) {
  293. print '<td class="left">'.$langs->trans("Total").'</td>';
  294. } else {
  295. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  296. }
  297. print '<td colspan="2"></td>';
  298. print '<td></td>';
  299. print '<td class="center">'.$total_qty.'</td>';
  300. print '<td></td>';
  301. print "</table>";
  302. print '</div>';
  303. print '</form>';
  304. } else {
  305. dol_print_error($db);
  306. }
  307. $db->free($result);
  308. }
  309. }
  310. } else {
  311. dol_print_error();
  312. }
  313. // End of page
  314. llxFooter();
  315. $db->close();