suite
This commit is contained in:
parent
d4c76bafa8
commit
8232f07e28
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class Admin::MOdrRepsController < ApplicationController
|
class Admin::MOdrRepsController < ApplicationController
|
||||||
layout "admin"
|
layout "admin"
|
||||||
before_action :auth_admin
|
before_action :auth_admin, :except => :ba
|
||||||
|
|
||||||
before_action :admin_space
|
before_action :admin_space
|
||||||
|
|
||||||
@ -98,6 +98,12 @@ class Admin::MOdrRepsController < ApplicationController
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ba
|
||||||
|
@m_odr_rep = MOdrRep.find(params[:id])
|
||||||
|
#@m_odr_rep.generate_ba if !params[:print]
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def generate_virement
|
def generate_virement
|
||||||
@m_odr_rep = MOdrRep.find(params[:id])
|
@m_odr_rep = MOdrRep.find(params[:id])
|
||||||
|
@ -5,6 +5,9 @@ class MOdrRep < ApplicationRecord
|
|||||||
include ActionView::Helpers::TranslationHelper
|
include ActionView::Helpers::TranslationHelper
|
||||||
include ActionView::Helpers::UrlHelper
|
include ActionView::Helpers::UrlHelper
|
||||||
|
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
has_many :particulars, :dependent => :destroy
|
has_many :particulars, :dependent => :destroy
|
||||||
accepts_nested_attributes_for :particulars, :allow_destroy => true
|
accepts_nested_attributes_for :particulars, :allow_destroy => true
|
||||||
@ -344,4 +347,47 @@ file_admin_ok remise particular_civilite particular_name particular_firstname pa
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_ba
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
doc_number = self.token
|
||||||
|
url = "/admin/m_odr_reps/#{self.id}/ba"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@temp_file = "#{Rails.root}/public/public_medias/#{doc_number}.png"
|
||||||
|
|
||||||
|
url = (Rails.env.development? ? "http://localhost:4000" : "https://offres.market-inn.fr/").to_s+url
|
||||||
|
puts url
|
||||||
|
pdf = ("ba")
|
||||||
|
|
||||||
|
node_file = @temp_file
|
||||||
|
|
||||||
|
req = "node #{pdf}.js #{Shellwords.escape(url)} #{Shellwords.escape(@temp_file)} #{self.m_odr.ba_width} #{self.m_odr.ba_height}"
|
||||||
|
puts "AAA"
|
||||||
|
puts req
|
||||||
|
system(req)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require 'posix/spawn'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return @temp_file
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def ba_url
|
||||||
|
|
||||||
|
|
||||||
|
url = (Rails.env.development? ? "http://localhost:4000" : "https://offres.market-inn.fr/").to_s+"/public_medias/#{self.token}.png"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -155,4 +155,9 @@ RIB :
|
|||||||
%br
|
%br
|
||||||
=link_to "Générer le virement", generate_virement_admin_m_odr_rep_path(@m_odr_rep), :class => "btn btn-primary"
|
=link_to "Générer le virement", generate_virement_admin_m_odr_rep_path(@m_odr_rep), :class => "btn btn-primary"
|
||||||
|
|
||||||
|
-if @m_odr_rep.m_odr.ba_generation
|
||||||
|
|
||||||
|
=debug @m_odr_rep.generate_ba
|
||||||
|
=link_to "Voir le bon d'achat", @m_odr_rep.ba_url, :class => "btn btn-primary"
|
||||||
|
|
||||||
|
|
38
app/views/admin/m_odr_reps/ba.html.haml
Normal file
38
app/views/admin/m_odr_reps/ba.html.haml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ba
|
||||||
|
=image_tag "https://offres.market-inn.fr/"+@m_odr_rep.m_odr.ba_image_file.file.url if @m_odr_rep.m_odr.ba_image_file
|
||||||
|
|
||||||
|
|
||||||
|
.name{:style => "top:#{@m_odr_rep.m_odr.ba_name_y}px;"}
|
||||||
|
=@m_odr_rep.particular_firstname
|
||||||
|
=@m_odr_rep.particular_name
|
||||||
|
|
||||||
|
.place{:style => "top:#{@m_odr_rep.m_odr.ba_place_y}px;"}
|
||||||
|
=@m_odr_rep.place_name
|
||||||
|
|
||||||
|
|
||||||
|
:scss
|
||||||
|
#ba{
|
||||||
|
position:absolute;
|
||||||
|
font-family:Arial;
|
||||||
|
.name{
|
||||||
|
position:absolute;
|
||||||
|
left:0;
|
||||||
|
right:0;
|
||||||
|
text-align:center;
|
||||||
|
font-size:30px;
|
||||||
|
text-transform:uppercase;
|
||||||
|
font-weigh:bold;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.place{
|
||||||
|
position:absolute;
|
||||||
|
left:0;
|
||||||
|
right:0;
|
||||||
|
text-align:center;
|
||||||
|
font-size:30px;
|
||||||
|
text-transform:uppercase;
|
||||||
|
font-weigh:bold;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -110,10 +110,10 @@
|
|||||||
|
|
||||||
= f.input :ba_width, :label => "Largeur du bon d'achat (px) :"
|
= f.input :ba_width, :label => "Largeur du bon d'achat (px) :"
|
||||||
= f.input :ba_height, :label => "Hauteur du bon d'achat (px) :"
|
= f.input :ba_height, :label => "Hauteur du bon d'achat (px) :"
|
||||||
= f.input :ba_name_x, :label => "Position X du nom (px) :"
|
=# f.input :ba_name_x, :label => "Position X du nom (px) :"
|
||||||
= f.input :ba_name_y, :label => "Position Y du nom (px) :"
|
= f.input :ba_name_y, :label => "Position Y du nom (px) :"
|
||||||
|
|
||||||
= f.input :ba_place_x, :label => "Position X du revendeur (px) :"
|
=# f.input :ba_place_x, :label => "Position X du revendeur (px) :"
|
||||||
= f.input :ba_place_y, :label => "Position Y du revendeur (px) :"
|
= f.input :ba_place_y, :label => "Position Y du revendeur (px) :"
|
||||||
|
|
||||||
|
|
||||||
|
42
ba.js
Normal file
42
ba.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
'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.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
|
||||||
|
await page.waitFor(250);
|
||||||
|
await page.emulateMedia('screen');
|
||||||
|
await page._emulationManager._client.send(
|
||||||
|
'Emulation.setDefaultBackgroundColorOverride',
|
||||||
|
{ color: { r: 0, g: 0, b: 0, a: 0 } }
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("AAAAAAAAAA");
|
||||||
|
console.log("AAAAAAAAAA");
|
||||||
|
|
||||||
|
console.log(process.argv[4]);
|
||||||
|
console.log(process.argv[5]);
|
||||||
|
await page.setViewport({
|
||||||
|
|
||||||
|
width: parseFloat(process.argv[4]),
|
||||||
|
height: parseFloat(process.argv[5]),
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.screenshot({path: process.argv[3]});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
} finally {
|
||||||
|
if (browser) {
|
||||||
|
browser.close();
|
||||||
|
}
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
createPdf();
|
@ -220,6 +220,8 @@ Rails.application.routes.draw do
|
|||||||
get :send_mail
|
get :send_mail
|
||||||
get :refuse
|
get :refuse
|
||||||
|
|
||||||
|
get :ba
|
||||||
|
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user