openstamanager/plugins/pianificazione_fatturazione/crea_fattura.php

159 lines
6.0 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-02-18 18:53:28 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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/>.
*/
2024-03-05 16:01:45 +01:00
use Models\Module;
2024-03-22 15:52:24 +01:00
use Plugins\PianificazioneFatturazione\Pianificazione;
include_once __DIR__.'/../../core.php';
2020-04-20 11:23:01 +02:00
$id_rata = get('rata');
$pianificazione = Pianificazione::find($id_rata);
$contratto = $pianificazione->contratto;
2020-04-20 11:23:01 +02:00
$id_pianificazione = $pianificazione->id;
2022-01-13 16:05:11 +01:00
2023-08-04 14:54:28 +02:00
foreach ($contratto->pianificazioni as $i => $p) {
if ($p->id == $id_pianificazione) {
$numero_rata = $i + 1;
2022-01-13 16:05:11 +01:00
break;
}
}
2024-06-11 16:58:27 +02:00
$id_module_fattura = Module::where('name', 'Fatture di vendita')->first()->id;
$id_conto = setting('Conto predefinito fatture di vendita');
2021-02-18 18:48:44 +01:00
$data = date('Y-m', strtotime($pianificazione->data_scadenza)).'-'.date('d', strtotime($contratto->data_accettazione));
echo '
<form action="" method="post">
<input type="hidden" name="op" value="add_fattura">
<input type="hidden" name="backto" value="record-edit">
2020-04-20 11:23:01 +02:00
<input type="hidden" name="rata" value="'.$id_rata.'">
<input type="hidden" name="id_module" value="'.$id_module.'">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_record" value="'.$id_record.'">';
// Data
echo '
<div class="row">
<div class="col-md-6">
2021-02-18 09:57:35 +01:00
{[ "type": "date", "label": "'.tr('Data').'", "name": "data", "required": 1, "class": "text-center", "value": "'.$pianificazione->data_scadenza.'" ]}
</div>';
// Tipo di documento
echo '
<div class="col-md-6">
2024-06-20 12:04:51 +02:00
{[ "type": "select", "label": "'.tr('Tipo di fattura').'", "name": "idtipodocumento", "required": 1, "values": "query=SELECT `co_tipidocumento`.*, `co_tipidocumento_lang`.`title` as descrizione FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `dir`=\'entrata\'" ]}
</div>
</div>';
// Sezionale
echo '
<div class="row">
<div class="col-md-6">
2024-03-05 16:01:45 +01:00
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "ajax-source": "segmenti", "select-options": '.json_encode(['id_module' => $id_module_fattura, 'is_sezionale' => 1]).', "value":"'.$_SESSION['module_'.$id_module_fattura]['id_segment'].'" ]}
</div>';
// Conto
echo '
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Conto').'", "name": "id_conto", "required": 1, "value": "'.$id_conto.'", "ajax-source": "conti-vendite" ]}
</div>
</div>';
2024-01-15 15:30:45 +01:00
// Accoda a fatture non emesse
echo '
<div class="row">
<div class="col-md-6">
{[ "type": "checkbox", "label": "<small>'.tr('Aggiungere alle fatture di vendita non ancora emesse?').'</small>", "placeholder": "'.tr('Aggiungere alle fatture di vendita nello stato bozza?').'", "name": "accodare" ]}
</div>
</div>';
2024-01-15 15:30:45 +01:00
// gestione replace
2022-12-06 17:45:38 +01:00
$descrizione = setting('Descrizione fattura pianificata');
2024-06-11 16:58:27 +02:00
$modules = Module::where('name', 'Contratti')->first()->id;
$variables = include Modules::filepath($modules, 'variables.php');
foreach ($variables as $variable => $value) {
$descrizione = str_replace('{'.$variable.'}', $value, $descrizione);
}
$descrizione = str_replace('{rata}', $numero_rata, $descrizione);
echo '
<div class="row">
<div class="col-md-12">
2020-02-24 18:41:30 +01:00
{[ "type": "textarea", "label": "'.tr('Note della fattura').'", "name": "note", "value": "'.$descrizione.'" ]}
</div>
</div>';
2020-02-17 20:21:18 +01:00
// Righe
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-info">
<div class="card-header with-border">
<h3 class="card-title">
2020-02-17 20:21:18 +01:00
'.tr('Righe previste').'
</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">
2020-02-17 20:21:18 +01:00
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th width="40%">'.tr('Descrizione').'</th>
<th class="text-center">'.tr('Q.').'</th>
<th class="text-center">'.tr('Prezzo unitario').'</th>
<th class="text-center">'.tr('IVA').'</th>
<th class="text-center">'.tr('Totale imponbile').'</th>
</tr>
</thead>
<tbody>';
$righe = $pianificazione->getRighe();
foreach ($righe as $riga) {
echo '
<tr>
<td>'.$riga->descrizione.'</td>
<td class="text-center">'.$riga->qta.'</td>
<td class="text-right">'.moneyFormat($riga->prezzo_unitario).'</td>
<td class="text-right">
'.moneyFormat($riga->iva).'<br>
2024-04-18 17:44:05 +02:00
<small class="help-block">'.$riga->aliquota->getTranslation('title').'</small>
2020-02-17 20:21:18 +01:00
</td>
<td class="text-right">'.moneyFormat($riga->totale_imponibile).'</td>
</tr>';
}
echo '
</tbody>
</table>
</div>
</div>';
echo '
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary pull-right">
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>
</div>
</div>
</form>';
echo '
<script>$(document).ready(init)</script>';