*
* 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");
require("./fichinter.class.php");
require("../project.class.php");
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
if ($socidp)
{
$sql = "SELECT s.nom, s.idp, s.prefix_comm FROM ".MAIN_DB_PREFIX."societe as s WHERE s.idp = $socidp;";
$result = $db->query($sql);
if ($result)
{
if ( $db->num_rows() )
{
$objsoc = $db->fetch_object(0);
}
$db->free();
}
}
llxHeader();
/*
* Traitements des actions
*
*
*/
if ($action == 'valid')
{
$fichinter = new Fichinter($db);
$fichinter->id = $id;
$fichinter->valid($user->id, $conf->fichinter->outputdir);
}
if ($action == 'add')
{
$fichinter = new Fichinter($db);
$fichinter->date = $db->idate(mktime(12, 1 , 1, $pmonth, $pday, $pyear));
$fichinter->socidp = $socidp;
$fichinter->duree = $duree;
$fichinter->projet_id = $projetidp;
$fichinter->author = $user->id;
$fichinter->note = $note;
$fichinter->ref = $ref;
$id = $fichinter->create();
}
if ($action == 'update')
{
$fichinter = new Fichinter($db);
$fichinter->date = $db->idate(mktime(12, 1 , 1, $remonth, $reday, $reyear));
$fichinter->socidp = $socidp;
$fichinter->duree = $duree;
$fichinter->projet_id = $projetidp;
$fichinter->author = $user->id;
$fichinter->note = $note;
$fichinter->ref = $ref;
$fichinter->update($id);
}
/*
*
* Generation du pdf
*
*/
if ($action == 'generate' && $id)
{
fichinter_pdf_create($db, $id);
$mesg = "PDF généré";
}
/*
*
* Mode creation
* Creation d'une nouvelle fiche d'intervention
*
*/
if ($action == 'create')
{
print_titre("Création d'une fiche d'intervention");
if ( $objsoc->prefix_comm )
{
$numpr = "FI-" . $objsoc->prefix_comm . "-" . strftime("%y%m%d", time());
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal WHERE ref like '$numpr%'";
if ( $db->query($sql) )
{
$num = $db->result(0, 0);
$db->free();
if ($num > 0)
{
$numpr .= "." . ($num + 1);
}
}
$fix = new Fichinter($db);
$numpr = $fix->get_new_num($objsoc->prefix_comm);
print "
';
}
else
{
print "Vous devez d'abord associer un prefixe commercial a cette societe" ;
}
}
/*
*
* Mode update
* Mise a jour de la fiche d'intervention
*
*/
if ($action == 'edit')
{
$fichinter = new Fichinter($db);
$fichinter->fetch($id);
/*
* Initialisation de la liste des projets
*/
$prj = new Project($db);
$listeprj = $prj->liste_array($fichinter->societe_id);
print_titre("Mettre à jour Fiche d'intervention");
print "";
print "
";
}
/*
* Mode Fiche
* Affichage de la fiche d'intervention
*
*
*/
if ($id)
{
print_fiche_titre("Fiche d'intervention",$mesg);
$fichinter = new Fichinter($db);
if ( $fichinter->fetch($id) )
{
$fichinter->fetch_client();
print '';
print '| Société | '.$fichinter->client->nom.' |
';
print '| Date | '.strftime("%A %d %B %Y",$fichinter->date).' |
';
print '| Numéro | '.$fichinter->ref.' |
';
print '| Durée | '.$fichinter->duree.' |
';
print '| Projet | |
';
print '| Description | ';
print '';
print nl2br($fichinter->note);
print ' |
';
print '';
print "
";
/*
*
*/
print '
';
if ($user->societe_id == 0)
{
if ($fichinter->statut == 0)
{
print '| Mettre à jour | ';
}
else
{
print '- | ';
}
print '- | ';
$file = FICHEINTER_OUTPUTDIR . "/$fichinter->ref/$fichinter->ref.pdf";
if ($fichinter->statut == 0 or !file_exists($file))
{
print 'Génération du pdf | ';
}
else
{
print '- | ';
}
print '- | ';
if ($fichinter->statut == 0)
{
print 'Valider | ';
}
else
{
print '- | ';
}
}
else
{
print '- | ';
print '- | ';
print '- | ';
print '- | ';
print '- | ';
}
print '
';
print '';
print_titre("Documents générés");
print '';
$file = FICHEINTER_OUTPUTDIR . "/$fichinter->ref/$fichinter->ref.pdf";
if (file_exists($file))
{
print "| Ficheinter PDF | ";
print ''.$fichinter->ref.'.pdf | ';
print ''.filesize($file). ' bytes | ';
print ''.strftime("%d %b %Y %H:%M:%S",filemtime($file)).' | ';
}
print " |
\n";
}
else
{
print "Fiche inexistante";
}
}
$db->close();
llxFooter();
?>