Skip to content

Commit

Permalink
Reworked reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Oct 10, 2023
1 parent 05ef315 commit 8712c54
Show file tree
Hide file tree
Showing 27 changed files with 222 additions and 136 deletions.
4 changes: 3 additions & 1 deletion all_batch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ ECHO -------------------------------------- PHP-PSALM --------------------------
ECHO -------------------------------------- PHP-STAN ------------------------------------------ && ^
.\vendor-bin\phpstan\vendor\bin\phpstan.bat analyse --memory-limit=2G && ^
ECHO -------------------------------------- PHP-RECTOR ---------------------------------------- && ^
.\vendor-bin\rector\vendor\bin\rector.bat process --dry-run && ^
.\vendor-bin\rector\vendor\bin\rector.bat process --dry-run --config=rector.php && ^
ECHO -------------------------------------- PHP-TWIG-CS --------------------------------------- && ^
.\vendor-bin\twigcs\vendor\bin\twigcs.bat --severity error --display blocking templates && ^
ECHO -------------------------------------- PHP-UNIT ------------------------------------------ && ^
.\vendor-bin\phpunit\vendor\bin\phpunit.bat
SET STA__TIME=%TIME: =0%
ECHO -------------------------------------- END BATCH %STA__TIME% -----------------------------
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion public/css/toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ html[data-bs-theme=dark] .toast-plugin .toast.border-info .btn-close,
html[data-bs-theme=dark] .toast-plugin .toast.border-warning .btn-close {
filter: inherit;
}

/*
* border for dark toast
*/
html[data-bs-theme=dark] .toast-plugin .toast.border-dark {
border-color: var(--bs-border-color) !important;
}
/**
* margins
*/
Expand Down
17 changes: 12 additions & 5 deletions public/js/application/parameters_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,23 @@ function updateVisibleButton() {
/**
* Display a notification.
*
* @param {string} [type] - the notification type.
* @param {jQuery} [source] - the notification source.
*/
function displayNotification(type) {
function displayNotification($source) {
'use strict';
// get random text
let title = $('.card-title:first').text();
const url = $('#edit-form').data("random");
$.getJSON(url, function (response) {
if (response.result && response.content) {
// content
const content = '<p class="m-0 p-0">' + response.content + '</p>';
// type
let type = null;
if ($source) {
type = $source.data('value');
if ($source.text().trim()) {
title = $source.text().trim();
}
}
if (!type) {
const types = Object.values(Toaster.NotificationTypes);
type = types.randomElement();
Expand All @@ -92,6 +97,8 @@ function displayNotification(type) {
if (!$('#message_title').isChecked()) {
title = null;
}
// content
const content = '<p class="m-0 p-0">' + response.content + '</p>';
// options
const options = {
dataset: '#flashes',
Expand Down Expand Up @@ -220,7 +227,7 @@ function handleEmail() {
});
$('.btn-notify').on('click', (e) => {
e.preventDefault();
displayNotification($(e.currentTarget).data('value'));
displayNotification($(e.currentTarget));
});

$('.card-parameter .collapse').on('shown.bs.collapse', function () {
Expand Down
10 changes: 5 additions & 5 deletions src/Pdf/AbstractPdfColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ public static function link(): self
*
* @param ?string $value a hexadecimal string
*
* @return array|false the RGB array (<code>red, green, blue</code>) or <code>false</code> if the value can not be converted
* @return ?array the RGB array (<code>red, green, blue</code>) or <code>null</code> if the value can not be converted
*
* @psalm-return array{0: int<0, 255>, 1: int<0, 255>, 2: int<0, 255>}|false
* @psalm-return array{0: int<0, 255>, 1: int<0, 255>, 2: int<0, 255>}|null
*/
public static function parse(?string $value): array|false
public static function parse(?string $value): ?array
{
if (null === $value || '' === $value) {
return false;
return null;
}

$parsed = (string) \preg_replace('/[^0-9A-Fa-f]/', '', $value);
Expand All @@ -268,7 +268,7 @@ public static function parse(?string $value): array|false
return [$r, $g, $b];

default:
return false;
return null;
}
}

Expand Down
54 changes: 54 additions & 0 deletions src/Pdf/PdfDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,42 @@ public function SetDisplayMode($zoom = PdfDocumentZoom::FULL_PAGE, $layout = Pdf
parent::SetDisplayMode($zoom, $layout);
}

/**
* Defines the color used for all drawing operations (lines, rectangles and cell borders).
*
* It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
*
* @param int $r If $g and $b are given, red component; if not, indicates the gray level. Value between 0 and 255.
* @param ?int $g the green component (value between 0 and 255)
* @param ?int $b the blue component (value between 0 and 255)
*
* @psalm-param int<0, 255> $r
* @psalm-param int<0, 255>|null $g
* @psalm-param int<0, 255>|null $b
*/
public function SetDrawColor($r, $g = null, $b = null): void
{
parent::SetDrawColor($r, $g, $b);
}

/**
* Defines the color used for all filling operations (filled rectangles and cell backgrounds).
*
* It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
*
* @param int $r If $g and $b are given, red component; if not, indicates the gray level. Value between 0 and 255.
* @param ?int $g the green component (value between 0 and 255)
* @param ?int $b the blue component (value between 0 and 255)
*
* @psalm-param int<0, 255> $r
* @psalm-param int<0, 255>|null $g
* @psalm-param int<0, 255>|null $b
*/
public function SetFillColor($r, $g = null, $b = null): void
{
parent::SetFillColor($r, $g, $b);
}

/**
* Sets the font used to print character strings.
*
Expand Down Expand Up @@ -861,6 +897,24 @@ public function SetFont($family, $style = '', $size = 0): void
parent::SetFont($family, $style, $size);
}

/**
* Defines the color used for text.
*
* It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
*
* @param int $r If $g et $b are given, red component; if not, indicates the gray level. Value between 0 and 255.
* @param ?int $g the green component (value between 0 and 255)
* @param ?int $b the blue component (value between 0 and 255)
*
* @psalm-param int<0, 255> $r
* @psalm-param int<0, 255>|null $g
* @psalm-param int<0, 255>|null $b
*/
public function SetTextColor($r, $g = null, $b = null): void
{
parent::SetTextColor($r, $g, $b);
}

/**
* Defines the document title.
*
Expand Down
30 changes: 12 additions & 18 deletions src/Report/CalculationByMonthReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class CalculationByMonthReport extends AbstractArrayReport
{
use MathTrait;

/**
* @psalm-param CalculationByMonthType[] $entities
*/
protected function doRender(array $entities): bool
{
$this->SetTitle($this->transChart('title_by_month'));
Expand All @@ -43,14 +40,14 @@ protected function doRender(array $entities): bool
$table = $this->createTable();

foreach ($entities as $entity) {
$table->startRow()->addValues(
$table->addRow(
$this->formatDate($entity['date']),
FormatUtils::formatInt($entity['count']),
FormatUtils::formatInt($entity['items']),
FormatUtils::formatInt($entity['total'] - $entity['items']),
$this->formatPercent($entity['margin']),
FormatUtils::formatInt($entity['total'])
)->endRow();
);
}

// total
Expand All @@ -60,32 +57,29 @@ protected function doRender(array $entities): bool
$net = $total - $items;
$margin = 1.0 + $this->safeDivide($net, $items);

$table->startHeaderRow()->addValues(
$table->addHeaderRow(
$this->transChart('fields.total'),
FormatUtils::formatInt($count),
FormatUtils::formatInt($items),
FormatUtils::formatInt($net),
$this->formatPercent($margin, true),
FormatUtils::formatInt($total)
)->endRow();
);

return true;
}

private function createTable(): PdfTableBuilder
{
$columns = [
PdfColumn::left($this->transChart('fields.month'), 20),
PdfColumn::right($this->transChart('fields.count'), 25, true),
PdfColumn::right($this->transChart('fields.net'), 25, true),
PdfColumn::right($this->transChart('fields.margin_amount'), 25, true),
PdfColumn::right($this->transChart('fields.margin_percent'), 20, true),
PdfColumn::right($this->transChart('fields.total'), 25, true),
];

return PdfTableBuilder::instance($this)
->addColumns(...$columns)
->outputHeaders();
->addColumns(
PdfColumn::left($this->transChart('fields.month'), 20),
PdfColumn::right($this->transChart('fields.count'), 25, true),
PdfColumn::right($this->transChart('fields.net'), 25, true),
PdfColumn::right($this->transChart('fields.margin_amount'), 25, true),
PdfColumn::right($this->transChart('fields.margin_percent'), 20, true),
PdfColumn::right($this->transChart('fields.total'), 25, true),
)->outputHeaders();
}

private function formatDate(\DateTimeInterface $date): string
Expand Down
Loading

0 comments on commit 8712c54

Please sign in to comment.