|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace producer\controllers; |
|
|
namespace producer\controllers; |
|
|
|
|
|
|
|
|
class CommandeController extends ProducerBaseController { |
|
|
|
|
|
|
|
|
class CommandeController extends ProducerBaseController |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
public function behaviors() { |
|
|
|
|
|
|
|
|
public function behaviors() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'access' => [ |
|
|
'access' => [ |
|
|
'class' => AccessControl::className(), |
|
|
'class' => AccessControl::className(), |
|
|
|
|
|
|
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionInfosProduction($id_production) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne au format JSON toutes les informations relatives à une |
|
|
|
|
|
* production donnée. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id_production |
|
|
|
|
|
* @return mixed |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionInfosProduction($id_production) |
|
|
|
|
|
{ |
|
|
$production = Production::findOne($id_production); |
|
|
$production = Production::findOne($id_production); |
|
|
|
|
|
|
|
|
if ($production) { |
|
|
if ($production) { |
|
|
|
|
|
|
|
|
return json_encode([]); |
|
|
return json_encode([]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialise le formulaire de création/modification de commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @param Commande $commande |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
public function initForm($commande = null) { |
|
|
public function initForm($commande = null) { |
|
|
|
|
|
|
|
|
// etablissements |
|
|
// etablissements |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @return ProducerView |
|
|
* @return ProducerView |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
public function actionHistorique() { |
|
|
|
|
|
|
|
|
public function actionHistorique() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$data_provider_commandes = new ActiveDataProvider([ |
|
|
$data_provider_commandes = new ActiveDataProvider([ |
|
|
'query' => Commande::find() |
|
|
'query' => Commande::find() |
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionRemoveEtablissement($id = 0) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Supprime un producteur. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionRemoveEtablissement($id = 0) |
|
|
|
|
|
{ |
|
|
$user_etablissement = UserEtablissement::find() |
|
|
$user_etablissement = UserEtablissement::find() |
|
|
->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id]) |
|
|
->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id]) |
|
|
->one(); |
|
|
->one(); |
|
|
|
|
|
|
|
|
$this->redirect(['commande/index']); |
|
|
$this->redirect(['commande/index']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionCreate() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Crée une commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @return mixed |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionCreate() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$id_etablissement = $this->getProducer()->id ; |
|
|
$id_etablissement = $this->getProducer()->id ; |
|
|
$commande = new Commande; |
|
|
$commande = new Commande; |
|
|
|
|
|
|
|
|
])); |
|
|
])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionUpdate($id) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Modifie une commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id |
|
|
|
|
|
* @return mixed |
|
|
|
|
|
* @throws UserException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionUpdate($id) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$commande = Commande::find() |
|
|
$commande = Commande::find() |
|
|
->with('production') |
|
|
->with('production') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->render('update', array_merge($this->initForm($commande), [ |
|
|
return $this->render('update', array_merge($this->initForm($commande), [ |
|
|
'model' => $commande, |
|
|
|
|
|
'commande_introuvable' => !$commande, |
|
|
|
|
|
|
|
|
'model' => $commande, |
|
|
|
|
|
'commande_introuvable' => !$commande, |
|
|
])); |
|
|
])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function _verifEtablissementActif($id_etablissement) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Vérifie si un producteur est actif. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id_etablissement |
|
|
|
|
|
* @throws NotFoundHttpException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function _verifEtablissementActif($id_etablissement) |
|
|
|
|
|
{ |
|
|
$etablissement = Etablissement::findOne($id_etablissement); |
|
|
$etablissement = Etablissement::findOne($id_etablissement); |
|
|
if ($etablissement && !$etablissement->actif) { |
|
|
if ($etablissement && !$etablissement->actif) { |
|
|
throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); |
|
|
throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function gestionForm($commande) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Traite le formulaire de création/modification de commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @param Commande $commande |
|
|
|
|
|
*/ |
|
|
|
|
|
public function gestionForm($commande) |
|
|
|
|
|
{ |
|
|
$posts = Yii::$app->request->post(); |
|
|
$posts = Yii::$app->request->post(); |
|
|
$produits = array(); |
|
|
$produits = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionAnnuler($id) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Annule une commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id |
|
|
|
|
|
* @throws \yii\web\NotFoundHttpException |
|
|
|
|
|
* @throws UserException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionAnnuler($id) |
|
|
|
|
|
{ |
|
|
$commande = Commande::find() |
|
|
$commande = Commande::find() |
|
|
->with('production', 'creditHistorique', 'commandeProduits') |
|
|
->with('production', 'creditHistorique', 'commandeProduits') |
|
|
->where(['id' => $id]) |
|
|
->where(['id' => $id]) |
|
|
|
|
|
|
|
|
$this->redirect(Yii::$app->urlManager->createUrl(['commande/historique'])); |
|
|
$this->redirect(Yii::$app->urlManager->createUrl(['commande/historique'])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionVerifCodePointVente($id_point_vente, $code) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Vérifie le code saisi pour un point de vente. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id_point_vente |
|
|
|
|
|
* @param string $code |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionVerifCodePointVente($id_point_vente, $code) |
|
|
|
|
|
{ |
|
|
$point_vente = PointVente::findOne($id_point_vente); |
|
|
$point_vente = PointVente::findOne($id_point_vente); |
|
|
if ($point_vente) { |
|
|
if ($point_vente) { |
|
|
if ($point_vente->verifCode($code)) { |
|
|
if ($point_vente->verifCode($code)) { |