mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 17:07:01 +01:00
Miglioramento Prima Nota
This commit is contained in:
parent
4d2a5e5e5c
commit
19731c33e2
@ -199,7 +199,27 @@ $(document).ready(function () {
|
||||
$(this).attr("data-id_records", table.data('selected'));
|
||||
$(this).data("id_records", table.data('selected'));
|
||||
|
||||
message(this);
|
||||
if ($(this).data("type") == "modal"){
|
||||
var data = JSON.parse(JSON.stringify($(this).data()));
|
||||
var href = data.url;
|
||||
|
||||
delete data.url;
|
||||
delete data.title;
|
||||
delete data.op;
|
||||
delete data.backto;
|
||||
delete data.blank;
|
||||
|
||||
var values = [];
|
||||
for (var name in data) {
|
||||
values.push(name + '=' + data[name]);
|
||||
}
|
||||
|
||||
var link = href + (href.indexOf('?') !== -1 ? '&' : '?') + values.join('&');
|
||||
|
||||
launch_modal($(this).data("title"), link);
|
||||
} else {
|
||||
message(this);
|
||||
}
|
||||
|
||||
$(this).attr("data-id_records", "");
|
||||
$(this).data("id_records", "");
|
||||
|
@ -289,29 +289,6 @@ switch (post('op')) {
|
||||
} else {
|
||||
$dbo->query("UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='Emessa') WHERE id=".prepare($rs_fatture[$i]['id']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato dei preventivi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idpreventivo FROM co_righe_documenti WHERE iddocumento='.prepare($rs_fatture[$i]['id']).' AND NOT idpreventivo=0 AND idpreventivo IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE co_preventivi SET idstato=(SELECT id FROM co_statipreventivi WHERE descrizione='Pagato') WHERE id=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato dei contratti collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idcontratto FROM co_righe_documenti WHERE iddocumento='.prepare($rs_fatture[$i]['id']).' AND NOT idcontratto=0 AND idcontratto IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE co_contratti SET idstato=(SELECT id FROM co_staticontratti WHERE descrizione='Pagato') WHERE id=".prepare($rs2[$j]['idcontratto']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato degli interventi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idintervento FROM co_righe_documenti WHERE iddocumento='.prepare($rs_fatture[$i]['id']).' AND idintervento IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE descrizione='Fatturato') WHERE id_preventivo=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
}
|
||||
|
||||
$database->commitTransaction();
|
||||
@ -323,12 +300,12 @@ switch (post('op')) {
|
||||
|
||||
if (App::debug()) {
|
||||
$operations = [
|
||||
'delete-bulk' => '<span><i class="fa fa-trash" ></i> '.tr('Elimina selezionati').'</span>',
|
||||
'delete-bulk' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span>',
|
||||
];
|
||||
}
|
||||
|
||||
$operations['registra-contabile'] = [
|
||||
'text' => '<span><i class="fa fa-calculator" ></i> '.tr('Registra contabile pagamento').'</span>',
|
||||
'text' => '<span><i class="fa fa-calculator"></i> '.tr('Registra contabile pagamento').'</span>',
|
||||
'data' => [
|
||||
'title' => '',
|
||||
'msg' => tr('Vuoi aggiungere un movimento contabile per le fatture selezionate?<br><small>(le fatture dovranno essere nello stato <i class="fa fa-clock-o text-info" title="Emessa"></i> <small>Emessa</small> altrimenti non saranno processate)</small>'),
|
||||
@ -338,9 +315,19 @@ $operations['registra-contabile'] = [
|
||||
],
|
||||
];
|
||||
|
||||
$operations['registra-contabile-2'] = [
|
||||
'text' => '<span><i class="fa fa-calculator"></i> '.tr('Registrazione contabile').'</span>',
|
||||
'data' => [
|
||||
'title' => tr('Registrazione contabile'),
|
||||
'type' => 'modal',
|
||||
'origine' => 'fatture',
|
||||
'url' => $rootdir.'/add.php?id_module='.Modules::get('Prima nota')['id'],
|
||||
],
|
||||
];
|
||||
|
||||
if ($module->name == 'Fatture di vendita') {
|
||||
$operations['genera-xml'] = [
|
||||
'text' => '<span><i class="fa fa-file-code-o" ></i> '.tr('Genera fatture elettroniche').'</span>',
|
||||
'text' => '<span><i class="fa fa-file-code-o"></i> '.tr('Genera fatture elettroniche').'</span>',
|
||||
'data' => [
|
||||
'title' => '',
|
||||
'msg' => tr('Generare le fatture elettroniche per i documenti selezionati?<br><small>(le fatture dovranno essere nello stato <i class="fa fa-clock-o text-info" title="Emessa"></i> <small>Emessa</small> e non essere mai state generate)</small>'),
|
||||
@ -351,7 +338,7 @@ if ($module->name == 'Fatture di vendita') {
|
||||
];
|
||||
|
||||
$operations['export-bulk'] = [
|
||||
'text' => '<span class="'.((!extension_loaded('zip')) ? 'text-muted disabled' : '').'"><i class="fa fa-file-archive-o" ></i> '.tr('Esporta stampe').'</span>',
|
||||
'text' => '<span class="'.((!extension_loaded('zip')) ? 'text-muted disabled' : '').'"><i class="fa fa-file-archive-o"></i> '.tr('Esporta stampe').'</span>',
|
||||
'data' => [
|
||||
'title' => '',
|
||||
'msg' => tr('Vuoi davvero esportare i PDF delle fatture selezionate in un archivio ZIP?'),
|
||||
@ -363,7 +350,7 @@ if ($module->name == 'Fatture di vendita') {
|
||||
}
|
||||
|
||||
$operations['export-xml-bulk'] = [
|
||||
'text' => '<span class="'.((!extension_loaded('zip')) ? 'text-muted disabled' : '').'"><i class="fa fa-file-archive-o" ></i> '.tr('Esporta XML').'</span>',
|
||||
'text' => '<span class="'.((!extension_loaded('zip')) ? 'text-muted disabled' : '').'"><i class="fa fa-file-archive-o"></i> '.tr('Esporta XML').'</span>',
|
||||
'data' => [
|
||||
'title' => '',
|
||||
'msg' => tr('Vuoi davvero esportare le fatture elettroniche selezionate in un archivio ZIP?'),
|
||||
|
@ -59,7 +59,7 @@ if (!empty($record['is_fiscale'])) {
|
||||
//Aggiunta insoluto
|
||||
if (!empty($record['riba']) && ($record['stato'] == 'Emessa' || $record['stato'] == 'Parzialmente pagato' || $record['stato'] == 'Pagato') && $dir == 'entrata') {
|
||||
?>
|
||||
<button type="button" class="btn btn-primary" onclick="launch_modal( '<?php echo tr('Registra insoluto'); ?>', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&iddocumento=<?php echo $id_record; ?>&dir=<?php echo $dir; ?>&insoluto=1', 1 );"><i class="fa fa-euro"></i> <?php echo tr('Registra insoluto'); ?>...</button>
|
||||
<button type="button" class="btn btn-primary" onclick="launch_modal( '<?php echo tr('Registra insoluto'); ?>', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&id_documenti=<?php echo $id_record; ?>&single=1&insoluto=1', 1 );"><i class="fa fa-euro"></i> <?php echo tr('Registra insoluto'); ?>...</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ if (!empty($record['is_fiscale'])) {
|
||||
|
||||
if (($n2 <= 0 && $record['stato'] == 'Emessa') || $differenza != 0) {
|
||||
?>
|
||||
<button type="button" class="btn btn-primary <?php echo (!empty(Modules::get('Prima nota'))) ? '' : 'disabled'; ?>" onclick="launch_modal( '<?php echo tr('Aggiungi prima nota'); ?>', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&iddocumento=<?php echo $id_record; ?>&dir=<?php echo $dir; ?>', 1 );"><small><i class="fa fa-euro"></i> <?php echo tr('Registra contabile pagamento'); ?>...</small></button>
|
||||
<button type="button" class="btn btn-primary <?php echo (!empty(Modules::get('Prima nota'))) ? '' : 'disabled'; ?>" onclick="launch_modal( '<?php echo tr('Aggiungi prima nota'); ?>', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&id_documenti=<?php echo $id_record; ?>&single=1', 1 );"><small><i class="fa fa-euro"></i> <?php echo tr('Registra contabile pagamento'); ?>...</small></button>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
@ -5,23 +5,14 @@ include_once __DIR__.'/../../core.php';
|
||||
switch (post('op')) {
|
||||
case 'add':
|
||||
$all_ok = true;
|
||||
$iddocumento = post('iddocumento');
|
||||
$idscadenza = post('idscadenza');
|
||||
$data = post('data');
|
||||
$idmastrino = get_new_idmastrino();
|
||||
$descrizione = post('descrizione');
|
||||
$insoluto = post('insoluto');
|
||||
|
||||
// Lettura info fattura
|
||||
$query = 'SELECT *, co_documenti.note, co_documenti.idpagamento, co_documenti.id AS iddocumento, co_statidocumento.descrizione AS `stato`, co_tipidocumento.descrizione AS `descrizione_tipodoc` FROM ((co_documenti LEFT OUTER JOIN co_statidocumento ON co_documenti.idstatodocumento=co_statidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$ragione_sociale = $rs[0]['ragione_sociale'];
|
||||
$data_documento = $rs[0]['data'];
|
||||
$totale = 0;
|
||||
$totale_pagato = 0;
|
||||
|
||||
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
|
||||
$idconto = post('idconto')[$i];
|
||||
$conti = post('idconto');
|
||||
foreach ($conti as $i => $id_conto) {
|
||||
$id_scadenza = post('id_scadenza')[$i];
|
||||
$insoluto = post('insoluto')[$i];
|
||||
$dare = post('dare')[$i];
|
||||
$avere = post('avere')[$i];
|
||||
|
||||
@ -30,74 +21,53 @@ switch (post('op')) {
|
||||
$totale = -$avere;
|
||||
} else {
|
||||
$totale = $dare;
|
||||
|
||||
$totale_pagato += $totale;
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO co_movimenti(idmastrino, data, data_documento, iddocumento, descrizione, idconto, totale, primanota) VALUES('.prepare($idmastrino).', '.prepare($data).', '.prepare($data_documento).', '.prepare($iddocumento).', '.prepare($descrizione).', '.prepare($idconto).', '.prepare($totale).", '1')";
|
||||
if (!$dbo->query($query)) {
|
||||
$all_ok = false;
|
||||
} else {
|
||||
$all_ok = true;
|
||||
$id_record = $idmastrino;
|
||||
$scadenza = $database->fetchOne('SELECT iddocumento, data_emissione FROM co_scadenziario WHERE id = '.prepare($id_scadenza));
|
||||
$id_documento = $scadenza['iddocumento'];
|
||||
|
||||
$database->insert('co_movimenti', [
|
||||
'idmastrino' => $idmastrino,
|
||||
'data' => $data,
|
||||
'data_documento' => $scadenza['data_emissione'],
|
||||
'iddocumento' => $id_documento ?: 0,
|
||||
'descrizione' => $descrizione,
|
||||
'idconto' => $id_conto,
|
||||
'totale' => $totale,
|
||||
'primanota' => 1,
|
||||
]);
|
||||
|
||||
if (!empty($id_documento)) {
|
||||
// Inserisco nello scadenziario il totale pagato
|
||||
if (empty($insoluto)) {
|
||||
aggiorna_scadenziario($id_documento, abs($totale), $data, $id_scadenza);
|
||||
}
|
||||
// Rimuovo dallo scadenzario l'insoluto
|
||||
else {
|
||||
aggiorna_scadenziario($id_documento, -abs($totale), $data, $id_scadenza);
|
||||
}
|
||||
|
||||
// Verifico se la fattura è stata pagata tutta, così imposto lo stato a "Pagato"
|
||||
$rs = $dbo->fetchArray('SELECT SUM(pagato) AS tot_pagato, SUM(da_pagare) AS tot_da_pagare FROM co_scadenziario WHERE iddocumento='.prepare($id_documento));
|
||||
|
||||
// Aggiorno lo stato della fattura
|
||||
if (abs($rs[0]['tot_pagato']) == abs($rs[0]['tot_da_pagare'])) {
|
||||
$stato = 'Pagato';
|
||||
} elseif (abs($rs[0]['tot_pagato']) != abs($rs[0]['tot_da_pagare']) && abs($rs[0]['tot_pagato']) != '0') {
|
||||
$stato = 'Parzialmente pagato';
|
||||
} else {
|
||||
$stato = 'Emessa';
|
||||
}
|
||||
|
||||
$dbo->query('UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='.prepare($stato).') WHERE id='.prepare($id_documento));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($totale_pagato != 0 && empty($insoluto)) {
|
||||
// Inserisco nello scadenziario il totale pagato
|
||||
aggiorna_scadenziario($iddocumento, abs($totale_pagato), $data, $idscadenza);
|
||||
} elseif (!empty($insoluto)) {
|
||||
//Rimuovo dallo scadenzario l'insoluto
|
||||
aggiorna_scadenziario($iddocumento, -abs($totale_pagato), $data, $idscadenza);
|
||||
}
|
||||
|
||||
// Se non va a buon fine qualcosa elimino il mastrino per non lasciare incongruenze nel db
|
||||
if (!$all_ok) {
|
||||
flash()->error(tr("Errore durante l'aggiunta del movimento!"));
|
||||
$dbo->query('DELETE FROM co_movimenti WHERE idmastrino='.prepare($idmastrino));
|
||||
} else {
|
||||
flash()->info(tr('Movimento aggiunto in prima nota!'));
|
||||
|
||||
// Verifico se la fattura è stata pagata tutta, così imposto lo stato a "Pagato"
|
||||
$query = 'SELECT SUM(pagato) AS tot_pagato, SUM(da_pagare) AS tot_da_pagare FROM co_scadenziario GROUP BY iddocumento HAVING iddocumento='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
|
||||
// Aggiorno lo stato della fattura
|
||||
if (abs($rs[0]['tot_pagato']) == abs($rs[0]['tot_da_pagare'])) {
|
||||
$dbo->query("UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='Pagato') WHERE id=".prepare($iddocumento));
|
||||
} elseif (abs($rs[0]['tot_pagato']) != abs($rs[0]['tot_da_pagare']) && abs($rs[0]['tot_pagato']) != '0') {
|
||||
$dbo->query("UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='Parzialmente pagato') WHERE id=".prepare($iddocumento));
|
||||
} else {
|
||||
$dbo->query("UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='Emessa') WHERE id=".prepare($iddocumento));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato dei preventivi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idpreventivo FROM co_righe_documenti WHERE iddocumento='.prepare($iddocumento).' AND NOT idpreventivo=0 AND idpreventivo IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE co_preventivi SET idstato=(SELECT id FROM co_statipreventivi WHERE descrizione='Pagato') WHERE id=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato dei contratti collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idcontratto FROM co_righe_documenti WHERE iddocumento='.prepare($iddocumento).' AND NOT idcontratto=0 AND idcontratto IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE co_contratti SET idstato=(SELECT id FROM co_staticontratti WHERE descrizione='Pagato') WHERE id=".prepare($rs2[$j]['idcontratto']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato degli interventi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idintervento FROM co_righe_documenti WHERE iddocumento='.prepare($iddocumento).' AND idintervento IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE descrizione='Fatturato') WHERE id_preventivo=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
}
|
||||
|
||||
//Creo il modello di prima nota
|
||||
$id_record = $idmastrino;
|
||||
flash()->info(tr('Movimento aggiunto in prima nota!'));
|
||||
|
||||
// Creo il modello di prima nota
|
||||
if (!empty(post('crea_modello'))) {
|
||||
if (empty(post('idmastrino'))) {
|
||||
$idmastrino = get_new_idmastrino('co_movimenti_modelli');
|
||||
@ -226,25 +196,6 @@ switch (post('op')) {
|
||||
}
|
||||
|
||||
$dbo->query('UPDATE co_documenti SET idstatodocumento=(SELECT id FROM co_statidocumento WHERE descrizione='.prepare($stato).') WHERE id='.prepare($iddocumento));
|
||||
|
||||
// Aggiorno lo stato dei preventivi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idpreventivo FROM co_righe_documenti WHERE iddocumento='.prepare($iddocumento).' AND NOT idpreventivo=0 AND idpreventivo IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE co_preventivi SET idstato=(SELECT id FROM co_statipreventivi WHERE descrizione='Pagato') WHERE id=".prepare($rs2[$j]['idpreventivo']));
|
||||
|
||||
// Aggiorno anche lo stato degli interventi collegati ai preventivi
|
||||
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE descrizione='Fatturato') WHERE id_preventivo=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
|
||||
// Aggiorno lo stato degli interventi collegati alla fattura se ce ne sono
|
||||
$query2 = 'SELECT idintervento FROM co_righe_documenti WHERE iddocumento='.prepare($iddocumento).' AND idintervento IS NOT NULL';
|
||||
$rs2 = $dbo->fetchArray($query2);
|
||||
|
||||
for ($j = 0; $j < sizeof($rs2); ++$j) {
|
||||
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE descrizione='Fatturato') WHERE id_preventivo=".prepare($rs2[$j]['idpreventivo']));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2,185 +2,173 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
?><form action="<?php echo ROOTDIR; ?>/controller.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>" method="post" id="add-form">
|
||||
use Modules\Fatture\Fattura;
|
||||
|
||||
$module = Modules::get('Prima nota');
|
||||
|
||||
$variables = Modules::get('Fatture di vendita')->getPlaceholders($id_documento);
|
||||
$righe = [];
|
||||
|
||||
$singola_scadenza = get('single') != null;
|
||||
|
||||
// Registrazione da remoto
|
||||
$id_records = get('id_records');
|
||||
if (!empty($id_records)) {
|
||||
$id_records = str_replace(';', ',', $id_records);
|
||||
if (get('origine') == 'fatture') {
|
||||
$id_documenti = $id_records;
|
||||
} else {
|
||||
$id_scadenze = $id_records;
|
||||
}
|
||||
}
|
||||
|
||||
// Fatture
|
||||
$id_documenti = $id_documenti ?: get('id_documenti');
|
||||
$id_documenti = $id_documenti ? explode(',', $id_documenti) : [];
|
||||
$numeri = [];
|
||||
foreach ($id_documenti as $id_documento) {
|
||||
$fattura = Fattura::find($id_documento);
|
||||
$tipo = $fattura->tipo;
|
||||
$dir = $fattura->direzione;
|
||||
|
||||
$numeri[] = !empty($fattura['numero_esterno']) ? $fattura['numero_esterno'] : $fattura['numero'];
|
||||
|
||||
$nota_credito = $tipo->descrizione == 'Nota di credito';
|
||||
$is_insoluto = (!empty($fattura['riba']) && in_array($tipo->descrizione, ['Emessa', 'Parzialmente pagato', 'Pagato']) && $dir == 'entrata');
|
||||
|
||||
// Predisposizione prima riga
|
||||
$conto_field = 'idconto_'.($dir == 'entrata' ? 'vendite' : 'acquisti');
|
||||
$id_conto_aziendale = $fattura->pagamento[$conto_field] ?: setting('Conto aziendale predefinito');
|
||||
|
||||
// Predisposizione conto crediti clienti
|
||||
$conto_field = 'idconto_'.($dir == 'entrata' ? 'cliente' : 'fornitore');
|
||||
$id_conto_controparte = $fattura->anagrafica[$conto_field];
|
||||
//$_SESSION['superselect']['idconto_controparte'] = $id_conto_controparte;
|
||||
|
||||
// Lettura delle scadenza della fattura
|
||||
$scadenze = $dbo->fetchArray('SELECT id, ABS(da_pagare - pagato) AS rata FROM co_scadenziario WHERE iddocumento='.prepare($id_documento).' AND ABS(da_pagare) > ABS(pagato) ORDER BY YEAR(scadenza) ASC, MONTH(scadenza) ASC');
|
||||
|
||||
// Selezione prima scadenza
|
||||
if ($singola_scadenza && !empty($scadenze)) {
|
||||
$scadenze = [$scadenze[0]];
|
||||
}
|
||||
|
||||
$righe_documento = [];
|
||||
|
||||
// Riga aziendale
|
||||
$totale = sum(array_column($scadenze, 'rata'));
|
||||
$ids = implode(',', array_column($scadenze, 'id'));
|
||||
if ($totale != 0) {
|
||||
$righe_documento[] = [
|
||||
'id_scadenza' => $ids,
|
||||
'insoluto' => $is_insoluto,
|
||||
'conto' => $id_conto_aziendale,
|
||||
'dare' => ($dir == 'entrata') ? 0 : $totale,
|
||||
'avere' => ($dir == 'entrata') ? $totale : 0,
|
||||
];
|
||||
}
|
||||
|
||||
// Riga controparte
|
||||
foreach ($scadenze as $scadenza) {
|
||||
$righe_documento[] = [
|
||||
'id_scadenza' => $scadenza['id'],
|
||||
'insoluto' => $is_insoluto,
|
||||
'conto' => $id_conto_controparte,
|
||||
'dare' => ($dir == 'entrata') ? $scadenza['rata'] : 0,
|
||||
'avere' => ($dir == 'entrata') ? 0 : $scadenza['rata'],
|
||||
];
|
||||
}
|
||||
|
||||
// Se è una nota di credito, inverto i valori
|
||||
if ($nota_credito || $is_insoluto) {
|
||||
foreach ($righe_documento as $key => $value) {
|
||||
$tmp = $value['avere'];
|
||||
$righe_documento[$key]['avere'] = $righe_documento[$key]['dare'];
|
||||
$righe_documento[$key]['dare'] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
$righe = array_merge($righe, $righe_documento);
|
||||
}
|
||||
|
||||
$dir = get('dir');
|
||||
|
||||
// Scadenze
|
||||
$id_scadenze = $id_scadenze ?: get('id_scadenze');
|
||||
$id_scadenze = $id_scadenze ? explode(',', $id_scadenze) : [];
|
||||
foreach ($id_scadenze as $id_scadenza) {
|
||||
$scadenza = $dbo->fetchOne('SELECT descrizione, scadenza, SUM(da_pagare - pagato) AS rata FROM co_scadenziario WHERE id='.prepare($id_scadenza));
|
||||
|
||||
$descrizione_conto = ($dir == 'entrata') ? 'Riepilogativo clienti' : 'Riepilogativo fornitori';
|
||||
$conto = $dbo->fetchOne('SELECT id FROM co_pianodeiconti3 WHERE descrizione = '.prepare($descrizione_conto));
|
||||
$id_conto_controparte = $conto['id'];
|
||||
|
||||
$righe_documento = [];
|
||||
|
||||
$righe_documento[] = [
|
||||
'id_scadenza' => $scadenza['id'],
|
||||
'conto' => $id_conto_controparte,
|
||||
'dare' => ($dir == 'entrata') ? $scadenza['rata'] : 0,
|
||||
'avere' => ($dir == 'entrata') ? 0 : $scadenza['rata'],
|
||||
];
|
||||
|
||||
$righe = array_merge($righe, $righe_documento);
|
||||
}
|
||||
|
||||
// Descrizione
|
||||
$numero_scadenze = count($id_scadenze);
|
||||
$numero_documenti = count($id_documenti);
|
||||
if ($numero_documenti + $numero_scadenze > 1) {
|
||||
$descrizione = 'Pag. fatture num. '.implode(', ', $numeri);
|
||||
} elseif ($numero_documenti == 1) {
|
||||
$numero_fattura = !empty($fattura['numero_esterno']) ? $fattura['numero_esterno'] : $fattura['numero'];
|
||||
|
||||
$tipo_fattura = $fattura->isNota() ? $tipo->descrizione : tr('Fattura');
|
||||
|
||||
if (!empty($is_insoluto)) {
|
||||
$operation = tr('Registrazione insoluto');
|
||||
} else {
|
||||
$operation = tr('Pag.');
|
||||
}
|
||||
|
||||
$descrizione = tr('_OP_ _DOC_ num. _NUM_ del _DATE_ (_NAME_)', [
|
||||
'_OP_' => $operation,
|
||||
'_DOC_' => strtolower($tipo_fattura),
|
||||
'_NUM_' => $numero_fattura,
|
||||
'_DATE_' => Translator::dateToLocale($fattura['data']),
|
||||
'_NAME_' => $fattura->anagrafica['ragione_sociale'],
|
||||
]);
|
||||
} elseif ($numero_scadenze == 1) {
|
||||
$descrizione = tr('Pag. _OP_ del _DATE_', [
|
||||
'_OP_' => $scadenza['descrizione'],
|
||||
'_DATE_' => Translator::dateToLocale($scadenza['scadenza']),
|
||||
]);
|
||||
}
|
||||
|
||||
echo '
|
||||
<form action="'.ROOTDIR.'/controller.php?id_module='.$module->id.'" method="post" id="add-form">
|
||||
<input type="hidden" name="op" value="add">
|
||||
<input type="hidden" name="backto" value="record-edit">
|
||||
<input type="hidden" name="iddocumento" id="iddocumento" value="<?php echo get('iddocumento'); ?>">
|
||||
<input type="hidden" name="idscadenza" id="idscadenza" value="<?php echo get('idscadenza'); ?>">
|
||||
<input type="hidden" name="crea_modello" id="crea_modello" value="0">
|
||||
<input type="hidden" name="idmastrino" id="idmastrino" value="0">
|
||||
|
||||
<?php
|
||||
$idscadenza = get('idscadenza');
|
||||
$idconto = get('idconto');
|
||||
$iddocumento = get('iddocumento');
|
||||
$dir = get('dir');
|
||||
$insoluto = get('insoluto');
|
||||
|
||||
if (!empty($insoluto)) {
|
||||
echo '<input type="hidden" name="insoluto" value="1">';
|
||||
}
|
||||
|
||||
// Lettura delle variabili nei singoli moduli
|
||||
$id_record = $iddocumento;
|
||||
$variables = include Modules::filepath(Modules::get('Fatture di vendita')['id'], 'variables.php');
|
||||
|
||||
if (!empty($iddocumento)) {
|
||||
// Lettura numero e tipo di documento
|
||||
$query = 'SELECT dir, numero, numero_esterno, data, co_tipidocumento.descrizione AS tdescrizione, idanagrafica AS parent_idanagrafica, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=parent_idanagrafica AND deleted_at IS NULL) AS ragione_sociale FROM co_documenti LEFT OUTER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$dir = $rs[0]['dir'];
|
||||
$numero_doc = !empty($rs[0]['numero_esterno']) ? $rs[0]['numero_esterno'] : $rs[0]['numero'];
|
||||
$tipo_doc = $rs[0]['tdescrizione'];
|
||||
|
||||
$nota_credito = false;
|
||||
|
||||
if ($tipo_doc == 'Nota di credito') {
|
||||
$nota_credito = true;
|
||||
$tipo_doc = 'nota di credito';
|
||||
} elseif ($tipo_doc == 'Nota di debito') {
|
||||
$tipo_doc = 'nota di debito';
|
||||
} else {
|
||||
$tipo_doc = 'fattura';
|
||||
}
|
||||
|
||||
if (!empty($insoluto)) {
|
||||
$operation = 'Registrazione insoluto';
|
||||
} else {
|
||||
$operation = 'Pag.';
|
||||
}
|
||||
|
||||
$descrizione = tr('_OP_ _DOC_ num. _NUM_ del _DATE_ (_NAME_)', [
|
||||
'_OP_' => $operation,
|
||||
'_DOC_' => $tipo_doc,
|
||||
'_NUM_' => $numero_doc,
|
||||
'_DATE_' => Translator::dateToLocale($rs[0]['data']),
|
||||
'_NAME_' => $rs[0]['ragione_sociale'],
|
||||
]);
|
||||
|
||||
/*
|
||||
Predisposizione prima riga
|
||||
*/
|
||||
$field = 'idconto_'.($dir == 'entrata' ? 'vendite' : 'acquisti');
|
||||
$idconto_aziendale = $dbo->fetchArray('SELECT '.$field.' FROM co_pagamenti WHERE id = (SELECT idpagamento FROM co_documenti WHERE id='.prepare($iddocumento).') GROUP BY descrizione')[0][$field];
|
||||
|
||||
// Lettura conto di default
|
||||
$idconto_aziendale = !empty($idconto_aziendale) ? $idconto_aziendale : setting('Conto aziendale predefinito');
|
||||
|
||||
// Generazione causale (incasso fattura)
|
||||
$descrizione_conto_aziendale = $descrizione;
|
||||
|
||||
/*
|
||||
Calcolo totale per chiudere la fattura
|
||||
*/
|
||||
// Lettura importo da scadenzario (seleziono l'importo di questo mese)
|
||||
$query = 'SELECT *, scadenza, ABS(da_pagare-pagato) AS rata FROM co_scadenziario WHERE iddocumento='.prepare($iddocumento).' AND ABS(da_pagare) > ABS(pagato) ORDER BY YEAR(scadenza) ASC, MONTH(scadenza) ASC';
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$importo_conto_aziendale = $rs[0]['rata'];
|
||||
|
||||
if ($dir == 'entrata') {
|
||||
$totale_dare = abs($importo_conto_aziendale);
|
||||
} else {
|
||||
$totale_dare = abs($importo_conto_aziendale);
|
||||
}
|
||||
|
||||
// Può essere che voglia inserire un movimento in un mese diverso da quello previsto per l'incasso, perciò devo
|
||||
// leggere solo il totale rimanente della fattura rispetto a quello pagato invece di leggere quello da pagare
|
||||
// per il mese corrente (viene calcolato sopra)
|
||||
if ($totale_dare == 0) {
|
||||
// Lettura totale finora pagato
|
||||
$query = 'SELECT SUM(pagato) AS tot_pagato, SUM(da_pagare) AS tot_da_pagare FROM co_scadenziario GROUP BY iddocumento HAVING iddocumento='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
|
||||
if (!empty($insoluto)) {
|
||||
$importo_conto_aziendale = abs($rs[0]['tot_da_pagare']);
|
||||
} else {
|
||||
$importo_conto_aziendale = abs($rs[0]['tot_da_pagare']) - abs($rs[0]['tot_pagato']);
|
||||
}
|
||||
$totale_dare = $importo_conto_aziendale;
|
||||
}
|
||||
|
||||
/*
|
||||
Predisposizione seconda riga
|
||||
*/
|
||||
// conto crediti clienti
|
||||
if ($dir == 'entrata') {
|
||||
// Se è la prima nota di una fattura leggo il conto del cliente
|
||||
if ($iddocumento != '') {
|
||||
$query = 'SELECT idconto_cliente FROM an_anagrafiche INNER JOIN co_documenti ON an_anagrafiche.idanagrafica=co_documenti.idanagrafica WHERE co_documenti.id='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$idconto_controparte = $rs[0]['idconto_cliente'];
|
||||
} else {
|
||||
$query = "SELECT id FROM co_pianodeiconti3 WHERE descrizione='Riepilogativo clienti'";
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$idconto_controparte = $rs[0]['id'];
|
||||
}
|
||||
}
|
||||
|
||||
// conto debiti fornitori
|
||||
else {
|
||||
// Se è la prima nota di una fattura leggo il conto del fornitore
|
||||
if ($iddocumento != '') {
|
||||
$query = 'SELECT idconto_fornitore FROM an_anagrafiche INNER JOIN co_documenti ON an_anagrafiche.idanagrafica=co_documenti.idanagrafica WHERE co_documenti.id='.prepare($iddocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$idconto_controparte = $rs[0]['idconto_fornitore'];
|
||||
} else {
|
||||
$query = "SELECT id FROM co_pianodeiconti3 WHERE descrizione='Riepilogativo fornitori'";
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$idconto_controparte = $rs[0]['id'];
|
||||
}
|
||||
}
|
||||
$_SESSION['superselect']['idconto_controparte'] = $idconto_controparte;
|
||||
|
||||
// Lettura causale movimento (documento e ragione sociale)
|
||||
$descrizione_conto_controparte = $descrizione;
|
||||
$importo_conto_controparte = $importo_conto_aziendale;
|
||||
|
||||
if ($dir == 'entrata') {
|
||||
$totale_avere = $importo_conto_controparte;
|
||||
} else {
|
||||
$totale_avere = $importo_conto_controparte;
|
||||
}
|
||||
} else {
|
||||
$scadenza = $dbo->fetchOne('SELECT descrizione, scadenza, SUM(da_pagare-pagato) AS pagare FROM co_scadenziario WHERE id='.prepare($idscadenza));
|
||||
|
||||
$descrizione = tr('Pag. _OP_ del _DATE_', [
|
||||
'_OP_' => $scadenza['descrizione'],
|
||||
'_DATE_' => Translator::dateToLocale($scadenza['scadenza']),
|
||||
]);
|
||||
|
||||
$importo_conto_aziendale = $scadenza['pagare'];
|
||||
$importo_conto_controparte = $scadenza['pagare'];
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="idmastrino" id="idmastrino" value="0">';
|
||||
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type": "select", "label": "<?php echo tr('Modello primanota'); ?>", "id": "modello_primanota", "values": "query=SELECT idmastrino AS id, nome AS descrizione, descrizione as causale FROM co_movimenti_modelli GROUP BY idmastrino" ]}
|
||||
{[ "type": "select", "label": "'.tr('Modello primanota').'", "id": "modello_primanota", "values": "query=SELECT idmastrino AS id, nome AS descrizione, descrizione as causale FROM co_movimenti_modelli GROUP BY idmastrino" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
{[ "type": "date", "label": "<?php echo tr('Data movimento'); ?>", "name": "data", "required": 1, "value": "-now-" ]}
|
||||
{[ "type": "date", "label": "'.tr('Data movimento').'", "name": "data", "required": 1, "value": "-now-" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
{[ "type": "text", "label": "<?php echo tr('Causale'); ?>", "name": "descrizione", "id": "desc", "required": 1, "value": <?php echo json_encode($descrizione); ?> ]}
|
||||
{[ "type": "text", "label": "'.tr('Causale').'", "name": "descrizione", "id": "desc", "required": 1, "value": '.json_encode($descrizione).' ]}
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
|
||||
<?php
|
||||
$totale_dare = 0.00;
|
||||
$totale_avere = 0.00;
|
||||
$idmastrino = $record['idmastrino'];
|
||||
|
||||
// Salvo l'elenco conti in un array (per non fare il ciclo ad ogni riga)
|
||||
|
||||
/*
|
||||
Form di aggiunta riga movimento
|
||||
*/
|
||||
echo '
|
||||
<table class="table table-striped table-condensed table-hover table-bordered"
|
||||
<tr>
|
||||
@ -189,60 +177,31 @@ include_once __DIR__.'/../../core.php';
|
||||
<th width="20%">'.tr('Avere').'</th>
|
||||
</tr>';
|
||||
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
($i <= 1) ? $required = 1 : $required = 0;
|
||||
$max = max(count($righe), 10);
|
||||
for ($i = 0; $i < $max; ++$i) {
|
||||
$required = ($i <= 1);
|
||||
$riga = $righe[$i];
|
||||
|
||||
// Conto
|
||||
echo '
|
||||
<tr>
|
||||
<input type="hidden" name="id_scadenza[]" value="'.$riga['id_scadenza'].'">
|
||||
<input type="hidden" name="insoluto[]" value="'.$riga['insoluto'].'">
|
||||
|
||||
<td>
|
||||
{[ "type": "select", "name": "idconto['.$i.']", "id": "conto'.$i.'", "value": "';
|
||||
if ($i == 0) {
|
||||
echo $idconto_controparte;
|
||||
} elseif ($i == 1) {
|
||||
echo $idconto_aziendale;
|
||||
}
|
||||
echo '", "ajax-source": "conti", "required": "'.$required.'" ]}
|
||||
{[ "type": "select", "name": "idconto[]", "id": "conto'.$i.'", "value": "'.($riga['conto'] ?: '').'", "ajax-source": "conti", "required": "'.$required.'" ]}
|
||||
</td>';
|
||||
|
||||
// Importo dare e avere
|
||||
if ($i == 0) {
|
||||
if ($dir == 'entrata') {
|
||||
$value_dare = '';
|
||||
$value_avere = $importo_conto_aziendale;
|
||||
} else {
|
||||
$value_dare = $importo_conto_aziendale;
|
||||
$value_avere = '';
|
||||
}
|
||||
} elseif ($i == 1) {
|
||||
if ($dir == 'entrata') {
|
||||
$value_dare = $importo_conto_controparte;
|
||||
$value_avere = '';
|
||||
} else {
|
||||
$value_dare = '';
|
||||
$value_avere = $importo_conto_controparte;
|
||||
}
|
||||
} else {
|
||||
$value_dare = '';
|
||||
$value_avere = '';
|
||||
}
|
||||
|
||||
// Se è una nota di credito, inverto i valori
|
||||
if ($nota_credito || $insoluto) {
|
||||
$tmp = $value_dare;
|
||||
$value_dare = $value_avere;
|
||||
$value_avere = $tmp;
|
||||
}
|
||||
|
||||
// Dare
|
||||
echo '
|
||||
<td>
|
||||
{[ "type": "number", "name": "dare['.$i.']", "value": "'.$value_dare.'", "disabled": 1 ]}
|
||||
{[ "type": "number", "name": "dare[]", "id": "dare'.$i.'", "value": "'.($riga['dare'] ?: 0).'" ]}
|
||||
</td>';
|
||||
|
||||
// Avere
|
||||
echo '
|
||||
<td>
|
||||
{[ "type": "number", "name": "avere['.$i.']", "value": "'.$value_avere.'", "disabled": 1 ]}
|
||||
{[ "type": "number", "name": "avere[]", "id": "avere'.$i.'", "value": "'.($riga['avere'] ?: 0).'" ]}
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
@ -274,170 +233,197 @@ include_once __DIR__.'/../../core.php';
|
||||
</td>
|
||||
</tr>
|
||||
</table>';
|
||||
?>
|
||||
|
||||
echo '
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<button type='button' class="btn btn-default" id='btn_crea_modello'><i class="fa fa-plus"></i> <?php echo tr('Aggiungi e crea modello'); ?></button>
|
||||
<button type="submit" class="btn btn-primary" id='btn_submit'><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
|
||||
<button type="button" class="btn btn-default" id="btn_crea_modello">
|
||||
<i class="fa fa-plus"></i> '.tr('Aggiungi e crea modello').'
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary" id="add-submit">
|
||||
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>';
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready( function(){
|
||||
$('#bs-popup input[id*=dare], #bs-popup input[id*=avere]').each(function(){
|
||||
if($(this).val() != "<?php echo Translator::numberToLocale(0); ?>") $(this).prop("disabled", false);
|
||||
});
|
||||
<script type="text/javascript">
|
||||
var variables = <?php echo json_encode($variables); ?>;
|
||||
var formatted_zero = "<?php echo Translator::numberToLocale(0); ?>";
|
||||
var nuovo_modello = "<?php echo tr('Aggiungi e crea modello'); ?>";
|
||||
var modifica_modello = "<?php echo tr('Aggiungi e modifica modello'); ?>";
|
||||
var sbilancio = "<?php echo tr('sbilancio di _NUM_', [
|
||||
'_NUM_' => '|value| '.currency(),
|
||||
]); ?>";
|
||||
|
||||
$('select').on('change', function(){
|
||||
if($(this).parent().parent().find('input[disabled]').length != 1){
|
||||
if($(this).val()) {
|
||||
$(this).parent().parent().find('input').prop("disabled", false);
|
||||
$("#bs-popup #add-form").submit(function() {
|
||||
return calcolaBilancio();
|
||||
});
|
||||
|
||||
// Ad ogni modifica dell'importo verifica che siano stati selezionati: il conto, la causale, la data. Inoltre aggiorna lo sbilancio
|
||||
function calcolaBilancio() {
|
||||
bilancio = 0.00;
|
||||
totale_dare = 0.00;
|
||||
totale_avere = 0.00;
|
||||
|
||||
// Calcolo il totale dare e totale avere
|
||||
$('#bs-popup input[id*=dare]').each(function() {
|
||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
||||
|
||||
totale_dare += Math.round(valore * 100) / 100;
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=avere]').each(function() {
|
||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
||||
|
||||
totale_avere += Math.round(valore * 100) / 100;
|
||||
});
|
||||
|
||||
$('#bs-popup #totale_dare').text(totale_dare.toLocale());
|
||||
$('#bs-popup #totale_avere').text(totale_avere.toLocale());
|
||||
|
||||
bilancio = Math.round(totale_dare * 100) / 100 - Math.round(totale_avere * 100) / 100;
|
||||
|
||||
if (bilancio == 0) {
|
||||
$('#bs-popup #testo_aggiuntivo').removeClass('text-danger').html("");
|
||||
$('#bs-popup #add-submit').removeClass('hide');
|
||||
$('#bs-popup #btn_crea_modello').removeClass('hide');
|
||||
} else {
|
||||
$('#bs-popup #testo_aggiuntivo').addClass('text-danger').html(sbilancio.replace('|value|', bilancio.toLocale()));
|
||||
$('#bs-popup #add-submit').addClass('hide');
|
||||
$('#bs-popup #btn_crea_modello').addClass('hide');
|
||||
}
|
||||
|
||||
return bilancio == 0;
|
||||
}
|
||||
|
||||
function bloccaZeri(){
|
||||
$('#bs-popup input[id*=dare], #bs-popup input[id*=avere]').each(function() {
|
||||
if ($(this).val() == formatted_zero) {
|
||||
$(this).prop("disabled", true);
|
||||
} else {
|
||||
$(this).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
calcolaBilancio();
|
||||
bloccaZeri();
|
||||
|
||||
$("#bs-popup #add-form").submit(function() {
|
||||
var result = calcolaBilancio();
|
||||
|
||||
if(!result) bloccaZeri();
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
$('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("0.00");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=dare]').on('keyup change', function() {
|
||||
if (!$(this).prop('disabled')) {
|
||||
if ($(this).val()) {
|
||||
$(this).parent().parent().find('input[id*=avere]').prop("disabled", true);
|
||||
} else {
|
||||
$(this).parent().parent().find('input[id*=avere]').prop("disabled", false);
|
||||
}
|
||||
|
||||
calcolaBilancio();
|
||||
}
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=avere]').on('keyup change', function() {
|
||||
if (!$(this).prop('disabled')) {
|
||||
if ($(this).val()) {
|
||||
$(this).parent().parent().find('input[id*=dare]').prop("disabled", true);
|
||||
} else {
|
||||
$(this).parent().parent().find('input[id*=dare]').prop("disabled", false);
|
||||
}
|
||||
|
||||
calcolaBilancio();
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger dell'evento keyup() per la prima volta, per eseguire i dovuti controlli nel caso siano predisposte delle righe in prima nota
|
||||
$("#bs-popup input[id*=dare][value!=''], #bs-popup input[id*=avere][value!='']").keyup();
|
||||
|
||||
$("#bs-popup select[id*=idconto]").click(function() {
|
||||
$("#bs-popup input[id*=dare][value!=''], #bs-popup input[id*=avere][value!='']").keyup();
|
||||
});
|
||||
|
||||
$('#bs-popup #modello_primanota').change(function() {
|
||||
if ($(this).val() != '') {
|
||||
$('#btn_crea_modello').html('<i class="fa fa-edit"></i> ' + modifica_modello);
|
||||
$('#bs-popup #idmastrino').val($(this).val());
|
||||
} else {
|
||||
$('#btn_crea_modello').html('<i class="fa fa-plus"></i> ' + nuovo_modello);
|
||||
$('#bs-popup #idmastrino').val(0);
|
||||
}
|
||||
|
||||
var idmastrino = $(this).val();
|
||||
var replaced = 0;
|
||||
|
||||
if (idmastrino != '') {
|
||||
var causale = $(this).find('option:selected').data('causale');
|
||||
|
||||
if ($('#iddocumento').val() != '') {
|
||||
for (i in variables) {
|
||||
if (causale.includes('{' + i + '}')) {
|
||||
replaced++;
|
||||
causale = causale.replace('{' + i + '}', variables[i]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$(this).parent().parent().find('input').prop("disabled", true);
|
||||
$(this).parent().parent().find('input').val("0.00");
|
||||
} else {
|
||||
for (i in variables) {
|
||||
causale = causale.replace('{' + i + '}', '_');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=dare]').on('keyup change', function(){
|
||||
if(!$(this).prop('disabled')){
|
||||
if($(this).val()) {
|
||||
$(this).parent().parent().find('#bs-popup input[id*=avere]').prop("disabled", true);
|
||||
}
|
||||
else {
|
||||
$(this).parent().parent().find('#bs-popup input[id*=avere]').prop("disabled", false);
|
||||
}
|
||||
|
||||
calcolaBilancio();
|
||||
// aggiornava erroneamente anche la causale ed eventuale numero di fattura e data
|
||||
if (replaced > 0 || $('#iddocumento').val() == '') {
|
||||
$('#bs-popup #desc').val(causale);
|
||||
}
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=avere]').on('keyup change', function(){
|
||||
if(!$(this).prop('disabled')){
|
||||
if($(this).val()) {
|
||||
$(this).parent().parent().find('#bs-popup input[id*=dare]').prop("disabled", true);
|
||||
}
|
||||
else {
|
||||
$(this).parent().parent().find('#bs-popup input[id*=dare]').prop("disabled", false);
|
||||
}
|
||||
|
||||
calcolaBilancio();
|
||||
}
|
||||
});
|
||||
|
||||
// Ad ogni modifica dell'importo verifica che siano stati selezionati: il conto, la causale, la data. Inoltre aggiorna lo sbilancio
|
||||
function calcolaBilancio(){
|
||||
bilancio = 0.00;
|
||||
totale_dare = 0.00;
|
||||
totale_avere = 0.00;
|
||||
|
||||
// Calcolo il totale dare e totale avere
|
||||
$('#bs-popup input[id*=dare]').each( function(){
|
||||
if( $(this).val() == '' ) valore = 0;
|
||||
else valore = $(this).val().toEnglish();
|
||||
totale_dare += Math.round(valore*100)/100;
|
||||
});
|
||||
|
||||
$('#bs-popup input[id*=avere]').each( function(){
|
||||
if( $(this).val() == '' ) valore = 0;
|
||||
else valore = $(this).val().toEnglish();
|
||||
totale_avere += Math.round(valore*100)/100;
|
||||
});
|
||||
|
||||
$('#bs-popup #totale_dare').text(totale_dare.toLocale());
|
||||
$('#bs-popup #totale_avere').text(totale_avere.toLocale());
|
||||
|
||||
bilancio = Math.round(totale_dare*100)/100 - Math.round(totale_avere*100)/100;
|
||||
|
||||
if(bilancio == 0){
|
||||
$('#bs-popup #testo_aggiuntivo').removeClass('text-danger').html("");
|
||||
$('#bs-popup #btn_submit').removeClass('hide');
|
||||
$('#bs-popup #btn_crea_modello').removeClass('hide');
|
||||
}
|
||||
else{
|
||||
$('#bs-popup #testo_aggiuntivo').addClass('text-danger').html("sbilancio di " + bilancio.toLocale() + " " + globals.currency );
|
||||
$('#bs-popup #btn_submit').addClass('hide');
|
||||
$('#bs-popup #btn_crea_modello').addClass('hide');
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger dell'evento keyup() per la prima volta, per eseguire i dovuti controlli nel caso siano predisposte delle righe in prima nota
|
||||
$("#bs-popup input[id*=dare][value!=''], #bs-popup input[id*=avere][value!='']").keyup();
|
||||
|
||||
$("#bs-popup select[id*=idconto]").click( function(){
|
||||
$("#bs-popup input[id*=dare][value!=''], #bs-popup input[id*=avere][value!='']").keyup();
|
||||
});
|
||||
|
||||
|
||||
$('#bs-popup #modello_primanota').change(function(){
|
||||
|
||||
if ($(this).val()!=''){
|
||||
$('#btn_crea_modello').html('<i class="fa fa-edit"></i> '+'<?php echo tr('Aggiungi e modifica modello'); ?>');
|
||||
$('#bs-popup #idmastrino').val($(this).val());
|
||||
}else{
|
||||
$('#btn_crea_modello').html('<i class="fa fa-plus"></i> '+'<?php echo tr('Aggiungi e crea modello'); ?>');
|
||||
$('#bs-popup #idmastrino').val(0);
|
||||
}
|
||||
|
||||
var idmastrino = $(this).val();
|
||||
var variables = <?php echo json_encode($variables); ?>;
|
||||
|
||||
var replaced = 0;
|
||||
|
||||
if(idmastrino!=''){
|
||||
var causale = $(this).find('option:selected').data('causale');
|
||||
|
||||
if($('#iddocumento').val()!=''){
|
||||
for (i in variables){
|
||||
if(causale.includes('{'+i+'}')){
|
||||
replaced++;
|
||||
causale = causale.replace('{'+i+'}', variables[i]);
|
||||
$.get(globals.rootdir + '/ajax_complete.php?op=get_conti&idmastrino=' + idmastrino, function(data) {
|
||||
var conti = data.split(',');
|
||||
for (i = 0; i < conti.length; i++) {
|
||||
var conto = conti[i].split(';');
|
||||
// Sostituzione conto cliente/fornitore
|
||||
if (conto[0] == -1) {
|
||||
if ($('#iddocumento').val() != '') {
|
||||
var option = $("<option selected></option>").val(variables['conto']).text(variables['conto_descrizione']);
|
||||
$('#bs-popup #conto' + i).selectReset();
|
||||
$('#bs-popup #conto' + i).append(option).trigger('change');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (i in variables){
|
||||
causale = causale.replace('{'+i+'}', '_');
|
||||
} else {
|
||||
var option = $("<option selected></option>").val(conto[0]).text(conto[1]);
|
||||
$('#bs-popup #conto' + i).selectReset();
|
||||
$('#bs-popup #conto' + i).append(option).trigger('change');
|
||||
}
|
||||
}
|
||||
|
||||
//aggiornava erroneamente anche la causale ed eventuale numero di fattura e data
|
||||
if(replaced>0 || $('#iddocumento').val()==''){
|
||||
$('#bs-popup #desc').val(causale);
|
||||
for (i = 9; i >= conti.length; i--) {
|
||||
$('#bs-popup #conto' + i).selectReset();
|
||||
console.log('#bs-popup #conto' + i);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$.get('<?php echo $rootdir; ?>/ajax_complete.php?op=get_conti&idmastrino='+idmastrino, function(data){
|
||||
var conti = data.split(',');
|
||||
for(i=0;i<conti.length;i++){
|
||||
var conto = conti[i].split(';');
|
||||
//Sostituzione conto cliente/fornitore
|
||||
if(conto[0]==-1){
|
||||
if($('#iddocumento').val()!=''){
|
||||
var option = $("<option selected></option>").val(variables['conto']).text(variables['conto_descrizione']);
|
||||
$('#bs-popup #conto'+i).selectReset();
|
||||
$('#bs-popup #conto'+i).append(option).trigger('change');
|
||||
}
|
||||
}else{
|
||||
var option = $("<option selected></option>").val(conto[0]).text(conto[1]);
|
||||
$('#bs-popup #conto'+i).selectReset();
|
||||
$('#bs-popup #conto'+i).append(option).trigger('change');
|
||||
}
|
||||
}
|
||||
for(i=9;i>=conti.length;i--){
|
||||
$('#bs-popup #conto'+i).selectReset();
|
||||
console.log('#bs-popup #conto'+i);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#bs-popup #btn_crea_modello').click(function(){
|
||||
$('#bs-popup #crea_modello').val("1");
|
||||
$('#bs-popup #add-form').submit();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
$('#bs-popup #btn_crea_modello').click(function() {
|
||||
$('#bs-popup #crea_modello').val("1");
|
||||
$('#bs-popup #add-form').submit();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
@ -21,15 +21,14 @@ echo '
|
||||
<table class="table table-striped table-hover table-condensed table-bordered">';
|
||||
|
||||
$rs = $dbo->fetchArray('SELECT * FROM (co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica WHERE co_documenti.id='.prepare($record['iddocumento']));
|
||||
|
||||
$dir = $rs[0]['dir'];
|
||||
$numero = (!empty($rs[0]['numero_esterno'])) ? $rs[0]['numero_esterno'] : $rs[0]['numero'];
|
||||
$modulo_fattura = $dir == 'entrata' ? 'Fatture di vendita' : 'Fatture di acquisto';
|
||||
|
||||
if ($rs[0]['dir'] == 'entrata') {
|
||||
$dir = 'entrata';
|
||||
$modulo = 'Fatture di vendita';
|
||||
if (!empty($rs)) {
|
||||
echo "
|
||||
<tr>
|
||||
<th width='120'>".tr('Cliente').':</th>
|
||||
<th width='120'>".($dir == 'entrata' ? tr('Cliente') : tr('Fornitore')).':</th>
|
||||
<td>
|
||||
'.Modules::link('Anagrafiche', $rs[0]['idanagrafica'], $rs[0]['ragione_sociale']).'
|
||||
</td>
|
||||
@ -49,29 +48,6 @@ if ($rs[0]['dir'] == 'entrata') {
|
||||
<th>'.tr('Data').':</th>
|
||||
<td>'.Translator::dateToLocale($rs[0]['data']).'</td>
|
||||
</tr>';
|
||||
} elseif ($rs[0]['dir'] == 'uscita') {
|
||||
$dir = 'uscita';
|
||||
$modulo = 'Fatture di acquisto';
|
||||
echo "
|
||||
<tr>
|
||||
<th width='120'>".tr('Fornitore').':</th>
|
||||
<td>'.$rs[0]['ragione_sociale'].'</td>
|
||||
</tr>';
|
||||
echo '
|
||||
<tr>
|
||||
<th>'.tr('Documento').':</th>
|
||||
<td>'.$rs[0]['descrizione'].'</td>
|
||||
</tr>';
|
||||
echo '
|
||||
<tr>
|
||||
<th>'.tr('Numero').':</th>
|
||||
<td>'.$numero.'</td>
|
||||
</tr>';
|
||||
echo '
|
||||
<tr>
|
||||
<th>'.tr('Data').':</th>
|
||||
<td>'.Translator::dateToLocale($rs[0]['data']).'</td>
|
||||
</tr>';
|
||||
} else {
|
||||
$rs = $dbo->fetchArray("SELECT * FROM co_scadenziario WHERE id='".$id_record."'");
|
||||
echo "
|
||||
@ -84,7 +60,7 @@ if ($rs[0]['dir'] == 'entrata') {
|
||||
echo '
|
||||
</table>
|
||||
|
||||
'.Modules::link($modulo, $record['iddocumento'], '<i class="fa fa-folder-open"></i> '.tr('Apri documento'), null, 'class="btn btn-primary"').'
|
||||
'.Modules::link($modulo_fattura, $record['iddocumento'], '<i class="fa fa-folder-open"></i> '.tr('Apri documento'), null, 'class="btn btn-primary"').'
|
||||
</div>
|
||||
|
||||
<!-- Elenco scadenze -->
|
||||
@ -156,7 +132,7 @@ echo '
|
||||
</table>
|
||||
|
||||
<div class='pull-right'>
|
||||
<a onclick="launch_modal( 'Registra contabile pagamento', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&iddocumento=<?php echo $record['iddocumento']; ?>&dir=<?php echo $dir; ?>&idscadenza=<?php echo $id_record; ?>', 1 );" class="btn btn-sm btn-primary"><i class="fa fa-euro"></i> <?php echo tr('Registra contabile pagamento...'); ?></a>
|
||||
<a onclick="launch_modal( 'Registra contabile pagamento', '<?php echo $rootdir; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&dir=<?php echo $dir; ?>&id_scadenze=<?php echo $id_record; ?>', 1 );" class="btn btn-sm btn-primary"><i class="fa fa-euro"></i> <?php echo tr('Registra contabile pagamento...'); ?></a>
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
|
@ -7,5 +7,5 @@ $reset_token = $record->reset_token;
|
||||
return [
|
||||
'username' => $record->username,
|
||||
'reset_token' => $reset_token,
|
||||
'reset_link' => ROOTDIR.'/reset.php?reset_token='.$reset_token,
|
||||
'reset_link' => BASEURL.'/reset.php?reset_token='.$reset_token,
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user