dolibarr  16.0.1
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'=>'CustomerRef',
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);
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 
1376  // Fields title
1377  print '<tr class="liste_titre">';
1378  if (!empty($arrayfields['p.ref']['checked'])) {
1379  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
1380  }
1381  if (!empty($arrayfields['p.ref_client']['checked'])) {
1382  print_liste_field_titre($arrayfields['p.ref_client']['label'], $_SERVER["PHP_SELF"], 'p.ref_client', '', $param, '', $sortfield, $sortorder);
1383  }
1384  if (!empty($arrayfields['pr.ref']['checked'])) {
1385  print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
1386  }
1387  if (!empty($arrayfields['pr.title']['checked'])) {
1388  print_liste_field_titre($arrayfields['pr.title']['label'], $_SERVER["PHP_SELF"], 'pr.title', '', $param, '', $sortfield, $sortorder);
1389  }
1390  if (!empty($arrayfields['s.nom']['checked'])) {
1391  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1392  }
1393  if (!empty($arrayfields['s.name_alias']['checked'])) {
1394  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1395  }
1396  if (!empty($arrayfields['s.town']['checked'])) {
1397  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1398  }
1399  if (!empty($arrayfields['s.zip']['checked'])) {
1400  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1401  }
1402  if (!empty($arrayfields['state.nom']['checked'])) {
1403  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1404  }
1405  if (!empty($arrayfields['country.code_iso']['checked'])) {
1406  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
1407  }
1408  if (!empty($arrayfields['typent.code']['checked'])) {
1409  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
1410  }
1411  if (!empty($arrayfields['p.date']['checked'])) {
1412  print_liste_field_titre($arrayfields['p.date']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, 'align="center"', $sortfield, $sortorder);
1413  }
1414  if (!empty($arrayfields['p.fin_validite']['checked'])) {
1415  print_liste_field_titre($arrayfields['p.fin_validite']['label'], $_SERVER["PHP_SELF"], 'dfv', '', $param, 'align="center"', $sortfield, $sortorder);
1416  }
1417  if (!empty($arrayfields['p.date_livraison']['checked'])) {
1418  print_liste_field_titre($arrayfields['p.date_livraison']['label'], $_SERVER["PHP_SELF"], 'p.date_livraison', '', $param, 'align="center"', $sortfield, $sortorder);
1419  }
1420  if (!empty($arrayfields['p.date_signature']['checked'])) {
1421  print_liste_field_titre($arrayfields['p.date_signature']['label'], $_SERVER["PHP_SELF"], 'p.date_signature', '', $param, 'align="center"', $sortfield, $sortorder);
1422  }
1423  if (!empty($arrayfields['ava.rowid']['checked'])) {
1424  print_liste_field_titre($arrayfields['ava.rowid']['label'], $_SERVER["PHP_SELF"], 'availability', '', $param, '', $sortfield, $sortorder);
1425  }
1426  if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1427  print_liste_field_titre($arrayfields['p.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "p.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1428  }
1429  if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1430  print_liste_field_titre($arrayfields['p.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "p.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1431  }
1432  if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1433  print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1434  }
1435  if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1436  print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1437  }
1438  if (!empty($arrayfields['p.total_ht']['checked'])) {
1439  print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1440  }
1441  if (!empty($arrayfields['p.total_tva']['checked'])) {
1442  print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1443  }
1444  if (!empty($arrayfields['p.total_ttc']['checked'])) {
1445  print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1446  }
1447  if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1448  print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1449  }
1450  if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1451  print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1452  }
1453  if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1454  print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1455  }
1456  if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1457  print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1458  }
1459  if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1460  print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1461  }
1462  if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1463  print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1464  }
1465  if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1466  print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1467  }
1468  if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1469  print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1470  }
1471  if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1472  print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1473  }
1474  if (!empty($arrayfields['u.login']['checked'])) {
1475  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1476  }
1477  if (!empty($arrayfields['sale_representative']['checked'])) {
1478  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1479  }
1480  if (!empty($arrayfields['total_pa']['checked'])) {
1481  print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1482  }
1483  if (!empty($arrayfields['total_margin']['checked'])) {
1484  print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1485  }
1486  if (!empty($arrayfields['total_margin_rate']['checked'])) {
1487  print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1488  }
1489  if (!empty($arrayfields['total_mark_rate']['checked'])) {
1490  print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1491  }
1492  $totalarray = array(
1493  'nbfield' => 0,
1494  'val' => array(
1495  'p.total_ht' => 0,
1496  'p.total_tva' => 0,
1497  'p.total_ttc' => 0,
1498  ),
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  print $hookmanager->resPrint;
1512  if (!empty($arrayfields['p.datec']['checked'])) {
1513  print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1514  }
1515  if (!empty($arrayfields['p.tms']['checked'])) {
1516  print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1517  }
1518  if (!empty($arrayfields['p.date_cloture']['checked'])) {
1519  print_liste_field_titre($arrayfields['p.date_cloture']['label'], $_SERVER["PHP_SELF"], "p.date_cloture", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1520  }
1521  if (!empty($arrayfields['p.note_public']['checked'])) {
1522  print_liste_field_titre($arrayfields['p.note_public']['label'], $_SERVER["PHP_SELF"], "p.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1523  }
1524  if (!empty($arrayfields['p.note_private']['checked'])) {
1525  print_liste_field_titre($arrayfields['p.note_private']['label'], $_SERVER["PHP_SELF"], "p.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1526  }
1527  if (!empty($arrayfields['p.fk_statut']['checked'])) {
1528  print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, 'class="right"', $sortfield, $sortorder);
1529  }
1530  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
1531  print '</tr>'."\n";
1532 
1533  $now = dol_now();
1534  $i = 0;
1535  $typenArray = null;
1536 
1537  $with_margin_info = false;
1538  if (!empty($conf->margin->enabled) && (
1539  !empty($arrayfields['total_pa']['checked'])
1540  || !empty($arrayfields['total_margin']['checked'])
1541  || !empty($arrayfields['total_margin_rate']['checked'])
1542  || !empty($arrayfields['total_mark_rate']['checked'])
1543  )
1544  ) {
1545  $with_margin_info = true;
1546  }
1547  $total_ht = 0;
1548  $total_margin = 0;
1549 
1550  $last_num = min($num, $limit);
1551  while ($i < $last_num) {
1552  $obj = $db->fetch_object($resql);
1553 
1554  $objectstatic->id = $obj->rowid;
1555  $objectstatic->ref = $obj->ref;
1556  $objectstatic->ref_client = $obj->ref_client;
1557  $objectstatic->note_public = $obj->note_public;
1558  $objectstatic->note_private = $obj->note_private;
1559  $objectstatic->statut = $obj->status;
1560  $objectstatic->status = $obj->status;
1561 
1562  $companystatic->id = $obj->socid;
1563  $companystatic->name = $obj->name;
1564  $companystatic->name_alias = $obj->alias;
1565  $companystatic->client = $obj->client;
1566  $companystatic->code_client = $obj->code_client;
1567  $companystatic->email = $obj->email;
1568  $companystatic->phone = $obj->phone;
1569  $companystatic->address = $obj->address;
1570  $companystatic->zip = $obj->zip;
1571  $companystatic->town = $obj->town;
1572  $companystatic->country_code = $obj->country_code;
1573 
1574  $projectstatic->id = $obj->project_id;
1575  $projectstatic->ref = $obj->project_ref;
1576  $projectstatic->title = $obj->project_label;
1577 
1578  $totalInvoicedHT = 0;
1579  $totalInvoicedTTC = 0;
1580  $multicurrency_totalInvoicedHT = 0;
1581  $multicurrency_totalInvoicedTTC = 0;
1582 
1583  $TInvoiceData = $objectstatic->InvoiceArrayList($obj->rowid);
1584 
1585  if (!empty($TInvoiceData)) {
1586  foreach ($TInvoiceData as $invoiceData) {
1587  $invoice = new Facture($db);
1588  $invoice->fetch($invoiceData->facid);
1589 
1590  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $invoice->type == Facture::TYPE_DEPOSIT) {
1591  continue;
1592  }
1593 
1594  $totalInvoicedHT += $invoice->total_ht;
1595  $totalInvoicedTTC += $invoice->total_ttc;
1596  $multicurrency_totalInvoicedHT += $invoice->multicurrency_total_ht;
1597  $multicurrency_totalInvoicedTTC += $invoice->multicurrency_total_ttc;
1598  }
1599  }
1600 
1601  $marginInfo = array();
1602  if ($with_margin_info === true) {
1603  $objectstatic->fetch_lines();
1604  $marginInfo = $formmargin->getMarginInfosArray($objectstatic);
1605  $total_ht += $obj->total_ht;
1606  $total_margin += $marginInfo['total_margin'];
1607  }
1608 
1609  print '<tr class="oddeven">';
1610 
1611  if (!empty($arrayfields['p.ref']['checked'])) {
1612  print '<td class="nowraponall">';
1613 
1614  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1615  // Picto + Ref
1616  print '<td class="nobordernopadding nowraponall">';
1617  print $objectstatic->getNomUrl(1, '', '', 0, 1, (isset($conf->global->PROPAL_LIST_SHOW_NOTES) ? $conf->global->PROPAL_LIST_SHOW_NOTES : 1));
1618  print '</td>';
1619  // Warning
1620  $warnornote = '';
1621  if ($obj->status == Propal::STATUS_VALIDATED && $db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
1622  $warnornote .= img_warning($langs->trans("Late"));
1623  }
1624  if ($warnornote) {
1625  print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
1626  print $warnornote;
1627  print '</td>';
1628  }
1629  // Other picto tool
1630  print '<td width="16" class="nobordernopadding right">';
1631  $filename = dol_sanitizeFileName($obj->ref);
1632  $filedir = $conf->propal->multidir_output[$obj->propal_entity].'/'.dol_sanitizeFileName($obj->ref);
1633  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1634  print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1635  print '</td></tr></table>';
1636 
1637  print "</td>\n";
1638  if (!$i) {
1639  $totalarray['nbfield']++;
1640  }
1641  }
1642 
1643  if (!empty($arrayfields['p.ref_client']['checked'])) {
1644  // Customer ref
1645  print '<td class="nowrap tdoverflowmax200">';
1646  print $obj->ref_client;
1647  print '</td>';
1648  if (!$i) {
1649  $totalarray['nbfield']++;
1650  }
1651  }
1652 
1653  if (!empty($arrayfields['pr.ref']['checked'])) {
1654  // Project ref
1655  print '<td class="nowraponall">';
1656  if ($obj->project_id > 0) {
1657  print $projectstatic->getNomUrl(1);
1658  }
1659  print '</td>';
1660  if (!$i) {
1661  $totalarray['nbfield']++;
1662  }
1663  }
1664 
1665  if (!empty($arrayfields['pr.title']['checked'])) {
1666  // Project label
1667  print '<td class="nowrap">';
1668  if ($obj->project_id > 0) {
1669  print $projectstatic->title;
1670  }
1671  print '</td>';
1672  if (!$i) {
1673  $totalarray['nbfield']++;
1674  }
1675  }
1676 
1677  // Thirdparty
1678  if (!empty($arrayfields['s.nom']['checked'])) {
1679  print '<td class="tdoverflowmax200">';
1680  print $companystatic->getNomUrl(1, 'customer');
1681  print '</td>';
1682  if (!$i) {
1683  $totalarray['nbfield']++;
1684  }
1685  }
1686 
1687  // Alias
1688  if (!empty($arrayfields['s.name_alias']['checked'])) {
1689  print '<td class="tdoverflowmax200">';
1690  print $obj->alias;
1691  print '</td>';
1692  if (!$i) {
1693  $totalarray['nbfield']++;
1694  }
1695  }
1696 
1697  // Town
1698  if (!empty($arrayfields['s.town']['checked'])) {
1699  print '<td class="nocellnopadd">';
1700  print $obj->town;
1701  print '</td>';
1702  if (!$i) {
1703  $totalarray['nbfield']++;
1704  }
1705  }
1706  // Zip
1707  if (!empty($arrayfields['s.zip']['checked'])) {
1708  print '<td class="nocellnopadd">';
1709  print $obj->zip;
1710  print '</td>';
1711  if (!$i) {
1712  $totalarray['nbfield']++;
1713  }
1714  }
1715  // State
1716  if (!empty($arrayfields['state.nom']['checked'])) {
1717  print "<td>".$obj->state_name."</td>\n";
1718  if (!$i) {
1719  $totalarray['nbfield']++;
1720  }
1721  }
1722  // Country
1723  if (!empty($arrayfields['country.code_iso']['checked'])) {
1724  print '<td class="center">';
1725  $tmparray = getCountry($obj->fk_pays, 'all');
1726  print $tmparray['label'];
1727  print '</td>';
1728  if (!$i) {
1729  $totalarray['nbfield']++;
1730  }
1731  }
1732  // Type ent
1733  if (!empty($arrayfields['typent.code']['checked'])) {
1734  if (!is_array($typenArray) || empty($typenArray)) {
1735  $typenArray = $formcompany->typent_array(1);
1736  }
1737 
1738  print '<td class="center">';
1739  print $typenArray[$obj->typent_code];
1740  print '</td>';
1741  if (!$i) {
1742  $totalarray['nbfield']++;
1743  }
1744  }
1745 
1746  // Date proposal
1747  if (!empty($arrayfields['p.date']['checked'])) {
1748  print '<td class="center">';
1749  print dol_print_date($db->jdate($obj->dp), 'day');
1750  print "</td>\n";
1751  if (!$i) {
1752  $totalarray['nbfield']++;
1753  }
1754  }
1755 
1756  // Date end validity
1757  if (!empty($arrayfields['p.fin_validite']['checked'])) {
1758  if ($obj->dfv) {
1759  print '<td class="center">'.dol_print_date($db->jdate($obj->dfv), 'day');
1760  print '</td>';
1761  } else {
1762  print '<td>&nbsp;</td>';
1763  }
1764  if (!$i) {
1765  $totalarray['nbfield']++;
1766  }
1767  }
1768  // Date delivery
1769  if (!empty($arrayfields['p.date_livraison']['checked'])) {
1770  if ($obj->ddelivery) {
1771  print '<td class="center">'.dol_print_date($db->jdate($obj->ddelivery), 'day');
1772  print '</td>';
1773  } else {
1774  print '<td>&nbsp;</td>';
1775  }
1776  if (!$i) {
1777  $totalarray['nbfield']++;
1778  }
1779  }
1780  // Date Signature
1781  if (!empty($arrayfields['p.date_signature']['checked'])) {
1782  if ($obj->dsignature) {
1783  print '<td class="center">'.dol_print_date($db->jdate($obj->dsignature), 'day');
1784  print '</td>';
1785  } else {
1786  print '<td>&nbsp;</td>';
1787  }
1788  if (!$i) {
1789  $totalarray['nbfield']++;
1790  }
1791  }
1792  // Availability
1793  if (!empty($arrayfields['ava.rowid']['checked'])) {
1794  print '<td class="center">';
1795  $form->form_availability('', $obj->availability, 'none', 1);
1796  print '</td>';
1797  if (!$i) {
1798  $totalarray['nbfield']++;
1799  }
1800  }
1801  // Shipping Method
1802  if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1803  print '<td>';
1804  $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
1805  print '</td>';
1806  if (!$i) {
1807  $totalarray['nbfield']++;
1808  }
1809  }
1810  // Source - input reason
1811  if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1812  print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($form->cache_demand_reason[$obj->fk_input_reason]['label']).'">';
1813  if ($obj->fk_input_reason > 0) {
1814  print $form->cache_demand_reason[$obj->fk_input_reason]['label'];
1815  }
1816  print '</td>';
1817  if (!$i) {
1818  $totalarray['nbfield']++;
1819  }
1820  }
1821  // Payment terms
1822  if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1823  print '<td>';
1824  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
1825  print '</td>';
1826  if (!$i) {
1827  $totalarray['nbfield']++;
1828  }
1829  }
1830  // Payment mode
1831  if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1832  print '<td>';
1833  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1834  print '</td>';
1835  if (!$i) {
1836  $totalarray['nbfield']++;
1837  }
1838  }
1839  // Amount HT
1840  if (!empty($arrayfields['p.total_ht']['checked'])) {
1841  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1842  if (!$i) {
1843  $totalarray['nbfield']++;
1844  }
1845  if (!$i) {
1846  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht';
1847  }
1848  $totalarray['val']['p.total_ht'] += $obj->total_ht;
1849  }
1850  // Amount VAT
1851  if (!empty($arrayfields['p.total_tva']['checked'])) {
1852  print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1853  if (!$i) {
1854  $totalarray['nbfield']++;
1855  }
1856  if (!$i) {
1857  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_tva';
1858  }
1859  $totalarray['val']['p.total_tva'] += $obj->total_tva;
1860  }
1861  // Amount TTC
1862  if (!empty($arrayfields['p.total_ttc']['checked'])) {
1863  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1864  if (!$i) {
1865  $totalarray['nbfield']++;
1866  }
1867  if (!$i) {
1868  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ttc';
1869  }
1870  $totalarray['val']['p.total_ttc'] += $obj->total_ttc;
1871  }
1872  // Amount invoiced HT
1873  if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1874  print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedHT)."</span></td>\n";
1875  if (!$i) {
1876  $totalarray['nbfield']++;
1877  }
1878  if (!$i) {
1879  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht_invoiced';
1880  }
1881  $totalarray['val']['p.total_ht_invoiced'] += $totalInvoicedHT;
1882  }
1883  // Amount invoiced TTC
1884  if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1885  print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedTTC)."</span></td>\n";
1886  if (!$i) {
1887  $totalarray['nbfield']++;
1888  }
1889  if (!$i) {
1890  $totalarray['pos'][$totalarray['nbfield']] = 'p.total_invoiced';
1891  }
1892  $totalarray['val']['p.total_invoiced'] += $totalInvoicedTTC;
1893  }
1894  // Currency
1895  if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1896  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1897  if (!$i) {
1898  $totalarray['nbfield']++;
1899  }
1900  }
1901 
1902  // Currency rate
1903  if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1904  print '<td class="nowrap">';
1905  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1906  print "</td>\n";
1907  if (!$i) {
1908  $totalarray['nbfield']++;
1909  }
1910  }
1911  // Amount HT
1912  if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1913  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1914  if (!$i) {
1915  $totalarray['nbfield']++;
1916  }
1917  }
1918  // Amount VAT
1919  if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1920  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1921  if (!$i) {
1922  $totalarray['nbfield']++;
1923  }
1924  }
1925  // Amount TTC
1926  if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1927  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1928  if (!$i) {
1929  $totalarray['nbfield']++;
1930  }
1931  }
1932  // Amount invoiced
1933  if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1934  print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedHT)."</span></td>\n";
1935  if (!$i) {
1936  $totalarray['nbfield']++;
1937  }
1938  }
1939  // Amount invoiced
1940  if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1941  print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedTTC)."</span></td>\n";
1942  if (!$i) {
1943  $totalarray['nbfield']++;
1944  }
1945  }
1946 
1947  $userstatic->id = $obj->fk_user_author;
1948  $userstatic->login = $obj->login;
1949  $userstatic->lastname = $obj->lastname;
1950  $userstatic->firstname = $obj->firstname;
1951  $userstatic->email = $obj->user_email;
1952  $userstatic->statut = $obj->user_statut;
1953  $userstatic->entity = $obj->user_entity;
1954  $userstatic->photo = $obj->photo;
1955  $userstatic->office_phone = $obj->office_phone;
1956  $userstatic->office_fax = $obj->office_fax;
1957  $userstatic->user_mobile = $obj->user_mobile;
1958  $userstatic->job = $obj->job;
1959  $userstatic->gender = $obj->gender;
1960 
1961  // Author
1962  if (!empty($arrayfields['u.login']['checked'])) {
1963  print '<td class="tdoverflowmax200">';
1964  if ($userstatic->id) {
1965  print $userstatic->getNomUrl(-1);
1966  }
1967  print "</td>\n";
1968  if (!$i) {
1969  $totalarray['nbfield']++;
1970  }
1971  }
1972 
1973  if (!empty($arrayfields['sale_representative']['checked'])) {
1974  // Sales representatives
1975  print '<td class="tdoverflowmax200">';
1976  if ($obj->socid > 0) {
1977  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
1978  if ($listsalesrepresentatives < 0) {
1979  dol_print_error($db);
1980  }
1981  $nbofsalesrepresentative = count($listsalesrepresentatives);
1982  if ($nbofsalesrepresentative > 6) {
1983  // We print only number
1984  print $nbofsalesrepresentative;
1985  } elseif ($nbofsalesrepresentative > 0) {
1986  $userstatic = new User($db);
1987  $j = 0;
1988  foreach ($listsalesrepresentatives as $val) {
1989  $userstatic->id = $val['id'];
1990  $userstatic->lastname = $val['lastname'];
1991  $userstatic->firstname = $val['firstname'];
1992  $userstatic->email = $val['email'];
1993  $userstatic->statut = $val['statut'];
1994  $userstatic->entity = $val['entity'];
1995  $userstatic->photo = $val['photo'];
1996  $userstatic->login = $val['login'];
1997  $userstatic->office_phone = $val['office_phone'];
1998  $userstatic->office_fax = $val['office_fax'];
1999  $userstatic->user_mobile = $val['user_mobile'];
2000  $userstatic->job = $val['job'];
2001  $userstatic->gender = $val['gender'];
2002  //print '<div class="float">':
2003  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2004  $j++;
2005  if ($j < $nbofsalesrepresentative) {
2006  print ' ';
2007  }
2008  //print '</div>';
2009  }
2010  }
2011  //else print $langs->trans("NoSalesRepresentativeAffected");
2012  } else {
2013  print '&nbsp;';
2014  }
2015  print '</td>';
2016  if (!$i) {
2017  $totalarray['nbfield']++;
2018  }
2019  }
2020 
2021  // Total buying or cost price
2022  if (!empty($arrayfields['total_pa']['checked'])) {
2023  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2024  if (!$i) {
2025  $totalarray['nbfield']++;
2026  }
2027  }
2028  // Total margin
2029  if (!empty($arrayfields['total_margin']['checked'])) {
2030  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2031  if (!$i) {
2032  $totalarray['nbfield']++;
2033  }
2034  if (!$i) {
2035  $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2036  }
2037  $totalarray['val']['total_margin'] = $total_margin;
2038  }
2039  // Total margin rate
2040  if (!empty($arrayfields['total_margin_rate']['checked'])) {
2041  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
2042  if (!$i) {
2043  $totalarray['nbfield']++;
2044  }
2045  }
2046  // Total mark rate
2047  if (!empty($arrayfields['total_mark_rate']['checked'])) {
2048  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
2049  if (!$i) {
2050  $totalarray['nbfield']++;
2051  }
2052  if (!$i) {
2053  $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2054  }
2055  if ($i >= $last_num - 1) {
2056  if (!empty($total_ht)) {
2057  $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2058  } else {
2059  $totalarray['val']['total_mark_rate'] = '';
2060  }
2061  }
2062  }
2063 
2064  // Extra fields
2065  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2066  // Fields from hook
2067  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
2068  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
2069  print $hookmanager->resPrint;
2070  // Date creation
2071  if (!empty($arrayfields['p.datec']['checked'])) {
2072  print '<td align="center" class="nowrap">';
2073  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2074  print '</td>';
2075  if (!$i) {
2076  $totalarray['nbfield']++;
2077  }
2078  }
2079  // Date modification
2080  if (!empty($arrayfields['p.tms']['checked'])) {
2081  print '<td align="center" class="nowrap">';
2082  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
2083  print '</td>';
2084  if (!$i) {
2085  $totalarray['nbfield']++;
2086  }
2087  }
2088  // Date cloture
2089  if (!empty($arrayfields['p.date_cloture']['checked'])) {
2090  print '<td align="center" class="nowrap">';
2091  print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
2092  print '</td>';
2093  if (!$i) {
2094  $totalarray['nbfield']++;
2095  }
2096  }
2097  // Note public
2098  if (!empty($arrayfields['p.note_public']['checked'])) {
2099  print '<td class="center">';
2100  print dol_string_nohtmltag($obj->note_public);
2101  print '</td>';
2102  if (!$i) {
2103  $totalarray['nbfield']++;
2104  }
2105  }
2106  // Note private
2107  if (!empty($arrayfields['p.note_private']['checked'])) {
2108  print '<td class="center">';
2109  print dol_string_nohtmltag($obj->note_private);
2110  print '</td>';
2111  if (!$i) {
2112  $totalarray['nbfield']++;
2113  }
2114  }
2115  // Status
2116  if (!empty($arrayfields['p.fk_statut']['checked'])) {
2117  print '<td class="nowrap right">'.$objectstatic->getLibStatut(5).'</td>';
2118  if (!$i) {
2119  $totalarray['nbfield']++;
2120  }
2121  }
2122  // Action column
2123  print '<td class="nowrap" align="center">';
2124  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2125  $selected = 0;
2126  if (in_array($obj->rowid, $arrayofselected)) {
2127  $selected = 1;
2128  }
2129  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2130  }
2131  print '</td>';
2132  if (!$i) {
2133  $totalarray['nbfield']++;
2134  }
2135 
2136  print '</tr>'."\n";
2137 
2138  $i++;
2139  }
2140 
2141  // Show total line
2142  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2143 
2144  // If no record found
2145  if ($num == 0) {
2146  $colspan = 1;
2147  foreach ($arrayfields as $key => $val) {
2148  if (!empty($val['checked'])) {
2149  $colspan++;
2150  }
2151  }
2152  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2153  }
2154 
2155  $db->free($resql);
2156 
2157  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2158  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2159  print $hookmanager->resPrint;
2160 
2161  print '</table>'."\n";
2162  print '</div>'."\n";
2163 
2164  print '</form>'."\n";
2165 
2166  $hidegeneratedfilelistifempty = 1;
2167  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2168  $hidegeneratedfilelistifempty = 0;
2169  }
2170 
2171  // Show list of available documents
2172  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2173  $urlsource .= str_replace('&amp;', '&', $param);
2174 
2175  $filedir = $diroutputmassaction;
2176  $genallowed = $user->rights->propal->lire;
2177  $delallowed = $user->rights->propal->creer;
2178 
2179  print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2180 } else {
2181  dol_print_error($db);
2182 }
2183 
2184 // End of page
2185 llxFooter();
2186 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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...
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.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
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
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
Class to manage generation of HTML components for proposal management.
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
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class with static methods for building HTML components related to products Only components common to ...
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
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...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
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:429
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.
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
const TYPE_DEPOSIT
Deposit invoice.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
const STATUS_VALIDATED
Validated status.
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:73
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
Class to manage proposals.