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.

EtablissementAdminController.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use yii\web\NotFoundHttpException;
  6. use yii\filters\VerbFilter;
  7. use yii\filters\AccessControl;
  8. use common\helpers\Upload ;
  9. use common\models\Etablissement ;
  10. use yii\data\ActiveDataProvider ;
  11. use common\models\Facture ;
  12. /**
  13. * UserController implements the CRUD actions for User model.
  14. */
  15. class EtablissementAdminController extends BackendController
  16. {
  17. public function behaviors()
  18. {
  19. return [
  20. 'verbs' => [
  21. 'class' => VerbFilter::className(),
  22. 'actions' => [
  23. 'delete' => ['post'],
  24. ],
  25. ],
  26. 'access' => [
  27. 'class' => AccessControl::className(),
  28. 'rules' => [
  29. [
  30. 'allow' => true,
  31. 'roles' => ['@'],
  32. 'matchCallback' => function ($rule, $action) {
  33. return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
  34. }
  35. ]
  36. ],
  37. ],
  38. ];
  39. }
  40. public function actionIndex()
  41. {
  42. $datas_etablissements = new ActiveDataProvider([
  43. 'query' => Etablissement::find()
  44. ->with('userEtablissement','user')
  45. ->orderBy('date_creation DESC'),
  46. 'pagination' => [
  47. 'pageSize' => 1000,
  48. ],
  49. ]);
  50. return $this->render('index', [
  51. 'datas_etablissements' => $datas_etablissements,
  52. ]);
  53. }
  54. public function actionFacturer($id_etablissement)
  55. {
  56. $etablissement = Etablissement::findOne($id_etablissement) ;
  57. if($etablissement)
  58. {
  59. $periode = date('Y-m', strtotime('-1 month')) ;
  60. $last_facture = Facture::getLastFacture() ;
  61. if(!$last_facture)
  62. {
  63. $reference = 'BAP000001' ;
  64. }
  65. else {
  66. $reference = str_replace('BAP','',$last_facture->reference) ;
  67. $reference ++ ;
  68. $reference = 'BAP'.$reference ;
  69. }
  70. $facture = new Facture ;
  71. $facture->id_etablissement = $id_etablissement ;
  72. $facture->date = date('Y-m-d H:i:s') ;
  73. $facture->reference = $reference ;
  74. $facture->ca = $etablissement->getCA($periode) ;
  75. $facture->montant_ht = $etablissement->getMontantFacturer($periode) ;
  76. $facture->libelle = 'Facture '.date('m/Y', strtotime('-1 month')) ;
  77. $facture->texte = 'Utilisation de la plateforme <strong>La boîte à pain</strong> pour le mois : '.date('m/Y', strtotime('-1 month')).'<br />'
  78. . 'Chiffre d\'affaire réalisé sur la plateforme : <strong>'.number_format($facture->ca,2).' €</strong> commissionné à <strong>1%</strong>.' ;
  79. $facture->paye = 0 ;
  80. $facture->periode = $periode ;
  81. $facture->save() ;
  82. }
  83. $this->redirect(['etablissement-admin/index']) ;
  84. }
  85. public function actionFacturation()
  86. {
  87. $datas_factures = new ActiveDataProvider([
  88. 'query' => Facture::find()
  89. ->with('etablissement')
  90. ->orderBy('reference DESC'),
  91. 'pagination' => [
  92. 'pageSize' => 1000,
  93. ],
  94. ]);
  95. return $this->render('facturation', [
  96. 'datas_factures' => $datas_factures,
  97. ]);
  98. }
  99. protected function findModel($id)
  100. {
  101. if (($model = Etablissement::findOne($id)) !== null) {
  102. return $model;
  103. } else {
  104. throw new NotFoundHttpException('The requested page does not exist.');
  105. }
  106. }
  107. }