forked from nathalie/pedi2
Merge pull request 'funcion/producto-paga-transporte' (#31) from funcion/producto-paga-transporte into master
Reviewed-on: nathalie/pedi2#31 Reviewed-by: Rodrigo <rodrigopdm@protonmail.com>
This commit is contained in:
commit
e334234c9f
|
@ -93,7 +93,11 @@ class GrupoDeCompra extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calcularCantidadBDT() {
|
public function calcularCantidadBDT() {
|
||||||
return ceil($this->totalPedidosSinBonos() / 500);
|
$total = 0;
|
||||||
|
foreach ($this->pedidosAprobados() as $pedido) {
|
||||||
|
$total += $pedido->totalParaTransporte();
|
||||||
|
}
|
||||||
|
return ceil($total / 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalBonosBarriales() {
|
public function totalBonosBarriales() {
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Filtros\FiltroDeProducto;
|
use App\Filtros\FiltroDeProducto;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Producto extends Model
|
class Producto extends Model
|
||||||
{
|
{
|
||||||
|
@ -16,12 +17,16 @@ class Producto extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]);
|
return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function proveedor()
|
public function proveedor()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Proveedor');
|
return $this->belongsTo('App\Proveedor');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pagaTransporte() {
|
||||||
|
return !($this->bono || Str::contains($this->categoria, 'SUBSIDIADO'));
|
||||||
|
}
|
||||||
|
|
||||||
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||||
public function scopeFiltrar($query, FiltroDeProducto $filtros)
|
public function scopeFiltrar($query, FiltroDeProducto $filtros)
|
||||||
{
|
{
|
||||||
|
@ -44,5 +49,5 @@ class Producto extends Model
|
||||||
public static function productosIDNombre() {
|
public static function productosIDNombre() {
|
||||||
return Producto::pluck('nombre', 'id',)->all();
|
return Producto::pluck('nombre', 'id',)->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,20 @@ class Subpedido extends Model
|
||||||
return $this->productosSinBonos()->sum('total');
|
return $this->productosSinBonos()->sum('total');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function totalParaTransporte() {
|
||||||
|
$total = 0;
|
||||||
|
foreach ($this->productos()->get() as $producto) {
|
||||||
|
if ($producto->pagaTransporte()) {
|
||||||
|
$total += $producto->precio * $producto->pivot->cantidad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ceil($total);
|
||||||
|
}
|
||||||
|
|
||||||
//Cantidad de bonos de transporte
|
//Cantidad de bonos de transporte
|
||||||
public function cantidadBDT()
|
public function cantidadBDT()
|
||||||
{
|
{
|
||||||
return ceil($this->totalSinBonos() / 500);
|
return ceil($this->totalParaTransporte() / 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Subtotal de dinero de bonos de transporte
|
//Subtotal de dinero de bonos de transporte
|
||||||
|
@ -98,11 +108,11 @@ class Subpedido extends Model
|
||||||
$view = view("pdfgen.subpedido_tabla", ["subpedido" => $this]);
|
$view = view("pdfgen.subpedido_tabla", ["subpedido" => $this]);
|
||||||
return $view->render();
|
return $view->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDevoluciones() {
|
public function getDevoluciones() {
|
||||||
return $this->devoluciones_total;
|
return $this->devoluciones_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNotasDevoluciones() {
|
public function getNotasDevoluciones() {
|
||||||
return $this->devoluciones_notas;
|
return $this->devoluciones_notas;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use Illuminate\Database\Seeder;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use App\Proveedor;
|
use App\Proveedor;
|
||||||
|
|
||||||
class ImportarProductoSeeder extends Seeder
|
class CanastaSeeder extends Seeder
|
||||||
{
|
{
|
||||||
const FILA_HEADER = "Tipo";
|
const FILA_HEADER = "Tipo";
|
||||||
const ULTIMA_FILA = "TOTAL";
|
const ULTIMA_FILA = "TOTAL";
|
||||||
|
@ -21,14 +21,14 @@ class ImportarProductoSeeder extends Seeder
|
||||||
$iHeader = $this->obtenerIndiceDeHeader($csv);
|
$iHeader = $this->obtenerIndiceDeHeader($csv);
|
||||||
$csv->setHeaderOffset($iHeader);
|
$csv->setHeaderOffset($iHeader);
|
||||||
$registros = $csv->getRecords();
|
$registros = $csv->getRecords();
|
||||||
|
|
||||||
$toInsert = [];
|
$toInsert = [];
|
||||||
$categoria = '';
|
$categoria = '';
|
||||||
foreach($registros as $i => $registro){
|
foreach($registros as $i => $registro){
|
||||||
//filas que están arriba del header
|
//filas que están arriba del header
|
||||||
if ($i <= $iHeader){
|
if ($i <= $iHeader){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//finalizar
|
//finalizar
|
||||||
if ($registro[$this::FILA_HEADER] == $this::ULTIMA_FILA){
|
if ($registro[$this::FILA_HEADER] == $this::ULTIMA_FILA){
|
||||||
|
@ -39,7 +39,7 @@ class ImportarProductoSeeder extends Seeder
|
||||||
if (!Arr::has($registro,$this::FILA_HEADER)|| trim($registro[$this::FILA_HEADER]) == ''){
|
if (!Arr::has($registro,$this::FILA_HEADER)|| trim($registro[$this::FILA_HEADER]) == ''){
|
||||||
var_dump("no hay tipo en la fila " . $i);
|
var_dump("no hay tipo en la fila " . $i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//saltear bono de transporte
|
//saltear bono de transporte
|
||||||
if ($registro[$this::FILA_HEADER] == "T"){
|
if ($registro[$this::FILA_HEADER] == "T"){
|
||||||
|
@ -51,7 +51,7 @@ class ImportarProductoSeeder extends Seeder
|
||||||
//es la pregunta de la copa?
|
//es la pregunta de la copa?
|
||||||
if (Str::contains($registro[$this::FILA_HEADER],"¿")) { continue; }
|
if (Str::contains($registro[$this::FILA_HEADER],"¿")) { continue; }
|
||||||
$categoria = $registro[$this::FILA_HEADER];
|
$categoria = $registro[$this::FILA_HEADER];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//completar producto
|
//completar producto
|
||||||
|
@ -65,9 +65,9 @@ class ImportarProductoSeeder extends Seeder
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||||
{
|
{
|
||||||
DB::table('productos')->insert($chunk);
|
DB::table('productos')->insert($chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ class DatabaseSeeder extends Seeder
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$this->call(GrupoDeCompraSeeder::class);
|
$this->call(CanastaSeeder::class);
|
||||||
$this->call(ImportarProductoSeeder::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
use League\Csv\Reader;
|
|
||||||
use App\Proveedor;
|
|
||||||
|
|
||||||
class ProductoSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$csv = Reader::createFromPath(resource_path('csv/productos.csv'), 'r');
|
|
||||||
$csv->setDelimiter("|");
|
|
||||||
$csv->setEnclosure("'");
|
|
||||||
$csv->setHeaderOffset(0);
|
|
||||||
$registros = $csv->getRecords();
|
|
||||||
$toInsert = [];
|
|
||||||
|
|
||||||
foreach($registros as $registro){
|
|
||||||
$toInsert[] = [
|
|
||||||
'categoria' => $registro['categoria'],
|
|
||||||
'nombre' => $registro['producto'],
|
|
||||||
'precio' => $registro['precio'],
|
|
||||||
'proveedor_id' => isset($registro['proveedor']) ? Proveedor::firstOrCreate([
|
|
||||||
'nombre' => $registro['proveedor']
|
|
||||||
])->id : null,
|
|
||||||
'bono' => $registro['categoria'] == 'BONOS Y FINANCIAMIENTO SORORO'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
||||||
{
|
|
||||||
DB::table('productos')->insert($chunk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue