coton_app/app/controllers/admin/p_customer_sheets_controller.rb
Nicolas Bally f6529ff3f3 suite
2020-02-11 12:37:04 +01:00

235 lines
5.6 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::PCustomerSheetsController < ApplicationController
layout "admin"
before_filter :auth_admin
before_filter :admin_space
def update_stocks
@p_sheet_lines = PSheetLine.where("p_customer_sheet_id is not null").where(:externe => false, :stock_done => false, :shiped => true).order("ok_at DESC")
@p_sheet_lines.each do |psl|
psl.update_stock
end
redirect_to :back
end
def affects
@p_sheet_lines = PSheetLine.where("p_customer_sheet_id is not null").where(:externe => false, :stock_done => false, :shiped => true)
end
def admin_space
@admin_space = "ventes"
end
def index
@p_customer_sheets = PCustomerSheet.order("created_at DESC").all
per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50
page = (params[:page] and params[:page] != "") ? params[:page] : 1
@p_customer_sheets = @p_customer_sheets.page(page).per(per_page)
end
def show
@p_customer_sheet = PCustomerSheet.find(params[:id])
end
def set_sheet_line_ship
@p_customer_sheet = PCustomerSheet.find(params[:id])
end
def set_sheet_line_ship_save
@p_customer_sheet = PCustomerSheet.find(params[:id])
if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!)
@redirect_to_url = admin_p_customer_sheet_path(@p_customer_sheet)
render :layout => false
else
render action: "set_sheet_line_ship"
end
end
def new
@p_customer = PCustomer.find(params[:p_customer_id]) if params[:p_customer_id]
@p_customer_sheet = PCustomerSheet.new(:p_customer => @p_customer, :wish_start => Date.today, :wish_stop => ((Date.today + 7.day).end_of_week)-2.day)
end
def dup
@past_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet = PCustomerSheet.new(:p_customer => @past_customer_sheet.p_customer, :wish_start => Date.today, :wish_stop => ((Date.today + 7.day).end_of_week)-2.day)
@p_customer_sheet.particular_bill_id = @past_customer_sheet.particular_bill_id
@p_customer_sheet.particular_send_id = @past_customer_sheet.particular_send_id
@p_customer_sheet.cust_ref = @past_customer_sheet.cust_ref
@past_customer_sheet.p_sheet_lines.each do |p_sheet_line|
new_p_sheet_line = p_sheet_line.dup
p_sheet_line.p_sheet_line_lines.each do |p_sheet_line_line|
new_p_sheet_line.p_sheet_line_lines << p_sheet_line_line.dup
end
p_sheet_line.p_sheet_line_stocks.each do |p_sheet_line_stock|
new_p_sheet_line.p_sheet_line_stocks << p_sheet_line_stock.dup
end
@p_customer_sheet.p_sheet_lines << new_p_sheet_line
end
@p_customer_sheet.fdp_force_price = @past_customer_sheet.fdp_force_price
@p_customer_sheet.obs_devis = @past_customer_sheet.obs_devis
@p_customer_sheet.obs_bdc = @past_customer_sheet.obs_bdc
@p_customer_sheet.obs_bdl = @past_customer_sheet.obs_bdl
@p_customer_sheet.p_payment_type_id = @past_customer_sheet.p_payment_type_id
@p_customer_sheet.comptant = @past_customer_sheet.comptant
@p_customer_sheet.acompte = @past_customer_sheet.acompte
@p_customer_sheet.acompte_percent = @past_customer_sheet.acompte_percent
@p_customer_sheet.payment_delais = @past_customer_sheet.payment_delais
@p_customer_sheet.payment_fin_de_mois = @past_customer_sheet.payment_fin_de_mois
@p_customer_sheet.save
redirect_to admin_p_customer_sheets_path()
end
def edit
@p_customer_sheet = PCustomerSheet.find(params[:id])
end
def create
@p_customer_sheet = PCustomerSheet.new(params.require(:p_customer_sheet).permit!)
if @p_customer_sheet.save
@p_customer_sheets = PCustomerSheet.order(:id).all
redirect_to admin_p_customer_sheet_path(@p_customer_sheet)
else
render action: "new"
end
end
def update
@p_customer_sheet = PCustomerSheet.find(params[:id])
if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!)
@p_customer_sheets = PCustomerSheet.order(:id).all
redirect_to admin_p_customer_sheet_path(@p_customer_sheet)
else
render action: "edit"
end
end
def destroy
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.destroy
end
def generate_d
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_d
redirect_to :back
end
def generate_fp
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_fp
redirect_to :back
end
def generate_fa
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_fa
redirect_to :back
end
def generate_bc
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_bc
@p_customer_sheet.customer_validation_at = Time.now
@p_customer_sheet.save
redirect_to :back
end
def generate_bl
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_bl
redirect_to :back
end
def generate_f
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.generate_f
redirect_to :back
end
def reject
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.state = "refusée"
@p_customer_sheet.save
redirect_to :back
end
end