* 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 card 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"); $confirm=GETPOST('confirm'); // 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' && $confirm == 'yes') { $chargesociales = new ChargeSociales($db); $chargesociales->fetch($id); $result = $chargesociales->set_paid($user); } // Delete social contribution if ($action == 'confirm_delete' && $confirm == 'yes') { $chargesociales=new ChargeSociales($db); $chargesociales->fetch($id); $result=$chargesociales->delete($user); if ($result > 0) { header("Location: index.php"); exit; } else { setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); } } // Add social contribution if ($action == 'add' && $user->rights->tax->charges->creer) { $dateech=@dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); $dateperiod=@dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $amount=GETPOST('amount'); $actioncode=GETPOST('actioncode'); if (! $dateech) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); $action = 'create'; } elseif (! $dateperiod) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); $action = 'create'; } elseif (! $actioncode > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")), 'errors'); $action = 'create'; } elseif (empty($amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")), 'errors'); $action = 'create'; } elseif (! is_numeric($amount)) { setEventMessage($langs->trans("ErrorFieldMustBeANumeric",$langs->transnoentities("Amount")), 'errors'); $action = 'create'; } else { $chargesociales=new ChargeSociales($db); $chargesociales->type=$actioncode; $chargesociales->lib=GETPOST('label'); $chargesociales->date_ech=$dateech; $chargesociales->periode=$dateperiod; $chargesociales->amount=price2num($amount); $id=$chargesociales->create($user); if ($id <= 0) { setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); $action='create'; } } } if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer) { $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $amount=GETPOST('amount'); if (! $dateech) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); $action = 'edit'; } elseif (! $dateperiod) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); $action = 'edit'; } elseif (empty($amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")), 'errors'); $action = 'edit'; } else { $chargesociales=new ChargeSociales($db); $result=$chargesociales->fetch($id); $chargesociales->lib=GETPOST('label'); $chargesociales->date_ech=$dateech; $chargesociales->periode=$dateperiod; $chargesociales->amount=price2num($amount); $result=$chargesociales->update($user); if ($result <= 0) { setEventMessage($chargesociales->error, 'errors'); } } } // Action clone object if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; } if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { $db->begin(); $originalId = $id; $object = new ChargeSociales($db); $object->fetch($id); if ($object->id > 0) { $object->paye = 0; $object->id = $object->ref = null; if(GETPOST('clone_for_next_month') != '') { $object->date_ech = strtotime('+1month', $object->date_ech); $object->periode = strtotime('+1month', $object->periode); } if ($object->check()) { $id = $object->create($user); if ($id > 0) { $db->commit(); $db->close(); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { $id=$originalId; $db->rollback(); setEventMessages($object->error,$object->errors, 'errors'); } } } else { $db->rollback(); dol_print_error($db,$object->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")); $var=false; print '
'; print ''; print ''; dol_fiche_head(); print ''; print ""; // Label print ''; print ''; print ''; print ''; // Type print ''; print ''; print ''; // Date end period print ''; print ''; print ''; print ''; // Amount print ''; print ''; print ''; print ''; // Date due print ''; print ''; print ''; print "\n"; print '
'; print $langs->trans("Label"); print '
'; print $langs->trans("Type"); print ''; $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode")?GETPOST("actioncode"):'','actioncode',1); print '
'; print $langs->trans("PeriodEndDate"); print ''; print $form->select_date(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1); print '
'; print $langs->trans("Amount"); print '
'; print $langs->trans("DateDue"); print ''; print $form->select_date(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1); print '
'; dol_fiche_end(); print '
'; print ''; print '
'; print ''; } /* *************************************************************************** */ /* */ /* Mode fiche */ /* */ /* *************************************************************************** */ if ($id > 0) { $object = new ChargeSociales($db); $result=$object->fetch($id); if ($result > 0) { $head=tax_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill'); // Clone confirmation if ($action === 'clone') { $formclone=array( array('type' => 'checkbox', 'name' => 'clone_for_next_month','label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1), ); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneTax'),$langs->trans('ConfirmCloneTax',$object->ref),'confirm_clone',$formclone,'yes'); } // 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 if ($action == 'edit') { print '"; } else { 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.code as type_code,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; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "'; print '\n"; $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; 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')."".$labeltype.' '.$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").""; print ''; print "
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'; if ($action == 'edit') { print '
'; print ''; print '   '; print ''; print '\n"; dol_fiche_end(); /* * Actions buttons */ if ($action != 'edit') { print "
\n"; // Edit if ($object->paye == 0 && $user->rights->tax->charges->creer) { print "id&action=edit\">".$langs->trans("Modify").""; } // Emit payment if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 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").""; } // Clone if ($user->rights->tax->charges->creer) { print "id&action=clone\">".$langs->trans("ToClone").""; } // Delete if ($user->rights->tax->charges->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } print "
"; } } else { /* Social contribution not found */ dol_print_error('',$object->error); } } llxFooter(); $db->close();