Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Controller/Modelo111.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use FacturaScripts\Core\Base\Controller;
use FacturaScripts\Core\DataSrc\Ejercicios;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Lib\ExportManager;
use FacturaScripts\Dinamic\Lib\Modelo111 as LibModelo111;
use FacturaScripts\Dinamic\Model\Empresa;

Expand Down Expand Up @@ -92,10 +93,90 @@ public function privateCore(&$response, $user, $permissions)
$this->ingresosPeriodoAnterior
);

$totalDebe = 0.0;
$totalHaber = 0.0;
foreach ($this->result['entryLines'] ?? [] as $line) {
$totalDebe += $line->debe;
$totalHaber += $line->haber;
}
$this->result['totalDebe'] = $totalDebe;
$this->result['totalHaber'] = $totalHaber;

$action = $this->request->inputOrQuery('action', '');
if ($action === 'download') {
$this->downloadFile($response);
} elseif ($action === 'print') {
$this->printAction();
}
}

protected function printAction(): void
{
if (empty($this->result)) {
return;
}

$this->setTemplate(false);

$exportManager = new ExportManager();
$exportManager->newDoc('PDF', Tools::trans('model-111-190'));

// resumen — las claves de las filas deben coincidir con los headers
$recipients = Tools::trans('number-recipients');
$base = Tools::trans('withholding-base');
$withholdings = Tools::trans('withholdings-made');
$previous = Tools::trans('previous-period-income');
$total = Tools::trans('total-to-enter');

$exportManager->addTablePage(
[$recipients, $base, $withholdings, $previous, $total],
[[
$recipients => $this->result['numRecipients'],
$base => Tools::money($this->result['baseRetenciones']),
$withholdings => Tools::money($this->result['retencionesPracticadas']),
$previous => Tools::money($this->result['ingresosPeriodoAnterior']),
$total => Tools::money($this->result['totalIngresar']),
]]
);

// asientos contables
if (!empty($this->result['entryLines'])) {
$entry = Tools::trans('accounting-entry');
$subaccount = Tools::trans('subaccount');
$counterpart = Tools::trans('counterpart');
$concept = Tools::trans('concept');
$debit = Tools::trans('debit');
$credit = Tools::trans('credit');
$date = Tools::trans('date');

$entryRows = [];
foreach ($this->result['entryLines'] as $line) {
$entryRows[] = [
$entry => $line->numero,
$subaccount => $line->codsubcuenta,
$counterpart => $line->codcontrapartida,
$concept => $line->concepto,
$debit => Tools::money($line->debe),
$credit => Tools::money($line->haber),
$date => $line->fecha,
];
}
$entryRows[] = [
$entry => '',
$subaccount => '',
$counterpart => '',
$concept => Tools::trans('total'),
$debit => Tools::money($this->result['totalDebe']),
$credit => Tools::money($this->result['totalHaber']),
$date => '',
];
$exportManager->addTablePage(
[$entry, $subaccount, $counterpart, $concept, $debit, $credit, $date],
$entryRows
);
}

$exportManager->show($this->response);
}

protected function getCurrentPeriod(): string
Expand Down
12 changes: 12 additions & 0 deletions View/Modelo111.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<button type="submit" name="action" value="download" class="btn btn-success ms-2">
<i class="fa-solid fa-download me-1"></i> {{ trans('download') }}
</button>
<button type="submit" name="action" value="print" formtarget="_blank"
class="btn btn-secondary ms-2">
<i class="fa-solid fa-print me-1"></i> {{ trans('print') }}
</button>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -221,6 +225,14 @@
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="table-active fw-bold">
<td colspan="4">{{ trans('total') }}</td>
<td class="text-end">{{ money(fsc.result.totalDebe) }}</td>
<td class="text-end">{{ money(fsc.result.totalHaber) }}</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
Expand Down