Skip to content

Commit bad1805

Browse files
committed
feat: aggiunta riferimento prima nota nelle scadenze
1 parent 97e814a commit bad1805

3 files changed

Lines changed: 159 additions & 35 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
}

modules/scadenzario/actions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$data = post('data');
3333
$tipo = post('tipo');
3434
$da_pagare = post('da_pagare');
35-
$descrizione = post('descrizione');
35+
$descrizione = strip_tags(post('descrizione'));
3636
$iddocumento = post('iddocumento') ?: '';
3737
$data_emissione = post('data_emissione') ?: date('Y-m-d');
3838

@@ -51,7 +51,7 @@
5151
case 'update':
5252
$idanagrafica = post('idanagrafica');
5353
$tipo = post('tipo');
54-
$descrizione = post('descrizione');
54+
$descrizione = strip_tags(post('descrizione'));
5555
$iddocumento = post('iddocumento') ?: 0;
5656
if (!empty($iddocumento)) {
5757
$scadenze = database()->table('co_scadenziario')->where('iddocumento', '=', $iddocumento)->orderBy('scadenza')->get();

modules/scadenzario/edit.php

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<th>'.tr('Numero').':</th>
8989
<td>'.$numero.'</td>
9090
</tr>
91-
</table>
91+
</table>
9292
9393
<table class="table table-striped table-hover table-sm table-bordered">
9494
<tr>
@@ -108,44 +108,64 @@
108108
</tr>
109109
</table>
110110
111-
'.Modules::link($documento->module, $record['iddocumento'], '<i class="fa fa-folder-open"></i> '.tr('Apri documento'), null, 'class="btn btn-primary"').'
112-
</div>';
111+
'.Modules::link($documento->module, $record['iddocumento'], '<i class="fa fa-folder-open"></i> '.tr('Apri documento'), null, 'class="btn btn-primary"').'';
112+
113113
} else {
114114
$scadenza = $dbo->fetchOne('SELECT * FROM co_scadenziario WHERE id = '.prepare($id_record));
115-
echo '
116-
<table class="table table-striped table-hover table-sm table-bordered">
117-
<tr>
118-
<td>';
119-
echo input([
120-
'type' => 'ckeditor',
121-
'label' => tr('Descrizione'),
122-
'name' => 'descrizione',
123-
'required' => 1,
124-
'extra' => 'rows="2"',
125-
'value' => $record['descrizione'],
126-
]);
127115
echo '
128-
</td>
129-
</tr>
130-
</table>
131-
</div>';
116+
</table>
117+
<div class="card">
118+
<div class="card-header">
119+
<h5 class="card-title">'.tr('Descrizione').'</h5>
120+
</div>
121+
<div class="card-body">
122+
<table class="table table-striped table-hover table-sm table-bordered">
123+
<tr>
124+
<td>';
125+
echo input([
126+
'type' => 'ckeditor',
127+
'name' => 'descrizione',
128+
'extra' => 'rows="2"',
129+
'value' => $record['descrizione'],
130+
]);
131+
echo '
132+
</td>
133+
</tr>
134+
</table>
135+
</div>
136+
</div>';
137+
}
138+
139+
// Visualizzazione movimenti di prima nota con primanota = 1
140+
include_once __DIR__.'/../primanota/movimenti_utils.php';
141+
142+
if (!empty($documento)) {
143+
echo renderTabellaMovimentiPrimaNota($documento->id, null);
144+
} else {
145+
echo renderTabellaMovimentiPrimaNota(null, $id_record);
132146
}
133147

134148
echo '
149+
150+
</div>
135151
<div class="col-md-6">
136-
<table class="table table-striped table-hover table-sm table-bordered">
137-
<tr>
138-
<td>';
152+
<div class="card">
153+
<div class="card-header">
154+
<h5 class="card-title">'.tr('Note').'</h5>
155+
</div>
156+
<div class="card-body">
157+
<table class="table table-striped table-hover table-sm table-bordered">
158+
<tr>
159+
<td>';
139160
echo input([
140161
'type' => 'ckeditor',
141-
'label' => tr('Note'),
142162
'name' => 'note',
143163
'extra' => 'rows="2"',
144164
'value' => $record['note'],
145165
]);
146166
echo '
147-
</td>
148-
</tr>';
167+
</td>
168+
</tr>';
149169

150170
if (!empty($record['presentazioni_exported_at'])) {
151171
$export_riba = '<i class="fa fa-check text-success"></i> '.tr('Esportata il _DATA_', [
@@ -155,9 +175,8 @@
155175
$export_riba = '<i class="fa fa-clock-o text-warning"></i> '.tr('Non ancora esportata');
156176
}
157177
echo '
158-
</table>';
159-
160-
echo '
178+
</table>
179+
</div>
161180
</div>
162181
</div>
163182
</div>
@@ -178,8 +197,8 @@
178197
<table class="table table-hover table-sm table-bordered">
179198
<thead>
180199
<tr>
181-
<th style="width:17%;">'.tr('Banca accredito').'</th>
182-
<th style="width:16%;">'.tr('Banca addebito').'</th>
200+
<th style="width:17%;">'.tr('Banca accredito').'</th>
201+
<th style="width:16%;">'.tr('Banca addebito').'</th>
183202
<th style="width:20%;">'.tr('Metodo di pagamento').'</th>
184203
<th style="width:10%;">'.tr('Data').'</th>
185204
<th style="width:10%;">'.tr('Data concordata').'</th>
@@ -340,14 +359,14 @@
340359
<a onclick="launch_modal(\''.tr('Registra contabile pagamento').'\', \''.base_path().'/add.php?id_module='.$id_modulo_prima_nota.'&id_scadenze=-id-\');" class="btn btn-sm btn-primary">
341360
<i class="fa fa-euro"></i> '.($dir == 'entrata' ? tr('Incassa') : tr('Paga')).'
342361
</a>
343-
</td>
344-
</input>
362+
</td>
363+
</input>
345364
</tr>
346365
</tbody>
347366
</table>
348367
349368
<script>
350-
369+
351370
$(document).on("click", "#add-scadenza", function() {
352371
this.disabled = true;
353372
var i = '.$i.';

0 commit comments

Comments
 (0)