63 lines
1.4 KiB
Ruby
63 lines
1.4 KiB
Ruby
class Origami::CustomersController < BaseOrigamiController
|
|
#Form to add customer -
|
|
def index
|
|
|
|
|
|
end
|
|
|
|
# GET /crm/customers/1
|
|
# GET /crm/customers/1.json
|
|
def show
|
|
end
|
|
|
|
def add_customer
|
|
|
|
@sale_id = params[:sale_id]
|
|
filter = params[:filter]
|
|
|
|
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
|
|
|
|
# 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]
|
|
if(id == "SAL")
|
|
sale = Sale.find(params[:sale_id])
|
|
else
|
|
sale = Order.find(params[:sale_id])
|
|
end
|
|
|
|
status = sale.update_attributes(customer_id: params[:customer_id])
|
|
|
|
if status == true
|
|
render json: JSON.generate({:status => true})
|
|
else
|
|
render json: JSON.generate({:status => false, :error_message => "Record not found"})
|
|
|
|
end
|
|
end
|
|
|
|
|
|
end
|