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.

417 lines
24KB

  1. <?php
  2. use yii\helpers\Html;
  3. use common\models\Commande;
  4. $this->title = 'Commande';
  5. $cpt_non_vrac = 0;
  6. foreach ($produits as $p) {
  7. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  8. if (!$p->vrac) {
  9. $cpt_non_vrac ++;
  10. }
  11. }
  12. }
  13. ?>
  14. <div id="page-commande">
  15. <div id="row1">
  16. <div class="col-md-3">
  17. <div class="panel panel-default">
  18. <div class="panel-heading">
  19. <h3 class="panel-title">Calendrier</h3>
  20. </div>
  21. <div class="panel-body">
  22. <?php
  23. // chargement assets
  24. common\components\fullcalendar\FullcalendarWidget::widget();
  25. // --> lancement du js en manuel (via lechatdesnoisettes.js)
  26. ?>
  27. <div id="calendar"></div>
  28. </div>
  29. </div>
  30. </div>
  31. <?php if ($date != ''): ?>
  32. <div class="col-md-5" id="bloc-production">
  33. <div class="panel panel-default">
  34. <div class="panel-heading">
  35. <?php if (!count($commandes)): ?><span class="label label-danger">Aucune commande</span>
  36. <?php else: ?><span class="label label-success"><?= count($commandes) ?> commande<?php if(count($commandes) > 1): ?>s<?php endif; ?></span>
  37. <?php endif; ?>
  38. <h3 class="panel-title">Production du <strong><?php echo date('d/m/Y', strtotime($date)); ?></strong></h3>
  39. </div>
  40. <div class="panel-body">
  41. <?php if (count($commandes)): ?>
  42. <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 les commandes</a>
  43. <?php endif; ?>
  44. <strong>Production</strong><br />
  45. <div class="btn-group" role="group">
  46. <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>
  47. <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>
  48. </div>
  49. <br />
  50. <br />
  51. <?php if ($production->actif): ?>
  52. <strong>Livraison</strong><br />
  53. <div class="btn-group" role="group">
  54. <a class="btn btn-default<?php if ($production->livraison): ?> btn-success<?php endif; ?>" href="<?php echo Yii::$app->urlManager->createUrl(['commande/change-livraison', 'date' => $date, 'livraison' => 1]); ?>">Activé</a>
  55. <a class="btn btn-default<?php if (!$production->livraison): ?> btn-danger<?php endif; ?>" href="<?php echo Yii::$app->urlManager->createUrl(['commande/change-livraison', 'date' => $date, 'livraison' => 0]); ?>">Désactivé</a>
  56. </div>
  57. <?php endif; ?>
  58. </div>
  59. </div>
  60. </div>
  61. <?php endif; ?>
  62. <?php if ($production): ?>
  63. <div id="bloc-produits" class="col-md-4">
  64. <div class="panel panel-default">
  65. <div class="panel-heading">
  66. <h3 class="panel-title">Produits</h3>
  67. </div>
  68. <div class="panel-body">
  69. <!-- produits sélectionnés -->
  70. <form id="produits-production" action="<?php echo Yii::$app->urlManager->createUrl(['commande/index', 'date' => $date]); ?>" method="post">
  71. <div class="overflow">
  72. <table class="table table-condensed">
  73. <thead>
  74. <tr>
  75. <th class="td-actif">Actif</th>
  76. <th class="td-produit">Produit</th>
  77. <th class="td-max">Max.</th>
  78. </tr>
  79. </thead>
  80. <tbody>
  81. <?php foreach ($produits as $p): ?>
  82. <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; ?>>
  83. <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>
  84. <td class="td-produit"><label for="produit-<?php echo $p->id; ?>"><?= Html::encode($p->nom) ?></label></td>
  85. <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>
  86. </tr>
  87. <?php endforeach; ?>
  88. </tbody>
  89. </table>
  90. </div>
  91. <input type="submit" name="valider_produit_selec" class="btn btn-default" value="Valider" />
  92. </form>
  93. </div>
  94. </div>
  95. </div>
  96. <?php endif; ?>
  97. </div>
  98. <div id="row2" class="col-md-12">
  99. <input type="hidden" value="<?php echo $date; ?>" id="current-date" />
  100. <ul id="jours-production">
  101. <?php foreach ($jours_production as $j) : ?>
  102. <li><?php echo $j->date; ?></li>
  103. <?php endforeach; ?>
  104. </ul>
  105. <?php if ($date != ''): ?>
  106. <?php
  107. $num_jour_semaine = date('w', strtotime($date));
  108. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  109. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  110. ?>
  111. <div class="panel panel-default">
  112. <div class="panel-heading">
  113. <h3 class="panel-title">Commandes</h3>
  114. </div>
  115. <div class="panel-body">
  116. <!-- Nav tabs -->
  117. <ul class="nav nav-tabs" role="tablist">
  118. <?php foreach($points_vente as $pv): ?>
  119. <li role="presentation" class="<?php if($pv->point_fabrication): ?>active<?php endif; ?>">
  120. <a href="#point-vente-<?= $pv->id ?>" aria-controls="point-vente-<?= $pv->id ?>" role="tab" data-toggle="tab"><?= Html::encode($pv->nom) ?> <span class="label label-<?php if(count($pv->commandes)): ?>success<?php else: ?>danger<?php endif; ?>"><?php echo count($pv->commandes); ?></span></a>
  121. </li>
  122. <?php endforeach; ?>
  123. </ul>
  124. <!-- Tab panes -->
  125. <div class="tab-content">
  126. <?php foreach($points_vente as $pv): ?>
  127. <div role="tabpanel" class="tab-pane<?php if($pv->point_fabrication): ?> active<?php endif; ?>" id="point-vente-<?= $pv->id ?>">
  128. <table class="table">
  129. <thead>
  130. <tr>
  131. <th>Produits</th>
  132. <th>
  133. <select>
  134. <option value="">Guillaume Bourgeois</option>
  135. <option value="">Jean-Marc Bonard</option>
  136. </select>
  137. </th>
  138. <th><a href="#" class="btn btn-default">Nouvelles commande</a></th>
  139. </tr>
  140. </thead>
  141. <tbody>
  142. <?php foreach ($produits as $p): ?>
  143. <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']): ?>
  144. <tr>
  145. <td><?php echo Html::encode($p->getLibelleAdmin()); ?></td>
  146. <td><?= rand(1,10) ?></td>
  147. <td><input type="text" /></td>
  148. </tr>
  149. <?php endif; ?>
  150. <?php endforeach; ?>
  151. </tbody>
  152. </table>
  153. </div>
  154. <?php endforeach; ?>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="panel panel-default">
  159. <div class="panel-heading">
  160. <h3 class="panel-title">Commandes</h3>
  161. </div>
  162. <div class="panel-body">
  163. <form class="form-commandes-point-vente" action="<?php echo Yii::$app->urlManager->createUrl(['commande/index', 'date' => $date]); ?>" method="post">
  164. <table class="table table-hover table-header-rotated">
  165. <thead>
  166. <tr>
  167. <td class="title-point-vente" colspan="<?php echo count($produits) + 3; ?>"><strong>Global</strong></td>
  168. </tr>
  169. <tr>
  170. <th class="border-left"></th>
  171. <?php foreach ($produits as $p): ?>
  172. <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']): ?>
  173. <th class="center rotate-45">
  174. <div><span><strong><?php echo Html::encode($p->getLibelleAdmin()); ?></strong></span></div>
  175. </th>
  176. <?php endif; ?>
  177. <?php endforeach; ?>
  178. <th class="title-totaux"><strong>Potentiel</strong></th>
  179. <th class="title-totaux border-right"><strong>Commandé</strong></th>
  180. </tr>
  181. <tr>
  182. <td><strong>Total</strong></td>
  183. <?php
  184. foreach ($produits as $p) {
  185. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  186. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  187. $str_quantite = '';
  188. if ($quantite)
  189. $str_quantite = $quantite;
  190. $classe = 'center total';
  191. if ($str_quantite > $produits_selec[$p->id]['quantite_max'] && !$produits_selec[$p->id]['vrac']) {
  192. $classe .= ' depasse';
  193. }
  194. if ($p->vrac) {
  195. $classe .= ' vrac';
  196. }
  197. echo '<td class="' . $classe . '"><strong>' . $str_quantite . ' <span>';
  198. if ($produits_selec[$p->id]['quantite_max'] && $str_quantite)
  199. echo '/ ' . $produits_selec[$p->id]['quantite_max'] . '</span></strong></td>';
  200. }
  201. }
  202. ?>
  203. <td><strong><?php echo number_format($ca_potentiel, 2); ?> €</strong><br /><?php echo number_format($poids_total / 1000, 2); ?> kg</td>
  204. <td><strong><?php echo str_replace(' ', '&nbsp;', $recettes_pain . ' €'); ?></strong><br /><?php echo round($poids_pain) . ' kg'; ?></td>
  205. </tr>
  206. </thead>
  207. <tbody>
  208. <?php foreach ($points_vente as $pv): ?>
  209. <?php
  210. if (strlen($pv->$champs_horaires_point_vente)):
  211. ?>
  212. <tr>
  213. <td class="title-point-vente" colspan="<?php echo count($produits) + 3; ?>"><?php echo Html::encode($pv->nom); ?></td>
  214. </tr>
  215. <tr>
  216. <th class="border-left"></th>
  217. <?php foreach ($produits as $p): ?>
  218. <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']): ?>
  219. <th class="center rotate-45">
  220. <div><span><strong><?php echo Html::encode($p->getLibelleAdmin()); ?></strong></span></div>
  221. </th>
  222. <?php endif; ?>
  223. <?php endforeach; ?>
  224. <th></th>
  225. <th class="border-right"></th>
  226. </tr>
  227. <?php foreach ($pv->commandes as $c): ?>
  228. <tr>
  229. <td class="client">
  230. <?php if (isset($c->user)): ?>
  231. <?php echo Html::encode($c->user->prenom . ' ' . $c->user->nom); ?>
  232. <?php else: ?>
  233. <?php echo Html::encode($c->username); ?>
  234. <?php endif; ?>
  235. <?php if (strlen($c->commentaire)): ?>
  236. <button type="button" class="btn btn-xs btn-info" data-toggle="popover" title="Commentaire" data-content="<?php echo Html::encode($c->commentaire); ?>"><span class="glyphicon glyphicon-comment"></span></button>
  237. <?php endif; ?>
  238. <br /><span class="date-commande"><?php echo date('d/m/Y à H:i ', strtotime($c->date));
  239. if ($c->date_update && date('d/m/Y', strtotime($c->date_update)) != date('d/m/Y', strtotime($c->date))): ?><br />modif. <?php echo date('d/m/Y', strtotime($c->date_update)); ?><?php endif; ?></span>
  240. </td>
  241. <?php
  242. foreach ($produits as $p) {
  243. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  244. $add = false;
  245. $quantite = 0;
  246. foreach ($c->commandeProduits as $cp) {
  247. if ($p->id == $cp->id_produit) {
  248. $quantite = $cp->quantite;
  249. $add = true;
  250. }
  251. }
  252. echo '<td class="td-produit"><input class="quantite" type="text" value="' . $quantite . '" name="produit_' . $c->id . '_' . $p->id . '" /></td>';
  253. }
  254. }
  255. ?>
  256. <td><?php echo str_replace(' ', '&nbsp;', number_format($c->montant, 2) . ' €'); ?></td>
  257. <td><a href="<?php echo Yii::$app->urlManager->createUrl(['commande/delete-commande', 'date' => $date, 'delete' => 1, 'id_commande' => $c->id]); ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a></td>
  258. </tr>
  259. <?php endforeach; ?>
  260. <tr>
  261. <td class="client"><!-- <select class="select-user" name="user_pv_<?php echo $pv->id; ?>">
  262. <?php
  263. foreach ($users as $id_user => $libelle_user) {
  264. echo '<option value="' . $id_user . '">' . $libelle_user . '</option>';
  265. }
  266. ?>
  267. </select> -->
  268. <input type="text" placeholder="Nom" class="text" name="username_pv_<?php echo $pv->id; ?>" />
  269. <br />
  270. <input type="text" name="date_commande_pv_<?php echo $pv->id; ?>" class="datepicker" value="<?php echo date('d/m/Y'); ?>" />
  271. </td>
  272. <?php
  273. foreach ($produits as $p) {
  274. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  275. echo '<td class="td-produit' . (($p->vrac) ? ' vrac' : '') . '"><input class="quantite" type="text" value="0" name="produit_pv_' . $pv->id . '_' . $p->id . '" /></td>';
  276. }
  277. }
  278. ?>
  279. <td></td>
  280. <td></td>
  281. </tr>
  282. <?php
  283. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  284. echo '<tr>';
  285. echo '<td><strong>Total pain</strong></td>';
  286. //$cpt_non_vrac = 0 ;
  287. foreach ($produits as $p) {
  288. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  289. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  290. $str_quantite = '';
  291. if (!$p->vrac) {
  292. //$cpt_non_vrac ++ ;
  293. if ($quantite)
  294. $str_quantite = $quantite;
  295. }
  296. echo '<td class="center' . (($p->vrac) ? ' vrac' : '') . '"><strong>' . $str_quantite . '</strong></td>';
  297. }
  298. }
  299. // total
  300. echo '<td><strong>' . number_format($pv->recettes_pain, 2) . ' €</strong></td><td></td></tr>';
  301. }
  302. ?>
  303. <?php endif; ?>
  304. <?php endforeach; ?>
  305. </tbody>
  306. </table>
  307. <input type="submit" class="btn btn-primary submit-pv" value="Enregistrer" name="submit_pv" />
  308. </form>
  309. </div>
  310. </div>
  311. <div class="clr"></div>
  312. <?php if (count($commandes) && false): ?>
  313. <h2>Récapitulatif production <a href="<?php echo Yii::$app->urlManager->createUrl(['commande/download', 'date' => $date]); ?>" class="btn btn-default">CSV</a></h2>
  314. <table class="table table-striped table-bordered">
  315. <thead>
  316. <tr>
  317. <th>Lieu</th>
  318. <?php foreach ($produits as $p): ?>
  319. <?php if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) : ?>
  320. <th><?php echo Html::encode($p->description); ?></th>
  321. <?php endif; ?>
  322. <?php endforeach; ?>
  323. </tr>
  324. </thead>
  325. <tbody>
  326. <?php
  327. foreach ($points_vente as $pv) {
  328. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  329. echo '<tr>';
  330. echo '<td>' . Html::encode($pv->nom) . '</td>';
  331. foreach ($produits as $p) {
  332. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  333. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  334. $str_quantite = '';
  335. if ($quantite)
  336. $str_quantite = $quantite;
  337. echo '<td>' . $str_quantite . '</td>';
  338. }
  339. }
  340. echo '</tr>';
  341. }
  342. }
  343. ?>
  344. </tbody>
  345. <tfoot>
  346. <tr>
  347. <td><strong>Total</strong></td>
  348. <?php
  349. foreach ($produits as $p) {
  350. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  351. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  352. $str_quantite = '';
  353. if ($quantite)
  354. $str_quantite = $quantite;
  355. echo '<td class="' . (($p->vrac) ? 'vrac' : '') . '">' . $str_quantite . '</td>';
  356. }
  357. }
  358. ?>
  359. </tr>
  360. </tfoot>
  361. </table>
  362. <?php endif; ?>
  363. <?php endif; ?>
  364. </div>
  365. </div>