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