diff --git a/htdocs/facturefourn.class.php b/htdocs/facturefourn.class.php index edc594ddd6d..c5ab94e4a59 100644 --- a/htdocs/facturefourn.class.php +++ b/htdocs/facturefourn.class.php @@ -63,7 +63,7 @@ class FactureFourn { * * */ - Function add_ligne($label, $amount, $tauxtva, $qty=1) + Function add_ligne($label, $amount, $tauxtva, $qty=1, $write=0) { $i = sizeof($this->lignes); @@ -71,6 +71,36 @@ class FactureFourn { $this->lignes[$i][1] = $amount; $this->lignes[$i][2] = $tauxtva; $this->lignes[$i][3] = $qty; + + if ($write) + { + + for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) + { + + $sql = "INSERT INTO llx_facture_fourn_det (fk_facture_fourn)"; + $sql .= " VALUES ($this->id);"; + if ($this->db->query($sql) ) + { + $idligne = $this->db->last_insert_id(); + + $this->update_ligne($idligne, + $this->lignes[$i][0], + $this->lignes[$i][1], + $this->lignes[$i][2], + $this->lignes[$i][3]); + } + else + { + print $this->db->error(); + } + } + /* + * Mise à jour prix + */ + + $this->updateprice($this->id); + } } /* * @@ -99,7 +129,26 @@ class FactureFourn { print $this->db->error() . '
'.$sql; } } + /* + * + */ + Function delete_ligne($id) + { + $sql = "DELETE FROM llx_facture_fourn_det "; + $sql .= " WHERE rowid = $id"; + + if (! $this->db->query($sql) ) + { + print $this->db->error() . '
'.$sql; + } + $this->updateprice($this->id); + return 1; + } + /* + * + * + */ Function create($user) { @@ -149,6 +198,8 @@ class FactureFourn { $this->updateprice($this->id); + return 1; + } else { @@ -191,7 +242,7 @@ class FactureFourn { /* * Lignes */ - $sql = "SELECT description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc FROM llx_facture_fourn_det WHERE fk_facture_fourn=".$this->id; + $sql = "SELECT rowid,description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc FROM llx_facture_fourn_det WHERE fk_facture_fourn=".$this->id; if ($this->db->query($sql) ) { @@ -209,6 +260,7 @@ class FactureFourn { $this->lignes[$i][4] = $obj->total_ht; $this->lignes[$i][5] = $obj->tva; $this->lignes[$i][6] = $obj->total_ttc; + $this->lignes[$i][7] = $obj->rowid; $i++; } } @@ -286,7 +338,12 @@ class FactureFourn { $sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $rowid ;"; $return = $this->db->query( $sql); } - + /* + * + * + * + * + */ Function set_valid($rowid, $userid) { global $conf; @@ -305,6 +362,8 @@ class FactureFourn { } } /* + * + * * * */ diff --git a/htdocs/fourn/facture/fiche.php3 b/htdocs/fourn/facture/fiche.php3 index 4384f9cc361..6bba83381ed 100644 --- a/htdocs/fourn/facture/fiche.php3 +++ b/htdocs/fourn/facture/fiche.php3 @@ -21,7 +21,14 @@ */ require("./pre.inc.php3"); -llxHeader(); +/* + * Sécurité accés client + */ +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} $db = new Db(); @@ -90,22 +97,52 @@ if ($action == 'add') $label = "label$i"; $amount = "amount$i"; $tauxtva = "tauxtva$i"; + $qty = "qty$i"; if (strlen($$label)) { // print "Ajour ligne $i " . $$label . " " . $$amount . " " . $$tauxtva ; // DEBUG - $facfou->add_ligne($$label, $$amount, $$tauxtva); + $facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty); } } - $facfou->create($user); - + if ($facfou->create($user)) + { + Header("Location: index.php3"); + } } + +if ($action == 'del_ligne') +{ + $facfou = new FactureFourn($db,"",$facid); + + if ($facfou->delete_ligne($ligne_id)) + { + $action="edit"; + } +} + +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"], + 1); + + $action="edit"; +} + + +/* + * + */ +llxHeader(); /* * * Mode creation * - * - * */ if ($action == 'create') @@ -115,7 +152,7 @@ if ($action == 'create') print '
'; print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ''; - - print ''; - print ''; - - print ''; - print ''; - - - $author = $GLOBALS["REMOTE_USER"]; - print ""; print ""; + print "
Société :
Société :
Numéro :
Libellé :
Date :'; $html->select_date(); print '
Montant HT :
TVA :
Auteur :".$user->fullname."

"; + print ''; + print ''; + print ''; print ''; - - print ''; + print ''; print ''; print ''; - - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; - print ''; + print ''; print ""; print "
 LibelléP.U.QtyTx TVA
Ligne 1 : TVA '; + print ''; $html->select_tva("tauxtva1"); print '
Ligne 2 : TVA '; + print ''; $html->select_tva("tauxtva2"); print '
Ligne 3 : TVA '; + print ''; $html->select_tva("tauxtva3"); print '
Ligne 4 : TVA '; + print ''; $html->select_tva("tauxtva4"); print '
"; @@ -241,14 +270,13 @@ else print ''; print ''; - print ""; + print ""; print ''; print ''; print ''; print ''; print ''; print ''; - print ''; - - print ''; - print ''; - + print ''; + print ""; - print ""; + print ""; print ""; print ""; print "
Société :
Société :'.stripslashes($obj->socnom); print 'Commentaires :
Numéro :'; - print $obj->facnumber .'
'; print '
'; @@ -257,30 +285,65 @@ else print '
Libellé :'; - print stripslashes($obj->libelle). '
'; print '
Montant HT :
TVA :
'.price($fac->total_ht).'
Date :"; print_date_select($obj->df); print "
Auteur :".$user->fullname."
Auteur :".' '."
"; + /* + * Lignes + * + */ + print '

'; + print ''; + print ''; + print ''; + print ''; + for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) + { + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + print ''; + print ''; + } + + /* Nouvelle ligne */ + print "rowid&action=add_ligne\" method=\"post\">"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
LibelléP.U. HTQtyTotal HTTaux TVATVATotal TTC 
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]."'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."['; + print 'Supprimer]
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '-'; + $html->select_tva("tauxtva"); + print ''; + print ''; + print ' 
"; + print ""; } else { @@ -291,13 +354,13 @@ else */ print ""; - print ""; - + print ""; print "
"; + print '
'; /* * Facture */ print ''; - print ""; - print "\n"; + print ""; + print "\n"; print ""; print "\n"; print ""; @@ -306,32 +369,31 @@ else print '"; print '"; print '"; - - print ""; - print ""; - - print ""; + if (strlen($obj->note)) + { + print ''; + } print "
Sociétésocidp\">$obj->socnomsocidp\">Autres factures
Sociétésocidp\">$obj->socnomsocidp\">Autres factures
Date".strftime("%A %d %B %Y",$obj->df)."
Libelle$obj->libelle
 Total HT'.price($fac->total_ht)."TVA'.price($fac->total_tva)."
 Total TTC'.price($fac->total_ttc)."
Statut$obj->statutPaye".$yn[$obj->paye]."
Commentaires'; + print nl2br(stripslashes($obj->note)); + print '
"; - - print "
 "; - - print nl2br(stripslashes($obj->note)); - + + print ""; + $_MONNAIE="euros"; /* * Paiements */ $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; - $sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id"; + $sql .= " FROM llx_paiementfourn as p, c_paiement as c WHERE p.fk_facture_fourn = ".$fac->id." AND p.fk_paiement = c.id"; - //$result = $db->query($sql); - $result = 0; + $result = $db->query($sql); + if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; - print "

Paiements"; + echo ''; print ""; print ""; @@ -353,39 +415,41 @@ else $i++; } print "\n"; - print "\n"; - $resteapayer = $obj->total - $total; + $resteapayer = $fac->total_ttc - $total; print ""; print '\n"; print "
Date
Total :".price($total)."$_MONNAIE
Facturé :".price($obj->total)."$_MONNAIE
Reste a payer :'.price($resteapayer)."$_MONNAIE
"; $db->free(); - } else { - // print $db->error(); + } + else + { + print $db->error(); } - print "

"; /* * Lignes * - */ - + */ print '

'; print ''; - print ''; + print ''; + print ''; + print ''; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { print '"; - print '"; + print '"; print '"; - print '"; + print '"; + print '"; + print '"; print '"; - print '"; - print '"; + print ''; } print "
LibelléP.U. HTQtyTotal HTTotal TTCTVATaux TVA
Taux TVATVATotal TTC
'.$fac->lignes[$i][0]."'.$fac->lignes[$i][4]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.$fac->lignes[$i][1]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]."'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."'.price($fac->lignes[$i][5])."'.$fac->lignes[$i][2]."
"; @@ -400,28 +464,38 @@ else print "

"; - if ($obj->statut == 0) + if ($obj->statut == 0 && $user->societe_id == 0) { - print ''; + print ''; + } + elseif ($obj->statut == 1 && $obj->paye == 0 && $user->societe_id == 0) + { + print ''; } else { - print ""; + print ''; } - - print ''; - - if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) + if ($obj->statut == 0 && $user->societe_id == 0) { - print ""; + print ''; + } + else + { + print ''; + } + + if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0 && $user->societe_id == 0) + { + print ""; } else { print ""; } - if ($obj->statut == 0) + if ($obj->statut == 0 && $user->societe_id == 0) { print ""; } @@ -430,44 +504,7 @@ else print ""; } - - print "
['.translate("Delete").'][Supprimer][Emmettre un paiement]--[Editer][Classer 'Payée'][Editer]-[Classer 'Payée']-[Valider]-

"; - - /* - * Documents générés - * - */ - print "


"; - print "
"; - print "Documents associés
"; - print ""; - - $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/facture/$obj->facnumber/$obj->facnumber.pdf"; - if (file_exists($file)) { - print ""; - } - $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/facture/$obj->facnumber/$obj->facnumber.ps"; - if (file_exists($file)) { - print ""; - print ""; - } - print ""; - - print "
Propale PDFfacnumber/$obj->facnumber.pdf\">$obj->facnumber.pdf
Propale Postscriptfacnumber/$obj->facnumber.ps\">$obj->facnumber.ps
(facnumber/\">liste...)
\n
"; - - /* - * Generation de la facture - * - */ - if ($action == 'pdf') { - print "
Génération de la facture
"; - $command = "export DBI_DSN=\"dbi:mysql:dbname=lolixfr\" "; - $command .= " ; ../../scripts/facture-tex.pl --html -vv --facture=$facid --pdf --gljroot=" . $GLOBALS["GLJ_ROOT"] ; - - $output = system($command); - print "

command :
$command
"; - print "

output :
$output
"; - } + print ""; } }