Compare commits
No commits in common. "master" and "seleccionar-subpedido-existente" have entirely different histories.
master
...
selecciona
190 changed files with 3115 additions and 14237 deletions
|
@ -1,9 +0,0 @@
|
|||
[Dolphin]
|
||||
HeaderColumnWidths=372,72,103
|
||||
SortRole=modificationtime
|
||||
Timestamp=2022,6,1,16,36,48
|
||||
Version=4
|
||||
ViewMode=1
|
||||
|
||||
[Settings]
|
||||
HiddenFilesShown=true
|
Binary file not shown.
|
@ -4,15 +4,11 @@ APP_KEY=
|
|||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
VITE_DEV_SERVER_URL=http://vite:5173
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
USERID=1000
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=db
|
||||
DB_PORT_EXPOSED=3306
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=pedi2
|
||||
DB_USERNAME=pedi2
|
||||
DB_PASSWORD=pedi2
|
||||
|
@ -51,5 +47,4 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|||
|
||||
WEB_CLIENT_EMAIL=informaticamps@buzon.uy
|
||||
WEB_CLIENT_NAME=web
|
||||
WEB_CLIENT_PASS=pass
|
||||
NGINX_PORT=8000
|
||||
WEB_CLIENT_PASS=pass
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -10,11 +10,3 @@ Homestead.json
|
|||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.idea
|
||||
/resources/csv/exports/*.csv
|
||||
/resources/csv/canastas/*.csv
|
||||
/storage/csv/exports/*.csv
|
||||
/storage/csv/canastas/*.csv
|
||||
/public/css/
|
||||
/public/js/
|
||||
/public/mix-manifest.json
|
||||
|
|
11
Dockerfile
11
Dockerfile
|
@ -1,4 +1,4 @@
|
|||
FROM php:8.3-fpm
|
||||
FROM php:7.4-fpm
|
||||
|
||||
# Arguments defined in docker-compose.yml
|
||||
ARG user
|
||||
|
@ -12,18 +12,13 @@ RUN apt-get update && apt-get install -y \
|
|||
libonig-dev \
|
||||
libxml2-dev \
|
||||
zip \
|
||||
unzip \
|
||||
libzip-dev
|
||||
|
||||
# Install node
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||
apt-get install -y nodejs
|
||||
unzip
|
||||
|
||||
# Clear cache
|
||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install PHP extensions
|
||||
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
|
||||
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
|
||||
|
||||
# Get latest Composer
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
|
100
README.md
100
README.md
|
@ -1,15 +1,14 @@
|
|||
# Pedi2
|
||||
|
||||
Aplicación de pedidos del Mercado Popular de Subsistencia.
|
||||
Aplicación de compras del Mercado Popular de Subsistencia.
|
||||
|
||||
Pedi2 está hecha en Laravel 12 y Vue 2 con Vite y Vuex.
|
||||
Pedi2 está hecha en Laravel 7 y utiliza laravel7-docker de dyarleniber.
|
||||
|
||||
Se utilizan los siguientes servicios, separadamente:
|
||||
|
||||
- `app`, un servicio que corre PHP8.3-FPM.
|
||||
- `app`, un servicio que corre PHP7.4-FPM.
|
||||
- `db`, un servicio que corre MySQL 5.7.
|
||||
- `nginx`, un servicio que usa el servicio app para parsear código PHP antes de servir la aplicación de Laravel al usuario final.
|
||||
- `vite`, un servicio que corre el frontend de la aplicación.
|
||||
|
||||
## Pre-requisitos
|
||||
- docker
|
||||
|
@ -18,50 +17,107 @@ Se utilizan los siguientes servicios, separadamente:
|
|||
## Instalación
|
||||
1. Una vez descargado el proyecto, hacé una copia del archivo `.env.example` que se encuentra en la raíz del proyecto y nombrala `.env`. Seteá los valores correctos - específicamente, para las variables, `APP_URL`, `DB_USERNAME` y `DB_PASSWORD`. Prestá atención a que `DB_HOST` sea el nombre del servicio que corre MySQL (por defecto `DB_HOST=db`).
|
||||
|
||||
2. Levantá los contenedores, construyendo la imagen de la app primero:
|
||||
2. Construí la imagen de la app
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
docker-compose build app
|
||||
```
|
||||
|
||||
El ambiente ahora está andando, deberías ver los logs de cada servicio en la terminal. Falta ejecutar un par de comandos para terminar la instalación de Laravel. Podemos usar `docker-compose exec [nombre-del-servicio]` previo a un comando para ejecutarlo dentro del contenedor.
|
||||
3. Cuando termine, levantá los contenedores:
|
||||
|
||||
3. Abrí una nueva terminal, y terminá de instalar las dependencias de la app, según fueron definidas en `composer.json`:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
El ambiente ahora está andando, pero necesitamos ejecutar un par de comandos para terminar la instalación de Laravel. Podemos usar `docker-compose exec [nombre-del-servicio]` previo a un comando para ejecutarlo dentro del contenedor.
|
||||
|
||||
4. Terminá de instalar las dependencias de la app, según fueron definidas en `composer.json`.
|
||||
|
||||
|
||||
```bash
|
||||
docker-compose exec app composer install
|
||||
docker-compose exec app composer update
|
||||
```
|
||||
|
||||
4. Generá una clave de aplicación. Esta clave se usa para encriptar datos sensibles:
|
||||
5. Generá una clave de aplicación. Esta clave se usa para encriptar datos sensibles.
|
||||
|
||||
```bash
|
||||
docker-compose exec app php artisan key:generate
|
||||
```
|
||||
|
||||
5. Corré las migraciones y seeders de Laravel:
|
||||
6. Corré las migraciones y seeders de Laravel
|
||||
|
||||
```bash
|
||||
docker-compose exec app php artisan migrate:fresh --seed
|
||||
docker-compose exec app php artisan migrate --seed
|
||||
```
|
||||
|
||||
6. Copia el token que se imprime al correr los seeders. Lo necesitamos para autenticar las llamadas que hagamos desde nuestro cliente web
|
||||
7. Copia el token que se imprime al correr los seeders. Lo necesitamos para autenticar las llamadas que hagamos desde nuestro cliente web
|
||||
|
||||
7. Instala las dependencias de npm:
|
||||
```bash
|
||||
docker-compose exec app npm install
|
||||
```
|
||||
|
||||
Ahora la aplicación está corriendo y la podés ver en el puerto 8000 de tu dominio o IP. En caso de que estés en tu máquina local, la vas a ver accediendo a `http://localhost:8000` desde tu navegador.
|
||||
|
||||
Podés usar el comando `logs` para ver los logs generados por tus servicios:
|
||||
|
||||
```bash
|
||||
docker-compose logs nginx
|
||||
```
|
||||
---
|
||||
|
||||
Si estás actualizando o no te anda, probá limpiar los caches:
|
||||
```
|
||||
docker-compose exec app php artisan optimize:clear
|
||||
docker-compose exec app composer dump-autoload
|
||||
## Services description
|
||||
|
||||
### Dockerfile
|
||||
|
||||
Although both `db` service and `nginx` service, will be based on default images obtained from the Docker Hub, the `app` service will be based on a custom image created by the `Dockerfile`.
|
||||
|
||||
The `Dockerfile` starts by defining the base image `php:7.4-fpm`.
|
||||
|
||||
After installing system packages and PHP extensions, the Composer will be installed by copying the composer executable from its latest official image.
|
||||
|
||||
A new system user is then created and set up using the `user` and `uid` arguments that were declared at the beginning of the `Dockerfile`. These values will be injected by Docker Compose at build time.
|
||||
|
||||
> This new system user is necessary to execute Laravel Artisan and Composer commands while developing the application. The `uid` setting ensures that the user inside the container has the same `uid` as your system user on your host machine. This way, any files created by these commands are replicated in the host with the correct permissions. This also means that you’ll be able to use your code editor of choice in the host machine to develop the application that is running inside containers.
|
||||
|
||||
Finally, the default working dir as `/var/www` and the newly created user are set. This will make sure you’re connecting as a regular user, and that you’re on the right directory, when running Laravel Artisan and Composer commands on the application container.
|
||||
|
||||
### PHP service
|
||||
|
||||
The `app` service will build an image called `laravel-image`, based on the `Dockerfile` previously created. The container defined by this service will run a php-fpm server to parse PHP code and send the results back to the nginx service, which will be running on a separate container. The mysql service defines a container running a MySQL 5.7 server. All these services will share a bridge network named `app-network`.
|
||||
|
||||
The application files will be synchronized on both the `app` and the `nginx` services via bind mounts. Bind mounts are useful in development environments because they allow for a performant two-way sync between host machine and containers.
|
||||
|
||||
Inside the `app` container you will be able to execute command line tasks with the Laravel Artisan and Composer.
|
||||
|
||||
The `app` service will set up a container named `laravel-app`. It builds a new Docker image based on a `Dockerfile` located in the same path as the `docker-compose.yml` file. The new image will be saved locally under the name `laravel-image`.
|
||||
|
||||
The `volumes` setting creates a shared volume that will synchronize contents from the current directory to `/var/www` inside the container. Notice that this is not your document root, since that will live in the nginx container.
|
||||
|
||||
Another file which will be synchronized is the `local.ini` file from the directory `./php/local.ini` to `/usr/local/etc/php/conf.d/local.ini` inside the container.
|
||||
|
||||
The `local.ini` is the configuration file (php.ini) that is read when PHP starts up.
|
||||
|
||||
### Nginx service
|
||||
|
||||
The `nginx` service uses a pre-built Nginx image on top of Alpine, a lightweight Linux distribution. It creates a container named `laravel-nginx`, and it uses the ports definition to create a redirection from port `8000` on the host system to port `80` inside the container.
|
||||
|
||||
The `volumes` setting creates two shared volumes. The first one will synchronize contents from the current directory to `/var/www` inside the container. This way, when you make local changes to the application files, they will be quickly reflected in the application being served by Nginx inside the container. The second volume will make sure the Nginx configuration file, located at `./nginx/conf.d/app.conf`, is copied to the container’s Nginx configuration folder. This configuration file will configure Nginx to listen on port `80` and use `index.php` as default index page. It will set the document root to `/var/www/public`, and then configure Nginx to use the `app` service on port `9000` to process all the php files.
|
||||
|
||||
### MySQL service
|
||||
|
||||
The `db` service uses a pre-built MySQL 5.7 image from Docker Hub. Because Docker Compose automatically loads `.env` variable files located in the same directory as the `docker-compose.yml` file, you can obtain the database settings from the Laravel `.env` file.
|
||||
|
||||
The `volumes` setting creates two shared volumes. The first one will make sure the MySQL configuration file, located at `./mysql/my.cnf`, is copied to the container’s MySQL configuration folder. The second volume will share a `.sql` database dump that will be used to initialize the application database. The MySQL image will automatically import `.sql` files placed in the `/docker-entrypoint-initdb.d` directory inside the container.
|
||||
|
||||
The `environment` setting defines environment variables in the new container. You can use values obtained from the Laravel `.env` file to set up the MySQL service, which will automatically create a new database and user based on the provided environment variables:
|
||||
|
||||
```bash
|
||||
DB_HOST=db
|
||||
DB_DATABASE=laravelapp
|
||||
DB_USERNAME=laravelapp_user
|
||||
DB_PASSWORD=password
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- https://www.digitalocean.com/community/tutorials/how-to-install-and-set-up-laravel-with-docker-compose-on-ubuntu-20-04
|
||||
- https://docs.docker.com/
|
||||
- https://docs.docker.com/compose/
|
||||
- https://github.com/dyarleniber/laravel7-docker
|
||||
- https://laravel.com/docs/7.x/installation
|
|
@ -4,7 +4,7 @@ namespace App;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserRole extends Model
|
||||
class Admin extends Model
|
||||
{
|
||||
protected $fillable = ["nombre"];
|
||||
//
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CanastaLog extends Model
|
||||
{
|
||||
protected $fillable = ["path", "descripcion"];
|
||||
protected $table = "carga_de_canastas";
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AgregarEsBonoAPedidosAprobados extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:AgregarEsBonoAPedidosAprobados';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Agrega "producto_bono" a la view PedidosAprobados';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
DB::statement("
|
||||
ALTER VIEW pedidos_aprobados(
|
||||
grupo_de_compra_id,
|
||||
grupo_de_compra_nombre,
|
||||
grupo_de_compra_region,
|
||||
producto_id,
|
||||
producto_nombre,
|
||||
producto_precio,
|
||||
cantidad_pedida,
|
||||
total_por_producto,
|
||||
producto_es_bono
|
||||
) AS
|
||||
SELECT
|
||||
g.id as grupo_de_compra_id,
|
||||
g.nombre as grupo_de_compra_nombre,
|
||||
g.region as grupo_de_compra_region,
|
||||
pr.id AS producto_id,
|
||||
pr.nombre as producto_nombre,
|
||||
pr.precio as producto_precio,
|
||||
SUM(ps.cantidad) as cantidad_pedida,
|
||||
pr.precio*SUM(ps.cantidad) as total_por_producto,
|
||||
pr.bono
|
||||
FROM grupos_de_compra g
|
||||
JOIN subpedidos s ON (s.grupo_de_compra_id = g.id AND s.aprobado=1)
|
||||
JOIN producto_subpedido ps ON (ps.subpedido_id = s.id)
|
||||
JOIN productos pr ON (pr.id = ps.producto_id)
|
||||
GROUP BY
|
||||
g.id, g.nombre, pr.id, pr.nombre
|
||||
;");
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CrearPedidosAprobadosViewCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'view:CrearPedidosAprobadosView';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Crea view "pedidos_aprobados"';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
DB::statement("
|
||||
CREATE OR REPLACE VIEW pedidos_aprobados
|
||||
AS
|
||||
SELECT
|
||||
g.id as grupo_de_compra_id,
|
||||
g.nombre as grupo_de_compra_nombre,
|
||||
g.region as grupo_de_compra_region,
|
||||
pr.id AS producto_id,
|
||||
pr.nombre as producto_nombre,
|
||||
pr.precio as producto_precio,
|
||||
SUM(ps.cantidad) as cantidad_pedida,
|
||||
pr.precio*SUM(ps.cantidad) as total_por_producto
|
||||
FROM grupos_de_compra g
|
||||
JOIN subpedidos s ON (s.grupo_de_compra_id = g.id AND s.aprobado=1)
|
||||
JOIN producto_subpedido ps ON (ps.subpedido_id = s.id)
|
||||
JOIN productos pr ON (pr.id = ps.producto_id)
|
||||
GROUP BY
|
||||
g.id, g.nombre, pr.id, pr.nombre
|
||||
;");
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -5,14 +5,12 @@ namespace App\Filtros;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Throwable;
|
||||
use TypeError;
|
||||
|
||||
class Filtro extends Model
|
||||
{
|
||||
protected Request $request;
|
||||
protected array $MENSAJES_ERROR = [
|
||||
protected $request;
|
||||
protected $builder;
|
||||
protected $MENSAJES_ERROR = [
|
||||
'ARGUMENTO' => 'Argumento inválido para el parámetro %s. Revise la documentación.'
|
||||
];
|
||||
|
||||
|
@ -24,10 +22,10 @@ class Filtro extends Model
|
|||
/**
|
||||
* Apply all existing filters, if available.
|
||||
*
|
||||
* @param Builder $builder
|
||||
* @return Builder
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function aplicar(Builder $builder): Builder
|
||||
public function aplicar(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
|
||||
|
@ -45,24 +43,17 @@ class Filtro extends Model
|
|||
//Obtener nombre del método (snake_case a camelCase)
|
||||
$metodo = str_replace('_', '', lcfirst(ucwords($filtro, '_')));
|
||||
|
||||
if (!method_exists($this, $metodo))
|
||||
continue;
|
||||
if(!method_exists($this, $metodo)) { continue; }
|
||||
|
||||
//Llamar métodos sin argumentos
|
||||
if ($valor === null || (is_a($valor,'String') && trim($valor)=='')) {
|
||||
$this->$metodo();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($valor === null|| (is_a($valor,'String') && trim($valor)=='')){ $this->$metodo(); continue; }
|
||||
|
||||
//Llamar métodos con argumentos
|
||||
try {
|
||||
$this->$metodo($valor);
|
||||
} catch (Throwable $error) {
|
||||
if (is_a($error,'TypeError')) {
|
||||
$mensaje = sprintf($this->MENSAJES_ERROR['ARGUMENTO'], $filtro);
|
||||
throw new HttpException(400, $mensaje);
|
||||
}
|
||||
throw $error;
|
||||
} catch (\Throwable $th) {
|
||||
if (is_a($th,'TypeError') ) { throw new HttpException(400, sprintf($this->MENSAJES_ERROR['ARGUMENTO'],$filtro)); }
|
||||
throw $th;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,16 +63,12 @@ class Filtro extends Model
|
|||
//Buscar un término en el nombre
|
||||
public function nombre(String $valor)
|
||||
{
|
||||
$this->builder
|
||||
->where('nombre', "LIKE", "%" . $valor . "%")
|
||||
->orderByRaw("IF(nombre = '$valor',2,IF(nombre LIKE '$valor%',1,0)) DESC");
|
||||
$this->builder->where('nombre', "LIKE", "%" . $valor . "%")->orderByRaw("IF(nombre = '{$valor}',2,IF(nombre LIKE '{$valor}%',1,0)) DESC");
|
||||
}
|
||||
|
||||
public function alfabetico(String $order = 'asc')
|
||||
{
|
||||
if (!in_array($order,['asc','desc']))
|
||||
throw new TypeError();
|
||||
|
||||
if(!in_array($order,['asc','desc'])) { throw new TypeError(); }
|
||||
$this->builder->orderBy('nombre', $order);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filtros;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class FiltroDeProducto extends Filtro {
|
||||
|
||||
|
@ -9,4 +10,4 @@ class FiltroDeProducto extends Filtro {
|
|||
$this->builder->where('categoria', $valor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,23 +2,13 @@
|
|||
|
||||
namespace App\Filtros;
|
||||
|
||||
use TypeError;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FiltroDeSubpedido extends Filtro
|
||||
{
|
||||
public function grupoDeCompra(String $valor)
|
||||
{
|
||||
if (!is_numeric($valor))
|
||||
throw new TypeError();
|
||||
|
||||
if (!is_numeric($valor)) { throw new TypeError();}
|
||||
$this->builder->where('grupo_de_compra_id', intval($valor));
|
||||
}
|
||||
|
||||
public function tipoPedido(String $valor)
|
||||
{
|
||||
if (!is_numeric($valor))
|
||||
throw new TypeError();
|
||||
|
||||
$this->builder->where('tipo_pedido_id', intval($valor));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,207 +2,17 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Helpers\CsvHelper;
|
||||
use App\Helpers\PdfHelper;
|
||||
use App\Helpers\TransporteHelper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Csv\Exception;
|
||||
use Mpdf\MpdfException;
|
||||
|
||||
class GrupoDeCompra extends Model
|
||||
{
|
||||
protected $fillable = ["nombre", "region", "devoluciones_habilitadas", "saldo"];
|
||||
protected $table = 'grupos_de_compra';
|
||||
public $timestamps = false;
|
||||
protected $fillable = [ "nombre","region","telefono","correo","referente_finanzas","cantidad_de_nucleos"];
|
||||
protected $table = 'grupos_de_compra';
|
||||
protected $hidden = ['password'];
|
||||
|
||||
public function subpedidos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Subpedido::class);
|
||||
}
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
public function toggleDevoluciones(): bool
|
||||
{
|
||||
$this->devoluciones_habilitadas = !$this->devoluciones_habilitadas;
|
||||
$this->save();
|
||||
return $this->devoluciones_habilitadas;
|
||||
}
|
||||
|
||||
public function pedidosAprobados()
|
||||
{
|
||||
return $this->pedidosHogares()
|
||||
->where('aprobado', 1);
|
||||
}
|
||||
|
||||
public function pedidosHogares()
|
||||
{
|
||||
return $this->subpedidos
|
||||
->where('tipo_pedido_id', '=', 1);
|
||||
}
|
||||
|
||||
public function totalARecaudar()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->total();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalSinDevoluciones() {
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalSinDevoluciones();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalBarrial()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalBarrial();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalDevoluciones()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->devoluciones_total;
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalDePedido()
|
||||
{
|
||||
return $this->totalCentralesQueNoPaganTransporte()
|
||||
+ $this->totalCentralesQuePaganTransporte()
|
||||
+ $this->totalTransporte()
|
||||
;
|
||||
}
|
||||
|
||||
public function totalATransferir()
|
||||
{
|
||||
return $this->totalDePedido() - $this->saldo;
|
||||
}
|
||||
|
||||
public function totalCentralesQueNoPaganTransporte()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalCentralesQueNoPaganTransporte();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalCentralesQuePaganTransporte()
|
||||
{
|
||||
$total = 0;
|
||||
foreach ($this->pedidosAprobados() as $subpedido) {
|
||||
$total = $total + $subpedido->totalCentralesQuePaganTransporte();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function totalTransporte()
|
||||
{
|
||||
return TransporteHelper::totalTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* Calcula la cantidad de bonos de transporte del barrio
|
||||
*/
|
||||
public function cantidadTransporte(): int
|
||||
{
|
||||
return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MpdfException
|
||||
*/
|
||||
public function exportarPedidosAPdf()
|
||||
{
|
||||
$fecha = now()->format('Y-m-d');
|
||||
$filepath = $this->nombre . '-' . $fecha . '.pdf';
|
||||
$pedidoOllas = $this->subpedidos
|
||||
->where('tipo_pedido_id', '=', TipoPedido::firstOrCreate(['nombre' => 'olla'])->id);
|
||||
$pedidos = $this->pedidosAprobados()->concat($pedidoOllas);
|
||||
PdfHelper::exportarPedidos($filepath, $pedidos);
|
||||
}
|
||||
|
||||
function pedidoParaPdf(): array
|
||||
{
|
||||
$productos = $this->productosPedidos(true, 'producto_id');
|
||||
$pedido = [];
|
||||
$pedido['productos'] = [];
|
||||
|
||||
$pedido['nombre'] = $this->nombre;
|
||||
foreach ($productos as $producto) {
|
||||
$productoParaPdf = [];
|
||||
$productoParaPdf['pivot'] = [];
|
||||
$productoParaPdf['nombre'] = $producto->producto_nombre;
|
||||
$productoParaPdf['pivot']['cantidad'] = $producto->cantidad_pedida;
|
||||
$productoParaPdf['pivot']['notas'] = false;
|
||||
$productoParaPdf['bono'] = $producto->producto_es_bono;
|
||||
|
||||
$pedido['productos'][] = $productoParaPdf;
|
||||
}
|
||||
|
||||
return $pedido;
|
||||
}
|
||||
|
||||
public function generarHTML()
|
||||
{
|
||||
$view = view("pdfgen.pedido_tabla", ["pedido" => $this->pedidoParaPdf()]);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MpdfException
|
||||
*/
|
||||
public static function exportarPedidosBarrialesAPdf()
|
||||
{
|
||||
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
|
||||
$fecha = now()->format('Y-m-d');
|
||||
$filepath = 'pedidos_por_barrio-' . $fecha . '.pdf';
|
||||
PdfHelper::exportarPedidos($filepath, $barrios);
|
||||
}
|
||||
|
||||
public static function barriosMenosPrueba(): Builder
|
||||
{
|
||||
return self::where('nombre', '<>', 'PRUEBA')
|
||||
->orderBy('region')
|
||||
->orderBy('nombre');
|
||||
}
|
||||
|
||||
public function productosPedidos($excluirBonos = false, $orderBy = 'producto_nombre'): Collection
|
||||
{
|
||||
$query = DB::table('pedidos_aprobados')
|
||||
->where('grupo_de_compra_id', $this->id)
|
||||
->where('producto_nombre','NOT LIKE','%barrial%');
|
||||
|
||||
if ($excluirBonos)
|
||||
$query = $query->where('producto_es_bono',false);
|
||||
|
||||
return $query
|
||||
->orderBy($orderBy)
|
||||
->get()
|
||||
->keyBy('producto_id');
|
||||
}
|
||||
|
||||
public function setSaldo(float $saldo) {
|
||||
$this->saldo = $saldo;
|
||||
$this->save();
|
||||
}
|
||||
public function subpedidos() {
|
||||
return $this->hasMany('App\Subpedido');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Producto;
|
||||
use App\CanastaLog;
|
||||
use DatabaseSeeder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Csv\Exception;
|
||||
|
||||
class CanastaHelper
|
||||
{
|
||||
const TIPO = "Tipo";
|
||||
const PRODUCTO = 'Producto';
|
||||
const PRECIO = 'Precio';
|
||||
const REGEX_BONO = "/^[BF]/i";
|
||||
const ARCHIVO_SUBIDO = 'Archivo subido';
|
||||
const CANASTA_CARGADA = 'Canasta cargada';
|
||||
const PRODUCTO_TALLE_COLOR = "PTC";
|
||||
|
||||
public static function canastaActual() {
|
||||
$result = [];
|
||||
$log = CanastaLog::where('descripcion', self::CANASTA_CARGADA)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
$nombre = str_replace(storage_path(), "", $log->path);
|
||||
$nombre = str_replace("/csv/canastas/", "", $nombre);
|
||||
$result["nombre"] = str_replace(".csv", "", $nombre);
|
||||
$result["fecha"] = $log->created_at;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function guardarCanasta($data, $path): string {
|
||||
if (!File::exists(storage_path('csv/canastas'))) {
|
||||
File::makeDirectory(storage_path('csv/canastas'), 0755, true);
|
||||
}
|
||||
|
||||
$nombre = $data->getClientOriginalName();
|
||||
|
||||
$storage_path = storage_path($path);
|
||||
$data->move($storage_path, $nombre);
|
||||
|
||||
self::log($storage_path . $nombre, self::ARCHIVO_SUBIDO);
|
||||
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cargarCanasta($archivo) {
|
||||
self::limpiarTablas();
|
||||
|
||||
$registros = CsvHelper::getRecords($archivo, "No se pudo leer el archivo.");
|
||||
|
||||
$toInsert = [];
|
||||
$categoria = '';
|
||||
|
||||
foreach($registros as $i => $registro) {
|
||||
// saltear bono de transporte y filas que no tienen tipo
|
||||
if (self::noTieneTipo($registro) || $registro[self::TIPO] == "T")
|
||||
continue;
|
||||
|
||||
// obtener categoria si no hay producto
|
||||
if ($registro[self::PRODUCTO] == '') {
|
||||
// no es la pregunta de la copa?
|
||||
if (!Str::contains($registro[self::TIPO],"¿"))
|
||||
$categoria = $registro[self::TIPO];
|
||||
continue; // saltear si es la pregunta de la copa
|
||||
}
|
||||
|
||||
// completar producto
|
||||
$toInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'fila' => $i,
|
||||
'categoria' => $categoria,
|
||||
'nombre' => trim(str_replace('*', '',$registro[self::PRODUCTO])),
|
||||
'precio' => $registro[self::PRECIO],
|
||||
'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)
|
||||
Producto::insert($chunk);
|
||||
|
||||
self::agregarBonoBarrial();
|
||||
|
||||
self::log($archivo, self::CANASTA_CARGADA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $descripcion
|
||||
* @return void
|
||||
*/
|
||||
private static function log($path, $descripcion): void
|
||||
{
|
||||
$log = new CanastaLog([
|
||||
'path' => $path,
|
||||
'descripcion' => $descripcion,
|
||||
]);
|
||||
$log->save();
|
||||
}
|
||||
|
||||
private static function limpiarTablas()
|
||||
{
|
||||
DB::delete('delete from producto_subpedido');
|
||||
DB::delete('delete from productos');
|
||||
DB::delete('delete from subpedidos');
|
||||
}
|
||||
|
||||
private static function agregarBonoBarrial()
|
||||
{
|
||||
$categoria = Producto::all()
|
||||
->pluck('categoria')
|
||||
->unique()
|
||||
->flatten()
|
||||
->first(function ($c) {
|
||||
return Str::contains($c, 'BONO');
|
||||
});
|
||||
|
||||
Producto::create([
|
||||
'nombre' => "Bono barrial",
|
||||
'precio' => 20,
|
||||
'categoria' => $categoria,
|
||||
'bono' => 1,
|
||||
'es_solidario' => 0,
|
||||
'requiere_notas'=> false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $registro
|
||||
* @return bool
|
||||
*/
|
||||
public static function noTieneTipo($registro): bool
|
||||
{
|
||||
return !Arr::has($registro, self::TIPO) || trim($registro[self::TIPO]) == '';
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Http\Controllers\ComisionesController;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Iterator;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\InvalidArgument;
|
||||
use League\Csv\Reader;
|
||||
use League\Csv\Writer;
|
||||
|
||||
class CsvHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getRecords($filePath, $message): Iterator {
|
||||
try {
|
||||
$csv = self::getReader($filePath);
|
||||
return $csv->getRecords();
|
||||
} catch (InvalidArgument|Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
throw new Exception($message, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cambiarParametro(string $id, string $valor): void
|
||||
{
|
||||
try {
|
||||
$updated = false;
|
||||
$filePath = resource_path(ComisionesController::PARAMETROS_PATH);
|
||||
$csv = self::getReader($filePath);
|
||||
$headers = $csv->getHeader();
|
||||
$records = array_map(fn($r) => (array) $r, iterator_to_array($csv->getRecords()));
|
||||
|
||||
foreach ($records as &$record) {
|
||||
if ($record['id'] === $id) {
|
||||
$record['valor'] = $valor;
|
||||
$updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($record);
|
||||
|
||||
if (!$updated)
|
||||
throw new Exception("Parametro '{$id}' no encontrado.");
|
||||
|
||||
self::generarCsv($filePath, $records, $headers, "|", "'", false);
|
||||
} catch (CannotInsertRecord | InvalidArgument $e) {
|
||||
Log::error("Error al actualizar csv: " . $e->getMessage());
|
||||
throw new Exception("Error al actualizar csv", $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
*/
|
||||
public static function generarCsv($filePath, $contenido, $headers = null, $delimiter = null, $enclosure = null, $export = true): void
|
||||
{
|
||||
$path = $filePath;
|
||||
|
||||
if ($export) {
|
||||
if (!File::exists(storage_path('csv/exports')))
|
||||
File::makeDirectory(storage_path('csv/exports'), 0755, true);
|
||||
$path = storage_path($filePath);
|
||||
}
|
||||
|
||||
$writer = Writer::createFromPath($path, 'w');
|
||||
if ($delimiter)
|
||||
$writer->setDelimiter($delimiter);
|
||||
if ($enclosure)
|
||||
$writer->setEnclosure($enclosure);
|
||||
if ($headers)
|
||||
$writer->insertOne($headers);
|
||||
|
||||
$writer->insertAll($contenido);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath
|
||||
* @return Reader
|
||||
* @throws InvalidArgument
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getReader(string $filePath): Reader
|
||||
{
|
||||
$csv = Reader::createFromPath($filePath);
|
||||
$csv->setDelimiter("|");
|
||||
$csv->setEnclosure("'");
|
||||
$csv->setHeaderOffset(0);
|
||||
return $csv;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Mpdf\Mpdf;
|
||||
use Mpdf\MpdfException;
|
||||
|
||||
class PdfHelper
|
||||
{
|
||||
/**
|
||||
* Requiere que el segundo argumento tenga definida la función generarHTML()
|
||||
* para crear la tabla con los datos del pedido que se inserta en el pdf.
|
||||
*
|
||||
* @return void
|
||||
* @throws MpdfException
|
||||
*/
|
||||
public static function exportarPedidos($filepath, $pedidos)
|
||||
{
|
||||
$mpdf = new Mpdf();
|
||||
|
||||
foreach ($pedidos as $pedido) {
|
||||
$html = $pedido->generarHTML();
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->AddPage();
|
||||
}
|
||||
|
||||
$mpdf->Output($filepath, 'D');
|
||||
}
|
||||
}
|
|
@ -1,258 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\TipoPedido;
|
||||
use Closure;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\InvalidArgument;
|
||||
|
||||
class PedidosExportHelper
|
||||
{
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function pedidosBarriales()
|
||||
{
|
||||
$filePath = "csv/exports/pedidos-por-barrio-" . now()->format('Y-m-d') . ".csv";
|
||||
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
|
||||
self::exportarCSV(
|
||||
$filePath,
|
||||
$barrios,
|
||||
self::generarContenidoCSV(
|
||||
$barrios,
|
||||
fn ($grupoId) =>
|
||||
"subpedidos.grupo_de_compra_id = $grupoId
|
||||
AND subpedidos.aprobado = 1
|
||||
AND subpedidos.tipo_pedido_id = 1"
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function pedidosDeOllas()
|
||||
{
|
||||
$filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv";
|
||||
$barrios = GrupoDeCompra::barriosMenosPrueba()
|
||||
->whereHas('subpedidos', function ($query) {
|
||||
$tipo_olla = self::getTipoId('olla');
|
||||
$query->where('tipo_pedido_id', $tipo_olla);
|
||||
})
|
||||
->get();
|
||||
|
||||
$contenido = self::generarContenidoCSV($barrios,
|
||||
fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId
|
||||
AND subpedidos.tipo_pedido_id = 2");
|
||||
$ollas = self::cantidadDeOllasParaCSV($barrios, $contenido);
|
||||
|
||||
self::exportarCSV(
|
||||
$filePath,
|
||||
$barrios,
|
||||
$contenido->concat([$ollas])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cantidadDeOllasParaCSV(Collection $barrios, Collection $contenido)
|
||||
{
|
||||
$tipo_olla = self::getTipoId('olla');
|
||||
|
||||
$parametros = collect(CsvHelper::getRecords(resource_path("csv/parametros.csv"), "No se pudo leer el archivo."));
|
||||
$fila = [
|
||||
"producto" => "Cantidad de ollas",
|
||||
"precio" => $parametros->where('id','monto-olla')->pluck('valor')->first(),
|
||||
"paga_transporte" => false,
|
||||
"fila" => $contenido->last()->fila + 1,
|
||||
];
|
||||
|
||||
foreach ($barrios as $barrio) {
|
||||
$pedido = $barrio->subpedidos()->where('tipo_pedido_id', $tipo_olla)->first();
|
||||
$fila[$barrio->nombre] = $pedido->cantidad_ollas;
|
||||
}
|
||||
|
||||
return (object) $fila;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function pedidoTotalDeBarrio(GrupoDeCompra $grupo)
|
||||
{
|
||||
$filePath = "csv/exports/" . $grupo->nombre . "-" . now()->format('Y-m-d') . ".csv";
|
||||
|
||||
$falsoBarrio = new GrupoDeCompra(['nombre' => 'Total']);
|
||||
$falsoBarrio->id = $grupo->id;
|
||||
$header = collect([$falsoBarrio]);
|
||||
|
||||
self::exportarCSV(
|
||||
$filePath,
|
||||
$header,
|
||||
self::generarContenidoCSV(
|
||||
$header,
|
||||
fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId
|
||||
AND subpedidos.aprobado = 1"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function pedidosDeBarrio(GrupoDeCompra $grupo)
|
||||
{
|
||||
$filePath = "csv/exports/" . $grupo->nombre . "-completo-" . now()->format('Y-m-d') . ".csv";
|
||||
$subpedidos = $grupo->subpedidos()->where('aprobado', true)->get();
|
||||
self::exportarCSV(
|
||||
$filePath,
|
||||
$subpedidos,
|
||||
self::generarContenidoCSV(
|
||||
$subpedidos,
|
||||
fn ($subpedidoId) => "subpedidos.id = $subpedidoId",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function exportarCSV(
|
||||
string $filename,
|
||||
Collection $headers,
|
||||
Collection $contenido
|
||||
): void {
|
||||
$nombresColumnas = $headers->pluck('nombre')->toArray();
|
||||
$columnas = array_merge(['Producto'], $nombresColumnas);
|
||||
$filaTransporte = TransporteHelper::filaTransporte();
|
||||
$planilla = [];
|
||||
$ultimaFila = 1;
|
||||
|
||||
foreach ($contenido as $fila) {
|
||||
$filaActual = $fila->fila;
|
||||
while ($filaActual - $ultimaFila > 1) {
|
||||
$ultimaFila++;
|
||||
$planilla[$ultimaFila] = [$ultimaFila === $filaTransporte ? 'Bono de transporte' : '---'];
|
||||
}
|
||||
$planilla[$filaActual] = [$fila->producto];
|
||||
foreach ($nombresColumnas as $nombre)
|
||||
$planilla[$filaActual][] = $fila->$nombre ?? 0;
|
||||
|
||||
$ultimaFila = $filaActual;
|
||||
}
|
||||
|
||||
$planilla[$filaTransporte] = array_merge(['Bono de transporte'], self::cantidadesTransporte($nombresColumnas, $contenido));
|
||||
|
||||
ksort($planilla);
|
||||
CsvHelper::generarCsv($filename, $planilla, $columnas);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $headers
|
||||
* @param Closure $filtroCallback
|
||||
* <br>
|
||||
* Ejemplo de uso:
|
||||
* ``
|
||||
* PedidosExportHelper::generarContenidoCSV(GrupoDeCompra::barriosMenosPrueba(),
|
||||
* fn($gdc_id) => "subpedidos.grupo_de_compra_id = $gdc_id");
|
||||
* ``
|
||||
* @return Collection
|
||||
* Los elementos son de la forma
|
||||
* {
|
||||
* fila: int (fila del producto),
|
||||
* producto: string (nombre del producto),
|
||||
* precio: float (precio del producto),
|
||||
* paga_transporte: bool (1 o 0, calculado a partir de bono y categoria),
|
||||
* barrio_1: string (cantidad pedida por barrio_1),
|
||||
* ...
|
||||
* barrio_n: string (cantidad pedida por barrio_n)
|
||||
* }
|
||||
*/
|
||||
public static function generarContenidoCSV(
|
||||
Collection $headers,
|
||||
Closure $filtroCallback
|
||||
): Collection {
|
||||
$expresionesColumnas = $headers->map(function ($header) use ($filtroCallback) {
|
||||
$id = $header['id'];
|
||||
$nombre = $header['nombre'];
|
||||
$filtro = $filtroCallback($id);
|
||||
return DB::raw("
|
||||
SUM(CASE WHEN $filtro THEN producto_subpedido.cantidad ELSE 0 END) as `$nombre`
|
||||
");
|
||||
})->toArray();
|
||||
|
||||
$query = DB::table('productos')
|
||||
->where('productos.nombre', 'not like', '%barrial%')
|
||||
->leftJoin('producto_subpedido', 'productos.id', '=', 'producto_subpedido.producto_id')
|
||||
->leftJoin('subpedidos', 'subpedidos.id', '=', 'producto_subpedido.subpedido_id');
|
||||
|
||||
$columnasProducto = [
|
||||
'productos.fila as fila',
|
||||
'productos.nombre as producto',
|
||||
'productos.precio as precio',
|
||||
self::pagaTransporte(),
|
||||
];
|
||||
|
||||
return $query->select(array_merge(
|
||||
$columnasProducto,
|
||||
$expresionesColumnas
|
||||
))->groupBy('productos.fila', 'productos.id', 'productos.nombre')
|
||||
->orderBy('productos.fila')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Expression
|
||||
*/
|
||||
public static function pagaTransporte(): Expression
|
||||
{
|
||||
return DB::raw('CASE WHEN productos.bono OR productos.categoria LIKE "%SUBSIDIADO%" THEN 0 ELSE 1 END as paga_transporte');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $nombresColumnas
|
||||
* @param Collection $contenido
|
||||
* @return array
|
||||
*/
|
||||
public static function cantidadesTransporte(array $nombresColumnas, Collection $contenido): array
|
||||
{
|
||||
$transporte = [];
|
||||
foreach ($nombresColumnas as $nombre) {
|
||||
$suma = 0;
|
||||
foreach ($contenido as $fila) {
|
||||
if ($fila->paga_transporte) {
|
||||
$cantidad = $fila->$nombre ?? 0;
|
||||
$precio = $fila->precio ?? 0;
|
||||
$suma += $cantidad * $precio;
|
||||
}
|
||||
}
|
||||
$transporte[] = TransporteHelper::cantidadTransporte($suma);
|
||||
}
|
||||
return $transporte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getTipoId(string $tipo)
|
||||
{
|
||||
$tipo_olla = TipoPedido::where('nombre', $tipo)->first()->id;
|
||||
return $tipo_olla;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\CanastaLog;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use InvalidArgumentException;
|
||||
use League\Csv\Exception;
|
||||
|
||||
class TransporteHelper
|
||||
{
|
||||
private const COSTO_TRANSPORTE = "bono-transporte";
|
||||
private const MONTO_TRANSPORTE = "monto-transporte";
|
||||
private static ?array $parametros = null;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cantidadTransporte($monto)
|
||||
{
|
||||
return ceil($monto / self::getParametro(self::MONTO_TRANSPORTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function totalTransporte($monto)
|
||||
{
|
||||
return self::cantidadTransporte($monto) * self::getParametro(self::COSTO_TRANSPORTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function filaTransporte()
|
||||
{
|
||||
$ultimaCanasta = CanastaLog::where('descripcion', CanastaHelper::CANASTA_CARGADA)
|
||||
->orderBy('created_at', 'desc')
|
||||
->pluck('path')
|
||||
->first();
|
||||
|
||||
$registros = CsvHelper::getRecords($ultimaCanasta, "No se encontró la ultima canasta.");
|
||||
$error = 'No hay fila de tipo T en la planilla: ' . $ultimaCanasta;
|
||||
|
||||
foreach ($registros as $key => $registro)
|
||||
if ($registro[CanastaHelper::TIPO] == 'T')
|
||||
return $key;
|
||||
|
||||
Log::error($error);
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getParametro(string $id): int
|
||||
{
|
||||
if (self::$parametros === null) {
|
||||
$records = CsvHelper::getRecords(resource_path('csv/parametros.csv'), "No se pudo leer el archivo.");
|
||||
self::$parametros = [];
|
||||
foreach ($records as $row) {
|
||||
self::$parametros[$row['id']] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(self::$parametros[$id])) {
|
||||
throw new InvalidArgumentException("Parámetro '$id' no encontrado.");
|
||||
}
|
||||
|
||||
return (int) self::$parametros[$id]['valor'];
|
||||
}
|
||||
|
||||
public static function resetParametros(): void {
|
||||
self::$parametros = null;
|
||||
}
|
||||
}
|
|
@ -2,62 +2,9 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\Helpers\PedidosExportHelper;
|
||||
use League\Csv\Exception;
|
||||
use Mpdf\MpdfException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return view('auth/login');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return view('auth/admin_subpedidos');
|
||||
}
|
||||
|
||||
public function exportarPedidosAPdf(GrupoDeCompra $gdc) {
|
||||
try {
|
||||
$gdc->exportarPedidosAPdf();
|
||||
return response();
|
||||
} catch (MpdfException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function exportarPedidoACSV(GrupoDeCompra $gdc)
|
||||
{
|
||||
try {
|
||||
PedidosExportHelper::pedidoTotalDeBarrio($gdc);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()]);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/'. $gdc->nombre . '-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
public function exportarPedidoConNucleosACSV(GrupoDeCompra $gdc)
|
||||
{
|
||||
try {
|
||||
PedidosExportHelper::pedidosDeBarrio($gdc);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()]);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/'.$gdc->nombre.'-completo-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
//
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\CanastaHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class CanastaController extends Controller
|
||||
{
|
||||
public function canastaActual() {
|
||||
return response()->json(CanastaHelper::canastaActual());
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\GrupoDeCompraComisionesResource;
|
||||
use App\Http\Resources\GrupoDeCompraResource;
|
||||
|
||||
class GrupoDeCompraController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return GrupoDeCompraResource::collection(GrupoDeCompra::all());
|
||||
}
|
||||
public function show(GrupoDeCompra $grupoDeCompra)
|
||||
{
|
||||
return new GrupoDeCompraResource($grupoDeCompra);
|
||||
}
|
||||
public function regiones()
|
||||
{
|
||||
return GrupoDeCompra::all()->pluck('region')->unique()->flatten();
|
||||
}
|
||||
|
||||
public function region(string $region)
|
||||
{
|
||||
return GrupoDeCompra::where('region', $region)->get();
|
||||
}
|
||||
|
||||
public function toggleDevoluciones(int $gdc) {
|
||||
GrupoDeCompra::find($gdc)->toggleDevoluciones();
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function setSaldo(int $gdc) {
|
||||
$valid = request()->validate([
|
||||
'saldo' => ['required', 'min:0'],
|
||||
]);
|
||||
$grupoDeCompra = GrupoDeCompra::find($gdc);
|
||||
$grupoDeCompra->setSaldo($valid['saldo']);
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function saldos()
|
||||
{
|
||||
return GrupoDeCompraComisionesResource::collection(GrupoDeCompra::all());
|
||||
}
|
||||
}
|
|
@ -2,21 +2,35 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Filtros\FiltroDeProducto;
|
||||
use App\Http\Resources\ProductoResource;
|
||||
use App\Producto;
|
||||
|
||||
class ProductoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mostrar una lista de productos.
|
||||
*
|
||||
* @param App\Filtros\FiltroDeProducto $filtros
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(FiltroDeProducto $filtros, Request $request)
|
||||
{
|
||||
return ProductoResource::collection(Producto::filtrar($filtros)->paginate(Producto::getPaginar($request)));
|
||||
}
|
||||
|
||||
public function categorias()
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Producto $producto
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Producto $producto)
|
||||
{
|
||||
return Producto::all()->pluck('categoria')->unique()->flatten();
|
||||
return new ProductoResource($producto);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,108 +3,54 @@
|
|||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Producto;
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Filtros\FiltroDeSubpedido;
|
||||
use App\Subpedido;
|
||||
use App\GrupoDeCompra;
|
||||
use App\Http\Resources\SubpedidoResource;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
|
||||
class SubpedidoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mostrar una lista de productos.
|
||||
*
|
||||
* @param App\Filtros\FiltroDeSubpedido $filtros
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(FiltroDeSubpedido $filtros, Request $request)
|
||||
{
|
||||
return Subpedido::filtrar($filtros)->select('id','nombre')->get();
|
||||
return Subpedido::filtrar($filtros)->get();
|
||||
}
|
||||
|
||||
public function indexResources(FiltroDeSubpedido $filtros, Request $request)
|
||||
{
|
||||
return SubpedidoResource::collection(Subpedido::filtrar($filtros)->get());
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validado = $this->validateSubpedido();
|
||||
|
||||
if (Subpedido::where([
|
||||
"nombre" => $validado["nombre"],
|
||||
"tipo_pedido_id" => $validado["tipo_id"],
|
||||
"grupo_de_compra_id" => $validado["grupo_de_compra_id"]])
|
||||
->get()
|
||||
->count())
|
||||
throw new HttpException(400, "Ya existe un pedido con este nombre");
|
||||
|
||||
$pedido = new Subpedido();
|
||||
$pedido->nombre = $validado["nombre"];
|
||||
$pedido->grupo_de_compra_id = $validado["grupo_de_compra_id"];
|
||||
$pedido->tipo_pedido_id = $validado["tipo_id"];
|
||||
$pedido->save();
|
||||
|
||||
return $this->show($pedido);
|
||||
if (Subpedido::where("nombre",$validado["nombre"])->where("grupo_de_compra_id",$validado["grupo_de_compra_id"])->get()->count()) {
|
||||
throw new HttpException(400, "Ya existe un subpedido con este nombre");
|
||||
}
|
||||
$s = new Subpedido();
|
||||
$s->nombre = $validado["nombre"];
|
||||
$s->grupo_de_compra_id = $validado["grupo_de_compra_id"];
|
||||
$s->save();
|
||||
return $s;
|
||||
}
|
||||
|
||||
protected function validateSubpedido(): array
|
||||
{
|
||||
protected function validateSubpedido(){
|
||||
return request()->validate([
|
||||
'nombre' => 'required|max:255',
|
||||
'grupo_de_compra_id' => [
|
||||
'required',
|
||||
Rule::in(GrupoDeCompra::all()->pluck('id')),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
Rule::in(TipoPedido::all()->pluck('id')),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Subpedido $subpedido)
|
||||
{
|
||||
return new SubpedidoResource($subpedido);
|
||||
}
|
||||
|
||||
// recibe request, saca producto y cantidad, valida, y pasa a syncProducto en Subpedido
|
||||
public function syncProductos(Subpedido $subpedido) {
|
||||
if ($subpedido->aprobado)
|
||||
abort(400, "No se puede modificar un pedido aprobado.");
|
||||
|
||||
$valid = request()->validate([
|
||||
'cantidad' => ['integer','required','min:0'],
|
||||
'notas' => 'nullable',
|
||||
'producto_id' => [
|
||||
'required',
|
||||
Rule::in(Producto::all()->pluck('id')),
|
||||
]
|
||||
]);
|
||||
|
||||
$producto = Producto::find($valid['producto_id']);
|
||||
$notas = $valid['notas'];
|
||||
$cantidad = $valid['cantidad'];
|
||||
$subpedido->syncProducto($producto, $cantidad, $notas ?? "");
|
||||
return new SubpedidoResource($subpedido);
|
||||
}
|
||||
|
||||
public function toggleAprobacion(Subpedido $subpedido) {
|
||||
$valid = request()->validate([
|
||||
'aprobacion' => 'required | boolean'
|
||||
]);
|
||||
$subpedido->toggleAprobacion($valid['aprobacion']);
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function syncDevoluciones(Subpedido $subpedido) {
|
||||
if ($subpedido->aprobado)
|
||||
abort(400, "No se puede modificar un pedido aprobado.");
|
||||
|
||||
$valid = request()->validate([
|
||||
'total' => 'required|min:0',
|
||||
'notas' => 'min:0'
|
||||
]);
|
||||
$subpedido->syncDevoluciones($valid['total'], $valid['notas'] ?? "");
|
||||
|
||||
return new SubpedidoResource($subpedido);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace App\Http\Controllers\Auth;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
@ -28,11 +28,6 @@ class LoginController extends Controller
|
|||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\Helpers\CanastaHelper;
|
||||
use App\Helpers\CsvHelper;
|
||||
use App\Helpers\PedidosExportHelper;
|
||||
use App\Helpers\TransporteHelper;
|
||||
use App\Http\Resources\GrupoDeCompraResource;
|
||||
use App\Producto;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\InvalidArgument;
|
||||
use Mpdf\MpdfException;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class ComisionesController
|
||||
{
|
||||
const PARAMETROS_PATH = 'csv/parametros.csv';
|
||||
const CANASTAS_PATH = 'csv/canastas/';
|
||||
const BARRIO = "Barrio";
|
||||
const SALDO = "Saldo";
|
||||
|
||||
public function show()
|
||||
{
|
||||
return view('auth/login');
|
||||
}
|
||||
|
||||
public function descargarPedidos()
|
||||
{
|
||||
try {
|
||||
PedidosExportHelper::pedidosBarriales();
|
||||
} catch (CannotInsertRecord|InvalidArgument|Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/pedidos-por-barrio-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
public function descargarPedidosDeOllas()
|
||||
{
|
||||
try {
|
||||
PedidosExportHelper::pedidosDeOllas();
|
||||
} catch (CannotInsertRecord|InvalidArgument|Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/pedidos-de-ollas-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
public function descargarNotas()
|
||||
{
|
||||
try {
|
||||
Producto::planillaNotas();
|
||||
} catch (CannotInsertRecord|InvalidArgument $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/notas-por-barrio-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
public function pdf() {
|
||||
try {
|
||||
GrupoDeCompra::exportarPedidosBarrialesAPdf();
|
||||
return response();
|
||||
} catch (MpdfException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function cargarCanasta(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'data' => 'required|file|mimes:csv,txt|max:2048',
|
||||
]);
|
||||
|
||||
$nombre = CanastaHelper::guardarCanasta($request->file('data'), self::CANASTAS_PATH);
|
||||
try {
|
||||
CanastaHelper::cargarCanasta(storage_path(self::CANASTAS_PATH . $nombre));
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Canasta cargada exitosamente',
|
||||
]);
|
||||
}
|
||||
|
||||
public function descargarCanastaEjemplo(): BinaryFileResponse
|
||||
{
|
||||
$file = resource_path('csv/productos.csv');
|
||||
return response()->download($file);
|
||||
}
|
||||
|
||||
public function cargarSaldos(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'data' => 'required|file|mimes:csv,txt|max:2048',
|
||||
]);
|
||||
|
||||
$file = $request->file('data')->getPathname();
|
||||
|
||||
try {
|
||||
$records = CsvHelper::getRecords($file, "No se pudo leer el archivo.");
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
$barrio = $record[self::BARRIO];
|
||||
$saldo = $record[self::SALDO];
|
||||
GrupoDeCompra::where('nombre', $barrio)
|
||||
->update(['saldo' => $saldo]);
|
||||
}
|
||||
|
||||
return response()->json(GrupoDeCompraResource::collection(GrupoDeCompra::all()));
|
||||
}
|
||||
|
||||
public function descargarSaldosEjemplo(): BinaryFileResponse
|
||||
{
|
||||
$file = resource_path('csv/saldos.csv');
|
||||
return response()->download($file);
|
||||
}
|
||||
|
||||
public function obtenerParametros(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$records = self::parametrosRecords();
|
||||
$result = [];
|
||||
foreach ($records as $record)
|
||||
$result[] = $record;
|
||||
return response()->json($result);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function modificarParametros(string $parametro_id, Request $request) {
|
||||
try {
|
||||
if (collect(self::parametrosRecords())
|
||||
->contains('id', $parametro_id)) {
|
||||
$valid = $request->validate([
|
||||
'valor' => ['required', 'numeric', 'gte:0'],
|
||||
]);
|
||||
CsvHelper::cambiarParametro($parametro_id, $valid['valor']);
|
||||
TransporteHelper::resetParametros();
|
||||
return response()->noContent();
|
||||
}
|
||||
return response()->json(['message' => 'Parametro no encontrado.'], 404);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function parametrosRecords(): array
|
||||
{
|
||||
$records = CsvHelper::getRecords(resource_path(self::PARAMETROS_PATH), "No se pudo leer el archivo.");
|
||||
return iterator_to_array($records);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\Http\Resources\PedidoOllasResource;
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OllasController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return view('auth/login');
|
||||
}
|
||||
|
||||
public function pedido(GrupoDeCompra $gdc)
|
||||
{
|
||||
$tipoOlla = TipoPedido::firstOrCreate(['nombre' => 'olla']);
|
||||
$pedido = $gdc->subpedidos()->firstOrCreate([
|
||||
'nombre' => 'Pedido de Ollas de ' . $gdc->nombre,
|
||||
'tipo_pedido_id' => $tipoOlla->id,
|
||||
]);
|
||||
if (!$pedido->cantidad_ollas) {
|
||||
$pedido->cantidad_ollas = 0;
|
||||
$pedido->save();
|
||||
}
|
||||
return response()->json(new PedidoOllasResource($pedido));
|
||||
}
|
||||
|
||||
public function actualizarCantidadOllas(GrupoDeCompra $gdc, Request $request)
|
||||
{
|
||||
$valid = $request->validate([
|
||||
'cantidad' => 'required|numeric|min:0',
|
||||
]);
|
||||
$pedido = $gdc->subpedidos()->where([
|
||||
'nombre' => 'Pedido de Ollas de ' . $gdc->nombre
|
||||
])->first();
|
||||
$pedido->cantidad_ollas = $valid['cantidad'];
|
||||
$pedido->save();
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductoController extends Controller
|
||||
{
|
||||
/**
|
||||
|
@ -14,6 +16,11 @@ class ProductoController extends Controller
|
|||
$this->middleware(['auth','subpedido']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('productos');
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\UserRole;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RouteController extends Controller
|
||||
{
|
||||
function home(Request $request) {
|
||||
if (!Auth::check())
|
||||
return redirect('/login');
|
||||
|
||||
$barrio = UserRole::where('nombre', 'barrio')->first();
|
||||
$admin = UserRole::where('nombre', 'admin_barrio')->first();
|
||||
$comision = UserRole::where('nombre', 'comision')->first();
|
||||
$ollas = UserRole::where('nombre', 'ollas')->first();
|
||||
|
||||
switch ($request->user()->role_id) {
|
||||
case $barrio->id:
|
||||
return redirect('/pedido');
|
||||
case $admin->id:
|
||||
return redirect('/admin');
|
||||
case $comision->id:
|
||||
return redirect('/comisiones');
|
||||
case $ollas->id:
|
||||
return redirect('/ollas');
|
||||
default:
|
||||
abort(400, 'Rol de usuario invalido');
|
||||
}
|
||||
}
|
||||
|
||||
function main(Request $request) {
|
||||
return view('main');
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Subpedido;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SessionController extends Controller
|
||||
{
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$grupo_de_compra_id = Auth::user()->grupo_de_compra_id;
|
||||
$validated = $request->validate([
|
||||
'id' => 'required',
|
||||
Rule::in(Subpedido::where('grupo_de_compra_id', $grupo_de_compra_id)->pluck('id')),
|
||||
]);
|
||||
session()->put('pedido_id', $validated["id"]);
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function fetch(): JsonResponse
|
||||
{
|
||||
return response()->json(['id' => session('pedido_id')]);
|
||||
}
|
||||
|
||||
public function destroy(): Response
|
||||
{
|
||||
session()->forget('pedido_id');
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\Http\Resources\GrupoDeCompraPedidoResource;
|
||||
use App\Http\Resources\GrupoDeCompraResource;
|
||||
use App\UserRole;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function user(Request $request)
|
||||
{
|
||||
return ['user' => $request->user()->name];
|
||||
}
|
||||
|
||||
public function rol(Request $request) {
|
||||
return ["rol" => UserRole::find($request->user()->role_id)->nombre];
|
||||
}
|
||||
|
||||
public function grupoDeCompra(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$result = [ 'grupo_de_compra' => null, ];
|
||||
$grupo_de_compra = GrupoDeCompra::find($user->grupo_de_compra_id);
|
||||
switch (UserRole::findOrFail($user->role_id)->nombre) {
|
||||
case 'ollas':
|
||||
case 'barrio':
|
||||
$result['grupo_de_compra'] = new GrupoDeCompraPedidoResource($grupo_de_compra);
|
||||
break;
|
||||
case 'admin_barrio':
|
||||
$result['grupo_de_compra'] = new GrupoDeCompraResource($grupo_de_compra);
|
||||
break;
|
||||
case 'comision':
|
||||
break;
|
||||
default:
|
||||
abort(400, 'Rol invalido.');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\CheckRole;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
|
||||
|
||||
|
@ -18,7 +17,7 @@ class Kernel extends HttpKernel
|
|||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
|
@ -57,7 +56,6 @@ class Kernel extends HttpKernel
|
|||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'role' => \App\Http\Middleware\CheckRole::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
|
|
|
@ -3,28 +3,19 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request): string
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (!$request->expectsJson()) {
|
||||
$path = $request->path();
|
||||
if (preg_match('~^admin.*~i', $path))
|
||||
return route('admin.login');
|
||||
if (preg_match('~^comisiones.*~i', $path))
|
||||
return route('comisiones.login');
|
||||
if (preg_match('~^ollas.*~i', $path))
|
||||
return route('ollas.login');
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\UserRole;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckRole
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string $role
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $role)
|
||||
{
|
||||
$role_id = UserRole::where('nombre', $role)->first()->id;
|
||||
return $request->user()->role_id == $role_id ? $next($request)
|
||||
: response('No tenés permiso para esto.', 403);
|
||||
}
|
||||
}
|
|
@ -3,18 +3,17 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Subpedido
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!session('subpedido_nombre') || !session('subpedido_id')) {
|
||||
return redirect()->route('subpedidos.create');
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
|
@ -19,8 +19,5 @@ class TrustProxies extends Middleware
|
|||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO;
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class GrupoDeCompraComisionesResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'saldo' => $this->saldo,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class GrupoDeCompraPedidoResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class GrupoDeCompraResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
|
||||
'pedidos' => SubpedidoResource::collection($this->pedidosHogares()),
|
||||
'total_a_recaudar' => number_format($this->totalARecaudar(),2),
|
||||
'saldo' => number_format($this->saldo, 2, ".", ""),
|
||||
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
|
||||
'total_barrial' => number_format($this->totalBarrial(),2),
|
||||
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
|
||||
'total_de_pedido' => number_format($this->totalDePedido(),2),
|
||||
'total_a_transferir' => number_format($this->totalATransferir(),2),
|
||||
'total_transporte' => number_format($this->totalTransporte()),
|
||||
'cantidad_transporte' => number_format($this->cantidadTransporte()),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PedidoOllasResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
$productos = $this->productos;
|
||||
foreach ($productos as $producto) {
|
||||
$producto['pivot']['total'] = number_format($producto->pivot->cantidad * $producto->precio, 2);
|
||||
}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'productos' => $productos,
|
||||
'total' => number_format($this->totalCentralesSinTransporte(),2),
|
||||
'cantidad_de_ollas' => $this->cantidad_ollas,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductoResource extends JsonResource
|
||||
|
@ -10,19 +9,23 @@ class ProductoResource extends JsonResource
|
|||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'precio' => $this->precio,
|
||||
'categoria' => $this->categoria,
|
||||
'economia_solidaria' => $this->es_solidario,
|
||||
'nacional' => $this->es_solidario,
|
||||
'requiere_notas' => $this->requiere_notas,
|
||||
'proveedor' => optional($this->proveedor)->nombre,
|
||||
'economia_solidaria' => optional($this->proveedor)->economia_solidaria,
|
||||
'nacional' => optional($this->proveedor)->nacional,
|
||||
'imagen' => optional($this->poster)->url(),
|
||||
'descripcion' => $this->descripcion,
|
||||
'apto_veganxs' => $this->apto_veganxs,
|
||||
'apto_celiacxs' => $this->apto_celiacxs
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SubpedidoResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
$productos = $this->productos;
|
||||
foreach ($productos as $producto) {
|
||||
$producto['pivot']['total'] = number_format($producto->pivot->cantidad * $producto->precio, 2);
|
||||
}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'productos' => $productos,
|
||||
'aprobado' => (bool) $this->aprobado,
|
||||
'total' => number_format($this->total(),2),
|
||||
'total_transporte' => number_format($this->totalTransporte()),
|
||||
'cantidad_transporte' => number_format($this->cantidadTransporte()),
|
||||
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
|
||||
'devoluciones_total' => number_format($this->devoluciones_total,2),
|
||||
'devoluciones_notas' => $this->devoluciones_notas,
|
||||
'tipo' => [
|
||||
'id' => $this->tipo_pedido_id,
|
||||
'nombre' => TipoPedido::find($this->tipo_pedido_id)->nombre
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
116
app/Producto.php
116
app/Producto.php
|
@ -2,105 +2,35 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Filtros\FiltroDeProducto;
|
||||
use App\Helpers\CsvHelper;
|
||||
use App\Helpers\TransporteHelper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\InvalidArgument;
|
||||
use App\Filtros\FiltroDeProducto;
|
||||
|
||||
class Producto extends Model
|
||||
{
|
||||
protected $fillable = ["nombre", "precio", "categoria", "bono", "es_solidario", "requiere_notas"];
|
||||
public $timestamps = false;
|
||||
protected $fillable = [ "nombre", "precio", "presentacion", "stock", "categoria" ];
|
||||
static $paginarPorDefecto = 10;
|
||||
|
||||
public function subpedidos(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Subpedido::class, 'productos_subpedidos')
|
||||
->withPivot(["cantidad", "notas"]);
|
||||
}
|
||||
public function subpedidos()
|
||||
{
|
||||
return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]);
|
||||
}
|
||||
|
||||
public function proveedor()
|
||||
{
|
||||
return $this->belongsTo('App\Proveedor');
|
||||
}
|
||||
|
||||
public function scopeFiltrar($query, FiltroDeProducto $filtros): Builder
|
||||
{
|
||||
return $filtros->aplicar($query);
|
||||
}
|
||||
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
public function scopeFiltrar($query, FiltroDeProducto $filtros)
|
||||
{
|
||||
return $filtros->aplicar($query);
|
||||
}
|
||||
|
||||
public static function getPaginar(Request $request): int
|
||||
{
|
||||
return $request->has('paginar') && intval($request->input('paginar')) ?
|
||||
intval($request->input('paginar')) :
|
||||
self::all()->count();
|
||||
}
|
||||
|
||||
public static function productosFilaID()
|
||||
{
|
||||
return self::noBarriales()->pluck('id', 'fila')->all();
|
||||
}
|
||||
|
||||
public static function productosIDFila()
|
||||
{
|
||||
return self::noBarriales()->pluck('fila', 'id')->all();
|
||||
}
|
||||
|
||||
public static function productosIDNombre()
|
||||
{
|
||||
return self::noBarriales()->pluck('nombre', 'id')->all();
|
||||
}
|
||||
|
||||
public static function noBarriales()
|
||||
{
|
||||
return self::where('nombre', 'not like', '%barrial%');
|
||||
}
|
||||
|
||||
public static function notasPorBarrio(): Collection
|
||||
{
|
||||
return DB::table('productos')
|
||||
->where('productos.nombre', 'not like', '%barrial%')
|
||||
->join('producto_subpedido', 'productos.id', '=', 'producto_subpedido.producto_id')
|
||||
->join('subpedidos', 'producto_subpedido.subpedido_id', '=', 'subpedidos.id')
|
||||
->join('grupos_de_compra', 'subpedidos.grupo_de_compra_id', '=', 'grupos_de_compra.id')
|
||||
->where('productos.requiere_notas', 1)
|
||||
->where('subpedidos.tipo_pedido_id', '=', 1)
|
||||
->select(
|
||||
'productos.nombre as producto',
|
||||
'grupos_de_compra.nombre as barrio',
|
||||
'producto_subpedido.notas'
|
||||
)
|
||||
->get()
|
||||
->groupBy('producto');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
*/
|
||||
static public function planillaNotas() {
|
||||
$headers = ['Producto'];
|
||||
$barrios = GrupoDeCompra::barriosMenosPrueba()
|
||||
->pluck('nombre')->toArray();
|
||||
$headers = array_merge($headers, $barrios);
|
||||
|
||||
$notasPorBarrio = self::notasPorBarrio();
|
||||
$planilla = [];
|
||||
|
||||
foreach ($notasPorBarrio as $producto => $notasGrupo) {
|
||||
$fila = [$producto];
|
||||
foreach ($barrios as $barrio) {
|
||||
$notas = $notasGrupo->where('barrio', $barrio)
|
||||
->pluck('notas')
|
||||
->implode('; ');
|
||||
$fila[] = $notas ?: '';
|
||||
}
|
||||
$planilla[] = $fila;
|
||||
}
|
||||
|
||||
$fecha = now()->format('Y-m-d');
|
||||
$filePath = 'csv/exports/notas-por-barrio-' . $fecha . '.csv';
|
||||
CsvHelper::generarCsv($filePath, $planilla, $headers);
|
||||
}
|
||||
public static function getPaginar(Request $request)
|
||||
{
|
||||
return $request->has('paginar') && intval($request->input('paginar')) ? intval($request->input('paginar')) : self::$paginarPorDefecto;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
17
app/Proveedor.php
Normal file
17
app/Proveedor.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Proveedor extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $fillable = [ "nombre","direccion","telefono","correo","comentario" ];
|
||||
protected $table = 'proveedores';
|
||||
|
||||
public function productos()
|
||||
{
|
||||
return $this->hasMany('App\Producto');
|
||||
}
|
||||
}
|
|
@ -2,149 +2,31 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Helpers\TransporteHelper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use League\Csv\Reader;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
use App\Filtros\FiltroDeSubpedido;
|
||||
|
||||
class Subpedido extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'grupo_de_compra_id',
|
||||
'aprobado',
|
||||
'nombre',
|
||||
'devoluciones_total',
|
||||
'devoluciones_notas',
|
||||
'tipo_pedido_id',
|
||||
'cantidad_ollas'
|
||||
];
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre'];
|
||||
|
||||
public function productos(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Producto::class)->withPivot(["cantidad", "notas"]);
|
||||
}
|
||||
public function productos()
|
||||
{
|
||||
return $this->belongsToMany('App\Producto','pedidos_productos')->withPivot(["cantidad"]);
|
||||
}
|
||||
|
||||
public function grupoDeCompra(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(GrupoDeCompra::class);
|
||||
}
|
||||
public function grupoDeCompra()
|
||||
{
|
||||
return $this->belongsTo('App\GrupoDeCompra');
|
||||
}
|
||||
|
||||
public function tipoPedido(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TipoPedido::class);
|
||||
}
|
||||
//Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
public function scopeFiltrar($query, FiltroDeSubpedido $filtros)
|
||||
{
|
||||
return $filtros->aplicar($query);
|
||||
}
|
||||
|
||||
// Permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
public function scopeFiltrar($query, FiltroDeSubpedido $filtros): Builder
|
||||
{
|
||||
return $filtros->aplicar($query);
|
||||
}
|
||||
|
||||
public function total()
|
||||
{
|
||||
return $this->totalSinDevoluciones() - $this->devoluciones_total;
|
||||
}
|
||||
|
||||
public function totalSinDevoluciones()
|
||||
{
|
||||
return $this->totalBarrial() + $this->totalCentral();
|
||||
}
|
||||
|
||||
public function totalBarrial()
|
||||
{
|
||||
return DB::table('producto_subpedido')
|
||||
->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id')
|
||||
->where('producto_subpedido.subpedido_id', $this->id)
|
||||
->where('productos.nombre', 'like', '%barrial%')
|
||||
->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total')
|
||||
->value('total');
|
||||
}
|
||||
|
||||
public function totalCentral()
|
||||
{
|
||||
return $this->totalCentralesSinTransporte() + $this->totalTransporte();
|
||||
}
|
||||
|
||||
public function totalCentralesSinTransporte() {
|
||||
return $this->totalCentralesQueNoPaganTransporte() + $this->totalCentralesQuePaganTransporte();
|
||||
}
|
||||
|
||||
public function totalCentralesQueNoPaganTransporte()
|
||||
{
|
||||
return DB::table('producto_subpedido')
|
||||
->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id')
|
||||
->where('producto_subpedido.subpedido_id', $this->id)
|
||||
->where('productos.nombre', 'not like', '%barrial%')
|
||||
->where(function ($query) {
|
||||
$query->where('productos.categoria', 'like', '%SUBSIDIADO%')
|
||||
->orWhere('productos.bono', true);
|
||||
})
|
||||
->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total')
|
||||
->value('total');
|
||||
}
|
||||
|
||||
public function totalCentralesQuePaganTransporte()
|
||||
{
|
||||
return DB::table('producto_subpedido')
|
||||
->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id')
|
||||
->where('producto_subpedido.subpedido_id', $this->id)
|
||||
->where('productos.nombre', 'not like', '%barrial%')
|
||||
->where('productos.bono', false)
|
||||
->where('productos.categoria', 'not like', '%SUBSIDIADO%')
|
||||
->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total')
|
||||
->value('total');
|
||||
}
|
||||
|
||||
public function totalTransporte()
|
||||
{
|
||||
return TransporteHelper::totalTransporte($this->totalCentralesQuePaganTransporte());
|
||||
}
|
||||
|
||||
public function cantidadTransporte()
|
||||
{
|
||||
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.
|
||||
public function syncProducto(Producto $producto, int $cantidad, string $notas)
|
||||
{
|
||||
if ($cantidad) {
|
||||
//si la cantidad es 1 o más se agrega el producto o actualiza la cantidad
|
||||
$this->productos()->syncWithoutDetaching([
|
||||
$producto->id => [
|
||||
'cantidad' => $cantidad,
|
||||
'notas' => $notas,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
//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();
|
||||
}
|
||||
|
||||
public function generarHTML()
|
||||
{
|
||||
$view = view("pdfgen.pedido_tabla", ["pedido" => $this]);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function syncDevoluciones(float $total, string $notas)
|
||||
{
|
||||
$this->devoluciones_total = $total;
|
||||
$this->devoluciones_notas = $notas;
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TipoPedido extends Model
|
||||
{
|
||||
protected $fillable = ["nombre"];
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
|
@ -16,7 +16,7 @@ class User extends Authenticatable
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'role_id',
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -38,8 +38,8 @@ class User extends Authenticatable
|
|||
];
|
||||
|
||||
|
||||
public function grupoDeCompra(): BelongsTo
|
||||
public function grupoDeCompra()
|
||||
{
|
||||
return $this->belongsTo(GrupoDeCompra::class);
|
||||
return $this->belongsTo('App\GrupoDeCompra');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.3",
|
||||
"doctrine/dbal": "^3.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"laravel/framework": "^12.0",
|
||||
"laravel/sanctum": "^4.0",
|
||||
"laravel/tinker": "^2.8",
|
||||
"laravel/ui": "^4.3",
|
||||
"league/csv": "^9.8",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
"prexview/prexview": "^1.1"
|
||||
"php": "^7.2.5|^8.0",
|
||||
"fideloper/proxy": "^4.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
|
||||
"laravel/framework": "^7.29",
|
||||
"laravel/sanctum": "^2.13",
|
||||
"laravel/tinker": "^2.5",
|
||||
"laravel/ui": "*",
|
||||
"league/csv": "^9.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"facade/ignition": "^2.0",
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"nunomaduro/collision": "^8.0"
|
||||
"nunomaduro/collision": "^4.3"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
|
|
4918
composer.lock
generated
4918
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -67,7 +67,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'America/Montevideo',
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
/** @var Factory $factory */
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use App\User;
|
||||
use Faker\Generator as Faker;
|
||||
use Illuminate\Database\Eloquent\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/*
|
||||
|
|
|
@ -19,8 +19,6 @@ class CreateUsersTable extends Migration
|
|||
$table->string('email')->unique()->nullable();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->foreignId('grupo_de_compra_id')->nullable();
|
||||
$table->boolean('is_admin');
|
||||
$table->unique(['name', 'is_admin']);
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
|
|
|
@ -17,7 +17,7 @@ class CreateSubpedidosTable extends Migration
|
|||
$table->id();
|
||||
$table->string('nombre');
|
||||
$table->foreignId('grupo_de_compra_id');
|
||||
$table->boolean('aprobado')->default(false);
|
||||
$table->boolean('aprobado')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarColumnaBonoATablaDeProductos extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->boolean('bono')->after('apto_celiacxs');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('bono');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarColumnaTotalATablaDeProductoSubpedido extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->double('total',10,2)->after('cantidad')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->dropColumn('total');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarColumnaFilaEnPlanillaATablaDeProductos extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->integer('fila')->after('id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('fila');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CallCrearPedidosAprobados extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Artisan::call("view:CrearPedidosAprobadosView");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DevolucionesPedido extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->double('devoluciones_total', 10, 2)->default(0);
|
||||
$table->string('devoluciones_notas')->default("");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->dropColumn('devoluciones_total');
|
||||
$table->dropColumn('devoluciones_notas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class HabilitarDevoluciones extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->boolean('devoluciones_habilitadas')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->dropColumn('devoluciones_habilitadas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarIsComprasAUser extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('is_compras')->after('is_admin')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('is_compras');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class NotasProducto extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->string('notas')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->dropColumn('notas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ProductoRequiereNotas extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->boolean('requiere_notas')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('requiere_notas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CrearCargaDeCanastas extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('carga_de_canastas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('path');
|
||||
$table->string('descripcion');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('carga_de_canastas');
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class CallAgregarEsBonoAPedidosAprobados extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Artisan::call("command:AgregarEsBonoAPedidosAprobados");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUserRolesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nombre');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$tipos = ["barrio", "admin_barrio", "comision"];
|
||||
foreach ($tipos as $tipo) {
|
||||
UserRole::create([
|
||||
"nombre" => $tipo,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_roles');
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarRolAUser extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->foreignId('role_id');
|
||||
});
|
||||
|
||||
$barrio = UserRole::where('nombre', 'barrio')->first();
|
||||
$admin_barrio = UserRole::where('nombre', 'admin_barrio')->first();
|
||||
$comision = UserRole::where('nombre', 'comision')->first();
|
||||
User::all()->each(function($user) use ($barrio, $comision, $admin_barrio) {
|
||||
$user->role_id = $user->is_admin ? $admin_barrio->id :
|
||||
($user->is_compras ? $comision->id : $barrio->id);
|
||||
$user->save();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('user', function (Blueprint $table) {
|
||||
$table->dropForeign('role_id');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SimplificarUsers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['is_admin', 'is_compras']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('is_admin')->default(false);
|
||||
$table->boolean('is_compras')->default(false);
|
||||
});
|
||||
|
||||
$admin_barrio = UserRole::where('nombre', 'admin_barrio')->first();
|
||||
$comision = UserRole::where('nombre', 'comision')->first();
|
||||
foreach (User::all() as $user) {
|
||||
$user->is_admin = $user->role_id == $admin_barrio->id;
|
||||
$user->is_compras = $user->role_id == $comision->id;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SimplificarBarrios extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'cantidad_de_nucleos',
|
||||
'telefono',
|
||||
'correo',
|
||||
'referente_finanzas',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->double('cantidad_de_nucleos');
|
||||
$table->string('telefono');
|
||||
$table->string('correo');
|
||||
$table->string('referente_finanzas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SimplificarProductos extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'presentacion',
|
||||
'stock',
|
||||
'imagen_id',
|
||||
'descripcion',
|
||||
'apto_veganxs',
|
||||
'apto_celiacxs',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->integer('presentacion')->nullable();
|
||||
$table->integer('stock')->nullable();
|
||||
$table->foreignId('imagen_id')->nullable();
|
||||
$table->string('descripcion')->nullable();
|
||||
$table->boolean('apto_veganxs')->nullable();
|
||||
$table->boolean('apto_celiacxs')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SimplificarProductoSubpedido extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->dropColumn('total');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('producto_subpedido', function (Blueprint $table) {
|
||||
$table->double('total');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Producto;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarEsSolidario extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->boolean('es_solidario')->default(false);
|
||||
});
|
||||
|
||||
foreach (Producto::all() as $producto) {
|
||||
$producto->es_solidario = $producto->proveedor_id != null;
|
||||
$producto->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('es_solidario');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Producto;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class EliminarProveedor extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->dropColumn('proveedor_id');
|
||||
});
|
||||
Schema::dropIfExists('proveedores');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('proveedores', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nombre');
|
||||
$table->string('direccion')->nullable();
|
||||
$table->string('telefono')->nullable();
|
||||
$table->string('correo')->nullable();
|
||||
$table->boolean('economia_solidaria')->nullable();
|
||||
$table->boolean('nacional')->nullable();
|
||||
$table->text('detalles_de_pago')->nullable();
|
||||
$table->text('comentario')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->foreignId('proveedor_id')->nullable();
|
||||
});
|
||||
|
||||
$proveedor_id = DB::table('proveedores')->insertGetId([
|
||||
['nombre' => 'Proveedor de economía solidaria',
|
||||
'economia_solidaria' => 1,
|
||||
'nacional' => 1]
|
||||
]);
|
||||
|
||||
foreach (Producto::all() as $producto) {
|
||||
$producto->proveedor_id = $producto->es_solidario ? $proveedor_id : null;
|
||||
$producto->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class EliminarAdmin extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('admins');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('admins', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nombre');
|
||||
$table->foreignId('grupo_de_compra_id');
|
||||
$table->string('email');
|
||||
$table->string('contrasena');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class HacerFilaNullable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->integer('fila')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('productos', function (Blueprint $table) {
|
||||
$table->integer('fila')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class QuitarPasswordDeGrupoDeCompra extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->dropColumn('password');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->string('password')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AgregarSaldosABarrios extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Agregar columna 'saldo' a la tabla 'grupos_de_compra'
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->double('saldo', 10, 2)->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// Remover columna 'saldo' de la tabla 'grupos_de_compra'
|
||||
Schema::table('grupos_de_compra', function (Blueprint $table) {
|
||||
$table->dropColumn('saldo');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTipoPedidosTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tipo_pedidos', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("nombre");
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$hogar = TipoPedido::firstOrCreate(['nombre' => 'hogar']);
|
||||
TipoPedido::firstOrCreate(['nombre' => 'olla']);
|
||||
|
||||
Schema::table('subpedidos', function (Blueprint $table) use ($hogar) {
|
||||
$table->foreignId('tipo_pedido_id')->default($hogar->id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tipo_pedidos');
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->dropColumn('tipo_pedido_id');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserRoleOllas extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$ollasRol = UserRole::firstOrCreate(['nombre' => 'ollas']);
|
||||
$barrios = GrupoDeCompra::all();
|
||||
foreach ($barrios as $barrio) {
|
||||
$barrio->users()->firstOrCreate([
|
||||
'name' => $barrio->nombre . '_ollas',
|
||||
'password' => Hash::make('123'),
|
||||
'role_id' => $ollasRol->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$ollasRol = UserRole::where('nombre', 'ollas')->firstOrFail();
|
||||
User::where('role_id', $ollasRol->id)->delete();
|
||||
$ollasRol->delete();
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CantidadOllasPedidos extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->integer('cantidad_ollas')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->dropColumn('cantidad_ollas');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Helpers\CanastaHelper;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class CanastaSeeder extends Seeder
|
||||
{
|
||||
const ARCHIVO_DEFAULT = 'csv/productos.csv';
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
* @throws \League\Csv\Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
CanastaHelper::cargarCanasta(resource_path(self::ARCHIVO_DEFAULT));
|
||||
}
|
||||
}
|
|
@ -1,19 +1,10 @@
|
|||
<?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.
|
||||
*
|
||||
|
@ -21,9 +12,7 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->call(CanastaSeeder::class);
|
||||
$this->call(GrupoDeCompraSeeder::class);
|
||||
$this->call(UserSeeder::class);
|
||||
$this->call(UsuarioOllasSeeder::class);
|
||||
$this->call(ProductoSeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Helpers\CsvHelper;
|
||||
use App\GrupoDeCompra;
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use League\Csv\Reader;
|
||||
|
||||
class GrupoDeCompraSeeder extends Seeder
|
||||
{
|
||||
|
@ -13,36 +9,41 @@ class GrupoDeCompraSeeder extends Seeder
|
|||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
* @throws \League\Csv\Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$registros = CsvHelper::getRecords(resource_path('csv/barrios.csv'), 'No se pudo leer la planilla de barrios.');
|
||||
$csv = Reader::createFromPath(resource_path('csv/barrios.csv'), 'r');
|
||||
$csv->setDelimiter("|");
|
||||
$csv->setEnclosure("'");
|
||||
$csv->setHeaderOffset(0);
|
||||
$registros = $csv->getRecords();
|
||||
$gdcToInsert = [];
|
||||
$usersToInsert = [];
|
||||
$roles = UserRole::where('nombre', 'barrio')->orWhere('nombre', 'admin_barrio')->get();
|
||||
|
||||
foreach($registros as $key => $registro){
|
||||
$gdcToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
$gdcToInsert[] = [
|
||||
'nombre' => $registro['barrio'],
|
||||
'region' => $registro['region'],
|
||||
]);
|
||||
'telefono' => $registro['telefono'],
|
||||
'correo' => $registro['correo'],
|
||||
'referente_finanzas' => $registro['referente']
|
||||
];
|
||||
|
||||
foreach($roles as $role) {
|
||||
$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,
|
||||
]);
|
||||
}
|
||||
$usersToInsert[] = [
|
||||
'name' => $registro['barrio'],
|
||||
'password' => Hash::make($registro['barrio']),
|
||||
'grupo_de_compra_id' => $key
|
||||
];
|
||||
}
|
||||
|
||||
foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
GrupoDeCompra::insert($chunk);
|
||||
foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
{
|
||||
DB::table('grupos_de_compra')->insert($chunk);
|
||||
}
|
||||
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
User::insert($chunk);
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
{
|
||||
DB::table('users')->insert($chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
39
database/seeds/ProductoSeeder.php
Normal file
39
database/seeds/ProductoSeeder.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?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
|
||||
];
|
||||
}
|
||||
|
||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
{
|
||||
DB::table('productos')->insert($chunk);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$usersToInsert = [];
|
||||
|
||||
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'name' => 'comision',
|
||||
'password' => Hash::make("123"),
|
||||
'role_id' => UserRole::where('nombre', 'comision')->first()->id,
|
||||
]);
|
||||
|
||||
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
User::insert($chunk);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\GrupoDeCompra;
|
||||
use App\User;
|
||||
use App\UserRole;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UsuarioOllasSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$barrios = GrupoDeCompra::all();
|
||||
$usersToInsert = [];
|
||||
$ollas_id = UserRole::where('nombre', 'ollas')->first()->id;
|
||||
|
||||
foreach ($barrios as $barrio) {
|
||||
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
||||
'name' => $barrio->nombre . '_ollas',
|
||||
'password' => Hash::make('123'),
|
||||
'role_id' => $ollas_id,
|
||||
'grupo_de_compra_id' => $barrio->id,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
User::insert($chunk);
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
#!/usr/bin/bash
|
||||
docker-compose up -d && docker-compose exec app npm run watch
|
|
@ -1,15 +1,14 @@
|
|||
version: '3.2'
|
||||
|
||||
version: "3.7"
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
args:
|
||||
user: www
|
||||
uid: ${USERID}
|
||||
uid: 1000
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
image: laravel-image
|
||||
container_name: pedi2-app
|
||||
container_name: laravel-app
|
||||
restart: unless-stopped
|
||||
working_dir: /var/www/
|
||||
volumes:
|
||||
|
@ -18,26 +17,12 @@ services:
|
|||
networks:
|
||||
- app-network
|
||||
|
||||
vite:
|
||||
build:
|
||||
args:
|
||||
user: www
|
||||
uid: ${USERID}
|
||||
context: ./
|
||||
container_name: vite
|
||||
working_dir: /var/www
|
||||
command: npm run dev
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
ports:
|
||||
- "5173:5173"
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
db:
|
||||
image: mysql:5.7
|
||||
container_name: pedi2-db
|
||||
container_name: laravel-db
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
MYSQL_DATABASE: ${DB_DATABASE}
|
||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||
|
@ -51,15 +36,13 @@ services:
|
|||
- dbdata:/var/lib/mysql
|
||||
networks:
|
||||
- app-network
|
||||
ports:
|
||||
- ${DB_PORT_EXPOSED}:3306
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: pedi2-nginx
|
||||
container_name: laravel-nginx
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${NGINX_PORT}:80
|
||||
- 8000:80
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./nginx/conf.d/:/etc/nginx/conf.d/
|
||||
|
@ -73,4 +56,4 @@ networks:
|
|||
#Volumes
|
||||
volumes:
|
||||
dbdata:
|
||||
driver: local
|
||||
driver: local
|
|
@ -13,22 +13,6 @@ server {
|
|||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
location ^~ /@vite/ {
|
||||
proxy_pass http://vite:5173;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
location ^~ /resources/ {
|
||||
proxy_pass http://vite:5173;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
gzip_static on;
|
||||
|
|
3315
package-lock.json
generated
3315
package-lock.json
generated
File diff suppressed because it is too large
Load diff
30
package.json
30
package.json
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"dev": "npm run development",
|
||||
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||
"watch": "npm run development -- --watch",
|
||||
"watch-poll": "npm run watch -- --watch-poll",
|
||||
|
@ -11,24 +10,17 @@
|
|||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/axios": "^0.9.36",
|
||||
"@vitejs/plugin-vue2": "^2.3.3",
|
||||
"axios": "^0.27.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"laravel-vite-plugin": "^1.3.0",
|
||||
"axios": "^0.19",
|
||||
"bootstrap": "^4.0.0",
|
||||
"cross-env": "^7.0",
|
||||
"jquery": "^3.2",
|
||||
"laravel-mix": "^5.0.1",
|
||||
"lodash": "^4.17.19",
|
||||
"popper.js": "^1.12",
|
||||
"resolve-url-loader": "^2.3.1",
|
||||
"sass": "^1.20.1",
|
||||
"sass-loader": "^8.0.0",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^5.2.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^2.7.16",
|
||||
"vue-template-compiler": "^2.7.16",
|
||||
"animate.css": "^4.1.1",
|
||||
"bulma": "^0.9.4",
|
||||
"bulma-switch": "^2.0.4",
|
||||
"bulma-toast": "^2.4.1",
|
||||
"vue-router": "^3.5.4",
|
||||
"vuex": "^3.6.2"
|
||||
"vue": "^2.5.17",
|
||||
"vue-template-compiler": "^2.6.10"
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB |
8
public/css/app.css
vendored
Normal file
8
public/css/app.css
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
p.navbar-item:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.breadcrumb a {
|
||||
color: #cc0f35;
|
||||
}
|
||||
|
4
public/css/productos.css
vendored
Normal file
4
public/css/productos.css
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
figure.image.icono {
|
||||
float: right;
|
||||
margin: 4px;
|
||||
}
|
73
public/js/app.js
vendored
Normal file
73
public/js/app.js
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
window.Event = new Vue();
|
||||
|
||||
Vue.component('nav-bar', {
|
||||
template: `
|
||||
<nav class="navbar is-danger" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="https://mps.org.uy">
|
||||
<img src="/assets/logoMPS.png" height="28">
|
||||
</a>
|
||||
<p style="margin:0 auto" class="navbar-item"><slot name="subpedido"></slot></p>
|
||||
<a role="button" class="navbar-burger" :class="{'is-active':isActive}" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample" @click="toggleState">
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="navbarBasicExample" class="navbar-menu" :class="{'is-active':isActive}">
|
||||
<div class="navbar-start has-text-right-mobile">
|
||||
<!-- Styles nombre del barrio-->
|
||||
<p class="navbar-item"><slot name="gdc"></slot></p>
|
||||
<a class="navbar-item"
|
||||
onclick="event.preventDefault();
|
||||
document.getElementById('logout-form').submit();">
|
||||
Cerrar sesión
|
||||
</a>
|
||||
<slot name="logout-form"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</nav>`,
|
||||
data() {
|
||||
return {
|
||||
isActive: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleState() {
|
||||
this.isActive = !this.isActive;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.component('nav-migas', {
|
||||
data() {
|
||||
return {
|
||||
migas: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
visible: function() {
|
||||
return this.migas.length > 0
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
Event.$on('migas-setear-como-inicio', (miga) => {
|
||||
this.migas = [];
|
||||
this.migas.push(miga);
|
||||
});
|
||||
Event.$on('migas-agregar', (miga) => {
|
||||
this.migas.push(miga);
|
||||
});
|
||||
Event.$on('migas-reset', () => {
|
||||
this.migas = [];
|
||||
});
|
||||
Event.$on('migas-pop', () => {
|
||||
this.migas.pop();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
new Vue({
|
||||
el: '#app'
|
||||
});
|
114
public/js/login.js
vendored
Normal file
114
public/js/login.js
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
window.Event = new Vue();
|
||||
|
||||
Vue.component('region-select', {
|
||||
template: `
|
||||
<div class="block">
|
||||
<div class="field">
|
||||
<label class="label">Seleccioná tu región</label>
|
||||
<div class="control">
|
||||
<div class="select">
|
||||
<select @change="onRegionSelected" v-model="region">
|
||||
<option :disabled="isDefaultDisabled==1" value=null>Seleccionar</option>
|
||||
<option v-for="region in regiones" v-text="region" :name="region"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
regiones: [],
|
||||
isDefaultDisabled: 0,
|
||||
region: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
axios.get("/api/regiones").then(response => this.regiones = response.data);
|
||||
},
|
||||
methods: {
|
||||
onRegionSelected() {
|
||||
this.isDefaultDisabled = 1;
|
||||
Event.$emit("region-seleccionada",this.region);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.component('barrio-select', {
|
||||
template: `
|
||||
<div v-show="visible" class="block">
|
||||
<div class="field">
|
||||
<label class="label">Seleccioná tu barrio o grupo de compra</label>
|
||||
<div class="control">
|
||||
<div class="select">
|
||||
<select @change="onGDCSelected" v-model="gdc" name="name">
|
||||
<option :disabled="isDefaultDisabled==1" value=null>Seleccionar</option>
|
||||
<option v-for="gdc in gdcs" v-text="gdc.nombre" :name="gdc.nombre"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
region: null,
|
||||
gdcs: [],
|
||||
isDefaultDisabled: 0,
|
||||
gdc: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
Event.$on('region-seleccionada', (region)=> {
|
||||
this.region = region;
|
||||
this.fillGDC(region);
|
||||
this.visible = true;
|
||||
});
|
||||
},
|
||||
methods : {
|
||||
fillGDC(region) {
|
||||
axios.get("/api/grupos-de-compra").then(response => {
|
||||
this.gdcs = response.data[this.region];
|
||||
});
|
||||
},
|
||||
onGDCSelected() {
|
||||
this.isDefaultDisabled = 1;
|
||||
Event.$emit("gdc-seleccionado",this.gdc);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Vue.component('login', {
|
||||
template: `
|
||||
<div v-show="visible" class="block">
|
||||
<div class="field">
|
||||
<label class="label">Contraseña del barrio</label>
|
||||
<p class="control">
|
||||
<input required class="input" type="password" name="password" placeholder="Contraseña del barrio">
|
||||
</p>
|
||||
<p class="help">Si no la sabés, consultá a tus compañerxs.</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input type="submit" class="button is-success" value="Ingresar">
|
||||
</input>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
gdc: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
Event.$on('gdc-seleccionado', (gdc) => {
|
||||
this.gdc = gdc;
|
||||
this.visible = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
new Vue({
|
||||
el: '#root'
|
||||
});
|
171
public/js/productos.js
vendored
Normal file
171
public/js/productos.js
vendored
Normal file
|
@ -0,0 +1,171 @@
|
|||
Vue.component('categorias-container', {
|
||||
template: `
|
||||
<div v-show="visible" class="container">
|
||||
<div class="columns is-multiline is-mobile">
|
||||
<div v-for="catego in categorias" class="block column is-one-quarter-desktop is-one-third-tablet is-half-mobile">
|
||||
<div @click.capture="seleccionarCategoria(catego)" class="card" style="height:100%" >
|
||||
<div class="card-content">
|
||||
<div class="media">
|
||||
<div class="media-content" style="overflow:hidden">
|
||||
<p class="title is-6" v-text="catego"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- END CARD -->
|
||||
</div><!-- END BLOCK COLUMN -->
|
||||
</div><!-- END COLUMNS -->
|
||||
</div><!-- END CONTAINER -->`,
|
||||
data() {
|
||||
return {
|
||||
categorias: null,
|
||||
visible: true,
|
||||
miga: {
|
||||
nombre: "Categorías",
|
||||
href: "/productos"
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
axios.get("/api/categorias").then(response => {
|
||||
this.categorias = response.data;
|
||||
});
|
||||
Event.$emit("migas-setear-como-inicio",this.miga);
|
||||
},
|
||||
methods: {
|
||||
seleccionarCategoria(categoria) {
|
||||
this.visible = false;
|
||||
Event.$emit("categoria-seleccionada",categoria);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.component('productos-container', {
|
||||
template: `
|
||||
<div v-show="visible" class="container">
|
||||
<div class="columns is-multiline is-mobile">
|
||||
<div v-for="producto in productos" class="block column is-one-quarter-desktop is-one-third-tablet is-half-mobile">
|
||||
<div @click.capture="seleccionarProducto(producto)" class="card" style="height:100%">
|
||||
<div class="card-image">
|
||||
<figure class="image is-4by3">
|
||||
<img v-bind:src="producto.imagen ? producto.imagen : 'https://bulma.io/images/placeholders/1280x960.png'">
|
||||
</figure>
|
||||
<figure v-show="producto.nacional" class="image icono is-32x32">
|
||||
<img src="/assets/uruguay.png">
|
||||
</figure>
|
||||
<figure v-show="producto.economia_solidaria" class="image icono is-32x32">
|
||||
<img src="/assets/solidaria.png">
|
||||
</figure>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="media">
|
||||
<div class="media-content">
|
||||
<p class="title is-6" v-text="producto.nombre"></p>
|
||||
<p class="subtitle is-7" v-text="producto.proveedor"></p>
|
||||
<p class="subtitle is-7">$<span v-text="producto.precio"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- END CARD -->
|
||||
</div><!-- END BLOCK COLUMN -->
|
||||
</div><!-- END COLUMNS -->
|
||||
</div><!-- END CONTAINER -->`,
|
||||
data() {
|
||||
return {
|
||||
productos: [],
|
||||
visible: false,
|
||||
categoria: null,
|
||||
paginar: 150
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
miga: function(){
|
||||
return {
|
||||
nombre: this.categoria,
|
||||
href: "#" + this.categoria
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
Event.$on('categoria-seleccionada', (categoria) => {
|
||||
this.categoria = categoria;
|
||||
|
||||
axios.get("/api/productos", {
|
||||
params: {
|
||||
categoria: this.categoria,
|
||||
paginar: this.paginar
|
||||
}
|
||||
}).then(response => {
|
||||
this.productos = response.data.data;
|
||||
});
|
||||
this.visible = true;
|
||||
Event.$emit("migas-agregar",this.miga);
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
seleccionarProducto(producto) {
|
||||
Event.$emit("producto-seleccionado",producto);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.component('producto-container', {
|
||||
template: `
|
||||
<div v-bind:class="visible ? 'is-active modal' : 'modal'">
|
||||
<div class="modal-background"></div>
|
||||
<div class="modal-card">
|
||||
<header class="modal-card-head">
|
||||
<p class="modal-card-title" v-text="producto.nombre"></p>
|
||||
<button class="delete" aria-label="close" @click.capture="cerrar"></button>
|
||||
</header>
|
||||
<section class="modal-card-body">
|
||||
<div class="card-image">
|
||||
<figure class="image is-4by3">
|
||||
<img v-bind:src="producto.imagen ? producto.imagen : 'https://bulma.io/images/placeholders/1280x960.png'">
|
||||
</figure>
|
||||
<figure v-show="producto.nacional" class="image icono is-32x32">
|
||||
<img src="/assets/uruguay.png">
|
||||
</figure>
|
||||
<figure v-show="producto.economia_solidaria" class="image icono is-32x32">
|
||||
<img src="/assets/solidaria.png">
|
||||
</figure>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<p class="title is-4" v-text="producto.proveedor"></p>
|
||||
<p class="subtitle is-4">$<span v-text="producto.precio"></span></p>
|
||||
<p class="subtitle is-5"><span v-text="producto.descripcion"></span></p>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="modal-card-foot">
|
||||
<button class="button is-success">Agregar a la chismosa</button>
|
||||
<button class="button" @click.capture="cerrar">Cancelar</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
producto: null,
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
miga: function(){
|
||||
return {
|
||||
nombre: this.producto.nombre,
|
||||
href: "#" + this.producto.nombre
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cerrar() {
|
||||
this.visible = false;
|
||||
Event.$emit("migas-pop");
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
Event.$on('producto-seleccionado', (producto) => {
|
||||
this.producto = producto;
|
||||
this.visible = true;
|
||||
Event.$emit("migas-agregar",this.miga);
|
||||
});
|
||||
}
|
||||
});
|
52
public/js/subpedidos-create.js
vendored
Normal file
52
public/js/subpedidos-create.js
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
Vue.component('subpedido-select', {
|
||||
data() {
|
||||
return {
|
||||
subpedido: null,
|
||||
subpedidosExistentes: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
nombresDeSubpedidos: function() {
|
||||
return this.subpedidosExistentes.map(a => a.nombre.toLowerCase())
|
||||
},
|
||||
botonCrearDesabilitado : function() {
|
||||
return !this.subpedido || this.nombresDeSubpedidos.includes(this.subpedido.toLowerCase())
|
||||
}
|
||||
},
|
||||
props: ["gdcid"],
|
||||
mounted() {
|
||||
console.log("ready");
|
||||
},
|
||||
methods: {
|
||||
onType() {
|
||||
if (!this.subpedido){
|
||||
this.subpedidosExistentes = [];
|
||||
return;
|
||||
}
|
||||
axios.get("/api/subpedidos", {
|
||||
params: {
|
||||
nombre: this.subpedido,
|
||||
grupo_de_compra: this.gdcid
|
||||
}
|
||||
}).then(response => {
|
||||
this.subpedidosExistentes = response.data
|
||||
});
|
||||
},
|
||||
submit() {
|
||||
axios.post("/api/subpedidos", {
|
||||
nombre: this.subpedido,
|
||||
grupo_de_compra_id: this.gdcid
|
||||
}).then(response => {
|
||||
//se creo el subpedido, guardamos el subpedido en sesion
|
||||
this.guardarSubpedidoEnSesion(response.data);
|
||||
});
|
||||
},
|
||||
guardarSubpedidoEnSesion(subpedido) {
|
||||
axios.post("/subpedidos/guardar_sesion", {
|
||||
subpedido: subpedido
|
||||
}).then(response => {
|
||||
window.location.href = 'productos';
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,4 +1,45 @@
|
|||
barrio|region|referente|telefono|correo
|
||||
ENTREVERO|SUR|||
|
||||
BUCEO|ESTE|||
|
||||
MALVIN NORTE|ESTE|||
|
||||
PINAR|ESTE|||
|
||||
UNION|ESTE|||
|
||||
SANTO DOMINGO|NORTE|||
|
||||
21 DE FEBRERO|NORTE|||
|
||||
PIEDRAS BLANCAS|NORTE|||
|
||||
BELLA ITALIA|NORTE|||
|
||||
JARDINES|NORTE|||
|
||||
LA SOCIALISTA|NORTE|||
|
||||
VILLA GARCIA|NORTE|||
|
||||
LAS ACACIAS|NORTE|||
|
||||
MANGA|NORTE|||
|
||||
CERRITO|OESTE|||
|
||||
LEZICA|OESTE|||
|
||||
PEÑAROL|OESTE|||
|
||||
LAS PIEDRAS|OESTE|||
|
||||
A.C.T.E.O|OESTE|||
|
||||
NUEVO PARIS|OESTE|||
|
||||
SANTA CATALINA|OESTE|||
|
||||
BELVEDERE|OESTE|||
|
||||
BATLLE BERRES|OESTE|||
|
||||
CERRO PTI|OESTE|||
|
||||
COLECTIVO UTU LAVALLEJA|OESTE|||
|
||||
FOGONES|OESTE|||
|
||||
LAVALLEJA|OESTE|||
|
||||
REJUNTE|OESTE|||
|
||||
CAPURRO|OESTE|||
|
||||
PARQUE RODO|SUR|||
|
||||
REDUCTO|SUR|||
|
||||
AGUADA|SUR|||
|
||||
CASA DEL VECINO|SUR|||
|
||||
CIUDAD VIEJA|SUR|||
|
||||
COOP EJIDO|SUR|||
|
||||
COVIREUS|SUR|||
|
||||
LA BLANQUEADA|SUR|||
|
||||
NITEP|SUR|||
|
||||
LA CURVA|SUR|||
|
||||
PANADERIA VIDAL|SUR|||
|
||||
SUA|SUR|||
|
||||
TRES CRUCES|SUR|||
|
||||
PRUEBA|SIN REGION|||
|
||||
VILLA ESPAÑOLA|SUR|||
|
||||
AUDA|OTRA|||
|
||||
SINTEP|OTRA|||
|
||||
|
|
|
|
@ -1,4 +0,0 @@
|
|||
id|nombre|valor
|
||||
bono-transporte|'Bono de transporte'|15
|
||||
monto-transporte|'Monto para bono de transporte'|500
|
||||
monto-olla|'Monto por olla'|800
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue