Plugin Contratti del cliente

This commit is contained in:
Beppe 2021-10-25 11:08:03 +02:00
parent 99ef21ee72
commit 6c65315e65
3 changed files with 227 additions and 8 deletions

View File

@ -31,20 +31,20 @@ if (!$is_cliente && !$is_fornitore && $is_tecnico) {
foreach ($ignore as $plugin) {
echo '
<script>
$("#link-tab_'.$plugin['id'].'").addClass("disabled");
</script>';
<script>
$("#link-tab_'.$plugin['id'].'").addClass("disabled");
</script>';
}
}
if (!$is_cliente) {
$ignore = $dbo->fetchArray("SELECT id FROM zz_plugins WHERE name='Impianti del cliente' OR name='Ddt del cliente'");
$ignore = $dbo->fetchArray("SELECT id FROM zz_plugins WHERE name IN ('Impianti del cliente','Contratti del cliente','Ddt del cliente')");
foreach ($ignore as $plugin) {
echo '
<script>
$("#link-tab_'.$plugin['id'].'").addClass("disabled");
</script>';
<script>
$("#link-tab_'.$plugin['id'].'").addClass("disabled");
</script>';
}
}

View File

@ -0,0 +1,216 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* 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/>.
*/
include_once __DIR__.'/../../../core.php';
use Modules\Contratti\Contratto;
//Estraggo tutti i contratti del cliente
$contratti = $dbo->table("co_contratti")->where('idanagrafica',$id_record)->get();
if( !$contratti->isEmpty() ){
echo '
<div class="row">
<div class="col-md-12">
<table class="table table-bordered table-condensed">
<tr>
<th>'.tr('Documento').'</th>
<th width="11%">'.tr('Totale').'</th>
<th width="3%"></th>
</tr>';
foreach($contratti as $c){
$contratto = Contratto::find($c->id);
$righe = $contratto->getRighe();
// Calcoli
$imponibile = abs($contratto->imponibile);
$sconto = $contratto->sconto;
$totale_imponibile = abs($contratto->totale_imponibile);
$iva = abs($contratto->iva);
$totale = abs($contratto->totale);
$descrizione = tr('Contratto num. _NUM_ del _DATA_',[
'_NUM_' => $contratto->numero,
'_DATA_' => Translator::dateToLocale($contratto->data_bozza),
]);
echo '
<tr>
<td>'.Modules::link('Contratti', $contratto->id, $descrizione).'</td>
<td class="text-right">'.moneyFormat($contratto->totale, 2).'</td>
<td class="text-center">
<a class="btn btn-xs btn-primary" onclick="if( $(\'#righe_'.$contratto->id.'\').is(\':visible\') ){ $(\'#righe_'.$contratto->id.'\').hide(); }else{ $(\'#righe_'.$contratto->id.'\').show(); }"><i class="fa fa-plus"></i></a>
</td>
</tr>';
if( $righe->isempty() ){
echo '
<tr id="righe_'.$contratto->id.'" >
<td colspan="3" class="text-muted">'.tr('Nessuna riga presente!').'</td>
</tr>';
}else{
echo '
<tr id="righe_'.$contratto->id.'" style="display:none;">
<td colspan="3">
<table class="table table-bordered table-stripped">
<tr>
<th width="2%">#</th>
<th>'.tr('Descrizione').'</th>
<th class="text-center" width="8%">'.tr('Q.').'</th>
<th width="11%">'.tr('Prezzo unitario').'</th>
<th width="11%">'.tr('Iva unitaria').'</th>
<th width="11%">'.tr('Importo').'</th>
</tr>';
$num = 0;
foreach($righe as $riga){
++$num;
echo '
<tr>
<td class="text-center">'.$num.'</td>';
// Descrizione
$descrizione = nl2br($riga->descrizione);
if ($riga->isArticolo()) {
$descrizione = Modules::link('Articoli', $riga->idarticolo, $riga->codice.' - '.$descrizione);
}
echo '
<td>'.$descrizione.'</td>';
// Quantità e unità di misura
echo '
<td class="text-center">
'.numberFormat($riga->qta_rimanente, 'qta').' / '.numberFormat($riga->qta, 'qta').' '.$riga->um.'
</td>';
// Prezzi unitari
echo '
<td class="text-right">
'.moneyFormat($riga->prezzo_unitario_corrente);
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
echo '
<br><small class="text-muted">
'.tr('Acquisto').': '.moneyFormat($riga->costo_unitario).'
</small>';
}
if (abs($riga->sconto_unitario) > 0) {
$text = discountInfo($riga);
echo '
<br><small class="label label-danger">'.$text.'</small>';
}
echo '
</td>';
// Iva
echo '
<td class="text-right">
'.moneyFormat($riga->iva_unitaria_scontata).'
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
</td>';
// Importo
echo '
<td class="text-right">
'.moneyFormat($riga->importo).'
</td>
</tr>';
}
// Totale totale imponibile
echo '
<tr>
<td colspan="5" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
'.moneyFormat($contratto->imponibile, 2).'
</td>
</tr>';
// SCONTO
if (!empty($sconto)) {
echo '
<tr>
<td colspan="5" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
'.moneyFormat($contratto->sconto, 2).'
</td>
</tr>';
// Totale totale imponibile
echo '
<tr>
<td colspan="5" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
'.moneyFormat($totale_imponibile, 2).'
</td>
</tr>';
}
// Totale iva
echo '
<tr>
<td colspan="5" class="text-right">
<b>'.tr('Iva', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
'.moneyFormat($contratto->iva, 2).'
</td>
</tr>';
// Totale contratto
echo '
<tr>
<td colspan="5" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
'.moneyFormat($contratto->totale, 2).'
</td>
</tr>';
echo '
</table>
</td>
</tr>';
}
}
echo '
</table>
</div>
</div>';
}else{
echo '
<div class="row">
<div class="col-md-12">
<span style="text-muted">'.tr('Non è stato trovato nessun contratto associato a questo cliente!').'</span>
</div>
</div>';
}

View File

@ -25,4 +25,7 @@ INSERT INTO `zz_tasks` (`id`, `name`, `class`, `expression`, `next_execution_at`
(NULL, 'Eliminazione automatica coda d\'invio', 'Modules\\StatoEmail\\EliminaMailTask', '0 */4 * * *', NULL, NULL);
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `help`) VALUES
(NULL, 'Numero di giorni mantenimento coda di invio', '0', 'integer', 1, 'Mail', 1, NULL);
(NULL, 'Numero di giorni mantenimento coda di invio', '0', 'integer', 1, 'Mail', 1, NULL);
-- Plugin contratti del cliente
INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`) VALUES (NULL, 'Contratti del cliente', 'Contratti del cliente', '2', '2', 'tab', 'contratti_cliente.php', '1', '0', '0', '', '', NULL, NULL, '', '');