* Copyright (C) 2004 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ require("./pre.inc.php"); $user->getrights('facture'); $user->getrights('compta'); if (!$user->admin && !$user->rights->compta->charges->lire) accessforbidden(); llxHeader(); /* * Ajout d'une charge sociale */ if ($action == 'add') { if (! $_POST["date"] || ! $_POST["periode"] || ! $_POST["amount"]) { $mesg="
Erreur: Tous les champs date et montant doivent etre renseignés avec une valeur non vide.
"; } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount) "; $sql .= " VALUES (".$_POST["type"].",'".addslashes($_POST["libelle"])."','".$_POST["date"]."','".$_POST["periode"]."','".$_POST["amount"]."');"; if (! $db->query($sql) ) { print $db->error(); } else { $mesg="
La charge a été ajoutée.
"; } } } /* * Suppression d'une charge sociale */ if ($_GET["action"] == 'del') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$_GET["id"]."'"; if (! $db->query($sql) ) { print $db->error(); } } /* * Affichage liste et formulaire des charges. */ $year=$_GET["year"]; $filtre=$_GET["filtre"]; //if (! $year) { $year=date("Y", time()); } print_fiche_titre("Charges sociales",($year?"".img_previous()." Année $year ".img_next()."":"")); print "
\n"; if ($mesg) { print "$mesg
"; } print ""; print ""; print ''; print ''; print "\n"; $sql = "SELECT s.rowid as id, s.fk_type as type, c.libelle as type_lib, s.amount,".$db->pdate("s.date_ech")." as de, s.date_pai, s.libelle, s.paye,".$db->pdate("s.periode")." as periode,".$db->pdate("s.date_pai")." as dp"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; $sql .= " WHERE s.fk_type = c.id"; if ($year > 0) { $sql .= " AND ("; // Si period renseigné on l'utilise comme critere de date, sinon on prend date échéance, // ceci afin d'etre compatible avec les cas ou la période n'etait pas obligatoire $sql .= " (s.periode is not null and date_format(s.periode, '%Y') = $year) "; $sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = $year)"; $sql .= ")"; } if ($filtre) { $filtre=ereg_replace(":","=",$filtre); $sql .= " AND $filtre"; } if ($_GET["sortfield"]) { $sql .= " ORDER BY ".$_GET["sortfield"]; } else { $sql .= " ORDER BY lower(s.date_ech)"; } if ($_GET["sortorder"]) { $sql .= " ".$_GET["sortorder"]; } else { $sql .= " DESC"; } if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object( $i); $var = !$var; print ""; print ''; print ''; print ''; print ''; print ''; if ($obj->paye) { print ''; print ''; } else { print ''; print ''; } print ''; $i++; } } else { print "Error :".$db->error()." - $sql"; } /* * Forumalaire d'ajout d'une charge * */ if ($user->rights->compta->charges->creer) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
'; print_liste_field_titre("Num",$PHP_SELF,"id"); print ''; print_liste_field_titre("Echéance",$PHP_SELF,"de"); print ''; print_liste_field_titre("Période",$PHP_SELF,"periode"); print ''; print_liste_field_titre("Type",$PHP_SELF,"type"); print ''; print_liste_field_titre("Libellé",$PHP_SELF,"s.libelle"); print ''; print_liste_field_titre("Montant",$PHP_SELF,"s.amount"); print ''; print_liste_field_titre("Statut",$PHP_SELF,"s.paye"); print ' 
'.$obj->id.''.dolibarr_print_date($obj->de).''; if ($obj->periode) { print 'periode).'">'.strftime("%Y",$obj->periode).''; } else { print ' '; } print ''.$obj->type_lib.''.$obj->libelle.''.price($obj->amount).'Payé Impayé'; if ($user->rights->compta->charges->creer) { print ''.img_edit().''; } if ($user->rights->compta->charges->supprimer) { print '   '.img_delete().''; } print '
 
YYYYMMDD

YYYYMMDD
'; print ' 
'; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>