Guillaume Bourgeois 1 год назад
Родитель
Сommit
15ecacd42f
1 измененных файлов: 35 добавлений и 0 удалений
  1. +35
    -0
      backend/controllers/ProducerAdminController.php

+ 35
- 0
backend/controllers/ProducerAdminController.php Просмотреть файл

@@ -38,6 +38,7 @@ termes.

namespace backend\controllers;

use common\helpers\GlobalParam;
use Yii;
use common\models\User;
use yii\web\NotFoundHttpException;
@@ -129,6 +130,40 @@ class ProducerAdminController extends BackendController
}
}

public function actionUserTransfer($fromProducerId, $toProducerId, $withOrders = 1)
{
$fromProducerId = (int) $fromProducerId;
$toProducerId = (int) $toProducerId;
$count = 0;
$usersArray = User::findBy(['id_producer' => $fromProducerId])->all();

foreach($usersArray as $user) {
$idUser = $user['user_id'];

$countOrders = 0;
if($withOrders) {
$countOrders = Order::searchCount([
'id_user' => $idUser,
'distribution.id_producer' => $fromProducerId
], ['conditions' => 'date_delete IS NULL']);
}

if(($withOrders && $countOrders) || !$withOrders) {
Producer::addUser($idUser, $toProducerId);
$count ++;
}
}

if($count) {
Yii::$app->getSession()->setFlash('success', $count.' clients importés du producteur #'.$fromProducerId.' vers le producteur #'.$toProducerId.'.');
}
else {
Yii::$app->getSession()->setFlash('error', 'Aucun client à importer.');
}

return $this->redirect(['producer-admin/index']);
}

/**
* Génère la facture mensuelle d'un producteur.
*

Загрузка…
Отмена
Сохранить