2
0
forked from Wavyzz/dolibarr

Qual: Uniformizing payments

This commit is contained in:
Laurent Destailleur
2014-03-26 15:41:09 +01:00
parent 59042a30e1
commit c45f509984
8 changed files with 82 additions and 76 deletions

View File

@@ -245,10 +245,15 @@ if ($conf->tax->enabled)
// Date payment
print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day').'</td>';
// Type payment
print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
print $obj->num_payment.'</td>';
// Paid
print '<td align="right">'.price($obj->totalpaye).'</td>';
print '<td align="right">';
if ($obj->totalpaye) print price($obj->totalpaye);
print '</td>';
print '</tr>';
$total = $total + $obj->total;
$totalnb = $totalnb + $obj->nb;
$totalpaye = $totalpaye + $obj->totalpaye;

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
*
@@ -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='<div class="error">'.$paiement->error.'</div>';
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='<div class="error">'.$paiement->error.'</div>';
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.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
@@ -161,9 +157,6 @@ if ($_GET['action'] == 'valide')
}
if ($mesg) print $mesg.'<br>';
print '<table class="border" width="100%">';
// Ref
@@ -182,8 +175,7 @@ print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$lan
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->num_paiement.'</td></tr>';
// Montant
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->amount).'&nbsp;'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($paiement->note).'</td></tr>';
@@ -262,7 +254,7 @@ if ($resql)
// Expected to pay
print '<td align="right">'.price($objp->sc_amount).'</td>';
// Status
print '<td align="center">'.$socialcontrib->getLibStatut(4).'</td>';
print '<td align="center">'.$socialcontrib->getLibStatut(4,$objp->amount).'</td>';
// Amount payed
print '<td align="right">'.price($objp->amount).'</td>';
print "</tr>\n";
@@ -323,7 +315,8 @@ if ($_GET['action'] == '')
print '</div>';
$db->close();
llxFooter();
$db->close();
?>

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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 '<td rowspan="'.$rowspan.'" valign="top">';
/*
* 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 '<table class="nobordernopadding" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Payments").'</td><td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Amount").'</td><td>&nbsp;</td></tr>';
print '<td align="right">'.$langs->trans("Amount").'</td><td>&nbsp;</td></tr>';
$var=True;
while ($i < $num)
@@ -336,7 +330,7 @@ if ($id > 0)
print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").'</a> ';
print dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
print "<td>".$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print "</tr>";
$totalpaye += $objp->amount;
$i++;
@@ -363,7 +357,7 @@ if ($id > 0)
print "</tr>";
// Period end date
// Period end date
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
print "<td>";
if ($action == 'edit')
@@ -388,10 +382,10 @@ if ($id > 0)
}
// Amount
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount).'</td></tr>';
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
print '</table>';

View File

@@ -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');
}

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
@@ -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 '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount).'</td></tr>';
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4,$alreadypayed).'</td></tr>';
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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 '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
print '<td align="right" class="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5).'</a></td>';
print '<td align="right" class="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).'</a></td>';
print '</tr>';
$i++;

View File

@@ -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);

View File

@@ -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,