dolibarr 18.0.6
list_det.php
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-2021 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
14 * Copyright (C) 2021-2022 Anthony Berton <anthony.berton@bb2a.fr>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43if (isModEnabled('margin')) {
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
45}
46require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
47require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
48require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
49require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
50
51// Load translation files required by the page
52$langs->loadLangs(array("orders", 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products'));
53
54$action = GETPOST('action', 'aZ09');
55$massaction = GETPOST('massaction', 'alpha');
56$show_files = GETPOST('show_files', 'int');
57$confirm = GETPOST('confirm', 'alpha');
58$toselect = GETPOST('toselect', 'array');
59$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'orderlistdet';
60$productobuy = GETPOST('productobuy', 'alpha');
61$productonly = GETPOST('productonly', 'alpha');
62$disablelinefree = GETPOST('disablelinefree', 'alpha');
63
64$search_datecloture_start = GETPOST('search_datecloture_start', 'int');
65if (empty($search_datecloture_start)) {
66 $search_datecloture_start = dol_mktime(0, 0, 0, GETPOST('search_datecloture_startmonth', 'int'), GETPOST('search_datecloture_startday', 'int'), GETPOST('search_datecloture_startyear', 'int'));
67}
68$search_datecloture_end = GETPOST('search_datecloture_end', 'int');
69if (empty($search_datecloture_end)) {
70 $search_datecloture_end = dol_mktime(23, 59, 59, GETPOST('search_datecloture_endmonth', 'int'), GETPOST('search_datecloture_endday', 'int'), GETPOST('search_datecloture_endyear', 'int'));
71}
72$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'));
73$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'));
74$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'));
75$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'));
76$search_product_category = GETPOST('search_product_category', 'int');
77
78// Détail commande
79$search_refProduct = GETPOST('search_refProduct', 'alpha');
80$search_descProduct = GETPOST('search_descProduct', 'alpha');
81
82$search_ref = GETPOST('search_ref', 'alpha') != '' ?GETPOST('search_ref', 'alpha') : GETPOST('sref', 'alpha');
83$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
84$search_company = GETPOST('search_company', 'alpha');
85$search_company_alias = GETPOST('search_company_alias', 'alpha');
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$search_total_ht = GETPOST('search_total_ht', 'alpha');
96$search_total_vat = GETPOST('search_total_vat', 'alpha');
97$search_total_ttc = GETPOST('search_total_ttc', 'alpha');
98$search_warehouse = GETPOST('search_warehouse', 'int');
99$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
100$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
101$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
102$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
103$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
104$search_login = GETPOST('search_login', 'alpha');
105$search_categ_cus = GETPOST("search_categ_cus", 'int');
106$optioncss = GETPOST('optioncss', 'alpha');
107$search_billed = GETPOSTISSET('search_billed') ? GETPOST('search_billed', 'int') : GETPOST('billed', 'int');
108$search_status = GETPOST('search_status', 'int');
109$search_btn = GETPOST('button_search', 'alpha');
110$search_remove_btn = GETPOST('button_removefilter', 'alpha');
111$search_project_ref = GETPOST('search_project_ref', 'alpha');
112$search_project = GETPOST('search_project', 'alpha');
113$search_shippable = GETPOST('search_shippable', 'aZ09');
114$search_fk_cond_reglement = GETPOST("search_fk_cond_reglement", 'int');
115$search_fk_shipping_method = GETPOST("search_fk_shipping_method", 'int');
116$search_fk_mode_reglement = GETPOST("search_fk_mode_reglement", 'int');
117$search_fk_input_reason = GETPOST("search_fk_input_reason", 'int');
118
119// Security check
120$id = (GETPOST('orderid') ?GETPOST('orderid', 'int') : GETPOST('id', 'int'));
121if ($user->socid) {
122 $socid = $user->socid;
123}
124$result = restrictedArea($user, 'commande', $id, '');
125
126$diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
127
128// Load variable for pagination
129$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
130$sortfield = GETPOST('sortfield', 'aZ09comma');
131$sortorder = GETPOST('sortorder', 'aZ09comma');
132$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
133if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
134 $page = 0;
135} // If $page is not defined, or '' or -1 or if we click on clear filters
136$offset = $limit * $page;
137$pageprev = $page - 1;
138$pagenext = $page + 1;
139if (!$sortfield) {
140 $sortfield = 'pr.ref';
141}
142if (!$sortorder) {
143 $sortorder = 'ASC';
144}
145
146$show_shippable_command = GETPOST('show_shippable_command', 'aZ09');
147
148// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
149$object = new Commande($db);
150$hookmanager->initHooks(array('orderlistdetail'));
151$extrafields = new ExtraFields($db);
152
153// fetch optionals attributes and labels
154$extrafields->fetch_name_optionals_label($object->table_element);
155$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
156
157// List of fields to search into when doing a "search in all"
158$fieldstosearchall = array(
159 'c.ref'=>'Ref',
160 'c.ref_client'=>'RefCustomerOrder',
161 'pd.description'=>'Description',
162 's.nom'=>"ThirdParty",
163 's.name_alias'=>"AliasNameShort",
164 's.zip'=>"Zip",
165 's.town'=>"Town",
166 'c.note_public'=>'NotePublic',
167);
168if (empty($user->socid)) {
169 $fieldstosearchall["c.note_private"] = "NotePrivate";
170}
171
172$checkedtypetiers = 0;
173$arrayfields = array(
174 // Détail commande
175 'pr.ref'=> array('label'=>'ProductRef', 'checked'=>1, 'position'=>1),
176 'pr.desc'=> array('label'=>'ProductDescription', 'checked'=>-1, 'position'=>1),
177 'cdet.qty'=> array('label'=>'QtyOrdered', 'checked'=>1, 'position'=>1),
178 'c.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>5),
179 'c.ref_client'=>array('label'=>"RefCustomerOrder", 'checked'=>-1, 'position'=>10),
180 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>-1, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1), 'position'=>20),
181 'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1), 'position'=>25),
182 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>30),
183 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>-1, 'position'=>31),
184 's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>35),
185 's.zip'=>array('label'=>"Zip", 'checked'=>-1, 'position'=>40),
186 'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>45),
187 'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>50),
188 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>55),
189 'c.date_commande'=>array('label'=>"OrderDateShort", 'checked'=>1, 'position'=>60),
190 'c.date_delivery'=>array('label'=>"DateDeliveryPlanned", 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE), 'position'=>65),
191 'c.fk_shipping_method'=>array('label'=>"SendingMethod", 'checked'=>-1, 'position'=>66 , 'enabled'=>isModEnabled('expedition')),
192 'c.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>-1, 'position'=>67),
193 'c.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>-1, 'position'=>68),
194 'c.fk_input_reason'=>array('label'=>"Channel", 'checked'=>-1, 'position'=>69),
195 'cdet.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>75),
196 'c.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>80),
197 'cdet.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>85),
198 'c.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>90),
199 'c.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>95),
200 'c.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>100),
201 'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105),
202 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110),
203 'c.fk_warehouse'=>array('label'=>'Warehouse', 'checked'=>0, 'enabled'=>(!isModEnabled('stock') && empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER) ? 0 : 1), 'position'=>110),
204 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115),
205 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>116),
206 'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous ? 0 : 1)),
207 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous ? 0 : 1)),
208 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)),
209 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)),
210 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120),
211 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125),
212 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130),
213 'c.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES)), 'position'=>135),
214 'c.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES)), 'position'=>140),
215 'shippable'=>array('label'=>"Shippable", 'checked'=>1,'enabled'=>(isModEnabled('expedition')), 'position'=>990),
216 'c.facture'=>array('label'=>"Billed", 'checked'=>1, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)), 'position'=>995),
217 'c.import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>999),
218 'c.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
219);
220
221// Extra fields
222include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
223
224$object->fields = dol_sort_array($object->fields, 'position');
225$arrayfields = dol_sort_array($arrayfields, 'position');
226
227
228
229/*
230 * Actions
231 */
232
233if (GETPOST('cancel', 'alpha')) {
234 $action = 'list'; $massaction = '';
235}
236if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
237 $massaction = '';
238}
239
240$parameters = array('socid'=>$socid);
241$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
242if ($reshook < 0) {
243 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
244}
245
246if (empty($reshook)) {
247 // Selection of new fields
248 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
249
250 // Purge search criteria
251 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
252 $productobuy = '';
253 $productonly = '';
254 $disablelinefree = '';
255 $search_categ = '';
256 $search_user = '';
257 $search_sale = '';
258 $search_product_category = '';
259 $search_refProduct = '';
260 $search_descProduct = '';
261 $search_ref = '';
262 $search_ref_customer = '';
263 $search_company = '';
264 $search_company_alias = '';
265 $search_town = '';
266 $search_zip = "";
267 $search_state = "";
268 $search_type = '';
269 $search_country = '';
270 $search_type_thirdparty = '';
271 $search_total_ht = '';
272 $search_total_vat = '';
273 $search_total_ttc = '';
274 $search_warehouse = '';
275 $search_multicurrency_code = '';
276 $search_multicurrency_tx = '';
277 $search_multicurrency_montant_ht = '';
278 $search_multicurrency_montant_vat = '';
279 $search_multicurrency_montant_ttc = '';
280 $search_login = '';
281 $search_dateorder_start = '';
282 $search_dateorder_end = '';
283 $search_datedelivery_start = '';
284 $search_datedelivery_end = '';
285 $search_project_ref = '';
286 $search_project = '';
287 $search_status = '';
288 $search_billed = '';
289 $toselect = array();
290 $search_array_options = array();
291 $search_categ_cus = 0;
292 $search_datecloture_start = '';
293 $search_datecloture_end = '';
294 $search_fk_cond_reglement = '';
295 $search_fk_shipping_method = '';
296 $search_fk_mode_reglement = '';
297 $search_fk_input_reason = '';
298 }
299 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
300 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
301 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
302 }
303
304 // Mass actions
305 $objectclass = 'Commande';
306 $objectlabel = 'Orders';
307 $permissiontoread = $user->rights->commande->lire;
308 $permissiontoadd = $user->rights->commande->creer;
309 $permissiontodelete = $user->rights->commande->supprimer;
310 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
311 $permissiontovalidate = $user->rights->commande->order_advance->validate;
312 $permissiontoclose = $user->rights->commande->order_advance->close;
313 $permissiontocancel = $user->rights->commande->order_advance->annuler;
314 $permissiontosendbymail = $user->rights->commande->order_advance->send;
315 } else {
316 $permissiontovalidate = $user->rights->commande->creer;
317 $permissiontoclose = $user->rights->commande->creer;
318 $permissiontocancel = $user->rights->commande->creer;
319 $permissiontosendbymail = $user->rights->commande->creer;
320 }
321 $uploaddir = $conf->commande->multidir_output[$conf->entity];
322 $triggersendname = 'ORDER_SENTBYMAIL';
323 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
324}
325
326// Closed records
327// if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
328
329// }
330
331/*
332 * View
333 */
334
335$now = dol_now();
336
337$form = new Form($db);
338$formother = new FormOther($db);
339$formfile = new FormFile($db);
340$formmargin = null;
341if (isModEnabled('margin')) {
342 $formmargin = new FormMargin($db);
343}
344$companystatic = new Societe($db);
345$formcompany = new FormCompany($db);
346$projectstatic = new Project($db);
347
348$title = $langs->trans("Orders");
349$help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
350// llxHeader('',$title,$help_url);
351
352$sql = 'SELECT';
353if ($sall || $search_product_category > 0 || $search_user > 0) {
354 $sql = 'SELECT DISTINCT';
355}
356$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.code_client,';
357$sql .= " typent.code as typent_code,";
358$sql .= " state.code_departement as state_code, state.nom as state_name,";
359$sql .= " country.code as country_code,";
360$sql .= ' c.rowid as c_rowid, c.ref, c.ref_client, c.fk_user_author,';
361$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,';
362$sql .= ' c.total_ht as c_total_ht, c.total_tva as c_total_tva, c.total_ttc as c_total_ttc, c.fk_warehouse as warehouse,';
363$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,';
364$sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture as date_cloture,';
365$sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
366$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,';
367$sql .= ' c.fk_cond_reglement,c.deposit_percent,c.fk_mode_reglement,c.fk_shipping_method,';
368$sql .= ' c.fk_input_reason, c.import_key';
369
370// Détail commande
371$sql .= ', cdet.rowid, cdet.description, cdet.qty, cdet.product_type, cdet.fk_product, cdet.total_ht, cdet.total_tva, cdet.total_ttc, ';
372$sql .= ' pr.rowid as product_rowid, pr.ref as product_ref, pr.label as product_label, pr.barcode as product_barcode, pr.tobatch as product_batch, pr.tosell as product_status, pr.tobuy as product_status_buy';
373
374if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
375 $sql .= ", cc.fk_categorie, cc.fk_soc";
376}
377// Add fields from extrafields
378if (!empty($extrafields->attributes[$object->table_element]['label'])) {
379 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
380 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
381 }
382}
383// Add fields from hooks
384$parameters = array();
385$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
386$sql .= $hookmanager->resPrint;
387$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
388$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
389$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
390$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
391if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
392 $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
393}
394
395// Détail commande
396$sql .= ', '.MAIN_DB_PREFIX.'commandedet as cdet';
397$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande as c ON cdet.fk_commande=c.rowid';
398$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as pr ON pr.rowid=cdet.fk_product';
399
400if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
401 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
402}
403if ($sall || $search_product_category > 0) {
404 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
405}
406if ($search_product_category > 0) {
407 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
408}
409$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
410$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
411
412// We'll need this table joined to the select in order to filter by sale
413if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
414 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
415}
416if ($search_user > 0) {
417 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
418 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
419}
420
421// Add table from hooks
422$parameters = array();
423$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
424$sql .= $hookmanager->resPrint;
425
426$sql .= ' WHERE c.fk_soc = s.rowid';
427$sql .= ' AND c.entity IN ('.getEntity('commande').')';
428$sql .= ' AND cdet.product_type <> 9';
429
430if (!empty($productobuy)) {
431 $sql .= " AND pr.tobuy = 1";
432}
433if (!empty($productonly)) {
434 $sql .= " AND (cdet.product_type = 0 OR cdet.product_type = 1)";
435}
436if (!empty($disablelinefree)) {
437 $sql .= " AND cdet.fk_product IS NOT NULL";
438}
439if ($search_product_category > 0) {
440 $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
441}
442if ($socid > 0) {
443 $sql .= ' AND s.rowid = '.((int) $socid);
444}
445if (empty($user->rights->societe->client->voir) && !$socid) {
446 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
447}
448if ($search_refProduct) {
449 $sql .= natural_search('pr.ref', $search_refProduct);
450}
451if ($search_descProduct) {
452 $sql .= natural_search('pr.label', $search_descProduct);
453 $sql .= natural_search('cdet.description', $search_descProduct);
454}
455if ($search_ref) {
456 $sql .= natural_search('c.ref', $search_ref);
457}
458if ($search_ref_customer) {
459 $sql .= natural_search('c.ref_client', $search_ref_customer);
460}
461if ($sall) {
462 $sql .= natural_search(array_keys($fieldstosearchall), $sall);
463}
464if ($search_billed != '' && $search_billed >= 0) {
465 $sql .= ' AND c.facture = '.((int) $search_billed);
466}
467if ($search_status <> '') {
468 if ($search_status <= 3 && $search_status >= -1) { // status from -1 to 3 are real status (other are virtual combination)
469 if ($search_status == 1 && !isModEnabled('expedition')) {
470 $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
471 } else {
472 $sql .= ' AND c.fk_statut = '.((int) $search_status); // brouillon, validee, en cours, annulee
473 }
474 }
475 if ($search_status == -2) { // To process
476 //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
477 $sql .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
478 }
479 if ($search_status == -3) { // To bill
480 //$sql.= ' AND c.fk_statut in (1,2,3)';
481 //$sql.= ' AND c.facture = 0'; // invoice not created
482 $sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed
483 }
484 if ($search_status == -4) { // "validate and in progress"
485 $sql .= ' AND (c.fk_statut IN (1,2))'; // validated, in process
486 }
487}
488
489if ($search_datecloture_start) {
490 $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
491}
492if ($search_datecloture_end) {
493 $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
494}
495if ($search_dateorder_start) {
496 $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
497}
498if ($search_dateorder_end) {
499 $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
500}
501if ($search_datedelivery_start) {
502 $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
503}
504if ($search_datedelivery_end) {
505 $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
506}
507if ($search_town) {
508 $sql .= natural_search('s.town', $search_town);
509}
510if ($search_zip) {
511 $sql .= natural_search("s.zip", $search_zip);
512}
513if ($search_state) {
514 $sql .= natural_search("state.nom", $search_state);
515}
516if ($search_country) {
517 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
518}
519if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
520 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
521}
522if ($search_company) {
523 $sql .= natural_search('s.nom', $search_company);
524}
525if ($search_company_alias) {
526 $sql .= natural_search('s.name_alias', $search_company_alias);
527}
528if ($search_sale > 0) {
529 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
530}
531if ($search_user > 0) {
532 $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);
533}
534if ($search_total_ht != '') {
535 $sql .= natural_search('cdet.total_ht', $search_total_ht, 1);
536}
537if ($search_total_vat != '') {
538 $sql .= natural_search('cdet.total_tva', $search_total_vat, 1);
539}
540if ($search_total_ttc != '') {
541 $sql .= natural_search('cdet.total_ttc', $search_total_ttc, 1);
542}
543if ($search_warehouse != '' && $search_warehouse > 0) {
544 $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
545}
546if ($search_multicurrency_code != '') {
547 $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
548}
549if ($search_multicurrency_tx != '') {
550 $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
551}
552if ($search_multicurrency_montant_ht != '') {
553 $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
554}
555if ($search_multicurrency_montant_vat != '') {
556 $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
557}
558if ($search_multicurrency_montant_ttc != '') {
559 $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
560}
561if ($search_login) {
562 $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
563}
564if ($search_project_ref != '') {
565 $sql .= natural_search("p.ref", $search_project_ref);
566}
567if ($search_project != '') {
568 $sql .= natural_search("p.title", $search_project);
569}
570if ($search_categ_cus > 0) {
571 $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
572}
573if ($search_categ_cus == -2) {
574 $sql .= " AND cc.fk_categorie IS NULL";
575}
576if ($search_fk_cond_reglement > 0) {
577 $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
578}
579if ($search_fk_shipping_method > 0) {
580 $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
581}
582if ($search_fk_mode_reglement > 0) {
583 $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
584}
585if ($search_fk_input_reason > 0) {
586 $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
587}
588
589// Add where from extra fields
590include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
591// Add where from hooks
592$parameters = array();
593$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
594$sql .= $hookmanager->resPrint;
595
596// Add HAVING from hooks
597$parameters = array();
598$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
599$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
600
601$sql .= $db->order($sortfield, $sortorder);
602
603// Count total nb of records
604$nbtotalofrecords = '';
605if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
606 $result = $db->query($sql);
607 $nbtotalofrecords = $db->num_rows($result);
608
609 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
610 $page = 0;
611 $offset = 0;
612 }
613}
614
615$sql .= $db->plimit($limit + 1, $offset);
616//print $sql;
617
618$resql = $db->query($sql);
619if ($resql) {
620 if ($socid > 0) {
621 $soc = new Societe($db);
622 $soc->fetch($socid);
623 $title = $langs->trans('ListOrderLigne').' - '.$soc->name;
624 if (empty($search_company)) {
625 $search_company = $soc->name;
626 }
627 } else {
628 $title = $langs->trans('ListOrderLigne');
629 }
630 if (strval($search_status) == '0') {
631 $title .= ' - '.$langs->trans('StatusOrderDraftShort');
632 }
633 if ($search_status == 1) {
634 $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
635 }
636 if ($search_status == 2) {
637 $title .= ' - '.$langs->trans('StatusOrderSentShort');
638 }
639 if ($search_status == 3) {
640 $title .= ' - '.$langs->trans('StatusOrderToBillShort');
641 }
642 if ($search_status == -1) {
643 $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
644 }
645 if ($search_status == -2) {
646 $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
647 }
648 if ($search_status == -3) {
649 $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(!isModEnabled('expedition') ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
650 }
651 if ($search_status == -4) {
652 $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
653 }
654
655 $num = $db->num_rows($resql);
656
657 $arrayofselected = is_array($toselect) ? $toselect : array();
658
659 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
660 $obj = $db->fetch_object($resql);
661 $id = $obj->rowid;
662 header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
663 exit;
664 }
665
666 llxHeader('', $title, $help_url);
667
668 $param = '';
669
670 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
671 $param .= '&contextpage='.urlencode($contextpage);
672 }
673 if ($limit > 0 && $limit != $conf->liste_limit) {
674 $param .= '&limit='.((int) $limit);
675 }
676 if ($sall) {
677 $param .= '&sall='.urlencode($sall);
678 }
679 if ($socid > 0) {
680 $param .= '&socid='.urlencode($socid);
681 }
682 if ($search_status != '') {
683 $param .= '&search_status='.urlencode($search_status);
684 }
685 if ($search_datecloture_start) {
686 $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');
687 }
688 if ($search_datecloture_end) {
689 $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');
690 }
691 if ($search_dateorder_start) {
692 $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');
693 }
694 if ($search_dateorder_end) {
695 $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');
696 }
697 if ($search_datedelivery_start) {
698 $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');
699 }
700 if ($search_datedelivery_end) {
701 $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');
702 }
703 if ($search_ref) {
704 $param .= '&search_ref='.urlencode($search_ref);
705 }
706 if ($search_company) {
707 $param .= '&search_company='.urlencode($search_company);
708 }
709 if ($search_company_alias) {
710 $param .= '&search_company_alias='.urlencode($search_company_alias);
711 }
712 if ($search_ref_customer) {
713 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
714 }
715 if ($search_user > 0) {
716 $param .= '&search_user='.urlencode($search_user);
717 }
718 if ($search_sale > 0) {
719 $param .= '&search_sale='.urlencode($search_sale);
720 }
721 if ($search_total_ht != '') {
722 $param .= '&search_total_ht='.urlencode($search_total_ht);
723 }
724 if ($search_total_vat != '') {
725 $param .= '&search_total_vat='.urlencode($search_total_vat);
726 }
727 if ($search_total_ttc != '') {
728 $param .= '&search_total_ttc='.urlencode($search_total_ttc);
729 }
730 if ($search_warehouse != '') {
731 $param .= '&search_warehouse='.urlencode($search_warehouse);
732 }
733 if ($search_login) {
734 $param .= '&search_login='.urlencode($search_login);
735 }
736 if ($search_multicurrency_code != '') {
737 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
738 }
739 if ($search_multicurrency_tx != '') {
740 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
741 }
742 if ($search_multicurrency_montant_ht != '') {
743 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
744 }
745 if ($search_multicurrency_montant_vat != '') {
746 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
747 }
748 if ($search_multicurrency_montant_ttc != '') {
749 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
750 }
751 if ($search_project_ref >= 0) {
752 $param .= "&search_project_ref=".urlencode($search_project_ref);
753 }
754 if ($search_town != '') {
755 $param .= '&search_town='.urlencode($search_town);
756 }
757 if ($search_zip != '') {
758 $param .= '&search_zip='.urlencode($search_zip);
759 }
760 if ($search_state != '') {
761 $param .= '&search_state='.urlencode($search_state);
762 }
763 if ($search_country != '') {
764 $param .= '&search_country='.urlencode($search_country);
765 }
766 if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
767 $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
768 }
769 if ($search_product_category != '') {
770 $param .= '&search_product_category='.urlencode($search_product_category);
771 }
772 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
773 $param .= '&search_categ_cus='.urlencode($search_categ_cus);
774 }
775 if ($show_files) {
776 $param .= '&show_files='.urlencode($show_files);
777 }
778 if ($optioncss != '') {
779 $param .= '&optioncss='.urlencode($optioncss);
780 }
781 if ($search_billed != '') {
782 $param .= '&search_billed='.urlencode($search_billed);
783 }
784 if ($search_fk_cond_reglement > 0) {
785 $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
786 }
787 if ($search_fk_shipping_method > 0) {
788 $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
789 }
790 if ($search_fk_mode_reglement > 0) {
791 $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
792 }
793 if ($search_fk_input_reason > 0) {
794 $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
795 }
796 if (!empty($productobuy)) {
797 $param .= '&productobuy='.urlencode($productobuy);
798 }
799 if (!empty($productonly)) {
800 $param .= '&productonly='.urlencode($productonly);
801 }
802 if (!empty($disablelinefree)) {
803 $param .= '&disablelinefree='.urlencode($disablelinefree);
804 }
805
806 // Add $param from extra fields
807 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
808
809 // Add $param from hooks
810 $parameters = array();
811 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
812 $param .= $hookmanager->resPrint;
813
814 // List of mass actions available
815 $arrayofmassactions = array(
816 // TODO add mass action here
817 );
818 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
819
820 $url = DOL_URL_ROOT.'/commande/card.php?action=create';
821 if (!empty($socid)) {
822 $url .= '&socid='.$socid;
823 }
824 $newcardbutton = '';//dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $contextpage == 'orderlistdet' && $permissiontoadd);
825
826 // Lines of title fields
827 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
828 if ($optioncss != '') {
829 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
830 }
831 print '<input type="hidden" name="token" value="'.newToken().'">';
832 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
833 print '<input type="hidden" name="action" value="list">';
834 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
835 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
836 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
837 print '<input type="hidden" name="search_status" value="'.$search_status.'">';
838 print '<input type="hidden" name="socid" value="'.$socid.'">';
839
840 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
841
842 $topicmail = "SendOrderRef";
843 $modelmail = "order_send";
844 $objecttmp = new Commande($db);
845 $trackid = 'ord'.$object->id;
846 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
847
848 if ($sall) {
849 foreach ($fieldstosearchall as $key => $val) {
850 $fieldstosearchall[$key] = $langs->trans($val);
851 }
852 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
853 }
854
855 $moreforfilter = '';
856
857 $moreforfilter .= '<input type="checkbox" name="productobuy"'.(!empty($productobuy)?'value="productobuychecked" checked':'' ).'><label for="productobuy">'.$langs->trans("productobuy").'</label>';
858 $moreforfilter .= '<input type="checkbox" name="productonly"'.(!empty($productonly)?'value="productonlychecked" checked':'' ).'><label for="productonly">'.$langs->trans("productonly").'</label>';
859 $moreforfilter .= '<input type="checkbox" name="disablelinefree"'.(!empty($disablelinefree)?'value="disablelinefreechecked" checked':'' ).'><label for="disablelinefree">'.$langs->trans("disablelinefree").'</label>';
860 $moreforfilter .= '<br>';
861
862 // If the user can view prospects other than his'
863 if ($user->rights->user->user->lire) {
864 $langs->load("commercial");
865 $moreforfilter .= '<div class="divsearchfield">';
866 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
867 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
868 $moreforfilter .= '</div>';
869 }
870 // If the user can view other users
871 if ($user->rights->user->user->lire) {
872 $moreforfilter .= '<div class="divsearchfield">';
873 $tmptitle = $langs->trans('LinkedToSpecificUsers');
874 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
875 $moreforfilter .= '</div>';
876 }
877 // If the user can view prospects other than his'
878 if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
879 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
880 $moreforfilter .= '<div class="divsearchfield">';
881 $tmptitle = $langs->trans('IncludingProductWithTag');
882 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
883 $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);
884 $moreforfilter .= '</div>';
885 }
886 if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {
887 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
888 $moreforfilter .= '<div class="divsearchfield">';
889 $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
890 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
891 $moreforfilter .= '</div>';
892 }
893 if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
894 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
895 $formproduct = new FormProduct($db);
896 $moreforfilter .= '<div class="divsearchfield">';
897 $tmptitle = $langs->trans('Warehouse');
898 $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
899 $moreforfilter .= '</div>';
900 }
901
902
903 $parameters = array();
904 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
905 if (empty($reshook)) {
906 $moreforfilter .= $hookmanager->resPrint;
907 } else {
908 $moreforfilter = $hookmanager->resPrint;
909 }
910
911 if (!empty($moreforfilter)) {
912 print '<div class="liste_titre liste_titre_bydiv centpercent">';
913 print $moreforfilter;
914 print '</div>';
915 }
916
917 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
918 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
919 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
920
921 if (GETPOST('autoselectall', 'int')) {
922 $selectedfields .= '<script>';
923 $selectedfields .= ' $(document).ready(function() {';
924 $selectedfields .= ' console.log("Autoclick on checkforselects");';
925 $selectedfields .= ' $("#checkforselects").click();';
926 $selectedfields .= ' $("#massaction").val("createbills").change();';
927 $selectedfields .= ' });';
928 $selectedfields .= '</script>';
929 }
930
931 print '<div class="div-table-responsive">';
932 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
933
934 print '<tr class="liste_titre_filter">';
935
936 // Action column
937 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
938 print '<td class="liste_titre" align="middle">';
939 $searchpicto = $form->showFilterButtons('left');
940 print $searchpicto;
941 print '</td>';
942 }
943
944 // Détail commande
945 if (!empty($arrayfields['pr.ref']['checked'])) {
946 print '<td class="liste_titre">';
947 print '<input class="flat" size="6" type="text" name="search_refProduct" value="'.dol_escape_htmltag($search_refProduct).'">';
948 print '</td>';
949 }
950 // Product Description
951 if (!empty($arrayfields['pr.desc']['checked'])) {
952 print '<td class="liste_titre">';
953 print '<input class="flat" size="6" type="text" name="search_descProduct" value="'.dol_escape_htmltag($search_descProduct).'">';
954 print '</td>';
955 }
956 // Product QtyOrdered
957 if (!empty($arrayfields['cdet.qty']['checked'])) {
958 print '<td class="liste_titre"></td>';
959 }
960
961 // Ref
962 if (!empty($arrayfields['c.ref']['checked'])) {
963 print '<td class="liste_titre">';
964 print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
965 print '</td>';
966 }
967 // Ref customer
968 if (!empty($arrayfields['c.ref_client']['checked'])) {
969 print '<td class="liste_titre" align="left">';
970 print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
971 print '</td>';
972 }
973 // Project ref
974 if (!empty($arrayfields['p.ref']['checked'])) {
975 print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
976 }
977 // Project title
978 if (!empty($arrayfields['p.title']['checked'])) {
979 print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
980 }
981 // Thirpdarty
982 if (!empty($arrayfields['s.nom']['checked'])) {
983 print '<td class="liste_titre" align="left">';
984 print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
985 print '</td>';
986 }
987 // Alias
988 if (!empty($arrayfields['s.name_alias']['checked'])) {
989 print '<td class="liste_titre" align="left">';
990 print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
991 print '</td>';
992 }
993 // Town
994 if (!empty($arrayfields['s.town']['checked'])) {
995 print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
996 }
997 // Zip
998 if (!empty($arrayfields['s.zip']['checked'])) {
999 print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1000 }
1001 // State
1002 if (!empty($arrayfields['state.nom']['checked'])) {
1003 print '<td class="liste_titre">';
1004 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1005 print '</td>';
1006 }
1007 // Country
1008 if (!empty($arrayfields['country.code_iso']['checked'])) {
1009 print '<td class="liste_titre" align="center">';
1010 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1011 print '</td>';
1012 }
1013 // Company type
1014 if (!empty($arrayfields['typent.code']['checked'])) {
1015 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1016 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);
1017 print '</td>';
1018 }
1019 // Date order
1020 if (!empty($arrayfields['c.date_commande']['checked'])) {
1021 print '<td class="liste_titre center">';
1022 print '<div class="nowrap">';
1023 print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1024 print '</div>';
1025 print '<div class="nowrap">';
1026 print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1027 print '</div>';
1028 print '</td>';
1029 }
1030 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1031 print '<td class="liste_titre center">';
1032 print '<div class="nowrap">';
1033 print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1034 print '</div>';
1035 print '<div class="nowrap">';
1036 print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1037 print '</div>';
1038 print '</td>';
1039 }
1040 // Shipping Method
1041 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1042 print '<td class="liste_titre">';
1043 $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1044 print '</td>';
1045 }
1046 // Payment term
1047 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1048 print '<td class="liste_titre">';
1049 $form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
1050 print '</td>';
1051 }
1052 // Payment mode
1053 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1054 print '<td class="liste_titre">';
1055 $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1);
1056 print '</td>';
1057 }
1058 // Channel
1059 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1060 print '<td class="liste_titre">';
1061 $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
1062 print '</td>';
1063 }
1064 if (!empty($arrayfields['cdet.total_ht']['checked'])) {
1065 // Amount
1066 print '<td class="liste_titre right">';
1067 print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
1068 print '</td>';
1069 }
1070 if (!empty($arrayfields['c.total_vat']['checked'])) {
1071 // Amount
1072 print '<td class="liste_titre right">';
1073 print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
1074 print '</td>';
1075 }
1076 if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
1077 // Amount
1078 print '<td class="liste_titre right">';
1079 print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1080 print '</td>';
1081 }
1082 if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
1083 // Warehouse
1084 print '<td class="liste_titre right"></td>';
1085 }
1086 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1087 // Currency
1088 print '<td class="liste_titre">';
1089 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1090 print '</td>';
1091 }
1092 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1093 // Currency rate
1094 print '<td class="liste_titre">';
1095 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1096 print '</td>';
1097 }
1098 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1099 // Amount
1100 print '<td class="liste_titre right">';
1101 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1102 print '</td>';
1103 }
1104 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1105 // Amount VAT
1106 print '<td class="liste_titre right">';
1107 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1108 print '</td>';
1109 }
1110 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1111 // Amount
1112 print '<td class="liste_titre right">';
1113 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1114 print '</td>';
1115 }
1116 if (!empty($arrayfields['u.login']['checked'])) {
1117 // Author
1118 print '<td class="liste_titre" align="center">';
1119 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1120 print '</td>';
1121 }
1122 if (!empty($arrayfields['sale_representative']['checked'])) {
1123 print '<td class="liste_titre"></td>';
1124 }
1125 if (!empty($arrayfields['total_pa']['checked'])) {
1126 print '<td class="liste_titre right">';
1127 print '</td>';
1128 }
1129 if (!empty($arrayfields['total_margin']['checked'])) {
1130 print '<td class="liste_titre right">';
1131 print '</td>';
1132 }
1133 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1134 print '<td class="liste_titre right">';
1135 print '</td>';
1136 }
1137 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1138 print '<td class="liste_titre right">';
1139 print '</td>';
1140 }
1141 // Extra fields
1142 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1143 // Fields from hook
1144 $parameters = array('arrayfields'=>$arrayfields);
1145 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1146 print $hookmanager->resPrint;
1147 // Date creation
1148 if (!empty($arrayfields['c.datec']['checked'])) {
1149 print '<td class="liste_titre">';
1150 print '</td>';
1151 }
1152 // Date modification
1153 if (!empty($arrayfields['c.tms']['checked'])) {
1154 print '<td class="liste_titre">';
1155 print '</td>';
1156 }
1157 // Date cloture
1158 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1159 print '<td class="liste_titre center">';
1160 print '<div class="nowrap">';
1161 print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1162 print '</div>';
1163 print '<div class="nowrap">';
1164 print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1165 print '</div>';
1166 print '</td>';
1167 }
1168 // Note public
1169 if (!empty($arrayfields['c.note_public']['checked'])) {
1170 print '<td class="liste_titre">';
1171 print '</td>';
1172 }
1173 // Note private
1174 if (!empty($arrayfields['c.note_private']['checked'])) {
1175 print '<td class="liste_titre">';
1176 print '</td>';
1177 }
1178 // Shippable
1179 if (!empty($arrayfields['shippable']['checked'])) {
1180 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1181 //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
1182 if (!empty($conf->global->ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT)) {
1183 print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
1184 print $langs->trans('ShowShippableStatus');
1185 } else {
1186 $show_shippable_command = 1;
1187 }
1188 print '</td>';
1189 }
1190 // Status billed
1191 if (!empty($arrayfields['c.facture']['checked'])) {
1192 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1193 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
1194 print '</td>';
1195 }
1196 // Import key
1197 if (!empty($arrayfields['c.import_key']['checked'])) {
1198 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1199 print '</td>';
1200 }
1201 // Status
1202 if (!empty($arrayfields['c.fk_statut']['checked'])) {
1203 print '<td class="liste_titre maxwidthonsmartphone center">';
1204 $liststatus = array(
1205 Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
1206 Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
1207 Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
1208 Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
1209 -3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
1210 -2=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
1211 Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
1212 );
1213 print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'maxwidth125', 1);
1214 print '</td>';
1215 }
1216 // Action column
1217 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1218 print '<td class="liste_titre" align="middle">';
1219 $searchpicto = $form->showFilterButtons();
1220 print $searchpicto;
1221 print '</td>';
1222 }
1223 print "</tr>\n";
1224
1225 // Fields title
1226 print '<tr class="liste_titre">';
1227
1228 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1229 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1230 }
1231
1232 // Détail commande
1233 if (!empty($arrayfields['pr.ref']['checked'])) {
1234 print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
1235 }
1236 if (!empty($arrayfields['pr.desc']['checked'])) {
1237 print_liste_field_titre($arrayfields['pr.desc']['label'], $_SERVER["PHP_SELF"], 'pr.desc', '', $param, '', $sortfield, $sortorder);
1238 }
1239 if (!empty($arrayfields['cdet.qty']['checked'])) {
1240 print_liste_field_titre($arrayfields['cdet.qty']['label'], $_SERVER["PHP_SELF"], 'cdet.qty', '', $param, '', $sortfield, $sortorder);
1241 }
1242
1243 if (!empty($arrayfields['c.ref']['checked'])) {
1244 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
1245 }
1246 if (!empty($arrayfields['c.ref_client']['checked'])) {
1247 print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
1248 }
1249 if (!empty($arrayfields['p.ref']['checked'])) {
1250 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1251 }
1252 if (!empty($arrayfields['p.title']['checked'])) {
1253 print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
1254 }
1255 if (!empty($arrayfields['s.nom']['checked'])) {
1256 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1257 }
1258 if (!empty($arrayfields['s.name_alias']['checked'])) {
1259 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1260 }
1261 if (!empty($arrayfields['s.town']['checked'])) {
1262 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1263 }
1264 if (!empty($arrayfields['s.zip']['checked'])) {
1265 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1266 }
1267 if (!empty($arrayfields['state.nom']['checked'])) {
1268 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1269 }
1270 if (!empty($arrayfields['country.code_iso']['checked'])) {
1271 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1272 }
1273 if (!empty($arrayfields['typent.code']['checked'])) {
1274 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1275 }
1276 if (!empty($arrayfields['c.date_commande']['checked'])) {
1277 print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
1278 }
1279 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1280 print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1281 }
1282 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1283 print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1284 }
1285 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1286 print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1287 }
1288 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1289 print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1290 }
1291 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1292 print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1293 }
1294 if (!empty($arrayfields['cdet.total_ht']['checked'])) {
1295 print_liste_field_titre($arrayfields['cdet.total_ht']['label'], $_SERVER["PHP_SELF"], 'cdet.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1296 }
1297 if (!empty($arrayfields['c.total_vat']['checked'])) {
1298 print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'cdet.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1299 }
1300 if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
1301 print_liste_field_titre($arrayfields['cdet.total_ttc']['label'], $_SERVER["PHP_SELF"], 'cdet.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1302 }
1303 if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
1304 print_liste_field_titre($arrayfields['c.fk_warehouse']['label'], "", '', '', $param, '', $sortfield, $sortorder);
1305 }
1306 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1307 print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1308 }
1309 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1310 print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1311 }
1312 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1313 print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1314 }
1315 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1316 print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1317 }
1318 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1319 print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1320 }
1321 if (!empty($arrayfields['u.login']['checked'])) {
1322 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1323 }
1324 if (!empty($arrayfields['sale_representative']['checked'])) {
1325 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1326 }
1327 if (!empty($arrayfields['total_pa']['checked'])) {
1328 print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1329 }
1330 if (!empty($arrayfields['total_margin']['checked'])) {
1331 print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1332 }
1333 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1334 print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1335 }
1336 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1337 print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1338 }
1339
1340 $totalarray = array(
1341 'nbfield' => 0,
1342 'val' => array(
1343 'cdet.total_ht' => 0,
1344 'cdet.total_tva' => 0,
1345 'cdet.total_ttc' => 0,
1346 ),
1347 'pos' => array(),
1348 );
1349 // Extra fields
1350 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1351 // Hook fields
1352 $parameters = array(
1353 'arrayfields' => $arrayfields,
1354 'param' => $param,
1355 'sortfield' => $sortfield,
1356 'sortorder' => $sortorder,
1357 'totalarray' => &$totalarray,
1358 );
1359 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1360 print $hookmanager->resPrint;
1361 if (!empty($arrayfields['c.datec']['checked'])) {
1362 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1363 }
1364 if (!empty($arrayfields['c.tms']['checked'])) {
1365 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1366 }
1367 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1368 print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1369 }
1370 if (!empty($arrayfields['c.note_public']['checked'])) {
1371 print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
1372 }
1373 if (!empty($arrayfields['c.note_private']['checked'])) {
1374 print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
1375 }
1376 if (!empty($arrayfields['shippable']['checked'])) {
1377 print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
1378 }
1379 if (!empty($arrayfields['c.facture']['checked'])) {
1380 print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
1381 }
1382 if (!empty($arrayfields['c.import_key']['checked'])) {
1383 print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1384 }
1385 if (!empty($arrayfields['c.fk_statut']['checked'])) {
1386 print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
1387 }
1388 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1389 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1390 }
1391 print '</tr>'."\n";
1392
1393 $total = 0;
1394 $subtotal = 0;
1395 $productstat_cache = array();
1396 $productstat_cachevirtual = array();
1397 $getNomUrl_cache = array();
1398
1399 $generic_commande = new Commande($db);
1400 $generic_product = new Product($db);
1401 $userstatic = new User($db);
1402 $i = 0;
1403
1404 $with_margin_info = false;
1405 if (isModEnabled('margin') && (
1406 !empty($arrayfields['total_pa']['checked'])
1407 || !empty($arrayfields['total_margin']['checked'])
1408 || !empty($arrayfields['total_margin_rate']['checked'])
1409 || !empty($arrayfields['total_mark_rate']['checked'])
1410 )
1411 ) {
1412 $with_margin_info = true;
1413 }
1414 $total_ht = 0;
1415 $total_margin = 0;
1416
1417
1418 // Détail commande
1419 $totalqty = 0;
1420
1421 $totalarray = array();
1422 $totalarray['nbfield'] = 0;
1423 $totalarray['val']['cdet.total_tva'] = 0;
1424 $totalarray['val']['cdet.total_ttc'] = 0;
1425 $imaxinloop = ($limit ? min($num, $limit) : $num);
1426 while ($i < $imaxinloop) {
1427 $obj = $db->fetch_object($resql);
1428
1429 $notshippable = 0;
1430 $warning = 0;
1431 $text_info = '';
1432 $text_warning = '';
1433 $nbprod = 0;
1434
1435 // Print SubTotal
1436 if (empty($i)) {
1437 $oldref = $obj->product_ref;
1438 }
1439 if ($oldref != $obj->product_ref && $sortfield == 'pr.ref') {
1440 // TODO make new /core/tpl/list_print_sub_total.php
1441 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1442 $oldref = $obj->product_ref;
1443 }
1444
1445 $companystatic->id = $obj->socid;
1446 $companystatic->name = $obj->name;
1447 $companystatic->name_alias = $obj->alias;
1448 $companystatic->client = $obj->client;
1449 $companystatic->code_client = $obj->code_client;
1450 $companystatic->email = $obj->email;
1451 $companystatic->phone = $obj->phone;
1452 $companystatic->address = $obj->address;
1453 $companystatic->zip = $obj->zip;
1454 $companystatic->town = $obj->town;
1455 $companystatic->country_code = $obj->country_code;
1456 if (!isset($getNomUrl_cache[$obj->socid])) {
1457 $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer');
1458 }
1459
1460 $generic_commande->id = $obj->c_rowid;
1461 $generic_commande->ref = $obj->ref;
1462 $generic_commande->statut = $obj->fk_statut;
1463 $generic_commande->billed = $obj->billed;
1464 $generic_commande->date = $db->jdate($obj->date_commande);
1465 $generic_commande->date_livraison = $db->jdate($obj->date_delivery); // deprecated
1466 $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
1467 $generic_commande->ref_client = $obj->ref_client;
1468 $generic_commande->total_ht = $obj->c_total_ht;
1469 $generic_commande->total_tva = $obj->c_total_tva;
1470 $generic_commande->total_ttc = $obj->c_total_ttc;
1471 $generic_commande->note_public = $obj->note_public;
1472 $generic_commande->note_private = $obj->note_private;
1473
1474 $projectstatic->id = $obj->project_id;
1475 $projectstatic->ref = $obj->project_ref;
1476 $projectstatic->title = $obj->project_label;
1477
1478 $marginInfo = array();
1479 if ($with_margin_info === true) {
1480 $generic_commande->fetch_lines();
1481 $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
1482 $total_ht += $obj->total_ht;
1483 $total_margin += $marginInfo['total_margin'];
1484 }
1485
1486 print '<tr class="oddeven">';
1487
1488 // Action column
1489 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1490 print '<td class="nowrap center">';
1491 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1492 $selected = 0;
1493 if (in_array($obj->rowid, $arrayofselected)) {
1494 $selected = 1;
1495 }
1496 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1497 }
1498 print '</td>';
1499 if (!$i) {
1500 $totalarray['nbfield']++;
1501 }
1502 }
1503
1504 // Détail commande
1505 // Product Ref
1506 if (!empty($arrayfields['pr.ref']['checked'])) {
1507 if (!empty($obj->product_rowid)) {
1508 $generic_product->id = $obj->product_rowid;
1509 $generic_product->ref = $obj->product_ref;
1510 $generic_product->label = $obj->product_label;
1511 $generic_product->status = $obj->product_status;
1512 $generic_product->status_buy = $obj->product_status_buy;
1513 $generic_product->status_batch = $obj->product_batch;
1514 $generic_product->barcode = $obj->product_barcode;
1515 print '<td class="nowrap tdoverflowmax200">'.$generic_product->getNomUrl(1).'</td>';
1516 } else {
1517 print '<td class="nowrap tdoverflowmax200">Ligne libre</td>';
1518 }
1519 if (!$i) {
1520 $totalarray['nbfield']++;
1521 }
1522 }
1523 // Product Description
1524 if (!empty($arrayfields['pr.desc']['checked'])) {
1525 // print '<td class="nowrap tdoverflowmax200">'.$obj->description.'</td>';
1526 !empty($obj->product_label) ? $labelproduct = $obj->product_label : $labelproduct = $obj->description;
1527 print '<td class="nowrap tdoverflowmax200">aa';
1528 print dolGetFirstLineOfText(dolPrintHTML($labelproduct), 5);
1529 print '</td>';
1530
1531 if (!$i) {
1532 $totalarray['nbfield']++;
1533 }
1534 }
1535 // Product QtyOrdered
1536 if (!empty($arrayfields['cdet.qty']['checked'])) {
1537 print '<td class="nowrap right">'.$obj->qty.'</td>';
1538 if (isset($totalarray['val']['cdet.qty'])) {
1539 $totalarray['val']['cdet.qty'] += $obj->qty;
1540 } else {
1541 $totalarray['val']['cdet.qty'] = $obj->qty;
1542 }
1543 if (!$i) {
1544 $totalarray['nbfield']++;
1545 }
1546 if (!$i) {
1547 $totalarray['pos'][$totalarray['nbfield']] = 'cdet.qty';
1548 }
1549 }
1550
1551 // Ref
1552 if (!empty($arrayfields['c.ref']['checked'])) {
1553 print '<td class="nowraponall">';
1554 print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
1555
1556 $filename = dol_sanitizeFileName($obj->ref);
1557 $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
1558 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1559 print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
1560
1561 print '</td>';
1562 if (!$i) {
1563 $totalarray['nbfield']++;
1564 }
1565 }
1566
1567 // Ref customer
1568 if (!empty($arrayfields['c.ref_client']['checked'])) {
1569 print '<td class="nowrap tdoverflowmax200">'.$obj->ref_client.'</td>';
1570 if (!$i) {
1571 $totalarray['nbfield']++;
1572 }
1573 }
1574
1575 // Project ref
1576 if (!empty($arrayfields['p.ref']['checked'])) {
1577 print '<td class="nowrap">';
1578 if ($obj->project_id > 0) {
1579 print $projectstatic->getNomUrl(1);
1580 }
1581 print '</td>';
1582 if (!$i) {
1583 $totalarray['nbfield']++;
1584 }
1585 }
1586
1587 // Project label
1588 if (!empty($arrayfields['p.title']['checked'])) {
1589 print '<td class="nowrap">';
1590 if ($obj->project_id > 0) {
1591 print $projectstatic->title;
1592 }
1593 print '</td>';
1594 if (!$i) {
1595 $totalarray['nbfield']++;
1596 }
1597 }
1598
1599 // Third party
1600 if (!empty($arrayfields['s.nom']['checked'])) {
1601 print '<td class="tdoverflowmax200">';
1602 print $getNomUrl_cache[$obj->socid];
1603
1604 // If module invoices enabled and user with invoice creation permissions
1605 if (isModEnabled('facture') && !empty($conf->global->ORDER_BILLING_ALL_CUSTOMER)) {
1606 if ($user->hasRight('facture', 'creer')) {
1607 if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
1608 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
1609 print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
1610 }
1611 }
1612 }
1613 print '</td>';
1614 if (!$i) {
1615 $totalarray['nbfield']++;
1616 }
1617 }
1618 // Alias name
1619 if (!empty($arrayfields['s.name_alias']['checked'])) {
1620 print '<td class="nocellnopadd">';
1621 print $obj->alias;
1622 print '</td>';
1623 if (!$i) {
1624 $totalarray['nbfield']++;
1625 }
1626 }
1627 // Town
1628 if (!empty($arrayfields['s.town']['checked'])) {
1629 print '<td class="nocellnopadd">';
1630 print $obj->town;
1631 print '</td>';
1632 if (!$i) {
1633 $totalarray['nbfield']++;
1634 }
1635 }
1636 // Zip
1637 if (!empty($arrayfields['s.zip']['checked'])) {
1638 print '<td class="nocellnopadd">';
1639 print $obj->zip;
1640 print '</td>';
1641 if (!$i) {
1642 $totalarray['nbfield']++;
1643 }
1644 }
1645 // State
1646 if (!empty($arrayfields['state.nom']['checked'])) {
1647 print "<td>".$obj->state_name."</td>\n";
1648 if (!$i) {
1649 $totalarray['nbfield']++;
1650 }
1651 }
1652 // Country
1653 if (!empty($arrayfields['country.code_iso']['checked'])) {
1654 print '<td class="center">';
1655 $tmparray = getCountry($obj->fk_pays, 'all');
1656 print $tmparray['label'];
1657 print '</td>';
1658 if (!$i) {
1659 $totalarray['nbfield']++;
1660 }
1661 }
1662 // Type ent
1663 if (!empty($arrayfields['typent.code']['checked'])) {
1664 print '<td class="center">';
1665 if (empty($typenArray)) {
1666 $typenArray = $formcompany->typent_array(1);
1667 }
1668 print $typenArray[$obj->typent_code];
1669 print '</td>';
1670 if (!$i) {
1671 $totalarray['nbfield']++;
1672 }
1673 }
1674
1675 // Order date
1676 if (!empty($arrayfields['c.date_commande']['checked'])) {
1677 print '<td class="center">';
1678 print dol_print_date($db->jdate($obj->date_commande), 'day');
1679 // Warning late icon and note
1680 if ($generic_commande->hasDelay()) {
1681 print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
1682 }
1683 print '</td>';
1684 if (!$i) {
1685 $totalarray['nbfield']++;
1686 }
1687 }
1688 // Plannned date of delivery
1689 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1690 print '<td class="center">';
1691 print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
1692 print '</td>';
1693 if (!$i) {
1694 $totalarray['nbfield']++;
1695 }
1696 }
1697 // Shipping Method
1698 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1699 print '<td>';
1700 $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
1701 print '</td>';
1702 if (!$i) {
1703 $totalarray['nbfield']++;
1704 }
1705 }
1706 // Payment terms
1707 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1708 print '<td>';
1709 $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
1710 print '</td>';
1711 if (!$i) {
1712 $totalarray['nbfield']++;
1713 }
1714 }
1715 // Payment mode
1716 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1717 print '<td>';
1718 $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1719 print '</td>';
1720 if (!$i) {
1721 $totalarray['nbfield']++;
1722 }
1723 }
1724 // Channel
1725 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1726 print '<td>';
1727 $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', '');
1728 print '</td>';
1729 if (!$i) {
1730 $totalarray['nbfield']++;
1731 }
1732 }
1733 // Amount HT
1734 if (!empty($arrayfields['cdet.total_ht']['checked'])) {
1735 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1736 if (!$i) {
1737 $totalarray['nbfield']++;
1738 }
1739 if (!$i) {
1740 $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_ht';
1741 }
1742 if (isset($totalarray['val']['cdet.total_ht'])) {
1743 $totalarray['val']['cdet.total_ht'] += $obj->total_ht;
1744 } else {
1745 $totalarray['val']['cdet.total_ht'] = $obj->total_ht;
1746 }
1747 }
1748 // Amount VAT
1749 if (!empty($arrayfields['c.total_vat']['checked'])) {
1750 print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1751 if (!$i) {
1752 $totalarray['nbfield']++;
1753 }
1754 if (!$i) {
1755 $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_tva';
1756 }
1757 $totalarray['val']['cdet.total_tva'] += $obj->total_tva;
1758 }
1759 // Amount TTC
1760 if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
1761 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1762 if (!$i) {
1763 $totalarray['nbfield']++;
1764 }
1765 if (!$i) {
1766 $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_ttc';
1767 }
1768 $totalarray['val']['cdet.total_ttc'] += $obj->total_ttc;
1769 }
1770 // Warehouse
1771 if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
1772 print '<td class="nowrap">';
1773 if ($obj->warehouse > 0) {
1774 print img_picto('', 'stock', 'class="paddingrightonly"');
1775 }
1776 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'], $obj->warehouse, 'none');
1777 print "</td>\n";
1778 if (!$i) {
1779 $totalarray['nbfield']++;
1780 }
1781 }
1782 // Currency
1783 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1784 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1785 if (!$i) {
1786 $totalarray['nbfield']++;
1787 }
1788 }
1789
1790 // Currency rate
1791 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1792 print '<td class="nowrap">';
1793 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1794 print "</td>\n";
1795 if (!$i) {
1796 $totalarray['nbfield']++;
1797 }
1798 }
1799 // Amount HT
1800 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1801 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1802 if (!$i) {
1803 $totalarray['nbfield']++;
1804 }
1805 }
1806 // Amount VAT
1807 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1808 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
1809 if (!$i) {
1810 $totalarray['nbfield']++;
1811 }
1812 }
1813 // Amount TTC
1814 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1815 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1816 if (!$i) {
1817 $totalarray['nbfield']++;
1818 }
1819 }
1820
1821 $userstatic->id = $obj->fk_user_author;
1822 $userstatic->login = $obj->login;
1823 $userstatic->lastname = $obj->lastname;
1824 $userstatic->firstname = $obj->firstname;
1825 $userstatic->email = $obj->user_email;
1826 $userstatic->statut = $obj->user_statut;
1827 $userstatic->entity = $obj->entity;
1828 $userstatic->photo = $obj->photo;
1829 $userstatic->office_phone = $obj->office_phone;
1830 $userstatic->office_fax = $obj->office_fax;
1831 $userstatic->user_mobile = $obj->user_mobile;
1832 $userstatic->job = $obj->job;
1833 $userstatic->gender = $obj->gender;
1834
1835 // Author
1836 if (!empty($arrayfields['u.login']['checked'])) {
1837 print '<td class="tdoverflowmax200">';
1838 if ($userstatic->id) {
1839 print $userstatic->getNomUrl(-1);
1840 } else {
1841 print '&nbsp;';
1842 }
1843 print "</td>\n";
1844 if (!$i) {
1845 $totalarray['nbfield']++;
1846 }
1847 }
1848
1849 if (!empty($arrayfields['sale_representative']['checked'])) {
1850 // Sales representatives
1851 print '<td>';
1852 if ($obj->socid > 0) {
1853 $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
1854 if ($listsalesrepresentatives < 0) {
1855 dol_print_error($db);
1856 }
1857 $nbofsalesrepresentative = count($listsalesrepresentatives);
1858 if ($nbofsalesrepresentative > 6) {
1859 // We print only number
1860 print $nbofsalesrepresentative;
1861 } elseif ($nbofsalesrepresentative > 0) {
1862 $j = 0;
1863 foreach ($listsalesrepresentatives as $val) {
1864 $userstatic->id = $val['id'];
1865 $userstatic->lastname = $val['lastname'];
1866 $userstatic->firstname = $val['firstname'];
1867 $userstatic->email = $val['email'];
1868 $userstatic->statut = $val['statut'];
1869 $userstatic->entity = $val['entity'];
1870 $userstatic->photo = $val['photo'];
1871 $userstatic->login = $val['login'];
1872 $userstatic->office_phone = $val['office_phone'];
1873 $userstatic->office_fax = $val['office_fax'];
1874 $userstatic->user_mobile = $val['user_mobile'];
1875 $userstatic->job = $val['job'];
1876 $userstatic->gender = $val['gender'];
1877 //print '<div class="float">':
1878 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1879 $j++;
1880 if ($j < $nbofsalesrepresentative) {
1881 print ' ';
1882 }
1883 //print '</div>';
1884 }
1885 }
1886 //else print $langs->trans("NoSalesRepresentativeAffected");
1887 } else {
1888 print '&nbsp;';
1889 }
1890 print '</td>';
1891 if (!$i) {
1892 $totalarray['nbfield']++;
1893 }
1894 }
1895
1896 // Total buying or cost price
1897 if (!empty($arrayfields['total_pa']['checked'])) {
1898 print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
1899 if (!$i) {
1900 $totalarray['nbfield']++;
1901 }
1902 }
1903 // Total margin
1904 if (!empty($arrayfields['total_margin']['checked'])) {
1905 print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
1906 if (!$i) {
1907 $totalarray['nbfield']++;
1908 }
1909 if (!$i) {
1910 $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
1911 }
1912 $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
1913 }
1914 // Total margin rate
1915 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1916 print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
1917 if (!$i) {
1918 $totalarray['nbfield']++;
1919 }
1920 }
1921 // Total mark rate
1922 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1923 print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
1924 if (!$i) {
1925 $totalarray['nbfield']++;
1926 }
1927 if (!$i) {
1928 $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
1929 }
1930 if ($i >= $imaxinloop - 1) {
1931 if (!empty($total_ht)) {
1932 $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
1933 } else {
1934 $totalarray['val']['total_mark_rate'] = '';
1935 }
1936 }
1937 }
1938
1939 // Extra fields
1940 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1941 // Fields from hook
1942 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1943 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1944 print $hookmanager->resPrint;
1945
1946 // Date creation
1947 if (!empty($arrayfields['c.datec']['checked'])) {
1948 print '<td align="center" class="nowrap">';
1949 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1950 print '</td>';
1951 if (!$i) {
1952 $totalarray['nbfield']++;
1953 }
1954 }
1955
1956 // Date modification
1957 if (!empty($arrayfields['c.tms']['checked'])) {
1958 print '<td align="center" class="nowrap">';
1959 print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1960 print '</td>';
1961 if (!$i) {
1962 $totalarray['nbfield']++;
1963 }
1964 }
1965
1966 // Date cloture
1967 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1968 print '<td align="center" class="nowrap">';
1969 print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
1970 print '</td>';
1971 if (!$i) {
1972 $totalarray['nbfield']++;
1973 }
1974 }
1975
1976 // Note public
1977 if (!empty($arrayfields['c.note_public']['checked'])) {
1978 print '<td class="center">';
1979 print dol_string_nohtmltag($obj->note_public);
1980 print '</td>';
1981 if (!$i) {
1982 $totalarray['nbfield']++;
1983 }
1984 }
1985
1986 // Note private
1987 if (!empty($arrayfields['c.note_private']['checked'])) {
1988 print '<td class="center">';
1989 print dol_string_nohtmltag($obj->note_private);
1990 print '</td>';
1991 if (!$i) {
1992 $totalarray['nbfield']++;
1993 }
1994 }
1995
1996 // Show shippable Icon (this creates subloops, so may be slow)
1997 if (!empty($arrayfields['shippable']['checked'])) {
1998 print '<td class="center">';
1999 if (!empty($show_shippable_command) && isModEnabled('stock')) {
2000 if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
2001 $generic_commande->loadExpeditions(); // Load array ->expeditions
2002
2003 if (isset($generic_commande->expeditions[$obj->rowid])) {
2004 $reliquat = $obj->qty - $generic_commande->expeditions[$obj->rowid];
2005 } else {
2006 $reliquat = $obj->qty;
2007 }
2008 if ($obj->product_type == 0 && $obj->fk_product > 0) { // If line is a product and not a service
2009 $nbprod++; // order contains real products
2010 $generic_product->id = $obj->fk_product;
2011
2012 // Get local and virtual stock and store it into cache
2013 if (empty($productstat_cache[$obj->fk_product])) {
2014 $generic_product->load_stock('nobatch'); // ->load_virtual_stock() is already included into load_stock()
2015 $productstat_cache[$obj->fk_product]['stock_reel'] = $generic_product->stock_reel;
2016 $productstat_cachevirtual[$obj->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2017 } else {
2018 $generic_product->stock_reel = $productstat_cache[$obj->fk_product]['stock_reel'];
2019 $generic_product->stock_theorique = $productstat_cachevirtual[$obj->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2020 }
2021
2022 if ($reliquat > $generic_product->stock_reel) {
2023 $notshippable++;
2024 }
2025 if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) { // Default code. Default should be this case.
2026 $text_info .= $reliquat.' x '.$obj->product_ref.'&nbsp;'.dol_trunc($obj->product_label, 20);
2027 $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
2028 $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
2029 $text_info .= ($reliquat != $obj->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($obj->qty - $reliquat).')</span>' : '');
2030 $text_info .= '<br>';
2031 } else { // BUGGED CODE.
2032 // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
2033 // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
2034 // Detailed virtual stock, looks bugged, uncomplete and need heavy load.
2035 // stock order and stock order_supplier
2036 $stock_order = 0;
2037 $stock_order_supplier = 0;
2038 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { // What about other options ?
2039 if (isModEnabled('commande')) {
2040 if (empty($productstat_cache[$obj->fk_product]['stats_order_customer'])) {
2041 $generic_product->load_stats_commande(0, '1,2');
2042 $productstat_cache[$obj->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
2043 } else {
2044 $generic_product->stats_commande['qty'] = $productstat_cache[$obj->fk_product]['stats_order_customer'];
2045 }
2046 $stock_order = $generic_product->stats_commande['qty'];
2047 }
2048 if (isModEnabled('supplier_order')) {
2049 if (empty($productstat_cache[$obj->fk_product]['stats_order_supplier'])) {
2050 $generic_product->load_stats_commande_fournisseur(0, '3');
2051 $productstat_cache[$obj->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
2052 } else {
2053 $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$obj->fk_product]['stats_order_supplier'];
2054 }
2055 $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
2056 }
2057 }
2058 $text_info .= $reliquat.' x '.$obj->product_ref.'&nbsp;'.dol_trunc($obj->product_label, 20);
2059 $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
2060 if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $obj->qty)) {
2061 $warning++;
2062 $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2063 }
2064 if ($reliquat > $generic_product->stock_reel) {
2065 $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2066 } else {
2067 $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2068 }
2069 if (isModEnabled('supplier_order')) {
2070 $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
2071 }
2072 $text_info .= ($reliquat != $obj->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($obj->qty - $reliquat).')</span>' : '');
2073 $text_info .= '<br>';
2074 }
2075 }
2076 if ($notshippable == 0) {
2077 $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
2078 $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
2079 } else {
2080 $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
2081 $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
2082 }
2083 }
2084
2085 if ($nbprod) {
2086 print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
2087 }
2088 if ($warning) { // Always false in default mode
2089 print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
2090 }
2091 }
2092 print '</td>';
2093 if (!$i) {
2094 $totalarray['nbfield']++;
2095 }
2096 }
2097
2098 // Billed
2099 if (!empty($arrayfields['c.facture']['checked'])) {
2100 print '<td class="center">'.yn($obj->billed).'</td>';
2101 if (!$i) {
2102 $totalarray['nbfield']++;
2103 }
2104 }
2105 // Import key
2106 if (!empty($arrayfields['c.import_key']['checked'])) {
2107 print '<td class="nowrap center">'.$obj->import_key.'</td>';
2108 if (!$i) {
2109 $totalarray['nbfield']++;
2110 }
2111 }
2112 // Status
2113 if (!empty($arrayfields['c.fk_statut']['checked'])) {
2114 print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
2115 if (!$i) {
2116 $totalarray['nbfield']++;
2117 }
2118 }
2119
2120 // Action column
2121 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
2122 print '<td class="nowrap center">';
2123 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2124 $selected = 0;
2125 if (in_array($obj->rowid, $arrayofselected)) {
2126 $selected = 1;
2127 }
2128 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2129 }
2130 print '</td>';
2131 if (!$i) {
2132 $totalarray['nbfield']++;
2133 }
2134 }
2135 // $totalarray['nbfield']--;
2136 // $totalarray['nbfield']--;
2137 print "</tr>\n";
2138
2139 $total += $obj->total_ht;
2140 $subtotal += $obj->total_ht;
2141 $i++;
2142 }
2143
2144 // Show total line
2145 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2146
2147 // If no record found
2148 if ($num == 0) {
2149 $colspan = 1;
2150 foreach ($arrayfields as $key => $val) {
2151 if (!empty($val['checked'])) {
2152 $colspan++;
2153 }
2154 }
2155 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2156 }
2157
2158 $db->free($resql);
2159
2160 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2161 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2162 print $hookmanager->resPrint;
2163
2164 print '</table>'."\n";
2165 print '</div>';
2166
2167 print '</form>'."\n";
2168
2169 $hidegeneratedfilelistifempty = 1;
2170 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2171 $hidegeneratedfilelistifempty = 0;
2172 }
2173
2174 // Show list of available documents
2175 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2176 $urlsource .= str_replace('&amp;', '&', $param);
2177
2178 $filedir = $diroutputmassaction;
2179 $genallowed = $permissiontoread;
2180 $delallowed = $permissiontoadd;
2181
2182 print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2183} else {
2184 dol_print_error($db);
2185}
2186
2187// End of page
2188llxFooter();
2189$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 standard extra fields.
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...
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
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...
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.
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.
dolPrintHTML($s)
Return a string ready to be output on HTML page To use text inside an attribute, use can use only dol...
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.