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