Pārlūkot izejas kodu

Merge branch 'dev'

prodstable
Guillaume Bourgeois pirms 1 gada
vecāks
revīzija
15ecacd42f
1 mainītis faili ar 35 papildinājumiem un 0 dzēšanām
  1. +35
    -0
      backend/controllers/ProducerAdminController.php

+ 35
- 0
backend/controllers/ProducerAdminController.php Parādīt failu

@@ -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.
*

Notiek ielāde…
Atcelt
Saglabāt