dolibarr 20.0.0
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 technical object to manage hooks of page. Note that conf->hooks_modules contains 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 $TFactThirdNbLines = array();
230
231 $nb_bills_created = 0;
232 $lastid = 0;
233 $lastref = '';
234
235 $db->begin();
236
237 //sort ids to keep order if one bill per third
238 sort($receptions);
239 foreach ($receptions as $id_reception) {
240 $rcp = new Reception($db);
241 // We not allow invoice reception that are in draft status
242 if ($rcp->fetch($id_reception) <= 0 || $rcp->statut == $rcp::STATUS_DRAFT) {
243 $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusReceptionValidatedShort"));
244 $error++;
245 continue;
246 }
247
248 $objecttmp = new FactureFournisseur($db);
249 if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
250 // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we reuse it.
251 $objecttmp = $TFactThird[$rcp->socid];
252
253 // Add all links of this new reception to the existing invoice
254 $objecttmp->fetchObjectLinked();
255 $rcp->fetchObjectLinked();
256 if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
257 foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
258 if (empty($objecttmp->linkedObjectsIds['order_supplier']) || !in_array($value, $objecttmp->linkedObjectsIds['order_supplier'])) { //Don't try to link if already linked
259 $objecttmp->add_object_linked('order_supplier', $value); // add supplier order linked object
260 }
261 }
262 }
263 } else {
264 $cond_reglement_id = 0;
265 $mode_reglement_id = 0;
266 $fk_account = 0;
267 $transport_mode_id = 0;
268 if (!empty($rcp->cond_reglement_id)) {
269 $cond_reglement_id = $rcp->cond_reglement_id;
270 }
271 if (!empty($rcp->mode_reglement_id)) {
272 $mode_reglement_id = $rcp->mode_reglement_id;
273 }
274 if (!empty($rcp->fk_account)) {
275 $fk_account = $rcp->fk_account;
276 }
277 if (!empty($rcp->transport_mode_id)) {
278 $transport_mode_id = $rcp->transport_mode_id;
279 }
280
281 if (empty($cond_reglement_id)
282 || empty($mode_reglement_id)
283 || empty($fk_account)
284 || empty($transport_mode_id)
285 ) {
286 if (!isset($rcp->supplier_order)) {
287 $rcp->fetch_origin();
288 }
289
290 // try to get from source of reception (supplier order)
291 if (!empty($rcp->origin_object)) {
292 $supplierOrder = $rcp->origin_object;
293 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
294 $cond_reglement_id = $supplierOrder->cond_reglement_id;
295 }
296 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
297 $mode_reglement_id = $supplierOrder->mode_reglement_id;
298 }
299 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
300 $fk_account = $supplierOrder->fk_account;
301 }
302 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
303 $transport_mode_id = $supplierOrder->transport_mode_id;
304 }
305 }
306
307 // try get from third-party of reception
308 if (!empty($rcp->thirdparty)) {
309 $soc = $rcp->thirdparty;
310 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
311 $cond_reglement_id = $soc->cond_reglement_supplier_id;
312 }
313 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
314 $mode_reglement_id = $soc->mode_reglement_supplier_id;
315 }
316 if (empty($fk_account) && !empty($soc->fk_account)) {
317 $fk_account = $soc->fk_account;
318 }
319 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
320 $transport_mode_id = $soc->transport_mode_id;
321 }
322 }
323 }
324
325 // If we want one invoice per reception or if there is no first invoice yet for this thirdparty.
326 $objecttmp->socid = $rcp->socid;
327 $objecttmp->type = $objecttmp::TYPE_STANDARD;
328 $objecttmp->cond_reglement_id = $cond_reglement_id;
329 $objecttmp->mode_reglement_id = $mode_reglement_id;
330 $objecttmp->fk_account = $fk_account;
331 $objecttmp->transport_mode_id = $transport_mode_id;
332
333 // if the VAT reverse-charge is activated by default in supplier card to resume the information
334 $objecttmp->vat_reverse_charge = $soc->vat_reverse_charge;
335
336 $objecttmp->fk_project = $rcp->fk_project;
337 //$objecttmp->multicurrency_code = $rcp->multicurrency_code;
338 if (empty($createbills_onebythird)) {
339 $objecttmp->ref_supplier = $rcp->ref;
340 } else {
341 // Set a unique value for the invoice for the n reception
342 $objecttmp->ref_supplier = $langs->trans("Reception").' '.dol_print_date(dol_now(), 'dayhourlog').'-'.$rcp->socid;
343 }
344
345 $datefacture = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
346 if (empty($datefacture)) {
347 $datefacture = dol_now();
348 }
349
350 $objecttmp->date = $datefacture;
351 $objecttmp->origin = 'reception';
352 $objecttmp->origin_id = $id_reception;
353
354 // Auto calculation of date due if not filled by user
355 if (empty($objecttmp->date_echeance)) {
356 $objecttmp->date_echeance = $objecttmp->calculate_date_lim_reglement();
357 }
358
359 $objecttmp->array_options = $rcp->array_options; // Copy extrafields
360
361 // Set $objecttmp->linked_objects with all links order_supplier existing on reception, so same links will be added to the generated supplier invoice
362 $rcp->fetchObjectLinked();
363 if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
364 foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
365 $objecttmp->linked_objects['order_supplier'] = $value;
366 }
367 }
368
369 $res = $objecttmp->create($user); // This should create the supplier invoice + links into $objecttmp->linked_objects + add a link to ->origin_id
370
371 //var_dump($objecttmp->error);exit;
372 if ($res > 0) {
373 $nb_bills_created++;
374 $lastref = $objecttmp->ref;
375 $lastid = $objecttmp->id;
376
377 $TFactThird[$rcp->socid] = $objecttmp;
378 $TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang
379 } else {
380 $langs->load("errors");
381 $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
382 $error++;
383 }
384 }
385
386 if ($objecttmp->id > 0) {
387 $res = $objecttmp->add_object_linked($objecttmp->origin, $id_reception);
388
389 if ($res == 0) {
390 $errors[] = $objecttmp->error;
391 $error++;
392 }
393
394 if (!$error) {
395 $lines = $rcp->lines;
396 if (empty($lines) && method_exists($rcp, 'fetch_lines')) {
397 $rcp->fetch_lines();
398 $lines = $rcp->lines;
399 }
400
401 $fk_parent_line = 0;
402 $num = count($lines);
403
404 for ($i = 0; $i < $num; $i++) {
405 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
406 // If we build one invoice for several reception, we must put the ref of reception on the invoice line
407 if (!empty($createbills_onebythird)) {
408 $desc = dol_concatdesc($desc, $langs->trans("Reception").' '.$rcp->ref.' - '.dol_print_date($rcp->date, 'day'));
409 }
410
411 if ($lines[$i]->subprice < 0) {
412 // Negative line, we create a discount line
413 $discount = new DiscountAbsolute($db);
414 $discount->fk_soc = $objecttmp->socid;
415 $discount->socid = $objecttmp->socid;
416 $discount->amount_ht = abs($lines[$i]->total_ht);
417 $discount->amount_tva = abs($lines[$i]->total_tva);
418 $discount->amount_ttc = abs($lines[$i]->total_ttc);
419 $discount->tva_tx = $lines[$i]->tva_tx;
420 $discount->fk_user = $user->id;
421 $discount->description = $desc;
422 $discountid = $discount->create($user);
423 if ($discountid > 0) {
424 $result = $objecttmp->insert_discount($discountid);
425 //$result=$discount->link_to_invoice($lineid,$id);
426 } else {
427 setEventMessages($discount->error, $discount->errors, 'errors');
428 $error++;
429 break;
430 }
431 } else {
432 // Positive line
433 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
434 // Date start
435 $date_start = false;
436 if ($lines[$i]->date_debut_prevue) {
437 $date_start = $lines[$i]->date_debut_prevue;
438 }
439 if ($lines[$i]->date_debut_reel) {
440 $date_start = $lines[$i]->date_debut_reel;
441 }
442 if ($lines[$i]->date_start) {
443 $date_start = $lines[$i]->date_start;
444 }
445 //Date end
446 $date_end = false;
447 if ($lines[$i]->date_fin_prevue) {
448 $date_end = $lines[$i]->date_fin_prevue;
449 }
450 if ($lines[$i]->date_fin_reel) {
451 $date_end = $lines[$i]->date_fin_reel;
452 }
453 if ($lines[$i]->date_end) {
454 $date_end = $lines[$i]->date_end;
455 }
456 // Reset fk_parent_line for no child products and special product
457 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
458 $fk_parent_line = 0;
459 }
460
461 // Extrafields
462 if (method_exists($lines[$i], 'fetch_optionals')) {
463 $lines[$i]->fetch_optionals();
464 $array_options = $lines[$i]->array_options;
465 }
466
467 $objecttmp->context['createfromclone'] = 'createfromclone';
468
469 $rang = $i;
470 //there may already be rows from previous receptions
471 if (!empty($createbills_onebythird)) {
472 $rang = $TFactThirdNbLines[$rcp->socid];
473 }
474
475 $result = $objecttmp->addline(
476 $desc,
477 $lines[$i]->subprice,
478 $lines[$i]->tva_tx,
479 $lines[$i]->localtax1_tx,
480 $lines[$i]->localtax2_tx,
481 $lines[$i]->qty,
482 $lines[$i]->fk_product,
483 $lines[$i]->remise_percent,
484 $date_start,
485 $date_end,
486 0,
487 $lines[$i]->info_bits,
488 'HT',
489 $product_type,
490 $rang,
491 false,
492 array(),
493 null,
494 $lines[$i]->rowid,
495 0,
496 $lines[$i]->ref_supplier
497 );
498
499 $rcp->add_object_linked('facture_fourn_det', $result);
500
501 if ($result > 0) {
502 $lineid = $result;
503 if (!empty($createbills_onebythird)) { //increment rang to keep order
504 $TFactThirdNbLines[$rcp->socid]++;
505 }
506 } else {
507 $lineid = 0;
508 $error++;
509 break;
510 }
511 // Defined the new fk_parent_line
512 if ($result > 0 && $lines[$i]->product_type == 9) {
513 $fk_parent_line = $result;
514 }
515 }
516 }
517 }
518 }
519
520 //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
521
522 if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
523 $TFactThird[$rcp->socid] = $objecttmp;
524 } else {
525 $TFact[$objecttmp->id] = $objecttmp;
526 }
527 }
528
529 // Build doc with all invoices
530 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
531 $toselect = array();
532
533 if (!$error && $validate_invoices) {
534 $massaction = $action = 'builddoc';
535 foreach ($TAllFact as &$objecttmp) {
536 $result = $objecttmp->validate($user);
537 if ($result <= 0) {
538 $error++;
539 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
540 break;
541 }
542
543 $id = $objecttmp->id; // For builddoc action
544 $lastref = $objecttmp->ref; // generated ref
545 $object = $objecttmp;
546
547 // Fac builddoc
548 $donotredirect = 1;
549 $upload_dir = $conf->fournisseur->facture->dir_output;
550 $permissiontoadd = ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer'));
551
552 // Call action to build doc
553 $savobject = $object;
554 $object = $objecttmp;
555 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
556 $object = $savobject;
557 }
558
559 $massaction = $action = 'confirm_createbills';
560 }
561
562 if (!$error) {
563 $db->commit();
564
565 if ($nb_bills_created == 1) {
566 $texttoshow = $langs->trans('BillXCreated', '{s1}');
567 $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode((string) ($lastid)).'">'.$lastref.'</a>', $texttoshow);
568 setEventMessages($texttoshow, null, 'mesgs');
569 } else {
570 setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
571 }
572 } else {
573 $db->rollback();
574
575 $action = 'create';
576 $_GET["origin"] = $_POST["origin"]; // Keep this ?
577 $_GET["originid"] = $_POST["originid"]; // Keep this ?
578 setEventMessages($object->error, $errors, 'errors');
579 $error++;
580 }
581 }
582}
583
584
585/*
586 * View
587 */
588
589$now = dol_now();
590
591$form = new Form($db);
592$companystatic = new Societe($db);
593$reception = new Reception($db);
594$formcompany = new FormCompany($db);
595$formfile = new FormFile($db);
596
597
598$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
599llxHeader('', $langs->trans('ListOfReceptions'), $helpurl, '', 0, 0, '', '', '', 'bodyforlist mod-reception page-list');
600
601$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,";
602$sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
603$sql .= " typent.code as typent_code,";
604$sql .= " state.code_departement as state_code, state.nom as state_name,";
605$sql .= " e.date_creation as date_creation, e.tms as date_modification";
606// Add fields from extrafields
607if (!empty($extrafields->attributes[$object->table_element]['label'])) {
608 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
609 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
610 }
611}
612// Add fields from hooks
613$parameters = array();
614$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
615$sql .= $hookmanager->resPrint;
616
617$sqlfields = $sql; // $sql fields to remove for count total
618
619$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
620if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
621 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
622}
623$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
624$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
625$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
626$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
627$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
628$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
629// Add table from hooks
630$parameters = array();
631$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
632$sql .= $hookmanager->resPrint;
633$sql .= " WHERE e.entity IN (".getEntity('reception').")";
634if ($socid) {
635 $sql .= " AND e.fk_soc = ".((int) $socid);
636}
637if ($search_status != '' && $search_status >= 0) {
638 $sql .= " AND e.fk_statut = ".((int) $search_status);
639}
640if ($search_billed != '' && $search_billed >= 0) {
641 $sql .= ' AND e.billed = '.((int) $search_billed);
642}
643if ($search_town) {
644 $sql .= natural_search('s.town', $search_town);
645}
646if ($search_zip) {
647 $sql .= natural_search("s.zip", $search_zip);
648}
649if ($search_state) {
650 $sql .= natural_search("state.nom", $search_state);
651}
652if ($search_country) {
653 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
654}
655if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
656 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
657}
658if ($search_date_delivery_start) {
659 $sql .= " AND e.date_delivery >= '".$db->idate($search_date_delivery_start)."'";
660}
661if ($search_date_delivery_end) {
662 $sql .= " AND e.date_delivery <= '".$db->idate($search_date_delivery_end)."'";
663}
664if ($search_date_create_start) {
665 $sql .= " AND e.date_creation >= '".$db->idate($search_date_create_start)."'";
666}
667if ($search_date_create_end) {
668 $sql .= " AND e.date_creation <= '".$db->idate($search_date_create_end)."'";
669}
670if ($search_ref_rcp) {
671 $sql .= natural_search('e.ref', $search_ref_rcp);
672}
673if ($search_ref_liv) {
674 $sql .= natural_search('l.ref', $search_ref_liv);
675}
676if ($search_company) {
677 $sql .= natural_search('s.nom', $search_company);
678}
679if ($search_ref_supplier) {
680 $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
681}
682if ($search_all) {
683 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
684}
685// Search on sale representative
686/*
687if ($search_sale && $search_sale != '-1') {
688 if ($search_sale == -2) {
689 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
690 } elseif ($search_sale > 0) {
691 $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).")";
692 }
693}
694*/
695// Add where from extra fields
696include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
697// Add where from hooks
698$parameters = array();
699$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
700$sql .= $hookmanager->resPrint;
701
702// Add HAVING from hooks
703$parameters = array();
704$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
705$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
706
707$nbtotalofrecords = '';
708if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
709 /* The fast and low memory method to get and count full list converts the sql into a sql count */
710 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
711 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
712 $resql = $db->query($sqlforcount);
713 if ($resql) {
714 $objforcount = $db->fetch_object($resql);
715 $nbtotalofrecords = $objforcount->nbtotalofrecords;
716 } else {
717 dol_print_error($db);
718 }
719
720 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
721 $page = 0;
722 $offset = 0;
723 }
724 $db->free($resql);
725}
726
727// Complete request and execute it with limit
728$sql .= $db->order($sortfield, $sortorder);
729if ($limit) {
730 $sql .= $db->plimit($limit + 1, $offset);
731}
732
733//print $sql;
734$resql = $db->query($sql);
735if (!$resql) {
736 dol_print_error($db);
737 exit;
738}
739
740$num = $db->num_rows($resql);
741
742$reception = new Reception($db);
743
744$arrayofselected = is_array($toselect) ? $toselect : array();
745
746$param = '';
747if (!empty($mode)) {
748 $param .= '&mode='.urlencode($mode);
749}
750if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
751 $param .= '&contextpage='.urlencode($contextpage);
752}
753if ($limit > 0 && $limit != $conf->liste_limit) {
754 $param .= '&limit='.((int) $limit);
755}
756if ($search_all) {
757 $param .= "&search_all=".urlencode($search_all);
758}
759if ($search_ref_rcp) {
760 $param .= "&search_ref_rcp=".urlencode($search_ref_rcp);
761}
762if ($search_ref_liv) {
763 $param .= "&search_ref_liv=".urlencode($search_ref_liv);
764}
765if ($search_company) {
766 $param .= "&search_company=".urlencode($search_company);
767}
768if ($optioncss != '') {
769 $param .= '&optioncss='.urlencode($optioncss);
770}
771if ($search_billed != '' && $search_billed >= 0) {
772 $param .= "&search_billed=".urlencode((string) ($search_billed));
773}
774if ($search_town) {
775 $param .= "&search_town=".urlencode($search_town);
776}
777if ($search_zip) {
778 $param .= "&search_zip=".urlencode($search_zip);
779}
780if ($search_state) {
781 $param .= "&search_state=".urlencode($search_state);
782}
783if ($search_status != '') {
784 $param .= "&search_status=".urlencode($search_status);
785}
786if ($search_country) {
787 $param .= "&search_country=".urlencode((string) ($search_country));
788}
789if ($search_type_thirdparty) {
790 $param .= "&search_type_thirdparty=".urlencode((string) ($search_type_thirdparty));
791}
792if ($search_date_delivery_startday) {
793 $param .= '&search_date_delivery_startday='.urlencode((string) ($search_date_delivery_startday));
794}
795if ($search_date_delivery_startmonth) {
796 $param .= '&search_date_delivery_startmonth='.urlencode((string) ($search_date_delivery_startmonth));
797}
798if ($search_date_delivery_startyear) {
799 $param .= '&search_date_delivery_startyear='.urlencode((string) ($search_date_delivery_startyear));
800}
801if ($search_date_delivery_endday) {
802 $param .= '&search_date_delivery_endday='.urlencode((string) ($search_date_delivery_endday));
803}
804if ($search_date_delivery_endmonth) {
805 $param .= '&search_date_delivery_endmonth='.urlencode((string) ($search_date_delivery_endmonth));
806}
807if ($search_date_delivery_endyear) {
808 $param .= '&search_date_delivery_endyear='.urlencode((string) ($search_date_delivery_endyear));
809}
810if ($search_date_create_startday) {
811 $param .= '&search_date_create_startday='.urlencode((string) ($search_date_create_startday));
812}
813if ($search_date_create_startmonth) {
814 $param .= '&search_date_create_startmonth='.urlencode((string) ($search_date_create_startmonth));
815}
816if ($search_date_create_startyear) {
817 $param .= '&search_date_create_startyear='.urlencode((string) ($search_date_create_startyear));
818}
819if ($search_date_create_endday) {
820 $param .= '&search_date_create_endday='.urlencode((string) ($search_date_create_endday));
821}
822if ($search_date_create_endmonth) {
823 $param .= '&search_date_create_endmonth='.urlencode((string) ($search_date_create_endmonth));
824}
825if ($search_date_create_endyear) {
826 $param .= '&search_date_create_endyear='.urlencode((string) ($search_date_create_endyear));
827}
828if ($search_ref_supplier) {
829 $param .= "&search_ref_supplier=".urlencode($search_ref_supplier);
830}
831// Add $param from extra fields
832if ($search_array_options) {
833 foreach ($search_array_options as $key => $val) {
834 $crit = $val;
835 $tmpkey = preg_replace('/search_options_/', '', $key);
836 if (is_array($val) && array_key_exists('start', $val) && array_key_exists('end', $val)) {
837 // date range from list filters is stored as array('start' => <timestamp>, 'end' => <timestamp>)
838 // start date
839 $param .= '&search_options_'.$tmpkey.'_startyear='.dol_print_date($val['start'], '%Y');
840 $param .= '&search_options_'.$tmpkey.'_startmonth='.dol_print_date($val['start'], '%m');
841 $param .= '&search_options_'.$tmpkey.'_startday='.dol_print_date($val['start'], '%d');
842 $param .= '&search_options_'.$tmpkey.'_starthour='.dol_print_date($val['start'], '%H');
843 $param .= '&search_options_'.$tmpkey.'_startmin='.dol_print_date($val['start'], '%M');
844 // end date
845 $param .= '&search_options_'.$tmpkey.'_endyear='.dol_print_date($val['end'], '%Y');
846 $param .= '&search_options_'.$tmpkey.'_endmonth='.dol_print_date($val['end'], '%m');
847 $param .= '&search_options_'.$tmpkey.'_endday='.dol_print_date($val['end'], '%d');
848 $param .= '&search_options_'.$tmpkey.'_endhour='.dol_print_date($val['end'], '%H');
849 $param .= '&search_options_'.$tmpkey.'_endmin='.dol_print_date($val['end'], '%M');
850 $val = '';
851 }
852 if ($val != '') {
853 $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
854 }
855 }
856}
857
858
859$arrayofmassactions = array(
860 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
861 // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
862);
863
864if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
865 $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisReceptions");
866}
867if (in_array($massaction, array('presend', 'createbills'))) {
868 $arrayofmassactions = array();
869}
870$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
871
872// Currently: a sending can't create from sending list
873// $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
874// if (!empty($socid)) $url .= '&socid='.$socid;
875// $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
876$newcardbutton = '';
877$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'));
878$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'));
879$newcardbutton .= dolGetButtonTitleSeparator();
880$newcardbutton .= dolGetButtonTitle($langs->trans('NewReception'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/reception/card.php?action=create2', '', $user->hasRight('reception', 'creer'));
881
882$i = 0;
883print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
884if ($optioncss != '') {
885 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
886}
887print '<input type="hidden" name="token" value="'.newToken().'">';
888print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
889print '<input type="hidden" name="action" value="list">';
890print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
891print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
892print '<input type="hidden" name="mode" value="'.$mode.'">';
893
894// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
895print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, $newcardbutton, '', $limit, 0, 0, 1);
896
897if ($massaction == 'createbills') {
898 //var_dump($_REQUEST);
899 print '<input type="hidden" name="massaction" value="confirm_createbills">';
900
901 print '<table class="noborder" width="100%" >';
902 print '<tr>';
903 print '<td class="titlefieldmiddle">';
904 print $langs->trans('DateInvoice');
905 print '</td>';
906 print '<td>';
907 print $form->selectDate('', '', 0, 0, 0, '', 1, 1);
908 print '</td>';
909 print '</tr>';
910 print '<tr>';
911 print '<td>';
912 print $langs->trans('CreateOneBillByThird');
913 print '</td>';
914 print '<td>';
915 print $form->selectyesno('createbills_onebythird', '', 1);
916 print '</td>';
917 print '</tr>';
918 print '<tr>';
919 print '<td>';
920 print $langs->trans('ValidateInvoices');
921 print '</td>';
922 print '<td>';
923 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
924 print $form->selectyesno('validate_invoices', 0, 1, 1);
925 print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
926 } else {
927 print $form->selectyesno('validate_invoices', 0, 1);
928 }
929 print '</td>';
930 print '</tr>';
931 print '</table>';
932
933 print '<br>';
934 print '<div class="center">';
935 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisReceptions').'"> ';
936 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
937 print '</div>';
938 print '<br>';
939}
940
941if ($search_all) {
942 foreach ($fieldstosearchall as $key => $val) {
943 $fieldstosearchall[$key] = $langs->trans($val);
944 }
945 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
946}
947
948$moreforfilter = '';
949
950if (!empty($moreforfilter)) {
951 print '<div class="liste_titre liste_titre_bydiv centpercent">';
952 print $moreforfilter;
953 $parameters = array('type' => $type);
954 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
955 print $hookmanager->resPrint;
956 print '</div>';
957}
958
959$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
960$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
961if ($massactionbutton) {
962 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields
963}
964
965print '<div class="div-table-responsive">';
966print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
967
968// Fields title search
969// --------------------------------------------------------------------
970print '<tr class="liste_titre_filter">';
971// Action column
972if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
973 print '<td class="liste_titre center maxwidthsearch">';
974 $searchpicto = $form->showFilterButtons('left');
975 print $searchpicto;
976 print '</td>';
977}
978// Ref
979if (!empty($arrayfields['e.ref']['checked'])) {
980 print '<td class="liste_titre">';
981 print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
982 print '</td>';
983}
984// Ref customer
985if (!empty($arrayfields['e.ref_supplier']['checked'])) {
986 print '<td class="liste_titre">';
987 print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
988 print '</td>';
989}
990// Thirdparty
991if (!empty($arrayfields['s.nom']['checked'])) {
992 print '<td class="liste_titre left">';
993 print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
994 print '</td>';
995}
996// Town
997if (!empty($arrayfields['s.town']['checked'])) {
998 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
999}
1000// Zip
1001if (!empty($arrayfields['s.zip']['checked'])) {
1002 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
1003}
1004// State
1005if (!empty($arrayfields['state.nom']['checked'])) {
1006 print '<td class="liste_titre">';
1007 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1008 print '</td>';
1009}
1010// Country
1011if (!empty($arrayfields['country.code_iso']['checked'])) {
1012 print '<td class="liste_titre center">';
1013 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1014 print '</td>';
1015}
1016// Company type
1017if (!empty($arrayfields['typent.code']['checked'])) {
1018 print '<td class="liste_titre maxwidthonsmartphone center">';
1019 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);
1020 print '</td>';
1021}
1022// Date delivery planned
1023if (!empty($arrayfields['e.date_delivery']['checked'])) {
1024 print '<td class="liste_titre center">';
1025 print '<div class="nowrapfordate">';
1026 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'));
1027 print '</div>';
1028 print '<div class="nowrapfordate">';
1029 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'));
1030 print '</div>';
1031 print '</td>';
1032}
1033if (!empty($arrayfields['l.ref']['checked'])) {
1034 // Delivery ref
1035 print '<td class="liste_titre">';
1036 print '<input class="flat" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
1037 print '</td>';
1038}
1039if (!empty($arrayfields['l.date_delivery']['checked'])) {
1040 // Date received
1041 print '<td class="liste_titre center">&nbsp;</td>';
1042}
1043// Extra fields
1044include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1045
1046// Fields from hook
1047$parameters = array('arrayfields' => $arrayfields);
1048$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1049print $hookmanager->resPrint;
1050// Date creation
1051if (!empty($arrayfields['e.datec']['checked'])) {
1052 print '<td class="liste_titre center">';
1053 print '<div class="nowrapfordate">';
1054 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'));
1055 print '</div>';
1056 print '<div class="nowrapfordate">';
1057 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'));
1058 print '</div>';
1059 print '</td>';
1060}
1061// Date modification
1062if (!empty($arrayfields['e.tms']['checked'])) {
1063 print '<td class="liste_titre">';
1064 print '</td>';
1065}
1066// Status
1067if (!empty($arrayfields['e.fk_statut']['checked'])) {
1068 print '<td class="liste_titre right parentonrightofpage">';
1069 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');
1070 print '</td>';
1071}
1072// Status billed
1073if (!empty($arrayfields['e.billed']['checked'])) {
1074 print '<td class="liste_titre maxwidthonsmartphone center">';
1075 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
1076 print '</td>';
1077}
1078// Action column
1079if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1080 print '<td class="liste_titre middle">';
1081 $searchpicto = $form->showFilterButtons();
1082 print $searchpicto;
1083 print '</td>';
1084}
1085print '</tr>'."\n";
1086
1087$totalarray = array();
1088$totalarray['nbfield'] = 0;
1089
1090// Fields title label
1091// --------------------------------------------------------------------
1092print '<tr class="liste_titre">';
1093// Action column
1094if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1095 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1096 $totalarray['nbfield']++;
1097}
1098if (!empty($arrayfields['e.ref']['checked'])) {
1099 print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
1100 $totalarray['nbfield']++;
1101}
1102if (!empty($arrayfields['e.ref_supplier']['checked'])) {
1103 print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
1104 $totalarray['nbfield']++;
1105}
1106if (!empty($arrayfields['s.nom']['checked'])) {
1107 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
1108 $totalarray['nbfield']++;
1109}
1110if (!empty($arrayfields['s.town']['checked'])) {
1111 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1112 $totalarray['nbfield']++;
1113}
1114if (!empty($arrayfields['s.zip']['checked'])) {
1115 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1116 $totalarray['nbfield']++;
1117}
1118if (!empty($arrayfields['state.nom']['checked'])) {
1119 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1120 $totalarray['nbfield']++;
1121}
1122if (!empty($arrayfields['country.code_iso']['checked'])) {
1123 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1124 $totalarray['nbfield']++;
1125}
1126if (!empty($arrayfields['typent.code']['checked'])) {
1127 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1128 $totalarray['nbfield']++;
1129}
1130if (!empty($arrayfields['e.date_delivery']['checked'])) {
1131 print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1132 $totalarray['nbfield']++;
1133}
1134if (!empty($arrayfields['l.ref']['checked'])) {
1135 print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
1136 $totalarray['nbfield']++;
1137}
1138if (!empty($arrayfields['l.date_delivery']['checked'])) {
1139 print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1140 $totalarray['nbfield']++;
1141}
1142// Extra fields
1143include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1144// Hook fields
1145$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, '$totalarray' => &$totalarray);
1146$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1147print $hookmanager->resPrint;
1148if (!empty($arrayfields['e.datec']['checked'])) {
1149 print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1150 $totalarray['nbfield']++;
1151}
1152if (!empty($arrayfields['e.tms']['checked'])) {
1153 print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1154 $totalarray['nbfield']++;
1155}
1156if (!empty($arrayfields['e.fk_statut']['checked'])) {
1157 print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1158 $totalarray['nbfield']++;
1159}
1160if (!empty($arrayfields['e.billed']['checked'])) {
1161 print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
1162 $totalarray['nbfield']++;
1163}
1164// Action column
1165if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1166 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1167 $totalarray['nbfield']++;
1168}
1169print "</tr>\n";
1170
1171
1172// Loop on record
1173// --------------------------------------------------------------------
1174$i = 0;
1175$savnbfield = $totalarray['nbfield'];
1176$totalarray = array();
1177$totalarray['nbfield'] = 0;
1178$imaxinloop = ($limit ? min($num, $limit) : $num);
1179while ($i < $imaxinloop) {
1180 $obj = $db->fetch_object($resql);
1181 if (empty($obj)) {
1182 break; // Should not happen
1183 }
1184
1185 $reception->id = $obj->rowid;
1186 $reception->ref = $obj->ref;
1187 //$reception->ref_supplier = $obj->ref_supplier;
1188 $reception->statut = $obj->status;
1189 $reception->status = $obj->status;
1190 $reception->socid = $obj->socid;
1191 $reception->billed = $obj->billed;
1192
1193 $reception->fetch_thirdparty();
1194
1195 $object = $reception;
1196
1197 $companystatic->id = $obj->socid;
1198 $companystatic->ref = $obj->name;
1199 $companystatic->name = $obj->name;
1200
1201 if ($mode == 'kanban') {
1202 if ($i == 0) {
1203 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1204 print '<div class="box-flex-container kanban">';
1205 }
1206 $object->date_delivery = $obj->delivery_date;
1207 $object->town = $obj->town;
1208
1209 // Output Kanban
1210 $selected = -1;
1211 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1212 $selected = 0;
1213 if (in_array($object->id, $arrayofselected)) {
1214 $selected = 1;
1215 }
1216 }
1217 print $object->getKanbanView('', array('thirdparty' => $companystatic->getNomUrl(1), 'selected' => $selected));
1218 if ($i == min($num, $limit) - 1) {
1219 print '</div>';
1220 print '</td></tr>';
1221 }
1222 } else {
1223 print '<tr class="oddeven">';
1224
1225 // Action column
1226 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1227 print '<td class="nowrap center">';
1228 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1229 $selected = 0;
1230 if (in_array($obj->rowid, $arrayofselected)) {
1231 $selected = 1;
1232 }
1233 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1234 }
1235 print '</td>';
1236 }
1237 // Ref
1238 if (!empty($arrayfields['e.ref']['checked'])) {
1239 print '<td class="nowraponall">';
1240 print $reception->getNomUrl(1);
1241 $filename = dol_sanitizeFileName($reception->ref);
1242 $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
1243 $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
1244 print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
1245 print "</td>\n";
1246
1247 if (!$i) {
1248 $totalarray['nbfield']++;
1249 }
1250 }
1251
1252 // Ref supplier
1253 if (!empty($arrayfields['e.ref_supplier']['checked'])) {
1254 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1255 print dol_escape_htmltag($obj->ref_supplier);
1256 print "</td>\n";
1257 if (!$i) {
1258 $totalarray['nbfield']++;
1259 }
1260 }
1261
1262 // Third party
1263 if (!empty($arrayfields['s.nom']['checked'])) {
1264 print '<td class="tdoverflowmax150">';
1265 print $companystatic->getNomUrl(1);
1266 print '</td>';
1267 if (!$i) {
1268 $totalarray['nbfield']++;
1269 }
1270 }
1271 // Town
1272 if (!empty($arrayfields['s.town']['checked'])) {
1273 print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">';
1274 print dol_escape_htmltag($obj->town);
1275 print '</td>';
1276 if (!$i) {
1277 $totalarray['nbfield']++;
1278 }
1279 }
1280 // Zip
1281 if (!empty($arrayfields['s.zip']['checked'])) {
1282 print '<td class="nocellnopadd center"">';
1283 print dol_escape_htmltag($obj->zip);
1284 print '</td>';
1285 if (!$i) {
1286 $totalarray['nbfield']++;
1287 }
1288 }
1289 // State
1290 if (!empty($arrayfields['state.nom']['checked'])) {
1291 print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
1292 if (!$i) {
1293 $totalarray['nbfield']++;
1294 }
1295 }
1296 // Country
1297 if (!empty($arrayfields['country.code_iso']['checked'])) {
1298 print '<td class="center">';
1299 $tmparray = getCountry($obj->fk_pays, 'all');
1300 print dol_escape_htmltag($tmparray['label']);
1301 print '</td>';
1302 if (!$i) {
1303 $totalarray['nbfield']++;
1304 }
1305 }
1306 // Type ent
1307 if (!empty($arrayfields['typent.code']['checked'])) {
1308 print '<td class="center">';
1309 if (!isset($typenArray) || empty($typenArray)) {
1310 $typenArray = $formcompany->typent_array(1);
1311 }
1312 if (isset($typenArray[$obj->typent_code])) {
1313 print $typenArray[$obj->typent_code];
1314 }
1315 print '</td>';
1316 if (!$i) {
1317 $totalarray['nbfield']++;
1318 }
1319 }
1320
1321 // Date delivery planned
1322 if (!empty($arrayfields['e.date_delivery']['checked'])) {
1323 print '<td class="center">';
1324 print dol_print_date($db->jdate($obj->delivery_date), "day");
1325 /*$now = time();
1326 if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
1327 {
1328 }*/
1329 print "</td>\n";
1330 if (!$i) {
1331 $totalarray['nbfield']++;
1332 }
1333 }
1334
1335 if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1336 $reception->fetchObjectLinked($reception->id, $reception->element);
1337 $receiving = '';
1338 if (count($reception->linkedObjects['delivery']) > 0) {
1339 $receiving = reset($reception->linkedObjects['delivery']);
1340 }
1341
1342 if (!empty($arrayfields['l.ref']['checked'])) {
1343 // Ref
1344 print '<td>';
1345 print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1346 print '</td>';
1347 }
1348
1349 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1350 // Date received
1351 print '<td class="center">';
1352 print dol_print_date($db->jdate($obj->date_reception), "day");
1353 print '</td>'."\n";
1354 }
1355 }
1356
1357 // Extra fields
1358 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1359
1360 // Fields from hook
1361 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1362 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1363 print $hookmanager->resPrint;
1364 // Date creation
1365 if (!empty($arrayfields['e.datec']['checked'])) {
1366 print '<td class="center nowraponall">';
1367 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');
1368 print '</td>';
1369 if (!$i) {
1370 $totalarray['nbfield']++;
1371 }
1372 }
1373 // Date modification
1374 if (!empty($arrayfields['e.tms']['checked'])) {
1375 print '<td class="center nowraponall">';
1376 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuserrel');
1377 print '</td>';
1378 if (!$i) {
1379 $totalarray['nbfield']++;
1380 }
1381 }
1382 // Status
1383 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1384 print '<td class="right nowrap">'.$reception->LibStatut($obj->status, 5).'</td>';
1385 if (!$i) {
1386 $totalarray['nbfield']++;
1387 }
1388 }
1389 // Billed
1390 if (!empty($arrayfields['e.billed']['checked'])) {
1391 print '<td class="center">'.yn($obj->billed).'</td>';
1392 if (!$i) {
1393 $totalarray['nbfield']++;
1394 }
1395 }
1396
1397 // Action column
1398 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1399 print '<td class="nowrap center">';
1400 if ($massactionbutton || $massaction) {
1401 // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1402 $selected = 0;
1403 if (in_array($obj->rowid, $arrayofselected)) {
1404 $selected = 1;
1405 }
1406 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1407 }
1408 print '</td>';
1409 }
1410 if (!$i) {
1411 $totalarray['nbfield']++;
1412 }
1413
1414 print "</tr>\n";
1415 }
1416 $i++;
1417}
1418
1419// If no record found
1420if ($num == 0) {
1421 $colspan = 1;
1422 foreach ($arrayfields as $key => $val) {
1423 if (!empty($val['checked'])) {
1424 $colspan++;
1425 }
1426 }
1427 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1428}
1429
1430// Show total line
1431include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1432
1433$parameters = array('arrayfields' => $arrayfields, 'totalarray' => $totalarray, 'sql' => $sql);
1434$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1435print $hookmanager->resPrint;
1436
1437print "</table>";
1438print "</div>";
1439print '</form>';
1440
1441$db->free($resql);
1442
1443$hidegeneratedfilelistifempty = 1;
1444if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1445 $hidegeneratedfilelistifempty = 0;
1446}
1447
1448// Show list of available documents
1449$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1450$urlsource .= str_replace('&amp;', '&', $param);
1451
1452$filedir = $diroutputmassaction;
1453$genallowed = $user->hasRight('reception', 'lire');
1454$delallowed = $user->hasRight('reception', 'creer');
1455$title = '';
1456
1457print $formfile->showdocuments('massfilesarea_receipts', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1458
1459// End of page
1460llxFooter();
1461$db->close();
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()
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=null, $outputlangs=null, $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 information (by default a local PHP server timestamp) Rep...
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.
print_barre_liste($title, $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.
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.
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 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.