Skip to content

Commit 676759c

Browse files
committed
Corregido el cálculo de total pendiente de facturar.
1 parent 82844df commit 676759c

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

Lib/ProjectTotalManager.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of Proyectos plugin for FacturaScripts
4-
* Copyright (C) 2022-2023 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2022-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -26,6 +26,7 @@
2626
use FacturaScripts\Dinamic\Model\FacturaProveedor;
2727
use FacturaScripts\Dinamic\Model\PedidoCliente;
2828
use FacturaScripts\Dinamic\Model\PedidoProveedor;
29+
use FacturaScripts\Dinamic\Model\PresupuestoCliente;
2930
use FacturaScripts\Plugins\Proyectos\Model\Proyecto;
3031

3132
/**
@@ -53,10 +54,15 @@ public static function recalculate(int $idproyecto)
5354
$project->totalcompras += $order->total;
5455
}
5556

57+
$netoPresupuestos = 0.0;
5658
$netoPedidos = 0.0;
5759
$netoAlbaranes = 0.0;
5860
$netoFacturas = 0.0;
5961
$project->totalventas = 0.0;
62+
foreach (static::salesEstimations($idproyecto) as $estimation) {
63+
$project->totalventas += $estimation->total;
64+
$netoPresupuestos += $estimation->neto;
65+
}
6066
foreach (static::salesInvoices($idproyecto) as $invoice) {
6167
$project->totalventas += $invoice->total;
6268
$netoFacturas += $invoice->neto;
@@ -70,21 +76,20 @@ public static function recalculate(int $idproyecto)
7076
$netoPedidos += $order->neto;
7177
}
7278

73-
$project->totalpendientefacturar = ($netoPedidos + $netoAlbaranes) - $netoFacturas;
79+
$project->totalpendientefacturar = ($netoPresupuestos + $netoPedidos + $netoAlbaranes) - $netoFacturas;
7480
if ($project->totalpendientefacturar < 0) {
7581
$project->totalpendientefacturar = 0;
7682
}
77-
83+
7884
$project->save();
7985
}
8086

8187
/**
82-
*
8388
* @param int $idproyecto
8489
*
8590
* @return AlbaranProveedor[]
8691
*/
87-
protected static function purchaseDeliveryNotes($idproyecto)
92+
protected static function purchaseDeliveryNotes($idproyecto): array
8893
{
8994
$delivery = new AlbaranProveedor();
9095
$where = [
@@ -94,13 +99,21 @@ protected static function purchaseDeliveryNotes($idproyecto)
9499
return $delivery->all($where, [], 0, 0);
95100
}
96101

102+
/**
103+
* @param int $idproyecto
104+
* @return FacturaProveedor[]
105+
*/
97106
protected static function purchaseInvoices(int $idproyecto): array
98107
{
99108
$invoice = new FacturaProveedor();
100109
$where = [new DataBaseWhere('idproyecto', $idproyecto)];
101110
return $invoice->all($where, [], 0, 0);
102111
}
103112

113+
/**
114+
* @param int $idproyecto
115+
* @return PedidoProveedor[]
116+
*/
104117
protected static function purchaseOrders(int $idproyecto): array
105118
{
106119
$order = new PedidoProveedor();
@@ -111,6 +124,10 @@ protected static function purchaseOrders(int $idproyecto): array
111124
return $order->all($where, [], 0, 0);
112125
}
113126

127+
/**
128+
* @param int $idproyecto
129+
* @return AlbaranCliente[]
130+
*/
114131
protected static function salesDeliveryNotes(int $idproyecto): array
115132
{
116133
$delivery = new AlbaranCliente();
@@ -121,13 +138,32 @@ protected static function salesDeliveryNotes(int $idproyecto): array
121138
return $delivery->all($where, [], 0, 0);
122139
}
123140

141+
/**
142+
* @param int $idproyecto
143+
* @return PresupuestoCliente[]
144+
*/
145+
protected static function salesEstimations(int $idproyecto): array
146+
{
147+
$estimation = new PresupuestoCliente();
148+
$where = [new DataBaseWhere('idproyecto', $idproyecto)];
149+
return $estimation->all($where, [], 0, 0);
150+
}
151+
152+
/**
153+
* @param int $idproyecto
154+
* @return FacturaCliente[]
155+
*/
124156
protected static function salesInvoices(int $idproyecto): array
125157
{
126158
$invoice = new FacturaCliente();
127159
$where = [new DataBaseWhere('idproyecto', $idproyecto)];
128160
return $invoice->all($where, [], 0, 0);
129161
}
130162

163+
/**
164+
* @param int $idproyecto
165+
* @return PedidoCliente[]
166+
*/
131167
protected static function salesOrders(int $idproyecto): array
132168
{
133169
$order = new PedidoCliente();

facturascripts.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name = 'Proyectos'
22
description = 'Permite gestionar proyectos, tareas, vincular usuarios, documentos de compra y de venta.'
3-
version = 3.9
4-
min_version = 2023.08
3+
version = 3.91
4+
min_version = 2023.1

0 commit comments

Comments
 (0)