pdfs
This commit is contained in:
parent
3474db169e
commit
c978bbfc37
3
Gemfile
3
Gemfile
@ -73,3 +73,6 @@ gem "paranoia", "~> 2.0"
|
||||
gem 'workflow', '~> 1.2.0'
|
||||
|
||||
gem 'sidekiq'
|
||||
|
||||
|
||||
gem "posix-spawn"
|
@ -132,6 +132,7 @@ GEM
|
||||
mini_portile (~> 0.6.0)
|
||||
paranoia (2.1.4)
|
||||
activerecord (~> 4.0)
|
||||
posix-spawn (0.3.11)
|
||||
rack (1.6.0)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
@ -247,6 +248,7 @@ DEPENDENCIES
|
||||
mysql2
|
||||
net-ssh (~> 2.7.0)
|
||||
paranoia (~> 2.0)
|
||||
posix-spawn
|
||||
rails (= 4.2.0)
|
||||
rmagick
|
||||
rvm-capistrano (= 1.4.1)
|
||||
|
@ -1,7 +1,23 @@
|
||||
class Admin::DocumentsController < ApplicationController
|
||||
layout "admin"
|
||||
before_filter :auth_admin
|
||||
before_filter :load_offer
|
||||
before_filter :load_offer, :except => [:edit, :update]
|
||||
|
||||
def edit
|
||||
@document = Document.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@document = Document.find(params[:id])
|
||||
|
||||
if @document.update_attributes(params.require(:document).permit!)
|
||||
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
|
@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
|
||||
def check_enabled
|
||||
if !@current_customer.account_validated?
|
||||
if !(!@current_customer and current_admin and params[:admin]) or (@current_customer and !@current_customer.account_validated?)
|
||||
redirect_to public_my_account_path
|
||||
end
|
||||
end
|
||||
@ -13,12 +13,14 @@ class ApplicationController < ActionController::Base
|
||||
def auth_customer
|
||||
|
||||
session[:devise_id] = params[:d] if params[:d]
|
||||
if !current_customer
|
||||
if !current_customer and !(current_admin and params[:admin])
|
||||
session[:before_auth_url] = request.url
|
||||
redirect_to new_public_customers_auth_path(:p => params[:p], :for_annonce => (true if params[:controller] == "public/annonces"))
|
||||
else
|
||||
@current_customer.last_activity = DateTime.now
|
||||
@current_customer.save
|
||||
if !(current_admin and params[:admin])
|
||||
@current_customer.last_activity = DateTime.now
|
||||
@current_customer.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -13,17 +13,73 @@ class Public::DocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
def download
|
||||
@document = @accepted_offer.documents.find(params[:id])
|
||||
if @document.state == 'document_available'
|
||||
@document.state = :document_downloaded
|
||||
@document.save
|
||||
if !params[:admin]
|
||||
@document = @accepted_offer.documents.find(params[:id])
|
||||
else
|
||||
@document = Document.find(params[:id])
|
||||
end
|
||||
if !params[:admin]
|
||||
if @document.state == 'document_available'
|
||||
@document.state = :document_downloaded
|
||||
@document.save
|
||||
|
||||
admins = Admin.where.not(email: nil)
|
||||
admins.each do |admin|
|
||||
AdminMailer.customer_download_document(admin, @document, current_customer).deliver
|
||||
admins = Admin.where.not(email: nil)
|
||||
admins.each do |admin|
|
||||
AdminMailer.customer_download_document(admin, @document, current_customer).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
send_file @document.document.file.path
|
||||
if @document.particulars
|
||||
@temp_file = "#{Rails.root}/pdf/documents/#{@document.id}_temp.pdf"
|
||||
@final_file = "#{Rails.root}/pdf/documents/#{@document.id}.pdf"
|
||||
@final_file2 = "#{Rails.root}/pdf/documents/#{@document.id}-2.pdf"
|
||||
|
||||
|
||||
view = ActionView::Base.new(Rails.root.join('app/views'))
|
||||
view.class.include ApplicationHelper
|
||||
view.class.include Rails.application.routes.url_helpers
|
||||
|
||||
pdf = view.render(
|
||||
:pdf => "#{@document.id}",
|
||||
:template => "public/documents/particulars.html.haml",
|
||||
|
||||
:locals => {:@document => @document})
|
||||
|
||||
# then save to a file
|
||||
pdf = WickedPdf.new.pdf_from_string(pdf, :margin => { top: 0, # default 10 (mm)
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0 })
|
||||
|
||||
save_path = @temp_file
|
||||
File.open(save_path, 'wb') do |file|
|
||||
file << pdf
|
||||
end
|
||||
|
||||
|
||||
|
||||
require 'posix/spawn'
|
||||
|
||||
::POSIX::Spawn::Child.new 'pdftk', @document.document.file.path, 'background',@temp_file , 'output', @final_file
|
||||
|
||||
::POSIX::Spawn::Child.new 'pdftk', "A="+@document.document.file.path, 'B='+@final_file ,"cat", "B1", "A2-end", 'output', @final_file2
|
||||
|
||||
|
||||
#pdftk A=/Users/nico/Dev/negos_app/pdf_stamp/contrat.pdf B=/Users/nico/Dev/negos_app/pdf/documents/3.pdf cat B1 A2-end output fichier-final.pdf
|
||||
|
||||
|
||||
@data_to_send = File.open( @final_file2).read
|
||||
|
||||
send_data @data_to_send, :filename =>"negos-document-#{@document.id}.pdf" , :type => 'application/pdf',:disposition => (params[:inline] ? 'inline' : "attachment")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#render :inline => "j"
|
||||
else
|
||||
send_file @document.document.file.path
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -73,11 +129,13 @@ class Public::DocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
def check_owner
|
||||
@accepted_offer = AcceptedOffer.find(params[:accepted_offer_id])
|
||||
if !params[:admin]
|
||||
@accepted_offer = AcceptedOffer.find(params[:accepted_offer_id])
|
||||
|
||||
if @accepted_offer.customer.id != current_customer.id
|
||||
flash[:error] = "Vous n'avez pas la permission d'accéder à cette page"
|
||||
redirect_back_or_default :root
|
||||
if @accepted_offer.customer.id != current_customer.id
|
||||
flash[:error] = "Vous n'avez pas la permission d'accéder à cette page"
|
||||
redirect_back_or_default :root
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,8 @@ class Document < ActiveRecord::Base
|
||||
|
||||
belongs_to :accepted_offer
|
||||
|
||||
has_one :customer, :through => :accepted_offer
|
||||
|
||||
mount_uploader :document, DocumentUploader
|
||||
mount_uploader :returned_document, DocumentUploader
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
= file_field_tag :document
|
||||
= submit_tag("Charger" , class:"btn btn-primary")
|
||||
-else
|
||||
=link_to i(:"download"), admin_offer_accepted_offer_document_download_path(@offer, @accepted_offer, document),title: "Télécharger le document"
|
||||
=link_to i(:"download"), download_public_document_path(document, :admin => true),title: "Télécharger le document"
|
||||
-if !document.document_verified?
|
||||
=link_to i(:"remove"), admin_offer_accepted_offer_document_delete_path(@offer, @accepted_offer, document), title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'}
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
= file_field_tag :returned_document
|
||||
= submit_tag("Charger manuellement" , class:"btn btn-primary")
|
||||
-else
|
||||
=link_to i(:"download"), admin_offer_accepted_offer_document_download_returned_path(@offer, @accepted_offer, document),title: "Télécharger le document"
|
||||
=link_to i(:"download"), admin_offer_accepted_offer_document_download_returned_path(@offer, @accepted_offer, document, :admin => true),title: "Télécharger le document"
|
||||
-if !document.document_verified?
|
||||
=link_to i(:"remove"), admin_offer_accepted_offer_document_delete_returned_path(@offer, @accepted_offer, document), title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'}
|
||||
-if document.document_returned?
|
||||
@ -72,6 +72,8 @@
|
||||
-if !document.document_verified?
|
||||
=link_to i(:"check"), admin_offer_accepted_offer_document_force_verified_path(@offer, @accepted_offer, document), title: "Marquer ce document comme vérifié", :data => {:confirm => 'Voulez-vous vraiment marquer ce document comme vérifié ?'}
|
||||
|
||||
=link_to i(:"pencil"), edit_admin_document_path(document), :remote => true
|
||||
|
||||
=link_to i(:"trash"), admin_offer_accepted_offer_document_destroy_path(@offer, @accepted_offer, document), title: "Supprimer le document", :data => {:confirm => 'Voulez-vous vraiment supprimer ce document ?'}
|
||||
|
||||
-if @accepted_offer.waiting_documents? && @accepted_offer.documents.where(state: :document_verified).count == @accepted_offer.documents.count
|
||||
|
@ -31,6 +31,8 @@
|
||||
=f.input :need_2, :label => "2ième besoin : ",:as => :select, :collection => [ "Materiel professionnel", "Matériel informatique", "Achat de véhicules", "Energie"]
|
||||
=f.input :need_3, :label => "3ième besoin : ", :placeholder => "Autre, précisez ",:rows => 5, :input_html => {:style => "height:100px;"}
|
||||
|
||||
=f.input :particulars_text, :label => "En-tête contrats : ",:rows => 5, :input_html => {:style => "height:100px;"}
|
||||
|
||||
|
||||
|
||||
|
||||
|
0
app/views/admin/documents/_document.html.haml
Normal file
0
app/views/admin/documents/_document.html.haml
Normal file
14
app/views/admin/documents/_form.html.haml
Executable file
14
app/views/admin/documents/_form.html.haml
Executable file
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
|
||||
=semantic_form_for [:admin, @document], :remote => true do |f|
|
||||
.content
|
||||
|
||||
|
||||
= f.inputs do
|
||||
|
||||
= f.input :particulars, :label => "Avec impression coordonnées ?"
|
||||
|
||||
|
||||
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"
|
||||
|
1
app/views/admin/documents/edit.js.erb
Executable file
1
app/views/admin/documents/edit.js.erb
Executable file
@ -0,0 +1 @@
|
||||
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);
|
3
app/views/admin/documents/update.js.erb
Executable file
3
app/views/admin/documents/update.js.erb
Executable file
@ -0,0 +1,3 @@
|
||||
//$('#annonce_cat_index').replaceWith("<%= escape_javascript(render(@document)) %>");
|
||||
|
||||
close_pane_hover();
|
28
app/views/public/documents/particulars.html.haml
Normal file
28
app/views/public/documents/particulars.html.haml
Normal file
@ -0,0 +1,28 @@
|
||||
!!!
|
||||
%html
|
||||
%head
|
||||
|
||||
%meta{:"http-equiv" => "Content-Type", :content=>"text/html; charset=UTF-8"}
|
||||
%meta{:name=>"viewport", :content=>"width=device-width,initial-scale=1"}
|
||||
:css
|
||||
#div{
|
||||
position:absolute;top:9.3cm;left:1.4cm;right:1.4cm;border:1px solid red;font-family:serif;
|
||||
|
||||
}
|
||||
p{
|
||||
margin:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%body
|
||||
|
||||
|
||||
#div
|
||||
=simple_format @document.customer.particulars_text
|
@ -72,6 +72,9 @@ set :application, 'negos_app'
|
||||
run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias"
|
||||
|
||||
|
||||
run "ln -s #{deploy_to}shared/pdf #{current_path}/pdf"
|
||||
|
||||
|
||||
run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3"
|
||||
|
||||
sudo "cp #{current_path}/config/unicorn_init_d /etc/init.d/#{application}"
|
||||
|
@ -0,0 +1,4 @@
|
||||
|
||||
WickedPdf.config = {
|
||||
:exe_path => "/usr/local/bin/wkhtmltopdf",
|
||||
}
|
@ -20,6 +20,12 @@ Rails.application.routes.draw do
|
||||
get 'p/:mlm_token' => "public/customers#parrainage", :as => :mlm_token
|
||||
|
||||
namespace :public do
|
||||
resources :documents do
|
||||
member do
|
||||
get :download
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
resources :customer_favs
|
||||
resources :customer_ribs do
|
||||
@ -224,6 +230,9 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
|
||||
resources :documents
|
||||
|
||||
resources :domains
|
||||
resources :annonces do
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
class AddParticularsToDocuments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :documents, :particulars, :boolean
|
||||
|
||||
add_column :customers, :particulars_text, :text
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160530213935) do
|
||||
ActiveRecord::Schema.define(version: 20160920185645) do
|
||||
|
||||
create_table "accepted_offers", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
@ -224,6 +224,7 @@ ActiveRecord::Schema.define(version: 20160530213935) do
|
||||
t.float "latitude", limit: 24
|
||||
t.float "longitude", limit: 24
|
||||
t.datetime "last_activity"
|
||||
t.text "particulars_text", limit: 65535
|
||||
end
|
||||
|
||||
create_table "data_files", force: :cascade do |t|
|
||||
@ -246,6 +247,7 @@ ActiveRecord::Schema.define(version: 20160530213935) do
|
||||
t.string "returned_document", limit: 255
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "particulars", limit: 1
|
||||
end
|
||||
|
||||
create_table "domain_customers", force: :cascade do |t|
|
||||
|
Loading…
x
Reference in New Issue
Block a user