From e9f9567618dbddbe074fb1104a7775cd0e22f187 Mon Sep 17 00:00:00 2001 From: rocho Date: Thu, 1 Oct 2015 17:31:48 +0200 Subject: [PATCH] add changes sell product --- common/models/Product.php | 41 ++++++ frontend/assets/ProductSellAsset.php | 28 ++++ frontend/controllers/ProductController.php | 18 +++ frontend/views/product/_sale_form.php | 85 +++++++++++ frontend/views/product/_sold_items.php | 64 ++++++++ frontend/views/product/sale.php | 164 +++------------------ frontend/web/js/product.sell.js | 67 +++++++++ 7 files changed, 323 insertions(+), 144 deletions(-) create mode 100644 frontend/assets/ProductSellAsset.php create mode 100644 frontend/views/product/_sale_form.php create mode 100644 frontend/views/product/_sold_items.php create mode 100644 frontend/web/js/product.sell.js diff --git a/common/models/Product.php b/common/models/Product.php index 0b1bbd5..d9e28b8 100644 --- a/common/models/Product.php +++ b/common/models/Product.php @@ -3,6 +3,7 @@ namespace common\models; use Yii; +use yii\helpers\ArrayHelper; /** * This is the model class for table "product". @@ -125,4 +126,44 @@ class Product extends \common\models\BaseFitnessActiveRecord { return $warehouses; } + public static function findProduct($query){ + $result = []; + $product = null; + + $products = Product::find() + ->andWhere( + ['or', + ['product_number' => $query ], + ['barcode' => $query ], + ] + )->andWhere(['status' =>Product::STATUS_ACTIVE]) + ->all(); + + + if ( count($products) == 1 ){ + $product = $products[0]; + } + return $product; + } + + public static function modelToArray($product,$default = null){ + + if ( $product == null ){ + return $default; + } + + return ArrayHelper::toArray($product, [ + 'common\models\Product' => [ + 'name', + 'product_number', + 'barcode', + 'sale_price', + 'stock', + 'category' => function ($product) { + return $product->productCategoryName; + }, + ], + ]); + } + } diff --git a/frontend/assets/ProductSellAsset.php b/frontend/assets/ProductSellAsset.php new file mode 100644 index 0000000..74fb237 --- /dev/null +++ b/frontend/assets/ProductSellAsset.php @@ -0,0 +1,28 @@ + + * @since 2.0 + */ +class ProductSellAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/product.sell.js', + ]; + public $depends = [ + 'frontend\assets\AppAsset', + ]; +} diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index 9c0fb34..5f431f6 100644 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -125,6 +125,24 @@ class ProductController extends Controller return $this->redirect(['index']); } + /** + */ + public function actionLookup($query = null) + { + $result = []; + $product = Product::findProduct($query); + $product = Product::modelToArray($product); + + $result['product'] = $product; + + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + + + return $result; + } + + /** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/frontend/views/product/_sale_form.php b/frontend/views/product/_sale_form.php new file mode 100644 index 0000000..e44cec4 --- /dev/null +++ b/frontend/views/product/_sale_form.php @@ -0,0 +1,85 @@ + +
+
+ +
+
+ 'product product-name']); ?> +
+
+
+
+ +
+
+ 'product product-price']); ?> +
+
+
+
+ +
+
+ 'product product-number']); ?> +
+
+
+
+ +
+
+ 'product barcode']); ?> +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ 'btn btn-success'] );?> +
+
+ 'btn btn-success'] );?> +
+
\ No newline at end of file diff --git a/frontend/views/product/_sold_items.php b/frontend/views/product/_sold_items.php new file mode 100644 index 0000000..a737b6e --- /dev/null +++ b/frontend/views/product/_sold_items.php @@ -0,0 +1,64 @@ + +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
     
     
     
+
+
diff --git a/frontend/views/product/sale.php b/frontend/views/product/sale.php index aff1bfd..42c3a00 100644 --- a/frontend/views/product/sale.php +++ b/frontend/views/product/sale.php @@ -3,6 +3,20 @@ use frontend\components\ReceptionMenuWidget; use frontend\components\ReceptionCardNumberWidget; use yii\helpers\Html; +use common\models\Product; +use frontend\assets\ProductSellAsset; +use yii\helpers\Url; + +ProductSellAsset::register($this); + +$options = []; + +$options['lookup_product_url'] = Url::toRoute(['product/lookup']); + +$this->registerJs ( 'new ProductSell( '. json_encode($options).');' ); + + + ?>