Commit 00aec9fd authored by Feu's avatar Feu
Browse files

compta: suite des notes de frais

parent c01c83f4
......@@ -58,13 +58,114 @@ elseif ( $_REQUEST["action"] == "create" )
if ( $notefrais->is_valid() )
{
if ( !$site->user->is_in_group("compta_admin")
&& !$asso->is_member_role($site->user->id,ROLEASSO_TRESORIER)
&& $site->user->id != $notefrais->id_utilisateur )
$site->error_forbidden("none","group");
$user = new utilisateur($this->bd);
$user->load_by_id($notefrais->id_utilisateur);
if ( $_REQUEST["action"] == "delete" && !$notefrais->valide )
{
$notefrais->delete();
header("Location: notefrais.php");
exit();
}
elseif ( $_REQUEST["action"] == "save" && !$notefrais->valide )
{
$asso->load_by_id($_REQUEST["id_asso"]);
$notefrais->update ( $asso->id, $_REQUEST["commentaire"], $_REQUEST["avance"] );
$notefrais->delete_all_lines();
foreach( $_REQUEST["designation"] as $i => $designation )
{
if ( $designation && $_REQUEST["prix"][$i] )
$notefrais->create_line( $designation, $_REQUEST["prix"][$i] );
}
}
elseif ( $_REQUEST["action"] == "edit" && !$notefrais->valide )
{
$site->start_page ("none", "Note de frais" );
$cts = new contents("Note de frais N°".$notefrais->id);
$frm = new form ("editnotefrais","notefrais.php?id_notefrais=".$notefrais->id,true,"POST","Modification");
$frm->add_hidden("action","save");
$frm->add_entity_smartselect ("id_asso","Activité concernée", $asso, false, true);
$frm->add_text_area("commentaire","Commentaire",$notefrais->commentaire,40,3,true);
$frm->add_price_field("avance","Avance (qui vous a déjà été versée)",$notefrais->avance);
$lines = $notefrais->get_lines();
for($i=0;$i<5;$i++)
{
$sfrm = new form(null,null,null,null);
$sfrm->add_text_field("designation[$i]","Designation",$lines[$i]["designation_ligne_notefrais"]);
$sfrm->add_price_field("prix[$i]","Prix",$lines[$i]["prix_ligne_notefrais"]);
$frm->add($sfrm, false, false, false, false, true);
}
$frm->add_submit("record","Enregistrer");
$cts->add($frm,true);
$site->add_contents($cts);
$site->end_page ();
exit();
}
$site->start_page ("none", "Note de frais" );
$cts = new contents("Note de frais");
$cts = new contents("Note de frais N°".$notefrais->id);
$cts->add_paragraph("Benevole : ".$user->get_html_link());
$cts->add_paragraph("Activité : ".$asso->get_html_link());
$cts->add_paragraph("Date : ".date("d/m/Y",$notefrais->date));
$cts->add_paragraph("Commentaire : ".$notefrais->commentaire);
$site->add_contents($cts);
$tbl = new sqltable("frais",
"",
$notefrais->get_lines(),
"notefrais.php?id_notefrais=".$notefrais->id,
"num_notefrais_ligne",
array(
"designation_ligne_notefrais" => "Designation",
"prix_ligne_notefrais" => "Prix"),
array(),
array(),
array() );
$cts->add($tbl);
$cts->add_paragraph("Total : ".($notefrais->total/100));
$cts->add_paragraph("Avance : ".($notefrais->avance/100));
$cts->add_paragraph("A payer : ".($notefrais->total_payer/100));
if ( $notefrais->valide )
{
if ( $notefrais->id_classeur )
$cts->add_paragraph("Validé et classé");
else
$cts->add_paragraph("Validé");
}
else
{
$cts->add_paragraph("En attente de validation");
$cts->add_paragraph("<a href=\"?id_notefrais=".$notefrais->id."&amp;action=edit\">Editer</a>");
$cts->add_paragraph("<a href=\"?id_notefrais=".$notefrais->id."&amp;action=delete\">Supprimer</a>");
if ( $asso->is_member_role($site->user->id,ROLEASSO_TRESORIER)
|| $site->user->is_in_group("compta_admin") )
{
// TODO: Valider, classer, et decomposer en operations
}
}
$site->add_contents($cts);
$site->end_page ();
exit();
}
......@@ -82,7 +183,28 @@ $cts->add_paragraph("Les notes de frais vous permettent d'obtenir le rembourseme
$cts->add_paragraph("La note de frais devra être accompagné de tous les justificatifs nécessaires (factures), qui devrons être remis au trésorier de l'activité. Les factures devront être à votre nom, justifiant ainsi que vous avez bien engagé les frais.");
$frm = new form ("saisienotefrais","notefrais.php",true,"POST","Saisie de la note de frais");
$req = new requete($site->db,"SELECT id_notefrais,date_notefrais,asso.id_asso,nom_asso
FROM cpta_notefrais
INNER JOIN asso USING(id_asso)
WHERE id_utilisateur='".$site->user->id."'
ORDER BY id_notefrais");
$tbl = new sqltable("mines",
"Mes notes de frais",
$req,
"notefrais.php",
"id_notefrais",
array(
"id_notefrais" => "Numéro",
"date_notefrais" => "Date",
"nom_asso" => "Activité"),
array(),
array(),
array() );
$cts->add($tbl,true);
$frm = new form ("saisienotefrais","notefrais.php",true,"POST","Saisie d'une nouvelle note de frais");
$frm->add_hidden("action","create");
if ( isset($Erreur) )
$frm->error($Erreur);
......@@ -98,6 +220,8 @@ for($i=0;$i<5;$i++)
$frm->add($sfrm, false, false, false, false, true);
}
$frm->add_submit("record","Enregistrer");
$cts->add($frm,true);
$site->add_contents($cts);
......
......@@ -87,9 +87,12 @@ $GLOBALS["entitiescatalog"] = array (
"secteur" => array( "id_secteur", "nom_secteur", "lieu.png", "entreprise.php", "secteur"),
"efact"=>array("id_efact","titre_facture","file.png","compta/efact.php","cpta_facture","efact.inc.php"),
"notefrais"=>array("id_notefrais","id_notefrais","file.png","compta/notefrais.php","cpta_notefrais","noetfrais.inc.php"),
"uv" => array ( "id_uv", "code_uv", "misc.png", "uvs/uvs.php", "edu_uv", "uv.inc.php" ),
"nouvelle"=>array("id_nouvelle", "titre_nvl", "misc.png", "news.php", "nvl_nouvelles", "news.inc.php", "nvl_nouvelles_tag")
......
......@@ -167,7 +167,16 @@ class notefrais extends stdentity
));
$this->update_fields();
}
function delete_all_lines ( )
{
$req = new delete ($this->dbrw,
"cpta_notefrais_ligne", array(
"id_notefrais"=>$this->id
));
$this->update_fields();
}
function update_fields()
{
$req = new requete($this->db, "SELECT SUM(prix_ligne_notefrais) FROM `cpta_notefrais_ligne`
......@@ -186,6 +195,18 @@ class notefrais extends stdentity
array("id_notefrais"=>$this->id));
}
function get_lines()
{
$lines = array();
$req = new requete($this->db, "SELECT * FROM `cpta_notefrais_ligne`
WHERE `id_notefrais` = '" . mysql_real_escape_string($this->id) . "'");
while ( $row = $req->get_row() )
$lines[]=$row;
return $lines;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment