Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
8 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\ProductionProduit;
  4. use Yii;
  5. use common\models\Production;
  6. use yii\filters\AccessControl;
  7. use yii\web\Controller;
  8. use common\models\LoginForm;
  9. use yii\filters\VerbFilter;
  10. use common\models\Commande;
  11. use common\models\PointVente;
  12. use common\models\Produit;
  13. use common\helpers\CSV;
  14. use common\models\User;
  15. use common\models\CommandeProduit;
  16. use kartik\mpdf\Pdf;
  17. class CommandeController extends \yii\web\Controller {
  18. var $enableCsrfValidation = false;
  19. public function behaviors() {
  20. return [
  21. 'access' => [
  22. 'class' => AccessControl::className(),
  23. 'rules' => [
  24. [
  25. 'allow' => true,
  26. 'roles' => ['@'],
  27. 'matchCallback' => function ($rule, $action) {
  28. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  29. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  30. }
  31. ]
  32. ],
  33. ],
  34. ];
  35. }
  36. public function actionReport() {
  37. // get your HTML raw content without any layouts or scripts
  38. $content = $this->renderPartial('report');
  39. /*$pdf = Yii::$app->pdf;
  40. $pdf->content = $content;
  41. $pdf->orientation = Pdf::ORIENT_LANDSCAPE ;
  42. return $pdf->render();*/
  43. // setup kartik\mpdf\Pdf component
  44. $pdf = new Pdf([
  45. // set to use core fonts only
  46. 'mode' => Pdf::MODE_UTF8,
  47. // A4 paper format
  48. 'format' => Pdf::FORMAT_A4,
  49. // portrait orientation
  50. 'orientation' => Pdf::ORIENT_LANDSCAPE,
  51. // stream to browser inline
  52. 'destination' => Pdf::DEST_BROWSER,
  53. // your html content input
  54. 'content' => $content,
  55. // format content from your own css file if needed or use the
  56. // enhanced bootstrap css built by Krajee for mPDF formatting
  57. //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
  58. // any css to be embedded if required
  59. //'cssInline' => '.kv-heading-1{font-size:18px}',
  60. // set mPDF properties on the fly
  61. //'options' => ['title' => 'Krajee Report Title'],
  62. // call mPDF methods on the fly
  63. 'methods' => [
  64. 'SetHeader'=>['Krajee Report Header'],
  65. 'SetFooter'=>['{PAGENO}'],
  66. ]
  67. ]);
  68. // return the pdf output as per the destination setting
  69. return $pdf->render();
  70. }
  71. public function actionDeleteCommande($date, $id_commande) {
  72. $commande = Commande::find()->where(['id' => $id_commande])->one();
  73. if ($commande) {
  74. $commande->delete();
  75. CommandeProduit::deleteAll(['id_commande' => $id_commande]);
  76. }
  77. $this->redirect(['index', 'date' => $date]);
  78. }
  79. public function gestionFormCommandes($production, $date, $points_vente, $produits, $users) {
  80. if ($date != '') {
  81. // commandes
  82. $commandes = Commande::find()
  83. ->with('commandeProduits', 'user')
  84. ->joinWith('production')
  85. ->where(['production.date' => $date])
  86. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  87. ->all();
  88. foreach ($commandes as $c)
  89. $c->init();
  90. foreach ($points_vente as $pv) {
  91. $pv->initCommandes($commandes);
  92. if (isset($_POST['submit_pv']) && $_POST['submit_pv']) {
  93. // modifs
  94. foreach ($pv->commandes as $c) {
  95. // suppression des commande_produit
  96. $commande_produits = CommandeProduit::find()->where(['id_commande' => $c->id])->all();
  97. foreach ($commande_produits as $cp)
  98. $cp->delete();
  99. // création des commande_produit modifiés
  100. foreach ($produits as $p) {
  101. $quantite = Yii::$app->getRequest()->post('produit_' . $c->id . '_' . $p->id, 0);
  102. if ($quantite) {
  103. $commande_produit = new CommandeProduit;
  104. $commande_produit->id_commande = $c->id;
  105. $commande_produit->id_produit = $p->id;
  106. $commande_produit->quantite = $quantite;
  107. $commande_produit->prix = $p->prix;
  108. $commande_produit->save();
  109. }
  110. }
  111. }
  112. // ajout
  113. //$id_client = Yii::$app->getRequest()->post('user_pv_'.$pv->id, 0) ;
  114. $username = Yii::$app->getRequest()->post('username_pv_' . $pv->id, 0);
  115. $date = Yii::$app->getRequest()->post('date_commande_pv_' . $pv->id, 0);
  116. $one_product = false;
  117. foreach ($produits as $p) {
  118. $quantite = Yii::$app->getRequest()->post('produit_pv_' . $pv->id . '_' . $p->id, 0);
  119. if ($quantite) {
  120. $one_product = true;
  121. }
  122. }
  123. if (strlen($username) && $date && $one_product) {
  124. $commande = new Commande;
  125. $commande->id_point_vente = $pv->id;
  126. $commande->id_production = $production->id;
  127. $commande->id_user = 0;
  128. $commande->username = $username;
  129. $tab_date = explode('/', $date);
  130. $commande->date = $tab_date[2] . '-' . $tab_date[1] . '-' . $tab_date[0] . ' 00:00:00';
  131. $commande->save();
  132. foreach ($produits as $p) {
  133. $quantite = Yii::$app->getRequest()->post('produit_pv_' . $pv->id . '_' . $p->id, 0);
  134. if ($quantite) {
  135. $commande_produit = new CommandeProduit;
  136. $commande_produit->id_commande = $commande->id;
  137. $commande_produit->id_produit = $p->id;
  138. $commande_produit->quantite = $quantite;
  139. $commande_produit->prix = $p->prix;
  140. $commande_produit->save();
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. public function actionIndex($date = '', $return_data = false) {
  149. $commandes = [];
  150. // points de vente
  151. $points_vente = PointVente::find()
  152. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  153. ->all();
  154. // produits
  155. $produits = Produit::find()
  156. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  157. ->orderBy('order ASC')
  158. ->all();
  159. // users
  160. $arr_users = [0 => '--'];
  161. $users = User::find()->orderBy('prenom, nom ASC')->all();
  162. foreach ($users as $u) {
  163. $arr_users[$u->id] = $u->prenom . ' ' . $u->nom;
  164. }
  165. // création du jour de production
  166. $production = null;
  167. if ($date != '') {
  168. $production = Production::find()
  169. ->where(['date' => $date])
  170. ->andWhere(['id_etablissement'=>Yii::$app->user->identity->id_etablissement])
  171. ->one();
  172. if (!$production) {
  173. $production = new Production;
  174. $production->date = $date;
  175. $production->livraison = 1;
  176. $production->id_etablissement = Yii::$app->user->identity->id_etablissement ;
  177. $production->save();
  178. }
  179. }
  180. // gestion des commandes
  181. $this->gestionFormCommandes($production, $date, $points_vente, $produits, $users);
  182. // commandes
  183. $commandes = Commande::find()
  184. ->with('commandeProduits', 'user')
  185. ->joinWith('production')
  186. ->where(['production.date' => $date])
  187. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  188. ->orderBy('date ASC')
  189. ->all();
  190. $recettes = 0;
  191. $recettes_pain = 0;
  192. $recettes_vrac = 0;
  193. $recettes_pain_livre = 0;
  194. $poids_pain = 0;
  195. $poids_vrac = 0;
  196. foreach ($commandes as $c) {
  197. $c->init();
  198. $recettes += $c->montant;
  199. $recettes_pain += $c->montant_pain;
  200. $recettes_vrac += $c->montant_vrac;
  201. if ($c->id_point_vente != 1)
  202. $recettes_pain_livre += $c->montant_pain;
  203. $poids_pain += $c->poids_pain;
  204. $poids_vrac += $c->poids_vrac;
  205. }
  206. $recettes = number_format($recettes, 2);
  207. $recettes_pain = number_format($recettes_pain, 2);
  208. $recettes_vrac = number_format($recettes_vrac, 2);
  209. // init commandes point de vente
  210. foreach ($points_vente as $pv) {
  211. $pv->initCommandes($commandes);
  212. }
  213. // gestion produits selec
  214. if (isset($_POST['valider_produit_selec'])) {
  215. if (isset($_POST['Produit'])) {
  216. foreach ($produits as $p) {
  217. $produit_production = ProductionProduit::find()->where(['id_production' => $production->id, 'id_produit' => $p->id])->one();
  218. if (!$produit_production) {
  219. $produit_production = new ProductionProduit();
  220. $produit_production->id_production = $production->id;
  221. $produit_production->id_produit = $p->id;
  222. $produit_production->actif = 0;
  223. if (isset($p->quantite_max))
  224. $produit_production->quantite_max = $p->quantite_max;
  225. $produit_production->save();
  226. }
  227. if (isset($_POST['Produit'][$p->id]['actif'])) {
  228. $produit_production->actif = 1;
  229. } else {
  230. $produit_production->actif = 0;
  231. }
  232. if ((isset($_POST['Produit'][$p->id]['quantite_max']) && $_POST['Produit'][$p->id]['quantite_max'] != '')) {
  233. $produit_production->quantite_max = (int) $_POST['Produit'][$p->id]['quantite_max'];
  234. } else {
  235. if (isset($p->quantite_max) && is_numeric($p->quantite_max) && $p->quantite_max > 0) {
  236. $produit_production->quantite_max = $p->quantite_max;
  237. }
  238. }
  239. $produit_production->save();
  240. }
  241. }
  242. }
  243. // init produits sélectionnés pour cette production
  244. $produits_selec = [];
  245. if ($production) {
  246. $day_production = date('N', strtotime($production->date));
  247. $produits_production = ProductionProduit::find()->where(['id_production' => $production->id])->all();
  248. if (!count($produits_production)) {
  249. foreach ($produits as $p) {
  250. $pp = new ProductionProduit();
  251. $pp->id_production = $production->id;
  252. $pp->id_produit = $p->id;
  253. $pp->actif = 0;
  254. if ($day_production == 1 && $p->lundi)
  255. $pp->actif = 1;
  256. if ($day_production == 2 && $p->mardi)
  257. $pp->actif = 1;
  258. if ($day_production == 3 && $p->mercredi)
  259. $pp->actif = 1;
  260. if ($day_production == 4 && $p->jeudi)
  261. $pp->actif = 1;
  262. if ($day_production == 5 && $p->vendredi)
  263. $pp->actif = 1;
  264. if ($day_production == 6 && $p->samedi)
  265. $pp->actif = 1;
  266. if ($day_production == 7 && $p->dimanche)
  267. $pp->actif = 1;
  268. $pp->quantite_max = $p->quantite_max;
  269. $pp->save();
  270. }
  271. }
  272. // produits selec pour production
  273. $produits_selec = ProductionProduit::findProduits($production->id);
  274. }
  275. // produit en vrac forcément activé
  276. if ($date != '') {
  277. foreach ($produits as $p) {
  278. $produit_production = ProductionProduit::find()->where(['id_production' => $production->id, 'id_produit' => $p->id])->one();
  279. if ($p->vrac) {
  280. if (!$produit_production) {
  281. $produit_production = new ProductionProduit();
  282. $produit_production->id_production = $production->id;
  283. $produit_production->id_produit = $p->id;
  284. $produit_production->quantite_max = 0;
  285. $produit_production->actif = 1;
  286. $produit_production->save();
  287. } else {
  288. $produit_production->actif = 1;
  289. $produit_production->save();
  290. }
  291. }
  292. }
  293. }
  294. // poids total de la production et CA potentiel
  295. $ca_potentiel = 0;
  296. $poids_total = 0;
  297. foreach ($produits_selec as $id_produit_selec => $produit_selec) {
  298. if ($produit_selec['actif']) {
  299. foreach ($produits as $produit) {
  300. if ($produit->id == $id_produit_selec) {
  301. //echo $produit->nom.' : '.$produit_selec['quantite_max'].'<br />' ;
  302. $ca_potentiel += $produit_selec['quantite_max'] * $produit->prix;
  303. $poids_total += $produit_selec['quantite_max'] * $produit->poids;
  304. }
  305. }
  306. }
  307. }
  308. // jours de production
  309. $jours_production = Production::find()->where(['actif' => 1])->all();
  310. $datas = [
  311. 'produits' => $produits,
  312. 'points_vente' => $points_vente,
  313. 'commandes' => $commandes,
  314. 'date' => $date,
  315. 'production' => $production,
  316. 'jours_production' => $jours_production,
  317. 'produits_selec' => $produits_selec,
  318. 'users' => $arr_users,
  319. 'recettes' => $recettes,
  320. 'recettes_pain' => $recettes_pain,
  321. 'recettes_vrac' => $recettes_vrac,
  322. 'recettes_pain_livre' => $recettes_pain_livre,
  323. 'poids_pain' => $poids_pain,
  324. 'poids_vrac' => $poids_vrac,
  325. 'ca_potentiel' => $ca_potentiel,
  326. 'poids_total' => $poids_total,
  327. ];
  328. if ($return_data) {
  329. return $datas;
  330. } else {
  331. return $this->render('index', $datas);
  332. }
  333. }
  334. public function actionDownload($date = '', $id_point_vente = 0, $global = 0) {
  335. // commandes
  336. $commandes = Commande::find()
  337. ->with('commandeProduits', 'user')
  338. ->joinWith('production')
  339. ->where(['production.date' => $date])
  340. ->orderBy('date ASC')
  341. ->all();
  342. foreach ($commandes as $c)
  343. $c->init();
  344. // points de vente
  345. $points_vente = PointVente::find()->all();
  346. foreach ($points_vente as $pv)
  347. $pv->initCommandes($commandes);
  348. // produits
  349. $produits = Produit::find()->orderBy('order ASC')->all();
  350. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  351. $produits_selec = ProductionProduit::findProduits($production->id);
  352. /*
  353. * export global
  354. */
  355. if ($global) {
  356. $data = [];
  357. $filename = 'export_' . $date . '_global';
  358. $num_jour_semaine = date('w', strtotime($date));
  359. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  360. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  361. // header
  362. /* $line = [''] ;
  363. foreach($produits as $p) {
  364. if(isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  365. $line[] = $p->getLibelleAdmin() ;
  366. }
  367. }
  368. $data[] = $line ; */
  369. // par point de vente
  370. foreach ($points_vente as $pv) {
  371. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  372. //$data[] = [$pv->nom] ;
  373. $line = [$pv->nom, 'Produits', 'Montant', 'Commentaire'];
  374. /* foreach($produits as $p) {
  375. if(isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  376. $line[] = $p->getLibelleAdmin() ;
  377. }
  378. } */
  379. $data[] = $line;
  380. $res = $this->contentPointVenteCSV($date, $produits, $points_vente, $pv->id);
  381. foreach ($res['data'] as $line) {
  382. $data[] = $line;
  383. }
  384. }
  385. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  386. $line = ['Total pain'];
  387. $str_produits = '';
  388. foreach ($produits as $p) {
  389. if (!$p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  390. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  391. $str_quantite = '';
  392. if ($quantite) {
  393. $str_quantite = $quantite;
  394. $str_produits .= $str_quantite . $p->diminutif . ', ';
  395. }
  396. }
  397. }
  398. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  399. $line[] = number_format($pv->recettes_pain, 2) . ' €';
  400. $data[] = $line;
  401. $line = ['Total vrac'];
  402. $str_produits = '';
  403. foreach ($produits as $p) {
  404. if ($p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  405. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  406. $str_quantite = '';
  407. if ($quantite) {
  408. $str_quantite = $quantite;
  409. $str_produits .= $str_quantite . $p->diminutif . ', ';
  410. }
  411. }
  412. }
  413. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  414. $line[] = number_format($pv->recettes_vrac, 2) . ' €';
  415. $data[] = $line;
  416. $data[] = [];
  417. }
  418. }
  419. // récap
  420. //$line = ['Totaux'] ;
  421. // pain
  422. $line = ['Total pain'];
  423. $str_produits = '';
  424. foreach ($produits as $p) {
  425. if (!$p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  426. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  427. $str_quantite = '';
  428. if ($quantite) {
  429. $str_quantite = $quantite;
  430. $str_produits .= $str_quantite . '' . $p->diminutif . ', ';
  431. }
  432. }
  433. }
  434. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  435. $data[] = $line;
  436. // vrac
  437. $line = ['Total vrac'];
  438. $str_produits = '';
  439. foreach ($produits as $p) {
  440. if ($p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  441. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  442. $str_quantite = '';
  443. if ($quantite) {
  444. $str_quantite = $quantite;
  445. $str_produits .= $str_quantite . '' . $p->diminutif . ', ';
  446. }
  447. }
  448. }
  449. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  450. $data[] = $line;
  451. $infos = $this->actionIndex($date, true);
  452. // $data[] = [] ;
  453. /* $data[] = [
  454. 'CA potentiel boutique',
  455. number_format($infos['ca_potentiel'] - $infos['recettes_pain_livre'], 2).' €',
  456. ] ; */
  457. /* $res = $this->contentRecapCSV($date, $produits, $points_vente, $commandes) ;
  458. $data[] = ['Récapitulatif global'] ;
  459. foreach($res['data'] as $line) {
  460. $data[] = $line ;
  461. } */
  462. CSV::downloadSendHeaders($filename . '.csv');
  463. echo CSV::array2csv($data);
  464. die();
  465. }
  466. /*
  467. * export individuel
  468. */ else {
  469. if ($commandes && count($commandes)) {
  470. $data = [];
  471. // par point de vente
  472. if ($id_point_vente) {
  473. $res = $this->contentPointVenteCSV($date, $produits, $points_vente, $id_point_vente);
  474. $data = $res['data'];
  475. $filename = $res['filename'];
  476. }
  477. // récapitulatif
  478. else {
  479. $res = $this->contentRecapCSV($date, $produits, $points_vente, $commandes);
  480. $filename = 'recapitulatif_' . $date;
  481. $data = $res['data'];
  482. }
  483. CSV::downloadSendHeaders($filename . '.csv');
  484. echo CSV::array2csv($data);
  485. die();
  486. }
  487. }
  488. }
  489. public function contentRecapCSV($date, $produits, $points_vente, $commandes) {
  490. $data = [];
  491. $filename = 'recapitulatif_' . $date;
  492. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  493. $produits_selec = ProductionProduit::findProduits($production->id);
  494. // head
  495. $data[0] = ['Lieu'];
  496. foreach ($produits as $p) {
  497. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  498. $data[0][] = $p->description;
  499. }
  500. }
  501. $num_jour_semaine = date('w', strtotime($date));
  502. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  503. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  504. // datas
  505. foreach ($points_vente as $pv) {
  506. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  507. $data_add = [$pv->nom];
  508. foreach ($produits as $p) {
  509. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  510. $data_add[] = Commande::getQuantiteProduit($p->id, $pv->commandes);
  511. }
  512. }
  513. $data[] = $data_add;
  514. }
  515. }
  516. $data_add = ['Total'];
  517. foreach ($produits as $p) {
  518. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  519. $data_add[] = Commande::getQuantiteProduit($p->id, $commandes);
  520. }
  521. }
  522. $data[] = $data_add;
  523. return [
  524. 'data' => $data,
  525. 'filename' => $filename
  526. ];
  527. }
  528. public function contentPointVenteCSV($date, $produits, $points_vente, $id_point_vente) {
  529. $data = [];
  530. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  531. $produits_selec = ProductionProduit::findProduits($production->id);
  532. // head
  533. /* $data[0] = ['Client', 'Date commande'] ;
  534. foreach($produits as $p) {
  535. if(isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  536. $data[0][] = $p->description ;
  537. }
  538. } */
  539. // datas
  540. foreach ($points_vente as $pv) {
  541. if ($pv->id == $id_point_vente) {
  542. $filename = 'export_' . $date . '_' . strtolower(str_replace(' ', '-', $pv->nom));
  543. foreach ($pv->commandes as $c) {
  544. $str_user = '';
  545. // username
  546. if ($c->user) {
  547. $str_user = $c->user->prenom . " " . $c->user->nom; //.' - '.date('d/m', strtotime($c->date)) ;
  548. } else {
  549. $str_user = $c->username; //.' - '.date('d/m', strtotime($c->date)) ;
  550. }
  551. // téléphone
  552. if (strlen($c->user->telephone)) {
  553. $str_user .= ' (' . $c->user->telephone . ')';
  554. }
  555. $data_add = [$str_user];
  556. // produits
  557. $str_produits = '';
  558. foreach ($produits as $p) {
  559. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  560. $add = false;
  561. foreach ($c->commandeProduits as $cp) {
  562. if ($p->id == $cp->id_produit) {
  563. $str_produits .= $cp->quantite . '' . $p->diminutif . ', ';
  564. $add = true;
  565. }
  566. }
  567. }
  568. }
  569. $data_add[] = substr($str_produits, 0, strlen($str_produits) - 2);
  570. $data_add[] = number_format($c->montant, 2) . ' €';
  571. $data_add[] = $c->commentaire;
  572. $data[] = $data_add;
  573. }
  574. }
  575. }
  576. return [
  577. 'data' => $data,
  578. 'filename' => $filename
  579. ];
  580. }
  581. public function actionChangeState($date, $actif) {
  582. // changement état
  583. $production = Production::find()->where(['date' => $date])->one();
  584. $production->actif = $actif;
  585. $production->save();
  586. $this->redirect(['index', 'date' => $date]);
  587. }
  588. public function actionChangeLivraison($date, $livraison) {
  589. $production = Production::find()->where(['date' => $date])->one();
  590. $production->livraison = $livraison;
  591. $production->save();
  592. $this->redirect(['index', 'date' => $date]);
  593. }
  594. }