|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\helpers\GlobalParam;
- use Yii;
- use yii\base\UserException;
-
-
- class QuotationController extends DocumentController
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::hasAccessBackend();
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $searchModel = new QuotationSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- public function actionTransform($id)
- {
- $quotation = $this->findModel($id) ;
- if($quotation->isStatusValid()) {
-
- $invoice = new Invoice ;
- $invoice->id_producer = GlobalParam::getCurrentProducerId();
- $invoice->id_user = $quotation->id_user ;
- $invoice->address = $quotation->address ;
- $invoice->comment = $quotation->comment ;
- $invoice->name = str_replace(['Devis', 'devis'], 'Facture', $quotation->name);
- $invoice->save() ;
-
- Order::updateAll([
- 'order.id_invoice' => $invoice->id
- ], [
- 'order.id_quotation' => $id
- ]) ;
-
- Yii::$app->getSession()->setFlash('success', 'Le devis <strong>'.Html::encode($quotation->name).'</strong> a bien été transformé en facture.');
- return $this->redirect(['/' . $this->getControllerUrl() . '/index']);
- }
- else {
- throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.');
- }
- }
-
- }
|