示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Productmain::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]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Finds the Productmain model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Productmain the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Productmain::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
 public function getProductmain()
 {
     return @$this->hasOne(Productmain::className(), ['id' => 'productmain_id']);
 }
示例#4
0
use app\models\Category;
use app\models\Productmain;
use app\models\Unit;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ProductsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Products';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="products-index">

    <h1><?php 
Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('เพิ่มรายการใหม่', ['create'], ['class' => 'btn btn-success fa fa-plus']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'panel' => ['before' => ' '], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => 'หมวดหมู่หลัก', 'format' => 'raw', 'value' => 'productmainname', 'filter' => Html::activeDropDownList($searchModel, 'productmain_id', ArrayHelper::map(Productmain::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Select Category'])], ['label' => 'หมวดหมู่รอง', 'format' => 'raw', 'value' => 'Categoryname', 'filter' => Html::activeDropDownList($searchModel, 'category_id', ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Select Category'])], 'sub_qty', ['label' => 'ชื่อหน่วยนับ', 'format' => 'raw', 'value' => 'unitname', 'filter' => Html::activeDropDownList($searchModel, 'productmain_id', ArrayHelper::map(Unit::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Select Category'])], ['label' => 'จำนวนคงเหลือ', 'format' => 'raw', 'value' => 'unitname', 'filter' => \app\models\Inventorydetail::find()->where(['product_id' => $dataProvider->id])->sum('qty')], 'name', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#5
0
use app\models\Category;
use app\models\Unit;
use app\models\Productmain;
/* @var $this yii\web\View */
/* @var $model app\models\Products */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="products-form">
    <?php 
$form = ActiveForm::begin();
?>
    <div class="row">
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'productmain_id')->dropdownList(ArrayHelper::map(Productmain::find()->all(), 'id', 'name'), ['id' => 'ddl-province', 'prompt' => 'เลือกหมวดหมู่', 'required' => '']);
?>

        </div>
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'category_id')->dropdownList(ArrayHelper::map(Category::find()->all(), 'id', 'name'), ['id' => 'ddl-province', 'prompt' => 'เลือกหมวดหมู่', 'required' => '']);
?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        </div>