mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-17 03:51:06 +01:00
Introduzione compilazione automatica FE
This commit is contained in:
parent
cbbc4069ab
commit
73d627a062
@ -270,7 +270,7 @@ switch (post('op')) {
|
|||||||
$dbo->query('UPDATE zz_users SET enabled = 0 WHERE idanagrafica = '.prepare($id_record));
|
$dbo->query('UPDATE zz_users SET enabled = 0 WHERE idanagrafica = '.prepare($id_record));
|
||||||
// Disabilito anche il token
|
// Disabilito anche il token
|
||||||
$dbo->query('UPDATE zz_tokens SET enabled = 0 WHERE id_utente = '.prepare($id_utente));
|
$dbo->query('UPDATE zz_tokens SET enabled = 0 WHERE id_utente = '.prepare($id_utente));
|
||||||
|
|
||||||
flash()->info(tr('Anagrafica eliminata!'));
|
flash()->info(tr('Anagrafica eliminata!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ switch ($resource) {
|
|||||||
|
|
||||||
case 'sedi':
|
case 'sedi':
|
||||||
if (isset($superselect['idanagrafica'])) {
|
if (isset($superselect['idanagrafica'])) {
|
||||||
$query = "SELECT * FROM (SELECT '0' AS id, CONCAT_WS(' - ', 'Sede legale' , (SELECT CONCAT (citta, ' (', ragione_sociale,')') FROM an_anagrafiche |where|)) AS descrizione UNION SELECT id, CONCAT_WS(' - ', nomesede, citta) FROM an_sedi |where|) AS tab HAVING descrizione LIKE ".prepare('%'.$search.'%')." ORDER BY descrizione";
|
$query = "SELECT * FROM (SELECT '0' AS id, CONCAT_WS(' - ', 'Sede legale' , (SELECT CONCAT (citta, ' (', ragione_sociale,')') FROM an_anagrafiche |where|)) AS descrizione UNION SELECT id, CONCAT_WS(' - ', nomesede, citta) FROM an_sedi |where|) AS tab HAVING descrizione LIKE ".prepare('%'.$search.'%').' ORDER BY descrizione';
|
||||||
|
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$filter[] = 'id='.prepare($element);
|
$filter[] = 'id='.prepare($element);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Modules\Anagrafiche;
|
namespace Modules\Anagrafiche;
|
||||||
|
|
||||||
use Common\Model;
|
use Common\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Modules\Contratti\Contratto;
|
use Modules\Contratti\Contratto;
|
||||||
use Modules\DDT\DDT;
|
use Modules\DDT\DDT;
|
||||||
@ -277,6 +278,20 @@ class Anagrafica extends Model
|
|||||||
return $this->hasMany(Fattura::class, 'idanagrafica');
|
return $this->hasMany(Fattura::class, 'idanagrafica');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fattureVendita()
|
||||||
|
{
|
||||||
|
return $this->fatture()->whereHas('tipo', function (Builder $query) {
|
||||||
|
$query->where('dir', 'entrata');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fattureAcquisto()
|
||||||
|
{
|
||||||
|
return $this->fatture()->whereHas('tipo', function (Builder $query) {
|
||||||
|
$query->where('dir', 'uscita');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function ordini()
|
public function ordini()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Ordine::class, 'idanagrafica');
|
return $this->hasMany(Ordine::class, 'idanagrafica');
|
||||||
|
@ -129,7 +129,7 @@ trait RelationTrait
|
|||||||
|
|
||||||
public function getIdContoAttribute()
|
public function getIdContoAttribute()
|
||||||
{
|
{
|
||||||
return $this->idconto;
|
return $this->attributes['idconto'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIdContoAttribute($value)
|
public function setIdContoAttribute($value)
|
||||||
|
@ -6,6 +6,7 @@ use Auth;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Common\Components\Description;
|
use Common\Components\Description;
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
use Modules\Fatture\Components\Riga;
|
use Modules\Fatture\Components\Riga;
|
||||||
use Modules\Pagamenti\Pagamento;
|
use Modules\Pagamenti\Pagamento;
|
||||||
@ -592,6 +593,20 @@ class Fattura extends Document
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope a query to only include popular users.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeContabile($query)
|
||||||
|
{
|
||||||
|
return $query->whereHas('stato', function (Builder $query) {
|
||||||
|
$query->whereIn('descrizione', ['Emessa', 'Parzialmente pagato', 'Pagato']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restituisce i dati bancari in base al pagamento.
|
* Restituisce i dati bancari in base al pagamento.
|
||||||
*
|
*
|
||||||
|
@ -185,11 +185,11 @@ echo '
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (empty($documento)) {
|
if (empty($documento)) {
|
||||||
echo '
|
echo '
|
||||||
<a class="btn btn-danger ask" data-backto="record-list">
|
<a class="btn btn-danger ask" data-backto="record-list">
|
||||||
<i class="fa fa-trash"></i> '.tr('Elimina').'
|
<i class="fa fa-trash"></i> '.tr('Elimina').'
|
||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<table class="hide">
|
<table class="hide">
|
||||||
|
@ -119,7 +119,7 @@ switch (filter('op')) {
|
|||||||
$utente = User::find($id_utente);
|
$utente = User::find($id_utente);
|
||||||
$tokens = $utente->getApiTokens();
|
$tokens = $utente->getApiTokens();
|
||||||
|
|
||||||
foreach ($tokens as $token){
|
foreach ($tokens as $token) {
|
||||||
$dbo->query('UPDATE zz_tokens SET enabled = 1 WHERE id = '.prepare($token['id']));
|
$dbo->query('UPDATE zz_tokens SET enabled = 1 WHERE id = '.prepare($token['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ switch (filter('op')) {
|
|||||||
$utente = User::find($id_utente);
|
$utente = User::find($id_utente);
|
||||||
$tokens = $utente->getApiTokens();
|
$tokens = $utente->getApiTokens();
|
||||||
|
|
||||||
foreach ($tokens as $token){
|
foreach ($tokens as $token) {
|
||||||
$dbo->query('UPDATE zz_tokens SET enabled = 0 WHERE id = '.prepare($token['id']));
|
$dbo->query('UPDATE zz_tokens SET enabled = 0 WHERE id = '.prepare($token['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,15 +75,13 @@ if (!empty($utenti)) {
|
|||||||
|
|
||||||
// Disabilitazione token API, se diverso da id_utente #1 (admin)
|
// Disabilitazione token API, se diverso da id_utente #1 (admin)
|
||||||
$token = $dbo->fetchOne('SELECT `enabled` FROM `zz_tokens` WHERE `id_utente` = '.prepare($utente['id']).'')['enabled'];
|
$token = $dbo->fetchOne('SELECT `enabled` FROM `zz_tokens` WHERE `id_utente` = '.prepare($utente['id']).'')['enabled'];
|
||||||
|
|
||||||
if ($utente['id'] == '1') {
|
if ($utente['id'] == '1') {
|
||||||
echo '
|
echo '
|
||||||
<span title="'.tr("Non è possibile gestire l'accesso API per l'utente admin").'" class="text-muted tip">
|
<span title="'.tr("Non è possibile gestire l'accesso API per l'utente admin").'" class="text-muted tip">
|
||||||
<i class="fa fa-2x fa-key "></i>
|
<i class="fa fa-2x fa-key "></i>
|
||||||
</span>';
|
</span>';
|
||||||
} elseif (!empty($token)) {
|
} elseif (!empty($token)) {
|
||||||
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<a title="'.tr('Disabilita API').'" class="text-danger clickable tip ask" data-msg="" data-backto="record-edit" data-title="'.tr("Disabilitare l'accesso API per questo utente?").'" data-op="token_disable" data-id_utente="'.$utente['id'].'" data-button="'.tr('Disabilita').'">
|
<a title="'.tr('Disabilita API').'" class="text-danger clickable tip ask" data-msg="" data-backto="record-edit" data-title="'.tr("Disabilitare l'accesso API per questo utente?").'" data-op="token_disable" data-id_utente="'.$utente['id'].'" data-button="'.tr('Disabilita').'">
|
||||||
<i class="fa fa-2x fa-key"></i>
|
<i class="fa fa-2x fa-key"></i>
|
||||||
|
@ -589,7 +589,6 @@ class FatturaElettronica
|
|||||||
}
|
}
|
||||||
//Rimuovo eventuali idicazioni relative alla nazione
|
//Rimuovo eventuali idicazioni relative alla nazione
|
||||||
$result['IdFiscaleIVA']['IdCodice'] = str_replace($anagrafica->nazione->iso2, '', $anagrafica['piva']);
|
$result['IdFiscaleIVA']['IdCodice'] = str_replace($anagrafica->nazione->iso2, '', $anagrafica['piva']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Codice fiscale
|
// Codice fiscale
|
||||||
@ -598,9 +597,9 @@ class FatturaElettronica
|
|||||||
$result['CodiceFiscale'] = preg_replace('/\s+/', '', $anagrafica['codice_fiscale']);
|
$result['CodiceFiscale'] = preg_replace('/\s+/', '', $anagrafica['codice_fiscale']);
|
||||||
|
|
||||||
//$result['CodiceFiscale'] = str_replace($anagrafica->nazione->iso2, '', $result['CodiceFiscale']);
|
//$result['CodiceFiscale'] = str_replace($anagrafica->nazione->iso2, '', $result['CodiceFiscale']);
|
||||||
|
|
||||||
//Rimuovo eventuali idicazioni relative all'iso2 della nazione, solo se la stringa inizia con quest'ultima.
|
//Rimuovo eventuali idicazioni relative all'iso2 della nazione, solo se la stringa inizia con quest'ultima.
|
||||||
$result['CodiceFiscale'] = preg_replace('/^' . preg_quote($anagrafica->nazione->iso2, '/') . '/', '', $anagrafica['codice_fiscale']);
|
$result['CodiceFiscale'] = preg_replace('/^'.preg_quote($anagrafica->nazione->iso2, '/').'/', '', $anagrafica['codice_fiscale']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($anagrafica['nome']) or !empty($anagrafica['cognome'])) {
|
if (!empty($anagrafica['nome']) or !empty($anagrafica['cognome'])) {
|
||||||
|
@ -166,4 +166,78 @@ switch (filter('op')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'compile':
|
||||||
|
$fatture = $anagrafica->fattureAcquisto()
|
||||||
|
->contabile()
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->take(10)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$righe = collect();
|
||||||
|
foreach ($fatture as $fattura) {
|
||||||
|
$righe->push($fattura->righe);
|
||||||
|
$righe->push($fattura->articoli);
|
||||||
|
}
|
||||||
|
$righe = $righe->flatten();
|
||||||
|
|
||||||
|
// Ricerca del tipo di documento più utilizzato
|
||||||
|
$tipi = $fatture->groupBy(function ($item, $key) {
|
||||||
|
return $item->tipo->id;
|
||||||
|
})->transform(function ($item, $key) {
|
||||||
|
return $item->count();
|
||||||
|
});
|
||||||
|
$id_tipo = $tipi->sort()->keys()->last();
|
||||||
|
|
||||||
|
// Ricerca del tipo di pagamento più utilizzato
|
||||||
|
$pagamenti = $fatture->mapToGroups(function ($item, $key) {
|
||||||
|
return [$item->pagamento->id => $item->pagamento];
|
||||||
|
});
|
||||||
|
$id_pagamento = $pagamenti->map(function ($item, $key) {
|
||||||
|
return $item->count();
|
||||||
|
})->sort()->keys()->last();
|
||||||
|
$pagamento = $pagamenti[$id_pagamento]->first();
|
||||||
|
|
||||||
|
// Ricerca del conto più utilizzato
|
||||||
|
$conti = $righe->groupBy(function ($item, $key) {
|
||||||
|
return $item->idconto;
|
||||||
|
})->transform(function ($item, $key) {
|
||||||
|
return $item->count();
|
||||||
|
});
|
||||||
|
$id_conto = $conti->sort()->keys()->last();
|
||||||
|
$conto = $dbo->fetchOne('SELECT * FROM co_pianodeiconti3 WHERE id = '.prepare($id_conto));
|
||||||
|
|
||||||
|
// Ricerca dell'IVA più utilizzata secondo percentuali
|
||||||
|
$iva = [];
|
||||||
|
$percentuali_iva = $righe->groupBy(function ($item, $key) {
|
||||||
|
return $item->aliquota->percentuale;
|
||||||
|
});
|
||||||
|
foreach ($percentuali_iva as $key => $values) {
|
||||||
|
$aliquote = $values->mapToGroups(function ($item, $key) {
|
||||||
|
return [$item->aliquota->id => $item->aliquota];
|
||||||
|
});
|
||||||
|
$id_aliquota = $aliquote->map(function ($item, $key) {
|
||||||
|
return $item->count();
|
||||||
|
})->sort()->keys()->last();
|
||||||
|
$aliquota = $aliquote[$id_aliquota]->first();
|
||||||
|
|
||||||
|
$iva[$key] = [
|
||||||
|
'id' => $aliquota->id,
|
||||||
|
'descrizione' => $aliquota->descrizione,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'id_tipo' => $id_tipo,
|
||||||
|
'pagamento' => [
|
||||||
|
'id' => $pagamento->id,
|
||||||
|
'descrizione' => $pagamento->descrizione,
|
||||||
|
],
|
||||||
|
'conto' => [
|
||||||
|
'id' => $conto['id'],
|
||||||
|
'descrizione' => $conto['descrizione'],
|
||||||
|
],
|
||||||
|
'iva' => $iva,
|
||||||
|
]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
47
plugins/importFE/buttons.php
Normal file
47
plugins/importFE/buttons.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<button type="button" class="btn btn-primary tip" '.(!empty($anagrafica) ? '' : 'disabled').' onclick="compile(this)" title="'.tr('Tenta la compilazione automatica delle informazioni delle fattura elettronica sulla base delle precedenti fatture del Fornitore').'.">
|
||||||
|
<i class="fa fa-address-book"></i> '.tr('Compila automaticamente').'
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function compile(btn) {
|
||||||
|
var restore = buttonLoading(btn);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
cache: false,
|
||||||
|
type: "GET",
|
||||||
|
data: {
|
||||||
|
id_module: "'.$id_module.'",
|
||||||
|
id_plugin: "'.$id_plugin.'",
|
||||||
|
id_record: "'.$id_record.'",
|
||||||
|
op: "compile",
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
var data = JSON.parse(response);
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
$("#id_tipo").selectSet(data.id_tipo);
|
||||||
|
$("#pagamento").selectSetNew(data.pagamento.id, data.pagamento.descrizione);
|
||||||
|
|
||||||
|
$("select[name^=iva]").each(function(){
|
||||||
|
var aliquota = $(this).closest("tr").find("[id^=aliquota]").text();
|
||||||
|
$(this).selectSet(data.iva[aliquota].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("select[name^=conto]").each(function(){
|
||||||
|
$(this).selectSetNew(data.conto.id, data.conto.descrizione);
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonRestore(btn, restore);
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
swal("'.tr('Errore').'", "'.tr('La compilazione automatica dei campi non è andata a buon fine').'.", "error");
|
||||||
|
|
||||||
|
buttonRestore(btn, restore);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>';
|
@ -310,6 +310,8 @@ if (!empty($righe)) {
|
|||||||
'_VALUE_' => empty($riga['Natura']) ? numberFormat($riga['AliquotaIVA']).'%' : $riga['Natura'],
|
'_VALUE_' => empty($riga['Natura']) ? numberFormat($riga['AliquotaIVA']).'%' : $riga['Natura'],
|
||||||
'_DESC_' => $riga['RiferimentoNormativo'] ? ' - '.$riga['RiferimentoNormativo'] : '',
|
'_DESC_' => $riga['RiferimentoNormativo'] ? ' - '.$riga['RiferimentoNormativo'] : '',
|
||||||
]).'</small>
|
]).'</small>
|
||||||
|
|
||||||
|
<span class="hide" id="aliquota['.$key.']">'.$riga['AliquotaIVA'].'</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{[ "type": "select", "name": "iva['.$key.']", "values": "query='.str_replace('"', '\"', $query).'", "required": 1, "placeholder": "Aliquota iva" ]}
|
{[ "type": "select", "name": "iva['.$key.']", "values": "query='.str_replace('"', '\"', $query).'", "required": 1, "placeholder": "Aliquota iva" ]}
|
||||||
|
@ -172,7 +172,8 @@ class User extends Model
|
|||||||
return $anagrafica->ragione_sociale.' ('.$this->username.')';
|
return $anagrafica->ragione_sociale.' ('.$this->username.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getApiTokens(){
|
public function getApiTokens()
|
||||||
|
{
|
||||||
$query = 'SELECT * FROM `zz_tokens` WHERE `enabled` = 1 AND `id_utente` = '.prepare($this->id);
|
$query = 'SELECT * FROM `zz_tokens` WHERE `enabled` = 1 AND `id_utente` = '.prepare($this->id);
|
||||||
$database = database();
|
$database = database();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user