class Origami::CustomersController < BaseOrigamiController load_and_authorize_resource def index end # GET /crm/customers/1 # GET /crm/customers/1.json def show end def get_customer filter = params[:filter] if filter.nil? @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else @crm_customers = Customer.search(filter) end render :json => @crm_customers.to_json end def add_customer @sale_id = params[:sale_id] if(@sale_id[0,3] == "SAL") @booking = Booking.find_by_sale_id(@sale_id) @dining_facility = DiningFacility.find(@booking.dining_facility_id) else @booking_order = BookingOrder.find_by_order_id(@sale_id) @booking = Booking.find(@booking_order.booking_id) @dining_facility = DiningFacility.find(@booking.dining_facility_id) end filter = params[:filter] if filter.nil? @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else @crm_customers = Customer.search(filter) end #@crm_customers = Customer.all @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new @count_customer = Customer.count_customer @taxes = TaxProfile.all.order("order_by asc") # if flash["errors"] # @crm_customer.valid? # end respond_to do |format| # format.html { render :template => "crm/customers/index" } format.html { render action: "index"} format.json { render json: @crm_customers } end end def update_sale_by_customer id = params[:sale_id][0,3] customer_id = params[:customer_id] # Check and find with card no # if(!customer_id.include? "CUS") # customer = Customer.find_by_paypar_account_no(customer_id) # if(customer != nil) # customer_id = customer.customer_id # end # end if(id == "SAL") sale = Sale.find(params[:sale_id]) status = sale.update_attributes(customer_id: customer_id) sale.sale_orders.each do |sale_order| order = Order.find(sale_order.order_id) status = order.update_attributes(customer_id: customer_id) end else @booking = BookingOrder.find_by_order_id(params[:sale_id]) @orders = BookingOrder.where("booking_id = ? ", @booking.booking_id) @orders.each do |bo| order = Order.find(bo.order_id) status = order.update_attributes(customer_id: customer_id) end end if status == true render json: JSON.generate({:status => true}) # Re-calc All Amount in Sale sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) end end end