Aggiunto campi dare e avere in modelli prima nota

This commit is contained in:
MatteoPistorello 2021-01-29 17:04:21 +01:00
parent 5e5fafd5f0
commit 513176714b
6 changed files with 125 additions and 9 deletions

View File

@ -27,8 +27,16 @@ switch (post('op')) {
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
$idconto = post('idconto')[$i];
$dare = post('dare')[$i];
$avere = post('avere')[$i];
if (!empty($idconto)) {
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).')';
if(!empty($dare)){
$totale = $dare;
} else {
$totale = -$avere;
}
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto, totale) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).', '.prepare($totale).')';
if ($dbo->query($query)) {
$id_record = $idmastrino;
}
@ -47,8 +55,16 @@ switch (post('op')) {
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
$idconto = post('idconto')[$i];
$dare = post('dare')[$i];
$avere = post('avere')[$i];
if (!empty($idconto)) {
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).')';
if(!empty($dare)){
$totale = $dare;
} else {
$totale = -$avere;
}
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto, totale) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).', '.prepare($totale).')';
if ($dbo->query($query)) {
$id_record = $idmastrino;
}

View File

@ -43,7 +43,9 @@ include_once __DIR__.'/../../core.php';
echo '
<table class="table table-striped table-condensed table-hover table-bordered"
<tr>
<th>'.tr('Conto').'</th>
<th width="60%">'.tr('Conto').'</th>
<th width="20%">'.tr('Dare').'</th>
<th width="20%">'.tr('Avere').'</th>
</tr>';
for ($i = 0; $i < 10; ++$i) {
@ -55,6 +57,14 @@ include_once __DIR__.'/../../core.php';
<td>
{[ "type": "select", "name": "idconto['.$i.']", "ajax-source": "conti", "required": "'.$required.'" ]}
</td>
<td class="text-right">
{[ "type": "number", "name": "dare['.$i.']", "id": "dare'.$id.'", "value": "'.($rs[$i]['totale']>0 ? $rs[$i]['totale'] : '').'"]}
</td>
<td class="text-right">
{[ "type": "number", "name": "avere['.$i.']", "id": "avere'.$id.'", "value": "'.($rs[$i]['totale']<0 ? abs($rs[$i]['totale']) : '').'"]}
</td>
</tr>';
}
@ -99,3 +109,42 @@ include_once __DIR__.'/../../core.php';
</div>
</form>
<script>
$(document).ready( function() {
$('#modals select').on('change', function() {
if($(this).parent().parent().find('input[disabled]').length != 1){
if($(this).val()) {
$(this).parent().parent().find('input').prop("disabled", false);
}
else{
$(this).parent().parent().find('input').prop("disabled", true);
$(this).parent().parent().find('input').val("");
}
}
});
});
$("#modals input[id*=dare], #modals input[id*=avere]").each(function() {
if (input(this).get() === 0) {
$(this).prop("disabled", true);
} else {
$(this).prop("disabled", false);
}
});
$(document).on("keyup change", "#modals input[id*=dare]", function() {
let row = $(this).parent().parent();
if (!$(this).prop("disabled")) {
row.find("#modals input[id*=avere]").prop("disabled", input(this).get() !== 0);
}
});
$(document).on("keyup change", "#modals input[id*=avere]", function() {
let row = $(this).parent().parent();
if (!$(this).prop("disabled")) {
row.find("#modals input[id*=dare]").prop("disabled", input(this).get() !== 0);
}
});
</script>

View File

@ -60,7 +60,9 @@ for ($x = 0; $x < sizeof($conti2); ++$x) {
echo '
<table class="table table-striped table-condensed table-hover table-bordered"
<tr>
<th>'.tr('Conto').'</th>
<th width="60%">'.tr('Conto').'</th>
<th width="20%">'.tr('Dare').'</th>
<th width="20%">'.tr('Avere').'</th>
</tr>';
// Lettura movimenti del mastrino selezionato
@ -73,7 +75,15 @@ for ($i = 0; $i < 10; ++$i) {
<tr>
<td>
{[ "type": "select", "name": "idconto['.$i.']", "value": "'.$rs[$i]['idconto'].'", "ajax-source": "conti-modelliprimanota", "required": "'.$required.'" ]}
</td>
</td>
<td class="text-right">
{[ "type": "number", "name": "dare['.$i.']", "id": "dare'.$id.'", "value": "'.($rs[$i]['totale']>0 ? $rs[$i]['totale'] : '').'"]}
</td>
<td class="text-right">
{[ "type": "number", "name": "avere['.$i.']", "id": "avere'.$id.'", "value": "'.($rs[$i]['totale']<0 ? abs($rs[$i]['totale']) : '').'"]}
</td>
</tr>';
}
@ -95,7 +105,35 @@ echo '
}
}
});
});
});
$("input[id*=dare], input[id*=avere]").each(function() {
let row = $(this).parent().parent();
if (!row.find("select").val()) {
if (input(this).get() === 0) {
$(this).prop("disabled", true);
} else {
$(this).prop("disabled", false);
}
}
});
$(document).on("keyup change", "input[id*=dare]", function() {
let row = $(this).parent().parent();
if (!$(this).prop("disabled")) {
row.find("input[id*=avere]").prop("disabled", input(this).get() !== 0);
}
});
$(document).on("keyup change", "input[id*=avere]", function() {
let row = $(this).parent().parent();
if (!$(this).prop("disabled")) {
row.find("input[id*=dare]").prop("disabled", input(this).get() !== 0);
}
});
</script>
</form>

View File

@ -391,7 +391,7 @@ if ($permetti_modelli) {
$.get(globals.rootdir + "/ajax_complete.php?op=get_conti&idmastrino=" + id_mastrino, function(data) {
let conti = data.split(",");
let table = $("table.scadenze").first();
let table = $("#modals table.scadenze").first();
let button = table.parent().find("button").first();
// Creazione delle eventuali righe aggiuntive
@ -409,6 +409,7 @@ if ($permetti_modelli) {
let id_conto = parseInt(dati_conto[0]);
let descrizione_conto = dati_conto[1];
let totale = dati_conto[2];
// Sostituzione del conto dell\'Anagrafica
if (id_conto === -1 && globals.prima_nota.id_documento !== ""){
@ -420,6 +421,15 @@ if ($permetti_modelli) {
let select = $(righe[i + 1]).find("select");
input(select).getElement()
.selectSetNew(id_conto, descrizione_conto);
if(totale>0){
input_field = $(righe[i + 1]).find("input[id*=dare]");
} else{
input_field = $(righe[i + 1]).find("input[id*=avere]");
totale = -totale;
}
input(input_field).getElement()
.val(totale).trigger("change");
}
});

View File

@ -26,7 +26,7 @@ switch ($resource) {
$rs_conti = $dbo->fetchArray('SELECT *, (SELECT CONCAT ((SELECT numero FROM co_pianodeiconti2 WHERE id=co_pianodeiconti3.idpianodeiconti2), ".", numero, " ", descrizione) FROM co_pianodeiconti3 WHERE id=co_movimenti_modelli.idconto) AS descrizione_conto FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino).' GROUP BY id ORDER BY id');
for ($i = 0; $i < sizeof($rs_conti); ++$i) {
$conti[$i] = $rs_conti[$i]['idconto'].';'.$rs_conti[$i]['descrizione_conto'];
$conti[$i] = $rs_conti[$i]['idconto'].';'.$rs_conti[$i]['descrizione_conto'].';'.$rs_conti[$i]['totale'];
}
echo implode(',', $conti);

View File

@ -67,4 +67,7 @@ INSERT INTO `co_iva` (`id`, `descrizione`, `percentuale`, `indetraibile`, `esent
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `help`) VALUES (NULL, 'Condizioni generali di fornitura', '', 'ckeditor', '1', 'Preventivi', NULL, NULL);
-- Aggiunta colonna condizioni_fornitura in co_preventivi
ALTER TABLE `co_preventivi` ADD `condizioni_fornitura` TEXT NOT NULL AFTER `numero_revision`;
ALTER TABLE `co_preventivi` ADD `condizioni_fornitura` TEXT NOT NULL AFTER `numero_revision`;
-- Aggiunta colonna totale in modelli prima nota
ALTER TABLE `co_movimenti_modelli` ADD `totale` DECIMAL(12,6) NOT NULL AFTER `idconto`;