Agregadas timestamps
This commit is contained in:
parent
6e0238eef7
commit
ea8611771b
5 changed files with 27 additions and 13 deletions
|
@ -50,7 +50,7 @@ class CanastaHelper
|
|||
}
|
||||
|
||||
// completar producto
|
||||
$toInsert[] = [
|
||||
$toInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'fila' => $i,
|
||||
'categoria' => $categoria,
|
||||
'nombre' => trim(str_replace('*', '',$registro[self::PRODUCTO])),
|
||||
|
@ -58,7 +58,7 @@ class CanastaHelper
|
|||
'es_solidario' => Str::contains($registro[self::PRODUCTO],"*"),
|
||||
'bono' => preg_match(self::REGEX_BONO, $registro[self::TIPO]),
|
||||
'requiere_notas'=> $registro[self::TIPO] == self::PRODUCTO_TALLE_COLOR,
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
|
|
|
@ -16,12 +16,12 @@ class Subpedido extends Model
|
|||
|
||||
public function productos(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany('App\Producto')->withPivot(["cantidad", "notas"]);
|
||||
return $this->belongsToMany(Producto::class)->withPivot(["cantidad", "notas"]);
|
||||
}
|
||||
|
||||
public function grupoDeCompra(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\GrupoDeCompra');
|
||||
return $this->belongsTo(GrupoDeCompra::class);
|
||||
}
|
||||
|
||||
// Permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
|
@ -91,7 +91,7 @@ class Subpedido extends Model
|
|||
return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
//Actualiza el pedido, agregando o quitando del subpedido según sea necesario. Debe ser llamado desde el controlador de subpedidos, luego de validar que los parámetros $producto y $cantidad son correctos. También calcula el subtotal por producto.
|
||||
// Actualiza el pedido, agregando o quitando del subpedido según sea necesario. Debe ser llamado desde el controlador de subpedidos, luego de validar que los parámetros $producto y $cantidad son correctos. También calcula el subtotal por producto.
|
||||
public function syncProducto(Producto $producto, int $cantidad, string $notas)
|
||||
{
|
||||
if ($cantidad) {
|
||||
|
@ -106,11 +106,15 @@ class Subpedido extends Model
|
|||
//si la cantidad es 0, se elimina el producto del subpedido
|
||||
$this->productos()->detach($producto->id);
|
||||
}
|
||||
|
||||
$this->updated_at = now();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function toggleAprobacion(bool $aprobacion)
|
||||
{
|
||||
$this->aprobado = $aprobacion;
|
||||
$this->update(['aprobado' => $aprobacion]);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
const CHUNK_SIZE = 100;
|
||||
|
||||
static function addTimestamps($object) {
|
||||
$now = DB::raw('CURRENT_TIMESTAMP');
|
||||
$object['created_at'] = $now;
|
||||
$object['updated_at'] = $now;
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*
|
||||
|
|
|
@ -19,21 +19,22 @@ class GrupoDeCompraSeeder extends Seeder
|
|||
$registros = CsvHelper::getRecords('csv/barrios.csv');
|
||||
$gdcToInsert = [];
|
||||
$usersToInsert = [];
|
||||
$roles = UserRole::where('nombre', 'barrio')->orWhere('nombre', 'barrio_admin')->get();
|
||||
$roles = UserRole::where('nombre', 'barrio')->orWhere('nombre', 'admin_barrio')->get();
|
||||
|
||||
foreach($registros as $key => $registro){
|
||||
$gdcToInsert[] = [
|
||||
$gdcToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'nombre' => $registro['barrio'],
|
||||
'region' => $registro['region'],
|
||||
];
|
||||
]);
|
||||
|
||||
foreach($roles as $role) {
|
||||
$usersToInsert[] = [
|
||||
'name' => $registro['barrio'],
|
||||
$nombre = $registro['barrio'] . ($role->nombre == 'barrio' ? '' : '_admin');
|
||||
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'name' => $nombre,
|
||||
'password' => Hash::make("123"),
|
||||
'role_id' => $role->id,
|
||||
'grupo_de_compra_id' => $key,
|
||||
];
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@ class UserSeeder extends Seeder
|
|||
{
|
||||
$usersToInsert = [];
|
||||
|
||||
$usersToInsert[] = [
|
||||
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'name' => 'comi',
|
||||
'password' => Hash::make("123"),
|
||||
'role_id' => UserRole::where('nombre', 'comision')->first()->id,
|
||||
];
|
||||
]);
|
||||
|
||||
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
|
|
Loading…
Add table
Reference in a new issue