Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Time::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['time_id' => SORT_ASC], 'enableMultiSort' => true]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['time_id' => $this->time_id]);
     $query->andFilterWhere(['like', 'time_text', $this->time_text])->andFilterWhere(['like', 'time_img', $this->time_img])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 private function generator($scenario)
 {
     $model = new Main();
     if (!empty(Yii::$app->request->post())) {
         $main_id = Yii::$app->request->post()['Main']['main_id'];
         if (empty($main_id)) {
             // New record
             $model->load(Yii::$app->request->post());
             // Load time_array manually, since it's not part of Main Table
             $model->time_array = Yii::$app->request->post()['Main']['time_array'];
             // Add Owner
             $model->user_id = Yii::$app->user->identity->id;
             $model->created = date('Y-m-d H:i:s');
             $model->updated = date('Y-m-d H:i:s');
         } else {
             // Update exist record
             $model = $this->findModel($main_id);
             $model->load(Yii::$app->request->post());
             // Load time_array manually, since it's not part of Main Table
             $model->time_array = Yii::$app->request->post()['Main']['time_array'];
             // Update Timestamp
             $model->updated = date('Y-m-d H:i:s');
         }
         if (!empty($model->time_array)) {
             // Convert array to bit
             $model->time_bit = $model->encodeBit($model->time_array);
         }
         // Force null
         $model->drug_name = empty($model->drug_name) ? null : $model->drug_name;
     }
     if (isset(Yii::$app->request->post()['save']) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('main_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->profile_name . '</strong> ' . Yii::t('backend', 'has been saved.')]);
         }
         $model = new Main();
     } elseif (isset(Yii::$app->request->post()['generate'])) {
         $model->scenario = $scenario;
         if ($model->validate()) {
             if ($model->scenario == 'generate-original') {
                 // Load patient_name manually, since it's not part of Main Table
                 $model->patient_name = Yii::$app->request->post()['Main']['patient_name'];
             }
             /* Get amount_img */
             $amount_data = \backend\models\Amount::find()->select(['amount_img'])->andWhere('amount_id = :amount_id', [':amount_id' => $model->amount_id])->one();
             $model->amount_id = $amount_data->amount_img;
             /* Get time_img */
             $time_data = \backend\models\Time::find()->select(['time_id', 'time_img'])->orderBy('time_id')->asArray()->all();
             foreach ($time_data as $time_all_key => $time_all_value) {
                 foreach ($model->time_array as $time_select_key => $time_select_value) {
                     if ($time_all_value['time_id'] == $time_select_value) {
                         $time_img[] = $time_all_value['time_img'];
                     }
                 }
             }
             $model->time_array = $time_img;
             /* Get meal_img */
             $meal_data = \backend\models\Meal::find()->select(['meal_img'])->andWhere('meal_id = :meal_id', [':meal_id' => $model->meal_id])->one();
             $model->meal_id = $meal_data->meal_img;
             /* Build PDF */
             $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'format' => [48, 80], 'orientation' => Pdf::ORIENT_LANDSCAPE, 'marginLeft' => 2, 'marginRight' => 2, 'marginTop' => 10, 'marginBottom' => 0, 'cssInline' => '
                     body{font-family:garuda; color: #000;}
                     hr{margin-top: 4px; margin-bottom: 4px; color: #000;}
                     .text-ctl{font-size: 10px;}
                     .table-ctl{text-align: center; width:80px;}
                     .table-vr{border-left: solid #000;}
                 ', 'content' => $this->renderPartial('_label', ['model' => $model]), 'filename' => 'label_' . date('YmdHi') . '.pdf', 'destination' => Pdf::DEST_BROWSER]);
             return $pdf->render();
         }
     }
     return $this->render('generator', ['model' => $model, 'scenario' => $scenario]);
 }
Ejemplo n.º 3
0
 public static function getTimeID()
 {
     // $time_id_array = [1, 2, 4, 8]
     $time_data = \backend\models\Time::find()->orderBy('time_id')->asArray()->all();
     if (!empty($time_data)) {
         foreach ($time_data as $key => $value) {
             $time_id_array[] = $value['time_id'];
         }
         return $time_id_array;
     } else {
         return null;
     }
 }