Browse Source

[Administration] Gestion des périodes de congés : affichage sur le calendrier des distributions et prise en compte dans l'activation automatique des distributions

feature/souke
Guillaume Bourgeois 10 months ago
parent
commit
7d9338b0c9
10 changed files with 179 additions and 26 deletions
  1. +19
    -0
      backend/controllers/DistributionController.php
  2. +2
    -2
      backend/controllers/ProducerController.php
  3. +7
    -2
      backend/views/distribution/index.php
  4. +6
    -0
      backend/views/producer/update.php
  5. +15
    -2
      backend/web/js/vuejs/distribution-index.js
  6. +36
    -2
      common/logic/Producer/Producer/Model/Producer.php
  7. +15
    -13
      common/logic/Producer/Producer/Service/ProducerBuilder.php
  8. +43
    -0
      common/logic/Producer/Producer/Service/ProducerSolver.php
  9. +8
    -5
      console/commands/ActiveDistributionsInAdvanceController.php
  10. +28
    -0
      console/migrations/m240206_081519_add_columns_producer_leave_period.php

+ 19
- 0
backend/controllers/DistributionController.php View File

@@ -108,6 +108,7 @@ class DistributionController extends BackendController
$orderModule = $this->getOrderModule();
$productModule = $this->getProductModule();
$userModule = $this->getUserModule();
$producerModule = $this->getProducerModule();

$producer = $this->getProducerCurrent();
$dateObject = DateTime::createFromFormat('Y-m-d', $date);
@@ -115,6 +116,7 @@ class DistributionController extends BackendController
$json['means_payment'] = MeanPayment::getAll();
$json['producer'] = $this->buildAjaxInfosResponseProducer($producer);
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject);
$json['leave_period_dates'] = $this->buildAjaxInfosResponseLeavePeriod($producer);
$json['units'] = Product::$unitsArray;

if ($distributionModule->getSolver()->validateDistributionDate($date)) {
@@ -138,6 +140,21 @@ class DistributionController extends BackendController
return $json;
}

public function buildAjaxInfosResponseLeavePeriod(Producer $producer)
{
$producerModule = $this->getProducerModule();
$leavePeriodDatesArray = [];
if($producerModule->getSolver()->hasLeavePeriodDefined($producer)) {
$leavePeriodStart = $producerModule->getSolver()->getLeavePeriodStartDateTime($producer);
$leavePeriodEnd = $producerModule->getSolver()->getLeavePeriodEndDateTime($producer);
for($date = $leavePeriodStart; $date <= $leavePeriodEnd; $date->modify('+1 day')) {
$leavePeriodDatesArray[] = $date->format('Y-m-d');
}
}

return $leavePeriodDatesArray;
}

public function buildAjaxInfosResponsePointsSale(Distribution $distribution)
{
$producerModule = $this->getProducerModule();
@@ -255,6 +272,7 @@ class DistributionController extends BackendController

public function buildAjaxInfosResponseDistribution(Distribution $distribution, array $ordersArray, array $productsArray)
{
$producerModule = $this->getProducerModule();
$productModule = $this->getProductModule();
$orderModule = $this->getOrderModule();
$distributionModule = $this-> getDistributionModule();
@@ -264,6 +282,7 @@ class DistributionController extends BackendController
'active' => $distribution->active,
'exports' => $distributionModule->getExportManager()->getAjaxArray($distribution),
'url_order' => $distributionModule->getLinkOrder($distribution),
'is_leave_period' => $producerModule->getSolver()->isOnLeavePeriod($distribution->producer, DateTime::createFromFormat('Y-m-d', $distribution->date))
];

// montant et poids des commandes

+ 2
- 2
backend/controllers/ProducerController.php View File

@@ -95,7 +95,7 @@ class ProducerController extends BackendController
$logoFilenameOld = $model->logo;
$photoFilenameOld = $model->photo;
$documentImageBottomFilenameOld = $model->document_image_bottom;
$producerBuilder->initOptionDashboardDatesDisplay($model);
$producerBuilder->initOptionsDatesDisplay($model);

if ($model->load(\Yii::$app->request->post())) {

@@ -105,10 +105,10 @@ class ProducerController extends BackendController

if($model->validate()) {

$producerBuilder->initOptionsDatesBeforeSave($model);
$producerBuilder->processUploadImage($model, 'logo', $logoFilenameOld, $request->post('delete_logo', 0));
$producerBuilder->processUploadImage($model, 'photo', $photoFilenameOld, $request->post('delete_photo', 0));
$producerBuilder->processUploadImage($model, 'document_image_bottom', $documentImageBottomFilenameOld, $request->post('delete_document_image_bottom', 0));
$producerBuilder->initOptionDashboardDatesBeforeSave($model);
$producerBuilder->savePrivateKeysStripe($model);
$model->save();


+ 7
- 2
backend/views/distribution/index.php View File

@@ -92,11 +92,16 @@ $this->setPageTitle('Distributions') ;
<span class="info-box-text">
<h4>
Distribution du <strong>{{ dateFormat }}</strong>
<a class="btn btn-default" :href="distribution.url_order" @click="copyLinkOrder($event, distribution.url_order)"><span class="glyphicon glyphicon-link"></span></a>
<a v-if="distribution.active" class="btn btn-default" :href="distribution.url_order" @click="copyLinkOrder($event, distribution.url_order)"><span class="glyphicon glyphicon-link"></span></a>
<span v-if="distribution.is_leave_period" class="label label-info">
<span class="glyphicon glyphicon-info-sign"></span>
Congés
</span>
</h4>

<a @click="activeWeekDistribution" data-active="0" class="btn btn-default btn-active-week" v-if="oneDistributionWeekActive">Désactiver cette semaine</a>
<a @click="activeWeekDistribution" data-active="1" class="btn btn-default btn-active-week" v-else>Activer cette semaine</a>
<a @click="activeDistribution" data-active="0" class="btn btn-default" v-if="distribution.active">Désactiver ce jour</a>
<a @click="activeDistribution" data-active="1" class="btn btn-default" v-else>Activer ce jour</a>
</span>

+ 6
- 0
backend/views/producer/update.php View File

@@ -282,6 +282,12 @@ $this->addBreadcrumb($this->getTitle());
->dropDownList(Dropdown::noYesChoices()); ?>

<h4>Divers</h4>
<?= $form->field($model, 'option_leave_period_start')->textInput([
'class' => 'datepicker form-control'
]); ?>
<?= $form->field($model, 'option_leave_period_end')->textInput([
'class' => 'datepicker form-control'
]); ?>
<?php
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
for ($i = 1; $i < 13; $i++) {

+ 15
- 2
backend/web/js/vuejs/distribution-index.js View File

@@ -46,7 +46,7 @@ var app = new Vue({
dateFormat: null,
loading: true,
distribution: {
active: false,
active: false
},
producer: null,
oneDistributionWeekActive: false,
@@ -210,6 +210,7 @@ var app = new Vue({

app.calendar.attrs = [];
var distributions = response.data.distributions;
var leave_period_dates = response.data.leave_period_dates;
var dayCurrentIsDistributionActive = false;
var dateFormatCompare = false;
if (app.date) {
@@ -244,6 +245,18 @@ var app = new Vue({
}
}

// leave period
if (leave_period_dates.length) {
app.calendar.attrs.push({
key: 'leave_period',
dates: leave_period_dates,
highlight: {
color: 'blue',
fillMode: 'solid'
}
});
}

app.showLoading = false;
app.checkboxSelectAllOrders = false;

@@ -260,7 +273,7 @@ var app = new Vue({
setTimeout("opendistrib_popover(); opendistrib_dropdown_tooltip();", 500);

var highlightStyle = {
color: 'orange',
color: 'black',
fillMode: 'light'
}
if (dayCurrentIsDistributionActive) {

+ 36
- 2
common/logic/Producer/Producer/Model/Producer.php View File

@@ -336,7 +336,39 @@ class Producer extends ActiveRecordCommon
'type' => 'number',
'message' => 'Prix libre doit être supérieur ou égal à 0'
],
[['option_dashboard_date_start', 'option_dashboard_date_end'], 'safe'],
[[
'option_dashboard_date_start',
'option_dashboard_date_end',
'option_leave_period_start',
'option_leave_period_end'
], 'safe'],
[
['option_leave_period_start', 'option_leave_period_end'],
'required',
'when' => function ($model) {
return $model->option_leave_period_start || $model->option_leave_period_end;
}
],
[
'option_leave_period_start',
function ($attribute, $params) {
if($this->option_leave_period_start
&& $this->option_leave_period_end
&& $this->option_leave_period_start > $this->option_leave_period_end) {
$this->addError($attribute, "La date de début de vos congés ne peut pas être après la date de fin.");
}
}
],
[
'option_leave_period_end',
function ($attribute, $params) {
if($this->option_leave_period_start
&& $this->option_leave_period_end
&& $this->option_leave_period_end < $this->option_leave_period_start) {
$this->addError($attribute, "La date de fin de vos congés ne peut pas être avant la date de début.");
}
}
],
];
}

@@ -471,7 +503,9 @@ class Producer extends ActiveRecordCommon
'id_user_group_default' => "Groupe utilisateur par défaut attribué à l'inscription",
'option_check_by_default_prevent_user_credit' => "Par défaut, prévenir l'utilisateur quand on crédite son compte",
'delivery_note_automatic_validation' => 'Validation automatique des bons de livraison',
'website' => 'Site web'
'website' => 'Site web',
'option_leave_period_start' => 'Prochains congés : date de début',
'option_leave_period_end' => 'Prochains congés : date de fin',
];
}


+ 15
- 13
common/logic/Producer/Producer/Service/ProducerBuilder.php View File

@@ -122,15 +122,24 @@ class ProducerBuilder extends AbstractBuilder
$producer->save();
}

public function initOptionDashboardDatesBeforeSave(Producer $producer): void
public function initOptionsDatesBeforeSave(Producer $producer): void
{
$this->initOptionDashboardDateStartEndBeforeSave($producer, true);
$this->initOptionDashboardDateStartEndBeforeSave($producer, false);
$this->initOptionsDatesBeforeSaveByField($producer, 'option_dashboard_date_start');
$this->initOptionsDatesBeforeSaveByField($producer, 'option_dashboard_date_end');
$this->initOptionsDatesBeforeSaveByField($producer, 'option_leave_period_start');
$this->initOptionsDatesBeforeSaveByField($producer, 'option_leave_period_end');
}

private function initOptionDashboardDateStartEndBeforeSave(Producer $producer, bool $dateStart): void
public function initOptionsDatesDisplay(Producer $producer): void
{
$this->initOptionsDatesDisplayByField($producer, 'option_dashboard_date_start');
$this->initOptionsDatesDisplayByField($producer, 'option_dashboard_date_end');
$this->initOptionsDatesDisplayByField($producer, 'option_leave_period_start');
$this->initOptionsDatesDisplayByField($producer, 'option_leave_period_end');
}

private function initOptionsDatesBeforeSaveByField(Producer $producer, string $field): void
{
$field = 'option_dashboard_date_'.($dateStart ? 'start' : 'end');
if ($producer->$field && strlen($producer->$field)) {
$producer->$field = date(
'Y-m-d',
@@ -139,15 +148,8 @@ class ProducerBuilder extends AbstractBuilder
}
}

public function initOptionDashboardDatesDisplay(Producer $producer, bool $dateStart = true): void
{
$this->initOptionDashboardDateStartEndDisplay($producer, true);
$this->initOptionDashboardDateStartEndDisplay($producer, false);
}

private function initOptionDashboardDateStartEndDisplay(Producer $producer, bool $dateStart): void
private function initOptionsDatesDisplayByField(Producer $producer, string $field): void
{
$field = 'option_dashboard_date_'.($dateStart ? 'start' : 'end');
if (strlen($producer->$field)) {
$producer->$field = date('d/m/Y', strtotime($producer->$field));
}

+ 43
- 0
common/logic/Producer/Producer/Service/ProducerSolver.php View File

@@ -260,4 +260,47 @@ class ProducerSolver extends AbstractService implements SolverInterface

return $producer->$config;
}

public function getLeavePeriodStartDateTime(Producer $producer): ?\DateTime
{
if(!$producer->option_leave_period_start) {
return null;
}

return \DateTime::createFromFormat('Y-m-d', $producer->option_leave_period_start)->setTime(0,0);;
}

public function getLeavePeriodEndDateTime(Producer $producer): ?\DateTime
{
if(!$producer->option_leave_period_end) {
return null;
}

return \DateTime::createFromFormat('Y-m-d', $producer->option_leave_period_end)->setTime(23,59);;
}

public function hasLeavePeriodDefined(Producer $producer): bool
{
return $producer->option_leave_period_start && $producer->option_leave_period_end;
}

public function isOnLeavePeriod(Producer $producer, \DateTime $date = null): bool
{
if(!$date) {
$date = new \DateTime();
}

if(!$producer->option_leave_period_start || !$producer->option_leave_period_end) {
return false;
}

$leavePeriodStart = $this->getLeavePeriodStartDateTime($producer);
$leavePeriodEnd = $this->getLeavePeriodEndDateTime($producer);

if($date >= $leavePeriodStart && $date <= $leavePeriodEnd) {
return true;
}

return false;
}
}

+ 8
- 5
console/commands/ActiveDistributionsInAdvanceController.php View File

@@ -8,6 +8,7 @@ use yii\console\Controller;

class ActiveDistributionsInAdvanceController extends Controller
{
// ./yii active-distributions-in-advance/index
public function actionIndex()
{
$producerModule = ProducerModule::getInstance();
@@ -19,12 +20,14 @@ class ActiveDistributionsInAdvanceController extends Controller
$weeksDistributionsActivatedInAdvance = $producerModule->getSolver()->getConfig('option_weeks_distributions_activated_in_advance');
if($weeksDistributionsActivatedInAdvance) {
$date = new \DateTime('+'.$weeksDistributionsActivatedInAdvance.' weeks');
$distributionModule->getBuilder()->activeDistributionByDateIfDelivery($date);
if(!$producerModule->getSolver()->isOnLeavePeriod($producer, $date)) {
$distributionModule->getBuilder()->activeDistributionByDateIfDelivery($date);

$distribution = $distributionModule->getRepository()
->findOneDistribution($date->format('Y-m-d'), true);
if($distribution) {
echo $producer->name. ' : distribution du ' . $date->format('d/m/Y') .' activée' ."\n";
$distribution = $distributionModule->getRepository()
->findOneDistribution($date->format('Y-m-d'), true);
if($distribution) {
echo $producer->name. ' : distribution du ' . $date->format('d/m/Y') .' activée' ."\n";
}
}
}
}

+ 28
- 0
console/migrations/m240206_081519_add_columns_producer_leave_period.php View File

@@ -0,0 +1,28 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240206_081519_add_columns_producer_leave_period
*/
class m240206_081519_add_columns_producer_leave_period extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'option_leave_period_start', Schema::TYPE_DATE);
$this->addColumn('producer', 'option_leave_period_end', Schema::TYPE_DATE);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'option_leave_period_start');
$this->dropColumn('producer', 'option_leave_period_end');
}
}

Loading…
Cancel
Save