consumption.php 27 KB

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