Skip to content

Commit

Permalink
OSS => Premium
Browse files Browse the repository at this point in the history
commit 5bcbc57
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sun Jan 24 13:56:48 2021 +0100

    Améliore le calcul du matériel restant

commit 5c661be
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sun Jan 24 14:04:37 2021 +0100

    Ajoute l'id aux donnnées récupérées pour le pivot `EventMaterial`

commit 839c24e
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sun Jan 24 14:05:21 2021 +0100

    Refactoring

commit 7f857a0
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sun Jan 24 12:41:24 2021 +0100

    Extraction de la méthode `_getSplittedPeriods ` vers une fonction utilitaire `splitPeriods`

commit cb3e168
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sun Jan 24 12:53:28 2021 +0100

    Renomme la table de pivot `EventMaterialsPivot` en `EventMaterial`

commit 4c7a69b
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Sat Jan 16 13:12:55 2021 +0100

    Supprime le endpoint `/parks/[id]/materials`, non utilisé

commit 5f5f346
Merge: f7bcb89 12b1990
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Thu Jan 14 15:47:26 2021 +0100

    Merge branch 'release/0.11.0' into develop

commit 12b1990
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Thu Jan 14 15:47:20 2021 +0100

    Release version 0.11.0

commit f7bcb89
Merge: 32fa00f 6827a9d
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Thu Jan 14 12:49:05 2021 +0100

    Merge pull request #95 from Robert-2/feature/94-filter-events-by-park

    Ajoute un filtre par parc dans le calendrier (#94)

commit 6827a9d
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Thu Jan 14 10:12:07 2021 +0100

    Limite l'utilisation du filtre au cas où il y a plusieurs parcs

    Et corrige selon self-review

commit ac1436b
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 23:08:59 2021 +0100

    Ajoute un filtre par parc dans le calendrier (#94)

commit 32fa00f
Merge: 0b4cb86 873ae02
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 18:19:53 2021 +0100

    Merge branch 'feature/87-auto-trim' into develop

commit 873ae02
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 18:19:46 2021 +0100

    Ajoute un trim() auto sur les champs de type string (#87)

commit 0b4cb86
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 15:18:59 2021 +0100

    Ajoute la configuration de l'extension Vetur

    On peut se permettre de ne pas l'ignorer, car c'est cross-IDE apparemment, et c'est un outil vraiment utile pour le développement d'une app en Vue.js (complétion auto, snippets, etc).

commit 2274ef9
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 15:16:58 2021 +0100

    Utilise une configuration ESlint spéciale pour les tests (temporaire)

commit 650fbd9
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 13 15:16:13 2021 +0100

    Met à jour les dépendances Front

commit cf99b89
Merge: 4b011a2 352bb1b
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Tue Jan 12 19:51:49 2021 +0100

    Merge pull request #89 from Robert-2/feature/51-category-link-to-materials

    Ajoute des liens vers le matériel depuis les catégories (#51)

commit 352bb1b
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 10 23:10:52 2021 +0100

    Corrige les filtres par catégories dans la liste du matériel

commit 5a141a4
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 10 22:35:16 2021 +0100

    Ajoute des liens vers le matériel depuis les catégories (#51)

commit 4b011a2
Merge: 4098963 a8b68be
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Tue Jan 12 19:44:31 2021 +0100

    Merge pull request #88 from Robert-2/feature/36-select-search

    Ajoute un système de recherche dans le choix des bénéficiaires et techniciens (#36)

commit a8b68be
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Tue Jan 12 19:38:11 2021 +0100

    Corrige selon auto-review

commit 4098963
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 10 21:27:26 2021 +0100

    Ajoute un fichier de config pour le dependabot (#86)

commit f62f310
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 10 13:24:35 2021 +0100

    Ajoute la prise en charge de l'overwrite du nombre de résultat par page

commit 753dc3e
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 10 13:13:06 2021 +0100

    Permet la recherche à la volée dans les multipleItems (#36)

commit 9352baa
Merge: c1162ca 9021cbc
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Jan 6 13:07:20 2021 +0100

    Merge pull request #85 from Robert-2/dependabot/npm_and_yarn/client/axios-0.21.1

    Bump axios from 0.20.0 to 0.21.1 in /client

commit 9021cbc
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Wed Jan 6 05:03:45 2021 +0000

    Bump axios from 0.20.0 to 0.21.1 in /client

    Bumps [axios](https://github.com/axios/axios) from 0.20.0 to 0.21.1.
    - [Release notes](https://github.com/axios/axios/releases)
    - [Changelog](https://github.com/axios/axios/blob/v0.21.1/CHANGELOG.md)
    - [Commits](axios/axios@v0.20.0...v0.21.1)

    Signed-off-by: dependabot[bot] <support@github.com>

commit c1162ca
Merge: 8640b5e 8573af6
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Tue Jan 5 18:38:04 2021 +0100

    Merge pull request #84 from Robert-2/feature/improves-models

    Améliorations au niveau des modèles

commit 8573af6
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 18:36:17 2021 +0100

    Supprime un commentaire inutile

commit 4aafe8f
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 18:35:01 2021 +0100

    Ajoute un auto-discover du modèle dans les contrôleurs

commit 44ea71b
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 17:06:35 2021 +0100

    Retourne le modèle avec les attributs actualisés lors de la creation / edition

commit a2c9f63
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 17:15:34 2021 +0100

    Conserve le casting dans les accessors du modèle Material

commit 3ba2646
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 16:43:58 2021 +0100

    Ajoute les valeurs par défaut pour le matériel

commit 17f6f02
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 16:42:23 2021 +0100

    Utilise des classes abstraites pour les classes de base

commit a7ab5d9
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Jan 5 16:35:15 2021 +0100

    Remplace `Material::format()` par des accesseurs

commit 8640b5e
Author: Donovan <donovan@pulsanova.com>
Date:   Tue Jan 5 15:26:34 2021 +0100

    Ajoute le champ `park_id` aux unités de matériel (#83)

commit 2dc074a
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Tue Jan 5 11:47:59 2021 +0100

    Ajoute des onglets dans la vue du matériel en détail (#82)

    * Ajoute des onglets dans la vue du matériel en détail

    * Renomme le Dotfile de développement

    * Supprime l'affichage des unités dans la vue d'un matériel

    Co-authored-by: Donovan Lambert <donovan@pulsanova.com>

commit 27e467d
Merge: d318c40 0b8c817
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Mon Jan 4 21:37:03 2021 +0100

    Merge pull request #80 from Robert-2/feature/material-view

    Ajoute la vue d'un matériel

commit 0b8c817
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sun Jan 3 22:27:42 2021 +0100

    Corrige selon review

commit 33cdf3d
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Thu Dec 31 02:42:06 2020 +0100

    Ajoute la vue d'un matériel

commit d318c40
Merge: 985126a 3053393
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Sat Jan 2 23:18:58 2021 +0100

    Merge pull request #81 from Robert-2/feature/improves-validation-2

    Améliore (encore) la validation

commit 3053393
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Fri Jan 1 16:35:37 2021 +0100

    Corrige les tests unitaires vu la nouvelle année (2021)

commit 37149e4
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Fri Jan 1 16:14:05 2021 +0100

    Améliore (encore) la validation

commit 985126a
Merge: acbb5cf de0bcb8
Author: Paul Maillardet <paul@pulsanova.com>
Date:   Wed Dec 30 14:04:04 2020 +0100

    Merge pull request #79 from Robert-2/feature/remove-partial-validation

    Améliore la validation des modèles

commit de0bcb8
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Wed Dec 30 12:25:45 2020 +0100

    Corrige la validation des modèles

commit 57993a9
Author: Donovan Lambert <donovan@pulsanova.com>
Date:   Tue Dec 29 18:56:47 2020 +0100

    Amélioration des booléens dans les fixtures

commit acbb5cf
Author: Donovan <donovan@pulsanova.com>
Date:   Tue Dec 29 17:27:42 2020 +0100

    Améliore la validation (+ Refactoring modèles) (#76)

commit f0bbab2
Author: Donovan <donovan@pulsanova.com>
Date:   Tue Dec 29 11:25:22 2020 +0100

    Ajuste la contrainte des unités de matériel dans les événements (#77)

    (Sera rollback lorsque l'on prendra en charge les guards lors du switch-back Gestion unitaire => Gestion non unitaire)
  • Loading branch information
Donov4n committed Jan 24, 2021
1 parent 73bf755 commit d6c77c2
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 124 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Tous les changements notables sur le projet sont documentés dans ce fichier.

Ce projet adhère au principe du [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.12.0 (unreleased)
- Améliore le calcul du matériel restant dans les événements.

## 0.11.0 (2021-01-14)

- Met à jour les dépendances du projet.
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/app.js

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions client/src/components/EventMissingMaterials/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ export default {

getMissingCount(missingMaterial) {
const { quantity } = missingMaterial.pivot;

const missing = Math.min(
Math.abs(missingMaterial.remaining_quantity),
quantity,
);

return { quantity, missing };
return { quantity, missing: missingMaterial.missing_quantity };
},

displayError(error) {
Expand Down
47 changes: 47 additions & 0 deletions server/src/App/Config/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,50 @@ function isDuplicateException(Illuminate\Database\QueryException $e): bool

return $subCode[0] == '1062';
}

function splitPeriods(array $slots): array
{
$normalizeDate = function ($date, $defaultTime) {
if (!($date instanceof \DateTime)) {
$parsedTime = date_parse($date);
if (!$parsedTime || $parsedTime['error_count'] > 0) {
throw new \InvalidArgumentException(
sprintf("La date \"%s\" est invalide.", $date)
);
}

$date = new \DateTime($date);
if ($parsedTime['hour'] === false) {
$timeParts = array_map('intval', explode(':', $defaultTime));
call_user_func_array([$date, 'setTime'], $timeParts);
}
}
return $date->format('Y-m-d H:i');
};

$timeLine = [];
foreach ($slots as $slot) {
$timeLine[] = $normalizeDate($slot['start_date'], '00:00');
$timeLine[] = $normalizeDate($slot['end_date'], '23:59');
}

$timeLine = array_unique($timeLine);
$timeLineCount = count($timeLine);
if ($timeLineCount < 2) {
return [];
}

usort($timeLine, function ($dateTime1, $dateTime2) {
if ($dateTime1 === $dateTime2) {
return 0;
}
return strtotime($dateTime1) < strtotime($dateTime2) ? -1 : 1;
});

$periods = [];
for ($i = 0; $i < $timeLineCount - 1; $i++) {
$periods[] = [$timeLine[$i], $timeLine[$i + 1]];
}

return $periods;
}
10 changes: 5 additions & 5 deletions server/src/App/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ protected function _saveEvent(?int $id, array $postData): int
);
}

$result = $this->model->edit($id, $postData);
$event = $this->model->edit($id, $postData);

if (isset($postData['beneficiaries'])) {
$result->Beneficiaries()->sync($postData['beneficiaries']);
$event->Beneficiaries()->sync($postData['beneficiaries']);
}

if (isset($postData['assignees'])) {
$result->Assignees()->sync($postData['assignees']);
$event->Assignees()->sync($postData['assignees']);
}

if (isset($postData['materials'])) {
Expand All @@ -128,10 +128,10 @@ protected function _saveEvent(?int $id, array $postData): int
'quantity' => $material['quantity']
];
}
$result->Materials()->sync($materials);
$event->Materials()->sync($materials);
}

return $result->id;
return $event->id;
}

protected function _getFormattedEvent(int $id): array
Expand Down
14 changes: 7 additions & 7 deletions server/src/App/Controllers/MaterialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,25 @@ public function update(Request $request, Response $response): Response

protected function _saveMaterial(?int $id, array $postData): array
{
if (empty($postData)) {
if (!is_array($postData) || empty($postData)) {
throw new \InvalidArgumentException(
"Missing request data to process validation",
ERROR_VALIDATION
);
}

if (isset($postData['stock_quantity'])) {
$stockQuantity = (int)$postData['stock_quantity'];
if (array_key_exists('stock_quantity', $postData)) {
$stockQuantity = $postData['stock_quantity'];
if ($stockQuantity !== null && (int)$stockQuantity < 0) {
$postData['stock_quantity'] = 0;
}
}

if (isset($postData['out_of_order_quantity'])) {
$stockQuantity = $postData['stock_quantity'] ?? 0;
if (array_key_exists('out_of_order_quantity', $postData)) {
$stockQuantity = (int)($postData['stock_quantity'] ?? 0);
$outOfOrderQuantity = (int)$postData['out_of_order_quantity'];
if ($outOfOrderQuantity > (int)$stockQuantity) {
$outOfOrderQuantity = (int)$stockQuantity;
if ($outOfOrderQuantity > $stockQuantity) {
$outOfOrderQuantity = $stockQuantity;
$postData['out_of_order_quantity'] = $outOfOrderQuantity;
}
if ($outOfOrderQuantity <= 0) {
Expand Down
25 changes: 16 additions & 9 deletions server/src/App/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public function Materials()
];

return $this->belongsToMany('Robert2\API\Models\Material', 'event_materials')
->using('Robert2\API\Models\EventMaterialsPivot')
->withPivot('quantity')
->using('Robert2\API\Models\EventMaterial')
->withPivot('id', 'quantity')
->select($fields);
}

Expand Down Expand Up @@ -214,20 +214,27 @@ public function getAll(bool $withDeleted = false): Builder
public function getMissingMaterials(int $id): ?array
{
$event = $this->with('Materials')->find($id);
if (!$event) {
if (!$event || empty($event->materials)) {
return null;
}

$material = new Material();
$eventMaterials = $material->recalcQuantitiesForPeriod(
$eventMaterials = (new Material())->recalcQuantitiesForPeriod(
$event->materials,
$event->start_date,
$event->end_date
$event->end_date,
$id
);

$missingMaterials = array_filter($eventMaterials, function ($eventMaterial) {
return $eventMaterial['remaining_quantity'] < 0;
});
$missingMaterials = [];
foreach ($eventMaterials as $material) {
$material['missing_quantity'] = $material['pivot']['quantity'] - $material['remaining_quantity'];
$material['missing_quantity'] = min($material['missing_quantity'], $material['pivot']['quantity']);
if ($material['missing_quantity'] <= 0) {
continue;
}

$missingMaterials[] = $material;
}

return empty($missingMaterials) ? null : array_values($missingMaterials);
}
Expand Down
23 changes: 23 additions & 0 deletions server/src/App/Models/EventMaterial.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Robert2\API\Models;

use Illuminate\Database\Eloquent\Relations\Pivot;

class EventMaterial extends Pivot
{
public $incrementing = true;

// ——————————————————————————————————————————————————————
// —
// — Mutators
// —
// ——————————————————————————————————————————————————————

protected $casts = [
'event_id' => 'integer',
'material_id' => 'integer',
'quantity' => 'integer',
];
}
15 changes: 0 additions & 15 deletions server/src/App/Models/EventMaterialsPivot.php

This file was deleted.

82 changes: 21 additions & 61 deletions server/src/App/Models/Material.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function Attributes()
public function Events()
{
return $this->belongsToMany('Robert2\API\Models\Event', 'event_materials')
->using('Robert2\API\Models\EventMaterialsPivot')
->withPivot('quantity')
->using('Robert2\API\Models\EventMaterial')
->withPivot('id', 'quantity')
->select(['events.id', 'title', 'start_date', 'end_date', 'is_confirmed']);
}

Expand Down Expand Up @@ -137,6 +137,10 @@ public function getOutOfOrderQuantityAttribute($value)

public function getParkAttribute()
{
if ($this->is_unitary) {
return null;
}

$park = $this->Park()->first();
return $park ? $park->toArray() : null;
}
Expand Down Expand Up @@ -228,84 +232,40 @@ public function recalcQuantitiesForPeriod(
return [];
}

$Event = new Event();
$events = $Event->setPeriod($start, $end)->getAll();
$events = (new Event())->setPeriod($start, $end)->getAll();
if ($exceptEventId) {
$events = $events->where('id', '!=', $exceptEventId);
}
$events = $events->with('Materials')->get()->toArray();

$periods = $this->_getSplittedPeriods($events);
$events = $events->with('Materials')->get()->toArray();
$periods = splitPeriods($events);

foreach ($data as $index => $material) {
$materialId = $material['id'];
$remainingQuantity = (int)$material['stock_quantity'] - (int)$material['out_of_order_quantity'];
foreach ($data as &$material) {
$quantityPerPeriod = [0];

foreach ($periods as $periodIndex => $period) {
$quantityPerPeriod[$periodIndex] = 0;
$overlapEvents = array_filter($events, function ($event) use ($period) {
return (strtotime($event['start_date']) < strtotime($period[1]) &&
strtotime($event['end_date']) > strtotime($period[0]));
return (
strtotime($event['start_date']) < strtotime($period[1]) &&
strtotime($event['end_date']) > strtotime($period[0])
);
});

$quantityPerPeriod[$periodIndex] = 0;
foreach ($overlapEvents as $event) {
$eventMaterial = $this->_getMaterialFromEvent($materialId, $event);
if (empty($eventMaterial)) {
$eventMaterialIndex = array_search($material['id'], array_column($event['materials'], 'id'));
if ($eventMaterialIndex === false) {
continue;
}

$eventMaterial = $event['materials'][$eventMaterialIndex];
$quantityPerPeriod[$periodIndex] += $eventMaterial['pivot']['quantity'];
}
}

$data[$index]['remaining_quantity'] = $remainingQuantity - max($quantityPerPeriod);
$remainingQuantity = (int)$material['stock_quantity'] - (int)$material['out_of_order_quantity'];
$material['remaining_quantity'] = max($remainingQuantity - max($quantityPerPeriod), 0);
}

return $data;
}

// ------------------------------------------------------
// -
// - Internal Methods
// -
// ------------------------------------------------------

protected function _getSplittedPeriods(array $events): array
{
$timeLine = [];
foreach ($events as $event) {
$timeLine[] = $event['start_date'];
$timeLine[] = $event['end_date'];
}

$timeLine = array_unique($timeLine);
$timeLineCount = count($timeLine);
if ($timeLineCount < 2) {
return [];
}

usort($timeLine, function ($dateTime1, $dateTime2) {
if ($dateTime1 === $dateTime2) {
return 0;
}
return strtotime($dateTime1) < strtotime($dateTime2) ? -1 : 1;
});

$periods = [];
for ($i = 0; $i < $timeLineCount - 1; $i++) {
$periods[] = [$timeLine[$i], $timeLine[$i + 1]];
}

return $periods;
}

protected function _getMaterialFromEvent(int $materialId, array $event): array
{
$eventMaterialIndex = array_search(
$materialId,
array_column($event['materials'], 'id')
);

return $eventMaterialIndex === false ? [] : $event['materials'][$eventMaterialIndex];
}
}
14 changes: 1 addition & 13 deletions server/src/App/Models/Traits/Taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,14 @@ public function getTagsAttribute()

public function getAllFilteredOrTagged(array $conditions, array $tags = [], bool $withDeleted = false): Builder
{
$builder = $this->_getOrderBy();

foreach ($conditions as $field => $value) {
$builder = $builder->where($field, $value);
}

if (!empty($this->searchTerm)) {
$builder = $this->_setSearchConditions($builder);
}
$builder = $this->getAllFiltered($conditions, $withDeleted);

if (!empty($tags)) {
$builder = $builder->whereHas('tags', function ($query) use ($tags) {
$query->whereIn('name', $tags);
});
}

if ($withDeleted) {
$builder = $builder->onlyTrashed();
}

return $builder;
}

Expand Down
Loading

0 comments on commit d6c77c2

Please sign in to comment.