From bd0bef34676065073141c39bf72ba53e766c87a5 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Sun, 12 Oct 2003 18:12:18 +0000 Subject: [PATCH] . --- htdocs/compta/facture/fiche-rec.php | 381 +++++----------------------- 1 file changed, 70 insertions(+), 311 deletions(-) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 71f469ae0be..e011306322c 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -20,6 +20,7 @@ * */ require("./pre.inc.php"); +require("./facture-rec.class.php"); $user->getrights('facture'); if (!$user->rights->facture->lire) @@ -28,7 +29,7 @@ if (!$user->rights->facture->lire) require("../../facture.class.php"); require("../../project.class.php"); -llxHeader('','Nouvelle facture récurrente','ch-facture.html#s-fac-facture-rec'); +llxHeader('','Facture récurrente','ch-facture.html#s-fac-facture-rec'); /* * Sécurité accés client @@ -43,61 +44,19 @@ if ($user->societe_id > 0) */ if ($HTTP_POST_VARS["action"] == 'add') { - $facture = new Facture($db, $socid); + $facturerec = new FactureRec($db, $facid); - $facture->number = $HTTP_POST_VARS["facnumber"]; - $facture->note = $HTTP_POST_VARS["note"]; - $facture->projetid = $HTTP_POST_VARS["projetid"]; - $facture->cond_reglement = $HTTP_POST_VARS["condid"]; - $facture->amount = $HTTP_POST_VARS["amount"]; - $facture->remise = $HTTP_POST_VARS["remise"]; - $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; + $facturerec->titre = $HTTP_POST_VARS["titre"]; - if (!$HTTP_POST_VARS["propalid"]) - { - $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"]); - $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"]); - $facture->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"]); - $facture->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"]); - - $facid = $facture->create($user); + if ($facturerec->create($user) > 0) + { + $facid = $facturerec->id; + $action = ''; } else { - $facture->propalid = $HTTP_POST_VARS["propalid"]; - - $facid = $facture->create($user); - - if ($facid) - { - $prop = New Propal($db); - if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) - { - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) - { - $result = $facture->addline($facid, - addslashes($prop->lignes[$i]->libelle), - $prop->lignes[$i]->subprice, - $prop->lignes[$i]->qty, - $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id, - $prop->lignes[$i]->remise_percent); - } - } - else - { - print "Erreur"; - } - } - else - { - print "

Erreur : la facture n'a pas été créée, vérifier le numéro !"; - print "

Retour à la propal"; - print $db->error(); - } + $action = "create"; } - - $action = ''; } /* * @@ -105,7 +64,7 @@ if ($HTTP_POST_VARS["action"] == 'add') if ($action == 'delete' && $user->rights->facture->supprimer) { - $fac = new Facture($db); + $fac = new FactureRec($db); $fac->delete($facid); $facid = 0 ; } @@ -134,8 +93,7 @@ if ($action == 'create') print '

'; print ''; - print '' ."\n"; - print ''; + print ''; print ''; @@ -144,12 +102,12 @@ if ($action == 'create') print ""; print ""; - print ""; - - print ''; + + print ''; - print ''; + print ""; print ""; - - print ''; + print "
Client :".$facture->client->nom."Commentaire
Auteur :".$user->fullname."'; + print '
Titre :'; print '
Auteur :".$user->fullname."
Conditions de réglement :"; print $facture->cond_reglement; @@ -163,10 +121,11 @@ if ($action == 'create') $proj->fetch($facture->projetid); print $proj->title; } - print "
Services/Produits
"; + + print_titre('Services/Produits'); + print ''; /* * Lignes de factures * @@ -289,9 +248,9 @@ else { if ($facid > 0) - { - - $fac = New Facture($db); + { + $fac = New FactureRec($db,0); + if ( $fac->fetch($facid, $user->societe_id) > 0) { $soc = new Societe($db, $fac->socidp); @@ -300,7 +259,7 @@ else $author->id = $fac->user_author; $author->fetch(); - print_titre("Facture : ".$fac->ref); + print_titre("Facture : ".$fac->titre); /* * Facture @@ -308,13 +267,10 @@ else print "
"; print ""; print "'; + print ''.$soc->nom.''; print ""; - print ""; - print "\n"; - print ""; print ""; if ($fac->remise_percent > 0) @@ -326,133 +282,59 @@ else print '"; print ''; print ''; - print ''; - - if ($fac->remise_percent > 0) - { - print ''; - print ''; - print ''; - } + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; if ($fac->note) { print '"; } print "
Client"; - print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
Date".strftime("%A %d %B %Y",$fac->date)."Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."
Auteur$author->fullname'; } - $_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"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows(); - $i = 0; $total = 0; - print "Paiements"; - echo ''; - print ""; - print ""; - print ""; - print ""; - if (! $fac->paye) - { - print ""; - } - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object( $i); - $var=!$var; - print ""; - print "\n"; - print "\n"; - print '\n"; - if (! $fac->paye && $user->rights->facture->paiement) - { - print '"; - $total = $total + $objp->amount; - $i++; - } - - if ($fac->paye == 0) - { - print "\n"; - print "\n"; - - $resteapayer = price($fac->total_ttc - $total); - - print ""; - print "\n"; - } - print "
DateTypeMontant  
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."$_MONNAIEDel'; - } - print "
Total :".price($total)."$_MONNAIE
Facturé :".price($fac->total_ttc)."$_MONNAIE
Reste à payer :".price($fac->total_ttc - $total)."$_MONNAIE
"; - $db->free(); - } else { - print $db->error(); - } - print "
Montant'.price($fac->total_ht).'euros HT
Remise'.$fac->remise_percent.'%
'.MAIN_MONNAIE.' HT
TVA'.price($fac->total_tva).'euros
'.MAIN_MONNAIE.'
Total'.price($fac->total_ttc).'euros TTC
'.MAIN_MONNAIE.' TTC
Note : '.nl2br($fac->note)."

"; - - if ($fac->brouillon == 1) - { - print ''; - print ''; - print '
Remise'; - print '%'; - print ''; - print '
'; - } - - /* - * Ajouter une ligne + * Lignes * */ - if ($fac->statut == 0) + print_titre("Produits"); + + print ''; + print ''; + print ''; + + $num = sizeof($fac->lignes); + $i = 0; + $var=True; + while ($i < $num) { - print ""; - // echo '
RéfProduitPrixRemiseQté.
'; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ""; + $var=!$var; + if ($fac->lignes[$i]->produit_id > 0) + { + $prod = New Product($db); + $prod->fetch($fac->lignes[$i]->produit_id); + print "'; + print ''; + } + else + { + print ""; + print ''; + } + print ""; + print ''; + print "\n"; + $i++; } - print "
DescriptionTvaQuantitéRemiseP.U.  
'; - print $html->select_tva("tva_tx"); - print ' %
[".$prod->ref.']'.$fac->lignes[$i]->desc.'
 '.$fac->lignes[$i]->desc.'".price($fac->lignes[$i]->price)."'.$fac->lignes[$i]->remise_percent.' %".$fac->lignes[$i]->qty."
"; + print ''; + /* - * Fin Ajout ligne + * Actions * */ if ($user->societe_id == 0 && $fac->paye == 0) @@ -503,14 +385,7 @@ else if ($fac->statut == 0 && $fac->total_ht > 0) { - if ($user->rights->facture->valider) - { - print "[Valider]"; - } - else - { - print '-'; - } + print '-'; } elseif ($fac->statut == 1 && $fac->paye == 0) { @@ -531,69 +406,6 @@ else } print "

\n"; - /* - * Documents générés - * - */ - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; - - if (file_exists($file)) - { - print "
"; - print_titre("Documents"); - print ''; - - print ""; - print ''; - print ''; - print ''; - print ''; - - print "
Facture PDFref."/".$fac->ref.'.pdf">'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
\n"; - print '
'; - print_titre("Actions"); - /* - * Liste des actions - * - */ - $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; - $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_facture = $facid"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows(); - if ($num) - { - $i = 0; $total = 0; - print ''; - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object( $i); - $var=!$var; - print ""; - print "\n"; - print ''; - print ""; - $i++; - } - print "
DateAction
".strftime("%d %B %Y",$objp->da)."'.stripslashes($objp->note).'
"; - } - } - else - { - print $db->error(); - } - - /* - * - * - */ - print "
"; - } /* * * @@ -697,7 +509,7 @@ else $total = $total + $objp->price; $i++; } - print "Total : ".price($total)." $_MONNAIE HT\n"; + print "Total : ".price($total)." ".MAIN_MONNAIE." HT\n"; print ""; } } else { @@ -732,36 +544,14 @@ else if ($sortfield == "") $sortfield="f.datef"; - $sql = "SELECT s.nom,s.idp,f.facnumber,f.total,".$db->pdate("f.datef")." as df,f.paye,f.rowid as facid, f.fk_statut"; - $sql .= " FROM llx_societe as s,llx_facture as f WHERE f.fk_soc = s.idp"; + $sql = "SELECT s.nom,s.idp,f.titre,f.total,f.rowid as facid"; + $sql .= " FROM llx_societe as s,llx_facture_rec as f WHERE f.fk_soc = s.idp"; if ($socidp) $sql .= " AND s.idp = $socidp"; - - if ($month > 0) - $sql .= " AND date_format(f.datef, '%m') = $month"; - - if ($filtre) - { - $filtrearr = split(",", $filtre); - foreach ($filtrearr as $fil) - { - $filt = split(":", $fil); - $sql .= " AND " . $filt[0] . " = " . $filt[1]; - } - } - - if ($year > 0) - $sql .= " AND date_format(f.datef, '%Y') = $year"; - - if (strlen($HTTP_POST_VARS["sf_ref"]) > 0) - { - $sql .= " AND f.facnumber like '%".$HTTP_POST_VARS["sf_ref"] . "%'"; - } - - - $sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; - $sql .= $db->plimit($limit + 1,$offset); + + //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; + // $sql .= $db->plimit($limit + 1,$offset); $result = $db->query($sql); } @@ -773,11 +563,10 @@ else $i = 0; print ""; print ''; - print ''; + print ''; print ''; print ''; print "\n"; @@ -791,43 +580,13 @@ else $var=!$var; print ""; - if ($objp->paye) - { - $class = "normal"; - } - else - { - if ($objp->fk_statut == 0) - { - $class = "normal"; - } - else - { - $class = "impayee"; - } - } - print '\n"; print ''; - if ($objp->df > 0 ) - { - print "\n"; - } - else - { - print "\n"; - } - print "\n"; if (! $objp->paye)
NuméroTitre'; print_liste_field_titre("Société",$PHP_SELF,"s.nom","","&socidp=$socidp"); - print ''; - print_liste_field_titre("Date",$PHP_SELF,"f.datef","","&socidp=$socidp"); + print 'Montant 
' . $objp->facnumber; + $class = "normal"; + + print '' . $objp->titre; print "'.$objp->nom.'"; - $y = strftime("%Y",$objp->df); - $m = strftime("%m",$objp->df); - - print strftime("%d",$objp->df)."\n"; - print ' '; - print strftime("%B",$objp->df)."\n"; - print ' '; - print strftime("%Y",$objp->df)."!!!".price($objp->total)."