[ 'class' => VerbFilter::class, 'actions' => [ ], ], 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserManager()->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) { $quotationManager = $this->getQuotationManager(); $invoiceManager = $this->getInvoiceManager(); $quotation = $this->findModel($id); if ($quotationManager->isStatusValid($quotation)) { $invoice = $invoiceManager->instanciateInvoice(); $invoiceManager->initTaxCalculationMethod($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); $invoiceManager->saveCreate($invoice); Order::updateAll([ 'order.id_invoice' => $invoice->id ], [ 'order.id_quotation' => $id ]); $this->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é.'); } } }