You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
21KB

  1. <?php
  2. /**
  3. Copyright La boîte à pain (2018)
  4. contact@laboiteapain.net
  5. Ce logiciel est un programme informatique servant à aider les producteurs
  6. à distribuer leur production en circuits courts.
  7. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  8. respectant les principes de diffusion des logiciels libres. Vous pouvez
  9. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  10. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  11. sur le site "http://www.cecill.info".
  12. En contrepartie de l'accessibilité au code source et des droits de copie,
  13. de modification et de redistribution accordés par cette licence, il n'est
  14. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  15. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  16. titulaire des droits patrimoniaux et les concédants successifs.
  17. A cet égard l'attention de l'utilisateur est attirée sur les risques
  18. associés au chargement, à l'utilisation, à la modification et/ou au
  19. développement et à la reproduction du logiciel par l'utilisateur étant
  20. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  21. manipuler et qui le réserve donc à des développeurs et des professionnels
  22. avertis possédant des connaissances informatiques approfondies. Les
  23. utilisateurs sont donc invités à charger et tester l'adéquation du
  24. logiciel à leurs besoins dans des conditions permettant d'assurer la
  25. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  26. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  27. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  28. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  29. termes.
  30. */
  31. use yii\helpers\Html;
  32. use common\models\Commande;
  33. use common\models\User ;
  34. use yii\helpers\ArrayHelper ;
  35. use yii\widgets\ActiveForm;
  36. $this->title = 'Commande';
  37. $cpt_non_vrac = 0;
  38. foreach ($produits as $p) {
  39. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  40. if (!$p->vrac) {
  41. $cpt_non_vrac ++;
  42. }
  43. }
  44. }
  45. ?>
  46. <div id="page-commande">
  47. <div class="col-md-3" id="col-left">
  48. <div class="panel panel-default">
  49. <div class="panel-heading">
  50. <h3 class="panel-title">Calendrier</h3>
  51. </div>
  52. <div class="panel-body">
  53. <?php
  54. // chargement assets
  55. common\components\fullcalendar\FullcalendarWidget::widget();
  56. // --> lancement du js en manuel (via lechatdesnoisettes.js)
  57. ?>
  58. <div id="calendar"></div>
  59. <?php if (!$date): ?>
  60. <br />
  61. <div class="alert alert-info">
  62. <span class="glyphicon glyphicon-share-alt"></span> Choisissez une date pour initier ou
  63. éditer un jour de production.
  64. </div>
  65. <?php else: ?>
  66. <a class="btn btn-sm btn-default btn-active-week" href="<?= Yii::$app->urlManager->createUrl(['commande/change-state-semaine', 'date' => $date, 'actif' => !$production_semaine_active, ]); ?>"><span class="glyphicon glyphicon-<?= $production_semaine_active ? 'remove' : 'ok' ?>"></span> <?= $production_semaine_active ? 'Désactiver' : 'Activer' ?> cette semaine de production</a>
  67. <?php endif; ?>
  68. </div>
  69. </div>
  70. <?php if ($date != ''): ?>
  71. <div id="bloc-production">
  72. <input type="hidden" id="date-production" value="<?= $date ?>" />
  73. <input type="hidden" id="id-production" value="<?= $production->id ?>" />
  74. <div class="panel panel-default">
  75. <div class="panel-heading">
  76. <h3 class="panel-title">Production du <strong><?php echo date('d/m/Y', strtotime($date)); ?></strong></h3>
  77. </div>
  78. <div class="panel-body">
  79. <strong>Production</strong><br />
  80. <div class="btn-group" role="group">
  81. <a class="btn btn-default<?php if ($production->actif): ?> btn-success<?php endif; ?>" href="<?php echo Yii::$app->urlManager->createUrl(['commande/change-state', 'date' => $date, 'actif' => 1]); ?>">Activé</a>
  82. <a class="btn btn-default<?php if (!$production->actif): ?> btn-danger<?php endif; ?>" href="<?php echo Yii::$app->urlManager->createUrl(['commande/change-state', 'date' => $date, 'actif' => 0]); ?>">Désactivé</a>
  83. </div>
  84. <br />
  85. <br />
  86. <?php if (!$production->actif): ?>
  87. <div class="alert alert-info">
  88. <span class="glyphicon glyphicon-share-alt"></span> Activez ici la production pour qu'elle soit visible au client.
  89. </div>
  90. <?php endif; ?>
  91. <?php if($production->livraison && count($arr_productions_point_vente)): ?>
  92. <div id="productions-point-vente">
  93. <strong>Points de vente : </strong>
  94. <div class="checkbox-list">
  95. <?= Html::activeCheckboxList(
  96. $production_point_vente,
  97. 'productions_point_vente',
  98. $arr_productions_point_vente ,
  99. ['encode' => false, 'class' => '']) ?>
  100. </div>
  101. </div>
  102. <?php endif; ?>
  103. </div>
  104. </div>
  105. </div>
  106. <?php endif; ?>
  107. <?php if ($production): ?>
  108. <div id="bloc-produits">
  109. <div class="panel panel-default">
  110. <div class="panel-heading">
  111. <h3 class="panel-title">Produits</h3>
  112. </div>
  113. <div class="panel-body">
  114. <!-- produits sélectionnés -->
  115. <form id="produits-production" action="<?php echo Yii::$app->urlManager->createUrl(['commande/index', 'date' => $date]); ?>" method="post">
  116. <div class="overflow">
  117. <table class="table table-condensed">
  118. <thead>
  119. <tr>
  120. <th class="td-actif">Actif</th>
  121. <th class="td-produit">Produit</th>
  122. <th class="td-max">Max. <span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" data-original-title="Quantité disponible à la commande. Laisser vide si vous ne souhaitez pas avoir de limite de commande. La valeur par défaut est configurable dans vos produits."></span></th>
  123. </tr>
  124. </thead>
  125. <tbody>
  126. <?php foreach ($produits as $p): ?>
  127. <tr<?php if ($p->vrac): ?> style="display:none;"<?php endif; ?> <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']): ?>class="active"<?php endif; ?>>
  128. <td class="td-actif"><input id="produit-<?php echo $p->id; ?>" name="Produit[<?php echo $p->id; ?>][actif]" type="checkbox" <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']): ?>checked="checked"<?php endif; ?> /></td>
  129. <td class="td-produit"><label for="produit-<?php echo $p->id; ?>"><?= Html::encode($p->nom) ?></label></td>
  130. <td class="td-max"><input class="quantite-max" name="Produit[<?php echo $p->id; ?>][quantite_max]" type="text" value="<?php if (isset($produits_selec[$p->id])) echo $produits_selec[$p->id]['quantite_max']; ?>" /></td>
  131. </tr>
  132. <?php endforeach; ?>
  133. </tbody>
  134. </table>
  135. </div>
  136. <input type="submit" name="valider_produit_selec" class="btn btn-default" value="Valider" />
  137. </form>
  138. </div>
  139. </div>
  140. </div>
  141. <?php endif; ?>
  142. </div>
  143. <div class="col-md-9" id="col-right">
  144. <input type="hidden" value="<?php echo $date; ?>" id="current-date" />
  145. <ul id="jours-production">
  146. <?php foreach ($jours_production as $j) : ?>
  147. <li><?php echo $j->date; ?></li>
  148. <?php endforeach; ?>
  149. </ul>
  150. <?php if ($date != ''): ?>
  151. <div id="bloc-totaux">
  152. <?= $this->render('_total_commandes.php',[
  153. 'produits' => $produits,
  154. 'commandes' => $commandes,
  155. 'produits_selec' => $produits_selec,
  156. 'recettes_pain' => $recettes_pain,
  157. 'poids_pain' => $poids_pain,
  158. 'ca_potentiel' => $ca_potentiel,
  159. 'poids_total' => $poids_total,
  160. ]); ?>
  161. </div>
  162. <?php
  163. $num_jour_semaine = date('w', strtotime($date));
  164. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  165. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  166. ?>
  167. <div class="panel panel-default" id="panel-commandes">
  168. <div class="panel-heading">
  169. <h3 class="panel-title">
  170. Commandes
  171. <?php if (!count($commandes)): ?><span class="label label-danger">0</span>
  172. <?php else: ?><span class="label label-success"><?= count($commandes) ?></span>
  173. <?php endif; ?>
  174. <?php if (count($commandes)): ?>
  175. <a id="btn-export-commandes" class="btn btn-primary" href="<?php echo Yii::$app->urlManager->createUrl(['commande/report', 'date' => $date, 'id_point_vente' => 0, 'global' => 1]); ?>"><span class="glyphicon glyphicon-download-alt"></span> Exporter</a>
  176. <?php endif; ?>
  177. <div id="btn-commandes-auto" class="btn-group">
  178. <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  179. <span class="glyphicon glyphicon-repeat"></span> Commandes récurrentes <span class="caret"></span>
  180. </button>
  181. <ul class="dropdown-menu">
  182. <li><a href="<?= Yii::$app->urlManager->createUrl(['commande/add-commandes-auto', 'date' => $date]); ?>">Importer toutes les commandes</a></li>
  183. </ul>
  184. </div>
  185. </h3>
  186. </div>
  187. <div class="panel-body">
  188. <div class="col-md-12">
  189. <div class="alert alert-danger" style="display:none;">Aucun point de vente activé</div>
  190. <!-- Nav tabs -->
  191. <ul id="tabs-points-vente" class="nav nav-tabs" role="tablist">
  192. <?php foreach($points_vente as $pv): ?>
  193. <li role="presentation" class="<?php if($pv->point_fabrication): ?>active<?php endif; ?>">
  194. <a href="#point-vente-<?= $pv->id ?>" id="btn-point-vente-<?= $pv->id ?>" aria-controls="point-vente-<?= $pv->id ?>" role="tab" data-toggle="tab"><?= Html::encode($pv->nom) ?> <span class="badge badge-<?php if(count($pv->commandes)): ?>success<?php else: ?>danger<?php endif; ?>"><?php echo count($pv->commandes); ?></span></a>
  195. </li>
  196. <?php endforeach; ?>
  197. </ul>
  198. <!-- Tab panes -->
  199. <div class="tab-content" id="commandes-points-vente">
  200. <?php foreach($points_vente as $pv): ?>
  201. <div role="tabpanel" data-id-pv="<?= $pv->id ?>" class="bloc-point-vente tab-pane <?php if($pv->point_fabrication): ?> active<?php endif; ?>" id="point-vente-<?= $pv->id ?>">
  202. <div class="col-md-12">
  203. <div class="alert alert-warning recap-pv <?php if(!count($pv->commandes)): ?>no-commande<?php endif; ?>">
  204. <?php if(count($pv->commandes)): ?>
  205. <strong class="commandes"><?= count($pv->commandes) ?> commande<?php if(count($pv->commandes) > 1): ?>s<?php endif; ?></strong>
  206. <span class="recettes"><?= number_format($pv->recettes, 2) ?> €</span>
  207. <?php else: ?>
  208. <strong class="commandes">Aucune commande</strong>
  209. <span class="recettes"></span>
  210. <?php endif; ?>
  211. </div>
  212. <ul class="liste-commandes btn-group-vertical<?php if(!count($pv->commandes)): ?> no-commande<?php endif; ?>">
  213. <?php foreach($pv->commandes as $c): ?>
  214. <li>
  215. <a href="javascript:void(0);" class="btn btn-default" data-pv-id="<?= $pv->id ?>" data-id-commande="<?= $c->id ?>" data-commande='<?= $pv->data_options_commandes[$c->id]['data-commande'] ?>' data-commentaire="<?= Html::encode($c->commentaire) ?>" data-date="<?= date('d/m à H:i',strtotime($c->date)); ?>">
  216. <span class="montant <?php if(number_format($c->montant_paye,2) >= number_format($c->montant,2)): ?>paye<?php endif; ?>">
  217. <?= Html::encode(number_format($c->montant, 2)); ?> €
  218. <?php if($c->montant_paye - $c->montant > 0.01): ?><span class="glyphicon glyphicon-warning-sign"></span><?php endif; ?>
  219. </span>
  220. <span class="user">
  221. <?php if($c->type): ?>
  222. <?php if($c->type == Commande::TYPE_ADMIN): ?>
  223. <span class="label label-warning">vous</span>
  224. <?php elseif($c->type == Commande::TYPE_AUTO): ?>
  225. <span class="label label-default">auto</span>
  226. <?php elseif($c->type == Commande::TYPE_USER): ?>
  227. <span class="label label-success">client</span>
  228. <?php endif; ?>
  229. <?php endif; ?>
  230. <?php if(isset($c->user)): ?>
  231. <?= Html::encode($c->user->nom.' '.$c->user->prenom); ?>
  232. <?php else: ?>
  233. <?= Html::encode($c->username); ?>
  234. <?php endif; ?>
  235. <?php if(!is_null($c->date_delete)): ?>
  236. (<span class="glyphicon glyphicon-remove"></span> Annulée)
  237. <?php endif; ?>
  238. </span>
  239. <?php if (strlen($c->commentaire)): ?>
  240. <span class="glyphicon glyphicon-comment"></span>
  241. <?php endif; ?>
  242. </a>
  243. </li>
  244. <?php endforeach; ?>
  245. </ul>
  246. <?= Html::a('<span class="glyphicon glyphicon-plus"></span> Créer une commande', 'javascript:void(0);', ['class' => 'btn btn-default creer-commande', 'data-pv-id' => $pv->id]) ?>
  247. </div>
  248. <div class="col-md-12 bloc-commande">
  249. <h2 class="title-user">
  250. <span class="buttons-edit-remove">
  251. <?= Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', 'javascript:void(0);', ['class' => 'btn btn-default btn-remove']) ?>
  252. <?= Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', 'javascript:void(0);', ['class' => 'btn btn-default btn-edit']) ?>
  253. </span>
  254. <span class="buttons-save-cancel">
  255. <?= Html::a('<span class="glyphicon glyphicon-ok"></span> Sauvegarder', 'javascript:void(0);', ['class' => 'btn btn-primary btn-save']) ?>
  256. <?= Html::a('<span class="glyphicon glyphicon-remove"></span> Annuler', 'javascript:void(0);', ['class' => 'btn btn-default btn-cancel']) ?>
  257. </span>
  258. <span class="the-title"></span>
  259. <span class="choix-user">
  260. <?= Html::activeDropDownList(new User, 'id', ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->andWhere('user_etablissement.actif = 1')->orderBy('user.nom ASC, user.prenom ASC')->all(), 'id', function($model, $defaultValue) {
  261. return $model['nom'].' '.$model['prenom'];
  262. }), ['prompt' => '--','class' => 'form-control user-id']) ?>
  263. OU <input type="text" class="form-control username" placeholder="Choisissez un nom" />
  264. </span>
  265. </h2>
  266. <div class="commentaire alert alert-info">
  267. </div>
  268. <textarea name="commentaire" class="form-control textarea-commentaire" placeholder="Commentaire"></textarea>
  269. <table class="table table-bordered table-condensed tab-content table-produits">
  270. <tbody>
  271. <?php foreach ($produits as $p): ?>
  272. <tr class="produit-<?= $p->id ?> <?php if(!$produits_selec[$p->id]['actif']): ?> disabled<?php endif; ?>" data-id-produit="<?= $p->id ?>">
  273. <td class="td-commande"></td>
  274. <td class="td-produit"><?php echo Html::encode($p->getLibelleAdmin()); ?></td>
  275. </tr>
  276. <?php endforeach; ?>
  277. <tr class="tr-total">
  278. <td class="td-total"></td>
  279. <td class="td-paiement"></td>
  280. </tr>
  281. </tbody>
  282. </table>
  283. </div>
  284. </div>
  285. <?php endforeach; ?>
  286. </div>
  287. </div>
  288. </div>
  289. </div>
  290. <?php endif; ?>
  291. </div>
  292. </div>