Преглед изворни кода

Merge branch 'dev'

prodstable
Guillaume Bourgeois пре 2 година
родитељ
комит
ba8cc0075b
5 измењених фајлова са 62 додато и 22 уклоњено
  1. +22
    -8
      backend/controllers/SubscriptionController.php
  2. +3
    -2
      common/models/Order.php
  3. +19
    -11
      common/models/Subscription.php
  4. +3
    -1
      common/models/SubscriptionForm.php
  5. +15
    -0
      common/versions/22.11.A.php

+ 22
- 8
backend/controllers/SubscriptionController.php Прегледај датотеку

@@ -164,11 +164,6 @@ class SubscriptionController extends BackendController
$model->id_user = $subscription->id_user;
$model->username = $subscription->username;
$model->id_point_sale = $subscription->id_point_sale;
$model->date_begin = date('d/m/Y', strtotime($subscription->date_begin));
if (strlen($subscription->date_end)) {
$model->date_end = date('d/m/Y', strtotime($subscription->date_end));
}
$model->monday = $subscription->monday;
$model->tuesday = $subscription->tuesday;
$model->wednesday = $subscription->wednesday;
@@ -178,6 +173,12 @@ class SubscriptionController extends BackendController
$model->sunday = $subscription->sunday;
$model->auto_payment = $subscription->auto_payment;
$model->week_frequency = $subscription->week_frequency;

$model->date_begin = date('d/m/Y', strtotime($subscription->date_begin));
if ($subscription->date_end) {
$model->date_end = date('d/m/Y', strtotime($subscription->date_end));
}

if(strlen($subscription->comment)) {
$model->comment = $subscription->comment ;
}
@@ -200,13 +201,26 @@ class SubscriptionController extends BackendController
]) ;

if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (!strlen($model->date_end)) {

if (!$model->date_end) {
$model->date_end = null;
}

if ($model->save()) {
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié');

$subscription = Subscription::findOne($model->id) ;

$messageOrdersDeleted = '';
if($model->date_end) {
$countOrdersDeleted = $subscription->deleteOrdersIncomingDistributions(true);

if($countOrdersDeleted) {
$messageOrdersDeleted = '<br />'.$countOrdersDeleted.' commandes supprimées';
}
}

Yii::$app->getSession()->setFlash('success', 'Abonnement modifié'.$messageOrdersDeleted);

$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions() ;
if(count($matchedDistributionsArray)) {
return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id,'update' => true]);

+ 3
- 2
common/models/Order.php Прегледај датотеку

@@ -349,7 +349,7 @@ class Order extends ActiveRecordCommon
}
}

public function delete()
public function delete($force = false)
{
// remboursement si l'utilisateur a payé pour cette commande
$amountPaid = $this->getAmount(Order::AMOUNT_PAID);
@@ -367,7 +367,8 @@ class Order extends ActiveRecordCommon
if (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
(Producer::getConfig(
'option_behavior_cancel_order'
) == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete))) {
) == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ||
$force) {
ProductOrder::deleteAll(['id_order' => $this->id]);
return parent::delete();
} // status 'delete'

+ 19
- 11
common/models/Subscription.php Прегледај датотеку

@@ -89,7 +89,7 @@ class Subscription extends ActiveRecordCommon
[['id_user', 'id_producer', 'id_point_sale', 'monday', 'tuesday',
'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'week_frequency'], 'integer'],
[['auto_payment'], 'boolean'],
[['date_begin', 'date_end', 'username', 'comment'], 'safe'],
[['username', 'comment', 'date_begin', 'date_end'], 'safe'],
];
}

@@ -253,7 +253,6 @@ class Subscription extends ActiveRecordCommon
}

// produits
$amountTotal = 0;
$productsAdd = false;
foreach ($this->productSubscription as $productSubscription) {
$productOrder = new ProductOrder;
@@ -390,7 +389,6 @@ class Subscription extends ActiveRecordCommon
*/
public function searchMatchedIncomingDistributions()
{
$producer = GlobalParam::getCurrentProducer();
$params = [
':date_earliest_order' => date('Y-m-d'),
':date_begin' => date('Y-m-d', strtotime($this->date_begin)),
@@ -403,7 +401,7 @@ class Subscription extends ActiveRecordCommon
->andWhere('date > :date_earliest_order');

if ($this->date_end) {
$incomingDistributions->andWhere('date < :date_end');
$incomingDistributions->andWhere('date <= :date_end');
$params[':date_end'] = date('Y-m-d', strtotime($this->date_end));
}

@@ -411,8 +409,7 @@ class Subscription extends ActiveRecordCommon

$incomingDistributions->params($params);
$incomingDistributionsArray = $incomingDistributions->all();

$incomingDistributions = Distribution::filterDistributionsByDateDelay($incomingDistributionsArray);
Distribution::filterDistributionsByDateDelay($incomingDistributionsArray);

$matchedIncomingDistributionsArray = [];
foreach ($incomingDistributionsArray as $incomingDistribution) {
@@ -424,16 +421,22 @@ class Subscription extends ActiveRecordCommon
return $matchedIncomingDistributionsArray;
}

public function deleteOrdersIncomingDistributions()
public function deleteOrdersIncomingDistributions($deleteAfterDateEnd = false)
{
$dateStart = $this->date_begin;
$comparatorDateStart = '>=';
if($deleteAfterDateEnd) {
$dateStart = $this->date_end;
$comparatorDateStart = '>';
}

$params = [
':id_producer' => GlobalParam::getCurrentProducerId(),
':date_today' => date('Y-m-d'),
':date_begin' => $this->date_begin,
':date_start' => $dateStart,
':id_subscription' => $this->id
];


$orderDeadline = Producer::getConfig('order_deadline');
$hour = date('G');

@@ -447,7 +450,7 @@ class Subscription extends ActiveRecordCommon
->joinWith('distribution')
->where('distribution.id_producer = :id_producer')
->andWhere($conditionDistributionDate)
->andWhere('distribution.date >= :date_begin')
->andWhere('distribution.date '.$comparatorDateStart.' :date_start')
->andWhere('order.id_subscription = :id_subscription');

$orders->params($params);
@@ -455,6 +458,7 @@ class Subscription extends ActiveRecordCommon
$ordersArray = $orders->all();
$configCredit = Producer::getConfig('credit');

$countOrdersDeleted = 0;
if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) {

@@ -471,9 +475,13 @@ class Subscription extends ActiveRecordCommon
);
}

$order->delete();
$order->delete(true);

$countOrdersDeleted ++;
}
}

return $countOrdersDeleted;
}

public function updateIncomingDistributions($update = false)

+ 3
- 1
common/models/SubscriptionForm.php Прегледај датотеку

@@ -133,7 +133,9 @@ class SubscriptionForm extends Model
'Y-m-d',
strtotime(str_replace('/', '-', $this->date_begin)
));
if (strlen($this->date_end)) {

$subscription->date_end = null;
if ($this->date_end) {
$subscription->date_end = date(
'Y-m-d',
strtotime(str_replace('/', '-', $this->date_end)

+ 15
- 0
common/versions/22.11.A.php Прегледај датотеку

@@ -0,0 +1,15 @@

<h4>Date de sortie</h4>
<ul>
<li></li>
</ul>

<h4>Évolutions</h4>
<ul>
<li></li>
</ul>

<h4>Maintenance</h4>
<ul>
<li>[Administration] Abonnements : suppression des commandes après la date de fin lors de l'arrêt d'un abonnement</li>
</ul>

Loading…
Откажи
Сачувај