Merge branch 'feature/traducir' into feature/columna-totales

This commit is contained in:
Alejandro Tasistro 2024-07-03 19:35:27 -03:00
commit a372571fa7
13 changed files with 538 additions and 54 deletions

View File

@ -16,7 +16,7 @@ class Barrio extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**
@ -36,25 +36,25 @@ public function pedidos(): HasMany
}
function crearPedido(string $nombre) : Pedido {
return $this->pedidos()->create(['name' => $name]);
return $this->pedidos()->create(['nombre' => $name]);
}
function pedidosConfirmados() {
return $this->pedidos()->where('confirmed',true);
function pedidosPagados() {
return $this->pedidos()->where('pagado',true);
}
function totalARecaudar() : float {
return $this->calcularTotalConfirmados();
return $this->calcularTotalPagados();
}
function totalNoBarriales() : float {
return $this->calcularTotalConfirmados(
return $this->calcularTotalPagados(
fn($p) => $p->total($p->productosNoBarriales())
);
}
function totalParaTransporte() : float {
return $this->calcularTotalConfirmados(
return $this->calcularTotalPagados(
fn($p) => $p->total($p->productosConTransporte())
);
}
@ -63,10 +63,10 @@ function totalATransferir() : float {
return $this->totalNoBarriales() + TransporteUtils::total($this->totalParaTransporte());
}
private function calcularTotalConfirmados(Closure $closure = null) : float {
private function calcularTotalPagados(Closure $closure = null) : float {
if (!$closure)
$closure = fn($p) => $p->totalChismosa();
return $this->pedidosConfirmados()->sum($closure);
return $this->pedidosPagados()->sum($closure);
}
/**
@ -78,7 +78,7 @@ public function productos(): HasMany
}
function exportarPedidoACsv() {
if ($this->pedidosConfirmados()->exists()) {
if ($this->pedidosPagados()->exists()) {
$columnaProductos = $this->armarColumnasPedido();
try {

View File

@ -13,7 +13,7 @@ class Categoria extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**

View File

@ -16,7 +16,7 @@ class Pedido extends Model
* @var array<int, string>
*/
protected $fillable = [
'name', 'confirmed'
'nombre', 'pagado', 'terminado'
];
/**

View File

@ -14,7 +14,7 @@ class Producto extends Model
* @var array<int, string>
*/
protected $fillable = [
'name', 'price', 'solidario', 'bono', 'barrial', 'categoria_id', 'barrio_id'
'nombre', 'precio', 'solidario', 'bono', 'barrial', 'categoria_id', 'barrio_id'
];
/**

View File

@ -20,7 +20,7 @@ class Region extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**

View File

@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.8",
"guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^0.6.8",
"laravel/framework": "^10.10",

395
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8d183499e584f55de945d0a59ab769e7",
"content-hash": "58bdc4fc7c5dfbc1a71d9f335386c5b2",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -309,6 +309,350 @@
},
"time": "2022-10-27T11:44:00+00:00"
},
{
"name": "doctrine/cache",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb",
"shasum": ""
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"cache/integration-tests": "dev-master",
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^4.4 || ^5.4 || ^6",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/2.2.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2022-05-20T20:07:39+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.8.6",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "b7411825cf7efb7e51f9791dea19d86e43b399a1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/b7411825cf7efb7e51f9791dea19d86e43b399a1",
"reference": "b7411825cf7efb7e51f9791dea19d86e43b399a1",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1|^2",
"php": "^7.4 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.1",
"phpstan/phpstan": "1.11.5",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "9.6.19",
"psalm/plugin-phpunit": "0.18.4",
"slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.10.1",
"symfony/cache": "^5.4|^6.0|^7.0",
"symfony/console": "^4.4|^5.4|^6.0|^7.0",
"vimeo/psalm": "4.30.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.8.6"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2024-06-19T10:38:17+00:00"
},
{
"name": "doctrine/deprecations",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab",
"reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpstan/phpstan": "1.4.10 || 1.10.15",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psalm/plugin-phpunit": "0.18.4",
"psr/log": "^1 || ^2 || ^3",
"vimeo/psalm": "4.30.0 || 5.12.0"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.",
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/1.1.3"
},
"time": "2024-01-30T19:34:25+00:00"
},
{
"name": "doctrine/event-manager",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/b680156fa328f1dfd874fd48c7026c41570b9c6e",
"reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e",
"shasum": ""
},
"require": {
"php": "^8.1"
},
"conflict": {
"doctrine/common": "<2.9"
},
"require-dev": {
"doctrine/coding-standard": "^12",
"phpstan/phpstan": "^1.8.8",
"phpunit/phpunit": "^10.5",
"vimeo/psalm": "^5.24"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/2.0.1"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2024-05-22T20:47:39+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.10",
@ -3125,6 +3469,55 @@
},
"time": "2022-06-13T21:57:56+00:00"
},
{
"name": "psr/cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/clock",
"version": "1.0.0",

View File

@ -0,0 +1,62 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('barrios', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
});
Schema::table('categorias', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
});
Schema::table('pedidos', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
});
Schema::table('regiones', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
});
Schema::table('caracteristicas', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
$table->renameColumn('key', 'codigo');
});
Schema::table('productos', function (Blueprint $table) {
$table->renameColumn('name', 'nombre');
$table->renameColumn('price', 'precio');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('barrios', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
});
Schema::table('categorias', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
});
Schema::table('pedidos', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
});
Schema::table('regiones', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
});
Schema::table('caracteristicas', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
$table->renameColumn('codigo', 'key');
});
Schema::table('productos', function (Blueprint $table) {
$table->renameColumn('nombre', 'name');
$table->renameColumn('precio', 'price');
});
}
};

View File

@ -0,0 +1,27 @@
<?php
namespace Database\Seeders;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Region;
use App\Models\Barrio;
class BarrioSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$prueba_id = Region::create([
'nombre' => 'PRUEBA',
])->id;
Barrio::create([
'nombre'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now()
]);
}
}

View File

@ -11,7 +11,7 @@
use App\Models\Producto;
use App\Models\Categoria;
class BarrioPruebaSeeder extends Seeder
class BonoBarrialSeeder extends Seeder
{
/**
* Run the database seeds.
@ -19,16 +19,15 @@ class BarrioPruebaSeeder extends Seeder
public function run(): void
{
Producto::create([
'name' => 'Bono barrial',
'price' => 20,
'nombre' => 'Bono barrial',
'precio' => 20,
'solidario' => false,
'bono' => true,
'categoria_id' => Categoria::firstOrCreate([
'name' => 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO'
'categoria_id' => Categoria::first([
'nombre' => 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO'
])->id,
'barrio_id' => Barrio::create([
'name'=>'PRUEBA',
'region_id' => Region::create(['name' => 'PRUEBA'])->id
'barrio_id' => Barrio::first([
'nombre'=>'PRUEBA'
])->id,
]);
}

View File

@ -37,15 +37,16 @@ public function run(): void
$tipo = trim($record[$tipoColumn]);
if (!in_array($tipo, $tipos)) {
if (!Str::contains($tipo,'¿') && ($tipo != 'T'))
$currentCategoria = Categoria::firstOrCreate(['name' => $tipo]);
if (!Str::contains($tipo,'¿') && ($tipo != 'T')) {
$currentCategoria = Categoria::firstOrCreate(['nombre' => $tipo]);
}
} else {
[$solidario, $name, $caracteristicas] = $this->parseAndFormatName($record[$productoColumn]);
$productosToInsert[] = [
'name' => $name,
'price' => $record[$precioColumn],
'solidario' => $solidario,
'nombre' => $parsed['nombre'],
'precio' => $record[$precioColumn],
'solidario' => $parsed['solidario'],
'bono' => $tipo == 'B',
'categoria_id' => $currentCategoria->id,
'created_at' => Date::now(),
@ -53,8 +54,8 @@ public function run(): void
];
$caracteristicasToInsert[] = [
'name' => $name,
'caracteristicas' => $caracteristicas
'nombre' => $parsed['nombre'],
'caracteristicas' => $parsed['caracteristicas']
];
}
}
@ -68,40 +69,40 @@ public function run(): void
/**
* Returns an array with data parsed from productoColumn.
*
* @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica->id)}
* @return array{solidario: bool, nombre: string, caracteristicas: array(Caracteristica)}
*/
private function parseAndFormatName($productoColumn): array {
$solidario = Str::contains($productoColumn, '*');
$name = Str::replace('*','',$productoColumn);
$nombre = Str::replace('*','',$productoColumn);
$caracteristicas = [];
if (Str::contains($name, 'S-G'))
$caracteristicas[] = Caracteristica::where('key','S-G')->first()->id;
if (Str::contains($name, 'S-A'))
$caracteristicas[] = Caracteristica::where('key','S-A')->first()->id;
if (Str::contains($name, 'S-S'))
$caracteristicas[] = Caracteristica::where('key','S-S')->first()->id;
if (Str::contains($name, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('key','S-P-A')->first()->id;
if (Str::contains($nombre, 'S-G'))
$caracteristicas[] = Caracteristica::where('codigo','S-G')->first()->id;
if (Str::contains($nombre, 'S-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-A')->first()->id;
if (Str::contains($nombre, 'S-S'))
$caracteristicas[] = Caracteristica::where('codigo','S-S')->first()->id;
if (Str::contains($nombre, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-P-A')->first()->id;
if ($caracteristicas) {
$name = Str::replaceMatches('/\(S\-.*\)/', '', $name);
$nombre = Str::replaceMatches('/\(S\-.*\)/', '', $nombre);
}
return [
$solidario,
trim($name),
$caracteristicas
'solidario' => $solidario,
'nombre' => trim($nombre),
'caracteristicas' => $caracteristicas
];
}
private function insertCaracteristicas($caracteristicasToInsert) : void {
foreach ($caracteristicasToInsert as $key => $item) {
$name = $item['name'];
$match = Producto::where('name',$name)->first();
foreach ($caracteristicasToInsert as $codigo => $item) {
$nombre = $item['nombre'];
$match = Producto::where('nombre',$nombre)->first();
if ($match) {
foreach ($item['caracteristicas'] as $key => $caracteristica) {
DB::table('producto_caracteristica')->insert([
foreach ($item['caracteristicas'] as $codigo => $caracteristica) {
DB::table('productos_caracteristicas')->insert([
'producto_id' => $match->id,
'caracteristica_id' => $caracteristica,
]);

View File

@ -15,10 +15,10 @@ class CaracteristicaSeeder extends Seeder
public function run(): void
{
DB::table('caracteristicas')->insert([
['name' => 'SIN GLUTEN', 'key' => 'S-G', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN SAL AGREGADA', 'key' => 'S-S', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN AZÚCAR AGREGADA', 'key' => 'S-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN PRODUCTOS DE ORIGEN ANIMAL', 'key' => 'S-P-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN GLUTEN', 'codigo' => 'S-G', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN SAL AGREGADA', 'codigo' => 'S-S', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN AZÚCAR AGREGADA', 'codigo' => 'S-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN PRODUCTOS DE ORIGEN ANIMAL', 'codigo' => 'S-P-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
]);
}
}

View File

@ -17,7 +17,8 @@ public function run(): void
$this->call([
CaracteristicaSeeder::class,
CanastaSeeder::class,
BarrioPruebaSeeder::class,
BarrioSeeder::class,
BonoBarrialSeeder::class,
]);
}
}