2018-02-22 11:07:52 +01: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 />.
*/
2018-02-22 11:07:52 +01:00
include_once __DIR__ . '/../../core.php' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2018-02-22 11:07:52 +01:00
2024-03-20 11:13:28 +01:00
if ( $module -> getTranslation ( 'name' ) == 'Fatture di vendita' ) {
2020-06-30 13:26:15 +02:00
$attributi_visibili = $record [ 'dati_aggiuntivi_fe' ] != null || $record [ 'stato' ] == 'Bozza' ;
2019-07-22 12:52:48 +02:00
2019-07-15 18:34:59 +02:00
echo '
2019-07-22 12:52:48 +02:00
< a class = " btn btn-info '.( $attributi_visibili ? '' : 'disabled').' " data - toggle = " modal " data - title = " '.tr('Dati Fattura Elettronica').' " data - href = " '. $structure->fileurl ('fe/document-fe.php').'?id_module='. $id_module .'&id_record='. $id_record .' " '.($attributi_visibili ? ' ' : ' disabled ').' >
2019-07-15 18:34:59 +02:00
< i class = " fa fa-file-code-o " ></ i > '.tr(' Attributi avanzati ').'
</ a > ' ;
}
2022-05-13 13:23:15 +02:00
if ( $dir == 'entrata' || ! empty ( $abilita_autofattura )) {
2023-08-04 14:54:28 +02:00
echo '
2018-07-03 17:28:02 +02:00
< div class = " btn-group " >
2022-09-01 15:38:31 +02:00
< button type = " button " class = " btn btn-primary unblockable dropdown-toggle '.(((!empty( $record['ref_documento'] ) || $record['stato'] != 'Bozza') and (empty( $record['is_reversed'] ) || !empty( $abilita_autofattura ))) ? '' : 'disabled').' " data - toggle = " dropdown " aria - haspopup = " true " aria - expanded = " false " >
2020-07-31 14:57:23 +02:00
< i class = " fa fa-magic " ></ i > '.tr(' Crea ').'
< span class = " caret " ></ span >
2022-05-13 13:23:15 +02:00
</ button > ' ;
if ( $dir == 'entrata' ) {
2023-08-04 14:54:28 +02:00
echo '
2018-07-03 17:28:02 +02:00
< ul class = " dropdown-menu dropdown-menu-right " >
2020-09-23 17:53:19 +02:00
< li >< a href = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=nota_addebito&backto=record-edit " >
2018-07-05 17:56:38 +02:00
'.tr(' Nota di debito ').'
2018-07-03 17:28:02 +02:00
</ a ></ li >
2020-09-23 17:53:19 +02:00
< li >< a data - href = " '.base_path().'/modules/fatture/crea_documento.php?id_module='. $id_module .'&id_record='. $id_record .'&iddocumento='. $id_record .' " data - title = " Aggiungi nota di credito " >
2018-07-05 17:56:38 +02:00
'.tr(' Nota di credito ').'
2018-07-03 17:28:02 +02:00
</ a ></ li >
2022-05-13 13:23:15 +02:00
</ ul > ' ;
} elseif ( ! empty ( $abilita_autofattura )) {
2023-08-04 14:54:28 +02:00
echo '
2022-05-13 13:23:15 +02:00
< ul class = " dropdown-menu dropdown-menu-right " >
< li >< a data - href = " '.base_path().'/modules/fatture/crea_autofattura.php?id_module='. $id_module .'&id_record='. $id_record .'&iddocumento='. $id_record .' " data - title = " Aggiungi autofattura " >
'.tr(' Autofattura ').'
</ a ></ li >
2023-08-04 14:54:28 +02:00
</ ul > ' ;
2022-05-13 13:23:15 +02:00
}
2023-08-04 14:54:28 +02:00
echo '
2018-07-03 17:28:02 +02:00
</ div > ' ;
}
2018-09-28 09:30:46 +02:00
if ( empty ( $record [ 'is_fiscale' ])) {
2023-08-04 14:54:28 +02:00
$msg = '<br>{[ "type": "select", "label": "' . tr ( 'Sezionale' ) . '", "name": "id_segment", "required": 1, "ajax-source": "segmenti", "select-options": ' . json_encode ([ 'id_module' => $id_module , 'is_sezionale' => 1 , 'is_fiscale' => 1 ]) . ' , " select-options-escape " : true ]}
2019-07-31 18:28:50 +02:00
{[ " type " : " date " , " label " : " '.tr('Data').' " , " name " : " data " , " required " : 1 , " value " : " -now- " ]} ' ;
2018-09-28 09:30:46 +02:00
echo '
2024-01-15 15:30:45 +01:00
< button type = " button " class = " btn btn-warning ask " data - msg = " '.tr('Vuoi trasformare questa fattura pro-forma in una di tipo fiscale?').'<br>'.prepareToField(HTMLBuilder \ HTMLBuilder::replace( $msg )).' " data - op = " transform " data - button = " '.tr('Trasforma').' " data - class = " btn btn-lg btn-warning " data - backto = " record-edit " >
2018-09-28 09:30:46 +02:00
< i class = " fa fa-upload " ></ i > '.tr(' Trasforma in fattura fiscale ').'
</ button > ' ;
}
2019-02-26 11:01:35 +01:00
2024-03-27 15:34:01 +01:00
$modulo_prima_nota = ( new Module ()) -> getByField ( 'name' , 'Prima nota' , \Models\Locale :: where ( 'predefined' , true ) -> first () -> id );
2020-11-13 16:12:29 +01:00
$totale_scadenze = $dbo -> fetchOne ( 'SELECT SUM(da_pagare - pagato) AS differenza, SUM(da_pagare) AS da_pagare FROM co_scadenziario WHERE iddocumento = ' . prepare ( $id_record ));
2019-02-26 11:01:35 +01:00
if ( ! empty ( $record [ 'is_fiscale' ])) {
2023-08-02 13:18:17 +02:00
$differenza = isset ( $totale_scadenze ) ? $totale_scadenze [ 'differenza' ] : 0 ;
2020-08-31 09:29:06 +02:00
// Aggiunta insoluto
2020-11-13 16:12:29 +01:00
$registrazione_insoluto = 0 ;
2021-04-19 17:35:42 +02:00
$pagamento = $fattura -> pagamento ;
2021-07-07 07:57:10 +02:00
if ( ! empty ( $pagamento )) {
2023-08-02 13:18:17 +02:00
if ( $pagamento -> isRiBa () && $dir == 'entrata' && in_array ( $record [ 'stato' ], [ 'Emessa' , 'Parzialmente pagato' , 'Pagato' ]) && $differenza == 0 ) {
2021-04-29 17:50:23 +02:00
$registrazione_insoluto = 1 ;
}
2020-11-13 16:12:29 +01:00
}
if ( floatval ( $totale_scadenze [ 'da_pagare' ]) == 0 ) {
2020-08-31 09:29:06 +02:00
$registrazione_insoluto = 0 ;
}
2019-04-11 16:04:08 +02:00
2020-08-31 09:29:06 +02:00
echo '
2024-03-05 16:01:45 +01:00
< a class = " btn btn-primary '.(!empty( $modulo_prima_nota ) && !empty( $registrazione_insoluto ) ? '' : 'disabled').' " data - href = " '.base_path().'/add.php?id_module='. $modulo_prima_nota .'&id_documenti='. $id_record .'&single=1&is_insoluto=1 " data - title = " '.tr('Registra insoluto').' " >
2020-08-31 09:29:06 +02:00
< i class = " fa fa-ban fa-inverse " ></ i > '.tr(' Registra insoluto ').'
</ a > ' ;
2019-02-26 11:01:35 +01:00
2020-08-31 09:29:06 +02:00
// Aggiunta prima nota solo se non c'è già, se non si è in bozza o se il pagamento non è completo
$prima_nota_presente = $dbo -> fetchNum ( 'SELECT id FROM co_movimenti WHERE iddocumento = ' . prepare ( $id_record ) . ' AND primanota = 1' );
2020-01-09 18:33:01 +01:00
2020-11-13 16:12:29 +01:00
$registrazione_contabile = 0 ;
2020-08-31 09:29:06 +02:00
if ( $differenza != 0 || ( ! $prima_nota_presente && $record [ 'stato' ] == 'Emessa' )) {
2020-11-13 16:12:29 +01:00
$registrazione_contabile = 1 ;
}
if ( floatval ( $totale_scadenze [ 'da_pagare' ]) == 0 ) {
2020-08-31 09:29:06 +02:00
$registrazione_contabile = 0 ;
}
2020-01-09 18:33:01 +01:00
2020-08-31 09:29:06 +02:00
echo '
2024-03-05 16:01:45 +01:00
< a class = " btn btn-primary '.(!empty( $modulo_prima_nota ) && !empty( $registrazione_contabile ) ? '' : 'disabled').' " data - href = " '.base_path().'/add.php?id_module='. $modulo_prima_nota .'&id_documenti='. $id_record .'&single=1 " data - title = " '.tr('Registra contabile').' " >
2020-08-31 09:29:06 +02:00
< i class = " fa fa-euro " ></ i > '.tr(' Registra contabile ').'
</ a > ' ;
2020-01-09 18:33:01 +01:00
2019-02-26 11:01:35 +01:00
if ( $record [ 'stato' ] == 'Pagato' ) {
2019-07-25 18:05:47 +02:00
echo '
2022-12-02 19:14:25 +01:00
< button type = " button " class = " btn btn-primary ask tip " data - msg = " '.tr('Se riapri questo documento verrà azzerato lo scadenzario e la relativa prima nota. Continuare?').' " data - button = " '.tr('Procedi').' " data - method = " post " data - op = " reopen " data - backto = " record-edit " data - title = " '.tr('Riaprire il documento?').' " title = " '.tr( " Riporta il documento nello stato di 'Emessa' e ne elimina i movimenti contabili " ).' " >
2020-11-02 16:23:24 +01:00
< i class = " fa fa-folder-open " ></ i > '.tr(' Riapri documento ').' ...
2019-07-25 17:20:24 +02:00
</ button > ' ;
2019-02-26 11:01:35 +01:00
}
2022-07-21 12:32:22 +02:00
}
// Duplica fattura
echo '
< button type = " button " class = " btn btn-primary ask " '.(empty($record[' is_reversed ']) ? ' ' : ' disabled ').' data - title = " '.tr('Duplicare questa fattura?').' " data - msg = " '.tr('Clicca su tasto duplica per procedere.').' " data - op = " copy " data - button = " '.tr('Duplica').' " data - class = " btn btn-lg btn-primary " data - backto = " record-edit " >
< i class = " fa fa-copy " ></ i > '.tr(' Duplica fattura ').'
</ button > ' ;