Skip to content
Merged
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
38 changes: 20 additions & 18 deletions Controller/EditLiquidacionComision.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected function generateInvoice(): bool
*/
protected function getInvoicesFromDataForm(array $data): array
{
if (!isset($data['code'])) {
if (false === isset($data['code'])) {
return [];
}

Expand All @@ -226,44 +226,44 @@ protected function getInvoicesFromDataForm(array $data): array
*
* @param array $data
*
* @return array[]
* @return DataBaseWhere[]
*/
protected function getInvoicesWhere(array $data): array
{
// Basic data filter
$where = [
Where::column('facturascli.idempresa', $data['idempresa']),
Where::column('facturascli.codserie', $data['codserie']),
Where::column('facturascli.codagente', $data['codagente'])
new DataBaseWhere('facturascli.idempresa', $data['idempresa']),
new DataBaseWhere('facturascli.codserie', $data['codserie']),
new DataBaseWhere('facturascli.codagente', $data['codagente']),
];

// Date filter
if (!empty($data['datefrom'])) {
$where[] = Where::column('facturascli.fecha', $data['datefrom'], '>=');
if (false === empty($data['datefrom'])) {
$where[] = new DataBaseWhere('facturascli.fecha', $data['datefrom'], '>=');
}
if (!empty($data['dateto'])) {
$where[] = Where::column('facturascli.fecha', $data['dateto'], '<=');
if (false === empty($data['dateto'])) {
$where[] = new DataBaseWhere('facturascli.fecha', $data['dateto'], '<=');
}

// Status payment filter
if ($data['status'] == self::INSERT_STATUS_CHARGED) {
$where[] = Where::column('facturascli.pagada', true);
if ($data['status'] === self::INSERT_STATUS_CHARGED) {
$where[] = new DataBaseWhere('facturascli.pagada', true);
}

// Payment source filter
switch ($data['domiciled']) {
case self::INSERT_DOMICILED_DOMICILED:
$where[] = Where::column('formaspago.domiciliado', true);
$where[] = new DataBaseWhere('formaspago.domiciliado', true);
break;

case self::INSERT_DOMICILED_WITHOUT:
$where[] = Where::column('formaspago.domiciliado', false);
$where[] = new DataBaseWhere('formaspago.domiciliado', false);
break;
}

// Customer filter
if (!empty($data['codcliente'])) {
$where[] = Where::column('facturascli.codcliente', $data['codcliente']);
if (false === empty($data['codcliente'])) {
$where[] = new DataBaseWhere('facturascli.codcliente', $data['codcliente']);
}

// Return completed filter
Expand All @@ -278,9 +278,11 @@ protected function insertInvoices(): bool
$data = $this->request->request->all();

// add new invoice to settlement commission
$where = $this->getInvoicesWhere($data);
$settleinvoice = new LiquidacionComisionFactura();
$settleinvoice->addInvoiceToSettle($data['idliquidacion'], $where);
$settleInvoice = new LiquidacionComisionFactura();
$settleInvoice->addInvoiceToSettle(
$data['idliquidacion'],
$this->getInvoicesWhere($data)
);

// update total to settlement commission
return $this->calculateTotalCommission();
Expand Down
23 changes: 18 additions & 5 deletions Model/Join/LiquidacionComisionFactura.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
namespace FacturaScripts\Plugins\Comisiones\Model\Join;

use Exception;
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Core\KernelException;
use FacturaScripts\Core\Model\Base\JoinModel;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Where;
use FacturaScripts\Dinamic\Model\FacturaCliente;

/**
Expand All @@ -35,6 +36,12 @@
*/
class LiquidacionComisionFactura extends JoinModel
{
/**
* Class constructor.
* Sets the master model to FacturaCliente.
*
* @param array $data
*/
public function __construct(array $data = [])
{
parent::__construct($data);
Expand All @@ -46,11 +53,12 @@ public function __construct(array $data = [])
* according to the where filter.
*
* @param int $settled
* @param array[] $where
* @param DataBaseWhere[] $where
* @throws KernelException
*/
public function addInvoiceToSettle($settled, $where): void
public function addInvoiceToSettle(int $settled, array $where): void
{
$where[] = Where::column('facturascli.idliquidacion', null, 'IS');
$where[] = new DataBaseWhere('facturascli.idliquidacion', null, 'IS');
$invoices = $this->all($where);
if (empty($invoices)) {
return;
Expand All @@ -74,6 +82,11 @@ public function addInvoiceToSettle($settled, $where): void
}
}

/**
* Remove the invoice from the settlement.
*
* @throws KernelException
*/
public function delete(): bool
{
$sql = 'UPDATE ' . FacturaCliente::tableName() . ' SET idliquidacion = NULL'
Expand All @@ -86,7 +99,7 @@ public function delete(): bool
*
* @return int
*/
public function primaryColumnValue()
public function primaryColumnValue(): int
{
return $this->idfactura;
}
Expand Down
4 changes: 2 additions & 2 deletions facturascripts.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = 'Comisiones'
description = 'Añade comisiones y liquidaciones a los agentes.'
version = 2.11
min_version = 2025.2
version = 2.12
min_version = 2025.5