* Copyright (C) 2004 Éric Seigne * Copyright (C) 2004 Laurent Destailleur * * 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("../lib/CMailFile.class.php"); require("../paiement.class.php"); require("../project.class.php"); require("../propal.class.php"); require("./bank/account.class.php"); require("../contrat/contrat.class.php"); require("../commande/commande.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($HTTP_POST_VARS["action"] == 'classin') { $facture = new Facture($db); $facture->fetch($facid); $facture->classin($HTTP_POST_VARS["projetid"]); } /* * */ if ($HTTP_POST_VARS["action"] == 'add') { $datefacture = mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]); $facture = new Facture($db, $HTTP_POST_VARS["socid"]); $facture->number = $HTTP_POST_VARS["facnumber"]; $facture->date = $datefacture; $facture->note = $HTTP_POST_VARS["note"]; if ($HTTP_POST_VARS["fac_rec"] > 0) { /* * Facture récurrente */ $facture->fac_rec = $HTTP_POST_VARS["fac_rec"]; $facid = $facture->create($user); } else { $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"] && !$HTTP_POST_VARS["commandeid"]) { $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"],$HTTP_POST_VARS["remise_percent1"]); $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"],$HTTP_POST_VARS["remise_percent2"]); $facture->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"],$HTTP_POST_VARS["remise_percent3"]); $facture->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"],$HTTP_POST_VARS["remise_percent4"]); $facid = $facture->create($user); if ($facid) { Header("Location: facture.php?facid=".$facid); } } else { /* * Propale */ if ($HTTP_POST_VARS["propalid"]) { $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++) { print "
la propale précédente en ligne " . $prop->lignes[$i]->libelle . " avait comme prix : " . $prop->lignes[$i]->price . " !
\n"; $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"; } } } /* * Commande */ if ($HTTP_POST_VARS["commandeid"]) { $facture->commandeid = $HTTP_POST_VARS["commandeid"]; $facid = $facture->create($user); if ($facid) { $comm = New Commande($db); if ( $comm->fetch($HTTP_POST_VARS["commandeid"]) ) { $lines = $comm->fetch_lignes(); for ($i = 0 ; $i < sizeof($lines) ; $i++) { $result = $facture->addline($facid, addslashes($lines[$i]->description), $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->product_id, $lines[$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 propale"; print $db->error(); } } } } $action = ''; } /* * */ if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->facture->valider) { $fac = new Facture($db); $fac->fetch($facid); $soc = new Societe($db); $soc->fetch($fac->socidp); $result = $fac->set_valid($facid, $user, $soc); if ($result) { facture_pdf_create($db, $facid); } } if ($action == 'payed' && $user->rights->facture->paiement) { $fac = new Facture($db); $result = $fac->set_payed($facid); } if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->facture->creer) { $fac = new Facture($db); $fac->fetch($facid); $fac->set_remise($user, $HTTP_POST_VARS["remise"]); } if ($action == 'addligne' && $user->rights->facture->creer) { $fac = new Facture($db); $fac->fetch($facid); $result = $fac->addline($facid, $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["pu"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["tva_tx"], 0, $HTTP_POST_VARS["remise_percent"]); } if ($action == 'updateligne' && $user->rights->facture->creer) { $fac = new Facture($db,"",$facid); $fac->fetch($facid); $result = $fac->updateline($rowid, $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["price"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["remise_percent"]); } if ($action == 'deleteline' && $user->rights->facture->creer) { $fac = new Facture($db,"",$facid); $fac->fetch($facid); $result = $fac->deleteline($rowid); } if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes) { if ($user->rights->facture->supprimer ) { $fac = new Facture($db); $fac->delete($_GET["facid"]); $_GET["facid"] = 0 ; } } /* * */ if ($HTTP_POST_VARS["action"] == 'send' || $HTTP_POST_VARS["action"] == 'relance') { $fac = new Facture($db,"",$facid); if ( $fac->fetch($facid) ) { $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; if (is_readable($file)) { if ($HTTP_POST_VARS["sendto"]) { // Le destinataire a été fourni via le champ libre $sendto = $HTTP_POST_VARS["sendto"]; $sendtoid = 0; } elseif ($HTTP_POST_VARS["destinataire"]) { // Le destinataire a été fourni via la liste déroulante $soc = new Societe($db, $fac->socidp); $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); $sendtoid = $HTTP_POST_VARS["destinataire"]; } if (strlen($sendto)) { if ($HTTP_POST_VARS["action"] == 'send') { $subject = "Facture $fac->ref"; $actioncode=9; $actionmsg="Envoyée à $sendto"; $actionmsg2="Envoi Facture par mail"; } if ($HTTP_POST_VARS["action"] == 'relance') { $subject = "Relance facture $fac->ref"; $actioncode=10; $actionmsg="Relance envoyée à $sendto"; $actionmsg2="Relance Facture par mail"; } $message = $HTTP_POST_VARS["message"]; $filename = $fac->ref.".pdf"; $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; // Envoi de la facture $mailfile = new CMailFile($subject,$sendto,$replyto,$message,array ($file),array ("application/pdf"),array ($filename)); if ( $mailfile->sendfile() ) { $sendto = htmlentities($sendto); $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '$actioncode' ,'$fac->socidp' ,'$actionmsg','$fac->id','$sendtoid','$user->id', '$actionmsg2',100);"; if (! $db->query($sql) ) { print $db->error(); print "

$sql

"; } } else { print "!! erreur d'envoi
$sendto
$replyto
$filename"; } } else { dolibarr_syslog("Le mail du destinataire est vide"); } } else { dolibarr_syslog("Impossible de lire :".$file); } } else { dolibarr_syslog("Impossible de lire les données de la facture. Le fichier facture n'a peut-être pas été généré."); } } /* * Générer ou regénérer le PDF */ if ($action == 'pdf') { /* * Generation de la facture * définit dans /includes/modules/facture/modules_facture.php */ facture_pdf_create($db, $facid); } llxHeader(); $html = new Form($db); /********************************************************************* * * Mode creation * * * ************************************************************************/ if ($_GET["action"] == 'create') { print_titre("Emettre une facture"); if ($propalid) { $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " AND p.rowid = $propalid"; } else { $sql = "SELECT s.nom, s.prefix_comm, s.idp "; $sql .= "FROM ".MAIN_DB_PREFIX."societe as s "; $sql .= "WHERE s.idp = ".$_GET["socidp"]; } if ($_GET["commandeid"]) { $commande = New Commande($db); $commande->fetch($_GET["commandeid"]); $societe_id = $commande->soc_id; } if ( $db->query($sql) ) { $num = $db->num_rows(); if ($num) { $obj = $db->fetch_object(0); $soc = new Societe($db); $soc->fetch($obj->idp); print '
'; print ''; print '' ."\n"; print ''; print ''; print ''; print ''; print ""; print ''; print ""; print ""; print ''; print ""; print ""; if ($_GET["propalid"] > 0) { $amount = ($obj->price); print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print ''; print ''; print '"; print '"; } elseif ($_GET["commandeid"] > 0) { print ''; print ''; print ''; print '"; print '"; } else { print ''; print ''; } /* * Factures récurrentes * */ if ($_GET["propalid"] == 0 && $_GET["commandeid"] == 0) { $sql = "SELECT r.rowid, r.titre, r.amount FROM ".MAIN_DB_PREFIX."facture_rec as r"; $sql .= " WHERE r.fk_soc = ".$soc->id; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; if ($num > 0) { print ''; } $db->free(); } else { print "$sql"; } } /* * */ print ''; print "\n"; print "
Client :'.$soc->nom.'Commentaire
Auteur :".$user->fullname."'; print '
Date :"; print_date_select(time()); print "
Numéro :Provisoire
Conditions de réglement :"; $sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."cond_reglement ORDER BY sortorder"; $result = $db->query($sql); $conds=array(); if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($i); $conds[$objp->rowid]=$objp->libelle; $i++; } $db->free(); } $html->select_array("condid",$conds); print "
Projet :"; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($socidp)); print "
Proposition'.$obj->ref.'
Montant HT'.price($amount).'
TVA'.price($obj->tva)."
Total TTC'.price($obj->total)."
Commande'.$commande->ref.'
Montant HT'.price($commande->total_ht).'
TVA'.price($commande->total_tva)."
Total TTC'.price($commande->total_ttc)."
 
'; /* * * Liste des elements * */ $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p "; $sql .= " WHERE envente = 1"; $sql .= " ORDER BY p.nbvente DESC LIMIT 20"; if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ''; print ''; for ($i = 1 ; $i < 5 ; $i++) { print ''; print ''; print ''; } print '
Services/Produits prédéfinisQuan.Remise
%
'; print '
Factures récurrentes :
\n"; if ($_GET["propalid"]) { /* * Produits */ print_titre("Produits"); print ''; print ''; print ''; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ""; print ''; print "\n"; $i++; } } $sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0"; $sql .= " ORDER BY pt.rowid ASC"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } } else { print $sql; } print '
RéfProduitPrixRemiseQté.
[$objp->ref]'.$objp->product.'".price($objp->price)."'.$objp->remise_percent.' %".$objp->qty."
 '.$objp->product.''.price($objp->price).''.$objp->remise_percent.' %".$objp->qty."
'; } /* * Produits dans la commande * */ if ($_GET["commandeid"]) { print_titre("Produits"); print ''; print ''; print ''; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt, ".MAIN_DB_PREFIX."product as p"; $sql .= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = ".$commande->id; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ''; print ''; print ''; $i++; } } else { print $sql; } print '
RéfProduitPrixRemiseQté.
[$objp->ref]'.$objp->product.''.price($objp->subprice).''.$objp->remise_percent.' %'.$objp->qty.'
'; } } } else { print $db->error(); } } else /* *************************************************************************** */ /* */ /* Mode fiche */ /* */ /* *************************************************************************** */ { if ($_GET["facid"] > 0) { $fac = New Facture($db); if ( $fac->fetch($_GET["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); /* * Confirmation de la suppression de la facture * */ if ($_GET["action"] == 'delete') { $html->form_confirm("$PHP_SELF?facid=$fac->id","Supprimer la facture","Etes-vous sûr de vouloir supprimer cette facture ?","confirm_delete"); } /* * Confirmation de la validation * */ if ($action == 'valid') { $numfa = facture_get_num($soc); $html->form_confirm("$PHP_SELF?facid=$fac->id","Valider la facture","Etes-vous sûr de vouloir valider cette facture avec le numéro $numfa ?","confirm_valid"); } /* * Facture */ print ''; print ""; print "'; print ""; print ""; print "\n"; print ""; 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) ."
Projet'; if ($fac->projetid > 0) { $projet = New Project($db); $projet->fetch($fac->projetid); print ''.$projet->title.''; } else { print 'Classer la facture'; } print " Paiements
Auteur$author->fullname'; } else { print ''; } /* * Paiements */ $sql = "SELECT ".$db->pdate("datep")." as dp, pf.amount,"; $sql .= "c.libelle as paiement_type, p.num_paiement, p.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf"; $sql .= " WHERE pf.fk_facture = ".$fac->id." AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid"; $sql .= " ORDER BY dp DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; echo ''; print ''; print ""; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print "\n"; print "\n"; print '\n"; print ""; $total = $total + $objp->amount; $i++; } if ($fac->paye == 0) { print "\n"; print "\n"; $resteapayer = $fac->total_ttc - $total; print ""; print "\n"; } print "
DateTypeMontant 
"; print ''.img_file().''; print " ".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."$_MONNAIE
Total :".price($total)."$_MONNAIE
Facturé :".price($fac->total_ttc)."$_MONNAIE
Reste à payer :".price($resteapayer)."$_MONNAIE
"; $db->free(); } else { print $db->error(); } print "
Montant'.price($fac->total_ht).''.MAIN_MONNAIE.' HT
Remise'.$fac->remise_percent.'%
TVA'.price($fac->total_tva).''.MAIN_MONNAIE.'
Total'.price($fac->total_ttc).''.MAIN_MONNAIE.' TTC
Note : '.nl2br($fac->note)."

"; if ($fac->brouillon == 1 && $user->rights->facture->creer) { print '
'; print ''; print '
Remise'; print '%'; print ''; print '
'; } /* * Lignes de factures * */ $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l WHERE l.fk_facture = $fac->id ORDER BY l.rowid"; $result = $db->query($sql); if ($result) { $num_lignes = $db->num_rows(); $i = 0; $total = 0; echo ''; if ($num_lignes) { print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=True; while ($i < $num_lignes) { $objp = $db->fetch_object( $i); $var=!$var; print ""; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } print ''; print '\n"; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; // Icone d'edition et suppression if ($fac->statut == 0 && $user->rights->facture->creer) { print ''; print ''; } else { print ''; } print ""; if ($action == 'editline' && $rowid == $objp->rowid) { print "id\" method=\"post\">"; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print '' . "\n"; print "\n"; } $total = $total + ($objp->qty * $objp->price); $i++; } $db->free(); // print "
DescriptionTvaP.U. HTQuantitéRemiseMontant HT  
'.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_taux.' %'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."'; print img_edit(); print ''; print img_delete(); print '  
  %
"; } else { print $db->error(); } /* * Ajouter une ligne * */ if ($fac->statut == 0 && $user->rights->facture->creer) { print "
id\" method=\"post\">"; // echo ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ""; } print "
DescriptionTvaP.U. HTQuantitéRemise   
'; print $html->select_tva("tva_tx",$conf->defaulttx); print ' %
"; /* * Fin Ajout ligne * */ if ($user->societe_id == 0 && $_GET["action"] <> 'valid') { print "
\n"; // Valider if ($fac->statut == 0 && $num_lignes > 0) { if ($user->rights->facture->valider) { print "id&action=valid\">Valider"; } } else { // Générer if ($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer) { if ($fac->paye == 0) { print "id&action=pdf\">Générer la facture"; } else { print "id&action=pdf\">Regénérer la facture"; } } } // Supprimer if ($fac->statut == 0 && $user->rights->facture->supprimer) { print "id&action=delete\">Supprimer"; } // Envoyer if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) { print "id&action=presend\">Envoyer"; } // Envoyer une relance if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) { print "id&action=prerelance\">Envoyer une relance"; } // Emettre paiement if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->paiement) { print "id."&action=create\">Emettre un paiement"; } // Classer 'payé' if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->rights->facture->paiement) { print "id&action=payed\">Classer 'Payée'"; } // Récurrente if (! defined("FACTURE_DISABLE_RECUR")) // Possibilité de désactiver les factures récurrentes { if ($fac->statut > 0) { print 'Récurrente'; } } print "
"; } 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 '
'; /* * Liste des actions * */ $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_facture = $fac->id"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); if ($num) { print_titre("Actions"); $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 == 'classer') { print "

id\">\n"; print ''; print ''; print '"; print '
Projet'; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($socidp)); print "

'; } /* * * */ if ($action == 'presend') { $replytoname = $user->fullname; $from_name = $replytoname; $replytomail = $user->email; $from_mail = $replytomail; print "
id&action=send\">\n"; print ''; print ''; print ''; print ''; print '
'; print_titre("Envoyer la facture par mail"); print ""; print ""; print ""; print '"; print '"; print "
Expéditeur$from_name$from_mail  
Répondre à$replytoname$replytomail  
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); print " ou email\">
Message'; print "

\n"; print "
\n"; } if ($action == 'prerelance') { $replytoname = $user->fullname; $from_name = $replytoname; $replytomail = $user->email; $from_mail = $replytomail; print "
id&action=send\">\n"; print ''; print ''; print ''; print ''; print '
'; print_titre("Envoyer une relance par mail"); print ""; print ""; print ""; print '"; print '"; print "
Expéditeur$from_name$from_mail  
Répondre à$replytoname$replytomail  
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); print " ou email\">
Message'; print "

\n"; print "
\n"; } /* * Propales */ $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid"; $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $fac->id"; $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,f.total_ttc,".$db->pdate("f.datef")." as df,f.paye,f.rowid as facid, f.fk_statut, sum(pf.amount) as am"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture 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 .= " GROUP BY f.facnumber"; $sql .= " ORDER BY $sortfield $sortorder, f.rowid DESC "; $sql .= $db->plimit($limit + 1,$offset); $result = $db->query($sql); } if ($result) { $num = $db->num_rows(); print_barre_liste("Factures clients",$page,$PHP_SELF,"&socidp=$socidp",$sortfield,$sortorder,'',$num); $i = 0; print ''; print ''; print ''; print ''; print "\n"; if ($num > 0) { $var=True; $total=0; $totalrecu=0; 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"; if ($objp->df > 0 ) { print "\n"; } else { print "\n"; } print ''; print ""; print ""; print ""; if (! $objp->paye) { if ($objp->fk_statut == 0) { print ''; } else { print ''; } } else { print ''; } print "\n"; $total+=$objp->total; $total_ttc+=$objp->total_ttc; $totalrecu+=$objp->am; $i++; } if ($num <= $limit) { // Print total print ""; print ""; print ""; print ""; print ""; print ''; print "\n"; } } print "
'; print_liste_field_titre("Numéro",$PHP_SELF,"f.facnumber","","&socidp=$socidp"); print ''; print_liste_field_titre("Date",$PHP_SELF,"f.datef","","&socidp=$socidp"); print ''; print_liste_field_titre("Société",$PHP_SELF,"s.nom","","&socidp=$socidp"); print ''; print_liste_field_titre("Montant HT",$PHP_SELF,"f.total","","&socidp=$socidp"); print ''; print_liste_field_titre("Montant TTC",$PHP_SELF,"f.totalttc","","&socidp=$socidp"); print 'ReçuStatus
'.img_file()." \n"; print ''.$objp->facnumber.""; $y = strftime("%Y",$objp->df); $m = strftime("%m",$objp->df); print strftime("%d",$objp->df)."\n"; print ' '; print substr(strftime("%B",$objp->df),0,3)."\n"; print ' '; print strftime("%Y",$objp->df)."!!!'.$objp->nom.'".price($objp->total)."".price($objp->total_ttc)."".price($objp->am)."brouillon'.($objp->am?"commencé":"impayée").'payée
Total : ".price($total)."".price($total_ttc)."".price($totalrecu)." 
"; $db->free(); } else { print $db->error() . "
" . $sql; } } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>