merged crm

This commit is contained in:
Yan
2017-06-06 09:41:06 +06:30
22 changed files with 371 additions and 129 deletions

View File

@@ -1,6 +1,6 @@
GIT
remote: git://github.com/amatsuda/kaminari.git
revision: c3c853a944cd2bff072ae05e48c563b2c9a29597
revision: bc52ae73d41386d344b5d1b18e689e5a988f1a03
branch: master
specs:
kaminari (1.0.1)
@@ -92,7 +92,7 @@ GEM
railties (>= 3.2, < 5.2)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
i18n (0.8.4)
jbuilder (2.6.4)
activesupport (>= 3.0.0)
multi_json (>= 1.2)
@@ -119,13 +119,12 @@ GEM
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
pdf-core (0.7.0)
pg (0.20.0)
prawn (2.2.2)
pdf-core (~> 0.7.0)
ttfunk (~> 1.5)
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
puma (3.8.2)
puma (3.9.1)
rack (2.0.3)
rack-cors (0.4.1)
rack-protection (2.0.0)
@@ -253,7 +252,6 @@ DEPENDENCIES
kaminari!
listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.5)
pg
prawn
prawn-table
puma (~> 3.0)

View File

@@ -4,7 +4,7 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers
# GET /crm/customers.json
def index
@crm_customers = Crm::Customer.all
@crm_customers = Customer.all
end
# GET /crm/customers/1
@@ -14,7 +14,7 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers/new
def new
@crm_customer = Crm::Customer.new
@crm_customer = Customer.new
end
# GET /crm/customers/1/edit
@@ -24,7 +24,7 @@ class Crm::CustomersController < ApplicationController
# POST /crm/customers
# POST /crm/customers.json
def create
@crm_customer = Crm::Customer.new(crm_customer_params)
@crm_customer = Customer.new(crm_customer_params)
respond_to do |format|
if @crm_customer.save
@@ -64,7 +64,7 @@ class Crm::CustomersController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_crm_customer
@crm_customer = Crm::Customer.find(params[:id])
@crm_customer = Customer.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -1,15 +1,24 @@
class Origami::HomeController < BaseOrigamiController
def index
@order_table = Order.get_order_table()
@order_rooms = Order.get_order_rooms()
@booking_orders = Order.get_booking_order_table()
@booking_rooms = Order.get_booking_order_rooms()
@orders = Order.get_orders()
end
def show
str = []
@order_details = OrderItem.get_order_items_details(params[:order_id])
@order_details.each do |ord_detail|
str.push(ord_detail)
end
render :json => str.to_json
if !params[:sale_id].nil?
@order_details = SaleItem.get_order_items_details(params[:sale_id])
@order_details.each do |ord_detail|
str.push(ord_detail)
end
render :json => str.to_json
else
@order_details = OrderItem.get_order_items_details(params[:order_id])
@order_details.each do |ord_detail|
str.push(ord_detail)
end
render :json => str.to_json
end
end
end

View File

@@ -2,21 +2,26 @@ class Origami::RequestBillsController < BaseOrigamiController
def show
@sale = Sale.new
check_order = Order.find_by_id(params[:id])
if check_order
@order_details = OrderItem.get_order_items_details(check_order.id)
@order_details = OrderItem.get_order_items_details(check_order.id)
@status, @sale_id = @sale.generate_invoice_from_order(check_order.id, nil,current_login_employee.name)
@sale_data = Sale.find_by_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
booking_id = params[:id]
check_booking = Booking.find_by_booking_id(booking_id)
if check_booking.sale_id.nil?
#check if it doesn't exist
@status = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee.name)
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
@sale_items = SaleItem.where("sale_id=?",check_booking.sale_id)
else
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
@sale_items = SaleItem.where("sale_id=?",check_booking.sale_id)
end
unique_code="ReceiptBillPdf"
print_settings=PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale)
printer.print_receipt_bill(print_settings,@sale_items,@sale,@sale_data)
end
end

View File

@@ -1,5 +1,5 @@
class OrderQueueProcessorJob < ApplicationJob
queue_as :default
queue_as :oqs
def perform(order_id)
# Do something later

View File

@@ -1,6 +1,6 @@
class Customer < ApplicationRecord
self.primary_key = "customer_id"
before_create :generate_custom_id
has_many :orders
has_many :sales

View File

@@ -1,5 +1,7 @@
class MenuItem < ApplicationRecord
# belongs_to :account
#belongs_to :account
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true

View File

@@ -192,7 +192,7 @@ class Order < ApplicationRecord
# Count number of different items
self.item_count = self.order_items.item_count
self.quantity_count = quantity_count
# Counter number of quantity
# Counter number of quantityf
end
#Process order items and send to order queue
@@ -209,43 +209,69 @@ class Order < ApplicationRecord
end
#Origami: Cashier : to view order type Table
def self.get_order_table
order_table = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
order_items.id as order_items_id,dining_facilities.name as table_name")
.joins("left join booking_orders on booking_orders.order_id = orders.id
left join bookings on bookings.id = booking_orders.id
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
left join order_items on order_items.order_id = orders.id")
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true)
.group("orders.id")
def self.get_booking_order_table
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,
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")
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
.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("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true)
.group("bookings.booking_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,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as room_name")
.joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id")
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
.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("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true)
.group("bookings.booking_id")
end
#Origami: Cashier : to view order type Room
def self.get_order_rooms
order_rooms = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
order_rooms = Order.select("orders.order_id as order_id,sum(order_items.qty*order_items.price) as total_price,
order_items.id as order_items_id,dining_facilities.name as room_name")
.joins("left join booking_orders on booking_orders.order_id = orders.id
left join bookings on bookings.id = booking_orders.id
.joins("left join booking_orders on booking_orders.order_id = orders.order_id
left join bookings on bookings.booking_id = booking_orders.order_id
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
left join order_items on order_items.order_id = orders.id")
left join order_items on order_items.order_id = orders.order_id")
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,"dine_in",true)
.group("orders.id,order_items.id,dining_facilities.name")
.group("orders.order_id,order_items.id,dining_facilities.name")
end
#Origami: Cashier : to view orders
def self.get_orders
from = Time.now.beginning_of_day.utc
to = Time.now.end_of_day.utc
orders = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
order_items.id as order_items_id,dining_facilities.name as table_or_room_name")
.joins("left join booking_orders on booking_orders.order_id = orders.id
left join bookings on bookings.id = booking_orders.id
orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status,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
left join bookings on bookings.booking_id = booking_orders.order_id
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
left join order_items on order_items.order_id = orders.id")
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("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
.group("orders.id")
.group("orders.order_id")
# Booking.select("sales.receipt_no,orders.status as order_status,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")
# .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
# .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("booking_orders.order_id IS NOT NULL and dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
# .group("orders.order_id")
end
private
def generate_custom_id
self.order_id = SeedGenerator.generate_id(self.class.name, "ODR")

View File

@@ -39,11 +39,19 @@ class OrderItem < ApplicationRecord
end
#Origami : Cashier : to show order items details
def self.get_order_items_details(order_id)
order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price")
.joins("left join orders on orders.id = order_items.order_id")
.where("order_items.order_id=?",order_id)
def self.get_order_items_details(booking_id)
booking_orders = BookingOrder.where("booking_id=?",booking_id)
if booking_orders
booking_orders.each do |book_order|
order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price")
.joins("left join orders on orders.order_id = order_items.order_id")
.where("order_items.order_id=?",book_order.order)
return order_details
end
else
return false
end
end
private

View File

@@ -64,12 +64,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
self.print(filename)
end
#Bill Receipt Print
def print_receipt_bill(printer_settings,sale_items,sale)
def print_receipt_bill(printer_settings,sale_items,sale,sale_data)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale)
pdf.render_file "tmp/receipt_bill_#{sale.id}.pdf"
self.print("tmp/receipt_bill_#{sale.id}.pdf")
pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale,sale_data)
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")
end
end

View File

@@ -25,9 +25,9 @@ class Sale < ApplicationRecord
#get all order attached to this booking and combine into 1 invoice
booking.booking_orders.each do |order|
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, requested_by)
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
else
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, requested_by)
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by)
end
booking.sale_id = sale_id
end
@@ -36,7 +36,7 @@ class Sale < ApplicationRecord
end
end
def generate_invoice_from_order (order_id, sale_id, requested_by)
def generate_invoice_from_order (order_id, sale_id, booking, requested_by)
taxable = true
#if sale_id is exsit and validate
#add order to that invoice
@@ -67,8 +67,8 @@ class Sale < ApplicationRecord
add_item(item)
end
link_order_sale(order.id)
link_order_sale(order.id)
end
@@ -78,6 +78,11 @@ class Sale < ApplicationRecord
#Update the order items that is billed
order.update_items_status_to_billed(nil)
order.status = "billed"
order.save
booking.sale_id = self.id
booking.save
return true, self.id
end

View File

@@ -10,8 +10,24 @@ class SaleItem < ApplicationRecord
def compute_item
end
def self.get_order_items_details(sale_id)
sale_orders = SaleOrder.where("sale_id=?",sale_id)
if sale_orders
sale_orders.each do |sale_order|
order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price")
.joins("left join sales on sales.id = sale_items.sale_id")
.where("sale_items.sale_id=?",sale_order.sale_id)
return order_details
end
else
return false
end
end
private
def generate_custom_id
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
end
end

View File

@@ -14,9 +14,11 @@ class SeedGenerator < ApplicationRecord
seed.current = current_no
seed.save
end
padding_len = 15 - prefix.length
return prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
end
def self.new_receipt_no

View File

@@ -1,11 +1,11 @@
class ReceiptBillPdf < Prawn::Document
attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width
def initialize(printer_settings, sale_items,sale)
def initialize(printer_settings, sale_items,sale, sale_data)
self.p_width = 200
self.page_height = 1450
self.margin = 10
# self.price_width = self.p_width / 2
self.price_width=90
self.price_width=80
self.item_width = self.p_width - self.price_width
self.item_height = self.item_height
self.qty_column_width = self.p_width / 2
@@ -14,7 +14,7 @@ class ReceiptBillPdf < Prawn::Document
@item_width = self.p_width.to_i / 2
@qty_width = @item_width.to_i / 3
@double = @qty_width * 2
@double = @qty_width * 1.3
@half_qty = @qty_width / 2
#setting page margin and width
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height])
@@ -23,8 +23,9 @@ class ReceiptBillPdf < Prawn::Document
header( printer_settings.printer_name, printer_settings.name)
stroke_horizontal_rule
cashier_info(sale.receipt_no,sale.customer.name, sale.receipt_date)
cashier_info(sale.receipt_no,sale.customer, sale.receipt_date)
line_items(sale_items)
all_total(sale_data)
end
@@ -89,7 +90,6 @@ class ReceiptBillPdf < Prawn::Document
text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Discount", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
@@ -98,13 +98,80 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule
add_line_item_row(sale_items)
stroke_horizontal_rule
end
def add_line_item_row(sale_items)
y_position = cursor
move_down 5
y_position = cursor
move_down 5
sub_total = 0.0
sale_items.each do |item|
sub_total += item.qty*item.unit_price
qty = item.qty
total_price = item.qty*item.unit_price
price = item.unit_price
product_name = item.product_name
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "#{product_name}", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "#{price}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{qty.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{total_price}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
move_down 3
end
stroke_horizontal_rule
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "#{sub_total}" , :size => self.item_font_size,:align => :right
end
end
def all_total(sale_data)
move_down 5
y_position =cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Discount", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
end
move_down 5
y_position =cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Total Tax", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
end
move_down 5
y_position = cursor
move_down 5
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Grand Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right
end
move_down 5
# stroke_horizontal_rule
end
end

View File

@@ -1,5 +1,5 @@
if (@booking)
json.id @booking.id
json.id @booking.booking_id
json.status @booking.booking_status
json.checkin_at @booking.checkin_at
json.checkin_by @booking.checkin_by
@@ -12,7 +12,8 @@ if (@booking)
end
@total_amount = 0.00
@total_tax = 0.00
@booking_orders = BookingOrder.where("booking_id = #{@booking.booking_id}").all;
if @booking.booking_orders
order_items = []
@booking.booking_orders.each do |bo|

View File

@@ -1,4 +1,5 @@
<%= simple_form_for(@crm_customer) do |f| %>
<%= simple_form_for([:crm,@crm_customer]) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
@@ -7,7 +8,7 @@
<%= f.input :contact_no %>
<%= f.input :email %>
<%= f.input :date_of_birth %>
<%= f.association :membership %>
<%= f.input :membership_type %>
<%= f.input :membership_authentication_code %>
</div>

View File

@@ -2,5 +2,5 @@
<%= render 'form', crm_customer: @crm_customer %>
<%= link_to 'Show', @crm_customer %> |
<%= link_to 'Show', @crm_customers_path %> |
<%= link_to 'Back', crm_customers_path %>

View File

@@ -25,12 +25,12 @@
<td><%= crm_customer.contact_no %></td>
<td><%= crm_customer.email %></td>
<td><%= crm_customer.date_of_birth %></td>
<td><%= crm_customer.membership %></td>
<td><%= crm_customer.membership_id %></td>
<td><%= crm_customer.membership_type %></td>
<td><%= crm_customer.membership_authentication_code %></td>
<td><%= link_to 'Show', crm_customer %></td>
<td><%= link_to 'Show', crm_customer_path(crm_customer) %></td>
<td><%= link_to 'Edit', edit_crm_customer_path(crm_customer) %></td>
<td><%= link_to 'Destroy', crm_customer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>

View File

@@ -4,7 +4,7 @@
<% @i = 0 %>
<% @booking.each do |booking| %>
<% if booking.booking_status == "new" %>
<% if booking.booking_status == "assign" %>
<div class="card">
<div class="card-block booking_click" data-ref="<%= api_booking_path booking.id%>" id="card-block booking_block" style="width:100%;">
<h4 class="card-title">
@@ -40,7 +40,7 @@ $(function(){
$(".summary-items tbody tr").remove();
$("#cancel").removeAttr("disabled");
$("#assign").removeAttr("disabled");
var url = $(this).attr('data-ref');
var url = $(this).attr('data-ref');alert(url);
show_details(url);
});

View File

@@ -29,9 +29,4 @@
</div>
<% end %>
<% end %>
</div>

View File

@@ -22,34 +22,56 @@
<div class="tab-pane active" id="tables" role="tabpanel">
<!--- Booking Items -->
<div class="card-columns" style="padding-top:10px">
<% if @order_table %>
<% @order_table.each do |order_table| %>
<div class="card" id="table-order-<%=order_table.order_id%>" onclick="callOrderDetails('<%=order_table.order_id%>')">
<div class="card-block">
<h4 class="card-title"><span id="table-name-<%=order_table.order_id%>" class="table-name"><%=order_table.table_name%></span></h4>
<p class="card-text"><%=order_table.total_price%></p>
</div>
</div>
<% if @booking_orders %>
<% @booking_orders.each do |booking_order| %>
<% if !booking_order.order_status = 'new'%>
<div style="background-color: red;color: white;" class="card" id="table-order-<%=booking_order.sale_id%>" onclick="callOrderDetails('sale_<%=booking_order.sale_id%>')">
<div class="card-block">
<h4 class="card-title">
<span id="table-name-<%=booking_order.sale_id%>" class="table-name"><%=booking_order.table_name%></span></h4>
<span>Receipt No : <%=booking_order.receipt_no%></span><br/>
<span>Order Status : <%=booking_order.order_status %></span>
</div>
</div>
<% else %>
<div class="card" id="table-order-<%=booking_order.id%>" onclick="callOrderDetails('order_<%=booking_order.id%>')">
<div class="card-block">
<h4 class="card-title"><span id="table-name-<%=booking_order.id%>" class="table-name"><%=booking_order.table_name%></span></h4>
<span>Order Status : <%=booking_order.order_status %></span>
</div>
</div>
<% end %>
<%end %>
<%end %>
</div>
</div>
<!-- Panel 1 - Tables - End -->
<!-- Panel 2 - Rooms -->
<div class="tab-pane" id="rooms" role="tabpanel" style="min-height:670px; max-height:670px; overflow-y:scroll">
<!--- Booking Items -->
<div class="card-columns" style="padding-top:10px">
<% @order_rooms.each do |order_room| %>
<div class="card" id="table-order-<%=order_room.order_id%>" onclick="callOrderDetails('<%=order_room.order_id%>')">
<div class="card-block">
<% tablename = order_room.room_name%>
<h4 class="card-title"><span id="table-name-<%=order_room.order_id%>" class="table-name"><%=order_room.room_name%></span></h4>
<p class="card-text"><%=order_room.total_price%></p>
</div>
</div>
<% if @booking_rooms %>
<% @booking_rooms.each do |booking_room| %>
<% if !booking_room.order_status = 'new'%>
<div style="background-color: red;color: white;" class="card" id="table-order-<%=booking_room.id%>" onclick="callOrderDetails('sale_<%=booking_room.id%>')">
<div class="card-block">
<h4 class="card-title">
<span id="table-name-<%=booking_room.id%>" class="table-name"><%=booking_room.room_name%></span></h4>
<span>Receipt No : <%=booking_room.receipt_no%></span><br/>
<span>Order Status : <%=booking_room.order_status %></span>
</div>
</div>
<% else %>
<div class="card" id="table-order-<%=booking_room.id%>" onclick="callOrderDetails('order_<%=booking_room.id%>')">
<div class="card-block">
<h4 class="card-title"><span id="table-name-<%=booking_room.id%>" class="table-name"><%=booking_room.room_name%>ddd</span></h4> \
<span>Order Status : <%=booking_room.order_status %></span>
</div>
</div>
<% end %>
<%end %>
<%end %>
</div>
@@ -60,15 +82,29 @@
<!--- Booking Items -->
<div class="card-columns" style="padding-top:10px">
<% @orders.each do |order| %>
<div class="card" id="table-order-<%=order.order_id%>" onclick="callOrderDetails('<%=order.order_id%>')">
<div class="card-block">
<h4 class="card-title"><span id="table-name-<%=order.order_id%>" class="table-name"><%=order.table_or_room_name%></span></h4>
<p class="card-text"><%=order.total_price%></p>
</div>
</div>
<% if @orders %>
<% @orders.each do |order| %>
<% if !order.order_status = 'new'%>
<div style="background-color: green;color: white;" class="card" id="table-order-<%=order.order_id%>" onclick="callOrderDetails('sale_<%=order.order_id%>')">
<div class="card-block">
<h4 class="card-title">
<span id="table-name-<%=order.order_id%>" class="table-name">Order No:<%=order.order_id%></span></h4>
<span>Receipt No : <%=order.receipt_no%></span><br/>
<span>Order Status : <%=order.order_status %></span>
</div>
</div>
<% else %>
<div class="card" id="table-order-<%=order.order_id%>" onclick="callOrderDetails('order_<%=order.order_id%>')">
<div class="card-block">
<h4 class="card-title"><span id="table-name-<%=order.order_id%>" class="table-name">Order No:<%=order.order_id%></span></h4>
<span>Order Status : <%=order.order_status %></span>
</div>
</div>
<% end %>
<%end %>
<%end %>
</div>
@@ -83,7 +119,9 @@
<div class="col-lg-5 col-md-5 col-sm-3">
<div class="card" >
<div class="card-header">
<div id="order-title"><strong>ORDER DETAILS</strong> <span id="order-detail-header"></span></div>
<div id="order-title"><strong><span id="receipt-no">ORDER DETAILS</span></strong>
<strong><span id ="receipt-date" style="margin-left: 20%"></span></strong></div><br/>
<div ><strong><span id="cashier-name"></span></strong><strong><span style="margin-left: 36%" id="order-detail-header"></span></strong></div>
</div>
<div class="card-block">
<div class="card-title">
@@ -120,7 +158,19 @@
<tfooter>
<tr>
<td style="width:80%; text-align:left; border-top:none"><strong>Sub Total</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span id="sub-total"></span></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span id="sub-total"></span></strong></td>
</tr>
<tr>
<td style="width:80%; text-align:left; border-top:none"><strong><span id="discount-header"></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span id="discount_amount"></span></strong></td>
</tr>
<tr>
<td style="width:80%; text-align:left; border-top:none"><strong><span id="tax-header"></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span id="tax_amount"></span></strong></td>
</tr>
<tr>
<td style="width:80%; text-align:left; border-top:none"><strong><span id="grand-total-header"></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span id="grand_total_amount"></span></strong></td>
</tr>
</tfooter>
</table>
@@ -152,9 +202,22 @@
var old_table_name = ""
var table_or_order_id = 0
function callOrderDetails(order_id){
table_or_order_id = order_id
$("#test").html(order_id)
function callOrderDetails(sale_order_id){
var order_id = 0
var data_val = ""
sale_order = sale_order_id.split("_")[0]
if (sale_order == 'sale') {
order_id = sale_order_id.split("_")[1]
url = "origami/"+sale_order_id.split("_")[1]
data_val = { sale_id: sale_order_id.split("_")[1]}
}else{
order_id = sale_order_id.split("_")[1]
url = "origami/"+order_id
data_val = { order_id: sale_order_id.split("_")[1]}
}
table_or_order_id = order_id
var tbody = ""
$("#append-table").html("")
if (old_order_id != order_id){
@@ -163,30 +226,70 @@ function callOrderDetails(order_id){
old_order_id = order_id
}
$("#order-detail-header").html("")
$("#order-detail-header").append(document.getElementById("table-name-"+order_id).innerHTML)
$("#sub-total").html("")
url = "origami/"+order_id
$("#order-detail-header").append("Table Name : "+document.getElementById("table-name-"+order_id).innerHTML)
$("#sub-total").html("")
$.ajax({type: "GET",
url: url,
data: { order_id: order_id},
data: data_val,
success:function(result){
var sub_total = 0
var discount_amount = 0
var receipt_no = ""
var cashier_name = ""
var receipt_date = ""
var tax_amount = 0
var grand_total_amount = 0
row = "<tbody>"
for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]);
var parse_data = JSON.parse(data)
sub_total += (parse_data.qty*parse_data.price)
row = '<tbody><tr><td style="width:60%; text-align:left"><span id="item-name-price">'+parse_data.item_name+"@"+(parse_data.price*1)+'</span></td>'
row = '<tr><td style="width:60%; text-align:left"><span id="item-name-price">'+parse_data.item_name+"@"+(parse_data.price*1)+'</span></td>'
+'<td style="width:20%; text-align:right"><span id="item-qty">'+(parse_data.qty*1)+'</span></td>s'
+'<td style="width:20%; text-align:right"><span id="item-total-price">'+(parse_data.qty*parse_data.price)+'</span></td>'
+'</tr></tbody>'
+'</tr>>'
tbody += row
discount_amount = result[i].discount_amount;
tax_amount = result[i].tax_amount;
grand_total_amount = result[i].grand_total_amount;
receipt_no = result[i].receipt_no;
cashier_name = result[i].cashier_name;
receipt_date = result[i].receipt_date;
}
row = "</tbody>"
$("#append-table").append(tbody)
$("#sub-total").append((sub_total)+"<br/>")
if (discount_amount > 0 ) {
$("#discount-header").html("(Discount)")
$("#discount_amount").html("("+discount_amount+")")
}
if (tax_amount > 0 ) {
$("#tax-header").html("Tax")
$("#tax_amount").html(tax_amount)
}
if (grand_total_amount > 0 ) {
$("#grand-total-header").html("Grand Total")
$("#grand_total_amount").html(grand_total_amount)
}
if (cashier_name == null){
cashier_name = ""
}
if(receipt_no != null){
$("#receipt-no").html("Receipt No : "+receipt_no)
}
if (receipt_date != null) {
$("#receipt-date").html("Receipt Date : "+receipt_date);
}
if (cashier_name != null) {
$("#cashier-name").html("Cashier Name : "+cashier_name);
}
},
error:function(result){
// alert('error');

View File

@@ -3,7 +3,8 @@
<div class="card" >
<div class="card-header">
<div id="order-title">
<span><strong>Receipt No</strong> <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %></span>
<span><strong>Receipt No : <%=@sale_data.receipt_no rescue ' '%></strong></span>
<span style="margin-left: 40%"><strong>Receipt Date : <%=@sale_data.receipt_date rescue '-'%></strong></span>
<span><strong>Table No</strong> <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %></span>
</div>
</div>
@@ -51,18 +52,21 @@
</tr>
<tr>
<td style="width:80%; text-align:left; border-top:none"><strong>(Discount)</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span>(<%=@sale_data.total_discount%>)</span></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span>(<%=@sale_data.total_discount rescue 0%>)</span></strong></td>
</tr>
<td style="width:80%; text-align:left; border-top:none"><strong>Tax</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span><%=@sale_data.total_tax%></span></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span><%=@sale_data.total_tax rescue 0%></span></strong></td>
</tr>
<td style="width:80%; text-align:left; border-top:none"><strong>Grand Total</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span><%=@sale_data.grand_total%></span></strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><span><%=@sale_data.grand_total rescue 0%></span></strong></td>
</tr>
</tfooter>
</table>
</div>
<div style='text-align:center;margin-top:20px'>
<INPUT TYPE="Button" class='btn btn-primary' VALUE="Reprint" onClick="" style='width:120px'/>
<INPUT TYPE="Submit" class='btn btn-primary' VALUE="CANCEL" action="origami/index" style='width:120px'/>
</div>
</div>
</div>
</div>