diff --git a/Gemfile b/Gemfile index 5344bdc5..fa2990ad 100644 --- a/Gemfile +++ b/Gemfile @@ -72,6 +72,10 @@ gem 'filterrific' gem 'cancancan', '~> 1.10' +#pageless no need for current +# gem 'will_paginate' +# gem 'pageless-rails', github: 'rorlab/pageless-rails' + # Use Capistrano for deployment # gem 'capistrano-rails', group: :development diff --git a/app/assets/images/ajax-loader.gif b/app/assets/images/ajax-loader.gif new file mode 100644 index 00000000..4155add2 Binary files /dev/null and b/app/assets/images/ajax-loader.gif differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 63c871d9..9adb6b75 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -30,134 +30,3 @@ function export_to(path) var form_params = $("#frm_report").serialize(); window.location = path+"?"+ form_params; } - -/* -* ToDo Move to here from pages -* -* - - - -$(function(){ - $('#custom_excel').hide(); - - $('#custom_excel').click(function(){ - var url = $('#custom_excel').attr('data-url'); - $('#frm_report').attr('action',url) - $('#frm_report').submit(); - // window.location = url; - }); - - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'order'){ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } - else if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - } - else{ - $('#waiter').hide(); - $('#cashier').show(); - $("#item").val('sale'); - } -}); - -//Reset the form to pervious values -$("#branch").val(<%=params[:branch]%>); -$("#waiter").val("<%=params[:waiter]%>"); -$("#cashier").val(<%=params[:cashier]%>); -$("#product").val(<%=params[:product]%>); -$("#singer").val(<%=params[:singer]%>); -$("#item").val('<%=params[:item]%>'); -$("#guest_role").val('<%=params[:guest_role]%>'); - - -$("#from").val("<%=params[:from]%>"); -$("#to").val("<%=params[:to]%>"); -$("#sel_period").val(<%=params[:period]%>); -$("#sel_sale_type").val(<%=params[:sale_type]%>); - -<% if params[:period_type] == 1 || params[:period_type] == "1" %> - $("#rd_period_type_1").attr("checked","checked"); -<% else %> - $("#rd_period_type_0").attr("checked","checked"); -<% end %> -$(".btn-group button").removeClass("active"); -<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %> -$("#btn_report_type_<%= report_type %>").addClass("active"); - -$('#item').change(function(){ - var item = $('#item').val(); - var payment_type = $('#payment_type'); - - if(item == 'sale'){ - $('#waiter').hide(); - $('#cashier').show(); - if(payment_type){ - $('#payment_type').show(); - } - } - else{ - $('#cashier').hide(); - $('#waiter').show(); - if(payment_type){ - $('#payment_type').hide(); - } - } -}); - -$(function(){ - var check_arr = []; - var search = '<%= params[:period_type] %>'; - if(search){ - if(parseInt(search) == 0){ - search_by_period(); - } - else{ - search_by_date(); - } - }else{ - search_by_period(); - } - $('#sel_period').change(function(){ - search_by_period(); - }); - function search_by_period(){ - var period = $('#sel_period').val(); - var period_type = 0; - var from = ""; - var to = ""; - } - - $('#from').change(function(){ - search_by_date(); - }); - - $('#to').change(function(){ - search_by_date(); - }); - function search_by_date(){ - var from = $('#from').val(); - var to = $('#to').val(); - var period = 0; - var period_type = 1; - if(to != '' && from != ''){ - shift_name = from + ',' + to; - check_arr.push(to); - // console.log(check_arr.length) - if(check_arr.length == 1){ - } - if(check_arr.length == 3){ - check_arr = []; - } - } - } -}); -*/ diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index cf6782dd..82b84afd 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -52,4 +52,33 @@ @include media-breakpoint-only(xl) { column-count: 5; } +} + +#sxModal { + display: none; + overflow: auto; + width: 100%; + height: 100%; + background-color: #000; + background-color: rgba(0,0,0,0.4); + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 1100; +} + +#sxModal-Content { + position: relative; + left: 42%; + top: 30%; + background-color: #32ad1a; + color: #fff; + text-align: center; + width: 200px; + height: 200px; + padding-top: 5%; + border-radius: 100px; + z-index: 1101; } \ No newline at end of file diff --git a/app/assets/stylesheets/OQS.scss b/app/assets/stylesheets/OQS.scss index 57c5a36d..74a8032f 100644 --- a/app/assets/stylesheets/OQS.scss +++ b/app/assets/stylesheets/OQS.scss @@ -24,4 +24,4 @@ width: 49%; font-size: 18px; margin: 0px 0px 5px 0px; -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 1f195ba5..10e2b319 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -10,7 +10,8 @@ // padding-top: 4.5rem; // } .card-columns { - font-size: 18px !important;} + font-size: 18px !important; +} .others-payment{ line-height:100px; @@ -53,7 +54,8 @@ .payment{ height:70px;line-height:70px; - align:center;color:white; + align:center; + color:white; font-size:16px; margin-top:5px; } @@ -161,15 +163,15 @@ } .green{ - background-color: #009900 + background-color: #009900; } .orange{ - background-color: #FF8C00 + background-color: #FF8C00; } .blue{ - background-color: blue + background-color: blue; } /* End Colors */ @@ -212,3 +214,57 @@ tr.discount-item-row:hover { margin-top:-40px !important; } +#sxModal { + display: none; + overflow: auto; + width: 100%; + height: 100%; + background-color: #000; + background-color: rgba(0,0,0,0.4); + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 1100; +} + +#sxModal-Content { + position: relative; + left: 42%; + top: 30%; + background-color: #d9534f; + color: #fff; + text-align: center; + width: 200px; + height: 200px; + padding-top: 5%; + border-radius: 100px; + z-index: 1101; +} + +/*Loading gif for payment*/ + +#loading_wrapper{ + + position: fixed; + background-color: #C8C8C8 ; + height: 100%; + width: 100%; + left: 0; + opacity: 0.6; + top: 0; + z-index: 9999999; +} +#loading{ + position: relative; + height: 100%; + width: 100%; + background-image: url('../../../image/loading-ajax.gif'); + background-position: center center; + background-repeat: no-repeat; + opacity: 1; + filter: alpha(opacity=100); /* ie */ + -moz-opacity: 1; /* mozilla */ + +} diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 12eeccd2..af9ec4fc 100644 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -34,12 +34,10 @@ class BaseReportController < ActionController::Base to = params[:to] day_ref = Time.now.utc.getlocal - if params[:report_type] == "daily_sale" || params[:report_type] == "sale_item" + if from.present? && to.present? - if from != "" && to != "" - - f_date = DateTime.parse(params[:from]) - t_date = DateTime.parse(params[:to]) + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) from = f_time.beginning_of_day.utc.getlocal @@ -83,59 +81,6 @@ class BaseReportController < ActionController::Base to = (day_ref - 1.year).end_of_year.utc end end - else # end daily sale report - if period_type.to_i == 1 - - if params[:from] != "" && params[:to] !="" - - f_date = DateTime.parse(params[:from]) - t_date = DateTime.parse(params[:to]) - f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - from = f_time.beginning_of_day.utc.getlocal - to = t_time.end_of_day.utc.getlocal - else - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - end - else - case period.to_i - when PERIOD["today"] - - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - - when PERIOD["yesterday"] - from = (day_ref - 1.day).beginning_of_day.utc - to = (day_ref - 1.day).end_of_day.utc - - when PERIOD["this_week"] - from = Time.now.beginning_of_week.utc - to = Time.now.utc - when PERIOD["last_week"] - from = (day_ref - 7.day).beginning_of_week.utc - to = (day_ref - 7.day).end_of_week.utc - when PERIOD["last_7"] - from = (day_ref - 7.day).utc - to = Time.now.utc - when PERIOD["this_month"] - from = Time.now.beginning_of_month.utc - to = Time.now.utc - when PERIOD["last_month"] - from = (day_ref - 1.month).beginning_of_month.utc - to = (day_ref - 1.month).end_of_month.utc - when PERIOD["last_30"] - from = (day_ref - 30.day).utc - to = Time.now.utc - when PERIOD["this_year"] - from = Time.now.beginning_of_year.utc - to = Time.now.utc - when PERIOD["last_year"] - from = (day_ref - 1.year).beginning_of_year.utc - to = (day_ref - 1.year).end_of_year.utc - end - end - end return from, to diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 7b846db0..4b045221 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -6,7 +6,6 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] - if filter.nil? @crm_customers = Customer.all else @@ -49,21 +48,7 @@ class Crm::CustomersController < BaseCrmController #get customer amount @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) - # get member information - total = Customer.get_member_account(@customer) - - - @balance = 0.00 - @accountable_type = '' - if total["status"]==true - total["data"].each do |res| - if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" - @balance += res["balance"] - # @accountable_type = res["accountable_type"] - @accountable_type = "Rebate Balance" - end - end - end + # @response = "" #end customer amount @@ -95,10 +80,10 @@ class Crm::CustomersController < BaseCrmController address = customer_params[:address] nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] + paypar_account_no = customer_params[:paypar_account_no] member_group_id = params[:member_group_id] if member_group_id.present? - puts "aaaaaaaaa" membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s @@ -109,6 +94,7 @@ class Crm::CustomersController < BaseCrmController response = HTTParty.post(url, :body => {name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, member_group_id: member_group_id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { @@ -119,18 +105,18 @@ class Crm::CustomersController < BaseCrmController ) rescue HTTParty::Error - response = {status: false, message: "Can't open membership server "} + response = {"status" => false, "message" => "Can't open membership server "} rescue Net::OpenTimeout - - response = { status: false , message: "Can't open membership server "} + response = {"status" => false, "message" => "Can't open membership server "} rescue OpenURI::HTTPError - response = { status: false, message: "Can't open membership server "} + response = {"status" => false, "message" => "Can't open membership server "} rescue SocketError - response = { status: false, message: "Can't open membership server "} - end + response = {"status" => false, "message" => "Can't open membership server "} + end + if response["status"] == true customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) @@ -145,9 +131,9 @@ class Crm::CustomersController < BaseCrmController customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_type:member_group_id ) if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response[:message]} + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]} else - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response[:message] } + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response["message"] } end end else @@ -186,6 +172,7 @@ end address = customer_params[:address] nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] + paypar_account_no = customer_params[:paypar_account_no] id = @crm_customer.membership_id member_group_id = params[:member_group_id] @@ -201,6 +188,7 @@ end response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc, + paypar_account_no: paypar_account_no, card_no:card_no,member_group_id: member_group_id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { @@ -245,6 +233,7 @@ end response = HTTParty.post(url, :body => {name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -301,6 +290,6 @@ end def customer_params params.require(:customer).permit(:name, :company, :contact_no, :email, - :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no) + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no) end end diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index 9c5f8b73..22351395 100644 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -86,7 +86,7 @@ class Crm::DiningQueuesController < BaseCrmController table_id = params[:table_id] status = queue.update_attributes(dining_facility_id: table_id,status:"Assign") - status = DiningFacility.find(table_id).update_attributes(status: "occupied") + # status = DiningFacility.find(table_id).update_attributes(status: "occupied") if status == true diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index 6866ddf1..012f2bc6 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -1,13 +1,13 @@ class Crm::HomeController < BaseCrmController def index - # @booking = Booking.all - # @customer = Customer.all - # from = Time.now.beginning_of_day.utc - # to = Time.now.end_of_day.utc - # @queue = DiningQueue.where('created_at BETWEEN ? AND ?', from, to).order('queue_no ASC') - redirect_to crm_customers_path - # .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) + @booking = Booking.all + @customer = Customer.all + from = Time.now.beginning_of_day.utc + to = Time.now.end_of_day.utc + @queue = DiningQueue.where('created_at BETWEEN ? AND ?', from, to).order('queue_no ASC') + redirect_to crm_customers_path + # .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d6960bc3..ead69f39 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -21,7 +21,8 @@ class HomeController < ApplicationController session[:session_token] = @employee.token_session route_by_role(@employee) else - render :show, flash[:notice] => "Invalid PIN for Employee. Please try again!" + flash[:notice] ="Invalid PIN for Employee. Please try again!" + render :show end end @@ -41,9 +42,12 @@ class HomeController < ApplicationController elsif @employee.role == "manager" session[:session_token] = @employee.token_session redirect_to dashboard_path - elsif @employee.role == "accountant" + elsif @employee.role == "supervisour" session[:session_token] = @employee.token_session - redirect_to dashboard_path + redirect_to origami_root_path + elsif @employee.role == "account" + session[:session_token] = @employee.token_session + redirect_to reports_dailysale_index_path else render :index end @@ -65,6 +69,8 @@ class HomeController < ApplicationController end def destroy + # clear in employee session + Employee.logout(session[:session_token]) session[:session_token] = nil redirect_to root_path end @@ -93,12 +99,15 @@ class HomeController < ApplicationController redirect_to new_origami_shift_path end elsif employee.role == "manager" - redirect_to oqs_root_path + redirect_to dashboard_path elsif employee.role == "waiter" redirect_to oqs_root_path elsif employee.role == "crm" redirect_to crm_root_path - + elsif @employee.role == "supervisour" + redirect_to origami_root_path + elsif @employee.role == "account" + redirect_to reports_dailysale_index_path end end end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 226b3a83..d8731ecb 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -26,6 +26,7 @@ class Oqs::HomeController < BaseOqsController @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) end + # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) @queue_stations_items end @@ -99,6 +100,7 @@ class Oqs::HomeController < BaseOqsController left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0") .group("assigned_order_items.assigned_order_item_id") + .order("assigned_order_items.created_at") end # Completed Order @@ -112,8 +114,10 @@ class Oqs::HomeController < BaseOqsController left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id left join dining_facilities as df on df.id = bk.dining_facility_id") - .where("assigned_order_items.delivery_status = true AND odt.price <> 0") + .where("assigned_order_items.delivery_status = true AND odt.price <> 0 AND assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'") .group("assigned_order_items.order_id") + .limit(20) + .order("assigned_order_items.created_at") # completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true'); diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 203e5600..26e3c74b 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -50,12 +50,22 @@ class Origami::CustomersController < BaseOrigamiController def update_sale_by_customer id = params[:sale_id][0,3] + customer_id = params[:customer_id] + + # Check and find with card no + if(!customer_id.include? "CUS") + customer = Customer.find_by_paypar_account_no(customer_id) + if(customer != nil) + customer_id = customer.customer_id + end + end + if(id == "SAL") sale = Sale.find(params[:sale_id]) - status = sale.update_attributes(customer_id: params[:customer_id]) + status = sale.update_attributes(customer_id: customer_id) sale.sale_orders.each do |sale_order| order = Order.find(sale_order.order_id) - status = order.update_attributes(customer_id: params[:customer_id]) + status = order.update_attributes(customer_id: customer_id) end else @booking = BookingOrder.find_by_order_id(params[:sale_id]) @@ -63,7 +73,7 @@ class Origami::CustomersController < BaseOrigamiController @orders.each do |bo| order = Order.find(bo.order_id) - status = order.update_attributes(customer_id: params[:customer_id]) + status = order.update_attributes(customer_id: customer_id) end end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 16590320..e6ddf11f 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -7,7 +7,7 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) end - + @member_discount = MembershipSetting.find_by_discount(1) @accounts = Account.all end @@ -42,6 +42,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.unit_price = di["price"] sale_item.taxable_price = di["price"] sale_item.is_taxable = 0 + sale_item.account_id = origin_sale_item.account_id sale_item.price = di["price"] sale_item.save @@ -49,11 +50,14 @@ class Origami::DiscountsController < BaseOrigamiController end # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } end - dining = {:table_id => table_id, :table_type => table_type } - render :json => dining.to_json + + render :json => result.to_json end # Remove selected discount Items @@ -78,11 +82,12 @@ class Origami::DiscountsController < BaseOrigamiController # sale.save # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) - end + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } + end - dining = {:table_id => table_id, :table_type => table_type } - - render :json => dining.to_json + render :json => result.to_json end # Remove all discount Items @@ -92,13 +97,14 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) table_id = sale.bookings[0].dining_facility_id - table_type = DiningFacility.find(table_id).type - + table_type = DiningFacility.find(table_id).type + + discount_items = [] #destroy all discount sale item - sale.sale_items.each do |si| - if si.remark == "Discount" && si.price < 0 - sale.total_amount = (sale.total_amount + si.price.abs) - si.destroy + sale.sale_items.each do |si| + if si.remark == "Discount" && si.price < 0 + sale.total_amount = (sale.total_amount + si.price.abs) + discount_items.push(si) end end @@ -106,13 +112,99 @@ class Origami::DiscountsController < BaseOrigamiController # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; # sale.save + #destroy in sale.sale_items + sale.sale_items.destroy(discount_items) + # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, 0) + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } + end + + render :json => result.to_json + end + + # Member Discount + def member_discount + sale_id = params[:sale_id] + # account_types = JSON.parse(params[:account_types]) + account_types = Account.where("discount=?",true) + sub_total = params[:sub_total] + sale = Sale.find(sale_id) + price = SaleItem.calculate_price_by_accounts(sale.sale_items) + + arr = Array.new; + + account_types.each do |at| + price.each do |pc| + if pc[:name] == at.title && pc[:price]>0 + str={type:pc[:name],amount:pc[:price]} + arr.push(str) + end + end end - dining = {:table_id => table_id, :table_type => table_type } + generic_customer_id = sale.customer.membership_id - render :json => dining.to_json + receipt_no = sale.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("member_discount") + merchant_uid = memberaction.merchant_account_id.to_s + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => { account_no: nil, + generic_customer_id:generic_customer_id , + campaign_type_id: campaign_type_id, + receipt_no: receipt_no, + merchant_uid:merchant_uid, + campaign_method:arr.to_json, + total_sale_transaction_amount: sale.grand_total, + auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10) + rescue HTTParty::Error + response = {:status=> false, :message => "Can't open membership server " } + + rescue Net::OpenTimeout + response = {:status=> false, :message => "Can't open membership server " } + rescue OpenURI::HTTPError + response = {:status=> false, :message => "Can't open membership server " } + + rescue SocketError + response = {:status=> false, :message => "Can't open membership server " } + end + + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type + + # Re-calc All Amount in Sale + if response["status"] == true + discount_amount = response["discount_earned"] + if response["discount_bonus_earned"] + discount_amount = discount_amount + response["discount_bonus_earned"] + end + sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount') + result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } + end + + if response["status"] == "500" + result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } + end + if !response.nil? + if response[:status] == false + result = {:status=> response[:message],:title=>"Alert", :table_id => table_id,:table_type => table_type } + end + end + + render :json => result.to_json end #discount for selected order diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 32f4ab12..7ee03e47 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -4,7 +4,7 @@ class Origami::HomeController < BaseOrigamiController def index @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.all + @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -13,7 +13,7 @@ class Origami::HomeController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.all + @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') @status_order = "" @status_sale = "" diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb index 50f2c774..6062216f 100644 --- a/app/controllers/origami/movetable_controller.rb +++ b/app/controllers/origami/movetable_controller.rb @@ -44,12 +44,14 @@ class Origami::MovetableController < BaseOrigamiController change_to = params[:change_to] #new change_from = params[:change_from] #original bookings = Booking.where('dining_facility_id=?',change_from) + booking_array = Array.new bookings.each do | booking | - if booking.sale_id.nil? || booking.sale.sale_status != 'completed' || booking.booking_status != 'moved' + if booking.sale_id.nil? && booking.booking_status != 'moved' booking_array.push(booking) end end + @get_type = Booking.update_dining_facility(booking_array,change_to,change_from) end end diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index ef213ddd..f3cddd74 100644 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -3,7 +3,7 @@ class Origami::OrdersController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.all + @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('status desc') @order = Order.find(params[:order_id]) sale_order = SaleOrder.find_by_order_id(@order.order_id) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index bb0d9e42..b0e6472c 100644 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -37,6 +37,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.unit_price = di["price"] sale_item.taxable_price = 0 sale_item.is_taxable = 0 + sale_item.account_id = 0 sale_item.price = di["price"] sale_item.save diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index c050c3f3..2a24e2ac 100644 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -6,6 +6,8 @@ class Origami::OthersPaymentsController < BaseOrigamiController @sale_id = params[:sale_id] @payment_method_setting = PaymentMethodSetting.all + @rebate = MembershipSetting.find_by_rebate(1) + # @sale_id = params[:sale_id] # sale_data = Sale.find_by_sale_id(@sale_id) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index c956f7f9..24d63b71 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -18,7 +18,8 @@ class Origami::PaymentsController < BaseOrigamiController # customer= Customer.where('customer_id=' +.customer_id) customer= Customer.find(sale_data.customer_id) # get member information - if customer.membership_id != nil + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate member_info = Customer.get_member_account(customer) end # get printer info @@ -55,7 +56,8 @@ class Origami::PaymentsController < BaseOrigamiController #shop detail shop_details = Shop.find(1) # get member information - if customer.membership_id != nil + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate member_info = Customer.get_member_account(customer) rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) end @@ -67,10 +69,8 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid") - - - end + printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid") + end end def show @@ -87,12 +87,13 @@ class Origami::PaymentsController < BaseOrigamiController @sale_data = Sale.find_by_sale_id(sale_id) @balance = 0.00 @accountable_type = '' + @table_no = '' #get customer amount @customer = Customer.find(@sale_data.customer_id) - + rebate = MembershipSetting.find_by_rebate(1) # get member information - if @customer.membership_id != nil + if @customer.membership_id != nil && rebate response = Customer.get_member_account(@customer) if response["status"]==true response["data"].each do |res| @@ -107,6 +108,12 @@ class Origami::PaymentsController < BaseOrigamiController #end customer amount + @sale_data.bookings.each do |sbk| + df = DiningFacility.find(sbk.dining_facility_id) + @table_no = df.type + ' ' + df.name + break + end + @sale_data.sale_payments.each do |spay| if spay.payment_method == "cash" @cash = spay.payment_amount @@ -140,7 +147,8 @@ class Origami::PaymentsController < BaseOrigamiController #shop detail shop_details = Shop.find(1) # get member information - if customer.membership_id != nil + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate member_info = Customer.get_member_account(customer) rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index cfea9d37..687c872f 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -5,19 +5,24 @@ class Origami::RequestBillsController < BaseOrigamiController @sale = Sale.new sale_order=SaleOrder.new - order_id = params[:id] # order_id - bk_order = BookingOrder.find_by_order_id(order_id) - check_booking = Booking.find_by_booking_id(bk_order.booking_id) - if check_booking.sale_id.nil? - # Create Sale if it doesn't exist - # puts "current_login_employee" - # puts current_login_employee.name - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil) - @sale_data = Sale.find_by_sale_id(@sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) + if ShiftSale.current_open_shift(current_user.id) + order_id = params[:id] # order_id + bk_order = BookingOrder.find_by_order_id(order_id) + check_booking = Booking.find_by_booking_id(bk_order.booking_id) + if check_booking.sale_id.nil? + # Create Sale if it doesn't exist + # puts "current_login_employee" + # puts current_login_employee.name + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil) + @sale_data = Sale.find_by_sale_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) + else + @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + end else - @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + @status = false + @error_message = "No Current Open Shift for This Employee" end # Not Use for these printed bill cannot give customer diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index e5728f99..823136b9 100644 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -3,7 +3,7 @@ class Origami::RoomsController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.all + @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') @room = DiningFacility.find(params[:room_id]) @sale_array = Array.new @@ -31,9 +31,6 @@ class Origami::RoomsController < BaseOrigamiController end end end - puts "hhhhhhhhhh" - puts @status - puts @obj.to_json end diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 3d632403..209ec4c0 100644 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -21,6 +21,10 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.is_taxable = 1 @newsaleitem.product_name = saleitemObj.product_name + " - void" @newsaleitem.save + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void end # def item_edit @@ -56,6 +60,10 @@ class Origami::SaleEditController < BaseOrigamiController # saleitemObj.remark = 'edit' saleitemObj.product_name = saleitemObj.product_name + " - updated" saleitemObj.save + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void end @@ -71,13 +79,17 @@ class Origami::SaleEditController < BaseOrigamiController end end saleitemObj.destroy + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + saleObj.compute_without_void end # remove all void items def cancel_all_void sale_id = params[:sale_id] - saleobj = Sale.find(sale_id) - saleobj.sale_items.each do |item| + saleObj = Sale.find(sale_id) + saleObj.sale_items.each do |item| if item.qty.to_i < 0 item.destroy else @@ -85,6 +97,9 @@ class Origami::SaleEditController < BaseOrigamiController end item.save end + + # re-calc tax + saleObj.compute_without_void end def apply_void diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index c397da0f..3a9586fb 100644 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -3,7 +3,7 @@ class Origami::SalesController < BaseOrigamiController def show @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') - @complete = Sale.all + @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') @sale = Sale.find(params[:sale_id]) end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index e527da46..e03dd0fc 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,8 +4,6 @@ class Origami::ShiftsController < BaseOrigamiController end def show - puts ">>>>>" - puts current_user.id @shift = ShiftSale.current_open_shift(current_user.id) end @@ -32,18 +30,29 @@ class Origami::ShiftsController < BaseOrigamiController unique_code = "CloseCashierPdf" shop_details = Shop.find(1) + #get tax + shift_obj = ShiftSale.where('id =?',@shift.id) + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') + # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,@shift,shop_details) + printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes) + end - + Employee.logout(session[:session_token]) + session[:session_token] = nil end def edit end + def sale_summary + @shift = ShiftSale.current_open_shift(current_user.id) + + end + end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 687d9fa5..73f89d13 100644 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -3,12 +3,21 @@ class Origami::VoidController < BaseOrigamiController def overall_void sale_id = params[:sale_id] + if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) sale.payment_status = 'void' sale.sale_status = 'void' sale.save + # update count for shift sale + if(sale.sale_status == "void") + if sale.shift_sale_id != nil + shift = ShiftSale.find(sale.shift_sale_id) + shift.calculate(sale_id, "void") + end + end + bookings = sale.bookings bookings.each do |booking| orders = booking.orders diff --git a/app/controllers/reports/bksaleitem_controller.rb b/app/controllers/reports/bksaleitem_controller.rb new file mode 100644 index 00000000..0f91681d --- /dev/null +++ b/app/controllers/reports/bksaleitem_controller.rb @@ -0,0 +1,19 @@ +class Reports::SaleitemController < BaseReportController + authorize_resource :class => false + def index + + from, to, report_type = get_date_range_from_params + + @sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type) + + respond_to do |format| + format.html + format.xls + end + end + + def show + + end + +end diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index 27e812ab..fc1f150f 100644 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -2,9 +2,12 @@ class Reports::DailysaleController < BaseReportController authorize_resource :class => false def index - from, to ,report_type = get_date_range_from_params + from, to = get_date_range_from_params @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) + @from = from + @to = to + respond_to do |format| format.html format.xls diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index e4157c4e..3ca19e9d 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -1,13 +1,37 @@ class Reports::ReceiptNoController < BaseReportController authorize_resource :class => false def index - from, to = get_date_range_from_params - puts "from..." - puts from - puts "to..." - puts to - @sale_data = Sale.get_receipt_no_list(from,to) - @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) + @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"], ["Other Payment","card"]] + + from, to = get_date_range_from_params + + @shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + @shift = '' + if params[:shift_name].to_i != 0 + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) + @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type) + + @from = from + @to = to + + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + respond_to do |format| format.html format.xls @@ -15,6 +39,25 @@ authorize_resource :class => false end def show - + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end end end \ No newline at end of file diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 0f91681d..00be65e6 100644 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -2,9 +2,43 @@ class Reports::SaleitemController < BaseReportController authorize_resource :class => false def index - from, to, report_type = get_date_range_from_params + from, to = get_date_range_from_params + shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) - @sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type) + shift = '' + if params[:shift_name].to_i != 0 + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + @sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + + + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.menu_category_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end respond_to do |format| format.html @@ -13,7 +47,26 @@ class Reports::SaleitemController < BaseReportController end def show - - end + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + end diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 87fae97d..5bc2020c 100644 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -3,16 +3,48 @@ class Reports::ShiftsaleController < BaseReportController def index - from, to, report_type = get_date_range_from_params - @sale_data = Sale.get_by_shiftsales(from,to) - respond_to do |format| + from, to = get_date_range_from_params + @shift = '' + if params[:shift_name].to_i != 0 + @shift = ShiftSale.find(params[:shift_name]) + end + @sale_data = Sale.get_by_shiftsales(from,to,@shift) + @from = from + @to = to + if @shift.present? + + @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = @shift + end + + respond_to do |format| format.html format.xls end end def show - + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end end end diff --git a/app/controllers/settings/membership_settings_controller.rb b/app/controllers/settings/membership_settings_controller.rb index 36bb0092..d4da84cd 100644 --- a/app/controllers/settings/membership_settings_controller.rb +++ b/app/controllers/settings/membership_settings_controller.rb @@ -70,6 +70,6 @@ class Settings::MembershipSettingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_membership_setting_params - params.require(:membership_setting).permit(:membership_type, :is_active, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by) + params.require(:membership_setting).permit(:membership_type, :is_active,:discount,:rebate,:bonus,:point, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 96956958..ae3934e4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,25 @@ module ApplicationHelper - def flash_class(level) - case level - when :notice then "alert alert-info fade-in" - when :success then "alert alert-success fade-in" - when :error then "alert alert-error fade-in" - when :alert then "alert alert-error fade-in" - end -end + def flash_class(level) + case level + when :notice then "alert alert-info fade-in" + when :success then "alert alert-success fade-in" + when :error then "alert alert-error fade-in" + when :alert then "alert alert-error fade-in" + end + end + + # For Pageless + # def pageless(total_pages, url=nil, container=nil) + # opts = { + # :totalPages => total_pages, + # :url => url, + # :loaderMsg => 'Loading more pages...', + # :loaderImage => image_path('load.gif') + # } + + # container && opts[:container] ||= container + + # javascript_tag("$('#{container}').pageless(#{opts.to_json});") + # end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 3e5fc8b6..368aa424 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -75,8 +75,8 @@ class Ability can :read, Sale can :update, Sale - can :add_customer, Customer - can :update_sale_by_customer, Customer + can :add_customer, Customer + can :update_sale_by_customer, Customer can :index, :other_charge can :create, :other_charge @@ -84,6 +84,7 @@ class Ability can :create, :discount can :remove_discount_items, :discount can :remove_all_discount, :discount + can :member_discount, :discount can :first_bill, :payment can :show, :payment @@ -100,8 +101,10 @@ class Ability can :show, :payment can :create, :payment can :reprint, :payment + + can :manage, DiningQueue - elsif user.role == "accountant" + elsif user.role == "account" can :index, :dailysale can :index, :saleitem @@ -110,11 +113,19 @@ class Ability elsif user.role == "supervisour" - can :index, :dailysale - can :index, :saleitem - can :index, :receipt_no - can :index, :shiftsale + can :edit, :sale_edit + can :item_void, :sale_edit + can :item_edit, :sale_edit + can :item_void_cancel, :sale_edit + can :cancel_all_void, :sale_edit + can :apply_void, :sale_edit + can :overall_void, :void + can :first_bill, :payment + can :create, :payment + can :show, :payment + can :reprint, :payment + can :rounding_adj, :payment end end diff --git a/app/models/booking.rb b/app/models/booking.rb index cc4ae389..e3d94a37 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -1,4 +1,3 @@ - class Booking < ApplicationRecord self.primary_key = "booking_id" @@ -14,6 +13,7 @@ class Booking < ApplicationRecord def self.update_dining_facility(booking_arr, newd, old) table = DiningFacility.find(newd) exist = table.get_booking + if exist # order exists booking_arr.each do |booking| diff --git a/app/models/customer.rb b/app/models/customer.rb index 2f09ff12..ef777c2d 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,6 +10,7 @@ class Customer < ApplicationRecord validates :contact_no, uniqueness: true validates :email, uniqueness: true validates :card_no, uniqueness: true + # validates :paypar_account_no paginates_per 50 @@ -66,6 +67,9 @@ class Customer < ApplicationRecord }, :timeout => 10 ) + rescue HTTParty::Error + response = {status: false, message: "Can't open membership server " } + rescue Net::OpenTimeout response = { status: false , message: "Server Time out"} @@ -193,7 +197,7 @@ class Customer < ApplicationRecord def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) - where("name LIKE ? OR contact_no LIKE ? OR card_no LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%",) + where("name LIKE ? OR contact_no LIKE ? OR card_no LIKE ? OR paypar_account_no ='#{search}'", "%#{search}%", "%#{search}%", "%#{search}%",) else find(:all) end diff --git a/app/models/employee.rb b/app/models/employee.rb index 2d70768d..7693c448 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -54,6 +54,7 @@ class Employee < ApplicationRecord def self.logout(session_token) if (session_token) user = Employee.find_by_token_session(session_token) + if user user.token_session = nil user.session_expiry = nil diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index e660b4b5..71ad42c8 100644 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,10 +1,12 @@ -class MenuCategory < ApplicationRecord +class MenuCategory < ApplicationRecord + before_create :generate_menu_category_code + belongs_to :menu has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id" belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true has_many :menu_items - validates_presence_of :name, :menu, :code, :order_by + validates_presence_of :name, :menu, :order_by default_scope { order('order_by asc') } @@ -12,7 +14,7 @@ class MenuCategory < ApplicationRecord # find the sub menu item of current item sub_menu_cat = MenuCategory.where("menu_category_id=?",menu_category.id) if sub_menu_cat.length != 0 - sub_menu_cat.each do |sub| + sub_menu_cat.each do |sub| if destroyCategory(sub) end end @@ -20,17 +22,22 @@ class MenuCategory < ApplicationRecord items = MenuItem.where("menu_category_id=?",menu_category.id) items.each do |item| abc = MenuItem.deleteRecursive(item) - end + end menu_category.destroy return true else items = MenuItem.where("menu_category_id=?",menu_category.id) items.each do |item| abc = MenuItem.deleteRecursive(item) - end + end menu_category.destroy return false end end + private + + def generate_menu_category_code + self.code = SeedGenerator.generate_code(self.class.name, "C") + end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 50b70e66..1f1afbe4 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,17 +1,19 @@ class MenuItem < ApplicationRecord + before_create :generate_menu_item_code + belongs_to :menu_category, :optional => true has_many :menu_item_instances belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" belongs_to :account - validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item + validates_presence_of :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item default_scope { order('item_code asc') } scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } - scope :set_menu_item, -> { where(type: 'SetMenuItem') } + scope :set_menu_item, -> { where(type: 'SetMenuItem') } def self.collection MenuItem.select("id, name").map { |e| [e.name, e.id] } @@ -46,7 +48,7 @@ class MenuItem < ApplicationRecord # find the sub menu item of current item sub_menu_items = MenuItem.where("menu_item_id=?",menu_item.id) if sub_menu_items.length != 0 - sub_menu_items.each do |subitem| + sub_menu_items.each do |subitem| if deleteRecursive(subitem) end end @@ -54,17 +56,24 @@ class MenuItem < ApplicationRecord instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) instances.each do |instance| instance.destroy - end + end menu_item.destroy return true else instances = MenuItemInstance.where("menu_item_id=?",menu_item.id) instances.each do |instance| instance.destroy - end + end menu_item.destroy return false end - end + end + + private + + def generate_menu_item_code + self.item_code = SeedGenerator.generate_code(self.class.name, "I") + end + end diff --git a/app/models/menu_item_instance.rb b/app/models/menu_item_instance.rb index 09225a23..f39c29a2 100644 --- a/app/models/menu_item_instance.rb +++ b/app/models/menu_item_instance.rb @@ -1,6 +1,7 @@ class MenuItemInstance < ApplicationRecord belongs_to :menu_item - + before_create :generate_menu_item_instance_code + def self.findParentCategory(item) if item.menu_category_id return item.menu_category_id @@ -9,4 +10,10 @@ class MenuItemInstance < ApplicationRecord findParentCategory(parentitem) end end + + private + + def generate_menu_item_instance_code + self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II") + end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 564b4909..55bf8c39 100644 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,13 +22,17 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,shift_sale,shop_details) + def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes) #Use CUPS service #Generate PDF #Print - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details) - pdf.render_file "tmp/print_close_cashier.pdf" - self.print("tmp/print_close_cashier.pdf") + cashier = shift_sale.employee.name + shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes) + filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" + pdf.render_file filename + self.print(filename) end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 6c8ba7e2..f66f1bc9 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -6,7 +6,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #Print order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) - filename = "tmp/order_item_#{order_item[0].item_name}" + ".pdf" + filename = "tmp/order_item.pdf" # check for item not to show if order_item[0].price != 0 @@ -35,7 +35,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # For Print Per Item if oqs.cut_per_item order.each do|odi| - filename = "tmp/order_item_#{odi.item_name}" + ".pdf" + filename = "tmp/order_item.pdf" # For Item Options options = odi.options == "[]"? "" : odi.options @@ -54,7 +54,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/order_summary_#{ order_id }" + ".pdf" + filename = "tmp/order_summary.pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name) pdf.render_file filename if oqs.print_copy @@ -75,7 +75,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # For Print Per Item if oqs.cut_per_item order.each do|odi| - filename = "tmp/order_item_#{odi.item_name}" + ".pdf" + filename = "tmp/order_item.pdf" # For Item Options options = odi.options == "[]"? "" : odi.options @@ -97,7 +97,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else - filename = "tmp/booking_summary_#{ booking_id }" + ".pdf" + filename = "tmp/booking_summary.pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name) pdf.render_file filename if oqs.print_copy diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 652339b9..4bd25201 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -75,8 +75,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # print as print copies in printer setting count = printer_settings.print_copies begin - pdf.render_file "tmp/receipt_bill.pdf" - self.print("tmp/receipt_bill.pdf") + if count == 1 + pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}.pdf" + self.print("tmp/receipt_bill_#{sale_data.receipt_no}.pdf") + else + pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + self.print("tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf") + end + count -= 1 end until count == 0 end diff --git a/app/models/sale.rb b/app/models/sale.rb index 0e767ea0..197c7106 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -42,8 +42,8 @@ class Sale < ApplicationRecord booking.sale_id = sale_id end - order = booking.booking_orders.take.order - link_order_sale(order.id) + order = booking.booking_orders.take.order + link_order_sale(order.id) return status, sale_id end @@ -208,7 +208,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -227,6 +227,9 @@ class Sale < ApplicationRecord sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + if discount_type == "member_discount" + sale.discount_type = discount_type + end #compute rounding adjustment # adjust_rounding @@ -246,7 +249,7 @@ class Sale < ApplicationRecord if item.remark != 'void' #compute each item and added to total subtotal_price = subtotal_price + item.price - total_taxable = total_taxable + item.taxable_price + total_taxable = total_taxable + item.price end end @@ -320,7 +323,8 @@ class Sale < ApplicationRecord sale_tax.tax_rate = tax.rate #include or execulive # sale_tax.tax_payable_amount = total_taxable * tax.rate - sale_tax.tax_payable_amount = total_taxable * tax.rate / 100 + total_tax = total_taxable - self.total_discount + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 #new taxable amount is standard rule for step by step # total_taxable = total_taxable + sale_tax.tax_payable_amount @@ -427,7 +431,7 @@ class Sale < ApplicationRecord SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount, SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, - SUM(case when (sale_payments.payment_method='credit') then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") .joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id") .where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to) @@ -445,6 +449,7 @@ class Sale < ApplicationRecord total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, + IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj") .where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date) @@ -454,6 +459,7 @@ class Sale < ApplicationRecord old_grand_total = sale.old_grand_total total_discount = sale.total_discount void_amount = sale.void_amount + total_change_amount = sale.total_change_amount total = {:sale_date => pay.sale_date, :mpu_amount => pay.mpu_amount, :master_amount => pay.master_amount, @@ -464,6 +470,7 @@ class Sale < ApplicationRecord :credit_amount => pay.credit_amount, :foc_amount => pay.foc_amount, :total_discount => total_discount, + :total_change_amount => total_change_amount, :grand_total => grand_total, :old_grand_total => old_grand_total, :void_amount => void_amount, @@ -493,89 +500,218 @@ def self.get_by_range_by_saleitems(from,to,status,report_type) JOIN employees ea ON ea.id = sales.cashier_id") - query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status) + query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status) - case report_type.to_i - when REPORT_TYPE["daily"] - return query - when REPORT_TYPE["monthly"] - - return query.group("MONTH(date)") - when REPORT_TYPE["yearly"] - return query.group("YEAR(date)") - end end -def self.get_by_shiftsales(from,to) - return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) +def self.get_by_shiftsales(from,to,shift) + if !shift.blank? + ShiftSale.where("id =?",shift.id) + else + ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) + end end -# def self.get_by_shiftsales(employee,from,to) -# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date') -# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id") -# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to) -# .order("shift_sales.id DESC") +def self.get_by_shift_sale(from,to,status) + query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date, + shift_closed_at As closing_date," + + " grand_total AS grand_total, cash_sales AS cash," + + "total_taxes AS total_tax,total_discounts As total_discount") + .order("shift_sales.id DESC") + return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) +end -# sale_arr = Array.new -# shift_sales.each do |shift| -# all_total= Sale.select("grand_total,sr.payment_method, sr.payment_amount, rounding_adjustment") -# .joins("join employees e on sales.cashier_id = e.id join shift_sales sh on sh.id = sales.shift_sale_id") -# .joins("INNER JOIN (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sr ON sr.sale_id = sales.sale_id") -# .where("sales.shift_sale_id =? and sales.sale_status = 'completed' and sales.total_amount != 0",shift.id) - -# void = Sale.select("SUM(sales.grand_total) AS grand_total") -# .joins("join shift_sales sh on sh.id = sales.shift_sale_id") -# .where('sales.sales_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id) -# .sum(:grand_total) -# cash = all_total.select('sr.payment_type') -# .where('sr.payment_type = "cash"') -# .sum(:amount) +def self.get_item_query() + query = Sale.select("acc.title as account_name,mi.account_id, mi.item_code as item_code, " + + "(SUM(i.qty * i.unit_price)) as grand_total,SUM(i.qty) as total_item," + + " i.unit_price as unit_price,mi.name as product_name, mc.name as" + + " menu_category_name,mc.id as menu_category_id ") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code" + + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id JOIN menu_categories mc ON mc.id = mi.menu_category_id ") + # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") -# credit = all_total.where('sr.payment_type = "credit"') -# .sum(:amount) - -# accept_credit = all_total.select('ci.amout') -# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id") -# .where('sr.payment_type = "credit"') -# .sum(:amout) - + query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") + query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id") + end + + + def self.get_by_shift_items(shift_sale_range, shift, from, to, status) + + # date_type_selection = get_sql_function_for_report_type(report_type) + + query = self.get_item_query() + discount_query = 0 + total_card_amount = 0 + total_cash_amount = 0 + total_credit_amount = 0 + total_foc_amount = 0 + total_grand_total = 0 - -# foc = all_total.where('sales.payment_type = "foc" and sales.sales_status = "completed"') -# .sum(:grand_total) - -# card = all_total.select('payment_type') -# .where('sr.payment_type = "card"') -# .sum(:amount).to_f - -# rounding_adj = all_total.sum(:rounding_adjustment) + if shift.present? + query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + ### => get all sales range in shift_sales + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + else + query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) + change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + end -# discount = all_total.sum(:discount_amount) -# void = void.nil? ? 0 : void -# cash = cash.nil? ? 0 : cash -# credit = credit.nil? ? 0 : credit -# foc = foc.nil? ? 0 : foc -# card = card.nil? ? 0 : card -# accept_credit = accept_credit.nil? ? 0 : accept_credit -# # all_payments = void.to_d + cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d -# all_payments = cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d -# payments = { void_amount: void, cash_amount: cash, credit_amount: credit,accept_credit_amount: accept_credit, foc_amount: foc, card_amount: card, grand_total: all_payments , cashier_station_name: shift.cashier_station_name, opening_date: shift.opening_date, closing_date: shift.closing_date, rounding_adj: rounding_adj } + return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end -# sale_arr.push(payments) -# end +def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type) + ## => left join -> show all sales although no orders + if payment_type.blank? + payment_type = '' + else + if payment_type == 'card' + payment_type = " and sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar'" + else + payment_type = " and sale_payments.payment_method = '#{payment_type}'" + end + end + + query = Sale.all + if shift.present? -# return sale_arr -# end + query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id") + + elsif shift_sale_range.present? + + query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id") + + else + + query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id") + end + +end + +def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) + + if payment_type.blank? + payment_type = '' + else + if payment_type == 'card' + payment_type = " and sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar'" + else + payment_type = " and sale_payments.payment_method = '#{payment_type}'" + end + end + + if shift.present? + query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + .group("sale_taxes.tax_name") + .order("sale_taxes.sale_tax_id asc") + elsif shift_sale_range.present? + query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a) + .group("sale_taxes.tax_name") + .order("sale_taxes.sale_tax_id asc") + else + query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", from,to) + .group("sale_taxes.tax_name") + .order("sale_taxes.sale_tax_id asc") + end + + # query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + # .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id") + # .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + # .group("sale_taxes.tax_name") + # .order("sale_taxes.sale_tax_id asc") + + # if shift.present? + # query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed'", shift.to_a) + # else + # query = query.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' ",from,to) + # end +end + +# def self.get_separate_tax(from,to,payment_method=nil) + +# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") +# .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id") +# .group("sale_taxes.tax_name") + +# return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to) +# end + +def grand_total_after_rounding + return self.old_grand_total.to_f + self.rounding_adjustment.to_f +end def get_cash_amount cash = 0.0 self.sale_payments.each do |pay| if pay.payment_method == 'cash' - cash = pay.payment_amount + cash = pay.payment_amount-self.amount_changed end end return cash @@ -604,7 +740,7 @@ end def get_commerical_tax tax = 0.0 self.sale_taxes.each do |taxobj| - if taxobj.tax_name == "Commerical Tax" + if taxobj.tax_name == "Commercial Tax" tax += taxobj.tax_payable_amount end end @@ -616,8 +752,4 @@ end def generate_custom_id self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL") end - - def self.get_receipt_no_list(from,to) - sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to) - end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 3cc0eb43..af2230de 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -57,7 +57,7 @@ class SaleItem < ApplicationRecord # Check for actual sale items sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si| if si.account_id == a.id - discount_account[:price] = (discount_account[:price] + si.price) * -1 + discount_account[:price] = (discount_account[:price].abs + si.price.abs) * -1 end end discount_accounts.push(discount_account) @@ -66,26 +66,32 @@ class SaleItem < ApplicationRecord return discount_accounts end - # Calculate rebate_by_account + # Calculate rebate_by_account def self.calculate_rebate_by_account(sale_items) rebateacc = Account.where("rebate=?",true) - puts "Account that can rebate" - rebateacc.each do |i| - puts i.title - end - prices=0 - sale_items.each do |si| - price = self.get_rebate_price(si.sale_item_id,rebateacc) + price = 0 + rebate_arr = [] + rebateacc.each do |a| + account_price = {:type => a.title, :amount => 0} - prices = prices + price + # Check for actual sale items + sale_items.each do |si| + if si.account_id == a.id + account_price[:amount] = account_price[:amount] + si.price + price = price + si.price + end + + end + rebate_arr.push(account_price) end - return prices + + return price,rebate_arr end # get food price or beverage price for item def self.get_rebate_price(sale_item_id,rebateacc) - price=0 - + price = 0 + type = '' item=SaleItem.select("sale_items.price , menu_items.account_id") .joins("left join menu_items on menu_items.item_code = sale_items.product_code") .where("sale_items.sale_item_id=?", sale_item_id.to_s) @@ -93,12 +99,14 @@ class SaleItem < ApplicationRecord rebateacc.each do |i| if item[0].account_id == i.id price = item[0].price + type = i.title end end - return price + return price,type end + # def self.get_overall_discount(sale_id) # price = 0.0 # item=SaleItem.where("product_code=?", sale_id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index b3455e27..74764785 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -77,7 +77,10 @@ class SalePayment < ApplicationRecord # Control for Paypar Cloud begin response = HTTParty.get(url, - :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :body => { app_token: token,membership_id:membership_id, + campaign_type_id:campaign_type_id,merchant_uid:merchant_uid, + auth_token:auth_token + }.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -115,7 +118,14 @@ class SalePayment < ApplicationRecord # Control for Paypar Cloud begin response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,total_amount: redeem_prices,total_sale_transaction_amount: sale_data.grand_total,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :body => { generic_customer_id:membership_id, + total_amount: redeem_prices, + total_sale_transaction_amount: sale_data.grand_total, + redeem_amount:received_amount, + receipt_no:sale_data.receipt_no, + campaign_type_id:campaign_type_id, + account_no:"",merchant_uid:merchant_uid, + auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -261,26 +271,31 @@ class SalePayment < ApplicationRecord end self.sale.sale_status = "completed" - response = rebat(sObj) + if MembershipSetting.find_by_rebate(1) + response = rebat(sObj) - if response["status"] == true - self.sale.rebate_status = 'true' - end - if response["status"] == false - self.sale.rebate_status = 'false' - end + if !response.nil? + if response["status"] == true + self.sale.rebate_status = 'true' + end + if response["status"] == false + self.sale.rebate_status = 'false' + end - if response[:status] == false - self.sale.rebate_status = 'false' - end - if response[:status] == "no_member" - self.sale.rebate_status = nil + if response[:status] == false + self.sale.rebate_status = 'false' + end + if response[:status] == "no_member" + self.sale.rebate_status = nil + end + end + puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr" + puts response.to_json end self.sale.save! table_update_status(sObj) - if paid_amount != "0.0" update_shift end @@ -288,6 +303,7 @@ class SalePayment < ApplicationRecord end + # update for cashier shift def update_shift shift = ShiftSale.current_open_shift(self.sale.cashier_id) if !shift.nil? @@ -305,10 +321,14 @@ class SalePayment < ApplicationRecord bookings = table.bookings bookings.each do |tablebooking| if tablebooking.booking_status != 'moved' - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + if tablebooking.sale_id + if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + status = false + end + else status = false - end - end + end + end end if status table.status = "available" @@ -318,13 +338,14 @@ class SalePayment < ApplicationRecord end def rebat(sObj) - rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items) - + rebate_prices,campaign_method = SaleItem.calculate_rebate_by_account(sObj.sale_items) generic_customer_id = sObj.customer.membership_id if generic_customer_id.present? - paypar = sObj.sale_payments + + paypar = sObj.sale_payments payparcost = 0 - credit = 0 + credit = 0 + paypar.each do |pp| if pp.payment_method == "paypar" payparcost = payparcost + pp.payment_amount @@ -333,46 +354,113 @@ class SalePayment < ApplicationRecord end end # overall_dis = SaleItem.get_overall_discount(sObj.id) - overall_dis = sObj.total_discount - - total_amount = rebate_prices - payparcost - overall_dis - if credit == 1 - total_amount = 0 - end - if total_amount >= 0 - receipt_no = sObj.receipt_no - membership = MembershipSetting.find_by_membership_type("paypar_url") - memberaction = MembershipAction.find_by_membership_type("rebate") - merchant_uid = memberaction.merchant_account_id.to_s - campaign_type_id = memberaction.additional_parameter["campaign_type_id"] - auth_token = memberaction.auth_token.to_s - url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + overall_dis = sObj.total_discount + + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("get_member_campaign") + merchant_uid = memberaction.merchant_account_id.to_s + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s # Control for Paypar Cloud begin - response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_sale_transaction_amount: sObj.grand_total,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, - receipt_no: receipt_no,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }, :timeout => 10) + response = HTTParty.get(url, + :body => { + member_group_id:sObj.customer.membership_type, + merchant_uid:merchant_uid, + campaign_type_id: campaign_type_id, + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10) rescue Net::OpenTimeout response = { "status": false , "message": "Connect To" } - - rescue OpenURI::HTTPError response = { "status": false, "message": "Can't connect server"} rescue SocketError response = { "status": false, "message": "Can't connect server"} + end + + redeem_amount = payparcost + overall_dis + + total_percentage = 0 + + type_arr = [] + response["membership_campaign_data"].each do |a| + data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i} + total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i + + type_arr.push(data) + end + + rebate_arr =[] + campaign_method.each do |a| + data = {:type => a[:type], :amount => a[:amount]} + puts data + type_arr.each do |si| + if si[:type] == a[:type] + puts "steeeeeeeeeeeee" + amount = (redeem_amount / total_percentage)*si[:percentage] + actual = a[:amount] - amount + data[:amount] = actual + end + + end + rebate_arr.push(data) + + end + puts "ssssssssss" + puts rebate_arr.to_json + total_amount = rebate_prices - payparcost - overall_dis + + if credit == 1 + total_amount = 0 + end + if total_amount >= 0 + receipt_no = sObj.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("rebate") + merchant_uid = memberaction.merchant_account_id.to_s + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => { + generic_customer_id:generic_customer_id , + total_sale_transaction_amount: sObj.grand_total, + merchant_uid:merchant_uid, + total_amount: total_amount, + campaign_type_id: campaign_type_id, + receipt_no: receipt_no, + campaign_method: rebate_arr.to_json, + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10) + rescue Net::OpenTimeout + response = { "status": false , "message": "Connect To" } + rescue OpenURI::HTTPError + response = { "status": false, "message": "Can't connect server"} + rescue SocketError + response = { "status": false, "message": "Can't connect server"} end return response + puts "latest respppppp" puts response.to_json - end + end else response = { "status": "no_member", "message": "Not membership"} - + end end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index fe896a4d..335ab131 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,5 +1,5 @@ class SeedGenerator < ApplicationRecord - + # Generate ID for Tables def self.generate_id(model, prefix) seed = SeedGenerator.find_by_model(model) new_receipt_no = 0 @@ -23,6 +23,7 @@ class SeedGenerator < ApplicationRecord end + # Generate Receipt No def self.new_receipt_no seed = SeedGenerator.find_by_model("sale") new_receipt_no = 0 @@ -41,4 +42,33 @@ class SeedGenerator < ApplicationRecord return seed.current end + + # Generate for 4 digit Code + def self.generate_code(model, prefix) + seed = SeedGenerator.find_by_model(model) + new_code = 0 + + if (seed.nil?) + seed = SeedGenerator.new() + seed.model = model + new_code = seed.next + seed.save + else + current_no = seed.next + seed.next = seed.next + seed.increase_by + seed.current = current_no + seed.save + end + + + if prefix.length == 1 + padding_len = 5 - prefix.length + count = 4-prefix.length + else prefix.length == 2 + padding_len = 6 - prefix.length + count = 5-prefix.length + end + next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0') + return next_code + end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index b9c5aa28..b7ce7299 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -18,15 +18,16 @@ class ShiftSale < ApplicationRecord def self.current_shift today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null",today_date).take + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").take return shift end def self.current_open_shift(current_user) #if current_user #find open shift where is open today and is not closed and login by current cashier + #DATE(shift_started_at)=? and today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}",today_date).take + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift #end end @@ -52,10 +53,34 @@ 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.grand_total.to_i - self.commercial_taxes + self.nett_sales = self.nett_sales + saleobj.total_amount.to_f #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 self.save + end + # Calculate by type and update + def calculate(sale, type) + saleobj = Sale.find_by_sale_id(sale) + cash = saleobj.get_cash_amount + credit = saleobj.get_credit_amount + other_sales = saleobj.get_other_amount + tax = saleobj.get_commerical_tax + if type == "void" + self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f + self.total_discounts = self.total_discounts - saleobj.total_discount + self.total_taxes = self.total_taxes - saleobj.total_tax + self.grand_total = self.grand_total - saleobj.grand_total + 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.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_void = self.total_void + saleobj.grand_total + self.save + end end def get_closing_balance(shift) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index fc04b6cc..893746b2 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,6 +1,6 @@ class CloseCashierPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width - def initialize(printer_settings, shift_sale,shop_details) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes) self.page_width = 210 self.page_height = 7000 self.margin = 5 @@ -32,7 +32,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale) + shift_detail(shift_sale,sale_taxes) @@ -51,7 +51,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale) + def shift_detail(shift_sale,sale_taxes) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -68,6 +68,22 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.cashier_terminal.name}" , :size => self.item_font_size,:align => :left end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_started_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -88,6 +104,12 @@ class CloseCashierPdf < Prawn::Document move_down 10 + y_position = cursor + bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do + text "Shift Sale Summary", :size => self.header_font_size, :align => :center + end + move_down 10 + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Received Amount :", :size => self.item_font_size, :align => :right @@ -96,6 +118,23 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.closing_balance}", :size => self.item_font_size, :align => :right end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash In:", :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.cash_in}", :size => self.item_font_size, :align => :right + end + + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash Out:", :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.cash_out}", :size => self.item_font_size, :align => :right + end + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Net Sales:", :size => self.item_font_size, :align => :right @@ -151,15 +190,17 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{shift_sale.total_discounts}", :size => self.item_font_size, :align => :right end - - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Commercial Tax :", :size => self.item_font_size, :align => :right + + sale_taxes.each do |tax| + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{tax.st_amount.round(2)}", :size => self.item_font_size, :align => :right + end end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.commercial_taxes}", :size => self.item_font_size, :align => :right - end - y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Grand Total :", :size => self.item_font_size, :align => :right @@ -168,6 +209,22 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Receipts :", :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_receipt}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Void:", :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_void})", :size => self.item_font_size, :align => :right + end + move_down 5 stroke_horizontal_rule move_down 5 diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 546e8f82..20a4537c 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -6,7 +6,7 @@ class OrderItemPdf < Prawn::Document self.page_height = 1450 self.margin = 0 self.price_width = 40 # No Need for item - self.qty_width = 35 + self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) self.item_height = 15 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 6d530058..244fbdfa 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -6,7 +6,7 @@ class OrderSummaryPdf < Prawn::Document self.page_height = 1450 self.margin = 0 self.price_width = 40 # No Need for item - self.qty_width = 35 + self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) self.item_height = 15 @@ -68,7 +68,7 @@ class OrderSummaryPdf < Prawn::Document text "Item", :size => self.item_font_size,:align => :left end - bounding_box([self.item_width-2,y_position], :width => self.qty_width, :height => self.item_height) do + bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do text "Qty", :size => self.item_font_size,:align => :left end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index bd65ed20..28ce5745 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,6 +1,6 @@ class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper - attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status) self.page_width = 210 self.page_height = 7000 @@ -12,6 +12,9 @@ class ReceiptBillPdf < Prawn::Document self.item_height = 15 self.item_description_width = (self.page_width-20) / 2 self.label_width = 100 + + self.description_width = 150 + self.price_num_width = 50 # @item_width = self.page_width.to_i / 2 # @qty_width = @item_width.to_i / 3 # @double = @qty_width * 1.3 @@ -73,10 +76,10 @@ class ReceiptBillPdf < Prawn::Document move_down 7 # move_down 2 y_position = cursor - bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + bounding_box([self.description_width,y_position], :width => self.price_num_width, :height => self.item_height) do text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right end move_down 5 @@ -140,10 +143,13 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor pad_top(15) { - text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size, :overflow => :shrink_to_fix - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + bounding_box([0,y_position], :width =>self.item_width) do + text "#{product_name}", :size => self.item_font_size,:align => :left + end + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 end @@ -165,9 +171,14 @@ class ReceiptBillPdf < Prawn::Document def all_total(sale_data,precision,delimiter) item_name_width = self.item_width y_position = cursor + if sale_data.discount_type == 'member_discount' + dis_type = "Member Discount:" + else + dis_type = "Overall Discount:" + end bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Overall Discount", :size => self.item_font_size,:align => :left + text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right @@ -317,16 +328,16 @@ class ReceiptBillPdf < Prawn::Document text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end - # old = balance + redeem + old = balance + redeem - # move_down 5 - # y_position = cursor - # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - # text "Old Balance", :size => self.item_font_size,:align => :left - # end - # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - # text "#{number_with_precision(old, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - # end + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Old Balance", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(old, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end end end @@ -386,10 +397,10 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor item_price_by_accounts.each do |ipa| y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.label_width) do text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end diff --git a/app/views/crm/customers/_crm_customer.json.jbuilder b/app/views/crm/customers/_crm_customer.json.jbuilder index 1b1b237e..c0d66225 100644 --- a/app/views/crm/customers/_crm_customer.json.jbuilder +++ b/app/views/crm/customers/_crm_customer.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at,:salutation, :gender,:nrc_no,:address,:card_no +json.extract! crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at,:salutation, :gender,:nrc_no,:address,:card_no, :paypar_account_no json.url crm_customer_url(crm_customer, format: :json) diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 66a16b2b..3c09d20f 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -1,7 +1,5 @@
| Membership Transactions | - -Current Balance : <%= @balance%> | - -||||||
|---|---|---|---|---|---|---|---|
| Date | -Redeem | -Rebate | -Balance | + +Discount Amount | +From Account | Status | Receipt No | @@ -86,9 +79,9 @@ <% @response["data"].each do |transaction| %>
| <%= transaction["date"]%> | -<%= transaction["redeem"]%> | +<%= transaction["rebate"] %> | -<%= transaction["balance"] %> | +<%= transaction["account_status"] %> | <%= transaction["status"] %> | <%= transaction["receipt_no"] %> | diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder index 86901801..5fd0410a 100644 --- a/app/views/crm/customers/show.json.jbuilder +++ b/app/views/crm/customers/show.json.jbuilder @@ -1,4 +1,4 @@ json.extract! @crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, - :salutation, :gender,:nrc_no,:address,:card_no + :salutation, :gender,:nrc_no,:address,:card_no, :paypar_account_no json.url crm_customer_url(@crm_customer, format: :json) diff --git a/app/views/crm/dining_queues/index.html.erb b/app/views/crm/dining_queues/index.html.erb index 4f39147f..3d186efe 100644 --- a/app/views/crm/dining_queues/index.html.erb +++ b/app/views/crm/dining_queues/index.html.erb @@ -50,6 +50,7 @@|