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