Riferimento fatture per note FE
This commit is contained in:
parent
8a7a53c40b
commit
c69b6844e5
|
@ -152,7 +152,7 @@ foreach ($righe as $row) {
|
|||
]);
|
||||
|
||||
echo '
|
||||
<br>'.Modules::link('Fatture di vendita', $record['ref_documento'], $text, $text);
|
||||
<br>'.Modules::link($id_module, $record['ref_documento'], $text, $text);
|
||||
}
|
||||
|
||||
$ref = doc_references($riga, $dir, ['iddocumento']);
|
||||
|
|
|
@ -10,12 +10,12 @@ switch (filter('op')) {
|
|||
$content = file_get_contents($_FILES['blob']['tmp_name']);
|
||||
$file = FatturaElettronica::store($_FILES['blob']['name'], $content);
|
||||
|
||||
$name = $file;
|
||||
|
||||
// no break
|
||||
case 'prepare':
|
||||
$name = $name ?: get('name');
|
||||
$file = Interaction::getImportXML($name);
|
||||
if (!isset($file)){
|
||||
$name = get('name');
|
||||
$file = Interaction::getImportXML($name);
|
||||
}
|
||||
|
||||
if (FatturaElettronica::isValid($file)) {
|
||||
echo json_encode([
|
||||
|
@ -43,6 +43,7 @@ switch (filter('op')) {
|
|||
'id_pagamento' => post('pagamento'),
|
||||
'id_segment' => post('id_segment'),
|
||||
'id_tipo' => post('id_tipo'),
|
||||
'ref_fattura' => post('ref_fattura'),
|
||||
'data_registrazione' => post('data_registrazione'),
|
||||
'articoli' => post('articoli'),
|
||||
'iva' => post('iva'),
|
||||
|
@ -67,7 +68,8 @@ switch (filter('op')) {
|
|||
if ($process_result != '') {
|
||||
flash()->error($process_result);
|
||||
redirect(ROOTDIR.'/controller.php?id_module='.$id_module);
|
||||
exit;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,12 +65,12 @@ echo '
|
|||
</div>';
|
||||
|
||||
// Tipo del documento
|
||||
$query = 'SELECT id, CONCAT (descrizione, IF((codice_tipo_documento_fe IS NULL), \'\', CONCAT( \' (\', codice_tipo_documento_fe, \')\' ) )) as descrizione FROM co_tipidocumento WHERE dir = \'uscita\'';
|
||||
$query = 'SELECT id, CONCAT (descrizione, IF((codice_tipo_documento_fe IS NULL), \'\', CONCAT( \' (\', codice_tipo_documento_fe, \')\' ) )) AS descrizione FROM co_tipidocumento WHERE dir = \'uscita\'';
|
||||
if (database()->fetchNum('SELECT id FROM co_tipidocumento WHERE codice_tipo_documento_fe = '.prepare($dati_generali['TipoDocumento']))) {
|
||||
$query .= ' AND codice_tipo_documento_fe = '.prepare($dati_generali['TipoDocumento']);
|
||||
}
|
||||
echo '
|
||||
<div class="row" >
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Tipo fattura').'", "name": "id_tipo", "required": 1, "values": "query='.$query.'" ]}
|
||||
</div>';
|
||||
|
@ -87,7 +87,34 @@ echo '
|
|||
<div class="row" >
|
||||
<div class="col-md-6">
|
||||
{[ "type": "date", "label": "'.tr('Data ricezione').'", "name": "data_registrazione", "required": 0, "value": "" ]}
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
// Riferimenti ad altre fatture
|
||||
if (in_array($dati_generali['TipoDocumento'], ['TD04', 'TD05'])){
|
||||
$anagrafica = $fattura_pa->saveAnagrafica();
|
||||
$query = "SELECT
|
||||
co_documenti.id,
|
||||
CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
|
||||
FROM
|
||||
co_documenti INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
|
||||
WHERE
|
||||
co_tipidocumento.dir = 'uscita' AND
|
||||
co_documenti.idanagrafica = ".prepare($anagrafica->id);
|
||||
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "required": 1, "values": "query='.$query.'" ]}
|
||||
</div>';
|
||||
}elseif ($dati_generali['TipoDocumento'] == 'TD06'){
|
||||
$anagrafica = $fattura_pa->saveAnagrafica();
|
||||
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "values": "query='.$query.'" ]}
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
// Blocco DatiPagamento è valorizzato (opzionale)
|
||||
|
|
|
@ -178,12 +178,18 @@ class FatturaElettronica
|
|||
}
|
||||
|
||||
// Registrazione XML come allegato
|
||||
$filename = Uploads::upload($this->file, array_merge($info, [
|
||||
Uploads::upload($this->file, array_merge($info, [
|
||||
'name' => tr('Fattura Elettronica'),
|
||||
'original' => basename($this->file),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'anagrafica collegata alla fattura, eventualmente generandola con i dati forniti.
|
||||
*
|
||||
* @param string $type
|
||||
* @return Anagrafica
|
||||
*/
|
||||
public function saveAnagrafica($type = 'Fornitore')
|
||||
{
|
||||
$info = $this->getAnagrafe();
|
||||
|
@ -267,9 +273,15 @@ class FatturaElettronica
|
|||
/**
|
||||
* Registra la fattura elettronica come fattura del gestionale.
|
||||
*
|
||||
* @param int $id_pagamento
|
||||
* @param int $id_sezionale
|
||||
* @param int $id_tipo
|
||||
* @param string $data_registrazione
|
||||
* @param int $ref_fattura
|
||||
*
|
||||
* @return Fattura
|
||||
*/
|
||||
public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_registrazione)
|
||||
public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_registrazione, $ref_fattura = null)
|
||||
{
|
||||
$anagrafica = $this->saveAnagrafica();
|
||||
|
||||
|
@ -288,6 +300,9 @@ class FatturaElettronica
|
|||
$fattura->numero_esterno = $numero_esterno;
|
||||
$fattura->idpagamento = $id_pagamento;
|
||||
|
||||
// Riferimento per nota di credito e debito
|
||||
$fattura->ref_documento = $ref_fattura ?: null;
|
||||
|
||||
// Per il destinatario, la data di ricezione della fattura assume grande rilievo ai fini IVA, poiché determina la decorrenza dei termini per poter esercitare il diritto alla detrazione.
|
||||
// La data di ricezione della fattura è contenuta all’interno della “ricevuta di consegna” visibile al trasmittente della stessa.
|
||||
if (empty($data_registrazione)) {
|
||||
|
@ -336,7 +351,7 @@ class FatturaElettronica
|
|||
|
||||
public function save($info = [])
|
||||
{
|
||||
$this->saveFattura($info['id_pagamento'], $info['id_segment'], $info['id_tipo'], $info['data_registrazione']);
|
||||
$this->saveFattura($info['id_pagamento'], $info['id_segment'], $info['id_tipo'], $info['data_registrazione'], $info['ref_fattura']);
|
||||
|
||||
$this->saveRighe($info['articoli'], $info['iva'], $info['conto'], $info['movimentazione']);
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ class Interaction extends Services
|
|||
{
|
||||
public static function listToImport()
|
||||
{
|
||||
$directory = FatturaElettronica::getImportDirectory();
|
||||
|
||||
$list = [];
|
||||
$names = [];
|
||||
|
||||
|
@ -31,6 +29,8 @@ class Interaction extends Services
|
|||
}
|
||||
|
||||
// Ricerca fisica
|
||||
$directory = FatturaElettronica::getImportDirectory();
|
||||
|
||||
$files = glob($directory.'/*.xml*');
|
||||
foreach ($files as $file) {
|
||||
$name = basename($file);
|
||||
|
|
|
@ -52,13 +52,17 @@ class SelectHandler implements HandlerInterface
|
|||
}
|
||||
|
||||
// Gestione del select da query specifica (se il campo "values" è impostato a "query=SQL")
|
||||
elseif (preg_match_all('/^query=(.+?)$/', $values['values'], $matches)) {
|
||||
$result .= $this->selectQuery($matches[1][0], $values['value']);
|
||||
elseif (starts_with($values['values'], 'query=')) {
|
||||
$query = substr($values['values'], strlen('query='));
|
||||
|
||||
$result .= $this->selectQuery($query, $values['value']);
|
||||
}
|
||||
|
||||
// Gestione del select dal formato JSON parziale (valori singoli)
|
||||
elseif (preg_match_all('/^list=(.+?)$/', $values['values'], $matches)) {
|
||||
$result .= $this->selectList(json_decode('{'.$matches[1][0].'}', true), $values);
|
||||
elseif (starts_with($values['values'], 'list=')) {
|
||||
$list = substr($values['values'], strlen('list='));
|
||||
|
||||
$result .= $this->selectList(json_decode('{'.$list.'}', true), $values);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue