diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f56e262c472..a5d0a03265c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -198,6 +198,12 @@ if ($action == 'payed' && $user->rights->facture->paiement) $result = $fac->set_payed($facid); } +if ($action == 'canceled' && $user->rights->facture->paiement) +{ + $fac = new Facture($db); + $result = $fac->set_canceled($facid); +} + if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->facture->creer) { $fac = new Facture($db); @@ -459,7 +465,7 @@ if ($_GET["action"] == 'create') } else { - print ' '; + print ' '; print ''; /* * @@ -566,7 +572,7 @@ if ($_GET["action"] == 'create') $var=!$var; print "[$objp->ref]\n"; print ''.$objp->product.''; - print "".price($objp->price).""; + print "".price($objp->price).""; print ''.$objp->remise_percent.' %'; print "".$objp->qty."\n"; $i++; @@ -717,14 +723,7 @@ else print "Auteur$author->fullname"; - if ($fac->remise_percent > 0) - { - print ''; - } - else - { - print ''; - } + print ''; /* * Paiements @@ -755,16 +754,16 @@ else print "$objp->paiement_type $objp->num_paiement\n"; print ''.price($objp->amount)."$_MONNAIE\n"; print ""; - $total = $total + $objp->amount; + $totalpaye += $objp->amount; $i++; } if ($fac->paye == 0) { - print "Total :".price($total)."$_MONNAIE\n"; + print "Total payé:".price($totalpaye)."$_MONNAIE\n"; print "Facturé :".price($fac->total_ttc)."$_MONNAIE\n"; - $resteapayer = $fac->total_ttc - $total; + $resteapayer = $fac->total_ttc - $totalpaye; print "Reste à payer :"; print "".price($resteapayer)."$_MONNAIE\n"; @@ -777,21 +776,19 @@ else print ""; - print 'Montant'; + print 'Remise globale'; + print ''.$fac->remise_percent.''; + print '%'; + + print 'Montant HT'; print ''.price($fac->total_ht).''; print ''.MAIN_MONNAIE.' HT'; - if ($fac->remise_percent > 0) - { - print 'Remise'; - print ''.$fac->remise_percent.''; - print '%'; - } - print 'TVA'.price($fac->total_tva).''; print ''.MAIN_MONNAIE.''; - print 'Total'.price($fac->total_ttc).''; + print 'Montant TTC'.price($fac->total_ttc).''; print ''.MAIN_MONNAIE.' TTC'; + print 'Statut'.($fac->get_libstatut()).''; if ($fac->note) { print 'Note : '.nl2br($fac->note).""; @@ -964,11 +961,11 @@ else { if ($fac->paye == 0) { - print "id&action=pdf\">Générer la facture"; + print "id&action=pdf\">Générer le PDF"; } else { - print "id&action=pdf\">Regénérer la facture"; + print "id&action=pdf\">Regénérer le PDF"; } } } @@ -988,13 +985,13 @@ else // Envoyer une relance if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) { - print "id&action=prerelance\">Envoyer une relance"; + print "id&action=prerelance\">Envoyer relance"; } // Emettre paiement if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->paiement) { - print "id."&action=create\">Emettre un paiement"; + print "id."&action=create\">Emettre paiement"; } // Classer 'payé' @@ -1004,7 +1001,12 @@ else print "id&action=payed\">Classer 'Payée'"; } - + // Classer 'annulée' (possible si validée et aucun paiement n'a encore eu lieu) + if ($fac->statut == 1 && $fac->paye == 0 && $totalpaye == 0 && $user->rights->facture->paiement) + { + print "id&action=canceled\">Classer 'Annulée'"; + } + // Récurrente if (! defined("FACTURE_DISABLE_RECUR")) // Possibilité de désactiver les factures récurrentes { @@ -1371,6 +1373,10 @@ else { print 'brouillon'; } + elseif ($objp->fk_statut == 3) + { + print 'annulée'; + } else { print ''.($objp->am?"commencé":"impayée").''; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index fc571d0bb1c..d8fd3206daf 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -233,7 +233,7 @@ if ($user->comm > 0 && $conf->commercial ) * Factures impayées */ -$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut > 0"; +$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index db2f41d05a4..7f79c052cb5 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -422,18 +422,54 @@ class Facture return -5; } } + /** - * Tag la facture comme payée + * Retourne le libellé du statut d'une facture (brouillon, validée, annulée, payée) * + */ + Function get_libstatut() + { + if (! $this->paye) + { + if ($this->statut == 0) return 'Brouillon (à valider)'; + if ($this->statut == 3) return 'Annulée'; + return 'Validée (à payer)'; + } + else + { + return 'Payée'; + } + } + + /** + * Tag la facture comme payée complètement * */ Function set_payed($rowid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye = 1 WHERE rowid = $rowid ;"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye=1 WHERE rowid = $rowid ;"; $return = $this->db->query( $sql); } /** - * Valide la facture + * Tag la facture comme paiement commencée + * + */ + Function set_paiement_started($rowid) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=2 WHERE rowid = $rowid ;"; + $return = $this->db->query( $sql); + } + /** + * Tag la facture comme annulée + * + */ + Function set_canceled($rowid) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=3 WHERE rowid = $rowid ;"; + $return = $this->db->query( $sql); + } + /** + * Tag la facture comme validée et valide la facture * */ Function set_valid($rowid, $user, $soc)