list.php 53 KB

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