metodos reordenados
This commit is contained in:
parent
a2214f1a56
commit
542e1c2315
1 changed files with 25 additions and 20 deletions
|
@ -43,12 +43,6 @@ class Barrio extends Model
|
||||||
return $this->pedidos()->where('confirmed',true);
|
return $this->pedidos()->where('confirmed',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function calcularTotalConfirmados(Closure $closure = null) : float {
|
|
||||||
if (!$closure)
|
|
||||||
$closure = fn($p) => $p->totalChismosa();
|
|
||||||
return $this->pedidosConfirmados()->sum($closure);
|
|
||||||
}
|
|
||||||
|
|
||||||
function totalARecaudar() : float {
|
function totalARecaudar() : float {
|
||||||
return $this->calcularTotalConfirmados();
|
return $this->calcularTotalConfirmados();
|
||||||
}
|
}
|
||||||
|
@ -69,6 +63,12 @@ class Barrio extends Model
|
||||||
return $this->totalNoBarriales() + TransporteUtils::total($this->totalParaTransporte());
|
return $this->totalNoBarriales() + TransporteUtils::total($this->totalParaTransporte());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function calcularTotalConfirmados(Closure $closure = null) : float {
|
||||||
|
if (!$closure)
|
||||||
|
$closure = fn($p) => $p->totalChismosa();
|
||||||
|
return $this->pedidosConfirmados()->sum($closure);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Los productos que pertenecen al barrio.
|
* Los productos que pertenecen al barrio.
|
||||||
*/
|
*/
|
||||||
|
@ -77,17 +77,20 @@ class Barrio extends Model
|
||||||
return $this->hasMany(Producto::class);
|
return $this->hasMany(Producto::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportarPedidoACsv() {
|
||||||
|
if ($this->pedidosConfirmados()->exists()) {
|
||||||
|
$columnaProductos = $this->armarColumnasPedido();
|
||||||
|
|
||||||
private function cantidadPedida(Producto $producto) : int {
|
try {
|
||||||
return DB::table('pedido_producto')
|
$writer = Writer::createFromPath(resource_path('csv/exports/'.$this->nombre.'.csv'), 'w');
|
||||||
->join('pedidos', 'pedido_producto.order_id', '=', 'pedidos.id')
|
$writer->insertAll($columnaProductos);
|
||||||
->where('pedidos.barrio_id', $this->id)
|
} catch (CannotInsertRecord $e) {
|
||||||
->where('pedido_producto.producto_id', $producto->id)
|
var_export($e->getRecords());
|
||||||
->where('pedidos.confirmed', true)
|
}
|
||||||
->sum('pedido_producto.cantidad');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function exportarPedidoACsv() {
|
private function armarColumnasPedido() : array {
|
||||||
$columnaProductos = [];
|
$columnaProductos = [];
|
||||||
$filasVaciasAgregadas = false;
|
$filasVaciasAgregadas = false;
|
||||||
|
|
||||||
|
@ -108,12 +111,14 @@ class Barrio extends Model
|
||||||
$columnaProductos[] = ['name' => $producto->name, 'cantidad' => $this->cantidadPedida($producto)];
|
$columnaProductos[] = ['name' => $producto->name, 'cantidad' => $this->cantidadPedida($producto)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$writer = Writer::createFromPath(resource_path('csv/exports/'.$this->nombre.'.csv'), 'w');
|
|
||||||
$writer->insertAll($columnaProductos);
|
|
||||||
} catch (CannotInsertRecord $e) {
|
|
||||||
var_export($e->getRecords());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cantidadPedida(Producto $producto) : int {
|
||||||
|
return DB::table('pedido_producto')
|
||||||
|
->join('pedidos', 'pedido_producto.order_id', '=', 'pedidos.id')
|
||||||
|
->where('pedidos.barrio_id', $this->id)
|
||||||
|
->where('pedido_producto.producto_id', $producto->id)
|
||||||
|
->where('pedidos.confirmed', true)
|
||||||
|
->sum('pedido_producto.cantidad');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue