dolibarr 19.0.3
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-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
5 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
6 * Copyright (C) 2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38
39$langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills', 'orders'));
40
41$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search
42
43$socid = GETPOST('socid', 'int');
44
45$massaction = GETPOST('massaction', 'alpha');
46$toselect = GETPOST('toselect', 'array');
47$optioncss = GETPOST('optioncss', 'alpha');
48$mode = GETPOST('mode', 'alpha');
49
50$diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
51
52$search_ref_rcp = GETPOST("search_ref_rcp");
53$search_ref_liv = GETPOST('search_ref_liv');
54$search_ref_supplier = GETPOST('search_ref_supplier');
55$search_company = GETPOST("search_company");
56$search_town = GETPOST('search_town', 'alpha');
57$search_zip = GETPOST('search_zip', 'alpha');
58$search_state = GETPOST("search_state");
59$search_country = GETPOST("search_country", 'int');
60$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
61$search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
62$search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
63$search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
64$search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
65$search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
66$search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
67$search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
68$search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
69$search_date_create_startday = GETPOST('search_date_create_startday', 'int');
70$search_date_create_startmonth = GETPOST('search_date_create_startmonth', 'int');
71$search_date_create_startyear = GETPOST('search_date_create_startyear', 'int');
72$search_date_create_endday = GETPOST('search_date_create_endday', 'int');
73$search_date_create_endmonth = GETPOST('search_date_create_endmonth', 'int');
74$search_date_create_endyear = GETPOST('search_date_create_endyear', 'int');
75$search_date_create_start = dol_mktime(0, 0, 0, $search_date_create_startmonth, $search_date_create_startday, $search_date_create_startyear); // Use tzserver
76$search_date_create_end = dol_mktime(23, 59, 59, $search_date_create_endmonth, $search_date_create_endday, $search_date_create_endyear);
77$search_billed = GETPOST("search_billed", 'int');
78$search_status = GETPOST('search_status', 'intcomma');
79$search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
80
81$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
82$sortfield = GETPOST('sortfield', 'aZ09comma');
83$sortorder = GETPOST('sortorder', 'aZ09comma');
84$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
85if (!$sortfield) {
86 $sortfield = "e.ref";
87}
88if (!$sortorder) {
89 $sortorder = "DESC";
90}
91if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
92 // If $page is not defined, or '' or -1 or if we click on clear filters
93 $page = 0;
94}
95$offset = $limit * $page;
96$pageprev = $page - 1;
97$pagenext = $page + 1;
98
99
100$object = new Reception($db);
101
102// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
103$hookmanager->initHooks(array('receptionlist'));
104$extrafields = new ExtraFields($db);
105
106// Fetch optionals attributes and labels
107$extrafields->fetch_name_optionals_label($object->table_element);
108$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
109
110// List of fields to search into when doing a "search in all"
111$fieldstosearchall = array(
112 'e.ref'=>"Ref",
113 's.nom'=>"ThirdParty",
114 'e.note_public'=>'NotePublic',
115);
116if (empty($user->socid)) {
117 $fieldstosearchall["e.note_private"] = "NotePrivate";
118}
119
120$checkedtypetiers = 0;
121$arrayfields = array(
122 'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
123 'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
124 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
125 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
126 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
127 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
128 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
129 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
130 'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
131 'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
132 'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
133 'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
134 'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>'getDolGlobalString("WORKFLOW_BILL_ON_RECEPTION") !== "0"')
135);
136
137// Extra fields
138include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
139
140$object->fields = dol_sort_array($object->fields, 'position');
141$arrayfields = dol_sort_array($arrayfields, 'position');
142
143$error = 0;
144
145// Security check
146$receptionid = GETPOST('id', 'int');
147if ($user->socid) {
148 $socid = $user->socid;
149}
150$result = restrictedArea($user, 'reception', $receptionid, '');
151
152
153/*
154 * Actions
155 */
156
157if (GETPOST('cancel', 'alpha')) {
158 $action = 'list';
159 $massaction = '';
160}
161if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_createbills') {
162 $massaction = '';
163}
164
165$parameters = array('socid'=>$socid);
166$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
167if ($reshook < 0) {
168 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
169}
170
171include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
172
173// Purge search criteria
174if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
175 $search_ref_supplier = '';
176 $search_ref_rcp = '';
177 $search_ref_liv = '';
178 $search_company = '';
179 $search_town = '';
180 $search_zip = "";
181 $search_state = "";
182 $search_country = '';
183 $search_type_thirdparty = '';
184 $search_date_delivery_startday = '';
185 $search_date_delivery_startmonth = '';
186 $search_date_delivery_startyear = '';
187 $search_date_delivery_endday = '';
188 $search_date_delivery_endmonth = '';
189 $search_date_delivery_endyear = '';
190 $search_date_delivery_start = '';
191 $search_date_delivery_end = '';
192 $search_date_create_startday = '';
193 $search_date_create_startmonth = '';
194 $search_date_create_startyear = '';
195 $search_date_create_endday = '';
196 $search_date_create_endmonth = '';
197 $search_date_create_endyear = '';
198 $search_date_create_start = '';
199 $search_date_create_end = '';
200 $search_billed = '';
201 $search_status = '';
202 $toselect = array();
203 $search_array_options = array();
204}
205
206if (empty($reshook)) {
207 // Mass actions
208 $objectclass = 'Reception';
209 $objectlabel = 'Receptions';
210 $permissiontoread = $user->rights->reception->lire;
211 $permissiontoadd = $user->rights->reception->creer;
212 $permissiontodelete = $user->rights->reception->supprimer;
213 $uploaddir = $conf->reception->multidir_output[$conf->entity];
214 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
215
216 if ($massaction == 'confirm_createbills') {
217 $receptions = GETPOST('toselect', 'array');
218 $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
219 $validate_invoices = GETPOST('validate_invoices', 'int');
220
221 $errors = array();
222
223 $TFact = array();
224 $TFactThird = array();
225 $TFactThirdNbLines = array();
226
227 $nb_bills_created = 0;
228 $lastid= 0;
229 $lastref = '';
230
231 $db->begin();
232
233 //sort ids to keep order if one bill per third
234 sort($receptions);
235 foreach ($receptions as $id_reception) {
236 $rcp = new Reception($db);
237 // We not allow invoice reception that are in draft status
238 if ($rcp->fetch($id_reception) <= 0 || $rcp->statut == $rcp::STATUS_DRAFT) {
239 $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusReceptionValidatedShort"));
240 $error++;
241 continue;
242 }
243
244 $objecttmp = new FactureFournisseur($db);
245 if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
246 // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
247 $objecttmp = $TFactThird[$rcp->socid];
248
249 // Add all links of this new reception to the existing invoice
250 $objecttmp->fetchObjectLinked();
251 $rcp->fetchObjectLinked();
252 if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
253 foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
254 if (empty($objecttmp->linkedObjectsIds['order_supplier']) || !in_array($value, $objecttmp->linkedObjectsIds['order_supplier'])) { //Dont try to link if already linked
255 $objecttmp->add_object_linked('order_supplier', $value); // add supplier order linked object
256 }
257 }
258 }
259 } else {
260 $cond_reglement_id = 0;
261 $mode_reglement_id = 0;
262 $fk_account = 0;
263 $transport_mode_id = 0;
264 if (!empty($rcp->cond_reglement_id)) {
265 $cond_reglement_id = $rcp->cond_reglement_id;
266 }
267 if (!empty($rcp->mode_reglement_id)) {
268 $mode_reglement_id = $rcp->mode_reglement_id;
269 }
270 if (!empty($rcp->fk_account)) {
271 $fk_account = $rcp->fk_account;
272 }
273 if (!empty($rcp->transport_mode_id)) {
274 $transport_mode_id = $rcp->transport_mode_id;
275 }
276
277 if (empty($cond_reglement_id)
278 || empty($mode_reglement_id)
279 || empty($fk_account)
280 || empty($transport_mode_id)
281 ) {
282 if (!isset($rcp->supplier_order)) {
283 $rcp->fetch_origin();
284 }
285
286 // try to get from source of reception (supplier order)
287 if (!empty($rcp->commandeFournisseur)) {
288 $supplierOrder = $rcp->commandeFournisseur;
289 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
290 $cond_reglement_id = $supplierOrder->cond_reglement_id;
291 }
292 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
293 $mode_reglement_id = $supplierOrder->mode_reglement_id;
294 }
295 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
296 $fk_account = $supplierOrder->fk_account;
297 }
298 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
299 $transport_mode_id = $supplierOrder->transport_mode_id;
300 }
301 }
302
303 // try get from third-party of reception
304 if (!empty($rcp->thirdparty)) {
305 $soc = $rcp->thirdparty;
306 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
307 $cond_reglement_id = $soc->cond_reglement_supplier_id;
308 }
309 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
310 $mode_reglement_id = $soc->mode_reglement_supplier_id;
311 }
312 if (empty($fk_account) && !empty($soc->fk_account)) {
313 $fk_account = $soc->fk_account;
314 }
315 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
316 $transport_mode_id = $soc->transport_mode_id;
317 }
318 }
319 }
320
321 // If we want one invoice per reception or if there is no first invoice yet for this thirdparty.
322 $objecttmp->socid = $rcp->socid;
323 $objecttmp->type = $objecttmp::TYPE_STANDARD;
324 $objecttmp->cond_reglement_id = $cond_reglement_id;
325 $objecttmp->mode_reglement_id = $mode_reglement_id;
326 $objecttmp->fk_account = $fk_account;
327 $objecttmp->transport_mode_id = $transport_mode_id;
328
329 // if the VAT reverse-charge is activated by default in supplier card to resume the information
330 $objecttmp->vat_reverse_charge = $soc->vat_reverse_charge;
331
332 $objecttmp->fk_project = $rcp->fk_project;
333 //$objecttmp->multicurrency_code = $rcp->multicurrency_code;
334 if (empty($createbills_onebythird)) {
335 $objecttmp->ref_supplier = $rcp->ref;
336 } else {
337 // Set a unique value for the invoice for the n reception
338 $objecttmp->ref_supplier = $langs->trans("Reception").' '.dol_print_date(dol_now(), 'dayhourlog').'-'.$rcp->socid;
339 }
340
341 $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
342 if (empty($datefacture)) {
343 $datefacture = dol_now();
344 }
345
346 $objecttmp->date = $datefacture;
347 $objecttmp->origin = 'reception';
348 $objecttmp->origin_id = $id_reception;
349
350 // Auto calculation of date due if not filled by user
351 if (empty($objecttmp->date_echeance)) {
352 $objecttmp->date_echeance = $objecttmp->calculate_date_lim_reglement();
353 }
354
355 $objecttmp->array_options = $rcp->array_options; // Copy extrafields
356
357 // Set $objecttmp->linked_objects with all links order_supplier existing on reception, so same links will be added to the generated supplier invoice
358 $rcp->fetchObjectLinked();
359 if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
360 foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
361 $objecttmp->linked_objects['order_supplier'] = $value;
362 }
363 }
364
365 $res = $objecttmp->create($user); // This should create the supplier invoice + links into $objecttmp->linked_objects + add a link to ->origin_id
366
367 //var_dump($objecttmp->error);exit;
368 if ($res > 0) {
369 $nb_bills_created++;
370 $lastref = $objecttmp->ref;
371 $lastid = $objecttmp->id;
372
373 $TFactThird[$rcp->socid] = $objecttmp;
374 $TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang
375 } else {
376 $langs->load("errors");
377 $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
378 $error++;
379 }
380 }
381
382 if ($objecttmp->id > 0) {
383 $res = $objecttmp->add_object_linked($objecttmp->origin, $id_reception);
384
385 if ($res == 0) {
386 $errors[] = $objecttmp->error;
387 $error++;
388 }
389
390 if (!$error) {
391 $lines = $rcp->lines;
392 if (empty($lines) && method_exists($rcp, 'fetch_lines')) {
393 $rcp->fetch_lines();
394 $lines = $rcp->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 : $lines[$i]->libelle);
402 // If we build one invoice for several reception, we must put the ref of reception on the invoice line
403 if (!empty($createbills_onebythird)) {
404 $desc = dol_concatdesc($desc, $langs->trans("Reception").' '.$rcp->ref.' - '.dol_print_date($rcp->date, 'day'));
405 }
406
407 if ($lines[$i]->subprice < 0) {
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 = $i;
465 //there may already be rows from previous receptions
466 if (!empty($createbills_onebythird)) {
467 $rang = $TFactThirdNbLines[$rcp->socid];
468 }
469
470 $result = $objecttmp->addline(
471 $desc,
472 $lines[$i]->subprice,
473 $lines[$i]->tva_tx,
474 $lines[$i]->localtax1_tx,
475 $lines[$i]->localtax2_tx,
476 $lines[$i]->qty,
477 $lines[$i]->fk_product,
478 $lines[$i]->remise_percent,
479 $date_start,
480 $date_end,
481 0,
482 $lines[$i]->info_bits,
483 'HT',
484 $product_type,
485 $rang,
486 false,
487 0,
488 null,
489 $lines[$i]->rowid,
490 0,
491 $lines[$i]->ref_supplier
492 );
493
494 $rcp->add_object_linked('facture_fourn_det', $result);
495
496 if ($result > 0) {
497 $lineid = $result;
498 if (!empty($createbills_onebythird)) { //increment rang to keep order
499 $TFactThirdNbLines[$rcp->socid]++;
500 }
501 } else {
502 $lineid = 0;
503 $error++;
504 break;
505 }
506 // Defined the new fk_parent_line
507 if ($result > 0 && $lines[$i]->product_type == 9) {
508 $fk_parent_line = $result;
509 }
510 }
511 }
512 }
513 }
514
515 //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
516
517 if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
518 $TFactThird[$rcp->socid] = $objecttmp;
519 } else {
520 $TFact[$objecttmp->id] = $objecttmp;
521 }
522 }
523
524 // Build doc with all invoices
525 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
526 $toselect = array();
527
528 if (!$error && $validate_invoices) {
529 $massaction = $action = 'builddoc';
530 foreach ($TAllFact as &$objecttmp) {
531 $result = $objecttmp->validate($user);
532 if ($result <= 0) {
533 $error++;
534 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
535 break;
536 }
537
538 $id = $objecttmp->id; // For builddoc action
539 $lastref = $objecttmp->ref; // generated ref
540 $object =$objecttmp;
541
542 // Fac builddoc
543 $donotredirect = 1;
544 $upload_dir = $conf->fournisseur->facture->dir_output;
545 $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
546
547 // Call action to build doc
548 $savobject = $object;
549 $object = $objecttmp;
550 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
551 $object = $savobject;
552 }
553
554 $massaction = $action = 'confirm_createbills';
555 }
556
557 if (!$error) {
558 $db->commit();
559
560 if ($nb_bills_created == 1) {
561 $texttoshow = $langs->trans('BillXCreated', '{s1}');
562 $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
563 setEventMessages($texttoshow, null, 'mesgs');
564 } else {
565 setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
566 }
567 } else {
568 $db->rollback();
569
570 $action = 'create';
571 $_GET["origin"] = $_POST["origin"];
572 $_GET["originid"] = $_POST["originid"];
573 setEventMessages($object->error, $errors, 'errors');
574 $error++;
575 }
576 }
577}
578
579
580/*
581 * View
582 */
583
584$now = dol_now();
585
586$form = new Form($db);
587$companystatic = new Societe($db);
588$reception = new Reception($db);
589$formcompany = new FormCompany($db);
590$formfile = new FormFile($db);
591
592
593$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
594llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
595
596$sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as delivery_date, l.date_delivery as date_reception2, e.fk_statut as status, e.billed,";
597$sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
598$sql .= " typent.code as typent_code,";
599$sql .= " state.code_departement as state_code, state.nom as state_name,";
600$sql .= " e.date_creation as date_creation, e.tms as date_update";
601// Add fields from extrafields
602if (!empty($extrafields->attributes[$object->table_element]['label'])) {
603 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
604 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
605 }
606}
607// Add fields from hooks
608$parameters = array();
609$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
610$sql .= $hookmanager->resPrint;
611
612$sqlfields = $sql; // $sql fields to remove for count total
613
614$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
615if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
616 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
617}
618$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
619$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
620$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
621$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
622$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
623$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
624// Add table from hooks
625$parameters = array();
626$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
627$sql .= $hookmanager->resPrint;
628$sql .= " WHERE e.entity IN (".getEntity('reception').")";
629if ($socid) {
630 $sql .= " AND e.fk_soc = ".((int) $socid);
631}
632if ($search_status != '' && $search_status >= 0) {
633 $sql .= " AND e.fk_statut = ".((int) $search_status);
634}
635if ($search_billed != '' && $search_billed >= 0) {
636 $sql .= ' AND e.billed = '.((int) $search_billed);
637}
638if ($search_town) {
639 $sql .= natural_search('s.town', $search_town);
640}
641if ($search_zip) {
642 $sql .= natural_search("s.zip", $search_zip);
643}
644if ($search_state) {
645 $sql .= natural_search("state.nom", $search_state);
646}
647if ($search_country) {
648 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
649}
650if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
651 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
652}
653if ($search_date_delivery_start) {
654 $sql .= " AND e.date_delivery >= '".$db->idate($search_date_delivery_start)."'";
655}
656if ($search_date_delivery_end) {
657 $sql .= " AND e.date_delivery <= '".$db->idate($search_date_delivery_end)."'";
658}
659if ($search_date_create_start) {
660 $sql .= " AND e.date_creation >= '".$db->idate($search_date_create_start)."'";
661}
662if ($search_date_create_end) {
663 $sql .= " AND e.date_creation <= '".$db->idate($search_date_create_end)."'";
664}
665if ($search_ref_rcp) {
666 $sql .= natural_search('e.ref', $search_ref_rcp);
667}
668if ($search_ref_liv) {
669 $sql .= natural_search('l.ref', $search_ref_liv);
670}
671if ($search_company) {
672 $sql .= natural_search('s.nom', $search_company);
673}
674if ($search_ref_supplier) {
675 $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
676}
677if ($search_all) {
678 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
679}
680// Search on sale representative
681/*
682if ($search_sale && $search_sale != '-1') {
683 if ($search_sale == -2) {
684 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
685 } elseif ($search_sale > 0) {
686 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
687 }
688}
689*/
690// Add where from extra fields
691include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
692// Add where from hooks
693$parameters = array();
694$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
695$sql .= $hookmanager->resPrint;
696
697// Add HAVING from hooks
698$parameters = array();
699$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
700$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
701
702$nbtotalofrecords = '';
703if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
704 /* The fast and low memory method to get and count full list converts the sql into a sql count */
705 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
706 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
707 $resql = $db->query($sqlforcount);
708 if ($resql) {
709 $objforcount = $db->fetch_object($resql);
710 $nbtotalofrecords = $objforcount->nbtotalofrecords;
711 } else {
712 dol_print_error($db);
713 }
714
715 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
716 $page = 0;
717 $offset = 0;
718 }
719 $db->free($resql);
720}
721
722// Complete request and execute it with limit
723$sql .= $db->order($sortfield, $sortorder);
724if ($limit) {
725 $sql .= $db->plimit($limit + 1, $offset);
726}
727
728//print $sql;
729$resql = $db->query($sql);
730if (!$resql) {
731 dol_print_error($db);
732 exit;
733}
734
735$num = $db->num_rows($resql);
736
737$reception = new Reception($db);
738
739$arrayofselected = is_array($toselect) ? $toselect : array();
740
741$param = '';
742if (!empty($mode)) {
743 $param .= '&mode='.urlencode($mode);
744}
745if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
746 $param .= '&contextpage='.urlencode($contextpage);
747}
748if ($limit > 0 && $limit != $conf->liste_limit) {
749 $param .= '&limit='.((int) $limit);
750}
751if ($search_all) {
752 $param .= "&search_all=".urlencode($search_all);
753}
754if ($search_ref_rcp) {
755 $param .= "&search_ref_rcp=".urlencode($search_ref_rcp);
756}
757if ($search_ref_liv) {
758 $param .= "&search_ref_liv=".urlencode($search_ref_liv);
759}
760if ($search_company) {
761 $param .= "&search_company=".urlencode($search_company);
762}
763if ($optioncss != '') {
764 $param .= '&optioncss='.urlencode($optioncss);
765}
766if ($search_billed != '' && $search_billed >= 0) {
767 $param .= "&search_billed=".urlencode($search_billed);
768}
769if ($search_town) {
770 $param .= "&search_town=".urlencode($search_town);
771}
772if ($search_zip) {
773 $param .= "&search_zip=".urlencode($search_zip);
774}
775if ($search_state) {
776 $param .= "&search_state=".urlencode($search_state);
777}
778if ($search_status != '') {
779 $param .= "&search_status=".urlencode($search_status);
780}
781if ($search_country) {
782 $param .= "&search_country=".urlencode($search_country);
783}
784if ($search_type_thirdparty) {
785 $param .= "&search_type_thirdparty=".urlencode($search_type_thirdparty);
786}
787if ($search_date_delivery_startday) {
788 $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
789}
790if ($search_date_delivery_startmonth) {
791 $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
792}
793if ($search_date_delivery_startyear) {
794 $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
795}
796if ($search_date_delivery_endday) {
797 $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
798}
799if ($search_date_delivery_endmonth) {
800 $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
801}
802if ($search_date_delivery_endyear) {
803 $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
804}
805if ($search_date_create_startday) {
806 $param .= '&search_date_create_startday='.urlencode($search_date_create_startday);
807}
808if ($search_date_create_startmonth) {
809 $param .= '&search_date_create_startmonth='.urlencode($search_date_create_startmonth);
810}
811if ($search_date_create_startyear) {
812 $param .= '&search_date_create_startyear='.urlencode($search_date_create_startyear);
813}
814if ($search_date_create_endday) {
815 $param .= '&search_date_create_endday='.urlencode($search_date_create_endday);
816}
817if ($search_date_create_endmonth) {
818 $param .= '&search_date_create_endmonth='.urlencode($search_date_create_endmonth);
819}
820if ($search_date_create_endyear) {
821 $param .= '&search_date_create_endyear='.urlencode($search_date_create_endyear);
822}
823if ($search_ref_supplier) {
824 $param .= "&search_ref_supplier=".urlencode($search_ref_supplier);
825}
826// Add $param from extra fields
827if ($search_array_options) {
828 foreach ($search_array_options as $key => $val) {
829 $crit = $val;
830 $tmpkey = preg_replace('/search_options_/', '', $key);
831 if (is_array($val) && array_key_exists('start', $val) && array_key_exists('end', $val)) {
832 // date range from list filters is stored as array('start' => <timestamp>, 'end' => <timestamp>)
833 // start date
834 $param .= '&search_options_'.$tmpkey.'_startyear='.dol_print_date($val['start'], '%Y');
835 $param .= '&search_options_'.$tmpkey.'_startmonth='.dol_print_date($val['start'], '%m');
836 $param .= '&search_options_'.$tmpkey.'_startday='.dol_print_date($val['start'], '%d');
837 $param .= '&search_options_'.$tmpkey.'_starthour='.dol_print_date($val['start'], '%H');
838 $param .= '&search_options_'.$tmpkey.'_startmin='.dol_print_date($val['start'], '%M');
839 // end date
840 $param .= '&search_options_'.$tmpkey.'_endyear='.dol_print_date($val['end'], '%Y');
841 $param .= '&search_options_'.$tmpkey.'_endmonth='.dol_print_date($val['end'], '%m');
842 $param .= '&search_options_'.$tmpkey.'_endday='.dol_print_date($val['end'], '%d');
843 $param .= '&search_options_'.$tmpkey.'_endhour='.dol_print_date($val['end'], '%H');
844 $param .= '&search_options_'.$tmpkey.'_endmin='.dol_print_date($val['end'], '%M');
845 $val = '';
846 }
847 if ($val != '') {
848 $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
849 }
850 }
851}
852
853
854$arrayofmassactions = array(
855 // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
856);
857
858if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
859 $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisReceptions");
860}
861if (in_array($massaction, array('presend', 'createbills'))) {
862 $arrayofmassactions = array();
863}
864$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
865
866// Currently: a sending can't create from sending list
867// $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
868// if (!empty($socid)) $url .= '&socid='.$socid;
869// $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
870$newcardbutton = '';
871$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
872$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
873$newcardbutton .= dolGetButtonTitleSeparator();
874$newcardbutton .= dolGetButtonTitle($langs->trans('NewReception'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/reception/card.php?action=create2', '', $user->hasRight('reception', 'creer'));
875
876$i = 0;
877print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
878if ($optioncss != '') {
879 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
880}
881print '<input type="hidden" name="token" value="'.newToken().'">';
882print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
883print '<input type="hidden" name="action" value="list">';
884print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
885print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
886print '<input type="hidden" name="mode" value="'.$mode.'">';
887
888print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, $newcardbutton, '', $limit, 0, 0, 1);
889
890if ($massaction == 'createbills') {
891 //var_dump($_REQUEST);
892 print '<input type="hidden" name="massaction" value="confirm_createbills">';
893
894 print '<table class="noborder" width="100%" >';
895 print '<tr>';
896 print '<td class="titlefieldmiddle">';
897 print $langs->trans('DateInvoice');
898 print '</td>';
899 print '<td>';
900 print $form->selectDate('', '', '', '', '', '', 1, 1);
901 print '</td>';
902 print '</tr>';
903 print '<tr>';
904 print '<td>';
905 print $langs->trans('CreateOneBillByThird');
906 print '</td>';
907 print '<td>';
908 print $form->selectyesno('createbills_onebythird', '', 1);
909 print '</td>';
910 print '</tr>';
911 print '<tr>';
912 print '<td>';
913 print $langs->trans('ValidateInvoices');
914 print '</td>';
915 print '<td>';
916 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
917 print $form->selectyesno('validate_invoices', 0, 1, 1);
918 print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
919 } else {
920 print $form->selectyesno('validate_invoices', 0, 1);
921 }
922 print '</td>';
923 print '</tr>';
924 print '</table>';
925
926 print '<br>';
927 print '<div class="center">';
928 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisReceptions').'"> ';
929 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
930 print '</div>';
931 print '<br>';
932}
933
934if ($search_all) {
935 foreach ($fieldstosearchall as $key => $val) {
936 $fieldstosearchall[$key] = $langs->trans($val);
937 }
938 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
939}
940
941$moreforfilter = '';
942
943if (!empty($moreforfilter)) {
944 print '<div class="liste_titre liste_titre_bydiv centpercent">';
945 print $moreforfilter;
946 $parameters = array('type'=>$type);
947 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
948 print $hookmanager->resPrint;
949 print '</div>';
950}
951
952$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
953$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', ''));
954if ($massactionbutton) {
955 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields
956}
957
958print '<div class="div-table-responsive">';
959print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
960
961// Fields title search
962// --------------------------------------------------------------------
963print '<tr class="liste_titre_filter">';
964// Action column
965if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
966 print '<td class="liste_titre center maxwidthsearch">';
967 $searchpicto = $form->showFilterButtons('left');
968 print $searchpicto;
969 print '</td>';
970}
971// Ref
972if (!empty($arrayfields['e.ref']['checked'])) {
973 print '<td class="liste_titre">';
974 print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
975 print '</td>';
976}
977// Ref customer
978if (!empty($arrayfields['e.ref_supplier']['checked'])) {
979 print '<td class="liste_titre">';
980 print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
981 print '</td>';
982}
983// Thirdparty
984if (!empty($arrayfields['s.nom']['checked'])) {
985 print '<td class="liste_titre left">';
986 print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
987 print '</td>';
988}
989// Town
990if (!empty($arrayfields['s.town']['checked'])) {
991 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
992}
993// Zip
994if (!empty($arrayfields['s.zip']['checked'])) {
995 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
996}
997// State
998if (!empty($arrayfields['state.nom']['checked'])) {
999 print '<td class="liste_titre">';
1000 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1001 print '</td>';
1002}
1003// Country
1004if (!empty($arrayfields['country.code_iso']['checked'])) {
1005 print '<td class="liste_titre center">';
1006 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1007 print '</td>';
1008}
1009// Company type
1010if (!empty($arrayfields['typent.code']['checked'])) {
1011 print '<td class="liste_titre maxwidthonsmartphone center">';
1012 print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
1013 print '</td>';
1014}
1015// Date delivery planned
1016if (!empty($arrayfields['e.date_delivery']['checked'])) {
1017 print '<td class="liste_titre center">';
1018 print '<div class="nowrapfordate">';
1019 print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1020 print '</div>';
1021 print '<div class="nowrapfordate">';
1022 print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1023 print '</div>';
1024 print '</td>';
1025}
1026if (!empty($arrayfields['l.ref']['checked'])) {
1027 // Delivery ref
1028 print '<td class="liste_titre">';
1029 print '<input class="flat" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
1030 print '</td>';
1031}
1032if (!empty($arrayfields['l.date_delivery']['checked'])) {
1033 // Date received
1034 print '<td class="liste_titre center">&nbsp;</td>';
1035}
1036// Extra fields
1037include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1038
1039// Fields from hook
1040$parameters = array('arrayfields'=>$arrayfields);
1041$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1042print $hookmanager->resPrint;
1043// Date creation
1044if (!empty($arrayfields['e.datec']['checked'])) {
1045 print '<td class="liste_titre center">';
1046 print '<div class="nowrapfordate">';
1047 print $form->selectDate($search_date_create_start ? $search_date_create_start : -1, 'search_date_create_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1048 print '</div>';
1049 print '<div class="nowrapfordate">';
1050 print $form->selectDate($search_date_create_end ? $search_date_create_end : -1, 'search_date_create_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1051 print '</div>';
1052 print '</td>';
1053}
1054// Date modification
1055if (!empty($arrayfields['e.tms']['checked'])) {
1056 print '<td class="liste_titre">';
1057 print '</td>';
1058}
1059// Status
1060if (!empty($arrayfields['e.fk_statut']['checked'])) {
1061 print '<td class="liste_titre right parentonrightofpage">';
1062 print $form->selectarray('search_status', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
1063 print '</td>';
1064}
1065// Status billed
1066if (!empty($arrayfields['e.billed']['checked'])) {
1067 print '<td class="liste_titre maxwidthonsmartphone center">';
1068 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
1069 print '</td>';
1070}
1071// Action column
1072if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1073 print '<td class="liste_titre middle">';
1074 $searchpicto = $form->showFilterButtons();
1075 print $searchpicto;
1076 print '</td>';
1077}
1078print '</tr>'."\n";
1079
1080$totalarray = array();
1081$totalarray['nbfield'] = 0;
1082
1083// Fields title label
1084// --------------------------------------------------------------------
1085print '<tr class="liste_titre">';
1086// Action column
1087if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1088 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1089 $totalarray['nbfield']++;
1090}
1091if (!empty($arrayfields['e.ref']['checked'])) {
1092 print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
1093 $totalarray['nbfield']++;
1094}
1095if (!empty($arrayfields['e.ref_supplier']['checked'])) {
1096 print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
1097 $totalarray['nbfield']++;
1098}
1099if (!empty($arrayfields['s.nom']['checked'])) {
1100 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
1101 $totalarray['nbfield']++;
1102}
1103if (!empty($arrayfields['s.town']['checked'])) {
1104 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1105 $totalarray['nbfield']++;
1106}
1107if (!empty($arrayfields['s.zip']['checked'])) {
1108 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1109 $totalarray['nbfield']++;
1110}
1111if (!empty($arrayfields['state.nom']['checked'])) {
1112 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1113 $totalarray['nbfield']++;
1114}
1115if (!empty($arrayfields['country.code_iso']['checked'])) {
1116 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1117 $totalarray['nbfield']++;
1118}
1119if (!empty($arrayfields['typent.code']['checked'])) {
1120 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1121 $totalarray['nbfield']++;
1122}
1123if (!empty($arrayfields['e.date_delivery']['checked'])) {
1124 print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1125 $totalarray['nbfield']++;
1126}
1127if (!empty($arrayfields['l.ref']['checked'])) {
1128 print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
1129 $totalarray['nbfield']++;
1130}
1131if (!empty($arrayfields['l.date_delivery']['checked'])) {
1132 print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1133 $totalarray['nbfield']++;
1134}
1135// Extra fields
1136include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1137// Hook fields
1138$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, '$totalarray'=>&$totalarray);
1139$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1140print $hookmanager->resPrint;
1141if (!empty($arrayfields['e.datec']['checked'])) {
1142 print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1143 $totalarray['nbfield']++;
1144}
1145if (!empty($arrayfields['e.tms']['checked'])) {
1146 print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1147 $totalarray['nbfield']++;
1148}
1149if (!empty($arrayfields['e.fk_statut']['checked'])) {
1150 print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1151 $totalarray['nbfield']++;
1152}
1153if (!empty($arrayfields['e.billed']['checked'])) {
1154 print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
1155 $totalarray['nbfield']++;
1156}
1157// Action column
1158if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1159 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1160 $totalarray['nbfield']++;
1161}
1162print "</tr>\n";
1163
1164
1165// Loop on record
1166// --------------------------------------------------------------------
1167$i = 0;
1168$savnbfield = $totalarray['nbfield'];
1169$totalarray = array();
1170$totalarray['nbfield'] = 0;
1171$imaxinloop = ($limit ? min($num, $limit) : $num);
1172while ($i < $imaxinloop) {
1173 $obj = $db->fetch_object($resql);
1174 if (empty($obj)) {
1175 break; // Should not happen
1176 }
1177
1178 $reception->id = $obj->rowid;
1179 $reception->ref = $obj->ref;
1180 //$reception->ref_supplier = $obj->ref_supplier;
1181 $reception->statut = $obj->status;
1182 $reception->status = $obj->status;
1183 $reception->socid = $obj->socid;
1184 $reception->billed = $obj->billed;
1185
1186 $reception->fetch_thirdparty();
1187
1188 $object = $reception;
1189
1190 $companystatic->id = $obj->socid;
1191 $companystatic->ref = $obj->name;
1192 $companystatic->name = $obj->name;
1193
1194 if ($mode == 'kanban') {
1195 if ($i == 0) {
1196 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1197 print '<div class="box-flex-container kanban">';
1198 }
1199 $object->date_delivery = $obj->delivery_date;
1200 $object->town = $obj->town;
1201
1202 // Output Kanban
1203 $selected = -1;
1204 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1205 $selected = 0;
1206 if (in_array($object->id, $arrayofselected)) {
1207 $selected = 1;
1208 }
1209 }
1210 print $object->getKanbanView('', array('thirdparty' => $companystatic->getNomUrl(1), 'selected' => $selected));
1211 if ($i == min($num, $limit) - 1) {
1212 print '</div>';
1213 print '</td></tr>';
1214 }
1215 } else {
1216 print '<tr class="oddeven">';
1217
1218 // Action column
1219 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1220 print '<td class="nowrap center">';
1221 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1222 $selected = 0;
1223 if (in_array($obj->rowid, $arrayofselected)) {
1224 $selected = 1;
1225 }
1226 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1227 }
1228 print '</td>';
1229 }
1230 // Ref
1231 if (!empty($arrayfields['e.ref']['checked'])) {
1232 print '<td class="nowraponall">';
1233 print $reception->getNomUrl(1);
1234 $filename = dol_sanitizeFileName($reception->ref);
1235 $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
1236 $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
1237 print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
1238 print "</td>\n";
1239
1240 if (!$i) {
1241 $totalarray['nbfield']++;
1242 }
1243 }
1244
1245 // Ref supplier
1246 if (!empty($arrayfields['e.ref_supplier']['checked'])) {
1247 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1248 print dol_escape_htmltag($obj->ref_supplier);
1249 print "</td>\n";
1250 if (!$i) {
1251 $totalarray['nbfield']++;
1252 }
1253 }
1254
1255 // Third party
1256 if (!empty($arrayfields['s.nom']['checked'])) {
1257 print '<td class="tdoverflowmax150">';
1258 print $companystatic->getNomUrl(1);
1259 print '</td>';
1260 if (!$i) {
1261 $totalarray['nbfield']++;
1262 }
1263 }
1264 // Town
1265 if (!empty($arrayfields['s.town']['checked'])) {
1266 print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">';
1267 print dol_escape_htmltag($obj->town);
1268 print '</td>';
1269 if (!$i) {
1270 $totalarray['nbfield']++;
1271 }
1272 }
1273 // Zip
1274 if (!empty($arrayfields['s.zip']['checked'])) {
1275 print '<td class="nocellnopadd center"">';
1276 print dol_escape_htmltag($obj->zip);
1277 print '</td>';
1278 if (!$i) {
1279 $totalarray['nbfield']++;
1280 }
1281 }
1282 // State
1283 if (!empty($arrayfields['state.nom']['checked'])) {
1284 print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
1285 if (!$i) {
1286 $totalarray['nbfield']++;
1287 }
1288 }
1289 // Country
1290 if (!empty($arrayfields['country.code_iso']['checked'])) {
1291 print '<td class="center">';
1292 $tmparray = getCountry($obj->fk_pays, 'all');
1293 print dol_escape_htmltag($tmparray['label']);
1294 print '</td>';
1295 if (!$i) {
1296 $totalarray['nbfield']++;
1297 }
1298 }
1299 // Type ent
1300 if (!empty($arrayfields['typent.code']['checked'])) {
1301 print '<td class="center">';
1302 if (!isset($typenArray) || empty($typenArray)) {
1303 $typenArray = $formcompany->typent_array(1);
1304 }
1305 if (isset($typenArray[$obj->typent_code])) {
1306 print $typenArray[$obj->typent_code];
1307 }
1308 print '</td>';
1309 if (!$i) {
1310 $totalarray['nbfield']++;
1311 }
1312 }
1313
1314 // Date delivery planed
1315 if (!empty($arrayfields['e.date_delivery']['checked'])) {
1316 print '<td class="center">';
1317 print dol_print_date($db->jdate($obj->delivery_date), "day");
1318 /*$now = time();
1319 if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
1320 {
1321 }*/
1322 print "</td>\n";
1323 if (!$i) {
1324 $totalarray['nbfield']++;
1325 }
1326 }
1327
1328 if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1329 $reception->fetchObjectLinked($reception->id, $reception->element);
1330 $receiving = '';
1331 if (count($reception->linkedObjects['delivery']) > 0) {
1332 $receiving = reset($reception->linkedObjects['delivery']);
1333 }
1334
1335 if (!empty($arrayfields['l.ref']['checked'])) {
1336 // Ref
1337 print '<td>';
1338 print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1339 print '</td>';
1340 }
1341
1342 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1343 // Date received
1344 print '<td class="center">';
1345 print dol_print_date($db->jdate($obj->date_reception), "day");
1346 print '</td>'."\n";
1347 }
1348 }
1349
1350 // Extra fields
1351 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1352
1353 // Fields from hook
1354 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1355 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1356 print $hookmanager->resPrint;
1357 // Date creation
1358 if (!empty($arrayfields['e.datec']['checked'])) {
1359 print '<td class="center nowraponall">';
1360 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');
1361 print '</td>';
1362 if (!$i) {
1363 $totalarray['nbfield']++;
1364 }
1365 }
1366 // Date modification
1367 if (!empty($arrayfields['e.tms']['checked'])) {
1368 print '<td class="center nowraponall">';
1369 print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuserrel');
1370 print '</td>';
1371 if (!$i) {
1372 $totalarray['nbfield']++;
1373 }
1374 }
1375 // Status
1376 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1377 print '<td class="right nowrap">'.$reception->LibStatut($obj->status, 5).'</td>';
1378 if (!$i) {
1379 $totalarray['nbfield']++;
1380 }
1381 }
1382 // Billed
1383 if (!empty($arrayfields['e.billed']['checked'])) {
1384 print '<td class="center">'.yn($obj->billed).'</td>';
1385 if (!$i) {
1386 $totalarray['nbfield']++;
1387 }
1388 }
1389
1390 // Action column
1391 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1392 print '<td class="nowrap center">';
1393 if ($massactionbutton || $massaction) {
1394 // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1395 $selected = 0;
1396 if (in_array($obj->rowid, $arrayofselected)) {
1397 $selected = 1;
1398 }
1399 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1400 }
1401 print '</td>';
1402 }
1403 if (!$i) {
1404 $totalarray['nbfield']++;
1405 }
1406
1407 print "</tr>\n";
1408 }
1409 $i++;
1410}
1411
1412// If no record found
1413if ($num == 0) {
1414 $colspan = 1;
1415 foreach ($arrayfields as $key => $val) {
1416 if (!empty($val['checked'])) {
1417 $colspan++;
1418 }
1419 }
1420 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1421}
1422
1423// Show total line
1424include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1425
1426$parameters = array('arrayfields'=>$arrayfields, 'totalarray' => $totalarray, 'sql'=>$sql);
1427$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1428print $hookmanager->resPrint;
1429
1430print "</table>";
1431print "</div>";
1432print '</form>';
1433$db->free($resql);
1434
1435llxFooter();
1436$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
Definition invoice.php:1907
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.