From 87a27250b7dd44cc0e9eb56eebaafc60b424451d Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 26 Nov 2017 22:23:37 +0630 Subject: [PATCH] fix minus addorder.js and void and other origami --- app/assets/javascripts/addorder.js | 6 +- app/controllers/origami/void_controller.rb | 15 +- app/models/sale_payment.rb | 2 +- app/models/shift_sale.rb | 2 +- app/pdf/close_cashier_pdf.rb | 15 +- app/views/origami/payments/show.html.erb | 169 ++++++++++----------- lib/tasks/clear_data.rake | 1 + 7 files changed, 111 insertions(+), 99 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 427f9e7b..5cacee2e 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -855,12 +855,12 @@ $(function() { $('#'+minus).on("click", function(){ - var count = parseInt($('#'+id).val()); - var countEl = document.getElementById(id); + // var count = parseInt($('#'+id).val()); + // var countEl = document.getElementById(id); if (count > 1) { count--; - countEl.value = count; + $('#'+id).val(count); if (id=="count") { price = $("#unit_price").text(); diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 80594a26..a243a388 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -8,12 +8,19 @@ class Origami::VoidController < BaseOrigamiController sale = Sale.find_by_sale_id(sale_id) # update count for shift sale - # if(sale.sale_status == "completed") + if(sale.sale_status == "completed") if sale.shift_sale_id != nil shift = ShiftSale.find(sale.shift_sale_id) shift.calculate(sale_id, "void") end - # end + else + # void before sale payment complete + if sale.shift_sale_id != nil + shift = ShiftSale.find(sale.shift_sale_id) + shift.total_void = shift.total_void + sale.grand_total + shift.save + end + end sale.payment_status = 'void' sale.sale_status = 'void' @@ -95,4 +102,8 @@ class Origami::VoidController < BaseOrigamiController end end + def void_before_pay + + end + end \ No newline at end of file diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e49190a5..cb6b1249 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -174,7 +174,7 @@ class SalePayment < ApplicationRecord sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") sale_items.each do|item| - SaleItem.update_existing_item(item.qty,item.item_instance_code, item, self.sale.sale_id, "foc", item.unit_price, item.price) + SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) end self.payment_method = "foc" diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index baf11cb3..6c956620 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -54,7 +54,7 @@ class ShiftSale < ApplicationRecord self.cash_sales = self.cash_sales.to_f + cash.to_f self.credit_sales = self.credit_sales.to_i + credit.to_f self.other_sales = self.other_sales.to_i + other_sales.to_f - self.nett_sales = self.nett_sales + (saleobj.total_amount.to_f - self.total_discounts) #self.grand_total.to_i - self.commercial_taxes + self.nett_sales = self.nett_sales + (saleobj.total_amount.to_f - saleobj.total_discount) #self.grand_total.to_i - self.commercial_taxes self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f self.total_rounding = self.total_rounding + saleobj.rounding_adjustment self.total_receipt = self.total_receipt + 1 diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 1f456a07..179e3336 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -263,13 +263,14 @@ class CloseCashierPdf < Prawn::Document end #end total amount by Account - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Sale :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right - end +#COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Total Sale :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right + # end move_down -5 stroke_horizontal_rule diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a911acf4..291060de 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -359,95 +359,94 @@ }); $( document ).ready(function() { - // Disable click event cash to prevent - $(".payment .cash-color").off('click'); + // Disable click event cash to prevent + $(".payment .cash-color").off('click'); - $('#credit_payment').click(function() { - var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/payment/credit_payment" - return false; - }); - - $('#card_payment').click(function() { - localStorage.setItem("cash",$('#cash').text() ); - var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment" - return false; - }); - - $('#pay').click(function() { - $('#pay').text("Processing, Please wait!") - - $( "#loading_wrapper" ).show(); - - if($('#balance').text() > 0){ - swal ( "Oops" , "Insufficient Amount!" , "error" ); - $( "#loading_wrapper" ).hide(); - }else{ - var sale_id = $('#sale_id').text(); - var item_row = $('.is_card'); - if (item_row.length < 1) { - calculate_member_discount(sale_id); - } - - // payment - var cash = $('#cash').text(); - var credit = $('#credit').text(); - var card = $('#card').text(); - - $.ajax({type: "POST", - url: "<%= origami_payment_cash_path %>", - data: "cash="+ cash + "&sale_id=" + sale_id, - async: false, - success:function(result){ - - localStorage.removeItem("cash"); - if (result.status) { - var msg = result.message; - } - else{ - var msg = ''; - } - $( "#loading_wrapper" ).hide(); - if($('#balance').text() < 0){ - swal({ - title: "Information!", - text: 'Changed amount ' + $('#balance').text() * (-1), - }, function () { - window.location.href = '/origami'; - }); - }else{ - $('#pay').text("Pay"); - swal({ - title: "Information!", - text: 'Thank You !', - }, function () { - window.location.href = '/origami'; - }); - } - } - }); - } + $('#credit_payment').click(function() { + var sale_id = $('#sale_id').text(); + window.location.href = '/origami/sale/'+ sale_id + "/payment/credit_payment" + return false; }); - $('#void').on('click',function () { - swal({ - title: "Information!", - text: 'Are you sure want to Void !', - }, function () { - var sale_id = $('#sale_id').text(); - var ajax_url = "/origami/sale/" + sale_id + '/void'; - $.ajax({ - type: 'POST', - url: ajax_url, - success: function () { - window.location.href = '/origami/'; - } - }) - }); - }); + $('#card_payment').click(function() { + localStorage.setItem("cash",$('#cash').text() ); + var sale_id = $('#sale_id').text(); + window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment" + return false; + }); -}); + $('#pay').click(function() { + $('#pay').text("Processing, Please wait!") + + $( "#loading_wrapper" ).show(); + + if($('#balance').text() > 0){ + swal ( "Oops" , "Insufficient Amount!" , "error" ); + $( "#loading_wrapper" ).hide(); + }else{ + var sale_id = $('#sale_id').text(); + var item_row = $('.is_card'); + if (item_row.length < 1) { + calculate_member_discount(sale_id); + } + + // payment + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + + $.ajax({type: "POST", + url: "<%= origami_payment_cash_path %>", + data: "cash="+ cash + "&sale_id=" + sale_id, + async: false, + success:function(result){ + + localStorage.removeItem("cash"); + if (result.status) { + var msg = result.message; + } + else{ + var msg = ''; + } + $( "#loading_wrapper" ).hide(); + if($('#balance').text() < 0){ + swal({ + title: "Information!", + text: 'Changed amount ' + $('#balance').text() * (-1), + }, function () { + window.location.href = '/origami'; + }); + }else{ + $('#pay').text("Pay"); + swal({ + title: "Information!", + text: 'Thank You !', + }, function () { + window.location.href = '/origami'; + }); + } + } + }); + } + }); + + $('#void').on('click',function () { + swal({ + title: "Information!", + text: 'Are you sure want to Void !', + }, function () { + var sale_id = $('#sale_id').text(); + var ajax_url = "/origami/sale/" + sale_id + '/void'; + $.ajax({ + type: 'POST', + url: ajax_url, + success: function () { + window.location.href = '/origami/'; + } + }) + }); + }); + }); function update_balance(){ var cash = $('#cash').text(); diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index 3071132b..126d8db7 100755 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -9,6 +9,7 @@ namespace :clear do SaleOrder.delete_all SaleItem.delete_all Sale.delete_all + SaleTax.delete_all SaleAudit.delete_all SalePayment.delete_all ShiftSale.delete_all