Correction of the Annual Gross Savings query.

This commit is contained in:
Djonathan 2022-06-23 23:00:28 -03:00
parent a00c170039
commit c911fec36e
14 changed files with 321 additions and 31 deletions

View File

@ -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);

View File

@ -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',

View File

@ -19,6 +19,8 @@ class DadosTe extends Model implements Auditing
protected $guarded = ['cod_te', 'cod_smart_unidade'];
public $incrementing = false;
protected $fillable = [
'mes',
'operacao',

View File

@ -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',

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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",

263
composer.lock generated
View File

@ -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"

View File

@ -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();

View File

@ -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']);
});
}

View File

@ -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();
});

View File

@ -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();

View File

@ -19,15 +19,15 @@ 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']);
});