diff --git a/app/controllers/admin/abonnements_controller.rb b/app/controllers/admin/abonnements_controller.rb new file mode 100755 index 0000000..b45f609 --- /dev/null +++ b/app/controllers/admin/abonnements_controller.rb @@ -0,0 +1,108 @@ +# -*- encoding : utf-8 -*- + +class Admin::AbonnementsController < ApplicationController + before_filter :auth_admin + + layout "admin" + + + before_filter :find_abonnements + + + def index + + end + + + + + + def new + @abonnement = Abonnement.new() + + + + end + + def edit + @abonnement = Abonnement.find(params[:id]) + end + + def show + @abonnement = Abonnement.find(params[:id]) + end + + + def create + @abonnement = Abonnement.new(params.require(:abonnement).permit!) + + + if @abonnement.save + + find_abonnements + flash[:notice] = "La catégorie à été ajouté avec succès." + + + else + render :action => "new" + + end + + end + + + def update + @abonnement = Abonnement.find(params[:id]) + + + + + + + respond_to do |format| + if @abonnement.update_attributes(params.require(:abonnement).permit!) + + + + flash[:notice] = "Le menu à été modifié avec succès." + + if @reorder + format.js { + + render :action => "update" } + else + format.js { + @abonnement = Abonnement.find(@abonnement.id) + render :action => "update_row" } + end + end + + end + + + + + + end + + + def destroy + @abonnement = Abonnement.find(params[:id]) + @abonnement.destroy + find_abonnements + + flash[:notice] = "La catégorie à bien été supprimée." + end + + + protected + + def find_abonnements + + @abonnements = Abonnement.order("created_at DESC").all + + + + end + +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d9cba69..ac8bb3c 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,11 @@ class ApplicationController < ActionController::Base def get_reseaux - if session[:reseaux_id] and current_customer and !params[:no_reseaux] + if params[:reseaux_id] and current_customer and !params[:no_reseaux] + @reseaux = current_customer.reseauxes.find(params[:reseaux_id]) + @reseaux_layout = true + session[:reseaux_id] = @reseaux.id + elsif session[:reseaux_id] and current_customer and !params[:no_reseaux] @reseaux = current_customer.reseauxes.find(session[:reseaux_id]) @reseaux_layout = true elsif !params[:no_reseaux] @@ -72,6 +76,8 @@ class ApplicationController < ActionController::Base end def require_negos_abo + get_reseaux + if !current_abo and (!session[:reseaux_id] or (@reseaux and @reseaux.abo_needed)) redirect_to new_public_abonnement_path end diff --git a/app/controllers/public/needs_controller.rb b/app/controllers/public/needs_controller.rb index 1f76345..dc39781 100755 --- a/app/controllers/public/needs_controller.rb +++ b/app/controllers/public/needs_controller.rb @@ -10,6 +10,15 @@ class Public::NeedsController < ApplicationController before_filter :check_owner, only: [:destroy,:edit,:update] def index + #dsffsd = sdfd + + if params[:reseaux_id] + @reseaux = Reseaux.find(params[:reseaux_id]) + session[:reseaux_id] = @reseaux.id + elsif session[:reseaux_id] + @reseaux = Reseaux.find(session[:reseaux_id]) + end + params[:type] = params[:type] || 1 params[:type] = params[:type].to_i diff --git a/app/controllers/public/products_controller.rb b/app/controllers/public/products_controller.rb index e633d03..22114d2 100755 --- a/app/controllers/public/products_controller.rb +++ b/app/controllers/public/products_controller.rb @@ -3,6 +3,7 @@ class Public::ProductsController < ApplicationController before_filter :auth_customer + before_filter :require_negos_abo layout "public" def show diff --git a/app/models/abonnement.rb b/app/models/abonnement.rb index 4abc530..d6f6f54 100644 --- a/app/models/abonnement.rb +++ b/app/models/abonnement.rb @@ -1,5 +1,6 @@ class Abonnement < ActiveRecord::Base belongs_to :reseaux + belongs_to :customer has_many :payments, :as => :element def after_paid diff --git a/app/models/customer.rb b/app/models/customer.rb index 9d0b7fc..0f627b9 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -288,6 +288,10 @@ class Customer < ActiveRecord::Base "#{firstname.capitalize} #{name.upcase}" end + def name_for_label + "#{self.organisation} #{self.name.upcase} #{self.firstname.capitalize} - #{self.email}" + end + def pseudo if self.pro self.organisation diff --git a/app/views/admin/abonnements/_abonnement.html.haml b/app/views/admin/abonnements/_abonnement.html.haml new file mode 100755 index 0000000..d344aa7 --- /dev/null +++ b/app/views/admin/abonnements/_abonnement.html.haml @@ -0,0 +1,30 @@ + +%tr#abonnement.abonnement{:id => abonnement.id} + + %td=abonnement.id + %td + -if abonnement.reseaux + =abonnement.reseaux.name + %td + -if abonnement.customer + =abonnement.customer.organisation + =abonnement.customer.name + =abonnement.customer.firstname + + %td=abonnement.slug + %td=l abonnement.start_at + %td=l abonnement.end_at + %td=number_to_currency abonnement.price + %td=ic :check if abonnement.paid + + + + + %td.actions + =# link_to i(:"trash-o"), [:admin, abonnement], :data =>{:remote => true, :confirm => 'Voulez-vous vraiment supprimer cette taille ? Elle sera supprimée de tous les produits qui la contenait'}, :method => :delete + + = link_to i(:pencil), edit_admin_abonnement_path(abonnement), :data => {:remote => true} + + + + diff --git a/app/views/admin/abonnements/_form.html.haml b/app/views/admin/abonnements/_form.html.haml new file mode 100755 index 0000000..6c547c0 --- /dev/null +++ b/app/views/admin/abonnements/_form.html.haml @@ -0,0 +1,19 @@ += semantic_form_for [:admin,@abonnement], :remote => true do |form| + + .content + = form.input :reseaux_id, :label => "Réseau :", :collection => Reseaux.where(:parent_id => nil).all, :as => :select, :include_blank => true + =form.input :customer_id, :label => "Client :", :collection => Customer.order(:organisation, :name).all, :as => :select, :include_blank => true, :member_label => :name_for_label + + = form.input :start_at, :label => "Début", :as => :date + = form.input :end_at, :label => "Fin", :as => :date + + = form.input :price, :label => "Prix :" + = form.input :paid, :label => "Payé ?" + + + + + + .actions + = form.submit "Sauvegarder" + \ No newline at end of file diff --git a/app/views/admin/abonnements/create.js.erb b/app/views/admin/abonnements/create.js.erb new file mode 100755 index 0000000..c9131f6 --- /dev/null +++ b/app/views/admin/abonnements/create.js.erb @@ -0,0 +1,4 @@ +close_pane_hover(); + +$('#abonnements').html("<%= escape_javascript(render(@abonnements)) %>"); + diff --git a/app/views/admin/abonnements/destroy.js.erb b/app/views/admin/abonnements/destroy.js.erb new file mode 100755 index 0000000..c3e3d12 --- /dev/null +++ b/app/views/admin/abonnements/destroy.js.erb @@ -0,0 +1,5 @@ + +$('#abonnement_<%= @abonnement.id %>').remove(); + + +<%= flash_js %> diff --git a/app/views/admin/abonnements/edit.js.erb b/app/views/admin/abonnements/edit.js.erb new file mode 100755 index 0000000..06a7cbc --- /dev/null +++ b/app/views/admin/abonnements/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",550,600); \ No newline at end of file diff --git a/app/views/admin/abonnements/index.html.haml b/app/views/admin/abonnements/index.html.haml new file mode 100755 index 0000000..79f7995 --- /dev/null +++ b/app/views/admin/abonnements/index.html.haml @@ -0,0 +1,27 @@ +.qi_header + .right= link_to 'Ajouter un abonnement manuellement', new_admin_abonnement_path, :class => "btn btn-primary", :remote => true + %h1 + + Boutique + %span + Liste des documents + + + +.qi_row + .qi_pannel.qi_plain.padding + %table.table + + %tr + %th ID + %th Réseaux + %th Client + %th Slug + %th Début + %th Fin + %th Prix + %th Payé ? + + %th + + %tbody#abonnements=render @abonnements diff --git a/app/views/admin/abonnements/new.js.erb b/app/views/admin/abonnements/new.js.erb new file mode 100755 index 0000000..06a7cbc --- /dev/null +++ b/app/views/admin/abonnements/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",550,600); \ No newline at end of file diff --git a/app/views/admin/abonnements/update_row.js.erb b/app/views/admin/abonnements/update_row.js.erb new file mode 100755 index 0000000..d912ac0 --- /dev/null +++ b/app/views/admin/abonnements/update_row.js.erb @@ -0,0 +1,2 @@ +close_pane_hover(); +$('#abonnement_<%= @abonnement.id %>').replaceWith("<%= escape_javascript(render(@abonnement))%>"); diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 1731db6..8576c1c 100755 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -72,6 +72,7 @@ %li= link_to "Type de documents", admin_product_order_document_types_path %li=# link_to "Codes de reduction", admin_vourcher_codes_path %li=link_to "Pages statiques", admin_menu_items_path(:menu_id => 1) + %li=link_to "Abos", admin_abonnements_path() %ul.nav.navbar-nav.navbar-right %li.dropdown diff --git a/config/routes.rb b/config/routes.rb index 73e243b..1768da9 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -336,6 +336,14 @@ Rails.application.routes.draw do end namespace :admin do + resources :abonnements do + + member do + get :force + end + end + + resources :fournisseurs resources :product_order_documents resources :product_order_document_types