sell product list
This commit is contained in:
parent
203dfeac72
commit
2610749305
@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Object;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "transfer".
|
||||
@ -94,6 +95,10 @@ class Transfer extends \yii\db\ActiveRecord
|
||||
return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
|
||||
}
|
||||
|
||||
public function getUserSoldItem(){
|
||||
return $this->hasOne( UserSoldItem::className(), ["id_transfer" =>"id_transfer" ] );
|
||||
}
|
||||
|
||||
|
||||
public function toProductSoldString(){
|
||||
$s = "";
|
||||
@ -143,4 +148,43 @@ class Transfer extends \yii\db\ActiveRecord
|
||||
return $transfer;
|
||||
}
|
||||
|
||||
public static function modelsToArray($transfers,$default = null){
|
||||
|
||||
if ( $transfers == null ){
|
||||
return $default;
|
||||
}
|
||||
|
||||
return ArrayHelper::toArray($transfers, [
|
||||
'common\models\Transfer' => [
|
||||
'id_transfer',
|
||||
'item_price',
|
||||
'count',
|
||||
'money',
|
||||
'money_currency',
|
||||
'account_name' => function ($transfer) {
|
||||
return $transfer->account->name;
|
||||
},
|
||||
'product_name' => function ($transfer) {
|
||||
return $transfer->product->name;
|
||||
},
|
||||
'category' => function ($transfer) {
|
||||
return $transfer->product->productCategoryName;
|
||||
},
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public static function readUserSoldTransfers($user){
|
||||
$transfers = [];
|
||||
|
||||
$query = Transfer::find();
|
||||
|
||||
$query->innerJoinWith('userSoldItem');
|
||||
$query->andWhere(['user_sold_item.id_user' => $user->id ]);
|
||||
$transfers = $query->all();
|
||||
|
||||
return $transfers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,4 +42,24 @@ class UserSoldItem extends \yii\db\ActiveRecord
|
||||
'id_transfer' => Yii::t('common/user-sold-item', 'Id Transfer'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getAccount(){
|
||||
$this->hasOne(Transfer::className(), ["id_transfer" => "id_transfer"]);
|
||||
}
|
||||
|
||||
public function getUser(){
|
||||
$this->hasOne(User::className(), ["id" => "id_user"]);
|
||||
}
|
||||
|
||||
|
||||
public static function read($user){
|
||||
|
||||
$query = UserSoldItem::find();
|
||||
$query->andWhere(['id_user' => $user->id_user]);
|
||||
$result = $query->all();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@
|
||||
"yiisoft/yii2-swiftmailer": "*",
|
||||
"kartik-v/yii2-widgets": "^3.4",
|
||||
"kartik-v/yii2-widget-typeahead": "*",
|
||||
"bower-asset/remarkable-bootstrap-notify": "^3.1"
|
||||
"bower-asset/remarkable-bootstrap-notify": "^3.1",
|
||||
"yiisoft/yii2-jui": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-codeception": "*",
|
||||
|
||||
77
composer.lock
generated
77
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "a1314409d3150e430e6ff7e350de0e3b",
|
||||
"hash": "7bff75eba2c88cda67ff49b95bda9644",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bower-asset/bootstrap",
|
||||
@ -99,6 +99,31 @@
|
||||
"library"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bower-asset/jquery-ui",
|
||||
"version": "1.11.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/components/jqueryui.git",
|
||||
"reference": "c34f8dbf3ba57b3784b93f26119f436c0e8288e1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/components/jqueryui/zipball/c34f8dbf3ba57b3784b93f26119f436c0e8288e1",
|
||||
"reference": "c34f8dbf3ba57b3784b93f26119f436c0e8288e1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"bower-asset/jquery": ">=1.6"
|
||||
},
|
||||
"type": "bower-asset-library",
|
||||
"extra": {
|
||||
"bower-asset-main": [
|
||||
"jquery-ui.js"
|
||||
],
|
||||
"bower-asset-ignore": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "bower-asset/jquery.inputmask",
|
||||
"version": "3.1.63",
|
||||
@ -1715,6 +1740,56 @@
|
||||
],
|
||||
"time": "2015-03-01 06:22:44"
|
||||
},
|
||||
{
|
||||
"name": "yiisoft/yii2-jui",
|
||||
"version": "2.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/yiisoft/yii2-jui.git",
|
||||
"reference": "ce16f29cca654702c2ee500ccad9657a2d2e6a09"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/yiisoft/yii2-jui/zipball/ce16f29cca654702c2ee500ccad9657a2d2e6a09",
|
||||
"reference": "ce16f29cca654702c2ee500ccad9657a2d2e6a09",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"bower-asset/jquery-ui": "1.11.*@stable",
|
||||
"yiisoft/yii2": ">=2.0.4"
|
||||
},
|
||||
"type": "yii2-extension",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
},
|
||||
"asset-installer-paths": {
|
||||
"npm-asset-library": "vendor/npm",
|
||||
"bower-asset-library": "vendor/bower"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"yii\\jui\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Qiang Xue",
|
||||
"email": "qiang.xue@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "The Jquery UI extension for the Yii framework",
|
||||
"keywords": [
|
||||
"jQuery UI",
|
||||
"yii2"
|
||||
],
|
||||
"time": "2015-05-10 22:09:43"
|
||||
},
|
||||
{
|
||||
"name": "yiisoft/yii2-swiftmailer",
|
||||
"version": "2.0.4",
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m151005_095529_alter__table__discount_rename_id extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->renameColumn('discount','id_warehouse','id_discount');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m151005_095529_alter__table__discount_rename_id cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -26,6 +26,6 @@ class AppAsset extends AssetBundle
|
||||
public $depends = [
|
||||
'yii\web\YiiAsset',
|
||||
'yii\bootstrap\BootstrapAsset',
|
||||
'frontend\assets\GrowlAsset'
|
||||
'frontend\assets\GrowlAsset',
|
||||
];
|
||||
}
|
||||
|
||||
@ -25,5 +25,6 @@ class ProductSellAsset extends AssetBundle
|
||||
];
|
||||
public $depends = [
|
||||
'frontend\assets\AppAsset',
|
||||
'yii\jui\JuiAsset',
|
||||
];
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ use yii\base\Object;
|
||||
use common\models\Currency;
|
||||
use common\models\Account;
|
||||
use common\models\Discount;
|
||||
use common\models\Transfer;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* ProductController implements the CRUD actions for Product model.
|
||||
@ -54,6 +56,7 @@ class ProductController extends Controller
|
||||
|
||||
$discounts = Discount::read();
|
||||
|
||||
$user = User::findOne(Yii::$app->user->id );
|
||||
|
||||
if (Yii::$app->request->isAjax) {
|
||||
|
||||
@ -76,10 +79,18 @@ class ProductController extends Controller
|
||||
$result['code'] = 'invalid';
|
||||
$result['errors'] = $model->getErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||
$result['transfers'] = $userTransfers;
|
||||
|
||||
return $result;
|
||||
|
||||
}else{
|
||||
|
||||
// $userTransfers = Transfer::readUserSoldTransfers( $user );
|
||||
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||
|
||||
return $this->render("sale",[
|
||||
'customer' => $this->customer,
|
||||
'card' => $this->card,
|
||||
@ -88,6 +99,7 @@ class ProductController extends Controller
|
||||
'currencies' => $currencies,
|
||||
'accounts' => $accounts,
|
||||
'discounts' => $discounts,
|
||||
'userTransfers' => $userTransfers
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ use yii\base\Object;
|
||||
use common\models\Account;
|
||||
use common\models\Discount;
|
||||
use common\models\Currency;
|
||||
use common\models\UserSoldItem;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
@ -19,6 +20,8 @@ use common\models\Currency;
|
||||
class ProductSaleForm extends Model
|
||||
{
|
||||
|
||||
public $append_to_sold_list;
|
||||
|
||||
public $id_product;
|
||||
public $count;
|
||||
public $id_currency;
|
||||
@ -51,11 +54,13 @@ class ProductSaleForm extends Model
|
||||
[['id_product','count','id_account'], 'required'],
|
||||
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
|
||||
[['comment'], 'string' ,'max' => 255],
|
||||
[['append_to_sold_list'], 'string' ,'max' => 10],
|
||||
[['id_product' ], 'validateProduct'],
|
||||
[['count' ], 'validateCount'],
|
||||
[['id_currency' ], 'validateCurrency'],
|
||||
[['id_account' ], 'validateAccount'],
|
||||
[['id_discount' ], 'validateDiscount'],
|
||||
[['id_discount' ], 'validateDiscount'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -114,6 +119,7 @@ class ProductSaleForm extends Model
|
||||
if ( $this->validate() ){
|
||||
$this->saveTransfer();
|
||||
$this->saveProduct();
|
||||
$this->appendToSoldList();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -137,4 +143,20 @@ class ProductSaleForm extends Model
|
||||
$this->product->save();
|
||||
}
|
||||
|
||||
public function isAppendToList(){
|
||||
$result = false;
|
||||
if ( isset( $this->append_to_sold_list ) && $this->append_to_sold_list == 'append' ){
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function appendToSoldList(){
|
||||
if ( $this->isAppendToList() ){
|
||||
$item = new UserSoldItem();
|
||||
$item->id_transfer = $this->transfer->id_transfer;
|
||||
$item->id_user = Yii::$app->user->id;
|
||||
$item->save(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
||||
]
|
||||
); ?>
|
||||
<?php echo Html::activeHiddenInput($model, 'id_product') ?>
|
||||
<?php echo Html::activeHiddenInput($model, 'append_to_sold_list') ?>
|
||||
|
||||
<div class="row">
|
||||
<div class='col-md-12'>
|
||||
|
||||
@ -5,7 +5,8 @@ use yii\bootstrap\Html;
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class='col-md-12'>
|
||||
<div class='col-md-12 '>
|
||||
<div class="sold-items-container">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -29,5 +30,6 @@ use yii\bootstrap\Html;
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
?>
|
||||
<table class="table table-bordered table-striped">
|
||||
<table class="table table-bordered table-striped table-product">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
|
||||
@ -18,11 +18,11 @@ ProductSellAsset::register($this);
|
||||
$options = [];
|
||||
|
||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||
$options['sold_items'] = $userTransfers;
|
||||
|
||||
|
||||
$this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
@ -49,12 +49,14 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
||||
<?php echo ReceptionCardNumberWidget::widget( [ 'customer' => $customer, 'card' =>$card, 'route' => ['product/sale'] ] )?>
|
||||
</div>
|
||||
</div>
|
||||
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
|
||||
<div class='row '>
|
||||
<div class='col-md-6 product-form'>
|
||||
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
|
||||
<?php echo $this->render('_sale_form' ,['model' =>$model , 'lookupModel' =>$lookupModel, 'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts,]) ?>
|
||||
</div>
|
||||
<div class='col-md-6'>
|
||||
<h1><?php echo Yii::t('frontend/product','Sold')?></h1>
|
||||
<?php echo $this->render('_sold_items' ) ?>
|
||||
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'class' => 'btn btn-primary' ]) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,13 +1,21 @@
|
||||
function ProductSell(o){
|
||||
|
||||
/**reference for the instance*/
|
||||
var app = this;
|
||||
/**currently loaded product*/
|
||||
var product = null;
|
||||
|
||||
this.defaults = {
|
||||
/**id of filter text*/
|
||||
selector_filter_text: '#filter_text',
|
||||
lookup_product_url: '' ,
|
||||
/** ajax url for lookup service*/
|
||||
lookup_product_url: '',
|
||||
/**the id of form*/
|
||||
selector_form: '#product_form',
|
||||
form_invalid: 'Az ürlap hibákat tartalmaz'
|
||||
/**form contains error text*/
|
||||
form_invalid: 'Az ürlap hibákat tartalmaz',
|
||||
/**list of sold items by current user*/
|
||||
sold_items: [],
|
||||
};
|
||||
|
||||
init();
|
||||
@ -25,13 +33,18 @@ function ProductSell(o){
|
||||
addBehaviorAccountEnterPressedListener();
|
||||
addBehaviorDiscountEnterPressedListener();
|
||||
productChanged();
|
||||
createUserSoldItemsTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the focus for text input #filter_text
|
||||
* */
|
||||
function setFocus(){
|
||||
$("#filter_text").focus();
|
||||
|
||||
}
|
||||
|
||||
/**listen for enter key pressed on #filter_text*/
|
||||
function addBehaviorEnterPressedListener(){
|
||||
$( app.defaults.selector_filter_text ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
@ -41,6 +54,7 @@ function ProductSell(o){
|
||||
});
|
||||
}
|
||||
|
||||
/**listen for enter key pressed on #productsaleform-count*/
|
||||
function addBehaviorCountEnterPressedListener(){
|
||||
$( '#productsaleform-count' ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
@ -50,7 +64,7 @@ function ProductSell(o){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**listen for enter key pressed on #productsaleform-id_currency*/
|
||||
function addBehaviorCurrencyEnterPressedListener(){
|
||||
$( '#productsaleform-id_currency' ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
@ -60,6 +74,7 @@ function ProductSell(o){
|
||||
}
|
||||
});
|
||||
}
|
||||
/**listen for enter key pressed on #productsaleform-id_account*/
|
||||
function addBehaviorAccountEnterPressedListener(){
|
||||
$( '#productsaleform-id_account' ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
@ -69,7 +84,7 @@ function ProductSell(o){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**listen for enter key pressed on #productsaleform-id_discount*/
|
||||
function addBehaviorDiscountEnterPressedListener(){
|
||||
$( '#productsaleform-id_discount' ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
@ -79,7 +94,7 @@ function ProductSell(o){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**listen for event "change" #productsaleform-count*/
|
||||
function addBehaviorCountChangedListener(){
|
||||
$( '#productsaleform-count' ).change(function( event ) {
|
||||
refreshCalculatedValues();
|
||||
@ -87,6 +102,7 @@ function ProductSell(o){
|
||||
});
|
||||
}
|
||||
|
||||
/**load a product from server by exact barcode or product number*/
|
||||
function lookupProduct(){
|
||||
var data, url;
|
||||
|
||||
@ -103,12 +119,13 @@ function ProductSell(o){
|
||||
});
|
||||
}
|
||||
|
||||
/**succes event handler after lookup product event*/
|
||||
function onLookupProductReady( data ){
|
||||
app.product = data.product;
|
||||
productChanged();
|
||||
}
|
||||
|
||||
|
||||
/**handles product change.*/
|
||||
function productChanged( ){
|
||||
clearForm();
|
||||
if ( app.product != null){
|
||||
@ -119,26 +136,30 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
function clearForm(){
|
||||
$('.product-name').html('-');
|
||||
$('.product-price').html('-');
|
||||
$('.product-number').html('-');
|
||||
$('.product-barcode').html('-');
|
||||
$('.product-stock').html('-');
|
||||
$('.product-price').html('-');
|
||||
$('.product-sale-price').html('-');
|
||||
$("#productsaleform-count").val(1);
|
||||
$('#productsaleform-id_product').val('');
|
||||
$('#productsaleform-id_account').val('');
|
||||
var table;
|
||||
table = $('.table-product');
|
||||
table.find('.product-name').html('-');
|
||||
table.find('.product-price').html('-');
|
||||
table.find('.product-number').html('-');
|
||||
table.find('.product-barcode').html('-');
|
||||
table.find('.product-stock').html('-');
|
||||
table.find('.product-price').html('-');
|
||||
table.find('.product-sale-price').html('-');
|
||||
table.find("#productsaleform-count").val(1);
|
||||
table.find('#productsaleform-id_product').val('');
|
||||
table.find('#productsaleform-id_account').val('');
|
||||
}
|
||||
|
||||
function applyProduct(product){
|
||||
$('#productsaleform-id_product').val(product.id_product);
|
||||
$('.product-name').html(product.name);
|
||||
$('.product-sale-price').html(product.sale_price);
|
||||
$('.product-number').html(product.product_number);
|
||||
$('.product-barcode').html(product.barcode);
|
||||
$('.product-stock').html(product.stock);
|
||||
$('#productsaleform-id_account').val(product.id_account);
|
||||
var table;
|
||||
table = $('.table-product');
|
||||
table.find('#productsaleform-id_product').val(product.id_product);
|
||||
table.find('.product-name').html(product.name);
|
||||
table.find('.product-sale-price').html(product.sale_price);
|
||||
table.find('.product-number').html(product.product_number);
|
||||
table.find('.product-barcode').html(product.barcode);
|
||||
table.find('.product-stock').html(product.stock);
|
||||
table.find('#productsaleform-id_account').val(product.id_account);
|
||||
|
||||
}
|
||||
|
||||
@ -159,12 +180,22 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
function addBehaviourBtnSellAndAppendToBill(){
|
||||
$('#btn_sell_append').on('click',submitSell);
|
||||
$('#btn_sell_append').on('click',submitSellAndAppend);
|
||||
}
|
||||
|
||||
function submitSell(){
|
||||
$('#productsaleform-append_to_sold_list').val('');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
function submitSellAndAppend(){
|
||||
$('#productsaleform-append_to_sold_list').val('append');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
|
||||
|
||||
function refreshSoldUseritems(){
|
||||
$('.sold-items-container').transferList('option','transfers' , app.defaults.sold_items );
|
||||
}
|
||||
|
||||
function addBehaviorAjaxSubmit(){
|
||||
|
||||
@ -188,6 +219,9 @@ function ProductSell(o){
|
||||
refreshCalculatedValues();
|
||||
$("#filter_text").val('');
|
||||
setFocus();
|
||||
app.defaults.sold_items = response.transfers;
|
||||
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
||||
|
||||
}else if ( response.code == 'invalid'){
|
||||
if ( response.errors ){
|
||||
$.each(response.errors, function (key, value){
|
||||
@ -206,4 +240,13 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
|
||||
function createUserSoldItemsTable(){
|
||||
console.info( app.defaults.sold_items );
|
||||
$('.sold-items-container').transferList({
|
||||
'transfers' : app.defaults.sold_items
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -6,29 +6,56 @@ $.widget( "fitness.transferList", {
|
||||
{ 'label' : 'Ár' },
|
||||
{ 'label' : 'Db' },
|
||||
{ 'label' : 'Összesen' },
|
||||
],
|
||||
footers: [
|
||||
{
|
||||
'label' : 'Összesen',
|
||||
'total' : function(transfers){
|
||||
var totals;
|
||||
totals = 0;
|
||||
for ( var i = 0; i < transfers.length ; i++ ){
|
||||
totals += transfers[i].money;
|
||||
}
|
||||
return totals;
|
||||
},
|
||||
'count' : function(transfers){
|
||||
var totals;
|
||||
totals = 0;
|
||||
for ( var i = 0; i < transfers.length ; i++ ){
|
||||
totals += transfers[i].count;
|
||||
}
|
||||
return totals;
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
_create: function() {
|
||||
var o;
|
||||
o = this.options;
|
||||
this._refresh();
|
||||
},
|
||||
_refresh: function(){
|
||||
var s;
|
||||
s = this._render('table',{ 'columns' : this.options.columns });
|
||||
s = this._render('table',{ 'columns' : this.options.columns, 'transfers' : this.options.transfers,'footer': this.options.footers });
|
||||
this.element.html(s);
|
||||
},
|
||||
|
||||
_render: function(template,params){
|
||||
var s;
|
||||
var columsn;
|
||||
var transfer;
|
||||
var footer;
|
||||
s = "";
|
||||
switch(template){
|
||||
case 'table':
|
||||
s += this._render('openTable', {});
|
||||
s += this._render('header', { 'columns' : params.columns });
|
||||
s += this._render('closeTable', {});
|
||||
s += this._render('header', { 'columns' : params.columns });
|
||||
s += this._render('body' , { 'transfers' : params.transfers });
|
||||
s += this._render('footer' , { 'transfers' : params.transfers ,'footers': this.options.footers});
|
||||
s += this._render('closeTable', { });
|
||||
break;
|
||||
case 'openTable':
|
||||
s += '<table class="table table-bordered table-striped">';
|
||||
s += '<table class="table table-bordered table-striped table-transfers">';
|
||||
break;
|
||||
case 'closeTable':
|
||||
s += '</table>';
|
||||
@ -48,17 +75,70 @@ $.widget( "fitness.transferList", {
|
||||
break;
|
||||
case 'body':
|
||||
s += '<tbody>';
|
||||
for( var i = 0; i < transfers.length; i++){
|
||||
|
||||
for( var i = 0; i < params.transfers.length; i++){
|
||||
s += this._render('row', { 'transfer' : params.transfers[i] })
|
||||
}
|
||||
s += '</tbody>';
|
||||
break;
|
||||
case 'row':
|
||||
|
||||
transfer = params.transfer;
|
||||
s += '<tr>';
|
||||
s += '<td class="product-name">';
|
||||
s += transfer.product_name;
|
||||
s += '</td>';
|
||||
s += '<td class="sale-price">';
|
||||
s += transfer.item_price;
|
||||
s += '</td>';
|
||||
s += '<td class=\'product-count\' >';
|
||||
s += transfer.count;
|
||||
s += '</td>';
|
||||
s += '<td class=\'product-money\' >';
|
||||
s += transfer.money;
|
||||
s += '</td>';
|
||||
s += '</tr>';
|
||||
break;
|
||||
case 'footer':
|
||||
s += "<tfoot>";
|
||||
for ( var i = 0; i < params.footers.length; i++ ){
|
||||
footer = params.footers[i];
|
||||
s += "<tr class='warning' >";
|
||||
s += "<th class='product-name'>";
|
||||
s += footer.label;
|
||||
s += "</th>";
|
||||
s += "<td class=\"sale-price\">";
|
||||
s += "</td>";
|
||||
s += "<td class=\'product-count\' >";
|
||||
s += footer.count( params.transfers );
|
||||
s += "</td>";
|
||||
s += "<td class=\'product-money\' >";
|
||||
s += footer.total( params.transfers );
|
||||
s += "</td>";
|
||||
s += "</tr>";
|
||||
}
|
||||
s += "</tfoot>";
|
||||
break;
|
||||
}
|
||||
|
||||
return s;
|
||||
},
|
||||
_setOption: function (key, value) {
|
||||
var self = this,
|
||||
prev = this.options[key],
|
||||
fnMap = {
|
||||
'transfers': function () {
|
||||
self._refresh();
|
||||
},
|
||||
};
|
||||
|
||||
// base
|
||||
this._super(key, value);
|
||||
|
||||
if (key in fnMap) {
|
||||
fnMap[key]();
|
||||
|
||||
// Fire event
|
||||
// this._triggerOptionChanged(key, prev, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user