Début de mise en place.refactoring
@@ -0,0 +1,496 @@ | |||
<?php | |||
namespace producer\controllers; | |||
class CommandeController extends CommonController { | |||
public function behaviors() { | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
] | |||
], | |||
], | |||
]; | |||
} | |||
public function actionInfosProduction($id_production) { | |||
$production = Production::findOne($id_production); | |||
if ($production) { | |||
$arr = []; | |||
$produits_dispos = ProductionProduit::findProduits($production->id); | |||
$arr['produits_dispos'] = $produits_dispos; | |||
$points_vente = PointVente::find() | |||
->joinWith(['productionPointVente' => function($q) use ($production) { | |||
$q->where(['id_production' => $production->id]); | |||
}]) | |||
->where([ | |||
'id_etablissement' => $production->id_etablissement, | |||
]) | |||
->all(); | |||
$arr['points_vente'] = []; | |||
foreach ($points_vente as $pv) { | |||
if (isset($pv->productionPointVente) && | |||
isset($pv->productionPointVente[0])) { | |||
$arr['points_vente'][$pv->id] = $pv->productionPointVente[0]->livraison; | |||
} else { | |||
$arr['points_vente'][$pv->id] = false; | |||
} | |||
} | |||
return json_encode($arr); | |||
} | |||
return json_encode([]); | |||
} | |||
public static function initForm($commande = null) { | |||
// etablissements | |||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | |||
$id_etablissement = Yii::$app->request->get('id_etablissement', 0); | |||
$etablissement_paiement_ok = false; | |||
if ($id_etablissement) { | |||
$etablissement = Etablissement::findOne($id_etablissement); | |||
if ($etablissement->etatPaiement() == Etablissement::PAIEMENT_OK || $etablissement->etatPaiement() == Etablissement::PAIEMENT_ESSAI) { | |||
$etablissement_paiement_ok = true; | |||
} | |||
} | |||
// etablissement | |||
$etablissement = Etablissement::findOne($id_etablissement); | |||
// points de vente | |||
$points_vente = PointVente::find() | |||
->with('pointVenteUser') | |||
->where(['id_etablissement' => $id_etablissement]) | |||
->andWhere('acces_restreint = 0 OR (acces_restreint = 1 AND (SELECT COUNT(*) FROM point_vente_user WHERE point_vente.id = point_vente_user.id_point_vente AND point_vente_user.id_user = :id_user) > 0)') | |||
->params([':id_user' => Yii::$app->user->identity->id]) | |||
->all(); | |||
$arr_points_vente = $points_vente; | |||
// jours de production | |||
$heure_limite = 20; | |||
$date = date('Y-m-d'); | |||
if (isset($etablissement)) { | |||
$heure_limite = $etablissement->heure_limite_commande; | |||
if (date('H') >= $heure_limite) { | |||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande) * (24 * 60 * 60)); | |||
} else { | |||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($etablissement->delai_commande - 1) * (24 * 60 * 60)); | |||
} | |||
} | |||
$jours_production = Production::find() | |||
->where(['actif' => 1]) | |||
->andWhere('date > :date') | |||
->andWhere(['id_etablissement' => $id_etablissement]) | |||
->addParams([':date' => $date]) | |||
->all(); | |||
$arr_jours_production = array('' => '--'); | |||
foreach ($jours_production as $j) | |||
$arr_jours_production[$j->id] = date('d/m/Y', strtotime($j->date)); | |||
// produits | |||
$produits = Produit::find() | |||
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') | |||
->where(['produit.actif' => 1, 'id_etablissement' => $id_etablissement]) | |||
->andWhere('produit.vrac IS NULL OR produit.vrac = 0') | |||
->orderBy('produit.order ASC')->all(); | |||
$arr_produits = array(); | |||
foreach ($produits as $p) | |||
$arr_produits[] = $p; | |||
// produits vrac | |||
$produits_vrac = Produit::find()->where(['actif' => 1, 'vrac' => 1])->orderBy('order ASC')->all(); | |||
// produits selec | |||
$posts = Yii::$app->request->post(); | |||
$produits_selec = []; | |||
if (isset($posts['Produit'])) { | |||
foreach ($posts['Produit'] as $key => $quantity) { | |||
$key = (int) str_replace('produit_', '', $key); | |||
$p = Produit::find()->where(['id' => $key])->one(); | |||
if ($p && $quantity) | |||
$produits_selec[$p->id] = (int) $quantity; | |||
} | |||
} | |||
elseif (!is_null($commande)) { | |||
$produits_commande = CommandeProduit::find()->where(['id_commande' => $commande->id])->all(); | |||
foreach ($produits_commande as $pc) { | |||
$produits_selec[$pc->id_produit] = (int) $pc->quantite; | |||
} | |||
} | |||
$produits_dispos = []; | |||
$production = null; | |||
if (!is_null($commande) && $commande->id_production) { | |||
$produits_dispos = ProductionProduit::findProduits($commande->id_production); | |||
$production = Production::find()->where(['id' => $commande->id_production])->one(); | |||
} | |||
$commandes = Commande::find() | |||
->where(['id_user' => Yii::$app->user->identity->id]) | |||
->all(); | |||
if ($id_etablissement) { | |||
$user_etablissement = UserEtablissement::find() | |||
->where([ | |||
'id_etablissement' => $id_etablissement, | |||
'id_user' => Yii::$app->user->identity->id | |||
]) | |||
->one(); | |||
$credit = $user_etablissement->credit; | |||
} else { | |||
$credit = 0; | |||
} | |||
return [ | |||
'points_vente' => $arr_points_vente, | |||
'jours_production' => $arr_jours_production, | |||
'produits' => $produits, | |||
'produits_selec' => $produits_selec, | |||
'produits_dispos' => $produits_dispos, | |||
'production' => $production, | |||
'commandes_en_cours' => $commandes, | |||
'produits_vrac' => $produits_vrac, | |||
'etablissements' => $etablissements, | |||
'id_etablissement' => $id_etablissement, | |||
'etablissement' => $etablissement, | |||
'etablissement_paiement_ok' => $etablissement_paiement_ok, | |||
'credit' => $credit | |||
]; | |||
} | |||
public function actionIndex() { | |||
$model_form_etablissement = new AddEtablissementForm(); | |||
if ($model_form_etablissement->load(Yii::$app->request->post()) && $model_form_etablissement->validate()) { | |||
$model_form_etablissement->add(); | |||
$model_form_etablissement->code = ''; | |||
} | |||
// liste des etablissements | |||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | |||
// liste des établissement disponibles | |||
$arr_etablissements = Etablissement::getEtablissementsPopulateDropdown(); | |||
$data_etablissements_dispos = $arr_etablissements['data']; | |||
$options_etablissements_dispos = $arr_etablissements['options']; | |||
// liste des commandes | |||
$commandes = Commande::find() | |||
->with('commandeProduits', 'pointVente', 'creditHistorique') | |||
->joinWith('production', 'production.etablissement') | |||
->where(['id_user' => Yii::$app->user->id]) | |||
//->andWhere('production.date < '.) | |||
->orderBy('production.date DESC') | |||
->limit(40) | |||
->all(); | |||
// initilisation commandes | |||
foreach ($commandes as $c) | |||
$c->init(); | |||
return $this->render('index', [ | |||
'commandes' => $commandes, | |||
'commande_ok' => Yii::$app->getRequest()->get('commande_ok', false), | |||
'annule_ok' => Yii::$app->getRequest()->get('annule_ok', false), | |||
'pate_deja_petrie' => Yii::$app->getRequest()->get('pate_deja_petrie', false), | |||
'etablissements' => $etablissements, | |||
'model_form_etablissement' => $model_form_etablissement, | |||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||
]); | |||
} | |||
public function actionRemoveEtablissement($id = 0) { | |||
$user_etablissement = UserEtablissement::find() | |||
->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id]) | |||
->one(); | |||
$user_etablissement->actif = 0; | |||
$user_etablissement->save(); | |||
$this->redirect(['commande/index']); | |||
} | |||
public function actionCreate($id_etablissement = 0) { | |||
$commande = new Commande; | |||
$posts = Yii::$app->request->post(); | |||
if ($id_etablissement) | |||
$this->_verifEtablissementActif($id_etablissement); | |||
if ($commande->load($posts)) { | |||
$commande = Commande::find()->where('id_production = ' . $posts['Commande']['id_production'])->andWhere('id_user = ' . Yii::$app->user->id)->one(); | |||
if (!$commande) { | |||
$commande = new Commande; | |||
$commande->load(Yii::$app->request->post()); | |||
$commande->id_user = Yii::$app->user->id; | |||
$commande->date = date('Y-m-d H:i:s'); | |||
$commande->type = Commande::TYPE_USER; | |||
} | |||
$this->gestionForm($commande); | |||
} | |||
return $this->render('create', array_merge(self::initForm($commande), [ | |||
'model' => $commande | |||
])); | |||
} | |||
public function actionUpdate($id) { | |||
$commande = Commande::find() | |||
->with('production') | |||
->where(['id' => $id]) | |||
->one(); | |||
if ($commande->getEtat() != Commande::ETAT_MODIFIABLE) { | |||
throw new UserException('Cette commande n\'est pas modifiable.'); | |||
} | |||
$this->_verifEtablissementActif($commande->production->id_etablissement); | |||
if ($commande && $commande->load(Yii::$app->request->post())) { | |||
$commande->date_update = date('Y-m-d H:i:s'); | |||
$this->gestionForm($commande); | |||
} | |||
return $this->render('update', array_merge(self::initForm($commande), [ | |||
'model' => $commande, | |||
'commande_introuvable' => !$commande, | |||
])); | |||
} | |||
public function _verifEtablissementActif($id_etablissement) { | |||
$etablissement = Etablissement::findOne($id_etablissement); | |||
if ($etablissement && !$etablissement->actif) { | |||
throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); | |||
} | |||
} | |||
public function gestionForm($commande) { | |||
$posts = Yii::$app->request->post(); | |||
$produits = array(); | |||
$quantite_totale = 0; | |||
foreach ($posts['Produit'] as $key => $quantity) { | |||
$key = (int) str_replace('produit_', '', $key); | |||
$p = Produit::find()->where(['id' => $key])->one(); | |||
$quantite_totale += $quantity; | |||
if ($p && $quantity) | |||
$produits[] = $p; | |||
} | |||
// nombre de produits | |||
$err_nb_produits = false; | |||
if (!Yii::$app->user->identity->confiance && $quantite_totale > 3) { | |||
$err_nb_produits = true; | |||
} | |||
// date | |||
$err_date = false; | |||
$pate_deja_petrie = false; | |||
if (isset($commande->id_production)) { | |||
// date de commande | |||
$production = Production::find()->where(['id' => $commande->id_production])->one(); | |||
if (date('H') >= 20) { | |||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + 60 * 60 * 24); | |||
} else { | |||
$date = date('Y-m-d'); | |||
} | |||
if ($production->date < $date) { | |||
$err_date = true; | |||
} | |||
} | |||
// point de vente | |||
$err_point_vente = false; | |||
if (isset($production) && $production) { | |||
$ppv = ProductionPointVente::find() | |||
->where([ | |||
'id_production' => $production->id, | |||
'id_point_vente' => $posts['Commande']['id_point_vente'] | |||
]) | |||
->one(); | |||
if (!$ppv || !$ppv->livraison) { | |||
$err_point_vente = true; | |||
} | |||
$point_vente = PointVente::findOne($posts['Commande']['id_point_vente']); | |||
if ($point_vente) { | |||
if (strlen($point_vente->code) && !$point_vente->verifCode($posts['code_point_vente_' . $point_vente->id])) { | |||
$err_point_vente = true; | |||
} | |||
} else { | |||
$err_point_vente = true; | |||
} | |||
} | |||
if ($commande->validate() && count($produits) && !$err_nb_produits && !$err_date && !$err_point_vente) { | |||
// gestion point de vente | |||
$pv = PointVente::find() | |||
->with('pointVenteUser') | |||
->where(['id' => $commande->id_point_vente]) | |||
->one(); | |||
if ($pv && strlen($pv->getCommentaire())) | |||
$commande->commentaire_point_vente = $pv->getCommentaire(); | |||
else | |||
$commande->commentaire_point_vente = ''; | |||
// sauvegarde de la commande | |||
$commande->save(); | |||
// suppression de tous les enregistrements CommandeProduit | |||
if (!is_null($commande)) { | |||
CommandeProduit::deleteAll(['id_commande' => $commande->id]); | |||
} | |||
// produits dispos | |||
$produits_dispos = ProductionProduit::findProduits($production->id); | |||
// sauvegarde des produits | |||
foreach ($produits as $p) { | |||
// le produit doit etre dispo à la vente | |||
if (isset($produits_dispos[$p->id]) && $produits_dispos[$p->id]['actif']) { | |||
$commande_produit = new CommandeProduit(); | |||
$commande_produit->id_commande = $commande->id; | |||
$commande_produit->id_produit = $p->id; | |||
$commande_produit->prix = $p->prix; | |||
$quantite_voulue = (int) $posts['Produit']['produit_' . $p->id]; | |||
if ($produits_dispos[$p->id]['quantite_max'] && $quantite_voulue > $produits_dispos[$p->id]['quantite_restante']) | |||
$quantite_voulue = $produits_dispos[$p->id]['quantite_restante']; | |||
$commande_produit->quantite = $quantite_voulue; | |||
$commande_produit->save(); | |||
} | |||
} | |||
// credit pain | |||
$credit_pain = isset($posts['credit_pain']) && $posts['credit_pain']; | |||
if ($credit_pain && ($pv->credit_pain || $commande->getMontantPaye())) { | |||
$commande = Commande::find() | |||
->with('commandeProduits') | |||
->where(['id' => $commande->id]) | |||
->one(); | |||
$commande->init(); | |||
$montant_paye = $commande->getMontantPaye(); | |||
// à payer | |||
if ($commande->getStatutPaiement() == Commande::STATUT_IMPAYEE) { | |||
$montant_payer = $commande->montant - $montant_paye; | |||
$credit = Yii::$app->user->identity->getCredit($production->id_etablissement); | |||
if ($montant_payer > $credit) { | |||
$montant_payer = $credit; | |||
} | |||
if ($montant_payer > 0) { | |||
$commande->creditHistorique( | |||
CreditHistorique::TYPE_PAIEMENT, | |||
$montant_payer, | |||
$production->id_etablissement, | |||
Yii::$app->user->identity->id, | |||
Yii::$app->user->identity->id | |||
); | |||
} | |||
} | |||
// surplus à rembourser | |||
elseif ($commande->getStatutPaiement() == Commande::STATUT_SURPLUS) { | |||
$montant_rembourser = $montant_paye - $commande->montant; | |||
$commande->creditHistorique( | |||
CreditHistorique::TYPE_REMBOURSEMENT, | |||
$montant_rembourser, | |||
$production->id_etablissement, | |||
Yii::$app->user->identity->id, | |||
Yii::$app->user->identity->id | |||
); | |||
} | |||
} | |||
// redirection | |||
$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie])); | |||
} else { | |||
if (!count($produits)) | |||
Yii::$app->session->setFlash('error', "Vous n'avez choisi aucun produit"); | |||
if ($err_nb_produits) | |||
Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander plus de 3 produits"); | |||
if ($err_date) | |||
Yii::$app->session->setFlash('error', "Vous ne pouvez pas commander pour cette date."); | |||
if ($err_point_vente) | |||
Yii::$app->session->setFlash('error', "Point de vente invalide."); | |||
} | |||
} | |||
public function actionAnnuler($id) { | |||
$commande = Commande::find() | |||
->with('production', 'creditHistorique', 'commandeProduits') | |||
->where(['id' => $id]) | |||
->one(); | |||
if ($commande->getEtat() != Commande::ETAT_MODIFIABLE) { | |||
throw new UserException('Vous ne pouvez plus annuler cette commande.'); | |||
} | |||
$commande->init(); | |||
if ($commande && Yii::$app->user->id == $commande->id_user) { | |||
// remboursement | |||
if ($commande->getMontantPaye()) { | |||
$commande->creditHistorique( | |||
CreditHistorique::TYPE_REMBOURSEMENT, | |||
$commande->getMontantPaye(), | |||
$commande->production->id_etablissement, | |||
Yii::$app->user->identity->id, | |||
Yii::$app->user->identity->id | |||
); | |||
} | |||
// delete | |||
$commande->delete(); | |||
CommandeProduit::deleteAll(['id_commande' => $commande->id]); | |||
} | |||
$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'annule_ok' => true])); | |||
} | |||
public function actionVerifCodePointVente($id_point_vente, $code) { | |||
$point_vente = PointVente::findOne($id_point_vente); | |||
if ($point_vente) { | |||
if ($point_vente->verifCode($code)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} | |||
@@ -0,0 +1,2 @@ | |||
* | |||
!.gitignore |
@@ -0,0 +1,307 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
use yii\widgets\ActiveForm; | |||
use common\models\Etablissement; | |||
/* @var $this yii\web\View */ | |||
/* @var $model common\models\Commande */ | |||
/* @var $form ActiveForm */ | |||
?> | |||
<div class="commande-form"> | |||
<h2 id="step-choix-etablissement">Je choisis mon producteur</h2> | |||
<?php if(count($etablissements)): ?> | |||
<?= | |||
$this->render('_liste_etablissements.php',[ | |||
'etablissements' => $etablissements, | |||
'context' => 'commande', | |||
'id_etablissement' => $id_etablissement, | |||
'etablissement_paiement_ok' => $etablissement_paiement_ok, | |||
]) ; | |||
?> | |||
<div class="clr"></div> | |||
<?php else: ?> | |||
<div class="alert alert-info">Veuiller <a href="<?= Yii::$app->urlManager->createUrl(['commande/index']) ; ?>">ajouter un producteur</a> à votre tableau de bord avant de passer commande.</div> | |||
<?php endif; ?> | |||
<?php | |||
$form = ActiveForm::begin([ | |||
'enableClientScript' => false | |||
]); | |||
?> | |||
<?php if($id_etablissement && $etablissement_paiement_ok): ?> | |||
<div class="col-md-6"> | |||
<h2 id="step-choix-date">Date de commande</h2> | |||
<?= $form->field($model, 'id_production')->label('')->hiddenInput(); ?> | |||
<?php if (isset($model->id)): ?> | |||
<div class="date-commande"><span><?php echo date('d/m/Y', strtotime($production->date)); ?></span></div> | |||
<?= Html::hiddenInput('id_commande', $model->id,['id'=>'id-commande']); ?> | |||
<?= Html::hiddenInput('montant_paye', $model->getMontantPaye(),['id'=>'montant-paye']); ?> | |||
<?php endif; ?> | |||
<div id="datepicker-production" <?php if (isset($model->id)): ?>style="display:none"<?php endif; ?>> | |||
</div> | |||
<?php if (!isset($model->id)): ?> | |||
<br /> | |||
<?php endif; ?> | |||
<div id="dates" style="display:none;"> | |||
<?php | |||
foreach ($jours_production as $id_production => $j) { | |||
if ($j != '--') { | |||
echo '<div><span class="date">' . $j . '</span><span class="id_production">' . $id_production . '</span></div>'; | |||
} | |||
} | |||
?> | |||
</div> | |||
<div class="clr"></div> | |||
<div id="commandes-en-cours" style="display:none;"> | |||
<?php foreach ($commandes_en_cours as $c): ?> | |||
<?php echo '<div class="commande" data-idproduction="' . $c->id_production . '" data-id="' . $c->id . '" data-href="' . Yii::$app->urlManager->createUrl(['commande/update', 'id' => $c->id, 'id_etablissement' => $c->production->id_etablissement]) . '"></div>'; ?> | |||
<?php endforeach; ?> | |||
</div> | |||
<div id="has-commande-en-cours" style="display:none;" class="alert alert-danger">Vous avez déjà une commande en cours pour cette date. <a href="#">Cliquez ici</a> pour la modifier.</div> | |||
</div> | |||
<div class="col-md-6"> | |||
<?php if(strlen($etablissement->infos_commande)): ?> | |||
<h2>Infos du producteur</h2> | |||
<div id="infos-commande"> | |||
<?= nl2br(Html::encode($etablissement->infos_commande)) ?> | |||
</div> | |||
<?php endif; ?> | |||
</div> | |||
<div class="clr"></div> | |||
<div id="depots"> | |||
<h2 id="step-choix-depot">Je choisis un dépôt</h2> | |||
<?= | |||
$form->field($model, 'id_point_vente') | |||
->label('') | |||
->hiddenInput(); | |||
//->dropDownList($points_vente) ; | |||
?> | |||
<input type="hidden" id="livraison" value="<?php if (!is_null($production) && $production->livraison): ?>1<?php else: ?>0<?php endif; ?>" /> | |||
<ul id="points-vente" class="blocs"> | |||
<?php | |||
foreach ($points_vente as $pv) { | |||
$commentaire = '' ; | |||
if(isset($pv->pointVenteUser) && is_array($pv->pointVenteUser) && count($pv->pointVenteUser)) | |||
{ | |||
foreach($pv->pointVenteUser as $pvu) | |||
{ | |||
if($pvu->id_user == Yii::$app->user->identity->id && strlen($pvu->commentaire)) | |||
{ | |||
$commentaire = '<div class="commentaire"><span>'.Html::encode($pvu->commentaire).'</span></div>' ; | |||
} | |||
} | |||
} | |||
$html_code = '' ; | |||
$data_code = '0' ; | |||
$code = '' ; | |||
if(strlen($pv->code)) | |||
{ | |||
if(!isset($model->id_point_vente) || $model->id_point_vente != $pv->id) | |||
{ | |||
$html_code .= '<span class="glyphicon glyphicon-lock"></span> ' ; | |||
$data_code = '1' ; | |||
} | |||
else { | |||
$code = $pv->code ; | |||
} | |||
} | |||
echo '<li class="bloc point-vente point-vente-' . $pv->id . '" data-code="'.$data_code.'" data-vrac="' . (int) $pv->vrac . '" data-pain="' . (int) $pv->pain . '" data-credit-pain="'.(int) $pv->credit_pain.'"><div class="contenu">' . | |||
'<span style="display:none;" class="id">' . $pv->id . '</span>' . | |||
'<div class="nom">' .$html_code. Html::encode($pv->nom) . '</div>' . | |||
'<div class="adresse">à ' . Html::encode($pv->localite) . '</div>' . | |||
'<div class="horaires">' . | |||
'<div class="jour jour-1">' . (strlen($pv->horaires_lundi) ? nl2br(Html::encode($pv->horaires_lundi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-2">' . (strlen($pv->horaires_mardi) ? nl2br(Html::encode($pv->horaires_mardi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-3">' . (strlen($pv->horaires_mercredi) ? nl2br(Html::encode($pv->horaires_mercredi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-4">' . (strlen($pv->horaires_jeudi) ? nl2br(Html::encode($pv->horaires_jeudi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-5">' . (strlen($pv->horaires_vendredi) ? nl2br(Html::encode($pv->horaires_vendredi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-6">' . (strlen($pv->horaires_samedi) ? nl2br(Html::encode($pv->horaires_samedi)) : 'Fermé') . '</div>' . | |||
'<div class="jour jour-0">' . (strlen($pv->horaires_dimanche) ? nl2br(Html::encode($pv->horaires_dimanche)) : 'Fermé') . '</div>' . | |||
'</div>' | |||
. $commentaire . | |||
'<input type="hidden" name="code_point_vente_'.$pv->id.'" value="'.$code.'" />'. | |||
'</div></li>'; | |||
} | |||
?> | |||
</ul> | |||
<div class="clr"></div> | |||
</div> | |||
<div id="produits"> | |||
<h2 id="step-choix-produits">Mes produits</h2> | |||
<?php // confiance ?> | |||
<input type="hidden" id="confiance" value="<?php echo (int) Yii::$app->user->identity->confiance; ?>" /> | |||
<?php if (!Yii::$app->user->identity->confiance): ?> | |||
<div id="mess-limit-quantity" class="alert alert-warning"><strong>Attention,</strong> vous ne pouvez commander que 3 produits.</div> | |||
<?php endif; ?> | |||
<?php // erreur ?> | |||
<?php if (Yii::$app->session->getFlash('error')): ?> | |||
<div class="alert alert-danger"><div class="icon"></div><?= Yii::$app->session->getFlash('error'); ?></div> | |||
<?php endif; ?> | |||
<div id="pain"> | |||
<div class="alert alert-warning indisponible">Pain indisponible pour ce point de vente</div> | |||
<table class="table table-bordered" id="table-produits"> | |||
<thead> | |||
<tr> | |||
<th class="th-photo">Photo</th> | |||
<th class="produit">Produit</th> | |||
<th class="prix-unit">Prix unitaire</th> | |||
<th class="colonne-quantite">Quantité</th> | |||
<th class="total">Total</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach ($produits as $p): ?> | |||
<?php | |||
$quantite = 0; | |||
if (isset($produits_selec[$p->id])) | |||
$quantite = $produits_selec[$p->id]; | |||
?> | |||
<tr class="produit-<?php echo $p->id; ?>" data-no-limit="<?php if(!$p->quantite_max): ?>1<?php else: ?>0<?php endif; ?>" data-quantite-max="<?= $quantite ?>" <?php if (count($produits_dispos) && !$produits_dispos[$p->id]['actif']): ?>style="display:none;"<?php endif; ?>> | |||
<td class="td-photo"> | |||
<?php if (strlen($p->photo) && file_exists(dirname(__FILE__).'/../../web/uploads/' . $p->photo)): ?><a href="<?= Yii::$app->urlManager->getBaseUrl() . '/uploads/' . $p->photo ?>" data-lightbox="produit-<?php echo $p->id; ?>"><img class="photo img-rounded" src="<?= Yii::$app->urlManager->getBaseUrl() . '/uploads/' . $p->photo ?>" alt="Photo <?= Html::encode($p->nom); ?>" /></a><?php endif; ?> | |||
</td> | |||
<td class="produit"> | |||
<span class="nom"><?= Html::encode($p->nom); ?></span> - <span class="description"><?= Html::encode($p->getDescription()); ?></span><br /> | |||
<span class="recette"><?= Html::encode($p->recette); ?></span> | |||
</td> | |||
<td class="prix-unit"><span class="prix"><?= number_format($p->prix, 2); ?></span> €</td> | |||
<td class="colonne-quantite"> | |||
<div class="input-group" <?php if (isset($produits_dispos[$p->id]) && $produits_dispos[$p->id]['quantite_restante'] == 0 && $quantite == 0): ?>style="display:none;"<?php endif; ?>> | |||
<span class="input-group-btn"> | |||
<button type="button" class="btn btn-default move-quantity moins">-</button> | |||
</span> | |||
<input type="text" value="<?php if (isset($produits_selec[$p->id])): echo $produits_selec[$p->id]; | |||
else: ?>0<?php endif; ?>" readonly name="Produit[produit_<?php echo $p->id; ?>]" class="quantity form-control"> | |||
<span class="input-group-btn"> | |||
<button type="button" class="btn btn-default move-quantity plus">+</button> | |||
</span> | |||
</div> | |||
<div class="quantite-restante">Reste <span class="nb"><?php if (isset($produits_dispos[$p->id])): echo $produits_dispos[$p->id]['quantite_restante'] + $quantite; | |||
endif; ?></span> <?php echo Html::encode(strtolower($p->nom)); ?>(s) | |||
</div> | |||
<div class="epuise">Épuisé</div> | |||
</td> | |||
<td class="total"><strong></strong></td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
<tfoot> | |||
<tr> | |||
<td></td> | |||
<td></td> | |||
<td></td> | |||
<!-- <td><strong><span id="total-commande">0</span> €</strong></td> --> | |||
<td id="total-commande"><strong></strong></td> | |||
</tr> | |||
</tfoot> | |||
</table> | |||
</div> | |||
</div> | |||
<?php if($id_etablissement): ?> | |||
<?php | |||
$etablissement = Etablissement::findOne($id_etablissement); | |||
?> | |||
<div id="bar-fixed" class="<?php if($etablissement->credit_pain): ?>credit-pain<?php else: ?>no-credit-pain<?php endif; ?>"> | |||
<div class="container"> | |||
<?php if (isset($model->id)): ?> | |||
<a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler', 'id' => $model->id]); ?>" class="btn btn-danger annuler-commande">Annuler ma commande</a> | |||
<?php endif; ?> | |||
<span id="total-commande-bottom"><span></span> €</span> | |||
<?= Html::submitButton('<span class="glyphicon glyphicon-comment"></span> Commentaire', ['class' => 'btn btn-default btn-commentaire', 'data-placement' => 'top', 'data-toggle' => 'tooltip', 'data-original-title' => 'Ajouter un commentaire']) ?> | |||
<?php | |||
if($etablissement->credit_pain): | |||
$lien_credit_pain = '<a class="info-credit-pain" href="'.Yii::$app->urlManager->createUrl(['site/creditpain']) .'" data-toggle="tooltip" data-placement="bottom" title="En savoir plus sur le Crédit Pain"><span class="glyphicon glyphicon-info-sign"></span></a>' ; ; | |||
?> | |||
<div id="checkbox-credit-pain" > | |||
<?php if($credit || $model->getMontantPaye()): ?> | |||
<?= Html::checkbox('credit_pain', true, ['label' => 'Utiliser mon compte Crédit Pain <span class="the-credit" data-toggle="tooltip" data-placement="top" data-original-title="Vous avez actuellement '.number_format($credit,2).' € sur votre compte Crédit Pain">'.number_format($credit,2).' €</span><br /><span class="info"></span>']) ?> | |||
<?= Html::hiddenInput('montant_credit_pain', $credit, ['id' => 'montant-credit-pain']) ?> | |||
<?= Html::hiddenInput('str_montant_credit_pain', number_format($credit,2).' €', ['id' => 'str-montant-credit-pain']) ?> | |||
<?php else: ?> | |||
<div id="info-credit-vide"> | |||
Votre compte Crédit Pain est vide <?= $lien_credit_pain ?> | |||
</div> | |||
<?php endif; ?> | |||
<div id="credit-pain-disabled">Le Crédit Pain est désactivé<br /> pour ce point de vente <?= $lien_credit_pain ?></div> | |||
</div> | |||
<div class="clr"></div> | |||
<?php endif; ?> | |||
<?= $form->field($model, 'commentaire')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?> | |||
<div id="bloc-valider-commande"> | |||
<?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span> Valider ma commande', ['class' => 'btn btn-primary valider-commande']) ?> | |||
</div> | |||
<?php endif; ?> | |||
</div> | |||
</div> | |||
<?php | |||
// id_etablissement | |||
endif; ?> | |||
<?php ActiveForm::end(); ?> | |||
<!-- modal code point de vente --> | |||
<div class="modal fade" id="modal-code" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |||
<div class="modal-dialog modal-lg" role="document"> | |||
<div class="modal-content"> | |||
<div class="modal-header"> | |||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |||
<h4 class="modal-title" id="myModalLabel">Code d'accès</h4> | |||
</div> | |||
<div class="modal-body"> | |||
<div class="alert alert-warning"> | |||
Ce point de vente nécessite un code d'accès. | |||
</div> | |||
<form action="index.php?r=commande/verif-code" method="post"> | |||
<input type="hidden" value="" name="id_point_vente" id="id-point-vente" /> | |||
<div class="form-group field-code required"> | |||
<label class="control-label" for="code">Code d'accès :</label> | |||
<input type="password" class="form-control" id="code" name="code" /> | |||
<p class="help-block help-block-error" style="display:none;">Code incorrect</p> | |||
</div> | |||
<div class="form-group"> | |||
<button type="submit" class="btn btn-primary">Valider</button> | |||
</div> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div><!-- commande-form --> |
@@ -0,0 +1,83 @@ | |||
<?php | |||
use yii\helpers\Html ; | |||
use common\helpers\Url ; | |||
?> | |||
<div class="liste-etablissements"> | |||
<?php if(count($etablissements)): ?> | |||
<?php if(isset($id_etablissement) && $id_etablissement && | |||
isset($etablissement_paiement_ok) && !$etablissement_paiement_ok): ?> | |||
<div class="alert alert-warning">Ce producteur est désactivé.</div> | |||
<?php endif; ?> | |||
<?php foreach($etablissements as $e): ?> | |||
<div class="col-md-6 boulangerie <?php if(isset($id_etablissement) && $e['id'] == $id_etablissement): ?>selected<?php endif; ?>"> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<?php if(isset($e['photo']) && strlen($e['photo'])): ?> | |||
<img class="img-back" src="./uploads/<?= $e['photo'] ?>" /> | |||
<?php endif; ?> | |||
</div> | |||
<div class="panel-body"> | |||
<h3 class="panel-title"> | |||
<?php echo Html::encode($e['nom']); ?> | |||
</h3> | |||
<div class="localite"> | |||
à <?php echo Html::encode($e['ville']).' ('.Html::encode($e['code_postal']).')'; ?> | |||
<?php if(!$e['actif']): ?> | |||
• <span class="label label-danger" data-toggle="tooltip" data-placement="bottom" data-original-title="Les commandes sont actuellement fermées pour ce producteur. Revenez plus tard ou prenez contact avec l'établissement.">Hors-ligne</span> | |||
<?php endif; ?> | |||
</div> | |||
<?php if(isset($id_etablissement) && $e['id'] == $id_etablissement): ?> | |||
<span class="glyphicon glyphicon-check"></span> | |||
<?php endif; ?> | |||
<?php if($context == 'index'): ?> | |||
<a href="<?= Yii::$app->urlManager->createUrl(['commande/remove-etablissement','id'=>$e['id']]); ?>" class="btn btn-xs btn-default remove"><span class="glyphicon glyphicon-remove"></span></a> | |||
<?php endif; ?> | |||
<?php | |||
$disabled = '' ; | |||
if(!$e['actif']): | |||
$disabled = 'disabled="disabled"' ; | |||
endif; | |||
?> | |||
<?php if($context == 'index'): ?> | |||
<a class="btn btn-primary" <?= $disabled; ?> href="<?= Yii::$app->urlManager->createUrl(['commande/create', 'id_etablissement' => $e['id']]) ?>">Commander</a> | |||
<?php if($e['id'] == Yii::$app->user->identity->id_etablissement): ?> | |||
<a class="btn btn-default" href="<?= Url::backend(); ?>" data-toggle="tooltip" data-placement="bottom" title="Accédez au panneau d'administration de votre établissement"><span class="glyphicon glyphicon-cog"></span> Gérer mon établissement</a> | |||
<?php endif; ?> | |||
<?php elseif($context == 'commande'): ?> | |||
<a class="btn btn-primary" <?= $disabled; ?> href="<?= Yii::$app->urlManager->createUrl(['commande/create', 'id_etablissement' => $e['id']]) ?>">Sélectionner</a> | |||
<?php endif; ?> | |||
<div class="clr"></div> | |||
<div class="heure-limite-commande"> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande"> | |||
<strong><span class="glyphicon glyphicon-time"></span> Heure limite :</strong> | |||
<?php echo Html::encode($e['heure_limite_commande']) ?> h | |||
</span> • | |||
<span data-toggle="tooltip" data-placement="bottom" title="Exemple : commande le lundi pour le <?php if($e['delai_commande'] == 1): ?>mardi<?php elseif($e['delai_commande'] == 2): ?>mercredi<?php elseif($e['delai_commande'] == 3): ?>jeudi<?php elseif($e['delai_commande'] == 4): ?>vendredi<?php elseif($e['delai_commande'] == 5): ?>samedi<?php elseif($e['delai_commande'] == 6): ?>dimanche<?php elseif($e['delai_commande'] == 7): ?>lundi d'après<?php endif; ?>"> | |||
<strong>Délai :</strong> | |||
<?= Html::encode($e['delai_commande']) ?> jour<?php if($e['delai_commande'] > 1): ?>s<?php endif; ?> | |||
</span> | |||
</div> | |||
<?php if($e['credit_pain']): ?> | |||
<div class="credit-pain"> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Montant de votre compte Crédit Pain. Rendez-vous chez votre producteur pour créditer votre compte."> | |||
<span class="montant"><?= number_format($e['credit'],2); ?> <span class="glyphicon glyphicon-euro"></span></span> | |||
</span> | |||
<a class="info-credit-pain" href="<?= Yii::$app->urlManager->createUrl(['site/creditpain']); ?>" data-toggle="tooltip" data-placement="bottom" title="En savoir plus sur le Crédit Pain"><span class="glyphicon glyphicon-info-sign"></span></a> | |||
</div> | |||
<?php endif; ?> | |||
<div class="clr"></div> | |||
</div> | |||
</div> | |||
</div> | |||
<?php endforeach; ?> | |||
<?php endif; ?> | |||
</div> |
@@ -0,0 +1,32 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
/* @var $this yii\web\View */ | |||
/* @var $model app\models\Produit */ | |||
$this->title = 'Passer une commande'; | |||
?> | |||
<div class="commande-create"> | |||
<h1 class="title-systeme-commande"><span class="glyphicon glyphicon-plus"></span> <?= Html::encode($this->title) ?></h1> | |||
<?= $this->render('_form', [ | |||
'model' => $model, | |||
'points_vente' => $points_vente, | |||
'jours_production' => $jours_production, | |||
'produits' => $produits, | |||
'produits_selec' => $produits_selec, | |||
'produits_dispos' => $produits_dispos, | |||
'production' => $production, | |||
'commandes_en_cours' => $commandes_en_cours, | |||
'produits_vrac' => $produits_vrac, | |||
'etablissements' => $etablissements, | |||
'id_etablissement' => $id_etablissement, | |||
'etablissement' => $etablissement, | |||
'etablissement_paiement_ok' => $etablissement_paiement_ok, | |||
'credit' => $credit | |||
]) ?> | |||
</div> |
@@ -0,0 +1,122 @@ | |||
<?php | |||
/* @var $this yii\web\View */ | |||
use yii\helpers\Html; | |||
use yii\bootstrap\ActiveForm; | |||
use common\models\Commande ; | |||
$this->title = 'Commande' ; | |||
?> | |||
<div id="index-commande"> | |||
<h1 class="title-systeme-commande"><span class="glyphicon glyphicon-th-list"></span> Tableau de bord</h1> | |||
<h2>Producteurs</h2> | |||
<?php if($commande_ok): ?> | |||
<div class="alert alert-success"> | |||
<div class="icon"></div> | |||
Votre commande a bien été prise en compte. | |||
</div> | |||
<?php endif; ?> | |||
<?php if($annule_ok): ?> | |||
<div class="alert alert-success"><div class="icon"></div>Votre commande a bien été annulée.</div> | |||
<?php endif; ?> | |||
<div id="liste-boulangeries"> | |||
<?= | |||
$this->render('_liste_etablissements.php',[ | |||
'etablissements' => $etablissements, | |||
'context' => 'index' | |||
]) ; | |||
?> | |||
<div class="col-md-6" id="bloc-add-etablissement"> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"><span class="glyphicon glyphicon-plus"></span> Ajouter un producteur</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<?php $form = ActiveForm::begin(['id' => 'form-add-boulanger','enableClientValidation'=> false]); ?> | |||
<?= $form->field($model_form_etablissement, 'id_etablissement') | |||
->label('') | |||
->dropDownList($data_etablissements_dispos, | |||
['prompt' => '--', | |||
'encode' => false, | |||
'options' => $options_etablissements_dispos | |||
]) ; ?> | |||
<div id="bloc-code-acces"> | |||
<?= $form->field($model_form_etablissement, 'code',[ | |||
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', | |||
]) | |||
->label('Code') | |||
->hint('Renseignez-vous auprès de votre producteur pour qu\'il vous fournisse le code d\'accès') ; ?> | |||
</div> | |||
<?= Html::submitButton('<span class="glyphicon glyphicon-plus"></span> Valider', ['class' => 'btn btn-default', 'name' => 'add-etablissement-button']) ?> | |||
<?php ActiveForm::end(); ?> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="clr"></div> | |||
</div> | |||
<h2>Historique</h2> | |||
<?php if(count($commandes)): ?> | |||
<p>Retrouvez ici vos dernières commandes.</p> | |||
<table id="historique-commandes" class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<th>Producteur</th> | |||
<th>Date livraison</th> | |||
<th>Résumé</th> | |||
<th>Lieu</th> | |||
<th class="montant">Montant</th> | |||
<th class="statut"></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach($commandes as $c): ?> | |||
<tr> | |||
<td><?= Html::encode($c->production->etablissement->nom) ?></td> | |||
<td><?php echo date('d/m/Y',strtotime($c->production->date)); ?></td> | |||
<td class="resume"><?= $c->getResumePanier() ; ?></td> | |||
<td><?= $c->getResumePointVente(); ?></td> | |||
<td class="montant"><?= $c->getResumeMontant(); ?></td> | |||
<td class="statut"> | |||
<?php if($c->getEtat() == Commande::ETAT_LIVREE): ?> | |||
Livrée | |||
<?php elseif($c->getEtat() == Commande::ETAT_PREPARATION): ?> | |||
En préparation | |||
<?php elseif($c->getEtat() == Commande::ETAT_MODIFIABLE): ?> | |||
<div class="btn-group"> | |||
<a href="<?php echo Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]) ; ?>" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a> | |||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> | |||
<span class="caret"></span> | |||
<span class="sr-only">Toggle Dropdown</span> | |||
</button> | |||
<ul class="dropdown-menu" role="menu"> | |||
<li><a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler','id'=>$c->id]) ; ?>"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li> | |||
</ul> | |||
</div> | |||
<?php endif; ?> | |||
</td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
<?php else: ?> | |||
<div class="alert alert-info">Vous n'avez pas encore passé de commandes</div> | |||
<?php endif; ?> | |||
</div> |
@@ -0,0 +1,40 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
/* @var $this yii\web\View */ | |||
/* @var $model app\models\Produit */ | |||
$this->title = 'Modifier une commande'; | |||
//$this->params['breadcrumbs'][] = ['label' => 'Produits', 'url' => ['index']]; | |||
//$this->params['breadcrumbs'][] = $this->title; | |||
?> | |||
<div class="commande-update"> | |||
<h1 class="title-systeme-commande"><span class="glyphicon glyphicon-pencil"></span> <?= Html::encode($this->title) ?></h1> | |||
<?php if($commande_introuvable): ?> | |||
<div class="alert alert-danger">Cette commande est introuvable</div><br /> | |||
<a class="btn btn-default" href="<?php echo Yii::$app->urlManager->createUrl(['commande/index']); ?>">Retour</a> | |||
<?php else: ?> | |||
<?= $this->render('_form', [ | |||
'model' => $model, | |||
'points_vente' => $points_vente, | |||
'jours_production' => $jours_production, | |||
'produits' => $produits, | |||
'produits_selec' => $produits_selec, | |||
'produits_dispos' => $produits_dispos, | |||
'production' => $production, | |||
'commandes_en_cours' => $commandes_en_cours, | |||
'produits_vrac' => $produits_vrac, | |||
'etablissements' => $etablissements, | |||
'id_etablissement' => $id_etablissement, | |||
'etablissement_paiement_ok' => $etablissement_paiement_ok, | |||
'credit' => $credit | |||
]) ?> | |||
<?php endif; ?> | |||
</div> |