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