Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print sign to pos PDF defini #24044

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8a78134
SQL
Feb 6, 2023
80efbd3
Class Propal
Feb 24, 2023
1ef16f6
model cyan
Feb 24, 2023
4c58867
Define signing position
Feb 24, 2023
2ed3f0e
Print sign to pos PDF
Feb 24, 2023
265e41d
Merge branch 'develop' into NEW---PDF-Pos-sign
BB2A-Anthony Feb 25, 2023
d4583f0
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
Feb 27, 2023
a2d406d
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
Mar 2, 2023
b602b3d
Use var exist and rewite
Mar 2, 2023
035ffc8
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
Mar 7, 2023
ffd82ec
del field
Mar 20, 2023
d0ea75d
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
Mar 21, 2023
2e3a767
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
May 5, 2023
6a9510b
Clean
May 22, 2023
15adefe
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
May 22, 2023
8a525f1
FIX - error php test unit
May 24, 2023
317b391
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into N…
May 26, 2023
67fb812
Merge branch 'NEW---PDF-Pos-sign' of https://github.com/bb2a/dolibarr…
Jul 12, 2023
9dd38ea
Merge branch develop
Oct 13, 2023
b33f07c
Merge branch develop
Oct 22, 2024
7273c96
Copy
Oct 22, 2024
067e33f
FIX
Oct 22, 2024
8f22a3f
FIX
Oct 22, 2024
e0097e9
FIX
Oct 22, 2024
edbf1b1
FIX
Oct 22, 2024
9d7a802
FIX
Oct 22, 2024
68b64bc
Merge branch 'develop' into NEW---PDF-Pos-sign
BB2A-Anthony Nov 3, 2024
f747593
Merge branch 'develop' into NEW---PDF-Pos-sign
eldy Nov 6, 2024
1f0664d
Merge branch 'develop' into NEW---PDF-Pos-sign
eldy Nov 7, 2024
ab0c066
Merge branch 'develop' into NEW---PDF-Pos-sign
eldy Nov 7, 2024
0fda9d9
Merge branch 'develop' into NEW---PDF-Pos-sign
eldy Nov 12, 2024
ad7225c
Update pdf.lib.php
eldy Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Anthony Berton <anthony.berton@bb2a.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1621,7 +1622,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0)
$sql .= ", p.datep as dp";
$sql .= ", p.fin_validite as dfv";
$sql .= ", p.date_livraison as delivery_date";
$sql .= ", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
$sql .= ", p.model_pdf, p.last_main_doc, p.model_pdf_pos_sign, p.ref_client, ref_ext, p.extraparams";
$sql .= ", p.note_private, p.note_public";
$sql .= ", p.fk_projet as fk_project, p.fk_statut";
$sql .= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
Expand Down Expand Up @@ -1691,6 +1692,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0)

$this->model_pdf = $obj->model_pdf;
$this->last_main_doc = $obj->last_main_doc;
$this->model_pdf_pos_sign = $obj->model_pdf_pos_sign;
$this->note = $obj->note_private; // TODO deprecated
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
Expand Down
72 changes: 34 additions & 38 deletions htdocs/core/ajax/onlineSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
* Copyright (C) 2024 Anthony Berton <anthony.berton@bb2a.fr>

*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -92,6 +94,10 @@
httponly_accessforbidden('Bad value for securitykey. Value provided ' . dol_escape_htmltag($SECUREKEY) . ' does not match expected value for ref=' . dol_escape_htmltag($ref), 403);
}

$marginLeft=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:5;
$marginRight=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:5;
$marginTop =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:5;
$marginDown =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:5;
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
$hookmanager->initHooks(array('ajaxonlinesign'));

Expand Down Expand Up @@ -161,7 +167,6 @@
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}

if (empty($reshook)) {
// We build the new PDF
$pdf = pdf_getInstance();
Expand All @@ -170,6 +175,7 @@
$pdf->setPrintFooter(false);
}
$pdf->SetFont(pdf_getPDFFont($langs));
$pdf->SetMargins($marginLeft, $marginTop, $marginRight);

if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
$pdf->SetCompression(false);
Expand All @@ -178,9 +184,25 @@
//$pdf->Open();
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF

// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
$param = array();
$param['online_sign_name'] = $online_sign_name;
$param['pathtoimage'] = $upload_dir . $filename;
$param['specificpage'] = getDolGlobalInt("PROPAL_SIGNATURE_ON_SPECIFIC_PAGE");
$param['allpages'] = getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES");
$param['xforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_XFORIMGSTART");
$param['yforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_YFORIMGSTART");
$param['wforimg'] = getDolGlobalString("PROPAL_SIGNATURE_WFORIMG");

// Read pos sign in database
if (isset($object->model_pdf_pos_sign) && !empty($object->model_pdf_pos_sign)) {
$pos = explode(':', $object->model_pdf_pos_sign);
$param['specificpage'] = isset($pos[0]) ? $pos[0] : '';
$param['xforimgstart'] = isset($pos[1]) ? $pos[1] : ''; // Pos x to print sign
$param['yforimgstart'] = isset($pos[2]) ? $pos[2] : ''; // Pos y to print sign
$param['wforimg'] = isset($pos[3]) ? $pos[3] : ''; // Width image sign
$param['allpages'] = isset($pos[0]) && empty($pos[0]) ? 1 : 0;
}

$s = array(); // Array with size of each page. Example array(w'=>210, 'h'=>297);
for ($i = 1; $i < ($pagecount + 1); $i++) {
Expand All @@ -189,31 +211,18 @@
$s = $pdf->getTemplatesize($tppl);
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
$pdf->useTemplate($tppl);
$propalsignonspecificpage = getDolGlobalInt("PROPAL_SIGNATURE_ON_SPECIFIC_PAGE");
if ($propalsignonspecificpage < 0) {
$propalsignonspecificpage = $pagecount - abs($propalsignonspecificpage);
}

if (getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES") || $propalsignonspecificpage == $i) {
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
// TODO Get position of box from PDF template
if (empty($param['xforimgstart']) && empty($param['yforimgstart'])) {
$param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
$param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
$param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
}

if (getDolGlobalString("PROPAL_SIGNATURE_XFORIMGSTART")) {
$param['xforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_XFORIMGSTART");
} else {
$param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
}
if (getDolGlobalString("PROPAL_SIGNATURE_YFORIMGSTART")) {
$param['yforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_YFORIMGSTART");
} else {
$param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
}
if (getDolGlobalString("PROPAL_SIGNATURE_WFORIMG")) {
$param['wforimg'] = getDolGlobalString("PROPAL_SIGNATURE_WFORIMG");
} else {
$param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
}
if ($param['specificpage'] < 0) {
$param['specificpage'] = $pagecount - abs($param['specificpage']);
}

if (!empty($param['allpages']) || $param['specificpage'] == $i) {
dolPrintSignatureImage($pdf, $langs, $param);
}
} catch (Exception $e) {
Expand All @@ -223,23 +232,10 @@
}
}

if (!getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES") && !getDolGlobalInt("PROPAL_SIGNATURE_ON_SPECIFIC_PAGE")) {
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
// TODO Get position of box from PDF template

if (getDolGlobalString("PROPAL_SIGNATURE_XFORIMGSTART")) {
$param['xforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_XFORIMGSTART");
} else {
if (empty($param['allpages']) && empty($param['specificpage'])) {
if (empty($param['xforimgstart']) && empty($param['yforimgstart'])) {
$param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
}
if (getDolGlobalString("PROPAL_SIGNATURE_YFORIMGSTART")) {
$param['yforimgstart'] = getDolGlobalString("PROPAL_SIGNATURE_YFORIMGSTART");
} else {
$param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
}
if (getDolGlobalString("PROPAL_SIGNATURE_WFORIMG")) {
$param['wforimg'] = getDolGlobalString("PROPAL_SIGNATURE_WFORIMG");
} else {
$param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
}

Expand Down
46 changes: 45 additions & 1 deletion htdocs/core/lib/pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2019 Lenin Rivas <lenin.rivas@servcom-it.com>
* Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2021-2022 Anthony Berton <anthony.berton@bb2a.fr>
* Copyright (C) 2021-2024 Anthony Berton <anthony.berton@bb2a.fr>
* Copyright (C) 2023-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
Expand Down Expand Up @@ -2717,3 +2717,47 @@
}
return 0;
}

/**
* Define signing position
*
* @param float $p Number page to print sign
* @param float $x Posx to print sign
* @param float $y Posy to print sign
* @param float $width Width sign
* @return int Return <0 if KO, >0 if OK
*/
function pdf_setPosSign($p, $x, $y, $width)
{
global $conf, $db, $object;
$error = 0;

$db->begin();

$possign = $p.":".$x.":".$y.":".$width;

$sql = "UPDATE ".MAIN_DB_PREFIX.$object->element;
$sql .= " SET model_pdf_pos_sign = '".$possign."'";
$sql .= " WHERE rowid = ".((int) $object->id);

dol_syslog(__METHOD__, LOG_DEBUG);

Check warning on line 2743 in htdocs/core/lib/pdf.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

pdf.lib.php: PhanSuspiciousMagicConstant: Suspicious reference to magic constant __METHOD__: used inside of a function/closure instead of a method
$resql = $db->query($sql);

if (!$resql) {
$object->errors[] = $db->error();
$error++;
}

if (!$error) {
$db->commit();
return 1;
} else {
foreach ($object->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);

Check warning on line 2756 in htdocs/core/lib/pdf.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

pdf.lib.php: PhanSuspiciousMagicConstant: Suspicious reference to magic constant __METHOD__: used inside of a function/closure instead of a method
$object->error .= ($object->error ? ', '.$errmsg : $errmsg);
}
$db->rollback();
return -1 * $error;
}
return 0;

Check warning on line 2762 in htdocs/core/lib/pdf.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

pdf.lib.php: PhanPluginUnreachableCode: Unreachable statement detected

Check failure on line 2762 in htdocs/core/lib/pdf.lib.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Unreachable statement - code above always terminates.
}
5 changes: 5 additions & 0 deletions htdocs/core/modules/propale/doc/pdf_cyan.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Nick Fragoulis
* Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2024 Anthony Berton <anthony.berton@bb2a.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1905,6 +1906,8 @@ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
*/
protected function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
{
global $conf, $pagenb;

$default_font_size = pdf_getPDFFontSize($outputlangs);
$tab_top = $posy + 4;
$tab_hl = 4;
Expand All @@ -1917,6 +1920,8 @@ protected function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
$pdf->SetXY($posx, $tab_top);
$pdf->SetFont('', '', $default_font_size - 2);
$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
$pdf->SetXY($posx, $tab_top + $tab_hl);
pdf_setPosSign($pdf->PageNo(), $posx, $tab_top + $tab_hl, $largcol);

$pdf->SetXY($posx, $tab_top + $tab_hl + 3);
$pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
Expand Down
Loading