adding PDF invoice
This commit is contained in:
parent
820bd03640
commit
159085c55d
Binary file not shown.
@ -427,39 +427,40 @@ class Admin::PriceDocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
|
||||
def print
|
||||
|
||||
|
||||
|
||||
def OLD_print
|
||||
@price_document = PriceDocument.find_by_token(params[:id])
|
||||
@element = @price_document.ref_element
|
||||
|
||||
doc_number = @price_document.d_number
|
||||
url = print_admin_price_document_path(:id => @price_document.token, :html => true)
|
||||
|
||||
|
||||
|
||||
|
||||
params[:inline] = true
|
||||
|
||||
if !params[:html] # and !Rails.env.development?
|
||||
|
||||
@data_to_send = File.open(@price_document.generate_pdf).read
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
send_data @data_to_send, :filename =>"#{doc_number}.pdf" , :type => 'application/pdf',:disposition => (params[:inline] ? 'inline' : "attachment")
|
||||
#render :inline => "y"
|
||||
|
||||
else
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def print
|
||||
@price_document = PriceDocument.find_by_token(params[:id])
|
||||
@element = @price_document.ref_element
|
||||
|
||||
doc_number = @price_document.d_number
|
||||
url = print_admin_price_document_path(:id => @price_document.token, :html => true)
|
||||
params[:inline] = true
|
||||
if !params[:html] # and !Rails.env.development?
|
||||
@data_to_send = File.open(@price_document.generate_pdf).read
|
||||
send_data @data_to_send, :filename =>"#{doc_number}.pdf" , :type => 'application/pdf',:disposition => (params[:inline] ? 'inline' : "attachment")
|
||||
#render :inline => "y"
|
||||
else
|
||||
render :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create_avoir
|
||||
@past_price_document = PriceDocument.find(params[:id])
|
||||
|
@ -585,50 +585,79 @@ class PriceDocument < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def generate_pdf
|
||||
|
||||
|
||||
|
||||
|
||||
def OLD_generate_pdf
|
||||
doc_number = self.d_number
|
||||
url = print_admin_price_document_path(:id => self.token, :html => true)
|
||||
|
||||
url = print_admin_price_document_path(:id => self.token, :html => true) #don't forget to copy line "include Rails.application.routes.url_helpers"
|
||||
|
||||
@temp_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp.pdf"
|
||||
@final_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp2.pdf"
|
||||
@final_file2 = "#{Rails.root}/pdf/price_documents/#{doc_number}.pdf"
|
||||
|
||||
url = (Rails.env.development? ? "http://localhost:4000" : "http://mdmb.basiclabs.fr").to_s+url
|
||||
puts url
|
||||
pdf = ("pdf")
|
||||
|
||||
url = (Rails.env.development? ? "http://localhost:3000" : "http://mdmb.basiclabs.fr").to_s+url
|
||||
pdf = ("pdf2")
|
||||
node_file = @temp_file
|
||||
|
||||
|
||||
puts "NODE IFLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
|
||||
puts url
|
||||
puts url
|
||||
puts url
|
||||
puts url
|
||||
puts url
|
||||
puts node_file
|
||||
puts "NODE IFLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
|
||||
|
||||
|
||||
|
||||
system("node #{pdf}.js #{Shellwords.escape(url)} #{Shellwords.escape(@temp_file)}")
|
||||
require 'posix/spawn'
|
||||
|
||||
::POSIX::Spawn::Child.new 'pdftk', @temp_file, 'stamp', "#{Rails.root}/pdf_stamp/en-tete.pdf", 'output', @final_file
|
||||
::POSIX::Spawn::Child.new 'pdftk', @final_file,"#{Rails.root}/pdf_stamp/cgv.pdf", 'cat', 'output', @final_file2 #AJOUT CGV
|
||||
|
||||
# File.rename(@temp_file, @final_file2) if File.exist?(@temp_file)
|
||||
# File.delete(@temp_file) if File.exist?(@temp_file)
|
||||
# File.delete(@final_file) if File.exist?(@final_file)
|
||||
|
||||
return @final_file
|
||||
|
||||
end
|
||||
|
||||
|
||||
def generate_pdf
|
||||
doc_number = self.d_number
|
||||
url = print_admin_price_document_path(:id => self.token, :html => true) #don't forget to copy line "include Rails.application.routes.url_helpers"
|
||||
|
||||
@temp_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp.pdf"
|
||||
@final_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp2.pdf"
|
||||
@final_file2 = "#{Rails.root}/pdf/price_documents/#{doc_number}.pdf"
|
||||
|
||||
url = (Rails.env.development? ? "http://localhost:3000" : "http://mdmb.basiclabs.fr").to_s+url
|
||||
pdf = ("pdf")
|
||||
node_file = @temp_file
|
||||
|
||||
system("node #{pdf}.js #{Shellwords.escape(url)} #{Shellwords.escape(@temp_file)}")
|
||||
|
||||
|
||||
|
||||
require 'posix/spawn'
|
||||
|
||||
::POSIX::Spawn::Child.new 'pdftk', @temp_file, 'stamp', "#{Rails.root}/pdf_stamp/en-tete.pdf", 'output', @final_file
|
||||
|
||||
|
||||
# ::POSIX::Spawn::Child.new 'pdftk', @final_file,"#{Rails.root}/pdf_stamp/cgv.pdf", 'cat', 'output', @final_file2 #AJOUT CGV
|
||||
# if true
|
||||
if self.label != "Bon de livraison"
|
||||
#::POSIX::Spawn::Child.new 'pdftk', @final_file,"#{Rails.root}/pdf_stamp/cgv.pdf", 'cat', 'output', @final_file2 #AJOUT CGV
|
||||
return @final_file2
|
||||
else
|
||||
return @final_file
|
||||
end
|
||||
|
||||
# File.rename(@temp_file, @final_file2)
|
||||
|
||||
|
||||
#File.delete(@temp_file) if File.exist?(@temp_file)
|
||||
#File.delete(@final_file) if File.exist?(@final_file)
|
||||
|
||||
return @final_file
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def create_avoir
|
||||
past_price_document = self
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
- if params[:controller] == "admin/p_articles"
|
||||
=semantic_form_for [:admin, @p_article], :remote => true do |f|
|
||||
.content
|
||||
=f.inputs do
|
||||
-if params[:p_product_ref_id]
|
||||
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :selected => f.object.p_product_ref , :label => f.object.label_for(:p_product_ref)
|
||||
-else
|
||||
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => f.object.label_for(:p_product_ref)
|
||||
-if PGrade::ACTIVATED
|
||||
= f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
|
||||
%h4 Numero de série :
|
||||
.p_article_serial_nums_form
|
||||
= f.semantic_fields_for :p_article_serial_nums do |form|
|
||||
=render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form}
|
||||
%p= link_to_add_fields "Ajouter un numéro de série", f, :p_article_serial_nums, {:class => "btn btn-primary"}
|
||||
=f.inputs do
|
||||
-if params[:p_product_ref_id]
|
||||
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :selected => f.object.p_product_ref , :label => f.object.label_for(:p_product_ref)
|
||||
-else
|
||||
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => f.object.label_for(:p_product_ref)
|
||||
-if PGrade::ACTIVATED
|
||||
= f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
|
||||
%h4 Numero de série :
|
||||
.p_article_serial_nums_form
|
||||
= f.semantic_fields_for :p_article_serial_nums do |form|
|
||||
=render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form}
|
||||
%p= link_to_add_fields "Ajouter un numéro de série", f, :p_article_serial_nums, {:class => "btn btn-primary"}
|
||||
|
||||
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
|
||||
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
|
||||
- elsif params[:controller] == "admin/price_lines"
|
||||
= form.inputs do
|
||||
-if params[:p_product_ref_id]
|
||||
|
@ -17,9 +17,6 @@
|
||||
|
||||
.qi_row
|
||||
.qi_pannel.qi_plain.padding
|
||||
|
||||
|
||||
|
||||
-if @bon_de_commande = @p_customer_sheet.price_documents.where(:cc_label => "Bon de commande").first
|
||||
-price_line_block = @bon_de_commande.price_line_block
|
||||
%h3
|
||||
@ -109,3 +106,4 @@
|
||||
|
||||
:javascript
|
||||
$('.p_articles_lines').hide();
|
||||
|
File diff suppressed because one or more lines are too long
@ -33,14 +33,6 @@
|
||||
=form_particular_bill.hidden_field :owner_id
|
||||
=form_particular_bill.hidden_field :owner_type
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-if current_admin.has_permission?("customer-sheets-bl")
|
||||
=# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"}
|
||||
|
||||
@ -102,8 +94,5 @@
|
||||
:javascript
|
||||
$('.p_product_ref_select').select2();
|
||||
$('.add_lines').click(function() {
|
||||
$('.p_product_ref_select').last().select2({
|
||||
//theme: "bootstrap"
|
||||
});
|
||||
//$('.p_product_ref_select').last().removeClass('form-control');
|
||||
})
|
||||
$('.p_product_ref_select').last().select2(});
|
||||
});
|
@ -61,7 +61,8 @@
|
||||
|
||||
.price_lines_form
|
||||
=f.semantic_fields_for :price_lines do |f|
|
||||
=render :partial => "admin/price_lines/form_bon_de_reception_achat", :locals => {:form => f}
|
||||
-# =render :partial => "admin/price_lines/form_bon_de_reception_achat", :locals => {:form => f}
|
||||
=render :partial => "admin/price_lines/form", :locals => {:form => f}
|
||||
|
||||
%p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary add_lines"}
|
||||
|
||||
@ -105,9 +106,7 @@
|
||||
= f.input :ct_payment_month_end, :label => "Fin de mois ?"
|
||||
|
||||
:javascript
|
||||
$('.p_product_ref_select').select2();
|
||||
$('.add_lines').click(function() {
|
||||
$('.p_product_ref_select').last().select2({
|
||||
//theme: "bootstrap"
|
||||
});
|
||||
//$('.p_product_ref_select').last().removeClass('form-control');
|
||||
})
|
||||
$('.p_product_ref_select').last().select2();
|
||||
});
|
||||
|
@ -1,7 +1 @@
|
||||
= form.input :p_article_id, as: :select, collection: PArticle.joins(:p_product_ref).where(p_product_ref: @price_line.p_product_ref).map{|p_article| [p_article.serialized_name, p_article.id]}, label: "Article(s) associé(s)", input_html: {class:"p_article_select"}
|
||||
|
||||
:javascript
|
||||
$('.p_article_select').select2({
|
||||
//theme: "bootstrap"
|
||||
});
|
||||
//$('.p_article_select').removeClass('form-control');
|
||||
|
@ -6,4 +6,4 @@
|
||||
= f.semantic_fields_for :p_articles do |form|
|
||||
=render :partial => "admin/p_articles/form", :locals => {:form => form, @price_line => f.object}
|
||||
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary"} if f.object.p_articles.count < f.object.qte
|
||||
.actions=f.submit "Sauvegarder", :class => "btn btn-primary"
|
||||
=render :partial => "qi/actions", :locals => {:f => f}
|
||||
|
@ -1,8 +1,17 @@
|
||||
.mx-2.my-2
|
||||
=semantic_form_for [:admin, @price_line], :remote => true do |f|
|
||||
=f.inputs do
|
||||
.price_line_p_articles_form.col-3
|
||||
= f.semantic_fields_for :price_line_p_articles do |form|
|
||||
= render "admin/price_line_p_articles/form", form: form, price_line: @price_line
|
||||
%p= link_to_add_fields "Ajouter un article", f, :price_line_p_articles, {:class => "btn btn-primary"} if @price_line.p_articles.count < @price_line.qte
|
||||
=render :partial => "qi/actions", :locals => {:f => f}
|
||||
.content
|
||||
=f.inputs do
|
||||
.price_line_p_articles_form
|
||||
= f.semantic_fields_for :price_line_p_articles do |form|
|
||||
= render "admin/price_line_p_articles/form", form: form, price_line: @price_line
|
||||
%p= link_to_add_fields "Ajouter un article", f, :price_line_p_articles, {:class => "btn btn-primary add_price_line_p_article"} if @price_line.p_articles.count < @price_line.qte
|
||||
=render :partial => "qi/actions", :locals => {:f => f}
|
||||
|
||||
|
||||
|
||||
:javascript
|
||||
$('.p_article_select').select2();
|
||||
$('.add_price_line_p_article').click(function() {
|
||||
$('.p_article_select').last().select2();
|
||||
});
|
||||
|
6
pdf.js
6
pdf.js
@ -8,16 +8,12 @@ const createPdf = async() => {
|
||||
browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
|
||||
const page = await browser.newPage();
|
||||
//await page.setViewport({width: 794, height: 1122, deviceScaleFactor: 1});
|
||||
await page._emulationManager._client.send(
|
||||
'Emulation.setDefaultBackgroundColorOverride',
|
||||
{ color: { r: 0, g: 0, b: 0, a: 0 } }
|
||||
);
|
||||
await page.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
|
||||
await page.waitFor(250);
|
||||
await page.pdf({
|
||||
path: process.argv[3],
|
||||
format: 'A4',
|
||||
margin: { top: "0cm", right: "0cm", bottom: "0cm", left: "0cm" },
|
||||
margin: { top: "0.5cm", right: "1cm", bottom: "4.2cm", left: "1cm" },
|
||||
printBackground: false
|
||||
});
|
||||
} catch (err) {
|
||||
|
32
pdf3.js
Normal file
32
pdf3.js
Normal file
@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
const createPdf = async() => {
|
||||
let browser;
|
||||
try {
|
||||
browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
|
||||
const page = await browser.newPage();
|
||||
//await page.setViewport({width: 794, height: 1122, deviceScaleFactor: 1});
|
||||
await page._emulationManager._client.send(
|
||||
'Emulation.setDefaultBackgroundColorOverride',
|
||||
{ color: { r: 0, g: 0, b: 0, a: 0 } }
|
||||
);
|
||||
await page.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
|
||||
await page.waitFor(250);
|
||||
await page.pdf({
|
||||
path: process.argv[3],
|
||||
format: 'A4',
|
||||
margin: { top: "0cm", right: "0cm", bottom: "0cm", left: "0cm" },
|
||||
printBackground: false
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err.message);
|
||||
} finally {
|
||||
if (browser) {
|
||||
browser.close();
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
createPdf();
|
BIN
pdf_stamp/cgv.pdf
Normal file
BIN
pdf_stamp/cgv.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
pdf_stamp/en-tête.pdf
Normal file
BIN
pdf_stamp/en-tête.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user