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' ;
echo '
2020-07-24 10:14:23 +02:00
< button type = " button " class = " btn btn-primary ask btn-primary " '.(empty($record[' is_reversed ']) ? ' ' : ' disabled ').' data - msg = " '.tr('Duplicare questa fattura?').' " data - op = " copy " data - button = " '.tr('Duplica').' " data - class = " btn btn-lg btn-warning " data - backto = " record-edit " >
2018-02-22 11:07:52 +01:00
< i class = " fa fa-copy " ></ i > '.tr(' Duplica fattura ').'
</ button > ' ;
2018-07-03 17:28:02 +02:00
2019-07-22 12:52:48 +02:00
if ( $module -> 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 > ' ;
}
2019-02-14 17:49:58 +01:00
if ( $dir == 'entrata' ) {
2018-07-03 17:28:02 +02:00
echo '
< div class = " btn-group " >
2020-07-24 10:14:23 +02:00
< button type = " button " class = " btn btn-primary unblockable dropdown-toggle '.(((!empty( $record['ref_documento'] ) || $record['stato'] != 'Bozza') and empty( $record['is_reversed'] )) ? '' : '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 >
2018-07-03 17:28:02 +02:00
</ button >
< 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 >
</ ul >
</ div > ' ;
}
2018-09-28 09:30:46 +02:00
if ( empty ( $record [ 'is_fiscale' ])) {
2019-07-31 18:28:50 +02:00
$msg = '<br>{[ "type": "select", "label": "' . tr ( 'Sezionale' ) . '", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module=\'' . $id_module . ' \ ' AND is_fiscale = 1 ORDER BY name " ]}
{[ " type " : " date " , " label " : " '.tr('Data').' " , " name " : " data " , " required " : 1 , " value " : " -now- " ]} ' ;
2018-09-28 09:30:46 +02:00
echo '
< 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 " >
< i class = " fa fa-upload " ></ i > '.tr(' Trasforma in fattura fiscale ').'
</ button > ' ;
}
2019-02-26 11:01:35 +01:00
2020-08-31 09:29:06 +02:00
$modulo_prima_nota = Modules :: get ( 'Prima nota' );
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' ])) {
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-04-29 17:50:23 +02:00
if ( ! empty ( $pagamento )){
if ( $pagamento -> isRiBa () && $dir == 'entrata' && in_array ( $record [ 'stato' ], [ 'Emessa' , 'Parzialmente pagato' , 'Pagato' ])) {
$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 '
2020-11-13 16:12:29 +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'] .'&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-08-31 09:29:06 +02:00
$differenza = isset ( $totale_scadenze ) ? $totale_scadenze [ 'differenza' ] : 0 ;
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 '
2020-11-13 16:12:29 +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'] .'&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 '
2020-11-02 16:23:24 +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 in stato " Bozza " e ne elimina i movimenti contabili').' " >
< 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
}
}