|
|
@@ -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) |