Skip to content

Commit

Permalink
Merge 461963c into 5743816
Browse files Browse the repository at this point in the history
  • Loading branch information
elguitarraverde committed Apr 27, 2024
2 parents 5743816 + 461963c commit 65358eb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Core/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static function init(): void
WorkQueue::addWorker('CuentaWorker', 'Model.Subcuenta.Update');
WorkQueue::addWorker('PartidaWorker', 'Model.Partida.Delete');
WorkQueue::addWorker('PartidaWorker', 'Model.Partida.Save');
WorkQueue::addWorker('FacturaClienteWorker', 'Model.FacturaCliente.Update');

self::stopTimer('kernel::init');
}
Expand Down
8 changes: 8 additions & 0 deletions Core/Model/Cliente.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Cliente extends Base\ComercialContact
/** @var float */
public $riesgomax;

/** @var float */
public $totalfacturado;

/** @var float */
public $pdtepago;

public function checkVies(): bool
{
$codiso = Paises::get($this->getDefaultAddress()->codpais)->codiso ?? '';
Expand All @@ -73,6 +79,8 @@ public function checkVies(): bool
public function clear()
{
parent::clear();
$this->totalfacturado = 0.0;
$this->pdtepago = 0.0;
$this->codretencion = Tools::settings('default', 'codretencion');
}

Expand Down
10 changes: 9 additions & 1 deletion Core/Table/clientes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
<name>web</name>
<type>character varying(100)</type>
</column>
<column>
<name>totalfacturado</name>
<type>double precision</type>
</column>
<column>
<name>pdtepago</name>
<type>double precision</type>
</column>
<constraint>
<name>clientes_pkey</name>
<type>PRIMARY KEY (codcliente)</type>
Expand Down Expand Up @@ -159,4 +167,4 @@
<name>ca_clientes_tarifas</name>
<type>FOREIGN KEY (codtarifa) REFERENCES tarifas (codtarifa) ON DELETE SET NULL ON UPDATE CASCADE</type>
</constraint>
</table>
</table>
36 changes: 36 additions & 0 deletions Core/Worker/FacturaClienteWorker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);

namespace FacturaScripts\Core\Worker;

use FacturaScripts\Core\DbQuery;
use FacturaScripts\Core\Model\FacturaCliente;
use FacturaScripts\Core\Model\WorkEvent;
use FacturaScripts\Core\Template\WorkerClass;

class FacturaClienteWorker extends WorkerClass
{
public function run(WorkEvent $event):bool
{
$facturaCliente = new FacturaCliente();

if (false === $facturaCliente->loadFromCode($event->param($facturaCliente::primaryColumn()))) {
return $this->done();
}

$totalInvoiced = DbQuery::table($facturaCliente::tableName())
->whereEq('codcliente', $facturaCliente->codcliente)
->sum('total', 2);

$totalToBePaid = DbQuery::table($facturaCliente::tableName())
->whereEq('codcliente', $facturaCliente->codcliente)
->whereEq('pagada', 0)
->sum('total', 2);

$cliente = $facturaCliente->getSubject();
$cliente->totalfacturado = $totalInvoiced;
$cliente->pdtepago = $totalToBePaid;
$cliente->save();

return $this->done();
}
}
6 changes: 6 additions & 0 deletions Core/XMLView/ListCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<column name="observations" order="190">
<widget type="textarea" fieldname="observaciones" />
</column>
<column name="totalfacturado" order="191">
<widget type="money" fieldname="totalfacturado" />
</column>
<column name="pdtepago" order="192">
<widget type="money" fieldname="pdtepago" />
</column>
<column name="current-risk" display="none" order="200">
<widget type="money" fieldname="riesgoalcanzado" />
</column>
Expand Down

0 comments on commit 65358eb

Please sign in to comment.