*
* 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.
*/
/**
\file htdocs/compta/sociales/charges.php
\ingroup tax
\brief Fiche d'une charge sociale
\version $Id$
*/
require("./pre.inc.php");
require(DOL_DOCUMENT_ROOT."/chargesociales.class.php");
$langs->load("compta");
$langs->load("bills");
$chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
/* *************************************************************************** */
/* */
/* Actions */
/* */
/* *************************************************************************** */
/*
* Classer paye
*/
if ($_POST["action"] == 'confirm_payed')
{
if ($_POST["confirm"] == 'yes')
{
$chargesociales = new ChargeSociales($db);
$result = $chargesociales->set_payed($chid);
}
else
{
$_GET["action"]='';
}
}
/*
* Suppression d'une charge sociale
*/
if ($_POST["action"] == 'confirm_delete')
{
if ($_POST["confirm"] == 'yes')
{
$chargesociales=new ChargeSociales($db);
$chargesociales->id=$_GET["id"];
$result=$chargesociales->delete($user);
if ($result > 0)
{
Header("Location: index.php");
exit;
}
else
{
$mesg='
'.$chargesociales->error.'
';
}
}
else
{
$_GET['action']='';
}
}
/*
* Ajout d'une charge sociale
*/
if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
{
$dateech=@dolibarr_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
if (! $dateech)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
';
$_GET["action"] = 'create';
}
elseif (! $_POST["period"])
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
';
$_GET["action"] = 'create';
}
elseif (! $_POST["amount"])
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'
';
$_GET["action"] = 'create';
}
else
{
$chargesociales=new ChargeSociales($db);
$chargesociales->type=$_POST["actioncode"];
$chargesociales->lib=$_POST["label"];
$chargesociales->date_ech=$dateech;
$chargesociales->periode=$_POST["period"];
$chargesociales->amount=$_POST["amount"];
$chid=$chargesociales->create($user);
if ($chid > 0)
{
//$mesg=''.$langs->trans("SocialContributionAdded").'
';
}
else
{
$mesg=''.$chargesociales->error.'
';
}
}
}
if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer)
{
$dateech=@dolibarr_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
if (! $dateech)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
';
$_GET["action"] = 'edit';
}
elseif (! $_POST["period"])
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
';
$_GET["action"] = 'edit';
}
else
{
$chargesociales=new ChargeSociales($db);
$result=$chargesociales->fetch($_GET["id"]);
$chargesociales->lib=$_POST["label"];
$chargesociales->date_ech=$dateech;
$chargesociales->periode=$_POST["period"];
$result=$chargesociales->update($user);
if ($result > 0)
{
//$mesg=''.$langs->trans("SocialContributionAdded").'
';
}
else
{
$mesg=''.$chargesociales->error.'
';
}
}
}
llxHeader();
$html = new Form($db);
/*
* Mode creation
*
*/
if ($_GET["action"] == 'create')
{
print_fiche_titre($langs->trans("NewSocialContribution"));
print "
\n";
if ($mesg) print $mesg.'
';
$var=false;
print '';
}
/* *************************************************************************** */
/* */
/* Mode fiche */
/* */
/* *************************************************************************** */
if ($chid > 0)
{
$cha = new ChargeSociales($db);
/*
* Charge
*/
if ($cha->fetch($chid) > 0)
{
if ($mesg) print $mesg.'
';
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$cha->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
dolibarr_fiche_head($head, 'card', $langs->trans("SocialContribution"));
/*
* Confirmation de la suppression de la charge
*
*/
if ($_GET["action"] == 'payed')
{
$text=$langs->trans('ConfirmPaySocialContribution');
$html->form_confirm($_SERVER["PHP_SELF"]."?id=$cha->id&action=confirm_payed",$langs->trans('PaySocialContribution'),$text,"confirm_payed");
print '
';
}
if ($_GET['action'] == 'delete')
{
$text=$langs->trans('ConfirmDeleteSocialContribution');
$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete');
print '
';
}
if ($_GET['action'] == 'edit') print "\n";
print '';
/*
* Boutons actions
*/
if (! $_GET["action"] || $_GET["action"] == 'update')
{
print "";
}
}
else
{
/* Charge non trouvé */
dolibarr_print_error('',$cha->error);
}
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>