New: Add a tab info for social contributions

This commit is contained in:
Laurent Destailleur 2011-12-21 21:14:10 +01:00
parent 79c07397d6
commit aa2a45db87
9 changed files with 514 additions and 332 deletions

View File

@ -23,17 +23,19 @@
*/ */
require('../../main.inc.php'); require('../../main.inc.php');
require(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php");
$langs->load("compta"); $langs->load("compta");
$langs->load("bills"); $langs->load("bills");
$chid=GETPOST("id"); $chid=GETPOST("id");
$action=GETPOST("action");
// Security check // Security check
$socid = GETPOST("socid"); $socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges'); $result = restrictedArea($user, 'tax', $langs->trans("SocialContribution"), '', 'charges');
@ -46,9 +48,9 @@ $result = restrictedArea($user, 'tax', '', '', 'charges');
/* *************************************************************************** */ /* *************************************************************************** */
/* /*
* Classer paye * Classify paid
*/ */
if ($_REQUEST["action"] == 'confirm_paid' && $_REQUEST["confirm"] == 'yes') if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
{ {
$chargesociales = new ChargeSociales($db); $chargesociales = new ChargeSociales($db);
$chargesociales->fetch($chid); $chargesociales->fetch($chid);
@ -56,9 +58,9 @@ if ($_REQUEST["action"] == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
} }
/* /*
* Suppression d'une charge sociale * Delete social contribution
*/ */
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes') if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{ {
$chargesociales=new ChargeSociales($db); $chargesociales=new ChargeSociales($db);
$chargesociales->fetch($chid); $chargesociales->fetch($chid);
@ -76,32 +78,32 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
/* /*
* Ajout d'une charge sociale * Add social contribution
*/ */
if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer) if ($action == 'add' && $user->rights->tax->charges->creer)
{ {
$dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); $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"]); $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
if (! $dateech) if (! $dateech)
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'</div>';
$_GET["action"] = 'create'; $action = 'create';
} }
elseif (! $dateperiod) elseif (! $dateperiod)
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'</div>';
$_GET["action"] = 'create'; $action = 'create';
} }
elseif (! $_POST["actioncode"] > 0) elseif (! $_POST["actioncode"] > 0)
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")).'</div>';
$_GET["action"] = 'create'; $action = 'create';
} }
elseif (! $_POST["amount"]) elseif (! $_POST["amount"])
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")).'</div>';
$_GET["action"] = 'create'; $action = 'create';
} }
else else
{ {
@ -126,19 +128,19 @@ if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
} }
if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer) 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"]); $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"]); $dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
if (! $dateech) if (! $dateech)
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'</div>';
$_GET["action"] = 'edit'; $action = 'edit';
} }
elseif (! $dateperiod) elseif (! $dateperiod)
{ {
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'</div>';
$_GET["action"] = 'edit'; $action = 'edit';
} }
else else
{ {
@ -167,12 +169,13 @@ if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->cha
* View * View
*/ */
llxHeader('',$langs->trans("SocialContribution")); $help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
llxHeader("",$langs->trans("SocialContribution"),$help_url);
$form = new Form($db); $form = new Form($db);
// Mode creation // Mode creation
if ($_GET["action"] == 'create') if ($action == 'create')
{ {
print_fiche_titre($langs->trans("NewSocialContribution")); print_fiche_titre($langs->trans("NewSocialContribution"));
print "<br>\n"; print "<br>\n";
@ -249,11 +252,7 @@ if ($chid > 0)
{ {
dol_htmloutput_mesg($mesg); dol_htmloutput_mesg($mesg);
$h = 0; $head=tax_prepare_head($cha);
$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"),0,'bill'); dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill');
@ -261,19 +260,19 @@ if ($chid > 0)
* Confirmation de la suppression de la charge * Confirmation de la suppression de la charge
* *
*/ */
if ($_GET["action"] == 'paid') if ($action == 'paid')
{ {
$text=$langs->trans('ConfirmPaySocialContribution'); $text=$langs->trans('ConfirmPaySocialContribution');
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$cha->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$cha->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2);
} }
if ($_GET['action'] == 'delete') if ($action == 'delete')
{ {
$text=$langs->trans('ConfirmDeleteSocialContribution'); $text=$langs->trans('ConfirmDeleteSocialContribution');
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2);
} }
if ($_GET['action'] == 'edit') if ($action == 'edit')
{ {
print "<form name=\"charge\" action=\"charges.php?id=$cha->id&amp;action=update\" method=\"post\">"; print "<form name=\"charge\" action=\"charges.php?id=$cha->id&amp;action=update\" method=\"post\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -287,7 +286,7 @@ if ($chid > 0)
print "</td></tr>"; print "</td></tr>";
// Label // Label
if ($_GET['action'] == 'edit') if ($action == 'edit')
{ {
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">';
print '<input type="text" name="label" size="40" value="'.$cha->lib.'">'; print '<input type="text" name="label" size="40" value="'.$cha->lib.'">';
@ -304,7 +303,7 @@ if ($chid > 0)
// Period end date // Period end date
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>"; print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
print "<td>"; print "<td>";
if ($_GET['action'] == 'edit') if ($action == 'edit')
{ {
print $form->select_date($cha->periode, 'period', 0, 0, 0, 'charge', 1); print $form->select_date($cha->periode, 'period', 0, 0, 0, 'charge', 1);
} }
@ -379,7 +378,7 @@ if ($chid > 0)
print "</tr>"; print "</tr>";
// Due date // Due date
if ($_GET['action'] == 'edit') if ($action == 'edit')
{ {
print '<tr><td>'.$langs->trans("DateDue")."</td><td>"; print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
print $form->select_date($cha->date_ech, 'ech', 0, 0, 0, 'charge', 1); print $form->select_date($cha->date_ech, 'ech', 0, 0, 0, 'charge', 1);
@ -397,18 +396,18 @@ if ($chid > 0)
print '<tr><td colspan="2">&nbsp;</td></tr>'; print '<tr><td colspan="2">&nbsp;</td></tr>';
if ($_GET['action'] == 'edit') print '</table>';
if ($action == 'edit')
{ {
print '<tr><td colspan="3" align="center">'; print '<div align="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; '; print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>'; print '</div';
} }
print '</table>'; if ($action == 'edit') print "</form>\n";
if ($_GET['action'] == 'edit') print "</form>\n";
print '</div>'; print '</div>';
@ -416,7 +415,7 @@ if ($chid > 0)
/* /*
* Boutons actions * Boutons actions
*/ */
if ($_GET["action"] != 'edit') if ($action != 'edit')
{ {
print "<div class=\"tabsAction\">\n"; print "<div class=\"tabsAction\">\n";

View File

@ -21,7 +21,6 @@
* \ingroup facture * \ingroup facture
* \brief Fichier de la classe des charges sociales * \brief Fichier de la classe des charges sociales
*/ */
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@ -31,132 +30,143 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
*/ */
class ChargeSociales extends CommonObject class ChargeSociales extends CommonObject
{ {
public $element='rowid'; public $element='rowid';
public $table='chargesociales'; public $table='chargesociales';
public $table_element='chargesociales'; public $table_element='chargesociales';
var $id; var $id;
var $date_ech; var $date_ech;
var $lib; var $lib;
var $type; var $type;
var $type_libelle; var $type_libelle;
var $amount; var $amount;
var $paye; var $paye;
var $periode; var $periode;
var $date_creation;
var $date_modification;
var $date_validation;
function ChargeSociales($DB) /**
{ * Constructor
$this->db = $DB; *
* @param DoliDB $db Database handler
*/
function ChargeSociales($db)
{
$this->db = $db;
return 1;
}
return 1; /**
} * Retrouve et charge une charge sociale
*
* @param int $id 1 si trouve, 0 sinon
* @return void
*/
function fetch($id)
{
$sql = "SELECT cs.rowid, cs.date_ech,";
$sql.= " cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode,";
$sql.= " c.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= " WHERE cs.fk_type = c.id";
$sql.= " AND cs.rowid = ".$id;
/** dol_syslog(get_class($this)."::fetch sql=".$sql);
* \brief Retrouve et charge une charge sociale $resql=$this->db->query($sql);
* \return int 1 si trouve, 0 sinon if ($resql)
*/ {
function fetch($id) if ($this->db->num_rows($resql))
{ {
$sql = "SELECT cs.rowid, cs.date_ech,"; $obj = $this->db->fetch_object($resql);
$sql.= " cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode,";
$sql.= " c.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= " WHERE cs.fk_type = c.id";
$sql.= " AND cs.rowid = ".$id;
dol_syslog("ChargesSociales::fetch sql=".$sql); $this->id = $obj->rowid;
$resql=$this->db->query($sql); $this->ref = $obj->rowid;
if ($resql) $this->date_ech = $this->db->jdate($obj->date_ech);
{ $this->lib = $obj->lib;
if ($this->db->num_rows($resql)) $this->type = $obj->fk_type;
{ $this->type_libelle = $obj->libelle;
$obj = $this->db->fetch_object($resql); $this->amount = $obj->amount;
$this->paye = $obj->paye;
$this->periode = $this->db->jdate($obj->periode);
$this->id = $obj->rowid; return 1;
$this->ref = $obj->rowid; }
$this->date_ech = $this->db->jdate($obj->date_ech); else
$this->lib = $obj->lib; {
$this->type = $obj->fk_type; return 0;
$this->type_libelle = $obj->libelle; }
$this->amount = $obj->amount; $this->db->free($resql);
$this->paye = $obj->paye; }
$this->periode = $this->db->jdate($obj->periode); else
{
return 1; $this->error=$this->db->error();
} return -1;
else }
{ }
return 0;
}
$this->db->free($resql);
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/** /**
* \brief Create a social contribution in database * Create a social contribution in database
* \param user User making creation *
* \return int <0 if KO, id if OK * @param User $user User making creation
*/ * @return int <0 if KO, id if OK
function create($user) */
{ function create($user)
// Nettoyage parametres {
$newamount=price2num($this->amount,'MT'); // Nettoyage parametres
$newamount=price2num($this->amount,'MT');
// Validation parametres // Validation parametres
if (! $newamount > 0) if (! $newamount > 0)
{ {
$this->error="ErrorBadParameter"; $this->error="ErrorBadParameter";
return -2; return -2;
} }
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount)";
$sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',"; $sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',";
$sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',"; $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',";
$sql.= " ".price2num($newamount); $sql.= " ".price2num($newamount);
$sql.= ")"; $sql.= ")";
dol_syslog("ChargesSociales::create sql=".$sql); dol_syslog(get_class($this)."::create sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
//dol_syslog("ChargesSociales::create this->id=".$this->id); //dol_syslog("ChargesSociales::create this->id=".$this->id);
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Delete a social contribution * Delete a social contribution
* @param user Object user making delete *
* @return int <0 if KO, >0 if OK * @param User $user Object user making delete
*/ * @return int <0 if KO, >0 if OK
function delete($user) */
{ function delete($user)
$error=0; {
$error=0;
$this->db->begin(); $this->db->begin();
// Get bank transaction lines for this social contributions // Get bank transaction lines for this social contributions
include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
$account=new Account($this->db); $account=new Account($this->db);
$lines_url=$account->get_url('',$this->id,'sc'); $lines_url=$account->get_url('',$this->id,'sc');
// Delete bank urls // Delete bank urls
@ -177,222 +187,289 @@ class ChargeSociales extends CommonObject
// Delete payments // Delete payments
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'";
dol_syslog(get_class($this)."::delete sql=".$sql); dol_syslog(get_class($this)."::delete sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
} }
} }
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'";
dol_syslog(get_class($this)."::delete sql=".$sql); dol_syslog(get_class($this)."::delete sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
} }
} }
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Met a jour une charge sociale * Met a jour une charge sociale
* @param user Utilisateur qui modifie *
* @return int <0 si erreur, >0 si ok * @param User $user Utilisateur qui modifie
*/ * @return int <0 si erreur, >0 si ok
function update($user) */
{ function update($user)
$this->db->begin(); {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
$sql.= " SET libelle='".$this->db->escape($this->lib)."',"; $sql.= " SET libelle='".$this->db->escape($this->lib)."',";
$sql.= " date_ech='".$this->db->idate($this->date_ech)."',"; $sql.= " date_ech='".$this->db->idate($this->date_ech)."',";
$sql.= " periode='".$this->db->idate($this->periode)."'"; $sql.= " periode='".$this->db->idate($this->periode)."'";
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
dol_syslog("ChargesSociales::update sql=".$sql); dol_syslog(get_class($this)."::update sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
/**
* Enter description here ...
*
* @param int $year Year
* @return number
*/
function solde($year = 0)
{
$sql = "SELECT sum(f.amount) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0";
if ($year) {
$sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
}
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
return $obj->amount;
}
else
{
return 0;
}
$this->db->free($result);
}
else
{
print $this->db->error();
return -1;
}
}
/**
* Tag social contribution as payed completely
*
* @param User $user Object user making change
* @return int <0 if KO, >0 if OK
*/
function set_paid($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
$sql.= " set paye=1";
$sql.= " WHERE rowid = ".$this->id;
$return = $this->db->query($sql);
if ($return) return 1;
else return -1;
}
/**
* Retourne le libelle du statut d'une charge (impaye, payee)
*
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
* @return string Label
*/
function getLibStatut($mode=0)
{
return $this->LibStatut($this->paye,$mode);
}
/**
* Renvoi le libelle d'un statut donne
*
* @param int $statut Id statut
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Label
*/
function LibStatut($statut,$mode=0)
{
global $langs;
$langs->load('customers');
if ($mode == 0)
{
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 1)
{
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 2)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 3)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
}
if ($mode == 4)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 5)
{
if ($statut == 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
}
return "Error, mode/status not found";
}
function solde($year = 0) /**
{ * Renvoie nom clicable (avec eventuellement le picto)
$sql = "SELECT sum(f.amount) as amount"; *
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0"; * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
* @param int $maxlen Longueur max libelle
* @return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$maxlen=0)
{
global $langs;
if ($year) { $result='';
$sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
}
$result = $this->db->query($sql); if (empty($this->ref)) $this->ref=$this->lib;
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
return $obj->amount;
} else {
return 0;
}
$this->db->free(); $lien = '<a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$this->id.'">';
$lienfin='</a>';
} else { if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution").': '.$this->lib,'bill').$lienfin.' ');
print $this->db->error(); if ($withpicto && $withpicto != 2) $result.=' ';
return -1; if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin;
} return $result;
} }
/** /**
* Tag social contribution as payed completely * Return amount of payments already done
* @param user Object user making change *
*/ * @return int Amount of payment already done, <0 if KO
function set_paid($user) */
{ function getSommePaiement()
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; {
$sql.= " set paye=1"; $table='paiementcharge';
$sql.= " WHERE rowid = ".$this->id; $field='fk_charge';
$return = $this->db->query($sql);
if ($return) return 1;
else return -1;
}
/** $sql = 'SELECT sum(amount) as amount';
* \brief Retourne le libelle du statut d'une charge (impaye, payee) $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long $sql.= ' WHERE '.$field.' = '.$this->id;
* \return string Libelle
*/
function getLibStatut($mode=0)
{
return $this->LibStatut($this->paye,$mode);
}
/** dol_syslog(get_class($this)."::getSommePaiement sql=".$sql, LOG_DEBUG);
* \brief Renvoi le libelle d'un statut donne $resql=$this->db->query($sql);
* \param statut Id statut if ($resql)
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto {
* \return string Libelle du statut $amount=0;
*/
function LibStatut($statut,$mode=0)
{
global $langs;
$langs->load('customers');
if ($mode == 0) $obj = $this->db->fetch_object($resql);
{ if ($obj) $amount=$obj->amount?$obj->amount:0;
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 1)
{
if ($statut == 0) return $langs->trans("Unpaid");
if ($statut == 1) return $langs->trans("Paid");
}
if ($mode == 2)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 3)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
}
if ($mode == 4)
{
if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
}
if ($mode == 5)
{
if ($statut == 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
}
return "Error, mode/status not found"; $this->db->free($resql);
} return $amount;
}
else
{
return -1;
}
}
/**
* Charge les informations d'ordre info dans l'objet entrepot
*
* @param int $id Id of social contribution
* @return int <0 if KO, >0 if OK
*/
function info($id)
{
$sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev";
$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
$sql.= " WHERE e.rowid = ".$id;
/** dol_syslog(get_class($this)."::info sql=".$sql);
* \brief Renvoie nom clicable (avec eventuellement le picto) $result=$this->db->query($sql);
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul if ($result)
* \param maxlen Longueur max libelle {
* \return string Chaine avec URL if ($this->db->num_rows($result))
*/ {
function getNomUrl($withpicto=0,$maxlen=0) $obj = $this->db->fetch_object($result);
{
global $langs;
$result=''; $this->id = $obj->rowid;
if (empty($this->ref)) $this->ref=$this->lib; if ($obj->fk_user_author) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
$lien = '<a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$this->id.'">'; if ($obj->fk_user_valid) {
$lienfin='</a>'; $vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser;
}
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution").': '.$this->lib,'bill').$lienfin.' '); $this->date_creation = $this->db->jdate($obj->datec);
if ($withpicto && $withpicto != 2) $result.=' '; $this->date_modification = $this->db->jdate($obj->datem);
if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; $this->date_validation = $this->db->jdate($obj->datev);
return $result;
}
/** }
* Return amount of payments already done
* @return int Amount of payment already done, <0 if KO
*/
function getSommePaiement()
{
$table='paiementcharge';
$field='fk_charge';
$sql = 'SELECT sum(amount) as amount'; $this->db->free($result);
$sql.= ' FROM '.MAIN_DB_PREFIX.$table;
$sql.= ' WHERE '.$field.' = '.$this->id;
dol_syslog("ChargeSociales::getSommePaiement sql=".$sql, LOG_DEBUG); }
$resql=$this->db->query($sql); else
if ($resql) {
{ dol_print_error($this->db);
$amount=0; }
}
$obj = $this->db->fetch_object($resql);
if ($obj) $amount=$obj->amount?$obj->amount:0;
$this->db->free($resql);
return $amount;
}
else
{
return -1;
}
}
/** /**
* Initialise an instance with random values. * Initialise an instance with random values.

View File

@ -0,0 +1,66 @@
<?php
/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/sociales/info.php
* \ingroup tax
* \brief Page with info about social contribution
*/
require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
$langs->load("compta");
$langs->load("bills");
$id=GETPOST("id");
$action=GETPOST("action");
// Security check
$socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', $langs->trans("SocialContribution"), '', 'charges');
/*
* View
*/
$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
llxHeader("",$langs->trans("SocialContribution"),$help_url);
$chargesociales = new ChargeSociales($db);
$chargesociales->fetch($id);
$chargesociales->info($id);
$head = tax_prepare_head($chargesociales);
dol_fiche_head($head, 'info', $langs->trans("SocialContribution"), 0, 'bill');
print '<table width="100%"><tr><td>';
dol_print_object_info($chargesociales);
print '</td></tr></table>';
print '</div>';
llxFooter();
$db->close();
?>

View File

@ -22,7 +22,7 @@
*/ */
/** /**
* Enter description here... * Prepare array for tabs of warehouses cards
* *
* @param $object * @param $object
* @return array * @return array

View File

@ -24,6 +24,39 @@
*/ */
/**
* Prepare array for tabs of warehouses cards
*
* @param $object
* @return array
*/
function tax_prepare_head($object)
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$object->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'tax');
$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/info.php?id='.$object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
return $head;
}
/** /**
* Look for collectable VAT clients in the chosen year (and month) * Look for collectable VAT clients in the chosen year (and month)
* @param db Database handle * @param db Database handle

View File

@ -30,7 +30,11 @@ ALTER TABLE llx_user ADD COLUMN ref_int varchar(50) AFTER ref_ext;
ALTER TABLE llx_societe MODIFY code_client varchar(24); ALTER TABLE llx_societe MODIFY code_client varchar(24);
ALTER TABLE llx_societe MODIFY code_fournisseur varchar(24); ALTER TABLE llx_societe MODIFY code_fournisseur varchar(24);
ALTER TABLE llx_chargesociales ADD COLUMN tms timestamp;
ALTER TABLE llx_chargesociales ADD COLUMN date_creation datetime;
ALTER TABLE llx_chargesociales ADD COLUMN date_valid datetime;
-- Europe -- Europe
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (1, 'EU4A0', 'Format 4A0', '1682', '2378', 'mm', 1); INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (1, 'EU4A0', 'Format 4A0', '1682', '2378', 'mm', 1);
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (2, 'EU2A0', 'Format 2A0', '1189', '1682', 'mm', 1); INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (2, 'EU2A0', 'Format 2A0', '1189', '1682', 'mm', 1);

View File

@ -23,6 +23,9 @@ create table llx_chargesociales
date_ech datetime NOT NULL, -- date echeance date_ech datetime NOT NULL, -- date echeance
libelle varchar(80) NOT NULL, libelle varchar(80) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp,
date_creation datetime, -- date de creation
date_valid datetime, -- date de validation
fk_type integer NOT NULL, fk_type integer NOT NULL,
amount real default 0 NOT NULL, amount real default 0 NOT NULL,
paye smallint default 0 NOT NULL, paye smallint default 0 NOT NULL,

View File

@ -288,7 +288,7 @@ class Entrepot extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e"; $sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
$sql.= " WHERE e.rowid = ".$id; $sql.= " WHERE e.rowid = ".$id;
dol_syslog("Entrepot::info sql=".$sql); dol_syslog(get_class($this)."::info sql=".$sql);
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
@ -320,7 +320,7 @@ class Entrepot extends CommonObject
} }
else else
{ {
dol_print_error($this->db); dol_print_error($this->db);
} }
} }

View File

@ -50,7 +50,7 @@ print '</td></tr></table>';
print '</div>'; print '</div>';
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>