2017-08-04 16:28:16 +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-01-20 15:08:51 +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 />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2018-02-23 16:04:50 +01:00
?> <form action="" method="post" id="edit-form">
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " update " >
<!-- DATI -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " >< ? php echo tr ( 'Dati' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2021-04-19 17:35:42 +02:00
< div class = " col-md-8 " >
2024-04-19 16:44:08 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Descrizione'); ?> " , " name " : " descrizione " , " value " : " $title $ " , " required " : 1 ]}
2017-09-13 13:05:35 +02:00
</ div >
2019-05-08 11:19:33 +02:00
< div class = " col-md-4 " >
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Codice Modalità (Fatturazione Elettronica)'); ?> " , " name " : " codice_modalita_pagamento_fe " , " value " : " $codice_modalita_pagamento_fe $ " , " values " : " query=SELECT `codice` as id, CONCAT(`codice`, ' - ', `title`) AS descrizione FROM `fe_modalita_pagamento` LEFT JOIN `fe_modalita_pagamento_lang` ON (`fe_modalita_pagamento_lang`.`id_record`=`fe_modalita_pagamento`.`codice` AND `fe_modalita_pagamento_lang`.`id_lang`=<?php echo prepare(Models \ Locale::getDefault()->id); ?>) " , " required " : 1 , " help " : " <?php echo tr('Impostando il codice MP12 il pagamento viene considerato di tipo Ri.Ba.: nelle fatture verrà visualizzata la banca della controparte'); ?> " ]}
2019-05-08 11:19:33 +02:00
</ div >
2018-10-04 17:37:28 +02:00
</ div >
< div class = " row " >
< div class = " col-md-6 " >
2021-09-01 10:20:13 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Conto predefinito per le vendite'); ?> " , " name " : " idconto_vendite " , " value " : " $idconto_vendite $ " , " ajax-source " : " conti " ]}
2017-09-13 13:05:35 +02:00
</ div >
2018-10-04 17:37:28 +02:00
< div class = " col-md-6 " >
2018-08-11 15:49:46 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Conto predefinito per gli acquisti'); ?> " , " name " : " idconto_acquisti " , " value " : " $idconto_acquisti $ " , " ajax-source " : " conti " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " >< ? php echo tr ( 'Rate' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2020-10-11 09:46:38 +02:00
< div id = " elenco-rate " >
2017-08-04 16:28:16 +02:00
< ? php
2020-10-11 09:46:38 +02:00
$giorni_pagamento = [];
2017-08-04 16:28:16 +02:00
for ( $i = 1 ; $i <= 31 ; ++ $i ) {
2020-10-11 09:46:38 +02:00
$giorni_pagamento [] = [
'id' => $i ,
'text' => $i ,
];
2017-08-04 16:28:16 +02:00
}
2020-10-11 09:46:38 +02:00
$tipi_scadenza_pagamento = [
[
'id' => 1 ,
'text' => tr ( 'Data fatturazione' ),
],
[
'id' => 2 ,
'text' => tr ( 'Data fatturazione fine mese' ),
],
[
'id' => 3 ,
'text' => tr ( 'Data fatturazione giorno fisso' ),
],
[
'id' => 4 ,
'text' => tr ( 'Data fatturazione fine mese (giorno fisso)' ),
],
];
2024-04-18 17:44:05 +02:00
$results = $dbo -> fetchArray ( 'SELECT *, `co_pagamenti`.`id` as id FROM `co_pagamenti` LEFT JOIN `co_pagamenti_lang` ON (`co_pagamenti`.`id` = `co_pagamenti_lang`.`id_record` AND `co_pagamenti_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') WHERE `title`=' . prepare ( $record [ 'name' ]) . ' ORDER BY `num_giorni` ASC' );
2020-10-11 09:46:38 +02:00
$numero_rata = 1 ;
2017-08-04 16:28:16 +02:00
foreach ( $results as $result ) {
2020-10-11 09:46:38 +02:00
$tipo_scadenza_pagamento = 3 ;
if ( $result [ 'giorno' ] == 0 ) {
$tipo_scadenza_pagamento = 1 ;
} elseif ( $result [ 'giorno' ] == - 1 ) {
$tipo_scadenza_pagamento = 2 ;
} elseif ( $result [ 'giorno' ] < - 1 ) {
$tipo_scadenza_pagamento = 4 ;
}
$giorno_pagamento = null ;
if ( $result [ 'giorno' ] != 0 && $result [ 'giorno' ] != - 1 ) {
$giorno_pagamento = ( $result [ 'giorno' ] < - 1 ) ? - $result [ 'giorno' ] - 1 : $result [ 'giorno' ];
}
2023-08-04 14:54:28 +02:00
// Collegamenti diretti
2024-04-18 17:44:05 +02:00
$elementi = $dbo -> fetchArray ( 'SELECT `co_documenti`.`id`, `co_documenti`.`data`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_tipidocumento_lang`.`title` AS tipo_documento, `co_tipidocumento`.`dir`, NULL AS `deleted_at` FROM `co_documenti` INNER JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` 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 `co_documenti`.`idpagamento` = ' . prepare ( $id_record ) . '
2022-12-16 15:05:27 +01:00
UNION
2024-04-18 17:44:05 +02:00
SELECT `or_ordini` . `id` , `or_ordini` . `data` , `or_ordini` . `numero` , `or_ordini` . `numero_esterno` , `or_tipiordine_lang` . `title` AS tipo_documento , `or_tipiordine` . `dir` , NULL AS `deleted_at` FROM `or_ordini` INNER JOIN `or_tipiordine` ON `or_tipiordine` . `id` = `or_ordini` . `idtipoordine` LEFT JOIN `or_tipiordine_lang` ON ( `or_tipiordine` . `id` = `or_tipiordine_lang` . `id_record` AND `or_tipiordine_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' ) WHERE `or_ordini` . `idpagamento` = '.prepare($id_record).'
2022-12-16 15:05:27 +01:00
UNION
2024-04-18 17:44:05 +02:00
SELECT `dt_ddt` . `id` , `dt_ddt` . `data` , `dt_ddt` . `numero` , `dt_ddt` . `numero_esterno` , `dt_tipiddt_lang` . `title` AS tipo_documento , `dt_tipiddt` . `dir` , NULL AS `deleted_at` FROM `dt_ddt` INNER JOIN `dt_tipiddt` ON `dt_tipiddt` . `id` = `dt_ddt` . `idtipoddt` LEFT JOIN `dt_tipiddt_lang` ON ( `dt_tipiddt` . `id` = `dt_tipiddt_lang` . `id_record` AND `dt_tipiddt_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' ) WHERE `dt_ddt` . `idpagamento` = '.prepare($id_record).'
2022-12-16 15:05:27 +01:00
UNION
SELECT `co_contratti` . `id` , `co_contratti` . `data_bozza` , `co_contratti` . `numero` , 0 AS numero_esterno , " Contratto " AS tipo_documento , 0 AS dir , NULL AS `deleted_at` FROM `co_contratti` WHERE `co_contratti` . `idpagamento` = '.prepare($id_record).'
UNION
SELECT `co_preventivi` . `id` , `co_preventivi` . `data_bozza` , `co_preventivi` . `numero` , 0 AS numero_esterno , " Preventivo " AS tipo_documento , 0 AS dir , NULL AS `deleted_at` FROM `co_preventivi` WHERE `co_preventivi` . `idpagamento` = '.prepare($id_record).'
ORDER BY `data` ' );
2017-08-04 16:28:16 +02:00
echo '
2024-05-16 18:02:50 +02:00
< div class = " card card-success " >
< div class = " card-header with-border " >
< h3 class = " card-title " > '.tr(' Rata _NUMBER_ ' , [
2024-03-22 15:52:24 +01:00
'_NUMBER_' => $numero_rata ,
]) . '</h3>' ;
2023-08-04 14:54:28 +02:00
if ( empty ( $elementi )) {
2023-02-10 15:00:55 +01:00
echo '
2023-08-04 14:54:28 +02:00
< button type = " button " class = " btn btn-danger pull-right " onclick = " rimuoviRata('. $result['id'] .') " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
2023-02-10 15:00:55 +01:00
</ button > ' ;
2023-08-04 14:54:28 +02:00
}
echo '
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2020-10-11 09:46:38 +02:00
< input type = " hidden " value = " '. $result['id'] .' " name = " id['. $numero_rata .'] " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " number " , " label " : " '.tr('Percentuale').' " , " name " : " percentuale['. $numero_rata .'] " , " decimals " : " 2 " , " min-value " : " 0 " , " value " : " '. $result['prc'] .' " , " icon-after " : " <i class= \" fa fa-percent \" ></i> " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " select " , " label " : " '.tr('Scadenza').' " , " name " : " scadenza['. $numero_rata .'] " , " values " : '.json_encode($tipi_scadenza_pagamento).' , " value " : " '. $tipo_scadenza_pagamento .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " select " , " label " : " '.tr('Giorno').' " , " name " : " giorno['. $numero_rata .'] " , " values " : '.json_encode($giorni_pagamento).' , " value " : " '. $giorno_pagamento .' " , " extra " : " ';
2017-08-04 16:28:16 +02:00
if ( $result [ 'giorno' ] == 0 || $result [ 'giorno' ] == - 1 ) {
echo ' disabled' ;
}
echo ' " ]}
</ div >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " number " , " label " : " '.tr('Distanza in giorni').' " , " name " : " distanza['. $numero_rata .'] " , " decimals " : " 0 " , " min-value " : " 0 " , " value " : " '. $result['num_giorni'] .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div > ' ;
2020-10-11 09:46:38 +02:00
++ $numero_rata ;
2017-08-04 16:28:16 +02:00
}
2023-02-10 15:00:55 +01:00
if ( empty ( $elementi )) {
2023-08-04 14:54:28 +02:00
?>
2017-08-04 16:28:16 +02:00
</ div >
2020-10-11 09:46:38 +02:00
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
2020-10-11 09:46:38 +02:00
< button type = " button " class = " btn btn-info " onclick = " aggiungiRata() " >
< i class = " fa fa-plus " ></ i > < ? php echo tr ( 'Aggiungi' ); ?>
</ button >
< button type = " submit " class = " btn btn-success " >
< i class = " fa fa-check " ></ i > < ? php echo tr ( 'Salva' ); ?>
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ form >
2024-05-16 18:02:50 +02:00
< div class = " card card-warning card-solid text-center hide " id = " wait " >
< div class = " card-header with-border " >
< h3 class = " card-title " >
2020-10-11 09:46:38 +02:00
< i class = " fa fa-warning " ></ i > < ? php echo tr ( 'Attenzione!' ); ?>
</ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2017-09-04 12:02:29 +02:00
< p >< ? php echo tr ( 'Prima di poter continuare con il salvataggio è necessario che i valori percentuali raggiungano in totale il 100%' ); ?> .</p>
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2022-12-16 15:05:27 +01:00
2017-08-04 16:28:16 +02:00
< ? php
echo '
< form class = " hide " id = " template " >
2024-05-16 18:02:50 +02:00
< div class = " card " >
< div class = " card-header with-border " >
< h3 class = " card-title " > '.tr(' Nuova rata ').' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2020-10-11 09:46:38 +02:00
< input type = " hidden " value = " " name = " id[-id-] " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-16 20:24:52 +02:00
{[ " type " : " number " , " label " : " '.tr('Percentuale').' " , " decimals " : " 2 " , " name " : " percentuale[-id-] " , " icon-after " : " <i class= \" fa fa-percent \" ></i> " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " select " , " label " : " '.tr('Scadenza').' " , " name " : " scadenza[-id-] " , " values " : '.json_encode($tipi_scadenza_pagamento).' , " value " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " select " , " label " : " '.tr('Giorno').' " , " name " : " giorno[-id-] " , " values " : '.json_encode($giorni_pagamento).' ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-02-20 16:46:23 +01:00
< div class = " col-md-6 " >
2020-10-11 09:46:38 +02:00
{[ " type " : " number " , " label " : " '.tr('Distanza in giorni').' " , " name " : " distanza[-id-] " , " decimals " : " 0 " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
</ form > ' ;
2023-02-10 15:00:55 +01:00
} else {
2023-08-04 14:54:28 +02:00
echo '
2023-02-10 15:00:55 +01:00
</ div >
</ div >
</ div >
</ form >
2024-05-16 18:02:50 +02:00
< div class = " card card-warning collapsable collapsed-card " >
< div class = " card-header with-border " >
< h3 class = " card-title " >< i class = " fa fa-warning " ></ i > '.tr(' Documenti collegati : _NUM_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => count ( $elementi ),
]) . ' </ h3 >
2024-05-16 18:02:50 +02:00
< div class = " card-tools pull-right " >
2024-05-23 17:51:21 +02:00
< button type = " button " class = " btn btn-tool " data - card - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
2022-12-16 15:05:27 +01:00
</ div >
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2022-12-16 15:05:27 +01:00
< ul > ' ;
foreach ( $elementi as $elemento ) {
$descrizione = tr ( '_DOC_ _NUM_ del _DATE_ _DELETED_AT_' , [
2024-03-22 15:52:24 +01:00
'_DOC_' => $elemento [ 'tipo_documento' ],
'_NUM_' => ! empty ( $elemento [ 'numero_esterno' ]) ? $elemento [ 'numero_esterno' ] : $elemento [ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $elemento [ 'data' ]),
'_DELETED_AT_' => ( ! empty ( $elemento [ 'deleted_at' ]) ? tr ( 'Eliminato il:' ) . ' ' . Translator :: dateToLocale ( $elemento [ 'deleted_at' ]) : '' ),
]);
2022-12-16 15:05:27 +01:00
2024-01-15 15:30:45 +01:00
// se non è un preventivo è un ddt o una fattura
// se non è un ddt è una fattura.
2022-12-16 15:05:27 +01:00
if ( in_array ( $elemento [ 'tipo_documento' ], [ 'Preventivo' ])) {
$modulo = 'Preventivi' ;
} elseif ( in_array ( $elemento [ 'tipo_documento' ], [ 'Contratto' ])) {
$modulo = 'Contratti' ;
} elseif ( in_array ( $elemento [ 'tipo_documento' ], [ 'Ordine cliente' , 'Ordine fornitore' ])) {
$modulo = ( $elemento [ 'dir' ] == 'entrata' ) ? 'Ordini cliente' : 'Ordini fornitore' ;
} elseif ( in_array ( $elemento [ 'tipo_documento' ], [ 'Ddt in uscita' , 'Ddt in entrata' ])) {
2024-05-03 12:15:09 +02:00
$modulo = ( $elemento [ 'dir' ] == 'entrata' ) ? 'Ddt in uscita' : 'Ddt in entrata' ;
2022-12-16 15:05:27 +01:00
} else {
$modulo = ( $elemento [ 'dir' ] == 'entrata' ) ? 'Fatture di vendita' : 'Fatture di acquisto' ;
}
$id = $elemento [ 'id' ];
echo '
< li > '.Modules::link($modulo, $id, $descrizione).' </ li > ' ;
}
2023-08-04 14:54:28 +02:00
echo '
2022-12-16 15:05:27 +01:00
</ ul >
</ div >
</ div > ' ;
}
if ( ! empty ( $elementi )) {
echo '
< div class = " alert alert-error " >
2023-08-04 14:54:28 +02:00
'.tr(' Eliminando questo metodo di pagamento si potrebbero verificare problemi nelle altre sezioni del gestionale ').' .
2022-12-16 15:05:27 +01:00
</ div >
< a class = " btn btn-danger ask disabled " data - backto = " record-list " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a > ' ;
} else {
2023-08-04 14:54:28 +02:00
echo '
2022-12-16 15:05:27 +01:00
< a class = " btn btn-danger ask " data - backto = " record-list " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a > ' ;
}
2017-08-04 16:28:16 +02:00
?>
< script >
2020-10-11 09:46:38 +02:00
var indice_rata = " <?php echo $numero_rata ; ?> " ;
2020-07-31 14:25:50 +02:00
$ ( document ) . ready ( function () {
2020-10-11 09:46:38 +02:00
$ ( document ) . on ( " change " , " [id^=scadenza] " , function () {
const giorno = $ ( this ) . parentsUntil ( " .box " ) . find ( " [id*=giorno] " );
const giorno_input = input ( giorno [ 0 ]);
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
const tipo_scadenza = parseInt ( input ( this ) . get ());
giorno_input . setDisabled ( tipo_scadenza === 1 || tipo_scadenza === 2 );
});
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
$ ( document ) . on ( " change " , " input[id^=percentuale] " , function () {
controllaRate ();
2017-08-04 16:28:16 +02:00
});
2020-10-11 09:46:38 +02:00
$ ( " #edit-form " ) . submit ( function ( event ) {
const result = controllaRate ();
if ( ! result ) {
event . preventDefault ();
return false ;
2017-08-04 16:28:16 +02:00
}
2018-07-23 11:15:38 +02:00
});
2020-10-11 09:46:38 +02:00
});
function aggiungiRata () {
2023-07-11 10:10:35 +02:00
aggiungiContenuto ( " #elenco-rate>div:last-of-type " , " #template " , { " -id- " : indice_rata });
2020-10-11 09:46:38 +02:00
indice_rata ++ ;
}
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
function controllaRate () {
let totale = 0 ;
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
$ ( " #elenco-rate " ) . find ( " input[id^=percentuale] " ) . each ( function () {
totale += input ( this ) . get ();
});
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
if ( totale !== 100 ) {
$ ( " #wait " ) . removeClass ( " hide " );
} else {
$ ( " #wait " ) . addClass ( " hide " );
}
2017-08-04 16:28:16 +02:00
2020-10-11 09:46:38 +02:00
return totale === 100 ;
}
function rimuoviRata ( id ) {
if ( confirm ( " <?php echo tr('Eliminare questo elemento?'); ?> " )){
location . href = " <?php echo base_path(); ?>/editor.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>&op=delete_rata&id= " + id ;
}
}
2017-08-04 16:28:16 +02:00
</ script >