# rubocop:disable Metrics/BlockLength
Rails.application.routes.draw do
  resources :storers
  resources :warehouse_stocks
  devise_for :users, path: "/", path_names: {
    sign_in: 'login',
    sign_out: 'logout',
    # password: 'secret',
    # password: 'pwdchange',
    # update_password: 'pwdchange',
    confirmation: 'verification',
    unlock: 'unblock',
    registration: 'register',
    sign_up: 'cmon_let_me_in'
  }

  devise_scope :user do
    get "login", to: "devise/sessions#new"
    get "logout", to: "devise/sessions#destroy"
    # get "secret", to: "devise/passwords#new"
    # get "pwdchange", to: "devise/registration#edit"
  end

  # rutas para login de usuarios
  get "pwdchange" => "users#edit_password", :as => "pwdchange"
  patch "update_password" => "users#update_password"
  post 'update_status/:user_id' => 'users#update_status', :as => "user_update_status"

  # rutas para administracion de usuarios
  get 'users' => 'users#index', :as => 'users'
  post 'users' => 'users#create'
  get 'users/new' => 'users#new', :as => 'new_user'
  get 'users/:id/edit' => 'users#edit', :as => 'edit_user'
  get 'users/:id' => 'users#show', :as => 'user'
  patch 'users/:id' => 'users#update'
  put 'users/:id' => 'users#update'

  resources :product_wastes, except: [:show, :edit] do
    post 'create' => 'product_wastes#create', defaults: { format: 'js' }
  end

  resources :suppliers do
    post 'update_status' => 'suppliers#update_status', :as => "update_status"
  end

  resources :commissions do
    resources :sellerscommissions
    post 'create' => 'commissions#create', defaults: { format: 'js' }
  end
  put 'commission_seller/:commission_id' => 'commissions#commission_seller', :format => :json
  get 'sellers_for_commissions' => 'commissions#sellers_for_commissions', :format => :js
  get 'find_sellers_by_date/:pointsale_id/:initial_date/:final_date' => 'commissions#find_sellers_by_date', :format => :js
  get 'generate_commissions' => 'commissions#generate_commissions', :format => :js

  resources :customers do
    post 'update_status' => 'customers#update_status', :as => "update_status"
    get 'reserved_sales' => 'customers#reserved_sales_by_customer'
  end
  get '/debtors' => 'customers#debtors'
  get '/customer_sales' => 'customers#customer_sales'

  resources :cash_registers, except: [:show] do
    post 'update_status' => 'cash_registers#update_status', :as => "update_status"
    get "get_cash_fund/" => "cash_registers#get_cash_fund", :as => "get_cash_fund", :format => :json
  end

  resources :expenses, except: [:show]

  resources :expensesconcepts, except: [:show]

  resources :pointsales, except: [:show] do
    post 'update_status' => 'pointsales#update_status', :as => "update_status"
    post 'assign_or_delete_products' => 'pointsales#assign_or_delete_products', :format => :js
    post 'delete_products_from_pointsale' => 'pointsales#delete_products_from_pointsale', :format => :js
    post 'assign_products_to_pointsale' => 'pointsales#assign_products_to_pointsale', :format => :js
  end
  post 'transfer_stock' => 'pointsales#transfer_stock', :as => "transfer_stock"

  resources :categories, except: [:show] do
    post 'update_status' => 'categories#update_status', :as => "update_status"
  end

  resources :special_prices, except: [:show, :edit] do
    post 'create' => 'special_products#create', defaults: { format: 'js' }
  end
  get 'add_special_price_by_barcode/:barcode/:customer_id' => 'special_prices#add_special_price_by_barcode', defaults: { format: 'js' }

  resources :credit_payments

  resources :products do
    post 'edit_from_purchase' => 'products#edit_from_purchase', defaults: { format: 'js' }
    patch 'update_from_purchase' => 'products#update_from_purchase', :constraints => ->(req) { req.xhr? }
    post 'update_status' => 'products#update_status', :as => "update_status"
    get 'prices' => 'products#list_prices'
    get 'variantsprices/:pointsale_id' => 'products#list_prices_variants', :format => :json
    get 'edit_variants' => 'products#edit_variants'
    post 'update_variants' => 'products#update_variants'
  end
  get 'validate_unique_barcode/:barcode' => 'products#validate_unique_barcode', defaults: { format: 'js' }
  get 'product_track' => 'products#product_track', :as => "product_track"

  resources :available_products, except: [:edit, :update] do
    get 'edit_price' => 'available_products#edit_price'
    patch 'update_price' => 'available_products#update_price'
  end
  post 'update_all_variants_prices' => 'available_products#update_all_variants_prices', defaults: { format: 'json' }

  resources :cash_outs
  get 'get_open_cash_registers' => 'cash_outs#get_open_cash_registers', defaults: { format: 'js' }
  post 'select_open_cash_to_close/:open_cash_register_id' => 'cash_outs#select_open_cash_to_close', defaults: { format: 'js' }
  get 'find_cash_outs_by_date/:pointsale_id/:begin_date/:end_date' => 'cash_outs#find_cash_outs_by_date', defaults: { format: 'js' }
  get 'opened_cash_registers' => 'cash_outs#opened_cash_registers'
  get 'print_cash_out_receipt/:cash_out_id' => 'cash_outs#print_receipt', :as => 'print_cash_out_receipt'

  resources :sellers, except: [:show] do
    post 'update_status' => 'sellers#update_status', :as => "update_status"
  end

  resources :pos_configs

  resources :credits

  resources :purchases
  get 'find_purchases_by_date/:begin_date/:end_date' => 'purchases#find_purchases_by_date', defaults: { format: 'js' }

  resources :pre_purchases, except: [:new, :show] do
    post 'create' => 'pre_purchases#create', defaults: { format: 'js' }
    put 'edit' => 'pre_purchases#update', defaults: { format: 'js' }
  end
  get 'add_pre_purchase_by_barcode_pointsale/:barcode/:supplier_id/:pointsale_id' => 'pre_purchases#add_pre_purchase_by_barcode', defaults: { format: 'js' }
  get 'add_pre_purchase_by_barcode_warehouse/:barcode/:supplier_id/:warehouse_id' => 'pre_purchases#add_pre_purchase_by_barcode', defaults: { format: 'js' }

  resources :sales do
    post 'create' => 'sales#create', defaults: { format: 'js' }
    post 'return_expired' => 'sales#return_expired', :as => "return_expired"
    get 'liquidate_reserve' => 'sales#liquidate_reserve'
  end
  get 'find_sales_by_date/:begin_date/:end_date' => 'sales#find_sales_by_date', defaults: { format: 'js' }
  get 'find_reserved_sales_by_date/:begin_date/:end_date' => 'sales#find_reserved_sales_by_date', defaults: { format: 'js' }
  get 'find_customer_sales_by_date/:begin_date/:end_date/:cliente' => 'sales#find_customer_sales_by_date', defaults: { format: 'js' }
  get 'print_receipt/:sale_id' => 'sales#print_receipt', :as => 'print_receipt'
  get 'print_reserve_receipt/:sale_id' => 'sales#print_reserve_receipt', :as => 'print_reserve_receipt'
  get 'print_credit_receipt/:sale_id' => 'sales#print_credit_receipt', :as => 'print_credit_receipt'
  get 'print_partial_payment_receipt' => 'sales#print_partial_payment_receipt', :as => 'print_partial_payment_receipt'
  get 'print_credit_payment_receipt' => 'sales#print_credit_payment_receipt', :as => 'print_credit_payment_receipt'
  get 'sales_reserved' => 'sales#sales_reserved', :as => 'sales_reserved'
  get 'add_haggle/:pre_sale' => 'sales#add_haggle', :as => 'add_sale_haggle'
  patch 'sale_create_haggle/:pre_sale' => 'sales#create_haggle', :as => 'create_haggle'
  get 'cancel_reserved_sale/:sale_id' => 'sales#cancel_reserved_sale', :as => 'cancel_reserved_sale'
  get 'find_sales_by_dates_or_code' => 'sales#find_sales_by_dates_or_code', defaults: { format: 'js' }
  get 'sales_per_month_report' => 'sales#sales_per_month_report'
  get 'sales_per_month' => 'sales#sales_per_month', defaults: { format: 'js' }
  put 'update_presale_customer/:customer_id' => 'pre_sales#update_presale_customer', as: 'update_presale_customer', format: :json

  resources :pre_sales, except: [:new, :show] do
    post 'create' => 'pre_sales#create', defaults: { format: 'js' }
    put 'edit' => 'pre_sales#update', defaults: { format: 'js' }
  end
  get 'add_pre_sale_by_barcode/:barcode/:customer_id/:open_cash_register_id/:sale_type' => 'pre_sales#add_pre_sale_by_barcode', defaults: { format: 'js' }
  put 'update_saletype/:type' => 'pre_sales#update_saletype'

  resources :open_cash_registers do
    post 'create' => 'open_cash_registers#create', defaults: { format: 'js' }
  end

  resources :cash_registers_moves do
    post 'create' => 'cash_registers_moves#create', defaults: { format: 'js' }
  end
  get 'add_quick_payment/:type' => 'cash_registers_moves#add_quick_payment', defaults: { format: 'js' }, :as => "add_quick_payment"
  get 'create_quick_debt_payment/:customer_id' => 'cash_registers_moves#create_quick_debt_payment', defaults: { format: 'js' }
  post 'confirm_payments' => 'cash_registers_moves#confirm_payments', :as => "cash_move_confirm_payments"
  post 'confirm_reserve/:sale_id' => 'cash_registers_moves#confirm_reserve', :as => "cash_move_confirm_reserve"
  post 'add_payments_to_reserve/:sale_id' => 'cash_registers_moves#add_payments_to_reserve', :as => "cash_move_add_payments_to_reserve"
  post 'delete_credit_payment/:credit_payment_id' => 'cash_registers_moves#delete_credit_payment', :as => "cash_move_delete_payment"

  resources :transfers do
    put 'accept_transfer' => 'transfers#accept_transfer', defaults: { format: 'js' }
    put 'detail_adjustment/:detail_id' => 'transfers#detail_adjustment', :format => :json
  end
  get 'print_transfer_receipt/:transfer_id' => 'transfers#print_receipt', :as => 'print_transfer_receipt'

  resources :pre_transfers, except: [:new, :show] do
    post 'create' => 'pre_transfers#create', defaults: { format: 'js' }
    put 'edit' => 'pre_transfers#update', defaults: { format: 'js' }
  end
  get 'add_pre_transfer_by_barcode/:barcode/:origin_id/:destiny_id' => 'pre_transfers#add_pre_transfer_by_barcode', defaults: { format: 'js' }

  resources :warehouses do
    post 'update_status' => 'warehouses#update_status', :as => "update_status"
  end

  resources :products_returns
  get 'sales_details/:sale_id' => 'products_returns#get_sale_details'
  get 'check_sale_detail_quantity' => 'products_returns#check_sale_detail_quantity'
  post 'add_product_to_return' => 'products_returns#add_product_to_return', defaults: { format: 'js' }, :as => "add_product_to_return"
  get 'update_quantity_prod_return' => 'products_returns#update_quantity_prod_return', :format => :json
  get 'print_return_receipt/:products_return_id' => 'products_returns#print_receipt', :as => 'print_return_receipt'
  get 'add_products_return_haggle' => 'products_returns#add_haggle', :as => 'add_products_return_haggle'
  post 'create_products_return_haggle' => 'products_returns#create_haggle', :as => 'create_products_return_haggle'

  root 'dashboard#index'
  get 'get_chart_data_for_dashboard' => 'dashboard#get_chart_data_for_dashboard'

  resources :units, except: [:show] do
    post 'create' => 'units#create', defaults: { format: 'js' }
    put 'edit' => 'units#update', defaults: { format: 'js' }
  end
  post 'update_unit_status/:id' => 'units#update_status', :as => "unit_status"

  get "getcounties/:state_id" => "application#getcounties", :as => "getcounties", :format => :json

  ## hcamargo: ruta  para cargar los productos
  get 'purchases_data/products_list'

  # rutas pre( lo que sea, sale, purchase, etc.)
  get 'delete_pre_purchases' => 'application#delete_pre_purchases', :constraints => ->(req) { req.xhr? }
  get 'delete_pre_sales' => 'application#delete_pre_sales', :constraints => ->(req) { req.xhr? }
  get 'delete_pre_transfers' => 'application#delete_pre_transfers', :constraints => ->(req) { req.xhr? }

  # rutas para el STOCK
  get 'stock_by_pointsale' => 'available_products#stock_by_pointsale', :as => 'stock_by_pointsale'
  get 'products_stock/:pointsale_id' => 'available_products#stock', :as => 'products_stock'
  put 'update_stock' => 'available_products#update_stock', defaults: { format: 'json' }
  get 'products_initial_stock/:pointsale_id' => 'available_products#initial_stock', :as => 'products_initial_stock'
  get 'print_stock_by_pointsale' => 'available_products#print_stock', :as => 'print_stock_by_pointsale'
  put 'set_initial_stock' => 'available_products#set_initial_stock', defaults: { format: 'json' }
  get 'total_products_by_pointsale' => 'available_products#total_products_by_pointsale', :format => :json
  get 'total_invested_in_pointsale' => 'available_products#total_invested_in_pointsale', :format => :json

  # find de productos para el typeahead
  get 'find_products' => 'application#find', :format => :json
  # para special_prices
  get 'find_products_sp/:query' => 'application#find_sp', :format => :json
  #
  get 'find_products_from_stock' => 'application#find_from_stock', :format => :json
  get 'find_from_stock_by_pointsale' => 'application#find_from_stock_by_pointsale', :format => :json

  get "getcategories/:category_id" => "application#get_subcategories", :as => "get_subcategories", :format => :json
  get 'get_max_product_id' => 'application#get_max_product_id', :format => :json
  get 'get_max_purchaseid_by_pointsale/:pointsale_id' => 'application#get_max_purchaseid_by_pointsale', :format => :json
  get 'get_max_purchaseid_by_warehouse/:warehouse_id' => 'application#get_max_purchaseid_by_warehouse', :format => :json
  get 'get_next_sale_code/:open_cash_register_id' => 'application#get_next_sale_code', :format => :json, :as => "get_sale_code"
  get 'get_next_expense_code/:open_cash_register_id' => 'application#get_next_expense_code', :format => :json, :as => "get_expense_code"
  get 'get_special_price_by_customer/:customer_id' => 'special_prices#get_special_price_by_customer', defaults: { format: 'js' }

  get "products_by_category_pointsale/:pointsale_id/:category_id" => "application#products_by_category_pointsale", :as => "products_by_category_pointsale", :format => :json
  get "verify_transfer/:transfer_id" => "transfers#verify_transfer", :as => "verify_transfer"
end
# rubocop:enable Metrics/BlockLength
