* Copyright (C) 2005-2009 Regis Houssin * * 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 Social contribution car page * \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 ($_REQUEST["action"] == 'confirm_paid' && $_REQUEST["confirm"] == 'yes') { $chargesociales = new ChargeSociales($db); $result = $chargesociales->set_paid($chid); } /* * Suppression d'une charge sociale */ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["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.'
'; } } /* * Ajout d'une charge sociale */ if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer) { $dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); if (! $dateech) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
'; $_GET["action"] = 'create'; } elseif (! $dateperiod) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; $_GET["action"] = 'create'; } elseif (! $_POST["actioncode"] > 0) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")).'
'; $_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=$dateperiod; $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=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); if (! $dateech) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
'; $_GET["action"] = 'edit'; } elseif (! $dateperiod) { $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=$dateperiod; $result=$chargesociales->update($user); if ($result > 0) { //$mesg='
'.$langs->trans("SocialContributionAdded").'
'; } else { $mesg='
'.$chargesociales->error.'
'; } } } /* * View */ 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 '
'; print ''; print ''; print ""; print ""; print ''; print "\n"; print ''; print ''; // Label print ''; // Type print ''; // Date end period print ''; print ''; print ''; print ''; print ''; print '
'; print ' '; print ''; print $langs->trans("Label"); print ''; print $langs->trans("Type"); print ''; print $langs->trans("PeriodEndDate"); print ''; print $langs->trans("Amount"); print ''; print $langs->trans("DateDue"); print ''; print ' '; print '
 '; $html->select_type_socialcontrib(isset($_POST["actioncode"])?$_POST["actioncode"]:'','actioncode',1); print ''; print $html->select_date(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1); print ''; print $html->select_date(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1); print '
'; 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++; dol_fiche_head($head, 'card', $langs->trans("SocialContribution")); /* * Confirmation de la suppression de la charge * */ if ($_GET["action"] == 'paid') { $text=$langs->trans('ConfirmPaySocialContribution'); $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=$cha->id&action=confirm_paid",$langs->trans('PaySocialContribution'),$text,"confirm_paid"); if ($ret == 'html') print '
'; } if ($_GET['action'] == 'delete') { $text=$langs->trans('ConfirmDeleteSocialContribution'); $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete'); if ($ret == 'html') print '
'; } if ($_GET['action'] == 'edit') { print "
id&action=update\" method=\"post\">"; print ''; } print ''; // Ref print ""; // Label if ($_GET['action'] == 'edit') { print ''; } else { print ''; } // Type print ""; // Period en date print ""; print ""; print '"; print ""; // Due date if ($_GET['action'] == 'edit') { print '"; } else { print ""; } print ''; print ''; if ($_GET['action'] == 'edit') { print ''; } print '
".$langs->trans("Ref").''; print $html->showrefnav($cha,'id'); print "
'.$langs->trans("Label").''; print ''; print '
'.$langs->trans("Label").''.$cha->lib.'
".$langs->trans("Type")."".$cha->type_libelle."".$langs->trans("Payments")."
".$langs->trans("PeriodEndDate").""; if ($_GET['action'] == 'edit') { print $html->select_date($cha->periode, 'period', 0, 0, 0, 'charge', 1); } else { print dol_print_date($cha->periode,"day"); } print "'; /* * Paiements */ $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount,"; $sql.= "c.libelle as paiement_type, p.num_paiement, p.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= " WHERE p.fk_charge = ".$chid; $sql.= " AND p.fk_charge = s.rowid"; $sql.= " AND s.entity = ".$conf->entity; $sql.= " AND p.fk_typepaiement = c.id"; $sql.= " ORDER BY dp DESC"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; echo ''; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "\n"; print "\n"; print '\n"; print ""; $totalpaye += $objp->amount; $i++; } if ($cha->paye == 0) { print "\n"; print "\n"; $resteapayer = $cha->amount - $totalpaye; print ""; print "\n"; } print "
'.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; print img_object($langs->trans("Payment"),"payment").' '; print dol_print_date($objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("AmountExpected")." :".price($cha->amount)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)."".$langs->trans("Currency".$conf->monnaie)."
"; $db->free($resql); } else { dol_print_error($db); } print "
'.$langs->trans("DateDue").""; print $html->select_date($cha->date_ech, 'ech', 0, 0, 0, 'charge', 1); print "
".$langs->trans("DateDue")."".dol_print_date($cha->date_ech,'day')."
'.$langs->trans("AmountTTC").''.price($cha->amount).'
'.$langs->trans("Status").''.$cha->getLibStatut(4).'
'; print ''; print '   '; print ''; print '
'; if ($_GET['action'] == 'edit') print "
\n"; print ''; /* * Boutons actions */ if ($_GET["action"] != 'edit') { print "
\n"; // Edit if ($user->rights->tax->charges->creer) { print "id&action=edit\">".$langs->trans("Modify").""; } // Emettre paiement if ($cha->paye == 0 && round($resteapayer) > 0 && $user->rights->tax->charges->creer) { print "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($cha->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer) { print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Delete if ($cha->paye == 0 && $totalpaye <=0 && $user->rights->tax->charges->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } print "
"; } } else { /* Charge non trouv� */ dol_print_error('',$cha->error); } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>