/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PriceCategoryModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'formula', $this->formula]); return $dataProvider; }
/** * Creates a new Price model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreateByPo($id) { if (($purchase = Purchase::findOne($id)) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } $products = []; foreach ($purchase->getPurchaseDtls()->with('product.category')->all() as $detail) { $product = new ProductPrice(['id' => $detail->product_id, 'name' => $detail->product->name, 'category' => $detail->product->category->name, 'price' => $detail->price]); $products[$detail->product_id] = $product; } if (ProductPrice::loadMultiple($products, Yii::$app->request->post()) && ProductPrice::validateMultiple($products)) { $transaction = Yii::$app->db->beginTransaction(); try { $success = true; foreach ($products as $product) { if (!$product->save(false)) { $success = false; break; } } if ($success) { $transaction->commit(); return $this->redirect(['list-po']); } else { $transaction->rollBack(); } } catch (\Exception $exc) { $transaction->rollBack(); throw $exc; } } return $this->render('create_by_po', ['purchase' => $purchase, 'products' => $products, 'categories' => PriceCategory::find()->all()]); }
/** * Finds the PriceCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PriceCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PriceCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getMasters($masters) { $masters = array_flip($masters); $result = []; // master product if (isset($masters['products'])) { $query_product = Product::find()->select(['id', 'cd' => 'code', 'text' => 'name', 'label' => 'name'])->andWhere(['status' => Product::STATUS_ACTIVE])->indexBy('id')->asArray(); $products = $query_product->all(); $query_uom = ProductUom::find()->select(['pu.product_id', 'pu.uom_id', 'pu.isi', 'uom_nm' => 'u.name'])->from(ProductUom::tableName() . ' pu')->joinWith(['uom' => function ($q) { $q->from(Uom::tableName() . ' u'); }])->orderBy(['pu.product_id' => SORT_ASC, 'pu.isi' => SORT_ASC])->asArray(); foreach ($query_uom->all() as $row) { $products[$row['product_id']]['uoms'][] = ['id' => $row['uom_id'], 'nm' => $row['uom_nm'], 'isi' => $row['isi']]; } $result['products'] = $products; } // barcodes if (isset($masters['barcodes'])) { $barcodes = []; $query_barcode = ProductChild::find()->select(['barcode' => 'lower(barcode)', 'id' => 'product_id'])->union(Product::find()->select(['lower(code)', 'id']))->asArray(); foreach ($query_barcode->all() as $row) { $barcodes[$row['barcode']] = $row['id']; } $result['barcodes'] = $barcodes; } // price_category if (isset($masters['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 if (isset($masters['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 if (isset($masters['customers'])) { $result['customers'] = Customer::find()->select(['id', 'label' => 'name'])->asArray()->all(); } // supplier if (isset($masters['suppliers'])) { $result['suppliers'] = Supplier::find()->select(['id', 'label' => 'name'])->asArray()->all(); } // product_supplier if (isset($masters['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 if (isset($masters['product_stock'])) { $prod_stock = []; $query_prod_stock = ProductStock::find()->select(['warehouse_id', 'product_id'])->asArray(); foreach ($query_prod_stock->all() as $row) { $prod_stock[$row['warehouse_id']][$row['product_id']] = $row['qty']; } $result['product_stock'] = $prod_stock; } // supplier if (isset($masters['coa'])) { $result['coa'] = Coa::find()->select(['id', 'cd' => 'code', 'text' => 'name', 'label' => 'name'])->asArray()->all(); } return $result; }
use yii\web\View; /* @var $this yii\web\View */ /* @var $model app\models\master\Price */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="box box-warning price-category-form"> <?php $form = ActiveForm::begin(); ?> <div class="box-body"> <?php echo $form->field($model, 'nmProduct')->widget('yii\\jui\\AutoComplete', ['clientOptions' => ['source' => new JsExpression('biz.master.sourceProduct'), 'search' => new JsExpression('biz.price.onProductSearch'), 'select' => new JsExpression('biz.price.onProductSelect')], 'options' => ['class' => 'form-control']]); ?> <?php echo $form->field($model, 'price_category_id')->dropDownList(\app\models\master\PriceCategory::selectOptions(), ['style' => 'width:200px;']); ?> <?php echo $form->field($model, 'price')->input('number', ['style' => 'width:150px;']); ?> </div> <div class="box-footer"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>