From 7afb4cf0ebbb1e64e8b0bb5075cb1662a3b63a7e Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Fri, 10 Jan 2020 15:05:02 +0630 Subject: [PATCH 1/7] Update shift credit with current user --- app/models/printer/printer_worker.rb | 22 +++++++++++----------- app/models/sale_payment.rb | 5 ++++- config/initializers/action_controller.rb | 10 +++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index d30af42d..5d7cce22 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -42,17 +42,17 @@ class Printer::PrinterWorker end def print(file_path, printer_destination = nil ) - if printer_destination.nil? - printer_destination = self.printer_destination - end + # if printer_destination.nil? + # printer_destination = self.printer_destination + # end - copy = self.print_copies - #Print only when printer information is not null - if !self.printer_destination.nil? - (1..copy).each do - page = Cups::PrintJob.new(file_path, printer_destination) - page.print - end - end + # copy = self.print_copies + # #Print only when printer information is not null + # if !self.printer_destination.nil? + # (1..copy).each do + # page = Cups::PrintJob.new(file_path, printer_destination) + # page.print + # end + # end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 06350f6f..36bc6de3 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -722,7 +722,10 @@ class SalePayment < ApplicationRecord # update for shift with credit payment def update_shift_for_credit_payment shift_credit = ShiftSale.find_by_id(self.sale.shift_sale_id) - shift = ShiftSale.find_by_id(ShiftSale.current_shift) + shift = self.action_by.current_shift + if !shift.nil? + shift = ShiftSale.current_shift + end if !shift.nil? credit_payment_left = get_credit_payment_left[0].payment_amount.to_f if self.payment_method == "cash" diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index eb7ba401..2cf70a1b 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end From 44b568a5f4fe2f6f31fd54e0645297b172937c40 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Fri, 10 Jan 2020 15:05:36 +0630 Subject: [PATCH 2/7] Update shift credit with current_user --- app/models/printer/printer_worker.rb | 22 +++++++++++----------- config/initializers/action_controller.rb | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 5d7cce22..d30af42d 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -42,17 +42,17 @@ class Printer::PrinterWorker end def print(file_path, printer_destination = nil ) - # if printer_destination.nil? - # printer_destination = self.printer_destination - # end + if printer_destination.nil? + printer_destination = self.printer_destination + end - # copy = self.print_copies - # #Print only when printer information is not null - # if !self.printer_destination.nil? - # (1..copy).each do - # page = Cups::PrintJob.new(file_path, printer_destination) - # page.print - # end - # end + copy = self.print_copies + #Print only when printer information is not null + if !self.printer_destination.nil? + (1..copy).each do + page = Cups::PrintJob.new(file_path, printer_destination) + page.print + end + end end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 2cf70a1b..eb7ba401 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end From ab70ddb8aa6c68edb28f57837ed24c84cfb91249 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 15 Jan 2020 16:26:55 +0630 Subject: [PATCH 3/7] fixed credit transactions --- .../transactions/credit_notes_controller.rb | 27 +++------- app/models/sale.rb | 54 +++++++------------ .../transactions/credit_notes/index.html.erb | 4 +- 3 files changed, 28 insertions(+), 57 deletions(-) diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 6740c89d..7303f126 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -1,5 +1,5 @@ class Transactions::CreditNotesController < ApplicationController - + before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy] before_action :check_user @@ -15,24 +15,9 @@ class Transactions::CreditNotesController < ApplicationController to = params[:to] order_source = params[:order_source] - if filter.nil? && from.nil? && to.nil? && customer.nil? && order_source.nil? - order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=sales.sale_id GROUP BY so.sale_id)" - - @credit_notes = Sale.select("sales.*, #{order_source_query} as source") - .joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id") - .where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount) - FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') - THEN NULL ELSE payment_method='creditnote' END)") - @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) - else - sale = Sale.search_credit_sales(customer,filter,from,to,order_source) - if !sale.nil? - @credit_notes = sale - @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) - else - @credit_notes = 0 - end - end + sale = Sale.search_credit_sales(customer,filter,from,to,order_source) + @credit_notes = Kaminari.paginate_array(sale).page(params[:page]).per(20) + respond_to do |format| format.html # index.html.erb format.json { render json: @credit_notes } @@ -45,5 +30,5 @@ class Transactions::CreditNotesController < ApplicationController redirect_to root_path end end - -end \ No newline at end of file + +end diff --git a/app/models/sale.rb b/app/models/sale.rb index dce922f7..ce7caf7c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -708,43 +708,29 @@ class Sale < ApplicationRecord end def self.search_credit_sales(customer,filter,from,to,order_source="") - if filter.blank? - keyword = '' - else - keyword = "and sales.receipt_no LIKE ? OR sales.cashier_name LIKE ? OR sales.sale_status ='#{filter}'","%#{filter}%","%#{filter}%" - end - - if customer.blank? - custo = '' - else - custo = "and sales.customer_id = '#{customer}'" - end - order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=sales.sale_id GROUP BY so.sale_id)" - if order_source.blank? - source = "" - else - if order_source == "cashier" - source = "and #{order_source_query}='cashier' or #{order_source_query}='emenu'" - else - source = "and #{order_source_query}='#{order_source}'" - end - end + sale = Sale.select(Sale.column_names) + .select(SalePayment.column_names) + .select(:source).includes(:customer) + .joins(:sale_payments, :orders) + .where(sale_payments: {payment_method: 'creditnote'}) + .group(:sale_payment_id) if from.present? && to.present? - sale = Sale.select("sales.*,#{order_source_query} as source").joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id") - .joins(" JOIN bookings ON bookings.sale_id=sales.sale_id") - .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") - .joins(" JOIN orders ON orders.order_id=booking_orders.order_id") - .where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and (CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount) - FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}", from,to) - else - sale = Sale.select("sales.*,#{order_source_query} as source").joins(" JOIN sale_payments sp on sp.sale_id = sales.sale_id") - .joins(" JOIN bookings ON bookings.sale_id=sales.sale_id") - .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") - .joins(" JOIN orders ON orders.order_id=booking_orders.order_id") - .where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount) - FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}") + sale = sale.receipt_date_between(from, to) end + + if filter.present? + sale = sale.where("sales.receipt_no LIKE ? OR sales.cashier_name LIKE ? OR sales.sale_status = ?", "%#{filter}%", "%#{filter}%", filter) + end + + if customer.present? + sale = sale.where(customer_id: customer) + end + + if order_source.present? + sale = sale.where(orders: {source: order_source}) + end + return sale end def self.get_rounding_adjustment(num) diff --git a/app/views/transactions/credit_notes/index.html.erb b/app/views/transactions/credit_notes/index.html.erb index 754cffb9..f533a1f7 100755 --- a/app/views/transactions/credit_notes/index.html.erb +++ b/app/views/transactions/credit_notes/index.html.erb @@ -37,7 +37,7 @@
- +
@@ -66,7 +66,7 @@
-
+ <% end %> From 397d99b942ba0fc134ca9cc58b303dc6847e7175 Mon Sep 17 00:00:00 2001 From: Zin Moe Date: Wed, 15 Jan 2020 17:41:12 +0630 Subject: [PATCH 4/7] add cashier change tax require manager access code --- app/views/origami/home/show.html.erb | 9 ++++++++- app/views/origami/payments/show.html.erb | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index e14fdde1..8e3c3b18 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -379,7 +379,11 @@ No Tax <% end %>
<%if !@webview && @changable_tax %> - + <% if @current_user.role == 'cashier' %> + + <% else %> + + <% end %> <% end %> <%= number_format(@obj_sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> @@ -1406,6 +1410,9 @@ // overall_void(); }else if(type == "waste_and_spoilage"){ + }else if(type == 'change_tax'){ + $('#AccessCodeModal').modal('hide'); + $('#change_taxModal').modal('show'); } }else{ swal("Opps",result.message,"warning") diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index ca2f6ada..4f5d387a 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -105,7 +105,11 @@ No Tax <% end %>
<%if @sale_payment.nil? && @changable_tax %> - + <% if @current_user.role == 'cashier' %> + + <% else %> + + <% end %> <% end %> <%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> @@ -1472,6 +1476,9 @@ $(document).ready(function(){ $('#AccessCodeModal').modal('hide'); $('#focModal').modal('show'); // overall_foc(); + }else if(type == 'change_tax'){ + $('#AccessCodeModal').modal('hide'); + $('#change_taxModal').modal('show'); } }else{ swal("Oops",result.message,"warning"); From a498eec8325edd7f4133c42307566ac717687cce Mon Sep 17 00:00:00 2001 From: Aung Ye Kyaw Date: Thu, 30 Jan 2020 05:25:23 +0000 Subject: [PATCH 5/7] Update Gemfile ruby version and mysql2 version ## gem 'mysql2', '~> 0.5.2' --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 11a34b3c..92b133de 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -#ruby '2.4.1' +ruby '2.6.5' #ruby '2.5.7' git_source(:github) do |repo_name| @@ -15,7 +15,7 @@ gem 'rails', '~> 5.1.0' #gem 'mysql2', '>= 0.3.18', '< 0.5' gem 'pg' -gem 'mysql2' +gem 'mysql2', '~> 0.5.2' #Use PosgreSQL From 4e8049581e11ccc4231429db8391d80521a80b11 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 31 Jan 2020 17:19:36 +0630 Subject: [PATCH 6/7] fixed redeem --- app/models/sale_audit.rb | 2 +- app/models/sale_payment.rb | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 0cc5b9e7..5aa42545 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -142,7 +142,7 @@ class SaleAudit < ApplicationRecord if paymal[0] remark = paymal[0].remark.split("}") response = "["+remark[0]+'}]' - response = JSON.parse(response) + # response = JSON.parse(response) puts response if response[0]["status"] == true if response[0]["current_rebate_amount"].present? diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 36bc6de3..607b22da 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -233,9 +233,9 @@ class SalePayment < ApplicationRecord return response; end - def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) - # membership_actions_data = MembershipAction.find_by_membership_type("redeem"); - membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem") + def redeem(paypar_url,token,membership_id,received_amount,sale_id) + membership_actions_data = MembershipAction.find_by_membership_type("redeem"); + # membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem") puts "This is membership_actions_data" puts membership_actions_data.to_json if !membership_actions_data.nil? @@ -243,8 +243,9 @@ class SalePayment < ApplicationRecord url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id auth_token = membership_actions_data.auth_token - campaign_type_id = JSON.parse(membership_actions_data.additional_parameters)["campaign_type_id"] + campaign_type_id = membership_actions_data.additional_parameters["campaign_type_id"] sale_data = Sale.find_by_sale_id(sale_id) + account_no = Customer.find_by_customer_id(self.sale.customer_id).paypar_account_no if sale_data others = 0 @@ -261,7 +262,7 @@ class SalePayment < ApplicationRecord redeem_amount:received_amount, receipt_no:sale_data.receipt_no, campaign_type_id:campaign_type_id, - account_no:"", + account_no: account_no, merchant_uid:merchant_uid, auth_token:auth_token}.to_json, :headers => { @@ -504,7 +505,7 @@ class SalePayment < ApplicationRecord #Next time - validate if the vochure number is valid - within customer_data = Customer.find_by_customer_id(self.sale.customer_id) membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} Redeem- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " From d2cfe06f3a6e333ea630fb2f5c6c414edfbd5b2a Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 31 Jan 2020 17:36:34 +0630 Subject: [PATCH 7/7] fixed redeem --- app/models/sale_payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 607b22da..a0b3501a 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -243,7 +243,7 @@ class SalePayment < ApplicationRecord url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id auth_token = membership_actions_data.auth_token - campaign_type_id = membership_actions_data.additional_parameters["campaign_type_id"] + campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] sale_data = Sale.find_by_sale_id(sale_id) account_no = Customer.find_by_customer_id(self.sale.customer_id).paypar_account_no