From c911fec36ec63ed0dae51e9e1bb9240f0d417bf9 Mon Sep 17 00:00:00 2001 From: Djonathan Date: Thu, 23 Jun 2022 23:00:28 -0300 Subject: [PATCH] Correction of the Annual Gross Savings query. --- .../Controllers/InfoSectorialController.php | 8 +- app/Models/DadosCadastrais.php | 4 +- app/Models/DadosTe.php | 2 + app/Models/Economy.php | 2 + app/Models/Scopes/UserScope.php | 10 + .../Economy/EconomyRepository.php | 10 +- composer.json | 5 +- composer.lock | 263 +++++++++++++++++- ... 2014_04_08_000000_create_users_table.php} | 0 ...2_171300_create_dados_cadastrais_table.php | 6 +- ...022_05_12_173518_create_economia_table.php | 16 +- .../2022_05_12_174204_create_pld_table.php | 8 +- ...2022_05_12_174614_create_med5min_table.php | 8 +- ...022_05_12_175125_create_dados_te_table.php | 10 +- 14 files changed, 321 insertions(+), 31 deletions(-) rename database/migrations/{2014_06_08_000000_create_users_table.php => 2014_04_08_000000_create_users_table.php} (100%) diff --git a/app/Http/Controllers/InfoSectorialController.php b/app/Http/Controllers/InfoSectorialController.php index 4182daf..2ce834d 100644 --- a/app/Http/Controllers/InfoSectorialController.php +++ b/app/Http/Controllers/InfoSectorialController.php @@ -25,7 +25,13 @@ class InfoSectorialController extends Controller $data['name'] = Str::of($file->getClientOriginalName())->explode('.')->offsetGet(0); $data['uid'] = Str::of($file->hashName())->explode('.')->offsetGet(0); $extension = $file->getClientOriginalExtension(); - $data['path'] = $file->storeAs("pdf", $data['uid'].".{$extension}"); + $path = $file->store('pdf','s3'); + + dd($path); +// $path = Storage::disk('s3')->put('pdf', $data['uid'].".{$extension}"); +// $path = Storage::disk('s3')->url($path); + dd($path); + //$data['uid'].".{$extension}" return InfoSectorial::query()->create($data); diff --git a/app/Models/DadosCadastrais.php b/app/Models/DadosCadastrais.php index 30adf33..c8d68d2 100644 --- a/app/Models/DadosCadastrais.php +++ b/app/Models/DadosCadastrais.php @@ -15,7 +15,9 @@ class DadosCadastrais extends Model implements Auditing protected $table = 'dados_cadastrais'; - protected $guarded = ['cod_smart_unidade']; + protected $guarded = ['cod_smart_unidade', 'cod_smart_cliente']; + + public $incrementing = false; protected $fillable = [ 'cliente', diff --git a/app/Models/DadosTe.php b/app/Models/DadosTe.php index bb77994..b4bd890 100644 --- a/app/Models/DadosTe.php +++ b/app/Models/DadosTe.php @@ -19,6 +19,8 @@ class DadosTe extends Model implements Auditing protected $guarded = ['cod_te', 'cod_smart_unidade']; + public $incrementing = false; + protected $fillable = [ 'mes', 'operacao', diff --git a/app/Models/Economy.php b/app/Models/Economy.php index d4024df..2045bb3 100644 --- a/app/Models/Economy.php +++ b/app/Models/Economy.php @@ -19,6 +19,8 @@ class Economy extends Model implements Auditing protected $guarded = ['cod_te', 'cod_smart_unidade']; + public $incrementing = false; + protected $fillable = [ 'mes', 'custo_cativo', diff --git a/app/Models/Scopes/UserScope.php b/app/Models/Scopes/UserScope.php index 0c73ac3..7c7238e 100644 --- a/app/Models/Scopes/UserScope.php +++ b/app/Models/Scopes/UserScope.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class UserScope implements Scope { @@ -27,6 +28,15 @@ class UserScope implements Scope "=", $model->qualifyColumn("cod_smart_unidade"), )->where('dados_cadastrais.cod_smart_cliente', '=', $user->client_id); + + +// $sql = DB::table('dados_cadastrais') +// ->select([ +// $model->qualifyColumn("cod_smart_unidade") +// ]) +// ->where($model->qualifyColumn("cod_smart_unidade"), '=', $user->client_id); +// +// $builder->whereRaw($sql, 'in', $user->client_id); } } diff --git a/app/Repositories/Economy/EconomyRepository.php b/app/Repositories/Economy/EconomyRepository.php index 05f9269..7575b41 100644 --- a/app/Repositories/Economy/EconomyRepository.php +++ b/app/Repositories/Economy/EconomyRepository.php @@ -45,7 +45,9 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt ->where(DB::raw("TO_DATE(economia.mes, 'YYMM')"), ">=", DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - interval '1' year")) - ->groupBy(['mes', 'dad_estimado']) + ->groupBy(['ano', 'dad_estimado']) + ->orderBy('ano') + ->orderBy('dad_estimado') ->get(); } @@ -63,6 +65,8 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt ">=", DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - interval '1' year")) ->groupBy(['mes', 'dad_estimado']) + ->orderBy('mes') + ->orderBy('dad_estimado') ->get(); } @@ -85,6 +89,8 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt DB::raw("TO_DATE(TO_CHAR(current_date, 'YYYY-12-31'), 'YYYY-MM-DD') ") ]) ->groupBy(['mes', 'dad_estimado']) + ->orderBy('mes') + ->orderBy('dad_estimado') ->get(); } @@ -104,6 +110,8 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt DB::raw("TO_DATE(TO_CHAR(current_date, 'YYYY-12-31'), 'YYYY-MM-DD') ") ]) ->groupBy(['mes', 'dad_estimado']) + ->orderBy('mes') + ->orderBy('dad_estimado') ->get(); return static::checkDate($result); diff --git a/composer.json b/composer.json index d6d6141..b5661e4 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,14 @@ "license": "MIT", "require": { "php": "^8.1", + "ext-fileinfo": "*", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.11", "laravel/sanctum": "^2.14.1", "laravel/tinker": "^2.7", + "league/flysystem-aws-s3-v3": "^3.0", "owen-it/laravel-auditing": "^13.0", - "umbrellio/laravel-pg-extensions": "^5.3", - "ext-fileinfo": "*" + "umbrellio/laravel-pg-extensions": "^5.3" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index f6618e8..877c096 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,149 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d8590635104440a9a9893816079d3e83", + "content-hash": "7fd6e8d155fbb1afa453c11d3a60d217", "packages": [ + { + "name": "aws/aws-crt-php", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/awslabs/aws-crt-php.git", + "reference": "3942776a8c99209908ee0b287746263725685732" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/awslabs/aws-crt-php/zipball/3942776a8c99209908ee0b287746263725685732", + "reference": "3942776a8c99209908ee0b287746263725685732", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|^5.4.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "AWS SDK Common Runtime Team", + "email": "aws-sdk-common-runtime@amazon.com" + } + ], + "description": "AWS Common Runtime for PHP", + "homepage": "http://aws.amazon.com/sdkforphp", + "keywords": [ + "amazon", + "aws", + "crt", + "sdk" + ], + "support": { + "issues": "https://github.com/awslabs/aws-crt-php/issues", + "source": "https://github.com/awslabs/aws-crt-php/tree/v1.0.2" + }, + "time": "2021-09-03T22:57:30+00:00" + }, + { + "name": "aws/aws-sdk-php", + "version": "3.228.1", + "source": { + "type": "git", + "url": "https://github.com/aws/aws-sdk-php.git", + "reference": "53b7f43945b19bb0700c75d4c5f130055096e817" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/53b7f43945b19bb0700c75d4c5f130055096e817", + "reference": "53b7f43945b19bb0700c75d4c5f130055096e817", + "shasum": "" + }, + "require": { + "aws/aws-crt-php": "^1.0.2", + "ext-json": "*", + "ext-pcre": "*", + "ext-simplexml": "*", + "guzzlehttp/guzzle": "^6.5.7 || ^7.4.4", + "guzzlehttp/promises": "^1.4.0", + "guzzlehttp/psr7": "^1.8.5 || ^2.3", + "mtdowling/jmespath.php": "^2.6", + "php": ">=5.5" + }, + "require-dev": { + "andrewsville/php-token-reflection": "^1.4", + "aws/aws-php-sns-message-validator": "~1.0", + "behat/behat": "~3.0", + "doctrine/cache": "~1.4", + "ext-dom": "*", + "ext-openssl": "*", + "ext-pcntl": "*", + "ext-sockets": "*", + "nette/neon": "^2.3", + "paragonie/random_compat": ">= 2", + "phpunit/phpunit": "^4.8.35 || ^5.6.3", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0", + "sebastian/comparator": "^1.2.3" + }, + "suggest": { + "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications", + "doctrine/cache": "To use the DoctrineCacheAdapter", + "ext-curl": "To send requests using cURL", + "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", + "ext-sockets": "To use client-side monitoring" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Aws\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Amazon Web Services", + "homepage": "http://aws.amazon.com" + } + ], + "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project", + "homepage": "http://aws.amazon.com/sdkforphp", + "keywords": [ + "amazon", + "aws", + "cloud", + "dynamodb", + "ec2", + "glacier", + "s3", + "sdk" + ], + "support": { + "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", + "issues": "https://github.com/aws/aws-sdk-php/issues", + "source": "https://github.com/aws/aws-sdk-php/tree/3.228.1" + }, + "time": "2022-06-22T18:16:48+00:00" + }, { "name": "brick/math", "version": "0.9.3", @@ -1883,6 +2024,62 @@ ], "time": "2022-06-12T17:54:28+00:00" }, + { + "name": "league/flysystem-aws-s3-v3", + "version": "3.0.21", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-aws-s3-v3.git", + "reference": "f4ee238279f1eb39a32539a18ef845db7251fd05" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-aws-s3-v3/zipball/f4ee238279f1eb39a32539a18ef845db7251fd05", + "reference": "f4ee238279f1eb39a32539a18ef845db7251fd05", + "shasum": "" + }, + "require": { + "aws/aws-sdk-php": "^3.132.4", + "league/flysystem": "^2.0.0 || ^3.0.0", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2" + }, + "conflict": { + "guzzlehttp/guzzle": "<7.0", + "guzzlehttp/ringphp": "<1.1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\AwsS3V3\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "AWS S3 filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "aws", + "file", + "files", + "filesystem", + "s3", + "storage" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem-aws-s3-v3/issues", + "source": "https://github.com/thephpleague/flysystem-aws-s3-v3/tree/3.0.21" + }, + "time": "2022-06-12T17:34:31+00:00" + }, { "name": "league/mime-type-detection", "version": "1.11.0", @@ -2043,6 +2240,67 @@ ], "time": "2022-06-09T08:59:12+00:00" }, + { + "name": "mtdowling/jmespath.php", + "version": "2.6.1", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/9b87907a81b87bc76d19a7fb2d61e61486ee9edb", + "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb", + "shasum": "" + }, + "require": { + "php": "^5.4 || ^7.0 || ^8.0", + "symfony/polyfill-mbstring": "^1.17" + }, + "require-dev": { + "composer/xdebug-handler": "^1.4 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^7.5.15" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "files": [ + "src/JmesPath.php" + ], + "psr-4": { + "JmesPath\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "support": { + "issues": "https://github.com/jmespath/jmespath.php/issues", + "source": "https://github.com/jmespath/jmespath.php/tree/2.6.1" + }, + "time": "2021-06-14T00:11:39+00:00" + }, { "name": "nesbot/carbon", "version": "2.58.0", @@ -8315,7 +8573,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.1" + "php": "^8.1", + "ext-fileinfo": "*" }, "platform-dev": [], "plugin-api-version": "2.3.0" diff --git a/database/migrations/2014_06_08_000000_create_users_table.php b/database/migrations/2014_04_08_000000_create_users_table.php similarity index 100% rename from database/migrations/2014_06_08_000000_create_users_table.php rename to database/migrations/2014_04_08_000000_create_users_table.php diff --git a/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php b/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php index 38d3386..3b54ced 100644 --- a/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php +++ b/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php @@ -18,11 +18,11 @@ return new class extends Migration $table->text('cliente')->nullable(); $table->text('unidade')->nullable(); $table->text('codigo_scde')->nullable(); - $table->numeric('demanda_p')->nullable(); - $table->numeric('demanda_fp')->nullable(); + $table->decimal('demanda_p', 30, 10)->nullable(); + $table->decimal('demanda_fp', 30, 10)->nullable(); $table->text('status_empresa')->nullable(); $table->text('status_unidade')->nullable(); - $table->numeric('data_de_migracao')->nullable(); + $table->decimal('data_de_migracao', 30, 10)->nullable(); $table->bigInteger('cod_smart_cliente')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2022_05_12_173518_create_economia_table.php b/database/migrations/2022_05_12_173518_create_economia_table.php index 830169b..3370ad7 100644 --- a/database/migrations/2022_05_12_173518_create_economia_table.php +++ b/database/migrations/2022_05_12_173518_create_economia_table.php @@ -15,22 +15,22 @@ return new class extends Migration { Schema::create('economia', function (Blueprint $table) { - $table->bigInteger('cod_te')->unsigned(); + $table->bigInteger('cod_econ')->unsigned(); $table->bigInteger('cod_smart_unidade')->unsigned(); $table->text('mes')->nullable()->default(null); - $table->numeric('custo_cativo')->nullable(); - $table->numeric('custo_livre')->nullable(); - $table->numeric('economia_mensal')->nullable(); - $table->numeric('economia_acumulada')->nullable(); - $table->numeric('custo_unit')->nullable(); + $table->decimal('custo_cativo', 30, 10)->nullable(); + $table->decimal('custo_livre', 30, 10)->nullable(); + $table->decimal('economia_mensal', 30, 10)->nullable(); + $table->decimal('economia_acumulada', 30, 10)->nullable(); + $table->decimal('custo_unit', 30, 10)->nullable(); $table->boolean('dad_estimado')->nullable(); $table->timestamps(); $table->softDeletes(); $table->foreign('cod_smart_unidade', 'economia_cod_smart_unidade_fkey') - ->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action')->notValid(); + ->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action'); - $table->primary(['cod_te','cod_smart_unidade']); + $table->primary(['cod_econ', 'cod_smart_unidade']); }); } diff --git a/database/migrations/2022_05_12_174204_create_pld_table.php b/database/migrations/2022_05_12_174204_create_pld_table.php index 94114f3..cd81e8a 100644 --- a/database/migrations/2022_05_12_174204_create_pld_table.php +++ b/database/migrations/2022_05_12_174204_create_pld_table.php @@ -15,12 +15,12 @@ return new class extends Migration { Schema::create('pld', function (Blueprint $table) { $table->integerIncrements('id'); - $table->numeric('dia_num')->nullable(); - $table->numeric('hora')->nullable(); + $table->decimal('dia_num', 30, 10)->nullable(); + $table->decimal('hora', 30, 10)->nullable(); $table->text('submercado')->nullable(); - $table->numeric('valor')->nullable(); + $table->decimal('valor', 30, 10)->nullable(); $table->string('mes_ref')->nullable(); - $table->numeric('dia_da_semana')->nullable(); + $table->decimal('dia_da_semana', 30, 10)->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2022_05_12_174614_create_med5min_table.php b/database/migrations/2022_05_12_174614_create_med5min_table.php index 783799a..24af586 100644 --- a/database/migrations/2022_05_12_174614_create_med5min_table.php +++ b/database/migrations/2022_05_12_174614_create_med5min_table.php @@ -18,10 +18,10 @@ return new class extends Migration $table->text('origem')->nullable(); $table->decimal('dia_num')->nullable(); $table->integer('minuto')->nullable(); - $table->numeric('ativa_consumo')->nullable(); - $table->numeric('ativa_geracao')->nullable(); - $table->numeric('reativa_consumo')->nullable(); - $table->numeric('reativa_geracao')->nullable(); + $table->decimal('ativa_consumo', 30, 10)->nullable(); + $table->decimal('ativa_geracao', 30, 10)->nullable(); + $table->decimal('reativa_consumo', 30, 10)->nullable(); + $table->decimal('reativa_geracao', 30,10)->nullable(); $table->text('ponto')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2022_05_12_175125_create_dados_te_table.php b/database/migrations/2022_05_12_175125_create_dados_te_table.php index 084f38c..d39cd05 100644 --- a/database/migrations/2022_05_12_175125_create_dados_te_table.php +++ b/database/migrations/2022_05_12_175125_create_dados_te_table.php @@ -19,17 +19,17 @@ return new class extends Migration $table->text('mes')->nullable(); $table->text('operacao')->nullable(); $table->text('tipo')->nullable(); - $table->numeric('montante_nf')->nullable(); - $table->numeric('preco_nf')->nullable(); - $table->numeric('nf_c_icms')->nullable(); + $table->decimal('montante_nf', 30, 10)->nullable(); + $table->decimal('preco_nf', 30, 10)->nullable(); + $table->decimal('nf_c_icms', 30, 10)->nullable(); $table->text('perfil_contr')->nullable(); $table->timestamps(); $table->softDeletes(); $table->foreign('cod_smart_unidade', 'dados_te_cod_smart_unidade_fkey') - ->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action')->notValid(); + ->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action'); - $table->primary(['cod_te','cod_smart_unidade']); + $table->primary(['cod_te', 'cod_smart_unidade']); }); }