public function actionIndex()
 {
     $post = Yii::$app->request->post();
     if ($post && array_key_exists('bills', $post)) {
         Bill::updateAll(['enabled' => false]);
         $updatedBills = $post['bills'];
         foreach ($updatedBills as $billType => $status) {
             /** @var Bill $bill */
             $bill = Bill::findOne(['bill_type' => $billType]);
             $bill->enabled = $status === 'on';
             $bill->save();
         }
         Yii::$app->session->setFlash('bills_updated');
     }
     $bills = Bill::find()->all();
     return $this->render('index', ['bills' => $bills]);
 }
Esempio n. 2
0
 /**
  * Finds the Bill model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Bill the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Bill::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionPrint($id)
 {
     if (($bill = Bill::findOne($id)) !== null) {
         $content = $this->renderPartial('print', ['bill' => $bill]);
         $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssInline' => '.kv-heading-1{font-size:18px}', 'options' => ['title' => Yii::t('app', 'Bill') . ' ' . Yii::t('app', 'Report')], 'methods' => ['SetHeader' => [Yii::t('app', 'Summary')], 'SetFooter' => ['{PAGENO}']]]);
         return $pdf->render();
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }