* Copyright (C) 2005-2013 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 3 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, see . */ /** * \file htdocs/compta/sociales/charges.php * \ingroup tax * \brief Social contribution car page */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; $langs->load("compta"); $langs->load("bills"); $id=GETPOST('id','int'); $action=GETPOST("action"); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); /* *************************************************************************** */ /* */ /* Actions */ /* */ /* *************************************************************************** */ /* * Classify paid */ if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes') { $chargesociales = new ChargeSociales($db); $chargesociales->fetch($id); $result = $chargesociales->set_paid($user); } /* * Delete social contribution */ if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes') { $chargesociales=new ChargeSociales($db); $chargesociales->fetch($id); $result=$chargesociales->delete($user); if ($result > 0) { header("Location: index.php"); exit; } else { $mesg='
'.$chargesociales->error.'
'; } } /* * Add social contribution */ if ($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")).'
'; $action = 'create'; } elseif (! $dateperiod) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; $action = 'create'; } elseif (! $_POST["actioncode"] > 0) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")).'
'; $action = 'create'; } elseif (! $_POST["amount"]) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'
'; $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"]; $id=$chargesociales->create($user); if ($id > 0) { //$mesg='
'.$langs->trans("SocialContributionAdded").'
'; } else { $mesg='
'.$chargesociales->error.'
'; } } } if ($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")).'
'; $action = 'edit'; } elseif (! $dateperiod) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
'; $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 */ $form = new Form($db); $formsocialcontrib = new FormSocialContrib($db); $help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; llxHeader("",$langs->trans("SocialContribution"),$help_url); // Mode creation if ($action == 'create') { print_fiche_titre($langs->trans("NewSocialContribution")); print "
\n"; dol_htmloutput_mesg($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 '
 '; $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode")?GETPOST("actioncode"):'','actioncode',1); print ''; print $form->select_date(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1); print ''; print $form->select_date(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1); print '
'; print '
'; } /* *************************************************************************** */ /* */ /* Mode fiche */ /* */ /* *************************************************************************** */ if ($id > 0) { $object = new ChargeSociales($db); $result=$object->fetch($id); if ($result > 0) { dol_htmloutput_mesg($mesg); $head=tax_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill'); // Confirmation de la suppression de la charge if ($action == 'paid') { $text=$langs->trans('ConfirmPaySocialContribution'); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2); } if ($action == 'delete') { $text=$langs->trans('ConfirmDeleteSocialContribution'); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2); } if ($action == 'edit') { print "
id&action=update\" method=\"post\">"; print ''; } print ''; // Ref print '"; // Label if ($action == 'edit') { print ''; } else { print ''; } // Type print ""; $rowspan=5; print '"; print ""; // Period end date print ""; print ""; // Due date if ($action == 'edit') { print '"; } else { print ""; } // Amount print ''; // Status print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id'); print "
'.$langs->trans("Label").''; print ''; print '
'.$langs->trans("Label").''.$object->lib.'
".$langs->trans("Type")."".$object->type_libelle."'; /* * Payments */ $sql = "SELECT p.rowid, p.num_paiement, datep as dp, p.amount,"; $sql.= "c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE p.fk_charge = ".$id; $sql.= " AND p.fk_charge = cs.rowid"; $sql.= " AND cs.entity = ".$conf->entity; $sql.= " AND p.fk_typepaiement = c.id"; $sql.= " ORDER BY dp DESC"; //print $sql; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; echo ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "'; print '\n"; print "\n"; print '\n"; print ""; $totalpaye += $objp->amount; $i++; } if ($object->paye == 0) { print "\n"; print "\n"; $resteapayer = $object->amount - $totalpaye; print ""; print "\n"; } print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."
"; $db->free($resql); } else { dol_print_error($db); } print "
".$langs->trans("PeriodEndDate").""; if ($action == 'edit') { print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1); } else { print dol_print_date($object->periode,"day"); } print "
'.$langs->trans("DateDue").""; print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); print "
".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day')."
'.$langs->trans("AmountTTC").''.price($object->amount).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'; if ($action == 'edit') { print '
'; print ''; print '   '; print ''; print '\n"; dol_fiche_end(); /* * Boutons actions */ if ($action != 'edit') { print "
\n"; // Edit if ($user->rights->tax->charges->creer) { print "id&action=edit\">".$langs->trans("Modify").""; } // Emettre paiement if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->tax->charges->creer) { print "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer) { print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Delete if ($user->rights->tax->charges->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } print "
"; } } else { /* Charge non trouv� */ dol_print_error('',$object->error); } } llxFooter(); $db->close(); ?>