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