Normalize code

This commit is contained in:
Laurent Destailleur 2012-02-11 20:30:16 +01:00
parent f161d185b3
commit 2fd870d987
2 changed files with 141 additions and 90 deletions

View File

@ -29,7 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php");
$langs->load("compta"); $langs->load("compta");
$langs->load("bills"); $langs->load("bills");
$chid=GETPOST("id"); $id=GETPOST("id");
$action=GETPOST("action"); $action=GETPOST("action");
// Security check // Security check
@ -53,7 +53,7 @@ $result = restrictedArea($user, 'tax', $langs->trans("SocialContribution"), '',
if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes') if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
{ {
$chargesociales = new ChargeSociales($db); $chargesociales = new ChargeSociales($db);
$chargesociales->fetch($chid); $chargesociales->fetch($id);
$result = $chargesociales->set_paid($user); $result = $chargesociales->set_paid($user);
} }
@ -63,7 +63,7 @@ if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes') if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{ {
$chargesociales=new ChargeSociales($db); $chargesociales=new ChargeSociales($db);
$chargesociales->fetch($chid); $chargesociales->fetch($id);
$result=$chargesociales->delete($user); $result=$chargesociales->delete($user);
if ($result > 0) if ($result > 0)
{ {
@ -115,8 +115,8 @@ if ($action == 'add' && $user->rights->tax->charges->creer)
$chargesociales->periode=$dateperiod; $chargesociales->periode=$dateperiod;
$chargesociales->amount=$_POST["amount"]; $chargesociales->amount=$_POST["amount"];
$chid=$chargesociales->create($user); $id=$chargesociales->create($user);
if ($chid > 0) if ($id > 0)
{ {
//$mesg='<div class="ok">'.$langs->trans("SocialContributionAdded").'</div>'; //$mesg='<div class="ok">'.$langs->trans("SocialContributionAdded").'</div>';
} }
@ -243,16 +243,16 @@ if ($action == 'create')
/* Mode fiche */ /* Mode fiche */
/* */ /* */
/* *************************************************************************** */ /* *************************************************************************** */
if ($chid > 0) if ($id > 0)
{ {
$cha = new ChargeSociales($db); $object = new ChargeSociales($db);
$result=$cha->fetch($chid); $result=$object->fetch($id);
if ($result > 0) if ($result > 0)
{ {
dol_htmloutput_mesg($mesg); dol_htmloutput_mesg($mesg);
$head=tax_prepare_head($cha); $head=tax_prepare_head($object);
print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill'); print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill');
@ -260,53 +260,53 @@ if ($chid > 0)
if ($action == 'paid') if ($action == 'paid')
{ {
$text=$langs->trans('ConfirmPaySocialContribution'); $text=$langs->trans('ConfirmPaySocialContribution');
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$cha->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2);
} }
if ($action == 'delete') if ($action == 'delete')
{ {
$text=$langs->trans('ConfirmDeleteSocialContribution'); $text=$langs->trans('ConfirmDeleteSocialContribution');
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2);
} }
if ($action == 'edit') if ($action == 'edit')
{ {
print "<form name=\"charge\" action=\"charges.php?id=$cha->id&amp;action=update\" method=\"post\">"; print "<form name=\"charge\" action=\"charges.php?id=$object->id&amp;action=update\" method=\"post\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
print "<tr><td>".$langs->trans("Ref").'</td><td colspan="2">'; print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="2">';
print $form->showrefnav($cha,'id'); print $form->showrefnav($object,'id');
print "</td></tr>"; print "</td></tr>";
// Label // Label
if ($action == 'edit') if ($action == 'edit')
{ {
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">';
print '<input type="text" name="label" size="40" value="'.$cha->lib.'">'; print '<input type="text" name="label" size="40" value="'.$object->lib.'">';
print '</td></tr>'; print '</td></tr>';
} }
else else
{ {
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$cha->lib.'</td></tr>'; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->lib.'</td></tr>';
} }
// Type // Type
print "<tr><td>".$langs->trans("Type")."</td><td>".$cha->type_libelle."</td><td>".$langs->trans("Payments")."</td></tr>"; print "<tr><td>".$langs->trans("Type")."</td><td>".$object->type_libelle."</td><td>".$langs->trans("Payments")."</td></tr>";
// Period end date // Period end date
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>"; print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
print "<td>"; print "<td>";
if ($action == 'edit') if ($action == 'edit')
{ {
print $form->select_date($cha->periode, 'period', 0, 0, 0, 'charge', 1); print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1);
} }
else else
{ {
print dol_print_date($cha->periode,"day"); print dol_print_date($object->periode,"day");
} }
print "</td>"; print "</td>";
@ -321,7 +321,7 @@ if ($chid > 0)
$sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
$sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
$sql.= " WHERE p.fk_charge = ".$chid; $sql.= " WHERE p.fk_charge = ".$id;
$sql.= " AND p.fk_charge = cs.rowid"; $sql.= " AND p.fk_charge = cs.rowid";
$sql.= " AND cs.entity = ".$conf->entity; $sql.= " AND cs.entity = ".$conf->entity;
$sql.= " AND p.fk_typepaiement = c.id"; $sql.= " AND p.fk_typepaiement = c.id";
@ -353,12 +353,12 @@ if ($chid > 0)
$i++; $i++;
} }
if ($cha->paye == 0) if ($object->paye == 0)
{ {
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaye)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaye)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($cha->amount)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->amount)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
$resteapayer = $cha->amount - $totalpaye; $resteapayer = $object->amount - $totalpaye;
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>"; print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
@ -378,18 +378,18 @@ if ($chid > 0)
if ($action == 'edit') if ($action == 'edit')
{ {
print '<tr><td>'.$langs->trans("DateDue")."</td><td>"; print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
print $form->select_date($cha->date_ech, 'ech', 0, 0, 0, 'charge', 1); print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
print "</td></tr>"; print "</td></tr>";
} }
else { else {
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($cha->date_ech,'day')."</td></tr>"; print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($object->date_ech,'day')."</td></tr>";
} }
// Amount // Amount
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($cha->amount).'</td></tr>'; print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount).'</td></tr>';
// Status // Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$cha->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
print '<tr><td colspan="2">&nbsp;</td></tr>'; print '<tr><td colspan="2">&nbsp;</td></tr>';
@ -419,25 +419,25 @@ if ($chid > 0)
// Edit // Edit
if ($user->rights->tax->charges->creer) if ($user->rights->tax->charges->creer)
{ {
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$cha->id&amp;action=edit\">".$langs->trans("Modify")."</a>"; print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&amp;action=edit\">".$langs->trans("Modify")."</a>";
} }
// Emettre paiement // Emettre paiement
if ($cha->paye == 0 && ((price2num($cha->amount) < 0 && round($resteapayer) < 0) || (price2num($cha->amount) > 0 && round($resteapayer) > 0)) && $user->rights->tax->charges->creer) if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->tax->charges->creer)
{ {
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$cha->id&amp;action=create\">".$langs->trans("DoPayment")."</a>"; print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$object->id&amp;action=create\">".$langs->trans("DoPayment")."</a>";
} }
// Classify 'paid' // Classify 'paid'
if ($cha->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer) if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer)
{ {
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$cha->id&amp;action=paid\">".$langs->trans("ClassifyPaid")."</a>"; print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&amp;action=paid\">".$langs->trans("ClassifyPaid")."</a>";
} }
// Delete // Delete
if ($user->rights->tax->charges->supprimer) if ($user->rights->tax->charges->supprimer)
{ {
print "<a class=\"butActionDelete\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$cha->id&amp;action=delete\">".$langs->trans("Delete")."</a>"; print "<a class=\"butActionDelete\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&amp;action=delete\">".$langs->trans("Delete")."</a>";
} }
print "</div>"; print "</div>";
@ -446,11 +446,12 @@ if ($chid > 0)
else else
{ {
/* Charge non trouv<75> */ /* Charge non trouv<75> */
dol_print_error('',$cha->error); dol_print_error('',$object->error);
} }
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -50,7 +50,9 @@ $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
$sortfield = GETPOST("sortfield",'alpha'); $sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha'); $sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int'); $page = GETPOST("page",'int');
if ($page == -1) { $page = 0; } if ($page == -1) {
$page = 0;
}
$offset = $conf->liste_limit * $page; $offset = $conf->liste_limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
@ -71,15 +73,15 @@ $modulepart='tax';
if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC)) if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
if (create_exdir($upload_dir) >= 0) if (create_exdir($upload_dir) >= 0)
{ {
$resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if (is_numeric($resupload) && $resupload > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1) if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
{ {
// Create small thumbs for company (Ratio is near 16/9) // Create small thumbs for company (Ratio is near 16/9)
// Used on logon for example // Used on logon for example
$imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs"); $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
@ -87,26 +89,26 @@ if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
// Create mini thumbs for company (Ratio is near 16/9) // Create mini thumbs for company (Ratio is near 16/9)
// Used on menu or for setup page for example // Used on menu or for setup page for example
$imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs"); $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
} }
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
} }
else else
{ {
$langs->load("errors"); $langs->load("errors");
if ($resupload < 0) // Unknown error if ($resupload < 0) // Unknown error
{ {
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
} }
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{ {
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
} }
else // Known error else // Known error
{ {
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>'; $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
} }
} }
} }
} }
@ -121,36 +123,84 @@ llxHeader("",$langs->trans("SocialContribution"),$help_url);
if ($object->id) if ($object->id)
{ {
if ( $error_msg ) if ( $error_msg )
{ {
echo '<div class="error">'.$error_msg.'</div><br>'; echo '<div class="error">'.$error_msg.'</div><br>';
} }
if ($action == 'delete') if ($action == 'delete')
{ {
$file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). $file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$result=dol_delete_file($file); $result=dol_delete_file($file);
//if ($result >= 0) $mesg=$langs->trans("FileWasRemoced"); //if ($result >= 0) $mesg=$langs->trans("FileWasRemoced");
} }
$head=tax_prepare_head($object, $user); $head=tax_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill'); dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill');
// Construit liste des fichiers // Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0; $totalsize=0;
foreach($filearray as $key => $file) foreach($filearray as $key => $file)
{ {
$totalsize+=$file['size']; $totalsize+=$file['size'];
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>'.$object->ref.'</td></tr>'; print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
print $form->showrefnav($object,'id');
print "</td></tr>";
// Label
if ($action == 'edit')
{
print '<tr><td>'.$langs->trans("Label").'</td><td>';
print '<input type="text" name="label" size="40" value="'.$object->lib.'">';
print '</td></tr>';
}
else
{
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->lib.'</td></tr>';
}
// Type
print "<tr><td>".$langs->trans("Type")."</td><td>".$object->type_libelle."</td></tr>";
// Period end date
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
print "<td>";
if ($action == 'edit')
{
print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1);
}
else
{
print dol_print_date($object->periode,"day");
}
print "</td>";
print "</tr>";
// Due date
if ($action == 'edit')
{
print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
print "</td></tr>";
}
else {
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($object->date_ech,'day')."</td></tr>";
}
// Amount
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount).'</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>'; print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
@ -161,17 +211,17 @@ if ($object->id)
// Affiche formulaire upload // Affiche formulaire upload
$formfile=new FormFile($db); $formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id,'',0,0,$user->rights->tax->charges->creer); $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id,'',0,0,$user->rights->tax->charges->creer);
// List of document // List of document
//$param='&id='.$object->id; //$param='&id='.$object->id;
$formfile->list_of_documents($filearray,$object,'tax',$param); $formfile->list_of_documents($filearray,$object,'tax',$param);
} }
else else
{ {
print $langs->trans("UnkownError"); print $langs->trans("UnkownError");
} }