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