|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?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é.');
- }
- }
-
- }
|