expedition.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/expedition.php
  24. * \ingroup product service facture
  25. * \brief Page of expedition 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.'/expedition/class/expedition.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('batchproductstatsexpedition'));
  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 = "exp.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. $expeditionstatic = new Expedition($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. $helpurl = '';
  97. $shortlabel = dol_trunc($object->batch, 16);
  98. $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
  99. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  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('expedition', 'lire')) {
  181. $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
  182. $sql .= " exp.ref, exp.date_creation, exp.fk_statut as statut, exp.rowid as facid,";
  183. $sql .= " d.rowid, db.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."expedition as exp ON (exp.fk_soc = s.rowid)";
  190. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet as d ON (d.fk_expedition = exp.rowid)";
  191. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as db ON (db.fk_expeditiondet = d.rowid)";
  192. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  193. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  194. }
  195. $sql .= " WHERE exp.entity IN (".getEntity('product').")";
  196. $sql .= " AND db.batch = '".($db->escape($object->batch))."'";
  197. if (!empty($search_month)) {
  198. $sql .= ' AND MONTH(exp.date_creation) IN ('.$db->sanitize($search_month).')';
  199. }
  200. if (!empty($search_year)) {
  201. $sql .= ' AND YEAR(exp.date_creation) IN ('.$db->sanitize($search_year).')';
  202. }
  203. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  204. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  205. }
  206. if ($socid) {
  207. $sql .= " AND exp.fk_soc = ".((int) $socid);
  208. }
  209. $sql .= $db->order($sortfield, $sortorder);
  210. // Calcul total qty and amount for global if full scan list
  211. $total_ht = 0;
  212. $total_qty = 0;
  213. // Count total nb of records
  214. $totalofrecords = '';
  215. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  216. $result = $db->query($sql);
  217. $totalofrecords = $db->num_rows($result);
  218. }
  219. $sql .= $db->plimit($limit + 1, $offset);
  220. $result = $db->query($sql);
  221. if ($result) {
  222. $num = $db->num_rows($result);
  223. $option .= '&id='.$object->id;
  224. if ($limit > 0 && $limit != $conf->liste_limit) {
  225. $option .= '&limit='.((int) $limit);
  226. }
  227. if (!empty($search_month)) {
  228. $option .= '&search_month='.urlencode($search_month);
  229. }
  230. if (!empty($search_year)) {
  231. $option .= '&search_year='.urlencode($search_year);
  232. }
  233. print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
  234. print '<input type="hidden" name="token" value="'.newToken().'">';
  235. if (!empty($sortfield)) {
  236. print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
  237. }
  238. if (!empty($sortorder)) {
  239. print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
  240. }
  241. print_barre_liste($langs->trans("Shipments"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
  242. if (!empty($page)) {
  243. $option .= '&page='.urlencode($page);
  244. }
  245. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  246. print '<div class="divsearchfield">';
  247. print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
  248. print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
  249. print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
  250. print '<div style="vertical-align: middle; display: inline-block">';
  251. 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")).'">';
  252. 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")).'">';
  253. print '</div>';
  254. print '</div>';
  255. print '</div>';
  256. $i = 0;
  257. print '<div class="div-table-responsive">';
  258. print '<table class="tagtable liste listwithfilterbefore" width="100%">';
  259. print '<tr class="liste_titre">';
  260. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
  261. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
  262. print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
  263. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "exp.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
  264. print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
  265. // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
  266. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "exp.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
  267. print "</tr>\n";
  268. if ($num > 0) {
  269. while ($i < min($num, $limit)) {
  270. $objp = $db->fetch_object($result);
  271. $total_ht += $objp->total_ht;
  272. $total_qty += $objp->qty;
  273. $expeditionstatic->id = $objp->facid;
  274. $expeditionstatic->ref = $objp->ref;
  275. $societestatic->fetch($objp->socid);
  276. // $paiement = $expeditionstatic->getSommePaiement();
  277. print '<tr class="oddeven">';
  278. print '<td>';
  279. print $expeditionstatic->getNomUrl(1);
  280. print "</td>\n";
  281. print '<td>'.$societestatic->getNomUrl(1).'</td>';
  282. print "<td>".$objp->code_client."</td>\n";
  283. print '<td class="center">';
  284. print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
  285. print '<td class="center">'.$objp->qty."</td>\n";
  286. // print '<td align="right">'.price($objp->total_ht)."</td>\n";
  287. print '<td align="right">'.$expeditionstatic->LibStatut($objp->statut, 5).'</td>';
  288. print "</tr>\n";
  289. $i++;
  290. }
  291. }
  292. print '<tr class="liste_total">';
  293. if ($num < $limit) {
  294. print '<td class="left">'.$langs->trans("Total").'</td>';
  295. } else {
  296. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  297. }
  298. print '<td colspan="2"></td>';
  299. print '<td></td>';
  300. print '<td class="center">'.$total_qty.'</td>';
  301. print '<td></td>';
  302. print "</table>";
  303. print '</div>';
  304. print '</form>';
  305. } else {
  306. dol_print_error($db);
  307. }
  308. $db->free($result);
  309. }
  310. }
  311. } else {
  312. dol_print_error();
  313. }
  314. // End of page
  315. llxFooter();
  316. $db->close();