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.

1340 lines
53KB

  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. namespace backend\controllers;
  32. class CommandeController extends BackendController {
  33. var $enableCsrfValidation = false;
  34. public function behaviors() {
  35. return [
  36. 'access' => [
  37. 'class' => AccessControl::className(),
  38. 'rules' => [
  39. [
  40. 'actions' => ['report-cron'],
  41. 'allow' => true,
  42. 'roles' => ['?']
  43. ],
  44. [
  45. 'allow' => true,
  46. 'roles' => ['@'],
  47. 'matchCallback' => function ($rule, $action) {
  48. return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  49. }
  50. ]
  51. ],
  52. ],
  53. ];
  54. }
  55. public function actionReportCron($date = '', $save = false, $id_etablissement = 0, $key = '') {
  56. if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
  57. $this->actionReport($date, $save, $id_etablissement);
  58. }
  59. }
  60. public function actionReport($date = '', $save = false, $id_etablissement = 0) {
  61. if (!Yii::$app->user->isGuest)
  62. $id_etablissement = Yii::$app->user->identity->id_etablissement;
  63. $commandes = Commande::findBy([
  64. 'date' => $date,
  65. 'date_delete' => 'NULL',
  66. 'id_etablissement' => $id_etablissement,
  67. 'orderby' => 'commentaire_point_vente ASC, user.nom ASC'
  68. ]);
  69. foreach ($commandes as $c)
  70. $c->init();
  71. $production = Production::find()
  72. ->where('date LIKE \'' . $date . '\'')
  73. ->andWhere(['id_etablissement' => $id_etablissement])
  74. ->one();
  75. if ($production) {
  76. $produits_selec = ProductionProduit::findProduits($production->id);
  77. $points_vente = PointVente::find()
  78. ->where(['id_etablissement' => $id_etablissement])
  79. ->all();
  80. foreach ($points_vente as $pv)
  81. $pv->initCommandes($commandes);
  82. // produits
  83. $produits = Produit::find()
  84. ->where(['id_etablissement' => $id_etablissement])
  85. ->orderBy('order ASC')
  86. ->all();
  87. // get your HTML raw content without any layouts or scripts
  88. $content = $this->renderPartial('report', [
  89. 'production' => $production,
  90. 'produits_selec' => $produits_selec,
  91. 'points_vente' => $points_vente,
  92. 'date' => $date,
  93. 'produits' => $produits,
  94. 'commandes' => $commandes
  95. ]);
  96. $date_str = date('d/m/Y', strtotime($date));
  97. if ($save) {
  98. $destination = Pdf::DEST_FILE;
  99. } else {
  100. $destination = Pdf::DEST_BROWSER;
  101. }
  102. $pdf = new Pdf([
  103. // set to use core fonts only
  104. 'mode' => Pdf::MODE_UTF8,
  105. // A4 paper format
  106. 'format' => Pdf::FORMAT_A4,
  107. // portrait orientation
  108. 'orientation' => Pdf::ORIENT_PORTRAIT,
  109. // stream to browser inline
  110. 'destination' => $destination,
  111. 'filename' => Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $id_etablissement . '.pdf'),
  112. // your html content input
  113. 'content' => $content,
  114. // format content from your own css file if needed or use the
  115. // enhanced bootstrap css built by Krajee for mPDF formatting
  116. //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
  117. // any css to be embedded if required
  118. //'cssInline' => '.kv-heading-1{font-size:18px}',
  119. // set mPDF properties on the fly
  120. //'options' => ['title' => 'Krajee Report Title'],
  121. // call mPDF methods on the fly
  122. 'methods' => [
  123. 'SetHeader' => ['Commandes du ' . $date_str],
  124. 'SetFooter' => ['{PAGENO}'],
  125. ]
  126. ]);
  127. // return the pdf output as per the destination setting
  128. return $pdf->render();
  129. }
  130. }
  131. public function actionDeleteCommande($date, $id_commande) {
  132. $commande = Commande::find()
  133. ->with(['production', 'commandeProduits'])
  134. ->where(['id' => $id_commande])
  135. ->one();
  136. if ($commande) {
  137. $commande->init();
  138. // remboursement de la commande
  139. if ($commande->id_user && $commande->getMontantPaye() && Etablissement::getConfig('credit_pain')) {
  140. $commande->creditHistorique(
  141. CreditHistorique::TYPE_REMBOURSEMENT,
  142. $commande->getMontantPaye(),
  143. $commande->production->id_etablissement,
  144. $commande->id_user,
  145. Yii::$app->user->identity->id
  146. );
  147. }
  148. $commande->delete();
  149. CommandeProduit::deleteAll(['id_commande' => $id_commande]);
  150. }
  151. $this->redirect(['index', 'date' => $date]);
  152. }
  153. public function gestionFormCommandes($production, $date, $points_vente, $produits, $users) {
  154. if ($date != '') {
  155. // commandes
  156. $commandes = Commande::find()
  157. ->with('commandeProduits', 'user')
  158. ->joinWith('production')
  159. ->where(['production.date' => $date])
  160. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  161. ->all();
  162. foreach ($commandes as $c)
  163. $c->init();
  164. foreach ($points_vente as $pv) {
  165. $pv->initCommandes($commandes);
  166. if (isset($_POST['submit_pv']) && $_POST['submit_pv']) {
  167. // modifs
  168. foreach ($pv->commandes as $c) {
  169. // suppression des commande_produit
  170. $commande_produits = CommandeProduit::find()->where(['id_commande' => $c->id])->all();
  171. foreach ($commande_produits as $cp)
  172. $cp->delete();
  173. // création des commande_produit modifiés
  174. foreach ($produits as $p) {
  175. $quantite = Yii::$app->getRequest()->post('produit_' . $c->id . '_' . $p->id, 0);
  176. if ($quantite) {
  177. $commande_produit = new CommandeProduit;
  178. $commande_produit->id_commande = $c->id;
  179. $commande_produit->id_produit = $p->id;
  180. $commande_produit->quantite = $quantite;
  181. $commande_produit->prix = $p->prix;
  182. $commande_produit->save();
  183. }
  184. }
  185. }
  186. // ajout
  187. //$id_client = Yii::$app->getRequest()->post('user_pv_'.$pv->id, 0) ;
  188. $username = Yii::$app->getRequest()->post('username_pv_' . $pv->id, 0);
  189. $date = Yii::$app->getRequest()->post('date_commande_pv_' . $pv->id, 0);
  190. $one_product = false;
  191. foreach ($produits as $p) {
  192. $quantite = Yii::$app->getRequest()->post('produit_pv_' . $pv->id . '_' . $p->id, 0);
  193. if ($quantite) {
  194. $one_product = true;
  195. }
  196. }
  197. if (strlen($username) && $date && $one_product) {
  198. $commande = new Commande;
  199. $commande->id_point_vente = $pv->id;
  200. $commande->id_production = $production->id;
  201. $commande->id_user = 0;
  202. $commande->username = $username;
  203. $tab_date = explode('/', $date);
  204. $commande->date = $tab_date[2] . '-' . $tab_date[1] . '-' . $tab_date[0] . ' 00:00:00';
  205. $commande->save();
  206. foreach ($produits as $p) {
  207. $quantite = Yii::$app->getRequest()->post('produit_pv_' . $pv->id . '_' . $p->id, 0);
  208. if ($quantite) {
  209. $commande_produit = new CommandeProduit;
  210. $commande_produit->id_commande = $commande->id;
  211. $commande_produit->id_produit = $p->id;
  212. $commande_produit->quantite = $quantite;
  213. $commande_produit->prix = $p->prix;
  214. $commande_produit->save();
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. public function actionIndex($date = '', $return_data = false) {
  223. if (!Produit::count() && !PointVente::count()) {
  224. $this->redirect(['site/index', 'erreur_produits_points_vente' => 1]);
  225. }
  226. $commandes = [];
  227. // users
  228. $arr_users = [0 => '--'];
  229. $users = User::find()->orderBy('prenom, nom ASC')->all();
  230. foreach ($users as $u) {
  231. $arr_users[$u->id] = $u->prenom . ' ' . $u->nom;
  232. }
  233. // création du jour de production
  234. $production = Production::initProduction($date) ;
  235. // points de vente
  236. if ($production) {
  237. $points_vente = PointVente::find()
  238. ->joinWith(['productionPointVente' => function($q) use ($production) {
  239. $q->where(['id_production' => $production->id]);
  240. }])
  241. ->where([
  242. 'id_etablissement' => Yii::$app->user->identity->id_etablissement,
  243. ])
  244. ->all();
  245. } else {
  246. $points_vente = PointVente::find()
  247. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement,])
  248. ->all();
  249. }
  250. // produits
  251. $produits = Produit::getAll();
  252. // gestion des commandes
  253. $this->gestionFormCommandes($production, $date, $points_vente, $produits, $users);
  254. // commandes
  255. $commandes = Commande::findBy([
  256. 'date' => $date,
  257. 'date_delete' => 'NULL'
  258. ]);
  259. $recettes = 0;
  260. $recettes_pain = 0;
  261. $recettes_vrac = 0;
  262. $recettes_pain_livre = 0;
  263. $poids_pain = 0;
  264. $poids_vrac = 0;
  265. foreach ($commandes as $c) {
  266. $c->init();
  267. if(is_null($c->date_delete)) {
  268. $recettes += $c->montant;
  269. $recettes_pain += $c->montant_pain;
  270. $recettes_vrac += $c->montant_vrac;
  271. if ($c->id_point_vente != 1)
  272. $recettes_pain_livre += $c->montant_pain;
  273. $poids_pain += $c->poids_pain;
  274. $poids_vrac += $c->poids_vrac;
  275. }
  276. }
  277. $recettes = number_format($recettes, 2);
  278. $recettes_pain = number_format($recettes_pain, 2);
  279. $recettes_vrac = number_format($recettes_vrac, 2);
  280. // init commandes point de vente
  281. foreach ($points_vente as $pv) {
  282. $pv->initCommandes($commandes);
  283. $data_select_commandes = [];
  284. $data_options_commandes = [];
  285. foreach ($pv->commandes as $c) {
  286. if ($c->user) {
  287. $data_select_commandes[$c->id] = $c->user->nom . ' ' . $c->user->prenom;
  288. } else {
  289. $data_select_commandes[$c->id] = $c->username;
  290. }
  291. $data_options_commandes[$c->id] = [];
  292. $array_options = [];
  293. $array_options[$c->id]['montant'] = $c->montant;
  294. $array_options[$c->id]['str_montant'] = number_format($c->montant, 2, ',', '') . ' €';
  295. $array_options[$c->id]['montant_paye'] = $c->montant_paye;
  296. $array_options[$c->id]['produits'] = [];
  297. $array_options[$c->id]['commentaire'] = Html::encode($c->commentaire);
  298. foreach ($c->commandeProduits as $cp) {
  299. $array_options[$c->id]['produits'][$cp->id_produit] = $cp->quantite;
  300. }
  301. $data_options_commandes[$c->id]['data-commande'] = json_encode($array_options[$c->id]);
  302. $data_options_commandes[$c->id]['value'] = $c->id;
  303. }
  304. $pv->data_select_commandes = $data_select_commandes;
  305. $pv->data_options_commandes = $data_options_commandes;
  306. }
  307. // gestion produits selec
  308. if (isset($_POST['valider_produit_selec'])) {
  309. if (isset($_POST['Produit'])) {
  310. foreach ($produits as $p) {
  311. $produit_production = ProductionProduit::find()->where(['id_production' => $production->id, 'id_produit' => $p->id])->one();
  312. if (!$produit_production) {
  313. $produit_production = new ProductionProduit();
  314. $produit_production->id_production = $production->id;
  315. $produit_production->id_produit = $p->id;
  316. $produit_production->actif = 0;
  317. if (isset($p->quantite_max))
  318. $produit_production->quantite_max = $p->quantite_max;
  319. else
  320. $produit_production->quantite_max = null;
  321. $produit_production->save();
  322. }
  323. if (isset($_POST['Produit'][$p->id]['actif'])) {
  324. $produit_production->actif = 1;
  325. } else {
  326. $produit_production->actif = 0;
  327. }
  328. if ((isset($_POST['Produit'][$p->id]['quantite_max']) && $_POST['Produit'][$p->id]['quantite_max'] != '')) {
  329. $produit_production->quantite_max = (int) $_POST['Produit'][$p->id]['quantite_max'];
  330. } else {
  331. $produit_production->quantite_max = null;
  332. }
  333. $produit_production->save();
  334. }
  335. }
  336. }
  337. // init produits sélectionnés pour cette production
  338. $produits_selec = [];
  339. if ($production) {
  340. $day_production = date('N', strtotime($production->date));
  341. $produits_production = ProductionProduit::find()->where(['id_production' => $production->id])->all();
  342. if (!count($produits_production)) {
  343. foreach ($produits as $p) {
  344. $pp = new ProductionProduit();
  345. $pp->id_production = $production->id;
  346. $pp->id_produit = $p->id;
  347. $pp->actif = 0;
  348. if ($p->actif && $day_production == 1 && $p->lundi)
  349. $pp->actif = 1;
  350. if ($p->actif && $day_production == 2 && $p->mardi)
  351. $pp->actif = 1;
  352. if ($p->actif && $day_production == 3 && $p->mercredi)
  353. $pp->actif = 1;
  354. if ($p->actif && $day_production == 4 && $p->jeudi)
  355. $pp->actif = 1;
  356. if ($p->actif && $day_production == 5 && $p->vendredi)
  357. $pp->actif = 1;
  358. if ($p->actif && $day_production == 6 && $p->samedi)
  359. $pp->actif = 1;
  360. if ($p->actif && $day_production == 7 && $p->dimanche)
  361. $pp->actif = 1;
  362. $pp->quantite_max = $p->quantite_max;
  363. $pp->save();
  364. }
  365. }
  366. // produits selec pour production
  367. $produits_selec = ProductionProduit::findProduits($production->id);
  368. }
  369. // produit en vrac forcément activé
  370. if ($date != '') {
  371. foreach ($produits as $p) {
  372. $produit_production = ProductionProduit::find()->where(['id_production' => $production->id, 'id_produit' => $p->id])->one();
  373. if ($p->vrac) {
  374. if (!$produit_production) {
  375. $produit_production = new ProductionProduit();
  376. $produit_production->id_production = $production->id;
  377. $produit_production->id_produit = $p->id;
  378. $produit_production->quantite_max = 0;
  379. $produit_production->actif = 1;
  380. $produit_production->save();
  381. } else {
  382. $produit_production->actif = 1;
  383. $produit_production->save();
  384. }
  385. }
  386. }
  387. }
  388. // produits
  389. if ($production)
  390. $produits = Produit::getByProduction($production->id);
  391. // poids total de la production et CA potentiel
  392. $ca_potentiel = 0;
  393. $poids_total = 0;
  394. foreach ($produits_selec as $id_produit_selec => $produit_selec) {
  395. if ($produit_selec['actif']) {
  396. foreach ($produits as $produit) {
  397. if ($produit->id == $id_produit_selec) {
  398. //echo $produit->nom.' : '.$produit_selec['quantite_max'].'<br />' ;
  399. $ca_potentiel += $produit_selec['quantite_max'] * $produit->prix;
  400. $poids_total += $produit_selec['quantite_max'] * $produit->poids / 1000;
  401. }
  402. }
  403. }
  404. }
  405. // jours de production
  406. $jours_production = Production::find()
  407. ->where([
  408. 'actif' => 1,
  409. 'id_etablissement' => Yii::$app->user->identity->id_etablissement
  410. ])
  411. ->all();
  412. // commandes auto
  413. $model_commande_auto = new CommandeAutoForm;
  414. // productions point vente
  415. $production_point_vente = new ProductionPointVente;
  416. $productions_point_vente = [];
  417. if ($production) {
  418. $productions_point_vente = ProductionPointVente::find()
  419. ->with('pointVente')
  420. ->where(['id_production' => $production->id])
  421. ->all();
  422. }
  423. $arr_productions_point_vente = [];
  424. foreach ($productions_point_vente as $ppv) {
  425. $key = $ppv->id_production . '-' . $ppv->id_point_vente;
  426. if ($ppv->livraison == 1)
  427. $production_point_vente->productions_point_vente[] = $key;
  428. if(isset($ppv->pointVente) && strlen($ppv->pointVente->nom)) {
  429. $arr_productions_point_vente[$key] = Html::encode($ppv->pointVente->nom);
  430. }
  431. }
  432. // une production de la semaine activée ou non
  433. $production_semaine_active = false ;
  434. $week = sprintf('%02d',date('W',strtotime($date)));
  435. $start = strtotime(date('Y',strtotime($date)).'W'.$week);
  436. $date_lundi = date('Y-m-d',strtotime('Monday',$start)) ;
  437. $date_mardi = date('Y-m-d',strtotime('Tuesday',$start)) ;
  438. $date_mercredi = date('Y-m-d',strtotime('Wednesday',$start)) ;
  439. $date_jeudi = date('Y-m-d',strtotime('Thursday',$start)) ;
  440. $date_vendredi = date('Y-m-d',strtotime('Friday',$start)) ;
  441. $date_samedi = date('Y-m-d',strtotime('Saturday',$start)) ;
  442. $date_dimanche = date('Y-m-d',strtotime('Sunday',$start)) ;
  443. $production_semaine = Production::find()
  444. ->andWhere([
  445. 'id_etablissement' => Yii::$app->user->identity->id_etablissement,
  446. 'actif' => 1,
  447. ])
  448. ->andWhere(['or',
  449. ['date' => $date_lundi],
  450. ['date' => $date_mardi],
  451. ['date' => $date_mercredi],
  452. ['date' => $date_jeudi],
  453. ['date' => $date_vendredi],
  454. ['date' => $date_samedi],
  455. ['date' => $date_dimanche],
  456. ])
  457. ->one();
  458. if($production_semaine) {
  459. $production_semaine_active = true ;
  460. }
  461. $datas = [
  462. 'produits' => $produits,
  463. 'points_vente' => $points_vente,
  464. 'commandes' => $commandes,
  465. 'date' => $date,
  466. 'production' => $production,
  467. 'jours_production' => $jours_production,
  468. 'produits_selec' => $produits_selec,
  469. 'users' => $arr_users,
  470. 'recettes' => $recettes,
  471. 'recettes_pain' => $recettes_pain,
  472. 'recettes_vrac' => $recettes_vrac,
  473. 'recettes_pain_livre' => $recettes_pain_livre,
  474. 'poids_pain' => $poids_pain,
  475. 'poids_vrac' => $poids_vrac,
  476. 'ca_potentiel' => $ca_potentiel,
  477. 'poids_total' => $poids_total,
  478. 'model_commande_auto' => $model_commande_auto,
  479. 'production_point_vente' => $production_point_vente,
  480. 'productions_point_vente' => $productions_point_vente,
  481. 'arr_productions_point_vente' => $arr_productions_point_vente,
  482. 'production_semaine_active' =>$production_semaine_active
  483. ];
  484. if ($return_data) {
  485. return $datas;
  486. } else {
  487. return $this->render('index', $datas);
  488. }
  489. }
  490. public function actionDownload($date = '', $id_point_vente = 0, $global = 0) {
  491. // commandes
  492. $commandes = Commande::find()
  493. ->with('commandeProduits', 'user')
  494. ->joinWith('production')
  495. ->where(['production.date' => $date])
  496. ->orderBy('date ASC')
  497. ->all();
  498. foreach ($commandes as $c)
  499. $c->init();
  500. // points de vente
  501. $points_vente = PointVente::find()->all();
  502. foreach ($points_vente as $pv)
  503. $pv->initCommandes($commandes);
  504. // produits
  505. $produits = Produit::find()->orderBy('order ASC')->all();
  506. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  507. $produits_selec = ProductionProduit::findProduits($production->id);
  508. /*
  509. * export global
  510. */
  511. if ($global) {
  512. $data = [];
  513. $filename = 'export_' . $date . '_global';
  514. $num_jour_semaine = date('w', strtotime($date));
  515. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  516. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  517. // par point de vente
  518. foreach ($points_vente as $pv) {
  519. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  520. $line = [$pv->nom, 'Produits', 'Montant', 'Commentaire'];
  521. $data[] = $line;
  522. $res = $this->contentPointVenteCSV($date, $produits, $points_vente, $pv->id);
  523. foreach ($res['data'] as $line) {
  524. $data[] = $line;
  525. }
  526. }
  527. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  528. $line = ['Total pain'];
  529. $str_produits = '';
  530. foreach ($produits as $p) {
  531. if (!$p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  532. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  533. $str_quantite = '';
  534. if ($quantite) {
  535. $str_quantite = $quantite;
  536. $str_produits .= $str_quantite . $p->diminutif . ', ';
  537. }
  538. }
  539. }
  540. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  541. $line[] = number_format($pv->recettes_pain, 2) . ' €';
  542. $data[] = $line;
  543. $line = ['Total vrac'];
  544. $str_produits = '';
  545. foreach ($produits as $p) {
  546. if ($p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  547. $quantite = Commande::getQuantiteProduit($p->id, $pv->commandes);
  548. $str_quantite = '';
  549. if ($quantite) {
  550. $str_quantite = $quantite;
  551. $str_produits .= $str_quantite . $p->diminutif . ', ';
  552. }
  553. }
  554. }
  555. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  556. $line[] = number_format($pv->recettes_vrac, 2) . ' €';
  557. $data[] = $line;
  558. $data[] = [];
  559. }
  560. }
  561. // récap
  562. //$line = ['Totaux'] ;
  563. // pain
  564. $line = ['Total pain'];
  565. $str_produits = '';
  566. foreach ($produits as $p) {
  567. if (!$p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  568. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  569. $str_quantite = '';
  570. if ($quantite) {
  571. $str_quantite = $quantite;
  572. $str_produits .= $str_quantite . '' . $p->diminutif . ', ';
  573. }
  574. }
  575. }
  576. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  577. $data[] = $line;
  578. // vrac
  579. $line = ['Total vrac'];
  580. $str_produits = '';
  581. foreach ($produits as $p) {
  582. if ($p->vrac && isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  583. $quantite = Commande::getQuantiteProduit($p->id, $commandes);
  584. $str_quantite = '';
  585. if ($quantite) {
  586. $str_quantite = $quantite;
  587. $str_produits .= $str_quantite . '' . $p->diminutif . ', ';
  588. }
  589. }
  590. }
  591. $line[] = substr($str_produits, 0, strlen($str_produits) - 2);
  592. $data[] = $line;
  593. $infos = $this->actionIndex($date, true);
  594. CSV::downloadSendHeaders($filename . '.csv');
  595. echo CSV::array2csv($data);
  596. die();
  597. }
  598. /*
  599. * export individuel
  600. */ else {
  601. if ($commandes && count($commandes)) {
  602. $data = [];
  603. // par point de vente
  604. if ($id_point_vente) {
  605. $res = $this->contentPointVenteCSV($date, $produits, $points_vente, $id_point_vente);
  606. $data = $res['data'];
  607. $filename = $res['filename'];
  608. }
  609. // récapitulatif
  610. else {
  611. $res = $this->contentRecapCSV($date, $produits, $points_vente, $commandes);
  612. $filename = 'recapitulatif_' . $date;
  613. $data = $res['data'];
  614. }
  615. CSV::downloadSendHeaders($filename . '.csv');
  616. echo CSV::array2csv($data);
  617. die();
  618. }
  619. }
  620. }
  621. public function contentRecapCSV($date, $produits, $points_vente, $commandes) {
  622. $data = [];
  623. $filename = 'recapitulatif_' . $date;
  624. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  625. $produits_selec = ProductionProduit::findProduits($production->id);
  626. // head
  627. $data[0] = ['Lieu'];
  628. foreach ($produits as $p) {
  629. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  630. $data[0][] = $p->description;
  631. }
  632. }
  633. $num_jour_semaine = date('w', strtotime($date));
  634. $arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
  635. $champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];
  636. // datas
  637. foreach ($points_vente as $pv) {
  638. if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
  639. $data_add = [$pv->nom];
  640. foreach ($produits as $p) {
  641. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  642. $data_add[] = Commande::getQuantiteProduit($p->id, $pv->commandes);
  643. }
  644. }
  645. $data[] = $data_add;
  646. }
  647. }
  648. $data_add = ['Total'];
  649. foreach ($produits as $p) {
  650. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  651. $data_add[] = Commande::getQuantiteProduit($p->id, $commandes);
  652. }
  653. }
  654. $data[] = $data_add;
  655. return [
  656. 'data' => $data,
  657. 'filename' => $filename
  658. ];
  659. }
  660. public function contentPointVenteCSV($date, $produits, $points_vente, $id_point_vente) {
  661. $data = [];
  662. $production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
  663. $produits_selec = ProductionProduit::findProduits($production->id);
  664. // head
  665. /* $data[0] = ['Client', 'Date commande'] ;
  666. foreach($produits as $p) {
  667. if(isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  668. $data[0][] = $p->description ;
  669. }
  670. } */
  671. // datas
  672. foreach ($points_vente as $pv) {
  673. if ($pv->id == $id_point_vente) {
  674. $filename = 'export_' . $date . '_' . strtolower(str_replace(' ', '-', $pv->nom));
  675. foreach ($pv->commandes as $c) {
  676. $str_user = '';
  677. // username
  678. if ($c->user) {
  679. $str_user = $c->user->prenom . " " . $c->user->nom; //.' - '.date('d/m', strtotime($c->date)) ;
  680. } else {
  681. $str_user = $c->username; //.' - '.date('d/m', strtotime($c->date)) ;
  682. }
  683. // téléphone
  684. if (isset($c->user) && strlen($c->user->telephone)) {
  685. $str_user .= ' (' . $c->user->telephone . ')';
  686. }
  687. $data_add = [$str_user];
  688. // produits
  689. $str_produits = '';
  690. foreach ($produits as $p) {
  691. if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
  692. $add = false;
  693. foreach ($c->commandeProduits as $cp) {
  694. if ($p->id == $cp->id_produit) {
  695. $str_produits .= $cp->quantite . '' . $p->diminutif . ', ';
  696. $add = true;
  697. }
  698. }
  699. }
  700. }
  701. $data_add[] = substr($str_produits, 0, strlen($str_produits) - 2);
  702. $data_add[] = number_format($c->montant, 2) . ' €';
  703. $data_add[] = $c->commentaire;
  704. $data[] = $data_add;
  705. }
  706. }
  707. }
  708. return [
  709. 'data' => $data,
  710. 'filename' => $filename
  711. ];
  712. }
  713. public function actionAddCommandesAuto($date) {
  714. CommandeAuto::addAll($date, true);
  715. $this->redirect(['index', 'date' => $date]);
  716. }
  717. public function actionChangeState($date, $actif, $redirect = true) {
  718. // changement état
  719. $production = Production::initProduction($date) ;
  720. $production->actif = $actif;
  721. $production->save();
  722. if ($actif) {
  723. // add commandes automatiques
  724. CommandeAuto::addAll($date);
  725. }
  726. if($redirect)
  727. $this->redirect(['index', 'date' => $date]);
  728. }
  729. public function actionChangeStateSemaine($date, $actif) {
  730. $week = sprintf('%02d',date('W',strtotime($date)));
  731. $start = strtotime(date('Y',strtotime($date)).'W'.$week);
  732. $date_lundi = date('Y-m-d',strtotime('Monday',$start)) ;
  733. $date_mardi = date('Y-m-d',strtotime('Tuesday',$start)) ;
  734. $date_mercredi = date('Y-m-d',strtotime('Wednesday',$start)) ;
  735. $date_jeudi = date('Y-m-d',strtotime('Thursday',$start)) ;
  736. $date_vendredi = date('Y-m-d',strtotime('Friday',$start)) ;
  737. $date_samedi = date('Y-m-d',strtotime('Saturday',$start)) ;
  738. $date_dimanche = date('Y-m-d',strtotime('Sunday',$start)) ;
  739. $points_vente = PointVente::find()
  740. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement,])
  741. ->all();
  742. $lundi_active = false ;
  743. $mardi_active = false ;
  744. $mercredi_active = false ;
  745. $jeudi_active = false ;
  746. $vendredi_active = false ;
  747. $samedi_active = false ;
  748. $dimanche_active = false ;
  749. foreach($points_vente as $pv) {
  750. if($pv->livraison_lundi) $lundi_active = true ;
  751. if($pv->livraison_mardi) $mardi_active = true ;
  752. if($pv->livraison_mercredi) $mercredi_active = true ;
  753. if($pv->livraison_jeudi) $jeudi_active = true ;
  754. if($pv->livraison_vendredi) $vendredi_active = true ;
  755. if($pv->livraison_samedi) $samedi_active = true ;
  756. if($pv->livraison_dimanche) $dimanche_active = true ;
  757. }
  758. if($lundi_active || !$actif) $this->actionChangeState($date_lundi, $actif, false) ;
  759. if($mardi_active || !$actif) $this->actionChangeState($date_mardi, $actif, false) ;
  760. if($mercredi_active || !$actif) $this->actionChangeState($date_mercredi, $actif, false) ;
  761. if($jeudi_active || !$actif) $this->actionChangeState($date_jeudi, $actif, false) ;
  762. if($vendredi_active || !$actif) $this->actionChangeState($date_vendredi, $actif, false) ;
  763. if($samedi_active || !$actif) $this->actionChangeState($date_samedi, $actif, false) ;
  764. if($dimanche_active || !$actif) $this->actionChangeState($date_dimanche, $actif, false) ;
  765. $this->redirect(['index', 'date' => $date]);
  766. }
  767. public function actionChangeLivraison($date, $livraison) {
  768. $production = Production::find()->where(['date' => $date])->one();
  769. $production->livraison = $livraison;
  770. $production->save();
  771. $this->redirect(['index', 'date' => $date]);
  772. }
  773. public function actionAjaxUpdate($id_commande, $produits, $date, $commentaire) {
  774. $commande = Commande::find()->with('production', 'creditHistorique', 'user')->where(['id' => $id_commande])->one();
  775. if ($commande &&
  776. $commande->production->id_etablissement == Yii::$app->user->identity->id_etablissement) {
  777. $commande->init();
  778. $produits = json_decode($produits);
  779. foreach ($produits as $key => $quantite) {
  780. $commande_produit = CommandeProduit::findOne([
  781. 'id_commande' => $id_commande,
  782. 'id_produit' => $key
  783. ]);
  784. if ($quantite) {
  785. if ($commande_produit) {
  786. $commande_produit->quantite = $quantite;
  787. } else {
  788. $produit = Produit::findOne($key);
  789. if ($produit) {
  790. $commande_produit = new CommandeProduit;
  791. $commande_produit->id_commande = $id_commande;
  792. $commande_produit->id_produit = $key;
  793. $commande_produit->quantite = $quantite;
  794. $commande_produit->prix = $produit->prix;
  795. }
  796. }
  797. $commande_produit->save();
  798. } else {
  799. if ($commande_produit)
  800. $commande_produit->delete();
  801. }
  802. }
  803. $commande->date_update = date('Y-m-d H:i:s');
  804. $commande->commentaire = $commentaire;
  805. $commande->save();
  806. // data commande
  807. $json_commande = $commande->getDataJson();
  808. // total point de vente
  809. $point_vente = PointVente::findOne($commande->id_point_vente);
  810. $commandes = Commande::find()
  811. ->with('commandeProduits', 'user')
  812. ->joinWith('production')
  813. ->where(['production.date' => $date])
  814. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  815. ->orderBy('date ASC')
  816. ->all();
  817. foreach ($commandes as $c)
  818. $c->init();
  819. $point_vente->initCommandes($commandes);
  820. echo json_encode([
  821. 'total_pv' => number_format($point_vente->recettes, 2) . ' €',
  822. 'json_commande' => $json_commande
  823. ]);
  824. die();
  825. }
  826. }
  827. public function actionAjaxDelete($date, $id_commande) {
  828. $commande = Commande::find()
  829. ->with(['production', 'commandeProduits'])
  830. ->where(['id' => $id_commande])
  831. ->one();
  832. $commande->init() ;
  833. // delete
  834. if ($commande) {
  835. // remboursement si l'utilisateur a payé pour cette commande
  836. $montant_paye = $commande->getMontantPaye();
  837. if ($montant_paye > 0.01) {
  838. $commande->creditHistorique(
  839. CreditHistorique::TYPE_REMBOURSEMENT,
  840. $montant_paye,
  841. Yii::$app->user->identity->id_etablissement,
  842. $commande->id_user,
  843. Yii::$app->user->identity->id
  844. );
  845. }
  846. $commande->delete();
  847. CommandeProduit::deleteAll(['id_commande' => $id_commande]);
  848. }
  849. // total point de vente
  850. $point_vente = PointVente::findOne($commande->id_point_vente);
  851. $commandes = Commande::find()
  852. ->with('commandeProduits', 'user')
  853. ->joinWith('production')
  854. ->where(['production.date' => $date])
  855. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  856. ->orderBy('date ASC')
  857. ->all();
  858. foreach ($commandes as $c)
  859. $c->init();
  860. $point_vente->initCommandes($commandes);
  861. echo json_encode([
  862. 'total_pv' => number_format($point_vente->recettes, 2) . ' €',
  863. ]);
  864. die();
  865. }
  866. public function actionAjaxCreate($date, $id_pv, $id_user, $username, $produits, $commentaire) {
  867. $produits = json_decode($produits);
  868. $point_vente = PointVente::findOne($id_pv);
  869. $production = Production::findOne([
  870. 'date' => $date,
  871. 'id_etablissement' => Yii::$app->user->identity->id_etablissement
  872. ]);
  873. if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date) &&
  874. ($id_user || strlen($username)) &&
  875. $point_vente &&
  876. count($produits) &&
  877. $production) {
  878. $commande = new Commande;
  879. $commande->date = date('Y-m-d H:i:s', strtotime($date . ' ' . date('H:i:s')));
  880. $commande->id_point_vente = $id_pv;
  881. $commande->id_production = $production->id;
  882. $commande->type = Commande::TYPE_ADMIN;
  883. $commande->commentaire = $commentaire;
  884. if ($id_user) {
  885. $commande->id_user = $id_user;
  886. // commentaire du point de vente
  887. $point_vente_user = PointVenteUser::find()
  888. ->where(['id_point_vente' => $id_pv, 'id_user' => $id_user])
  889. ->one();
  890. if ($point_vente_user && strlen($point_vente_user->commentaire)) {
  891. $commande->commentaire_point_vente = $point_vente_user->commentaire;
  892. }
  893. } else {
  894. $commande->username = $username;
  895. $commande->id_user = 0;
  896. }
  897. $commande->save();
  898. foreach ($produits as $key => $quantite) {
  899. $produit = Produit::findOne($key);
  900. if ($produit) {
  901. $commande_produit = new CommandeProduit;
  902. $commande_produit->id_commande = $commande->id;
  903. $commande_produit->id_produit = $key;
  904. $commande_produit->quantite = $quantite;
  905. $commande_produit->prix = $produit->prix;
  906. $commande_produit->save();
  907. }
  908. }
  909. // total point de vente
  910. $point_vente = PointVente::findOne($commande->id_point_vente);
  911. $commandes = Commande::find()
  912. ->with('commandeProduits', 'user')
  913. ->joinWith('production')
  914. ->where(['production.date' => $date])
  915. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  916. ->orderBy('date ASC')
  917. ->all();
  918. foreach ($commandes as $c)
  919. $c->init();
  920. $point_vente->initCommandes($commandes);
  921. // json commande
  922. $commande = Commande::find()
  923. ->with('commandeProduits', 'user')
  924. ->where(['commande.id' => $commande->id])
  925. ->one();
  926. $commande->init();
  927. $produits = [];
  928. foreach ($commande->commandeProduits as $cp) {
  929. $produits[$cp->id_produit] = $cp->quantite;
  930. }
  931. $json_commande = json_encode(['montant' => number_format($commande->montant, 2), 'produits' => $produits]);
  932. $json_commande = $commande->getDataJson();
  933. $str_user = '';
  934. if ($commande->user)
  935. $str_user = $commande->user->nom . ' ' . $commande->user->prenom;
  936. else
  937. $str_user = $commande->username;
  938. $str_commentaire = '';
  939. if (strlen($commande->commentaire)) {
  940. $str_commentaire = ' <span class="glyphicon glyphicon-comment"></span>';
  941. }
  942. $str_label_type_commande = '';
  943. if ($commande->type) {
  944. $str_label_type_commande = ' <span class="label label-warning">vous</span>';
  945. }
  946. echo json_encode([
  947. 'id_commande' => $commande->id,
  948. 'total_pv' => number_format($point_vente->recettes, 2) . ' €',
  949. 'commande' => '<li>'
  950. . '<a class="btn btn-default" href="javascript:void(0);" '
  951. . 'data-pv-id="' . $id_pv . '" '
  952. . 'data-id-commande="' . $commande->id . '" '
  953. . 'data-commande=\'' . $json_commande . '\' '
  954. . 'data-date="' . date('d/m H:i', strtotime($commande->date)) . '">'
  955. . '<span class="montant">' . number_format($commande->montant, 2) . ' €</span>'
  956. . '<span class="user">' . $str_label_type_commande . ' ' . $str_user . '</span>'
  957. . $str_commentaire
  958. . '</a></li>',
  959. ]);
  960. die();
  961. }
  962. }
  963. public function actionAjaxTotalCommandes($date) {
  964. $production = Production::find()
  965. ->where(['date' => $date])
  966. ->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  967. ->one();
  968. if ($production) {
  969. // produits
  970. $produits = Produit::find()
  971. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  972. ->orderBy('order ASC')
  973. ->all();
  974. // commandes
  975. $commandes = Commande::find()
  976. ->with('commandeProduits','commandeProduits.produit', 'user')
  977. ->joinWith('production')
  978. ->where(['production.date' => $date])
  979. ->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  980. ->orderBy('date ASC')
  981. ->all();
  982. $recettes = 0;
  983. $poids_pain = 0;
  984. foreach ($commandes as $c) {
  985. $c->init();
  986. if(is_null($c->date_delete)) {
  987. $recettes += $c->montant;
  988. $poids_pain += $c->poids_pain;
  989. }
  990. }
  991. // produits selec pour production
  992. $produits_selec = ProductionProduit::findProduits($production->id);
  993. $ca_potentiel = 0;
  994. $poids_total = 0;
  995. foreach ($produits_selec as $id_produit_selec => $produit_selec) {
  996. if ($produit_selec['actif']) {
  997. foreach ($produits as $produit) {
  998. if ($produit->id == $id_produit_selec) {
  999. $ca_potentiel += $produit_selec['quantite_max'] * $produit->prix;
  1000. $poids_total += $produit_selec['quantite_max'] * $produit->poids / 1000;
  1001. }
  1002. }
  1003. }
  1004. }
  1005. $html_totaux = $this->renderPartial('_total_commandes.php', [
  1006. 'produits' => $produits,
  1007. 'commandes' => $commandes,
  1008. 'produits_selec' => $produits_selec,
  1009. 'recettes_pain' => $recettes,
  1010. 'poids_total' => $poids_total,
  1011. 'ca_potentiel' => $ca_potentiel,
  1012. 'poids_pain' => $poids_pain,
  1013. ]);
  1014. echo json_encode([
  1015. 'html_totaux' => $html_totaux,
  1016. ]);
  1017. }
  1018. die();
  1019. }
  1020. public function actionAjaxPointVenteLivraison($id_production, $id_point_vente, $bool_livraison) {
  1021. $production_point_vente = ProductionPointVente::find()
  1022. ->where([
  1023. 'id_production' => $id_production,
  1024. 'id_point_vente' => $id_point_vente,
  1025. ])
  1026. ->one();
  1027. if ($production_point_vente) {
  1028. $production_point_vente->livraison = $bool_livraison;
  1029. $production_point_vente->save();
  1030. }
  1031. die();
  1032. }
  1033. public function actionStatutPaiement($id_commande) {
  1034. $commande = Commande::find()
  1035. ->with('commandeProduits', 'production')
  1036. ->where(['id' => $id_commande])
  1037. ->one();
  1038. if ($commande) {
  1039. $commande->init();
  1040. $html = '';
  1041. if ($commande->id_user) {
  1042. $user_etablissement = UserEtablissement::find()
  1043. ->where([
  1044. 'id_user' => $commande->id_user,
  1045. 'id_etablissement' => $commande->production->id_etablissement
  1046. ])
  1047. ->one();
  1048. $montant_paye = $commande->getMontantPaye();
  1049. //$html .= $commande->montant.' | '.$montant_paye ;
  1050. if (abs($commande->montant - $montant_paye) < 0.0001) {
  1051. $html .= '<span class="label label-success">Payé</span>';
  1052. $buttons_credit = Html::a('Rembourser ' . $commande->getMontant(true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $commande->montant, 'data-type' => 'remboursement']);
  1053. } elseif ($commande->montant > $montant_paye) {
  1054. $montant_payer = $commande->montant - $montant_paye;
  1055. $html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($montant_payer, 2) . ' €</strong> à payer';
  1056. $buttons_credit = Html::a('Payer ' . number_format($montant_payer, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs payer', 'data-montant' => $montant_payer, 'data-type' => 'paiement']);
  1057. } elseif ($commande->montant < $montant_paye) {
  1058. $montant_rembourser = $montant_paye - $commande->montant;
  1059. $html .= ' <span class="label label-success">Payé</span> <strong>' . number_format($montant_rembourser, 2) . ' €</strong> à rembourser';
  1060. $buttons_credit = Html::a('Rembourser ' . number_format($montant_rembourser, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $montant_rembourser, 'data-type' => 'remboursement']);
  1061. }
  1062. $html .= '<span class="buttons-credit">'
  1063. . 'Crédit pain : <strong>' . number_format($user_etablissement->credit, 2) . ' €</strong><br />'
  1064. . $buttons_credit
  1065. . '</span>';
  1066. // historique
  1067. $historique = CreditHistorique::find()
  1068. ->with('userAction')
  1069. ->where(['id_commande' => $id_commande])
  1070. ->all();
  1071. $html .= '<br /><br /><strong>Historique</strong><br /><table class="table table-condensed table-bordered">'
  1072. . '<thead><tr><th>Date</th><th>Utilisateur</th><th>Action</th><th>- Débit</th><th>+ Crédit</th></tr></thead>'
  1073. . '<tbody>';
  1074. if ($historique && is_array($historique) && count($historique)) {
  1075. foreach ($historique as $h) {
  1076. $html .= '<tr>'
  1077. . '<td>' . date('d/m/Y H:i:s', strtotime($h->date)) . '</td>'
  1078. . '<td>' . Html::encode($h->strUserAction()) . '</td>'
  1079. . '<td>' . $h->getStrLibelle() . '</td>'
  1080. . '<td>' . ($h->isTypeDebit() ? '- '.$h->getMontant(true) : '') . '</td>'
  1081. . '<td>' . ($h->isTypeCredit() ? '+ '.$h->getMontant(true) : '') . '</td>'
  1082. . '</tr>';
  1083. }
  1084. } else {
  1085. $html .= '<tr><td colspan="4">Aucun résultat</td></tr>';
  1086. }
  1087. $html .= '</tbody></table>';
  1088. } else {
  1089. $html .= '<div class="alert alert-warning">Pas de gestion de crédit pain pour cette commande car elle n\'est pas liée à un compte utilisateur.</div>';
  1090. }
  1091. echo json_encode([
  1092. 'html_statut_paiement' => $html,
  1093. 'json_commande' => $commande->getDataJson()
  1094. ]);
  1095. }
  1096. die();
  1097. }
  1098. public function actionPaiement($id_commande, $type, $montant) {
  1099. $commande = Commande::find()
  1100. ->with('commandeProduits', 'production')
  1101. ->where(['id' => $id_commande])
  1102. ->one();
  1103. $commande->init() ;
  1104. if ($commande) {
  1105. $commande->creditHistorique(
  1106. $type,
  1107. $montant,
  1108. Yii::$app->user->identity->id_etablissement,
  1109. $commande->id_user,
  1110. Yii::$app->user->identity->id
  1111. );
  1112. }
  1113. return $this->actionStatutPaiement($id_commande);
  1114. }
  1115. }