diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index ead6b12784b..cb697e6cc70 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -245,10 +245,15 @@ if ($conf->tax->enabled) // Date payment print ''.dol_print_date($db->jdate($obj->datep),'day').''; // Type payment - print ''.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.''; + print ''; + if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' '; + print $obj->num_payment.''; // Paid - print ''.price($obj->totalpaye).''; + print ''; + if ($obj->totalpaye) print price($obj->totalpaye); + print ''; print ''; + $total = $total + $obj->total; $totalnb = $totalnb + $obj->nb; $totalpaye = $totalpaye + $obj->totalpaye; diff --git a/htdocs/compta/payment_sc/fiche.php b/htdocs/compta/payment_sc/fiche.php index d502e6e2fc0..fd0df83fc1a 100644 --- a/htdocs/compta/payment_sc/fiche.php +++ b/htdocs/compta/payment_sc/fiche.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 * @@ -37,13 +37,19 @@ $langs->load('banks'); $langs->load('companies'); // Security check -$id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; -$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; +$id=GETPOST("id"); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); if ($user->societe_id) $socid=$user->societe_id; // TODO ajouter regle pour restreindre acces paiement //$result = restrictedArea($user, 'facture', $id,''); -$mesg=''; +$paiement = new PaymentSocialContribution($db); +if ($id > 0) +{ + $result=$paiement->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} /* @@ -51,12 +57,10 @@ $mesg=''; */ // Delete payment -if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->supprimer) +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) { $db->begin(); - $paiement = new PaymentSocialContribution($db); - $paiement->fetch($_REQUEST['id']); $result = $paiement->delete($user); if ($result > 0) { @@ -66,19 +70,19 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && } else { - $mesg='
'.$paiement->error.'
'; + setEventMessage($paiement->error, 'errors'); $db->rollback(); } } // Create payment -if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->creer) +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer) { $db->begin(); - $paiement = new PaymentSocialContribution($db); - $paiement->id = $_REQUEST['id']; - if ($paiement->valide() > 0) + $result=$paiement->valide(); + + if ($result > 0) { $db->commit(); @@ -102,7 +106,7 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && } else { - $mesg='
'.$paiement->error.'
'; + setEventMessage($paiement->error); $db->rollback(); } } @@ -115,14 +119,6 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && llxHeader(); $socialcontrib=new ChargeSociales($db); -$paiement = new PaymentSocialContribution($db); - -$result=$paiement->fetch($_GET['id']); -if ($result <= 0) -{ - dol_print_error($db,'Payment '.$_GET['id'].' not found in database'); - exit; -} $form = new Form($db); @@ -144,7 +140,7 @@ dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), 0, /* * Confirmation de la suppression du paiement */ -if ($_GET['action'] == 'delete') +if ($action == 'delete') { print $form->formconfirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); @@ -153,7 +149,7 @@ if ($_GET['action'] == 'delete') /* * Confirmation de la validation du paiement */ -if ($_GET['action'] == 'valide') +if ($action == 'valide') { $facid = $_GET['facid']; print $form->formconfirm('fiche.php?id='.$paiement->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); @@ -161,9 +157,6 @@ if ($_GET['action'] == 'valide') } -if ($mesg) print $mesg.'
'; - - print ''; // Ref @@ -182,8 +175,7 @@ print ''; // Montant -print ''; - +print ''; // Note print ''; @@ -262,7 +254,7 @@ if ($resql) // Expected to pay print ''; // Status - print ''; + print ''; // Amount payed print ''; print "\n"; @@ -323,7 +315,8 @@ if ($_GET['action'] == '') print ''; -$db->close(); llxFooter(); + +$db->close(); ?> diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index b7d0e39ae6f..99268fe29f8 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * * 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 ''; + print ''; // Status - print ''; + print ''; print ''; print ''; 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 ''; - print ''; + print ''; 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,
'.$langs->trans('Mode').''.$lan print '
'.$langs->trans('Numero').''.$paiement->num_paiement.'
'.$langs->trans('Amount').''.price($paiement->amount).' '.$langs->trans('Currency'.$conf->currency).'
'.$langs->trans('Amount').''.price($paiement->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($paiement->note).'
'.price($objp->sc_amount).''.$socialcontrib->getLibStatut(4).''.$socialcontrib->getLibStatut(4,$objp->amount).''.price($objp->amount).'
'; /* - * 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 ''; - print ''; + print ''; $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 "\n"; - print '\n"; + print '\n"; print ""; $totalpaye += $objp->amount; $i++; @@ -363,7 +357,7 @@ if ($id > 0) print ""; - // Period end date + // Period end date print ""; print "'; + print ''; // Status - print ''; + print ''; print '
'.$langs->trans("Payments").''.$langs->trans("Type").''.$langs->trans("Amount").' 
'.$langs->trans("Amount").' 
".$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("PeriodEndDate").""; if ($action == 'edit') @@ -388,10 +382,10 @@ if ($id > 0) } // Amount - print '
'.$langs->trans("AmountTTC").''.price($object->amount).'
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'; 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).'
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4,$alreadypayed).'
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'.dol_print_date($db->jdate($obj->date_ech), 'day').''.$chargesociale_static->LibStatut($obj->paye,5).''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).'