require 'sidekiq/web'

Rails.application.routes.draw do

  root 'home#index'
  mount Sidekiq::Web => '/kiq'

  # Action Cable Creation
  mount ActionCable.server => "/cable"

  #--------- SmartSales Installation ------------#
  get 'install' => 'install#index'
  post 'install' =>  'install#create'

  #--------- Login/Authentication ------------#
  get 'auth/:emp_id' => 'home#show' , as: :emp_login
  patch "auth/:emp_id" => 'home#update', as: :emp_login_update

  post 'login' => 'home#create'
  delete 'logout' => 'home#destroy'
  get 'dashboard' => 'home#dashboard'


  #--------- API Routes ------------#
  namespace :api,  :defaults => { :format => 'json' } do
    #Session Login and Logout
    post   'authenticate' => "authenticate#create"
    delete 'authenticate' => "authenticate#destroy"

    namespace :restaurant do
      get 'zones' => "zones#index"
      resources :menu, only:[:index, :show]
      resources :menu_categories, only: [:index]
      resources :menu_items, only: [:index, :show]
      resources :menu_item_attributes, only: [:index]
      resources :menu_item_options, only: [:index]
      resources :menu_sold_out, only: [:index]
    end

    #User request move table or bills
    post "bill/:booking_id" => "bill#create"
    post "move" => "move#create"


    #Order Controller
    resources :orders, only: [:create, :show, :update] do
      post "bill" => "bill#create"
    end
    get 'view_orders' => "orders#view_orders"

    #Current active bookings
    resources :bookings, only: [:index, :show, :create, :update]
    resources :customers
    #get customer details by order items
    get "customers/get_order/:id" => "customers#get_customer_order"

    #Generating Invoice and making payments - output render @sale
    resources :invoices, only: [:index, :show, :create, :update, :destroy ] do
      resources :sale_items, only:[:create, :update, :destroy]
      resources :discounts, only: [:create, :update, :destroy]
      resources :memberships, only:[:create]
      post "payment/:payment_method" => "payment#create"
      put "payment/:id" => "payment#update"
      resources :receipt, only: [:create, :show] #generate receipt, show receipt

    end


  end

  #--------- Cashier ------------#
  namespace :origami do
    resources :cash_ins, only:[:new, :create]
    resources :cash_outs, only:[:new, :create]
    root "home#index"
    get "table/:dining_id" => "home#show" do #origami/:booking_id will show
      # resources :discounts, only: [:index,:new, :create ] #add discount type
      resources :customers #add customer type
    end
    post 'moving' => "movetable#moving"
    get "/table/:table_id/sale/:sale_id/edit" => "sale_edit#edit"
    post 'item_void' => "sale_edit#item_void"
    post 'item_edit' => "sale_edit#item_edit"
    post 'item_void_cancel' => "sale_edit#item_void_cancel"
    post 'cancel_all_void' => 'sale_edit#cancel_all_void'
    post 'apply_void' => 'sale_edit#apply_void'

    get 'table/:dining_id/movetable' => "movetable#move_dining"
    get 'table/:dining_id/moveroom' => "moveroom#move_dining"
    get 'sale/:sale_id' => 'sales#show'
    post 'sale/append_order' => 'sales#add_to_existing_invoice'
    get 'room/:room_id' => 'rooms#show'
    get 'order/:order_id' => "orders#show"

    # post '/:booking_id' => 'home#item_show'

    # Other Charges
    get "/:sale_id/other_charges" => "other_charges#index"
    post "/:sale_id/other_charges" => "other_charges#create"

    # Discount
    get "/:id/discount" => "discounts#index"
    post "/:id/discount" => "discounts#create"
    get "/:id/remove_all_discount" => "discounts#remove_all_discount"
    post "/:id/remove_discount_items" => "discounts#remove_discount_items"

    get "/:id/request_bills" => "request_bills#print",:as => "request_bill"
    get '/:sale_id/reprint' => 'payments#reprint' ,:defaults => { :format => 'json' }

    #---------Shift ---------------#
    resources :shifts, only: [:index, :new, :create, :edit]
    post 'close_shift' => 'shifts#update_shift'
    get 'shift/close' => 'shifts#show'
    #shift - index (open/close shift landing page)
    #shift - show (sales summary display)
    #shift - new (open shift)
    #shift - edit (close shift)

    resources :cash_mgmt, only: [:new, :create]
    #payment - accepting or expending money from cashier - [Cash Journal]
    #payment - Incoming payments - [accept all payment types (cash, other payments (except rebate))
    #payment - Outing payments - Cash only [ *Misc expeness tracking]

    #--------- Payment ------------#
    post 'sale/:sale_id/rounding_adj' => 'payments#rounding_adj',:as => "calculate_rouding_adjs"
    get 'sale/:sale_id/first_bill' => 'payments#first_bill', :defaults => { :format => 'json' }
    get 'sale/:sale_id/payment' => 'payments#show'

    post 'payment/cash' => 'payments#create'
    post 'payment/mpu' => "mpu#create"
    post 'payment/jcb' => "jcb#create"
    post 'payment/master' => "master#create"
    post 'payment/visa' => "visa#create"
    post 'payment/paypar' => 'paypar_payments#create'
    post 'payment/credit' => 'credit_payments#create'

    get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index"
    get 'sale/:sale_id/payment/others_payment' => "others_payments#index"
    get 'sale/:sale_id/payment/others_payment/MPU' => "mpu#index"
    get 'sale/:sale_id/payment/others_payment/VISA' => "visa#index"
    get 'sale/:sale_id/payment/others_payment/Master' => "master#index"
    get 'sale/:sale_id/payment/others_payment/JCB' => "jcb#index"
    get 'sale/:sale_id/payment/others_payment/Redeem' => "redeem_payments#index"

    #---------Void --------------#
    post 'sale/:sale_id/void' => 'void#overall_void'

    #---------Multiple Invoices --------------#
    get 'table/:table_id/table_invoices' => "table_invoices#index" , :as => "table_invoice_index"
    get 'table/:table_id/table_invoice/:invoice_id' => "table_invoices#show" , :as => "table_invoice_show"
    get 'room/:room_id/room_invoices' => "room_invoices#index" , :as => "room_invoice_index"
    get 'room/:room_id/room_invoice/:invoice_id' => "room_invoices#show" , :as => "room_invoice_show"

    #---------Add Customer --------------#
    #resources :customers
    get '/:sale_id/customers', to: "customers#add_customer"
    get '/:customer_id/get_customer' => 'home#get_customer',:as => "show_customer_details"
    post '/:sale_id/update_sale' , to: "customers#update_sale_by_customer" # update customer id in sale table
  end

  #--------- Waiter/Ordering Station ------------#
  namespace :oishi do
      #zones
      #tables
      #orders
  end

  #--------- Customer Relationship Management ------------#
  namespace :crm do
      root "home#index"
      resources :customers
      resources :dining_queues
      post "update_booking" , to: "bookings#update_booking", as: "update_booking"#assign and cancel
      get '/print/:id', to: "home#print_order"#print order for crm

      get "/dining_queues/:id/assign"    =>"dining_queues#assign", :as => "assign"
      post "/dining_queues/assign_table" =>"dining_queues#assign_table", :as => "assign_table"
      post "/dining_queues/cancel_queue" =>"dining_queues#cancel_queue", :as => "cancel_queue"

  end

  #--------- Order Queue Station ------------#
  namespace :oqs do
    root "home#index"
    get "/:table_id", to: "home#get_order_items"

    post 'update_delivery', to: "home#update_delivery_status"

    # qty update
    get "/:id/edit", to: "edit#index"
    post "/:id", to: "edit#update"

    # Pass assigned_order_item_id
    get 'print/print/:id', to: "print#print"
    get 'print/print_order_summary/:id', to: "print#print_order_summary"
    #dashboard
    #
  end

  #--------- System Settings ------------#
  namespace :settings do
    #employees
    resources :employees
    #menu
    resources :menus do
      #menu_categories
      resources :menu_categories, only: [:new, :create, :edit,:delete]
    end

    #accounts
    resources :accounts

    resources :menu_categories do
      #menu_items
      # resources :menu_items
      resources :simple_menu_items
      resources :set_menu_items
    end

    resources :simple_menu_items do
      resources :menu_item_instances
    end
    resources :set_menu_items do
      resources :menu_item_instances
    end
    #menu_item_attributes
    resources :menu_item_attributes
    #menu_item_options
    resources :menu_item_options
    #tax_profiles
    resources :tax_profiles
    #lookups
    resources :lookups
    #cashier_terminals
    resources :cashier_terminals
    #order_job_stations

    #order_queue_stations
    resources :order_queue_stations do
      resources :processing_items, :only => [:new, :create]
    end
    #payment method settings
    resources :payment_method_settings
    #membership_settings
    resources :membership_settings
    resources :membership_actions

    #zones
    resources :zones do
      #tables
      resources :tables
      #rooms
      resources :rooms
    end

  end

  #--------- Transactions Sections ------------#
  namespace :transactions do
    resources :sales
    resources :orders
    resources :credit_notes

    get "/sales/:sale_id/manual_complete_sale" =>"manual_sales#manual_complete_sale", :as => "manual_complete_sale"
    get "/sales/:sale_id/void" =>"manual_sales#void", :as => "void"
    post "sales/:sale_id/manual_void_sale", to: "manual_sales#manual_void_sale", :as => "manual_void_sale"
  end

  #--------- Reports Controller Sections ------------#
  namespace :reports do
    resources :receipt_no, :only => [:index, :show]
    resources :dailysale, :only => [:index, :show]
    resources :saleitem, :only => [:index, :show]
    resources :shiftsale, :only => [:index, :show]
    # resources :sales, :only => [:index, :show]
    # resources :orders, :only => [:index, :show]
    # resources :customers, :only => [:index, :show]
    # resources :products,  :only => [:index, :show]
    # resources :inventory, :only => [:index, :show]
    # resources :employees, :only => [:index, :show]
  end

  #mount_compendium at: '/report' #, controller: 'reports'

  #--------- Reports ------------#
  # namespace :reports do
  #   #dashboard
  #   #sales
  #   #orders
  #   #shifts
  #   resources :shifts do
  #     resources :orders
  #     resources :sales
  #   end
  # end

  #----------- Print Setup --------#
  resources :print_settings

  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
