add changes sell product

This commit is contained in:
rocho 2015-10-01 17:31:48 +02:00
parent e3d6c0b902
commit e9f9567618
7 changed files with 323 additions and 144 deletions

View File

@ -3,6 +3,7 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\helpers\ArrayHelper;
/** /**
* This is the model class for table "product". * This is the model class for table "product".
@ -125,4 +126,44 @@ class Product extends \common\models\BaseFitnessActiveRecord {
return $warehouses; 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;
},
],
]);
}
} }

View File

@ -0,0 +1,28 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @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',
];
}

View File

@ -125,6 +125,24 @@ class ProductController extends Controller
return $this->redirect(['index']); 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. * Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -0,0 +1,85 @@
<?php
use yii\helpers\Html;
?>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product name'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-name']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product price'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-price']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product number'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-number']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Barcode'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product barcode']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Count'))?>
</div>
<div class='col-md-6'>
<?php echo Html::textInput('count') ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Currency'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('currency',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Account'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('account',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Discount'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('discount',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Comment'))?>
</div>
</div>
<div class="row">
<div class='col-md-10'>
<?php echo Html::textarea('comment', ''); ?>
</div>
</div>
<div class="row">
<div class='col-md-3'>
<?php echo Html::a(Yii::t("frontend/product","Sell product"),null,['class' => 'btn btn-success'] );?>
</div>
<div class='col-md-7'>
<?php echo Html::a(Yii::t("frontend/product","Sell product and add to total"),null,['class' => 'btn btn-success'] );?>
</div>
</div>

View File

@ -0,0 +1,64 @@
<?php
use yii\bootstrap\Html;
?>
<div class="row">
<div class='col-md-10'>
<?php echo Html::label(Yii::t('frontend/product', 'Bill'))?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Debit'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag("span",'0,00',['sale', 'sale-debit'])?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
<?php echo Yii::t('frontend/product', 'Product name')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Count')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Currency')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Item Price')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Total Price')?>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@ -3,6 +3,20 @@
use frontend\components\ReceptionMenuWidget; use frontend\components\ReceptionMenuWidget;
use frontend\components\ReceptionCardNumberWidget; use frontend\components\ReceptionCardNumberWidget;
use yii\helpers\Html; 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).');' );
?> ?>
<style> <style>
@ -21,160 +35,22 @@ use yii\helpers\Html;
<div class='col-md-4'> <div class='col-md-4'>
</div> </div>
</div> </div>
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1> <h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
<div class='row'> <div class='row'>
<div class='col-md-4'> <div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product'))?> <?php echo Html::label(Yii::t('frontend/product', 'Product'))?>
<?php echo Html::textInput('filter_text')?> <?php echo Html::textInput('filter_text','', ['id'=>'filter_text'])?>
</div> </div>
<div class='col-md-4'> <div class='col-md-4'>
</div> </div>
<div class='col-md-4'> <div class='col-md-4'>
</div> </div>
</div> </div>
<div class='row '>
<div class='row product-form'> <div class='col-md-6 product-form'>
<div class='col-md-6'> <?php echo $this->render('_sale_form' ) ?>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product name'))?>
</div> </div>
<div class='col-md-6'> <div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-name']); ?> <?php echo $this->render('_sold_items' ) ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product price'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-price']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Product number'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product product-number']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Barcode'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag('span','',[ 'class' => 'product barcode']); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Count'))?>
</div>
<div class='col-md-6'>
<?php echo Html::textInput('count') ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Currency'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('currency',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Account'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('account',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Discount'))?>
</div>
<div class='col-md-6'>
<?php echo Html::dropDownList('discount',null,[],[]); ?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Comment'))?>
</div>
</div>
<div class="row">
<div class='col-md-10'>
<?php echo Html::textarea('comment', ''); ?>
</div>
</div>
</div>
<div class='col-md-6'>
<div class="row">
<div class='col-md-10'>
<?php echo Html::label(Yii::t('frontend/product', 'Bill'))?>
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::label(Yii::t('frontend/product', 'Debit'))?>
</div>
<div class='col-md-6'>
<?php echo Html::tag("span",'0,00',['sale', 'sale-debit']) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
<?php echo Yii::t('frontend/product', 'Product name')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Count')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Currency')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Item Price')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Total Price')?>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</div>
</div> </div>
</div> </div>

View File

@ -0,0 +1,67 @@
function ProductSell(o){
this.defaults = {
selector_filter_text: '#filter_text',
lookup_product_url: ''
};
init();
function init(){
this.defaults = $.extend(this.defaults, o );
addBehaviorEnterPressedListener();
}
function addBehaviorEnterPressedListener(){
alert($( this.defaults.selector_filter_text ).length);
$( this.defaults.selector_filter_text ).keypress(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
lookupProduct();
}
});
}
function lookupProduct(){
var data, url;
url = this.defaults.lookup_product_url;
data = {
'query' : $( this.defaults.selector_filter_text ).val()
};
$.ajax({
dataType: "json",
url: url,
data: data,
success: onLookupProductReady
});
}
function onLookupProductReady( data ){
alert('ok');
productChanged(data.product);
}
function productChanged(product){
clearForm();
if ( product == null){
applyProduct();
}
}
function clearForm(){
$('.product-name').html('-');
}
function applyProduct(product){
$('.product-name').html(product.name);
}
}