1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-11 07:56:16 +01:00
openstamanager/modules/anagrafiche/plugins/allegati.php

171 lines
9.3 KiB
PHP
Raw Normal View History

2021-06-14 18:34:55 +02:00
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* 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/>.
*/
use Models\Upload;
2021-07-07 07:57:10 +02:00
use Modules\Anagrafiche\Anagrafica;
2024-03-05 16:01:45 +01:00
use Models\Module;
2021-06-14 18:34:55 +02:00
include_once __DIR__.'/../../../core.php';
2024-01-15 15:30:45 +01:00
// Allegati dell'anagrafica
echo '
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">'.tr('Allegati dell\'anagrafica').'</h3>
</div>
<div class="box-body">';
2021-06-14 18:34:55 +02:00
if (empty($_GET['visualizza_allegati'])) {
echo '
<div class="row">
<div class="col-md-12 text-center">
<a class="btn btn-info btn-lg" href="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&visualizza_allegati=1#tab_'.$id_plugin.'">
<i class="fa fa-eye"></i>
'.tr('Visualizza tutti gli allegati').'
</a>
</div>
</div>';
} else {
2024-01-15 15:30:45 +01:00
// Controllo i permessi dei modulo per la visualizzazione degli allegati
$rs = $dbo->table('zz_permissions')->where('idgruppo', $user->idgruppo)->get();
$permessi = [];
2023-06-21 10:34:46 +02:00
$documenti[] = 0;
foreach ($rs as $r) {
$permessi[] = $r->idmodule;
}
2021-06-14 18:34:55 +02:00
if ($anagrafica->uploads()->first()) {
$documenti[] = [
'id_module' => $id_module,
'id_record' => $id_record,
'descrizione' => "Allegato dell'anagrafica",
];
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// Interventi dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Interventi'), $permessi)) {
$interventi = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Interventi'))." AS id_module, `id` AS id_record, CONCAT('Intervento num. ',codice,' del ',DATE_FORMAT(`data_richiesta`,'%d/%m/%Y')) AS descrizione FROM `in_interventi` WHERE `idanagrafica`=".prepare($id_record));
$documenti = array_merge($documenti, $interventi);
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// Preventivi dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Preventivi'), $permessi)) {
$preventivi = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Preventivi'))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_preventivi WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $preventivi);
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// Contratti dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Contratti'), $permessi)) {
$contratti = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Contratti'))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_contratti WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $contratti);
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// DDT dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Ddt di vendita'), $permessi)) {
$ddt_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Ddt di vendita'))." AS id_module, id AS id_record, CONCAT('Ddt di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $ddt_vendita);
}
2021-06-14 18:34:55 +02:00
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Ddt di acquisto'), $permessi)) {
$ddt_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Ddt di acquisto'))." AS id_module, id AS id_record, CONCAT('Ddt di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $ddt_acquisto);
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// Fatture dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Fatture di vendita'), $permessi)) {
$fatture_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Fatture di vendita'))." AS id_module, id AS id_record, CONCAT('Fattura di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $fatture_vendita);
}
2021-06-14 18:34:55 +02:00
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Fatture di acquisto'), $permessi)) {
$fatture_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Fatture di acquisto'))." AS id_module, id AS id_record, CONCAT('Fattura di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $fatture_acquisto);
}
2021-06-14 18:34:55 +02:00
2024-01-15 15:30:45 +01:00
// Ordini dell'anagrafica
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Ordini cliente'), $permessi)) {
$ordini_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Ordini cliente'))." AS id_module, id AS id_record, CONCAT('Ordine cliente num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $ordini_vendita);
}
2021-06-14 18:34:55 +02:00
2024-03-20 11:13:28 +01:00
if ($user->is_admin || in_array((new Module())->getByField('name', 'Ordini fornitore'), $permessi)) {
$ordini_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('name', 'Ordini fornitore'))." AS id_module, id AS id_record, CONCAT('Ordine fornitore num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record));
$documenti = array_merge($documenti, $ordini_acquisto);
}
2021-06-14 18:34:55 +02:00
if (!empty($documenti)) {
echo '
<table class="table table-striped table-hover">
<tr>
<th class="text-center" width="7%">#</th>
<th>'.tr('Allegato').'</th>
<th width="40%">'.tr('Documento').'</th>
<th class="text-center" width="10%">'.tr('Data').'</th>
</tr>';
2021-07-07 07:57:10 +02:00
foreach ($documenti as $documento) {
$allegati = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($documento['id_module']).' AND id_record='.prepare($documento['id_record']));
2021-06-14 18:34:55 +02:00
2021-07-07 07:57:10 +02:00
foreach ($allegati as $allegato) {
$file = Upload::find($allegato['id']);
2021-06-14 18:34:55 +02:00
2021-07-07 07:57:10 +02:00
echo '
<tr>
<td class="text-center">
<a class="btn btn-xs btn-primary" href="'.base_path().'/actions.php?id_module='.$file->id_module.'&op=download-allegato&id='.$file->id.'&filename='.$file->filename.'" target="_blank">
<i class="fa fa-download"></i>
</a>';
2021-06-14 18:34:55 +02:00
2021-07-07 07:57:10 +02:00
// Anteprime supportate dal browser
if ($file->hasPreview()) {
echo '
2024-03-20 11:13:28 +01:00
<button class="btn btn-xs btn-info" type="button" data-title="'.prepareToField($file->getTranslation('name')).' <small style=\'color:white\'><i>('.$file->filename.')</i></small>" data-href="'.base_path().'/view.php?file_id='.$file->id.'">
<i class="fa fa-eye"></i>
</button>';
2021-07-07 07:57:10 +02:00
} else {
echo '
<button class="btn btn-xs btn-default disabled" title="'.tr('Anteprima file non disponibile').'" disabled>
<i class="fa fa-eye"></i>
</button>';
2021-07-07 07:57:10 +02:00
}
echo '
</td>
<td>
<a href="'.base_path().'/view.php?file_id='.$file->id.'" target="_blank">
2024-03-20 11:13:28 +01:00
<i class="fa fa-external-link"></i> '.$file->getTranslation('name').'
</a>
</td>
2024-03-20 11:13:28 +01:00
<td>'.Modules::link(Module::find($allegato['id_module']->getTranslation('name')), $file->id_record, $documento['descrizione']).'</td>
<td class="text-center">'.Translator::dateToLocale($file->created_at).'</td>
2021-06-14 18:34:55 +02:00
</tr>';
2021-07-07 07:57:10 +02:00
}
}
2021-06-14 18:34:55 +02:00
echo '
</table>';
} else {
echo '
<div class=\'alert alert-info\' ><i class=\'fa fa-info-circle\'></i> '.tr('Nessun allegato per questa anagrafica').'.</div>';
}
}
2021-06-14 18:34:55 +02:00
echo '
</div>
2021-07-07 07:57:10 +02:00
</div>';