# -*- encoding : utf-8 -*-

class Admin::MOdrRepRibsController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "payments"
  end
  
  def index
    @m_odr_rep_ribs = MOdrRepRib.all

    @m_odr_rep_ribs = sort_by_sorting(@m_odr_rep_ribs, "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_rep_ribs = @m_odr_rep_ribs.page(page).per(per_page)
      
      }
    end
  end

  def show
    @m_odr_rep_rib = MOdrRepRib.find(params[:id])

  end

  def new
    @m_odr_rep_rib = MOdrRepRib.new(:p_customer_id => params[:p_customer_id])
  
  end

  def edit
    @m_odr_rep_rib = MOdrRepRib.find(params[:id])
    
  end

  def create
    @m_odr_rep_rib = MOdrRepRib.new(params.require(:m_odr_rep_rib).permit!)

    if @m_odr_rep_rib.save
      #@m_odr_rep_rib.m_odr_rep.change_state("En cours de traitement")
    else
      render action: "new"
 
    end

  end


  def update
    @m_odr_rep_rib = MOdrRepRib.find(params[:id])
    @m_odr_rep = @m_odr_rep_rib.m_odr_rep

    if @m_odr_rep_rib.update_attributes(params.require(:m_odr_rep_rib).permit!)
      #@m_odr_rep_rib.m_odr_rep.change_state("En cours de traitement")
    else
     render action: "edit" 
      
    end
      
  end

  
  def send_mail
    @m_odr_rep_rib = MOdrRepRib.find(params[:id])
    @m_odr_rep = @m_odr_rep_rib.m_odr_rep
    
    @m_odr_rep.send_mail_type("erreur-coordonnees-bancaire", @m_odr_rep_rib)
    
    redirect_to [:admin, @m_odr_rep]
    
    
  end


  def destroy
    @m_odr_rep_rib = MOdrRepRib.find(params[:id])
    @m_odr_rep_rib.destroy
    
  end
end
