|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace backend\controllers; |
|
|
namespace backend\controllers; |
|
|
|
|
|
|
|
|
|
|
|
use common\helpers\GlobalParam; |
|
|
use Yii; |
|
|
use Yii; |
|
|
use common\models\User; |
|
|
use common\models\User; |
|
|
use yii\web\NotFoundHttpException; |
|
|
use yii\web\NotFoundHttpException; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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. |
|
|
* Génère la facture mensuelle d'un producteur. |
|
|
* |
|
|
* |