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 10 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
4 changes: 3 additions & 1 deletion htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class Propal extends CommonObject
'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountVAT', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>250, 'isameasure'=>1),
'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountTTC', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>255, 'isameasure'=>1),
'last_main_doc' =>array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>1, 'visible'=>-1, 'position'=>260),
'model_pdf_pos_sign' =>array('type'=>'varchar(10)', 'label'=>'PDFPosSign', 'enabled'=>1, 'visible'=>0, 'position'=>261),
BB2A-Anthony marked this conversation as resolved.
Show resolved Hide resolved
'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Status', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>900),
);
Expand Down Expand Up @@ -1546,7 +1547,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 @@ -1619,6 +1620,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0)
$this->model_pdf = $obj->model_pdf;
$this->modelpdf = $obj->model_pdf; // deprecated
$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
54 changes: 39 additions & 15 deletions htdocs/core/ajax/onlineSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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;

/*
* Actions
Expand Down Expand Up @@ -151,35 +155,55 @@

//$pdf->Open();
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF
$pdf->SetMargins($marginLeft, $marginTop, $marginRight);
$pdf->SetAutoPageBreak(1, 0);

// Retrieve information on the position of the signature
$pos = array();
$possign = array();
$s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
$pforimg = $pagecount; // Page number to print sign if not difini last page

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

for ($i=1; $i<($pagecount+1); $i++) {
try {
$tppl = $pdf->importPage($i);
$s = $pdf->getTemplatesize($tppl);
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
$pdf->useTemplate($tppl);

if ($i==$pforimg) {
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
if (empty($pos)) {
$xforimgstart = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
$yforimgstart = (empty($s['h']) ? 240 : $s['h'] - 60);
$wforimg = $s['w'] - 20 - $xforimgstart;
$hforimg = round($wforimg / 4);
}

$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4) - 4);
$pdf->SetFont($default_font, '', $default_font_size - 1);
$pdf->MultiCell($wforimg, 4, $langs->trans("DateSigning").': '.dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname").': '.$online_sign_name, 0, 'L');

$pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, $hforimg);
}
} catch (Exception $e) {
dol_syslog("Error when manipulating the PDF ".$sourcefile." by onlineSign: ".$e->getMessage(), LOG_ERR);
$response = $e->getMessage();
$error++;
}
}

// 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
$xforimgstart = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
$yforimgstart = (empty($s['h']) ? 240 : $s['h'] - 60);
$wforimg = $s['w'] - 20 - $xforimgstart;

$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4) - 4);
$pdf->SetFont($default_font, '', $default_font_size - 1);
$pdf->MultiCell($wforimg, 4, $langs->trans("DateSigning").': '.dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname").': '.$online_sign_name, 0, 'L');

$pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));

//$pdf->Close();
$pdf->Output($newpdffilename, "F");

Expand Down Expand Up @@ -318,7 +342,7 @@
$wforimg = $s['w']/2 - $xforimgstart;

$pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
//$pdf->Close();
//$pdf->Close();require_once
$pdf->Output($newpdffilename, "F");

// Index the new file and update the last_main_doc property of object.
Expand Down
43 changes: 43 additions & 0 deletions htdocs/core/lib/pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2574,3 +2574,46 @@ function pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails =
}
return '';
}

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

$db->begin();

$sql = "UPDATE ".MAIN_DB_PREFIX.$object->element;
$sql .= " SET model_pdf_pos_sign = '".$p.":".$x.":".$y.":".$height.":".$width."'";
$sql .= " WHERE rowid = ".((int) $object->id);

dol_syslog(__METHOD__, LOG_DEBUG);
$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);
$object->error .= ($object->error ? ', '.$errmsg : $errmsg);
}
$db->rollback();
return -1 * $error;
}
return 0;
}
4 changes: 2 additions & 2 deletions htdocs/core/modules/propale/doc/pdf_cyan.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
*/
protected function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
{
global $conf;
global $conf, $pagenb;
$default_font_size = pdf_getPDFFontSize($outputlangs);
$tab_top = $posy + 4;
$tab_hl = 4;
Expand All @@ -1856,8 +1856,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, $tab_hl * 3, $largcol);
$pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
Expand Down
3 changes: 3 additions & 0 deletions htdocs/install/mysql/migration/17.0.0-18.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ ALTER TABLE llx_bank_account ADD COLUMN owner_country_id integer DEFAULT NULL;

ALTER TABLE llx_prelevement_bons ADD COLUMN fk_bank_account integer DEFAULT NULL;

ALTER TABLE llx_propal ADD COLUMN model_pdf_pos_sign VARCHAR(10) DEFAULT NULL AFTER last_main_doc;


ALTER TABLE llx_supplier_proposal ADD UNIQUE INDEX uk_supplier_proposal_ref (ref, entity);

ALTER TABLE llx_supplier_proposal ADD INDEX idx_supplier_proposal_fk_soc (fk_soc);
Expand Down
3 changes: 2 additions & 1 deletion htdocs/install/mysql/tables/llx_propal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ create table llx_propal

model_pdf varchar(255), -- last template used to generate main document
last_main_doc varchar(255), -- relative filepath+filename of last main generated document

model_pdf_pos_sign varchar(10),

date_livraison date DEFAULT NULL, -- delivery date
fk_shipping_method integer, -- shipping method id
fk_warehouse integer DEFAULT NULL, -- warehouse id
Expand Down