dolibarr 25.0.0-alpha
recap-fourn.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2019 Pierre Ardoin <mapiolca@me.com>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2026 Nick Fragoulis
8 * Copyright (C) 2026 Christos Kanotidis <christoskanotidis@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
40require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
41require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
42require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
43require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
44
45
46// Load translation files required by the page
47$langs->loadLangs(array('bills', 'companies', 'compta'));
48
49$action = GETPOST('action', 'aZ09');
50$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
51$search_date_start = GETPOSTDATE('search_date_start', 'getpost'); // Use tzserver because invoice date is a date without hour
52$search_date_end = GETPOSTDATE('search_date_end', 'getpostend');
53$search_status = GETPOST('search_status', 'aZ09');
54if (!in_array($search_status, array('unpaid', 'paid'), true)) {
55 $search_status = '';
56}
57$search_late = GETPOST('search_late', 'aZ09');
58if (!in_array($search_late, array('late', 'notlate'), true)) {
59 $search_late = '';
60}
61if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests are required to be compatible with all browsers
62 $search_date_start = '';
63 $search_date_end = '';
64 $search_status = '';
65 $search_late = '';
66}
67
68// Security check
69$socid = GETPOSTINT("socid");
70if ($user->isExternalUser()) {
71 $action = '';
72 $socid = $user->isExternalUser();
73}
74$result = restrictedArea($user, 'societe', $socid, '&societe');
75
76// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
77$hookmanager->initHooks(array('supplierbalencelist', 'globalcard'));
78
79// Load variable for pagination
80$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
81$sortfield = GETPOST('sortfield', 'aZ09comma');
82$sortorder = GETPOST('sortorder', 'aZ09comma');
83$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
84if (empty($page) || $page == -1) {
85 $page = 0;
86} // If $page is not defined, or '' or -1
87$offset = $limit * $page;
88$pageprev = $page - 1;
89$pagenext = $page + 1;
90if (!$sortfield) {
91 $sortfield = "f.datef,f.rowid"; // Set here default search field
92}
93if (!$sortorder) {
94 $sortorder = "DESC";
95}
96
97// Export of the statement. Test on permission already done
98$permissiontoreadinvoice = ((isModEnabled("fournisseur") && $user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight("supplier_invoice", "lire")));
99
100// Date filter as url parameters
101$dateparam = '';
102foreach (array('search_date_start' => $search_date_start, 'search_date_end' => $search_date_end) as $dateprefix => $datets) {
103 if ($datets) {
104 $dateparam .= '&' . $dateprefix . 'day=' . dol_print_date($datets, '%d') . '&' . $dateprefix . 'month=' . dol_print_date($datets, '%m') . '&' . $dateprefix . 'year=' . dol_print_date($datets, '%Y');
105 }
106}
107$filterparam = '';
108if ($search_status !== '') {
109 $filterparam .= '&search_status=' . urlencode($search_status);
110}
111if ($search_late !== '') {
112 $filterparam .= '&search_late=' . urlencode($search_late);
113}
114
115
130function recapFournGetData($db, $societe, $sortfield, $sortorder, $datestart, $dateend, &$opening, $search_status = '', $search_late = '')
131{
132 global $langs;
133
134 $userstatic = new User($db);
135
137 $TData = array();
138
139 $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.total_ttc, f.datef as df,";
140 $sql .= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
141 $sql .= " u.login, u.rowid as userid";
142 $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s," . MAIN_DB_PREFIX . "facture_fourn as f," . MAIN_DB_PREFIX . "user as u";
143 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = " . ((int) $societe->id);
144 $sql .= " AND f.entity IN (" . getEntity("facture_fourn") . ")"; // Recognition of the entity attributed to this invoice for Multicompany
145 $sql .= " AND f.fk_user_valid = u.rowid";
146 $sql .= $db->order($sortfield, $sortorder);
147
148 $resql = $db->query($sql);
149 if ($resql) {
150 $num = $db->num_rows($resql);
151
152 // Loop over each invoice
153 for ($i = 0; $i < $num; $i++) {
154 $objf = $db->fetch_object($resql);
155
156 $fac = new FactureFournisseur($db);
157 $ret = $fac->fetch($objf->facid);
158 if ($ret < 0) {
159 print $fac->error . "<br>";
160 continue;
161 }
162 $totalpaid = $fac->getSommePaiement();
163
164 if ($search_status !== '') {
165 $remaintopay = $societe->getInvoiceRemainToPayInOutstanding($fac, 'supplier', 0);
166 if ($search_status === 'unpaid' && $remaintopay <= 0) {
167 continue;
168 }
169 if ($search_status === 'paid' && ($remaintopay > 0 || $fac->status == FactureFournisseur::STATUS_DRAFT || $fac->status == FactureFournisseur::STATUS_ABANDONED)) {
170 continue;
171 }
172 }
173 if ($search_late !== '') {
174 $remaintopaylate = $societe->getInvoiceRemainToPayInOutstanding($fac, 'supplier', 1);
175 if (($search_late === 'late' && $remaintopaylate <= 0) || ($search_late === 'notlate' && $remaintopaylate > 0)) {
176 continue;
177 }
178 }
179
180 $userstatic->id = $objf->userid;
181 $userstatic->login = $objf->login;
182
183 $values = array(
184 'fk_facture' => $objf->facid,
185 'date' => $fac->date,
186 'datefieldforsort' => $fac->date . '-' . $fac->ref,
187 'link' => $fac->getNomUrl(1),
188 'status' => $fac->getLibStatut(2, $totalpaid),
189 'amount' => $fac->total_ttc,
190 'author' => $userstatic->getLoginUrl(1),
191 'ref' => $fac->ref . ($fac->ref_supplier ? ' (' . $fac->ref_supplier . ')' : ''),
192 'statuslabel' => dol_string_nohtmltag($fac->getLibStatut(1, $totalpaid))
193 );
194
195 $TData[] = $values;
196
197 // Payments
198 $sql = "SELECT p.rowid, p.ref, p.datep as dp, pf.amount, p.statut,";
199 $sql .= " p.fk_user_author, u.login, u.rowid as userid";
200 $sql .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as pf,";
201 $sql .= " " . MAIN_DB_PREFIX . "paiementfourn as p";
202 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON p.fk_user_author = u.rowid";
203 $sql .= " WHERE pf.fk_paiementfourn = p.rowid";
204 $sql .= " AND pf.fk_facturefourn = " . ((int) $fac->id);
205 $sql .= " ORDER BY p.datep ASC, p.rowid ASC";
206
207 $resqlp = $db->query($sql);
208 if ($resqlp) {
209 $nump = $db->num_rows($resqlp);
210 $j = 0;
211
212 while ($j < $nump) {
213 $objp = $db->fetch_object($resqlp);
214
215 $paymentstatic = new PaiementFourn($db);
216 $paymentstatic->id = $objp->rowid;
217 $paymentstatic->ref = $objp->ref;
218
219 $userstatic->id = $objp->userid;
220 $userstatic->login = $objp->login;
221
222 $values = array(
223 'fk_paiement' => $objp->rowid,
224 'date' => $db->jdate($objp->dp),
225 'datefieldforsort' => $db->jdate($objp->dp) . '-' . $fac->ref,
226 'link' => $langs->trans("Payment") . ' ' . $paymentstatic->getNomUrl(1),
227 'status' => '',
228 'amount' => -$objp->amount,
229 'author' => $userstatic->getLoginUrl(1),
230 'ref' => $langs->transnoentitiesnoconv("Payment") . ' ' . $objp->ref . ' (' . $fac->ref . ')',
231 'statuslabel' => ''
232 );
233
234 $TData[] = $values;
235
236 $j++;
237 }
238
239 $db->free($resqlp);
240 } else {
241 dol_print_error($db);
242 }
243 }
244 } else {
245 dol_print_error($db);
246 }
247
248 $opening = 0.0;
249 if (empty($TData)) {
250 return $TData;
251 }
252
253 // Sort array by date ASC to calculate balance
254 $TData = dol_sort_array($TData, 'datefieldforsort', 'ASC');
255
256 // Balance calculation
257 $balance = 0;
258 foreach (array_keys($TData) as $key) {
259 $balance += $TData[$key]['amount'];
260 if (!array_key_exists('balance', $TData[$key])) {
261 $TData[$key]['balance'] = 0;
262 }
263 $TData[$key]['balance'] += $balance;
264 }
265
266 // Date filter. The balance was computed on the full history, so rows keep their real balance.
267 if ($datestart || $dateend) {
268 $filtered = array();
269 foreach ($TData as $row) {
270 if ($datestart && (int) $row['date'] < $datestart) {
271 $opening = (float) $row['balance'];
272 continue;
273 }
274 if ($dateend && (int) $row['date'] > $dateend) {
275 continue;
276 }
277 $filtered[] = $row;
278 }
279 if ($datestart && (!empty($filtered) || (float) price2num($opening, 'MT') != 0)) {
280 $filtered[] = array(
281 'isopening' => true,
282 'date' => $datestart,
283 'datefieldforsort' => '',
284 'amount' => 0,
285 'ref' => $langs->transnoentitiesnoconv("PreviousBalance"),
286 'balance' => $opening
287 );
288 }
289 $TData = $filtered;
290 }
291
292 // Resorte array to have elements on the required $sortorder
293 $TData = dol_sort_array($TData, 'datefieldforsort', $sortorder);
294
295 return $TData;
296}
297
307function recapFournPdfTableHeader($pdf, $outputlangs, $widths, $fontsize)
308{
309 $pdf->SetFont('', 'B', $fontsize - 1);
310 $pdf->SetFillColor(230, 230, 230);
311 $pdf->Cell($widths[0], 6, $outputlangs->transnoentities("Date"), 1, 0, 'C', true);
312 $pdf->Cell($widths[1], 6, $outputlangs->transnoentities("Element"), 1, 0, 'L', true);
313 $pdf->Cell($widths[2], 6, $outputlangs->transnoentities("Status"), 1, 0, 'L', true);
314 $pdf->Cell($widths[3], 6, $outputlangs->transnoentities("Debit"), 1, 0, 'R', true);
315 $pdf->Cell($widths[4], 6, $outputlangs->transnoentities("Credit"), 1, 0, 'R', true);
316 $pdf->Cell($widths[5], 6, $outputlangs->transnoentities("Balance"), 1, 1, 'R', true);
317 $pdf->SetFont('', '', $fontsize - 1);
318}
319
320
321/*
322 * Actions
323 */
324
325if ($action == 'exportpdf' && $socid > 0 && $permissiontoreadinvoice) {
326 $societe = new Societe($db);
327 $societe->fetch($socid);
328 $opening = 0.0;
329 $TData = recapFournGetData($db, $societe, $sortfield, $sortorder, $search_date_start, $search_date_end, $opening, $search_status, $search_late);
330
331 $outputlangs = $langs;
332 $pdfinit = reportPdfInit($outputlangs, (string) $societe->name, $outputlangs->transnoentities("SupplierPreview"));
333 $pdf = $pdfinit['pdf'];
334 $margin = $pdfinit['margin'];
335 $pageheight = $pdfinit['pageheight'];
336 $usablewidth = $pdfinit['usablewidth'];
337 $fontsize = $pdfinit['fontsize'];
338 // Date, Element, Status, Debit, Credit, Balance
339 $ratios = array(0.12, 0.30, 0.16, 0.14, 0.14, 0.14);
340 $widths = array();
341 foreach ($ratios as $ratio) {
342 $widths[] = round($usablewidth * $ratio, 2);
343 }
344
345 $posy = reportPdfCompanyHeader($pdf, $outputlangs, $mysoc, $margin, $fontsize);
346
347 // Title block
348 $pdf->SetXY($margin, $posy);
349 $pdf->SetFont('', 'B', $fontsize + 3);
350 $pdf->Cell($usablewidth, 8, $outputlangs->convToOutputCharset($outputlangs->transnoentities("SupplierPreview")), 0, 1, 'L');
351 $supplierlabel = $societe->name . ($societe->code_fournisseur ? ' (' . $societe->code_fournisseur . ')' : '');
352 $pdf->SetFont('', 'B', $fontsize);
353 $pdf->Cell($usablewidth, 5, $outputlangs->transnoentities("ThirdParty") . ': ' . $outputlangs->convToOutputCharset($supplierlabel), 0, 1, 'L');
354 $pdf->SetFont('', '', $fontsize - 1);
355 $periodlabel = reportPeriodLabel($outputlangs, $search_date_start, $search_date_end);
356 if ($periodlabel !== '') {
357 $pdf->Cell($usablewidth, 5, $outputlangs->transnoentities("Period") . ': ' . $outputlangs->convToOutputCharset($periodlabel), 0, 1, 'L');
358 }
359 $pdf->Cell($usablewidth, 5, $outputlangs->transnoentities("Date") . ': ' . dol_print_date(dol_now(), 'dayhour', 'tzuser', $outputlangs), 0, 1, 'L');
360 $pdf->Ln(3);
361
362 recapFournPdfTableHeader($pdf, $outputlangs, $widths, $fontsize);
363
364 $totalDebit = 0;
365 $totalCredit = 0;
366 $rowheight = 5;
367 if (empty($TData)) {
368 $pdf->Cell($usablewidth, $rowheight, $outputlangs->transnoentities("NoInvoice"), 1, 1, 'L');
369 }
370 foreach ($TData as $data) {
371 if ($pdf->GetY() + $rowheight > $pageheight - $margin) {
372 $pdf->AddPage();
373 recapFournPdfTableHeader($pdf, $outputlangs, $widths, $fontsize);
374 }
375 if (!empty($data['isopening'])) {
376 $pdf->SetFont('', 'B', $fontsize - 1);
377 $pdf->Cell($widths[0], $rowheight, dol_print_date($data['date'], 'day', 'tzserver', $outputlangs), 1, 0, 'C');
378 $pdf->Cell($widths[1] + $widths[2], $rowheight, $outputlangs->convToOutputCharset((string) $data['ref']), 1, 0, 'L', false, '', 1);
379 $pdf->Cell($widths[3], $rowheight, '', 1, 0, 'R');
380 $pdf->Cell($widths[4], $rowheight, '', 1, 0, 'R');
381 $pdf->Cell($widths[5], $rowheight, price(price2num((float) $data['balance'], 'MT'), 0, $outputlangs), 1, 1, 'R');
382 $pdf->SetFont('', '', $fontsize - 1);
383 continue;
384 }
385 $amount = (float) price2num($data['amount'], 'MT');
386 $debit = ($amount > 0) ? $amount : 0;
387 $credit = ($amount < 0) ? abs($amount) : 0;
388 $totalDebit += $debit;
389 $totalCredit += $credit;
390
391 $pdf->Cell($widths[0], $rowheight, dol_print_date($data['date'], 'day', 'auto', $outputlangs), 1, 0, 'C');
392 $pdf->Cell($widths[1], $rowheight, $outputlangs->convToOutputCharset((string) ($data['ref'] ?? '')), 1, 0, 'L', false, '', 1);
393 $pdf->Cell($widths[2], $rowheight, $outputlangs->convToOutputCharset((string) ($data['statuslabel'] ?? '')), 1, 0, 'L', false, '', 1);
394 $pdf->Cell($widths[3], $rowheight, ($debit ? price($debit, 0, $outputlangs) : ''), 1, 0, 'R');
395 $pdf->Cell($widths[4], $rowheight, ($credit ? price($credit, 0, $outputlangs) : ''), 1, 0, 'R');
396 $pdf->Cell($widths[5], $rowheight, price(price2num((float) $data['balance'], 'MT'), 0, $outputlangs), 1, 1, 'R');
397 }
398
399 if (!empty($TData)) {
400 if ($pdf->GetY() + $rowheight > $pageheight - $margin) {
401 $pdf->AddPage();
402 }
403 $pdf->SetFont('', 'B', $fontsize - 1);
404 $pdf->Cell($widths[0] + $widths[1] + $widths[2], $rowheight, $outputlangs->transnoentities("Total"), 1, 0, 'L');
405 $pdf->Cell($widths[3], $rowheight, price($totalDebit, 0, $outputlangs), 1, 0, 'R');
406 $pdf->Cell($widths[4], $rowheight, price($totalCredit, 0, $outputlangs), 1, 0, 'R');
407 $pdf->Cell($widths[5], $rowheight, price(price2num($opening + $totalDebit - $totalCredit, 'MT'), 0, $outputlangs), 1, 1, 'R');
408 }
409
410 $filename = reportFileName($outputlangs->transnoentitiesnoconv("SupplierPreview"), ((string) $societe->name !== '' ? (string) $societe->name : (string) $societe->id), 'pdf');
411 $pdf->Output($filename, 'I');
412
413 $db->close();
414 exit;
415}
416
417
418if ($action == 'exportxlsx' && $socid > 0 && $permissiontoreadinvoice) {
419 if (!class_exists('ZipArchive')) {
420 $langs->load("errors");
421 setEventMessages($langs->trans('ErrorPHPNeedModule', 'zip'), null, 'errors');
422 header('Location: ' . $_SERVER["PHP_SELF"] . '?socid=' . ((int) $socid) . ($dol_openinpopup ? '&dol_openinpopup=' . urlencode($dol_openinpopup) : ''));
423 exit;
424 }
425
426 $societe = new Societe($db);
427 $societe->fetch($socid);
428 $opening = 0.0;
429 $TData = recapFournGetData($db, $societe, $sortfield, $sortorder, $search_date_start, $search_date_end, $opening, $search_status, $search_late);
430
431 $spreadsheet = reportXlsxInit($langs, $langs->transnoentitiesnoconv("SupplierPreview") . ' - ' . $societe->name, (string) $societe->name);
432 $sheet = $spreadsheet->getActiveSheet();
433
434 // Header: logo on the left, company info on the right (same as the PDF)
435 $headrows = reportXlsxCompanyHeader($sheet, $langs, $mysoc, 'C', 'F');
436
437 // Title block
438 $row = $headrows + 2;
439 $sheet->setCellValue('A' . $row, $langs->transnoentitiesnoconv("SupplierPreview"));
440 $sheet->getStyle('A' . $row)->getFont()->setBold(true)->setSize(14);
441 $row++;
442 $supplierlabel = $societe->name . ($societe->code_fournisseur ? ' (' . $societe->code_fournisseur . ')' : '');
443 $sheet->setCellValueExplicit('A' . $row, $langs->transnoentitiesnoconv("ThirdParty") . ': ' . $supplierlabel, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
444 $sheet->getStyle('A' . $row)->getFont()->setBold(true);
445 $row++;
446 $periodlabel = reportPeriodLabel($langs, $search_date_start, $search_date_end);
447 if ($periodlabel !== '') {
448 $sheet->setCellValueExplicit('A' . $row, $langs->transnoentitiesnoconv("Period") . ': ' . $periodlabel, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
449 $row++;
450 }
451 $sheet->setCellValueExplicit('A' . $row, $langs->transnoentitiesnoconv("Date") . ': ' . dol_print_date(dol_now(), 'dayhour', 'tzuser', $langs), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
452 $row += 2;
453
454 // Table
455 $headrow = $row;
456 $headers = array('A' => "Date", 'B' => "Element", 'C' => "Status", 'D' => "Debit", 'E' => "Credit", 'F' => "Balance");
457 foreach ($headers as $colletter => $key) {
458 $sheet->setCellValue($colletter . $headrow, $langs->transnoentitiesnoconv($key));
459 }
460 $sheet->getStyle('A' . $headrow . ':F' . $headrow)->getFont()->setBold(true);
461 $sheet->getStyle('D' . $headrow . ':F' . $headrow)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT);
462 $sheet->freezePane('A' . ($headrow + 1));
463
464 $firstrow = $headrow + 1;
465 $row = $firstrow;
466 $openrow = 0;
467 foreach ($TData as $data) {
468 if (!empty($data['isopening'])) {
469 $openrow = $row;
470 $sheet->setCellValue('A' . $row, \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel((int) dol_print_date($data['date'], '%Y'), (int) dol_print_date($data['date'], '%m'), (int) dol_print_date($data['date'], '%d')));
471 $sheet->setCellValueExplicit('B' . $row, (string) $data['ref'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
472 $sheet->setCellValue('F' . $row, (float) price2num((float) $data['balance'], 'MT'));
473 $sheet->getStyle('A' . $row . ':F' . $row)->getFont()->setBold(true);
474 $row++;
475 continue;
476 }
477 $amount = (float) price2num($data['amount'], 'MT');
478 if (!empty($data['date'])) {
479 $sheet->setCellValue('A' . $row, \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel((int) dol_print_date($data['date'], '%Y'), (int) dol_print_date($data['date'], '%m'), (int) dol_print_date($data['date'], '%d')));
480 }
481 $sheet->setCellValueExplicit('B' . $row, (string) ($data['ref'] ?? ''), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
482 $sheet->setCellValueExplicit('C' . $row, (string) ($data['statuslabel'] ?? ''), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
483 if ($amount > 0) {
484 $sheet->setCellValue('D' . $row, $amount);
485 } elseif ($amount < 0) {
486 $sheet->setCellValue('E' . $row, abs($amount));
487 }
488 $sheet->setCellValue('F' . $row, (float) price2num((float) $data['balance'], 'MT'));
489 $row++;
490 }
491
492 if ($row > $firstrow) {
493 $last = $row - 1;
494 $sheet->setCellValue('C' . $row, $langs->transnoentitiesnoconv("Total"));
495 $sheet->setCellValue('D' . $row, '=SUM(D' . $firstrow . ':D' . $last . ')');
496 $sheet->setCellValue('E' . $row, '=SUM(E' . $firstrow . ':E' . $last . ')');
497 $sheet->setCellValue('F' . $row, ($openrow ? '=F' . $openrow . '+' : '=') . 'D' . $row . '-E' . $row);
498 $sheet->getStyle('A' . $row . ':F' . $row)->getFont()->setBold(true);
499 }
500
501 $sheet->getStyle('A' . $firstrow . ':A' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD);
502 $sheet->getStyle('D' . $firstrow . ':F' . $row)->getNumberFormat()->setFormatCode('#,##0.00');
503 foreach (array('A' => 12, 'B' => 34, 'C' => 20, 'D' => 14, 'E' => 14, 'F' => 14) as $colletter => $colwidth) {
504 $sheet->getColumnDimension($colletter)->setWidth($colwidth);
505 }
506
507 // Print on one page width
508 $sheet->getPageSetup()->setFitToPage(true);
509 $sheet->getPageSetup()->setFitToWidth(1);
510 $sheet->getPageSetup()->setFitToHeight(0);
511
512 $filename = reportFileName($langs->transnoentitiesnoconv("SupplierPreview"), ((string) $societe->name !== '' ? (string) $societe->name : (string) $societe->id), 'xlsx');
513 reportXlsxOutput($spreadsheet, $filename);
514
515 $db->close();
516 exit;
517}
518
519
520/*
521 * View
522 */
523
524$form = new Form($db);
525$userstatic = new User($db);
526
527llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-fourn page-recap-fourn');
528
529if ($socid > 0) {
530 $societe = new Societe($db);
531 $societe->fetch($socid);
532
533 /*
534 * Show tabs
535 */
536 if (empty($dol_openinpopup)) {
537 $head = societe_prepare_head($societe);
538
539 print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
540 dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
541 print dol_get_fiche_end();
542 }
543
544 if ((isModEnabled("fournisseur") && $user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight("supplier_invoice", "lire"))) {
545 // Invoice list
546 $morehtmlright = reportExportButtons('&socid=' . ((int) $socid) . '&sortfield=' . urlencode($sortfield) . '&sortorder=' . urlencode($sortorder) . $dateparam . $filterparam, 'recapfourn');
547 $titrelist = $langs->trans("SupplierPreview");
548 if ($search_status === 'unpaid' && $search_late === 'late') {
549 $titrelist = $langs->trans("CurrentOutstandingBillLate");
550 } elseif ($search_status === 'unpaid' && $search_late === '') {
551 $titrelist = $langs->trans("CurrentOutstandingBill");
552 }
553 print load_fiche_titre($titrelist, $morehtmlright);
554
555 // Add parameter for sorting
556 $param = '';
557 if ($socid > 0) {
558 $param .= '&socid=' . $socid;
559 }
560 if ($dol_openinpopup) {
561 $param .= '&dol_openinpopup=' . urlencode($dol_openinpopup);
562 }
563 $param .= $dateparam . $filterparam;
564
565 // Date filter
566 print '<form method="GET" action="' . dol_escape_htmltag($_SERVER["PHP_SELF"]) . '" name="recapfournfilter">';
567 print '<input type="hidden" name="socid" value="' . ((int) $socid) . '">';
568 if ($dol_openinpopup) {
569 print '<input type="hidden" name="dol_openinpopup" value="' . dol_escape_htmltag($dol_openinpopup) . '">';
570 }
571 print '<input type="hidden" name="sortfield" value="' . dol_escape_htmltag($sortfield) . '">';
572 print '<input type="hidden" name="sortorder" value="' . dol_escape_htmltag($sortorder) . '">';
573 print '<div class="div-table-responsive-no-min">';
574 print '<div class="inline-block valignmiddle nowrapfordate">';
575 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
576 print '</div> ';
577 print '<div class="inline-block valignmiddle nowrapfordate">';
578 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
579 print '</div> ';
580 print '<div class="inline-block valignmiddle marginleftonlyshort">' . $langs->trans('Status') . ' ';
581 print $form->selectarray('search_status', array('unpaid' => $langs->trans('Unpaid'), 'paid' => $langs->trans('Paid')), $search_status, $langs->trans('All'), 0, 0, '', 0, 0, 0, '', 'minwidth100', 0);
582 print '</div> ';
583 print '<div class="inline-block valignmiddle marginleftonlyshort">' . $langs->trans('Late') . ' ';
584 print $form->selectarray('search_late', array('late' => $langs->trans('Late'), 'notlate' => $langs->trans('NotLate')), $search_late, $langs->trans('All'), 0, 0, '', 0, 0, 0, '', 'minwidth100', 0);
585 print '</div> ';
586 print '<div class="inline-block valignmiddle">' . $form->showFilterButtons() . '</div>';
587 print '</div>';
588 print '</form>';
589
590 print '<table class="noborder tagtable liste centpercent">';
591 print '<tr class="liste_titre">';
592 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
593 print '<td>' . $langs->trans("Element") . '</td>';
594 print '<td>' . $langs->trans("Status") . '</td>';
595 print '<td class="right">' . $langs->trans("Debit") . '</td>';
596 print '<td class="right">' . $langs->trans("Credit") . '</td>';
597 print '<td class="right">' . $langs->trans("Balance") . '</td>';
598 print '<td class="right">' . $langs->trans("Author") . '</td>';
599 print '</tr>';
600
601 $opening = 0.0;
602 $TData = recapFournGetData($db, $societe, $sortfield, $sortorder, $search_date_start, $search_date_end, $opening, $search_status, $search_late);
603
604 if (empty($TData)) {
605 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">' . $langs->trans("NoInvoice") . '</span></td></tr>';
606 } else {
607 $totalDebit = 0;
608 $totalCredit = 0;
609
610 // Display array
611 foreach ($TData as $data) {
612 if (!empty($data['isopening'])) {
613 print '<tr class="oddeven">';
614 print '<td class="center">' . dol_print_date($data['date'], 'day', 'tzserver') . '</td>';
615 print '<td colspan="2"><b>' . dol_escape_htmltag((string) $data['ref']) . '</b></td>';
616 print '<td></td><td></td>';
617 print '<td class="right"><span class="amount"><b>' . price($data['balance']) . '</b></span></td>';
618 print '<td></td>';
619 print "</tr>\n";
620 continue;
621 }
622 $html_class = '';
623 if (!empty($data['fk_facture'])) {
624 $html_class = 'facid-' . $data['fk_facture'];
625 } elseif (!empty($data['fk_paiement'])) {
626 $html_class = 'payid-' . $data['fk_paiement'];
627 }
628
629 print '<tr class="oddeven ' . $html_class . '">';
630
631 $datedetail = dol_print_date($data['date'], 'dayhour');
632 if (!empty($data['fk_facture'])) {
633 $datedetail = dol_print_date($data['date'], 'day');
634 }
635 print '<td class="center" title="' . dol_escape_htmltag($datedetail) . '">';
636 print dol_print_date($data['date'], 'day');
637 print "</td>\n";
638
639 print '<td>' . $data['link'] . "</td>\n";
640
641 print '<td class="left">' . $data['status'] . '</td>';
642
643 print '<td class="right">' . (($data['amount'] > 0) ? price(abs($data['amount'])) : '') . "</td>\n";
644
645 $totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0;
646
647 print '<td class="right">' . (($data['amount'] > 0) ? '' : price(abs($data['amount']))) . "</td>\n";
648 $totalCredit += ($data['amount'] > 0) ? 0 : abs($data['amount']);
649
650 // Balance
651 print '<td class="right"><span class="amount">' . price($data['balance']) . "</span></td>\n";
652
653 // Author
654 print '<td class="nowrap right">';
655 print $data['author'];
656 print '</td>';
657
658 print "</tr>\n";
659 }
660
661 print '<tr class="liste_total">';
662 print '<td colspan="3">&nbsp;</td>';
663 print '<td class="right">' . price($totalDebit) . '</td>';
664 print '<td class="right">' . price($totalCredit) . '</td>';
665 print '<td class="right">' . price(price2num($opening + $totalDebit - $totalCredit, 'MT')) . '</td>';
666 print '<td></td>';
667 print "</tr>\n";
668 }
669
670 print "</table>";
671 }
672} else {
673 dol_print_error($db);
674}
675
676// End of page
677llxFooter();
678$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage suppliers invoices.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments for supplier invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
global $mysoc
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
recapFournPdfTableHeader($pdf, $outputlangs, $widths, $fontsize)
Print the statement table header row into the PDF.
reportPeriodLabel($outputlangs, $datestart, $dateend)
Return the label of a filtered period.
reportXlsxCompanyHeader($sheet, $outputlangs, $mysoc, $firstcol, $lastcol)
Write logo (left) and company info (right) at top of a report worksheet.
reportPdfInit($outputlangs, $title, $subject, $orientation='P')
Create a PDF instance for a report, with first page added.
reportFileName($title, $name, $ext)
Return a report export file name.
reportPdfCompanyHeader($pdf, $outputlangs, $mysoc, $margin, $fontsize)
Print our company logo (left) and company info (right) at top of a report PDF page.
reportXlsxInit($outputlangs, $title, $sheetlabel)
Create a spreadsheet for a report.
reportExportButtons($param, $idprefix, $enabled=1)
Return the PDF and XLSX export buttons of a report page.
reportXlsxOutput($spreadsheet, $filename)
Send a report spreadsheet to the browser as an xlsx download.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.