From f12075a0283c91d8125c8e6a3011f37e19a3322a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 18 May 2011 18:38:12 +0000 Subject: [PATCH] Try to add a patch but keep it with a condition because of several problems. --- htdocs/compta/paiement.php | 870 ++++++++++++++++++++++--------------- 1 file changed, 512 insertions(+), 358 deletions(-) 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 '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; - print ''; + print '
'; - // Third party - print '\n"; + // Third party + print '\n"; - // Date payment - print ''; - print ''; + // Date payment + print ''; + print ''; - print '\n"; + $rowspan=5; + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) $rowspan++; - print ''; + // Payment mode + print '\n"; + print ''; + print ''; - print ''; - if ($conf->banque->enabled) - { - if ($facture->type != 2) print ''; - if ($facture->type == 2) print ''; - print ''; - } - else - { - print ''; - } - print "\n"; + // Payment amount + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) + { + print ''; + print ''; + print ''; + } - print ''; - print ''; + print ''; + if ($conf->banque->enabled) + { + if ($facture->type != 2) print ''; + if ($facture->type == 2) print ''; + print ''; + } + else + { + print ''; + } + print "\n"; - // Check transmitter - print ''; - print ''; + // Cheque number + print ''; + print ''; - print ''; - print ''; + // Check transmitter + print ''; + print ''; - print '
'.$langs->trans('Company').''.$facture->client->getNomUrl(4)."
'.$langs->trans('Company').''.$facture->client->getNomUrl(4)."
'.$langs->trans('Date').''; - $datepayment = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $datepayment= ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0) : $datepayment); - $html->select_date($datepayment,'','','',0,"add_paiement",1,1); - print ''.$langs->trans('Comments').'
'.$langs->trans('Date').''; + $datepayment = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datepayment= ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0) : $datepayment); + $html->select_date($datepayment,'','','',0,"add_paiement",1,1); + print ''.$langs->trans('Comments').'
'.$langs->trans('PaymentMode').''; - $html->select_types_paiements(GETPOST('paiementcode'),'paiementcode','',2); - print "'; - print '
'.$langs->trans('PaymentMode').''; + $html->select_types_paiements(GETPOST('paiementcode'),'paiementcode','',2); + print "'; + print '
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; - $html->select_comptes(GETPOST('accountid'),'accountid',0,'',2); - print ' 
'.$langs->trans('AmountPayment').''; + if ($_POST["action"] == 'add_paiement') + { + print ''; + print ''; + } + else + { + print ''; + } + print '
'.$langs->trans('Numero'); - print ' ('.$langs->trans("ChequeOrTransferNumber").')'; - print '
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; + $html->select_comptes(GETPOST('accountid'),'accountid',0,'',2); + print ' 
'.$langs->trans('CheckTransmitter'); - print ' ('.$langs->trans("ChequeMaker").')'; - print '
'.$langs->trans('Numero'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'.$langs->trans('Bank'); - print ' ('.$langs->trans("ChequeBank").')'; - print '
'.$langs->trans('CheckTransmitter'); + print ' ('.$langs->trans("ChequeMaker").')'; + print '
'; + // Bank name + print ''.$langs->trans('Bank'); + print ' ('.$langs->trans("ChequeBank").')'; + print ''; + print ''; - /* - * List of unpaid invoices - */ - $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, '; - $sql.= ' f.datef as df'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' WHERE f.fk_soc = '.$facture->socid; - $sql.= ' AND f.paye = 0'; - $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled - if ($facture->type != 2) - { - $sql .= ' AND type in (0,1,3)'; // Standard invoice, replacement, deposit - } - else - { - $sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes - } + print ''; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num > 0) - { + /* + * List of unpaid invoices + */ + $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, '; + $sql.= ' f.datef as df'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; + $sql.= ' WHERE f.fk_soc = '.$facture->socid; + $sql.= ' AND f.paye = 0'; + $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled + if ($facture->type != 2) + { + $sql .= ' AND type in (0,1,3)'; // Standard invoice, replacement, deposit + } + else + { + $sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes + } - $i = 0; - //print ''; - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) + { - $var=True; - $total=0; - $totalrecu=0; - $totalrecucreditnote=0; - $totalrecudeposits=0; + $i = 0; + //print '\n"; - } - $db->free($resql); - } - else - { - dol_print_error($db); - } + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$paiement; + $totalrecucreditnote+=$creditnotes; + $totalrecudeposits+=$deposits; + $i++; + } + if ($i > 1) + { + // Print total + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + print "
'.$langs->trans('Invoice').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('Received').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').' 
'; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; + // FIXME Does not work yet because : + // - Does not support non , and non . decimal separator. + // - Does not use dolibarr param rounding + // - Other minor bugs + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) + { + print ''; + } + + $var=True; + $total=0; + $totalrecu=0; + $totalrecucreditnote=0; + $totalrecudeposits=0; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + $invoice=new Facture($db); + $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); - $creditnotes=$invoice->getSumCreditNotesUsed(); - $deposits=$invoice->getSumDepositsUsed(); + $creditnotes=$invoice->getSumCreditNotesUsed(); + $deposits=$invoice->getSumDepositsUsed(); $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); - print ''; + print ''; - print '\n"; + print '\n"; - // Date - print '\n"; + // Date + print '\n"; - // Prix - print ''; + // Prix + print ''; - // Recu - print ''; + // Recu + print ''; - // Remain to pay - print ''; + // Remain to pay + print ''; + $test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); - // Amount - print '"; + // Amount + print ''; + // Add remind amount + $namef = 'amount_'.$objp->facid; + + $namef = 'amount_'.$objp->facid; + if ($_POST["action"] != 'add_paiement') + { + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) + { + print img_picto($langs->trans('AddRemind'),'rightarrow.png','id="calcRemind'.$i.'" onclick="calcRemind(\''.$i.'\');return false;"'); + print ''; + } + print ''; + } + else + { + print ''; + print ''; + } + print ""; + + // Warning + print ''; - print "\n"; + print "\n"; - $total+=$objp->total; - $total_ttc+=$objp->total_ttc; - $totalrecu+=$paiement; - $totalrecucreditnote+=$creditnotes; - $totalrecudeposits+=$deposits; - $i++; - } - if ($i > 1) - { - // Print total - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - print "
'.$langs->trans('Invoice').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('Received').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').' 
'; - print $invoice->getNomUrl(1,''); - print "'; + print $invoice->getNomUrl(1,''); + print "'.dol_print_date($db->jdate($objp->df),'day')."'.dol_print_date($db->jdate($objp->df),'day')."'.price($objp->total_ttc).''.price($objp->total_ttc).''.price($paiement); - if ($creditnotes) print '+'.price($creditnotes); - if ($deposits) print '+'.price($deposits); - print ''.price($paiement); + if ($creditnotes) print '+'.price($creditnotes); + if ($deposits) print '+'.price($deposits); + print ''.price($remaintopay).''.price($remaintopay).''; - $namef = 'amount_'.$objp->facid; - if ($_POST["action"] != 'add_paiement') - { - print ''; - } - else - { - print ''; - print ''; - } - print "'; - // Warning - print ''; - if ($amounts[$invoice->id] && $amounts[$invoice->id] > $amountsresttopay[$invoice->id]) - { - print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); - } - print ''; + if ($amounts[$invoice->id] && $amounts[$invoice->id] > $amountsresttopay[$invoice->id]) + { + print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); + } + print '
'.$langs->trans('TotalTTC').''.price($total_ttc).''.price($totalrecu); - if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); - if ($totalrecudeposits) print '+'.price($totalrecudeposits); - print ''.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'  
"; - //print "
'.$langs->trans('TotalTTC').''.price($total_ttc).''.price($totalrecu); + if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); + if ($totalrecudeposits) print '+'.price($totalrecudeposits); + print ''.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).' 
"; + //print "\n"; + } + $db->free($resql); + } + else + { + dol_print_error($db); + } - // Bouton Enregistrer - if ($_POST["action"] != 'add_paiement') - { - // print ''; - print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); - print '
'; - // print ''; - } + // Bouton Enregistrer + if ($_POST["action"] != 'add_paiement') + { + // print ''; + print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); + print '
'; + // print ''; + } - // Message d'erreur - if ($fiche_erreur_message) - { - print $fiche_erreur_message; - } + // Message d'erreur + if ($fiche_erreur_message) + { + print $fiche_erreur_message; + } - // Form to confirm payment - if ($_POST["action"] == 'add_paiement') - { - $preselectedchoice=$addwarning?'no':'yes'; + // Form to confirm payment + if ($_POST["action"] == 'add_paiement') + { + $preselectedchoice=$addwarning?'no':'yes'; - print '
'; - $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->monnaie)); - if (GETPOST('closepaidinvoices')) - { - $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); - print ''; - } - $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice); - } + print '
'; + $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->monnaie)); + if (GETPOST('closepaidinvoices')) + { + $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); + print ''; + } + $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice); + } - 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 '\n"; - print '\n"; - print '\n"; - print ''; - print ''; - $i++; - } - print '
 
'.$objp->facnumber."'.dol_print_date($db->jdate($objp->dp))."'.$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount).' 
'; - } + 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();