From 5992175b687e7a7b226951269eb24cc4bbe10ea1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 03:23:44 +0200 Subject: [PATCH] Standardize code between customer and supplier invoice list. --- htdocs/compta/facture/list.php | 33 ++++++-- htdocs/core/lib/functions.lib.php | 2 +- htdocs/fourn/facture/list.php | 124 ++++++++++++++++++++++-------- 3 files changed, 119 insertions(+), 40 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 10b11812b1a..1ab17765d8f 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -536,7 +536,7 @@ if ($resql) $param='&socid='.$socid; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($sall) $param.='&sall='.$sall; + if ($sall) $param.='&sall='.urlencode($sall); if ($day) $param.='&day='.urlencode($day); if ($month) $param.='&month='.urlencode($month); if ($year) $param.='&year=' .urlencode($year); @@ -760,14 +760,14 @@ if ($resql) // Filters lines print ''; // Ref - if (! empty($arrayfields['f.facnumber']['checked'])) + if (! empty($arrayfields['f.facnumber']['checked'])) { print ''; print ''; print ''; } // Ref customer - if (! empty($arrayfields['f.ref_client']['checked'])) + if (! empty($arrayfields['f.ref_client']['checked'])) { print ''; print ''; @@ -806,6 +806,11 @@ if ($resql) print '
'.$langs->trans("Late"); print ''; } + // Project + if (! empty($arrayfields['p.ref']['checked'])) + { + print ''; + } // Thirpdarty if (! empty($arrayfields['s.nom']['checked'])) { @@ -1016,7 +1021,7 @@ if ($resql) print ''; print $facturestatic->getNomUrl(1,'',200,0,'',0,1); - print $obj->increment; + print empty($obj->increment)?'':' ('.$obj->increment.')'; print ''; print ''; @@ -1071,6 +1076,20 @@ if ($resql) if (! $i) $totalarray['nbfield']++; } + // Project + if (! empty($arrayfields['p.ref']['checked'])) + { + print ''; + if ($obj->project_id > 0) + { + $projectstatic->id=$obj->project_id; + $projectstatic->ref=$obj->project_ref; + print $projectstatic->getNomUrl(1); + } + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Third party if (! empty($arrayfields['s.nom']['checked'])) { @@ -1295,15 +1314,13 @@ if ($resql) print $hookmanager->resPrint; print "\n"; - print ""; + print ''; print "\n"; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { - /* - * Show list of available documents - */ + // Show list of available documents $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource.=str_replace('&','&',$param); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b6365a23b9a..14f61d99590 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -105,7 +105,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * @param string $element Current element * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', * 'product', 'productprice', 'stock', - * 'propal', 'facture', 'facture_fourn', + * 'propal', 'supplier_proposal', 'facture', 'facture_fourn', * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index e449ed83371..0918423908e 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -163,6 +163,8 @@ $arrayfields=array( 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj=="1"), 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj=="1"), 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), + 'dynamount_payed'=>array('label'=>$langs->trans("Payed"), 'checked'=>0), + 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0), 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), @@ -263,7 +265,9 @@ $sql.= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s. $sql.= " typent.code as typent_code,"; $sql.= " state.code_departement as state_code, state.nom as state_name,"; $sql.= " p.rowid as project_id, p.ref as project_ref"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; +// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) +// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. +if (! $search_all) $sql.= ', SUM(pf.amount) as dynamount_payed'; // Add fields from extrafields foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); // Add fields from hooks @@ -276,6 +280,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; $sql.= ', '.MAIN_DB_PREFIX.'facture_fourn as f'; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn_extrafields as ef on (f.rowid = ef.fk_object)"; +if (! $search_all) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; if ($search_all || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn'; if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet"; @@ -287,14 +292,10 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE f.fk_soc = s.rowid'; -$sql.= " AND f.entity = ".$conf->entity; +$sql.= ' AND f.entity IN ('.getEntity('facture_fourn', 1).')'; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; if ($socid > 0) $sql .= ' AND s.rowid = '.$socid; -if ($search_all) -{ - $sql.= natural_search(array_keys($fieldstosearchall), $search_all); -} if ($search_ref) { if (is_numeric($search_ref)) $sql .= natural_search(array('f.ref'), $search_ref); @@ -337,7 +338,7 @@ if ($month_lim > 0) else if ($year_lim > 0 && ! empty($day_lim)) $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'"; else - $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'"; + $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$db->escape($month_lim)."'"; } else if ($year_lim > 0) { @@ -382,6 +383,26 @@ $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; +if (! $search_all) +{ + $sql.= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement, f.fk_mode_reglement,"; + $sql.= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,"; + $sql.= " f.localtax1, f.localtax2,"; + $sql.= " s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.client, s.code_client,"; + $sql.= " typent.code,"; + $sql.= " state.code_departement, state.nom,"; + $sql.= " p.rowid, p.ref"; + + foreach ($extrafields->attribute_label as $key => $val) //prevent error with sql_mode=only_full_group_by + { + $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : ''); + } +} +else +{ + $sql.= natural_search(array_keys($fieldstosearchall), $search_all); +} + $sql.= $db->order($sortfield,$sortorder); $nbtotalofrecords = ''; @@ -410,7 +431,8 @@ if ($resql) $param='&socid='.$socid; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($day) $param.='&day='.urlencode($day); + if ($search_all) $param.='&search_all='.urlencode($search_all); + if ($day) $param.='&day='.urlencode($day); if ($month) $param.='&month='.urlencode($month); if ($year) $param.='&year=' .urlencode($year); if ($day_lim) $param.='&day_lim='.urlencode($day_lim); @@ -428,6 +450,8 @@ if ($resql) if ($search_amount_no_tax) $param.='&search_amount_no_tax='.urlencode($search_amount_no_tax); if ($search_amount_all_tax) $param.='&search_amount_all_tax='.urlencode($search_amount_all_tax); if ($search_status >= 0) $param.="&search_status=".urlencode($search_status); + if ($show_files) $param.='&show_files=' .$show_files; + if ($option) $param.="&option=".$option; if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields foreach ($search_array_options as $key => $val) @@ -453,13 +477,13 @@ if ($resql) print ''; print ''; print ''; - print ''; print ''; print ''; + print ''; print ''; print ''; - print_barre_liste($langs->trans("BillsSuppliers").($socid?" - $soc->name":""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); + print_barre_liste($langs->trans("BillsSuppliers").($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); if ($massaction == 'presend') { @@ -467,7 +491,7 @@ if ($resql) if (! GETPOST('cancel')) { - $objecttmp=new Commande($db); + $objecttmp=new FactureFourn($db); $listofselectedid=array(); $listofselectedthirdparties=array(); $listofselectedref=array(); @@ -491,8 +515,8 @@ if ($resql) dol_fiche_head(null, '', ''); - $topicmail="SendOrderRef"; - $modelmail="order_send"; + $topicmail="SendBillRef"; + $modelmail="supplier_invoice_send"; // Cree l'objet formulaire mail include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; @@ -506,12 +530,12 @@ if ($resql) } if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set { - $formmail->trackid='ord'.$object->id; + $formmail->trackid='sinv'.$object->id; } if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set { include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id); + $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'sinv'.$object->id); } $formmail->withfrom=1; $liste=$langs->trans("AllRecipientSelected"); @@ -678,7 +702,7 @@ if ($resql) if (! empty($arrayfields['f.datef']['checked'])) { print ''; - if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; print ''; $formother->select_year($year?$year:-1,'year',1, 20, 5); print ''; @@ -687,7 +711,7 @@ if ($resql) if (! empty($arrayfields['f.date_lim_reglement']['checked'])) { print ''; - if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; print ''; $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5); print '
'.$langs->trans("Late"); @@ -704,9 +728,9 @@ if ($resql) print ''; } // Town - if (! empty($arrayfields['s.town']['checked'])) print ''; + if (! empty($arrayfields['s.town']['checked'])) print ''; // Zip - if (! empty($arrayfields['s.zip']['checked'])) print ''; + if (! empty($arrayfields['s.zip']['checked'])) print ''; // State if (! empty($arrayfields['state.nom']['checked'])) { @@ -739,14 +763,14 @@ if ($resql) { // Amount print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['f.total_vat']['checked'])) { // Amount print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['f.total_localtax1']['checked'])) @@ -767,9 +791,19 @@ if ($resql) { // Amount print ''; - print ''; + print ''; print ''; } + if (! empty($arrayfields['dynamount_payed']['checked'])) + { + print ''; + print ''; + } + if (! empty($arrayfields['rtp']['checked'])) + { + print ''; + print ''; + } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -819,7 +853,7 @@ if ($resql) } // Action column print ''; - $searchpicto=$form->showFilterButtons('checkforselect', 0); + $searchpicto=$form->showFilterButtons(); print $searchpicto; print ''; @@ -844,6 +878,8 @@ if ($resql) if (! empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'],$_SERVER['PHP_SELF'],'f.localtax1','',$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'],$_SERVER['PHP_SELF'],'f.localtax2','',$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder); // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -880,14 +916,20 @@ if ($resql) { $obj = $db->fetch_object($resql); - $datelimit=$db->jdate($obj->datelimite); $facturestatic->id=$obj->facid; $facturestatic->ref=$obj->ref; + $facturestatic->type=$obj->type; $facturestatic->ref_supplier=$obj->ref_supplier; $facturestatic->date_echeance = $db->jdate($obj->datelimite); $facturestatic->statut = $obj->fk_statut; - + + $paiement = $facturestatic->getSommePaiement(); + $totalcreditnotes = $facturestatic->getSumCreditNotesUsed(); + $totaldeposits = $facturestatic->getSumDepositsUsed(); + $totalpay = $paiement + $totalcreditnotes + $totaldeposits; + $remaintopay = $obj->total_ttc - $totalpay; + print ''; if (! empty($arrayfields['f.ref']['checked'])) { @@ -969,7 +1011,7 @@ if ($resql) // Third party if (! empty($arrayfields['s.nom']['checked'])) { - print ''; + print ''; $thirdparty=new Societe($db); $thirdparty->id=$obj->socid; $thirdparty->name=$obj->name; @@ -1070,22 +1112,23 @@ if ($resql) $totalarray['totalttc'] += $obj->total_ttc; } - if (! empty($arrayfields['am']['checked'])) + if (! empty($arrayfields['dynamount_payed']['checked'])) { - print ''.(! empty($paiement)?price($paiement,0,$langs):' ').''; + print ''.(! empty($totalpay)?price($totalpay,0,$langs):' ').''; // TODO Use a denormalized field if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['totalamfield']=$totalarray['nbfield']; - $totalarray['totalam'] += $paiement; + $totalarray['totalam'] += $totalpay; } if (! empty($arrayfields['rtp']['checked'])) { - print ''.(! empty($remaintopay)?price($remaintopay,0,$langs):' ').''; + print ''.(! empty($remaintopay)?price($remaintopay,0,$langs):' ').''; // TODO Use a denormalized field if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield']; $totalarray['totalrtp'] += $remaintopay; } + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -1135,7 +1178,6 @@ if ($resql) } // Action column - // Action column print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined { @@ -1193,7 +1235,27 @@ if ($resql) print "\n"; print ''; + print "\n"; + + /* + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) + { + // Show list of available documents + $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource.=str_replace('&','&',$param); + + $filedir=$diroutputmassaction; + $genallowed=$user->rights->facture->lire; + $delallowed=$user->rights->facture->lire; + + print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); + } + else + { + print '
'.$langs->trans("ShowTempMassFilesArea").''; + } + */ } else {