Finish product_list
This commit is contained in:
commit
a7a0df3ab6
@ -89,6 +89,7 @@ class AdminMenuStructure{
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
$items = [];
|
$items = [];
|
||||||
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ];
|
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ];
|
||||||
|
$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
|
||||||
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
|
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
|
||||||
$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
|
$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
|
||||||
$this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl,
|
$this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl,
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use yii\web\NotFoundHttpException;
|
|||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
use common\models\User;
|
use common\models\User;
|
||||||
|
use backend\models\TransferSummarySearch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TransferController implements the CRUD actions for Transfer model.
|
* TransferController implements the CRUD actions for Transfer model.
|
||||||
@ -23,7 +24,7 @@ class TransferController extends \backend\controllers\BackendController
|
|||||||
'rules' => [
|
'rules' => [
|
||||||
// allow authenticated users
|
// allow authenticated users
|
||||||
[
|
[
|
||||||
'actions' => [ 'index','view' ],
|
'actions' => [ 'index','view','summary' ],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
'roles' => ['admin','employee','reception'],
|
'roles' => ['admin','employee','reception'],
|
||||||
],
|
],
|
||||||
@ -57,6 +58,29 @@ class TransferController extends \backend\controllers\BackendController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all Transfer models.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionSummary()
|
||||||
|
{
|
||||||
|
$searchModel = new TransferSummarySearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
|
$accounts = Account::read();
|
||||||
|
|
||||||
|
$users = User::read();
|
||||||
|
|
||||||
|
return $this->render('summary', [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'accounts' => $accounts,
|
||||||
|
'users' => $users,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a single Transfer model.
|
* Displays a single Transfer model.
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
|
|||||||
@ -114,7 +114,8 @@ class TransferSearch extends Transfer
|
|||||||
|
|
||||||
$accounts = Account::read();
|
$accounts = Account::read();
|
||||||
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
|
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
|
||||||
$idUser = Yii::$app->user->id;
|
$idUser = $this->id_user;
|
||||||
|
|
||||||
|
|
||||||
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
|
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
|
||||||
|
|
||||||
|
|||||||
180
backend/models/TransferSummarySearch.php
Normal file
180
backend/models/TransferSummarySearch.php
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use common\models\Transfer;
|
||||||
|
use yii\db\Expression;
|
||||||
|
use yii\base\Object;
|
||||||
|
use yii\db\Query;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use common\models\Account;
|
||||||
|
use common\components\Helper;
|
||||||
|
use common\components\RoleDefinition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||||
|
*/
|
||||||
|
class TransferSummarySearch extends Transfer
|
||||||
|
{
|
||||||
|
public $searchObjectName;
|
||||||
|
public $searchTypeName;
|
||||||
|
public $searchUserName;
|
||||||
|
public $start;
|
||||||
|
public $end;
|
||||||
|
|
||||||
|
public $timestampStart;
|
||||||
|
public $timestampEnd;
|
||||||
|
|
||||||
|
|
||||||
|
public $types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* all money gained with ticket sell
|
||||||
|
* */
|
||||||
|
public $ticketMoney;
|
||||||
|
/**
|
||||||
|
* all money gained with product sell grouped by category
|
||||||
|
* */
|
||||||
|
public $productMoneies;
|
||||||
|
/**
|
||||||
|
* all money lost by money movement
|
||||||
|
* */
|
||||||
|
public $moneyMovementMoneis;
|
||||||
|
/**
|
||||||
|
* total gained money
|
||||||
|
* */
|
||||||
|
public $total;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[[ 'id_account','id_user', 'type'], 'integer'],
|
||||||
|
// [[ 'searchObjectName' ], 'string'],
|
||||||
|
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||||
|
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||||
|
['types', 'each', 'rule' => ['integer']],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function scenarios()
|
||||||
|
{
|
||||||
|
// bypass scenarios() implementation in the parent class
|
||||||
|
return Model::scenarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data provider instance with search query applied
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return ActiveDataProvider
|
||||||
|
*/
|
||||||
|
public function search($params)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->load($params);
|
||||||
|
|
||||||
|
if (!$this->validate()) {
|
||||||
|
// $query->where('0=1');
|
||||||
|
// return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->readTicketMoney();
|
||||||
|
$this->readProductsByCategory();
|
||||||
|
$this->readMoneyMovements();
|
||||||
|
$this->calcTotal();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function calcTotal(){
|
||||||
|
$this->total = 0;
|
||||||
|
$this->total += $this->ticketMoney;
|
||||||
|
$this->total -= $this->moneyMovementMoneis['money_movement_money'];
|
||||||
|
foreach ($this->productMoneies as $pm ){
|
||||||
|
$this->total += $pm['product_money'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function addQueryFilters($query){
|
||||||
|
if ( !RoleDefinition::isAdmin() ){
|
||||||
|
$query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' );
|
||||||
|
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->andFilterWhere([
|
||||||
|
'transfer.id_account' => $this->id_account,
|
||||||
|
'transfer.type' => $this->type,
|
||||||
|
'transfer.id_user' => $this->id_user,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
|
||||||
|
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];
|
||||||
|
|
||||||
|
|
||||||
|
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
|
||||||
|
|
||||||
|
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function readTicketMoney(){
|
||||||
|
|
||||||
|
$query = (new \yii\db\Query());
|
||||||
|
$query->select([' coalesce(sum(abs(transfer.money)),0) AS ticket_money']);
|
||||||
|
$query->from('transfer');
|
||||||
|
$query->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||||
|
$query->innerJoin("ticket", "ticket.id_ticket = transfer.id_object");
|
||||||
|
$this->addQueryFilters($query);
|
||||||
|
|
||||||
|
// $query = Transfer::find();
|
||||||
|
// $query->andWhere(['type' => Transfer::TYPE_TICKET]);
|
||||||
|
// $this->addQueryFilters($query);
|
||||||
|
$this->ticketMoney = $query->scalar();
|
||||||
|
print_r($this->ticketMoney);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function readProductsByCategory(){
|
||||||
|
|
||||||
|
|
||||||
|
$query = (new \yii\db\Query());
|
||||||
|
$query->select(['coalesce(sum(transfer.money),0) AS product_money', 'product_category.name as category_name']);
|
||||||
|
$query->from('transfer');
|
||||||
|
$query->groupBy(['product_category.id_product_category','product_category.name']);
|
||||||
|
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||||
|
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||||
|
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||||
|
$query->innerJoin("product_category", "product.id_product_category = product_category.id_product_category");
|
||||||
|
$this->addQueryFilters($query);
|
||||||
|
|
||||||
|
$this->productMoneies = $query->all();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function readMoneyMovements(){
|
||||||
|
$query = (new \yii\db\Query());
|
||||||
|
$query->select([' coalesce(sum(abs(transfer.money)),0) AS money_movement_money']);
|
||||||
|
$query->from('transfer');
|
||||||
|
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
|
||||||
|
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");
|
||||||
|
$this->addQueryFilters($query);
|
||||||
|
|
||||||
|
$this->moneyMovementMoneis = $query->one();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
58
backend/views/transfer/_search_summary.php
Normal file
58
backend/views/transfer/_search_summary.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use frontend\components\HtmlHelper;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use common\models\Transfer;
|
||||||
|
use kartik\widgets\DatePicker;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model backend\models\TransferSearch */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="transfer-search">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin([
|
||||||
|
'action' => ['summary'],
|
||||||
|
'method' => 'get',
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
<div class='row'>
|
||||||
|
<div class='col-md-4'>
|
||||||
|
<?= $form->field($model, 'id_account')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +HtmlHelper::mkAccountOptions($accounts) ) ?>
|
||||||
|
</div>
|
||||||
|
<div class='col-md-4'>
|
||||||
|
<?= $form->field($model, 'id_user')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +ArrayHelper::map($users,'id' , 'username') ) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
|
||||||
|
'pluginOptions' => [
|
||||||
|
'autoclose'=>true,
|
||||||
|
'format' => 'yyyy.mm.dd'
|
||||||
|
]
|
||||||
|
]) ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'end') ->widget(DatePicker::classname(), [
|
||||||
|
'pluginOptions' => [
|
||||||
|
'autoclose'=>true,
|
||||||
|
'format' => 'yyyy.mm.dd'
|
||||||
|
]
|
||||||
|
]) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
@ -43,6 +43,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
|
|
||||||
|
[
|
||||||
|
'attribute' => 'id_transfer',
|
||||||
|
'value' => 'id_transfer'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'attribute' => 'type',
|
'attribute' => 'type',
|
||||||
'value' => 'transferTypeName'
|
'value' => 'transferTypeName'
|
||||||
@ -72,6 +76,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'value' => 'signedMoney'
|
'value' => 'signedMoney'
|
||||||
],
|
],
|
||||||
'created_at:datetime',
|
'created_at:datetime',
|
||||||
|
'paid_at:datetime',
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn',
|
['class' => 'yii\grid\ActionColumn',
|
||||||
'template' => '{view}'
|
'template' => '{view}'
|
||||||
|
|||||||
73
backend/views/transfer/summary.php
Normal file
73
backend/views/transfer/summary.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $searchModel backend\models\TransferSearch */
|
||||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||||
|
|
||||||
|
$this->title = Yii::t('frontend/transfer', 'Transfers Summary');
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<style>
|
||||||
|
.table-summary th
|
||||||
|
{
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="transfer-index">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
<?php echo $this->render('_search_summary', ['model' => $searchModel, 'accounts' => $accounts,'users' => $users,]); ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Bérletek összesen</h2>
|
||||||
|
<table class="table-bordered table-striped table-summary">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th >Bérletek</th>
|
||||||
|
<td><?php echo $searchModel->ticketMoney?> FT</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h2>Termékek összesen</h2>
|
||||||
|
<table class="table-bordered table-striped table-summary">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Termék kategória</th>
|
||||||
|
<th>Összeg</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<?php
|
||||||
|
foreach ($searchModel->productMoneies as $pm ){
|
||||||
|
?>
|
||||||
|
<th ><?php echo $pm['category_name'] ?></th>
|
||||||
|
<td><?php echo $pm['product_money']?> FT</td>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h2>Pénzmozgások összesen</h2>
|
||||||
|
<table class="table-bordered table-striped table-summary">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th >Pénzmozgások</th>
|
||||||
|
<td><?php echo $searchModel->moneyMovementMoneis['money_movement_money']?> FT</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h2>Bevétel összesen</h2>
|
||||||
|
<table class="table-bordered table-striped table-summary">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th >Bérletek</th>
|
||||||
|
<td><span style='border-bottom: 1px solid black'><?php echo $searchModel->total?> FT</span></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
@ -41,6 +41,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'money',
|
'money',
|
||||||
'comment',
|
'comment',
|
||||||
'created_at',
|
'created_at',
|
||||||
|
'paid_at',
|
||||||
],
|
],
|
||||||
]) ?>
|
]) ?>
|
||||||
|
|
||||||
|
|||||||
27
common/assets/TypeAheadAsset.php
Normal file
27
common/assets/TypeAheadAsset.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @link http://www.yiiframework.com/
|
||||||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||||
|
* @license http://www.yiiframework.com/license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace common\assets;
|
||||||
|
|
||||||
|
use yii\web\AssetBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
class TypeAheadAsset extends AssetBundle
|
||||||
|
{
|
||||||
|
public $sourcePath = '@vendor/bassjobsen/bootstrap-3-typeahead';
|
||||||
|
public $js = [
|
||||||
|
'bootstrap3-typeahead.min.js',
|
||||||
|
];
|
||||||
|
public $depends = [
|
||||||
|
// 'yii\bootstrap\BootstrapAsset',
|
||||||
|
// 'yii\bootstrap\BootstrapPluginAsset',
|
||||||
|
];
|
||||||
|
}
|
||||||
@ -28,4 +28,5 @@ return [
|
|||||||
'Update' => 'Módosítás',
|
'Update' => 'Módosítás',
|
||||||
'Update {modelClass}: ' => '{modelClass} módosítás: ',
|
'Update {modelClass}: ' => '{modelClass} módosítás: ',
|
||||||
'pieces' => 'db',
|
'pieces' => 'db',
|
||||||
|
'Transfers Summary' => 'Bevétel'
|
||||||
];
|
];
|
||||||
|
|||||||
@ -168,6 +168,20 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function modelToMapIdName($product,$default = null){
|
||||||
|
|
||||||
|
if ( $product == null ){
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ArrayHelper::toArray($product, [
|
||||||
|
'common\models\Product' => [
|
||||||
|
'id_product',
|
||||||
|
'name',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public static function sellProduct($product,$count){
|
public static function sellProduct($product,$count){
|
||||||
$product->stock = $product->stock - $count;
|
$product->stock = $product->stock - $count;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
"yiisoft/yii2-jui": "^2.0",
|
"yiisoft/yii2-jui": "^2.0",
|
||||||
"bower-asset/moment": "^2.10",
|
"bower-asset/moment": "^2.10",
|
||||||
"bower-asset/accounting": "^0.3.2",
|
"bower-asset/accounting": "^0.3.2",
|
||||||
"dmstr/yii2-adminlte-asset": "2.*"
|
"dmstr/yii2-adminlte-asset": "2.*",
|
||||||
|
"bassjobsen/bootstrap-3-typeahead": "^4.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"yiisoft/yii2-codeception": "*",
|
"yiisoft/yii2-codeception": "*",
|
||||||
|
|||||||
40
composer.lock
generated
40
composer.lock
generated
@ -4,8 +4,8 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "48dcd434e58d6b2167477f208c700dc3",
|
"hash": "acfc873fb659d08adc23d325138a56b2",
|
||||||
"content-hash": "2678695117e871d59f193589465751cf",
|
"content-hash": "28e2bce30da929c84bd2ac7cffd90f3f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "almasaeed2010/adminlte",
|
"name": "almasaeed2010/adminlte",
|
||||||
@ -47,6 +47,42 @@
|
|||||||
],
|
],
|
||||||
"time": "2015-10-23 14:50:49"
|
"time": "2015-10-23 14:50:49"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "bassjobsen/bootstrap-3-typeahead",
|
||||||
|
"version": "v4.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/bassjobsen/Bootstrap-3-Typeahead.git",
|
||||||
|
"reference": "516d96962e1d7fc7c3972c9bbba3b0a133ae9aae"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/bassjobsen/Bootstrap-3-Typeahead/zipball/516d96962e1d7fc7c3972c9bbba3b0a133ae9aae",
|
||||||
|
"reference": "516d96962e1d7fc7c3972c9bbba3b0a133ae9aae",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"type": "component",
|
||||||
|
"extra": {
|
||||||
|
"component": {
|
||||||
|
"files": [
|
||||||
|
"bootstrap3-typeahead.js",
|
||||||
|
"bootstrap3-typeahead.min.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Bass Jobsen",
|
||||||
|
"email": "bass@w3masters.nl"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Bootstrap 3 Typeahead",
|
||||||
|
"time": "2015-11-14 22:02:27"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "bower-asset/accounting",
|
"name": "bower-asset/accounting",
|
||||||
"version": "v0.3.2",
|
"version": "v0.3.2",
|
||||||
|
|||||||
@ -26,5 +26,7 @@ class ProductSellAsset extends AssetBundle
|
|||||||
public $depends = [
|
public $depends = [
|
||||||
'frontend\assets\AppAsset',
|
'frontend\assets\AppAsset',
|
||||||
'yii\jui\JuiAsset',
|
'yii\jui\JuiAsset',
|
||||||
|
'common\assets\TypeAheadAsset',
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class ProductController extends Controller
|
|||||||
],
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\filters\AccessControl::className(),
|
'class' => \yii\filters\AccessControl::className(),
|
||||||
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup'],
|
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup','find'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
// allow authenticated users
|
// allow authenticated users
|
||||||
[
|
[
|
||||||
@ -82,6 +82,11 @@ class ProductController extends Controller
|
|||||||
$model->customer = $this->customer;
|
$model->customer = $this->customer;
|
||||||
$model->card = $this->card;
|
$model->card = $this->card;
|
||||||
|
|
||||||
|
$products = Product::read();
|
||||||
|
$products = Product::modelToMapIdName($products);
|
||||||
|
|
||||||
|
$model->products = $products;
|
||||||
|
|
||||||
if (Yii::$app->request->isAjax) {
|
if (Yii::$app->request->isAjax) {
|
||||||
|
|
||||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||||
@ -203,6 +208,23 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function actionFind($id=null)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$product = Product::findOne($id);
|
||||||
|
$product = Product::modelToArray($product);
|
||||||
|
|
||||||
|
$result['product'] = $product;
|
||||||
|
|
||||||
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,9 @@ class ProductLookupForm extends Model
|
|||||||
{
|
{
|
||||||
|
|
||||||
public $filter_text;
|
public $filter_text;
|
||||||
|
public $product_search;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,6 +36,7 @@ class ProductLookupForm extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'filter_text' => Yii::t('frontend/product','Barcode or product code') ,
|
'filter_text' => Yii::t('frontend/product','Barcode or product code') ,
|
||||||
|
'product_search' => Yii::t("frontend/product", "Name"),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,6 +76,8 @@ class ProductSaleForm extends Model
|
|||||||
|
|
||||||
public $customerCart;
|
public $customerCart;
|
||||||
|
|
||||||
|
public $products;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -47,6 +47,8 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
|||||||
],
|
],
|
||||||
] )?>
|
] )?>
|
||||||
<div class='col-md-12'>
|
<div class='col-md-12'>
|
||||||
|
<!-- <input type='text' name='product_search' id="product_search" > -->
|
||||||
|
<?php echo $form->field($lookupModel,'product_search')->textInput(['id'=>'product_search']); ?>
|
||||||
<?php echo $form->field($lookupModel,'filter_text')->textInput(['id'=>'filter_text']); ?>
|
<?php echo $form->field($lookupModel,'filter_text')->textInput(['id'=>'filter_text']); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php ActiveForm::end()?>
|
<?php ActiveForm::end()?>
|
||||||
|
|||||||
@ -16,8 +16,10 @@ ProductSellAsset::register($this);
|
|||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||||
|
$options['find_product_url'] = Url::toRoute(['product/find']);
|
||||||
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart']);
|
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart']);
|
||||||
$options['user_cart'] = $userTransfers;
|
$options['user_cart'] = $userTransfers;
|
||||||
|
$options['products'] = $model->products;
|
||||||
if ( isset($model->card) ){
|
if ( isset($model->card) ){
|
||||||
$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $model->card->number]);
|
$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $model->card->number]);
|
||||||
$options['customer_cart'] = $model->customerCart;
|
$options['customer_cart'] = $model->customerCart;
|
||||||
|
|||||||
@ -18,6 +18,7 @@ function ProductSell(o){
|
|||||||
url_pay_user_cart: '',
|
url_pay_user_cart: '',
|
||||||
/** ajax url for lookup service*/
|
/** ajax url for lookup service*/
|
||||||
lookup_product_url: '',
|
lookup_product_url: '',
|
||||||
|
find_product_url: '',
|
||||||
/**the id of form*/
|
/**the id of form*/
|
||||||
selector_form: '#product_form',
|
selector_form: '#product_form',
|
||||||
/**form contains error text*/
|
/**form contains error text*/
|
||||||
@ -28,6 +29,7 @@ function ProductSell(o){
|
|||||||
discounts: [],
|
discounts: [],
|
||||||
customer_cart: [],
|
customer_cart: [],
|
||||||
id_account: null,
|
id_account: null,
|
||||||
|
products : [],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,6 +53,8 @@ function ProductSell(o){
|
|||||||
|
|
||||||
productChanged();
|
productChanged();
|
||||||
addDocumentKeypressedListener();
|
addDocumentKeypressedListener();
|
||||||
|
|
||||||
|
initAutocomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,7 +121,7 @@ function ProductSell(o){
|
|||||||
var word;
|
var word;
|
||||||
word = data.word;
|
word = data.word;
|
||||||
if ( word.length > 0){
|
if ( word.length > 0){
|
||||||
if ( word.length >= 6 && word.length <= 8 ){
|
if ( word.length >= 6 && word.length <= 9 ){
|
||||||
//lookupuser
|
//lookupuser
|
||||||
}else{
|
}else{
|
||||||
$("#filter_text").val(data.word);
|
$("#filter_text").val(data.word);
|
||||||
@ -175,11 +179,20 @@ function ProductSell(o){
|
|||||||
$( app.defaults.selector_filter_text ).keypress(function( event ) {
|
$( app.defaults.selector_filter_text ).keypress(function( event ) {
|
||||||
if ( event.which == 13 ) {
|
if ( event.which == 13 ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
$('#product_search').val('');
|
||||||
|
$(this).val( fixBarcode($(this).val()));
|
||||||
lookupProduct();
|
lookupProduct();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fixBarcode(s){
|
||||||
|
var result;
|
||||||
|
result = s;
|
||||||
|
result = result.replace(/ö/g, "0");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**listen for enter key pressed on #productsaleform-count*/
|
/**listen for enter key pressed on #productsaleform-count*/
|
||||||
function addBehaviorCountEnterPressedListener(){
|
function addBehaviorCountEnterPressedListener(){
|
||||||
$( '#productsaleform-count' ).keypress(function( event ) {
|
$( '#productsaleform-count' ).keypress(function( event ) {
|
||||||
@ -249,6 +262,22 @@ function ProductSell(o){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _findProduct(id){
|
||||||
|
var data, url;
|
||||||
|
|
||||||
|
url = app.defaults.find_product_url;
|
||||||
|
data = {
|
||||||
|
'id' : id,
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
dataType: "json",
|
||||||
|
url: url,
|
||||||
|
data: data,
|
||||||
|
success: onLookupProductReady
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**succes event handler after lookup product event*/
|
/**succes event handler after lookup product event*/
|
||||||
function onLookupProductReady( data ){
|
function onLookupProductReady( data ){
|
||||||
app.product = data.product;
|
app.product = data.product;
|
||||||
@ -278,6 +307,7 @@ function ProductSell(o){
|
|||||||
$('#productsaleform-id_product').val('');
|
$('#productsaleform-id_product').val('');
|
||||||
$('#productsaleform-id_account').val( app.defaults.id_account ? app.defaults.id_account : '');
|
$('#productsaleform-id_account').val( app.defaults.id_account ? app.defaults.id_account : '');
|
||||||
$("#productsaleform-count").val(1);
|
$("#productsaleform-count").val(1);
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyProduct(product){
|
function applyProduct(product){
|
||||||
@ -374,6 +404,7 @@ function ProductSell(o){
|
|||||||
clearForm();
|
clearForm();
|
||||||
refreshCalculatedValues();
|
refreshCalculatedValues();
|
||||||
$("#filter_text").val('');
|
$("#filter_text").val('');
|
||||||
|
$("#product_search").val('');
|
||||||
setFocus();
|
setFocus();
|
||||||
app.defaults.user_cart = response.transfers;
|
app.defaults.user_cart = response.transfers;
|
||||||
app.defaults.customer_cart = response.customer_cart;
|
app.defaults.customer_cart = response.customer_cart;
|
||||||
@ -486,7 +517,7 @@ function ProductSell(o){
|
|||||||
|
|
||||||
function normalizePrice( price ){
|
function normalizePrice( price ){
|
||||||
var result;
|
var result;
|
||||||
result = hufRound(price);
|
// result = hufRound(price);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,4 +530,44 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initAutocomplete(){
|
||||||
|
// var colors = ["red", "blue", "green", "yellow", "brown", "black"];
|
||||||
|
// $('#product_search').typeahead( {source: colors } );
|
||||||
|
|
||||||
|
var $input = $('#product_search');
|
||||||
|
$input.typeahead({source: app.defaults.products,
|
||||||
|
autoSelect: true,
|
||||||
|
items: 12,
|
||||||
|
minLength: 3,
|
||||||
|
// displayText: function (item){
|
||||||
|
// return item.
|
||||||
|
// }
|
||||||
|
|
||||||
|
});
|
||||||
|
$input.change(function() {
|
||||||
|
var current = $input.typeahead("getActive");
|
||||||
|
$("#filter_text").val('');
|
||||||
|
if (current) {
|
||||||
|
// Some item from your model is active!
|
||||||
|
if (current.name == $input.val()) {
|
||||||
|
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
|
||||||
|
console.info(current);
|
||||||
|
_findProduct(current.id_product);
|
||||||
|
} else {
|
||||||
|
// This means it is only a partial match, you can either add a new item
|
||||||
|
// or take the active if you don't want new items
|
||||||
|
console.info('partial');
|
||||||
|
app.product = null;
|
||||||
|
productChanged();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Nothing is active so it is a new value (or maybe empty value)
|
||||||
|
console.info('incactive');
|
||||||
|
app.product = null;
|
||||||
|
productChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user