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 9 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

$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$productModule = $this->getProductModule(); $productModule = $this->getProductModule();
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$producerModule = $this->getProducerModule();


$producer = $this->getProducerCurrent(); $producer = $this->getProducerCurrent();
$dateObject = DateTime::createFromFormat('Y-m-d', $date); $dateObject = DateTime::createFromFormat('Y-m-d', $date);
$json['means_payment'] = MeanPayment::getAll(); $json['means_payment'] = MeanPayment::getAll();
$json['producer'] = $this->buildAjaxInfosResponseProducer($producer); $json['producer'] = $this->buildAjaxInfosResponseProducer($producer);
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject); $json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject);
$json['leave_period_dates'] = $this->buildAjaxInfosResponseLeavePeriod($producer);
$json['units'] = Product::$unitsArray; $json['units'] = Product::$unitsArray;


if ($distributionModule->getSolver()->validateDistributionDate($date)) { if ($distributionModule->getSolver()->validateDistributionDate($date)) {
return $json; 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) public function buildAjaxInfosResponsePointsSale(Distribution $distribution)
{ {
$producerModule = $this->getProducerModule(); $producerModule = $this->getProducerModule();


public function buildAjaxInfosResponseDistribution(Distribution $distribution, array $ordersArray, array $productsArray) public function buildAjaxInfosResponseDistribution(Distribution $distribution, array $ordersArray, array $productsArray)
{ {
$producerModule = $this->getProducerModule();
$productModule = $this->getProductModule(); $productModule = $this->getProductModule();
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$distributionModule = $this-> getDistributionModule(); $distributionModule = $this-> getDistributionModule();
'active' => $distribution->active, 'active' => $distribution->active,
'exports' => $distributionModule->getExportManager()->getAjaxArray($distribution), 'exports' => $distributionModule->getExportManager()->getAjaxArray($distribution),
'url_order' => $distributionModule->getLinkOrder($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 // montant et poids des commandes

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

$logoFilenameOld = $model->logo; $logoFilenameOld = $model->logo;
$photoFilenameOld = $model->photo; $photoFilenameOld = $model->photo;
$documentImageBottomFilenameOld = $model->document_image_bottom; $documentImageBottomFilenameOld = $model->document_image_bottom;
$producerBuilder->initOptionDashboardDatesDisplay($model);
$producerBuilder->initOptionsDatesDisplay($model);


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




if($model->validate()) { if($model->validate()) {


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



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

<span class="info-box-text"> <span class="info-box-text">
<h4> <h4>
Distribution du <strong>{{ dateFormat }}</strong> 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> </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="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="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="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> <a @click="activeDistribution" data-active="1" class="btn btn-default" v-else>Activer ce jour</a>
</span> </span>

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

->dropDownList(Dropdown::noYesChoices()); ?> ->dropDownList(Dropdown::noYesChoices()); ?>


<h4>Divers</h4> <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 <?php
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--']; $choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
for ($i = 1; $i < 13; $i++) { for ($i = 1; $i < 13; $i++) {

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

dateFormat: null, dateFormat: null,
loading: true, loading: true,
distribution: { distribution: {
active: false,
active: false
}, },
producer: null, producer: null,
oneDistributionWeekActive: false, oneDistributionWeekActive: false,


app.calendar.attrs = []; app.calendar.attrs = [];
var distributions = response.data.distributions; var distributions = response.data.distributions;
var leave_period_dates = response.data.leave_period_dates;
var dayCurrentIsDistributionActive = false; var dayCurrentIsDistributionActive = false;
var dateFormatCompare = false; var dateFormatCompare = false;
if (app.date) { if (app.date) {
} }
} }


// 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.showLoading = false;
app.checkboxSelectAllOrders = false; app.checkboxSelectAllOrders = false;


setTimeout("opendistrib_popover(); opendistrib_dropdown_tooltip();", 500); setTimeout("opendistrib_popover(); opendistrib_dropdown_tooltip();", 500);


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

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

'type' => 'number', 'type' => 'number',
'message' => 'Prix libre doit être supérieur ou égal à 0' '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.");
}
}
],
]; ];
} }


'id_user_group_default' => "Groupe utilisateur par défaut attribué à l'inscription", '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", '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', '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

$producer->save(); $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)) { if ($producer->$field && strlen($producer->$field)) {
$producer->$field = date( $producer->$field = date(
'Y-m-d', 'Y-m-d',
} }
} }


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)) { if (strlen($producer->$field)) {
$producer->$field = date('d/m/Y', strtotime($producer->$field)); $producer->$field = date('d/m/Y', strtotime($producer->$field));
} }

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



return $producer->$config; 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



class ActiveDistributionsInAdvanceController extends Controller class ActiveDistributionsInAdvanceController extends Controller
{ {
// ./yii active-distributions-in-advance/index
public function actionIndex() public function actionIndex()
{ {
$producerModule = ProducerModule::getInstance(); $producerModule = ProducerModule::getInstance();
$weeksDistributionsActivatedInAdvance = $producerModule->getSolver()->getConfig('option_weeks_distributions_activated_in_advance'); $weeksDistributionsActivatedInAdvance = $producerModule->getSolver()->getConfig('option_weeks_distributions_activated_in_advance');
if($weeksDistributionsActivatedInAdvance) { if($weeksDistributionsActivatedInAdvance) {
$date = new \DateTime('+'.$weeksDistributionsActivatedInAdvance.' weeks'); $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

<?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