Skip to content

Commit d890930

Browse files
NeoRazorXclaude
andcommitted
Añadido cron update-unpaid-invoices para recalcular facturas impagadas cuyos recibos ya están pagados
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 75bc788 commit d890930

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Core/Controller/Cron.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use FacturaScripts\Core\Where;
2929
use FacturaScripts\Core\WorkQueue;
3030
use FacturaScripts\Dinamic\Lib\Import\CSVImport;
31+
use FacturaScripts\Dinamic\Lib\ReceiptGenerator;
3132
use FacturaScripts\Dinamic\Model\AlbaranCliente;
3233
use FacturaScripts\Dinamic\Model\AlbaranProveedor;
3334
use FacturaScripts\Dinamic\Model\AttachedFileRelation;
@@ -278,6 +279,12 @@ protected function runCoreJobs(): void
278279
->run(function () {
279280
$this->restoreNotifications();
280281
});
282+
283+
$this->job('update-unpaid-invoices')
284+
->everyDayAt(6)
285+
->run(function () {
286+
$this->updateUnpaidInvoices();
287+
});
281288
}
282289

283290
protected function runPlugins(): void
@@ -454,4 +461,24 @@ protected function updateReceipts(): void
454461
$recibo->save();
455462
}
456463
}
464+
465+
protected function updateUnpaidInvoices(): void
466+
{
467+
echo PHP_EOL . PHP_EOL . Tools::trans('updating-unpaid-invoices') . ' ... ';
468+
ob_flush();
469+
470+
$generator = new ReceiptGenerator();
471+
$where = [Where::eq('pagada', false)];
472+
$orderBy = ['fecha' => 'DESC'];
473+
474+
// recorremos las facturas de cliente impagadas
475+
foreach (FacturaCliente::all($where, $orderBy, 0, 500) as $factura) {
476+
$generator->update($factura);
477+
}
478+
479+
// recorremos las facturas de proveedor impagadas
480+
foreach (FacturaProveedor::all($where, $orderBy, 0, 500) as $factura) {
481+
$generator->update($factura);
482+
}
483+
}
457484
}

0 commit comments

Comments
 (0)