|
|
@@ -4,13 +4,12 @@ class SpecialPricesController < ApplicationController
|
|
|
|
|
|
##--- Breadcrum_rails
|
|
|
add_breadcrumb I18n.t("breadcrumbs." + controller_name), :special_prices_path
|
|
|
- add_breadcrumb "Nuevo precio(s) especial " , :new_special_price_path, only: :new
|
|
|
- add_breadcrumb "Detalle de precio(s) especial " , :special_price_path, only: :show
|
|
|
- add_breadcrumb "Editar precio(s) especial" , :edit_special_price_path, only: :edit
|
|
|
+ add_breadcrumb "Nuevo precio(s) especial", :new_special_price_path, only: :new
|
|
|
+ add_breadcrumb "Detalle de precio(s) especial", :special_price_path, only: :show
|
|
|
+ add_breadcrumb "Editar precio(s) especial", :edit_special_price_path, only: :edit
|
|
|
|
|
|
before_action :set_special_price, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
-
|
|
|
# GET /special_prices/new
|
|
|
def new
|
|
|
@special_price = SpecialPrice.new
|
|
|
@@ -21,8 +20,8 @@ class SpecialPricesController < ApplicationController
|
|
|
def create
|
|
|
@special_price = SpecialPrice.new(special_price_params)
|
|
|
@special_price.user_id = current_user.id
|
|
|
- existence = SpecialPrice.where(:product_id => @special_price.product_id, :customer_id => @special_price.customer_id).any?
|
|
|
- @variantes = Product.where(:parent_id => @special_price.product_id)
|
|
|
+ existence = SpecialPrice.where(product_id: @special_price.product_id, customer_id: @special_price.customer_id).any?
|
|
|
+ @variantes = Product.where(parent_id: @special_price.product_id)
|
|
|
|
|
|
respond_to do |format|
|
|
|
if existence == true
|
|
|
@@ -38,15 +37,16 @@ class SpecialPricesController < ApplicationController
|
|
|
# PATCH/PUT /special_prices/1.json
|
|
|
def update
|
|
|
respond_to do |format|
|
|
|
- unless params[:special_price][:percent].blank?
|
|
|
- @special_price.price = nil
|
|
|
- else
|
|
|
+ if params[:special_price][:percent].blank?
|
|
|
@special_price.percent = nil
|
|
|
+ else
|
|
|
+ @special_price.price = nil
|
|
|
end
|
|
|
+
|
|
|
@special_price.audit_comment = "Precio especial #{@special_price.product.name} #{@special_price.product.display_attributes} con #{'$' + params[:special_price][:price] if params[:special_price][:price].present?} #{params[:special_price][:percent] + '%' if params[:special_price][:percent].present?} de descuento"
|
|
|
if @special_price.update(special_price_params)
|
|
|
format.html { redirect_to @special_price, notice: 'Special price was successfully updated.' }
|
|
|
- format.json { render :show, status: :ok, location: @special_price }
|
|
|
+ format.json { head :no_content }
|
|
|
else
|
|
|
format.html { render :edit }
|
|
|
format.json { render json: @special_price.errors, status: :unprocessable_entity }
|
|
|
@@ -66,7 +66,7 @@ class SpecialPricesController < ApplicationController
|
|
|
end
|
|
|
|
|
|
def get_special_price_by_customer
|
|
|
- @special_prices = SpecialPrice.includes(:product).where(:customer_id => params[:customer_id]).order("id ASC")
|
|
|
+ @special_prices = SpecialPrice.includes(:product).where(customer_id: params[:customer_id]).order("id ASC")
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
@@ -74,13 +74,13 @@ class SpecialPricesController < ApplicationController
|
|
|
|
|
|
def add_special_price_by_barcode
|
|
|
respond_to do |format|
|
|
|
- @product = Product.find_by(:barcode => params[:barcode])
|
|
|
+ @product = Product.find_by(barcode: params[:barcode])
|
|
|
unless @product.blank?
|
|
|
@special_price = SpecialPrice.new
|
|
|
@special_price.product_id = @product.id
|
|
|
@special_price.customer_id = params[:customer_id]
|
|
|
@special_price.user_id = current_user.id
|
|
|
- @existence = SpecialPrice.where(:product_id => @special_price.product_id, :customer_id => @special_price.customer_id).any?
|
|
|
+ @existence = SpecialPrice.where(product_id: @special_price.product_id, customer_id: @special_price.customer_id).any?
|
|
|
@special_price.save
|
|
|
end
|
|
|
format.js
|
|
|
@@ -88,13 +88,14 @@ class SpecialPricesController < ApplicationController
|
|
|
end
|
|
|
|
|
|
private
|
|
|
- # Use callbacks to share common setup or constraints between actions.
|
|
|
- def set_special_price
|
|
|
- @special_price = SpecialPrice.find(params[:id])
|
|
|
- end
|
|
|
|
|
|
- # Never trust parameters from the scary internet, only allow the white list through.
|
|
|
- def special_price_params
|
|
|
- params.require(:special_price).permit(:product_id, :customer_id, :price, :percent, :status, :user_id)
|
|
|
- end
|
|
|
+ # Use callbacks to share common setup or constraints between actions.
|
|
|
+ def set_special_price
|
|
|
+ @special_price = SpecialPrice.find(params[:id])
|
|
|
+ end
|
|
|
+
|
|
|
+ # Never trust parameters from the scary internet, only allow the white list through.
|
|
|
+ def special_price_params
|
|
|
+ params.require(:special_price).permit(:product_id, :customer_id, :price, :percent, :status, :user_id)
|
|
|
+ end
|
|
|
end
|