*
* This program is free software; you can redistribute it and/or modify
@@ -32,6 +32,7 @@ $langs->load("bills");
$id=GETPOST('id','int');
$action=GETPOST("action");
+$confirm=GETPOST('confirm');
// Security check
$socid = GETPOST('socid','int');
@@ -47,20 +48,16 @@ $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
/* */
/* *************************************************************************** */
-/*
- * Classify paid
- */
-if ($action == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
+// 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' && $_REQUEST["confirm"] == 'yes')
+// Delete social contribution
+if ($action == 'confirm_delete' && $confirm == 'yes')
{
$chargesociales=new ChargeSociales($db);
$chargesociales->fetch($id);
@@ -77,10 +74,7 @@ if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
}
-/*
- * Add social contribution
- */
-
+// 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"]);
@@ -303,8 +297,8 @@ if ($id > 0)
print '';
/*
- * Paiements
- */
+ * Paiements
+ */
$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";
@@ -325,7 +319,7 @@ if ($id > 0)
echo '';
print '';
print '| '.$langs->trans("Payments").' | '.$langs->trans("Type").' | ';
- print ''.$langs->trans("Amount").' | | ';
+ print ''.$langs->trans("Amount").' | | ';
$var=True;
while ($i < $num)
@@ -336,7 +330,7 @@ if ($id > 0)
print ''.img_object($langs->trans("Payment"),"payment").' ';
print dol_print_date($db->jdate($objp->dp),'day')."\n";
print "".$objp->paiement_type.' '.$objp->num_paiement." | \n";
- print ''.price($objp->amount)." | ".$langs->trans("Currency".$conf->currency)." | \n";
+ print ''.price($objp->amount)." | ".$langs->trans("Currency".$conf->currency)." | \n";
print "";
$totalpaye += $objp->amount;
$i++;
@@ -363,7 +357,7 @@ if ($id > 0)
print "";
- // Period end date
+ // Period end date
print "| ".$langs->trans("PeriodEndDate")." | ";
print "";
if ($action == 'edit')
@@ -388,10 +382,10 @@ if ($id > 0)
}
// Amount
- print ' | | '.$langs->trans("AmountTTC").' | '.price($object->amount).' | ';
+ print '| '.$langs->trans("AmountTTC").' | '.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).' | ';
// Status
- print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' | ';
+ print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4, $totalpaye).' | ';
print ' ';
diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php
index 4efd90c10aa..8693ff31b70 100644
--- a/htdocs/compta/sociales/class/chargesociales.class.php
+++ b/htdocs/compta/sociales/class/chargesociales.class.php
@@ -102,7 +102,7 @@ class ChargeSociales extends CommonObject
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
return -1;
}
}
@@ -317,28 +317,31 @@ class ChargeSociales extends CommonObject
}
/**
- * Retourne le libelle du statut d'une charge (impaye, payee)
+ * 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
+ * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
+ * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
+ * @return string Label
*/
- function getLibStatut($mode=0)
+ function getLibStatut($mode=0,$alreadypayed=-1)
{
- return $this->LibStatut($this->paye,$mode);
+ return $this->LibStatut($this->paye,$mode,$alreadypayed);
}
/**
- * Renvoi le libelle d'un statut donne
+ * 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
+ * @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
+ * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
+ * @return string Label
*/
- function LibStatut($statut,$mode=0)
+ function LibStatut($statut,$mode=0,$alreadypayed=-1)
{
global $langs;
$langs->load('customers');
-
+ $langs->load('bills');
+
if ($mode == 0)
{
if ($statut == 0) return $langs->trans("Unpaid");
@@ -361,12 +364,14 @@ class ChargeSociales extends CommonObject
}
if ($mode == 4)
{
- if ($statut == 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
+ if ($statut == 0 && $alreadypayed <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
+ if ($statut == 0 && $alreadypayed > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
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 == 0 && $alreadypayed <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
+ if ($statut == 0 && $alreadypayed > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
}
diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php
index 88c888de62e..0647f0986d8 100644
--- a/htdocs/compta/sociales/document.php
+++ b/htdocs/compta/sociales/document.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2010 Laurent Destailleur
+ * Copyright (C) 2004-2014 Laurent Destailleur
* Copyright (C) 2005 Marc Barilley / Ocebo
* Copyright (C) 2005-2009 Regis Houssin
* Copyright (C) 2005 Simon TOSSER
@@ -63,7 +63,7 @@ if (! $sortfield) $sortfield="name";
$object = new ChargeSociales($db);
-$object->fetch($id);
+if ($id > 0) $object->fetch($id);
$upload_dir = $conf->tax->dir_output.'/'.dol_sanitizeFileName($object->ref);
$modulepart='tax';
@@ -87,6 +87,8 @@ llxHeader("",$langs->trans("SocialContribution"),$help_url);
if ($object->id)
{
+ $alreadypayed=$object->getSommePaiement();
+
$head=tax_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill');
@@ -149,10 +151,10 @@ if ($object->id)
}
// Amount
- print '| '.$langs->trans("AmountTTC").' | '.price($object->amount).' | ';
+ print '| '.$langs->trans("AmountTTC").' | '.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).' | ';
// Status
- print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' | ';
+ print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4,$alreadypayed).' | ';
print '| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ';
print '| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' | ';
diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php
index 6ccc9943afa..89e2f84d7fb 100644
--- a/htdocs/compta/sociales/index.php
+++ b/htdocs/compta/sociales/index.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2010 Laurent Destailleur
+ * Copyright (C) 2004-2014 Laurent Destailleur
* Copyright (C) 2005-2009 Regis Houssin
*
* This program is free software; you can redistribute it and/or modify
@@ -78,12 +78,14 @@ llxHeader();
$sql = "SELECT cs.rowid as id, cs.fk_type as type, ";
$sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,";
-$sql.= " c.libelle as type_lib";
-$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
-$sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
+$sql.= " c.libelle as type_lib,";
+$sql.= " SUM(pc.amount) as alreadypayed";
+$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
+$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
$sql.= " WHERE cs.fk_type = c.id";
$sql.= " AND cs.entity = ".$conf->entity;
-if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".GETPOST("search_label")."%'";
+if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".$db->escape(GETPOST("search_label"))."%'";
if ($year > 0)
{
$sql .= " AND (";
@@ -100,6 +102,7 @@ if ($filtre) {
if ($typeid) {
$sql .= " AND cs.fk_type=".$typeid;
}
+$sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle";
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1,$offset);
@@ -207,7 +210,7 @@ if ($resql)
// Due date
print ''.dol_print_date($db->jdate($obj->date_ech), 'day').' | ';
- print ''.$chargesociale_static->LibStatut($obj->paye,5).' | ';
+ print ''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).' | ';
print '';
$i++;
diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
index 397a4896a54..31a3b593fb1 100644
--- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
+++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
@@ -1094,3 +1094,5 @@ ALTER TABLE llx_societe ADD INDEX idx_societe_barcode (barcode);
ALTER TABLE llx_societe ADD UNIQUE INDEX uk_societe_barcode (barcode, fk_barcode_type, entity);
+ALTER TABLE llx_tva ADD COLUMN fk_typepayment integer NULL; -- table may already contains data
+ALTER TABLE llx_tva ADD COLUMN num_payment varchar(50);
diff --git a/htdocs/install/mysql/tables/llx_tva.sql b/htdocs/install/mysql/tables/llx_tva.sql
index 98d0ca6d575..c5b1542198c 100644
--- a/htdocs/install/mysql/tables/llx_tva.sql
+++ b/htdocs/install/mysql/tables/llx_tva.sql
@@ -24,6 +24,8 @@ create table llx_tva
datep date, -- date de paiement
datev date, -- date de valeur
amount real NOT NULL DEFAULT 0,
+ fk_typepayment integer NULL,
+ num_payment varchar(50),
label varchar(255),
entity integer DEFAULT 1 NOT NULL, -- multi company id
note text,
|