From ec5ed9f5f401001dd4bd3fc4c4249703adc94fdb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 10 May 2009 04:20:37 +0000 Subject: [PATCH] Add date of last change in invoice tables --- htdocs/comm/index.php | 85 +++++++-- htdocs/compta/index.php | 185 ++++++++++++++++++- htdocs/facture.class.php | 11 +- htdocs/fourn/fournisseur.facture.class.php | 23 +-- htdocs/includes/boxes/box_factures.php | 4 +- htdocs/includes/boxes/box_factures_fourn.php | 4 +- htdocs/langs/fr_FR/boxes.lang | 4 +- 7 files changed, 272 insertions(+), 44 deletions(-) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 8c970094d8e..162b2e3414d 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -339,10 +339,12 @@ if ($conf->propal->enabled && $user->rights->propale->lire) } /* - * Last modified prospects + * Last modified customers prospects */ -if ($user->rights->societe->lire) +if ($conf->societe->enabled && $user->rights->societe->lire) { + $langs->load("boxes"); + $sql = "SELECT s.rowid,s.nom,s.client,s.tms"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -356,24 +358,24 @@ if ($user->rights->societe->lire) $resql = $db->query($sql); if ($resql) { + $var=false; $num = $db->num_rows($resql); + $i = 0; + + print ''; + print ''; + print ''; if ($num) { - $langs->load("boxes"); - - print '
'.$langs->trans("BoxTitleLastCustomersOrProspects",$max).'
'; - print ''; - print ''; - - $i = 0; - $var=false; + $company=new Societe($db); while ($i < $num) { $objp = $db->fetch_object($resql); - print ""; - print ""; - if ($objp->client == 2) print "rowid."\">".img_object($langs->trans("ShowCustomer"),"company")." ".$objp->nom.""; + $company->id=$objp->rowid; + $company->nom=$objp->nom; + $company->client=$objp->client; + print ''; + print ''; print ''; + } + } +} + +// Last suppliers +if ($conf->fournisseur->enabled && $user->rights->societe->lire) +{ + $langs->load("boxes"); + + $sql = "SELECT s.nom, s.rowid, ".$db->pdate("s.datec")." as dc"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE s.fournisseur = 1"; + $sql.= " AND s.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($socid) $sql.= " AND s.rowid = ".$socid; + $sql.= " ORDER BY s.datec DESC"; + $sql.= $db->plimit($max, 0); + + $result = $db->query($sql); + if ($result) + { + $var=false; + $num = $db->num_rows($result); + $i = 0; + + print '
'.$langs->trans("BoxTitleLastCustomersOrProspects",$max).'
"; - if ($objp->client == 1) print "rowid."\">".img_object($langs->trans("ShowCustomer"),"company")." ".$objp->nom."
'.$company->getNomUrl(1,'customer',48).''; if ($objp->client == 1) print $langs->trans("Customer"); if ($objp->client == 2) print $langs->trans("Prospect"); @@ -388,6 +390,61 @@ if ($user->rights->societe->lire) $db->free($resql); } + else + { + print '
'.$langs->trans("None").'
'; + print ''; + print ''; + print ''; + if ($num) + { + $company=new Societe($db); + while ($i < $num && $i < $max) + { + $objp = $db->fetch_object($result); + $company->id=$objp->rowid; + $company->nom=$objp->nom; + print ''; + print ''; + print ''; + print ''; + $var=!$var; + $i++; + } + + } + else + { + print ''; + } + print '
'.$langs->trans("BoxTitleLastSuppliers",min($max,$num)).''.$langs->trans("DateModificationShort").'
'.$company->getNomUrl(1,'supplier',48).''.dol_print_date($objp->dc,'day').'
'.$langs->trans("None").'

'; } } diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 56e186b7add..a2392852f1d 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -81,8 +81,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark') /* - * Affichage page - * + * View */ $now=gmmktime(); @@ -107,6 +106,9 @@ if (($conf->facture->enabled && $user->rights->facture->lire) || print ''; } +$max=3; + + /* * Find invoices */ @@ -291,12 +293,178 @@ else print ''; } +// Last modified customer invoices +if ($conf->facture->enabled && $user->rights->facture->lire) +{ + $langs->load("boxes"); + $facstatic=new Facture($db); + + $sql = "SELECT f.rowid, f.facnumber, f.fk_statut, f.type, f.total, f.total_ttc, f.tms,"; + $sql.= " f.date_lim_reglement as datelimite,"; + $sql.= " sum(pf.amount) as am,"; + $sql.= " s.nom, s.rowid as socid"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE s.rowid = f.fk_soc"; + $sql.= " AND f.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql.= " GROUP BY f.rowid, f.facnumber, f.fk_statut, f.total, f.total_ttc, s.nom, s.rowid"; + $sql.= " ORDER BY f.tms DESC "; + $sql.= $db->plimit($max, 0); + + $resql = $db->query($sql); + if ($resql) + { + $var=false; + $num = $db->num_rows($resql); + $i = 0; + + print ''; + print ''; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; + print ''; + print ''; + print ''; + print ''; + if ($num) + { + $total_ttc = $totalam = $total = 0; + while ($i < $num && $i < $conf->liste_limit) + { + $obj = $db->fetch_object($resql); + + print ''; + print ''; + print ''; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; + print ''; + print ''; + print ''; + print ''; + + $total_ttc += $obj->total_ttc; + $total += $obj->total; + $totalam += $obj->am; + $var=!$var; + $i++; + } + } + else + { + $colspan=5; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) $colspan++; + print ''; + } + print '
'.$langs->trans("BoxTitleLastCustomerBills",min($max,$num)).''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").' 
'; + + print ''; + print ''; + print ''; + print '
'; + $facturestatic->ref=$obj->facnumber; + $facturestatic->id=$obj->rowid; + $facturestatic->type=$obj->type; + print $facturestatic->getNomUrl(1,''); + print ''; + if ($obj->datelimite < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); + print ''; + $filename=dol_sanitizeFileName($obj->facnumber); + $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber); + $urlsource=$_SERVER['PHP_SELF'].'?facid='.$obj->rowid; + $formfile->show_documents('facture',$filename,$filedir,$urlsource,'','','','','',1); + print '
'; + + print '
'.img_object($langs->trans("ShowCustomer"),"company").' '.dol_trunc($obj->nom,44).''.price($obj->total).''.price($obj->total_ttc).''.dol_print_date($db->jdate($obj->tms),'day').''.$facstatic->LibStatut($obj->paye,$obj->fk_statut,3,$obj->am).'
'.$langs->trans("NoInvoice").'

'; + $db->free($resql); + } + else + { + dol_print_error($db); + } +} + + + +// Last modified supplier invoices +if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) +{ + $langs->load("boxes"); + $facstatic=new FactureFournisseur($db); + + $sql = "SELECT ff.rowid, ff.facnumber, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc, ff.tms,"; + $sql.= " sum(pf.amount) as am,"; + $sql.= " s.nom, s.rowid as socid"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE s.rowid = ff.fk_soc"; + $sql.= " AND s.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($socid) $sql.= " AND ff.fk_soc = ".$socid; + $sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.libelle, ff.total, ff.total_ttc, ff.tms, s.nom, s.rowid"; + $sql.= " ORDER BY ff.tms DESC "; + $sql.= $db->plimit($max, 0); + + $resql=$db->query($sql); + if ($resql) + { + $var=false; + $num = $db->num_rows($resql); + + print ''; + print ''; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; + print ''; + print ''; + print ''; + print "\n"; + if ($num) + { + $i = 0; + $total = $total_ttc = $totalam = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + print ''; + print ''; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; + print ''; + print ''; + print ''; + print ''; + $total += $obj->total_ht; + $total_ttc += $obj->total_ttc; + $totalam += $obj->am; + $i++; + $var = !$var; + } + } + else + { + $colspan=5; + if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) $colspan++; + print ''; + } + print '
'.$langs->trans("BoxTitleLastSupplierBills",min($max,$num)).''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").' 
'; + $facstatic->ref=$obj->facnumber; + $facstatic->id=$obj->rowid; + print $facstatic->getNomUrl(1,''); + print ''.img_object($langs->trans("ShowSupplier"),"company").' '.dol_trunc($obj->nom,44).''.price($obj->total_ht).''.price($obj->total_ttc).''.dol_print_date($db->jdate($obj->tms),'day').''.$facstatic->LibStatut($obj->paye,$obj->fk_statut,3).'
'.$langs->trans("NoInvoice").'

'; + } + else + { + dol_print_error($db); + } +} + + // Last customers if ($conf->societe->enabled && $user->rights->societe->lire) { $langs->load("boxes"); - $max=3; $sql = "SELECT s.nom, s.rowid, ".$db->pdate("s.datec")." as dc"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; @@ -319,7 +487,7 @@ if ($conf->societe->enabled && $user->rights->societe->lire) print ''; print ''; - print ''; + print ''; print ''; if ($num) { @@ -356,7 +524,6 @@ if ($conf->societe->enabled && $user->rights->societe->lire) if ($conf->fournisseur->enabled && $user->rights->societe->lire) { $langs->load("boxes"); - $max=3; $sql = "SELECT s.nom, s.rowid, ".$db->pdate("s.datec")." as dc"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; @@ -378,7 +545,7 @@ if ($conf->fournisseur->enabled && $user->rights->societe->lire) print '
'.$langs->trans("BoxTitleLastCustomers",min($max,$num)).''.$langs->trans("Date").''.$langs->trans("DateModificationShort").'
'; print ''; - print ''; + print ''; print ''; if ($num) { @@ -684,11 +851,11 @@ if ($conf->facture->enabled && $user->rights->facture->lire) /* * Factures fournisseurs impayées */ -if ($conf->facture->enabled && $user->rights->facture->lire) +if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) { $facstatic=new FactureFournisseur($db); - $sql = "SELECT ff.rowid, ff.facnumber, ff.fk_statut, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc,"; + $sql = "SELECT ff.rowid, ff.facnumber, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc,"; $sql.= " sum(pf.amount) as am,"; $sql.= " s.nom, s.rowid as socid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; @@ -699,7 +866,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire) $sql.= " AND ff.paye=0 AND ff.fk_statut = 1"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; if ($socid) $sql.= " AND ff.fk_soc = ".$socid; - $sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.total, ff.total_ttc, s.nom, s.rowid"; + $sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.libelle, ff.total, ff.total_ttc, s.nom, s.rowid"; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 59ef95f7394..9e80baa89fa 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -61,6 +61,7 @@ class Facture extends CommonObject var $date; var $date_creation; var $date_validation; + var $datem; var $ref; var $ref_client; //! 0=Standard invoice, 1=Replacement invoice, 2=Credit note invoice, 3=Deposit invoice, 4=Proformat invoice @@ -512,6 +513,7 @@ class Facture extends CommonObject $sql.= ','.$this->db->pdate('f.date_lim_reglement').' as dlr'; $sql.= ','.$this->db->pdate('f.datec').' as datec'; $sql.= ','.$this->db->pdate('f.date_valid').' as datev'; + $sql.= ','.$this->db->pdate('f.tms').' as datem'; $sql.= ', f.note, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.fk_user_valid, f.model_pdf'; $sql.= ', f.fk_facture_source'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet'; @@ -541,6 +543,7 @@ class Facture extends CommonObject $this->date = $obj->df; $this->date_creation = $obj->datec; $this->date_validation = $obj->datev; + $this->datem = $this->db->jdate($obj->datem); $this->amount = $obj->amount; $this->remise_percent = $obj->remise_percent; $this->remise_absolue = $obj->remise_absolue; @@ -2177,8 +2180,7 @@ class Facture extends CommonObject */ function info($id) { - $sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec,'; - $sql.= ' '.$this->db->pdate('date_valid').' as datev,'; + $sql = 'SELECT c.rowid, datec, date_valid as datev, tms as datem,'; $sql.= ' fk_user_author, fk_user_valid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as c'; $sql.= ' WHERE c.rowid = '.$id; @@ -2202,8 +2204,9 @@ class Facture extends CommonObject $vuser->fetch(); $this->user_validation = $vuser; } - $this->date_creation = $obj->datec; - $this->date_validation = $obj->datev; + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + $this->date_validation = $this->db->jdate($obj->datev); // Should be in log table } $this->db->free($result); } diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 274078e147f..397920642ca 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -402,7 +402,7 @@ class FactureFournisseur extends Facture $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn'; $sql.= ' SET paye = 1'; $sql.= ' WHERE rowid = '.$this->id; - + $resql = $this->db->query($sql); if (! $resql) { @@ -652,10 +652,10 @@ class FactureFournisseur extends Facture */ function info($id) { - $sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec'; - $sql .= ', fk_user_author, fk_user_valid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as c'; - $sql .= ' WHERE c.rowid = '.$id; + $sql = 'SELECT c.rowid, datec, tms as datem,'; + $sql.= ' fk_user_author, fk_user_valid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as c'; + $sql.= ' WHERE c.rowid = '.$id; $result=$this->db->query($sql); if ($result) @@ -677,7 +677,8 @@ class FactureFournisseur extends Facture $this->user_validation = $vuser; } $this->date_creation = $obj->datec; - //$this->date_validation = $obj->datev; \todo La date de validation n'est pas encore geree + $this->date_modification = $obj->datem; + //$this->date_validation = $obj->datev; Should be stored in log table } $this->db->free($result); } @@ -708,7 +709,7 @@ class FactureFournisseur extends Facture $sql.= " AND ff.entity = ".$conf->entity; if ($user->societe_id) $sql.=' AND ff.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; - + $resql=$this->db->query($sql); if ($resql) { @@ -763,13 +764,13 @@ class FactureFournisseur extends Facture // Charge tableau des id de societe socids $socids = array(); - + $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE fournisseur = 1"; $sql.= " AND entity = ".$conf->entity; $sql.= " LIMIT 10"; - + $resql = $this->db->query($sql); if ($resql) { @@ -786,12 +787,12 @@ class FactureFournisseur extends Facture // Charge tableau des produits prodids $prodids = array(); - + $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " WHERE envente = 1"; $sql.= " AND entity = ".$conf->entity; - + $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/includes/boxes/box_factures.php b/htdocs/includes/boxes/box_factures.php index 91339581afc..d12b61d7894 100644 --- a/htdocs/includes/boxes/box_factures.php +++ b/htdocs/includes/boxes/box_factures.php @@ -74,7 +74,7 @@ class box_factures extends ModeleBoxes { if ($user->rights->facture->lire) { $sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.datef as df"; - $sql.= ", f.paye, f.fk_statut, f.datec"; + $sql.= ", f.paye, f.fk_statut, f.datec, f.tms"; $sql.= ", s.nom, s.rowid as socid"; $sql.= ", f.date_lim_reglement as datelimite"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; @@ -83,7 +83,7 @@ class box_factures extends ModeleBoxes { $sql.= " AND s.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; - $sql.= " ORDER BY f.datef DESC, f.facnumber DESC "; + $sql.= " ORDER BY f.tms DESC"; $sql.= $db->plimit($max, 0); $result = $db->query($sql); diff --git a/htdocs/includes/boxes/box_factures_fourn.php b/htdocs/includes/boxes/box_factures_fourn.php index 7f50cce35bc..6ec62499fb7 100644 --- a/htdocs/includes/boxes/box_factures_fourn.php +++ b/htdocs/includes/boxes/box_factures_fourn.php @@ -76,7 +76,7 @@ class box_factures_fourn extends ModeleBoxes { $sql.= " f.paye, f.fk_statut,"; $sql.= ' f.datef as df,'; $sql.= ' f.datec as datec,'; - $sql.= ' f.date_lim_reglement as datelimite '; + $sql.= ' f.date_lim_reglement as datelimite, f.tms'; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -84,7 +84,7 @@ class box_factures_fourn extends ModeleBoxes { $sql.= " AND s.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; - $sql.= " ORDER BY f.datef DESC, f.facnumber DESC "; + $sql.= " ORDER BY f.tms DESC"; $sql.= $db->plimit($max, 0); $result = $db->query($sql); diff --git a/htdocs/langs/fr_FR/boxes.lang b/htdocs/langs/fr_FR/boxes.lang index 860c965bc8a..707a44464fe 100644 --- a/htdocs/langs/fr_FR/boxes.lang +++ b/htdocs/langs/fr_FR/boxes.lang @@ -27,8 +27,8 @@ BoxTitleLastSuppliers=Les %s derniers fournisseurs modifiées BoxTitleLastCustomers=Les %s derniers clients modifiées BoxTitleLastCustomersOrProspects=Les %s derniers clients ou prospects modifiés BoxTitleLastPropals=Les %s dernières propositions enregistrés -BoxTitleLastCustomerBills=Les %s dernières factures clients enregistrées -BoxTitleLastSupplierBills=Les %s dernières factures fournisseurs enregistrées +BoxTitleLastCustomerBills=Les %s dernières factures clients modifiées +BoxTitleLastSupplierBills=Les %s dernières factures fournisseurs modifiées BoxTitleLastProspects=Les %s derniers prospects modifiés BoxTitleLastProductsInContract=Les %s derniers produits/services contractés BoxTitleOldestUnpayedCustomerBills=Les %s plus anciennes factures clients impayées
'.$langs->trans("BoxTitleLastSuppliers",min($max,$num)).''.$langs->trans("Date").''.$langs->trans("DateModificationShort").'