Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'group_id' => $this->group_id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductModel::find()->select(['p.*', 'pc.*'])->from(ProductModel::tableName() . ' p')->joinWith(['prices' => function ($q) {
         $q->from(Price::tableName() . ' pc');
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['p.id' => $this->id, 'p.group_id' => $this->group_id, 'p.category_id' => $this->category_id, 'p.status' => $this->status, 'pc.price_category_id' => $this->price_category_id]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #3
0
 public function getMasters()
 {
     $result = [];
     // master product
     $query_product = Product::find()->select(['id', 'code', 'name'])->andWhere(['status' => Product::STATUS_ACTIVE])->indexBy('id')->asArray();
     $result['products'] = $query_product->all();
     // uoms
     $_uoms = Uom::find()->indexBy('id')->asArray()->all();
     $uoms = [];
     foreach (ProductUom::find()->asArray()->all() as $row) {
         $uoms[$row['product_id']][] = ['id' => $row['uom_id'], 'name' => $_uoms[$row['uom_id']]['name'], 'isi' => $row['isi']];
     }
     $result['product_uoms'] = $uoms;
     // barcodes
     $barcodes = [];
     $query_barcode = ProductChild::find()->select(['barcode', 'product_id'])->asArray();
     foreach ($query_barcode->all() as $row) {
         $barcodes[strtoupper($row['barcode'])] = $row['product_id'];
     }
     $query_barcode = Product::find()->select(['code', 'id'])->asArray();
     foreach ($query_barcode->all() as $row) {
         $barcodes[strtoupper($row['code'])] = $row['id'];
     }
     $result['barcodes'] = $barcodes;
     // category
     $result['categories'] = Category::find()->select(['id', 'name'])->asArray()->all();
     // product_group
     $result['product_groups'] = ProductGroup::find()->select(['id', 'name'])->asArray()->all();
     // price_category
     $price_category = [];
     $query_price_category = PriceCategory::find()->asArray();
     foreach ($query_price_category->all() as $row) {
         $price_category[$row['id']] = $row['name'];
     }
     $result['price_category'] = $price_category;
     // prices
     $prices = [];
     $query_prices = Price::find()->asArray();
     foreach ($query_prices->all() as $row) {
         $prices[$row['product_id']][$row['price_category_id']] = $row['price'];
     }
     $result['prices'] = $prices;
     // customer
     $result['customers'] = Customer::find()->select(['id', 'name'])->asArray()->all();
     // supplier
     $result['suppliers'] = Supplier::find()->select(['id', 'name'])->asArray()->all();
     // product_supplier
     $prod_supp = [];
     $query_prod_supp = ProductSupplier::find()->select(['supplier_id', 'product_id'])->asArray();
     foreach ($query_prod_supp->all() as $row) {
         $prod_supp[$row['supplier_id']][] = $row['product_id'];
     }
     $result['product_supplier'] = $prod_supp;
     // product_stock
     $prod_stock = [];
     $query_prod_stock = ProductStock::find()->select(['warehouse_id', 'product_id', 'qty'])->asArray();
     foreach ($query_prod_stock->all() as $row) {
         $prod_stock[$row['warehouse_id']][$row['product_id']] = $row['qty'];
     }
     $result['product_stock'] = $prod_stock;
     // branch
     $result['branchs'] = Branch::find()->asArray()->all();
     // warehouse
     $warehouses = Warehouse::find()->asArray()->all();
     $result['warehouses'] = [];
     foreach ($warehouses as $warehouse) {
         $result['warehouses'][$warehouse['branch_id']][] = $warehouse;
     }
     //apicode
     $result['mvconfig'] = Yii::$app->bizConfig->movement;
     // coa
     $result['coa'] = Coa::find()->select(['id', 'cd' => 'code', 'text' => 'name', 'label' => 'name'])->asArray()->all();
     return $result;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%price}}', ['price_category_id' => 'id']);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%product_stock}}', ['warehouse_id' => 'id']);
 }
Example #6
0
 public function getProduct()
 {
     return $this->hasOne(Product::className(), ['id' => 'product_id']);
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%product_uom}}', ['uom_id' => 'id']);
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['group_id' => 'id']);
 }