188 lines
4.4 KiB
Ruby
188 lines
4.4 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
|
|
class Admin::MOdrPrimesController < ApplicationController
|
|
layout "admin"
|
|
before_action :auth_admin
|
|
|
|
before_action :admin_space
|
|
|
|
def admin_space
|
|
@admin_space = "payments"
|
|
end
|
|
|
|
def index
|
|
@m_odr_primes = MOdrPrime.joins(:p_customer).joins(:m_odr_file_roulage).all
|
|
|
|
if params[:search][:state].to_s != ""
|
|
@m_odr_primes = @m_odr_primes.where(:state => params[:search][:state])
|
|
end
|
|
|
|
if params[:search][:name].to_s != ""
|
|
|
|
@m_odr_primes = @m_odr_primes.joins(:particular).where("particulars.organisation LIKE ? or particulars.name LIKE ? or particulars.firstname LIKE ?", "%#{params[:search][:name]}%", "%#{params[:search][:name]}%", "%#{params[:search][:name]}%")
|
|
end
|
|
|
|
|
|
@m_odr_primes = sort_by_sorting(@m_odr_primes, "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
|
|
@m_odr_primes = @m_odr_primes.page(page).per(per_page)
|
|
|
|
}
|
|
|
|
|
|
format.csv {
|
|
@headers = []
|
|
@columns = []
|
|
MOdrPrime.qi_table_order.each do |key, value|
|
|
|
|
if value.instance_of? Hash
|
|
name = value[:name]
|
|
else
|
|
name = value
|
|
end
|
|
|
|
if name != "Actions"
|
|
@headers << name.to_s
|
|
@columns << key
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
xlsx_package = Axlsx::Package.new
|
|
wb = xlsx_package.workbook
|
|
wb.add_worksheet(name: "import") do |sheet|
|
|
sheet.add_row @headers
|
|
|
|
@m_odr_primes.each do |m_odr_prime|
|
|
line = []
|
|
|
|
@columns.each do |column|
|
|
|
|
if (m_odr_prime.respond_to?("csv_"+column.to_s))
|
|
line << m_odr_prime.send("csv_"+column.to_s)
|
|
elsif (m_odr_prime.respond_to?(column))
|
|
if m_odr_prime.send(column.to_s).class.to_s == "BigDecimal"
|
|
line << m_odr_prime.send(column.to_s).to_s.gsub('.', ',')
|
|
else
|
|
line << m_odr_prime.send(column.to_s)
|
|
end
|
|
else
|
|
line << column.to_s
|
|
end
|
|
|
|
end
|
|
|
|
|
|
sheet.add_row line, types: line.map{|t| self.cell_type_from_value(t)}
|
|
end
|
|
|
|
|
|
end
|
|
|
|
@final_file = "#{Rails.root}/private_medias/export-primes-#{Time.now.to_s.to_slug}.xlsx"
|
|
|
|
|
|
xlsx_package.serialize(@final_file)
|
|
|
|
|
|
send_file @final_file
|
|
|
|
|
|
|
|
}
|
|
|
|
end
|
|
end
|
|
|
|
def show
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
|
|
end
|
|
|
|
def new
|
|
@m_odr_prime = MOdrPrime.new
|
|
|
|
end
|
|
|
|
def edit
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
|
|
end
|
|
|
|
def create
|
|
@m_odr_prime = MOdrPrime.new(params.require(:m_odr_prime).permit!)
|
|
|
|
if @m_odr_prime.save
|
|
|
|
else
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def update
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
|
|
|
|
if @m_odr_prime.update_attributes(params.require(:m_odr_prime).permit!)
|
|
|
|
else
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def destroy
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
@m_odr_prime.destroy
|
|
|
|
end
|
|
|
|
def generate_virement
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
|
|
if @m_odr_prime.p_customer.valid_m_odr_rep_rib
|
|
@m_odr_prime.m_odr_virements.create
|
|
@m_odr_prime.change_state("Virement demandé")
|
|
|
|
|
|
if @m_odr_prime.p_customer.mail_hists.where(:mail_type_id => 14).count == 0
|
|
@m_odr_prime.send_mail_type("primes-valide-1")
|
|
|
|
else
|
|
@m_odr_prime.send_mail_type("primes-valide-2")
|
|
end
|
|
|
|
|
|
|
|
else
|
|
@m_odr_prime.change_state("Manque RIB")
|
|
|
|
@m_odr_prime.send_mail_type("primes-manque-rib") if @m_odr_prime.p_customer.m_odr_rep_ribs.count == 0
|
|
end
|
|
|
|
redirect_back(fallback_location:"/")
|
|
end
|
|
|
|
def attente_roulage
|
|
@m_odr_prime = MOdrPrime.find(params[:id])
|
|
@m_odr_prime.change_state("En attente de roulage")
|
|
|
|
redirect_back(fallback_location:"/")
|
|
|
|
end
|
|
|
|
|
|
end
|