consumption.php 29 KB

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