From c3cbd7c24e2e0cda837b1ef1c0d18eccac534d9d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 13 Jun 2011 11:10:43 +0000 Subject: [PATCH] New: Add link from turnover report by third parties to payments of third parties. Fix: List of payments with no invoices works again. --- htdocs/compta/paiement/liste.php | 114 +++++++++++-------------- htdocs/compta/resultat/clientfourn.php | 2 +- htdocs/compta/stats/cabyuser.php | 4 +- htdocs/compta/stats/casoc.php | 9 +- htdocs/compta/stats/index.php | 19 +++-- 5 files changed, 72 insertions(+), 76 deletions(-) diff --git a/htdocs/compta/paiement/liste.php b/htdocs/compta/paiement/liste.php index 0731ab9e775..1381f12661e 100644 --- a/htdocs/compta/paiement/liste.php +++ b/htdocs/compta/paiement/liste.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -32,7 +32,8 @@ require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); $langs->load("bills"); // Security check -$facid = isset($_GET["facid"])?$_GET["facid"]:''; +$facid = GETPOST("facid"); +$socid = GETPOST("socid"); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'facture',$facid,''); @@ -62,70 +63,51 @@ llxHeader('',$langs->trans("ListPayment")); $form=new Form($db); -$sql = "SELECT DISTINCT p.rowid, p.datep as dp, p.amount,"; -$sql.= " p.statut, p.num_paiement,"; -//$sql.= " c.libelle as paiement_type,"; -$sql.= " c.code as paiement_code,"; -$sql.= " ba.rowid as bid, ba.label,"; -$sql.= " s.rowid as socid, s.nom"; -//$sql.= " f.facnumber"; -$sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p"; -$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"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; -if (!$user->rights->societe->client->voir && !$socid) -{ - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; -} -$sql.= " WHERE p.fk_paiement = c.id"; -$sql.= " AND s.entity = ".$conf->entity; -if (!$user->rights->societe->client->voir && !$socid) -{ - $sql.= " AND sc.fk_user = " .$user->id; -} -if ($socid) -{ - $sql.= " AND f.fk_soc = ".$socid; -} -// Search criteria -if ($_REQUEST["search_ref"]) -{ - $sql .=" AND p.rowid=".$_REQUEST["search_ref"]; -} -if ($_REQUEST["search_account"]) -{ - $sql .=" AND b.fk_account=".$_REQUEST["search_account"]; -} -if ($_REQUEST["search_paymenttype"]) -{ - $sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'"; -} -if ($_REQUEST["search_amount"]) -{ - $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]); -} -if ($_REQUEST["search_company"]) -{ - $sql .=" AND s.nom LIKE '%".$db->escape($_REQUEST["search_company"])."%'"; -} - -if ($_GET["orphelins"]) // Option for debugging purpose only +if (GETPOST("orphelins")) { // Paiements lies a aucune facture (pour aide au diagnostic) $sql = "SELECT p.rowid, p.datep as dp, p.amount,"; $sql.= " p.statut, p.num_paiement,"; //$sql.= " c.libelle as paiement_type"; - $sql.= " c.code as paiement_code,"; - $sql.= " s.rowid as socid, s.nom"; - $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p,"; - $sql.= " ".MAIN_DB_PREFIX."c_paiement as c"; + $sql.= " c.code as paiement_code"; + $sql.= " FROM (".MAIN_DB_PREFIX."paiement as p,"; + $sql.= " ".MAIN_DB_PREFIX."c_paiement as c)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE p.fk_paiement = c.id"; + $sql.= " AND pf.fk_facture IS NULL"; +} +else +{ + $sql = "SELECT DISTINCT p.rowid, p.datep as dp, p.amount,"; // DISTINCT is to avoid duplicate when there is a link to sales representatives + $sql.= " p.statut, p.num_paiement,"; + //$sql.= " c.libelle as paiement_type,"; + $sql.= " c.code as paiement_code,"; + $sql.= " ba.rowid as bid, ba.label,"; + $sql.= " s.rowid as socid, s.nom"; + //$sql.= " f.facnumber"; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p)"; + $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"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; + if (!$user->rights->societe->client->voir && !$socid) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + } $sql.= " WHERE p.fk_paiement = c.id"; $sql.= " AND s.entity = ".$conf->entity; - $sql.= " AND pf.rowid IS NULL"; + if (!$user->rights->societe->client->voir && !$socid) + { + $sql.= " AND sc.fk_user = " .$user->id; + } + if ($socid > 0) $sql.= " AND f.fk_soc = ".$socid; + // Search criteria + if ($_REQUEST["search_ref"]) $sql .=" AND p.rowid=".$_REQUEST["search_ref"]; + if ($_REQUEST["search_account"]) $sql .=" AND b.fk_account=".$_REQUEST["search_account"]; + if ($_REQUEST["search_paymenttype"]) $sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'"; + if ($_REQUEST["search_amount"]) $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]); + if ($_REQUEST["search_company"]) $sql .=" AND s.nom LIKE '%".$db->escape($_REQUEST["search_company"])."%'"; } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit( $limit+1 ,$offset); @@ -139,26 +121,26 @@ if ($resql) $i = 0; $paramlist=''; - $paramlist.=($_REQUEST["orphelins"]?"&orphelins=1":""); + $paramlist.=(GETPOST("orphelins")?"&orphelins=1":""); $paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:""); $paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:""); $paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:""); - print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, "liste.php",$paramlist,$sortfield,$sortorder,'',$num); + print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"],$paramlist,$sortfield,$sortorder,'',$num); print '
'; print ''; print ''; - print_liste_field_titre($langs->trans("RefPayment"),"liste.php","p.rowid","",$paramlist,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Date"),"liste.php","dp","",$paramlist,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("ThirdParty"),"liste.php","s.nom","",$paramlist,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Type"),"liste.php","c.libelle","",$paramlist,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Account"),"liste.php","ba.label","",$paramlist,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Amount"),"liste.php","p.amount","",$paramlist,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"p.rowid","",$paramlist,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"dp","",$paramlist,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom","",$paramlist,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"c.libelle","",$paramlist,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$paramlist,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"p.amount","",$paramlist,'align="right"',$sortfield,$sortorder); //print_liste_field_titre($langs->trans("Invoices"),"","","",$paramlist,'align="left"',$sortfield,$sortorder); if ($conf->global->BILL_ADD_PAYMENT_VALIDATION) { - print_liste_field_titre($langs->trans("Status"),"liste.php","p.statut","",$paramlist,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$paramlist,'align="right"',$sortfield,$sortorder); } print "\n"; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 6cd10819396..a2668c49c32 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -65,7 +65,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); if (! GETPOST('month')) { - if ($month_start > $month_current) + if (! GETPOST("year") && $month_start > $month_current) { $year_start--; $year_end--; diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index bbab0460c3f..581b342640d 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -71,7 +71,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $month_end=$month_start; if (! GETPOST("month")) // If month not forced { - if ($month_start > $month_current) + if (! GETPOST('year') && $month_start > $month_current) { $year_start--; $year_end--; @@ -265,7 +265,7 @@ if (sizeof($amount)) if ($conf->commande->enabled && $conf->global->MAIN_FEATURES_LEVEL == 2) { if($key>0){ - print ''; + print ''; } else { print '' ; } diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 92a7ac1295b..f924e501fc6 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -74,7 +74,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $month_end=$month_start; if (! GETPOST("month")) // If month not forced { - if ($month_start > $month_current) + if (! GETPOST('year') && $month_start > $month_current) { $year_start--; $year_end--; @@ -265,7 +265,12 @@ if (sizeof($amount)) $linkname=$langs->trans("PaymentsNotLinkedToInvoice"); } print "\n"; - print ''; + print ''; print ''; print "\n"; $i++; diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 52b01a4c900..210fd4c1e0b 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -30,12 +30,13 @@ require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); $year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"]; $year_current = strftime("%Y",time()); +$nbofyear=4; if (! $year_start) { - $year_start = $year_current - 4; - $year_end = $year_current; + $year_start = $year_current - ($nbofyear-1); + $year_end = $year_current; } else { - $year_end=$year_start + 4; + $year_end=$year_start + ($nbofyear-1); } // Security check @@ -164,12 +165,20 @@ if ($modecompta != 'CREANCES-DETTES') { } +/* + * Show result array + */ + print '
'.img_picto($langs->trans("Show"),"vcard").''.img_picto($langs->trans("Show"),"stats").'   ".$linkname."'.price($amount[$key]).''; + if ($key > 0) print ''; + else print ''; + print price($amount[$key]); + print ''; + print ''.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : ' ').'
'; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print ''; + print ''; if ($annee != $year_end) print ''; } print '';
'.$langs->trans("Month").''.$annee.''; + print ''; + print $annee; + if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1); + print '