|
28 | 28 | use FacturaScripts\Core\Where; |
29 | 29 | use FacturaScripts\Core\WorkQueue; |
30 | 30 | use FacturaScripts\Dinamic\Lib\Import\CSVImport; |
| 31 | +use FacturaScripts\Dinamic\Lib\ReceiptGenerator; |
31 | 32 | use FacturaScripts\Dinamic\Model\AlbaranCliente; |
32 | 33 | use FacturaScripts\Dinamic\Model\AlbaranProveedor; |
33 | 34 | use FacturaScripts\Dinamic\Model\AttachedFileRelation; |
@@ -278,6 +279,12 @@ protected function runCoreJobs(): void |
278 | 279 | ->run(function () { |
279 | 280 | $this->restoreNotifications(); |
280 | 281 | }); |
| 282 | + |
| 283 | + $this->job('update-unpaid-invoices') |
| 284 | + ->everyDayAt(6) |
| 285 | + ->run(function () { |
| 286 | + $this->updateUnpaidInvoices(); |
| 287 | + }); |
281 | 288 | } |
282 | 289 |
|
283 | 290 | protected function runPlugins(): void |
@@ -454,4 +461,24 @@ protected function updateReceipts(): void |
454 | 461 | $recibo->save(); |
455 | 462 | } |
456 | 463 | } |
| 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 | + } |
457 | 484 | } |
0 commit comments