diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e6bebcb8992..22c2384403a 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1,416 +1,416 @@ - - * Copyright (C) 2004 Éric Seigne - * Copyright (C) 2004-2005 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$ - */ - -/** - \file htdocs/compta/facture.php - \ingroup facture - \brief Page de création d'une facture - \version $Revision$ -*/ - -require("./pre.inc.php"); - -$user->getrights('facture'); -$user->getrights('banque'); - -if (!$user->rights->facture->lire) -accessforbidden(); - -$langs->load("bills"); - - -require_once "../facture.class.php"; -require_once "../paiement.class.php"; -if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); -if ($conf->propal->enabled) require_once("../propal.class.php"); -if ($conf->contrat->enabled) require_once("../contrat/contrat.class.php"); -if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); -require_once DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"; - - -if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; } -if (isset($_GET["msg"])) { $msg=urldecode($_GET["msg"]); } - -// Sécurité accés client -if ($user->societe_id > 0) -{ - $action = ''; - $socidp = $user->societe_id; -} - -// Nombre de ligne pour choix de produit/service prédéfinis -$NBLINES=4; - - -/* - * Actions - */ - -if ($_POST["action"] == 'classin') -{ - $facture = new Facture($db); - $facture->fetch($_GET["facid"]); - $facture->classin($_POST["projetid"]); -} - -/* - * Insertion facture - */ -if ($_POST["action"] == 'add') -{ - $datefacture = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - - $facture = new Facture($db, $_POST["socid"]); - - $facture->number = $_POST["facnumber"]; - $facture->date = $datefacture; - $facture->note = $_POST["note"]; - - if ($_POST["fac_rec"] > 0) - { - // Facture récurrente - $facture->fac_rec = $_POST["fac_rec"]; - $facid = $facture->create($user); - } - else - { - $facture->projetid = $_POST["projetid"]; - $facture->cond_reglement = $_POST["condid"]; - $facture->mode_reglement = $_POST["mode_reglement"]; - $facture->amount = $_POST["amount"]; - $facture->remise = $_POST["remise"]; - $facture->remise_percent = $_POST["remise_percent"]; - - if (!$_POST["propalid"] && !$_POST["commandeid"]) + + * Copyright (C) 2004 Éric Seigne + * Copyright (C) 2004-2005 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$ + */ + +/** + \file htdocs/compta/facture.php + \ingroup facture + \brief Page de création d'une facture + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$user->getrights('facture'); +$user->getrights('banque'); + +if (!$user->rights->facture->lire) +accessforbidden(); + +$langs->load("bills"); + + +require_once "../facture.class.php"; +require_once "../paiement.class.php"; +if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/project.class.php"); +if ($conf->propal->enabled) require_once("../propal.class.php"); +if ($conf->contrat->enabled) require_once("../contrat/contrat.class.php"); +if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); +require_once DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"; + + +if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; } +if (isset($_GET["msg"])) { $msg=urldecode($_GET["msg"]); } + +// Sécurité accés client +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + +// Nombre de ligne pour choix de produit/service prédéfinis +$NBLINES=4; + + +/* + * Actions + */ + +if ($_POST["action"] == 'classin') +{ + $facture = new Facture($db); + $facture->fetch($_GET["facid"]); + $facture->classin($_POST["projetid"]); +} + +/* + * Insertion facture + */ +if ($_POST["action"] == 'add') +{ + $datefacture = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + $facture = new Facture($db, $_POST["socid"]); + + $facture->number = $_POST["facnumber"]; + $facture->date = $datefacture; + $facture->note = $_POST["note"]; + + if ($_POST["fac_rec"] > 0) + { + // Facture récurrente + $facture->fac_rec = $_POST["fac_rec"]; + $facid = $facture->create($user); + } + else + { + $facture->projetid = $_POST["projetid"]; + $facture->cond_reglement = $_POST["condid"]; + $facture->mode_reglement = $_POST["mode_reglement"]; + $facture->amount = $_POST["amount"]; + $facture->remise = $_POST["remise"]; + $facture->remise_percent = $_POST["remise_percent"]; + + if (!$_POST["propalid"] && !$_POST["commandeid"]) { - for ($i = 1 ; $i <= $NBLINES ; $i++) - { - if ($_POST["idprod${i}"]) - { - $startday=''; - $endday=''; - if ($_POST["date_start${i}year"] && $_POST["date_start${i}month"] && $_POST["date_start${i}day"]) { - $startday=$_POST["date_start${i}year"].'-'.$_POST["date_start${i}month"].'-'.$_POST["date_start${i}day"]; - } - if ($_POST["date_end${i}year"] && $_POST["date_end${i}month"] && $_POST["date_end${i}day"]) { - $endday=$_POST["date_end${i}year"].'-'.$_POST["date_end${i}month"].'-'.$_POST["date_end${i}day"]; - } - $facture->add_product($_POST["idprod${i}"],$_POST["qty${i}"],$_POST["remise_percent${i}"],$startday,$endday); - - } - } - $facid = $facture->create($user); - - if ($facid) - { - Header("Location: facture.php?facid=".$facid); - exit; - } - } - else - { - /* - * Si creation depuis propale - */ - if ($_POST["propalid"]) - { - $facture->propalid = $_POST["propalid"]; - - $facid = $facture->create($user); - - if ($facid) - { - $prop = New Propal($db); - if ( $prop->fetch($_POST["propalid"]) ) - { - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) - { - $liblignefac=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); - - $result = $facture->addline($facid, - addslashes($liblignefac), - $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 $langs->trans("UnknownError"); - } - } - } - - /* - * Commande - */ - if ($_POST["commandeid"]) - { - $facture->commandeid = $_POST["commandeid"]; - $facid = $facture->create($user); - - if ($facid) - { - $comm = New Commande($db); - if ( $comm->fetch($_POST["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 $langs->trans("UnknownError"); - } - } - else - { - dolibarr_print_error($db); - } - } - - if ($facid) - { - Header("Location: facture.php?facid=".$facid); - exit; - } - } - } -} - -/* - * - */ -if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->facture->valider) -{ - $fac = new Facture($db); - $fac->fetch($_GET["facid"]); - $soc = new Societe($db); - $soc->fetch($fac->socidp); + for ($i = 1 ; $i <= $NBLINES ; $i++) + { + if ($_POST["idprod${i}"]) + { + $startday=''; + $endday=''; + if ($_POST["date_start${i}year"] && $_POST["date_start${i}month"] && $_POST["date_start${i}day"]) { + $startday=$_POST["date_start${i}year"].'-'.$_POST["date_start${i}month"].'-'.$_POST["date_start${i}day"]; + } + if ($_POST["date_end${i}year"] && $_POST["date_end${i}month"] && $_POST["date_end${i}day"]) { + $endday=$_POST["date_end${i}year"].'-'.$_POST["date_end${i}month"].'-'.$_POST["date_end${i}day"]; + } + $facture->add_product($_POST["idprod${i}"],$_POST["qty${i}"],$_POST["remise_percent${i}"],$startday,$endday); + + } + } + $facid = $facture->create($user); + + if ($facid) + { + Header("Location: facture.php?facid=".$facid); + exit; + } + } + else + { + /* + * Si creation depuis propale + */ + if ($_POST["propalid"]) + { + $facture->propalid = $_POST["propalid"]; + + $facid = $facture->create($user); + + if ($facid) + { + $prop = New Propal($db); + if ( $prop->fetch($_POST["propalid"]) ) + { + for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + { + $liblignefac=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); + + $result = $facture->addline($facid, + addslashes($liblignefac), + $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 $langs->trans("UnknownError"); + } + } + } + + /* + * Commande + */ + if ($_POST["commandeid"]) + { + $facture->commandeid = $_POST["commandeid"]; + $facid = $facture->create($user); + + if ($facid) + { + $comm = New Commande($db); + if ( $comm->fetch($_POST["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 $langs->trans("UnknownError"); + } + } + else + { + dolibarr_print_error($db); + } + } + + if ($facid) + { + Header("Location: facture.php?facid=".$facid); + exit; + } + } + } +} + +/* + * + */ +if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->facture->valider) +{ + $fac = new Facture($db); + $fac->fetch($_GET["facid"]); + $soc = new Societe($db); + $soc->fetch($fac->socidp); $result = $fac->set_valid($fac->id, $user, $soc); - if ($result) - { - facture_pdf_create($db, $fac->id); - } -} - -if ($_GET["action"] == 'payed' && $user->rights->facture->paiement) -{ - $fac = new Facture($db); - $result = $fac->set_payed($_GET["facid"]); -} - -if ($_POST["action"] == 'setremise' && $user->rights->facture->creer) -{ - $fac = new Facture($db); - $fac->fetch($_GET["facid"]); - - $fac->set_remise($user, $_POST["remise"]); -} - -if ($_POST["action"] == 'addligne' && $user->rights->facture->creer) -{ - $fac = new Facture($db); - $fac->fetch($_POST["facid"]); - $datestart=''; - $dateend=''; - if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { - $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; - } - if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { - $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; - } - $result = $fac->addline($_POST["facid"], - $_POST["desc"], - $_POST["pu"], - $_POST["qty"], - $_POST["tva_tx"], - 0, - $_POST["remise_percent"], - $datestart, - $dateend - ); - - $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition -} - -if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["save"] == $langs->trans("Save")) -{ - $fac = new Facture($db,"",$_POST["facid"]); - $fac->fetch($_POST["facid"]); - - $datestart=''; - $dateend=''; - if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { - $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; - } - if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { - $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; - } - - $result = $fac->updateline($_POST["rowid"], - $_POST["desc"], - $_POST["price"], - $_POST["qty"], - $_POST["remise_percent"], - $datestart, - $dateend - ); - - $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition -} - -if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["cancel"] == $langs->trans("Cancel")) -{ - Header("Location: facture.php?facid=".$_POST["facid"]); // Pour réaffichage de la fiche en cours d'édition - exit; -} - -if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) -{ - $fac = new Facture($db,"",$_GET["facid"]); - $fac->fetch($_GET["facid"]); - $result = $fac->deleteline($_GET["rowid"]); -} - -if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') -{ - if ($user->rights->facture->supprimer ) - { - $fac = new Facture($db); - $fac->delete($_GET["facid"]); - $_GET["facid"] = 0 ; - Header("Location: facture.php"); - exit; - } -} - -if ($_POST["action"] == 'confirm_canceled' && $_POST["confirm"] == 'yes') -{ - if ($user->rights->facture->supprimer ) - { - $fac = new Facture($db); - $result = $fac->set_canceled($_GET["facid"]); - $_GET["facid"] = 0 ; - Header("Location: facture.php"); - exit; - } -} - -/* - * Ordonnancement des lignes - */ - -if ($_GET["action"] == 'up' && $user->rights->facture->creer) -{ - $fac = new Facture($db,"",$_GET["facid"]); - $fac->line_up($_GET["rowid"]); -} - -if ($_GET["action"] == 'down' && $user->rights->facture->creer) -{ - $fac = new Facture($db,"",$_GET["facid"]); - $fac->line_down($_GET["rowid"]); -} - -/* - * Action envoi de mail - */ -if ($_POST["action"] == 'send' || $_POST["action"] == 'relance') -{ - $langs->load("mails"); - - $fac = new Facture($db,"",$_POST["facid"]); - if ( $fac->fetch($_POST["facid"]) ) - { - $facref = sanitize_string($fac->ref); - $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; - - if (is_readable($file)) - { - $soc = new Societe($db, $fac->socidp); - - if ($_POST["sendto"]) { - // Le destinataire a été fourni via le champ libre - $sendto = $_POST["sendto"]; - $sendtoid = 0; - } - elseif ($_POST["receiver"]) { - // Le destinataire a été fourni via la liste déroulante - $sendto = $soc->contact_get_email($_POST["receiver"]); - $sendtoid = $_POST["receiver"]; - } - - if (strlen($sendto)) - { - $from = $_POST["fromname"] . " <" . $_POST["frommail"] .">"; - $replyto = $_POST["replytoname"]. " <" . $_POST["replytomail"].">"; - $message = $_POST["message"]; - if ($_POST["action"] == 'send') { - $subject = $langs->trans("Bill")." $fac->ref"; - $actiontypeid=9; - $actionmsg ="Mail envoyé par $from à $sendto.
"; - if ($message) { - $actionmsg.="Texte utilisé dans le corps du message:
"; - $actionmsg.="$message"; - } - $actionmsg2="Envoi facture par mail"; - } - if ($_POST["action"] == 'relance') { - $subject = "Relance facture $fac->ref"; - $actiontypeid=10; - $actionmsg="Mail envoyé par $from à $sendto.
"; - if ($message) { - $actionmsg.="Texte utilisé dans le corps du message:
"; - $actionmsg.="$message"; - } - $actionmsg2="Relance facture par mail"; - } - - $filepath[0] = $file; - $filename[0] = $fac->ref.".pdf"; - $mimetype[0] = "application/pdf"; - $filepath[1] = $_FILES['addedfile']['tmp_name']; - $filename[1] = $_FILES['addedfile']['name']; - $mimetype[1] = $_FILES['addedfile']['type']; - - // Envoi de la facture - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc); - - if ($mailfile->sendfile()) - { - $msg='
'.$langs->trans("MailSuccessfulySent",$from,$sendto).'.
'; - + if ($result) + { + facture_pdf_create($db, $fac->id); + } +} + +if ($_GET["action"] == 'payed' && $user->rights->facture->paiement) +{ + $fac = new Facture($db); + $result = $fac->set_payed($_GET["facid"]); +} + +if ($_POST["action"] == 'setremise' && $user->rights->facture->creer) +{ + $fac = new Facture($db); + $fac->fetch($_GET["facid"]); + + $fac->set_remise($user, $_POST["remise"]); +} + +if ($_POST["action"] == 'addligne' && $user->rights->facture->creer) +{ + $fac = new Facture($db); + $fac->fetch($_POST["facid"]); + $datestart=''; + $dateend=''; + if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { + $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; + } + if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { + $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; + } + $result = $fac->addline($_POST["facid"], + $_POST["desc"], + $_POST["pu"], + $_POST["qty"], + $_POST["tva_tx"], + 0, + $_POST["remise_percent"], + $datestart, + $dateend + ); + + $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition +} + +if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["save"] == $langs->trans("Save")) +{ + $fac = new Facture($db,"",$_POST["facid"]); + $fac->fetch($_POST["facid"]); + + $datestart=''; + $dateend=''; + if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { + $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; + } + if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { + $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; + } + + $result = $fac->updateline($_POST["rowid"], + $_POST["desc"], + $_POST["price"], + $_POST["qty"], + $_POST["remise_percent"], + $datestart, + $dateend + ); + + $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition +} + +if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["cancel"] == $langs->trans("Cancel")) +{ + Header("Location: facture.php?facid=".$_POST["facid"]); // Pour réaffichage de la fiche en cours d'édition + exit; +} + +if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) +{ + $fac = new Facture($db,"",$_GET["facid"]); + $fac->fetch($_GET["facid"]); + $result = $fac->deleteline($_GET["rowid"]); +} + +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') +{ + if ($user->rights->facture->supprimer ) + { + $fac = new Facture($db); + $fac->delete($_GET["facid"]); + $_GET["facid"] = 0 ; + Header("Location: facture.php"); + exit; + } +} + +if ($_POST["action"] == 'confirm_canceled' && $_POST["confirm"] == 'yes') +{ + if ($user->rights->facture->supprimer ) + { + $fac = new Facture($db); + $result = $fac->set_canceled($_GET["facid"]); + $_GET["facid"] = 0 ; + Header("Location: facture.php"); + exit; + } +} + +/* + * Ordonnancement des lignes + */ + +if ($_GET["action"] == 'up' && $user->rights->facture->creer) +{ + $fac = new Facture($db,"",$_GET["facid"]); + $fac->line_up($_GET["rowid"]); +} + +if ($_GET["action"] == 'down' && $user->rights->facture->creer) +{ + $fac = new Facture($db,"",$_GET["facid"]); + $fac->line_down($_GET["rowid"]); +} + +/* + * Action envoi de mail + */ +if ($_POST["action"] == 'send' || $_POST["action"] == 'relance') +{ + $langs->load("mails"); + + $fac = new Facture($db,"",$_POST["facid"]); + if ( $fac->fetch($_POST["facid"]) ) + { + $facref = sanitize_string($fac->ref); + $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; + + if (is_readable($file)) + { + $soc = new Societe($db, $fac->socidp); + + if ($_POST["sendto"]) { + // Le destinataire a été fourni via le champ libre + $sendto = $_POST["sendto"]; + $sendtoid = 0; + } + elseif ($_POST["receiver"]) { + // Le destinataire a été fourni via la liste déroulante + $sendto = $soc->contact_get_email($_POST["receiver"]); + $sendtoid = $_POST["receiver"]; + } + + if (strlen($sendto)) + { + $from = $_POST["fromname"] . " <" . $_POST["frommail"] .">"; + $replyto = $_POST["replytoname"]. " <" . $_POST["replytomail"].">"; + $message = $_POST["message"]; + if ($_POST["action"] == 'send') { + $subject = $langs->trans("Bill")." $fac->ref"; + $actiontypeid=9; + $actionmsg ="Mail envoyé par $from à $sendto.
"; + if ($message) { + $actionmsg.="Texte utilisé dans le corps du message:
"; + $actionmsg.="$message"; + } + $actionmsg2="Envoi facture par mail"; + } + if ($_POST["action"] == 'relance') { + $subject = "Relance facture $fac->ref"; + $actiontypeid=10; + $actionmsg="Mail envoyé par $from à $sendto.
"; + if ($message) { + $actionmsg.="Texte utilisé dans le corps du message:
"; + $actionmsg.="$message"; + } + $actionmsg2="Relance facture par mail"; + } + + $filepath[0] = $file; + $filename[0] = $fac->ref.".pdf"; + $mimetype[0] = "application/pdf"; + $filepath[1] = $_FILES['addedfile']['tmp_name']; + $filename[1] = $_FILES['addedfile']['name']; + $mimetype[1] = $_FILES['addedfile']['type']; + + // Envoi de la facture + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc); + + if ($mailfile->sendfile()) + { + $msg='
'.$langs->trans("MailSuccessfulySent",$from,$sendto).'.
'; + // Insertion action include_once("../contact.class.php"); include_once("../actioncomm.class.php"); @@ -427,500 +427,537 @@ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance') $ret=$actioncomm->add($user); // User qui saisi l'action - if ($ret < 0) - { - dolibarr_print_error($db); - } - else - { - // Renvoie sur la fiche - Header("Location: facture.php?facid=".$fac->id."&msg=".urlencode($msg)); - exit; - } - } - else - { - $msg='
'.$langs->trans("ErrorFailedToSendMail",$from,$sendto).' !
'; - } - } - else - { - $msg='
'.$langs->trans("ErrorMailRecipientIsEmpty").'
'; - 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 ($_GET["action"] == 'pdf') -{ - // Generation de la facture définie dans /includes/modules/facture/modules_facture.php - // Génère également le fichier meta dans le m$eme répertoire (pour faciliter les recherches et indexation) - facture_pdf_create($db, $_GET["facid"]); -} - - -llxHeader('',$langs->trans("Bill"),'Facture'); - -$html = new Form($db); - - -/********************************************************************* -* -* Mode creation -* -**********************************************************************/ -if ($_GET["action"] == 'create') -{ - - print_titre($langs->trans("NewBill")); - - if ($_GET["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 = ".$_GET["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(); - - $soc = new Societe($db); - $soc->fetch($obj->idp); - - print '
'; - print ''; - print '' ."\n"; - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - - print ""; - - // Mode de réglement - print ""; - - // Projet - if ($conf->projet->enabled) - { - $langs->load("projects"); - print '"; - } - else - { - 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 - { - dolibarr_print_error($db); - } - } - - /* - * - */ - print ''; - print "\n"; - print "
'.$langs->trans("Company").' :'.$soc->nom.''.$langs->trans("Comments").'
'.$langs->trans("Author").' :'.$user->fullname.''; - print '
'.$langs->trans("Date").' :'; - $html->select_date(); - print '
'.$langs->trans("Ref").' :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($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $conds[$objp->rowid]=$objp->libelle; - $i++; - } - $db->free($result); - } - - $html->select_array("condid",$conds); - print "
Mode de réglement :"; - $sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY libelle"; - $result = $db->query($sql); - $modesregl=array(); - if ($result) - { - $num = $db->num_rows(); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object(); - $modesregl[$objp->id]=$objp->libelle; - $i++; - } - $db->free(); - } - - $html->select_array("mode_reglement",$modesregl); - print "
'.$langs->trans("Project").' :'; - $proj = new Project($db); - $html->select_array( - "projetid", - $proj->liste_array($socidp), - (is_object($commande) && !empty($commande->projet_id)) ? $commande->projet_id : '' - ); - print "
 
'.$langs->trans("Proposal").''.$obj->ref.'
'.$langs->trans("TotalHT").''.price($amount).'
'.$langs->trans("VAT").''.price($obj->tva)."
'.$langs->trans("TotalTTC").''.price($obj->total)."
'.$langs->trans("Order").''.$commande->ref.'
'.$langs->trans("TotalHT").''.price($commande->total_ht).'
'.$langs->trans("VAT").''.price($commande->total_tva)."
'.$langs->trans("TotalTTC").''.price($commande->total_ttc)."
 
'; - - print ''; - print ''; - if ($conf->service->enabled) - { - print ''; - } - for ($i = 1 ; $i <= $NBLINES ; $i++) - { - print ''; - print ''; - print ''; - print ''; - // Si le module service est actif, on propose des dates de début et fin à la ligne - if ($conf->service->enabled) { - print ''; - } - print "\n"; - } - - print '
Services/Produits prédéfinis'.$langs->trans("Qty").''.$langs->trans("Discount").'     Si produit de type service à durée limitée
'; - $html->select_produits('',"idprod$i"); - print '% '; - print 'Du '; - print $html->select_date('',"date_start$i",0,0,1); - print '
au '; - print $html->select_date('',"date_end$i",0,0,1); - print '
'; - print '
Factures récurrentes :
\n"; - - // Si creation depuis un propal - if ($_GET["propalid"]) - { - print '
'; - print_titre($langs->trans("ProductsAndServices")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Lignes de propal produits prédéfinis - $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = ".$_GET["propalid"]; - $sql .= " ORDER BY pt.rowid ASC"; - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print '\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - // Lignes de propal non produits prédéfinis - $sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt "; - $sql .= " WHERE pt.fk_propal = ".$_GET["propalid"]; - $sql .= " AND pt.fk_product = 0"; - $sql .= " ORDER BY pt.rowid ASC"; - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; - print $objp->product?' - '.$objp->product:''; - print "'; - print $objp->description; - print ''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
 '.$objp->product.''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
'; - } - - // Si creation depuis une commande - if ($_GET["commandeid"]) - { - print_titre($langs->trans("Products")); - - 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(); - $var=!$var; - print "\n"; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
[$objp->ref]'.$objp->product.''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
'; - } - - } - } - else - { - dolibarr_print_error($db); - } -} -else -/* *************************************************************************** */ -/* */ -/* Mode fiche */ -/* */ -/* *************************************************************************** */ -{ - - if ($_GET["facid"] > 0) - { - if ($msg) print "$msg
"; - - $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(); - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("CardBill"); - $hselected = $h; - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Preview"); - $h++; - - if ($fac->mode_reglement == 3) - { - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("StandingOrders"); - $h++; - } - - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Note"); - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); - - - /* - * Confirmation de la suppression de la facture - * - */ - if ($_GET["action"] == 'delete') - { - $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id",$langs->trans("DeleteBill"),$langs->trans("ConfirmDeleteBill"),"confirm_delete"); - print '
'; - } - - /* - * Confirmation du classement abandonn - * - */ - if ($_GET["action"] == 'canceled') - { - $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id",$langs->trans("CancelBill"),$langs->trans("ConfirmCancelBill"),"confirm_canceled"); - print '
'; - } - - /* - * Confirmation de la validation - * - */ - if ($_GET["action"] == 'valid') - { - $numfa = facture_get_num($soc); + if ($ret < 0) + { + dolibarr_print_error($db); + } + else + { + // Renvoie sur la fiche + Header("Location: facture.php?facid=".$fac->id."&msg=".urlencode($msg)); + exit; + } + } + else + { + $msg='
'.$langs->trans("ErrorFailedToSendMail",$from,$sendto).' !
'; + } + } + else + { + $msg='
'.$langs->trans("ErrorMailRecipientIsEmpty").'
'; + 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 ($_GET["action"] == 'pdf') +{ + // Generation de la facture définie dans /includes/modules/facture/modules_facture.php + // Génère également le fichier meta dans le m$eme répertoire (pour faciliter les recherches et indexation) + facture_pdf_create($db, $_GET["facid"]); +} + + +llxHeader('',$langs->trans("Bill"),'Facture'); + +$html = new Form($db); + + +/********************************************************************* +* +* Mode creation +* +**********************************************************************/ +if ($_GET["action"] == 'create') +{ + + print_titre($langs->trans("NewBill")); + + if ($_GET["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 = ".$_GET["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(); + + $soc = new Societe($db); + $soc->fetch($obj->idp); + + print '
'; + print ''; + print '' ."\n"; + print ''; + + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + + print ""; + + // Mode de réglement + print ""; + + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print '"; + } + else + { + 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 + { + dolibarr_print_error($db); + } + } + + /* + * + */ + print ''; + print "\n"; + print "
'.$langs->trans("Company").' :'.$soc->nom.''.$langs->trans("Comments").'
'.$langs->trans("Author").' :'.$user->fullname.''; + print '
'.$langs->trans("Date").' :'; + $html->select_date(); + print '
'.$langs->trans("Ref").' :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($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $conds[$objp->rowid]=$objp->libelle; + $i++; + } + $db->free($result); + } + + $html->select_array("condid",$conds); + print "
Mode de réglement :"; + $sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY libelle"; + $result = $db->query($sql); + $modesregl=array(); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object(); + $modesregl[$objp->id]=$objp->libelle; + $i++; + } + $db->free(); + } + + $html->select_array("mode_reglement",$modesregl); + print "
'.$langs->trans("Project").' :'; + $proj = new Project($db); + $html->select_array( + "projetid", + $proj->liste_array($socidp), + (is_object($commande) && !empty($commande->projet_id)) ? $commande->projet_id : '' + ); + print "
 
'.$langs->trans("Proposal").''.$obj->ref.'
'.$langs->trans("TotalHT").''.price($amount).'
'.$langs->trans("VAT").''.price($obj->tva)."
'.$langs->trans("TotalTTC").''.price($obj->total)."
'.$langs->trans("Order").''.$commande->ref.'
'.$langs->trans("TotalHT").''.price($commande->total_ht).'
'.$langs->trans("VAT").''.price($commande->total_tva)."
'.$langs->trans("TotalTTC").''.price($commande->total_ttc)."
 
'; + + print ''; + print ''; + if ($conf->service->enabled) + { + print ''; + } + for ($i = 1 ; $i <= $NBLINES ; $i++) + { + print ''; + print ''; + print ''; + print ''; + // Si le module service est actif, on propose des dates de début et fin à la ligne + if ($conf->service->enabled) { + print ''; + } + print "\n"; + } + + print '
Services/Produits prédéfinis'.$langs->trans("Qty").''.$langs->trans("Discount").'     Si produit de type service à durée limitée
'; + $html->select_produits('',"idprod$i"); + print '% '; + print 'Du '; + print $html->select_date('',"date_start$i",0,0,1); + print '
au '; + print $html->select_date('',"date_end$i",0,0,1); + print '
'; + print '
Factures récurrentes :
\n"; + + // Si creation depuis un propal + if ($_GET["propalid"]) + { + print '
'; + print_titre($langs->trans("ProductsAndServices")); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Lignes de propal produits prédéfinis + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = ".$_GET["propalid"]; + $sql .= " ORDER BY pt.rowid ASC"; + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print '\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + // Lignes de propal non produits prédéfinis + $sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt "; + $sql .= " WHERE pt.fk_propal = ".$_GET["propalid"]; + $sql .= " AND pt.fk_product = 0"; + $sql .= " ORDER BY pt.rowid ASC"; + $result=$db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; + print $objp->product?' - '.$objp->product:''; + print "'; + print $objp->description; + print ''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
 '.$objp->product.''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
'; + } + + // Si creation depuis une commande + if ($_GET["commandeid"]) + { + print_titre($langs->trans("Products")); + + print ''; + print ''; + print ''; + + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; + $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(); + $var=!$var; + print '\n"; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + // Lignes de commande non produits prédéfinis + $sql = "SELECT pt.rowid, pt.description as product, pt.subprice, pt.qty, pt.remise_percent"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt"; + $sql .= " WHERE pt.fk_commande = ".$commande->id; + $sql .= " AND pt.fk_product = 0"; + $sql .= " ORDER BY pt.rowid ASC"; + + $result=$db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; + print $objp->product?' - '.$objp->product:''; + print "'; + print $objp->description; + print ''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
 '.$objp->product.''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
'; + } + + } + } + else + { + dolibarr_print_error($db); + } +} +else +/* *************************************************************************** */ +/* */ +/* Mode fiche */ +/* */ +/* *************************************************************************** */ +{ + + if ($_GET["facid"] > 0) + { + if ($msg) print "$msg
"; + + $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(); + + $h = 0; + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("CardBill"); + $hselected = $h; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Preview"); + $h++; + + if ($fac->mode_reglement == 3) + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("StandingOrders"); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Note"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Info"); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + + + /* + * Confirmation de la suppression de la facture + * + */ + if ($_GET["action"] == 'delete') + { + $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id",$langs->trans("DeleteBill"),$langs->trans("ConfirmDeleteBill"),"confirm_delete"); + print '
'; + } + + /* + * Confirmation du classement abandonn + * + */ + if ($_GET["action"] == 'canceled') + { + $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id",$langs->trans("CancelBill"),$langs->trans("ConfirmCancelBill"),"confirm_canceled"); + print '
'; + } + + /* + * Confirmation de la validation + * + */ + if ($_GET["action"] == 'valid') + { + $numfa = facture_get_num($soc); $html->form_confirm("facture.php?facid=$fac->id",$langs->trans("ValidateBill"),$langs->trans("ConfirmValidateBill",$numfa),"confirm_valid"); print '
'; - } - - /* - * Facture - */ - print ''; - print ''; - print ''; - - print ""; - - print ''; - print "\n"; - print '"; - - print ''; - + } + + /* + * Facture + */ + print '
'.$langs->trans("Company").''; - print ''.$soc->nom.'Conditions de réglement" . $fac->cond_reglement ."
'.$langs->trans("Date").'".dolibarr_print_date($fac->date,"%A %d %B %Y")."'.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); - if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans("Late")); - print "
'; + print ''; + print ''; + + print ""; + + print ''; + print "\n"; + print '"; + + print ''; + // Projet if ($conf->projet->enabled) { @@ -941,124 +978,124 @@ else $html->form_project($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none"); } print ""; - } else { - print ''; - } + } else { + print ''; + } - print '"; - - print ""; - - print ''; - if ($fac->brouillon == 1 && $user->rights->facture->creer) - { - print ''; - print ''; - print ''; - print ''; - } - else { - print ''; - } - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - - if ($fac->note) - { - print '"; - } - else { - print ''; - } - - print "
'.$langs->trans("Company").''; + print ''.$soc->nom.'Conditions de réglement" . $fac->cond_reglement ."
'.$langs->trans("Date").'".dolibarr_print_date($fac->date,"%A %d %B %Y")."'.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); + if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans("Late")); + print "
    '; - - /* - * Paiements - */ - print $langs->trans("Payments").' :
'; - $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($result); - $i = 0; $total = 0; - print ''; - print ''; - print ''; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print "\n"; - print "\n"; - print '\n"; - print ""; - $totalpaye += $objp->amount; - $i++; - } - - if ($fac->paye == 0) - { - print "\n"; - print "\n"; - - $resteapayer = $fac->total_ttc - $totalpaye; - - print ""; - print "\n"; - } - print "
'.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; - print ''.img_object($langs->trans("ShowPayment"),"payment").''; - print " ".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("AlreadyPayed")." :".price($totalpaye)."".$langs->trans("Currency".$conf->monnaie)."
Facturé :".price($fac->total_ttc)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)."".$langs->trans("Currency".$conf->monnaie)."
"; - $db->free($result); - } else { - dolibarr_print_error($db); - } - - print "
".$langs->trans("Author")."$author->fullname
'.$langs->trans("GlobalDiscount").'
% '; - print ''.$fac->remise_percent.'%
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("VAT").''.price($fac->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("Status").''.($fac->getLibStatut()).'
'.$langs->trans("Note").' : '.nl2br($fac->note)."
 

"; - - /* - * Lignes de factures - */ - $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,"; - $sql .= " l.remise_percent, l.subprice,"; - $sql .= " ".$db->pdate("l.date_start")." as date_start,"; - $sql .= " ".$db->pdate("l.date_end")." as date_end, "; - $sql .= " p.ref, p.fk_product_type, p.label as product"; - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l "; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON l.fk_product=p.rowid"; - $sql .= " WHERE l.fk_facture = ".$fac->id; - $sql .= " ORDER BY l.rang ASC, l.rowid"; - - $resql = $db->query($sql); - if ($resql) - { - $num_lignes = $db->num_rows($resql); - $i = 0; $total = 0; - - print ''; - if ($num_lignes) - { + print '"; + + print ""; + + print ''; + if ($fac->brouillon == 1 && $user->rights->facture->creer) + { + print ''; + print ''; + print ''; + print ''; + } + else { + print ''; + } + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + + if ($fac->note) + { + print '"; + } + else { + print ''; + } + + print "
'; + + /* + * Paiements + */ + print $langs->trans("Payments").' :
'; + $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($result); + $i = 0; $total = 0; + print ''; + print ''; + print ''; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print "\n"; + print "\n"; + print '\n"; + print ""; + $totalpaye += $objp->amount; + $i++; + } + + if ($fac->paye == 0) + { + print "\n"; + print "\n"; + + $resteapayer = $fac->total_ttc - $totalpaye; + + print ""; + print "\n"; + } + print "
'.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; + print ''.img_object($langs->trans("ShowPayment"),"payment").''; + print " ".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("AlreadyPayed")." :".price($totalpaye)."".$langs->trans("Currency".$conf->monnaie)."
Facturé :".price($fac->total_ttc)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)."".$langs->trans("Currency".$conf->monnaie)."
"; + $db->free($result); + } else { + dolibarr_print_error($db); + } + + print "
".$langs->trans("Author")."$author->fullname
'.$langs->trans("GlobalDiscount").'
% '; + print ''.$fac->remise_percent.'%
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("VAT").''.price($fac->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("Status").''.($fac->getLibStatut()).'
'.$langs->trans("Note").' : '.nl2br($fac->note)."
 

"; + + /* + * Lignes de factures + */ + $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,"; + $sql .= " l.remise_percent, l.subprice,"; + $sql .= " ".$db->pdate("l.date_start")." as date_start,"; + $sql .= " ".$db->pdate("l.date_end")." as date_end, "; + $sql .= " p.ref, p.fk_product_type, p.label as product"; + $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l "; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON l.fk_product=p.rowid"; + $sql .= " WHERE l.fk_facture = ".$fac->id; + $sql .= " ORDER BY l.rang ASC, l.rowid"; + + $resql = $db->query($sql); + if ($resql) + { + $num_lignes = $db->num_rows($resql); + $i = 0; $total = 0; + + print ''; + if ($num_lignes) + { print ''; print ''; print ''; @@ -1066,26 +1103,26 @@ else print ''; print ''; print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num_lignes) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - // Update ligne de facture - if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) - { + print ''; + print "\n"; + } + $var=true; + while ($i < $num_lignes) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + // Update ligne de facture + if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) + { print ''; - if ($objp->fk_product > 0) - { - print ''; - } - else - { + 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 ''; - - print ''; - } - } - else - { - print ''; - } - print ""; - - } - - // Update ligne de facture - if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) - { - print ''; - print ''; - print ''; - print ''; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - if ($conf->service->enabled) - { - print ""; - print ''; - print '' . "\n"; - } - print "\n"; - } - - $total = $total + ($objp->qty * $objp->price); - $i++; - } - - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - - /* - * Ajouter une ligne - */ - if ($fac->statut == 0 && $user->rights->facture->creer && $_GET["action"] <> 'valid') - { - - print ""; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; - print ''; - - $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($conf->service->enabled) - { - print ''; - print ''; - } - print ''; - print ""; - } - print "
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').' 
 
'; - if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); - else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.''; - print ' - '.nl2br($objp->product); + if ($objp->fk_product > 0) + { + print ''; + if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); + else print img_object($langs->trans('ShowProduct'),'product'); + print ' '.$objp->ref.''; + print ' - '.nl2br($objp->product); if ($objp->date_start && $objp->date_end) { print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; @@ -1099,10 +1136,10 @@ else print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; } print ($objp->description&&$objp->description!=$objp->product)?'
'.$objp->description:''; - print '
'.stripslashes(nl2br($objp->description)); if ($objp->date_start && $objp->date_end) { @@ -1116,696 +1153,696 @@ else { print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; } - print "'.$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 ''; - if ($i > 0) - { - print ''; - print img_up(); - print ''; - } - if ($i < $num_lignes-1) - { - print ''; - print img_down(); - print ' 
'; - if ($objp->fk_product > 0) - { - print ''; - if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); - else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.''; - print ' - '.stripslashes(nl2br($objp->product)); - print '
'; - } - print '
'; - //print $html->select_tva("tva_tx",$objp->tva_taux); - print $objp->tva_taux."%"; // Taux tva dépend du produit, donc on ne doit pas pouvoir le changer ici - print '%'; - print '
Si produit de type service à durée limitée: Du '; - print $html->select_date($objp->date_start,"date_start",0,0,$objp->date_start?0:1); - print ' au '; - print $html->select_date($objp->date_end,"date_end",0,0,$objp->date_end?0:1); - print '
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'    
'; - print $html->select_tva("tva_tx",$conf->defaulttx); - print '%
Si produit de type service à durée limitée: Du '; - print $html->select_date('',"date_start",0,0,1); - print ' au '; - print $html->select_date('',"date_end",0,0,1); - print '
\n"; - - - print "\n"; - - - /* - * Boutons actions - */ - - if ($user->societe_id == 0 && $_GET["action"] <> 'valid' && $_GET["action"] <> 'editline') - { - print "
\n"; - - // Valider - if ($fac->statut == 0 && $num_lignes > 0) - { - if ($user->rights->facture->valider) - { - print " id."&action=valid\">".$langs->trans("Valid")."\n"; - } - } - 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\">".$langs->trans("BuildPDF")."\n"; - } - else - { - print " id&action=pdf\">".$langs->trans("RebuildPDF")."\n"; - } - } - } - - // Supprimer - if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET["action"] != 'delete') - { - print "id&action=delete\">".$langs->trans("Delete").""; - } - - // Envoyer - if ($fac->statut == 1 && $user->rights->facture->envoyer) - { - print " id&action=presend\">".$langs->trans("Send")."\n"; - } - - // Envoyer une relance - if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) - { - print " id&action=prerelance\">".$langs->trans("SendRemind")."\n"; - } - - // Emettre paiement - if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) - { - print " id."&action=create\">".$langs->trans("DoPaiement")."\n"; - } - - // Classer 'payé' - if ($fac->statut == 1 && price($resteapayer) <= 0 - && $fac->paye == 0 && $user->rights->facture->paiement) - { - print " id&action=payed\">".$langs->trans("ClassifyPayed")."\n"; - } - - // Classer 'abandonnée' (possible si validée et pas encore classer payée) - if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) - { - print " id&action=canceled\">".$langs->trans("ClassifyCanceled")."\n"; - } - - // Récurrente - if (! defined("FACTURE_DISABLE_RECUR")) // Possibilité de désactiver les factures récurrentes - { - if ($fac->statut > 0) - { - print " id."&action=create\">Récurrente\n"; - } - } - - print "
\n"; - - } - - print '
'; - - /* - * Documents générés - * Le fichier de facture détaillée est de la forme - * REFFACTURE-XXXXXX-detail.pdf ou XXXXX est une forme diverse - */ - - $facref = sanitize_string($fac->ref); - $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; - $relativepath = "${facref}/${facref}.pdf"; - - $var=true; - - if (file_exists($file)) - { - print "
\n"; - print_titre("Documents"); - print ''; - - print ""; - - print ''; - print ''; - print ''; - print ''; - - - $dir = $conf->facture->dir_output . "/" . $facref . "/"; - $handle=opendir($dir); - - while (($file = readdir($handle))!==false) - { - if (is_readable($dir.$file) && substr($file, -10) == 'detail.pdf') - { - print ""; - $relativepathdetail = "${facref}/$file"; - - print ''; - print ''; - print ''; - print ''; - } - } - print "
".$langs->trans("Bill")." PDF'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Facture détaillée'.$file.''.filesize($dir.$file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($dir.$file)).'
\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"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num) - { - $i = 0; $total = 0; - print "
"; - print_titre($langs->trans("RelatedCommercialProposals")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - print ""; - print ''; - print "\n"; - print ''; - print ""; - $total = $total + $objp->price; - $i++; - } - print "\n"; - print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'".dolibarr_print_date($objp->dp)."'.price($objp->price).'
 ".$langs->trans("TotalHT")."".price($total)."
"; - } - } - else - { - dolibarr_print_error($db); - } - - - print '
'; - - /* - * Liste des actions propres à la facture - */ - $sql = "SELECT id, ".$db->pdate("a.datea")." as da, a.label, a.note, code"; - $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."user as u "; - $sql .= " WHERE a.fk_user_author = u.rowid "; - $sql .= " AND a.fk_action in (9,10) "; - $sql .= " AND a.fk_soc = ".$fac->socidp ; - $sql .= " AND a.fk_facture = ".$fac->id; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num) - { - print "
\n"; - print_titre($langs->trans("ActionsOnBill")); - - $i = 0; $total = 0; - print ''; - print ''; - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - print ""; - print ''; - print '\n"; - print ''; - print ''; - print "\n"; - $i++; - } - print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Action").''.$langs->trans("By").'
'.img_object($langs->trans("ShowTask"),"task").' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$objp->code.'
\n"; - } - } - else - { - dolibarr_print_error($db); - } - - print "
"; - - - /* - * Affiche formulaire mail - */ - if ($_GET["action"] == 'presend') - { - print '
'; - print_titre($langs->trans("SendBillByMail")); - - $liste[0]=" "; - foreach ($soc->contact_email_array() as $key=>$value) { - $liste[$key]=$value; - } - - // Créé l'objet formulaire mail - include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php"); - $formmail = new FormMail($db); - $formmail->fromname = $user->fullname; - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=$liste; - $formmail->withcc=1; - $formmail->withtopic=$langs->trans("SendBillRef","__FACREF__"); - $formmail->withfile=1; - $formmail->withbody=1; - // Tableau des substitutions - $formmail->substit["__FACREF__"]=$fac->ref; - // Tableau des paramètres complémentaires du post - $formmail->param["action"]="send"; - $formmail->param["models"]="facture_send"; - $formmail->param["facid"]=$fac->id; - $formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id"; - - $formmail->show_form(); - - print '
'; - } - - if ($_GET["action"] == 'prerelance') - { - print '
'; - print_titre($langs->trans("SendReminderBillByMail")); - - $liste[0]=" "; - foreach ($soc->contact_email_array() as $key=>$value) - { - $liste[$key]=$value; - } - - // Créé l'objet formulaire mail - include_once("../html.formmail.class.php"); - $formmail = new FormMail($db); - $formmail->fromname = $user->fullname; - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=$liste; - $formmail->withcc=1; - $formmail->withtopic=$langs->trans("SendReminderBillRef","__FACREF__"); - $formmail->withfile=1; - $formmail->withbody=1; - // Tableau des substitutions - $formmail->substit["__FACREF__"]=$fac->ref; - // Tableau des paramètres complémentaires - $formmail->param["action"]="relance"; - $formmail->param["models"]="facture_relance"; - $formmail->param["facid"]=$fac->id; - $formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id"; - - $formmail->show_form(); - - print '
'; - } - - } - else - { - /* Facture non trouvée */ - print $langs->trans("ErrorBillNotFound",$_GET["facid"]); - } - } - else - { - /*************************************************************************** - * * - * Mode Liste * - * * - ***************************************************************************/ - $page = $_GET["page"]; - $sortorder=$_GET["sortorder"]; - $sortfield=$_GET["sortfield"]; - $month=$_GET["month"]; - $year=$_GET["year"]; - - $fac=new Facture($db); - - 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.increment,f.total,f.total_ttc,"; + print "\n"; + } + print ''.$objp->tva_taux.'%'; + print ''.price($objp->subprice)."\n"; + print ''.$objp->qty.''; + if ($objp->remise_percent > 0) + { + print ''.$objp->remise_percent."%\n"; + } + else + { + print ' '; + } + print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."\n"; + + // Icone d'edition et suppression + if ($fac->statut == 0 && $user->rights->facture->creer) + { + print ''; + print img_edit(); + print ''; + print ''; + print img_delete(); + print ''; + + print ''; + if ($i > 0) + { + print ''; + print img_up(); + print ''; + } + if ($i < $num_lignes-1) + { + print ''; + print img_down(); + print ''; + } + } + else + { + print ' '; + } + print ""; + + } + + // Update ligne de facture + if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) + { + print '
'; + print ''; + print ''; + print ''; + print ""; + print ''; + if ($objp->fk_product > 0) + { + print ''; + if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); + else print img_object($langs->trans('ShowProduct'),'product'); + print ' '.$objp->ref.''; + print ' - '.stripslashes(nl2br($objp->product)); + print '
'; + } + print ''; + print ''; + //print $html->select_tva("tva_tx",$objp->tva_taux); + print $objp->tva_taux."%"; // Taux tva dépend du produit, donc on ne doit pas pouvoir le changer ici + print ''; + print ''; + print ''; + print '%'; + print ''; + print '
'; + print '' . "\n"; + if ($conf->service->enabled) + { + print ""; + print 'Si produit de type service à durée limitée: Du '; + print $html->select_date($objp->date_start,"date_start",0,0,$objp->date_start?0:1); + print ' au '; + print $html->select_date($objp->date_end,"date_end",0,0,$objp->date_end?0:1); + print ''; + print '' . "\n"; + } + print "
\n"; + } + + $total = $total + ($objp->qty * $objp->price); + $i++; + } + + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + + /* + * Ajouter une ligne + */ + if ($fac->statut == 0 && $user->rights->facture->creer && $_GET["action"] <> 'valid') + { + + print "
"; + print ""; + print ''.$langs->trans("Description").''; + print ''.$langs->trans("VAT").''; + print ''.$langs->trans("PriceUHT").''; + print ''.$langs->trans("Qty").''; + print ''.$langs->trans("Discount").''; + print ' '; + print ' '; + print ' '; + print ' '; + print "\n"; + print ''; + print ''; + + $var=!$var; + + print ''; + print ''; + print ''; + print $html->select_tva("tva_tx",$conf->defaulttx); + print ''; + print ''; + print ''; + print '%'; + print ''; + if ($conf->service->enabled) + { + print ''; + print 'Si produit de type service à durée limitée: Du '; + print $html->select_date('',"date_start",0,0,1); + print ' au '; + print $html->select_date('',"date_end",0,0,1); + print ''; + } + print ''; + print "
"; + } + print "\n"; + + + print "\n"; + + + /* + * Boutons actions + */ + + if ($user->societe_id == 0 && $_GET["action"] <> 'valid' && $_GET["action"] <> 'editline') + { + print "
\n"; + + // Valider + if ($fac->statut == 0 && $num_lignes > 0) + { + if ($user->rights->facture->valider) + { + print " id."&action=valid\">".$langs->trans("Valid")."\n"; + } + } + 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\">".$langs->trans("BuildPDF")."\n"; + } + else + { + print " id&action=pdf\">".$langs->trans("RebuildPDF")."\n"; + } + } + } + + // Supprimer + if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET["action"] != 'delete') + { + print "id&action=delete\">".$langs->trans("Delete").""; + } + + // Envoyer + if ($fac->statut == 1 && $user->rights->facture->envoyer) + { + print " id&action=presend\">".$langs->trans("Send")."\n"; + } + + // Envoyer une relance + if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) + { + print " id&action=prerelance\">".$langs->trans("SendRemind")."\n"; + } + + // Emettre paiement + if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) + { + print " id."&action=create\">".$langs->trans("DoPaiement")."\n"; + } + + // Classer 'payé' + if ($fac->statut == 1 && price($resteapayer) <= 0 + && $fac->paye == 0 && $user->rights->facture->paiement) + { + print " id&action=payed\">".$langs->trans("ClassifyPayed")."\n"; + } + + // Classer 'abandonnée' (possible si validée et pas encore classer payée) + if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement) + { + print " id&action=canceled\">".$langs->trans("ClassifyCanceled")."\n"; + } + + // Récurrente + if (! defined("FACTURE_DISABLE_RECUR")) // Possibilité de désactiver les factures récurrentes + { + if ($fac->statut > 0) + { + print " id."&action=create\">Récurrente\n"; + } + } + + print "
\n"; + + } + + print '
'; + + /* + * Documents générés + * Le fichier de facture détaillée est de la forme + * REFFACTURE-XXXXXX-detail.pdf ou XXXXX est une forme diverse + */ + + $facref = sanitize_string($fac->ref); + $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; + $relativepath = "${facref}/${facref}.pdf"; + + $var=true; + + if (file_exists($file)) + { + print "
\n"; + print_titre("Documents"); + print ''; + + print ""; + + print ''; + print ''; + print ''; + print ''; + + + $dir = $conf->facture->dir_output . "/" . $facref . "/"; + $handle=opendir($dir); + + while (($file = readdir($handle))!==false) + { + if (is_readable($dir.$file) && substr($file, -10) == 'detail.pdf') + { + print ""; + $relativepathdetail = "${facref}/$file"; + + print ''; + print ''; + print ''; + print ''; + } + } + print "
".$langs->trans("Bill")." PDF'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Facture détaillée'.$file.''.filesize($dir.$file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($dir.$file)).'
\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"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; $total = 0; + print "
"; + print_titre($langs->trans("RelatedCommercialProposals")); + + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print ""; + print ''; + print "\n"; + print ''; + print ""; + $total = $total + $objp->price; + $i++; + } + print "\n"; + print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'".dolibarr_print_date($objp->dp)."'.price($objp->price).'
 ".$langs->trans("TotalHT")."".price($total)."
"; + } + } + else + { + dolibarr_print_error($db); + } + + + print '
'; + + /* + * Liste des actions propres à la facture + */ + $sql = "SELECT id, ".$db->pdate("a.datea")." as da, a.label, a.note, code"; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."user as u "; + $sql .= " WHERE a.fk_user_author = u.rowid "; + $sql .= " AND a.fk_action in (9,10) "; + $sql .= " AND a.fk_soc = ".$fac->socidp ; + $sql .= " AND a.fk_facture = ".$fac->id; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + print "
\n"; + print_titre($langs->trans("ActionsOnBill")); + + $i = 0; $total = 0; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print ""; + print ''; + print '\n"; + print ''; + print ''; + print "\n"; + $i++; + } + print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Action").''.$langs->trans("By").'
'.img_object($langs->trans("ShowTask"),"task").' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$objp->code.'
\n"; + } + } + else + { + dolibarr_print_error($db); + } + + print "
"; + + + /* + * Affiche formulaire mail + */ + if ($_GET["action"] == 'presend') + { + print '
'; + print_titre($langs->trans("SendBillByMail")); + + $liste[0]=" "; + foreach ($soc->contact_email_array() as $key=>$value) { + $liste[$key]=$value; + } + + // Créé l'objet formulaire mail + include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php"); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans("SendBillRef","__FACREF__"); + $formmail->withfile=1; + $formmail->withbody=1; + // Tableau des substitutions + $formmail->substit["__FACREF__"]=$fac->ref; + // Tableau des paramètres complémentaires du post + $formmail->param["action"]="send"; + $formmail->param["models"]="facture_send"; + $formmail->param["facid"]=$fac->id; + $formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id"; + + $formmail->show_form(); + + print '
'; + } + + if ($_GET["action"] == 'prerelance') + { + print '
'; + print_titre($langs->trans("SendReminderBillByMail")); + + $liste[0]=" "; + foreach ($soc->contact_email_array() as $key=>$value) + { + $liste[$key]=$value; + } + + // Créé l'objet formulaire mail + include_once("../html.formmail.class.php"); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans("SendReminderBillRef","__FACREF__"); + $formmail->withfile=1; + $formmail->withbody=1; + // Tableau des substitutions + $formmail->substit["__FACREF__"]=$fac->ref; + // Tableau des paramètres complémentaires + $formmail->param["action"]="relance"; + $formmail->param["models"]="facture_relance"; + $formmail->param["facid"]=$fac->id; + $formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id"; + + $formmail->show_form(); + + print '
'; + } + + } + else + { + /* Facture non trouvée */ + print $langs->trans("ErrorBillNotFound",$_GET["facid"]); + } + } + else + { + /*************************************************************************** + * * + * Mode Liste * + * * + ***************************************************************************/ + $page = $_GET["page"]; + $sortorder=$_GET["sortorder"]; + $sortfield=$_GET["sortfield"]; + $month=$_GET["month"]; + $year=$_GET["year"]; + + $fac=new Facture($db); + + 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.increment,f.total,f.total_ttc,"; $sql.= $db->pdate("f.datef")." as df, ".$db->pdate("f.date_lim_reglement")." as datelimite, "; - $sql.= " f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ",".MAIN_DB_PREFIX."facture as f"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture "; - $sql.= " 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 ($_GET["filtre"]) - { - $filtrearr = split(",", $_GET["filtre"]); - foreach ($filtrearr as $fil) - { - $filt = split(":", $fil); - $sql .= " AND " . $filt[0] . " = " . $filt[1]; - } - } - - if ($_GET["search_ref"]) - { - $sql .= " AND f.facnumber like '%".$_GET["search_ref"]."%'"; - } - - if ($_GET["search_societe"]) - { - $sql .= " AND s.nom like '%".$_GET["search_societe"]."%'"; - } - - if ($_GET["search_montant_ht"]) - { - $sql .= " AND f.total = '".$_GET["search_montant_ht"]."'"; - } - - if ($_GET["search_montant_ttc"]) - { - $sql .= " AND f.total_ttc = '".$_GET["search_montant_ttc"]."'"; - } - - if ($year > 0) $sql .= " AND date_format(f.datef, '%Y') = $year"; - - if (strlen($_POST["sf_ref"]) > 0) - { - $sql .= " AND f.facnumber like '%".$_POST["sf_ref"] . "%'"; - } - - $sql .= " GROUP BY f.facnumber"; - - $sql .= " ORDER BY "; - $listfield=split(',',$sortfield); - foreach ($listfield as $key => $value) { - $sql.="$listfield[$key] $sortorder,"; - } - $sql .= " f.rowid DESC "; - - $sql .= $db->plimit($limit+1,$offset); - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - - if ($socidp) - { - $soc = new Societe($db); - $soc->fetch($socidp); - } - - print_barre_liste($langs->trans("BillsCustomers")." ".($socidp?" $soc->nom":""),$page,"facture.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); - - $i = 0; - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.facnumber","","&socidp=$socidp","",$sortfield); - print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef","","&socidp=$socidp",'align="center"',$sortfield); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&socidp=$socidp","",$sortfield); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&socidp=$socidp",'align="right"',$sortfield); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","","&socidp=$socidp",'align="right"',$sortfield); - print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","","&socidp=$socidp",'align="right"',$sortfield); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye","","&socidp=$socidp",'align="right"',$sortfield); - print "\n"; - - // Lignes des champs de filtre - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; - - - if ($num > 0) - { - $var=True; - $total=0; - $totalrecu=0; - - while ($i < min($num,$limit)) - { - $objp = $db->fetch_object($resql); - $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 ""; - - // Affiche statut de la facture - if (! $objp->paye) - { - if ($objp->fk_statut == 0) - { - print ''; - } - elseif ($objp->fk_statut == 3) - { - print ''; - } - else - { - print ''; - } - } - else - { - print ''; - } - - print "\n"; - $total+=$objp->total; - $total_ttc+=$objp->total_ttc; - $totalrecu+=$objp->am; - $i++; - } - - if (($offset + $num) <= $limit) { - // Print total - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - } - - print "
'; - print ''; - print ' '; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'.img_object($langs->trans("ShowBill"),"bill").' '; - print ''.$objp->facnumber.''.$objp->increment; - if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans("Late")); - print ""; - $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)."!!!'.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom.'".price($objp->total)."".price($objp->total_ttc)."".price($objp->am)."'.$langs->trans("BillShortStatusDraft").''.$langs->trans("BillShortStatusCanceled").''.($objp->am?$langs->trans("BillShortStatusStarted"):$langs->trans("BillShortStatusNotPayed")).''.$langs->trans("BillShortStatusPayed").'
'.$langs->trans("Total").''.price($total).''.price($total_ttc).''.price($totalrecu).' 
"; - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - } - } -} - -$db->close(); - -llxFooter('$Date$ - $Revision$'); -?> + $sql.= " f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ",".MAIN_DB_PREFIX."facture as f"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture "; + $sql.= " 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 ($_GET["filtre"]) + { + $filtrearr = split(",", $_GET["filtre"]); + foreach ($filtrearr as $fil) + { + $filt = split(":", $fil); + $sql .= " AND " . $filt[0] . " = " . $filt[1]; + } + } + + if ($_GET["search_ref"]) + { + $sql .= " AND f.facnumber like '%".$_GET["search_ref"]."%'"; + } + + if ($_GET["search_societe"]) + { + $sql .= " AND s.nom like '%".$_GET["search_societe"]."%'"; + } + + if ($_GET["search_montant_ht"]) + { + $sql .= " AND f.total = '".$_GET["search_montant_ht"]."'"; + } + + if ($_GET["search_montant_ttc"]) + { + $sql .= " AND f.total_ttc = '".$_GET["search_montant_ttc"]."'"; + } + + if ($year > 0) $sql .= " AND date_format(f.datef, '%Y') = $year"; + + if (strlen($_POST["sf_ref"]) > 0) + { + $sql .= " AND f.facnumber like '%".$_POST["sf_ref"] . "%'"; + } + + $sql .= " GROUP BY f.facnumber"; + + $sql .= " ORDER BY "; + $listfield=split(',',$sortfield); + foreach ($listfield as $key => $value) { + $sql.="$listfield[$key] $sortorder,"; + } + $sql .= " f.rowid DESC "; + + $sql .= $db->plimit($limit+1,$offset); + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + + if ($socidp) + { + $soc = new Societe($db); + $soc->fetch($socidp); + } + + print_barre_liste($langs->trans("BillsCustomers")." ".($socidp?" $soc->nom":""),$page,"facture.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); + + $i = 0; + print ''; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.facnumber","","&socidp=$socidp","",$sortfield); + print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef","","&socidp=$socidp",'align="center"',$sortfield); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&socidp=$socidp","",$sortfield); + print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&socidp=$socidp",'align="right"',$sortfield); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","","&socidp=$socidp",'align="right"',$sortfield); + print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","","&socidp=$socidp",'align="right"',$sortfield); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye","","&socidp=$socidp",'align="right"',$sortfield); + print "\n"; + + // Lignes des champs de filtre + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ''; + + + if ($num > 0) + { + $var=True; + $total=0; + $totalrecu=0; + + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); + $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 ""; + + // Affiche statut de la facture + if (! $objp->paye) + { + if ($objp->fk_statut == 0) + { + print ''; + } + elseif ($objp->fk_statut == 3) + { + print ''; + } + else + { + print ''; + } + } + else + { + print ''; + } + + print "\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + + if (($offset + $num) <= $limit) { + // Print total + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + } + + print "
'; + print ''; + print ' '; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.img_object($langs->trans("ShowBill"),"bill").' '; + print ''.$objp->facnumber.''.$objp->increment; + if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans("Late")); + print ""; + $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)."!!!'.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom.'".price($objp->total)."".price($objp->total_ttc)."".price($objp->am)."'.$langs->trans("BillShortStatusDraft").''.$langs->trans("BillShortStatusCanceled").''.($objp->am?$langs->trans("BillShortStatusStarted"):$langs->trans("BillShortStatusNotPayed")).''.$langs->trans("BillShortStatusPayed").'
'.$langs->trans("Total").''.price($total).''.price($total_ttc).''.price($totalrecu).' 
"; + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + } + } +} + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?>