[ 'class' => VerbFilter::className(), 'actions' => [ ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend(); } ] ], ], ]; } /** * Liste les modèles Invoice. * * @return mixed */ 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->initTaxCalculationMethod(); $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 '.Html::encode($quotation->name).' 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é.'); } } }