dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 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-2011 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) 2015 Jean-François Ferry <jfefe@aternatik.fr>
13  * Copyright (C) 2016-2021 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2017-2018 Charlene Benke <charlie@patas-monkey.com>
15  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
16  * Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
17  * Copyright (C) 2021 Anthony Berton <anthony.berton@bb2a.fr>
18  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program. If not, see <https://www.gnu.org/licenses/>.
32  */
33 
40 require '../../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45 if (!empty($conf->margin->enabled)) {
46  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
47 }
48 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
50 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
52 
53 // Load translation files required by the page
54 $langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'categories'));
55 if (!empty($conf->expedition->enabled)) {
56  $langs->loadLangs(array('sendings'));
57 }
58 
59 $socid = GETPOST('socid', 'int');
60 
61 $action = GETPOST('action', 'aZ09');
62 $massaction = GETPOST('massaction', 'alpha');
63 $show_files = GETPOST('show_files', 'int');
64 $confirm = GETPOST('confirm', 'alpha');
65 $toselect = GETPOST('toselect', 'array');
66 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'proposallist';
67 
68 $search_user = GETPOST('search_user', 'int');
69 $search_sale = GETPOST('search_sale', 'int');
70 $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
71 $search_refcustomer = GETPOST('search_refcustomer', 'alpha');
72 
73 $search_refproject = GETPOST('search_refproject', 'alpha');
74 $search_project = GETPOST('search_project', 'alpha');
75 
76 $search_societe = GETPOST('search_societe', 'alpha');
77 $search_societe_alias = GETPOST('search_societe_alias', 'alpha');
78 $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
79 $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
80 $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
81 $search_warehouse = GETPOST('search_warehouse', 'alpha');
82 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
83 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
84 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
85 $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
86 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
87 $search_login = GETPOST('search_login', 'alpha');
88 $search_product_category = GETPOST('search_product_category', 'int');
89 $search_town = GETPOST('search_town', 'alpha');
90 $search_zip = GETPOST('search_zip', 'alpha');
91 $search_state = GETPOST("search_state");
92 $search_country = GETPOST("search_country", 'int');
93 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
94 $search_date_startday = GETPOST('search_date_startday', 'int');
95 $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
96 $search_date_startyear = GETPOST('search_date_startyear', 'int');
97 $search_date_endday = GETPOST('search_date_endday', 'int');
98 $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
99 $search_date_endyear = GETPOST('search_date_endyear', 'int');
100 $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
101 $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
102 $search_date_end_startday = GETPOST('search_date_end_startday', 'int');
103 $search_date_end_startmonth = GETPOST('search_date_end_startmonth', 'int');
104 $search_date_end_startyear = GETPOST('search_date_end_startyear', 'int');
105 $search_date_end_endday = GETPOST('search_date_end_endday', 'int');
106 $search_date_end_endmonth = GETPOST('search_date_end_endmonth', 'int');
107 $search_date_end_endyear = GETPOST('search_date_end_endyear', 'int');
108 $search_date_end_start = dol_mktime(0, 0, 0, $search_date_end_startmonth, $search_date_end_startday, $search_date_end_startyear); // Use tzserver
109 $search_date_end_end = dol_mktime(23, 59, 59, $search_date_end_endmonth, $search_date_end_endday, $search_date_end_endyear);
110 $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
111 $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
112 $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
113 $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
114 $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
115 $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
116 $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear);
117 $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
118 $search_availability = GETPOST('search_availability', 'int');
119 $search_categ_cus = GETPOST("search_categ_cus", 'int');
120 $search_fk_cond_reglement = GETPOST("search_fk_cond_reglement", 'int');
121 $search_fk_shipping_method = GETPOST("search_fk_shipping_method", 'int');
122 $search_fk_input_reason = GETPOST("search_fk_input_reason", 'int');
123 $search_fk_mode_reglement = GETPOST("search_fk_mode_reglement", 'int');
124 $search_btn = GETPOST('button_search', 'alpha');
125 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
126 $search_date_signature_startday = GETPOST('search_date_signature_startday', 'int');
127 $search_date_signature_startmonth = GETPOST('search_date_signature_startmonth', 'int');
128 $search_date_signature_startyear = GETPOST('search_date_signature_startyear', 'int');
129 $search_date_signature_endday = GETPOST('search_date_signature_endday', 'int');
130 $search_date_signature_endmonth = GETPOST('search_date_signature_endmonth', 'int');
131 $search_date_signature_endyear = GETPOST('search_date_signature_endyear', 'int');
132 $search_date_signature_start = dol_mktime(0, 0, 0, $search_date_signature_startmonth, $search_date_signature_startday, $search_date_signature_startyear);
133 $search_date_signature_end = dol_mktime(23, 59, 59, $search_date_signature_endmonth, $search_date_signature_endday, $search_date_signature_endyear);
134 
135 
136 $search_status = GETPOST('search_status', 'alpha');
137 $optioncss = GETPOST('optioncss', 'alpha');
138 $object_statut = GETPOST('search_statut', 'alpha');
139 
140 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
141 $mesg = (GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg"));
142 
143 
144 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
145 $sortfield = GETPOST('sortfield', 'aZ09comma');
146 $sortorder = GETPOST('sortorder', 'aZ09comma');
147 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
148 if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
149  $page = 0;
150 } // If $page is not defined, or '' or -1
151 $offset = $limit * $page;
152 $pageprev = $page - 1;
153 $pagenext = $page + 1;
154 if (!$sortfield) {
155  $sortfield = 'p.ref';
156 }
157 if (!$sortorder) {
158  $sortorder = 'DESC';
159 }
160 
161 // Security check
162 $module = 'propal';
163 $dbtable = '';
164 $objectid = '';
165 if (!empty($user->socid)) {
166  $socid = $user->socid;
167 }
168 if (!empty($socid)) {
169  $objectid = $socid;
170  $module = 'societe';
171  $dbtable = '&societe';
172 }
173 $result = restrictedArea($user, $module, $objectid, $dbtable);
174 
175 $diroutputmassaction = $conf->propal->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
176 
177 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
178 $object = new Propal($db);
179 $hookmanager->initHooks(array('propallist'));
180 $extrafields = new ExtraFields($db);
181 
182 // fetch optionals attributes and labels
183 $extrafields->fetch_name_optionals_label($object->table_element);
184 
185 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
186 
187 // List of fields to search into when doing a "search in all"
188 $fieldstosearchall = array(
189  'p.ref'=>'Ref',
190  'p.ref_client'=>'RefCustomer',
191  'pd.description'=>'Description',
192  's.nom'=>"ThirdParty",
193  's.name_alias'=>"AliasNameShort",
194  's.zip'=>"Zip",
195  's.town'=>"Town",
196  'p.note_public'=>'NotePublic',
197 );
198 if (empty($user->socid)) {
199  $fieldstosearchall["p.note_private"] = "NotePrivate";
200 }
201 
202 
203 $checkedtypetiers = 0;
204 $arrayfields = array(
205  'p.ref'=>array('label'=>"Ref", 'checked'=>1),
206  'p.ref_client'=>array('label'=>"RefCustomer", 'checked'=>-1),
207  'pr.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1)),
208  'pr.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1)),
209  's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
210  's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>-1),
211  's.town'=>array('label'=>"Town", 'checked'=>-1),
212  's.zip'=>array('label'=>"Zip", 'checked'=>-1),
213  'state.nom'=>array('label'=>"StateShort", 'checked'=>0),
214  'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
215  'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers),
216  'p.date'=>array('label'=>"DatePropal", 'checked'=>1),
217  'p.fin_validite'=>array('label'=>"DateEnd", 'checked'=>1),
218  'p.date_livraison'=>array('label'=>"DeliveryDate", 'checked'=>0),
219  'p.date_signature'=>array('label'=>"DateSigning", 'checked'=>0),
220  'ava.rowid'=>array('label'=>"AvailabilityPeriod", 'checked'=>0),
221  'p.fk_shipping_method'=>array('label'=>"SendingMethod", 'checked'=>0, 'enabled'=>!empty($conf->expedition->enabled)),
222  'p.fk_input_reason'=>array('label'=>"Origin", 'checked'=>0, 'enabled'=>1),
223  'p.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>0),
224  'p.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>0),
225  'p.total_ht'=>array('label'=>"AmountHT", 'checked'=>1),
226  'p.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0),
227  'p.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0),
228  'p.total_ht_invoiced'=>array('label'=>"AmountInvoicedHT", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
229  'p.total_invoiced'=>array('label'=>"AmountInvoicedTTC", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
230  'p.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
231  'p.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
232  'p.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
233  'p.multicurrency_total_tva'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
234  'p.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
235  'p.multicurrency_total_ht_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedHT', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
236  'p.multicurrency_total_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedTTC', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
237  'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>10),
238  'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>-1),
239  'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)),
240  'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)),
241  'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)),
242  'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)),
243  'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
244  'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
245  'p.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>500),
246  'p.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
247  'p.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
248  'p.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
249 );
250 
251 // Extra fields
252 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
253 
254 $permissiontoread = $user->rights->propal->lire;
255 $permissiontoadd = $user->rights->propal->creer;
256 $permissiontodelete = $user->rights->propal->supprimer;
257 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
258  $permissiontovalidate = $user->rights->propal->propal_advance->validate;
259  $permissiontoclose = $user->rights->propal->propal_advance->close;
260  $permissiontosendbymail = $user->rights->propal->propal_advance->send;
261 } else {
262  $permissiontovalidate = $user->rights->propal->creer;
263  $permissiontoclose = $user->rights->propal->creer;
264  $permissiontosendbymail = $user->rights->propal->lire;
265 }
266 
267 
268 /*
269  * Actions
270  */
271 
272 if (GETPOST('cancel', 'alpha')) {
273  $action = 'list';
274  $massaction = '';
275 }
276 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
277  $massaction = '';
278 }
279 
280 $parameters = array('socid'=>$socid, 'arrayfields'=>&$arrayfields);
281 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
282 if ($reshook < 0) {
283  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
284 }
285 
286 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
287 
288 // Do we click on purge search criteria ?
289 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
290  $search_categ = '';
291  $search_user = '';
292  $search_sale = '';
293  $search_ref = '';
294  $search_refcustomer = '';
295  $search_refproject = '';
296  $search_project = '';
297  $search_societe = '';
298  $search_societe_alias = '';
299  $search_montant_ht = '';
300  $search_montant_vat = '';
301  $search_montant_ttc = '';
302  $search_warehouse = '';
303  $search_multicurrency_code = '';
304  $search_multicurrency_tx = '';
305  $search_multicurrency_montant_ht = '';
306  $search_multicurrency_montant_vat = '';
307  $search_multicurrency_montant_ttc = '';
308  $search_login = '';
309  $search_product_category = '';
310  $search_town = '';
311  $search_zip = "";
312  $search_state = "";
313  $search_type = '';
314  $search_country = '';
315  $search_type_thirdparty = '';
316  $search_date_startday = '';
317  $search_date_startmonth = '';
318  $search_date_startyear = '';
319  $search_date_endday = '';
320  $search_date_endmonth = '';
321  $search_date_endyear = '';
322  $search_date_start = '';
323  $search_date_end = '';
324  $search_date_end_startday = '';
325  $search_date_end_startmonth = '';
326  $search_date_end_startyear = '';
327  $search_date_end_endday = '';
328  $search_date_end_endmonth = '';
329  $search_date_end_endyear = '';
330  $search_date_end_start = '';
331  $search_date_end_end = '';
332  $search_date_delivery_startday = '';
333  $search_date_delivery_startmonth = '';
334  $search_date_delivery_startyear = '';
335  $search_date_delivery_endday = '';
336  $search_date_delivery_endmonth = '';
337  $search_date_delivery_endyear = '';
338  $search_date_delivery_start = '';
339  $search_date_delivery_end = '';
340  $search_availability = '';
341  $search_status = '';
342  $object_statut = '';
343  $toselect = array();
344  $search_array_options = array();
345  $search_categ_cus = 0;
346  $search_fk_cond_reglement = '';
347  $search_fk_shipping_method = '';
348  $search_fk_input_reason = '';
349  $search_fk_mode_reglement = '';
350  $search_date_signature_startday = '';
351  $search_date_signature_startmonth = '';
352  $search_date_signature_startyear = '';
353  $search_date_signature_endday = '';
354  $search_date_signature_endmonth = '';
355  $search_date_signature_endyear = '';
356  $search_date_signature_start = '';
357  $search_date_signature_end = '';
358 }
359 if ($object_statut != '') {
360  $search_status = $object_statut;
361 }
362 
363 
364 if (empty($reshook)) {
365  $objectclass = 'Propal';
366  $objectlabel = 'Proposals';
367  $uploaddir = $conf->propal->multidir_output[$conf->entity];
368  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
369 }
370 
371 if ($action == 'validate' && $permissiontovalidate) {
372  if (GETPOST('confirm') == 'yes') {
373  $tmpproposal = new Propal($db);
374  $db->begin();
375  $error = 0;
376  foreach ($toselect as $checked) {
377  if ($tmpproposal->fetch($checked) > 0) {
378  if ($tmpproposal->statut == $tmpproposal::STATUS_DRAFT) {
379  if ($tmpproposal->valid($user) > 0) {
380  setEventMessages($langs->trans('hasBeenValidated', $tmpproposal->ref), null, 'mesgs');
381  } else {
382  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
383  $error++;
384  }
385  } else {
386  $langs->load("errors");
387  setEventMessages($langs->trans('ErrorIsNotADraft', $tmpproposal->ref), null, 'errors');
388  $error++;
389  }
390  } else {
391  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
392  $error++;
393  }
394  }
395  if ($error) {
396  $db->rollback();
397  } else {
398  $db->commit();
399  }
400  }
401 }
402 
403 if ($action == "sign" && $permissiontoclose) {
404  if (GETPOST('confirm') == 'yes') {
405  $tmpproposal = new Propal($db);
406  $db->begin();
407  $error = 0;
408  foreach ($toselect as $checked) {
409  if ($tmpproposal->fetch($checked) > 0) {
410  if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED) {
411  $tmpproposal->statut = $tmpproposal::STATUS_SIGNED;
412  if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_SIGNED) >= 0) {
413  setEventMessages($tmpproposal->ref." ".$langs->trans('Signed'), null, 'mesgs');
414  } else {
415  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
416  $error++;
417  }
418  } else {
419  setEventMessage($langs->trans('MustBeValidatedToBeSigned', $tmpproposal->ref), 'errors');
420  $error++;
421  }
422  } else {
423  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
424  $error++;
425  }
426  }
427  if ($error) {
428  $db->rollback();
429  } else {
430  $db->commit();
431  }
432  }
433 }
434 
435 if ($action == "nosign" && $permissiontoclose) {
436  if (GETPOST('confirm') == 'yes') {
437  $tmpproposal = new Propal($db);
438  $db->begin();
439  $error = 0;
440  foreach ($toselect as $checked) {
441  if ($tmpproposal->fetch($checked) > 0) {
442  if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED) {
443  $tmpproposal->statut = $tmpproposal::STATUS_NOTSIGNED;
444  if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_NOTSIGNED) > 0) {
445  setEventMessage($tmpproposal->ref." ".$langs->trans('NoSigned'), 'mesgs');
446  } else {
447  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
448  $error++;
449  }
450  } else {
451  setEventMessage($tmpproposal->ref." ".$langs->trans('CantBeNoSign'), 'errors');
452  $error++;
453  }
454  } else {
455  setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
456  $error++;
457  }
458  }
459  if ($error) {
460  $db->rollback();
461  } else {
462  $db->commit();
463  }
464  }
465 }
466 
467 // Closed records
468 if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
469  $db->begin();
470 
471  $objecttmp = new $objectclass($db);
472  $nbok = 0;
473  foreach ($toselect as $toselectid) {
474  $result = $objecttmp->fetch($toselectid);
475  if ($result > 0) {
476  $result = $objecttmp->classifyBilled($user, 0);
477  if ($result <= 0) {
478  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
479  $error++;
480  break;
481  } else {
482  $nbok++;
483  }
484  } else {
485  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
486  $error++;
487  break;
488  }
489  }
490 
491  if (!$error) {
492  if ($nbok > 1) {
493  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
494  } else {
495  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
496  }
497  $db->commit();
498  } else {
499  $db->rollback();
500  }
501 }
502 
503 
504 
505 /*
506  * View
507  */
508 
509 $now = dol_now();
510 
511 $form = new Form($db);
512 $formother = new FormOther($db);
513 $formfile = new FormFile($db);
514 $formpropal = new FormPropal($db);
515 $formmargin = null;
516 if (!empty($conf->margin->enabled)) {
517  $formmargin = new FormMargin($db);
518 }
519 $companystatic = new Societe($db);
520 $projectstatic = new Project($db);
521 $formcompany = new FormCompany($db);
522 
523 $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos';
524 //llxHeader('',$langs->trans('Proposal'),$help_url);
525 
526 $sql = 'SELECT';
527 if ($sall || $search_product_category > 0 || $search_user > 0) {
528  $sql = 'SELECT DISTINCT';
529 }
530 $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax , s.address, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
531 $sql .= " typent.code as typent_code,";
532 $sql .= " ava.rowid as availability,";
533 $sql .= " country.code as country_code,";
534 $sql .= " state.code_departement as state_code, state.nom as state_name,";
535 $sql .= ' p.rowid, p.entity as propal_entity, p.note_private, p.total_ht, p.total_tva, p.total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut as status, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,p.date_livraison as ddelivery,';
536 $sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc,';
537 $sql .= ' p.datec as date_creation, p.tms as date_update, p.date_cloture as date_cloture,';
538 $sql .= ' p.date_signature as dsignature,';
539 $sql .= ' p.note_public, p.note_private,';
540 $sql .= ' p.fk_cond_reglement,p.deposit_percent,p.fk_mode_reglement,p.fk_shipping_method,p.fk_input_reason,';
541 $sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label,";
542 $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity as user_entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
543 if (empty($user->rights->societe->client->voir) && !$socid) {
544  $sql .= ", sc.fk_soc, sc.fk_user";
545 }
546 if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
547  $sql .= ", cc.fk_categorie, cc.fk_soc";
548 }
549 // Add fields from extrafields
550 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
551  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
552  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
553  }
554 }
555 // Add fields from hooks
556 $parameters = array();
557 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
558 $sql .= $hookmanager->resPrint;
559 $sql = preg_replace('/, $/', '', $sql);
560 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
561 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
562 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
563 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
564 if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
565  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
566 }
567 $sql .= ', '.MAIN_DB_PREFIX.'propal as p';
568 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
569  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
570 }
571 if ($sall || $search_product_category > 0) {
572  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal';
573 }
574 if ($search_product_category > 0) {
575  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
576 }
577 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid';
578 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = p.fk_projet";
579 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_availability as ava on (ava.rowid = p.fk_availability)";
580 // We'll need this table joined to the select in order to filter by sale
581 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
582  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
583 }
584 if ($search_user > 0) {
585  $sql .= ", ".MAIN_DB_PREFIX."element_contact as c";
586  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
587 }
588 
589 // Add table from hooks
590 $parameters = array();
591 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
592 $sql .= $hookmanager->resPrint;
593 
594 $sql .= ' WHERE p.fk_soc = s.rowid';
595 $sql .= ' AND p.entity IN ('.getEntity('propal').')';
596 if (empty($user->rights->societe->client->voir) && !$socid) { //restriction
597  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
598 }
599 
600 if ($search_town) {
601  $sql .= natural_search('s.town', $search_town);
602 }
603 if ($search_zip) {
604  $sql .= natural_search("s.zip", $search_zip);
605 }
606 if ($search_state) {
607  $sql .= natural_search("state.nom", $search_state);
608 }
609 if ($search_country) {
610  $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
611 }
612 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
613  $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
614 }
615 if ($search_ref) {
616  $sql .= natural_search('p.ref', $search_ref);
617 }
618 if ($search_refcustomer) {
619  $sql .= natural_search('p.ref_client', $search_refcustomer);
620 }
621 if ($search_refproject) {
622  $sql .= natural_search('pr.ref', $search_refproject);
623 }
624 if ($search_project) {
625  $sql .= natural_search('pr.title', $search_project);
626 }
627 if ($search_availability) {
628  $sql .= " AND p.fk_availability IN (".$db->sanitize($db->escape($search_availability)).')';
629 }
630 if ($search_societe) {
631  $sql .= natural_search('s.nom', $search_societe);
632 }
633 if ($search_societe_alias) {
634  $sql .= natural_search('s.name_alias', $search_societe_alias);
635 }
636 if ($search_login) {
637  $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
638 }
639 if ($search_montant_ht != '') {
640  $sql .= natural_search("p.total_ht", $search_montant_ht, 1);
641 }
642 if ($search_montant_vat != '') {
643  $sql .= natural_search("p.total_tva", $search_montant_vat, 1);
644 }
645 if ($search_montant_ttc != '') {
646  $sql .= natural_search("p.total_ttc", $search_montant_ttc, 1);
647 }
648 if ($search_warehouse != '' && $search_warehouse > 0) {
649  $sql .= natural_search("p.fk_warehouse", $search_warehouse, 1);
650 }
651 if ($search_multicurrency_code != '') {
652  $sql .= " AND p.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
653 }
654 if ($search_multicurrency_tx != '') {
655  $sql .= natural_search('p.multicurrency_tx', $search_multicurrency_tx, 1);
656 }
657 if ($search_multicurrency_montant_ht != '') {
658  $sql .= natural_search('p.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
659 }
660 if ($search_multicurrency_montant_vat != '') {
661  $sql .= natural_search('p.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
662 }
663 if ($search_multicurrency_montant_ttc != '') {
664  $sql .= natural_search('p.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
665 }
666 if ($sall) {
667  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
668 }
669 
670 if ($search_categ_cus > 0) {
671  $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
672 }
673 if ($search_categ_cus == -2) {
674  $sql .= " AND cc.fk_categorie IS NULL";
675 }
676 
677 if ($search_fk_cond_reglement > 0) {
678  $sql .= " AND p.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
679 }
680 if ($search_fk_shipping_method > 0) {
681  $sql .= " AND p.fk_shipping_method = ".((int) $search_fk_shipping_method);
682 }
683 if ($search_fk_input_reason > 0) {
684  $sql .= " AND p.fk_input_reason = ".((int) $search_fk_input_reason);
685 }
686 if ($search_fk_mode_reglement > 0) {
687  $sql .= " AND p.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
688 }
689 
690 if ($search_product_category > 0) {
691  $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
692 }
693 if ($socid > 0) {
694  $sql .= ' AND s.rowid = '.((int) $socid);
695 }
696 if ($search_status != '' && $search_status != '-1') {
697  $sql .= ' AND p.fk_statut IN ('.$db->sanitize($search_status).')';
698 }
699 if ($search_date_start) {
700  $sql .= " AND p.datep >= '".$db->idate($search_date_start)."'";
701 }
702 if ($search_date_end) {
703  $sql .= " AND p.datep <= '".$db->idate($search_date_end)."'";
704 }
705 if ($search_date_end_start) {
706  $sql .= " AND p.fin_validite >= '".$db->idate($search_date_end_start)."'";
707 }
708 if ($search_date_end_end) {
709  $sql .= " AND p.fin_validite <= '".$db->idate($search_date_end_end)."'";
710 }
711 if ($search_date_delivery_start) {
712  $sql .= " AND p.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
713 }
714 if ($search_date_delivery_end) {
715  $sql .= " AND p.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
716 }
717 if ($search_sale > 0) {
718  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
719 }
720 if ($search_user > 0) {
721  $sql .= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".((int) $search_user);
722 }
723 if ($search_date_signature_start) {
724  $sql .= " AND p.date_signature >= '".$db->idate($search_date_signature_start)."'";
725 }
726 if ($search_date_signature_end) {
727  $sql .= " AND p.date_signature <= '".$db->idate($search_date_signature_end)."'";
728 }
729 // Add where from extra fields
730 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
731 
732 // Add where from hooks
733 $parameters = array();
734 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
735 $sql .= $hookmanager->resPrint;
736 
737 // Add HAVING from hooks
738 $parameters = array();
739 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
740 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
741 
742 $sql .= $db->order($sortfield, $sortorder);
743 $sql .= ', p.ref DESC';
744 
745 // Count total nb of records
746 $nbtotalofrecords = '';
747 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
748  $result = $db->query($sql);
749  $nbtotalofrecords = $db->num_rows($result);
750 
751  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
752  $page = 0;
753  $offset = 0;
754  }
755 }
756 
757 $sql .= $db->plimit($limit + 1, $offset);
758 
759 $resql = $db->query($sql);
760 
761 if ($resql) {
762  $objectstatic = new Propal($db);
763  $userstatic = new User($db);
764 
765  if ($socid > 0) {
766  $soc = new Societe($db);
767  $soc->fetch($socid);
768  $title = $langs->trans('Proposals').' - '.$soc->name;
769  if (empty($search_societe)) {
770  $search_societe = $soc->name;
771  }
772  } else {
773  $title = $langs->trans('Proposals');
774  }
775 
776  $num = $db->num_rows($resql);
777 
778  $arrayofselected = is_array($toselect) ? $toselect : array();
779 
780  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
781  $obj = $db->fetch_object($resql);
782 
783  $id = $obj->rowid;
784 
785  header("Location: ".DOL_URL_ROOT.'/comm/propal/card.php?id='.$id);
786  exit;
787  }
788 
789  llxHeader('', $langs->trans('Proposal'), $help_url);
790 
791  $param = '&search_status='.urlencode($search_status);
792  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
793  $param .= '&contextpage='.urlencode($contextpage);
794  }
795  if ($limit > 0 && $limit != $conf->liste_limit) {
796  $param .= '&limit='.urlencode($limit);
797  }
798  if ($sall) {
799  $param .= '&sall='.urlencode($sall);
800  }
801  if ($search_date_startday) {
802  $param .= '&search_date_startday='.urlencode($search_date_startday);
803  }
804  if ($search_date_startmonth) {
805  $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
806  }
807  if ($search_date_startyear) {
808  $param .= '&search_date_startyear='.urlencode($search_date_startyear);
809  }
810  if ($search_date_endday) {
811  $param .= '&search_date_endday='.urlencode($search_date_endday);
812  }
813  if ($search_date_endmonth) {
814  $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
815  }
816  if ($search_date_endyear) {
817  $param .= '&search_date_endyear='.urlencode($search_date_endyear);
818  }
819  if ($search_date_end_startday) {
820  $param .= '&search_date_end_startday='.urlencode($search_date_end_startday);
821  }
822  if ($search_date_end_startmonth) {
823  $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth);
824  }
825  if ($search_date_end_startyear) {
826  $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear);
827  }
828  if ($search_date_end_endday) {
829  $param .= '&search_date_end_endday='.urlencode($search_date_end_endday);
830  }
831  if ($search_date_end_endmonth) {
832  $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth);
833  }
834  if ($search_date_end_endyear) {
835  $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear);
836  }
837  if ($search_date_delivery_startday) {
838  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
839  }
840  if ($search_date_delivery_startmonth) {
841  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
842  }
843  if ($search_date_delivery_startyear) {
844  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
845  }
846  if ($search_date_delivery_endday) {
847  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
848  }
849  if ($search_date_delivery_endmonth) {
850  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
851  }
852  if ($search_date_delivery_endyear) {
853  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
854  }
855  if ($search_ref) {
856  $param .= '&search_ref='.urlencode($search_ref);
857  }
858  if ($search_refcustomer) {
859  $param .= '&search_refcustomer='.urlencode($search_refcustomer);
860  }
861  if ($search_refproject) {
862  $param .= '&search_refproject='.urlencode($search_refproject);
863  }
864  if ($search_societe) {
865  $param .= '&search_societe='.urlencode($search_societe);
866  }
867  if ($search_societe_alias) {
868  $param .= '&search_societe_alias='.urlencode($search_societe_alias);
869  }
870  if ($search_user > 0) {
871  $param .= '&search_user='.urlencode($search_user);
872  }
873  if ($search_sale > 0) {
874  $param .= '&search_sale='.urlencode($search_sale);
875  }
876  if ($search_montant_ht) {
877  $param .= '&search_montant_ht='.urlencode($search_montant_ht);
878  }
879  if ($search_multicurrency_code != '') {
880  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
881  }
882  if ($search_multicurrency_tx != '') {
883  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
884  }
885  if ($search_multicurrency_montant_ht != '') {
886  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
887  }
888  if ($search_multicurrency_montant_vat != '') {
889  $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
890  }
891  if ($search_multicurrency_montant_ttc != '') {
892  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
893  }
894  if ($search_login) {
895  $param .= '&search_login='.urlencode($search_login);
896  }
897  if ($search_town) {
898  $param .= '&search_town='.urlencode($search_town);
899  }
900  if ($search_zip) {
901  $param .= '&search_zip='.urlencode($search_zip);
902  }
903  if ($socid > 0) {
904  $param .= '&socid='.urlencode($socid);
905  }
906  if ($optioncss != '') {
907  $param .= '&optioncss='.urlencode($optioncss);
908  }
909  if ($search_categ_cus > 0) {
910  $param .= '&search_categ_cus='.urlencode($search_categ_cus);
911  }
912  if ($search_product_category != '') {
913  $param .= '&search_product_category='.urlencode($search_product_category);
914  }
915  if ($search_fk_cond_reglement > 0) {
916  $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
917  }
918  if ($search_fk_shipping_method > 0) {
919  $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
920  }
921  if ($search_fk_input_reason > 0) {
922  $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
923  }
924  if ($search_fk_mode_reglement > 0) {
925  $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
926  }
927  if ($search_type_thirdparty > 0) {
928  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
929  }
930  if ($search_town) {
931  $param .= '&search_town='.urlencode($search_town);
932  }
933  if ($search_zip) {
934  $param .= '&search_zip='.urlencode($search_zip);
935  }
936  if ($search_state) {
937  $param .= '&search_state='.urlencode($search_state);
938  }
939  if ($search_town) {
940  $param .= '&search_town='.urlencode($search_town);
941  }
942  if ($search_country) {
943  $param .= '&search_country='.urlencode($search_country);
944  }
945  if ($search_date_signature_startday) {
946  $param .= '&search_date_signature_startday='.urlencode($search_date_signature_startday);
947  }
948  if ($search_date_signature_startmonth) {
949  $param .= '&search_date_signature_startmonth='.urlencode($search_date_signature_startmonth);
950  }
951  if ($search_date_signature_startyear) {
952  $param .= '&search_date_signature_startyear='.urlencode($search_date_signature_startyear);
953  }
954  if ($search_date_signature_endday) {
955  $param .= '&search_date_signature_endday='.urlencode($search_date_signature_endday);
956  }
957  if ($search_date_signature_endmonth) {
958  $param .= '&search_date_signature_endmonth='.urlencode($search_date_signature_endmonth);
959  }
960  if ($search_date_signature_endyear) {
961  $param .= '&search_date_signature_endyear='.urlencode($search_date_signature_endyear);
962  }
963 
964  // Add $param from extra fields
965  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
966  // Add $param from hooks
967  $parameters = array();
968  $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
969  $param .= $hookmanager->resPrint;
970 
971  // List of mass actions available
972  $arrayofmassactions = array(
973  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
974  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
975  );
976  if ($permissiontosendbymail) {
977  $arrayofmassactions['presend']=img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
978  }
979  if ($permissiontovalidate) {
980  $arrayofmassactions['prevalidate']=img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
981  }
982  if ($permissiontoclose) {
983  $arrayofmassactions['presign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("Sign");
984  $arrayofmassactions['nopresign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("NoSign");
985  $arrayofmassactions['setbilled'] =img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
986  }
987  if ($permissiontodelete) {
988  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
989  }
990 
991  if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
992  $arrayofmassactions = array();
993  }
994  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
995 
996  $url = DOL_URL_ROOT.'/comm/propal/card.php?action=create';
997  if (!empty($socid)) {
998  $url .= '&socid='.$socid;
999  }
1000  $newcardbutton = dolGetButtonTitle($langs->trans('NewPropal'), '', 'fa fa-plus-circle', $url, '', $user->rights->propal->creer);
1001 
1002  // Fields title search
1003  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
1004  if ($optioncss != '') {
1005  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1006  }
1007  print '<input type="hidden" name="token" value="'.newToken().'">';
1008  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1009  print '<input type="hidden" name="action" value="list">';
1010  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1011  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1012  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1013 
1014  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'propal', 0, $newcardbutton, '', $limit, 0, 0, 1);
1015 
1016  $topicmail = "SendPropalRef";
1017  $modelmail = "propal_send";
1018  $objecttmp = new Propal($db);
1019  $trackid = 'pro'.$object->id;
1020  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1021 
1022  if ($massaction == 'prevalidate') {
1023  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1024  }
1025 
1026  if ($massaction == 'presign') {
1027  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassSignature"), $langs->trans("ConfirmMassSignatureQuestion"), "sign", null, '', 0, 200, 500, 1);
1028  }
1029 
1030  if ($massaction == 'nopresign') {
1031  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassNoSignature"), $langs->trans("ConfirmMassNoSignatureQuestion"), "nosign", null, '', 0, 200, 500, 1);
1032  }
1033 
1034  if ($sall) {
1035  foreach ($fieldstosearchall as $key => $val) {
1036  $fieldstosearchall[$key] = $langs->trans($val);
1037  }
1038  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1039  }
1040 
1041  $i = 0;
1042 
1043  $moreforfilter = '';
1044 
1045  // If the user can view prospects other than his'
1046  if ($user->rights->user->user->lire) {
1047  $langs->load("commercial");
1048  $moreforfilter .= '<div class="divsearchfield">';
1049  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1050  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1051  $moreforfilter .= '</div>';
1052  }
1053  // If the user can view prospects other than his'
1054  if ($user->rights->user->user->lire) {
1055  $moreforfilter .= '<div class="divsearchfield">';
1056  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1057  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1058  $moreforfilter .= '</div>';
1059  }
1060  // If the user can view products
1061  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
1062  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1063  $moreforfilter .= '<div class="divsearchfield">';
1064  $tmptitle = $langs->trans('IncludingProductWithTag');
1065  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1066  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300 widthcentpercentminusx' : 'maxwidth250 widthcentpercentminusx'), 1);
1067  $moreforfilter .= '</div>';
1068  }
1069  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
1070  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1071  $moreforfilter .= '<div class="divsearchfield">';
1072  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1073  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300 widthcentpercentminusx' : 'maxwidth250 widthcentpercentminusx'));
1074  $moreforfilter .= '</div>';
1075  }
1076  if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1077  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1078  $formproduct = new FormProduct($db);
1079  $moreforfilter .= '<div class="divsearchfield">';
1080  $tmptitle = $langs->trans('Warehouse');
1081  $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', $tmptitle, 0, 0, $tmptitle);
1082  $moreforfilter .= '</div>';
1083  }
1084  $parameters = array();
1085  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1086  if (empty($reshook)) {
1087  $moreforfilter .= $hookmanager->resPrint;
1088  } else {
1089  $moreforfilter = $hookmanager->resPrint;
1090  }
1091 
1092  if (!empty($moreforfilter)) {
1093  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1094  print $moreforfilter;
1095  print '</div>';
1096  }
1097 
1098  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1099  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1100  $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1101 
1102  print '<div class="div-table-responsive">';
1103  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1104 
1105  print '<tr class="liste_titre_filter">';
1106  if (!empty($arrayfields['p.ref']['checked'])) {
1107  print '<td class="liste_titre">';
1108  print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1109  print '</td>';
1110  }
1111  if (!empty($arrayfields['p.ref_client']['checked'])) {
1112  print '<td class="liste_titre">';
1113  print '<input class="flat maxwidth50" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
1114  print '</td>';
1115  }
1116  if (!empty($arrayfields['pr.ref']['checked'])) {
1117  print '<td class="liste_titre">';
1118  print '<input class="flat maxwidth50" type="text" name="search_refproject" value="'.dol_escape_htmltag($search_refproject).'">';
1119  print '</td>';
1120  }
1121  if (!empty($arrayfields['pr.title']['checked'])) {
1122  print '<td class="liste_titre">';
1123  print '<input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'">';
1124  print '</td>';
1125  }
1126  if (!empty($arrayfields['s.nom']['checked'])) {
1127  print '<td class="liste_titre" align="left">';
1128  print '<input class="flat maxwidth100" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
1129  print '</td>';
1130  }
1131  if (!empty($arrayfields['s.name_alias']['checked'])) {
1132  print '<td class="liste_titre" align="left">';
1133  print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
1134  print '</td>';
1135  }
1136  if (!empty($arrayfields['s.town']['checked'])) {
1137  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
1138  }
1139  if (!empty($arrayfields['s.zip']['checked'])) {
1140  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
1141  }
1142  // State
1143  if (!empty($arrayfields['state.nom']['checked'])) {
1144  print '<td class="liste_titre">';
1145  print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1146  print '</td>';
1147  }
1148  // Country
1149  if (!empty($arrayfields['country.code_iso']['checked'])) {
1150  print '<td class="liste_titre" align="center">';
1151  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1152  print '</td>';
1153  }
1154  // Company type
1155  if (!empty($arrayfields['typent.code']['checked'])) {
1156  print '<td class="liste_titre maxwidth100onsmartphone" align="center">';
1157  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);
1158  print ajax_combobox('search_type_thirdparty');
1159  print '</td>';
1160  }
1161  // Date
1162  if (!empty($arrayfields['p.date']['checked'])) {
1163  print '<td class="liste_titre center">';
1164  print '<div class="nowrap">';
1165  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1166  print '</div>';
1167  print '<div class="nowrap">';
1168  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1169  print '</div>';
1170  print '</td>';
1171  }
1172  // Date end
1173  if (!empty($arrayfields['p.fin_validite']['checked'])) {
1174  print '<td class="liste_titre center">';
1175  print '<div class="nowrap">';
1176  print $form->selectDate($search_date_end_start ? $search_date_end_start : -1, 'search_date_end_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1177  print '</div>';
1178  print '<div class="nowrap">';
1179  print $form->selectDate($search_date_end_end ? $search_date_end_end : -1, 'search_date_end_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1180  print '</div>';
1181  print '</td>';
1182  }
1183  // Date delivery
1184  if (!empty($arrayfields['p.date_livraison']['checked'])) {
1185  print '<td class="liste_titre center">';
1186  print '<div class="nowrap">';
1187  print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1188  print '</div>';
1189  print '<div class="nowrap">';
1190  print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1191  print '</div>';
1192  print '</td>';
1193  }
1194  // Date Signature
1195  if (!empty($arrayfields['p.date_signature']['checked'])) {
1196  print '<td class="liste_titre center">';
1197  print '<div class="nowrap">';
1198  print $form->selectDate($search_date_signature_start ? $search_date_signature_start : -1, 'search_date_signature_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1199  print '</div>';
1200  print '<div class="nowrap">';
1201  print $form->selectDate($search_date_signature_end ? $search_date_signature_end : -1, 'search_date_signature_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1202  print '</div>';
1203  print '</td>';
1204  }
1205  // Availability
1206  if (!empty($arrayfields['ava.rowid']['checked'])) {
1207  print '<td class="liste_titre maxwidth100onsmartphone center">';
1208  $form->selectAvailabilityDelay($search_availability, 'search_availability', '', 1);
1209  print ajax_combobox('search_availability');
1210  print '</td>';
1211  }
1212  // Shipping Method
1213  if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1214  print '<td class="liste_titre">';
1215  $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1216  print '</td>';
1217  }
1218  // Source - Input reason
1219  if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1220  print '<td class="liste_titre">';
1221  $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, 'maxwidth125', 1);
1222  print '</td>';
1223  }
1224  // Payment term
1225  if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1226  print '<td class="liste_titre">';
1227  $form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
1228  print '</td>';
1229  }
1230  // Payment mode
1231  if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1232  print '<td class="liste_titre">';
1233  $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1);
1234  print '</td>';
1235  }
1236  if (!empty($arrayfields['p.total_ht']['checked'])) {
1237  // Amount
1238  print '<td class="liste_titre right">';
1239  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1240  print '</td>';
1241  }
1242  if (!empty($arrayfields['p.total_tva']['checked'])) {
1243  // Amount
1244  print '<td class="liste_titre right">';
1245  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1246  print '</td>';
1247  }
1248  if (!empty($arrayfields['p.total_ttc']['checked'])) {
1249  // Amount
1250  print '<td class="liste_titre right">';
1251  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1252  print '</td>';
1253  }
1254  if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1255  // Amount invoiced
1256  print '<td class="liste_titre right">';
1257  print '</td>';
1258  }
1259  if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1260  // Amount invoiced
1261  print '<td class="liste_titre right">';
1262  print '</td>';
1263  }
1264  if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1265  // Currency
1266  print '<td class="liste_titre">';
1267  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1268  print '</td>';
1269  }
1270  if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1271  // Currency rate
1272  print '<td class="liste_titre">';
1273  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1274  print '</td>';
1275  }
1276  if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1277  // Amount
1278  print '<td class="liste_titre right">';
1279  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1280  print '</td>';
1281  }
1282  if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1283  // Amount
1284  print '<td class="liste_titre right">';
1285  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1286  print '</td>';
1287  }
1288  if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1289  // Amount
1290  print '<td class="liste_titre right">';
1291  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1292  print '</td>';
1293  }
1294  if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1295  // Amount invoiced
1296  print '<td class="liste_titre right">';
1297  print '</td>';
1298  }
1299  if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1300  // Amount invoiced
1301  print '<td class="liste_titre right">';
1302  print '</td>';
1303  }
1304  if (!empty($arrayfields['u.login']['checked'])) {
1305  // Author
1306  print '<td class="liste_titre" align="center">';
1307  print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1308  print '</td>';
1309  }
1310  if (!empty($arrayfields['sale_representative']['checked'])) {
1311  print '<td class="liste_titre"></td>';
1312  }
1313  if (!empty($arrayfields['total_pa']['checked'])) {
1314  print '<td class="liste_titre right">';
1315  print '</td>';
1316  }
1317  if (!empty($arrayfields['total_margin']['checked'])) {
1318  print '<td class="liste_titre right">';
1319  print '</td>';
1320  }
1321  if (!empty($arrayfields['total_margin_rate']['checked'])) {
1322  print '<td class="liste_titre right">';
1323  print '</td>';
1324  }
1325  if (!empty($arrayfields['total_mark_rate']['checked'])) {
1326  print '<td class="liste_titre right">';
1327  print '</td>';
1328  }
1329  // Extra fields
1330  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1331 
1332  // Fields from hook
1333  $parameters = array('arrayfields'=>$arrayfields);
1334  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1335  print $hookmanager->resPrint;
1336  // Date creation
1337  if (!empty($arrayfields['p.datec']['checked'])) {
1338  print '<td class="liste_titre">';
1339  print '</td>';
1340  }
1341  // Date modification
1342  if (!empty($arrayfields['p.tms']['checked'])) {
1343  print '<td class="liste_titre">';
1344  print '</td>';
1345  }
1346  // Date cloture
1347  if (!empty($arrayfields['p.date_cloture']['checked'])) {
1348  print '<td class="liste_titre">';
1349  print '</td>';
1350  }
1351  if (!empty($arrayfields['p.note_public']['checked'])) {
1352  // Note public
1353  print '<td class="liste_titre">';
1354  print '</td>';
1355  }
1356  if (!empty($arrayfields['p.note_private']['checked'])) {
1357  // Note private
1358  print '<td class="liste_titre">';
1359  print '</td>';
1360  }
1361  // Status
1362  if (!empty($arrayfields['p.fk_statut']['checked'])) {
1363  print '<td class="liste_titre maxwidthonsmartphone right">';
1364  $formpropal->selectProposalStatus($search_status, 1, 0, 1, 'customer', 'search_statut');
1365  print '</td>';
1366  }
1367  // Action column
1368  print '<td class="liste_titre" align="middle">';
1369  $searchpicto = $form->showFilterButtons();
1370  print $searchpicto;
1371  print '</td>';
1372 
1373  print "</tr>\n";
1374 
1375  $totalarray = array(
1376  'nbfield' => 0,
1377  'val' => array(
1378  'p.total_ht' => 0,
1379  'p.total_tva' => 0,
1380  'p.total_ttc' => 0,
1381  ),
1382  );
1383 
1384  // Fields title
1385  print '<tr class="liste_titre">';
1386  if (!empty($arrayfields['p.ref']['checked'])) {
1387  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
1388  }
1389  if (!empty($arrayfields['p.ref_client']['checked'])) {
1390  print_liste_field_titre($arrayfields['p.ref_client']['label'], $_SERVER["PHP_SELF"], 'p.ref_client', '', $param, '', $sortfield, $sortorder);
1391  }
1392  if (!empty($arrayfields['pr.ref']['checked'])) {
1393  print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
1394  }
1395  if (!empty($arrayfields['pr.title']['checked'])) {
1396  print_liste_field_titre($arrayfields['pr.title']['label'], $_SERVER["PHP_SELF"], 'pr.title', '', $param, '', $sortfield, $sortorder);
1397  }
1398  if (!empty($arrayfields['s.nom']['checked'])) {
1399  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1400  }
1401  if (!empty($arrayfields['s.name_alias']['checked'])) {
1402  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1403  }
1404  if (!empty($arrayfields['s.town']['checked'])) {
1405  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1406  }
1407  if (!empty($arrayfields['s.zip']['checked'])) {
1408  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1409  }
1410  if (!empty($arrayfields['state.nom']['checked'])) {
1411  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1412  }
1413  if (!empty($arrayfields['country.code_iso']['checked'])) {
1414  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
1415  }
1416  if (!empty($arrayfields['typent.code']['checked'])) {
1417  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
1418  }
1419  if (!empty($arrayfields['p.date']['checked'])) {
1420  print_liste_field_titre($arrayfields['p.date']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, 'align="center"', $sortfield, $sortorder);
1421  }
1422  if (!empty($arrayfields['p.fin_validite']['checked'])) {
1423  print_liste_field_titre($arrayfields['p.fin_validite']['label'], $_SERVER["PHP_SELF"], 'dfv', '', $param, 'align="center"', $sortfield, $sortorder);
1424  }
1425  if (!empty($arrayfields['p.date_livraison']['checked'])) {
1426  print_liste_field_titre($arrayfields['p.date_livraison']['label'], $_SERVER["PHP_SELF"], 'p.date_livraison', '', $param, 'align="center"', $sortfield, $sortorder);
1427  }
1428  if (!empty($arrayfields['p.date_signature']['checked'])) {
1429  print_liste_field_titre($arrayfields['p.date_signature']['label'], $_SERVER["PHP_SELF"], 'p.date_signature', '', $param, 'align="center"', $sortfield, $sortorder);
1430  }
1431  if (!empty($arrayfields['ava.rowid']['checked'])) {
1432  print_liste_field_titre($arrayfields['ava.rowid']['label'], $_SERVER["PHP_SELF"], 'availability', '', $param, '', $sortfield, $sortorder);
1433  }
1434  if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1435  print_liste_field_titre($arrayfields['p.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "p.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1436  }
1437  if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1438  print_liste_field_titre($arrayfields['p.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "p.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1439  }
1440  if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1441  print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1442  }
1443  if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1444  print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1445  }
1446  if (!empty($arrayfields['p.total_ht']['checked'])) {
1447  print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1448  }
1449  if (!empty($arrayfields['p.total_tva']['checked'])) {
1450  print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1451  }
1452  if (!empty($arrayfields['p.total_ttc']['checked'])) {
1453  print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1454  }
1455  if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1456  print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1457  }
1458  if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1459  print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1460  }
1461  if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1462  print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1463  }
1464  if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1465  print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1466  }
1467  if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1468  print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1469  }
1470  if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1471  print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1472  }
1473  if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1474  print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1475  }
1476  if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1477  print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1478  }
1479  if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1480  print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1481  }
1482  if (!empty($arrayfields['u.login']['checked'])) {
1483  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1484  }
1485  if (!empty($arrayfields['sale_representative']['checked'])) {
1486  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1487  }
1488  if (!empty($arrayfields['total_pa']['checked'])) {
1489  print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1490  }
1491  if (!empty($arrayfields['total_margin']['checked'])) {
1492  print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1493  }
1494  if (!empty($arrayfields['total_margin_rate']['checked'])) {
1495  print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1496  }
1497  if (!empty($arrayfields['total_mark_rate']['checked'])) {
1498  print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1499  }
1500  // Extra fields
1501  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1502  // Hook fields
1503  $parameters = array(
1504  'arrayfields' => $arrayfields,
1505  'param' => $param,
1506  'sortfield' => $sortfield,
1507  'sortorder' => $sortorder,
1508  'totalarray' => &$totalarray,
1509  );
1510  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1511 
1512  print $hookmanager->resPrint;
1513  if (!empty($arrayfields['p.datec']['checked'])) {
1514  print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1515  }
1516  if (!empty($arrayfields['p.tms']['checked'])) {
1517  print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1518  }
1519  if (!empty($arrayfields['p.date_cloture']['checked'])) {
1520  print_liste_field_titre($arrayfields['p.date_cloture']['label'], $_SERVER["PHP_SELF"], "p.date_cloture", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1521  }
1522  if (!empty($arrayfields['p.note_public']['checked'])) {
1523  print_liste_field_titre($arrayfields['p.note_public']['label'], $_SERVER["PHP_SELF"], "p.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1524  }
1525  if (!empty($arrayfields['p.note_private']['checked'])) {
1526  print_liste_field_titre($arrayfields['p.note_private']['label'], $_SERVER["PHP_SELF"], "p.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1527  }
1528  if (!empty($arrayfields['p.fk_statut']['checked'])) {
1529  print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, 'class="right"', $sortfield, $sortorder);
1530  }
1531  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
1532  print '</tr>'."\n";
1533 
1534  $now = dol_now();
1535  $i = 0;
1536  $typenArray = null;
1537 
1538  $with_margin_info = false;
1539  if (!empty($conf->margin->enabled) && (
1540  !empty($arrayfields['total_pa']['checked'])
1541  || !empty($arrayfields['total_margin']['checked'])
1542  || !empty($arrayfields['total_margin_rate']['checked'])
1543  || !empty($arrayfields['total_mark_rate']['checked'])
1544  )
1545  ) {
1546  $with_margin_info = true;
1547  }
1548  $total_ht = 0;
1549  $total_margin = 0;
1550 
1551  $savnbfield = $totalarray['nbfield'];
1552  $totalarray = array();
1553  $totalarray['nbfield'] = 0;
1554  $last_num = min($num, $limit);
1555  while ($i < $last_num) {
1556  $obj = $db->fetch_object($resql);
1557 
1558  $objectstatic->id = $obj->rowid;
1559  $objectstatic->ref = $obj->ref;
1560  $objectstatic->ref_client = $obj->ref_client;
1561  $objectstatic->note_public = $obj->note_public;
1562  $objectstatic->note_private = $obj->note_private;
1563  $objectstatic->statut = $obj->status;
1564  $objectstatic->status = $obj->status;
1565 
1566  $companystatic->id = $obj->socid;
1567  $companystatic->name = $obj->name;
1568  $companystatic->name_alias = $obj->alias;
1569  $companystatic->client = $obj->client;
1570  $companystatic->code_client = $obj->code_client;
1571  $companystatic->email = $obj->email;
1572  $companystatic->phone = $obj->phone;
1573  $companystatic->address = $obj->address;
1574  $companystatic->zip = $obj->zip;
1575  $companystatic->town = $obj->town;
1576  $companystatic->country_code = $obj->country_code;
1577 
1578  $projectstatic->id = $obj->project_id;
1579  $projectstatic->ref = $obj->project_ref;
1580  $projectstatic->title = $obj->project_label;
1581 
1582  $totalInvoicedHT = 0;
1583  $totalInvoicedTTC = 0;
1584  $multicurrency_totalInvoicedHT = 0;
1585  $multicurrency_totalInvoicedTTC = 0;
1586 
1587  $TInvoiceData = $objectstatic->InvoiceArrayList($obj->rowid);
1588 
1589  if (!empty($TInvoiceData)) {
1590  foreach ($TInvoiceData as $invoiceData) {
1591  $invoice = new Facture($db);
1592  $invoice->fetch($invoiceData->facid);
1593 
1594  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $invoice->type == Facture::TYPE_DEPOSIT) {
1595  continue;
1596  }
1597 
1598  $totalInvoicedHT += $invoice->total_ht;
1599  $totalInvoicedTTC += $invoice->total_ttc;
1600  $multicurrency_totalInvoicedHT += $invoice->multicurrency_total_ht;
1601  $multicurrency_totalInvoicedTTC += $invoice->multicurrency_total_ttc;
1602  }
1603  }
1604 
1605  $marginInfo = array();
1606  if ($with_margin_info === true) {
1607  $objectstatic->fetch_lines();
1608  $marginInfo = $formmargin->getMarginInfosArray($objectstatic);
1609  $total_ht += $obj->total_ht;
1610  $total_margin += $marginInfo['total_margin'];
1611  }
1612 
1613  print '<tr class="oddeven">';
1614 
1615  if (!empty($arrayfields['p.ref']['checked'])) {
1616  print '<td class="nowraponall">';
1617 
1618  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1619  // Picto + Ref
1620  print '<td class="nobordernopadding nowraponall">';
1621  print $objectstatic->getNomUrl(1, '', '', 0, 1, (isset($conf->global->PROPAL_LIST_SHOW_NOTES) ? $conf->global->PROPAL_LIST_SHOW_NOTES : 1));
1622  print '</td>';
1623  // Warning
1624  $warnornote = '';
1625  if ($obj->status == Propal::STATUS_VALIDATED && $db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
1626  $warnornote .= img_warning($langs->trans("Late"));
1627  }
1628  if ($warnornote) {
1629  print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
1630  print $warnornote;
1631  print '</td>';
1632  }
1633  // Other picto tool
1634  print '<td width="16" class="nobordernopadding right">';
1635  $filename = dol_sanitizeFileName($obj->ref);
1636  $filedir = $conf->propal->multidir_output[$obj->propal_entity].'/'.dol_sanitizeFileName($obj->ref);
1637  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1638  print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1639  print '</td></tr></table>';
1640 
1641  print "</td>\n";
1642  if (!$i) {
1643  $totalarray['nbfield']++;
1644  }
1645  }
1646 
1647  if (!empty($arrayfields['p.ref_client']['checked'])) {
1648  // Customer ref
1649  print '<td class="nowrap tdoverflowmax200">';
1650  print $obj->ref_client;
1651  print '</td>';
1652  if (!$i) {
1653  $totalarray['nbfield']++;
1654  }
1655  }
1656 
1657  if (!empty($arrayfields['pr.ref']['checked'])) {
1658  // Project ref
1659  print '<td class="nowraponall">';
1660  if ($obj->project_id > 0) {
1661  print $projectstatic->getNomUrl(1);
1662  }
1663  print '</td>';
1664  if (!$i) {
1665  $totalarray['nbfield']++;
1666  }
1667  }
1668 
1669  if (!empty($arrayfields['pr.title']['checked'])) {
1670  // Project label
1671  print '<td class="nowrap">';
1672  if ($obj->project_id > 0) {
1673  print $projectstatic->title;
1674  }
1675  print '</td>';
1676  if (!$i) {
1677  $totalarray['nbfield']++;
1678  }
1679  }
1680 
1681  // Thirdparty
1682  if (!empty($arrayfields['s.nom']['checked'])) {
1683  print '<td class="tdoverflowmax150">';
1684  print $companystatic->getNomUrl(1, 'customer');
1685  print '</td>';
1686  if (!$i) {
1687  $totalarray['nbfield']++;
1688  }
1689  }
1690 
1691  // Alias
1692  if (!empty($arrayfields['s.name_alias']['checked'])) {
1693  print '<td class="tdoverflowmax200">';
1694  print $obj->alias;
1695  print '</td>';
1696  if (!$i) {
1697  $totalarray['nbfield']++;
1698  }
1699  }
1700 
1701  // Town
1702  if (!empty($arrayfields['s.town']['checked'])) {
1703  print '<td class="nocellnopadd">';
1704  print $obj->town;
1705  print '</td>';
1706  if (!$i) {
1707  $totalarray['nbfield']++;
1708  }
1709  }
1710  // Zip
1711  if (!empty($arrayfields['s.zip']['checked'])) {
1712  print '<td class="nocellnopadd">';
1713  print $obj->zip;
1714  print '</td>';
1715  if (!$i) {
1716  $totalarray['nbfield']++;
1717  }
1718  }
1719  // State
1720  if (!empty($arrayfields['state.nom']['checked'])) {
1721  print "<td>".$obj->state_name."</td>\n";
1722  if (!$i) {
1723  $totalarray['nbfield']++;
1724  }
1725  }
1726  // Country
1727  if (!empty($arrayfields['country.code_iso']['checked'])) {
1728  print '<td class="center">';
1729  $tmparray = getCountry($obj->fk_pays, 'all');
1730  print $tmparray['label'];
1731  print '</td>';
1732  if (!$i) {
1733  $totalarray['nbfield']++;
1734  }
1735  }
1736  // Type ent
1737  if (!empty($arrayfields['typent.code']['checked'])) {
1738  if (!is_array($typenArray) || empty($typenArray)) {
1739  $typenArray = $formcompany->typent_array(1);
1740  }
1741 
1742  print '<td class="center">';
1743  print $typenArray[$obj->typent_code];
1744  print '</td>';
1745  if (!$i) {
1746  $totalarray['nbfield']++;
1747  }
1748  }
1749 
1750  // Date proposal
1751  if (!empty($arrayfields['p.date']['checked'])) {
1752  print '<td class="center">';
1753  print dol_print_date($db->jdate($obj->dp), 'day');
1754  print "</td>\n";
1755  if (!$i) {
1756  $totalarray['nbfield']++;
1757  }
1758  }
1759 
1760  // Date end validity
1761  if (!empty($arrayfields['p.fin_validite']['checked'])) {
1762  if ($obj->dfv) {
1763  print '<td class="center">'.dol_print_date($db->jdate($obj->dfv), 'day');
1764  print '</td>';
1765  } else {
1766  print '<td>&nbsp;</td>';
1767  }
1768  if (!$i) {
1769  $totalarray['nbfield']++;
1770  }
1771  }
1772  // Date delivery
1773  if (!empty($arrayfields['p.date_livraison']['checked'])) {
1774  if ($obj->ddelivery) {
1775  print '<td class="center">'.dol_print_date($db->jdate($obj->ddelivery), 'day');
1776  print '</td>';
1777  } else {
1778  print '<td>&nbsp;</td>';
1779  }
1780  if (!$i) {
1781  $totalarray['nbfield']++;
1782  }
1783  }
1784  // Date Signature
1785  if (!empty($arrayfields['p.date_signature']['checked'])) {
1786  if ($obj->dsignature) {
1787  print '<td class="center">'.dol_print_date($db->jdate($obj->dsignature), 'day');
1788  print '</td>';
1789  } else {
1790  print '<td>&nbsp;</td>';
1791  }
1792  if (!$i) {
1793  $totalarray['nbfield']++;
1794  }
1795  }
1796  // Availability
1797  if (!empty($arrayfields['ava.rowid']['checked'])) {
1798  print '<td class="center">';
1799  $form->form_availability('', $obj->availability, 'none', 1);
1800  print '</td>';
1801  if (!$i) {
1802  $totalarray['nbfield']++;
1803  }
1804  }
1805  // Shipping Method
1806  if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1807  print '<td>';
1808  $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
1809  print '</td>';
1810  if (!$i) {
1811  $totalarray['nbfield']++;
1812  }
1813  }
1814  // Source - input reason
1815  if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1816  print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($form->cache_demand_reason[$obj->fk_input_reason]['label']).'">';
1817  if ($obj->fk_input_reason > 0) {
1818  print $form->cache_demand_reason[$obj->fk_input_reason]['label'];
1819  }
1820  print '</td>';
1821  if (!$i) {
1822  $totalarray['nbfield']++;
1823  }
1824  }
1825  // Payment terms
1826  if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1827  print '<td>';
1828  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
1829  print '</td>';
1830  if (!$i) {
1831  $totalarray['nbfield']++;
1832  }
1833  }
1834  // Payment mode
1835  if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1836  print '<td>';
1837  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1838  print '</td>';
1839  if (!$i) {
1840  $totalarray['nbfield']++;
1841  }
1842  }
1843  // Amount HT
1844  if (!empty($arrayfields['p.total_ht']['checked'])) {
1845  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1846  if (!$i) {
1847  $totalarray['nbfield']++;
1848  }
1849  if (!$i) {
1850  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht';
1851  }
1852  $totalarray['val']['p.total_ht'] += $obj->total_ht;
1853  }
1854  // Amount VAT
1855  if (!empty($arrayfields['p.total_tva']['checked'])) {
1856  print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1857  if (!$i) {
1858  $totalarray['nbfield']++;
1859  }
1860  if (!$i) {
1861  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_tva';
1862  }
1863  $totalarray['val']['p.total_tva'] += $obj->total_tva;
1864  }
1865  // Amount TTC
1866  if (!empty($arrayfields['p.total_ttc']['checked'])) {
1867  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1868  if (!$i) {
1869  $totalarray['nbfield']++;
1870  }
1871  if (!$i) {
1872  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ttc';
1873  }
1874  $totalarray['val']['p.total_ttc'] += $obj->total_ttc;
1875  }
1876  // Amount invoiced HT
1877  if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1878  print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedHT)."</span></td>\n";
1879  if (!$i) {
1880  $totalarray['nbfield']++;
1881  }
1882  if (!$i) {
1883  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht_invoiced';
1884  }
1885  $totalarray['val']['p.total_ht_invoiced'] += $totalInvoicedHT;
1886  }
1887  // Amount invoiced TTC
1888  if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1889  print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedTTC)."</span></td>\n";
1890  if (!$i) {
1891  $totalarray['nbfield']++;
1892  }
1893  if (!$i) {
1894  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_invoiced';
1895  }
1896  $totalarray['val']['p.total_invoiced'] += $totalInvoicedTTC;
1897  }
1898  // Currency
1899  if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1900  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1901  if (!$i) {
1902  $totalarray['nbfield']++;
1903  }
1904  }
1905 
1906  // Currency rate
1907  if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1908  print '<td class="nowrap">';
1909  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1910  print "</td>\n";
1911  if (!$i) {
1912  $totalarray['nbfield']++;
1913  }
1914  }
1915  // Amount HT
1916  if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1917  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1918  if (!$i) {
1919  $totalarray['nbfield']++;
1920  }
1921  }
1922  // Amount VAT
1923  if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1924  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1925  if (!$i) {
1926  $totalarray['nbfield']++;
1927  }
1928  }
1929  // Amount TTC
1930  if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1931  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1932  if (!$i) {
1933  $totalarray['nbfield']++;
1934  }
1935  }
1936  // Amount invoiced
1937  if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1938  print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedHT)."</span></td>\n";
1939  if (!$i) {
1940  $totalarray['nbfield']++;
1941  }
1942  }
1943  // Amount invoiced
1944  if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1945  print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedTTC)."</span></td>\n";
1946  if (!$i) {
1947  $totalarray['nbfield']++;
1948  }
1949  }
1950 
1951  $userstatic->id = $obj->fk_user_author;
1952  $userstatic->login = $obj->login;
1953  $userstatic->lastname = $obj->lastname;
1954  $userstatic->firstname = $obj->firstname;
1955  $userstatic->email = $obj->user_email;
1956  $userstatic->statut = $obj->user_statut;
1957  $userstatic->entity = $obj->user_entity;
1958  $userstatic->photo = $obj->photo;
1959  $userstatic->office_phone = $obj->office_phone;
1960  $userstatic->office_fax = $obj->office_fax;
1961  $userstatic->user_mobile = $obj->user_mobile;
1962  $userstatic->job = $obj->job;
1963  $userstatic->gender = $obj->gender;
1964 
1965  // Author
1966  if (!empty($arrayfields['u.login']['checked'])) {
1967  print '<td class="tdoverflowmax150">';
1968  if ($userstatic->id) {
1969  print $userstatic->getNomUrl(-1);
1970  }
1971  print "</td>\n";
1972  if (!$i) {
1973  $totalarray['nbfield']++;
1974  }
1975  }
1976 
1977  if (!empty($arrayfields['sale_representative']['checked'])) {
1978  // Sales representatives
1979  print '<td class="tdoverflowmax150">';
1980  if ($obj->socid > 0) {
1981  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
1982  if ($listsalesrepresentatives < 0) {
1983  dol_print_error($db);
1984  }
1985  $nbofsalesrepresentative = count($listsalesrepresentatives);
1986  if ($nbofsalesrepresentative > 6) {
1987  // We print only number
1988  print $nbofsalesrepresentative;
1989  } elseif ($nbofsalesrepresentative > 0) {
1990  $userstatic = new User($db);
1991  $j = 0;
1992  foreach ($listsalesrepresentatives as $val) {
1993  $userstatic->id = $val['id'];
1994  $userstatic->lastname = $val['lastname'];
1995  $userstatic->firstname = $val['firstname'];
1996  $userstatic->email = $val['email'];
1997  $userstatic->statut = $val['statut'];
1998  $userstatic->entity = $val['entity'];
1999  $userstatic->photo = $val['photo'];
2000  $userstatic->login = $val['login'];
2001  $userstatic->office_phone = $val['office_phone'];
2002  $userstatic->office_fax = $val['office_fax'];
2003  $userstatic->user_mobile = $val['user_mobile'];
2004  $userstatic->job = $val['job'];
2005  $userstatic->gender = $val['gender'];
2006  //print '<div class="float">':
2007  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2008  $j++;
2009  if ($j < $nbofsalesrepresentative) {
2010  print ' ';
2011  }
2012  //print '</div>';
2013  }
2014  }
2015  //else print $langs->trans("NoSalesRepresentativeAffected");
2016  } else {
2017  print '&nbsp;';
2018  }
2019  print '</td>';
2020  if (!$i) {
2021  $totalarray['nbfield']++;
2022  }
2023  }
2024 
2025  // Total buying or cost price
2026  if (!empty($arrayfields['total_pa']['checked'])) {
2027  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2028  if (!$i) {
2029  $totalarray['nbfield']++;
2030  }
2031  }
2032  // Total margin
2033  if (!empty($arrayfields['total_margin']['checked'])) {
2034  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2035  if (!$i) {
2036  $totalarray['nbfield']++;
2037  }
2038  if (!$i) {
2039  $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2040  }
2041  $totalarray['val']['total_margin'] = $total_margin;
2042  }
2043  // Total margin rate
2044  if (!empty($arrayfields['total_margin_rate']['checked'])) {
2045  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
2046  if (!$i) {
2047  $totalarray['nbfield']++;
2048  }
2049  }
2050  // Total mark rate
2051  if (!empty($arrayfields['total_mark_rate']['checked'])) {
2052  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
2053  if (!$i) {
2054  $totalarray['nbfield']++;
2055  }
2056  if (!$i) {
2057  $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2058  }
2059  if ($i >= $last_num - 1) {
2060  if (!empty($total_ht)) {
2061  $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2062  } else {
2063  $totalarray['val']['total_mark_rate'] = '';
2064  }
2065  }
2066  }
2067 
2068  // Extra fields
2069  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2070  // Fields from hook
2071  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
2072  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
2073  print $hookmanager->resPrint;
2074  // Date creation
2075  if (!empty($arrayfields['p.datec']['checked'])) {
2076  print '<td align="center" class="nowrap">';
2077  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2078  print '</td>';
2079  if (!$i) {
2080  $totalarray['nbfield']++;
2081  }
2082  }
2083  // Date modification
2084  if (!empty($arrayfields['p.tms']['checked'])) {
2085  print '<td align="center" class="nowrap">';
2086  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
2087  print '</td>';
2088  if (!$i) {
2089  $totalarray['nbfield']++;
2090  }
2091  }
2092  // Date cloture
2093  if (!empty($arrayfields['p.date_cloture']['checked'])) {
2094  print '<td align="center" class="nowrap">';
2095  print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
2096  print '</td>';
2097  if (!$i) {
2098  $totalarray['nbfield']++;
2099  }
2100  }
2101  // Note public
2102  if (!empty($arrayfields['p.note_public']['checked'])) {
2103  print '<td class="center">';
2104  print dol_string_nohtmltag($obj->note_public);
2105  print '</td>';
2106  if (!$i) {
2107  $totalarray['nbfield']++;
2108  }
2109  }
2110  // Note private
2111  if (!empty($arrayfields['p.note_private']['checked'])) {
2112  print '<td class="center">';
2113  print dol_string_nohtmltag($obj->note_private);
2114  print '</td>';
2115  if (!$i) {
2116  $totalarray['nbfield']++;
2117  }
2118  }
2119  // Status
2120  if (!empty($arrayfields['p.fk_statut']['checked'])) {
2121  print '<td class="nowrap right">'.$objectstatic->getLibStatut(5).'</td>';
2122  if (!$i) {
2123  $totalarray['nbfield']++;
2124  }
2125  }
2126  // Action column
2127  print '<td class="nowrap" align="center">';
2128  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2129  $selected = 0;
2130  if (in_array($obj->rowid, $arrayofselected)) {
2131  $selected = 1;
2132  }
2133  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2134  }
2135  print '</td>';
2136  if (!$i) {
2137  $totalarray['nbfield']++;
2138  }
2139 
2140  print '</tr>'."\n";
2141 
2142  $i++;
2143  }
2144 
2145  // Show total line
2146  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2147 
2148  // If no record found
2149  if ($num == 0) {
2150  $colspan = 1;
2151  foreach ($arrayfields as $key => $val) {
2152  if (!empty($val['checked'])) {
2153  $colspan++;
2154  }
2155  }
2156  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2157  }
2158 
2159  $db->free($resql);
2160 
2161  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2162  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2163  print $hookmanager->resPrint;
2164 
2165  print '</table>'."\n";
2166  print '</div>'."\n";
2167 
2168  print '</form>'."\n";
2169 
2170  $hidegeneratedfilelistifempty = 1;
2171  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2172  $hidegeneratedfilelistifempty = 0;
2173  }
2174 
2175  // Show list of available documents
2176  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2177  $urlsource .= str_replace('&amp;', '&', $param);
2178 
2179  $filedir = $diroutputmassaction;
2180  $genallowed = $user->rights->propal->lire;
2181  $delallowed = $user->rights->propal->creer;
2182 
2183  print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2184 } else {
2185  dol_print_error($db);
2186 }
2187 
2188 // End of page
2189 llxFooter();
2190 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormMargin
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formmargin.class.php:29
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
FormPropal
Class to manage generation of HTML components for proposal management.
Definition: html.formpropal.class.php:28
Facture
Class to manage invoices.
Definition: facture.class.php:60
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
Facture\TYPE_DEPOSIT
const TYPE_DEPOSIT
Deposit invoice.
Definition: facture.class.php:397
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
Propal\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: propal.class.php:356
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8108
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Definition: functions.lib.php:9420
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:489
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
Propal
Class to manage proposals.
Definition: propal.class.php:52
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59