1+ <?php
2+
3+ /*
4+ * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+ * Copyright (C) DevCode s.r.l.
6+ *
7+ * This program is free software: you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation, either version 3 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19+ */
20+
21+ /**
22+ * Utility functions for displaying Prima Nota movements
23+ */
24+
25+ /**
26+ * Renderizza una tabella con i movimenti di prima nota collegati a un documento o scadenza
27+ *
28+ * @param int|null $id_documento ID del documento (fattura)
29+ * @param int|null $id_scadenza ID della scadenza
30+ * @param string|null $titolo Titolo personalizzato per la tabella
31+ * @return string HTML della tabella
32+ */
33+
34+ function renderTabellaMovimentiPrimaNota ($ id_documento = null , $ id_scadenza = null ) {
35+ global $ dbo ;
36+
37+ $ where_conditions = ["co_movimenti.primanota = 1 " ];
38+ $ params = [];
39+
40+ if (!empty ($ id_documento )) {
41+ $ where_conditions [] = "co_movimenti.iddocumento = ? " ;
42+ $ params [] = $ id_documento ;
43+ } elseif (!empty ($ id_scadenza )) {
44+ $ where_conditions [] = "co_movimenti.id_scadenza = ? " ;
45+ $ params [] = $ id_scadenza ;
46+ } else {
47+ return "" ;
48+ }
49+
50+ $ where_clause = implode (" AND " , $ where_conditions );
51+
52+ $ query = "SELECT
53+ co_movimenti.idmastrino,
54+ co_movimenti.data,
55+ co_movimenti.descrizione as causale,
56+ SUM(CASE WHEN co_movimenti.totale > 0 THEN co_movimenti.totale ELSE 0 END) as importo_totale
57+ FROM co_movimenti
58+ WHERE $ where_clause
59+ GROUP BY co_movimenti.idmastrino, co_movimenti.data, co_movimenti.descrizione
60+ ORDER BY co_movimenti.data DESC, co_movimenti.idmastrino DESC " ;
61+
62+ $ movimenti = $ dbo ->fetchArray ($ query , $ params );
63+
64+ if (empty ($ movimenti )) {
65+ return '' ;
66+ }
67+
68+ $ html = '
69+ <div class="card" style="margin-top: 15px;">
70+ <div class="card-header">
71+ <h5 class="card-title"> ' .tr ('Movimenti in prima nota ' ).'</h5>
72+ </div>
73+ <div class="card-body">
74+ <div class="table-responsive">
75+ <table class="table table-sm table-striped">
76+ <tbody> ' ;
77+
78+ foreach ($ movimenti as $ movimento ) {
79+ $ data = dateFormat ($ movimento ['data ' ]);
80+ $ causale = $ movimento ['causale ' ];
81+ $ importo = moneyFormat ($ movimento ['importo_totale ' ]);
82+
83+ $ html .= '
84+ <tr>
85+ <td style="width: 80px;"> ' .$ data .'</td>
86+ <td> ' .$ causale .'</td>
87+ <td style="text-align: right; width: 100px;"> ' .$ importo .'</td>
88+ <td style="width: 100px;">
89+ <a href=" ' .base_path ().'/editor.php?id_module= ' .$ dbo ->fetchOne ("SELECT id FROM zz_modules WHERE name = 'Prima nota' " )['id ' ].'&id_record= ' .$ movimento ['idmastrino ' ].'"
90+ class="btn btn-primary btn-xs" target="_blank">
91+ Visualizza »
92+ </a>
93+ </td>
94+ </tr> ' ;
95+ }
96+
97+ $ html .= '
98+ </tbody>
99+ </table>
100+ </div>
101+ </div>
102+ </div> ' ;
103+
104+ return $ html ;
105+ }
0 commit comments