feat: RIB Online Sign

This commit is contained in:
Florian HENRY 2023-05-05 11:48:24 +02:00
parent 93255a0250
commit ce2b2f345f
8 changed files with 84 additions and 26 deletions

View file

@ -426,6 +426,7 @@ if ($action == "importSignature") {
$langs->load('withdrawals');
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
$modelpath = "core/modules/bank/doc/";
$object = new CompanyBankAccount($db);
$object->fetch($ref);
if (!empty($object->id)) {
@ -459,12 +460,16 @@ if ($action == "importSignature") {
if (!$error) {
// Defined modele of doc
$last_main_doc_file = $object->last_main_doc;
$last_modelpdf = $object->model_pdf;
$directdownloadlink = $object->getLastMainDocLink('company'); // url to download the $object->last_main_doc
if (preg_match('/\.pdf/i', $last_main_doc_file)) {
$newpdffilename = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . "_signed-" . $date . ".pdf";
$sourcefile = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref). "-" . dol_sanitizeFileName($object->rum) . ".pdf";
$sourcefile = '';
$newpdffilename = '';
if ($last_modelpdf == 'sepamandate') {
$newpdffilename = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . "_signed-" . $date . ".pdf";
$sourcefile = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . ".pdf";
}
if (dol_is_file($sourcefile)) {
// We build the new PDF
$pdf = pdf_getInstance();
@ -495,23 +500,58 @@ if ($action == "importSignature") {
}
}
// 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, dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
// Get position of box from PDF template
$file = '';
$classname = '';
$filefound = '';
$dirmodels = array('/');
if (is_array($conf->modules_parts['models'])) {
$dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
}
foreach ($dirmodels as $reldir) {
$file = "pdf_" . $last_modelpdf . ".modules.php";
// On vérifie l'emplacement du modele
$file = dol_buildpath($reldir . $modelpath . $file, 0);
if (file_exists($file)) {
$filefound = $file;
$classname = 'pdf_' . $last_modelpdf;
break;
}
if ($filefound) {
break;
}
}
if (!$filefound) {
$response = $langs->trans("Error") . ' Failed to load doc generator with modelpaths=' . $modelpath . ' - modele=' . $last_modelpdf;
dol_syslog($response, LOG_ERR);
$error++;
}
if (!$error) {
// If PDF template class was found
require_once $file;
$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname") . ': ' . $online_sign_name, 0, 'L');
$objPDF = new $classname($db);
$pdf->Image($upload_dir . $filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
$pdf->SetFont($default_font, '', $default_font_size - 1);
$xForDate = $objPDF->marge_gauche;
$yForDate = $objPDF->page_hauteur - $objPDF->heightforinfotot - $objPDF->heightforfreetext - $objPDF->heightforfooter + 10;
$pdf->SetXY($xForDate, $yForDate);
$pdf->MultiCell(100, 4, dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
$xforimgstart = $objPDF->xPosSignArea;
$yforimgstart = $yForDate - 5;
$wforimg = $s['w'] - 20 - $xforimgstart;
$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname") . ': ' . $online_sign_name, 0, 'L');
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
$pdf->Image($upload_dir . $filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
}
//$pdf->Close();
$pdf->Output($newpdffilename, "F");
@ -543,6 +583,8 @@ if ($action == "importSignature") {
if ($online_sign_name) {
$sql .= ", online_sign_name = '" . $db->escape($online_sign_name) . "'";
}
//$sql .= ", last_main_doc = '" . $db->escape($object->element'..') . "'";
$sql .= " WHERE rowid = " . ((int) $object->id);
dol_syslog(__METHOD__, LOG_DEBUG);
@ -563,7 +605,7 @@ if ($action == "importSignature") {
if (!$error) {
$db->commit();
$response = "success";
setEventMessages("PropalSigned", null, 'warnings');
setEventMessages(dol_ucfirst($mode)."Signed", null, 'warnings');
} else {
$db->rollback();
}

View file

@ -51,17 +51,22 @@ class pdf_sepamandate extends ModeleBankAccountDoc
/**
* @var int Height reserved to output the info and total part
*/
private $heightforinfotot;
public $heightforinfotot;
/**
* @var int Height reserved to output the free text on last page
*/
private $heightforfreetext;
public $heightforfreetext;
/**
* @var int Height reserved to output the footer (value include bottom margin)
*/
private $heightforfooter;
public $heightforfooter;
/**
* @var int x coordinate reserved to output the Signature area
*/
public $xPosSignArea;
/**
* Constructor
*
@ -105,6 +110,8 @@ class pdf_sepamandate extends ModeleBankAccountDoc
$this->heightforinfotot=50;
$this->xPosSignArea=120;
$this->heightforfreetext = (!empty(getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT')) ? getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT') : 5);
$this->heightforfooter = $this->marge_basse + 8;
@ -551,7 +558,7 @@ class pdf_sepamandate extends ModeleBankAccountDoc
$pdf->MultiCell(100, 3, ' ');
$pdf->MultiCell(100, 3, '______________________', 0, 'L', 0);
$posx = 120;
$posx = $this->xPosSignArea;
$largcol = ($this->page_largeur - $this->marge_droite - $posx);
$useborder = 0;
$index = 0;

View file

@ -411,7 +411,8 @@ CREATE TABLE llx_c_invoice_subtype (
ALTER TABLE llx_c_invoice_subtype ADD UNIQUE INDEX uk_c_invoice_subtype (entity, code);
ALTER TABLE llx_societe_rib ADD COLUMN last_main_doc varchar(255) AFTER currency_code;
ALTER TABLE llx_societe_rib ADD COLUMN model_pdf varchar(255) AFTER currency_code;
ALTER TABLE llx_societe_rib ADD COLUMN last_main_doc varchar(255) AFTER model_pdf;
ALTER TABLE llx_societe_rib ADD COLUMN date_signature datetime AFTER stripe_account;
ALTER TABLE llx_societe_rib ADD COLUMN online_sign_ip varchar(48) AFTER date_signature;
ALTER TABLE llx_societe_rib ADD COLUMN online_sign_name varchar(64) AFTER online_sign_ip;

View file

@ -47,6 +47,7 @@ create table llx_societe_rib
fk_country integer,
currency_code varchar(3),
model_pdf varchar(255), -- last template used to generate main document
last_main_doc varchar(255), -- relative filepath+filename of last main generated document
-- For BAN direct debit feature

View file

@ -160,4 +160,5 @@ ErrorICSmissing=Missing ICS in Bank account %s
TotalAmountOfdirectDebitOrderDiffersFromSumOfLines=Total amount of direct debit order differs from sum of lines
WarningSomeDirectDebitOrdersAlreadyExists=Warning: There is already some pending Direct Debit orders (%s) requested for an amount of %s
WarningSomeCreditTransferAlreadyExists=Warning: There is already some pending Credit Transfer (%s) requested for an amount of %s
UsedFor=Used for %s
UsedFor=Used for %s
Societe_ribSigned=SEPA mandat Signed

View file

@ -161,3 +161,4 @@ TotalAmountOfdirectDebitOrderDiffersFromSumOfLines=Le montant total de l'ordre d
WarningSomeDirectDebitOrdersAlreadyExists=Attention : Il y a déjà des ordres de prélèvement automatique en attente (%s) demandés pour un montant de %s
WarningSomeCreditTransferAlreadyExists=Attention : Il y a déjà des virements en attente (%s) demandés pour un montant de %s
UsedFor=Utilisé pour %s
Societe_ribSigned=SEPA mandat signé

View file

@ -529,7 +529,7 @@ if ($source == 'proposal') {
print '</td></tr>'."\n";
} elseif ($source == 'societe_rib') {
$found = true;
$langs->loadLangs(array("companies", "commercial"));
$langs->loadLangs(array("companies", "commercial", "withdrawals"));
$result = $object->fetch_thirdparty();
@ -556,13 +556,16 @@ if ($source == 'proposal') {
$last_main_doc_file = $object->last_main_doc;
$diroutput = $conf->societe->multidir_output[$object->thirdparty->entity].'/'
.dol_sanitizeFileName($object->thirdparty->id).'/';
if (empty($last_main_doc_file) ||
if ((empty($last_main_doc_file) ||
!dol_is_file($diroutput
.$langs->transnoentitiesnoconv("SepaMandateShort").' '.$object->id."-".dol_sanitizeFileName($object->rum).".pdf")) {
.$langs->transnoentitiesnoconv("SepaMandateShort").' '.$object->id."-".dol_sanitizeFileName($object->rum).".pdf"))
&& $message != "signed") {
// It seems document has never been generated, or was generated and then deleted.
// So we try to regenerate it with its default template.
$defaulttemplate = 'sepamandate';
//$defaulttemplate = 'sepamandate';
$defaulttemplate = getDolGlobalString("BANKADDON_PDF");
$object->setDocModel($user, $defaulttemplate);
$moreparams = array(
'use_companybankid'=>$object->id,
'force_dir_output'=>$diroutput

View file

@ -283,7 +283,7 @@ class CompanyBankAccount extends Account
$sql .= ", model_pdf";
$sql .= ")";
$sql .= " VALUES (".((int) $this->socid).", '".$this->type."', '".$this->db->idate($this->datec)."'";
$sql .= "\"".getDolGlobalString()."\"";
$sql .= ",\"".$this->db->escape(getDolGlobalString("BANKADDON_PDF"))."\"";
$sql .= ")";
$resql = $this->db->query($sql);
if ($resql) {
@ -419,6 +419,7 @@ class CompanyBankAccount extends Account
$sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum,";
$sql .= " stripe_card_ref, stripe_account";
$sql .= " ,last_main_doc";
$sql .= " ,model_pdf";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
if ($id) {
$sql .= " WHERE rowid = ".((int) $id);
@ -462,6 +463,7 @@ class CompanyBankAccount extends Account
$this->stripe_card_ref = $obj->stripe_card_ref;
$this->stripe_account = $obj->stripe_account;
$this->last_main_doc = $obj->last_main_doc;
$this->model_pdf = $obj->model_pdf;
}
$this->db->free($resql);