From 231eec6a01c8b9e33529ce2e9548fa5b300690f3 Mon Sep 17 00:00:00 2001 From: PhyoTheingi Date: Tue, 6 Jun 2017 10:50:51 +0630 Subject: [PATCH 1/8] Payment delete bug fix --- app/views/settings/menu_item_options/show.html.erb | 3 +-- app/views/settings/payment_method_settings/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/settings/menu_item_options/show.html.erb b/app/views/settings/menu_item_options/show.html.erb index fdcb9d09..611f3165 100644 --- a/app/views/settings/menu_item_options/show.html.erb +++ b/app/views/settings/menu_item_options/show.html.erb @@ -2,8 +2,7 @@ From 59434e2c3a6b10ae7e5fa66136621a8e14d40e31 Mon Sep 17 00:00:00 2001 From: PhyoTheingi Date: Tue, 6 Jun 2017 17:29:34 +0630 Subject: [PATCH 3/8] Menu item with Accout --- .../settings/set_menu_items_controller.rb | 2 +- .../settings/simple_menu_items_controller.rb | 2 +- app/models/account.rb | 4 +++- app/models/menu_item.rb | 3 ++- .../settings/set_menu_items/_form.html.erb | 1 + .../settings/set_menu_items/show.html.erb | 2 ++ .../settings/simple_menu_items/_form.html.erb | 1 + .../settings/simple_menu_items/show.html.erb | 2 ++ ...ts.rb => 20170331024747_create_accounts.rb} | 0 db/migrate/20170331024749_create_menu_items.rb | 1 + db/seeds.rb | 18 +++++++++++------- 11 files changed, 25 insertions(+), 11 deletions(-) rename db/migrate/{20170602101727_create_accounts.rb => 20170331024747_create_accounts.rb} (100%) diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index 1c3e2247..5946ff49 100644 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -81,6 +81,6 @@ class Settings::SetMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) + params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id,:account_id , :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) end end diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index b02310dc..05952d0d 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -78,6 +78,6 @@ class Settings::SimpleMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id,:item_attributes, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) + params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id,:account_id,:item_attributes, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) end end diff --git a/app/models/account.rb b/app/models/account.rb index e1cdc6d3..a950865c 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -3,5 +3,7 @@ class Account < ApplicationRecord has_many :menu_items # belongs_to :lookup , :class_name => "Lookup" - + def self.collection + Account.select("id, title").map { |e| [e.title, e.id] } + end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 22ec36de..9ff40ae2 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,9 +1,10 @@ class MenuItem < ApplicationRecord - # 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 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 diff --git a/app/views/settings/set_menu_items/_form.html.erb b/app/views/settings/set_menu_items/_form.html.erb index bdf0e97e..aeae0f5c 100644 --- a/app/views/settings/set_menu_items/_form.html.erb +++ b/app/views/settings/set_menu_items/_form.html.erb @@ -6,6 +6,7 @@ <%= f.input :name %> <%= f.input :alt_name %> <%= f.input :type %> + <%= f.input :account_id, :label => "Account type", :collection => Account.collection %> <%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %> <%= f.input :min_qty %> diff --git a/app/views/settings/set_menu_items/show.html.erb b/app/views/settings/set_menu_items/show.html.erb index 0082c819..ba23771f 100644 --- a/app/views/settings/set_menu_items/show.html.erb +++ b/app/views/settings/set_menu_items/show.html.erb @@ -19,6 +19,7 @@ Name Alt name Type + Account Type Menu category Menu item Min qty @@ -35,6 +36,7 @@ <%= @settings_menu_item.name rescue "-" %> <%= @settings_menu_item.alt_name %> <%= @settings_menu_item.type %> + <%= @settings_menu_item.account.title %> <%= @settings_menu_item.menu_category_id %> <%= @settings_menu_item.menu_item_id %> <%= @settings_menu_item.min_qty %> diff --git a/app/views/settings/simple_menu_items/_form.html.erb b/app/views/settings/simple_menu_items/_form.html.erb index 885f725e..01c5b482 100644 --- a/app/views/settings/simple_menu_items/_form.html.erb +++ b/app/views/settings/simple_menu_items/_form.html.erb @@ -6,6 +6,7 @@ <%= f.input :name %> <%= f.input :alt_name %> <%= f.input :type %> + <%= f.input :account_id, :label => "Account type", :collection => Account.collection %> <%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %> <%= f.input :min_qty %> <%= f.input :min_selectable_item %> diff --git a/app/views/settings/simple_menu_items/show.html.erb b/app/views/settings/simple_menu_items/show.html.erb index d2d93e0e..11620acd 100644 --- a/app/views/settings/simple_menu_items/show.html.erb +++ b/app/views/settings/simple_menu_items/show.html.erb @@ -21,6 +21,7 @@ Name Alt name Type + Accout Menu category Menu item Min qty @@ -37,6 +38,7 @@ <%= @settings_menu_item.name rescue "-" %> <%= @settings_menu_item.alt_name %> <%= @settings_menu_item.type %> + <%= @settings_menu_item.account.title %> <%= @settings_menu_item.menu_category_id %> <%= @settings_menu_item.menu_item_id %> <%= @settings_menu_item.min_qty %> diff --git a/db/migrate/20170602101727_create_accounts.rb b/db/migrate/20170331024747_create_accounts.rb similarity index 100% rename from db/migrate/20170602101727_create_accounts.rb rename to db/migrate/20170331024747_create_accounts.rb diff --git a/db/migrate/20170331024749_create_menu_items.rb b/db/migrate/20170331024749_create_menu_items.rb index f61a9172..81baa5ab 100644 --- a/db/migrate/20170331024749_create_menu_items.rb +++ b/db/migrate/20170331024749_create_menu_items.rb @@ -10,6 +10,7 @@ class CreateMenuItems < ActiveRecord::Migration[5.0] t.string :type, :null => false, :default => "SimpleMenuItem" t.references :menu_category, foreign_key: true t.references :menu_item, foreign_key: true + t.references :account, foreign_key: true t.integer :min_qty, :null => false, :default => 1 t.boolean :taxable, :null => false, :default => true t.integer :min_selectable_item, :null => false, :default => 1 diff --git a/db/seeds.rb b/db/seeds.rb index 5e4dd995..aefa396c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -74,6 +74,10 @@ booking_status = Lookup.create([{lookup_type:'booking_status', name: 'Available' account_type = Lookup.create([{lookup_type:'account_type', name: 'Income', value: 'income'}, {lookup_type:'account_type', name: 'Expense', value: 'expense'}]) +#Account for Menu Item Type (eg: Food, Beverage) +food = Account.create({title: "Food", account_type: "0"}) +beverage = Account.create({title: "Beverage", account_type: "1"}) + #WALK CUSTOMER - Default CUSTOMER (take key 1) customer = Customer.create({id:1, name:"WALK-IN", contact_no:"000000000"}) customer = Customer.create({id:2, name:"TAKEAWAY", contact_no:"000000000"}) @@ -104,17 +108,17 @@ menu_category3 = MenuCategory.create({menu: menu, code:"C006", name: "Sample Men menu_category4 = MenuCategory.create({menu: menu, code:"C006", name: "Sample Menu Category 4", alt_name: "Sample Alternate Category 4", order_by: 1, menu_category_id: menu_category3.id, created_by: "SYSTEM DEFAULT"}) #Default Menu items -menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) +menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1, account: food }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"half portion",item_instance_code:"01001-1", menu_item: menu_category1_menu_item0, price:12.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"full portion",item_instance_code:"01001-2", menu_item: menu_category1_menu_item0, price:18.00, is_on_promotion:false}]) -menu_category1_menu_item1 = SetMenuItem.create({item_code:"I004", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) -menu_category1_menu_item2 = SetMenuItem.create({item_code:"I005", name: "Default Menu Item Name 2",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 2", min_selectable_item: 1, max_selectable_item:1 }) -menu_category1_menu_item3 = SetMenuItem.create({item_code:"I006", name: "Default Menu Item Name 3",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 3", min_selectable_item: 1, max_selectable_item:1 }) +menu_category1_menu_item1 = SetMenuItem.create({item_code:"I004", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 , account: food}) +menu_category1_menu_item2 = SetMenuItem.create({item_code:"I005", name: "Default Menu Item Name 2",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 2", min_selectable_item: 1, max_selectable_item:1 , account: food}) +menu_category1_menu_item3 = SetMenuItem.create({item_code:"I006", name: "Default Menu Item Name 3",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 3", min_selectable_item: 1, max_selectable_item:1 , account: food}) -menu_category2_menu_item0 = SimpleMenuItem.create({item_code:"I007", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 }) -menu_category2_menu_item1 = SimpleMenuItem.create({item_code:"I008", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 }) -menu_category2_menu_item2 = SimpleMenuItem.create({item_code:"I009", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 3 }) +menu_category2_menu_item0 = SimpleMenuItem.create({item_code:"I007", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 , account: food}) +menu_category2_menu_item1 = SimpleMenuItem.create({item_code:"I008", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 , account: food}) +menu_category2_menu_item2 = SimpleMenuItem.create({item_code:"I009", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 3 , account: food}) menu_item_attribute_size_small = MenuItemAttribute.create({attribute_type:"size", name: "Small", value: "small"}) menu_item_attribute_size_medium = MenuItemAttribute.create({attribute_type:"size",name: "Medium", value: "medium"}) From c18b57eca8c8b19dd05b796c2be4ccf2b633cfb7 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 7 Jun 2017 10:29:00 +0630 Subject: [PATCH 4/8] payment --- app/assets/stylesheets/orgiami.scss | 8 ++++++++ app/views/origami/home/index.html.erb | 10 ++++++---- app/views/origami/request_bills/show.html.erb | 10 ++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/orgiami.scss b/app/assets/stylesheets/orgiami.scss index 327c5897..afefe4c7 100644 --- a/app/assets/stylesheets/orgiami.scss +++ b/app/assets/stylesheets/orgiami.scss @@ -29,3 +29,11 @@ .purple { background-color:#7a62d3; } + +.red { + background-color:#ff0000; +} + +.green{ + background-color: #009900 +} diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 4897407d..7a955a8d 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -190,13 +190,13 @@ - - + @@ -217,12 +217,14 @@ function callOrderDetails(sale_order_id){ sale_id = sale_order_id.split("_")[1] url = "origami/"+sale_order_id.split("_")[1] data_val = { sale_id: sale_order_id.split("_")[1]} - + $("#pay").prop('disabled',false); + $("#request_bills").prop('disabled',true); }else{ order_id = sale_order_id.split("_")[1] url = "origami/"+order_id data_val = { order_id: sale_order_id.split("_")[1]} - + $("#request_bills").prop('disabled',false); + $("#pay").prop('disabled',true); } table_or_order_id = order_id pay_sale_id = sale_id diff --git a/app/views/origami/request_bills/show.html.erb b/app/views/origami/request_bills/show.html.erb index 573a63f4..6de89ab8 100644 --- a/app/views/origami/request_bills/show.html.erb +++ b/app/views/origami/request_bills/show.html.erb @@ -4,12 +4,10 @@
- - Receipt No : <%=@sale_data.receipt_no rescue ' '%> - Receipt Date : <%=@sale_data.receipt_date rescue '-'%> + Receipt Date : <%=@sale_data.receipt_date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> Table No <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %> - Sale Id <% if @sale_data %><%=@sale_data.sale_id %><% end %> + Sale Id <% if @sale_data %><%=@sale_data.sale_id %><% end %>
@@ -152,8 +150,8 @@
-
DEL
-
CLR
+
DEL
+
CLR
From 608cd5bb213133737863321de01fcd187524e647 Mon Sep 17 00:00:00 2001 From: PhyoTheingi Date: Wed, 7 Jun 2017 10:53:15 +0630 Subject: [PATCH 5/8] update seed --- db/seeds.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 9d9dbb61..41b975eb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -94,6 +94,9 @@ room = Room.create({name:"Default Room", zone: zone2, status:"available", seater #Tax Profile tax_profiles = TaxProfile.create({id:1, name: "Commerical Tax", rate:5.0, order_by:1, created_by:"SYSTEM DEFAULT"}) +#Account for Menu Item Type (eg: Food, Beverage) +food = Account.create({title: "Food", account_type: "0"}) +beverage = Account.create({title: "Beverage", account_type: "1"}) #Default menu menu = Menu.create({name: "Default Menu", is_active: true, created_by: "SYSTEM DEFAULT"}) @@ -137,7 +140,3 @@ zone_queue_station = OrderQueueProcessByZone.create({order_queue_station: zone_o #Create Adminstrator employee admin_employee = Employee.create({name: "Administrator", role: "Administrator", password: "99999", emp_id:"999", created_by: "SYSTEM DEFAULT"}) - -#Account for Menu Item Type (eg: Food, Beverage) -food = Account.create({title: "Food", account_type: "0"}) -beverage = Account.create({title: "Beverage", account_type: "1"}) From ad5d41768d97ed0e28d1510868635dc401bda935 Mon Sep 17 00:00:00 2001 From: PhyoTheingi Date: Wed, 7 Jun 2017 11:02:53 +0630 Subject: [PATCH 6/8] Fix conflict --- db/seeds.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 41b975eb..02fa39fb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -74,10 +74,6 @@ booking_status = Lookup.create([{lookup_type:'booking_status', name: 'Available' account_type = Lookup.create([{lookup_type:'account_type', name: 'Income', value: 'income'}, {lookup_type:'account_type', name: 'Expense', value: 'expense'}]) -#Account for Menu Item Type (eg: Food, Beverage) -food = Account.create({title: "Food", account_type: "0"}) -beverage = Account.create({title: "Beverage", account_type: "1"}) - #WALK CUSTOMER - Default CUSTOMER (take key 1) customer = Customer.create({id:1, name:"WALK-IN", contact_no:"000000000"}) customer = Customer.create({id:2, name:"TAKEAWAY", contact_no:"000000000"}) From 9a23716c2360d1ee2aee1f686e9dab47b93d7c04 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 7 Jun 2017 13:02:12 +0630 Subject: [PATCH 7/8] others payment --- .../origami/card_payments_controller.rb | 10 ------ .../origami/others_payments_controller.rb | 10 ++++++ .../origami/payments_controller.rb | 12 ++++--- .../origami/request_bills_controller.rb | 10 +----- .../index.html.erb | 0 .../{request_bills => payments}/show.html.erb | 32 ++++++++++++++----- config/routes.rb | 10 +++--- 7 files changed, 49 insertions(+), 35 deletions(-) delete mode 100644 app/controllers/origami/card_payments_controller.rb create mode 100644 app/controllers/origami/others_payments_controller.rb rename app/views/origami/{card_payments => others_payments}/index.html.erb (100%) rename app/views/origami/{request_bills => payments}/show.html.erb (92%) diff --git a/app/controllers/origami/card_payments_controller.rb b/app/controllers/origami/card_payments_controller.rb deleted file mode 100644 index 2df4b266..00000000 --- a/app/controllers/origami/card_payments_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Origami::CardPaymentsController < BaseOrigamiController - - - def index - end - - def create - end - -end diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb new file mode 100644 index 00000000..e92c9535 --- /dev/null +++ b/app/controllers/origami/others_payments_controller.rb @@ -0,0 +1,10 @@ +class Origami::OthersPaymentsController < BaseOrigamiController + + + def index + end + + def create + end + +end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index f64e27e3..45b03c79 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -5,13 +5,17 @@ class Origami::PaymentsController < BaseOrigamiController end def create - #payment type - #sale status - #point - get [ food amount ] + cash = params[:cash] + card = params[:card] + + #process_payment(invoice, action_by) end def show - + sale_id = params[:sale_id] + if Sale.exists?(sale_id) + @sale_data = Sale.find_by_sale_id(sale_id) + end end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 31766599..9e14e9ea 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -25,13 +25,5 @@ class Origami::RequestBillsController < BaseOrigamiController printer.print_receipt_bill(print_settings,@sale_items,@sale,@sale_data) end - - - def show - sale_id = params[:sale_id] - if Sale.exists?(sale_id) - @sale_data = Sale.find_by_sale_id(sale_id) - end - end - + end diff --git a/app/views/origami/card_payments/index.html.erb b/app/views/origami/others_payments/index.html.erb similarity index 100% rename from app/views/origami/card_payments/index.html.erb rename to app/views/origami/others_payments/index.html.erb diff --git a/app/views/origami/request_bills/show.html.erb b/app/views/origami/payments/show.html.erb similarity index 92% rename from app/views/origami/request_bills/show.html.erb rename to app/views/origami/payments/show.html.erb index 6de89ab8..e35696d2 100644 --- a/app/views/origami/request_bills/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -87,7 +87,7 @@

-
CARD
+
OTHERS PAYMENT
0.0

@@ -150,8 +150,8 @@
-
DEL
-
CLR
+
DEL
+
CLR
@@ -191,6 +191,10 @@ $(document).on('click', '.cashier_number', function(event){ update_balance(); break; + case 'clr': + $('#cash').text("0.0"); + update_balance(); + break; } event.handled = true; } else { @@ -207,16 +211,28 @@ $( document ).ready(function() { $('#card_payment').click(function() { var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/payment/card_payment" + window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment" return false; }); $('#pay').click(function() { - console.log("pay") - if($('#amount_due').text() > 0){ - console.log("greater") + + if($('#balance').text() > 0){ + alert(" Insufficient Amount!") }else{ - console.log("less") + // payment + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + + $.ajax({type: "POST", + url: "<%= origami_payment_process_path %>", + data: "cash="+ cash, + success:function(result){ + alert("THANK YOU") + } + }); + } }); diff --git a/config/routes.rb b/config/routes.rb index 64b5feeb..558e2c2d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,14 +68,16 @@ Rails.application.routes.draw do namespace :origami do root "home#index" get "/:booking_id" => "home#show" do #origami/:booking_id will show - resources :payments, only: [:index, :new, :create ] #add payment by payment_method resources :discounts, only: [:index,:new, :create ] #add discount type resources :customers, only: [:index,:new, :create ] #add customer type end - # resources :request_bills, only: [:show] - get 'sale/:sale_id/payment' => 'request_bills#show' + + get 'sale/:sale_id/payment' => 'payments#show' + post 'payment_process' => 'payments#create' + get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index" - get 'sale/:sale_id/payment/card_payment' => "card_payments#index" + get 'sale/:sale_id/payment/others_payment' => "others_payments#index" + end #--------- Waiter/Ordering Station ------------# From 810a6d8afcc0b9fda0be676a2b48a7b1700b68f7 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 7 Jun 2017 14:45:03 +0630 Subject: [PATCH 8/8] update sale_payment database --- .../origami/payments_controller.rb | 9 ++- app/models/sale_audit.rb | 5 +- app/models/sale_payment.rb | 70 ++++++++++--------- app/views/origami/payments/show.html.erb | 5 +- .../20170403174111_create_sale_audits.rb | 4 +- 5 files changed, 52 insertions(+), 41 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 45b03c79..bac414ad 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -6,9 +6,12 @@ class Origami::PaymentsController < BaseOrigamiController def create cash = params[:cash] - card = params[:card] - - #process_payment(invoice, action_by) + sale_id = params[:sale_id] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + sale_payment.process_payment(saleObj, @user, cash) + end end def show diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index c99d2dfc..29daa796 100644 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -1,6 +1,6 @@ class SaleAudit < ApplicationRecord self.primary_key = "sale_audit_id" - + #primary key - need to be unique generated for SaleAudit before_create :generate_custom_id @@ -44,13 +44,14 @@ class SaleAudit < ApplicationRecord sale_audit.save! end - def record_payment(sale_id, remark, action_by) + def self.record_payment(sale_id, remark, action_by) sale_audit = SaleAudit.new() sale_audit.sale_id = sale_id sale_audit.action = "SALEPAYMENT" sale_audit.action_at = DateTime.now.utc sale_audit.action_by = action_by sale_audit.remark = remark + sale_audit.approved_by = Time.now sale_audit.save! end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 15fe4c74..8f9b7294 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -1,17 +1,21 @@ class SalePayment < ApplicationRecord self.primary_key = "sale_payment_id" - + #primary key - need to be unique generated for multiple shops before_create :generate_custom_id belongs_to :sale - :attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status + attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status + + def process_payment(invoice, action_by, cash_amount) - def process_payment(invoice, action_by) self.sale = invoice - + self.received_amount = cash_amount + + payment_method = "cash" amount_due = invoice.grand_total + #get all payment for this invoices invoice.sale_payments.each do |payment| if (payment.payment_status == "paid" ) @@ -22,32 +26,33 @@ class SalePayment < ApplicationRecord if (amount_due > 0) payment_status = false #route to payment type - switch (payment_method) - case "cash" + case payment_method + when "cash" payment_status = cash_payment - case "creditnote" - payment_status = creditnote_payment - case "visa" - payment_status = external_terminal_card_payment(:visa) - case "master" - payment_status = external_terminal_card_payment(:master) - case "jcb" - payment_status = external_terminal_card_payment(:jcb) - case "mpu" - payment_status = external_terminal_card_payment(:mpu) - case "unionpay" - payment_status = external_terminal_card_payment(:unionpay) - case "vochure" - payment_status = vochure_payment - case "giftcard" - payment_status = giftcard_payment - case "paypar" - #TODO: implement paypar implementation + when "creditnote" + if !self.customer_id.nil? + payment_status = creditnote_payment(self.customer_id) + end + when "visa" + payment_status = external_terminal_card_payment(:visa) + when "master" + payment_status = external_terminal_card_payment(:master) + when "jcb" + payment_status = external_terminal_card_payment(:jcb) + when "mpu" + payment_status = external_terminal_card_payment(:mpu) + when "unionpay" + payment_status = external_terminal_card_payment(:unionpay) + when "vochure" + payment_status = vochure_payment + when "giftcard" + payment_status = giftcard_payment + when "paypar" payment_status = paypar_payment + else + puts "it was something else" end - - #record an payment in sale-audit remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) @@ -66,10 +71,9 @@ class SalePayment < ApplicationRecord private def cash_payment payment_status = false - self.payment_method = "cash" self.payment_amount = self.received_amount - self.outstanding_amount = self.sale.grand_total - received_amount + self.outstanding_amount = self.sale.grand_total - self.received_amount self.payment_status = "paid" payment_method = self.save! @@ -78,7 +82,8 @@ class SalePayment < ApplicationRecord return payment_status end - def creditnote_payment(self.customer_id) + def creditnote_payment(customer_id) + payment_status = false self.payment_method = "creditnote" @@ -147,11 +152,12 @@ class SalePayment < ApplicationRecord end def sale_update_payment_status(paid_amount) - + puts "paid_amount" + puts paid_amount #update amount_outstanding self.sale.amount_received = self.sale.amount_received + paid_amount - self.sale.amount_changed = amount - self.sale.amount_received - if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0) + self.sale.amount_changed = amount - self.sale.amount_received + if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0) self.sale.payment_status = "paid" self.sale.sale_status = "completed" self.sale.save! diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index e35696d2..ccd9fd77 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -172,6 +172,7 @@ $(document).on('click', '.cashier_number', function(event){ original_value = $('#cash').text(); var input_type = $(this).attr("data-type"); + switch (input_type) { case 'num': var input_value = $(this).attr("data-value"); @@ -224,10 +225,10 @@ $( document ).ready(function() { var cash = $('#cash').text(); var credit = $('#credit').text(); var card = $('#card').text(); - + var sale_id = $('#sale_id').text(); $.ajax({type: "POST", url: "<%= origami_payment_process_path %>", - data: "cash="+ cash, + data: "cash="+ cash + "&sale_id=" + sale_id, success:function(result){ alert("THANK YOU") } diff --git a/db/migrate/20170403174111_create_sale_audits.rb b/db/migrate/20170403174111_create_sale_audits.rb index ae6ba3f4..e8197c4b 100644 --- a/db/migrate/20170403174111_create_sale_audits.rb +++ b/db/migrate/20170403174111_create_sale_audits.rb @@ -7,8 +7,8 @@ class CreateSaleAudits < ActiveRecord::Migration[5.0] t.string :action, :null => false t.datetime :action_at, :null => false t.string :action_by, :null => false - t.string :approved_by, :null => false - t.datetime :approved_by, :null => false + t.string :approved_by, :null => true + t.datetime :approved_at, :null => true t.string :remark t.timestamps end