Browse Source

Merge branch 'dev'

master
Guillaume Bourgeois 5 years ago
parent
commit
16b98f05a7
1 changed files with 25 additions and 22 deletions
  1. +25
    -22
      backend/controllers/CronController.php

+ 25
- 22
backend/controllers/CronController.php View File

* récap aux producteurs. * récap aux producteurs.
* *
* @param string $key * @param string $key
* @param string $force_date
* @param string $forceDate
*/ */
public function actionProcessOrders($key = '', $forceDate = '') public function actionProcessOrders($key = '', $forceDate = '')
{ {
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
$hour = 20 ;
if(strlen($forceDate)) { if(strlen($forceDate)) {
$date = $forceDate ; $date = $forceDate ;
} }
$distribution = Distribution::findOne([ $distribution = Distribution::findOne([
'date' => $date, 'date' => $date,
'active' => 1, 'active' => 1,
'id_producer' => $producer['id'],
'id_producer' => $producer->id,
]); ]);


if ($distribution && ($hour == $producer['order_deadline'] || strlen($forceDate))) {
if ($distribution && ($hour == $producer->order_deadline || strlen($forceDate))) {
/* /*
* Paiement des commandes (paiement automatique) * Paiement des commandes (paiement automatique)
$arrayOrders = Order::searchAll([ $arrayOrders = Order::searchAll([
'distribution.date' => $date, 'distribution.date' => $date,
'distribution.id_producer' => $producer['id']
'distribution.id_producer' => $producer->id
], [ ], [
'conditions' => 'date_delete IS NULL' 'conditions' => 'date_delete IS NULL'
]) ; ]) ;


$configCredit = Producer::getConfig('credit', $producer['id']) ;
$configCredit = Producer::getConfig('credit', $producer->id) ;
foreach($arrayOrders as $order) {
if($order->payment_auto && $configCredit) {
if ($order->getAmount(Order::AMOUNT_REMAINING) > 0) {
$order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
$order->getAmount(Order::AMOUNT_REMAINING),
$order->distribution->id_producer,
$order->id_user,
User::ID_USER_SYSTEM
);
if($arrayOrders && is_array($arrayOrders)) {
foreach($arrayOrders as $order) {
if($order->auto_payment && $configCredit) {

if ($order->getAmount(Order::AMOUNT_REMAINING) > 0) {
$order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
$order->getAmount(Order::AMOUNT_REMAINING),
$order->distribution->id_producer,
$order->id_user,
User::ID_USER_SYSTEM
);
}
} }
} }
} }
if(!strlen($forceDate)) { if(!strlen($forceDate)) {
$arrayOrders = Order::searchAll([ $arrayOrders = Order::searchAll([
'distribution.date' => $date, 'distribution.date' => $date,
'distribution.id_producer' => $producer['id']
'distribution.id_producer' => $producer->id
], [ ], [
'conditions' => 'date_delete IS NULL' 'conditions' => 'date_delete IS NULL'
]) ; ]) ;
$user = User::searchOne([ $user = User::searchOne([
'id_producer' => $producer['id'],
'id_producer' => $producer->id,
'status' => User::STATUS_PRODUCER 'status' => User::STATUS_PRODUCER
]); ]);


Yii::$app->runAction('distribution/report-cron', [ Yii::$app->runAction('distribution/report-cron', [
'date' => $date, 'date' => $date,
'save' => true, 'save' => true,
'idProducer' => $producer['id'],
'idProducer' => $producer->id,
'key' => '64ac0bdab7e9f5e48c4d991ec5201d57' 'key' => '64ac0bdab7e9f5e48c4d991ec5201d57'
]); ]);
$mail->attach(Yii::getAlias('@app/web/pdf/Orders-' . $date . '-' . $producer['id'] . '.pdf'));
$mail->attach(Yii::getAlias('@app/web/pdf/Orders-' . $date . '-' . $producer->id . '.pdf'));
} else { } else {
$sujet = '[distrib] Aucune commande';
$subject = '[distrib] Aucune commande';
} }


$mail->setSubject($sujet)
$mail->setSubject($subject)
->send(); ->send();
} }
} }

Loading…
Cancel
Save