/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CustomerModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->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])->andFilterWhere(['like', 'contact_name', $this->contact_name])->andFilterWhere(['like', 'contact_number', $this->contact_number]); return $dataProvider; }
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; }
public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'customer_id']); }