2020-04-20 11:23:01 +02:00
|
|
|
<?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/>.
|
|
|
|
*/
|
2020-04-20 11:23:01 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../../core.php';
|
2024-03-08 16:29:53 +01:00
|
|
|
use Models\Module;
|
2024-03-22 15:52:24 +01:00
|
|
|
use Models\Plugin;
|
2020-04-20 11:23:01 +02:00
|
|
|
|
2022-11-30 16:58:03 +01:00
|
|
|
$mesi = [
|
|
|
|
1 => 'Gennaio',
|
|
|
|
2 => 'Febbraio',
|
|
|
|
3 => 'Marzo',
|
|
|
|
4 => 'Aprile',
|
|
|
|
5 => 'Maggio',
|
|
|
|
6 => 'Giugno',
|
|
|
|
7 => 'Luglio',
|
|
|
|
8 => 'Agosto',
|
|
|
|
9 => 'Settembre',
|
|
|
|
10 => 'Ottobre',
|
|
|
|
11 => 'Novembre',
|
|
|
|
12 => 'Dicembre',
|
|
|
|
];
|
|
|
|
|
2023-08-04 14:54:28 +02:00
|
|
|
echo '<div class="container"
|
2022-11-30 16:58:03 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-2 col-md-offset-9">
|
|
|
|
<select class="form-control select-input openstamanager-input superselect select-year">';
|
2020-04-20 11:23:01 +02:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
for ($i = intval(date('Y')) - 1; $i <= intval(date('Y')) + 10; ++$i) {
|
|
|
|
$selectType = ($i == date('Y')) ? 'selected' : '';
|
|
|
|
echo '<option value="'.$i.'" '.$selectType.'>'.$i.'</option>';
|
|
|
|
}
|
2022-11-30 16:58:03 +01:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '</select><br>
|
2022-11-30 16:58:03 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="div-month">';
|
2024-01-15 15:30:45 +01:00
|
|
|
for ($i = 1; $i <= 12; ++$i) {
|
|
|
|
$btnType = ($i == date('m')) ? 'btn-primary' : '';
|
|
|
|
echo '<div class="col-md-1">
|
2023-08-04 14:54:28 +02:00
|
|
|
<a class="btn btn-month '.$btnType.'" data-month="'.$i.'" style="cursor:pointer" onclick="month_click($(this))">'.
|
2024-01-15 15:30:45 +01:00
|
|
|
$mesi[$i].' </br>('.$conteggio[$i - 1]->conto.')</a>
|
2022-11-30 16:58:03 +01:00
|
|
|
</div>';
|
2024-01-15 15:30:45 +01:00
|
|
|
}
|
2020-04-20 11:23:01 +02:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '</div>';
|
2022-11-30 16:58:03 +01:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '<div style="display:none" class="template-month">
|
2022-11-30 16:58:03 +01:00
|
|
|
<div class="col-md-1 " style="margin:10px 0px; padding:0px;">
|
|
|
|
<a class="btn btn-month" onclick="month_click($(this))">
|
|
|
|
<div class="text"></div>
|
|
|
|
<div class="text-count"></div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>';
|
2024-01-15 15:30:45 +01:00
|
|
|
?>
|
2022-11-30 16:58:03 +01:00
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
|
|
|
<br>
|
2023-08-04 14:54:28 +02:00
|
|
|
<input type="text" class="filter-input form-control" placeholder="<?php echo tr('Applica filtro...'); ?>">
|
2022-11-30 16:58:03 +01:00
|
|
|
<br>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '<div>
|
2022-11-30 16:58:03 +01:00
|
|
|
<table id="tbl-rate" class="table-rate table table-hover table-striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2023-09-07 14:21:32 +02:00
|
|
|
<th width="4%">'.tr(' ').'</th>
|
2022-11-30 16:58:03 +01:00
|
|
|
<th width="28%">'.tr('Scadenza').'</th>
|
|
|
|
<th width="32%">'.tr('Ragione sociale').'</th>
|
|
|
|
<th width="26%">'.tr('Importo').'</th>
|
|
|
|
<th width="10%"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>';
|
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
// Elenco fatture da emettere
|
|
|
|
foreach ($pianificazioni as $pianificazione) {
|
|
|
|
$contratto = $pianificazione->contratto;
|
|
|
|
$anagrafica = $contratto->anagrafica;
|
|
|
|
$numero_pianificazioni = $contratto->pianificazioni()->count();
|
|
|
|
echo '
|
2022-11-30 16:58:03 +01:00
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<div class="form-check">
|
|
|
|
<input class="form-check-input" type="checkbox"
|
2023-08-04 14:54:28 +02:00
|
|
|
data-contrattoId="'.$contratto->id.'" data-pianificazioneId="'.$pianificazione->id.'">
|
2022-11-30 16:58:03 +01:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div>'.dateFormat($pianificazione->data_scadenza).'</div>
|
|
|
|
<small>'.reference($contratto).'</small>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
'.Modules::link('Anagrafiche', $anagrafica->id, nl2br($anagrafica->ragione_sociale)).'
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div>'.moneyFormat($pianificazione->totale).'</div>
|
|
|
|
<small>'.tr('Rata _IND_/_NUM_ (totale: _TOT_)', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_IND_' => numberFormat($pianificazione->getNumeroPianificazione(), 0),
|
|
|
|
'_NUM_' => numberFormat($numero_pianificazioni, 0),
|
|
|
|
'_TOT_' => moneyFormat($contratto->totale),
|
|
|
|
]).
|
2024-01-15 15:30:45 +01:00
|
|
|
'</small>
|
2022-11-30 16:58:03 +01:00
|
|
|
</td>';
|
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
// Pulsanti
|
|
|
|
echo '
|
2022-11-30 16:58:03 +01:00
|
|
|
<td class="text-center">
|
|
|
|
<button type="button" class="btn btn-primary btn-sm" onclick="crea_fattura('.$contratto->id.', '.$pianificazione->id.')">
|
|
|
|
<i class="fa fa-euro"></i> '.tr('Crea fattura').'
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>';
|
2024-01-15 15:30:45 +01:00
|
|
|
}
|
2022-11-30 16:58:03 +01:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '</tbody>
|
2022-11-30 16:58:03 +01:00
|
|
|
<tfoot style="display:none">
|
|
|
|
<tr>
|
|
|
|
|
|
|
|
<td class="seleziona">
|
|
|
|
<div class="form-check">
|
|
|
|
<input class="form-check-input" type="checkbox">
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td class="data-scadenza">
|
|
|
|
<div class="text"></div>
|
|
|
|
<small></small>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td class="ragione-sociale">
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td class="importo">
|
|
|
|
<div class="text"></div>
|
|
|
|
<small></small>
|
|
|
|
</td>
|
|
|
|
<td class="text-center azione">
|
|
|
|
<button type="button" class="btn btn-default btn-sm">
|
|
|
|
<i class="fa fa-euro"></i> '.tr('Crea fattura').'
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
</table><br>
|
|
|
|
</div>';
|
2024-01-15 15:30:45 +01:00
|
|
|
?>
|
2022-11-30 16:58:03 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-4">
|
2023-08-04 14:54:28 +02:00
|
|
|
<a class="btn btn-primary seleziona-tutti"><?php echo tr('Seleziona tutti'); ?></a>
|
|
|
|
<a class="btn btn-default deseleziona-tutti"><?php echo tr('Deseleziona tutti'); ?></a>
|
2022-11-30 16:58:03 +01:00
|
|
|
</div>
|
|
|
|
<?php
|
2024-01-15 15:30:45 +01:00
|
|
|
echo '
|
2022-11-30 16:58:03 +01:00
|
|
|
|
|
|
|
<div class="col-md-3 col-md-offset-5">
|
|
|
|
<button type="button" class="btn btn-primary" onclick="crea_fattura_multipla($(this))">
|
|
|
|
<i class="fa fa-euro"></i> '.tr('Fattura tutti i selezionati').'
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-20 11:23:01 +02:00
|
|
|
</div>';
|
|
|
|
|
2024-03-20 11:13:28 +01:00
|
|
|
$id_modulo_pianificazione = (new Module())->getByField('name', 'Contratti');
|
|
|
|
$plugin_pianificazione = Plugin::find((new Plugin())->getByField('name', 'Pianificazione fatturazione'));
|
2022-11-30 16:58:03 +01:00
|
|
|
|
2020-04-20 11:23:01 +02:00
|
|
|
echo '
|
|
|
|
<script>
|
2022-11-30 16:58:03 +01:00
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
$(".select-year").on("change", function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var currentMonth = $(".div-month .btn-primary").data("month");
|
|
|
|
var currentYear = $this.val();
|
|
|
|
update_month(currentMonth, currentYear);
|
|
|
|
update_table(currentMonth, currentYear);
|
|
|
|
});
|
|
|
|
$(".filter-input").on("keyup", function() {
|
|
|
|
var value = $(this).val().toLowerCase();
|
|
|
|
$("#tbl-rate tbody tr").filter(function() {
|
|
|
|
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(".seleziona-tutti").on("click", function() {
|
|
|
|
$("#tbl-rate").find("input[type=checkbox]").each(function() {
|
|
|
|
if ($(this).closest("tr").css("display") != "none") {
|
|
|
|
$(this).prop("checked", true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(".deseleziona-tutti").on("click", function() {
|
|
|
|
$("#tbl-rate").find("input[type=checkbox]").prop("checked", false);
|
|
|
|
});
|
|
|
|
$(".select-year").change();
|
|
|
|
|
|
|
|
});
|
|
|
|
function month_click($this) {
|
|
|
|
var oldSelected = $(".div-month .btn-primary");
|
|
|
|
oldSelected.removeClass("btn-primary");
|
|
|
|
oldSelected.addClass("btn-light");
|
|
|
|
$this.removeClass("btn-light");
|
|
|
|
$this.addClass("btn-primary");
|
|
|
|
var currentMonth = $this.data("month");
|
|
|
|
var currentYear = $(".select-year").val();
|
|
|
|
update_table(currentMonth, currentYear);
|
|
|
|
}
|
|
|
|
function update_month(currentMonth, currentYear) {
|
|
|
|
$.ajax({
|
2023-08-04 14:54:28 +02:00
|
|
|
url: "'.$plugin_pianificazione->fileurl('ajax_rate.php').'",
|
2022-11-30 16:58:03 +01:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
action: "update_month",
|
|
|
|
currentYear: currentYear,
|
|
|
|
},
|
|
|
|
success: function(data){
|
|
|
|
data = JSON.parse(data);
|
|
|
|
var $template = $(".template-month");
|
|
|
|
var $div = $(".div-month");
|
|
|
|
$div.html("");
|
|
|
|
for (var i=1; i<=12; i++) {
|
|
|
|
$template.find("a").attr("data-month", i);
|
|
|
|
$template.find(".text").html(mesi[i]);
|
|
|
|
if (typeof data[i] === "undefined") {
|
|
|
|
$template.find(".text-count").html("(0)");
|
|
|
|
} else {
|
|
|
|
$template.find(".text-count").html("(" + data[i] + ")");
|
|
|
|
}
|
|
|
|
if (i == parseInt(currentMonth)) {
|
|
|
|
$template.find("a").addClass("btn-primary");
|
|
|
|
} else {
|
|
|
|
$template.find("a").addClass("btn-light");
|
|
|
|
}
|
|
|
|
$div.append($template.html());
|
|
|
|
$template.find("a").removeClass("btn-primary");
|
|
|
|
$template.find("a").removeClass("btn-light");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function update_table(currentMonth, currentYear) {
|
|
|
|
$.ajax({
|
2023-08-04 14:54:28 +02:00
|
|
|
url: "'.$plugin_pianificazione->fileurl('ajax_rate.php').'",
|
2022-11-30 16:58:03 +01:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
action: "update_table",
|
|
|
|
currentMonth: currentMonth,
|
|
|
|
currentYear: currentYear,
|
|
|
|
},
|
|
|
|
success: function(data){
|
|
|
|
data = JSON.parse(data);
|
|
|
|
var $template = $(".table-rate tfoot");
|
|
|
|
var $tbody = $(".table-rate tbody");
|
|
|
|
$tbody.html("");
|
|
|
|
$.each(data, function(key, value) {
|
|
|
|
$template.find(".seleziona input").attr("data-contrattoId", value.idContratto);
|
|
|
|
$template.find(".seleziona input").attr("data-pianificazioneId", value.idPianificazione);
|
|
|
|
$template.find(".data-scadenza .text").html(value.dataScadenza);
|
|
|
|
$template.find(".data-scadenza small").html(value.contratto);
|
|
|
|
$template.find(".ragione-sociale").html(value.ragioneSociale);
|
|
|
|
$template.find(".importo .text").html(value.totale);
|
|
|
|
$template.find(".importo small").html(value.importo);
|
|
|
|
$template.find(".azione button").attr("onclick","crea_fattura(" + value.idContratto + ", " + value.idPianificazione + ")");
|
|
|
|
$tbody.append($template.html());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-04-20 11:23:01 +02:00
|
|
|
function crea_fattura(contratto, rata){
|
2024-03-05 16:01:45 +01:00
|
|
|
openModal("Crea fattura", "'.$plugin_pianificazione->fileurl('crea_fattura.php').'?id_module='.$id_modulo_pianificazione.'&id_plugin='.$plugin_pianificazione->id.'&id_record=" + contratto + "&rata=" + rata);
|
2020-04-20 11:23:01 +02:00
|
|
|
}
|
2022-11-30 16:58:03 +01:00
|
|
|
function crea_fattura_multipla($this) {
|
|
|
|
var $table = $("table");
|
|
|
|
var $rows = $table.find("tbody");
|
|
|
|
var fatture = [];
|
|
|
|
$rows.find("input[type=checkbox]").each(function() {
|
|
|
|
if ($(this).is(":checked")) {
|
|
|
|
fatture.push($(this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$fatture = $(fatture);
|
|
|
|
records = []
|
|
|
|
for (var i=0; i<$fatture.length; i++) {
|
|
|
|
records.push(
|
|
|
|
{
|
|
|
|
rata: $fatture[i].attr("data-pianificazioneId"),
|
|
|
|
contratto: $fatture[i].attr("data-contrattoId"),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
records = JSON.stringify(records);
|
|
|
|
console.log(records);
|
|
|
|
if (records.length > 0) {
|
|
|
|
openModal(
|
|
|
|
"Crea fattura multipla",
|
2024-03-05 16:01:45 +01:00
|
|
|
"'.$plugin_pianificazione->fileurl('crea_fattura_multipla.php').'?id_module='.$id_modulo_pianificazione.
|
2023-08-04 14:54:28 +02:00
|
|
|
'&id_plugin='.$plugin_pianificazione->id.'&records=" + records
|
2022-11-30 16:58:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var mesi = {
|
|
|
|
1: "Gennaio",
|
|
|
|
2: "Febbraio",
|
|
|
|
3: "Marzo",
|
|
|
|
4: "Aprile",
|
|
|
|
5: "Maggio",
|
|
|
|
6: "Giugno",
|
|
|
|
7: "Luglio",
|
|
|
|
8: "Agosto",
|
|
|
|
9: "Settembre",
|
|
|
|
10: "Ottobre",
|
|
|
|
11: "Novembre",
|
|
|
|
12: "Dicembre",
|
|
|
|
};
|
|
|
|
|
|
|
|
init();
|
2020-04-20 11:23:01 +02:00
|
|
|
</script>';
|