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