Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

115 linhas
3.7KB

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