Merge pull request #1197 from grandoc/develop

some fix for contract model and clean code
This commit is contained in:
Laurent Destailleur 2013-08-26 14:10:08 -07:00
commit 83c3bde1bd
7 changed files with 192 additions and 185 deletions

View File

@ -190,23 +190,6 @@ else if ($action == 'set_CONTRAT_DRAFT_WATERMARK')
} }
} }
elseif ($action == 'set_CONTRAT_PRINT_PRODUCTS')
{
$val = GETPOST('CONTRAT_PRINT_PRODUCTS','alpha');
$res = dolibarr_set_const($db, "CONTRAT_PRINT_PRODUCTS",($val == 'on'),'bool',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
setEventMessage($langs->trans("SetupSaved"));
}
else
{
setEventMessage($langs->trans("Error"),'errors');
}
}
/* /*
* View * View
*/ */
@ -215,7 +198,6 @@ $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
llxHeader(); llxHeader();
$dir=DOL_DOCUMENT_ROOT."/core/modules/contract/";
$form=new Form($db); $form=new Form($db);
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
@ -244,84 +226,90 @@ print "</tr>\n";
clearstatcache(); clearstatcache();
$dir = "../core/modules/contract/"; foreach ($dirmodels as $reldir)
$handle = opendir($dir);
if (is_resource($handle))
{ {
$var=true; $dir = dol_buildpath($reldir."core/modules/contract/");
while (($file = readdir($handle))!==false) if (is_dir($dir))
{ {
if (substr($file, 0, 13) == 'mod_contract_' && substr($file, dol_strlen($file)-3, 3) == 'php') $handle = opendir($dir);
{ if (is_resource($handle))
$file = substr($file, 0, dol_strlen($file)-4); {
$var=true;
require_once DOL_DOCUMENT_ROOT ."/core/modules/contract/".$file.'.php'; while (($file = readdir($handle))!==false)
{
if (substr($file, 0, 13) == 'mod_contract_' && substr($file, dol_strlen($file)-3, 3) == 'php')
{
$file = substr($file, 0, dol_strlen($file)-4);
$module = new $file; require_once $dir.$file.'.php';
// Show modules according to features level $module = new $file($db);
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
if ($module->isEnabled()) // Show modules according to features level
{ if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
$var=!$var; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td>\n";
print '<td>';
print $module->info();
print '</td>';
// Show example of numbering model if ($module->isEnabled())
print '<td class="nowrap">'; {
$tmp=$module->getExample(); $var=!$var;
if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; } print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
elseif ($tmp=='NotConfigured') print $langs->trans($tmp); print $module->info();
else print $tmp; print '</td>';
print '</td>'."\n";
print '<td align="center">'; // Show example of numbering model
if ($conf->global->CONTRACT_ADDON == "$file") print '<td class="nowrap">';
{ $tmp=$module->getExample();
print img_picto($langs->trans("Activated"),'switch_on'); if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
} elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
else else print $tmp;
{ print '</td>'."\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a>';
}
print '</td>';
$contract=new Contrat($db); print '<td align="center">';
$contract->initAsSpecimen(); if ($conf->global->CONTRACT_ADDON == "$file")
{
print img_picto($langs->trans("Activated"),'switch_on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a>';
}
print '</td>';
// Info $contract=new Contrat($db);
$htmltooltip=''; $contract->initAsSpecimen();
$htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$nextval=$module->getNextValue($mysoc,$contract);
if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
{
$htmltooltip.=''.$langs->trans("NextValue").': ';
if ($nextval)
{
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '<td align="center">'; // Info
print $form->textwithpicto('',$htmltooltip,1,0); $htmltooltip='';
print '</td>'; $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$nextval=$module->getNextValue($mysoc,$contract);
if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
{
$htmltooltip.=''.$langs->trans("NextValue").': ';
if ($nextval)
{
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '</tr>'; print '<td align="center">';
} print $form->textwithpicto('',$htmltooltip,1,0);
} print '</td>';
}
closedir($handle); print '</tr>';
}
}
}
closedir($handle);
}
}
} }
print '</table><br>'; print '</table><br>';
@ -372,84 +360,116 @@ clearstatcache();
$var=true; $var=true;
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir)
{ {
$dir = dol_buildpath($reldir."core/modules/contract/doc/"); foreach (array('','/doc') as $valdir)
{
$dir = dol_buildpath($reldir."core/modules/contract".$valdir);
if (is_dir($dir)) if (is_dir($dir))
{ {
$handle=opendir($dir); $handle=opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_') $filelist[]=$file;
{ }
$name = substr($file, 4, dol_strlen($file) -16); closedir($handle);
$classname = substr($file, 0, dol_strlen($file) -12); arsort($filelist);
$var=!$var; foreach($filelist as $file)
{
if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
{
print '<tr '.$bc[$var].'><td>'; if (file_exists($dir.'/'.$file))
echo "$name"; {
print "</td><td>\n"; $name = substr($file, 4, dol_strlen($file) -16);
require_once $dir.$file; $classname = substr($file, 0, dol_strlen($file) -12);
$module = new $classname($db);
print $module->description;
print '</td>';
// Active require_once $dir.'/'.$file;
if (in_array($name, $def)) $module = new $classname($db);
{
print "<td align=\"center\">\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("Enabled"),'switch_on');
print '</a>';
print "</td>";
}
else
{
print "<td align=\"center\">\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
print "</td>";
}
// Default $modulequalified=1;
print "<td align=\"center\">"; if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
if ($conf->global->CONTRACT_ADDON_PDF == "$name") if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
{
print img_picto($langs->trans("Default"),'on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
print '</td>';
// Info if ($modulequalified)
$htmltooltip = ''.$langs->trans("Name").': '.$module->name; {
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); $var = !$var;
$htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; print '<tr '.$bc[$var].'><td width="100">';
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; print (empty($module->name)?$name:$module->name);
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); print "</td><td>\n";
$htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); if (method_exists($module,'info')) print $module->info($langs);
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); else print $module->description;
$htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); print '</td>';
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,-1,0);
print '</td>';
// Preview // Active
$link='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>'; if (in_array($name, $def))
print '<td align="center">'; {
print $link; print '<td align="center">'."\n";
print '</td>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
print img_picto($langs->trans("Enabled"),'switch_on');
print '</a>';
print '</td>';
}
else
{
print '<td align="center">'."\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
print "</td>";
}
print '</tr>'; // Defaut
} print '<td align="center">';
} if ($conf->global->CONTRACT_ADDON_PDF == $name)
closedir($handle); {
} print img_picto($langs->trans("Default"),'on');
} }
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
print '</td>';
// Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
if ($module->type == 'pdf')
{
$htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
}
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
$htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>';
// Preview
print '<td align="center">';
if ($module->type == 'pdf')
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
}
else
{
print img_object($langs->trans("PreviewNotAvailable"),'generic');
}
print '</td>';
print "</tr>\n";
}
}
}
}
}
}
}
} }
print '</table>'; print '</table>';
@ -492,25 +512,8 @@ print '<input size="50" class="flat" type="text" name="CONTRAT_DRAFT_WATERMARK"
print '</td><td align="right">'; print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print "</td></tr>\n"; print "</td></tr>\n";
// print products on fichinter
$var=! $var;
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_CONTRAT_PRINT_PRODUCTS">';
print '<tr '.$bc[$var].'><td>';
print $langs->trans("PrintProductsOnContract").' ('.$langs->trans("PrintProductsOnContractDetails").')</td>';
print '<td align="center"><input type="checkbox" name="CONTRAT_PRINT_PRODUCTS" ';
if ($conf->global->CONTRAT_PRINT_PRODUCTS)
print 'checked="checked" ';
print '/>';
print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print "</td></tr>\n";
print '</form>'; print '</form>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@ -88,7 +88,7 @@ class Contrat extends CommonObject
function getNextNumRef($soc) function getNextNumRef($soc)
{ {
global $db, $langs, $conf; global $db, $langs, $conf;
$langs->load("contract"); $langs->load("contracts");
$dir = DOL_DOCUMENT_ROOT . "/core/modules/contract"; $dir = DOL_DOCUMENT_ROOT . "/core/modules/contract";

View File

@ -154,10 +154,10 @@ class ModelNumRefContracts
* @param int $hideref Hide ref * @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK * @return int 0 if KO, 1 if OK
*/ */
function contract_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) function contract_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{ {
global $conf,$langs,$user; global $conf,$langs,$user,$hookmanager;
$langs->load("contract"); $langs->load("contracts");
$error=0; $error=0;
@ -224,6 +224,9 @@ function contract_create($db, $object, $modele, $outputlangs, $hidedetails=0, $h
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($object); dol_delete_preview($object);
// Success in building document. We build meta file.
dol_meta_create($object);
// Appel des triggers // Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db); $interface=new Interfaces($db);

View File

@ -57,7 +57,7 @@ class modContrat extends DolibarrModules
$this->picto='contract'; $this->picto='contract';
// Data directories to create when module is enabled // Data directories to create when module is enabled
$this->dirs = array("/contracts/temp"); $this->dirs = array("/contract/temp");
// Dependances // Dependances
$this->depends = array("modSociete","modService"); $this->depends = array("modSociete","modService");

View File

@ -90,6 +90,7 @@ ListOfServicesToExpireWithDuration=Liste des services actifs expirant dans %s jo
ListOfServicesToExpireWithDurationNeg=Liste des services actifs expiré depuis plus de %s jours ListOfServicesToExpireWithDurationNeg=Liste des services actifs expiré depuis plus de %s jours
ListOfServicesToExpire=Liste des services actifs en expiration ListOfServicesToExpire=Liste des services actifs en expiration
NoteListOfYourExpiredServices=Cette list ne contient que les contrats de services des tiers pour lesquels vous êtes liés comme représentant commercial. NoteListOfYourExpiredServices=Cette list ne contient que les contrats de services des tiers pour lesquels vous êtes liés comme représentant commercial.
DocumentModelStandard=Modèle de contrat standard
##### Types de contacts ##### ##### Types de contacts #####
TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat