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
5 changes: 3 additions & 2 deletions Controller/EditLiquidacionComision.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ protected function execPreviousAction($action)
*/
protected function generateInvoice(): bool
{
if ($this->views[$this->getMainViewName()]->model->generateInvoice()) {
$model = $this->getModel();
if ($model->generateInvoice()) {
Tools::log()->notice('record-updated-correctly');

// redireccionamos a la factura
$invoice = new FacturaProveedor();
if ($invoice->load($this->views[$this->getMainViewName()]->model->idfactura)) {
if ($invoice->load($model->idfactura)) {
$this->redirect($invoice->url() . '&action=save-ok');
}

Expand Down
4 changes: 2 additions & 2 deletions Extension/XMLView/EditAlbaranCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
Expand All @@ -27,4 +27,4 @@
</column>
</group>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/EditFacturaCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
Expand All @@ -27,4 +27,4 @@
</column>
</group>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/EditPedidoCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
Expand All @@ -27,4 +27,4 @@
</column>
</group>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/EditPresupuestoCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
Expand All @@ -27,4 +27,4 @@
</column>
</group>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/ListAlbaranCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
<column name="commission" display="none" order="351">
<widget type="money" fieldname="totalcomision" />
</column>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/ListFacturaCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
Expand All @@ -28,4 +28,4 @@
<widget type="text" fieldname="idliquidacion" onclick="EditLiquidacionComision"/>
</column>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/ListPedidoCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
<column name="commission" display="none" order="351">
<widget type="money" fieldname="totalcomision" />
</column>
</columns>
</view>
</view>
4 changes: 2 additions & 2 deletions Extension/XMLView/ListPresupuestoCliente.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Fco. Antonio Moreno Pérez <famphuelva@gmail.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
<column name="commission" display="none" order="351">
<widget type="money" fieldname="totalcomision" />
</column>
</columns>
</view>
</view>
33 changes: 33 additions & 0 deletions Extension/XMLView/SettingsDefault.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of Comisiones plugin for FacturaScripts
* Copyright (C) 2022-2025 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/>.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
-->
<view>
<columns>
<group name="commissions" title="commissions" icon="fa-solid fa-percentage" valign="bottom" numcolumns="12">
<column name="comission-position" title="total-position" numcolumns="3" order="110">
<widget type="select" fieldname="comissionposition" required="true" translate="true">
<values title="show-into-modal">modal</values>
<values title="show-into-footer">footer</values>
</widget>
</column>
</group>
</columns>
</view>
3 changes: 3 additions & 0 deletions Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use FacturaScripts\Core\Lib\Calculator;
use FacturaScripts\Core\Model\Base\TransformerDocument;
use FacturaScripts\Core\Template\InitClass;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Model\Cliente;
use FacturaScripts\Plugins\Comisiones\Model\LiquidacionComision;

Expand Down Expand Up @@ -56,5 +57,7 @@ public function update(): void
{
new Cliente();
new LiquidacionComision();
Tools::settings('default', 'comissionposition', 'modal');
Tools::settingsSave();
}
}
32 changes: 23 additions & 9 deletions Mod/CalculatorMod.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace FacturaScripts\Plugins\Comisiones\Mod;

use Exception;
use FacturaScripts\Core\Contract\CalculatorModInterface;
use FacturaScripts\Core\Model\Base\BusinessDocument;
use FacturaScripts\Core\Model\Base\BusinessDocumentLine;
Expand Down Expand Up @@ -176,13 +177,13 @@ protected function getPenalty(float $discount): float

protected function isValidCommissionForDoc(Comision $commission, string $codagente, string $codcliente): bool
{
// comprobamos el agente
if (!empty($commission->codagente) && $commission->codagente != $codagente) {
// comprobamos el agente si la comision tiene uno asignado
if (false === empty($commission->codagente) && $commission->codagente != $codagente) {
return false;
}

// comprobamos el cliente
if (!empty($commission->codcliente) && $commission->codcliente != $codcliente) {
// comprobamos el cliente si la comision tiene uno asignado
if (false === empty($commission->codcliente) && $commission->codcliente != $codcliente) {
return false;
}

Expand All @@ -204,14 +205,23 @@ protected function isValidCommissionForLine(SalesDocumentLine &$line, Producto $
return true;
}

/**
* @throws Exception
*/
protected function loadCommissions(int $idempresa, ?string $codagente, string $codcliente): void
{
$this->commissions = [];
if (empty($codagente)) {
return;
}

$where = [Where::eq('idempresa', $idempresa)];
$where = [
Where::column('idempresa', $idempresa),
Where::sub([
Where::column('codagente', $codagente),
Where::column('codagente', null, 'IS', 'OR'),
]),
];
foreach (Comision::all($where, ['prioridad' => 'DESC']) as $comm) {
if ($this->isValidCommissionForDoc($comm, $codagente, $codcliente)) {
$this->commissions[] = $comm;
Expand All @@ -227,14 +237,18 @@ protected function loadPenalties(int $idempresa, ?string $codagente): void
}

$where = [
Where::eq('codagente', $codagente),
Where::sub([
Where::eq('idempresa', $idempresa),
Where::orIsNull('idempresa')
])
Where::column('codagente', $codagente),
Where::column('codagente', null, 'IS', 'OR'),
]),
Where::sub([
Where::column('idempresa', $idempresa),
Where::column('idempresa', null, 'IS', 'OR'),
]),
];
$order = [
'COALESCE(idempresa, 9999999)' => 'ASC',
'COALESCE(codagente, \'zzzzzz\')' => 'ASC',
'dto_desde' => 'ASC'
];
foreach (ComisionPenalizacion::all($where, $order) as $penalty) {
Expand Down
16 changes: 10 additions & 6 deletions Mod/SalesFooterHTMLMod.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ public function newBtnFields(): array

public function newFields(): array
{
return [];
return Tools::settings('default', 'comissionposition', 'modal') === 'footer'
? ['totalcomision']
: [];
}

public function newModalFields(): array
{
return ['totalcomision'];
return Tools::settings('default', 'comissionposition', 'modal') === 'modal'
? ['totalcomision']
: [];
}

public function renderField(SalesDocument $model, string $field): ?string
Expand All @@ -67,13 +71,13 @@ private function totalcomision(SalesDocument $model): string
return '';
}

return '<div class="col-sm-3">'
return '<div class="col-sm-6 col-md-4 col-lg">'
. '<div class="mb-3">'
. Tools::trans('commission')
. '<input type="text" name="totalcomision" class="form-control text-end" disabled'
. ' value="' . Tools::money($model->totalcomision, $model->coddivisa, 2) . '"'
. '<input type="text" name="totalcomision" class="form-control" disabled'
. ' value="' . Tools::money($model->totalcomision, $model->coddivisa, 2) . '"'
. '/>'
. '</div>'
. '</div>';
. '</div>';
}
}
3 changes: 1 addition & 2 deletions Table/comisionespenalizaciones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<column>
<name>codagente</name>
<type>character varying(10)</type>
<null>NO</null>
</column>
<column>
<name>idempresa</name>
Expand Down Expand Up @@ -46,4 +45,4 @@
<name>ca_comisionespenalizaciones_empresas</name>
<type>FOREIGN KEY (idempresa) REFERENCES empresas (idempresa) ON DELETE SET NULL ON UPDATE CASCADE</type>
</constraint>
</table>
</table>
3 changes: 3 additions & 0 deletions Translation/ca_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Si en fer una venda un agent fa un descompte és possible penalitzar la comissió que rebrà per la venda. Mitjançant aquesta relació de percentatges, <b>es resta<\/b> de la comissió <b>la penalització<\/b> segons el des de\/fins on es trobi el descompte aplicat pel comercial a la venda.<br><br> ><b>Per exemple:<\/b><br>Si tenim un registre que estableix un <i>Des de<\/i> 1 i un <i>Fins<\/i> 20, si l'agent fa un descompte al client d'un 15% ja que se li restarà de la comissió el valor que introduïm a <i>Penalització<\/i>",
"penalty-help-title": "Penalització per fer descomptes",
"penalty-penalty-info": "Percentatge que resta al percentatge de comissió sobre la venda. (Introduir un valor positiu)",
"show-into-footer": "Mostrar en peu de document",
"show-into-modal": "Mostrar en finestra auxiliar",
"total-position": "Posició del Total",
"until-dto": "Fins a descompte",
"until-penalty-info": "Fi del rang del descompte a què s'aplica la penalització. '100' indica màxim del rang"
}
3 changes: 3 additions & 0 deletions Translation/cs_CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Si al realizar una venta un agente hace un descuento es posible penalizar la comisión que recibirá por la venta. Mediante esta relación de porcentajes, <b>se resta<\/b> de la comisión <b>la penalización<\/b> según el desde\/hasta donde se encuentre el descuento aplicado por el comercial en la venta.<br><br><b>Por ejemplo:<\/b><br>Si tenemos un registro que establece un <i>Desde<\/i> 1 y un <i>Hasta<\/i> 20, si el agente hace un descuento al cliente de un 15% pues se le restará de la comisión el valor que introduzcamos en <i>Penalización<\/i>",
"penalty-help-title": "Penalización por hacer descuentos",
"penalty-penalty-info": "Porcentaje que se resta al porcentaje de comisión sobre la venta. (Introducir un valor positivo)",
"show-into-footer": "Mostrar en pie de documento",
"show-into-modal": "Mostrar en ventana auxiliar",
"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"
}
3 changes: 3 additions & 0 deletions Translation/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Wenn ein Agent beim Verkauf einen Rabatt gewährt, kann die Provision, die er für den Verkauf erhält, bestraft werden. Durch diese Prozentsatzbeziehung wird <b>von der Provision<\/b> <b>die Strafe<\/b> abgezogen, je nachdem, wo sich der Rabatt befindet, den der Verkaufsträger im Verkauf gewährt hat.<br><br><b>Zum Beispiel:<\/b><br>Wenn wir einen Datensatz haben, der einen <i>Von<\/i> 1 und einen <i>Bis<\/i> 20 festlegt, wird dem Agenten 15 % Rabatt vom Kunden von der Provision der Wert abgezogen, den wir in <i>Strafe<\/i> eingeben.",
"penalty-help-title": "Strafe für Rabatte",
"penalty-penalty-info": "Prozentsatz, der vom Verkaufsprovisionssatz abgezogen wird. (Positiven Wert eingeben)",
"show-into-footer": "Mostrar en pie de documento",
"show-into-modal": "Mostrar en ventana auxiliar",
"total-position": "Posición del Total",
"until-dto": "Bis Rabatt",
"until-penalty-info": "Ende des Rabattranges, auf den die Strafe angewendet wird. '100' zeigt das Maximum des Bereichs an"
}
3 changes: 3 additions & 0 deletions Translation/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "If an agent makes a discount when making a sale, it is possible to penalize the commission that he will receive for the sale. Through this ratio of percentages, <b>the penalty is subtracted<\/b> from the commission depending on the from\/to where the discount applied by the salesperson of the sale.<br><br ><b>For example:<\/b><br>If we have a record that sets a <i>From<\/i> 1 and a <i>To<\/i> 20, if the agent makes a discount to the customer of 15% the value that we enter in <i>Penalty<\/i> will be subtracted from the commission",
"penalty-help-title": "Penalty for making discounts",
"penalty-penalty-info": "Percentage that is subtracted from the commission percentage on the sale. (Enter a positive value)",
"show-into-footer": "Show in document footer",
"show-into-modal": "Show in auxiliary window",
"total-position": "Position of the Total",
"until-dto": "Until discount",
"until-penalty-info": "End of the range of the discount to which the penalty is applied. '100' indicates maximum range"
}
3 changes: 3 additions & 0 deletions Translation/es_AR.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Si al realizar una venta un agente hace un descuento es posible penalizar la comisión que recibirá por la venta. Mediante esta relación de porcentajes, <b>se resta<\/b> de la comisión <b>la penalización<\/b> según el desde\/hasta donde se encuentre el descuento aplicado por el comercial en la venta.<br><br><b>Por ejemplo:<\/b><br>Si tenemos un registro que establece un <i>Desde<\/i> 1 y un <i>Hasta<\/i> 20, si el agente hace un descuento al cliente de un 15% pues se le restará de la comisión el valor que introduzcamos en <i>Penalización<\/i>",
"penalty-help-title": "Penalización por hacer descuentos",
"penalty-penalty-info": "Porcentaje que se resta al porcentaje de comisión sobre la venta. (Introducir un valor positivo)",
"show-into-footer": "Mostrar en pie de documento",
"show-into-modal": "Mostrar en ventana auxiliar",
"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"
}
3 changes: 3 additions & 0 deletions Translation/es_CL.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Si al realizar una venta un agente hace un descuento es posible penalizar la comisión que recibirá por la venta. Mediante esta relación de porcentajes, <b>se resta<\/b> de la comisión <b>la penalización<\/b> según el desde\/hasta donde se encuentre el descuento aplicado por el comercial en la venta.<br><br><b>Por ejemplo:<\/b><br>Si tenemos un registro que establece un <i>Desde<\/i> 1 y un <i>Hasta<\/i> 20, si el agente hace un descuento al cliente de un 15% pues se le restará de la comisión el valor que introduzcamos en <i>Penalización<\/i>",
"penalty-help-title": "Penalización por hacer descuentos",
"penalty-penalty-info": "Porcentaje que se resta al porcentaje de comisión sobre la venta. (Introducir un valor positivo)",
"show-into-footer": "Mostrar en pie de documento",
"show-into-modal": "Mostrar en ventana auxiliar",
"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"
}
3 changes: 3 additions & 0 deletions Translation/es_CO.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"penalty-help-info": "Si al realizar una venta un agente hace un descuento es posible penalizar la comisión que recibirá por la venta. Mediante esta relación de porcentajes, <b>se resta<\/b> de la comisión <b>la penalización<\/b> según el desde\/hasta donde se encuentre el descuento aplicado por el comercial en la venta.<br><br><b>Por ejemplo:<\/b><br>Si tenemos un registro que establece un <i>Desde<\/i> 1 y un <i>Hasta<\/i> 20, si el agente hace un descuento al cliente de un 15% pues se le restará de la comisión el valor que introduzcamos en <i>Penalización<\/i>",
"penalty-help-title": "Penalización por hacer descuentos",
"penalty-penalty-info": "Porcentaje que se resta al porcentaje de comisión sobre la venta. (Introducir un valor positivo)",
"show-into-footer": "Mostrar en pie de documento",
"show-into-modal": "Mostrar en ventana auxiliar",
"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"
}
Loading