diff --git a/Gemfile b/Gemfile index e6e99241..53d6f963 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -# gem 'pg' +gem 'pg' # redis server for cable # gem 'redis', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7b18943d..3fabf983 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,7 @@ GEM nokogiri (1.8.0) mini_portile2 (~> 2.2.0) pdf-core (0.7.0) + pg (0.20.0) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -246,6 +247,7 @@ DEPENDENCIES kaminari (~> 0.16.3) listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) + pg prawn prawn-table puma (~> 3.0) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index f1df9cf8..dc3ab163 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -68,11 +68,12 @@ $(document).ready(function(){ // Receipt Header receipt_no = result[i].receipt_no; cashier = result[i].cashier_name; - receipt_date = result[i].receipt_date; + receipt_date = new Date(result[i].receipt_date); + show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() $("#receipt_no").text(receipt_no); $("#cashier").text(cashier == null ? "" : cashier); - $("#receipt_date").text(receipt_date); + $("#receipt_date").text(show_date); //Receipt Charges @@ -132,7 +133,8 @@ $(document).ready(function(){ }); // Pay Discount for Payment - $("#pay-discount").on('click', function(){ + $("#pay-discount").on('click', function(e){ + e.preventDefault(); var sale_id = $('#sale-id').text(); var sale_item_id = $('.selected-item').attr('id'); var sub_total = $('#order-sub-total').text(); @@ -140,10 +142,10 @@ $(document).ready(function(){ var discount_type = $('#discount-type').val(); var discount_value = $('#discount-amount').val(); var discount_amount = discount_value; + var ajax_url = "/origami/" + sale_id + "/discount"; - if(sale_item_id == null){ - alert('Please select item row to discount!'); - return; + if(sale_item_id != null){ + ajax_url = "/origami/" + sale_item_id + "/discount"; } // For Percentage Discount @@ -154,7 +156,7 @@ $(document).ready(function(){ var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; $.ajax({ type: "POST", - url: "/origami/" + sale_item_id + "/discount", + url: ajax_url, data: params, success:function(result){ } }); diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 193a4a45..a01cc717 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -8,9 +8,15 @@ class Api::BillController < Api::ApiController #create Bill by Booking ID if (params[:booking_id]) - @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) - + booking = Booking.find(params[:booking_id]) + if booking + if booking.sale_id.nil? + @sale = Sale.new + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) + else + @status = true + end + end elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee.name) diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 77e38f2c..c1ae1a01 100644 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,8 +1,77 @@ class BaseReportController < ActionController::Base - include LoginVerification + include LoginVerification + layout "application" - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now + if period_type.to_i == 1 + if params[:from] && params[:to] + if params[:from] != "" && params[:to] !="" + from = DateTime.strptime(params[:from], "%m/%d/%Y") + to = DateTime.strptime(params[:to], "%m/%d/%Y") + else + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + end + 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 + return from, to + end end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 2933cda8..eb8b7c6f 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,7 +5,7 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] - + if filter.nil? @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) @@ -31,7 +31,7 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers/1.json def show @orders = Order.where("customer_id=?", params[:id]) - + if @orders @order_items = [] @orders.each do |bo| @@ -57,7 +57,6 @@ class Crm::CustomersController < BaseCrmController def create @crm_customers = Customer.new(customer_params) - respond_to do |format| puts @crm_customers.errors.to_json if @crm_customers.save @@ -73,7 +72,9 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + dob: dob, + member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -82,18 +83,18 @@ class Crm::CustomersController < BaseCrmController ) if response["status"] == true - + customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } else format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} - end + end # format.json { render :index, status: :created, location: @crm_customers } else - + @crm_customers.destroy if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} @@ -104,7 +105,7 @@ class Crm::CustomersController < BaseCrmController else if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} else format.html { redirect_to crm_customers_path} @@ -133,7 +134,7 @@ end memberaction = MembershipAction.find_by_membership_type("update_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index e80ca348..fb981a80 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -30,13 +30,15 @@ class Origami::DiscountsController < BaseOrigamiController sale.save #save sale item for discount - origin_sale_item = SaleItem.find(sale_item_id) + if sale_item_id != nil + origin_sale_item = SaleItem.find(sale_item_id) + end sale_item = SaleItem.new #pull sale_item.sale_id = sale_id - sale_item.product_code = origin_sale_item.product_code - sale_item.product_name = origin_sale_item.product_name + " Discount" + sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id + sale_item.product_name = "Overall Discount" sale_item.remark = remark sale_item.qty = 1 diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 1e08f8a8..bdae0f0e 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -49,8 +49,8 @@ class Origami::PaymentsController < BaseOrigamiController if spay.payment_method == "cash" @cash = spay.payment_amount end - if spay.payment_method == "mpu" - @other = spay.payment_amount + if spay.payment_method == "mpu" || spay.payment_method == "paypar" + @other += spay.payment_amount end end end diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb new file mode 100644 index 00000000..b4c701ae --- /dev/null +++ b/app/controllers/reports/daily_sale_controller.rb @@ -0,0 +1,21 @@ +class Reports::DailySaleController < BaseReportController + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def index + from, to = get_date_range_from_params + @sale_data = Sale.get_receipt_no_list(from,to) + @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) +end + +end \ No newline at end of file diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 930659b9..8569c051 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -1,17 +1,4 @@ -class Reports::ReceiptNoController < ApplicationController - PERIOD = { - "today" => 0, - "yesterday" => 1, - "this_week" => 2, - "last_week" => 3, - "last_7" => 4, - "this_month" => 5, - "last_month" => 6, - "last_30" => 7, - "this_year" => 8, - "last_year" => 9 - } - +class Reports::ReceiptNoController < BaseReportController def index from, to = get_date_range_from_params puts "from..." @@ -25,61 +12,4 @@ class Reports::ReceiptNoController < ApplicationController def show end - - private - def get_date_range_from_params - period_type = params[:period_type] - period = params[:period] - from = params[:from] - to = params[:to] - day_ref = Time.now - if period_type.to_i == 1 - if params[:from] && params[:to] - if params[:from] != "" && params[:to] !="" - from = DateTime.strptime(params[:from], "%m/%d/%Y") - to = DateTime.strptime(params[:to], "%m/%d/%Y") - else - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - end - 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 - return from, to - end end \ No newline at end of file diff --git a/app/models/order.rb b/app/models/order.rb index ac51c115..c1dfec43 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -223,7 +223,7 @@ class Order < ApplicationRecord #Origami: Cashier : to view booking order Table def self.get_booking_order_table - booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id, bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") @@ -232,7 +232,6 @@ class Order < ApplicationRecord .joins("left join sales on sales.sale_id = bookings.sale_id") .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") - end #Origami: Cashier : to view booking order Table @@ -244,13 +243,12 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") end - #Origami: Cashier : to view order type Room def self.get_booking_order_rooms - booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status, + booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id, bookings.booking_id,orders.customer_id as customer_id, sales.sale_id as sale_id,dining_facilities.name as room_name") @@ -259,8 +257,8 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sale_orders on sale_orders.order_id = orders.order_id") .joins("left join sales on sales.sale_id = sale_orders.sale_id") - .where("sales.sale_status<>'completed' and sales.sale_status<>'complete' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id") + .where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") end #Origami: Cashier : to view order type Room @@ -280,7 +278,7 @@ class Order < ApplicationRecord def self.get_orders from = Time.now.beginning_of_day.utc to = Time.now.end_of_day.utc - orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, + orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id ,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.order_id = orders.order_id @@ -289,7 +287,7 @@ class Order < ApplicationRecord left join order_items on order_items.order_id = orders.order_id left join sale_orders on sale_orders.order_id = orders.order_id left join sales on sales.sale_id = sale_orders.sale_id") - .where("sales.sale_status<>'completed' and dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) + .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) .group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id,orders.customer_id") end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index b8c527af..ffe881e6 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -60,7 +60,7 @@ class SalePayment < ApplicationRecord #record an payment in sale-audit remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by) - + return false, "No outstanding Amount" end @@ -217,7 +217,7 @@ class SalePayment < ApplicationRecord self.sale.sale_status = "completed" self.sale.save! table_update_status(sObj) - rebat() + rebat(sObj) end end @@ -233,8 +233,37 @@ class SalePayment < ApplicationRecord end end - def rebat + def rebat(sObj) + food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + generic_customer_id = sObj.customer.membership_id + if generic_customer_id != nil || generic_customer_id != "" + paypar = sObj.sale_payments + payparcost = 0 + paypar.each do |pp| + if pp.payment_method == "paypar" + payparcost = payparcost + pp.payment_amount + end + end + total_amount = food_prices - payparcost + puts "aaaa" + puts food_prices + puts payparcost + puts total_amount + receipt_no = sObj.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("rebate") + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + app_token = membership.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_amount: total_amount,campaign_type_id: campaign_type_id, + receipt_no: receipt_no}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }) + puts response.to_json + end end private diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 641678f9..33938b95 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -27,8 +27,8 @@
<%= unique_id %>
<%= customer_id %>
<%= cpo.order_id %>
-
Receipt No :
@@ -87,6 +87,11 @@
<%= sale_item.product_name %>
@@ -319,7 +333,7 @@
sub_total = 0
if @selected_item_type == "Order"
@selected_item.order_items.each do |order_item|
- sub_total += order_item.qty*order_item.unit_price
+ sub_total += (order_item.qty*order_item.unit_price)
%>
<%= order_item.item_name %>
@@ -337,7 +351,7 @@
Sub Total:
- <%=sub_total%>
+ <%= sub_total %>