dolibarr  21.0.0-alpha
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
8  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
9  * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
10  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
11  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
12  * Copyright (C) 2016-2023 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2018-2023 Charlene Benke <charlene@patas-monkey.com>
14  * Copyright (C) 2021-2024 Anthony Berton <anthony.berton@bb2a.fr>
15  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
16  * Copyright (C) 2024 Noé Cendrier <noe.cendrier@altairis.fr>
17  * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <https://www.gnu.org/licenses/>.
31  */
32 
40 // Load Dolibarr environment
41 require '../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
48 if (isModEnabled('margin')) {
49  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
50 }
51 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55 
56 // Load translation files required by the page
57 $langs->loadLangs(array('orders', 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products'));
58 
59 // Get Parameters
60 $action = GETPOST('action', 'aZ09');
61 $massaction = GETPOST('massaction', 'alpha');
62 $show_files = GETPOSTINT('show_files');
63 $confirm = GETPOST('confirm', 'alpha');
64 $toselect = GETPOST('toselect', 'array');
65 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'orderlist';
66 $optioncss = GETPOST('optioncss', 'alpha');
67 $mode = GETPOST('mode', 'alpha');
68 
69 if (getDolGlobalInt('MAIN_SEE_SUBORDINATES')) {
70  $userschilds = $user->getAllChildIds();
71 }
72 
73 // Search Parameters
74 $search_datecloture_start = GETPOSTINT('search_datecloture_start');
75 if (empty($search_datecloture_start)) {
76  $search_datecloture_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datecloture_startmonth'), GETPOSTINT('search_datecloture_startday'), GETPOSTINT('search_datecloture_startyear'));
77 }
78 $search_datecloture_end = GETPOSTINT('search_datecloture_end');
79 if (empty($search_datecloture_end)) {
80  $search_datecloture_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datecloture_endmonth'), GETPOSTINT('search_datecloture_endday'), GETPOSTINT('search_datecloture_endyear'));
81 }
82 $search_dateorder_start = dol_mktime(0, 0, 0, GETPOSTINT('search_dateorder_start_month'), GETPOSTINT('search_dateorder_start_day'), GETPOSTINT('search_dateorder_start_year'));
83 $search_dateorder_end = dol_mktime(23, 59, 59, GETPOSTINT('search_dateorder_end_month'), GETPOSTINT('search_dateorder_end_day'), GETPOSTINT('search_dateorder_end_year'));
84 $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datedelivery_start_month'), GETPOSTINT('search_datedelivery_start_day'), GETPOSTINT('search_datedelivery_start_year'));
85 $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datedelivery_end_month'), GETPOSTINT('search_datedelivery_end_day'), GETPOSTINT('search_datedelivery_end_year'));
86 
87 $socid = GETPOSTINT('socid');
88 
89 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
90 $search_product_category = GETPOST('search_product_category', 'intcomma');
91 $search_id = GETPOST('search_id', 'int');
92 $search_ref = GETPOST('search_ref', 'alpha') != '' ? GETPOST('search_ref', 'alpha') : GETPOST('sref', 'alpha');
93 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
94 $search_company = GETPOST('search_company', 'alpha');
95 $search_company_alias = GETPOST('search_company_alias', 'alpha');
96 $search_parent_name = trim(GETPOST('search_parent_name', 'alphanohtml'));
97 $search_town = GETPOST('search_town', 'alpha');
98 $search_zip = GETPOST('search_zip', 'alpha');
99 $search_state = GETPOST('search_state', 'alpha');
100 $search_country = GETPOST('search_country', 'aZ09');
101 $search_type_thirdparty = GETPOST('search_type_thirdparty', 'intcomma');
102 $search_user = GETPOST('search_user', 'intcomma');
103 $search_sale = GETPOST('search_sale', 'intcomma');
104 $search_total_ht = GETPOST('search_total_ht', 'alpha');
105 $search_total_vat = GETPOST('search_total_vat', 'alpha');
106 $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
107 $search_warehouse = GETPOST('search_warehouse', 'intcomma');
108 
109 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
110 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
111 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
112 $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
113 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
114 
115 $search_login = GETPOST('search_login', 'alpha');
116 $search_categ_cus = GETPOST("search_categ_cus", 'intcomma');
117 $search_billed = GETPOST('search_billed', 'intcomma');
118 $search_status = GETPOST('search_status', 'intcomma');
119 $search_project_ref = GETPOST('search_project_ref', 'alpha');
120 $search_project = GETPOST('search_project', 'alpha');
121 $search_shippable = GETPOST('search_shippable', 'aZ09');
122 
123 $search_fk_cond_reglement = GETPOST('search_fk_cond_reglement', 'intcomma');
124 $search_fk_shipping_method = GETPOST('search_fk_shipping_method', 'intcomma');
125 $search_fk_mode_reglement = GETPOST('search_fk_mode_reglement', 'intcomma');
126 $search_fk_input_reason = GETPOST('search_fk_input_reason', 'intcomma');
127 
128 $diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
129 
130 // Load variable for pagination
131 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
132 $sortfield = GETPOST('sortfield', 'aZ09comma');
133 $sortorder = GETPOST('sortorder', 'aZ09comma');
134 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
135 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
136  // If $page is not defined, or '' or -1 or if we click on clear filters
137  $page = 0;
138 }
139 $offset = $limit * $page;
140 $pageprev = $page - 1;
141 $pagenext = $page + 1;
142 if (!$sortfield) {
143  $sortfield = 'c.ref';
144 }
145 if (!$sortorder) {
146  $sortorder = 'DESC';
147 }
148 
149 $show_shippable_command = GETPOST('show_shippable_command', 'aZ09');
150 
151 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
152 $object = new Commande($db);
153 $hookmanager->initHooks(array('orderlist'));
154 $extrafields = new ExtraFields($db);
155 
156 // fetch optionals attributes and labels
157 $extrafields->fetch_name_optionals_label($object->table_element);
158 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
159 
160 // List of fields to search into when doing a "search in all"
161 $fieldstosearchall = array(
162  'c.ref' => 'Ref',
163  'c.ref_client' => 'RefCustomerOrder',
164  'pd.description' => 'Description',
165  's.nom' => "ThirdParty",
166  's.name_alias' => "AliasNameShort",
167  's.zip' => "Zip",
168  's.town' => "Town",
169  'c.note_public' => 'NotePublic',
170 );
171 if (empty($user->socid)) {
172  $fieldstosearchall["c.note_private"] = "NotePrivate";
173 }
174 
175 $checkedtypetiers = 0;
176 $arrayfields = array(
177  'c.rowid' => array('label' => "ID", 'checked' => 1, 'enabled' => getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'position' => 1),
178  'c.ref' => array('label' => "Ref", 'checked' => 1, 'position' => 5, 'searchall' => 1),
179  'c.ref_client' => array('label' => "RefCustomerOrder", 'checked' => -1, 'position' => 10, 'searchall' => 1),
180  'p.ref' => array('label' => "ProjectRef", 'checked' => -1, 'enabled' => (!isModEnabled('project') ? 0 : 1), 'position' => 20),
181  'p.title' => array('label' => "ProjectLabel", 'checked' => 0, 'enabled' => (!isModEnabled('project') ? 0 : 1), 'position' => 25),
182  's.nom' => array('label' => "ThirdParty", 'checked' => 1, 'position' => 30, 'searchall' => 1),
183  's.name_alias' => array('label' => "AliasNameShort", 'checked' => -1, 'position' => 31, 'searchall' => 1),
184  's2.nom' => array('label' => 'ParentCompany', 'position' => 32, 'checked' => 0),
185  's.town' => array('label' => "Town", 'checked' => -1, 'position' => 35, 'searchall' => 1),
186  's.zip' => array('label' => "Zip", 'checked' => -1, 'position' => 40, 'searchall' => 1),
187  'state.nom' => array('label' => "StateShort", 'checked' => 0, 'position' => 45),
188  'country.code_iso' => array('label' => "Country", 'checked' => 0, 'position' => 50),
189  'typent.code' => array('label' => "ThirdPartyType", 'checked' => $checkedtypetiers, 'position' => 55),
190  'c.date_commande' => array('label' => "OrderDateShort", 'checked' => 1, 'position' => 60, 'csslist' => 'nowraponall'),
191  'c.date_delivery' => array('label' => "DateDeliveryPlanned", 'checked' => 1, 'enabled' => !getDolGlobalString('ORDER_DISABLE_DELIVERY_DATE'), 'position' => 65, 'csslist' => 'nowraponall'),
192  'c.fk_shipping_method' => array('label' => "SendingMethod", 'checked' => -1, 'position' => 66 , 'enabled' => isModEnabled("shipping")),
193  'c.fk_cond_reglement' => array('label' => "PaymentConditionsShort", 'checked' => -1, 'position' => 67),
194  'c.fk_mode_reglement' => array('label' => "PaymentMode", 'checked' => -1, 'position' => 68),
195  'c.fk_input_reason' => array('label' => "Channel", 'checked' => -1, 'position' => 69),
196  'c.total_ht' => array('label' => "AmountHT", 'checked' => 1, 'position' => 75),
197  'c.total_vat' => array('label' => "AmountVAT", 'checked' => 0, 'position' => 80),
198  'c.total_ttc' => array('label' => "AmountTTC", 'checked' => 0, 'position' => 85),
199  'c.multicurrency_code' => array('label' => 'Currency', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 90),
200  'c.multicurrency_tx' => array('label' => 'CurrencyRate', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 95),
201  'c.multicurrency_total_ht' => array('label' => 'MulticurrencyAmountHT', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 100),
202  'c.multicurrency_total_vat' => array('label' => 'MulticurrencyAmountVAT', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 105),
203  'c.multicurrency_total_ttc' => array('label' => 'MulticurrencyAmountTTC', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 110),
204  'u.login' => array('label' => "Author", 'checked' => 1, 'position' => 115),
205  'sale_representative' => array('label' => "SaleRepresentativesOfThirdParty", 'checked' => 0, 'position' => 116),
206  'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") ? 0 : 1)),
207  'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") ? 0 : 1)),
208  'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") || !getDolGlobalString('DISPLAY_MARGIN_RATES') ? 0 : 1)),
209  'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") || !getDolGlobalString('DISPLAY_MARK_RATES') ? 0 : 1)),
210  'c.datec' => array('label' => "DateCreation", 'checked' => 0, 'position' => 120),
211  'c.tms' => array('label' => "DateModificationShort", 'checked' => 0, 'position' => 125),
212  'c.date_cloture' => array('label' => "DateClosing", 'checked' => 0, 'position' => 130),
213  'c.note_public' => array('label' => 'NotePublic', 'checked' => 0, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES')), 'position' => 135, 'searchall' => 1),
214  'c.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'position' => 140),
215  'shippable' => array('label' => "Shippable", 'checked' => 1,'enabled' => (isModEnabled("shipping")), 'position' => 990),
216  'c.facture' => array('label' => "Billed", 'checked' => 1, 'enabled' => (!getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')), 'position' => 995),
217  'c.import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 999),
218  'c.fk_statut' => array('label' => "Status", 'checked' => 1, 'position' => 1000)
219 );
220 
221 $parameters = array('fieldstosearchall' => $fieldstosearchall);
222 $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
223 if ($reshook > 0) {
224  $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
225 } elseif ($reshook == 0) {
226  $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
227 }
228 
229 // Extra fields
230 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
231 
232 $object->fields = dol_sort_array($object->fields, 'position');
233 //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
234 $arrayfields = dol_sort_array($arrayfields, 'position');
235 '@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
236 
237 
238 // Security check
239 $id = GETPOSTINT('orderid', GETPOSTINT('id'));
240 if ($user->socid) {
241  $socid = $user->socid;
242 }
243 
244 $permissiontoreadallthirdparty = $user->hasRight('societe', 'client', 'voir');
245 
246 
247 $result = restrictedArea($user, 'commande', $id, '');
248 
249 $error = 0;
250 
251 
252 /*
253  * Actions
254  */
255 
256 if (GETPOST('cancel', 'alpha')) {
257  $action = 'list';
258  $massaction = '';
259 }
260 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
261  $massaction = '';
262 }
263 
264 $parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
265 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
266 if ($reshook < 0) {
267  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
268 }
269 
270 if (empty($reshook)) {
271  // Selection of new fields
272  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
273 
274  // Purge search criteria
275  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
276  $search_user = '';
277  $search_sale = '';
278  $search_product_category = '';
279  $search_id = '';
280  $search_ref = '';
281  $search_ref_customer = '';
282  $search_company = '';
283  $search_company_alias = '';
284  $search_parent_name = '';
285  $search_town = '';
286  $search_zip = "";
287  $search_state = "";
288  $search_type = '';
289  $search_country = '';
290  $search_type_thirdparty = '';
291  $search_total_ht = '';
292  $search_total_vat = '';
293  $search_total_ttc = '';
294  $search_warehouse = '';
295  $search_multicurrency_code = '';
296  $search_multicurrency_tx = '';
297  $search_multicurrency_montant_ht = '';
298  $search_multicurrency_montant_vat = '';
299  $search_multicurrency_montant_ttc = '';
300  $search_login = '';
301  $search_dateorder_start = '';
302  $search_dateorder_end = '';
303  $search_datedelivery_start = '';
304  $search_datedelivery_end = '';
305  $search_project_ref = '';
306  $search_project = '';
307  $search_status = '';
308  $search_billed = '';
309  $toselect = array();
310  $search_array_options = array();
311  $search_categ_cus = 0;
312  $search_datecloture_start = '';
313  $search_datecloture_end = '';
314  $search_fk_cond_reglement = '';
315  $search_fk_shipping_method = '';
316  $search_fk_mode_reglement = '';
317  $search_fk_input_reason = '';
318  }
319  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
320  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
321  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
322  }
323 
324  // Mass actions
325  $objectclass = 'Commande';
326  $objectlabel = 'Orders';
327  $permissiontoread = $user->hasRight("commande", "lire");
328  $permissiontoadd = $user->hasRight("commande", "creer");
329  $permissiontodelete = $user->hasRight("commande", "supprimer");
330  if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
331  $permissiontovalidate = $user->hasRight("commande", "order_advance", "validate");
332  $permissiontoclose = $user->hasRight("commande", "order_advance", "close");
333  $permissiontocancel = $user->hasRight("commande", "order_advance", "annuler");
334  $permissiontosendbymail = $user->hasRight("commande", "order_advance", "send");
335  } else {
336  $permissiontovalidate = $user->hasRight("commande", "creer");
337  $permissiontoclose = $user->hasRight("commande", "creer");
338  $permissiontocancel = $user->hasRight("commande", "creer");
339  $permissiontosendbymail = $user->hasRight("commande", "creer");
340  }
341  $uploaddir = $conf->commande->multidir_output[$conf->entity];
342  $triggersendname = 'ORDER_SENTBYMAIL';
343  $year = "";
344  $month = "";
345  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
346 
347  if ($massaction == 'confirm_createbills') { // Create bills from orders.
348  $orders = GETPOST('toselect', 'array');
349  $createbills_onebythird = GETPOSTINT('createbills_onebythird');
350  $validate_invoices = GETPOSTINT('validate_invoices');
351 
352  $errors = array();
353 
354  $TFact = array();
355  $TFactThird = array();
356  $TFactThirdNbLines = array();
357 
358  $nb_bills_created = 0;
359  $lastid = 0;
360  $lastref = '';
361 
362  $db->begin();
363 
364  $nbOrders = is_array($orders) ? count($orders) : 1;
365 
366  foreach ($orders as $id_order) {
367  $cmd = new Commande($db);
368  if ($cmd->fetch($id_order) <= 0) {
369  continue;
370  }
371  $cmd->fetch_thirdparty();
372 
373  $objecttmp = new Facture($db);
374  if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
375  // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we reuse it.
376  $objecttmp = $TFactThird[$cmd->socid];
377  } else {
378  // If we want one invoice per order or if there is no first invoice yet for this thirdparty.
379  $objecttmp->socid = $cmd->socid;
380  $objecttmp->thirdparty = $cmd->thirdparty;
381 
382  $objecttmp->type = $objecttmp::TYPE_STANDARD;
383  $objecttmp->cond_reglement_id = !empty($cmd->cond_reglement_id) ? $cmd->cond_reglement_id : $cmd->thirdparty->cond_reglement_id;
384  $objecttmp->mode_reglement_id = !empty($cmd->mode_reglement_id) ? $cmd->mode_reglement_id : $cmd->thirdparty->mode_reglement_id;
385 
386  $objecttmp->fk_project = $cmd->fk_project;
387  $objecttmp->multicurrency_code = $cmd->multicurrency_code;
388  if (empty($createbills_onebythird)) {
389  $objecttmp->ref_client = $cmd->ref_client;
390  }
391 
392  $datefacture = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
393  if (empty($datefacture)) {
394  $datefacture = dol_now();
395  }
396 
397  $objecttmp->date = $datefacture;
398  $objecttmp->origin = 'commande';
399  $objecttmp->origin_id = $id_order;
400 
401  $objecttmp->array_options = $cmd->array_options; // Copy extrafields
402 
403  $res = $objecttmp->create($user);
404 
405  if ($res > 0) {
406  $nb_bills_created++;
407  $lastref = $objecttmp->ref;
408  $lastid = $objecttmp->id;
409 
410  $TFactThird[$cmd->socid] = $objecttmp;
411  $TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang
412  } else {
413  $langs->load("errors");
414  $errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
415  $error++;
416  }
417  }
418 
419  if ($objecttmp->id > 0) {
420  $res = $objecttmp->add_object_linked($objecttmp->origin, $id_order);
421 
422  if ($res == 0) {
423  $errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
424  $error++;
425  }
426 
427  if (!$error) {
428  $lines = $cmd->lines;
429  if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
430  $cmd->fetch_lines();
431  $lines = $cmd->lines;
432  }
433 
434  $fk_parent_line = 0;
435  $num = count($lines);
436 
437  for ($i = 0; $i < $num; $i++) {
438  $desc = ($lines[$i]->desc ? $lines[$i]->desc : '');
439  // If we build one invoice for several orders, we must put the ref of order on the invoice line
440  if (!empty($createbills_onebythird)) {
441  $desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day'));
442  }
443 
444  if ($lines[$i]->subprice < 0 && !getDolGlobalString('INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
445  // Negative line, we create a discount line
446  $discount = new DiscountAbsolute($db);
447  $discount->fk_soc = $objecttmp->socid;
448  $discount->socid = $objecttmp->socid;
449  $discount->amount_ht = abs($lines[$i]->total_ht);
450  $discount->amount_tva = abs($lines[$i]->total_tva);
451  $discount->amount_ttc = abs($lines[$i]->total_ttc);
452  $discount->tva_tx = $lines[$i]->tva_tx;
453  $discount->fk_user = $user->id;
454  $discount->description = $desc;
455  $discountid = $discount->create($user);
456  if ($discountid > 0) {
457  $result = $objecttmp->insert_discount($discountid);
458  //$result=$discount->link_to_invoice($lineid,$id);
459  } else {
460  setEventMessages($discount->error, $discount->errors, 'errors');
461  $error++;
462  break;
463  }
464  } else {
465  // Positive line
466  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
467  // Date start
468  $date_start = false;
469  if ($lines[$i]->date_debut_prevue) {
470  $date_start = $lines[$i]->date_debut_prevue;
471  }
472  if ($lines[$i]->date_debut_reel) {
473  $date_start = $lines[$i]->date_debut_reel;
474  }
475  if ($lines[$i]->date_start) {
476  $date_start = $lines[$i]->date_start;
477  }
478  //Date end
479  $date_end = false;
480  if ($lines[$i]->date_fin_prevue) {
481  $date_end = $lines[$i]->date_fin_prevue;
482  }
483  if ($lines[$i]->date_fin_reel) {
484  $date_end = $lines[$i]->date_fin_reel;
485  }
486  if ($lines[$i]->date_end) {
487  $date_end = $lines[$i]->date_end;
488  }
489  // Reset fk_parent_line for no child products and special product
490  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
491  $fk_parent_line = 0;
492  }
493 
494  // Extrafields
495  if (method_exists($lines[$i], 'fetch_optionals')) {
496  $lines[$i]->fetch_optionals();
497  $array_options = $lines[$i]->array_options;
498  }
499 
500  $objecttmp->context['createfromclone'] = 'createfromclone';
501 
502  $rang = ($nbOrders > 1) ? -1 : $lines[$i]->rang;
503  //there may already be rows from previous orders
504  if (!empty($createbills_onebythird)) {
505  $TFactThirdNbLines[$cmd->socid]++;
506  $rang = $TFactThirdNbLines[$cmd->socid];
507  }
508 
509  $result = $objecttmp->addline(
510  $desc,
511  $lines[$i]->subprice,
512  $lines[$i]->qty,
513  $lines[$i]->tva_tx,
514  $lines[$i]->localtax1_tx,
515  $lines[$i]->localtax2_tx,
516  $lines[$i]->fk_product,
517  $lines[$i]->remise_percent,
518  $date_start,
519  $date_end,
520  0,
521  $lines[$i]->info_bits,
522  $lines[$i]->fk_remise_except,
523  'HT',
524  0,
525  $product_type,
526  $rang,
527  $lines[$i]->special_code,
528  $objecttmp->origin,
529  $lines[$i]->rowid,
530  $fk_parent_line,
531  $lines[$i]->fk_fournprice,
532  $lines[$i]->pa_ht,
533  $lines[$i]->label,
534  $array_options,
535  100,
536  0,
537  $lines[$i]->fk_unit
538  );
539  if ($result > 0) {
540  $lineid = $result;
541  } else {
542  $lineid = 0;
543  $error++;
544  $errors[] = $objecttmp->error;
545  break;
546  }
547  // Defined the new fk_parent_line
548  if ($result > 0 && $lines[$i]->product_type == 9) {
549  $fk_parent_line = $result;
550  }
551  }
552  }
553  }
554  }
555 
556  //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
557 
558  if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
559  $TFactThird[$cmd->socid] = $objecttmp;
560  } else {
561  $TFact[$objecttmp->id] = $objecttmp;
562  }
563  }
564 
565  // Build doc with all invoices
566  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
567  $toselect = array();
568 
569  if (!$error && $validate_invoices) {
570  $massaction = $action = 'builddoc';
571 
572  foreach ($TAllFact as &$objecttmp) {
573  $result = $objecttmp->validate($user);
574  if ($result <= 0) {
575  $error++;
576  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
577  break;
578  }
579 
580  $id = $objecttmp->id; // For builddoc action
581 
582  // Builddoc
583  $donotredirect = 1;
584  $upload_dir = $conf->facture->dir_output;
585  $permissiontoadd = $user->hasRight('facture', 'creer');
586 
587  // Call action to build doc
588  $savobject = $object;
589  $object = $objecttmp;
590  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
591  $object = $savobject;
592  }
593 
594  $massaction = $action = 'confirm_createbills';
595  }
596 
597  if (!$error) {
598  $db->commit();
599 
600  if ($nb_bills_created == 1) {
601  if (getDolGlobalInt('MAIN_MASSACTION_CREATEBILLS_REDIRECT_IF_ONE') == 1) {
602  // Redirect to generated invoice if unique
603  header('Location: '.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode((string) $lastid));
604  exit;
605  }
606  $texttoshow = $langs->trans('BillXCreated', '{s1}');
607  $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode((string) ($lastid)).'">'.$lastref.'</a>', $texttoshow);
608  setEventMessages($texttoshow, null, 'mesgs');
609  } else {
610  if (getDolGlobalInt('MAIN_MASSACTION_CREATEBILLS_REDIRECT_IF_MANY') == 1) {
611  // Redirect to invoice list
612  header("Location: ".DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills');
613  exit;
614  }
615  setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
616  }
617 
618  // Make a redirect to avoid to bill twice if we make a refresh or back
619  $param = '';
620  if (!empty($mode)) {
621  $param .= '&mode='.urlencode($mode);
622  }
623  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
624  $param .= '&contextpage='.urlencode($contextpage);
625  }
626  if ($limit > 0 && $limit != $conf->liste_limit) {
627  $param .= '&limit='.((int) $limit);
628  }
629  if ($optioncss != '') {
630  $param .= '&optioncss='.urlencode($optioncss);
631  }
632  if ($search_all) {
633  $param .= '&search_all='.urlencode($search_all);
634  }
635  if ($show_files) {
636  $param .= '&show_files='.urlencode((string) ($show_files));
637  }
638  if ($socid > 0) {
639  $param .= '&socid='.urlencode((string) ($socid));
640  }
641  if ($search_status != '') {
642  $param .= '&search_status='.urlencode($search_status);
643  }
644  if ($search_orderday) {
645  $param .= '&search_orderday='.urlencode($search_orderday);
646  }
647  if ($search_ordermonth) {
648  $param .= '&search_ordermonth='.urlencode($search_ordermonth);
649  }
650  if ($search_orderyear) {
651  $param .= '&search_orderyear='.urlencode($search_orderyear);
652  }
653  if ($search_deliveryday) {
654  $param .= '&search_deliveryday='.urlencode($search_deliveryday);
655  }
656  if ($search_deliverymonth) {
657  $param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
658  }
659  if ($search_deliveryyear) {
660  $param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
661  }
662  if ($search_id) {
663  $param .= '&search_id='.urlencode((string) $search_id);
664  }
665  if ($search_ref) {
666  $param .= '&search_ref='.urlencode($search_ref);
667  }
668  if ($search_company) {
669  $param .= '&search_company='.urlencode($search_company);
670  }
671  if ($search_ref_customer) {
672  $param .= '&search_ref_customer='.urlencode($search_ref_customer);
673  }
674  if ($search_user > 0) {
675  $param .= '&search_user='.urlencode((string) ($search_user));
676  }
677  if ($search_sale > 0) {
678  $param .= '&search_sale='.urlencode((string) ($search_sale));
679  }
680  if ($search_total_ht != '') {
681  $param .= '&search_total_ht='.urlencode($search_total_ht);
682  }
683  if ($search_total_vat != '') {
684  $param .= '&search_total_vat='.urlencode($search_total_vat);
685  }
686  if ($search_total_ttc != '') {
687  $param .= '&search_total_ttc='.urlencode($search_total_ttc);
688  }
689  if ($search_project_ref >= 0) {
690  $param .= "&search_project_ref=".urlencode($search_project_ref);
691  }
692  if ($search_billed != '') {
693  $param .= '&search_billed='.urlencode($search_billed);
694  }
695 
696  header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
697  exit;
698  } else {
699  $db->rollback();
700 
701  $action = 'create';
702  $_GET["origin"] = $_POST["origin"]; // Keep GET and POST here ?
703  $_GET["originid"] = $_POST["originid"]; // Keep GET and POST here ?
704  if (!empty($errors)) {
705  setEventMessages(null, $errors, 'errors');
706  } else {
707  setEventMessages("Error", null, 'errors');
708  }
709  $error++;
710  }
711  }
712 }
713 if ($action == 'validate' && $permissiontoadd) {
714  if (GETPOST('confirm') == 'yes') {
715  $objecttmp = new $objectclass($db);
716  $db->begin();
717  $error = 0;
718  foreach ($toselect as $checked) {
719  if ($objecttmp->fetch($checked)) {
720  if ($objecttmp->statut == 0) {
721  if (!empty($objecttmp->fk_warehouse)) {
722  $idwarehouse = $objecttmp->fk_warehouse;
723  } else {
724  $idwarehouse = 0;
725  }
726  if ($objecttmp->valid($user, $idwarehouse)) {
727  setEventMessages($langs->trans('hasBeenValidated', $objecttmp->ref), null, 'mesgs');
728  } else {
729  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
730  $error++;
731  }
732  } else {
733  $langs->load("errors");
734  setEventMessages($langs->trans('ErrorIsNotADraft', $objecttmp->ref), null, 'errors');
735  $error++;
736  }
737  } else {
738  dol_print_error($db);
739  $error++;
740  }
741  }
742  if ($error) {
743  $db->rollback();
744  } else {
745  $db->commit();
746  }
747  }
748 }
749 if ($action == 'shipped' && $permissiontoadd) {
750  if (GETPOST('confirm') == 'yes') {
751  $objecttmp = new $objectclass($db);
752  $db->begin();
753  $error = 0;
754  foreach ($toselect as $checked) {
755  if ($objecttmp->fetch($checked)) {
756  if ($objecttmp->statut == 1 || $objecttmp->statut == 2) {
757  if ($objecttmp->cloture($user)) {
758  setEventMessages($langs->trans('StatusOrderDelivered', $objecttmp->ref), null, 'mesgs');
759  } else {
760  setEventMessages($langs->trans('ErrorOrderStatusCantBeSetToDelivered'), null, 'errors');
761  $error++;
762  }
763  } else {
764  $langs->load("errors");
765  setEventMessages($langs->trans('ErrorIsNotADraft', $objecttmp->ref), null, 'errors');
766  $error++;
767  }
768  } else {
769  dol_print_error($db);
770  $error++;
771  }
772  }
773  if ($error) {
774  $db->rollback();
775  } else {
776  $db->commit();
777  }
778  }
779 }
780 
781 // Closed records
782 if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
783  $db->begin();
784 
785  $objecttmp = new $objectclass($db);
786  $nbok = 0;
787  foreach ($toselect as $toselectid) {
788  $result = $objecttmp->fetch($toselectid);
789  if ($result > 0) {
790  $result = $objecttmp->classifyBilled($user, 0);
791  if ($result <= 0) {
792  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
793  $error++;
794  break;
795  } else {
796  $nbok++;
797  }
798  } else {
799  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
800  $error++;
801  break;
802  }
803  }
804 
805  if (!$error) {
806  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
807  $db->commit();
808  } else {
809  $db->rollback();
810  }
811 }
812 
813 
814 /*
815  * View
816  */
817 
818 $form = new Form($db);
819 $formother = new FormOther($db);
820 $formfile = new FormFile($db);
821 $formmargin = null;
822 if (isModEnabled('margin')) {
823  $formmargin = new FormMargin($db);
824 }
825 $companystatic = new Societe($db);
826 $company_url_list = array();
827 $formcompany = new FormCompany($db);
828 $projectstatic = new Project($db);
829 
830 $now = dol_now();
831 
832 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
833 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
834 
835 $title = $langs->trans("Orders");
836 $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
837 
838 // Build and execute select
839 // --------------------------------------------------------------------
840 $sql = 'SELECT';
841 if ($search_all) {
842  $sql = 'SELECT DISTINCT';
843 }
844 $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.fournisseur, s.code_client,';
845 $sql .= " s.parent as fk_parent,";
846 $sql .= " s2.nom as name2,";
847 $sql .= " typent.code as typent_code,";
848 $sql .= " state.code_departement as state_code, state.nom as state_name,";
849 $sql .= " country.code as country_code,";
850 $sql .= ' c.rowid, c.ref, c.total_ht, c.total_tva, c.total_ttc, c.ref_client, c.fk_user_author,';
851 $sql .= ' c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva as multicurrency_total_vat, c.multicurrency_total_ttc,';
852 $sql .= ' c.date_valid, c.date_commande, c.note_public, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as billed,';
853 $sql .= ' c.date_creation as date_creation, c.tms as date_modification, c.date_cloture as date_cloture,';
854 $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
855 $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,';
856 $sql .= ' c.fk_cond_reglement,c.deposit_percent,c.fk_mode_reglement,c.fk_shipping_method,';
857 $sql .= ' c.fk_input_reason, c.import_key';
858 
859 // Add fields from extrafields
860 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
861  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
862  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
863  }
864 }
865 
866 // Add fields from hooks
867 $parameters = array();
868 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
869 $sql .= $hookmanager->resPrint;
870 $sql = preg_replace('/,\s*$/', '', $sql);
871 
872 $sqlfields = $sql; // $sql fields to remove for count total
873 
874 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
875 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
876 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
877 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
878 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
879 $sql .= ', '.MAIN_DB_PREFIX.'commande as c';
880 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
881  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
882 }
883 if ($search_all) {
884  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
885 }
886 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
887 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
888 // Add table from hooks
889 $parameters = array();
890 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
891 $sql .= $hookmanager->resPrint;
892 
893 $sql .= ' WHERE c.fk_soc = s.rowid';
894 $sql .= ' AND c.entity IN ('.getEntity('commande').')';
895 if ($socid > 0) {
896  $sql .= ' AND s.rowid = '.((int) $socid);
897 }
898 
899 // Restriction on sale representative
900 if (!$permissiontoreadallthirdparty) {
901  $sql .= " AND (EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
902  if (getDolGlobalInt('MAIN_SEE_SUBORDINATES') && $userschilds) {
903  $sql .= " OR EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user IN (".$db->sanitize(implode(',', $userschilds))."))";
904  }
905  $sql .= ")";
906 }
907 
908 if ($search_id > 0) {
909  $sql .= natural_search('c.rowid', $search_id);
910 }
911 if ($search_ref) {
912  $sql .= natural_search('c.ref', $search_ref);
913 }
914 if ($search_ref_customer) {
915  $sql .= natural_search('c.ref_client', $search_ref_customer);
916 }
917 if ($search_all) {
918  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
919 }
920 if ($search_billed != '' && $search_billed >= 0) {
921  $sql .= ' AND c.facture = '.((int) $search_billed);
922 }
923 if ($search_status != '') {
924  if ($search_status <= 3 && $search_status >= -1) { // status from -1 to 3 are real status (other are virtual combination)
925  if ($search_status == 1 && !isModEnabled('shipping')) {
926  $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status "sent" into "validated"
927  } else {
928  $sql .= ' AND c.fk_statut = '.((int) $search_status); // draft, validated, in process or canceled
929  }
930  }
931  if ($search_status == -2) { // "validated + in progress"
932  //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
933  $sql .= " AND (c.fk_statut IN (1,2))";
934  }
935  if ($search_status == -3) { // "validated + in progress + shipped"
936  //$sql.= ' AND c.fk_statut in (1,2,3)';
937  //$sql.= ' AND c.facture = 0'; // invoice not created
938  $sql .= ' AND (c.fk_statut IN (1,2,3))'; // validated, in process or closed
939  }
940 }
941 
942 if ($search_datecloture_start) {
943  $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
944 }
945 if ($search_datecloture_end) {
946  $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
947 }
948 if ($search_dateorder_start) {
949  $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
950 }
951 if ($search_dateorder_end) {
952  $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
953 }
954 if ($search_datedelivery_start) {
955  $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
956 }
957 if ($search_datedelivery_end) {
958  $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
959 }
960 if ($search_town) {
961  $sql .= natural_search('s.town', $search_town);
962 }
963 if ($search_zip) {
964  $sql .= natural_search("s.zip", $search_zip);
965 }
966 if ($search_state) {
967  $sql .= natural_search("state.nom", $search_state);
968 }
969 if ($search_country) {
970  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
971 }
972 if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
973  $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
974 }
975 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
976  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
977 } else {
978  if ($search_company) {
979  $sql .= natural_search('s.nom', $search_company);
980  }
981  if ($search_company_alias) {
982  $sql .= natural_search('s.name_alias', $search_company_alias);
983  }
984 }
985 if ($search_parent_name) {
986  $sql .= natural_search('s2.nom', $search_parent_name);
987 }
988 if ($search_total_ht != '') {
989  $sql .= natural_search('c.total_ht', $search_total_ht, 1);
990 }
991 if ($search_total_vat != '') {
992  $sql .= natural_search('c.total_tva', $search_total_vat, 1);
993 }
994 if ($search_total_ttc != '') {
995  $sql .= natural_search('c.total_ttc', $search_total_ttc, 1);
996 }
997 if ($search_warehouse != '' && $search_warehouse > 0) {
998  $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
999 }
1000 if ($search_multicurrency_code != '') {
1001  $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
1002 }
1003 if ($search_multicurrency_tx != '') {
1004  $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
1005 }
1006 if ($search_multicurrency_montant_ht != '') {
1007  $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
1008 }
1009 if ($search_multicurrency_montant_vat != '') {
1010  $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
1011 }
1012 if ($search_multicurrency_montant_ttc != '') {
1013  $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
1014 }
1015 if ($search_login) {
1016  $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
1017 }
1018 if ($search_project_ref != '') {
1019  $sql .= natural_search("p.ref", $search_project_ref);
1020 }
1021 if ($search_project != '') {
1022  $sql .= natural_search("p.title", $search_project);
1023 }
1024 if ($search_fk_cond_reglement > 0) {
1025  $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
1026 }
1027 if ($search_fk_shipping_method > 0) {
1028  $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
1029 }
1030 if ($search_fk_mode_reglement > 0) {
1031  $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
1032 }
1033 if ($search_fk_input_reason > 0) {
1034  $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
1035 }
1036 // Search on user
1037 if ($search_user > 0) {
1038  $sql .= " AND EXISTS (";
1039  $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople";
1040  $sql .= " FROM llx_element_contact as ec";
1041  $sql .= " INNER JOIN llx_c_type_contact as tc";
1042  $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal'";
1043  $sql .= " WHERE ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user).")";
1044 }
1045 // Search on sale representative
1046 if ($search_sale && $search_sale != '-1') {
1047  if ($search_sale == -2) {
1048  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
1049  } elseif ($search_sale > 0) {
1050  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
1051  }
1052 }
1053 // Search for tag/category ($searchCategoryCustomerList is an array of ID)
1054 $searchCategoryCustomerOperator = -1;
1055 $searchCategoryCustomerList = array($search_categ_cus);
1056 if (!empty($searchCategoryCustomerList)) {
1057  $searchCategoryCustomerSqlList = array();
1058  $listofcategoryid = '';
1059  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
1060  if (intval($searchCategoryCustomer) == -2) {
1061  $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";
1062  } elseif (intval($searchCategoryCustomer) > 0) {
1063  if ($searchCategoryCustomerOperator == 0) {
1064  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategoryCustomer).")";
1065  } else {
1066  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
1067  }
1068  }
1069  }
1070  if ($listofcategoryid) {
1071  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1072  }
1073  if ($searchCategoryCustomerOperator == 1) {
1074  if (!empty($searchCategoryCustomerSqlList)) {
1075  $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
1076  }
1077  } else {
1078  if (!empty($searchCategoryCustomerSqlList)) {
1079  $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
1080  }
1081  }
1082 }
1083 // Search for tag/category ($searchCategoryProductList is an array of ID)
1084 $searchCategoryProductOperator = -1;
1085 $searchCategoryProductList = array($search_product_category);
1086 if (!empty($searchCategoryProductList)) {
1087  $searchCategoryProductSqlList = array();
1088  $listofcategoryid = '';
1089  foreach ($searchCategoryProductList as $searchCategoryProduct) {
1090  if (intval($searchCategoryProduct) == -2) {
1091  $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product)";
1092  } elseif (intval($searchCategoryProduct) > 0) {
1093  if ($searchCategoryProductOperator == 0) {
1094  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
1095  } else {
1096  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
1097  }
1098  }
1099  }
1100  if ($listofcategoryid) {
1101  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1102  }
1103  if ($searchCategoryProductOperator == 1) {
1104  if (!empty($searchCategoryProductSqlList)) {
1105  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
1106  }
1107  } else {
1108  if (!empty($searchCategoryProductSqlList)) {
1109  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
1110  }
1111  }
1112 }
1113 // Add where from extra fields
1114 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1115 // Add where from hooks
1116 $parameters = array();
1117 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1118 $sql .= $hookmanager->resPrint;
1119 
1120 // Add HAVING from hooks
1121 $parameters = array();
1122 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1123 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
1124 //print $sql;
1125 
1126 // Count total nb of records
1127 $nbtotalofrecords = '';
1128 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1129  /* The fast and low memory method to get and count full list converts the sql into a sql count */
1130  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1131  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1132  $resql = $db->query($sqlforcount);
1133  if ($resql) {
1134  $objforcount = $db->fetch_object($resql);
1135  $nbtotalofrecords = $objforcount->nbtotalofrecords;
1136  } else {
1137  dol_print_error($db);
1138  }
1139 
1140  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than paging size (filtering), goto and load page 0
1141  $page = 0;
1142  $offset = 0;
1143  }
1144  $db->free($resql);
1145 }
1146 
1147 $sql .= $db->order($sortfield, $sortorder);
1148 if ($limit) {
1149  $sql .= $db->plimit($limit + 1, $offset);
1150 }
1151 //print $sql;
1152 
1153 $resql = $db->query($sql);
1154 if (!$resql) {
1155  dol_print_error($db);
1156  exit;
1157 }
1158 
1159 if ($socid > 0) {
1160  $soc = new Societe($db);
1161  $soc->fetch($socid);
1162  $title = $langs->trans('CustomersOrders').' - '.$soc->name;
1163  if (empty($search_company)) {
1164  $search_company = $soc->name;
1165  }
1166 } else {
1167  $title = $langs->trans('CustomersOrders');
1168 }
1169 if (strval($search_status) == '0') {
1170  $title .= ' - '.$langs->trans('StatusOrderDraftShort');
1171 }
1172 if ($search_status == 1) {
1173  $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
1174 }
1175 if ($search_status == 2) {
1176  $title .= ' - '.$langs->trans('StatusOrderSentShort');
1177 }
1178 if ($search_status == 3) {
1179  $title .= ' - '.$langs->trans('StatusOrderToBillShort');
1180 }
1181 if ($search_status == -1) {
1182  $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
1183 }
1184 if ($search_status == -2) {
1185  $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
1186 }
1187 if ($search_status == -3) {
1188  $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(!isModEnabled('shipping') ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
1189 }
1190 if ($search_status == -4) {
1191  $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
1192 }
1193 
1194 $num = $db->num_rows($resql);
1195 
1196 $arrayofselected = is_array($toselect) ? $toselect : array();
1197 
1198 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all) {
1199  $obj = $db->fetch_object($resql);
1200  $id = $obj->rowid;
1201  header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
1202  exit;
1203 }
1204 
1205 // Output page
1206 // --------------------------------------------------------------------
1207 
1208 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-list');
1209 
1210 $arrayofselected = is_array($toselect) ? $toselect : array();
1211 
1212 $param = '';
1213 if (!empty($mode)) {
1214  $param .= '&mode='.urlencode($mode);
1215 }
1216 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1217  $param .= '&contextpage='.urlencode($contextpage);
1218 }
1219 if ($limit > 0 && $limit != $conf->liste_limit) {
1220  $param .= '&limit='.((int) $limit);
1221 }
1222 if ($search_all) {
1223  $param .= '&search_all='.urlencode($search_all);
1224 }
1225 if ($socid > 0) {
1226  $param .= '&socid='.((int) $socid);
1227 }
1228 if ($search_status != '') {
1229  $param .= '&search_status='.urlencode($search_status);
1230 }
1231 if ($search_datecloture_start) {
1232  $param .= '&search_datecloture_startday='.dol_print_date($search_datecloture_start, '%d').'&search_datecloture_startmonth='.dol_print_date($search_datecloture_start, '%m').'&search_datecloture_startyear='.dol_print_date($search_datecloture_start, '%Y');
1233 }
1234 if ($search_datecloture_end) {
1235  $param .= '&search_datecloture_endday='.dol_print_date($search_datecloture_end, '%d').'&search_datecloture_endmonth='.dol_print_date($search_datecloture_end, '%m').'&search_datecloture_endyear='.dol_print_date($search_datecloture_end, '%Y');
1236 }
1237 if ($search_dateorder_start) {
1238  $param .= '&search_dateorder_start_day='.dol_print_date($search_dateorder_start, '%d').'&search_dateorder_start_month='.dol_print_date($search_dateorder_start, '%m').'&search_dateorder_start_year='.dol_print_date($search_dateorder_start, '%Y');
1239 }
1240 if ($search_dateorder_end) {
1241  $param .= '&search_dateorder_end_day='.dol_print_date($search_dateorder_end, '%d').'&search_dateorder_end_month='.dol_print_date($search_dateorder_end, '%m').'&search_dateorder_end_year='.dol_print_date($search_dateorder_end, '%Y');
1242 }
1243 if ($search_datedelivery_start) {
1244  $param .= '&search_datedelivery_start_day='.dol_print_date($search_datedelivery_start, '%d').'&search_datedelivery_start_month='.dol_print_date($search_datedelivery_start, '%m').'&search_datedelivery_start_year='.dol_print_date($search_datedelivery_start, '%Y');
1245 }
1246 if ($search_datedelivery_end) {
1247  $param .= '&search_datedelivery_end_day='.dol_print_date($search_datedelivery_end, '%d').'&search_datedelivery_end_month='.dol_print_date($search_datedelivery_end, '%m').'&search_datedelivery_end_year='.dol_print_date($search_datedelivery_end, '%Y');
1248 }
1249 if ($search_id) {
1250  $param .= '&search_id='.urlencode((string) $search_id);
1251 }
1252 if ($search_ref) {
1253  $param .= '&search_ref='.urlencode($search_ref);
1254 }
1255 if ($search_company) {
1256  $param .= '&search_company='.urlencode($search_company);
1257 }
1258 if ($search_company_alias) {
1259  $param .= '&search_company_alias='.urlencode($search_company_alias);
1260 }
1261 if ($search_parent_name != '') {
1262  $param .= '&search_parent_name='.urlencode($search_parent_name);
1263 }
1264 if ($search_ref_customer) {
1265  $param .= '&search_ref_customer='.urlencode($search_ref_customer);
1266 }
1267 if ($search_user > 0) {
1268  $param .= '&search_user='.urlencode((string) ($search_user));
1269 }
1270 if ($search_sale > 0) {
1271  $param .= '&search_sale='.urlencode((string) ($search_sale));
1272 }
1273 if ($search_total_ht != '') {
1274  $param .= '&search_total_ht='.urlencode($search_total_ht);
1275 }
1276 if ($search_total_vat != '') {
1277  $param .= '&search_total_vat='.urlencode($search_total_vat);
1278 }
1279 if ($search_total_ttc != '') {
1280  $param .= '&search_total_ttc='.urlencode($search_total_ttc);
1281 }
1282 if ($search_warehouse != '') {
1283  $param .= '&search_warehouse='.urlencode((string) ($search_warehouse));
1284 }
1285 if ($search_login) {
1286  $param .= '&search_login='.urlencode($search_login);
1287 }
1288 if ($search_multicurrency_code != '') {
1289  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1290 }
1291 if ($search_multicurrency_tx != '') {
1292  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1293 }
1294 if ($search_multicurrency_montant_ht != '') {
1295  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1296 }
1297 if ($search_multicurrency_montant_vat != '') {
1298  $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
1299 }
1300 if ($search_multicurrency_montant_ttc != '') {
1301  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1302 }
1303 if ($search_project_ref >= 0) {
1304  $param .= "&search_project_ref=".urlencode($search_project_ref);
1305 }
1306 if ($search_town != '') {
1307  $param .= '&search_town='.urlencode($search_town);
1308 }
1309 if ($search_zip != '') {
1310  $param .= '&search_zip='.urlencode($search_zip);
1311 }
1312 if ($search_state != '') {
1313  $param .= '&search_state='.urlencode($search_state);
1314 }
1315 if ($search_country != '') {
1316  $param .= '&search_country='.urlencode((string) ($search_country));
1317 }
1318 if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
1319  $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
1320 }
1321 if ($search_product_category != '') {
1322  $param .= '&search_product_category='.urlencode((string) ($search_product_category));
1323 }
1324 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
1325  $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
1326 }
1327 if ($show_files) {
1328  $param .= '&show_files='.urlencode((string) ($show_files));
1329 }
1330 if ($optioncss != '') {
1331  $param .= '&optioncss='.urlencode($optioncss);
1332 }
1333 if ($search_billed != '') {
1334  $param .= '&search_billed='.urlencode($search_billed);
1335 }
1336 if ($search_fk_cond_reglement > 0) {
1337  $param .= '&search_fk_cond_reglement='.urlencode((string) ($search_fk_cond_reglement));
1338 }
1339 if ($search_fk_shipping_method > 0) {
1340  $param .= '&search_fk_shipping_method='.urlencode((string) ($search_fk_shipping_method));
1341 }
1342 if ($search_fk_mode_reglement > 0) {
1343  $param .= '&search_fk_mode_reglement='.urlencode((string) ($search_fk_mode_reglement));
1344 }
1345 if ($search_fk_input_reason > 0) {
1346  $param .= '&search_fk_input_reason='.urlencode((string) ($search_fk_input_reason));
1347 }
1348 
1349 // Add $param from extra fields
1350 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1351 
1352 // Add $param from hooks
1353 $parameters = array();
1354 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1355 $param .= $hookmanager->resPrint;
1356 
1357 // List of mass actions available
1358 $arrayofmassactions = array(
1359  'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1360  'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1361 );
1362 if ($permissiontovalidate) {
1363  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1364 }
1365 if ($permissiontoclose) {
1366  $arrayofmassactions['preshipped'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').$langs->trans("ClassifyShipped");
1367 }
1368 if (isModEnabled('invoice') && $user->hasRight("facture", "creer")) {
1369  $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomer");
1370 }
1371 if ($permissiontoclose) {
1372  $arrayofmassactions['setbilled'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
1373 }
1374 if ($permissiontocancel) {
1375  $arrayofmassactions['cancelorders'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("CancelOrder");
1376 }
1377 if (!empty($permissiontodelete)) {
1378  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1379 }
1380 if ($permissiontosendbymail) {
1381  $arrayofmassactions['presend'] = img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
1382 }
1383 if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1384  $arrayofmassactions = array();
1385 }
1386 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1387 
1388 $url = DOL_URL_ROOT.'/commande/card.php?action=create';
1389 if (!empty($socid)) {
1390  $url .= '&socid='.$socid;
1391 }
1392 $newcardbutton = '';
1393 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
1394 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
1395 $newcardbutton .= dolGetButtonTitleSeparator();
1396 $newcardbutton .= dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', ($contextpage == 'orderlist' || $contextpage == 'billableorders') && $permissiontoadd);
1397 
1398 // Lines of title fields
1399 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1400 if ($optioncss != '') {
1401  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1402 }
1403 print '<input type="hidden" name="token" value="'.newToken().'">';
1404 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1405 print '<input type="hidden" name="action" value="list">';
1406 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1407 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1408 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1409 print '<input type="hidden" name="search_status" value="'.$search_status.'">';
1410 print '<input type="hidden" name="socid" value="'.$socid.'">';
1411 print '<input type="hidden" name="page_y" value="">';
1412 print '<input type="hidden" name="mode" value="'.$mode.'">';
1413 
1414 
1415 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1416 
1417 $topicmail = "SendOrderRef";
1418 $modelmail = "order_send";
1419 $objecttmp = new Commande($db);
1420 $trackid = 'ord'.$object->id;
1421 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1422 
1423 if ($massaction == 'prevalidate') {
1424  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1425 }
1426 if ($massaction == 'preshipped') {
1427  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("CloseOrder"), $langs->trans("ConfirmCloseOrder"), "shipped", null, '', 0, 200, 500, 1);
1428 }
1429 
1430 if ($massaction == 'createbills') {
1431  print '<input type="hidden" name="massaction" value="confirm_createbills">';
1432 
1433  print '<table class="noborder centpercent">';
1434  print '<tr>';
1435  print '<td>';
1436  print $langs->trans('DateInvoice');
1437  print '</td>';
1438  print '<td>';
1439  print $form->selectDate('', '', 0, 0, 0, '', 1, 1);
1440  print '</td>';
1441  print '</tr>';
1442  print '<tr>';
1443  print '<td>';
1444  print $langs->trans('CreateOneBillByThird');
1445  print '</td>';
1446  print '<td>';
1447  print $form->selectyesno('createbills_onebythird', getDolGlobalString('MAIN_ORDERLIST_CREATEBILLS_ONEBYTHIRD', 'no'), 1);
1448  print '</td>';
1449  print '</tr>';
1450  print '<tr>';
1451  print '<td>';
1452  print $langs->trans('ValidateInvoices');
1453  print '</td>';
1454  print '<td>';
1455  if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
1456  print $form->selectyesno('validate_invoices', 0, 1, 1);
1457  $langs->load("errors");
1458  print ' ('.$langs->trans("WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal").')';
1459  } else {
1460  print $form->selectyesno('validate_invoices', 0, 1);
1461  }
1462  if (!empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER')) {
1463  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
1464  } else {
1465  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
1466  }
1467  print '</td>';
1468  print '</tr>';
1469  print '</table>';
1470 
1471  print '<div class="center">';
1472  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1473  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1474  print '</div>';
1475  print '<br><br>';
1476 }
1477 
1478 if ($search_all) {
1479  $setupstring = '';
1480  foreach ($fieldstosearchall as $key => $val) {
1481  $fieldstosearchall[$key] = $langs->trans($val);
1482  $setupstring .= $key."=".$val.";";
1483  }
1484  print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1485  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1486 }
1487 
1488 $moreforfilter = '';
1489 
1490 // If the user can view prospects? sales other than his own
1491 if ($user->hasRight("user", "user", "lire")) {
1492  $langs->load("commercial");
1493  $moreforfilter .= '<div class="divsearchfield">';
1494  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1495  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1496  $moreforfilter .= '</div>';
1497 }
1498 // If the user can view other users
1499 if ($user->hasRight("user", "user", "lire")) {
1500  $moreforfilter .= '<div class="divsearchfield">';
1501  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1502  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1503  $moreforfilter .= '</div>';
1504 }
1505 
1506 // If the user can view other products/services than his own
1507 if (isModEnabled('category') && $user->hasRight("categorie", "lire") && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
1508  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1509  $moreforfilter .= '<div class="divsearchfield">';
1510  $tmptitle = $langs->trans('IncludingProductWithTag');
1511  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1512  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
1513  $moreforfilter .= '</div>';
1514 }
1515 // If Categories are enabled & user has rights to see
1516 if (isModEnabled('category') && $user->hasRight("categorie", "lire")) {
1517  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1518  $moreforfilter .= '<div class="divsearchfield">';
1519  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1520  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
1521  $moreforfilter .= '</div>';
1522 }
1523 // If Stock is enabled
1524 if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1525  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1526  $formproduct = new FormProduct($db);
1527  $moreforfilter .= '<div class="divsearchfield">';
1528  $tmptitle = $langs->trans('Warehouse');
1529  $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
1530  $moreforfilter .= '</div>';
1531 }
1532 $parameters = array();
1533 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1534 if (empty($reshook)) {
1535  $moreforfilter .= $hookmanager->resPrint;
1536 } else {
1537  $moreforfilter = $hookmanager->resPrint;
1538 }
1539 
1540 if (!empty($moreforfilter)) {
1541  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1542  print $moreforfilter;
1543  print '</div>';
1544 }
1545 
1546 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1547 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1548 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1549 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1550 
1551 if (GETPOSTINT('autoselectall')) {
1552  $selectedfields .= '<script>';
1553  $selectedfields .= ' $(document).ready(function() {';
1554  $selectedfields .= ' console.log("Autoclick on checkforselects");';
1555  $selectedfields .= ' $("#checkforselects").click();';
1556  $selectedfields .= ' $("#massaction").val("createbills").change();';
1557  $selectedfields .= ' });';
1558  $selectedfields .= '</script>';
1559 }
1560 
1561 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1562 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1563 
1564 // Fields title search
1565 // --------------------------------------------------------------------
1566 print '<tr class="liste_titre_filter">';
1567 // Action column
1568 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1569  print '<td class="liste_titre center maxwidthsearch">';
1570  $searchpicto = $form->showFilterButtons('left');
1571  print $searchpicto;
1572  print '</td>';
1573 }
1574 
1575 // Line numbering
1576 if (!empty($arrayfields['c.rowid']['checked'])) {
1577  print '<td class="liste_titre">';
1578  print '<input class="flat" size="6" type="text" name="search_id" value="'.dol_escape_htmltag($search_id).'">';
1579  print '</td>';
1580 }
1581 
1582 // Ref
1583 if (!empty($arrayfields['c.ref']['checked'])) {
1584  print '<td class="liste_titre">';
1585  print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1586  print '</td>';
1587 }
1588 // Ref customer
1589 if (!empty($arrayfields['c.ref_client']['checked'])) {
1590  print '<td class="liste_titre" align="left">';
1591  print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
1592  print '</td>';
1593 }
1594 // Project ref
1595 if (!empty($arrayfields['p.ref']['checked'])) {
1596  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
1597 }
1598 // Project title
1599 if (!empty($arrayfields['p.title']['checked'])) {
1600  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1601 }
1602 // Thirpdarty
1603 if (!empty($arrayfields['s.nom']['checked'])) {
1604  print '<td class="liste_titre" align="left">';
1605  print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
1606  print '</td>';
1607 }
1608 // Alias
1609 if (!empty($arrayfields['s.name_alias']['checked'])) {
1610  print '<td class="liste_titre" align="left">';
1611  print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
1612  print '</td>';
1613 }
1614 // Parent company
1615 if (!empty($arrayfields['s2.nom']['checked'])) {
1616  print '<td class="liste_titre">';
1617  print '<input class="flat maxwidth100" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
1618  print '</td>';
1619 }
1620 // Town
1621 if (!empty($arrayfields['s.town']['checked'])) {
1622  print '<td class="liste_titre"><input class="flat width50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1623 }
1624 // Zip
1625 if (!empty($arrayfields['s.zip']['checked'])) {
1626  print '<td class="liste_titre"><input class="flat width50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1627 }
1628 // State
1629 if (!empty($arrayfields['state.nom']['checked'])) {
1630  print '<td class="liste_titre">';
1631  print '<input class="flat width50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1632  print '</td>';
1633 }
1634 // Country
1635 if (!empty($arrayfields['country.code_iso']['checked'])) {
1636  print '<td class="liste_titre" align="center">';
1637  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1638  print '</td>';
1639 }
1640 // Company type
1641 if (!empty($arrayfields['typent.code']['checked'])) {
1642  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1643  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
1644  print '</td>';
1645 }
1646 // Date order
1647 if (!empty($arrayfields['c.date_commande']['checked'])) {
1648  print '<td class="liste_titre center">';
1649  print '<div class="nowrapfordate">';
1650  print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1651  print '</div>';
1652  print '<div class="nowrapfordate">';
1653  print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1654  print '</div>';
1655  print '</td>';
1656 }
1657 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1658  print '<td class="liste_titre center">';
1659  print '<div class="nowrapfordate">';
1660  print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1661  print '</div>';
1662  print '<div class="nowrapfordate">';
1663  print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1664  print '</div>';
1665  print '</td>';
1666 }
1667 // Shipping Method
1668 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1669  print '<td class="liste_titre">';
1670  $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1671  print '</td>';
1672 }
1673 // Payment term
1674 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1675  print '<td class="liste_titre">';
1676  print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
1677  print '</td>';
1678 }
1679 // Payment mode
1680 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1681  print '<td class="liste_titre">';
1682  print $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1, '', 1);
1683  print '</td>';
1684 }
1685 // Channel
1686 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1687  print '<td class="liste_titre">';
1688  $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
1689  print '</td>';
1690 }
1691 // Amount HT / net
1692 if (!empty($arrayfields['c.total_ht']['checked'])) {
1693  print '<td class="liste_titre right">';
1694  print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
1695  print '</td>';
1696 }
1697 // Amount of VAT
1698 if (!empty($arrayfields['c.total_vat']['checked'])) {
1699  print '<td class="liste_titre right">';
1700  print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
1701  print '</td>';
1702 }
1703 // Total Amount (TTC / gross)
1704 if (!empty($arrayfields['c.total_ttc']['checked'])) {
1705  print '<td class="liste_titre right">';
1706  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1707  print '</td>';
1708 }
1709 // Currency
1710 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1711  print '<td class="liste_titre">';
1712  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1713  print '</td>';
1714 }
1715 // Currency rate
1716 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1717  print '<td class="liste_titre">';
1718  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1719  print '</td>';
1720 }
1721 // Amount HT/net in foreign currency
1722 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1723  print '<td class="liste_titre right">';
1724  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1725  print '</td>';
1726 }
1727 // VAT in foreign currency
1728 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1729  print '<td class="liste_titre right">';
1730  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1731  print '</td>';
1732 }
1733 // Amount/Total (TTC / gross) in foreign currency
1734 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1735  print '<td class="liste_titre right">';
1736  print '<input class="flat width75" type="text" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1737  print '</td>';
1738 }
1739 // Author
1740 if (!empty($arrayfields['u.login']['checked'])) {
1741  print '<td class="liste_titre">';
1742  print '<input class="flat width75" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1743  print '</td>';
1744 }
1745 // Sales Representative
1746 if (!empty($arrayfields['sale_representative']['checked'])) {
1747  print '<td class="liste_titre"></td>';
1748 }
1749 if (!empty($arrayfields['total_pa']['checked'])) {
1750  print '<td class="liste_titre right">';
1751  print '</td>';
1752 }
1753 if (!empty($arrayfields['total_margin']['checked'])) {
1754  print '<td class="liste_titre right">';
1755  print '</td>';
1756 }
1757 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1758  print '<td class="liste_titre right">';
1759  print '</td>';
1760 }
1761 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1762  print '<td class="liste_titre right">';
1763  print '</td>';
1764 }
1765 
1766 // Date creation
1767 if (!empty($arrayfields['c.datec']['checked'])) {
1768  print '<td class="liste_titre">';
1769  print '</td>';
1770 }
1771 // Date modification
1772 if (!empty($arrayfields['c.tms']['checked'])) {
1773  print '<td class="liste_titre">';
1774  print '</td>';
1775 }
1776 // Date cloture
1777 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1778  print '<td class="liste_titre center">';
1779  print '<div class="nowrapfordate">';
1780  print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1781  print '</div>';
1782  print '<div class="nowrapfordate">';
1783  print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1784  print '</div>';
1785  print '</td>';
1786 }
1787 // Note public
1788 if (!empty($arrayfields['c.note_public']['checked'])) {
1789  print '<td class="liste_titre">';
1790  print '</td>';
1791 }
1792 // Note private
1793 if (!empty($arrayfields['c.note_private']['checked'])) {
1794  print '<td class="liste_titre">';
1795  print '</td>';
1796 }
1797 // Shippable
1798 if (!empty($arrayfields['shippable']['checked'])) {
1799  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1800  //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
1801  if (getDolGlobalString('ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT')) {
1802  print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
1803  print $langs->trans('ShowShippableStatus');
1804  } else {
1805  $show_shippable_command = 1;
1806  }
1807  print '</td>';
1808 }
1809 
1810 // Extra fields
1811 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1812 
1813 // Fields from hook
1814 $parameters = array('arrayfields' => $arrayfields);
1815 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1816 print $hookmanager->resPrint;
1817 
1818 // Status billed
1819 if (!empty($arrayfields['c.facture']['checked'])) {
1820  print '<td class="liste_titre maxwidthonsmartphone center">';
1821  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
1822  print '</td>';
1823 }
1824 
1825 // Import key
1826 if (!empty($arrayfields['c.import_key']['checked'])) {
1827  print '<td class="liste_titre maxwidthonsmartphone center">';
1828  print '</td>';
1829 }
1830 
1831 // Status
1832 if (!empty($arrayfields['c.fk_statut']['checked'])) {
1833  print '<td class="liste_titre center parentonrightofpage">';
1834  $liststatus = array(
1835  Commande::STATUS_DRAFT => $langs->trans("StatusOrderDraftShort"),
1836  Commande::STATUS_VALIDATED => $langs->trans("StatusOrderValidated"),
1837  Commande::STATUS_SHIPMENTONPROCESS => $langs->trans("StatusOrderSentShort"),
1838  -2 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
1839  -3 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
1840  Commande::STATUS_CLOSED => $langs->trans("StatusOrderDelivered"),
1841  Commande::STATUS_CANCELED => $langs->trans("StatusOrderCanceledShort")
1842  );
1843  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1844  print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);
1845  print '</td>';
1846 }
1847 // Action column
1848 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1849  print '<td class="liste_titre center maxwidthsearch">';
1850  $searchpicto = $form->showFilterButtons();
1851  print $searchpicto;
1852  print '</td>';
1853 }
1854 print '</tr>'."\n";
1855 
1856 $totalarray = array(
1857  'nbfield' => 0,
1858  'val' => array(
1859  'c.total_ht' => 0,
1860  'c.total_tva' => 0,
1861  'c.total_ttc' => 0,
1862  ),
1863  'pos' => array(),
1864 );
1865 
1866 
1867 // Fields title label
1868 // --------------------------------------------------------------------
1869 print '<tr class="liste_titre">';
1870 
1871 // Action column
1872 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1873  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1874  $totalarray['nbfield']++;
1875 }
1876 if (!empty($arrayfields['c.rowid']['checked'])) {
1877  print_liste_field_titre($arrayfields['c.rowid']['label'], $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1878  $totalarray['nbfield']++;
1879 }
1880 if (!empty($arrayfields['c.ref']['checked'])) {
1881  print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
1882  $totalarray['nbfield']++;
1883 }
1884 if (!empty($arrayfields['c.ref_client']['checked'])) {
1885  print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
1886  $totalarray['nbfield']++;
1887 }
1888 if (!empty($arrayfields['p.ref']['checked'])) {
1889  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1890  $totalarray['nbfield']++;
1891 }
1892 if (!empty($arrayfields['p.title']['checked'])) {
1893  print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
1894  $totalarray['nbfield']++;
1895 }
1896 if (!empty($arrayfields['s.nom']['checked'])) {
1897  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1898  $totalarray['nbfield']++;
1899 }
1900 if (!empty($arrayfields['s.name_alias']['checked'])) {
1901  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1902  $totalarray['nbfield']++;
1903 }
1904 if (!empty($arrayfields['s2.nom']['checked'])) {
1905  print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER['PHP_SELF'], 's2.nom', '', $param, '', $sortfield, $sortorder);
1906  $totalarray['nbfield']++;
1907 }
1908 if (!empty($arrayfields['s.town']['checked'])) {
1909  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1910  $totalarray['nbfield']++;
1911 }
1912 if (!empty($arrayfields['s.zip']['checked'])) {
1913  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1914  $totalarray['nbfield']++;
1915 }
1916 if (!empty($arrayfields['state.nom']['checked'])) {
1917  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1918  $totalarray['nbfield']++;
1919 }
1920 if (!empty($arrayfields['country.code_iso']['checked'])) {
1921  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1922  $totalarray['nbfield']++;
1923 }
1924 if (!empty($arrayfields['typent.code']['checked'])) {
1925  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1926  $totalarray['nbfield']++;
1927 }
1928 if (!empty($arrayfields['c.date_commande']['checked'])) {
1929  print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
1930  $totalarray['nbfield']++;
1931 }
1932 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1933  print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1934  $totalarray['nbfield']++;
1935 }
1936 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1937  print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1938  $totalarray['nbfield']++;
1939 }
1940 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1941  print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1942  $totalarray['nbfield']++;
1943 }
1944 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1945  print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1946  $totalarray['nbfield']++;
1947 }
1948 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1949  print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1950  $totalarray['nbfield']++;
1951 }
1952 if (!empty($arrayfields['c.total_ht']['checked'])) {
1953  print_liste_field_titre($arrayfields['c.total_ht']['label'], $_SERVER["PHP_SELF"], 'c.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1954  $totalarray['nbfield']++;
1955 }
1956 if (!empty($arrayfields['c.total_vat']['checked'])) {
1957  print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'c.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1958  $totalarray['nbfield']++;
1959 }
1960 if (!empty($arrayfields['c.total_ttc']['checked'])) {
1961  print_liste_field_titre($arrayfields['c.total_ttc']['label'], $_SERVER["PHP_SELF"], 'c.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1962  $totalarray['nbfield']++;
1963 }
1964 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1965  print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1966  $totalarray['nbfield']++;
1967 }
1968 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1969  print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1970  $totalarray['nbfield']++;
1971 }
1972 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1973  print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1974  $totalarray['nbfield']++;
1975 }
1976 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1977  print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1978  $totalarray['nbfield']++;
1979 }
1980 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1981  print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1982  $totalarray['nbfield']++;
1983 }
1984 if (!empty($arrayfields['u.login']['checked'])) {
1985  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1986  $totalarray['nbfield']++;
1987 }
1988 if (!empty($arrayfields['sale_representative']['checked'])) {
1989  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1990  $totalarray['nbfield']++;
1991 }
1992 if (!empty($arrayfields['total_pa']['checked'])) {
1993  print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1994  $totalarray['nbfield']++;
1995 }
1996 if (!empty($arrayfields['total_margin']['checked'])) {
1997  print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1998  $totalarray['nbfield']++;
1999 }
2000 if (!empty($arrayfields['total_margin_rate']['checked'])) {
2001  print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2002  $totalarray['nbfield']++;
2003 }
2004 if (!empty($arrayfields['total_mark_rate']['checked'])) {
2005  print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2006  $totalarray['nbfield']++;
2007 }
2008 
2009 if (!empty($arrayfields['c.datec']['checked'])) {
2010  print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2011  $totalarray['nbfield']++;
2012 }
2013 if (!empty($arrayfields['c.tms']['checked'])) {
2014  print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2015  $totalarray['nbfield']++;
2016 }
2017 if (!empty($arrayfields['c.date_cloture']['checked'])) {
2018  print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2019  $totalarray['nbfield']++;
2020 }
2021 if (!empty($arrayfields['c.note_public']['checked'])) {
2022  print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
2023  $totalarray['nbfield']++;
2024 }
2025 if (!empty($arrayfields['c.note_private']['checked'])) {
2026  print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
2027  $totalarray['nbfield']++;
2028 }
2029 if (!empty($arrayfields['shippable']['checked'])) {
2030  print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
2031  $totalarray['nbfield']++;
2032 }
2033 // Extra fields
2034 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
2035 
2036 // Hook fields
2037 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
2038 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2039 print $hookmanager->resPrint;
2040 
2041 if (!empty($arrayfields['c.facture']['checked'])) {
2042  print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
2043  $totalarray['nbfield']++;
2044 }
2045 if (!empty($arrayfields['c.import_key']['checked'])) {
2046  print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
2047  $totalarray['nbfield']++;
2048 }
2049 if (!empty($arrayfields['c.fk_statut']['checked'])) {
2050  print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
2051  $totalarray['nbfield']++;
2052 }
2053 // Action column
2054 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2055  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
2056  $totalarray['nbfield']++;
2057 }
2058 print '</tr>'."\n";
2059 
2060 $total = 0;
2061 $subtotal = 0;
2062 $productstat_cache = array();
2063 $productstat_cachevirtual = array();
2064 $getNomUrl_cache = array();
2065 
2066 $generic_commande = new Commande($db);
2067 $generic_product = new Product($db);
2068 $userstatic = new User($db);
2069 
2070 $with_margin_info = false;
2071 if (isModEnabled('margin') && (
2072  !empty($arrayfields['total_pa']['checked'])
2073  || !empty($arrayfields['total_margin']['checked'])
2074  || !empty($arrayfields['total_margin_rate']['checked'])
2075  || !empty($arrayfields['total_mark_rate']['checked'])
2076 )
2077 ) {
2078  $with_margin_info = true;
2079 }
2080 
2081 $total_ht = 0;
2082 $total_margin = 0;
2083 
2084 // Loop on record
2085 // --------------------------------------------------------------------
2086 $i = 0;
2087 $savnbfield = $totalarray['nbfield'];
2088 $totalarray = array();
2089 $totalarray['nbfield'] = 0;
2090 $imaxinloop = ($limit ? min($num, $limit) : $num);
2091 while ($i < $imaxinloop) {
2092  $obj = $db->fetch_object($resql);
2093  if (empty($obj)) {
2094  break; // Should not happen
2095  }
2096 
2097  $notshippable = 0;
2098  $warning = 0;
2099  $text_info = '';
2100  $text_warning = '';
2101  $nbprod = 0;
2102 
2103  $companystatic->id = $obj->socid;
2104  $companystatic->name = $obj->name;
2105  $companystatic->name_alias = $obj->alias;
2106  $companystatic->client = $obj->client;
2107  $companystatic->fournisseur = $obj->fournisseur;
2108  $companystatic->code_client = $obj->code_client;
2109  $companystatic->email = $obj->email;
2110  $companystatic->phone = $obj->phone;
2111  $companystatic->address = $obj->address;
2112  $companystatic->zip = $obj->zip;
2113  $companystatic->town = $obj->town;
2114  $companystatic->country_code = $obj->country_code;
2115  if (!isset($getNomUrl_cache[$obj->socid])) {
2116  $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2117  }
2118 
2119  $generic_commande->id = $obj->rowid;
2120  $generic_commande->ref = $obj->ref;
2121  $generic_commande->statut = $obj->fk_statut;
2122  $generic_commande->billed = $obj->billed;
2123  $generic_commande->date = $db->jdate($obj->date_commande);
2124  $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
2125  $generic_commande->ref_client = $obj->ref_client;
2126  $generic_commande->total_ht = $obj->total_ht;
2127  $generic_commande->total_tva = $obj->total_tva;
2128  $generic_commande->total_ttc = $obj->total_ttc;
2129  $generic_commande->note_public = $obj->note_public;
2130  $generic_commande->note_private = $obj->note_private;
2131 
2132  $generic_commande->thirdparty = $companystatic;
2133 
2134 
2135  $projectstatic->id = $obj->project_id;
2136  $projectstatic->ref = $obj->project_ref;
2137  $projectstatic->title = $obj->project_label;
2138 
2139  $marginInfo = array();
2140  if ($with_margin_info === true) {
2141  $generic_commande->fetch_lines();
2142  $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
2143  $total_ht += $obj->total_ht;
2144  $total_margin += $marginInfo['total_margin'];
2145  }
2146 
2147  if ($mode == 'kanban') {
2148  if ($i == 0) {
2149  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
2150  print '<div class="box-flex-container kanban">';
2151  }
2152 
2153  // Output Kanban
2154  $selected = -1;
2155  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2156  $selected = 0;
2157  if (in_array($object->id, $arrayofselected)) {
2158  $selected = 1;
2159  }
2160  }
2161  print $generic_commande->getKanbanView('', array('selected' => $selected));
2162  if ($i == ($imaxinloop - 1)) {
2163  print '</div>';
2164  print '</td></tr>';
2165  }
2166  } else {
2167  // Show line of result
2168  $j = 0;
2169  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
2170 
2171  // Action column
2172  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2173  print '<td class="nowrap center">';
2174  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2175  $selected = 0;
2176  if (in_array($obj->rowid, $arrayofselected)) {
2177  $selected = 1;
2178  }
2179  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2180  }
2181  print '</td>';
2182  if (!$i) {
2183  $totalarray['nbfield']++;
2184  }
2185  }
2186 
2187  // Technical ID
2188  if (!empty($arrayfields['c.rowid']['checked'])) {
2189  print '<td class="center" data-key="id">'.$obj->rowid.'</td>';
2190  if (!$i) {
2191  $totalarray['nbfield']++;
2192  }
2193  }
2194 
2195  // Ref
2196  if (!empty($arrayfields['c.ref']['checked'])) {
2197  print '<td class="nowraponall">';
2198  print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
2199 
2200  $filename = dol_sanitizeFileName($obj->ref);
2201  $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
2202  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
2203  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
2204 
2205  print '</td>';
2206  if (!$i) {
2207  $totalarray['nbfield']++;
2208  }
2209  }
2210 
2211  // Ref customer
2212  if (!empty($arrayfields['c.ref_client']['checked'])) {
2213  print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_client).'">';
2214  print dol_escape_htmltag($obj->ref_client);
2215  print '</td>';
2216  if (!$i) {
2217  $totalarray['nbfield']++;
2218  }
2219  }
2220 
2221  // Project ref
2222  if (!empty($arrayfields['p.ref']['checked'])) {
2223  print '<td class="nowrap">';
2224  if ($obj->project_id > 0) {
2225  print $projectstatic->getNomUrl(1);
2226  }
2227  print '</td>';
2228  if (!$i) {
2229  $totalarray['nbfield']++;
2230  }
2231  }
2232 
2233  // Project label
2234  if (!empty($arrayfields['p.title']['checked'])) {
2235  print '<td class="nowrap">';
2236  if ($obj->project_id > 0) {
2237  print $projectstatic->title;
2238  }
2239  print '</td>';
2240  if (!$i) {
2241  $totalarray['nbfield']++;
2242  }
2243  }
2244 
2245  // Third party
2246  if (!empty($arrayfields['s.nom']['checked'])) {
2247  print '<td class="tdoverflowmax150">';
2248  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2249  print $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2250  } else {
2251  print $getNomUrl_cache[$obj->socid];
2252  }
2253 
2254  // If module invoices enabled and user with invoice creation permissions
2255  if (isModEnabled('invoice') && getDolGlobalString('ORDER_BILLING_ALL_CUSTOMER')) {
2256  if ($user->hasRight('facture', 'creer')) {
2257  if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
2258  print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
2259  print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
2260  }
2261  }
2262  }
2263  print '</td>';
2264  if (!$i) {
2265  $totalarray['nbfield']++;
2266  }
2267  }
2268 
2269  // Alias name
2270  if (!empty($arrayfields['s.name_alias']['checked'])) {
2271  print '<td class="nocellnopadd">';
2272  print $obj->alias;
2273  print '</td>';
2274  if (!$i) {
2275  $totalarray['nbfield']++;
2276  }
2277  }
2278 
2279  // Parent company
2280  if (!empty($arrayfields['s2.nom']['checked'])) {
2281  print '<td class="tdoverflowmax200">';
2282  if ($obj->fk_parent > 0) {
2283  if (!isset($company_url_list[$obj->fk_parent])) {
2284  $companyparent = new Societe($db);
2285  $res = $companyparent->fetch($obj->fk_parent);
2286  if ($res > 0) {
2287  $company_url_list[$obj->fk_parent] = $companyparent->getNomUrl(1);
2288  }
2289  }
2290  if (isset($company_url_list[$obj->fk_parent])) {
2291  print $company_url_list[$obj->fk_parent];
2292  }
2293  }
2294  print "</td>";
2295  if (!$i) {
2296  $totalarray['nbfield']++;
2297  }
2298  }
2299 
2300  // Town
2301  if (!empty($arrayfields['s.town']['checked'])) {
2302  print '<td class="nocellnopadd">';
2303  print $obj->town;
2304  print '</td>';
2305  if (!$i) {
2306  $totalarray['nbfield']++;
2307  }
2308  }
2309 
2310  // Zip
2311  if (!empty($arrayfields['s.zip']['checked'])) {
2312  print '<td class="nocellnopadd">';
2313  print $obj->zip;
2314  print '</td>';
2315  if (!$i) {
2316  $totalarray['nbfield']++;
2317  }
2318  }
2319 
2320  // State
2321  if (!empty($arrayfields['state.nom']['checked'])) {
2322  print "<td>".$obj->state_name."</td>\n";
2323  if (!$i) {
2324  $totalarray['nbfield']++;
2325  }
2326  }
2327 
2328  // Country
2329  if (!empty($arrayfields['country.code_iso']['checked'])) {
2330  print '<td class="center">';
2331  $tmparray = getCountry($obj->fk_pays, 'all');
2332  print $tmparray['label'];
2333  print '</td>';
2334  if (!$i) {
2335  $totalarray['nbfield']++;
2336  }
2337  }
2338 
2339  // Type ent
2340  if (!empty($arrayfields['typent.code']['checked'])) {
2341  print '<td class="center">';
2342  if (empty($typenArray)) {
2343  $typenArray = $formcompany->typent_array(1);
2344  }
2345  print $typenArray[$obj->typent_code];
2346  print '</td>';
2347  if (!$i) {
2348  $totalarray['nbfield']++;
2349  }
2350  }
2351 
2352  // Order date
2353  if (!empty($arrayfields['c.date_commande']['checked'])) {
2354  print '<td class="center nowraponall">';
2355  print dol_print_date($db->jdate($obj->date_commande), 'day');
2356  // Warning late icon and note
2357  if ($generic_commande->hasDelay()) {
2358  print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
2359  }
2360  print '</td>';
2361  if (!$i) {
2362  $totalarray['nbfield']++;
2363  }
2364  }
2365 
2366  // Plannned date of delivery
2367  if (!empty($arrayfields['c.date_delivery']['checked'])) {
2368  print '<td class="center nowraponall">';
2369  print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
2370  print '</td>';
2371  if (!$i) {
2372  $totalarray['nbfield']++;
2373  }
2374  }
2375 
2376  // Shipping Method
2377  if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
2378  print '<td>';
2379  $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
2380  print '</td>';
2381  if (!$i) {
2382  $totalarray['nbfield']++;
2383  }
2384  }
2385 
2386  // Payment terms
2387  if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
2388  print '<td>';
2389  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
2390  print '</td>';
2391  if (!$i) {
2392  $totalarray['nbfield']++;
2393  }
2394  }
2395 
2396  // Payment mode
2397  if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
2398  print '<td>';
2399  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
2400  print '</td>';
2401  if (!$i) {
2402  $totalarray['nbfield']++;
2403  }
2404  }
2405 
2406  // Channel
2407  if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
2408  print '<td>';
2409  $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', '');
2410  print '</td>';
2411  if (!$i) {
2412  $totalarray['nbfield']++;
2413  }
2414  }
2415 
2416  // Amount HT/net
2417  if (!empty($arrayfields['c.total_ht']['checked'])) {
2418  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
2419  if (!$i) {
2420  $totalarray['nbfield']++;
2421  }
2422  if (!$i) {
2423  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ht';
2424  }
2425  if (isset($totalarray['val']['c.total_ht'])) {
2426  $totalarray['val']['c.total_ht'] += $obj->total_ht;
2427  } else {
2428  $totalarray['val']['c.total_ht'] = $obj->total_ht;
2429  }
2430  }
2431 
2432  // Amount VAT
2433  if (!empty($arrayfields['c.total_vat']['checked'])) {
2434  print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
2435  if (!$i) {
2436  $totalarray['nbfield']++;
2437  }
2438  if (!$i) {
2439  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_tva';
2440  }
2441  if (isset($totalarray['val']['c.total_tva'])) {
2442  $totalarray['val']['c.total_tva'] += $obj->total_tva;
2443  } else {
2444  $totalarray['val']['c.total_tva'] = $obj->total_tva;
2445  }
2446  }
2447 
2448  // Amount TTC / gross
2449  if (!empty($arrayfields['c.total_ttc']['checked'])) {
2450  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
2451  if (!$i) {
2452  $totalarray['nbfield']++;
2453  }
2454  if (!$i) {
2455  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ttc';
2456  }
2457  if (isset($totalarray['val']['c.total_ttc'])) {
2458  $totalarray['val']['c.total_ttc'] += $obj->total_ttc;
2459  } else {
2460  $totalarray['val']['c.total_ttc'] = $obj->total_ttc;
2461  }
2462  }
2463 
2464  // Currency
2465  if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
2466  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
2467  if (!$i) {
2468  $totalarray['nbfield']++;
2469  }
2470  }
2471 
2472  // Currency rate
2473  if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
2474  print '<td class="nowrap">';
2475  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2476  print "</td>\n";
2477  if (!$i) {
2478  $totalarray['nbfield']++;
2479  }
2480  }
2481 
2482  // Amount HT/net in foreign currency
2483  if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
2484  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
2485  if (!$i) {
2486  $totalarray['nbfield']++;
2487  }
2488  }
2489  // Amount VAT in foreign currency
2490  if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
2491  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
2492  if (!$i) {
2493  $totalarray['nbfield']++;
2494  }
2495  }
2496  // Amount TTC / gross in foreign currency
2497  if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
2498  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2499  if (!$i) {
2500  $totalarray['nbfield']++;
2501  }
2502  }
2503 
2504  $userstatic->id = $obj->fk_user_author;
2505  $userstatic->login = $obj->login;
2506  $userstatic->lastname = $obj->lastname;
2507  $userstatic->firstname = $obj->firstname;
2508  $userstatic->email = $obj->user_email;
2509  $userstatic->status = $obj->user_statut;
2510  $userstatic->entity = $obj->entity;
2511  $userstatic->photo = $obj->photo;
2512  $userstatic->office_phone = $obj->office_phone;
2513  $userstatic->office_fax = $obj->office_fax;
2514  $userstatic->user_mobile = $obj->user_mobile;
2515  $userstatic->job = $obj->job;
2516  $userstatic->gender = $obj->gender;
2517 
2518  // Author
2519  if (!empty($arrayfields['u.login']['checked'])) {
2520  print '<td class="tdoverflowmax150">';
2521  if ($userstatic->id) {
2522  print $userstatic->getNomUrl(-1);
2523  } else {
2524  print '&nbsp;';
2525  }
2526  print "</td>\n";
2527  if (!$i) {
2528  $totalarray['nbfield']++;
2529  }
2530  }
2531 
2532  // Sales representatives
2533  if (!empty($arrayfields['sale_representative']['checked'])) {
2534  print '<td>';
2535  if ($obj->socid > 0) {
2536  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
2537  if ($listsalesrepresentatives < 0) {
2538  dol_print_error($db);
2539  }
2540  $nbofsalesrepresentative = count($listsalesrepresentatives);
2541  if ($nbofsalesrepresentative > 6) {
2542  // We print only number
2543  print $nbofsalesrepresentative;
2544  } elseif ($nbofsalesrepresentative > 0) {
2545  $j = 0;
2546  foreach ($listsalesrepresentatives as $val) {
2547  $userstatic->id = $val['id'];
2548  $userstatic->lastname = $val['lastname'];
2549  $userstatic->firstname = $val['firstname'];
2550  $userstatic->email = $val['email'];
2551  $userstatic->status = $val['statut'];
2552  $userstatic->entity = $val['entity'];
2553  $userstatic->photo = $val['photo'];
2554  $userstatic->login = $val['login'];
2555  $userstatic->office_phone = $val['office_phone'];
2556  $userstatic->office_fax = $val['office_fax'];
2557  $userstatic->user_mobile = $val['user_mobile'];
2558  $userstatic->job = $val['job'];
2559  $userstatic->gender = $val['gender'];
2560  //print '<div class="float">':
2561  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2562  $j++;
2563  if ($j < $nbofsalesrepresentative) {
2564  print ' ';
2565  }
2566  //print '</div>';
2567  }
2568  }
2569  //else print $langs->trans("NoSalesRepresentativeAffected");
2570  } else {
2571  print '&nbsp;';
2572  }
2573  print '</td>';
2574  if (!$i) {
2575  $totalarray['nbfield']++;
2576  }
2577  }
2578 
2579  // Total buying or cost price
2580  if (!empty($arrayfields['total_pa']['checked'])) {
2581  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2582  if (!$i) {
2583  $totalarray['nbfield']++;
2584  }
2585  }
2586 
2587  // Total margin
2588  if (!empty($arrayfields['total_margin']['checked'])) {
2589  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2590  if (!$i) {
2591  $totalarray['nbfield']++;
2592  }
2593  if (!$i) {
2594  $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2595  }
2596  $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
2597  }
2598 
2599  // Total margin rate
2600  if (!empty($arrayfields['total_margin_rate']['checked'])) {
2601  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], 0, '', 0, 0, 2).'%').'</td>';
2602  if (!$i) {
2603  $totalarray['nbfield']++;
2604  }
2605  }
2606 
2607  // Total mark rate
2608  if (!empty($arrayfields['total_mark_rate']['checked'])) {
2609  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], 0, '', 0, 0, 2).'%').'</td>';
2610  if (!$i) {
2611  $totalarray['nbfield']++;
2612  }
2613  if (!$i) {
2614  $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2615  }
2616  if ($i >= $imaxinloop - 1) {
2617  if (!empty($total_ht)) {
2618  $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2619  } else {
2620  $totalarray['val']['total_mark_rate'] = '';
2621  }
2622  }
2623  }
2624 
2625  // Date creation
2626  if (!empty($arrayfields['c.datec']['checked'])) {
2627  print '<td align="center" class="nowrap">';
2628  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2629  print '</td>';
2630  if (!$i) {
2631  $totalarray['nbfield']++;
2632  }
2633  }
2634 
2635  // Date modification
2636  if (!empty($arrayfields['c.tms']['checked'])) {
2637  print '<td align="center" class="nowrap">';
2638  print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2639  print '</td>';
2640  if (!$i) {
2641  $totalarray['nbfield']++;
2642  }
2643  }
2644 
2645  // Date cloture
2646  if (!empty($arrayfields['c.date_cloture']['checked'])) {
2647  print '<td align="center" class="nowrap">';
2648  print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
2649  print '</td>';
2650  if (!$i) {
2651  $totalarray['nbfield']++;
2652  }
2653  }
2654 
2655  // Note public
2656  if (!empty($arrayfields['c.note_public']['checked'])) {
2657  print '<td class="sensiblehtmlcontent center">';
2658  print dolPrintHTML($obj->note_public);
2659  print '</td>';
2660  if (!$i) {
2661  $totalarray['nbfield']++;
2662  }
2663  }
2664 
2665  // Note private
2666  if (!empty($arrayfields['c.note_private']['checked'])) {
2667  print '<td class="sensiblehtmlcontent center">';
2668  print dolPrintHTML($obj->note_private);
2669  print '</td>';
2670  if (!$i) {
2671  $totalarray['nbfield']++;
2672  }
2673  }
2674 
2675  // Show shippable Icon (this creates subloops, so may be slow)
2676  if (!empty($arrayfields['shippable']['checked'])) {
2677  print '<td class="center">';
2678  if (!empty($show_shippable_command) && isModEnabled('stock')) {
2679  if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
2680  $generic_commande->getLinesArray(); // Load array ->lines
2681  $generic_commande->loadExpeditions(); // Load array ->expeditions
2682 
2683  $numlines = count($generic_commande->lines); // Loop on each line of order
2684  for ($lig = 0; $lig < $numlines; $lig++) {
2685  if (isset($generic_commande->expeditions[$generic_commande->lines[$lig]->id])) {
2686  $reliquat = $generic_commande->lines[$lig]->qty - $generic_commande->expeditions[$generic_commande->lines[$lig]->id];
2687  } else {
2688  $reliquat = $generic_commande->lines[$lig]->qty;
2689  }
2690  if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) { // If line is a product and not a service
2691  $nbprod++; // order contains real products
2692  $generic_product->id = $generic_commande->lines[$lig]->fk_product;
2693 
2694  // Get local and virtual stock and store it into cache
2695  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
2696  $generic_product->load_stock('nobatch,warehouseopen'); // ->load_virtual_stock() is already included into load_stock()
2697  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
2698  $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2699  } else {
2700  $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
2701  $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2702  }
2703 
2704  if ($reliquat > $generic_product->stock_reel) {
2705  $notshippable++;
2706  }
2707  if (!getDolGlobalString('SHIPPABLE_ORDER_ICON_IN_LIST')) { // Default code. Default should be this case.
2708  $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->product_ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
2709  $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
2710  $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
2711  $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
2712  $text_info .= '<br>';
2713  } else { // BUGGED CODE.
2714  // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
2715  // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
2716  // Detailed virtual stock, looks bugged, incomplete and need heavy load.
2717  // stock order and stock order_supplier
2718  $stock_order = 0;
2719  $stock_order_supplier = 0;
2720  if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { // What about other options ?
2721  if (isModEnabled('order')) {
2722  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
2723  $generic_product->load_stats_commande(0, '1,2');
2724  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
2725  } else {
2726  $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
2727  }
2728  $stock_order = $generic_product->stats_commande['qty'];
2729  }
2730  if (isModEnabled("supplier_order")) {
2731  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
2732  $generic_product->load_stats_commande_fournisseur(0, '3');
2733  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
2734  } else {
2735  $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
2736  }
2737  $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
2738  }
2739  }
2740  $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
2741  $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
2742  if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
2743  $warning++;
2744  $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2745  }
2746  if ($reliquat > $generic_product->stock_reel) {
2747  $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2748  } else {
2749  $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2750  }
2751  if (isModEnabled("supplier_order")) {
2752  $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
2753  }
2754  $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
2755  $text_info .= '<br>';
2756  }
2757  }
2758  }
2759  if ($notshippable == 0) {
2760  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
2761  $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
2762  } else {
2763  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
2764  $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
2765  }
2766  }
2767 
2768  if ($nbprod) {
2769  print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
2770  }
2771  if ($warning) { // Always false in default mode
2772  print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
2773  }
2774  }
2775  print '</td>';
2776  if (!$i) {
2777  $totalarray['nbfield']++;
2778  }
2779  }
2780 
2781  // Extra fields
2782  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2783  // Fields from hook
2784  $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2785  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2786  print $hookmanager->resPrint;
2787 
2788  // Billed
2789  if (!empty($arrayfields['c.facture']['checked'])) {
2790  print '<td class="center">';
2791  if ($obj->billed) {
2792  print yn($obj->billed, 4);
2793  }
2794  print '</td>';
2795  if (!$i) {
2796  $totalarray['nbfield']++;
2797  }
2798  }
2799 
2800  // Import key
2801  if (!empty($arrayfields['c.import_key']['checked'])) {
2802  print '<td class="nowrap center">'.dol_escape_htmltag($obj->import_key).'</td>';
2803  if (!$i) {
2804  $totalarray['nbfield']++;
2805  }
2806  }
2807 
2808  // Status
2809  if (!empty($arrayfields['c.fk_statut']['checked'])) {
2810  print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
2811  if (!$i) {
2812  $totalarray['nbfield']++;
2813  }
2814  }
2815 
2816  // Action column
2817  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2818  print '<td class="nowrap center">';
2819  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2820  $selected = 0;
2821  if (in_array($obj->rowid, $arrayofselected)) {
2822  $selected = 1;
2823  }
2824  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2825  }
2826  print '</td>';
2827  if (!$i) {
2828  $totalarray['nbfield']++;
2829  }
2830  }
2831 
2832  print "</tr>\n";
2833 
2834  $total += $obj->total_ht;
2835  $subtotal += $obj->total_ht;
2836  }
2837  $i++;
2838 }
2839 
2840 // Show total line
2841 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2842 
2843 // If no record found
2844 if ($num == 0) {
2845  $colspan = 1;
2846  foreach ($arrayfields as $key => $val) {
2847  if (!empty($val['checked'])) {
2848  $colspan++;
2849  }
2850  }
2851  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2852 }
2853 
2854 $db->free($resql);
2855 
2856 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2857 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2858 print $hookmanager->resPrint;
2859 
2860 print '</table>'."\n";
2861 print '</div>'."\n";
2862 
2863 print '</form>'."\n";
2864 
2865 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2866  $hidegeneratedfilelistifempty = 1;
2867  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2868  $hidegeneratedfilelistifempty = 0;
2869  }
2870 
2871  // Show list of available documents
2872  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2873  $urlsource .= str_replace('&amp;', '&', $param);
2874 
2875  $filedir = $diroutputmassaction;
2876  $genallowed = $permissiontoread;
2877  $delallowed = $permissiontoadd;
2878 
2879  print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2880 }
2881 
2882 // End of page
2883 llxFooter();
2884 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage invoices.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class permettant la generation de composants html autre Only common components are here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:50
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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...
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=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.