diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 2a131d97b53..f7b4a0cdc51 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -385,7 +385,7 @@ class Commande Function fetch ($id) { $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva"; - $sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source"; + $sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.facture"; $sql .= " FROM llx_commande as c"; $sql .= " WHERE c.rowid = $id"; @@ -407,7 +407,7 @@ class Commande $this->remise_percent = $obj->remise_percent; $this->source = $obj->source; - + $this->facturee = $obj->facture; $this->projet_id = $obj->fk_projet; $this->db->free(); @@ -571,6 +571,25 @@ class Commande } } } + /** + * Classe la facture comme facturée + * + */ + Function classer_facturee() + { + $sql = "UPDATE llx_commande SET facture = 1"; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut > 0 ;"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + print $this->db->error() . ' in ' . $sql; + } + + } /** * Mettre à jour le prix * diff --git a/htdocs/compta/commande.php b/htdocs/compta/commande.php index 403aa940945..050a679d43a 100644 --- a/htdocs/compta/commande.php +++ b/htdocs/compta/commande.php @@ -41,6 +41,14 @@ if ($user->societe_id > 0) * */ +if ($_GET["action"] == 'facturee') +{ + $commande = new Commande($db); + $commande->fetch($_GET["id"]); + $commande->classer_facturee(); +} + + llxHeader(); $html = new Form($db); @@ -194,7 +202,7 @@ if ($_GET["id"] > 0) * Barre d'actions */ - if ($user->societe_id == 0) + if ($user->societe_id == 0 && !$commande->facturee) { print '

'; @@ -203,7 +211,16 @@ if ($_GET["id"] > 0) print ''; print ''; print ''; - print ''; + if (!$commande->facturee) + { + print ''; + } + else + { + print ''; + } print ''; print "
---'; + print 'Classer comme facturée'; + print '--
"; @@ -230,18 +247,77 @@ if ($_GET["id"] > 0) print "\n"; print ''; - - /* * * */ print ""; } + /* + * Factures associees + */ + $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; + $sql .= " FROM llx_facture as f, llx_co_fa as fp WHERE fp.fk_facture = f.rowid AND fp.fk_commande = ".$commande->id; + + if ($db->query($sql) ) + { + $num_fac_asso = $db->num_rows(); + $i = 0; $total = 0; + print "
"; + if ($num_fac_asso > 1) + { + print_titre("Factures associées"); + } + else + { + print_titre("Facture associée"); + } + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num_fac_asso) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + if ($objp->fk_user_author <> $user->id) + { + $fuser = new User($db, $objp->fk_user_author); + $fuser->fetch(); + print "\n"; + } + else + { + print "\n"; + } + print ''; + print ""; + $total = $total + $objp->total; + $i++; + } + print "\n"; + print "
NuméroDateAuteurPrix
facid\">$objp->facnumber"; + if ($objp->paye) + { + print " (payée)"; + } + print "".strftime("%d %B %Y",$objp->df)."".$fuser->fullname."".$user->fullname."'.price($objp->total).'
Total : $total Euros HT
"; + $db->free(); + } + else + { + print $db->error(); + } /* * * */ + } else