Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.49 KB | None | 0 0
  1. $(function() {
  2. "use strict";
  3.  
  4. //Make the dashboard widgets sortable Using jquery UI
  5. $(".connectedSortable").sortable({
  6. placeholder: "sort-highlight",
  7. connectWith: ".connectedSortable",
  8. handle: ".box-header, .nav-tabs",
  9. forcePlaceholderSize: true,
  10. zIndex: 999999
  11. }).disableSelection();
  12. $(".connectedSortable .box-header, .connectedSortable .nav-tabs-custom").css("cursor", "move");
  13. });
  14.  
  15. window.onkeydown = function(e) {
  16. if($('#barcode-input-inventory').length > 0){
  17. if(e.ctrlKey && e.shiftKey && e.keyCode === 192) {
  18. var input = $("#barcode-input-inventory");
  19. input.val("");
  20. input.focus();
  21. }
  22. }else{
  23. if(e.ctrlKey && e.shiftKey && e.keyCode === 192) {
  24. var input = $("#barcode-input");
  25. input.val("");
  26. input.focus();
  27. }
  28. }
  29. };
  30. $("document").ready(function() {
  31. $(document).on("keydown", '#barcode-input, #barcode-input-inventory', function(e) {
  32. if(e.ctrlKey && e.keyCode === 89) {
  33. sendCode(e);
  34. }
  35. });
  36.  
  37. $(document).on("click", '#barcode-button', function(e) {
  38. var e = jQuery.Event("keydown");
  39. e.keyCode = 89;
  40. e.ctrlKey = true;
  41. $('#barcode-input').trigger(e);
  42. });
  43. $('#barcode-input').on('keydown',function (e) {
  44. if(e.keyCode === 13) {
  45. var e = jQuery.Event("keydown");
  46. e.keyCode = 89;
  47. e.ctrlKey = true;
  48. $('#barcode-input').trigger(e);
  49. }
  50. });
  51.  
  52. function sendCode(e){
  53. url = ACTION_SALE;
  54. inventory = $('.inventory-item').length;
  55. replace = $('#replace-inventory').length;
  56. if($('#'+e.target.value).length){
  57. $.notify({
  58. message: 'Этот инвентарь уже добавлен'
  59. },{
  60. z_index: '1051',
  61. type: 'danger'
  62. });
  63. return false;
  64. }
  65. data = {'barcode': e.target.value};
  66. if(inventory){
  67. url = ACTION_SALE+'?index='+inventory;
  68. }
  69. if(replace){
  70. url = ACTION_INVENTORY_TO_REPLACE;
  71. tariff_id = $('.replace-inventory-button').attr('data-rent-tariff');
  72. order_id = $('.replace-inventory-button').attr('data-rent-order');
  73. data = {'barcode': e.target.value, 'tariff' : tariff_id, 'order' : order_id};
  74. }
  75. $.ajax({
  76. url: url,
  77. type: "POST",
  78. data: data,
  79. success: function(data){
  80. $('#formLoader').hide();
  81. if(data.status){
  82. $('#modal').modal('toggle');
  83. if(data.status === false) {
  84. $.notify({
  85. message: data.message
  86. }, {
  87. type: 'danger'
  88. });
  89. }else{
  90. $.notify({
  91. message: data.message
  92. }, {
  93. type: 'success'
  94. });
  95. }
  96. }else{
  97. if(inventory){
  98. $(".inventory-box").append(data);
  99. $('.started_at').clockpicker({
  100. autoclose: true,
  101. donetext: 'ок'
  102. });
  103. }else{
  104. $("#modalBody").html(data);
  105. $('#modal').modal('show');
  106. }
  107. }
  108. },
  109. error: function() {
  110. $('#modal').modal('toggle');
  111. $.notify({
  112. message: 'Произошла ошибка при выполнении операции.'
  113. },{
  114. type: 'danger'
  115. });
  116. }
  117. });
  118. }
  119.  
  120. $('#select-tariff-type').on('change', function () {
  121. inputTypes = jQuery.parseJSON($('#input-types').html());
  122. inputType = inputTypes[$(this).val()];
  123. timeInput = $('#set_time');
  124. timeInput.prop('disabled',false);
  125. if(inputType === 'datetime'){
  126. timeInput.attr('type', 'text');
  127. timeInput.clockpicker({
  128. autoclose: true,
  129. donetext: 'ок'
  130. });
  131. }else{
  132. timeInput.attr('type', 'number');
  133. timeInput.clockpicker('remove');
  134. }
  135. });
  136.  
  137. $(document).on('submit', '#ticket-sale-form, #barcode-form, #inventory-sale-form, #ticket-sold-form', function (e) {
  138. url = $(this).attr('action');
  139. $.ajax({
  140. url: url,
  141. type: "POST",
  142. data: $(this).serialize(),
  143. success: function(data){
  144. $('#modal').modal('toggle');
  145. status = data.status === true ? 'success' : 'danger';
  146. message = data.message ? data.message : 'Операция выполнена успешно.';
  147. $.notify({
  148. message: message
  149. },{
  150. type: status
  151. });
  152. $.pjax.reload({container:'#pjax-barcode'});
  153. $.pjax.reload({container:'#pjax-inventory'});
  154. },
  155. error: function() {
  156. $('#modal').modal('toggle');
  157. $.notify({
  158. message: 'Произошла ошибка при выполнении операции.'
  159. },{
  160. type: 'danger'
  161. });
  162. }
  163. });
  164. e.preventDefault();
  165. return false;
  166. });
  167. $(document).on('click','.action-button', function () {
  168. url = $(this).attr('href');
  169. $.ajax({
  170. url: url,
  171. type: "POST",
  172. success: function(data){
  173. if(data.status){
  174. status = data.status === true ? 'success' : 'danger';
  175. message = data.message ? data.message : 'Операция выполнена успешно.';
  176. $.notify({
  177. message: message
  178. },{
  179. type: status
  180. });
  181. }else{
  182. $("#modalBody").html(data);
  183. $('#modal').modal('show');
  184. }
  185. },
  186. error: function() {
  187. $.notify({
  188. message: 'Произошла ошибка при выполнении операции.'
  189. },{
  190. type: 'danger'
  191. });
  192. }
  193. });
  194.  
  195. return false;
  196. });
  197.  
  198. $(document).on('click','#remove-inventory-tariff', function () {
  199. boxId = $(this).attr('data-tariff-index');
  200. $("#inventory-tariff-box-"+boxId).remove();
  201. return false;
  202. });
  203.  
  204. $(document).on('click','#remove-inventory', function () {
  205. boxId = $(this).attr('data-inventory-id');
  206. $(".item-"+boxId).remove();
  207. if($('#w0').length > 0){
  208. $('select option[value="' + boxId + '"]').prop("selected", false)
  209. $("#w0").trigger('change');
  210. }else{
  211. if($('.inventory-item').length < 1){
  212. $("#modalBody").html('');
  213. $('#modal').modal('toggle');
  214. }
  215. }
  216. return false;
  217. });
  218.  
  219. $(document).on('click','#add-inventory-tariff', function () {
  220. index = $('.inventory-tariff-box').length;
  221. $('.tariffs-box').append(inventoryTariffTemplate(index));
  222. return false;
  223. });
  224. $(document).on('change','.tariff-radio', function () {
  225. price = $(this).attr('data-price');
  226. priceInput = $('#'+$(this).attr('data-input-id'));
  227. priceInput.val(price);
  228. priceInput.prop('disabled', false);
  229. setDelayPrice();
  230. });
  231.  
  232. $(document).on('change paste keyup','.tariff-price-input', function () {
  233. setDelayPrice();
  234. });
  235.  
  236.  
  237. $(document).keypress(function(e) {
  238. if(e.which == 13 && $('#modal').is(':visible')) {
  239. $(":focus").each(function() {
  240. if(this.id === 'modal'){
  241. $('#modal form').submit();
  242. }
  243. });
  244. }
  245. });
  246. $(document).on('click','.return-inventory-button', function () {
  247. rest = $(this).attr('data-rest-time');
  248. inventoryId = $(this).attr('data-rent-inventory');
  249. if(rest < 0){
  250. delayOfTimeTemplate(rest,inventoryId);
  251. }else{
  252. returnInventory(inventoryId);
  253. }
  254.  
  255. });
  256.  
  257. $(document).on('click','.cancel-inventory-sale-button', function () {
  258. inventoryId = $(this).attr('data-rent-inventory');
  259.  
  260. $.ajax({
  261. url: CANCEL_SELL_INVENTORY_TEMPLATE,
  262. type: "POST",
  263. data: { 'id': inventoryId},
  264. success: function(data){
  265. $('#modalBody').html(data);
  266. $('#cancel-sale').focus();
  267. },
  268. error: function() {
  269. $.notify({
  270. message: 'Произошла ошибка при выполнении операции.'
  271. },{
  272. type: 'danger'
  273. });
  274. }
  275. });
  276. });
  277.  
  278. $(document).on('click','.replace-inventory-button', function () {
  279. $('.inventory-item-is-use').attr('id','replace-inventory')
  280. $('#formLoader p').html('Отсканируйте новый инвентарь.');
  281. $('#formLoader').show();
  282. });
  283.  
  284. $(document).on('click','.add-surcharge-to-inventory-button', function () {
  285. id = $(this).attr('data-rent-inventory');
  286. sum = $('#surcharge').val();
  287. returnInventoryWithPay(id,sum);
  288. });
  289.  
  290. $(document).on('click','.cancel-sell-inventory-button', function () {
  291. id = $(this).attr('data-rent-inventory');
  292. message = $('#cancel-sale').val();
  293. cancelInventorySale(id,message);
  294. });
  295.  
  296.  
  297. $(document).on('click','.cancel-surcharge-to-inventory-button', function () {
  298. id = $(this).attr('data-rent-inventory');
  299. returnInventory(id)
  300. });
  301.  
  302. $(document).on('click', '#add-order', function () {
  303. $('#modalAddInventory').modal('show');
  304. $('#s2-togall-w0').hide();
  305. });
  306. $('#w0').on('select2:select', function (e) {
  307. var data = e.params.data;
  308. setNewInventory(data.id)
  309. });
  310. $('#w0').on('select2:unselect', function (e) {
  311. var data = e.params.data;
  312. $('.item-'+data.id).remove();
  313. });
  314. function setNewInventory(id) {
  315.  
  316. $.get( ACTION_SALE+'?inv_id='+id, function(data) {
  317. $(".inventory-box-manual").append(data);
  318. $('.started_at').clockpicker({
  319. autoclose: true,
  320. donetext: 'ок'
  321. });
  322. }).fail(function() {
  323. $('#modalAddInventory').modal('toggle');
  324. $.notify({
  325. message: 'Произошла ошибка при выполнении операции.'
  326. },{
  327. type: 'danger'
  328. });
  329. });
  330.  
  331. $('#formLoader').hide();
  332. }
  333. function setDelayPrice() {
  334. var sum = 0;
  335. $('.tariff-price-input').each(function(){
  336. sum += parseFloat(this.value);
  337. });
  338. $('#delay-price-input').val(sum)
  339. }
  340. function inventoryTariffTemplate(index) {
  341. return '<div class="row inventory-tariff-box" id="inventory-tariff-box-'+index+'">' +
  342. '<div class="col-sm-5">' +
  343. '<div class="form-group field-rentinventorytariff-duration-'+index+'">' +
  344. '<label class="control-label" for="rentinventorytariff-duration-'+index+'">Длительность</label>' +
  345. '<input type="number" id="rentinventorytariff-duration-'+index+'" class="form-control" name="RentInventoryTariff['+index+'][duration]" 0-class="col-sm-5">' +
  346. '<p class="help-block help-block-error"></p>' +
  347. '</div></div>' +
  348. '<div class="col-sm-5">' +
  349. '<div class="form-group field-rentinventorytariff-price-'+index+'">' +
  350. '<label class="control-label" for="rentinventorytariff-price-'+index+'">Цена</label>' +
  351. '<input type="number" id="rentinventorytariff-price-'+index+'" class="form-control" name="RentInventoryTariff['+index+'][price]" 0-class="col-sm-5">' +
  352. '<p class="help-block help-block-error"></p>' +
  353. '</div></div>' +
  354. '<div class="col-sm-2">' +
  355. '<div>' +
  356. '<a id="remove-inventory-tariff" class="btn btn-warning" href="/inventory/#" data-tariff-index="'+index+'">Х</a></div>' +
  357. ' </div>' +
  358. '</div>';
  359. }
  360. function returnInventory(id) {
  361. $.ajax({
  362. url: RETURN_INVENTORY,
  363. type: "POST",
  364. data: {'id' : id},
  365. success: function(data){
  366. $('#modal').modal('toggle');
  367. status = data.status === true ? 'success' : 'danger';
  368. message = data.message ? data.message : 'Операция выполнена успешно.';
  369. $.notify({
  370. message: message
  371. },{
  372. type: status
  373. });
  374. },
  375. error: function() {
  376. $.notify({
  377. message: 'Произошла ошибка при выполнении операции.'
  378. },{
  379. type: 'danger'
  380. });
  381. }
  382. });
  383. }
  384. function delayOfTimeTemplate(rest,inventoryId){
  385. $.ajax({
  386. url: DELAY_OF_TIME,
  387. type: "POST",
  388. data: {'rest' : rest, 'id': inventoryId},
  389. success: function(data){
  390. $('#modalBody').html(data);
  391. $('#surcharge').focus();
  392. },
  393. error: function() {
  394. $.notify({
  395. message: 'Произошла ошибка при выполнении операции.'
  396. },{
  397. type: 'danger'
  398. });
  399. }
  400. });
  401. }
  402.  
  403. function returnInventoryWithPay(id,sum){
  404. $.ajax({
  405. url: RETURN_INVENTORY_WITH_PAY,
  406. type: "POST",
  407. data: {'sum' : sum, 'id': id},
  408. success: function(data){
  409. $('#modal').modal('toggle');
  410. status = data.status === true ? 'success' : 'danger';
  411. message = data.message ? data.message : 'Операция выполнена успешно.';
  412. $.notify({
  413. message: message
  414. },{
  415. type: status
  416. });
  417. },
  418. error: function() {
  419. $.notify({
  420. message: 'Произошла ошибка при выполнении операции.'
  421. },{
  422. type: 'danger'
  423. });
  424. }
  425. });
  426. }
  427.  
  428. function cancelInventorySale(id,message){
  429. $.ajax({
  430. url: CANCEL_SELL_INVENTORY,
  431. type: "POST",
  432. data: { 'id': id, 'message' : message},
  433. success: function(data){
  434. $('#modal').modal('toggle');
  435. status = data.status === true ? 'success' : 'danger';
  436. message = data.message ? data.message : 'Операция выполнена успешно.';
  437. $.notify({
  438. message: message
  439. },{
  440. type: status
  441. });
  442. },
  443. error: function() {
  444. $.notify({
  445. message: 'Произошла ошибка при выполнении операции.'
  446. },{
  447. type: 'danger'
  448. });
  449. }
  450. });
  451. }
  452.  
  453. $('#modal').on('hidden.bs.modal', function () {
  454. $("#modalBody").html('');
  455. });
  456. $('#modalAddInventory').on('hidden.bs.modal', function () {
  457. $(".inventory-box-manual").html('');
  458. $("#w0").val('').trigger('change');
  459. });
  460. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement