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