Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- "use strict";
- //Make the dashboard widgets sortable Using jquery UI
- $(".connectedSortable").sortable({
- placeholder: "sort-highlight",
- connectWith: ".connectedSortable",
- handle: ".box-header, .nav-tabs",
- forcePlaceholderSize: true,
- zIndex: 999999
- }).disableSelection();
- $(".connectedSortable .box-header, .connectedSortable .nav-tabs-custom").css("cursor", "move");
- });
- window.onkeydown = function(e) {
- if($('#barcode-input-inventory').length > 0){
- if(e.ctrlKey && e.shiftKey && e.keyCode === 192) {
- var input = $("#barcode-input-inventory");
- input.val("");
- input.focus();
- }
- }else{
- if(e.ctrlKey && e.shiftKey && e.keyCode === 192) {
- var input = $("#barcode-input");
- input.val("");
- input.focus();
- }
- }
- };
- $("document").ready(function() {
- $(document).on("keydown", '#barcode-input, #barcode-input-inventory', function(e) {
- if(e.ctrlKey && e.keyCode === 89) {
- sendCode(e);
- }
- });
- $(document).on("click", '#barcode-button', function(e) {
- var e = jQuery.Event("keydown");
- e.keyCode = 89;
- e.ctrlKey = true;
- $('#barcode-input').trigger(e);
- });
- $('#barcode-input').on('keydown',function (e) {
- if(e.keyCode === 13) {
- var e = jQuery.Event("keydown");
- e.keyCode = 89;
- e.ctrlKey = true;
- $('#barcode-input').trigger(e);
- }
- });
- function sendCode(e){
- url = ACTION_SALE;
- inventory = $('.inventory-item').length;
- replace = $('#replace-inventory').length;
- if($('#'+e.target.value).length){
- $.notify({
- message: 'Этот инвентарь уже добавлен'
- },{
- z_index: '1051',
- type: 'danger'
- });
- return false;
- }
- data = {'barcode': e.target.value};
- if(inventory){
- url = ACTION_SALE+'?index='+inventory;
- }
- if(replace){
- url = ACTION_INVENTORY_TO_REPLACE;
- tariff_id = $('.replace-inventory-button').attr('data-rent-tariff');
- order_id = $('.replace-inventory-button').attr('data-rent-order');
- data = {'barcode': e.target.value, 'tariff' : tariff_id, 'order' : order_id};
- }
- $.ajax({
- url: url,
- type: "POST",
- data: data,
- success: function(data){
- $('#formLoader').hide();
- if(data.status){
- $('#modal').modal('toggle');
- if(data.status === false) {
- $.notify({
- message: data.message
- }, {
- type: 'danger'
- });
- }else{
- $.notify({
- message: data.message
- }, {
- type: 'success'
- });
- }
- }else{
- if(inventory){
- $(".inventory-box").append(data);
- $('.started_at').clockpicker({
- autoclose: true,
- donetext: 'ок'
- });
- }else{
- $("#modalBody").html(data);
- $('#modal').modal('show');
- }
- }
- },
- error: function() {
- $('#modal').modal('toggle');
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- }
- $('#select-tariff-type').on('change', function () {
- inputTypes = jQuery.parseJSON($('#input-types').html());
- inputType = inputTypes[$(this).val()];
- timeInput = $('#set_time');
- timeInput.prop('disabled',false);
- if(inputType === 'datetime'){
- timeInput.attr('type', 'text');
- timeInput.clockpicker({
- autoclose: true,
- donetext: 'ок'
- });
- }else{
- timeInput.attr('type', 'number');
- timeInput.clockpicker('remove');
- }
- });
- $(document).on('submit', '#ticket-sale-form, #barcode-form, #inventory-sale-form, #ticket-sold-form', function (e) {
- url = $(this).attr('action');
- $.ajax({
- url: url,
- type: "POST",
- data: $(this).serialize(),
- success: function(data){
- $('#modal').modal('toggle');
- status = data.status === true ? 'success' : 'danger';
- message = data.message ? data.message : 'Операция выполнена успешно.';
- $.notify({
- message: message
- },{
- type: status
- });
- $.pjax.reload({container:'#pjax-barcode'});
- $.pjax.reload({container:'#pjax-inventory'});
- },
- error: function() {
- $('#modal').modal('toggle');
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- e.preventDefault();
- return false;
- });
- $(document).on('click','.action-button', function () {
- url = $(this).attr('href');
- $.ajax({
- url: url,
- type: "POST",
- success: function(data){
- if(data.status){
- status = data.status === true ? 'success' : 'danger';
- message = data.message ? data.message : 'Операция выполнена успешно.';
- $.notify({
- message: message
- },{
- type: status
- });
- }else{
- $("#modalBody").html(data);
- $('#modal').modal('show');
- }
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- return false;
- });
- $(document).on('click','#remove-inventory-tariff', function () {
- boxId = $(this).attr('data-tariff-index');
- $("#inventory-tariff-box-"+boxId).remove();
- return false;
- });
- $(document).on('click','#remove-inventory', function () {
- boxId = $(this).attr('data-inventory-id');
- $(".item-"+boxId).remove();
- if($('#w0').length > 0){
- $('select option[value="' + boxId + '"]').prop("selected", false)
- $("#w0").trigger('change');
- }else{
- if($('.inventory-item').length < 1){
- $("#modalBody").html('');
- $('#modal').modal('toggle');
- }
- }
- return false;
- });
- $(document).on('click','#add-inventory-tariff', function () {
- index = $('.inventory-tariff-box').length;
- $('.tariffs-box').append(inventoryTariffTemplate(index));
- return false;
- });
- $(document).on('change','.tariff-radio', function () {
- price = $(this).attr('data-price');
- priceInput = $('#'+$(this).attr('data-input-id'));
- priceInput.val(price);
- priceInput.prop('disabled', false);
- setDelayPrice();
- });
- $(document).on('change paste keyup','.tariff-price-input', function () {
- setDelayPrice();
- });
- $(document).keypress(function(e) {
- if(e.which == 13 && $('#modal').is(':visible')) {
- $(":focus").each(function() {
- if(this.id === 'modal'){
- $('#modal form').submit();
- }
- });
- }
- });
- $(document).on('click','.return-inventory-button', function () {
- rest = $(this).attr('data-rest-time');
- inventoryId = $(this).attr('data-rent-inventory');
- if(rest < 0){
- delayOfTimeTemplate(rest,inventoryId);
- }else{
- returnInventory(inventoryId);
- }
- });
- $(document).on('click','.cancel-inventory-sale-button', function () {
- inventoryId = $(this).attr('data-rent-inventory');
- $.ajax({
- url: CANCEL_SELL_INVENTORY_TEMPLATE,
- type: "POST",
- data: { 'id': inventoryId},
- success: function(data){
- $('#modalBody').html(data);
- $('#cancel-sale').focus();
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- });
- $(document).on('click','.replace-inventory-button', function () {
- $('.inventory-item-is-use').attr('id','replace-inventory')
- $('#formLoader p').html('Отсканируйте новый инвентарь.');
- $('#formLoader').show();
- });
- $(document).on('click','.add-surcharge-to-inventory-button', function () {
- id = $(this).attr('data-rent-inventory');
- sum = $('#surcharge').val();
- returnInventoryWithPay(id,sum);
- });
- $(document).on('click','.cancel-sell-inventory-button', function () {
- id = $(this).attr('data-rent-inventory');
- message = $('#cancel-sale').val();
- cancelInventorySale(id,message);
- });
- $(document).on('click','.cancel-surcharge-to-inventory-button', function () {
- id = $(this).attr('data-rent-inventory');
- returnInventory(id)
- });
- $(document).on('click', '#add-order', function () {
- $('#modalAddInventory').modal('show');
- $('#s2-togall-w0').hide();
- });
- $('#w0').on('select2:select', function (e) {
- var data = e.params.data;
- setNewInventory(data.id)
- });
- $('#w0').on('select2:unselect', function (e) {
- var data = e.params.data;
- $('.item-'+data.id).remove();
- });
- function setNewInventory(id) {
- $.get( ACTION_SALE+'?inv_id='+id, function(data) {
- $(".inventory-box-manual").append(data);
- $('.started_at').clockpicker({
- autoclose: true,
- donetext: 'ок'
- });
- }).fail(function() {
- $('#modalAddInventory').modal('toggle');
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- });
- $('#formLoader').hide();
- }
- function setDelayPrice() {
- var sum = 0;
- $('.tariff-price-input').each(function(){
- sum += parseFloat(this.value);
- });
- $('#delay-price-input').val(sum)
- }
- function inventoryTariffTemplate(index) {
- return '<div class="row inventory-tariff-box" id="inventory-tariff-box-'+index+'">' +
- '<div class="col-sm-5">' +
- '<div class="form-group field-rentinventorytariff-duration-'+index+'">' +
- '<label class="control-label" for="rentinventorytariff-duration-'+index+'">Длительность</label>' +
- '<input type="number" id="rentinventorytariff-duration-'+index+'" class="form-control" name="RentInventoryTariff['+index+'][duration]" 0-class="col-sm-5">' +
- '<p class="help-block help-block-error"></p>' +
- '</div></div>' +
- '<div class="col-sm-5">' +
- '<div class="form-group field-rentinventorytariff-price-'+index+'">' +
- '<label class="control-label" for="rentinventorytariff-price-'+index+'">Цена</label>' +
- '<input type="number" id="rentinventorytariff-price-'+index+'" class="form-control" name="RentInventoryTariff['+index+'][price]" 0-class="col-sm-5">' +
- '<p class="help-block help-block-error"></p>' +
- '</div></div>' +
- '<div class="col-sm-2">' +
- '<div>' +
- '<a id="remove-inventory-tariff" class="btn btn-warning" href="/inventory/#" data-tariff-index="'+index+'">Х</a></div>' +
- ' </div>' +
- '</div>';
- }
- function returnInventory(id) {
- $.ajax({
- url: RETURN_INVENTORY,
- type: "POST",
- data: {'id' : id},
- success: function(data){
- $('#modal').modal('toggle');
- status = data.status === true ? 'success' : 'danger';
- message = data.message ? data.message : 'Операция выполнена успешно.';
- $.notify({
- message: message
- },{
- type: status
- });
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- }
- function delayOfTimeTemplate(rest,inventoryId){
- $.ajax({
- url: DELAY_OF_TIME,
- type: "POST",
- data: {'rest' : rest, 'id': inventoryId},
- success: function(data){
- $('#modalBody').html(data);
- $('#surcharge').focus();
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- }
- function returnInventoryWithPay(id,sum){
- $.ajax({
- url: RETURN_INVENTORY_WITH_PAY,
- type: "POST",
- data: {'sum' : sum, 'id': id},
- success: function(data){
- $('#modal').modal('toggle');
- status = data.status === true ? 'success' : 'danger';
- message = data.message ? data.message : 'Операция выполнена успешно.';
- $.notify({
- message: message
- },{
- type: status
- });
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- }
- function cancelInventorySale(id,message){
- $.ajax({
- url: CANCEL_SELL_INVENTORY,
- type: "POST",
- data: { 'id': id, 'message' : message},
- success: function(data){
- $('#modal').modal('toggle');
- status = data.status === true ? 'success' : 'danger';
- message = data.message ? data.message : 'Операция выполнена успешно.';
- $.notify({
- message: message
- },{
- type: status
- });
- },
- error: function() {
- $.notify({
- message: 'Произошла ошибка при выполнении операции.'
- },{
- type: 'danger'
- });
- }
- });
- }
- $('#modal').on('hidden.bs.modal', function () {
- $("#modalBody").html('');
- });
- $('#modalAddInventory').on('hidden.bs.modal', function () {
- $(".inventory-box-manual").html('');
- $("#w0").val('').trigger('change');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement