diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 1bf1b0ec69b..c190fe3398d 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -61,64 +61,64 @@ if ($user->societe_id > 0)
*/
if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement' && $_POST['confirm']=='yes'))
{
- $error = 0;
+ $error = 0;
- $datepaye = dol_mktime(12, 0 , 0,
- $_POST['remonth'],
- $_POST['reday'],
- $_POST['reyear']);
- $paiement_id = 0;
+ $datepaye = dol_mktime(12, 0 , 0,
+ $_POST['remonth'],
+ $_POST['reday'],
+ $_POST['reyear']);
+ $paiement_id = 0;
- // Verifie si des paiements sont superieurs au montant facture
- foreach ($_POST as $key => $value)
- {
- if (substr($key,0,7) == 'amount_')
- {
- $cursorfacid = substr($key,7);
- $amounts[$cursorfacid] = price2num($_POST[$key]);
- $totalpaiement = $totalpaiement + $amounts[$cursorfacid];
- $tmpfacture=new Facture($db);
- $tmpfacture->fetch($cursorfacid);
- $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement());
- if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid])
- {
- $addwarning=1;
- $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
- }
+ // Verifie si des paiements sont superieurs au montant facture
+ foreach ($_POST as $key => $value)
+ {
+ if (substr($key,0,7) == 'amount_')
+ {
+ $cursorfacid = substr($key,7);
+ $amounts[$cursorfacid] = price2num($_POST[$key]);
+ $totalpaiement = $totalpaiement + $amounts[$cursorfacid];
+ $tmpfacture=new Facture($db);
+ $tmpfacture->fetch($cursorfacid);
+ $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement());
+ if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid])
+ {
+ $addwarning=1;
+ $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
+ }
- $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]);
- }
- }
+ $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]);
+ }
+ }
- // Check parameters
- if (! GETPOST('paiementcode'))
- {
- $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
';
- $error++;
- }
+ // Check parameters
+ if (! GETPOST('paiementcode'))
+ {
+ $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
';
+ $error++;
+ }
- if ($conf->banque->enabled)
- {
- // Si module bank actif, un compte est obligatoire lors de la saisie
- // d'un paiement
- if (! $_POST['accountid'])
- {
- $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
- $error++;
- }
- }
+ if ($conf->banque->enabled)
+ {
+ // Si module bank actif, un compte est obligatoire lors de la saisie
+ // d'un paiement
+ if (! $_POST['accountid'])
+ {
+ $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
+ $error++;
+ }
+ }
- if ($totalpaiement == 0)
- {
- $fiche_erreur_message = ''.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'
';
- $error++;
- }
+ if ($totalpaiement == 0)
+ {
+ $fiche_erreur_message = ''.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'
';
+ $error++;
+ }
- if (empty($datepaye))
- {
- $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'
';
- $error++;
- }
+ if (empty($datepaye))
+ {
+ $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'
';
+ $error++;
+ }
}
/*
@@ -126,12 +126,12 @@ if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement
*/
if ($_POST['action'] == 'add_paiement')
{
- if ($error)
- {
- $_POST['action']='';
- $_GET['action'] = 'create';
- }
- // Le reste propre a cette action s'affiche en bas de page.
+ if ($error)
+ {
+ $_POST['action']='';
+ $_GET['action'] = 'create';
+ }
+ // Le reste propre a cette action s'affiche en bas de page.
}
/*
@@ -141,45 +141,45 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
{
$error=0;
- $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- $db->begin();
+ $db->begin();
- // Creation of payment line
- $paiement = new Paiement($db);
- $paiement->datepaye = $datepaye;
- $paiement->amounts = $amounts; // Array with all payments dispatching
- $paiement->paiementid = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement');
- $paiement->num_paiement = $_POST['num_paiement'];
- $paiement->note = $_POST['comment'];
+ // Creation of payment line
+ $paiement = new Paiement($db);
+ $paiement->datepaye = $datepaye;
+ $paiement->amounts = $amounts; // Array with all payments dispatching
+ $paiement->paiementid = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement');
+ $paiement->num_paiement = $_POST['num_paiement'];
+ $paiement->note = $_POST['comment'];
- if (! $error)
- {
- $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
- if ($paiement_id < 0)
- {
- $errmsg=$paiement->error;
- $error++;
- }
- }
+ if (! $error)
+ {
+ $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
+ if ($paiement_id < 0)
+ {
+ $errmsg=$paiement->error;
+ $error++;
+ }
+ }
- if (! $error)
- {
- $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
+ if (! $error)
+ {
+ $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
if ($result < 0)
{
$errmsg=$paiement->error;
$error++;
}
- }
+ }
- if (! $error)
- {
- $db->commit();
+ if (! $error)
+ {
+ $db->commit();
- // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
+ // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
$invoiceid=0;
- foreach ($paiement->amounts as $key => $amount)
+ foreach ($paiement->amounts as $key => $amount)
{
$facid = $key;
if (is_numeric($amount) && $amount <> 0)
@@ -188,15 +188,15 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
else $invoiceid=$facid;
}
}
- if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid;
- else $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
- Header('Location: '.$loc);
- exit;
- }
- else
- {
- $db->rollback();
- }
+ if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid;
+ else $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
+ Header('Location: '.$loc);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ }
}
@@ -211,43 +211,43 @@ $html=new Form($db);
if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_POST['action'] == 'add_paiement')
{
- $facture = new Facture($db);
- $result=$facture->fetch($facid);
+ $facture = new Facture($db);
+ $result=$facture->fetch($facid);
- if ($result >= 0)
- {
- $facture->fetch_thirdparty();
+ if ($result >= 0)
+ {
+ $facture->fetch_thirdparty();
- $title='';
- if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
- if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
- print_fiche_titre($title);
+ $title='';
+ if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
+ if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
+ print_fiche_titre($title);
- if ($errmsg) dol_htmloutput_errors($errmsg);
+ if ($errmsg) dol_htmloutput_errors($errmsg);
- // Bouchon
- if ($facture->type == 2)
- {
- print $langs->trans("FeatureNotYetAvailable");
- llxFooter();
- exit;
- }
+ // Bouchon
+ if ($facture->type == 2)
+ {
+ print $langs->trans("FeatureNotYetAvailable");
+ llxFooter();
+ exit;
+ }
- // Initialize data for confirmation (this is used because data can be change during confirmation)
- if ($_POST["action"] == 'add_paiement')
- {
- $i=0;
+ // Initialize data for confirmation (this is used because data can be change during confirmation)
+ if ($_POST["action"] == 'add_paiement')
+ {
+ $i=0;
- $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
- $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
- $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type);
- }
+ $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
+ $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
+ $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type);
+ }
if ($conf->use_javascript_ajax)
{
print "\n".''."\n";
}
- print '\n";
- }
+ print "\n";
+ }
}
@@ -506,56 +660,56 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P
*/
if (! GETPOST('action'))
{
- if ($page == -1) $page = 0 ;
- $limit = $conf->liste_limit;
- $offset = $limit * $page ;
+ if ($page == -1) $page = 0 ;
+ $limit = $conf->liste_limit;
+ $offset = $limit * $page ;
- if (! $sortorder) $sortorder='DESC';
- if (! $sortfield) $sortfield='p.datep';
+ if (! $sortorder) $sortorder='DESC';
+ if (! $sortfield) $sortfield='p.datep';
- $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.facnumber';
- $sql .=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
- $sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
- if ($socid)
- {
- $sql .= ' AND f.fk_soc = '.$socid;
- }
+ $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.facnumber';
+ $sql .=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
+ $sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
+ if ($socid)
+ {
+ $sql .= ' AND f.fk_soc = '.$socid;
+ }
- $sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
- $sql .= $db->plimit( $limit +1 ,$offset);
- $resql = $db->query($sql);
+ $sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
+ $sql .= $db->plimit( $limit +1 ,$offset);
+ $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
- $var=True;
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $var=True;
- print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num);
- print '';
- print '';
- print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','','','',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Amount'),'paiement.php','fa_amount','','','align="right"',$sortfield,$sortorder);
- print '| | ';
- print "
\n";
+ print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num);
+ print '';
+ print '';
+ print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','','','',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Amount'),'paiement.php','fa_amount','','','align="right"',$sortfield,$sortorder);
+ print '| | ';
+ print "
\n";
- while ($i < min($num,$limit))
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
- print '';
- print '| '.$objp->facnumber." | \n";
- print ''.dol_print_date($db->jdate($objp->dp))." | \n";
- print ''.$objp->paiement_type.' '.$objp->num_paiement." | \n";
- print ''.price($objp->amount).' | | ';
- print '
';
- $i++;
- }
- print '
';
- }
+ while ($i < min($num,$limit))
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+ print '';
+ print '| '.$objp->facnumber." | \n";
+ print ''.dol_print_date($db->jdate($objp->dp))." | \n";
+ print ''.$objp->paiement_type.' '.$objp->num_paiement." | \n";
+ print ''.price($objp->amount).' | | ';
+ print '
';
+ $i++;
+ }
+ print '
';
+ }
}
$db->close();