Fix creazione nota di credito

This commit is contained in:
Thomas Zilio 2019-12-13 15:56:52 +01:00
parent 3de31bbec4
commit 4c30f237fd
4 changed files with 26 additions and 33 deletions

View File

@ -28,11 +28,11 @@ if (empty($righe)) {
$link = !empty($documento_finale) ? ROOTDIR.'/editor.php?id_module='.$final_module['id'].'&id_record='.$documento_finale->id : ROOTDIR.'/controller.php?id_module='.$final_module['id'];
echo '
<form action="'.$link.'" method="post">
<input type="hidden" name="op" value="'.$options['op'].'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_documento" value="'.$documento->id.'">
<input type="hidden" name="type" value="'.$options['type'].'">';
@ -44,10 +44,10 @@ if (!empty($options['create_document'])) {
<h3 class="box-title">'.tr('Nuovo documento').'</h3>
</div>
<div class="box-body">
<div class="row">
<input type="hidden" name="create_document" value="on" />
<div class="col-md-6">
{[ "type": "date", "label": "'.tr('Data del documento').'", "name": "data", "required": 1, "value": "-now-" ]}
</div>';
@ -65,7 +65,7 @@ if (!empty($options['create_document'])) {
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Ritenuta contributi').'", "name": "id_ritenuta_contributi", "value": "$id_ritenuta_contributi$", "values": "query=SELECT * FROM co_ritenuta_contributi" ]}
</div>
<div class="col-md-12">
{[ "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.'" ]}
</div>';
@ -161,7 +161,7 @@ if (in_array($final_module['name'], ['Fatture di vendita', 'Fatture di acquisto'
<div class="box-header with-border">
<h3 class="box-title">'.tr('Righe da importare').'</h3>
</div>
<table class="box-body table table-striped table-hover table-condensed">
<tr>
<th>'.tr('Descrizione').'</th>
@ -213,7 +213,7 @@ foreach ($righe as $i => $r) {
echo '
<td>
<big id="subtotale_'.$i.'">'.moneyFormat($r->totale).'</big><br/>
<small style="color:#777;" id="subtotaledettagli_'.$i.'">'.Translator::numberToLocale($r->totale_imponibile).' + '.Translator::numberToLocale($r->iva).'</small>
</td>';

View File

@ -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;
}
}

View File

@ -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');

View File

@ -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);