* Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * Copyright (C) 2015 Marcos GarcĂ­a * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2017 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/fourn/facture/paiement.php * \ingroup fournisseur,facture * \brief Payment page for suppliers invoices */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->load('companies'); $langs->load('bills'); $langs->load('banks'); $langs->load('compta'); // Security check $action = GETPOST('action','alpha'); $confirm = GETPOST('confirm'); $facid = GETPOST('facid','int'); $socid = GETPOST('socid','int'); $accountid = GETPOST('accountid'); $day = GETPOST('day','int'); $month = GETPOST('month','int'); $year = GETPOST('year','int'); $search_ref=GETPOST("search_ref","int"); $search_account=GETPOST("search_account","int"); $search_paymenttype=GETPOST("search_paymenttype"); $search_amount=GETPOST("search_amount",'alpha'); // alpha because we must be able to search on "< x" $search_company=GETPOST("search_company",'alpha'); $search_payment_num=GETPOST('search_payment_num','alpha'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.rowid"; $optioncss = GETPOST('optioncss','alpha'); $amounts = array();array(); $amountsresttopay=array(); $addwarning=0; $multicurrency_amounts=array(); $multicurrency_amountsresttopay=array(); // Security check if ($user->societe_id > 0) { $socid = $user->societe_id; } // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('paymentsupplier')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label('paymentsupplier'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); $arrayfields=array(); /* * Actions */ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers { $search_ref=""; $search_account=""; $search_amount=""; $search_paymenttype=""; $search_payment_num=""; $search_company=""; $day=''; $year=''; $month=''; $search_array_options=array(); } $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error = 0; $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $paiement_id = 0; $totalpayment = 0; $atleastonepaymentnotnull = 0; // Generate payment array and check if there is payment higher than invoice and payment date before invoice date $tmpinvoice=new FactureFournisseur($db); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') { $cursorfacid = substr($key,7); $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); $totalpayment = $totalpayment + $amounts[$cursorfacid]; if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; $result=$tmpinvoice->fetch($cursorfacid); if ($result <= 0) dol_print_error($db); $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); if ($amounts[$cursorfacid]) { // Check amount if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) { $addwarning=1; $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); } // Check date if ($datepaye && ($datepaye < $tmpinvoice->date)) { $langs->load("errors"); //$error++; setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); } } $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); } elseif (substr($key,0,21) == 'multicurrency_amount_') { $cursorfacid = substr($key,21); $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key))); $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++; $result=$tmpinvoice->fetch($cursorfacid); if ($result <= 0) dol_print_error($db); $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1)); if ($multicurrency_amounts[$cursorfacid]) { // Check amount if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) { $addwarning=1; $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); } // Check date if ($datepaye && ($datepaye < $tmpinvoice->date)) { $langs->load("errors"); //$error++; setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); } } $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => GETPOST($key, 'int')); } } // Check parameters if ($_POST['paiementid'] <= 0) { setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), null, 'errors'); $error++; } if (! empty($conf->banque->enabled)) { // If bank module is on, account is required to enter a payment if (GETPOST('accountid') <= 0) { setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors'); $error++; } } if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) { setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors'); $error++; } if (empty($datepaye)) { setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors'); $error++; } // Check if payments in both currency if ($totalpayment > 0 && $multicurrency_totalpayment > 0) { setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors'); $error++; } } /* * Action add_paiement */ if ($action == 'add_paiement') { if ($error) { $action = 'create'; } // Le reste propre a cette action s'affiche en bas de page. } /* * Action confirm_paiement */ if ($action == 'confirm_paiement' && $confirm == 'yes') { $error=0; $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); if (! $error) { $db->begin(); // Creation de la ligne paiement $paiement = new PaiementFourn($db); $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array of amounts $paiement->multicurrency_amounts = $multicurrency_amounts; $paiement->paiementid = $_POST['paiementid']; $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) { setEventMessages($paiement->error, $paiement->errors, 'errors'); $error++; } } if (! $error) { $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$accountid,'',''); if ($result < 0) { setEventMessages($paiement->error, $paiement->errors, 'errors'); $error++; } } if (! $error) { $db->commit(); // 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) { $facid = $key; if (is_numeric($amount) && $amount <> 0) { if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment else $invoiceid=$facid; } } if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid; else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id; header('Location: '.$loc); exit; } else { $db->rollback(); } } } } /* * View */ $supplierstatic=new Societe($db); $invoicesupplierstatic = new FactureFournisseur($db); llxHeader('',$langs->trans('ListPayment')); $form=new Form($db); $formother=new FormOther($db); if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { $object = new FactureFournisseur($db); $result = $object->fetch($facid); $datefacture=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datefacture); $sql = 'SELECT s.nom as name, s.rowid as socid,'; $sql.= ' f.rowid, f.ref, f.ref_supplier, f.amount, f.total_ttc as total, f.fk_mode_reglement, f.fk_account'; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f'; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ' WHERE f.fk_soc = s.rowid'; $sql.= ' AND f.rowid = '.$facid; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { $obj = $db->fetch_object($resql); $total = $obj->total; print load_fiche_titre($langs->trans('DoPayment')); // Add realtime total information if (! empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; dol_fiche_head(null); print ''; print ''; print ''; print ''; if (! empty($conf->banque->enabled)) { print ''; } else { print ''; } print ''; print ''; print ''; print '
'.$langs->trans('Company').''; $supplierstatic->id=$obj->socid; $supplierstatic->name=$obj->name; print $supplierstatic->getNomUrl(1,'supplier'); print '
'.$langs->trans('Date').''; $form->select_date($dateinvoice,'','','','',"addpaiement",1,1,0,0,'','',$object->date); print '
'.$langs->trans('PaymentMode').''; $form->select_types_paiements(empty($_POST['paiementid'])?$obj->fk_mode_reglement:$_POST['paiementid'],'paiementid'); print '
'.$langs->trans('Account').''; $form->select_comptes(empty($accountid)?$obj->fk_account:$accountid,'accountid',0,'',2); print '
 
'.$langs->trans('Numero').'
'.$langs->trans('Comments').''; print '
'; dol_fiche_end(); $parameters=array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('paymentsupplierinvoices',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; if (empty($reshook)) { /* * Autres factures impayees */ $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df,'; $sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; $sql.= " WHERE f.entity = ".$conf->entity; $sql.= ' AND f.fk_soc = '.$object->socid; $sql.= ' AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee $sql.= ' GROUP BY f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef'; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num > 0) { $sign=1; if ($object->type == 2) $sign=-1; $i = 0; print '
'; if (!empty($conf->use_javascript_ajax)){ //Add js for AutoFill print "\n".''."\n"; } print '
'; print ''."\n"; print ''; print ''; print ''; print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; print ''; print ''; print ''; print ''; if (!empty($conf->multicurrency->enabled)) print ''; print ''; $total=0; $total_ttc=0; $totalrecu=0; while ($i < $num) { $objp = $db->fetch_object($resql); $invoice=new FactureFournisseur($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); $creditnotes=$invoice->getSumCreditNotesUsed(); $deposits=$invoice->getSumDepositsUsed(); $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); // Multicurrency Price if (!empty($conf->multicurrency->enabled)) { $multicurrency_payment = $invoice->getSommePaiement(1); $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1); $multicurrency_deposits=$invoice->getSumDepositsUsed(1); $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT'); $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT'); } print ''; // Ref print ''; // Ref supplier print ''; // Date if ($objp->df > 0 ) { print ''; } else { print ''; } // Multicurrency if (!empty($conf->multicurrency->enabled)) { // Currency print '\n"; print ''; print ''; print ''; } print ''; print ''; print ''; // Amount print '"; // Multicurrency Price if (! empty($conf->multicurrency->enabled)) { print '"; } print "\n"; $total+=$objp->total_ht; $total_ttc+=$objp->total_ttc; $totalrecu+=$objp->am; $totalrecucreditnote+=$creditnotes; $totalrecudeposits+=$deposits; $i++; } if ($i > 1) { // Print total print ''; print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; if (!empty($conf->multicurrency->enabled)) print ''; print ''; print ''; print ''; print ''; // Autofilled if (!empty($conf->multicurrency->enabled)) print ''; print "\n"; } print "
'.$langs->trans('Invoice').''.$langs->trans('RefSupplier').''.$langs->trans('Date').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$langs->trans('MulticurrencyAlreadyPaid').''.$langs->trans('MulticurrencyRemainderToPay').''.$langs->trans('AmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').''.$langs->trans('MulticurrencyPaymentAmount').'
'; $invoicesupplierstatic->ref=$objp->ref; $invoicesupplierstatic->id=$objp->facid; print $invoicesupplierstatic->getNomUrl(1); print ''.$objp->ref_supplier.''; print dol_print_date($db->jdate($objp->df), 'day').'!!!'.$objp->multicurrency_code."'; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($objp->multicurrency_total_ttc); } print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($objp->multicurrency_am); } print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($objp->multicurrency_total_ttc - $objp->multicurrency_am); } print ''.price($objp->total_ttc).''.price($objp->am); if ($creditnotes) print '+'.price($creditnotes); if ($deposits) print '+'.price($deposits); print ''.price($remaintopay).''; $namef = 'amount_'.$objp->facid; $nameRemain = 'remain_'.$objp->facid; if ($action != 'add_paiement') { if (!empty($conf->use_javascript_ajax)) print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'"); print ''; print ''; } else { print ''; print ''; } print "'; // Add remind multicurrency amount $namef = 'multicurrency_amount_'.$objp->facid; $nameRemain = 'multicurrency_remain_'.$objp->facid; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { if ($action != 'add_paiement') { if (!empty($conf->use_javascript_ajax)) print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'"); print ''; print ''; } else { print ''; print ''; } } 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')).'
\n"; print "
"; } $db->free($resql); } else { dol_print_error($db); } } // Bouton Enregistrer if ($action != 'add_paiement') { print '
'.$langs->trans("ClosePaidInvoicesAutomatically"); print '
'; } // Form to confirm payment if ($action == 'add_paiement') { $preselectedchoice=$addwarning?'no':'yes'; print '
'; if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',price($totalpayment),$langs->trans("Currency".$conf->currency)); if (!empty($multicurrency_totalpayment)) { $text.='
'.$langs->trans('ConfirmSupplierPayment',price($multicurrency_totalpayment),$langs->trans("paymentInInvoiceCurrency")); } if (GETPOST('closepaidinvoices')) { $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); print ''; } print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('PayedSuppliersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice); } print '
'; } } else dol_print_error($db); } /* * Show list */ if (empty($action)) { $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page=GETPOST("page",'int'); if ($page == -1 || $page == null) { $page = 0 ; } $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder='DESC'; if (! $sortfield) $sortfield='p.datep'; $sql = 'SELECT p.rowid as pid, p.datep as dp, p.amount as pamount, p.num_paiement,'; $sql.= ' s.rowid as socid, s.nom as name,'; $sql.= ' c.code as paiement_type, c.libelle as paiement_libelle,'; $sql.= ' ba.rowid as bid, ba.label,'; if (!$user->rights->societe->client->voir) $sql .= ' sc.fk_soc, sc.fk_user,'; $sql.= ' SUM(f.amount)'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.entity = ".$conf->entity; if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql .= ' AND f.fk_soc = '.$socid; // Search criteria if ($month > 0) { if ($year > 0 && empty($day)) $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; else if ($year > 0 && ! empty($day)) $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'"; else $sql.= " AND date_format(p.datep, '%m') = '".$month."'"; } else if ($year > 0) { $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; } if ($search_ref) $sql .= natural_search('p.rowid', $search_ref); if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account; if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'"; if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num); if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1); if ($search_company) $sql .= natural_search('s.nom', $search_company); include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; $sql.= " GROUP BY p.rowid, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, c.code, c.libelle, ba.rowid, ba.label"; if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user"; // Add where from extra fields $sql.= $db->order($sortfield,$sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 { $page = 0; $offset = 0; } } $sql.= $db->plimit($limit+1, $offset); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($day) $param.=($day?"&day=".urlencode($day):""); if ($month) $param.=($month?"&month=".urlencode($month):""); if ($year) $param.=($year?"&year=".urlencode($year):""); if ($search_ref) $param.=($search_ref?"&search_ref=".urlencode($search_ref):""); if ($search_company) $param.=($search_company?"&search_company=".urlencode($search_company):""); if ($search_amount != '') $param.=($search_amount?"&search_amount=".urlencode($search_amount):""); if ($search_payment_num) $param.=($search_payment_num?"&search_payment_num=".urlencode($search_payment_num):""); if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); print_barre_liste($langs->trans('SupplierPayments'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit); print '
'; if ($optioncss != '') print ''; print ''; print ''; print ''; print ''; print ''; $moreforfilter=''; $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; if ($moreforfilter) { print '
'; print $moreforfilter; print '
'; } $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields print '
'; print ''."\n"; // Lines for filters fields print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print_liste_field_titre("RefPayment",$_SERVER["PHP_SELF"],'p.rowid','',$param,'',$sortfield,$sortorder); print_liste_field_titre("Date",$_SERVER["PHP_SELF"],'dp','',$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder); print_liste_field_titre("Type",$_SERVER["PHP_SELF"],'c.libelle','',$param,'',$sortfield,$sortorder); print_liste_field_titre("Numero",$_SERVER["PHP_SELF"],"p.num_paiement","",$param,"",$sortfield,$sortorder); print_liste_field_titre("Account",$_SERVER["PHP_SELF"],'ba.label','',$param,'',$sortfield,$sortorder); print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],'p.amount','',$param,'align="right"',$sortfield,$sortorder); //print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],'ref_supplier','',$param,'',$sortfield,$sortorder); print_liste_field_titre(''); print "\n"; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); print ''; // Ref payment print ''; // Date print '\n"; // Thirdparty print ''; // Type $payment_type = $langs->trans("PaymentType".$objp->paiement_type)!=("PaymentType".$objp->paiement_type)?$langs->trans("PaymentType".$objp->paiement_type):$objp->paiement_libelle; print '\n"; // Payment number print ''; print ''; print ''; // Ref invoice /*$invoicesupplierstatic->ref=$objp->ref_supplier; $invoicesupplierstatic->id=$objp->facid; print '';*/ print ''; print ''; $i++; } print "
'; print ''; print ''; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; print ''; $formother->select_year($year?$year:-1,'year',1, 20, 5); print ''; print ''; print ''; $form->select_types_paiements($search_paymenttype,'search_paymenttype','',2,1,1); print ''; print ''; print ''; $form->select_comptes($search_account,'search_account',0,'',1); print ''; print ''; print ''; $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; print '
'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.''.dol_print_date($db->jdate($objp->dp),'day')."'; if ($objp->socid) print ''.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->name,32).''; else print ' '; print ''.$payment_type.' '.dol_trunc($objp->num_paiement,32)."'.$objp->num_paiement.''; if ($objp->bid) print ''.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).''; else print ' '; print ''.price($objp->pamount).''; print $invoicesupplierstatic->getNomUrl(1); print ' 
"; print "
"; print "
\n"; } else { dol_print_error($db); } } llxFooter(); $db->close();