diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 2e37b681168..058d144223e 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -33,7 +33,11 @@ if ($user->societe_id > 0) $socidp = $user->societe_id; } + $html = new Form($db); +$mesg=''; +$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; + if ($action == 'valid') { @@ -62,7 +66,7 @@ if($_GET["action"] == 'deletepaiement') } } -if ($HTTP_POST_VARS["action"] == 'modif_libelle') +if ($_POST["action"] == 'modif_libelle') { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set libelle = '$form_libelle' WHERE rowid = $facid ;"; $result = $db->query( $sql); @@ -71,12 +75,12 @@ if ($HTTP_POST_VARS["action"] == 'modif_libelle') if ($action == 'update') { - $datefacture = $db->idate(mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"])); + $datefacture = $db->idate(mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"])); $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set "; - $sql .= " facnumber='".trim($HTTP_POST_VARS["facnumber"])."'"; - $sql .= ", libelle='".trim($HTTP_POST_VARS["libelle"])."'"; - $sql .= ", note='".$HTTP_POST_VARS["note"]."'"; + $sql .= " facnumber='".trim($_POST["facnumber"])."'"; + $sql .= ", libelle='".trim($_POST["libelle"])."'"; + $sql .= ", note='".$_POST["note"]."'"; $sql .= ", datef = '$datefacture'"; $sql .= " WHERE rowid = $facid ;"; $result = $db->query( $sql); @@ -84,40 +88,54 @@ if ($action == 'update') if ($action == 'add') { - $datefacture = $db->idate(mktime(12, - 0, - 0, - $HTTP_POST_VARS["remonth"], - $HTTP_POST_VARS["reday"], - $HTTP_POST_VARS["reyear"])); - $tva = 0; - $tva = ($tva_taux * $amount) / 100 ; - $remise = 0; - $total = $tva + $amount ; - - $facfou = new FactureFourn($db); - - $facfou->number = $HTTP_POST_VARS["facnumber"]; - $facfou->socid = $HTTP_POST_VARS["socidp"]; - $facfou->libelle = $HTTP_POST_VARS["libelle"]; - $facfou->date = $datefacture; - $facfou->note = $HTTP_POST_VARS["note"]; - - for ($i = 1 ; $i < 9 ; $i++) - { - $label = "label$i"; - $amount = "amount$i"; - $tauxtva = "tauxtva$i"; - $qty = "qty$i"; + if ($_POST["facnumber"]) { + $datefacture = $db->idate(mktime(12, + 0, + 0, + $_POST["remonth"], + $_POST["reday"], + $_POST["reyear"])); + $tva = 0; + $tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ; + $remise = 0; + $total = $tva + $_POST["amount"] ; - if (strlen($$label)) - { - // print "Ajour ligne $i " . $$label . " " . $$amount . " " . $$tauxtva ; // DEBUG - $facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty); - } - } - $facid = $facfou->create($user); + $db->begin(); + + // Creation facture + $facfou = new FactureFourn($db); + + $facfou->number = $_POST["facnumber"]; + $facfou->socid = $_POST["socidp"]; + $facfou->libelle = $_POST["libelle"]; + $facfou->date = $datefacture; + $facfou->note = $_POST["note"]; + $facid = $facfou->create($user); + + // Ajout des lignes de factures + if ($facid) { + for ($i = 1 ; $i < 9 ; $i++) + { + $label = "label$i"; + $amount = "amount$i"; + $tauxtva = "tauxtva$i"; + $qty = "qty$i"; + + if (strlen($$label) && $$amount > 0) + { + $atleastoneline=1; + $facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty); + } + } + } + + $db->commit(); + + } + else { + $mesg="
Erreur: Un numéro de facture fournisseur est obligatoire.
"; + } } if ($action == 'del_ligne') @@ -134,10 +152,10 @@ if ($action == 'add_ligne') { $facfou = new FactureFourn($db,"", $facid); - $facfou->add_ligne($HTTP_POST_VARS["label"], - $HTTP_POST_VARS["amount"], - $HTTP_POST_VARS["tauxtva"], - $HTTP_POST_VARS["qty"], + $facfou->add_ligne($_POST["label"], + $_POST["amount"], + $_POST["tauxtva"], + $_POST["qty"], 1); $action="edit"; @@ -148,9 +166,12 @@ if ($action == 'add_ligne') * */ llxHeader(); + +if ($mesg) { print "
$mesg
"; } + /* * - * Mode creation + * Fiche de creation * */ @@ -161,7 +182,7 @@ if ($action == 'create' or $action == 'copy') $fac_ori = new FactureFourn($db); $fac_ori->fetch($facid); } - print_titre("Saisir une facture"); + print_titre("Saisir une facture fournisseur"); print '
'; print ''; @@ -215,7 +236,7 @@ if ($action == 'create' or $action == 'copy') print "
"; print ''; - print "".''; + print "".''; for ($i = 1 ; $i < 9 ; $i++) { @@ -246,6 +267,7 @@ else { if ($facid > 0) { + $fac = new FactureFourn($db); $fac->fetch($facid); @@ -268,15 +290,15 @@ else print $db->error(); } - print_titre ('Facture : '.$obj->facnumber); - /* - * Edition - * + * Fiche facture en mode edition * */ if ($action == "edit") { + + print_titre('Facture : '.$obj->facnumber); + print "rowid\" method=\"post\">"; print ''; @@ -290,7 +312,7 @@ else print "".''; - print ''; @@ -314,6 +336,7 @@ else $authorfullname=$author->fullname; } print ""; + print ""; print ""; print "
 LibelléP.U.QtyTx TVA
 LibelléP.U. HTQuantitéTx TVA
Numéro :'; print ''; + print ''; print '
Auteur :$authorfullname
Statut:".$fac->LibStatut($fac->paye,$fac->statut)."
"; print "
"; @@ -324,7 +347,7 @@ else */ print "

rowid&action=add_ligne\" method=\"post\">"; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -365,11 +388,17 @@ else else { /* - * Affichage - * + * Affichage en visu * */ + $head[0][0] = DOL_URL_ROOT."$PHP_SELF?facid=".$_GET["facid"]; + $head[0][1] = 'Facture : '.$obj->facnumber; + $h = 1; + $a = 0; + + dolibarr_fiche_head($head, $a); + print "
LibelléP.U. HTQtyTotal HT
LibelléP.U. HTQuantitéTotal HTTaux TVATVATotal TTC 
"; print '"; print "\n"; print ""; - print "\n"; + print "\n"; print ""; @@ -405,8 +434,6 @@ else print ""; print "\n"; print "\n"; - print "\n"; + print "\n"; if ($obj->statut == 1 && $obj->paye == 0 && $user->societe_id == 0) { @@ -455,12 +482,12 @@ else $total = $total + $objp->amount; $i++; } - print "$_MONNAIE\n"; + print "".MAIN_MONNAIE."\n"; $resteapayer = abs($fac->total_ttc - $total); print ""; - print '$_MONNAIE"; + print '".MAIN_MONNAIE.""; print "\n"; print "
'; /* @@ -379,7 +408,7 @@ else print "
Sociétésocidp\">$obj->socnomsocidp\">Autres factures
Date".strftime("%A %d %B %Y",$obj->df)."
Date".dolibarr_print_date($obj->df,"%A %d %B %Y")."
Libellé"; print $obj->libelle; print ""; - $_MONNAIE="euros"; - /* * Paiements */ @@ -441,7 +468,7 @@ else print "
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."$_MONNAIE".price($objp->amount)."".MAIN_MONNAIE."
Total :".price($total)."
Total :".price($total)."
Reste a payer :'.price($resteapayer)."'.price($resteapayer)."
"; @@ -482,9 +509,11 @@ else print 'Taux TVA'; print 'TVA'; print 'Total TTC'; + $var=1; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { - print "".''.$fac->lignes[$i][0].""; + $var=!$var; + print "".''.$fac->lignes[$i][0].""; print ''.price($fac->lignes[$i][1]).""; print ''.$fac->lignes[$i][3].""; print ''.price($fac->lignes[$i][4]).""; @@ -494,8 +523,9 @@ else print ''; } - print ""; + print "
"; + print "\n"; } /* @@ -504,7 +534,7 @@ else * */ - print "
\n"; + print "
\n"; if ($obj->statut == 0 && $user->societe_id == 0) {