Browse Source

Merge branch 'dev'

prodstable
Guillaume Bourgeois 1 year ago
parent
commit
15ecacd42f
1 changed files with 35 additions and 0 deletions
  1. +35
    -0
      backend/controllers/ProducerAdminController.php

+ 35
- 0
backend/controllers/ProducerAdminController.php View File

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

Loading…
Cancel
Save