-
+
-
+
{[ "type": "date", "label": "'.tr('Data del documento').'", "name": "data", "required": 1, "value": "-now-" ]}
';
@@ -65,7 +65,7 @@ if (!empty($options['create_document'])) {
{[ "type": "select", "label": "'.tr('Ritenuta contributi').'", "name": "id_ritenuta_contributi", "value": "$id_ritenuta_contributi$", "values": "query=SELECT * FROM co_ritenuta_contributi" ]}
-
+
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare($final_module['id']).' ORDER BY name", "value": "'.$id_segment.'" ]}
';
@@ -161,7 +161,7 @@ if (in_array($final_module['name'], ['Fatture di vendita', 'Fatture di acquisto'
-
+
'.tr('Descrizione').' |
@@ -213,7 +213,7 @@ foreach ($righe as $i => $r) {
echo '
'.moneyFormat($r->totale).'
-
+
'.Translator::numberToLocale($r->totale_imponibile).' + '.Translator::numberToLocale($r->iva).'
| ';
diff --git a/include/src/Components/MorphTrait.php b/include/src/Components/MorphTrait.php
index 88df1408e..6c83039e5 100644
--- a/include/src/Components/MorphTrait.php
+++ b/include/src/Components/MorphTrait.php
@@ -4,18 +4,21 @@ namespace Common\Components;
trait MorphTrait
{
+ protected $original_model = null;
+
public function hasOriginal()
{
return !empty($this->original_type) && !empty($this->getOriginal());
}
- public function original()
- {
- return $this->morphedByMany($this->original_type, 'original', $this->table, 'id');
- }
-
public function getOriginal()
{
- return $this->original()->first();
+ if(!isset($this->original_model) && !empty($this->original_type)) {
+ $class = $this->original_type;
+
+ $this->original_model = $class::find($this->original_id);
+ }
+
+ return $this->original_model;
}
}
diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php
index cd203e712..cecb11d74 100644
--- a/modules/fatture/actions.php
+++ b/modules/fatture/actions.php
@@ -636,6 +636,9 @@ switch (post('op')) {
// Nota di credito
case 'nota_credito':
+ $id_documento = post('id_documento');
+ $fattura = Fattura::find($id_documento);
+
$id_segment = post('id_segment');
$data = post('data');
diff --git a/modules/fatture/crea_documento.php b/modules/fatture/crea_documento.php
index 10b1ee359..3fc6a3404 100644
--- a/modules/fatture/crea_documento.php
+++ b/modules/fatture/crea_documento.php
@@ -2,31 +2,18 @@
include_once __DIR__.'/../../core.php';
-$module = Modules::get($id_module);
+use Modules\Fatture\Fattura;
+
+$documento = Fattura::find($id_record);
$options = [
+ 'type' => 'nota_credito',
'op' => 'nota_credito',
- 'id_importazione' => 'id_documento',
- 'final_module' => $module['name'],
- 'original_module' => $module['name'],
- 'sql' => [
- 'table' => 'co_documenti',
- 'rows' => 'co_righe_documenti',
- 'id_rows' => 'iddocumento',
- ],
- 'serials' => [
- 'id_riga' => 'id_riga_documento',
- 'condition' => '(1 = 2)',
- ],
+ 'module' => 'Fatture di vendita',
+ 'documento' => $documento,
'button' => tr('Aggiungi'),
- 'dir' => $dir,
'create_document' => true,
'allow-empty' => true,
];
-$result = [
- 'id_record' => $id_record,
- 'id_documento' => get('iddocumento'),
-];
-
-echo App::load('importa.php', $result, $options, true);
+echo App::load('importa.php', [], $options, true);