consumption.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. /* Copyright (C) 2012-2013 Philippe Berthet <berthet@systune.be>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2013-2015 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2015-2017 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2021-2022 Frédéric France <frederic.france@netlogic.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/societe/consumption.php
  24. * \ingroup societe
  25. * \brief Add a tab on thirdparty view to list all products/services bought or sells by thirdparty
  26. */
  27. // Load Dolibarr environment
  28. require "../main.inc.php";
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
  35. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
  36. // Security check
  37. $socid = GETPOST('socid', 'int');
  38. if ($user->socid) {
  39. $socid = $user->socid;
  40. }
  41. $result = restrictedArea($user, 'societe', $socid, '&societe');
  42. $object = new Societe($db);
  43. if ($socid > 0) {
  44. $object->fetch($socid);
  45. }
  46. // Sort & Order fields
  47. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  48. $sortfield = GETPOST('sortfield', 'aZ09comma');
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. $optioncss = GETPOST('optioncss', 'alpha');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortorder) {
  59. $sortorder = 'DESC';
  60. }
  61. if (!$sortfield) {
  62. $sortfield = 'dateprint';
  63. }
  64. // Search fields
  65. $sref = GETPOST("sref");
  66. $sprod_fulldescr = GETPOST("sprod_fulldescr");
  67. $month = GETPOST('month', 'int');
  68. $year = GETPOST('year', 'int');
  69. // Clean up on purge search criteria ?
  70. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  71. $sref = '';
  72. $sprod_fulldescr = '';
  73. $year = '';
  74. $month = '';
  75. }
  76. // Customer or supplier selected in drop box
  77. $thirdTypeSelect = GETPOST("third_select_id", 'az09');
  78. $type_element = GETPOST('type_element') ? GETPOST('type_element') : '';
  79. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  80. $hookmanager->initHooks(array('consumptionthirdparty', 'globalcard'));
  81. /*
  82. * Actions
  83. */
  84. $parameters = array('id'=>$socid);
  85. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  86. if ($reshook < 0) {
  87. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  88. }
  89. /*
  90. * View
  91. */
  92. $form = new Form($db);
  93. $formother = new FormOther($db);
  94. $productstatic = new Product($db);
  95. $title = $langs->trans("Referers", $object->name);
  96. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  97. $title = $object->name." - ".$title;
  98. }
  99. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  100. llxHeader('', $title, $help_url);
  101. if (empty($socid)) {
  102. dol_print_error($db);
  103. exit;
  104. }
  105. $head = societe_prepare_head($object);
  106. print dol_get_fiche_head($head, 'consumption', $langs->trans("ThirdParty"), -1, 'company');
  107. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  108. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  109. print '<div class="fichecenter">';
  110. print '<div class="underbanner clearboth"></div>';
  111. print '<table class="border centpercent tableforfield">';
  112. // Type Prospect/Customer/Supplier
  113. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  114. print $object->getTypeUrl(1);
  115. print '</td></tr>';
  116. if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
  117. print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  118. }
  119. //if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'read')) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
  120. $elementTypeArray = array();
  121. if ($object->client) {
  122. print '<tr><td class="titlefield">';
  123. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  124. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  125. $tmpcheck = $object->check_codeclient();
  126. if ($tmpcheck != 0 && $tmpcheck != -5) {
  127. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  128. }
  129. print '</td></tr>';
  130. $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
  131. $resql = $db->query($sql);
  132. if (!$resql) {
  133. dol_print_error($db);
  134. }
  135. $obj = $db->fetch_object($resql);
  136. $nbFactsClient = $obj->nb;
  137. $thirdTypeArray['customer'] = $langs->trans("customer");
  138. if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
  139. $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
  140. }
  141. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  142. $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
  143. }
  144. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  145. $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
  146. }
  147. if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
  148. $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
  149. }
  150. }
  151. if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire')) {
  152. $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
  153. }
  154. if ($object->fournisseur) {
  155. $langs->load("supplier_proposal");
  156. print '<tr><td class="titlefield">';
  157. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  158. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
  159. $tmpcheck = $object->check_codefournisseur();
  160. if ($tmpcheck != 0 && $tmpcheck != -5) {
  161. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  162. }
  163. print '</td></tr>';
  164. $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
  165. $resql = $db->query($sql);
  166. if (!$resql) {
  167. dol_print_error($db);
  168. }
  169. $obj = $db->fetch_object($resql);
  170. $nbCmdsFourn = $obj->nb;
  171. $thirdTypeArray['supplier'] = $langs->trans("supplier");
  172. if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
  173. $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
  174. }
  175. if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
  176. $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
  177. }
  178. if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
  179. $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
  180. }
  181. }
  182. print '</table>';
  183. print '</div>';
  184. print dol_get_fiche_end();
  185. print '<br>';
  186. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
  187. print '<input type="hidden" name="token" value="'.newToken().'">';
  188. $sql_select = '';
  189. $documentstaticline = '';
  190. /*if ($type_element == 'action')
  191. { // Customer : show products from invoices
  192. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  193. $documentstatic=new ActionComm($db);
  194. $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
  195. $tables_from = MAIN_DB_PREFIX."actioncomm as f";
  196. $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
  197. $dateprint = 'f.datep';
  198. $doc_number='f.id';
  199. }*/
  200. if ($type_element == 'fichinter') { // Customer : show products from invoices
  201. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  202. $documentstatic = new Fichinter($db);
  203. $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, NULL as paid, ';
  204. $sql_select .= 'NULL as fk_product, NULL as info_bits, NULL as date_start, NULL as date_end, NULL as prod_qty, NULL as total_ht, ';
  205. $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines.
  206. $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  207. $where .= " AND f.entity = ".$conf->entity;
  208. $dateprint = 'f.datec';
  209. $doc_number = 'f.ref';
  210. }
  211. if ($type_element == 'invoice') { // Customer : show products from invoices
  212. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  213. $documentstatic = new Facture($db);
  214. $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, d.fk_remise_except, ';
  215. $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
  216. $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  217. $where .= " AND d.fk_facture = f.rowid";
  218. $where .= " AND f.entity IN (".getEntity('invoice').")";
  219. $dateprint = 'f.datef';
  220. $doc_number = 'f.ref';
  221. $thirdTypeSelect = 'customer';
  222. }
  223. if ($type_element == 'propal') {
  224. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  225. $documentstatic = new Propal($db);
  226. $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, NULL as paid,';
  227. $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
  228. $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  229. $where .= " AND d.fk_propal = c.rowid";
  230. $where .= " AND c.entity = ".$conf->entity;
  231. $dateprint = 'c.datep';
  232. $doc_number = 'c.ref';
  233. $thirdTypeSelect = 'customer';
  234. }
  235. if ($type_element == 'order') {
  236. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  237. $langs->load('sendings'); // delivery planned date
  238. $documentstatic = new Commande($db);
  239. $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, NULL as paid, c.date_livraison as delivery_planned_date,';
  240. $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
  241. $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  242. $where .= " AND d.fk_commande = c.rowid";
  243. $where .= " AND c.entity = ".$conf->entity;
  244. $dateprint = 'c.date_commande';
  245. $doc_number = 'c.ref';
  246. $thirdTypeSelect = 'customer';
  247. }
  248. if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
  249. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  250. $documentstatic = new FactureFournisseur($db);
  251. $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, ';
  252. $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
  253. $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  254. $where .= " AND d.fk_facture_fourn = f.rowid";
  255. $where .= " AND f.entity = ".$conf->entity;
  256. $dateprint = 'f.datef';
  257. $doc_number = 'f.ref';
  258. $thirdTypeSelect = 'supplier';
  259. }
  260. if ($type_element == 'supplier_proposal') {
  261. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  262. $documentstatic = new SupplierProposal($db);
  263. $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, NULL as paid, ';
  264. $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
  265. $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  266. $where .= " AND d.fk_supplier_proposal = c.rowid";
  267. $where .= " AND c.entity = ".$conf->entity;
  268. $dateprint = 'c.date_valid';
  269. $doc_number = 'c.ref';
  270. $thirdTypeSelect = 'supplier';
  271. }
  272. if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
  273. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  274. $langs->load('sendings'); // delivery planned date
  275. $documentstatic = new CommandeFournisseur($db);
  276. $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, NULL as paid, c.date_livraison as delivery_planned_date, ';
  277. $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
  278. $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  279. $where .= " AND d.fk_commande = c.rowid";
  280. $where .= " AND c.entity = ".$conf->entity;
  281. $dateprint = 'c.date_valid';
  282. $doc_number = 'c.ref';
  283. $thirdTypeSelect = 'supplier';
  284. }
  285. if ($type_element == 'contract') { // Order
  286. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  287. $documentstatic = new Contrat($db);
  288. $documentstaticline = new ContratLigne($db);
  289. $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_contrat as dateprint, d.statut as status, NULL as paid,';
  290. $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
  291. $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
  292. $where .= " AND d.fk_contrat = c.rowid";
  293. $where .= " AND c.entity = ".$conf->entity;
  294. $dateprint = 'c.date_valid';
  295. $doc_number = 'c.ref';
  296. $thirdTypeSelect = 'customer';
  297. }
  298. $parameters = array();
  299. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  300. if (!empty($sql_select)) {
  301. $sql = $sql_select;
  302. $sql .= ' d.description as description,';
  303. if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
  304. $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
  305. }
  306. if ($type_element == 'supplier_proposal') {
  307. $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
  308. }
  309. if ($type_element == 'contract') {
  310. $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
  311. }
  312. if ($type_element != 'fichinter') {
  313. $sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity, ';
  314. }
  315. $sql .= " s.rowid as socid ";
  316. if ($type_element != 'fichinter') {
  317. $sql .= ", p.ref as prod_ref, p.label as product_label";
  318. }
  319. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
  320. if ($type_element != 'fichinter') {
  321. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
  322. }
  323. $sql .= $where;
  324. $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
  325. if ($sref) {
  326. $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
  327. }
  328. if ($sprod_fulldescr) {
  329. // We test both case description is correctly saved of was save after dol_escape_htmltag().
  330. $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
  331. if (GETPOST('type_element') != 'fichinter') {
  332. $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
  333. }
  334. if (GETPOST('type_element') != 'fichinter') {
  335. $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
  336. }
  337. $sql .= ")";
  338. }
  339. $sql .= $db->order($sortfield, $sortorder);
  340. $resql = $db->query($sql);
  341. $totalnboflines = $db->num_rows($resql);
  342. $sql .= $db->plimit($limit + 1, $offset);
  343. //print $sql;
  344. }
  345. $disabled = 0;
  346. $showempty = 2;
  347. if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
  348. $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
  349. $disabled = 1;
  350. }
  351. // Define type of elements
  352. $typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
  353. $button = '<input type="submit" class="button buttonform small" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  354. $total_qty = 0;
  355. $param = '';
  356. if ($sql_select) {
  357. $resql = $db->query($sql);
  358. if (!$resql) {
  359. dol_print_error($db);
  360. }
  361. $num = $db->num_rows($resql);
  362. $param = "&socid=".urlencode($socid)."&type_element=".urlencode($type_element);
  363. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  364. $param .= '&contextpage='.urlencode($contextpage);
  365. }
  366. if ($limit > 0 && $limit != $conf->liste_limit) {
  367. $param .= '&limit='.((int) $limit);
  368. }
  369. if ($sprod_fulldescr) {
  370. $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
  371. }
  372. if ($sref) {
  373. $param .= "&sref=".urlencode($sref);
  374. }
  375. if ($month) {
  376. $param .= "&month=".urlencode($month);
  377. }
  378. if ($year) {
  379. $param .= "&year=".urlencode($year);
  380. }
  381. if ($optioncss) {
  382. $param .= '&optioncss='.urlencode($optioncss);
  383. }
  384. print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit);
  385. print '<div class="div-table-responsive-no-min">';
  386. print '<table class="liste centpercent">'."\n";
  387. // Filters
  388. print '<tr class="liste_titre">';
  389. print '<td class="liste_titre left">';
  390. print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
  391. print '</td>';
  392. print '<td class="liste_titre nowrap center valignmiddle">'; // date
  393. print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle');
  394. print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
  395. print '</td>';
  396. // delivery planned date
  397. if ($type_element == 'order' || $type_element == 'supplier_order') {
  398. print '<td class="liste_titre center"></td>';
  399. }
  400. print '<td class="liste_titre center">';
  401. print '</td>';
  402. print '<td class="liste_titre left">';
  403. print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
  404. print '</td>';
  405. print '<td class="liste_titre center">';
  406. print '</td>';
  407. print '<td class="liste_titre center">';
  408. print '</td>';
  409. print '<td class="liste_titre maxwidthsearch">';
  410. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  411. print $searchpicto;
  412. print '</td>';
  413. print '</tr>';
  414. // Titles with sort buttons
  415. print '<tr class="liste_titre">';
  416. print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
  417. print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
  418. // delivery planned date
  419. if ($type_element == 'order' || $type_element == 'supplier_order') {
  420. print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
  421. }
  422. print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
  423. print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
  424. print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
  425. print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  426. print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  427. print "</tr>\n";
  428. $i = 0;
  429. while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
  430. $documentstatic->id = $objp->doc_id;
  431. $documentstatic->ref = $objp->doc_number;
  432. $documentstatic->type = $objp->doc_type;
  433. $documentstatic->fk_statut = $objp->status;
  434. $documentstatic->fk_status = $objp->status;
  435. $documentstatic->statut = $objp->status;
  436. $documentstatic->status = $objp->status;
  437. $documentstatic->paye = $objp->paid;
  438. $documentstatic->alreadypaid = $objp->paid;
  439. if (is_object($documentstaticline)) {
  440. $documentstaticline->statut = $objp->status;
  441. }
  442. print '<tr class="oddeven">';
  443. print '<td class="nobordernopadding nowrap" width="100">';
  444. print $documentstatic->getNomUrl(1);
  445. print '</td>';
  446. print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
  447. // delivery planned date
  448. if ($type_element == 'order' || $type_element == 'supplier_order') {
  449. print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
  450. }
  451. // Status
  452. print '<td class="center">';
  453. if ($type_element == 'contract') {
  454. print $documentstaticline->getLibStatut(5);
  455. } elseif ($type_element == 'invoice') {
  456. print $documentstatic->getLibStatut(5, $objp->paid);
  457. } elseif ($type_element == 'supplier_invoice') {
  458. print $documentstatic->getLibStatut(5, $objp->paid);
  459. } else {
  460. print $documentstatic->getLibStatut(5);
  461. }
  462. print '</td>';
  463. // Label
  464. print '<td class="tdoverflowmax300">';
  465. // Define text, description and type
  466. $text = '';
  467. $description = '';
  468. $type = 0;
  469. // Code to show product duplicated from commonobject->printObjectLine
  470. if ($objp->fk_product > 0) {
  471. $product_static = new Product($db);
  472. $product_static->type = $objp->fk_product_type;
  473. $product_static->id = $objp->fk_product;
  474. $product_static->ref = $objp->ref;
  475. $product_static->entity = $objp->pentity;
  476. $text = $product_static->getNomUrl(1);
  477. }
  478. // Product
  479. if ($objp->fk_product > 0) {
  480. // Define output language
  481. if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
  482. $prod = new Product($db);
  483. $prod->fetch($objp->fk_product);
  484. $outputlangs = $langs;
  485. $newlang = '';
  486. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  487. $newlang = GETPOST('lang_id', 'aZ09');
  488. }
  489. if (empty($newlang)) {
  490. $newlang = $object->default_lang;
  491. }
  492. if (!empty($newlang)) {
  493. $outputlangs = new Translate("", $conf);
  494. $outputlangs->setDefaultLang($newlang);
  495. }
  496. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
  497. } else {
  498. $label = $objp->product_label;
  499. }
  500. $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
  501. $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
  502. }
  503. if (($objp->info_bits & 2) == 2) { ?>
  504. <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
  505. <?php
  506. $txt = '';
  507. print img_object($langs->trans("ShowReduc"), 'reduc').' ';
  508. if ($objp->description == '(DEPOSIT)') {
  509. $txt = $langs->trans("Deposit");
  510. } elseif ($objp->description == '(EXCESS RECEIVED)') {
  511. $txt = $langs->trans("ExcessReceived");
  512. } elseif ($objp->description == '(EXCESS PAID)') {
  513. $txt = $langs->trans("ExcessPaid");
  514. }
  515. //else $txt=$langs->trans("Discount");
  516. print $txt;
  517. ?>
  518. </a>
  519. <?php
  520. if ($objp->description) {
  521. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  522. if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
  523. $discount = new DiscountAbsolute($db);
  524. $discount->fetch($objp->fk_remise_except);
  525. echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
  526. }
  527. if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
  528. $discount = new DiscountAbsolute($db);
  529. $discount->fetch($objp->fk_remise_except);
  530. echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
  531. } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
  532. $discount = new DiscountAbsolute($db);
  533. $discount->fetch($objp->fk_remise_except);
  534. echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
  535. } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
  536. $discount = new DiscountAbsolute($db);
  537. $discount->fetch($objp->fk_remise_except);
  538. echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
  539. // Add date of deposit
  540. if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
  541. echo ' ('.dol_print_date($discount->datec).')';
  542. }
  543. } else {
  544. echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
  545. }
  546. }
  547. } else {
  548. if ($objp->fk_product > 0) {
  549. echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, '');
  550. // Show range
  551. echo get_date_range($objp->date_start, $objp->date_end);
  552. // Add description in form
  553. if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
  554. print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
  555. }
  556. } else {
  557. if (!empty($objp->label) || !empty($objp->description)) {
  558. if ($type == 1) {
  559. $text = img_object($langs->trans('Service'), 'service');
  560. } else {
  561. $text = img_object($langs->trans('Product'), 'product');
  562. }
  563. if (!empty($objp->label)) {
  564. $text .= ' <strong>'.$objp->label.'</strong>';
  565. echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, '', '', $i, 0, '');
  566. } else {
  567. echo $text.' '.dol_htmlentitiesbr($objp->description);
  568. }
  569. }
  570. // Show range
  571. echo get_date_range($objp->date_start, $objp->date_end);
  572. }
  573. }
  574. /*
  575. $prodreftxt='';
  576. if ($objp->prod_id > 0)
  577. {
  578. $productstatic->id = $objp->prod_id;
  579. $productstatic->ref = $objp->prod_ref;
  580. $productstatic->status = $objp->prod_type;
  581. $prodreftxt = $productstatic->getNomUrl(0);
  582. if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
  583. }
  584. // Show range
  585. $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
  586. // Add description in form
  587. if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
  588. {
  589. $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
  590. }
  591. */
  592. print '</td>';
  593. //print '<td class="left">'.$prodreftxt.'</td>';
  594. if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
  595. $objp->prod_qty = -($objp->prod_qty);
  596. }
  597. print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
  598. $total_qty += $objp->prod_qty;
  599. print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
  600. if (empty($total_ht)) {
  601. $total_ht = 0;
  602. }
  603. $total_ht += (float) $objp->total_ht;
  604. print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
  605. print "</tr>\n";
  606. $i++;
  607. }
  608. print '<tr class="liste_total">';
  609. print '<td>'.$langs->trans('Total').'</td>';
  610. print '<td colspan="3"></td>';
  611. // delivery planned date
  612. if ($type_element == 'order' || $type_element == 'supplier_order') {
  613. print '<td></td>';
  614. }
  615. print '<td class="right">'.$total_qty.'</td>';
  616. print '<td class="right">'.price($total_ht).'</td>';
  617. print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
  618. print "</table>";
  619. print '</div>';
  620. if ($num > $limit) {
  621. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
  622. }
  623. $db->free($resql);
  624. } elseif (empty($type_element) || $type_element == -1) {
  625. print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', (!empty($num) ? $num : 0), '', '');
  626. print '<table class="liste centpercent">'."\n";
  627. // Titles with sort buttons
  628. print '<tr class="liste_titre">';
  629. print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
  630. print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
  631. print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
  632. print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
  633. print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
  634. print "</tr>\n";
  635. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
  636. print "</table>";
  637. } else {
  638. print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
  639. print '<table class="liste centpercent">'."\n";
  640. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
  641. print "</table>";
  642. }
  643. print "</form>";
  644. // End of page
  645. llxFooter();
  646. $db->close();