forked from Dolibarr/dolibarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
781 lines (667 loc) · 28 KB
/
index.php
File metadata and controls
781 lines (667 loc) · 28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015-2020 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
* Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2021-2023 Frédéric France <frederic.france@netlogic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/index.php
* \ingroup compta
* \brief Main page of accountancy area
*/
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
// L'espace compta/treso doit toujours etre actif car c'est un espace partage
// par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
// de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
// est protegee par le droit qui va bien du module concerne.
//if (!$user->rights->compta->general->lire)
// accessforbidden();
// Load translation files required by the page
$langs->loadLangs(array('compta', 'bills'));
if (isModEnabled('commande')) {
$langs->load("orders");
}
// Get parameters
$action = GETPOST('action', 'aZ09');
$bid = GETPOST('bid', 'int');
// Security check
$socid = '';
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
// Maximum elements of the tables
$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
$maxLatestEditCount = 5;
$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager->initHooks(array('invoiceindex'));
$maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
/*
* Actions
*/
// None
/*
* View
*/
$now = dol_now();
$form = new Form($db);
$formfile = new FormFile($db);
$thirdpartystatic = new Societe($db);
llxHeader("", $langs->trans("InvoicesArea"));
print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
print '<div class="fichecenter"><div class="fichethirdleft">';
if (isModEnabled('facture')) {
print getNumberInvoicesPieChart('customers');
print '<br>';
}
if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
print getNumberInvoicesPieChart('suppliers');
print '<br>';
}
if (isModEnabled('facture')) {
print getCustomerInvoiceDraftTable($max, $socid);
print '<br>';
}
if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
print getDraftSupplierTable($max, $socid);
print '<br>';
}
print '</div><div class="fichetwothirdright">';
// Latest modified customer invoices
if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
$langs->load("boxes");
$tmpinvoice = new Facture($db);
$sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
$sql .= ", f.date_lim_reglement as datelimite";
$sql .= ", s.nom as name";
$sql .= ", s.rowid as socid";
$sql .= ", s.code_client, s.code_compta, s.email";
$sql .= ", cc.rowid as country_id, cc.code as country_code";
$sql .= ", sum(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays, ".MAIN_DB_PREFIX."facture as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND f.fk_soc = ".((int) $socid);
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
$sql .= $hookmanager->resPrint;
$sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
$sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
$sql .= " cc.rowid, cc.code";
$sql .= " ORDER BY f.tms DESC";
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$othernb = 0;
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16"> </th>';
print '</tr>';
if ($num) {
$total_ttc = $totalam = $total_ht = 0;
while ($i < $num && $i < $conf->liste_limit) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
$othernb += 1;
$i++;
$total_ht += $obj->total_ht;
$total_ttc += $obj->total_ttc;
continue;
}
$tmpinvoice->ref = $obj->ref;
$tmpinvoice->id = $obj->rowid;
$tmpinvoice->total_ht = $obj->total_ht;
$tmpinvoice->total_tva = $obj->total_tva;
$tmpinvoice->total_ttc = $obj->total_ttc;
$tmpinvoice->statut = $obj->status;
$tmpinvoice->paye = $obj->paye;
$tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
$tmpinvoice->type = $obj->type;
$thirdpartystatic->id = $obj->socid;
$thirdpartystatic->name = $obj->name;
$thirdpartystatic->email = $obj->email;
$thirdpartystatic->country_id = $obj->country_id;
$thirdpartystatic->country_code = $obj->country_code;
$thirdpartystatic->email = $obj->email;
$thirdpartystatic->client = 1;
$thirdpartystatic->code_client = $obj->code_client;
//$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
$thirdpartystatic->code_compta = $obj->code_compta;
//$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
$totalallpayments = $tmpinvoice->getSommePaiement(0);
$totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
$totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
print '<tr class="oddeven">';
print '<td class="nowrap">';
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td class="nobordernopadding nowraponall">';
print $tmpinvoice->getNomUrl(1, '');
print '</td>';
if ($tmpinvoice->hasDelay()) {
print '<td width="20" class="nobordernopadding nowrap">';
print img_warning($langs->trans("Late"));
print '</td>';
}
print '<td width="16" class="nobordernopadding hideonsmartphone right">';
$filename = dol_sanitizeFileName($obj->ref);
$filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
$urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
print '</td></tr></table>';
print '</td>';
print '<td class="tdoverflowmax150">';
print $thirdpartystatic->getNomUrl(1, 'customer', 44);
print '</td>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
}
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
print '</tr>';
$total_ttc += $obj->total_ttc;
$total_ht += $obj->total_ht;
$totalam += $obj->am;
$i++;
}
if ($othernb) {
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="5">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
print '</td>';
print "</tr>\n";
}
} else {
$colspan = 5;
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
}
print '</table></div><br>';
$db->free($resql);
} else {
dol_print_error($db);
}
}
// Last modified supplier invoices
if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
$langs->load("boxes");
$facstatic = new FactureFournisseur($db);
$sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier";
$sql .= ", s.nom as name";
$sql .= ", s.rowid as socid";
$sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
$sql .= ", SUM(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = ff.fk_soc";
$sql .= " AND ff.entity = ".$conf->entity;
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND ff.fk_soc = ".((int) $socid);
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
$sql .= $hookmanager->resPrint;
$sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier,";
$sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
$sql .= " ORDER BY ff.tms DESC ";
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16"> </th>';
print "</tr>\n";
if ($num) {
$i = 0;
$total_ht = $total_ttc = $totalam = 0;
$othernb = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
$othernb += 1;
$i++;
$total_ht += $obj->total_ht;
$total_ttc += $obj->total_ttc;
continue;
}
$facstatic->ref = $obj->ref;
$facstatic->id = $obj->rowid;
$facstatic->total_ht = $obj->total_ht;
$facstatic->total_tva = $obj->total_tva;
$facstatic->total_ttc = $obj->total_ttc;
$facstatic->statut = $obj->status;
$facstatic->paye = $obj->paye;
$facstatic->type = $obj->type;
$facstatic->ref_supplier = $obj->ref_supplier;
$thirdpartystatic->id = $obj->socid;
$thirdpartystatic->name = $obj->name;
$thirdpartystatic->email = $obj->email;
$thirdpartystatic->country_id = 0;
$thirdpartystatic->country_code = '';
$thirdpartystatic->client = 0;
$thirdpartystatic->fournisseur = 1;
$thirdpartystatic->code_client = '';
$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
$thirdpartystatic->code_compta = '';
$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
print $facstatic->getNomUrl(1, '');
print '</td>';
print '<td class="nowrap tdoverflowmax100">';
print $thirdpartystatic->getNomUrl(1, 'supplier');
print '</td>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
}
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
$alreadypaid = $facstatic->getSommePaiement();
$alreadypaid += $facstatic->getSumCreditNotesUsed();
$alreadypaid += $facstatic->getSumDepositsUsed();
print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
print '</tr>';
$total_ht += $obj->total_ht;
$total_ttc += $obj->total_ttc;
$totalam += $obj->am;
$i++;
}
if ($othernb) {
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="5">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
print '</td>';
print "</tr>\n";
}
} else {
$colspan = 5;
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
}
print '</table></div><br>';
} else {
dol_print_error($db);
}
}
// Latest donations
if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
$langs->load("boxes");
$donationstatic = new Don($db);
$sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."don as d";
$sql .= " WHERE d.entity IN (".getEntity('donation').")";
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
$sql .= $hookmanager->resPrint;
$sql .= $db->order("d.tms", "DESC");
$sql .= $db->plimit($max, 0);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$othernb = 0;
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
print '<th></th>';
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16"> </th>';
print '</tr>';
if ($num) {
$total_ttc = $totalam = $total_ht = 0;
while ($i < $num && $i < $max) {
$obj = $db->fetch_object($result);
if ($i >= $max) {
$othernb += 1;
$i++;
$total_ht += $obj->total_ht;
$total_ttc += $obj->total_ttc;
continue;
}
$donationstatic->id = $obj->rowid;
$donationstatic->ref = $obj->rowid;
$donationstatic->lastname = $obj->lastname;
$donationstatic->firstname = $obj->firstname;
$donationstatic->date = $db->jdate($obj->date);
$donationstatic->statut = $obj->status;
$donationstatic->status = $obj->status;
$label = $donationstatic->getFullName($langs);
if ($obj->societe) {
$label .= ($label ? ' - ' : '').$obj->societe;
}
print '<tr class="oddeven tdoverflowmax100">';
print '<td>'.$donationstatic->getNomUrl(1).'</td>';
print '<td>'.$label.'</td>';
print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->dm), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->dm), 'day', 'tzuserrel').'</td>';
print '<td>'.$donationstatic->getLibStatut(3).'</td>';
print '</tr>';
$i++;
}
if ($othernb) {
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="5">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
print '</td>';
print "</tr>\n";
}
} else {
print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
}
print '</table></div><br>';
} else {
dol_print_error($db);
}
}
/**
* Social contributions to pay
*/
if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
if (!$socid) {
$chargestatic = new ChargeSociales($db);
$sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
$sql .= " cc.libelle as label,";
$sql .= " SUM(pc.amount) as sumpaid";
$sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
$sql .= " WHERE c.fk_type = cc.id";
$sql .= " AND c.entity IN (".getEntity('tax').')';
$sql .= " AND c.paye = 0";
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
$sql .= $hookmanager->resPrint;
$sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
print '<th align="center">'.$langs->trans("DateDue").'</th>';
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("Paid").'</th>';
print '<th align="center" width="16"> </th>';
print '</tr>';
if ($num) {
$i = 0;
$tot_ttc = 0;
$othernb = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
$othernb += 1;
$tot_ttc += $obj->amount;
$i++;
continue;
}
$chargestatic->id = $obj->rowid;
$chargestatic->ref = $obj->rowid;
$chargestatic->label = $obj->label;
$chargestatic->paye = $obj->paye;
$chargestatic->status = $obj->paye;
print '<tr class="oddeven">';
print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
print '</tr>';
$tot_ttc += $obj->amount;
$i++;
}
if ($othernb) {
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="5">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
print '</td>';
print "</tr>\n";
}
print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
print '<td class="nowrap right">'.price($tot_ttc).'</td>';
print '<td class="right"></td>';
print '<td class="right"> </td>';
print '</tr>';
} else {
print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
}
print "</table></div><br>";
$db->free($resql);
} else {
dol_print_error($db);
}
}
}
/*
* Customers orders to be billed
*/
if (isModEnabled('facture') && isModEnabled('commande') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
$commandestatic = new Commande($db);
$langs->load("orders");
$sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
$sql .= ", s.nom as name, s.email";
$sql .= ", s.rowid as socid";
$sql .= ", s.code_client, s.code_compta";
$sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
$sql .= " cc.rowid as country_id, cc.code as country_code";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ", ".MAIN_DB_PREFIX."commande as c";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
$sql .= " WHERE c.fk_soc = s.rowid";
$sql .= " AND c.entity = ".$conf->entity;
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($socid) {
$sql .= " AND c.fk_soc = ".((int) $socid);
}
$sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
$sql .= " AND c.facture = 0";
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
$sql .= $hookmanager->resPrint;
$sql .= " GROUP BY s.nom, s.email, s.rowid, s.code_client, s.code_compta, c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.total_tva, c.total_ttc, cc.rowid, cc.code";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
if ($num) {
$i = 0;
$othernb = 0;
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print "<tr class=\"liste_titre\">";
print '<th colspan="2">';
print $langs->trans("OrdersDeliveredToBill").' ';
print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&billed=0">';
print '<span class="badge">'.$num.'</span>';
print '</a>';
print '</th>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("ToBill").'</th>';
print '<th align="center" width="16"> </th>';
print '</tr>';
$tot_ht = $tot_ttc = $tot_tobill = 0;
$societestatic = new Societe($db);
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
$othernb += 1;
$i++;
$total_ht += $obj->total_ht;
$total_ttc += $obj->total_ttc;
continue;
}
$societestatic->id = $obj->socid;
$societestatic->name = $obj->name;
$societestatic->email = $obj->email;
$societestatic->country_id = $obj->country_id;
$societestatic->country_code = $obj->country_code;
$societestatic->client = 1;
$societestatic->code_client = $obj->code_client;
//$societestatic->code_fournisseur = $obj->code_fournisseur;
$societestatic->code_compta = $obj->code_compta;
//$societestatic->code_fournisseur = $obj->code_fournisseur;
$commandestatic->id = $obj->rowid;
$commandestatic->ref = $obj->ref;
$commandestatic->statut = $obj->status;
$commandestatic->billed = $obj->facture;
print '<tr class="oddeven">';
print '<td class="nowrap">';
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td class="nobordernopadding nowrap">';
print $commandestatic->getNomUrl(1);
print '</td>';
print '<td width="20" class="nobordernopadding nowrap">';
print ' ';
print '</td>';
print '<td width="16" class="nobordernopadding hideonsmartphone right">';
$filename = dol_sanitizeFileName($obj->ref);
$filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
print '</td></tr></table>';
print '</td>';
print '<td class="nowrap tdoverflowmax100">';
print $societestatic->getNomUrl(1, 'customer');
print '</td>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
}
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
print '<td>'.$commandestatic->getLibStatut(3).'</td>';
print '</tr>';
$tot_ht += $obj->total_ht;
$tot_ttc += $obj->total_ttc;
//print "x".$tot_ttc."z".$obj->tot_fttc;
$tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
$i++;
}
if ($othernb) {
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="5">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
print '</td>';
print "</tr>\n";
}
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' <span style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</span> </td>';
if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
print '<td class="right">'.price($tot_ht).'</td>';
}
print '<td class="nowrap right">'.price($tot_ttc).'</td>';
print '<td class="nowrap right">'.price($tot_tobill).'</td>';
print '<td> </td>';
print '</tr>';
print '</table></div><br>';
}
$db->free($resql);
} else {
dol_print_error($db);
}
}
// TODO Mettre ici recup des actions en rapport avec la compta
$sql = '';
if ($sql) {
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
print "</tr>\n";
$i = 0;
$resql = $db->query($sql);
if ($resql) {
$num_rows = $db->num_rows($resql);
while ($i < $num_rows) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
$i++;
}
$db->free($resql);
}
print "</table></div><br>";
}
print '</div></div>';
$parameters = array('user' => $user);
$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
// End of page
llxFooter();
$db->close();