list.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2019 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  12. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  14. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/supplier_proposal/list.php
  31. * \ingroup supplier_proposal
  32. * \brief Page of supplier proposals card and list
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  42. if (!empty($conf->projet->enabled)) {
  43. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  44. }
  45. // Load translation files required by the page
  46. $langs->loadLangs(array('companies', 'propal', 'supplier_proposal', 'compta', 'bills', 'orders', 'products'));
  47. $socid = GETPOST('socid', 'int');
  48. $action = GETPOST('action', 'aZ09');
  49. $massaction = GETPOST('massaction', 'alpha');
  50. $show_files = GETPOST('show_files', 'int');
  51. $confirm = GETPOST('confirm', 'alpha');
  52. $toselect = GETPOST('toselect', 'array');
  53. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'supplierproposallist';
  54. $search_user = GETPOST('search_user', 'int');
  55. $search_sale = GETPOST('search_sale', 'int');
  56. $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
  57. $search_societe = GETPOST('search_societe', 'alpha');
  58. $search_login = GETPOST('search_login', 'alpha');
  59. $search_town = GETPOST('search_town', 'alpha');
  60. $search_zip = GETPOST('search_zip', 'alpha');
  61. $search_state = GETPOST("search_state");
  62. $search_country = GETPOST("search_country", 'int');
  63. $search_date_startday = GETPOST('search_date_startday', 'int');
  64. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  65. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  66. $search_date_endday = GETPOST('search_date_endday', 'int');
  67. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  68. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  69. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  70. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  71. $search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
  72. $search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
  73. $search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
  74. $search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
  75. $search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
  76. $search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
  77. $search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
  78. $search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
  79. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  80. $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
  81. $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
  82. $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
  83. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  84. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  85. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  86. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  87. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  88. $search_status = GETPOST('search_status', 'int');
  89. $object_statut = $db->escape(GETPOST('supplier_proposal_statut'));
  90. $search_btn = GETPOST('button_search', 'alpha');
  91. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  92. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  93. $mesg = (GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg"));
  94. $optioncss = GETPOST('optioncss', 'alpha');
  95. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  96. $sortfield = GETPOST('sortfield', 'aZ09comma');
  97. $sortorder = GETPOST('sortorder', 'aZ09comma');
  98. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  99. if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
  100. $page = 0;
  101. } // If $page is not defined, or '' or -1
  102. $offset = $limit * $page;
  103. $pageprev = $page - 1;
  104. $pagenext = $page + 1;
  105. if (!$sortfield) {
  106. $sortfield = 'sp.date_livraison';
  107. }
  108. if (!$sortorder) {
  109. $sortorder = 'DESC';
  110. }
  111. if ($object_statut != '') {
  112. $search_status = $object_statut;
  113. }
  114. // Nombre de ligne pour choix de produit/service predefinis
  115. $NBLINES = 4;
  116. // Security check
  117. $module = 'supplier_proposal';
  118. $dbtable = '';
  119. $objectid = '';
  120. if (!empty($user->socid)) {
  121. $socid = $user->socid;
  122. }
  123. if (!empty($socid)) {
  124. $objectid = $socid;
  125. $module = 'societe';
  126. $dbtable = '&societe';
  127. }
  128. $result = restrictedArea($user, $module, $objectid, $dbtable);
  129. $diroutputmassaction = $conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id;
  130. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  131. $object = new SupplierProposal($db);
  132. $hookmanager->initHooks(array('supplier_proposallist'));
  133. $extrafields = new ExtraFields($db);
  134. // fetch optionals attributes and labels
  135. $extrafields->fetch_name_optionals_label($object->table_element);
  136. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  137. // List of fields to search into when doing a "search in all"
  138. $fieldstosearchall = array(
  139. 'sp.ref'=>'Ref',
  140. 's.nom'=>'Supplier',
  141. 'pd.description'=>'Description',
  142. 'sp.note_public'=>'NotePublic',
  143. );
  144. if (empty($user->socid)) {
  145. $fieldstosearchall["p.note_private"] = "NotePrivate";
  146. }
  147. $checkedtypetiers = 0;
  148. $arrayfields = array(
  149. 'sp.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  150. 's.nom'=>array('label'=>$langs->trans("Supplier"), 'checked'=>1),
  151. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  152. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  153. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  154. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  155. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  156. 'sp.date_valid'=>array('label'=>$langs->trans("Date"), 'checked'=>1),
  157. 'sp.date_livraison'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1),
  158. 'sp.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  159. 'sp.total_tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
  160. 'sp.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
  161. 'sp.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  162. 'sp.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  163. 'sp.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  164. 'sp.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  165. 'sp.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  166. 'u.login'=>array('label'=>$langs->trans("Author"), 'checked'=>1, 'position'=>10),
  167. 'sp.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  168. 'sp.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  169. 'sp.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  170. );
  171. // Extra fields
  172. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  173. $object->fields = dol_sort_array($object->fields, 'position');
  174. $arrayfields = dol_sort_array($arrayfields, 'position');
  175. /*
  176. * Actions
  177. */
  178. if (GETPOST('cancel', 'alpha')) {
  179. $action = 'list'; $massaction = '';
  180. }
  181. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  182. $massaction = '';
  183. }
  184. $parameters = array('socid'=>$socid);
  185. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  186. if ($reshook < 0) {
  187. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  188. }
  189. $search_product_category = 0;
  190. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  191. // Do we click on purge search criteria ?
  192. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  193. $search_categ = '';
  194. $search_user = '';
  195. $search_sale = '';
  196. $search_ref = '';
  197. $search_societe = '';
  198. $search_montant_ht = '';
  199. $search_montant_vat = '';
  200. $search_montant_ttc = '';
  201. $search_multicurrency_code = '';
  202. $search_multicurrency_tx = '';
  203. $search_multicurrency_montant_ht = '';
  204. $search_multicurrency_montant_vat = '';
  205. $search_multicurrency_montant_ttc = '';
  206. $search_login = '';
  207. $search_product_category = '';
  208. $search_town = '';
  209. $search_zip = "";
  210. $search_state = "";
  211. $search_type = '';
  212. $search_country = '';
  213. $search_type_thirdparty = '';
  214. $search_date_startday = '';
  215. $search_date_startmonth = '';
  216. $search_date_startyear = '';
  217. $search_date_endday = '';
  218. $search_date_endmonth = '';
  219. $search_date_endyear = '';
  220. $search_date_start = '';
  221. $search_date_end = '';
  222. $search_date_valid_startday = '';
  223. $search_date_valid_startmonth = '';
  224. $search_date_valid_startyear = '';
  225. $search_date_valid_endday = '';
  226. $search_date_valid_endmonth = '';
  227. $search_date_valid_endyear = '';
  228. $search_date_valid_start = '';
  229. $search_date_valid_end = '';
  230. $search_status = '';
  231. $object_statut = '';
  232. }
  233. if (empty($reshook)) {
  234. $objectclass = 'SupplierProposal';
  235. $objectlabel = 'SupplierProposals';
  236. $permissiontoread = $user->rights->supplier_proposal->lire;
  237. $permissiontodelete = $user->rights->supplier_proposal->supprimer;
  238. $uploaddir = $conf->supplier_proposal->dir_output;
  239. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  240. }
  241. /*
  242. * View
  243. */
  244. $now = dol_now();
  245. $form = new Form($db);
  246. $formother = new FormOther($db);
  247. $formfile = new FormFile($db);
  248. $formpropal = new FormPropal($db);
  249. $companystatic = new Societe($db);
  250. $formcompany = new FormCompany($db);
  251. $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
  252. //llxHeader('',$langs->trans('CommRequest'),$help_url);
  253. $sql = 'SELECT';
  254. if ($sall || $search_product_category > 0 || $search_user > 0) {
  255. $sql = 'SELECT DISTINCT';
  256. }
  257. $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  258. $sql .= " typent.code as typent_code,";
  259. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  260. $sql .= ' sp.rowid, sp.note_public, sp.note_private, sp.total_ht, sp.total_tva, sp.total_ttc, sp.localtax1, sp.localtax2, sp.ref, sp.fk_statut as status, sp.fk_user_author, sp.date_valid, sp.date_livraison as dp,';
  261. $sql .= ' sp.fk_multicurrency, sp.multicurrency_code, sp.multicurrency_tx, sp.multicurrency_total_ht, sp.multicurrency_total_tva as multicurrency_total_vat, sp.multicurrency_total_ttc,';
  262. $sql .= ' sp.datec as date_creation, sp.tms as date_update,';
  263. $sql .= " p.rowid as project_id, p.ref as project_ref,";
  264. if (empty($user->rights->societe->client->voir) && !$socid) {
  265. $sql .= " sc.fk_soc, sc.fk_user,";
  266. }
  267. $sql .= " u.firstname, u.lastname, u.photo, u.login, u.statut as status, u.admin, u.employee, u.email as uemail";
  268. // Add fields from extrafields
  269. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  270. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  271. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  272. }
  273. }
  274. // Add fields from hooks
  275. $parameters = array();
  276. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  277. $sql .= $hookmanager->resPrint;
  278. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  279. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  280. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  281. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  282. $sql .= ', '.MAIN_DB_PREFIX.'supplier_proposal as sp';
  283. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  284. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (sp.rowid = ef.fk_object)";
  285. }
  286. if ($sall || $search_product_category > 0) {
  287. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'supplier_proposaldet as pd ON sp.rowid=pd.fk_supplier_proposal';
  288. }
  289. if ($search_product_category > 0) {
  290. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  291. }
  292. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sp.fk_user_author = u.rowid';
  293. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = sp.fk_projet";
  294. // We'll need this table joined to the select in order to filter by sale
  295. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  296. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  297. }
  298. if ($search_user > 0) {
  299. $sql .= ", ".MAIN_DB_PREFIX."element_contact as c";
  300. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  301. }
  302. $sql .= ' WHERE sp.fk_soc = s.rowid';
  303. $sql .= ' AND sp.entity IN ('.getEntity('supplier_proposal').')';
  304. if (empty($user->rights->societe->client->voir) && !$socid) { //restriction
  305. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  306. }
  307. if ($search_town) {
  308. $sql .= natural_search('s.town', $search_town);
  309. }
  310. if ($search_zip) {
  311. $sql .= natural_search("s.zip", $search_zip);
  312. }
  313. if ($search_state) {
  314. $sql .= natural_search("state.nom", $search_state);
  315. }
  316. if ($search_country) {
  317. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  318. }
  319. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  320. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  321. }
  322. if ($search_ref) {
  323. $sql .= natural_search('sp.ref', $search_ref);
  324. }
  325. if ($search_societe) {
  326. $sql .= natural_search('s.nom', $search_societe);
  327. }
  328. if ($search_login) {
  329. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_login);
  330. }
  331. if ($search_montant_ht) {
  332. $sql .= natural_search('sp.total_ht=', $search_montant_ht, 1);
  333. }
  334. if ($search_montant_vat != '') {
  335. $sql .= natural_search("sp.total_tva", $search_montant_vat, 1);
  336. }
  337. if ($search_montant_ttc != '') {
  338. $sql .= natural_search("sp.total_ttc", $search_montant_ttc, 1);
  339. }
  340. if ($search_multicurrency_code != '') {
  341. $sql .= " AND sp.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  342. }
  343. if ($search_multicurrency_tx != '') {
  344. $sql .= natural_search('sp.multicurrency_tx', $search_multicurrency_tx, 1);
  345. }
  346. if ($search_multicurrency_montant_ht != '') {
  347. $sql .= natural_search('sp.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  348. }
  349. if ($search_multicurrency_montant_vat != '') {
  350. $sql .= natural_search('sp.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  351. }
  352. if ($search_multicurrency_montant_ttc != '') {
  353. $sql .= natural_search('sp.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  354. }
  355. if ($sall) {
  356. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  357. }
  358. if ($socid) {
  359. $sql .= ' AND s.rowid = '.((int) $socid);
  360. }
  361. if ($search_status >= 0 && $search_status != '') {
  362. $sql .= ' AND sp.fk_statut IN ('.$db->sanitize($db->escape($search_status)).')';
  363. }
  364. if ($search_date_start) {
  365. $sql .= " AND sp.date_livraison >= '".$db->idate($search_date_start)."'";
  366. }
  367. if ($search_date_end) {
  368. $sql .= " AND sp.date_livraison <= '".$db->idate($search_date_end)."'";
  369. }
  370. if ($search_date_valid_start) {
  371. $sql .= " AND sp.date_valid >= '".$db->idate($search_date_valid_start)."'";
  372. }
  373. if ($search_date_valid_end) {
  374. $sql .= " AND sp.date_valid <= '".$db->idate($search_date_valid_end)."'";
  375. }
  376. if ($search_sale > 0) {
  377. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  378. }
  379. if ($search_user > 0) {
  380. $sql .= " AND c.fk_c_type_contact = tc.rowid AND tc.element='supplier_proposal' AND tc.source='internal' AND c.element_id = sp.rowid AND c.fk_socpeople = ".((int) $search_user);
  381. }
  382. // Add where from extra fields
  383. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  384. // Add where from hooks
  385. $parameters = array();
  386. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  387. $sql .= $hookmanager->resPrint;
  388. $sql .= $db->order($sortfield, $sortorder);
  389. $sql .= ', sp.ref DESC';
  390. // Count total nb of records
  391. $nbtotalofrecords = '';
  392. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  393. $resql = $db->query($sql);
  394. $nbtotalofrecords = $db->num_rows($resql);
  395. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  396. $page = 0;
  397. $offset = 0;
  398. }
  399. }
  400. $sql .= $db->plimit($limit + 1, $offset);
  401. $resql = $db->query($sql);
  402. if ($resql) {
  403. $objectstatic = new SupplierProposal($db);
  404. $userstatic = new User($db);
  405. if ($socid > 0) {
  406. $soc = new Societe($db);
  407. $soc->fetch($socid);
  408. $title = $langs->trans('SupplierProposals').' - '.$soc->name;
  409. } else {
  410. $title = $langs->trans('SupplierProposals');
  411. }
  412. $num = $db->num_rows($resql);
  413. $arrayofselected = is_array($toselect) ? $toselect : array();
  414. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  415. $obj = $db->fetch_object($resql);
  416. $id = $obj->rowid;
  417. header("Location: ".DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$id);
  418. exit;
  419. }
  420. llxHeader('', $langs->trans('CommRequest'), $help_url);
  421. $param = '';
  422. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  423. $param .= '&contextpage='.urlencode($contextpage);
  424. }
  425. if ($limit > 0 && $limit != $conf->liste_limit) {
  426. $param .= '&limit='.urlencode($limit);
  427. }
  428. if ($sall) {
  429. $param .= '&sall='.urlencode($sall);
  430. }
  431. if ($search_date_startday) {
  432. $param .= '&search_date_startday='.urlencode($search_date_startday);
  433. }
  434. if ($search_date_startmonth) {
  435. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  436. }
  437. if ($search_date_startyear) {
  438. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  439. }
  440. if ($search_date_endday) {
  441. $param .= '&search_date_endday='.urlencode($search_date_endday);
  442. }
  443. if ($search_date_endmonth) {
  444. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  445. }
  446. if ($search_date_endyear) {
  447. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  448. }
  449. if ($search_date_valid_startday) {
  450. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  451. }
  452. if ($search_date_valid_startmonth) {
  453. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  454. }
  455. if ($search_date_valid_startyear) {
  456. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  457. }
  458. if ($search_date_valid_endday) {
  459. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  460. }
  461. if ($search_date_valid_endmonth) {
  462. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  463. }
  464. if ($search_date_valid_endyear) {
  465. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  466. }
  467. if ($search_ref) {
  468. $param .= '&search_ref='.urlencode($search_ref);
  469. }
  470. if ($search_societe) {
  471. $param .= '&search_societe='.urlencode($search_societe);
  472. }
  473. if ($search_user > 0) {
  474. $param .= '&search_user='.urlencode($search_user);
  475. }
  476. if ($search_sale > 0) {
  477. $param .= '&search_sale='.urlencode($search_sale);
  478. }
  479. if ($search_montant_ht) {
  480. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  481. }
  482. if ($search_multicurrency_code != '') {
  483. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  484. }
  485. if ($search_multicurrency_tx != '') {
  486. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  487. }
  488. if ($search_multicurrency_montant_ht != '') {
  489. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  490. }
  491. if ($search_multicurrency_montant_vat != '') {
  492. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  493. }
  494. if ($search_multicurrency_montant_ttc != '') {
  495. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  496. }
  497. if ($search_login) {
  498. $param .= '&search_login='.urlencode($search_login);
  499. }
  500. if ($search_town) {
  501. $param .= '&search_town='.urlencode($search_town);
  502. }
  503. if ($search_zip) {
  504. $param .= '&search_zip='.urlencode($search_zip);
  505. }
  506. if ($socid > 0) {
  507. $param .= '&socid='.urlencode($socid);
  508. }
  509. if ($search_status != '') {
  510. $param .= '&search_status='.urlencode($search_status);
  511. }
  512. if ($optioncss != '') {
  513. $param .= '&optioncss='.urlencode($optioncss);
  514. }
  515. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  516. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  517. }
  518. // Add $param from extra fields
  519. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  520. // List of mass actions available
  521. $arrayofmassactions = array(
  522. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  523. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  524. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  525. );
  526. if ($user->rights->supplier_proposal->supprimer) {
  527. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  528. }
  529. if (in_array($massaction, array('presend', 'predelete'))) {
  530. $arrayofmassactions = array();
  531. }
  532. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  533. $url = DOL_URL_ROOT.'/supplier_proposal/card.php?action=create';
  534. if (!empty($socid)) {
  535. $url .= '&socid='.$socid;
  536. }
  537. $newcardbutton = dolGetButtonTitle($langs->trans('NewAskPrice'), '', 'fa fa-plus-circle', $url, '', $user->rights->supplier_proposal->creer);
  538. // Fields title search
  539. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  540. if ($optioncss != '') {
  541. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  542. }
  543. print '<input type="hidden" name="token" value="'.newToken().'">';
  544. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  545. print '<input type="hidden" name="action" value="list">';
  546. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  547. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  548. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_proposal', 0, $newcardbutton, '', $limit, 0, 0, 1);
  549. $topicmail = "SendSupplierProposalRef";
  550. $modelmail = "supplier_proposal_send";
  551. $objecttmp = new SupplierProposal($db);
  552. $trackid = 'spro'.$object->id;
  553. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  554. if ($sall) {
  555. foreach ($fieldstosearchall as $key => $val) {
  556. $fieldstosearchall[$key] = $langs->trans($val);
  557. }
  558. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  559. }
  560. $i = 0;
  561. $moreforfilter = '';
  562. // If the user can view prospects other than his'
  563. if ($user->rights->user->user->lire) {
  564. $langs->load("commercial");
  565. $moreforfilter .= '<div class="divsearchfield">';
  566. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  567. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  568. $moreforfilter .= '</div>';
  569. }
  570. // If the user can view prospects other than his'
  571. if ($user->rights->user->user->lire) {
  572. $moreforfilter .= '<div class="divsearchfield">';
  573. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  574. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  575. $moreforfilter .= '</div>';
  576. }
  577. // If the user can view products
  578. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  579. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  580. $moreforfilter .= '<div class="divsearchfield">';
  581. $tmptitle = $langs->trans('IncludingProductWithTag');
  582. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  583. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
  584. $moreforfilter .= '</div>';
  585. }
  586. $parameters = array();
  587. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  588. if (empty($reshook)) {
  589. $moreforfilter .= $hookmanager->resPrint;
  590. } else {
  591. $moreforfilter = $hookmanager->resPrint;
  592. }
  593. if (!empty($moreforfilter)) {
  594. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  595. print $moreforfilter;
  596. print '</div>';
  597. }
  598. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  599. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  600. if ($massactionbutton) {
  601. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  602. }
  603. print '<div class="div-table-responsive">';
  604. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  605. print '<tr class="liste_titre_filter">';
  606. if (!empty($arrayfields['sp.ref']['checked'])) {
  607. print '<td class="liste_titre">';
  608. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  609. print '</td>';
  610. }
  611. if (!empty($arrayfields['s.nom']['checked'])) {
  612. print '<td class="liste_titre left">';
  613. print '<input class="flat" type="text" size="12" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
  614. print '</td>';
  615. }
  616. if (!empty($arrayfields['s.town']['checked'])) {
  617. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  618. }
  619. if (!empty($arrayfields['s.zip']['checked'])) {
  620. print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.$search_zip.'"></td>';
  621. }
  622. // State
  623. if (!empty($arrayfields['state.nom']['checked'])) {
  624. print '<td class="liste_titre">';
  625. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  626. print '</td>';
  627. }
  628. // Country
  629. if (!empty($arrayfields['country.code_iso']['checked'])) {
  630. print '<td class="liste_titre center">';
  631. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  632. print '</td>';
  633. }
  634. // Company type
  635. if (!empty($arrayfields['typent.code']['checked'])) {
  636. print '<td class="liste_titre maxwidthonsmartphone center">';
  637. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  638. print '</td>';
  639. }
  640. // Date
  641. if (!empty($arrayfields['sp.date_valid']['checked'])) {
  642. print '<td class="liste_titre center">';
  643. print '<div class="nowrap">';
  644. print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  645. print '</div>';
  646. print '<div class="nowrap">';
  647. print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  648. print '</div>';
  649. print '</td>';
  650. }
  651. // Date
  652. if (!empty($arrayfields['sp.date_livraison']['checked'])) {
  653. print '<td class="liste_titre center">';
  654. print '<div class="nowrap">';
  655. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  656. print '</div>';
  657. print '<div class="nowrap">';
  658. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  659. print '</div>';
  660. print '</td>';
  661. }
  662. if (!empty($arrayfields['sp.total_ht']['checked'])) {
  663. // Amount
  664. print '<td class="liste_titre right">';
  665. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  666. print '</td>';
  667. }
  668. if (!empty($arrayfields['sp.total_tva']['checked'])) {
  669. // Amount
  670. print '<td class="liste_titre right">';
  671. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  672. print '</td>';
  673. }
  674. if (!empty($arrayfields['sp.total_ttc']['checked'])) {
  675. // Amount
  676. print '<td class="liste_titre right">';
  677. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  678. print '</td>';
  679. }
  680. if (!empty($arrayfields['sp.multicurrency_code']['checked'])) {
  681. // Currency
  682. print '<td class="liste_titre">';
  683. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  684. print '</td>';
  685. }
  686. if (!empty($arrayfields['sp.multicurrency_tx']['checked'])) {
  687. // Currency rate
  688. print '<td class="liste_titre">';
  689. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  690. print '</td>';
  691. }
  692. if (!empty($arrayfields['sp.multicurrency_total_ht']['checked'])) {
  693. // Amount
  694. print '<td class="liste_titre right">';
  695. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  696. print '</td>';
  697. }
  698. if (!empty($arrayfields['sp.multicurrency_total_vat']['checked'])) {
  699. // Amount
  700. print '<td class="liste_titre right">';
  701. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  702. print '</td>';
  703. }
  704. if (!empty($arrayfields['sp.multicurrency_total_ttc']['checked'])) {
  705. // Amount
  706. print '<td class="liste_titre right">';
  707. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  708. print '</td>';
  709. }
  710. if (!empty($arrayfields['u.login']['checked'])) {
  711. // Author
  712. print '<td class="liste_titre center">';
  713. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  714. print '</td>';
  715. }
  716. // Extra fields
  717. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  718. // Fields from hook
  719. $parameters = array('arrayfields'=>$arrayfields);
  720. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  721. print $hookmanager->resPrint;
  722. // Date creation
  723. if (!empty($arrayfields['sp.datec']['checked'])) {
  724. print '<td class="liste_titre">';
  725. print '</td>';
  726. }
  727. // Date modification
  728. if (!empty($arrayfields['sp.tms']['checked'])) {
  729. print '<td class="liste_titre">';
  730. print '</td>';
  731. }
  732. // Status
  733. if (!empty($arrayfields['sp.fk_statut']['checked'])) {
  734. print '<td class="liste_titre right">';
  735. $formpropal->selectProposalStatus($search_status, 1, 0, 1, 'supplier', 'search_status', 'minwidth75imp');
  736. print '</td>';
  737. }
  738. // Action column
  739. print '<td class="liste_titre middle">';
  740. $searchpicto = $form->showFilterButtons();
  741. print $searchpicto;
  742. print '</td>';
  743. print "</tr>\n";
  744. // Fields title
  745. print '<tr class="liste_titre">';
  746. if (!empty($arrayfields['sp.ref']['checked'])) {
  747. print_liste_field_titre($arrayfields['sp.ref']['label'], $_SERVER["PHP_SELF"], 'sp.ref', '', $param, '', $sortfield, $sortorder);
  748. }
  749. if (!empty($arrayfields['s.nom']['checked'])) {
  750. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
  751. }
  752. if (!empty($arrayfields['s.town']['checked'])) {
  753. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  754. }
  755. if (!empty($arrayfields['s.zip']['checked'])) {
  756. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  757. }
  758. if (!empty($arrayfields['state.nom']['checked'])) {
  759. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  760. }
  761. if (!empty($arrayfields['country.code_iso']['checked'])) {
  762. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  763. }
  764. if (!empty($arrayfields['typent.code']['checked'])) {
  765. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  766. }
  767. if (!empty($arrayfields['sp.date_valid']['checked'])) {
  768. print_liste_field_titre($arrayfields['sp.date_valid']['label'], $_SERVER["PHP_SELF"], 'sp.date_valid', '', $param, '', $sortfield, $sortorder, 'center ');
  769. }
  770. if (!empty($arrayfields['sp.date_livraison']['checked'])) {
  771. print_liste_field_titre($arrayfields['sp.date_livraison']['label'], $_SERVER["PHP_SELF"], 'sp.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  772. }
  773. if (!empty($arrayfields['sp.total_ht']['checked'])) {
  774. print_liste_field_titre($arrayfields['sp.total_ht']['label'], $_SERVER["PHP_SELF"], 'sp.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  775. }
  776. if (!empty($arrayfields['sp.total_tva']['checked'])) {
  777. print_liste_field_titre($arrayfields['sp.total_tva']['label'], $_SERVER["PHP_SELF"], 'sp.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  778. }
  779. if (!empty($arrayfields['sp.total_ttc']['checked'])) {
  780. print_liste_field_titre($arrayfields['sp.total_ttc']['label'], $_SERVER["PHP_SELF"], 'sp.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  781. }
  782. if (!empty($arrayfields['sp.multicurrency_code']['checked'])) {
  783. print_liste_field_titre($arrayfields['sp.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  784. }
  785. if (!empty($arrayfields['sp.multicurrency_tx']['checked'])) {
  786. print_liste_field_titre($arrayfields['sp.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  787. }
  788. if (!empty($arrayfields['sp.multicurrency_total_ht']['checked'])) {
  789. print_liste_field_titre($arrayfields['sp.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  790. }
  791. if (!empty($arrayfields['sp.multicurrency_total_vat']['checked'])) {
  792. print_liste_field_titre($arrayfields['sp.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  793. }
  794. if (!empty($arrayfields['sp.multicurrency_total_ttc']['checked'])) {
  795. print_liste_field_titre($arrayfields['sp.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  796. }
  797. if (!empty($arrayfields['u.login']['checked'])) {
  798. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder, 'center ');
  799. }
  800. // Extra fields
  801. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  802. // Hook fields
  803. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  804. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  805. print $hookmanager->resPrint;
  806. if (!empty($arrayfields['sp.datec']['checked'])) {
  807. print_liste_field_titre($arrayfields['sp.datec']['label'], $_SERVER["PHP_SELF"], "sp.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  808. }
  809. if (!empty($arrayfields['sp.tms']['checked'])) {
  810. print_liste_field_titre($arrayfields['sp.tms']['label'], $_SERVER["PHP_SELF"], "sp.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap');
  811. }
  812. if (!empty($arrayfields['sp.fk_statut']['checked'])) {
  813. print_liste_field_titre($arrayfields['sp.fk_statut']['label'], $_SERVER["PHP_SELF"], "sp.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  814. }
  815. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  816. print '</tr>'."\n";
  817. $now = dol_now();
  818. $i = 0;
  819. $total = 0;
  820. $subtotal = 0;
  821. $totalarray = array();
  822. $totalarray['nbfield'] = 0;
  823. $totalarray['val'] = array();
  824. $totalarray['val']['sp.total_ht'] = 0;
  825. $totalarray['val']['sp.total_tva'] = 0;
  826. $totalarray['val']['sp.total_ttc'] = 0;
  827. while ($i < min($num, $limit)) {
  828. $obj = $db->fetch_object($resql);
  829. $objectstatic->id = $obj->rowid;
  830. $objectstatic->ref = $obj->ref;
  831. $objectstatic->note_public = $obj->note_public;
  832. $objectstatic->note_private = $obj->note_private;
  833. $objectstatic->status = $obj->status;
  834. // Company
  835. $companystatic->id = $obj->socid;
  836. $companystatic->name = $obj->name;
  837. $companystatic->client = $obj->client;
  838. $companystatic->code_client = $obj->code_client;
  839. print '<tr class="oddeven">';
  840. if (!empty($arrayfields['sp.ref']['checked'])) {
  841. print '<td class="nowraponall">';
  842. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  843. // Picto + Ref
  844. print '<td class="nobordernopadding nowraponall">';
  845. print $objectstatic->getNomUrl(1, '', '', 0, -1, 1);
  846. print '</td>';
  847. // Warning
  848. $warnornote = '';
  849. //if ($obj->fk_statut == 1 && $db->jdate($obj->date_valid) < ($now - $conf->supplier_proposal->warning_delay)) $warnornote .= img_warning($langs->trans("Late"));
  850. if ($warnornote) {
  851. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  852. print $warnornote;
  853. print '</td>';
  854. }
  855. // Other picto tool
  856. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  857. $filename = dol_sanitizeFileName($obj->ref);
  858. $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  859. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  860. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  861. print '</td></tr></table>';
  862. print "</td>\n";
  863. if (!$i) {
  864. $totalarray['nbfield']++;
  865. }
  866. }
  867. // Thirdparty
  868. if (!empty($arrayfields['s.nom']['checked'])) {
  869. print '<td class="tdoverflowmax200">';
  870. print $companystatic->getNomUrl(1, 'supplier');
  871. print '</td>';
  872. if (!$i) {
  873. $totalarray['nbfield']++;
  874. }
  875. }
  876. // Town
  877. if (!empty($arrayfields['s.town']['checked'])) {
  878. print '<td class="nocellnopadd">';
  879. print $obj->town;
  880. print '</td>';
  881. if (!$i) {
  882. $totalarray['nbfield']++;
  883. }
  884. }
  885. // Zip
  886. if (!empty($arrayfields['s.zip']['checked'])) {
  887. print '<td class="nocellnopadd">';
  888. print $obj->zip;
  889. print '</td>';
  890. if (!$i) {
  891. $totalarray['nbfield']++;
  892. }
  893. }
  894. // State
  895. if (!empty($arrayfields['state.nom']['checked'])) {
  896. print "<td>".$obj->state_name."</td>\n";
  897. if (!$i) {
  898. $totalarray['nbfield']++;
  899. }
  900. }
  901. // Country
  902. if (!empty($arrayfields['country.code_iso']['checked'])) {
  903. print '<td class="center">';
  904. $tmparray = getCountry($obj->fk_pays, 'all');
  905. print $tmparray['label'];
  906. print '</td>';
  907. if (!$i) {
  908. $totalarray['nbfield']++;
  909. }
  910. }
  911. // Type ent
  912. if (!empty($arrayfields['typent.code']['checked'])) {
  913. print '<td class="center">';
  914. if (count($typenArray) == 0) {
  915. $typenArray = $formcompany->typent_array(1);
  916. }
  917. print $typenArray[$obj->typent_code];
  918. print '</td>';
  919. if (!$i) {
  920. $totalarray['nbfield']++;
  921. }
  922. }
  923. // Date proposal
  924. if (!empty($arrayfields['sp.date_valid']['checked'])) {
  925. print '<td class="center">';
  926. print dol_print_date($db->jdate($obj->date_valid), 'day');
  927. print "</td>\n";
  928. if (!$i) {
  929. $totalarray['nbfield']++;
  930. }
  931. }
  932. // Date delivery
  933. if (!empty($arrayfields['sp.date_livraison']['checked'])) {
  934. print '<td class="center">';
  935. print dol_print_date($db->jdate($obj->dp), 'day');
  936. print "</td>\n";
  937. if (!$i) {
  938. $totalarray['nbfield']++;
  939. }
  940. }
  941. // Amount HT
  942. if (!empty($arrayfields['sp.total_ht']['checked'])) {
  943. print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  944. if (!$i) {
  945. $totalarray['nbfield']++;
  946. }
  947. if (!$i) {
  948. $totalarray['pos'][$totalarray['nbfield']] = 'sp.total_ht';
  949. }
  950. $totalarray['val']['sp.total_ht'] += $obj->total_ht;
  951. }
  952. // Amount VAT
  953. if (!empty($arrayfields['sp.total_tva']['checked'])) {
  954. print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  955. if (!$i) {
  956. $totalarray['nbfield']++;
  957. }
  958. if (!$i) {
  959. $totalarray['pos'][$totalarray['nbfield']] = 'sp.total_tva';
  960. }
  961. $totalarray['val']['sp.total_tva'] += $obj->total_tva;
  962. }
  963. // Amount TTC
  964. if (!empty($arrayfields['sp.total_ttc']['checked'])) {
  965. print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  966. if (!$i) {
  967. $totalarray['nbfield']++;
  968. }
  969. if (!$i) {
  970. $totalarray['pos'][$totalarray['nbfield']] = 'sp.total_ttc';
  971. }
  972. $totalarray['val']['sp.total_ttc'] += $obj->total_ttc;
  973. }
  974. // Currency
  975. if (!empty($arrayfields['sp.multicurrency_code']['checked'])) {
  976. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  977. if (!$i) {
  978. $totalarray['nbfield']++;
  979. }
  980. }
  981. // Currency rate
  982. if (!empty($arrayfields['sp.multicurrency_tx']['checked'])) {
  983. print '<td class="nowrap">';
  984. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  985. print "</td>\n";
  986. if (!$i) {
  987. $totalarray['nbfield']++;
  988. }
  989. }
  990. // Amount HT
  991. if (!empty($arrayfields['sp.multicurrency_total_ht']['checked'])) {
  992. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  993. if (!$i) {
  994. $totalarray['nbfield']++;
  995. }
  996. }
  997. // Amount VAT
  998. if (!empty($arrayfields['sp.multicurrency_total_vat']['checked'])) {
  999. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
  1000. if (!$i) {
  1001. $totalarray['nbfield']++;
  1002. }
  1003. }
  1004. // Amount TTC
  1005. if (!empty($arrayfields['sp.multicurrency_total_ttc']['checked'])) {
  1006. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1007. if (!$i) {
  1008. $totalarray['nbfield']++;
  1009. }
  1010. }
  1011. $userstatic->id = $obj->fk_user_author;
  1012. $userstatic->login = $obj->login;
  1013. $userstatic->status = $obj->status;
  1014. $userstatic->lastname = $obj->name;
  1015. $userstatic->firstname = $obj->firstname;
  1016. $userstatic->photo = $obj->photo;
  1017. $userstatic->admin = $obj->admin;
  1018. $userstatic->ref = $obj->fk_user_author;
  1019. $userstatic->employee = $obj->employee;
  1020. $userstatic->email = $obj->uemail;
  1021. // Author
  1022. if (!empty($arrayfields['u.login']['checked'])) {
  1023. print '<td class="center">';
  1024. if ($userstatic->id > 0) {
  1025. print $userstatic->getNomUrl(-1, '', 0, 0, 24, 1, 'login', '', 1);
  1026. } else {
  1027. print '&nbsp;';
  1028. }
  1029. print "</td>\n";
  1030. if (!$i) {
  1031. $totalarray['nbfield']++;
  1032. }
  1033. }
  1034. // Extra fields
  1035. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1036. // Fields from hook
  1037. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1038. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1039. print $hookmanager->resPrint;
  1040. // Date creation
  1041. if (!empty($arrayfields['sp.datec']['checked'])) {
  1042. print '<td class="center nowrap">';
  1043. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1044. print '</td>';
  1045. if (!$i) {
  1046. $totalarray['nbfield']++;
  1047. }
  1048. }
  1049. // Date modification
  1050. if (!empty($arrayfields['sp.tms']['checked'])) {
  1051. print '<td class="center nowrap">';
  1052. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1053. print '</td>';
  1054. if (!$i) {
  1055. $totalarray['nbfield']++;
  1056. }
  1057. }
  1058. // Status
  1059. if (!empty($arrayfields['sp.fk_statut']['checked'])) {
  1060. print '<td class="right">'.$objectstatic->getLibStatut(5)."</td>\n";
  1061. if (!$i) {
  1062. $totalarray['nbfield']++;
  1063. }
  1064. }
  1065. // Action column
  1066. print '<td class="nowrap center">';
  1067. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1068. $selected = 0;
  1069. if (in_array($obj->rowid, $arrayofselected)) {
  1070. $selected = 1;
  1071. }
  1072. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1073. }
  1074. print '</td>';
  1075. if (!$i) {
  1076. $totalarray['nbfield']++;
  1077. }
  1078. print "</tr>\n";
  1079. $total += $obj->total_ht;
  1080. $subtotal += $obj->total_ht;
  1081. $i++;
  1082. }
  1083. // Show total line
  1084. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1085. $db->free($resql);
  1086. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1087. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1088. print $hookmanager->resPrint;
  1089. print '</table>'."\n";
  1090. print '</div>'."\n";
  1091. print '</form>'."\n";
  1092. $hidegeneratedfilelistifempty = 1;
  1093. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1094. $hidegeneratedfilelistifempty = 0;
  1095. }
  1096. // Show list of available documents
  1097. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1098. $urlsource .= str_replace('&amp;', '&', $param);
  1099. $filedir = $diroutputmassaction;
  1100. $genallowed = $user->rights->supplier_proposal->lire;
  1101. $delallowed = $user->rights->supplier_proposal->creer;
  1102. print $formfile->showdocuments('massfilesarea_supplier_proposal', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1103. } else {
  1104. dol_print_error($db);
  1105. }
  1106. // End of page
  1107. llxFooter();
  1108. $db->close();