forked from nathalie/pedi2
Nuevos metodos de totales
This commit is contained in:
parent
e598e1496b
commit
641eb6a4d3
1 changed files with 59 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Helpers\TransporteHelper;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
|
@ -16,6 +17,11 @@ class GrupoDeCompra extends Model
|
|||
protected $table = 'grupos_de_compra';
|
||||
protected $hidden = ['password'];
|
||||
|
||||
public function subpedidos()
|
||||
{
|
||||
return $this->hasMany('App\Subpedido');
|
||||
}
|
||||
|
||||
public function toggleDevoluciones()
|
||||
{
|
||||
$this->devoluciones_habilitadas = !$this->devoluciones_habilitadas;
|
||||
|
@ -23,16 +29,64 @@ class GrupoDeCompra extends Model
|
|||
return $this->devoluciones_habilitadas;
|
||||
}
|
||||
|
||||
public function subpedidos()
|
||||
{
|
||||
return $this->hasMany('App\Subpedido');
|
||||
}
|
||||
|
||||
public function pedidosAprobados()
|
||||
{
|
||||
return $this->subpedidos->where('aprobado', 1);
|
||||
}
|
||||
|
||||
public function totalARecaudar()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->total();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalBarrial()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalBarrial();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalATransferir()
|
||||
{
|
||||
return $this->totalCentralesQueNoPaganTransporte()
|
||||
+ $this->totalCentralesQuePaganTransporte()
|
||||
+ $this->totalTransporte();
|
||||
}
|
||||
|
||||
public function totalCentralesQueNoPaganTransporte()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalCentralesQueNoPaganTransporte();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalCentralesQuePaganTransporte()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalCentralesQuePaganTransporte();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalTransporte()
|
||||
{
|
||||
return TransporteHelper::totalTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
public function cantidadTransporte()
|
||||
{
|
||||
return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
public function exportarPlanillasAPdf()
|
||||
{
|
||||
$subpedidos = $this->pedidosAprobados();
|
||||
|
|
Loading…
Add table
Reference in a new issue