From 2e3a8d53ca278fa50822e742b2e7e3badf1541f9 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sun, 28 Feb 2016 15:48:30 +0100 Subject: [PATCH] Fix hide reception cart - add property user_cart_on - add property product_sale_default_focus - add property ticket_create-price_editable - add discount product/ticket enabled --- backend/components/AdminMenuStructure.php | 2 +- backend/views/discount/_form.php | 5 +- backend/views/discount/index.php | 9 ++ backend/views/discount/view.php | 8 ++ changelog.txt | 5 + common/components/Helper.php | 12 ++ common/config/params.php | 19 +-- common/models/Discount.php | 24 +++- ...__add__columns__product_on__ticket__on.php | 33 ++++++ frontend/controllers/ProductController.php | 2 +- frontend/controllers/TicketController.php | 2 +- frontend/views/contract/_make_contract.php | 2 +- frontend/views/product/_sale_form.php | 3 + frontend/views/product/sale.php | 6 + frontend/views/ticket/_form.php | 18 ++- frontend/views/ticket/create.php | 7 +- frontend/web/js/product.sell.js | 108 ++++-------------- frontend/web/js/ticket.sell.js | 53 ++------- 18 files changed, 175 insertions(+), 143 deletions(-) create mode 100644 console/migrations/m160228_111209_alter__table__discount__add__columns__product_on__ticket__on.php diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index d33943c..55ca0a3 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -66,7 +66,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ]; $items[] = ['label' => 'Kulcsok', 'url' =>['/key/index']]; // $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; - $this->menuItems[] = ['label' => 'Törszadatok', 'url' =>$this->emptyUrl, + $this->menuItems[] = ['label' => 'Törzsadatok', 'url' =>$this->emptyUrl, 'items' => $items ]; diff --git a/backend/views/discount/_form.php b/backend/views/discount/_form.php index 971db92..adcbea7 100644 --- a/backend/views/discount/_form.php +++ b/backend/views/discount/_form.php @@ -19,8 +19,11 @@ use common\models\Discount; field($model, 'type')->dropDownList(Discount::types()) ?> - field($model, 'value')->textInput() ?> + + field($model, 'product_enabled')->checkbox() ?> + + field($model, 'ticket_enabled')->checkbox() ?>
diff --git a/backend/views/discount/index.php b/backend/views/discount/index.php index 1307d05..053e289 100644 --- a/backend/views/discount/index.php +++ b/backend/views/discount/index.php @@ -33,8 +33,17 @@ $this->params['breadcrumbs'][] = $this->title; [ 'attribute' => 'type', 'value' => 'typeHuman', + ], + [ + 'attribute' => 'ticket_enabled', + 'value' => 'ticketEnabledHuman', + ], + [ + 'attribute' => 'product_enabled', + 'value' => 'procutEnabledHuman', ], 'value', + 'created_at:datetime', 'updated_at:datetime', diff --git a/backend/views/discount/view.php b/backend/views/discount/view.php index f1df9b9..24c0718 100644 --- a/backend/views/discount/view.php +++ b/backend/views/discount/view.php @@ -34,6 +34,14 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'type', 'value' => $model->typeHuman ], + [ + 'attribute' => 'product_enabled', + 'value' => $model->getProcutEnabledHuman() + ], + [ + 'attribute' => 'ticket_enabled', + 'value' => $model->getTicketEnabledHuman() + ], // 'status', // 'type', 'value', diff --git a/changelog.txt b/changelog.txt index a555e74..cc75a75 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +-0.0.42 + - add property user_cart_on + - add property product_sale_default_focus + - add property ticket_create_price_editable + - add discount visibility for ticket/product -0.0.42 - add detsta import improvements - add procurement/create-product , translations, redirects diff --git a/common/components/Helper.php b/common/components/Helper.php index ccdc969..e96bc1e 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -278,6 +278,13 @@ class Helper { return \Yii::$app->params ['company'] == 'movar'; } + public static function isUserCartOn() { + return \Yii::$app->params ['user_cart_on'] == true; + } + + public static function getProductSaleDefaultFocus() { + return \Yii::$app->params ['product_sale_default_focus'] ; + } public static function isProductVisibilityAccount() { return \Yii::$app->params ['product_visiblity'] == 'account'; } @@ -298,6 +305,11 @@ class Helper { return \Yii::$app->params ['reception_visibility_days'] ; } + + public static function isTicketCreatePriceEditable() { + return \Yii::$app->params ['ticket_create_price_editable'] == true ; + } + public static function getRealUserIp() { $client = @$_SERVER ['HTTP_CLIENT_IP']; $forward = @$_SERVER ['HTTP_X_FORWARDED_FOR']; diff --git a/common/config/params.php b/common/config/params.php index 8003b7d..b7cb94a 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.42', + 'version' => 'v0.0.43', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global @@ -30,12 +30,17 @@ return [ * */ 'reception_visibility_days' => 3, 'backend_skin' => 'skin-red', //skin-green + /**User cart module on/off*/ + 'user_cart_on' => true, /** - * if products in carts are visible for everyone or only for the user - * possible values : - * - user: a felhasználó csak azokat a termékeket látja a kosrába, amiket ő rakott bele - * - global: a felhasználó minden kosrában lévő terméket lát, még azokat is , amiket nem ő rakott bele - * - **/ + * a termék eladás oldalon hol legyen az alaéprtelmezett focus + * a vonalkód mezőn vagy az autocomplete mezőn + barcode | autocomplete */ + 'product_sale_default_focus' => 'barcode', + /** + * Bérlet eladásnál módosítható e az ár + * */ + 'ticket_create_price_editable' => true, + ]; diff --git a/common/models/Discount.php b/common/models/Discount.php index 4aeea95..f5cc1f9 100644 --- a/common/models/Discount.php +++ b/common/models/Discount.php @@ -14,6 +14,8 @@ use yii\helpers\ArrayHelper; * @property integer $status * @property integer $type * @property integer $value + * @property integer $product_enabled + * @property integer $ticket_enabled * @property string $created_at * @property string $updated_at */ @@ -51,7 +53,7 @@ class Discount extends \yii\db\ActiveRecord { return [ [['name','value'], 'required'], - [['status', 'type', 'value'], 'integer'], + [['status', 'type', 'value','product_enabled','ticket_enabled'], 'integer'], [['name'], 'string', 'max' => 64] ]; } @@ -69,6 +71,8 @@ class Discount extends \yii\db\ActiveRecord 'value' => Yii::t('common/discount', 'Value'), 'created_at' => Yii::t('common/discount', 'Created At'), 'updated_at' => Yii::t('common/discount', 'Updated At'), + 'product_enabled' => "Termékre adható", + 'ticket_enabled' => "Bérletre adható", ]; } @@ -104,10 +108,28 @@ class Discount extends \yii\db\ActiveRecord return $result; } + public function getProcutEnabledHuman(){ + return $this->product_enabled == 1 ? 'Igen' : 'Nem'; + } + + public function getTicketEnabledHuman(){ + return $this->ticket_enabled == 1 ? 'Igen' : 'Nem'; + } + public static function read(){ return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE ])->all(); } + + public static function readProductDiscounts(){ + return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE , 'product_enabled' => 1 ])->all(); + } + + + public static function readTicketDiscounts(){ + return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE , 'ticket_enabled' => 1 ])->all(); + } + /** * @param integer $money * @param common\models\Discount $discount diff --git a/console/migrations/m160228_111209_alter__table__discount__add__columns__product_on__ticket__on.php b/console/migrations/m160228_111209_alter__table__discount__add__columns__product_on__ticket__on.php new file mode 100644 index 0000000..5b96b6b --- /dev/null +++ b/console/migrations/m160228_111209_alter__table__discount__add__columns__product_on__ticket__on.php @@ -0,0 +1,33 @@ +addColumn("discount", "product_enabled", "int default 0"); + $this->addColumn("discount", "ticket_enabled", "int default 0"); + + $this->execute("update discount set product_enabled = 1 , ticket_enabled = 1;"); + } + + public function down() + { + echo "m160228_111209_alter__table__discount__add__columns__product_on__ticket__on cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index 0033c22..56e6c21 100644 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -95,7 +95,7 @@ class ProductController extends Controller { $accounts = Account::read (); - $discounts = Discount::read (); + $discounts = Discount::readProductDiscounts(); $user = User::findOne ( Yii::$app->user->id ); diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php index 9260c96..a0ebd98 100644 --- a/frontend/controllers/TicketController.php +++ b/frontend/controllers/TicketController.php @@ -104,7 +104,7 @@ class TicketController extends FrontendController $model = new TicketCreate(); - $discounts = Discount::read(); + $discounts = Discount::readTicketDiscounts(); $ticketTypes = TicketType::read(null, null); diff --git a/frontend/views/contract/_make_contract.php b/frontend/views/contract/_make_contract.php index 87b1ff9..278fe3c 100644 --- a/frontend/views/contract/_make_contract.php +++ b/frontend/views/contract/_make_contract.php @@ -20,7 +20,7 @@ use common\models\Discount; $types = TicketType::findAll(['status' => TicketType::STATUS_ACTIVE ,'installment_enabled' => '1']); $types = HtmlHelper::mkTicketTypeOptions($types); - $discounts = Discount::read(); + $discounts = Discount::readTicketDiscounts(); $discounts = ['' => ''] + HtmlHelper::mkDiscountOptions($discounts); ?> diff --git a/frontend/views/product/_sale_form.php b/frontend/views/product/_sale_form.php index 4c4a046..2609f36 100644 --- a/frontend/views/product/_sale_form.php +++ b/frontend/views/product/_sale_form.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\ArrayHelper; use common\models\Transfer; +use common\components\Helper; /* @var $this yii\web\View */ /* @var $model frontend\models\ProductSaleForm */ @@ -110,7 +111,9 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name' 'btn btn-danger btn-block', 'id' => 'btn_sell'] );?>
+ 'btn btn-success btn-block', 'id' => 'btn_sell_append'] );?> +
card) ){ $options['discounts'] = Discount::modelsToArray($discounts); $options['id_account'] = Account::readDefault(); +$options['product_sale_default_focus'] = Helper::getProductSaleDefaultFocus(); +$options['user_cart_on'] = Helper::isUserCartOn(); + $this->registerJs ( 'new ProductSell( '. json_encode($options).');' ); @@ -97,7 +101,9 @@ $this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale'); isCardWithCustomer() ){ ?> render('_customer_cart' , ['model' => $model]) ?> + render('_user_cart' ) ?> +
diff --git a/frontend/views/ticket/_form.php b/frontend/views/ticket/_form.php index 7ff151f..6a70e0d 100644 --- a/frontend/views/ticket/_form.php +++ b/frontend/views/ticket/_form.php @@ -6,6 +6,7 @@ use frontend\components\HtmlHelper; use kartik\widgets\DatePicker; use common\models\Account; use common\models\Transfer; +use common\components\Helper; /* @var $this yii\web\View */ /* @var $model common\models\Ticket */ @@ -65,7 +66,15 @@ use common\models\Transfer; field($model, 'max_usage_count')->input('number') ?> - field($model, 'price_brutto')->input('number') ?> + field($model, 'price_brutto')->input('number' ); + }else{ + echo $form->field($model, 'price_brutto')->input('number' ,['readonly' => true] ); + + } + + ?> field($model, 'comment')->textarea(['maxlength' => true]) ?> @@ -74,7 +83,12 @@ use common\models\Transfer; 'btn btn-danger btn-block', 'id' => 'btn_sell'] );?>
- 'btn btn-success btn-block', 'id' => 'btn_add_to_user_cart'] );?> + + 'btn btn-success btn-block', 'id' => 'btn_add_to_user_cart'] ); + } + ?>
registerJs ( 'new TicketSell( '. json_encode($options).');' ); isCardWithCustomer() ){ ?> render('_customer_cart' ,['model' => $receptionForm]) ?> - render('_user_cart' ) ?> + render('_user_cart' ) ; + } + ?>
diff --git a/frontend/web/js/product.sell.js b/frontend/web/js/product.sell.js index f02db5e..d437e37 100644 --- a/frontend/web/js/product.sell.js +++ b/frontend/web/js/product.sell.js @@ -34,6 +34,12 @@ function ProductSell(o){ url_pay_transaction : '', value_number: '', name_number: '', + user_cart_on: true, + //if enter pressed in count field, what to submet: 'paid' or 'add_to_user_cart' action + product_count_enter_action: 'user_cart', + //barcode or autocomplete + product_sale_default_focus: 'barcode', + }; @@ -53,10 +59,7 @@ function ProductSell(o){ createCarts(); - addPayoutButtons(); - productChanged(); -// addDocumentKeypressedListener(); initAutocomplete(); disalbeMousewheelSpinOnNumberInput(); @@ -68,13 +71,6 @@ function ProductSell(o){ }); } - /** - * payout out user or customer cart - * */ - function addPayoutButtons(){ -// addBehaviourPayoutUserCart(); -// addBehaviourPayoutCustomerCart(); - } /** * display user and customer cart on page load * */ @@ -111,41 +107,6 @@ function ProductSell(o){ $("#productsaleform-id_discount").change(refreshCalculatedValues); } - function addDocumentKeypressedListener(){ - $( document ).keypress(function( event ) { - - var tag = event.target.tagName.toLowerCase(); - if ( tag != 'input' && tag != 'textarea') { - - resetSequenceIfToMuchTimePassedOrEnterWasPressed(event); - - if ( event.which == 13 ) { - app.enterPressed = 1; - $( document ).trigger( "wordtyped", [ { originalEvent: event, 'word': app.seq } ] ); - }else { - appendCharToSeq(event); - } - } - }); - - $( document ).on( "wordtyped", function( event, data ) { - var word; - word = data.word; - if ( word.length > 0){ - if ( word.length >= 6 && word.length <= 9 ){ - //lookupuser - }else{ - $("#filter_text").val(data.word); - _lookupProduct(data.word); - } - - } - }); - - } - - - function resetSequenceIfToMuchTimePassedOrEnterWasPressed(){ var prevDate, timePassed; prevDate= app.keyDate; @@ -181,7 +142,11 @@ function ProductSell(o){ * set the focus for text input #filter_text * */ function setFocus(){ - $("#filter_text").focus(); + if ( app.defaults.product_sale_default_focus == 'barcode'){ + $("#filter_text").focus(); + }else{ + $("#product_search").focus(); + } } @@ -210,7 +175,18 @@ function ProductSell(o){ if ( event.which == 13 ) { event.preventDefault(); event.stopImmediatePropagation(); - submitSellAndAppend(); + + if ( app.defaults.user_cart_on ){ + if ( app.defaults.product_count_enter_action == 'user_cart'){ + submitSellAndAppend(); + }else{ + submitSell(); + } + }else{ + submitSell(); + } + + } }); } @@ -445,44 +421,6 @@ function ProductSell(o){ $(app.defaults.selector_customer_cart ).transferList( 'option', 'transfers' , app.defaults.customer_cart ); } - function addBehaviourPayoutUserCart( ){ - $( app.defaults.selector_btn_pay_user_cart ).on('click',function(){ - - $.ajax({ - url: app.defaults.url_pay_user_cart, - type: 'post', - data: {}, - success: function (response) { - if ( response.code == 'success'){ - app.defaults.user_cart = response.transfers; - refreshUserCart(); - $.notify(app.defaults.message_paid, { 'type' : 'success' }); - } - } - } - ); - }); - } - function addBehaviourPayoutCustomerCart( ){ - $( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){ - $.ajax({ - url: app.defaults.url_pay_customer_card, - type: 'post', - data: {}, - success: function (response) { - if ( response.code == 'success'){ - app.defaults.customer_cart = response.customer_cart; - refreshCustomerCart(); - } - $.notify(response.message, { 'type' : response.code }); - }, - error: function(){ - alert('Hiba történt'); - } - } - ); - }); - } function createUserCartTable(){ $(app.defaults.selector_user_cart).transferList({ diff --git a/frontend/web/js/ticket.sell.js b/frontend/web/js/ticket.sell.js index 6d6903a..6930182 100644 --- a/frontend/web/js/ticket.sell.js +++ b/frontend/web/js/ticket.sell.js @@ -50,6 +50,8 @@ function TicketSell(o){ url_pay_transaction: '', discounts : [], discount: null, + //if user cart module is on or off + user_cart_on: true }; @@ -61,7 +63,7 @@ function TicketSell(o){ addBehaviourDiscountChangedListener(); useDefaults(); createCarts(); - addPayoutButtons(); +// addPayoutButtons(); addSellButtons(); // addBehaviourBtnCartPaid(); } @@ -82,16 +84,19 @@ function TicketSell(o){ /** * payout out user or customer cart * */ + /* function addPayoutButtons(){ // addBehaviourPayoutUserCart(); // addBehaviourPayoutCustomerCart(); } - + */ /** * display user and customer cart on page load * */ function createCarts(){ - createUserCartTable(); + if ( app.defaults.user_cart_on ){ + createUserCartTable(); + } createCustomerCartTable(); } @@ -117,7 +122,9 @@ function TicketSell(o){ } function addSellButtons(){ - addBehaviourBtnSellAndAppendToUserCart(); + if ( app.defaults.user_cart_on ){ + addBehaviourBtnSellAndAppendToUserCart(); + } addBehaviourBtnAddToCustomerCart(); addBehaviourBtnSell(); } @@ -148,44 +155,6 @@ function TicketSell(o){ $('#btn_sell').on('click',submitSell); } - function addBehaviourPayoutUserCart( ){ -// $( app.defaults.selector_btn_pay_user_cart ).on('click',function(){ -// -// $.ajax({ -// url: app.defaults.url_pay_user_cart, -// type: 'post', -// data: {}, -// success: function (response) { -// if ( response.code == 'success'){ -// app.defaults.user_cart = response.transfers; -// refreshUserCart(); -// $.notify(app.defaults.message_paid, { 'type' : 'success' }); -// } -// } -// } -// ); -// }); - } - function addBehaviourPayoutCustomerCart( ){ -// $( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){ -// $.ajax({ -// url: app.defaults.url_pay_customer_card, -// type: 'post', -// data: {}, -// success: function (response) { -// if ( response.code == 'success'){ -// app.defaults.customer_cart = response.customer_cart; -// refreshCustomerCart(); -// } -// $.notify(response.message, { 'type' : response.code }); -// }, -// error: function(){ -// alert('Hiba történt'); -// } -// } -// ); -// }); - } function addBehaviourTypeChangedListener(){