diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index 825b54ab721..86ef0f3c29d 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -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(); } diff --git a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php index e7c022e315f..42d3454fdf7 100644 --- a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php +++ b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php @@ -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; diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql index 1972b39eae7..66962b8e141 100644 --- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql +++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_societe_rib.sql b/htdocs/install/mysql/tables/llx_societe_rib.sql index 380c6dba855..f5bd83d9939 100644 --- a/htdocs/install/mysql/tables/llx_societe_rib.sql +++ b/htdocs/install/mysql/tables/llx_societe_rib.sql @@ -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 diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index d2dee3f4657..a01725567c0 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -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 \ No newline at end of file +UsedFor=Used for %s +Societe_ribSigned=SEPA mandat Signed diff --git a/htdocs/langs/fr_FR/withdrawals.lang b/htdocs/langs/fr_FR/withdrawals.lang index 6620cea6f07..659f3b1ad28 100644 --- a/htdocs/langs/fr_FR/withdrawals.lang +++ b/htdocs/langs/fr_FR/withdrawals.lang @@ -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é diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index 57da5697dbe..70c32372973 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -529,7 +529,7 @@ if ($source == 'proposal') { print ''."\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 diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index b04ec6fc152..11c451ab84c 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -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);