105 lines
2.4 KiB
Ruby
105 lines
2.4 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
|
|
class Admin::ImportCsvsController < ApplicationController
|
|
layout "admin"
|
|
before_action :auth_admin
|
|
|
|
before_action :admin_space
|
|
|
|
def admin_space
|
|
@admin_space = "default"
|
|
end
|
|
|
|
def index
|
|
@import_csvs = ImportCsv.all
|
|
|
|
@import_csvs = sort_by_sorting(@import_csvs, "id DESC")
|
|
respond_to do |format|
|
|
format.html{
|
|
|
|
params[:search][:per_page] = params[:search][:per_page] || 100
|
|
per_page = params[:search][:per_page]
|
|
page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
|
@import_csvs = @import_csvs.page(page).per(per_page)
|
|
|
|
}
|
|
end
|
|
end
|
|
|
|
def show
|
|
@import_csv = ImportCsv.find(params[:id])
|
|
|
|
end
|
|
|
|
def match_refs
|
|
@price_documents = PriceDocument.joins(price_line_block: :price_lines).where({price_line_block: {price_lines: {p_product_ref: nil}}}).distinct
|
|
redirect_to :action => :index if @price_documents.empty?
|
|
end
|
|
|
|
def charge
|
|
@import_csv = ImportCsv.find(params[:id])
|
|
@import_csv.load
|
|
|
|
# redirect_to :action => :index
|
|
redirect_to match_refs_admin_import_csvs_path
|
|
end
|
|
|
|
|
|
def new
|
|
@import_csv = ImportCsv.new(:parent_id => params[:parent_id])
|
|
if @import_csv.parent
|
|
@import_csv.name = @import_csv.parent.name
|
|
@import_csv.table_name = @import_csv.parent.table_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit
|
|
@import_csv = ImportCsv.find(params[:id])
|
|
|
|
end
|
|
|
|
def create
|
|
@import_csv = ImportCsv.new(params.require(:import_csv).permit!)
|
|
|
|
if @import_csv.save
|
|
redirect_to :action => :index
|
|
else
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def update
|
|
@import_csv = ImportCsv.find(params[:id])
|
|
|
|
|
|
if @import_csv.update_attributes(params.require(:import_csv).permit!)
|
|
redirect_to :action => :index
|
|
else
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def destroy
|
|
@import_csv = ImportCsv.find(params[:id])
|
|
@import_csv.destroy
|
|
|
|
end
|
|
|
|
def temp_p_product
|
|
if params[:price_line_id]
|
|
@price_line = PriceLine.find(params[:price_line_id])
|
|
p_product = PProduct.find_or_create_by(name: "--> Selectioner un produit <--", code: "--> Indiquer un code produit <--")
|
|
@p_product_ref = PProductRef.find_or_create_by(p_product: p_product, ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht)
|
|
@p_product_ref.p_product_ref_specs.build
|
|
end
|
|
end
|
|
end
|