From 2668cb20cc9d556751560de82af3ab254538de79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 1 Oct 2016 20:45:50 +0200 Subject: [PATCH] Work on SEPA mandate --- htdocs/admin/bank.php | 220 +++++++++++++++++- htdocs/admin/commande.php | 4 +- htdocs/admin/prelevement.php | 196 +++++++++++++++- .../bank/doc/pdf_sepamandate.modules.php | 15 +- htdocs/langs/en_US/banks.lang | 2 + 5 files changed, 421 insertions(+), 16 deletions(-) diff --git a/htdocs/admin/bank.php b/htdocs/admin/bank.php index 8a5c60c8483..bccae5bbfaf 100644 --- a/htdocs/admin/bank.php +++ b/htdocs/admin/bank.php @@ -40,6 +40,7 @@ if (!$user->admin) accessforbidden(); $action = GETPOST('action','alpha'); +$type = 'bankaccount'; /* @@ -60,14 +61,82 @@ if ($action == 'setbankorder') } } + +if ($action == 'specimen') +{ + $modele=GETPOST('module','alpha'); + + $commande = new Commande($db); + $commande->initAsSpecimen(); + + // Search template files + $file=''; $classname=''; $filefound=0; + $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + foreach($dirmodels as $reldir) + { + $file=dol_buildpath($reldir."core/modules/paymentorders/doc/pdf_".$modele.".modules.php",0); + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + } + } + + if ($filefound) + { + require_once $file; + + $module = new $classname($db); + + if ($module->write_file($commande,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=paymentorders&file=SPECIMEN.pdf"); + return; + } + else + { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } + } + else + { + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } +} + +// Set default model +else if ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "PAYMENTORDER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + // The constant that was read before the new set + // We therefore requires a variable to have a coherent view + $conf->global->PAYMENTORDER_ADDON_PDF = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } +} + + + /* * view */ -llxHeader("",$langs->trans("BankSetupModule")); - $form=new Form($db); +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + +llxHeader("",$langs->trans("BankSetupModule")); + $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BankSetupModule"),$linkback,'title_setup'); @@ -79,7 +148,7 @@ $var=true; $var=! $var; //Show bank account order -print load_fiche_titre($langs->trans("BankOrderShow")); +print load_fiche_titre($langs->trans("BankOrderShow"), '', ''); print ''; print ''; @@ -137,6 +206,151 @@ while ($i < $nbofbank) print '
'."\n"; + +print '

'; + + +/* + * Document templates generators + */ +print load_fiche_titre($langs->trans("BankAccountModelModule"), '', ''); + +// Load array def with activated templates +$def = array(); +$sql = "SELECT nom"; +$sql .= " FROM " . MAIN_DB_PREFIX . "document_model"; +$sql .= " WHERE type = '" . $type . "'"; +$sql .= " AND entity = " . $conf->entity; +$resql = $db->query($sql); +if ($resql) { + $i = 0; + $num_rows = $db->num_rows($resql); + while ($i < $num_rows) { + $array = $db->fetch_array($resql); + array_push($def, $array[0]); + $i ++; + } +} else { + dol_print_error($db); +} + +print "\n"; +print "\n"; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var = true; +foreach ($dirmodels as $reldir) +{ + foreach (array('', '/doc') as $valdir) { + $dir = dol_buildpath($reldir . "core/modules/bank" . $valdir); + + if (is_dir($dir)) { + $handle = opendir($dir); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + $filelist[] = $file; + } + closedir($handle); + arsort($filelist); + + foreach ($filelist as $file) { + if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) { + + if (file_exists($dir . '/' . $file)) { + $name = substr($file, 4, dol_strlen($file) - 16); + $classname = substr($file, 0, dol_strlen($file) - 12); + + require_once $dir . '/' . $file; + $module = new $classname($db); + + $modulequalified = 1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) + $modulequalified = 0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) + $modulequalified = 0; + + if ($modulequalified) { + $var = ! $var; + print ''; + + // Active + if (in_array($name, $def)) { + print ''; + } else { + print '"; + } + + // Default + print ''; + + // Info + $htmltooltip = '' . $langs->trans("Name") . ': ' . $module->name; + $htmltooltip .= '
' . $langs->trans("Type") . ': ' . ($module->type ? $module->type : $langs->trans("Unknown")); + if ($module->type == 'pdf') { + $htmltooltip .= '
' . $langs->trans("Width") . '/' . $langs->trans("Height") . ': ' . $module->page_largeur . '/' . $module->page_hauteur; + } + $htmltooltip .= '

' . $langs->trans("FeaturesSupported") . ':'; + $htmltooltip .= '
' . $langs->trans("Logo") . ': ' . yn($module->option_logo, 1, 1); + $htmltooltip .= '
' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1); + $htmltooltip .= '
' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1); + $htmltooltip .= '
' . $langs->trans("MultiLanguage") . ': ' . yn($module->option_multilang, 1, 1); + // $htmltooltip.='
'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1); + // $htmltooltip.='
'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1); + $htmltooltip .= '
' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1); + + print ''; + + // Preview + print ''; + + print "\n"; + } + } + } + } + } + } + } +} + + + + dol_fiche_end(); llxFooter(); diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 2a1c4a1561d..c2f8cf2d4d6 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -273,12 +273,12 @@ else if ($action == 'set_WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER') * View */ +$form=new Form($db); + $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); llxHeader("",$langs->trans("OrdersSetup")); -$form=new Form($db); - $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("OrdersSetup"),$linkback,'title_setup'); diff --git a/htdocs/admin/prelevement.php b/htdocs/admin/prelevement.php index bece7e72d01..6d5c915dae2 100644 --- a/htdocs/admin/prelevement.php +++ b/htdocs/admin/prelevement.php @@ -36,6 +36,7 @@ $langs->load("withdrawals"); if (!$user->admin) accessforbidden(); $action = GETPOST('action','alpha'); +$type = 'paymentorder'; /* @@ -110,6 +111,7 @@ if ($action == "deletenotif") exit; } +/* if ($action == 'specimen') { $modele=GETPOST('module','alpha'); @@ -122,7 +124,7 @@ if ($action == 'specimen') $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); foreach($dirmodels as $reldir) { - $file=dol_buildpath($reldir."core/modules/commande/doc/pdf_".$modele.".modules.php",0); + $file=dol_buildpath($reldir."core/modules/paymentorders/doc/pdf_".$modele.".modules.php",0); if (file_exists($file)) { $filefound=1; @@ -139,7 +141,7 @@ if ($action == 'specimen') if ($module->write_file($commande,$langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf"); + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=paymentorders&file=SPECIMEN.pdf"); return; } else @@ -154,7 +156,26 @@ if ($action == 'specimen') dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } - + +// Set default model +else if ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "PAYMENTORDER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + // The constant that was read before the new set + // We therefore requires a variable to have a coherent view + $conf->global->PAYMENTORDER_ADDON_PDF = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } +} +*/ + /* * View @@ -162,6 +183,8 @@ if ($action == 'specimen') $form=new Form($db); +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + llxHeader('',$langs->trans("WithdrawalsSetup")); $linkback=''.$langs->trans("BackToModuleList").''; @@ -173,6 +196,7 @@ print ''; print ''; print '
' . $langs->trans("Name") . '' . $langs->trans("Description") . '' . $langs->trans("Status") . "' . $langs->trans("Default") . "' . $langs->trans("ShortInfo") . '' . $langs->trans("Preview") . '
'; + print(empty($module->name) ? $name : $module->name); + print "\n"; + if (method_exists($module, 'info')) + print $module->info($langs); + else + print $module->description; + print '' . "\n"; + print ''; + print img_picto($langs->trans("Enabled"), 'switch_on'); + print ''; + print '' . "\n"; + print '' . img_picto($langs->trans("Disabled"), 'switch_off') . ''; + print "'; + if ($conf->global->PAYMENTORDER_ADDON_PDF == $name) { + print img_picto($langs->trans("Default"), 'on'); + } else { + print '' . img_picto($langs->trans("Disabled"), 'off') . ''; + } + print ''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print ''; + if ($module->type == 'pdf') { + print '' . img_object($langs->trans("Preview"), 'bill') . ''; + } else { + print img_object($langs->trans("PreviewNotAvailable"), 'generic'); + } + print '
'; + print ''; print ''; print ''; @@ -204,6 +228,172 @@ print '
entity; +$resql=$db->query($sql); +if ($resql) +{ + $i = 0; + $num_rows=$db->num_rows($resql); + while ($i < $num_rows) + { + $array = $db->fetch_array($resql); + array_push($def, $array[0]); + $i++; + } +} +else +{ + dol_print_error($db); +} + + +print "
'.$langs->trans("Parameter").''.$langs->trans("Value").'
\n"; +print "\n"; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var=true; +foreach ($dirmodels as $reldir) +{ + foreach (array('','/doc') as $valdir) + { + $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir); + + if (is_dir($dir)) + { + $handle=opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + $filelist[]=$file; + } + closedir($handle); + arsort($filelist); + + foreach($filelist as $file) + { + if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + { + + if (file_exists($dir.'/'.$file)) + { + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); + + require_once $dir.'/'.$file; + $module = new $classname($db); + + $modulequalified=1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + + if ($modulequalified) + { + $var = !$var; + print ''; + + // Active + if (in_array($name, $def)) + { + print ''; + } + else + { + print '"; + } + + // Default + print ''; + + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + if ($module->type == 'pdf') + { + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + } + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + //$htmltooltip.='
'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1); + //$htmltooltip.='
'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1); + $htmltooltip.='
'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1); + + + print ''; + + // Preview + print ''; + + print "\n"; + } + } + } + } + } + } + } +} + +*/ + + dol_fiche_end(); print '
'; diff --git a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php index fac7ef1a9d5..111b426267b 100644 --- a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php +++ b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php @@ -22,9 +22,8 @@ * \brief File of class to generate document with template sepamandate */ -require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; -require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; -require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -48,11 +47,11 @@ class pdf_sepamandate extends ModeleBankAccountDoc global $conf,$langs,$mysoc; $langs->load("main"); - $langs->load("projects"); + $langs->load("bank"); $langs->load("companies"); $this->db = $db; - $this->name = "baleine"; + $this->name = "sepamandate"; $this->description = $langs->trans("DocumentModelSepaMandate"); // Dimension page pour format A4 @@ -104,12 +103,12 @@ class pdf_sepamandate extends ModeleBankAccountDoc $outputlangs->load("companies"); $outputlangs->load("projects"); - if ($conf->projet->dir_output) + if ($conf->bank->dir_output) { //$nblignes = count($object->lines); // This is set later with array of tasks $objectref = dol_sanitizeFileName($object->ref); - $dir = $conf->projet->dir_output; + $dir = $conf->bank->dir_output; if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; @@ -489,7 +488,7 @@ class pdf_sepamandate extends ModeleBankAccountDoc { global $conf; $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; - return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); + return pdf_pagefoot($pdf,$outputlangs,'PAYMENTORDER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } } diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index b0b7af4076f..8a6a6aaeeac 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -144,3 +144,5 @@ ConfirmRejectCheck=Are you sure you want to mark this check as rejected ? RejectCheckDate=Date the check was returned CheckRejected=Check returned CheckRejectedAndInvoicesReopened=Check returned and invoices reopened +BankAccountModelModule=Document templates for bank accounts +DocumentModelSepaMandate=Template of SEPA mandate. Usefull for european countries in EEC only. \ No newline at end of file
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Status")."'.$langs->trans("Default")."'.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
'; + print (empty($module->name)?$name:$module->name); + print "\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print ''."\n"; + print ''; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print ''."\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print "'; + if ($conf->global->PAYMENTORDER_ADDON_PDF == $name) + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + if ($module->type == 'pdf') + { + print ''.img_object($langs->trans("Preview"),'bill').''; + } + else + { + print img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print '