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
35 changes: 35 additions & 0 deletions Extension/Controller/Randomizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* This file is part of Comisiones plugin for FacturaScripts.
* Copyright (C) 2026 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace FacturaScripts\Plugins\Comisiones\Extension\Controller;

use Closure;

/**
* @author Esteban Sánchez Martínez <Esteban@factura.city>
*/
class Randomizer
{
protected function loadButtons(): Closure
{
return function () {
$this->addButton('sales', 'comisiones', 'generated-commissions', 'commissions', 'fa-solid fa-percentage', 'Random\\Comisiones', 'Comision');
};
}
}
6 changes: 5 additions & 1 deletion Init.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* This file is part of Comisiones plugin for FacturaScripts.
* Copyright (C) 2022-2025 Carlos Garcia Gomez <carlos@facturascripts.com>
* Copyright (C) 2022-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -49,6 +49,10 @@ public function init(): void
SalesLineHTML::addMod(new Mod\SalesLineHTMLMod());

TransformerDocument::addUnlockedField('totalcomision');

if (class_exists('FacturaScripts\\Dinamic\\Controller\\Randomizer')) {
$this->loadExtension(new Extension\Controller\Randomizer());
}
}

public function uninstall(): void
Expand Down
56 changes: 56 additions & 0 deletions Lib/Random/Comisiones.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* This file is part of Comisiones plugin for FacturaScripts.
* Copyright (C) 2026 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace FacturaScripts\Plugins\Comisiones\Lib\Random;

use FacturaScripts\Plugins\Comisiones\Model\Comision;
use FacturaScripts\Plugins\Randomizer\Lib\Random\NewItems;
use Faker;

/**
* @author Esteban Sánchez Martínez <Esteban@factura.city>
*/
class Comisiones extends NewItems
{
public static function create(int $number = 50): int
{
$faker = Faker\Factory::create('es_ES');

for ($generated = 0; $generated < $number; $generated++) {
$comision = new Comision();
$comision->codagente = static::codagente();
$comision->codcliente = static::codcliente();
$comision->codfamilia = static::codfamilia();
$comision->idempresa = static::idempresa();
$comision->idproducto = static::idproducto();
$comision->porcentaje = $faker->numberBetween(1, 30);
$comision->prioridad = $faker->optional(0.1)->numberBetween(1, 10);

if ($comision->exists()) {
continue;
}

if (false === $comision->save()) {
break;
}
}

return $generated;
}
}
3 changes: 2 additions & 1 deletion Translation/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"total-position": "Posición del Total",
"until-dto": "Hasta descuento",
"until-penalty-info": "Fin del rango del descuento al que se aplica la penalización. '100' indica máximo del rango",
"edit-commission": "Editar Comisión"
"edit-commission": "Editar Comisión",
"generated-commissions": "Comisiones generadas: %quantity%"
}
Loading