Skip to content

Commit

Permalink
Merge pull request #99 from dbarzin/dev
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
dbarzin committed May 2, 2022
2 parents 0c3dc1f + 44a852e commit 14a632b
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 118 deletions.
66 changes: 37 additions & 29 deletions app/Http/Controllers/Admin/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

use Carbon\Carbon;

// PhpOffice
// see : https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
Expand Down Expand Up @@ -980,7 +982,7 @@ public function administration()

public function entities()
{
$path = storage_path('app/entities.xlsx');
$path = storage_path('app/entities-'. Carbon::today()->format('Ymd') .'.xlsx');

$entities = Entity::All()->sortBy('name');

Expand Down Expand Up @@ -1036,7 +1038,7 @@ public function entities()

public function applicationsByBlocks()
{
$path = storage_path('app/applications.xlsx');
$path = storage_path('app/applications-'. Carbon::today()->format('Ymd') .'.xlsx');

$applicationBlocks = ApplicationBlock::All()->sortBy('name');
$applicationBlocks->load('applications');
Expand Down Expand Up @@ -1158,7 +1160,7 @@ public function applicationsByBlocks()

public function logicalServerResp()
{
$path = storage_path('app/logicalServersResp.xlsx');
$path = storage_path('app/logicalServersResp-'. Carbon::today()->format('Ymd') .'.xlsx');

$logicalServers = LogicalServer::All()->sortBy('name');
$logicalServers->load('applications', 'applications.application_block');
Expand Down Expand Up @@ -1231,23 +1233,25 @@ public function logicalServerResp()

public function logicalServerConfigs()
{
$path = storage_path('app/logicalServers.xlsx');
$path = storage_path('app/logicalServers-'. Carbon::today()->format('Ymd') .'.xlsx');

$logicalServers = LogicalServer::All()->sortBy('name');
$logicalServers->load('applications', 'servers');

$header = [
trans('cruds.logicalServer.fields.name'),
trans('cruds.logicalServer.fields.operating_system'),
trans('cruds.logicalServer.fields.address_ip'),
trans('cruds.logicalServer.fields.cpu'),
trans('cruds.logicalServer.fields.memory'),
trans('cruds.logicalServer.fields.disk'),
trans('cruds.logicalServer.fields.environment'),
trans('cruds.logicalServer.fields.net_services'),
trans('cruds.logicalServer.fields.configuration'),
trans('cruds.logicalServer.fields.applications'),
trans('cruds.logicalServer.fields.servers'),
trans('cruds.logicalServer.fields.name'), // A
trans('cruds.logicalServer.fields.operating_system'), // B
trans('cruds.logicalServer.fields.environment'), // C
trans('cruds.logicalServer.fields.install_date'), // D
trans('cruds.logicalServer.fields.update_date'), // E
trans('cruds.logicalServer.fields.cpu'), // F
trans('cruds.logicalServer.fields.memory'), // G
trans('cruds.logicalServer.fields.disk'), // H
trans('cruds.logicalServer.fields.net_services'), // I
trans('cruds.logicalServer.fields.address_ip'), // J
trans('cruds.logicalServer.fields.configuration'), // K
trans('cruds.logicalServer.fields.applications'), // L
trans('cruds.logicalServer.fields.servers'), // M
];

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
Expand All @@ -1269,11 +1273,13 @@ public function logicalServerConfigs()
$sheet->getColumnDimension('I')->setAutoSize(true);
$sheet->getColumnDimension('J')->setAutoSize(true);
$sheet->getColumnDimension('K')->setAutoSize(true);
$sheet->getColumnDimension('L')->setAutoSize(true);
$sheet->getColumnDimension('M')->setAutoSize(true);

// center
$sheet->getStyle('D')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$sheet->getStyle('E')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
// center (CPU, Men, Disk)
$sheet->getStyle('F')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$sheet->getStyle('G')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$sheet->getStyle('H')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);

// converter
$html = new \PhpOffice\PhpSpreadsheet\Helper\Html();
Expand All @@ -1283,15 +1289,17 @@ public function logicalServerConfigs()
foreach ($logicalServers as $logicalServer) {
$sheet->setCellValue("A{$row}", $logicalServer->name);
$sheet->setCellValue("B{$row}", $logicalServer->operating_system);
$sheet->setCellValue("C{$row}", $logicalServer->address_ip);
$sheet->setCellValue("D{$row}", $logicalServer->cpu);
$sheet->setCellValue("E{$row}", $logicalServer->memory);
$sheet->setCellValue("F{$row}", $logicalServer->disk);
$sheet->setCellValue("G{$row}", $logicalServer->environment);
$sheet->setCellValue("H{$row}", $logicalServer->net_services);
$sheet->setCellValue("I{$row}", $html->toRichTextObject($logicalServer->configuration));
$sheet->setCellValue("J{$row}", $logicalServer->applications->implode('name', ', '));
$sheet->setCellValue("K{$row}", $logicalServer->servers->implode('name', ', '));
$sheet->setCellValue("C{$row}", $logicalServer->environment);
$sheet->setCellValue("D{$row}", $logicalServer->install_date);
$sheet->setCellValue("E{$row}", $logicalServer->update_date);
$sheet->setCellValue("F{$row}", $logicalServer->cpu);
$sheet->setCellValue("G{$row}", $logicalServer->memory);
$sheet->setCellValue("H{$row}", $logicalServer->disk);
$sheet->setCellValue("I{$row}", $logicalServer->net_services);
$sheet->setCellValue("J{$row}", $logicalServer->address_ip);
$sheet->setCellValue("K{$row}", $html->toRichTextObject($logicalServer->configuration));
$sheet->setCellValue("L{$row}", $logicalServer->applications->implode('name', ', '));
$sheet->setCellValue("M{$row}", $logicalServer->servers->implode('name', ', '));

$row++;
}
Expand All @@ -1304,7 +1312,7 @@ public function logicalServerConfigs()

public function securityNeeds()
{
$path = storage_path('app/securityNeeds.xlsx');
$path = storage_path('app/securityNeeds-'. Carbon::today()->format('Ymd') .'.xlsx');

// macroprocess - process - application - base de données - information
$header = [
Expand Down Expand Up @@ -1425,7 +1433,7 @@ public function securityNeeds()

public function physicalInventory()
{
$path = storage_path('app/physicalInventory.xlsx');
$path = storage_path('app/physicalInventory-'. Carbon::today()->format('Ymd') .'.xlsx');

$inventory = [];

Expand Down
29 changes: 29 additions & 0 deletions app/LogicalServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Traits\Auditable;
use DateTimeInterface;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

Expand Down Expand Up @@ -86,8 +87,36 @@ class LogicalServer extends Model
'created_at',
'updated_at',
'deleted_at',
'install_date',
'update_date'
];

/**
* Permet d'exécuter de modifier un attribut avant que la valeurs soit récupérée du model
*/
public function getInstallDateAttribute($value)
{
return $value ? Carbon::parse($value)->format(config('panel.date_format').' '.config('panel.time_format')) : null;
}

public function setInstallDateAttribute($value)
{
$this->attributes['install_date'] = $value ? Carbon::createFromFormat(config('panel.date_format').' '.config('panel.time_format'), $value)->format('Y-m-d H:i:s') : null;
}

/**
* Permet d'exécuter de modifier un attribut avant que la valeurs soit récupérée du model
*/
public function getUpdateDateAttribute($value)
{
return $value ? Carbon::parse($value)->format(config('panel.date_format').' '.config('panel.time_format')) : null;
}

public function setUpdateDateAttribute($value)
{
$this->attributes['update_date'] = $value ? Carbon::createFromFormat(config('panel.date_format').' '.config('panel.time_format'), $value)->format('Y-m-d H:i:s') : null;
}

public function applications()
{
return $this->belongsToMany(MApplication::class)->orderBy('name');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUpdateToLogicalServers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('logical_servers', function (Blueprint $table) {
$table->dateTime('install_date')->nullable();
$table->dateTime('update_date')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('logical_servers', function (Blueprint $table) {
$table->dropColumn(['install_date', 'update_date']);
});
}
}

Loading

0 comments on commit 14a632b

Please sign in to comment.