function get_history($id) { $truck = new Truck(); $license = $truck->find()->where(['id' => $id])->one(); $licenses_plate = $license['license_plate']; $sql = "SELECT o.assign_id,o.order_date_start,o.order_date_end,o.car_id,o.employer,o.driver1,o.driver2,SUM(o.income) AS income\n FROM assign o INNER JOIN map_truck m ON o.car_id = m.car_id\n WHERE (m.truck_1 = '{$licenses_plate}' OR m.truck_2 = '{$licenses_plate}')\n\t\tGROUP BY o.assign_id\n ORDER BY o.id DESC "; $result = \Yii::$app->db->createCommand($sql)->queryAll(); return $result; }
public function allListTruck() { $list_trucks = Truck::getInstance()->getAlls(); if (count($list_trucks) > 0) { foreach ($list_trucks as &$truck) { $id = $truck->id; $sql_product = 'SELECT * FROM order_custome WHERE key_r_order = ' . $id . ' ORDER BY price_order DESC LIMIT 6'; $order_products = app('db')->select($sql_product); $truck->order_price = $order_products; } } return view('truck', array('list_trucks' => $list_trucks)); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Truck::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'date_buy' => $this->date_buy, 'price' => $this->price, 'down' => $this->down, 'period_price' => $this->period_price, 'period' => $this->period, 'date_supply' => $this->date_supply, 'type_id' => $this->type_id]); $query->andFilterWhere(['like', 'license_plate', $this->license_plate])->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'color', $this->color]); $query->andWhere(['delete_flag' => '0']); return $dataProvider; }
/* @var $model app\models\MapTruck */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="map-truck-form"> <?php $form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL, 'formConfig' => ['labelSpan' => 2, 'deviceSize' => ActiveForm::SIZE_SMALL]]); ?> <?php echo $form->field($model, 'truck_1')->dropDownList(ArrayHelper::map(\app\models\Truck::find()->where(['type_id' => '1'])->all(), 'license_plate', 'license_plate'), ['id' => 'id', 'required' => 'required', 'prompt' => 'เลือกหัวลาก']); ?> <?php echo $form->field($model, 'truck_2')->dropDownList(ArrayHelper::map(\app\models\Truck::find()->where(['type_id' => '2'])->all(), 'license_plate', 'license_plate'), ['id' => 'id', 'required' => 'required', 'prompt' => 'เลือกพ่วง']); ?> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <?php echo Html::submitButton($model->isNewRecord ? '<i class="fa fa-save"></i> บันทึกข้อมูล' : '<i class="fa fa-pencil"></i> แก้ไข', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> <?php echo Html::resetButton('<i class="fa fa-remove"></i> ยกเลิก', ['class' => 'btn btn-danger']); ?> </div> </div> <?php ActiveForm::end();
?> <?php echo $form->field($model, 'order_date_start')->widget(\kartik\widgets\DatePicker::classname(), ['language' => 'th', 'removeButton' => false, 'options' => ['value' => date("Y-m-d"), 'readonly' => true], 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd', 'todayHighlight' => true]]); ?> <?php echo $form->field($model, 'order_date_end')->widget(\kartik\widgets\DatePicker::classname(), ['language' => 'th', 'removeButton' => false, 'options' => ['value' => date("Y-m-d"), 'readonly' => true], 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd', 'todayHighlight' => true]]); ?> <?php echo $form->field($model, 'truck1')->dropDownList(ArrayHelper::map(\app\models\Truck::find()->where(['delete_flag' => '0'])->all(), 'id', 'license_plate'), ['id' => 'id', 'required' => 'required', 'prompt' => 'เลือกรถบรรทุก']); ?> <?php echo $form->field($model, 'truck2')->dropDownList(ArrayHelper::map(\app\models\Truck::find()->where(['delete_flag' => '0'])->all(), 'id', 'license_plate'), ['id' => 'id', 'prompt' => 'เลือกรถถบรรทุก']); ?> <?php $sql1 = "select id,concat(name,' ',lname) as name from driver where delete_flag = '0'"; echo $form->field($model, 'driver1')->dropDownList(ArrayHelper::map(\app\models\Driver::findBySql($sql1)->all(), 'id', 'name'), ['id' => 'id', 'required' => 'required', 'prompt' => 'เลือกคนขับ']); ?> <?php echo $form->field($model, 'driver2')->dropDownList(ArrayHelper::map(\app\models\Driver::findBySql($sql1)->all(), 'id', 'name'), ['id' => 'id', 'prompt' => 'เลือกคนขับ']); ?> <div class="form-group"> <div class="col-sm-_3 col-md-3 col-lg-3"></div> <div class="col-sm-9 col-md-9 col-lg-9"> <?php
public function actionGet_detail_truck() { $license_plate = Yii::$app->request->post('license_plate'); $truck = new Truck(); $t = $truck->find()->where(['license_plate' => $license_plate])->one(); $id = $t['id']; return $this->renderPartial('detail', ['model' => $this->findModel($id)]); }