Issues (2811)

public/htdocs/compta/index.php (3 issues)

1
<?php
2
3
/* Copyright (C) 2001-2005  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2004-2022  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2005-2015  Regis Houssin               <[email protected]>
6
 * Copyright (C) 2015-2020  Juanjo Menent	            <[email protected]>
7
 * Copyright (C) 2015       Jean-François Ferry	        <[email protected]>
8
 * Copyright (C) 2015       Raphaël Doursenaud          <[email protected]>
9
 * Copyright (C) 2016       Marcos García               <[email protected]>
10
 * Copyright (C) 2019       Nicolas ZABOURI             <[email protected]>
11
 * Copyright (C) 2020       Tobias Sekan                <[email protected]>
12
 * Copyright (C) 2020       Josep Lluís Amador          <[email protected]>
13
 * Copyright (C) 2021-2024  Frédéric France		        <[email protected]>
14
 * Copyright (C) 2024		MDW							<[email protected]>
15
 * Copyright (C) 2024       Rafael San José             <[email protected]>
16
 *
17
 * This program is free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 3 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29
 */
30
31
use Dolibarr\Lib\ViewMain;
32
33
/**
34
 *  \file       htdocs/compta/index.php
35
 *  \ingroup    compta
36
 *  \brief      Main page of accountancy area
37
 */
38
39
use Dolibarr\Code\Commande\Classes\Commande;
40
use Dolibarr\Code\Compta\Classes\ChargeSociales;
41
use Dolibarr\Code\Compta\Classes\Facture;
42
use Dolibarr\Code\Core\Classes\Form;
43
use Dolibarr\Code\Core\Classes\FormFile;
44
use Dolibarr\Code\Don\Classes\Don;
45
use Dolibarr\Code\Fourn\Classes\FactureFournisseur;
46
use Dolibarr\Code\Societe\Classes\Societe;
47
48
// Load Dolibarr environment
49
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
50
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/invoice.lib.php';
51
52
// L'espace compta/treso doit toujours etre actif car c'est un espace partage
53
// par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
54
// de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
55
// est protegee par le droit qui va bien du module concerne.
56
57
// Load translation files required by the page
58
$langs->loadLangs(array('compta', 'bills'));
59
if (isModEnabled('order')) {
60
    $langs->load("orders");
61
}
62
63
// Get parameters
64
$action = GETPOST('action', 'aZ09');
65
$bid = GETPOSTINT('bid');
66
67
// Security check
68
$socid = '';
69
if ($user->socid > 0) {
70
    $action = '';
71
    $socid = $user->socid;
72
}
73
74
// Maximum elements of the tables
75
$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
76
$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
77
$maxLatestEditCount = 5;
78
$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
79
80
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
81
$hookmanager->initHooks(array('invoiceindex'));
82
83
84
$maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
85
86
87
/*
88
 * Actions
89
 */
90
91
// None
92
93
94
/*
95
 * View
96
 */
97
98
$now = dol_now();
99
100
$form = new Form($db);
101
$formfile = new FormFile($db);
102
$thirdpartystatic = new Societe($db);
103
104
ViewMain::llxHeader("", $langs->trans("InvoicesArea"));
105
106
print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
107
108
109
print '<div class="fichecenter">';
110
111
print '<div class="twocolumns">';
112
113
print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
114
115
116
if (isModEnabled('invoice')) {
117
    print getNumberInvoicesPieChart('customers');
118
    print '<br>';
119
}
120
121
if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
122
    print getNumberInvoicesPieChart('suppliers');
123
    print '<br>';
124
}
125
126
if (isModEnabled('invoice')) {
127
    print getCustomerInvoiceDraftTable($max, $socid);
128
    print '<br>';
129
}
130
131
if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
132
    print getDraftSupplierTable($max, $socid);
133
    print '<br>';
134
}
135
136
137
print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
138
139
140
// Latest modified customer invoices
141
if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
142
    $langs->load("boxes");
143
    $tmpinvoice = new Facture($db);
144
145
    $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";
146
    $sql .= ", f.date_lim_reglement as datelimite";
147
    $sql .= ", s.nom as name";
148
    $sql .= ", s.rowid as socid";
149
    $sql .= ", s.code_client, s.code_compta, s.email";
150
    $sql .= ", cc.rowid as country_id, cc.code as country_code";
151
    $sql .= ", (SELECT SUM(pf.amount) FROM " . $db->prefix() . "paiement_facture as pf WHERE pf.fk_facture = f.rowid) as am";
152
    $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
153
    $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
154
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as cc ON cc.rowid = s.fk_pays";
155
    $sql .= " WHERE f.entity IN (" . getEntity('invoice') . ")";
156
    if ($socid > 0) {
157
        $sql .= " AND f.fk_soc = " . ((int)$socid);
158
    }
159
    // Filter on sale representative
160
    if (!$user->hasRight('societe', 'client', 'voir')) {
161
        $sql .= " AND EXISTS (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = " . ((int)$user->id) . ")";
162
    }
163
    // Add where from hooks
164
    $parameters = array();
165
    $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
166
    $sql .= $hookmanager->resPrint;
167
168
    $sql .= " ORDER BY f.tms DESC";
169
    $sql .= $db->plimit($max, 0);
170
171
    $resql = $db->query($sql);
172
    if ($resql) {
173
        $num = $db->num_rows($resql);
174
        $i = 0;
175
        $othernb = 0;
176
177
        print '<div class="div-table-responsive-no-min">';
178
        print '<table class="noborder centpercent">';
179
180
        print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("BoxTitleLastCustomerBills", $max);
181
        print '<a href="' . constant('BASE_URL') . '/compta/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
182
        print '</th>';
183
        if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
184
            print '<th class="right">' . $langs->trans("AmountHT") . '</th>';
185
        }
186
        print '<th class="right">' . $langs->trans("AmountTTC") . '</th>';
187
        print '<th class="right">' . $langs->trans("DateModificationShort") . '</th>';
188
        print '<th width="16">&nbsp;</th>';
189
        print '</tr>';
190
        if ($num) {
191
            $total_ttc = $totalam = $total_ht = 0;
192
            while ($i < $num && $i < $conf->liste_limit) {
193
                $obj = $db->fetch_object($resql);
194
195
                if ($i >= $max) {
196
                    $othernb += 1;
197
                    $i++;
198
                    $total_ht += $obj->total_ht;
199
                    $total_ttc += $obj->total_ttc;
200
                    continue;
201
                }
202
203
                $tmpinvoice->ref = $obj->ref;
204
                $tmpinvoice->id = $obj->rowid;
205
                $tmpinvoice->total_ht = $obj->total_ht;
206
                $tmpinvoice->total_tva = $obj->total_tva;
207
                $tmpinvoice->total_ttc = $obj->total_ttc;
208
                $tmpinvoice->statut = $obj->status;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

208
                /** @scrutinizer ignore-deprecated */ $tmpinvoice->statut = $obj->status;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
209
                $tmpinvoice->status = $obj->status;
210
                $tmpinvoice->paye = $obj->paye;
211
                $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
212
                $tmpinvoice->type = $obj->type;
213
214
                $thirdpartystatic->id = $obj->socid;
215
                $thirdpartystatic->name = $obj->name;
216
                $thirdpartystatic->email = $obj->email;
217
                $thirdpartystatic->country_id = $obj->country_id;
218
                $thirdpartystatic->country_code = $obj->country_code;
219
                $thirdpartystatic->email = $obj->email;
220
                $thirdpartystatic->client = 1;
221
                $thirdpartystatic->code_client = $obj->code_client;
222
                //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
223
                $thirdpartystatic->code_compta_client = $obj->code_compta;
224
                //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
225
226
                print '<tr class="oddeven">';
227
                print '<td class="nowrap">';
228
229
                print '<table class="nobordernopadding"><tr class="nocellnopadd">';
230
231
                print '<td class="nobordernopadding nowraponall">';
232
                print $tmpinvoice->getNomUrl(1, '');
233
                print '</td>';
234
                if ($tmpinvoice->hasDelay()) {
235
                    print '<td width="20" class="nobordernopadding nowrap">';
236
                    print img_warning($langs->trans("Late"));
237
                    print '</td>';
238
                }
239
                print '<td width="16" class="nobordernopadding hideonsmartphone right">';
240
                $filename = dol_sanitizeFileName($obj->ref);
241
                $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref);
242
                $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $obj->rowid;
243
                print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
244
                print '</td></tr></table>';
245
246
                print '</td>';
247
248
                print '<td class="tdoverflowmax150">';
249
                print $thirdpartystatic->getNomUrl(1, 'customer', 44);
250
                print '</td>';
251
                if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
252
                    print '<td class="nowrap right"><span class="amount">' . price($obj->total_ht) . '</span></td>';
253
                }
254
                print '<td class="nowrap right"><span class="amount">' . price($obj->total_ttc) . '</span></td>';
255
256
                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>';
257
258
                print '<td>' . $tmpinvoice->getLibStatut(3, $obj->am) . '</td>';
259
260
                print '</tr>';
261
262
                $total_ttc += $obj->total_ttc;
263
                $total_ht += $obj->total_ht;
264
                $totalam += $obj->am;
265
266
                $i++;
267
            }
268
269
            if ($othernb) {
270
                print '<tr class="oddeven">';
271
                print '<td class="nowrap" colspan="5">';
272
                print '<span class="opacitymedium">' . $langs->trans("More") . '... (' . $othernb . ')</span>';
273
                print '</td>';
274
                print "</tr>\n";
275
            }
276
        } else {
277
            $colspan = 5;
278
            if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
279
                $colspan++;
280
            }
281
            print '<tr class="oddeven"><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoInvoice") . '</span></td></tr>';
282
        }
283
        print '</table></div><br>';
284
        $db->free($resql);
285
    } else {
286
        dol_print_error($db);
287
    }
288
}
289
290
291
// Last modified supplier invoices
292
if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
293
    $langs->load("boxes");
294
    $facstatic = new FactureFournisseur($db);
295
296
    $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";
297
    $sql .= ", s.nom as name";
298
    $sql .= ", s.rowid as socid";
299
    $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
300
    $sql .= ", (SELECT SUM(pf.amount) FROM " . $db->prefix() . "paiementfourn_facturefourn as pf WHERE pf.fk_facturefourn = ff.rowid) as am";
301
    $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "facture_fourn as ff";
302
    $sql .= " WHERE s.rowid = ff.fk_soc";
303
    $sql .= " AND ff.entity IN (" . getEntity('facture_fourn') . ")";
304
    if ($socid > 0) {
305
        $sql .= " AND ff.fk_soc = " . ((int)$socid);
306
    }
307
    // Filter on sale representative
308
    if (!$user->hasRight('societe', 'client', 'voir')) {
309
        $sql .= " AND EXISTS (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc WHERE sc.fk_soc = ff.fk_soc AND sc.fk_user = " . ((int)$user->id) . ")";
310
    }
311
    // Add where from hooks
312
    $parameters = array();
313
    $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
314
    $sql .= $hookmanager->resPrint;
315
316
    $sql .= " ORDER BY ff.tms DESC";
317
    $sql .= $db->plimit($max, 0);
318
319
    $resql = $db->query($sql);
320
    if ($resql) {
321
        $num = $db->num_rows($resql);
322
323
        print '<div class="div-table-responsive-no-min">';
324
        print '<table class="noborder centpercent">';
325
        print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("BoxTitleLastSupplierBills", $max);
326
        print '<a href="' . constant('BASE_URL') . '/fourn/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
327
        print '</th>';
328
        if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
329
            print '<th class="right">' . $langs->trans("AmountHT") . '</th>';
330
        }
331
        print '<th class="right">' . $langs->trans("AmountTTC") . '</th>';
332
        print '<th class="right">' . $langs->trans("DateModificationShort") . '</th>';
333
        print '<th width="16">&nbsp;</th>';
334
        print "</tr>\n";
335
        if ($num) {
336
            $i = 0;
337
            $total_ht = $total_ttc = $totalam = 0;
338
            $othernb = 0;
339
340
            while ($i < $num) {
341
                $obj = $db->fetch_object($resql);
342
343
                if ($i >= $max) {
344
                    $othernb += 1;
345
                    $i++;
346
                    $total_ht += $obj->total_ht;
347
                    $total_ttc += $obj->total_ttc;
348
                    continue;
349
                }
350
351
                $facstatic->ref = $obj->ref;
352
                $facstatic->id = $obj->rowid;
353
                $facstatic->total_ht = $obj->total_ht;
354
                $facstatic->total_tva = $obj->total_tva;
355
                $facstatic->total_ttc = $obj->total_ttc;
356
                $facstatic->statut = $obj->status;
357
                $facstatic->status = $obj->status;
358
                $facstatic->paye = $obj->paye;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Code\Fourn\Clas...ctureFournisseur::$paye has been deprecated: Use $paid ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

358
                /** @scrutinizer ignore-deprecated */ $facstatic->paye = $obj->paye;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
359
                $facstatic->paid = $obj->paye;
360
                $facstatic->type = $obj->type;
361
                $facstatic->ref_supplier = $obj->ref_supplier;
362
363
                $thirdpartystatic->id = $obj->socid;
364
                $thirdpartystatic->name = $obj->name;
365
                $thirdpartystatic->email = $obj->email;
366
                $thirdpartystatic->country_id = 0;
367
                $thirdpartystatic->country_code = '';
368
                $thirdpartystatic->client = 0;
369
                $thirdpartystatic->fournisseur = 1;
370
                $thirdpartystatic->code_client = '';
371
                $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
372
                $thirdpartystatic->code_compta_client = '';
373
                $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
374
375
                print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
376
                print $facstatic->getNomUrl(1, '');
377
                print '</td>';
378
                print '<td class="nowrap tdoverflowmax100">';
379
                print $thirdpartystatic->getNomUrl(1, 'supplier');
380
                print '</td>';
381
                if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
382
                    print '<td class="right"><span class="amount">' . price($obj->total_ht) . '</span></td>';
383
                }
384
                print '<td class="nowrap right"><span class="amount">' . price($obj->total_ttc) . '</span></td>';
385
                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>';
386
                $alreadypaid = $facstatic->getSommePaiement();
387
                print '<td>' . $facstatic->getLibStatut(3, $alreadypaid) . '</td>';
388
                print '</tr>';
389
                $total_ht += $obj->total_ht;
390
                $total_ttc += $obj->total_ttc;
391
                $totalam += $obj->am;
392
                $i++;
393
            }
394
395
            if ($othernb) {
396
                print '<tr class="oddeven">';
397
                print '<td class="nowrap" colspan="5">';
398
                print '<span class="opacitymedium">' . $langs->trans("More") . '... (' . $othernb . ')</span>';
399
                print '</td>';
400
                print "</tr>\n";
401
            }
402
        } else {
403
            $colspan = 5;
404
            if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
405
                $colspan++;
406
            }
407
            print '<tr class="oddeven"><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoInvoice") . '</span></td></tr>';
408
        }
409
        print '</table></div><br>';
410
    } else {
411
        dol_print_error($db);
412
    }
413
}
414
415
416
// Latest donations
417
if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
418
    include_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
419
420
    $langs->load("boxes");
421
    $donationstatic = new Don($db);
422
423
    $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";
424
    $sql .= " FROM " . MAIN_DB_PREFIX . "don as d";
425
    $sql .= " WHERE d.entity IN (" . getEntity('donation') . ")";
426
    // Add where from hooks
427
    $parameters = array();
428
    $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
429
    $sql .= $hookmanager->resPrint;
430
431
    $sql .= $db->order("d.tms", "DESC");
432
    $sql .= $db->plimit($max, 0);
433
434
    $result = $db->query($sql);
435
    if ($result) {
436
        $num = $db->num_rows($result);
437
438
        $i = 0;
439
        $othernb = 0;
440
441
        print '<div class="div-table-responsive-no-min">';
442
        print '<table class="noborder centpercent">';
443
        print '<tr class="liste_titre">';
444
        print '<th colspan="2">' . $langs->trans("BoxTitleLastModifiedDonations", $max);
445
        print '<a href="' . constant('BASE_URL') . '/don/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
446
        print '</th>';
447
        print '<th class="right">' . $langs->trans("AmountTTC") . '</th>';
448
        print '<th class="right">' . $langs->trans("DateModificationShort") . '</th>';
449
        print '<th width="16">&nbsp;</th>';
450
        print '</tr>';
451
452
        if ($num) {
453
            $total_ttc = $totalam = $total_ht = 0;
454
455
            while ($i < $num && $i < $max) {
456
                $obj = $db->fetch_object($result);
457
458
                if ($i >= $max) {
459
                    $othernb += 1;
460
                    $i++;
461
                    $total_ht += $obj->total_ht;
462
                    $total_ttc += $obj->total_ttc;
463
                    continue;
464
                }
465
466
                $donationstatic->id = $obj->rowid;
467
                $donationstatic->ref = $obj->rowid;
468
                $donationstatic->lastname = $obj->lastname;
469
                $donationstatic->firstname = $obj->firstname;
470
                $donationstatic->date = $db->jdate($obj->date);
471
                $donationstatic->statut = $obj->status;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

471
                /** @scrutinizer ignore-deprecated */ $donationstatic->statut = $obj->status;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
472
                $donationstatic->status = $obj->status;
473
474
                $label = $donationstatic->getFullName($langs);
475
                if ($obj->societe) {
476
                    $label .= ($label ? ' - ' : '') . $obj->societe;
477
                }
478
479
                print '<tr class="oddeven tdoverflowmax100">';
480
                print '<td>' . $donationstatic->getNomUrl(1) . '</td>';
481
                print '<td>' . $label . '</td>';
482
                print '<td class="nowrap right"><span class="amount">' . price($obj->amount) . '</span></td>';
483
                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>';
484
                print '<td>' . $donationstatic->getLibStatut(3) . '</td>';
485
                print '</tr>';
486
487
                $i++;
488
            }
489
490
            if ($othernb) {
491
                print '<tr class="oddeven">';
492
                print '<td class="nowrap" colspan="5">';
493
                print '<span class="opacitymedium">' . $langs->trans("More") . '... (' . $othernb . ')</span>';
494
                print '</td>';
495
                print "</tr>\n";
496
            }
497
        } else {
498
            print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
499
        }
500
        print '</table></div><br>';
501
    } else {
502
        dol_print_error($db);
503
    }
504
}
505
506
/**
507
 * Social contributions to pay
508
 */
509
if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
510
    if (!$socid) {
511
        $chargestatic = new ChargeSociales($db);
512
513
        $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
514
        $sql .= " cc.libelle as label,";
515
        $sql .= " SUM(pc.amount) as sumpaid";
516
        $sql .= " FROM (" . MAIN_DB_PREFIX . "c_chargesociales as cc, " . MAIN_DB_PREFIX . "chargesociales as c)";
517
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "paiementcharge as pc ON pc.fk_charge = c.rowid";
518
        $sql .= " WHERE c.fk_type = cc.id";
519
        $sql .= " AND c.entity IN (" . getEntity('tax') . ')';
520
        $sql .= " AND c.paye = 0";
521
        // Add where from hooks
522
        $parameters = array();
523
        $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
524
        $sql .= $hookmanager->resPrint;
525
526
        $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
527
528
        $resql = $db->query($sql);
529
        if ($resql) {
530
            $num = $db->num_rows($resql);
531
532
            print '<div class="div-table-responsive-no-min">';
533
            print '<table class="noborder centpercent">';
534
            print '<tr class="liste_titre">';
535
            print '<th>' . $langs->trans("ContributionsToPay") . ($num ? '<a href="' . constant('BASE_URL') . '/compta/sociales/list.php?status=0"><span class="badge marginleftonly">' . $num . '</span></a>' : '') . '</th>';
536
            print '<th align="center">' . $langs->trans("DateDue") . '</th>';
537
            print '<th class="right">' . $langs->trans("AmountTTC") . '</th>';
538
            print '<th class="right">' . $langs->trans("Paid") . '</th>';
539
            print '<th align="center" width="16">&nbsp;</th>';
540
            print '</tr>';
541
            if ($num) {
542
                $i = 0;
543
                $tot_ttc = 0;
544
                $tot_paid = 0;
545
                $othernb = 0;
546
547
                while ($i < $num) {
548
                    $obj = $db->fetch_object($resql);
549
550
                    if ($i >= $max) {
551
                        $othernb += 1;
552
                        $tot_ttc += $obj->amount;
553
                        $tot_paid += $obj->sumpaid;
554
                        $i++;
555
                        continue;
556
                    }
557
558
                    $chargestatic->id = $obj->rowid;
559
                    $chargestatic->ref = $obj->rowid;
560
                    $chargestatic->label = $obj->label;
561
                    $chargestatic->paye = $obj->paye;
562
                    $chargestatic->status = $obj->paye;
563
564
                    print '<tr class="oddeven">';
565
                    print '<td class="nowraponall">' . $chargestatic->getNomUrl(1) . '</td>';
566
                    print '<td class="center">' . dol_print_date($db->jdate($obj->date_ech), 'day') . '</td>';
567
                    print '<td class="nowrap right"><span class="amount">' . price($obj->amount) . '</span></td>';
568
                    print '<td class="nowrap right"><span class="amount">' . price($obj->sumpaid) . '</span></td>';
569
                    print '<td class="center">' . $chargestatic->getLibStatut(3) . '</td>';
570
                    print '</tr>';
571
572
                    $tot_ttc += $obj->amount;
573
                    $i++;
574
                }
575
576
                if ($othernb) {
577
                    print '<tr class="oddeven">';
578
                    print '<td class="nowrap" colspan="5">';
579
                    print '<span class="opacitymedium">' . $langs->trans("More") . '... (' . $othernb . ')</span>';
580
                    print '</td>';
581
                    print "</tr>\n";
582
                }
583
584
                print '<tr class="liste_total"><td class="left" colspan="2">' . $langs->trans("Total") . '</td>';
585
                print '<td class="nowrap right">' . price($tot_ttc) . '</td>';
586
                print '<td class="nowrap right">' . price($tot_paid) . '</td>';
587
                print '<td class="right">&nbsp;</td>';
588
                print '</tr>';
589
            } else {
590
                print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
591
            }
592
            print "</table></div><br>";
593
            $db->free($resql);
594
        } else {
595
            dol_print_error($db);
596
        }
597
    }
598
}
599
600
/*
601
 * Customers orders to be billed
602
 */
603
if (isModEnabled('invoice') && isModEnabled('order') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
604
    $commandestatic = new Commande($db);
605
    $langs->load("orders");
606
607
    $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
608
    $sql .= ", s.nom as name, s.email";
609
    $sql .= ", s.rowid as socid";
610
    $sql .= ", s.code_client, s.code_compta";
611
    $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
612
    $sql .= " cc.rowid as country_id, cc.code as country_code";
613
    $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s LEFT JOIN " . MAIN_DB_PREFIX . "c_country as cc ON cc.rowid = s.fk_pays";
614
    $sql .= ", " . MAIN_DB_PREFIX . "commande as c";
615
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
616
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
617
    $sql .= " WHERE c.fk_soc = s.rowid";
618
    $sql .= " AND c.entity IN (" . getEntity('commande') . ")";
619
    if ($socid) {
620
        $sql .= " AND c.fk_soc = " . ((int)$socid);
621
    }
622
    $sql .= " AND c.fk_statut = " . ((int)Commande::STATUS_CLOSED);
623
    $sql .= " AND c.facture = 0";
624
    // Filter on sale representative
625
    if (!$user->hasRight('societe', 'client', 'voir')) {
626
        $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)$user->id) . ")";
627
    }
628
629
    // Add where from hooks
630
    $parameters = array();
631
    $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
632
    $sql .= $hookmanager->resPrint;
633
634
    $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";
635
636
    $resql = $db->query($sql);
637
    if ($resql) {
638
        $num = $db->num_rows($resql);
639
640
        if ($num) {
641
            $i = 0;
642
            $othernb = 0;
643
644
            print '<div class="div-table-responsive-no-min">';
645
            print '<table class="noborder centpercent">';
646
647
            print '<tr class="liste_titre">';
648
            print '<th colspan="2">';
649
            print $langs->trans("OrdersDeliveredToBill");
650
            print '<a href="' . constant('BASE_URL') . '/commande/list.php?search_status=' . Commande::STATUS_CLOSED . '&search_billed=0">';
651
            print '<span class="badge marginleftonly">' . $num . '</span>';
652
            print '</a>';
653
            print '</th>';
654
655
            if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
656
                print '<th class="right">' . $langs->trans("AmountHT") . '</th>';
657
            }
658
            print '<th class="right">' . $langs->trans("AmountTTC") . '</th>';
659
            print '<th class="right">' . $langs->trans("ToBill") . '</th>';
660
            print '<th align="center" width="16">&nbsp;</th>';
661
            print '</tr>';
662
663
            $tot_ht = $tot_ttc = $tot_tobill = 0;
664
            $societestatic = new Societe($db);
665
            while ($i < $num) {
666
                $obj = $db->fetch_object($resql);
667
668
                if ($i >= $max) {
669
                    $othernb += 1;
670
                    $i++;
671
                    $total_ht += $obj->total_ht;
672
                    $total_ttc += $obj->total_ttc;
673
                    continue;
674
                }
675
676
                $societestatic->id = $obj->socid;
677
                $societestatic->name = $obj->name;
678
                $societestatic->email = $obj->email;
679
                $societestatic->country_id = $obj->country_id;
680
                $societestatic->country_code = $obj->country_code;
681
                $societestatic->client = 1;
682
                $societestatic->code_client = $obj->code_client;
683
                //$societestatic->code_fournisseur = $obj->code_fournisseur;
684
                $societestatic->code_compta_client = $obj->code_compta;
685
                //$societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
686
687
                $commandestatic->id = $obj->rowid;
688
                $commandestatic->ref = $obj->ref;
689
                $commandestatic->statut = $obj->status;
690
                $commandestatic->billed = $obj->facture;
691
692
                print '<tr class="oddeven">';
693
                print '<td class="nowrap">';
694
695
                print '<table class="nobordernopadding"><tr class="nocellnopadd">';
696
                print '<td class="nobordernopadding nowrap">';
697
                print $commandestatic->getNomUrl(1);
698
                print '</td>';
699
                print '<td width="20" class="nobordernopadding nowrap">';
700
                print '&nbsp;';
701
                print '</td>';
702
                print '<td width="16" class="nobordernopadding hideonsmartphone right">';
703
                $filename = dol_sanitizeFileName($obj->ref);
704
                $filedir = $conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
705
                $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $obj->rowid;
706
                print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
707
                print '</td></tr></table>';
708
709
                print '</td>';
710
711
                print '<td class="nowrap tdoverflowmax100">';
712
                print $societestatic->getNomUrl(1, 'customer');
713
                print '</td>';
714
                if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
715
                    print '<td class="right"><span class="amount">' . price($obj->total_ht) . '</span></td>';
716
                }
717
                print '<td class="nowrap right"><span class="amount">' . price($obj->total_ttc) . '</span></td>';
718
                print '<td class="nowrap right"><span class="amount">' . price($obj->total_ttc - $obj->tot_fttc) . '</span></td>';
719
                print '<td>' . $commandestatic->getLibStatut(3) . '</td>';
720
                print '</tr>';
721
                $tot_ht += $obj->total_ht;
722
                $tot_ttc += $obj->total_ttc;
723
                //print "x".$tot_ttc."z".$obj->tot_fttc;
724
                $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
725
                $i++;
726
            }
727
728
            if ($othernb) {
729
                print '<tr class="oddeven">';
730
                print '<td class="nowrap" colspan="5">';
731
                print '<span class="opacitymedium">' . $langs->trans("More") . '... (' . $othernb . ')</span>';
732
                print '</td>';
733
                print "</tr>\n";
734
            }
735
736
            print '<tr class="liste_total"><td colspan="2">' . $langs->trans("Total") . ' &nbsp; <span style="font-weight: normal">(' . $langs->trans("RemainderToBill") . ': ' . price($tot_tobill) . ')</span> </td>';
737
            if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
738
                print '<td class="right">' . price($tot_ht) . '</td>';
739
            }
740
            print '<td class="nowrap right">' . price($tot_ttc) . '</td>';
741
            print '<td class="nowrap right">' . price($tot_tobill) . '</td>';
742
            print '<td>&nbsp;</td>';
743
            print '</tr>';
744
            print '</table></div><br>';
745
        }
746
        $db->free($resql);
747
    } else {
748
        dol_print_error($db);
749
    }
750
}
751
752
753
// TODO Mettre ici recup des actions en rapport avec la compta
754
$sql = '';
755
if ($sql) {
756
    print '<div class="div-table-responsive-no-min">';
757
    print '<table class="noborder centpercent">';
758
    print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("TasksToDo") . '</th>';
759
    print "</tr>\n";
760
    $i = 0;
761
    $resql = $db->query($sql);
762
    if ($resql) {
763
        $num_rows = $db->num_rows($resql);
764
        while ($i < $num_rows) {
765
            $obj = $db->fetch_object($resql);
766
767
            print '<tr class="oddeven"><td>' . dol_print_date($db->jdate($obj->da), "day") . '</td>';
768
            print '<td><a href="action/card.php">' . $obj->label . '</a></td></tr>';
769
            $i++;
770
        }
771
        $db->free($resql);
772
    }
773
    print "</table></div><br>";
774
}
775
776
777
print '</div></div></div>';
778
779
$parameters = array('user' => $user);
780
$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
781
782
// End of page
783
ViewMain::llxFooter();
784
$db->close();
785