diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php new file mode 100644 index 00000000000..5029192cc00 --- /dev/null +++ b/htdocs/compta/facture/fiche-rec.php @@ -0,0 +1,831 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ +require("./pre.inc.php"); + +$user->getrights('facture'); +if (!$user->rights->facture->lire) + accessforbidden(); + +require("../../facture.class.php"); +require("../../project.class.php"); + +llxHeader(); + +/* + * Sécurité accés client + */ +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} +/* + * + */ +if ($HTTP_POST_VARS["action"] == 'add') +{ + $facture = new Facture($db, $socid); + + $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"]; + + 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); + } + 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 = ''; +} +/* + * + */ + +if ($action == 'delete' && $user->rights->facture->supprimer) +{ + $fac = new Facture($db); + $fac->delete($facid); + $facid = 0 ; +} + +/* + * + */ + +$html = new Form($db); + +/********************************************************************* + * + * Mode creation + * + * + * + ************************************************************************/ +if ($action == 'create') +{ + print_titre("Créer une facture récurrente"); + + $facture = new Facture($db); + + if ($facture->fetch($facid) > 0) + { + + print '

'; + print ''; + print '' ."\n"; + print ''; + + print ''; + + $facture->fetch_client(); + + print ""; + print ""; + + print ""; + + print ''; + + print ''; + print ""; + + print ""; + + print ''; + + /* + * Lignes de factures + * + */ + print ''; + print "\n"; + print "
Client :".$facture->client->nom."Commentaire
Auteur :".$user->fullname."'; + print '
Conditions de réglement :"; + + print $facture->cond_reglement; + + print "
Projet :"; + if ($facture->projetid > 0) + { + $proj = new Project($db); + $proj->fetch($facture->projetid); + print $proj->title; + } + print "
Services/Produits
'; + + $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; + $sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid ORDER BY l.rowid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; $total = 0; + + echo ''; + if ($num) + { + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + if ($objp->fk_product) + { + print ''; + } + else + { + print "\n"; + } + print ''; + print ''; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + print '\n"; + + print ""; + + $i++; + } + + $db->free(); + + } + else + { + print $db->error(); + } + print "
DescriptionTvaQuantitéRemiseP.U.
'.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_taux.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."
"; + + print '
\n"; + + } + else + { + print "Erreur facture $facid inexistante"; + } +} +else +/* *************************************************************************** */ +/* */ +/* */ +/* */ +/* *************************************************************************** */ +{ + + if ($facid > 0) + { + + $fac = New Facture($db); + if ( $fac->fetch($facid, $user->societe_id) > 0) + { + $soc = new Societe($db, $fac->socidp); + $soc->fetch($fac->socidp); + $author = new User($db); + $author->id = $fac->user_author; + $author->fetch(); + + print_titre("Facture : ".$fac->ref); + + /* + * Facture + */ + print ""; + print ""; + print "'; + + print ""; + + print ""; + print "\n"; + print ""; + print ""; + + if ($fac->remise_percent > 0) + { + print '"; + + print ''; + print ''; + print ''; + + if ($fac->remise_percent > 0) + { + 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'; + } + else + { + 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"; + + $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.'%
TVA'.price($fac->total_tva).'euros
Total'.price($fac->total_ttc).'euros TTC
Note : '.nl2br($fac->note)."

"; + + if ($fac->brouillon == 1) + { + print '
'; + print ''; + print '
Remise'; + print '%'; + print ''; + print '
'; + } + + + /* + * Ajouter une ligne + * + */ + if ($fac->statut == 0) + { + print "
"; + // echo ''; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ""; + } + print "
DescriptionTvaQuantitéRemiseP.U.  
'; + print $html->select_tva("tva_tx"); + print ' %
"; + /* + * Fin Ajout ligne + * + */ + if ($user->societe_id == 0 && $fac->paye == 0) + { + print "

"; + + if ($fac->statut == 0 && $user->rights->facture->supprimer) + { + print ""; + } + elseif ($fac->statut == 1 && abs($resteapayer) > 0 && $user->rights->facture->envoyer) + { + print ""; + } + else + { + print ""; + } + + if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->paiement) + { + print ""; + } + else + { + print ""; + } + + if ($fac->statut == 1 && abs($resteapayer) == 0 && $fac->paye == 0) + { + if ($user->rights->facture->paiement) + { + print ""; + } + else + { + print ''; + } + } + elseif ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer) + { + print ""; + } + else + { + print ''; + } + + if ($fac->statut == 0 && $fac->total_ht > 0) + { + if ($user->rights->facture->valider) + { + print ""; + } + else + { + print ''; + } + } + elseif ($fac->statut == 1 && $fac->paye == 0) + { + if ($user->rights->facture->creer) + { + print ""; + } + else + { + print ''; + } + } + else + { + print ''; + } + print "
[Supprimer][Envoyer]-[Emettre un paiement]-[Classer 'Payée']-[Envoyer une relance]-[Valider]-Générer la facture--
"; + } + 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 "
"; + } + /* + * + * + */ + if ($action == 'presend') + { + $replytoname = $user->fullname; + $from_name = $replytoname; + + $replytomail = $user->email; + $from_mail = $replytomail; + + print "

\n"; + print ''; + print ''; + + print "

Envoyer la facture par mail"; + print ""; + print '"; + print ""; + print ""; + print "
Destinataire'; + + $form = new Form($db); + $form->select_array("destinataire",$soc->contact_email_array()); + + print "email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; + + print "

"; + } + + if ($action == 'prerelance') + { + $replytoname = $user->fullname; + $from_name = $replytoname; + + $replytomail = $user->email; + $from_mail = $replytomail; + + print "
\n"; + print ''; + print ''; + print ''; + + print_titre("Envoyer une relance"); + print ""; + print '"; + print ""; + print ""; + print "
Destinataire'; + + $form = new Form($db); + $form->select_array("destinataire",$soc->contact_email_array()); + + print "email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; + + print "
"; + } + + /* + * Propales + */ + + $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid"; + $sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $facid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + if ($num) + { + $i = 0; $total = 0; + print "

"; + if ($num >1) + { + print_titre("Propositions commerciales associées"); + } + else + { + print_titre("Proposition commerciale associée"); + } + + print ''; + print ''; + print ""; + print ""; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print ''; + print ""; + $total = $total + $objp->price; + $i++; + } + print "\n"; + print "
NuméroDatePrix
propalid\">$objp->ref".strftime("%d %B %Y",$objp->dp)."'.price($objp->price).'
Total : ".price($total)." $_MONNAIE HT
"; + } + } else { + print $db->error(); + } + } + else + { + /* Facture non trouvée */ + print "Facture inexistante ou accés refusé"; + } + } else { + /*************************************************************************** + * * + * Mode Liste * + * * + * * + ***************************************************************************/ + if ($page == -1) + { + $page = 0 ; + } + + if ($user->rights->facture->lire) + { + $limit = $conf->liste_limit; + $offset = $limit * $page ; + + if ($sortorder == "") + $sortorder="DESC"; + + 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"; + + 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); + + $result = $db->query($sql); + } + if ($result) + { + $num = $db->num_rows(); + print_barre_liste("Factures",$page,$PHP_SELF,"&socidp=$socidp",$sortfield,$sortorder,'',$num); + + $i = 0; + print ""; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $var=True; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($i); + $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) + { + if ($objp->fk_statut == 0) + { + print ''; + } + else + { + print ''; + } + } + else + { + print ''; + } + + print "\n"; + $i++; + } + } + + print "
Numéro'; + 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; + 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)."brouillonimpayée 
"; + $db->free(); + } + else + { + print $db->error() . "
" . $sql; + } + } + +} + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/pgsql/README b/pgsql/README new file mode 100644 index 00000000000..3cb45b82fb6 --- /dev/null +++ b/pgsql/README @@ -0,0 +1,4 @@ +Les fichiers contenus dans ce répertoire ne sont plus valides, le +support de PostgreSQL a été abandonné temporairement. + +-- Rodolphe Quiédeville \ No newline at end of file