Compare commits
No commits in common. "a2214f1a5690a218a58175692fb789b486345045" and "4c9ef3f782368ab2980c24495d709499a5a56247" have entirely different histories.
a2214f1a56
...
4c9ef3f782
4 changed files with 17 additions and 67 deletions
9
app/Constants.php
Normal file
9
app/Constants.php
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
class Constants
|
||||||
|
{
|
||||||
|
public const COSTO_TRANSPORTE = 15;
|
||||||
|
public const DIVISOR_TRANSPORTE = 500;
|
||||||
|
}
|
|
@ -5,8 +5,6 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use League\Csv\CannotInsertRecord;
|
|
||||||
use League\Csv\Writer;
|
|
||||||
|
|
||||||
class Barrio extends Model
|
class Barrio extends Model
|
||||||
{
|
{
|
||||||
|
@ -59,14 +57,15 @@ class Barrio extends Model
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function totalParaTransporte() : float {
|
function totalTransporte() : float {
|
||||||
return $this->calcularTotalConfirmados(
|
$totalSinTransporte = $this->calcularTotalConfirmados(
|
||||||
fn($p) => $p->total($p->productosConTransporte())
|
fn($p) => $p->total($p->productosSinTransporte())
|
||||||
);
|
);
|
||||||
|
return ($totalSinTransporte / Constants::DIVISOR_TRANSPORTE) * Constants::COSTO_TRANSPORTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function totalATransferir() : float {
|
function totalATransferir() : float {
|
||||||
return $this->totalNoBarriales() + TransporteUtils::total($this->totalParaTransporte());
|
return $this->totalNoBarriales() + $this->totalTransporte();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,44 +75,4 @@ class Barrio extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(Producto::class);
|
return $this->hasMany(Producto::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function exportarPedidoACsv() {
|
|
||||||
$columnaProductos = [];
|
|
||||||
$filasVaciasAgregadas = false;
|
|
||||||
|
|
||||||
foreach (Categoria::orderBy('id')->get() as $key => $categoria) {
|
|
||||||
$columnaProductos[] = ['name' => $categoria->name, 'cantidad' => null];
|
|
||||||
|
|
||||||
if ($categoria->name == 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO')
|
|
||||||
$columnaProductos[] = ['name' => 'Bono de Transporte', 'cantidad' => TransporteUtils::cantidad($this->totalParaTransporte)];
|
|
||||||
|
|
||||||
if ($categoria->name == 'PRODUCTOS DE GESTIÓN MENSTRUAL')
|
|
||||||
$columnaProductos[] = ['name' => '¿Cuántas copas quieren y pueden comprar en el grupo?', 'cantidad' => null];
|
|
||||||
|
|
||||||
foreach ($categoria->productos()->orderBy('id')->get() as $key => $producto) {
|
|
||||||
if ($producto->price == 0 && !$filasVaciasAgregadas) {
|
|
||||||
$columnaProductos[] = ['name' => '¿Cuántas copas quieren adquirir a través del financiamiento sororo?', 'cantidad' => null];
|
|
||||||
$filasVaciasAgregadas = true;
|
|
||||||
}
|
|
||||||
$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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Utils\TransporteUtils;
|
use App\Constants;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
@ -85,7 +85,8 @@ class Pedido extends Model
|
||||||
if ($this->productos()->every(fn($prod) => !$prod->pagaTransporte()))
|
if ($this->productos()->every(fn($prod) => !$prod->pagaTransporte()))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return TransporteUtils::total($this->productosConTransporte());
|
$cantidad = 1 + floor($this->total($this->productosConTransporte()) / Constants::DIVISOR_TRANSPORTE);
|
||||||
|
return $cantidad * Constants::COSTO_TRANSPORTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App;
|
|
||||||
|
|
||||||
class TransporteUtils
|
|
||||||
{
|
|
||||||
public const COSTO_TRANSPORTE = 15;
|
|
||||||
public const DIVISOR_TRANSPORTE = 500;
|
|
||||||
|
|
||||||
static function cantidad(float $total) : int {
|
|
||||||
if ($total)
|
|
||||||
return 1 + floor($total / DIVISOR_TRANSPORTE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function total(float $total) : int {
|
|
||||||
return cantidad($total) * COSTO_TRANSPORTE;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue