2005-08-20 21:02:26 +02:00
< ? php
2005-09-15 02:37:03 +02:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 <EFBFBD> ric Seigne < eric . seigne @ ryxeo . com >
2006-02-25 01:43:24 +01:00
* Copyright ( C ) 2004 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-10-02 17:14:16 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2006-02-12 19:02:36 +01:00
* Copyright ( C ) 2005 - 2006 Regis Houssin < regis . houssin @ cap - networks . com >
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2005-08-20 21:02:26 +02:00
*
* 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 $
*/
/**
2005-09-15 02:37:03 +02:00
\file htdocs / compta / facture . php
\ingroup facture
\brief Page de cr<EFBFBD> ation d ' une facture
\version $Revision $
2005-08-20 21:02:26 +02:00
*/
2005-09-15 02:37:03 +02:00
require ( './pre.inc.php' );
2005-11-11 21:11:57 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /includes/modules/facture/modules_facture.php " );
2005-09-15 02:37:03 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/facture.class.php' );
require_once ( DOL_DOCUMENT_ROOT . '/paiement.class.php' );
2005-12-03 18:18:35 +01:00
require_once ( DOL_DOCUMENT_ROOT . '/lib/invoice.lib.php' );
2005-09-15 02:37:03 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/lib/CMailFile.class.php' );
if ( $conf -> projet -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/project.class.php' );
if ( $conf -> propal -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/propal.class.php' );
if ( $conf -> contrat -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/contrat/contrat.class.php' );
if ( $conf -> commande -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/commande/commande.class.php' );
2005-08-20 21:02:26 +02:00
2005-11-11 21:11:57 +01:00
$user -> getrights ( 'facture' );
$user -> getrights ( 'banque' );
if ( ! $user -> rights -> facture -> lire )
accessforbidden ();
$langs -> load ( 'bills' );
2006-05-25 13:48:54 +02:00
$langs -> load ( 'companies' );
2005-12-07 17:13:23 +01:00
$langs -> load ( 'products' );
$langs -> load ( 'main' );
2005-08-20 21:02:26 +02:00
2005-09-15 02:37:03 +02:00
$sall = isset ( $_GET [ 'sall' ]) ? $_GET [ 'sall' ] : $_POST [ 'sall' ];
if ( isset ( $_GET [ 'msg' ])) { $msg = urldecode ( $_GET [ 'msg' ]); }
if ( $_GET [ 'socidp' ]) { $socidp = $_GET [ 'socidp' ]; }
2005-08-20 21:02:26 +02:00
// S<> curit<69> acc<63> s client
if ( $user -> societe_id > 0 )
{
2005-09-15 02:37:03 +02:00
$action = '' ;
$socidp = $user -> societe_id ;
2005-08-20 21:02:26 +02:00
}
2006-04-10 15:18:40 +02:00
// R<> cup<75> ration de l'id de projet
$projetid = 0 ;
if ( $_GET [ " projetid " ])
{
$projetid = $_GET [ " projetid " ];
}
2005-08-20 21:02:26 +02:00
// Nombre de ligne pour choix de produit/service pr<70> d<EFBFBD> finis
$NBLINES = 4 ;
/*
* Actions
*/
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'classin' )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$facture = new Facture ( $db );
$facture -> fetch ( $_GET [ 'facid' ]);
$facture -> classin ( $_POST [ 'projetid' ]);
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'setmode' )
2005-09-03 14:47:56 +02:00
{
2005-09-15 02:37:03 +02:00
$facture = new Facture ( $db );
$facture -> fetch ( $_GET [ 'facid' ]);
$result = $facture -> mode_reglement ( $_POST [ 'mode_reglement_id' ]);
2006-03-14 22:31:59 +01:00
if ( $result < 0 ) dolibarr_print_error ( $facture -> db , $facture -> error );
2005-09-03 14:47:56 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'setconditions' )
2005-09-03 14:47:56 +02:00
{
2005-09-15 02:37:03 +02:00
$facture = new Facture ( $db );
$facture -> fetch ( $_GET [ 'facid' ]);
$result = $facture -> cond_reglement ( $_POST [ 'cond_reglement_id' ]);
2006-03-14 22:31:59 +01:00
if ( $result < 0 ) dolibarr_print_error ( $facture -> db , $facture -> error );
2005-09-03 14:47:56 +02:00
}
2006-04-04 02:27:02 +02:00
if ( $_REQUEST [ 'action' ] == 'setremisepercent' && $user -> rights -> facture -> creer )
2006-04-04 02:12:45 +02:00
{
$fac = new Facture ( $db );
2006-04-04 02:27:02 +02:00
$fac -> fetch ( $_REQUEST [ 'facid' ]);
2006-04-04 02:12:45 +02:00
$result = $fac -> set_remise ( $user , $_POST [ 'remise_percent' ]);
2006-04-04 02:27:02 +02:00
$_GET [ 'facid' ] = $_REQUEST [ 'facid' ];
2006-04-04 02:12:45 +02:00
}
2006-07-01 01:38:12 +02:00
if ( $_POST [ 'action' ] == " setabsolutediscount " && $user -> rights -> propale -> creer )
2006-04-04 02:12:45 +02:00
{
2006-07-01 01:38:12 +02:00
if ( $_POST [ " remise_id " ])
{
$fac = new Facture ( $db );
$fac -> id = $_GET [ 'facid' ];
$ret = $fac -> fetch ( $_GET [ 'facid' ]);
if ( $ret > 0 )
{
$fac -> insert_discount ( $_POST [ " remise_id " ]);
}
else
{
dolibarr_print_error ( $db , $fac -> error );
}
}
2006-04-04 02:12:45 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'classin' )
2005-09-03 14:47:56 +02:00
{
2005-09-15 02:37:03 +02:00
$facture = new Facture ( $db );
$facture -> fetch ( $_GET [ 'facid' ]);
$facture -> classin ( $_POST [ 'projetid' ]);
}
if ( $_POST [ 'action' ] == 'set_ref_client' )
{
$facture = new Facture ( $db );
$facture -> fetch ( $_GET [ 'facid' ]);
$facture -> set_ref_client ( $_POST [ 'ref_client' ]);
2005-09-03 14:47:56 +02:00
}
2006-04-04 02:12:45 +02:00
// Classe <20> "valid<69> e"
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 )
{
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-06-27 13:40:14 +02:00
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
2006-04-04 02:12:45 +02:00
}
}
2006-07-16 14:26:36 +02:00
// Repasse la facture en mode brouillon
2006-07-11 08:42:44 +02:00
if ( $_GET [ 'action' ] == 'modif' && $user -> rights -> facture -> modifier && $conf -> global -> FACTURE_ENABLE_EDITDELETE )
{
2006-07-16 14:26:36 +02:00
$fac = new Facture ( $db );
2006-07-11 08:42:44 +02:00
$fac -> fetch ( $_GET [ 'facid' ]);
2006-07-13 09:46:46 +02:00
2006-07-16 14:46:07 +02:00
// On v<> rifie si la facture a des paiements
2006-07-16 14:57:42 +02:00
$sql = 'SELECT pf.amount' ;
2006-07-16 14:46:07 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf' ;
$sql .= ' WHERE pf.fk_facture = ' . $fac -> id ;
$result = $db -> query ( $sql );
if ( $result )
{
2006-07-16 14:57:42 +02:00
$i = 0 ;
$num = $db -> num_rows ( $result );
2006-07-16 14:46:07 +02:00
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
$totalpaye += $objp -> amount ;
$i ++ ;
}
}
$resteapayer = $fac -> total_ttc - $totalpaye ;
2006-07-16 14:26:36 +02:00
// On v<> rifie si les lignes de factures ont <20> t<EFBFBD> export<72> es en compta et/ou ventil<69> es
$ventilExportCompta = $fac -> getVentilExportCompta ();
// On v<> rifie si aucun paiement n'a <20> t<EFBFBD> effectu<74>
if ( $resteapayer == $fac -> total_ttc && $fac -> paye == 0 && $ventilExportCompta == 0 )
{
$fac -> reopen ( $user );
2006-07-13 09:46:46 +02:00
}
2006-07-11 08:42:44 +02:00
}
2006-06-08 14:40:10 +02:00
if ( $_POST [ 'action' ] == 'confirm_deleteproductline' && $_POST [ 'confirm' ] == 'yes' && $conf -> global -> PRODUIT_CONFIRM_DELETE_LINE )
{
if ( $user -> rights -> facture -> creer )
{
2006-07-18 09:54:58 +02:00
$fac = new Facture ( $db );
$fac -> fetch ( $_GET [ 'facid' ]);
$fac -> deleteline ( $_GET [ 'rowid' ]);
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
2006-06-08 14:40:10 +02:00
}
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $_GET [ 'facid' ]);
exit ;
}
2006-04-04 02:12:45 +02:00
// Classe <20> "pay<61> e"
if ( $_POST [ 'action' ] == 'confirm_payed' && $_POST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> paiement )
{
$fac = new Facture ( $db );
$fac -> fetch ( $_GET [ 'facid' ]);
$result = $fac -> set_payed ( $user );
}
2005-08-20 21:02:26 +02:00
/*
* Insertion facture
*/
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'add' )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$datefacture = mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
$facture = new Facture ( $db , $_POST [ 'socid' ]);
$facture -> number = $_POST [ 'facnumber' ];
$facture -> date = $datefacture ;
2006-02-12 16:54:21 +01:00
$facture -> note_public = $_POST [ 'note_public' ];
2005-09-15 02:37:03 +02:00
$facture -> note = $_POST [ 'note' ];
2006-06-20 11:56:54 +02:00
$facture -> ref_client = $_POST [ 'ref_client' ];
2006-07-02 15:45:06 +02:00
$facture -> modelpdf = $_POST [ 'model' ];
2005-09-15 02:37:03 +02:00
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_id = $_POST [ 'cond_reglement_id' ];
$facture -> mode_reglement_id = $_POST [ 'mode_reglement_id' ];
$facture -> amount = $_POST [ 'amount' ];
2006-04-04 02:12:45 +02:00
$facture -> remise_absolue = $_POST [ 'remise_absolue' ];
2005-09-15 02:37:03 +02:00
$facture -> remise_percent = $_POST [ 'remise_percent' ];
$facture -> ref_client = $_POST [ 'ref_client' ];
if ( ! $_POST [ 'propalid' ] && ! $_POST [ 'commandeid' ] && ! $_POST [ 'contratid' ])
{
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 );
2006-02-12 16:54:21 +01:00
if ( $facid > 0 )
2005-09-15 02:37:03 +02:00
{
2006-04-08 13:39:41 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid );
2005-09-15 02:37:03 +02:00
exit ;
}
2006-02-12 16:54:21 +01:00
else
{
$_GET [ " action " ] = 'create' ;
$mesg = '<div class="error">' . $facture -> error . '</div>' ;
}
2005-09-15 02:37:03 +02:00
}
else
{
/*
* Si creation depuis propale
*/
if ( $_POST [ 'propalid' ])
{
$facture -> propalid = $_POST [ 'propalid' ];
$facid = $facture -> create ( $user );
2006-02-17 00:26:14 +01:00
if ( $facid > 0 )
2005-09-15 02:37:03 +02:00
{
$prop = New Propal ( $db );
if ( $prop -> fetch ( $_POST [ 'propalid' ]) )
{
for ( $i = 0 ; $i < sizeof ( $prop -> lignes ) ; $i ++ )
{
2006-06-16 02:33:04 +02:00
$desc = ( $prop -> lignes [ $i ] -> desc ? $prop -> lignes [ $i ] -> desc : $prop -> lignes [ $i ] -> libelle );
2005-09-15 02:37:03 +02:00
2006-02-17 00:26:14 +01:00
$result = $facture -> addline (
$facid ,
2006-06-16 02:33:04 +02:00
$desc ,
2006-02-17 00:26:14 +01:00
$prop -> lignes [ $i ] -> subprice ,
$prop -> lignes [ $i ] -> qty ,
$prop -> lignes [ $i ] -> tva_tx ,
2006-06-23 21:05:33 +02:00
$prop -> lignes [ $i ] -> fk_product ,
2006-02-17 00:26:14 +01:00
$prop -> lignes [ $i ] -> remise_percent );
2005-09-15 02:37:03 +02:00
}
}
else
{
print $langs -> trans ( 'UnknownError' );
}
}
2006-02-17 00:26:14 +01:00
else
{
2006-03-14 22:31:59 +01:00
dolibarr_print_error ( $facture -> db , $facture -> error );
2006-02-17 00:26:14 +01:00
}
2005-09-15 02:37:03 +02:00
}
/*
* Si cr<EFBFBD> ation depuis commande
*/
if ( $_POST [ 'commandeid' ])
{
$facture -> commandeid = $_POST [ 'commandeid' ];
$facid = $facture -> create ( $user );
2006-02-17 00:26:14 +01:00
if ( $facid > 0 )
2005-09-15 02:37:03 +02:00
{
$comm = New Commande ( $db );
if ( $comm -> fetch ( $_POST [ 'commandeid' ]) )
{
$lines = $comm -> fetch_lignes ();
for ( $i = 0 ; $i < sizeof ( $lines ) ; $i ++ )
{
2006-06-19 16:54:54 +02:00
$desc = ( $lines [ $i ] -> desc ? $lines [ $i ] -> desc : $lines [ $i ] -> libelle );
2006-06-16 02:33:04 +02:00
2006-02-17 00:26:14 +01:00
$result = $facture -> addline (
$facid ,
2006-06-16 02:33:04 +02:00
$desc ,
2006-02-17 00:26:14 +01:00
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
2006-06-23 14:05:51 +02:00
$lines [ $i ] -> fk_product ,
2006-02-17 00:26:14 +01:00
$lines [ $i ] -> remise_percent );
2005-09-15 02:37:03 +02:00
}
}
else
{
print $langs -> trans ( 'UnknownError' );
}
}
else
{
2006-03-14 22:31:59 +01:00
dolibarr_print_error ( $facture -> db , $facture -> error );
2005-09-15 02:37:03 +02:00
}
}
/*
* Si cr<EFBFBD> ation depuis contrat
*/
if ( $_POST [ 'contratid' ])
{
$facture -> contratid = $_POST [ 'contratid' ];
$facid = $facture -> create ( $user );
2006-02-17 00:26:14 +01:00
if ( $facid > 0 )
2005-09-15 02:37:03 +02:00
{
$contrat = New Contrat ( $db );
2005-10-29 20:46:58 +02:00
if ( $contrat -> fetch ( $_POST [ 'contratid' ]) > 0 )
2005-09-15 02:37:03 +02:00
{
$lines = $contrat -> fetch_lignes ();
2005-10-29 20:46:58 +02:00
2005-09-15 02:37:03 +02:00
for ( $i = 0 ; $i < sizeof ( $lines ) ; $i ++ )
{
2006-06-16 02:33:04 +02:00
$desc = ( $contrat -> lignes [ $i ] -> desc ? $contrat -> lignes [ $i ] -> desc : $contrat -> lignes [ $i ] -> libelle );
2005-09-15 02:37:03 +02:00
// Plage de dates
$date_start = $contrat -> lignes [ $i ] -> date_debut_prevue ;
if ( $contrat -> lignes [ $i ] -> date_debut_reel ) $date_start = $contrat -> lignes [ $i ] -> date_debut_reel ;
$date_end = $contrat -> lignes [ $i ] -> date_fin_prevue ;
if ( $contrat -> lignes [ $i ] -> date_fin_reel ) $date_end = $contrat -> lignes [ $i ] -> date_fin_reel ;
2006-02-17 00:26:14 +01:00
$result = $facture -> addline (
$facid ,
2006-06-16 02:33:04 +02:00
$desc ,
2006-02-17 00:26:14 +01:00
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
2006-06-23 21:05:33 +02:00
$lines [ $i ] -> fk_product ,
2006-02-17 00:26:14 +01:00
$lines [ $i ] -> remise_percent ,
$date_start ,
$date_end );
2005-09-15 02:37:03 +02:00
}
}
else
{
print $langs -> trans ( 'UnknownError' );
}
}
else
{
2006-03-14 22:31:59 +01:00
dolibarr_print_error ( $facture -> db , $facture -> error );
2005-09-15 02:37:03 +02:00
}
}
// Fin cr<63> ation facture, on l'affiche
2006-02-12 16:54:21 +01:00
if ( $facid > 0 )
2005-09-15 02:37:03 +02:00
{
2006-04-08 13:39:41 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid );
2005-09-15 02:37:03 +02:00
exit ;
}
}
}
2005-08-20 21:02:26 +02:00
}
2006-06-17 01:55:20 +02:00
/*
* Ajout d ' une ligne produit dans la facture
*/
2006-03-14 01:53:54 +01:00
if (( $_POST [ 'action' ] == 'addligne' || $_POST [ 'action' ] == 'addligne_predef' ) && $user -> rights -> facture -> creer )
2005-08-20 21:02:26 +02:00
{
2006-06-17 01:55:20 +02:00
if ( $_POST [ 'qty' ] && (( $_POST [ 'pu' ] != 0 && $_POST [ 'desc' ]) || $_POST [ 'idprod' ]))
2005-09-15 02:37:03 +02:00
{
$fac = new Facture ( $db );
2006-06-17 01:55:20 +02:00
$ret = $fac -> fetch ( $_POST [ 'facid' ]);
2006-06-16 02:33:04 +02:00
$soc = new Societe ( $db );
2006-06-17 01:55:20 +02:00
$ret = $soc -> fetch ( $fac -> socidp );
2006-06-16 02:33:04 +02:00
2006-06-17 20:12:46 +02:00
$date_start = '' ;
$date_end = '' ;
2006-03-14 01:53:54 +01:00
// Si ajout champ produit libre
if ( $_POST [ 'action' ] == 'addligne' )
2005-09-15 02:37:03 +02:00
{
2006-03-14 01:53:54 +01:00
if ( $_POST [ 'date_startyear' ] && $_POST [ 'date_startmonth' ] && $_POST [ 'date_startday' ])
{
2006-06-17 20:12:46 +02:00
$date_start = $_POST [ 'date_startyear' ] . '-' . $_POST [ 'date_startmonth' ] . '-' . $_POST [ 'date_startday' ];
2006-03-14 01:53:54 +01:00
}
if ( $_POST [ 'date_endyear' ] && $_POST [ 'date_endmonth' ] && $_POST [ 'date_endday' ])
{
2006-06-17 20:12:46 +02:00
$date_end = $_POST [ 'date_endyear' ] . '-' . $_POST [ 'date_endmonth' ] . '-' . $_POST [ 'date_endday' ];
2006-03-14 01:53:54 +01:00
}
2005-09-15 02:37:03 +02:00
}
2006-03-14 01:53:54 +01:00
// Si ajout champ produit pr<70> d<EFBFBD> fini
if ( $_POST [ 'action' ] == 'addligne_predef' )
2005-09-15 02:37:03 +02:00
{
2006-03-14 01:53:54 +01:00
if ( $_POST [ 'date_start_predefyear' ] && $_POST [ 'date_start_predefmonth' ] && $_POST [ 'date_start_predefday' ])
{
2006-06-17 20:12:46 +02:00
$date_start = $_POST [ 'date_start_predefyear' ] . '-' . $_POST [ 'date_start_predefmonth' ] . '-' . $_POST [ 'date_start_predefday' ];
2006-03-14 01:53:54 +01:00
}
if ( $_POST [ 'date_end_predefyear' ] && $_POST [ 'date_end_predefmonth' ] && $_POST [ 'date_end_predefday' ])
{
2006-06-17 20:12:46 +02:00
$date_end = $_POST [ 'date_end_predefyear' ] . '-' . $_POST [ 'date_end_predefmonth' ] . '-' . $_POST [ 'date_end_predefday' ];
2006-03-14 01:53:54 +01:00
}
2005-09-15 02:37:03 +02:00
}
2006-06-16 02:33:04 +02:00
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
if ( $_POST [ 'idprod' ])
{
$prod = new Product ( $db , $_POST [ 'idprod' ]);
$prod -> fetch ( $_POST [ 'idprod' ]);
2006-06-16 15:10:45 +02:00
// multiprix
if ( $conf -> global -> PRODUIT_MULTIPRICES == 1 )
{
$pu = $prod -> multiprices [ $soc -> price_level ];
}
else
{
2006-06-16 02:33:04 +02:00
$pu = $prod -> price ;
2006-06-16 15:10:45 +02:00
}
2006-06-17 01:55:20 +02:00
// La description de la ligne est celle saisie ou
// celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC d<> fini)
2006-06-16 15:10:45 +02:00
$desc = $_POST [ 'desc' ];
2006-06-17 01:55:20 +02:00
if ( ! $desc && $conf -> global -> PRODUIT_CHANGE_PROD_DESC )
2006-06-16 15:10:45 +02:00
{
$desc = $prod -> description ;
}
$tva_tx = get_default_tva ( $mysoc , $soc , $prod -> tva_tx );
2006-06-16 02:33:04 +02:00
}
else
{
$pu = $_POST [ 'pu' ];
$tva_tx = $_POST [ 'tva_tx' ];
$desc = $_POST [ 'desc' ];
}
// Insere ligne
2006-02-12 16:54:21 +01:00
$result = $fac -> addline (
$_POST [ 'facid' ],
2006-06-16 02:33:04 +02:00
$desc ,
$pu ,
2005-09-15 02:37:03 +02:00
$_POST [ 'qty' ],
2006-06-16 02:33:04 +02:00
$tva_tx ,
2005-10-08 17:54:06 +02:00
$_POST [ 'idprod' ],
2005-09-15 02:37:03 +02:00
$_POST [ 'remise_percent' ],
2006-06-17 20:12:46 +02:00
$date_start ,
$date_end
2005-09-15 02:37:03 +02:00
);
}
$_GET [ 'facid' ] = $_POST [ 'facid' ]; // Pour r<> affichage de la fiche en cours d'<27> dition
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ 'save' ] == $langs -> trans ( 'Save' ))
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$fac = new Facture ( $db , '' , $_POST [ 'facid' ]);
2006-06-17 01:55:20 +02:00
if ( ! $fac -> fetch ( $_POST [ 'facid' ]) > 0 ) dolibarr_print_error ( $db );
2005-09-15 02:37:03 +02:00
2006-06-17 20:12:46 +02:00
$date_start = '' ;
$date_end = '' ;
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'date_startyear' ] && $_POST [ 'date_startmonth' ] && $_POST [ 'date_startday' ]) {
2006-06-17 20:12:46 +02:00
$date_start = $_POST [ 'date_startyear' ] . '-' . $_POST [ 'date_startmonth' ] . '-' . $_POST [ 'date_startday' ];
2005-09-15 02:37:03 +02:00
}
if ( $_POST [ 'date_endyear' ] && $_POST [ 'date_endmonth' ] && $_POST [ 'date_endday' ]) {
2006-06-17 20:12:46 +02:00
$date_end = $_POST [ 'date_endyear' ] . '-' . $_POST [ 'date_endmonth' ] . '-' . $_POST [ 'date_endday' ];
2005-09-15 02:37:03 +02:00
}
$result = $fac -> updateline ( $_POST [ 'rowid' ],
$_POST [ 'desc' ],
$_POST [ 'price' ],
$_POST [ 'qty' ],
$_POST [ 'remise_percent' ],
2006-06-17 20:12:46 +02:00
$date_start ,
$date_end ,
2005-09-15 02:37:03 +02:00
$_POST [ 'tva_tx' ]
);
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-06-17 01:55:20 +02:00
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
2005-09-15 02:37:03 +02:00
$_GET [ 'facid' ] = $_POST [ 'facid' ]; // Pour r<> affichage de la fiche en cours d'<27> dition
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ 'cancel' ] == $langs -> trans ( 'Cancel' ))
2005-08-20 21:02:26 +02:00
{
2006-04-08 13:39:41 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $_POST [ 'facid' ]); // Pour r<> affichage de la fiche en cours d'<27> dition
2005-09-15 02:37:03 +02:00
exit ;
2005-08-20 21:02:26 +02:00
}
2006-06-08 14:40:10 +02:00
if ( $_GET [ 'action' ] == 'deleteline' && $user -> rights -> facture -> creer && ! $conf -> global -> PRODUIT_CONFIRM_DELETE_LINE )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$fac = new Facture ( $db , '' , $_GET [ 'facid' ]);
$fac -> fetch ( $_GET [ 'facid' ]);
$result = $fac -> deleteline ( $_GET [ 'rowid' ]);
2006-07-18 09:54:58 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'confirm_delete' && $_POST [ 'confirm' ] == 'yes' )
2005-08-20 21:02:26 +02:00
{
2006-07-15 20:29:46 +02:00
if ( $user -> rights -> facture -> supprimer )
2005-09-15 02:37:03 +02:00
{
$fac = new Facture ( $db );
2005-10-30 18:32:09 +01:00
$result = $fac -> delete ( $_GET [ 'facid' ]);
2005-09-15 02:37:03 +02:00
$_GET [ 'facid' ] = 0 ;
2006-04-08 13:39:41 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ]);
2005-09-15 02:37:03 +02:00
exit ;
}
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'confirm_canceled' && $_POST [ 'confirm' ] == 'yes' )
2005-08-20 21:02:26 +02:00
{
2006-02-12 16:54:21 +01:00
if ( $user -> rights -> facture -> supprimer )
2005-09-15 02:37:03 +02:00
{
$fac = new Facture ( $db );
2006-07-18 09:54:58 +02:00
$fac -> fetch ( $_GET [ 'facid' ]);
2005-11-11 21:11:57 +01:00
$result = $fac -> set_canceled ( $user );
2005-09-15 02:37:03 +02:00
}
2005-08-20 21:02:26 +02:00
}
/*
* Ordonnancement des lignes
*/
2005-09-15 02:37:03 +02:00
if ( $_GET [ 'action' ] == 'up' && $user -> rights -> facture -> creer )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$fac = new Facture ( $db , '' , $_GET [ 'facid' ]);
2006-07-18 09:54:58 +02:00
$fac -> fetch ( $_GET [ 'facid' ]);
2005-09-15 02:37:03 +02:00
$fac -> line_up ( $_GET [ 'rowid' ]);
2006-07-18 09:54:58 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $_GET [ " facid " ] . '#' . $_GET [ 'rowid' ]);
2005-08-20 21:02:26 +02:00
}
2005-09-15 02:37:03 +02:00
if ( $_GET [ 'action' ] == 'down' && $user -> rights -> facture -> creer )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$fac = new Facture ( $db , '' , $_GET [ 'facid' ]);
2006-07-18 09:54:58 +02:00
$fac -> fetch ( $_GET [ 'facid' ]);
2005-09-15 02:37:03 +02:00
$fac -> line_down ( $_GET [ 'rowid' ]);
2006-07-18 09:54:58 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $_GET [ " facid " ] . '#' . $_GET [ 'rowid' ]);
2005-08-20 21:02:26 +02:00
}
/*
* Action envoi de mail
*/
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'send' || $_POST [ 'action' ] == 'relance' )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
$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' ;
2006-05-06 17:51:28 +02:00
if ( is_readable ( $file ))
2006-05-05 00:58:14 +02:00
{
2005-09-15 02:37:03 +02:00
$soc = new Societe ( $db , $fac -> socidp );
if ( $_POST [ 'sendto' ]) {
// Le destinataire a <20> t<EFBFBD> fourni via le champ libre
$sendto = $_POST [ 'sendto' ];
$sendtoid = 0 ;
}
elseif ( $_POST [ 'receiver' ]) {
// Le destinataire a <20> t<EFBFBD> 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' ];
2006-05-04 15:58:00 +02:00
$sendtocc = $_POST [ 'sendtocc' ];
2006-06-26 17:15:51 +02:00
$deliveryreceipt = $_POST [ 'deliveryreceipt' ];
2006-05-04 15:58:00 +02:00
2005-09-15 02:37:03 +02:00
if ( $_POST [ 'action' ] == 'send' )
{
2006-02-13 15:21:46 +01:00
if ( strlen ( $_POST [ 'subject' ]))
2006-05-04 15:58:00 +02:00
{
2006-02-13 15:21:46 +01:00
$subject = $_POST [ 'subject' ];
2006-05-04 15:58:00 +02:00
}
2006-02-13 15:21:46 +01:00
else
2006-05-04 15:58:00 +02:00
{
2006-02-13 15:21:46 +01:00
$subject = $langs -> trans ( 'Bill' ) . ' ' . $fac -> ref ;
2006-05-04 15:58:00 +02:00
}
2005-09-15 02:37:03 +02:00
$actiontypeid = 9 ;
$actionmsg = 'Mail envoy<6F> par ' . $from . ' <20> ' . $sendto . '.<br>' ;
2006-05-04 15:58:00 +02:00
if ( $message )
{
2005-09-15 02:37:03 +02:00
$actionmsg .= 'Texte utilis<69> dans le corps du message:<br>' ;
$actionmsg .= $message ;
}
2006-05-04 15:58:00 +02:00
2005-09-15 02:37:03 +02:00
$actionmsg2 = 'Envoi facture par mail' ;
}
if ( $_POST [ 'action' ] == 'relance' )
{
$subject = 'Relance facture ' . $fac -> ref ;
$actiontypeid = 10 ;
$actionmsg = 'Mail envoy<6F> par ' . $from . ' <20> ' . $sendto . '.<br>' ;
if ( $message ) {
$actionmsg .= 'Texte utilis<69> dans le corps du message:<br>' ;
$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
2006-06-26 17:15:51 +02:00
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , '' , $deliveryreceipt );
2005-09-15 02:37:03 +02:00
if ( $mailfile -> sendfile ())
{
$msg = '<div class="ok">' . $langs -> trans ( 'MailSuccessfulySent' , $from , $sendto ) . '.</div>' ;
// Insertion action
require_once ( DOL_DOCUMENT_ROOT . '/contact.class.php' );
2005-09-25 00:28:19 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/actioncomm.class.php' );
2005-09-15 02:37:03 +02:00
$actioncomm = new ActionComm ( $db );
$actioncomm -> type_id = $actiontypeid ;
$actioncomm -> label = $actionmsg2 ;
$actioncomm -> note = $actionmsg ;
$actioncomm -> date = time ();
$actioncomm -> percent = 100 ;
$actioncomm -> contact = new Contact ( $db , $sendtoid );
$actioncomm -> societe = new Societe ( $db , $fac -> socidp );
$actioncomm -> user = $user ; // User qui a fait l'action
$actioncomm -> facid = $fac -> id ;
$ret = $actioncomm -> add ( $user ); // User qui saisit l'action
if ( $ret < 0 )
{
dolibarr_print_error ( $db );
}
else
{
// Renvoie sur la fiche
2006-04-08 13:39:41 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&msg=' . urlencode ( $msg ));
2005-09-15 02:37:03 +02:00
exit ;
}
}
else
{
2006-05-05 00:58:14 +02:00
$langs -> load ( " other " );
2005-09-15 02:37:03 +02:00
$msg = '<div class="error">' . $langs -> trans ( 'ErrorFailedToSendMail' , $from , $sendto ) . ' !</div>' ;
}
}
else
{
2006-05-05 00:58:14 +02:00
$langs -> load ( " other " );
2005-09-15 02:37:03 +02:00
$msg = '<div class="error">' . $langs -> trans ( 'ErrorMailRecipientIsEmpty' ) . '</div>' ;
2006-05-05 00:58:14 +02:00
dolibarr_syslog ( 'Recipient email is empty' );
2005-09-15 02:37:03 +02:00
}
}
else
{
2006-05-05 00:58:14 +02:00
$langs -> load ( " other " );
$msg = '<div class="error">' . $langs -> trans ( 'ErrorCantReadFile' , $file ) . '</div>' ;
dolibarr_syslog ( 'Failed to read file: ' . $file );
2005-09-15 02:37:03 +02:00
}
}
else
{
2006-05-05 00:58:14 +02:00
$langs -> load ( " other " );
$msg = '<div class="error">' . $langs -> trans ( 'ErrorFailedToReadEntity' , $langs -> trans ( " Invoice " )) . '</div>' ;
2005-09-15 02:37:03 +02:00
dolibarr_syslog ( 'Impossible de lire les donn<6E> es de la facture. Le fichier facture n\'a peut-<2D> tre pas <20> t<EFBFBD> g<> n<EFBFBD> r<EFBFBD> .' );
}
2005-08-20 21:02:26 +02:00
}
/*
2006-01-21 20:08:36 +01:00
* G<EFBFBD> n<EFBFBD> rer ou reg<EFBFBD> n<EFBFBD> rer le document PDF
2005-08-20 21:02:26 +02:00
*/
2006-03-22 00:47:01 +01:00
if ( $_REQUEST [ 'action' ] == 'builddoc' ) // En get ou en post
2005-08-20 21:02:26 +02:00
{
2006-07-18 09:54:58 +02:00
$fac = new Facture ( $db , 0 , $_GET [ 'facid' ]);
$fac -> fetch ( $_GET [ 'facid' ]);
2006-06-27 14:01:52 +02:00
2006-07-02 15:45:06 +02:00
if ( $_REQUEST [ 'model' ])
2006-06-27 14:01:52 +02:00
{
2006-07-18 09:54:58 +02:00
$fac -> set_pdf_model ( $user , $_REQUEST [ 'model' ]);
2006-06-27 14:01:52 +02:00
}
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-06-27 14:01:52 +02:00
2006-07-18 09:54:58 +02:00
$result = facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
2006-04-23 16:01:42 +02:00
if ( $result <= 0 )
{
2006-05-05 00:58:14 +02:00
dolibarr_print_error ( $db , $result );
2006-07-18 09:54:58 +02:00
exit ;
}
else
{
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '#builddoc' );
2006-04-23 16:01:42 +02:00
}
2005-08-20 21:02:26 +02:00
}
2005-09-06 03:22:40 +02:00
/*********************************************************************
*
* Fonctions internes
*
**********************************************************************/
function print_date_range ( $date_start , $date_end )
{
2005-09-15 02:37:03 +02:00
global $langs ;
if ( $date_start && $date_end )
{
print ' (' . $langs -> trans ( 'DateFromTo' , dolibarr_print_date ( $date_start ), dolibarr_print_date ( $date_end )) . ')' ;
}
if ( $date_start && ! $date_end )
{
print ' (' . $langs -> trans ( 'DateFrom' , dolibarr_print_date ( $date_start )) . ')' ;
}
if ( ! $date_start && $date_end )
{
print ' (' . $langs -> trans ( 'DateUntil' , dolibarr_print_date ( $date_end )) . ')' ;
}
2005-09-06 03:22:40 +02:00
}
2005-09-15 02:37:03 +02:00
llxHeader ( '' , $langs -> trans ( 'Bill' ), 'Facture' );
2005-08-20 21:02:26 +02:00
$html = new Form ( $db );
/*********************************************************************
*
* Mode creation
*
**********************************************************************/
2005-09-15 02:37:03 +02:00
if ( $_GET [ 'action' ] == 'create' )
2005-08-20 21:02:26 +02:00
{
2005-09-15 02:37:03 +02:00
print_titre ( $langs -> trans ( 'NewBill' ));
2006-02-12 16:54:21 +01:00
if ( $mesg ) print $mesg ;
2005-09-15 02:37:03 +02:00
$soc = new Societe ( $db );
if ( $_GET [ 'propalid' ])
{
$propal = New Propal ( $db );
$propal -> fetch ( $_GET [ 'propalid' ]);
2006-06-19 22:35:22 +02:00
$societe_id = $propal -> socidp ;
2006-04-10 15:18:40 +02:00
$projetid = $propal -> projetidp ;
2006-06-20 11:56:54 +02:00
$ref_client = $propal -> ref_client ;
2006-04-08 15:29:18 +02:00
$soc -> fetch ( $societe_id );
2006-02-16 18:54:20 +01:00
$cond_reglement_id = $propal -> cond_reglement_id ;
2006-03-18 21:11:54 +01:00
$mode_reglement_id = $propal -> mode_reglement_id ;
2006-04-08 15:29:18 +02:00
$remise_percent = $propal -> remise_percent ;
$remise_absolue = $propal -> remise_absolue ;
2005-09-15 02:37:03 +02:00
}
elseif ( $_GET [ 'commandeid' ])
{
$commande = New Commande ( $db );
$commande -> fetch ( $_GET [ 'commandeid' ]);
2006-06-19 22:35:22 +02:00
$societe_id = $commande -> socidp ;
2006-04-10 15:18:40 +02:00
$projetid = $commande -> projet_id ;
2005-09-15 02:37:03 +02:00
$ref_client = $commande -> ref_client ;
2006-04-08 15:29:18 +02:00
$soc -> fetch ( $societe_id );
2006-02-16 18:46:09 +01:00
$cond_reglement_id = $commande -> cond_reglement_id ;
2006-03-18 21:11:54 +01:00
$mode_reglement_id = $commande -> mode_reglement_id ;
2006-04-08 15:29:18 +02:00
$remise_percent = $commande -> remise_percent ;
$remise_absolue = $commande -> remise_absolue ;
2005-09-15 02:37:03 +02:00
}
elseif ( $_GET [ 'contratid' ])
{
$contrat = New Contrat ( $db );
$contrat -> fetch ( $_GET [ 'contratid' ]);
$societe_id = $contrat -> societe -> id ;
2006-04-10 15:18:40 +02:00
$projetid = $contrat -> fk_projet ;
2006-04-08 15:29:18 +02:00
2005-09-15 02:37:03 +02:00
$soc = $contrat -> societe ;
2006-04-08 15:29:18 +02:00
$cond_reglement_id = $soc -> cond_reglement ;
$mode_reglement_id = $soc -> mod_reglement ;
$remise_percent = $soc -> remise_client ;
$remise_absolue = 0 ;
2005-09-15 02:37:03 +02:00
}
else
{
$societe_id = $socidp ;
2006-04-08 15:29:18 +02:00
2005-09-15 02:37:03 +02:00
$soc -> fetch ( $societe_id );
2006-02-16 18:46:09 +01:00
$cond_reglement_id = $soc -> cond_reglement ;
2006-03-18 21:11:54 +01:00
$mode_reglement_id = $soc -> mode_reglement ;
2006-04-08 15:29:18 +02:00
$remise_percent = $soc -> remise_client ;
$remise_absolue = 0 ;
2005-09-15 02:37:03 +02:00
}
2006-06-24 15:50:22 +02:00
$absolute_discount = $soc -> getCurrentDiscount ();
2005-09-15 02:37:03 +02:00
2006-04-08 13:39:41 +02:00
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2005-09-15 02:37:03 +02:00
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' . " \n " ;
2006-04-04 02:12:45 +02:00
print '<input name="facnumber" type="hidden" value="provisoire">' ;
2005-09-15 02:37:03 +02:00
print '<table class="border" width="100%">' ;
2005-12-03 17:56:04 +01:00
2006-04-06 20:36:52 +02:00
// Ref
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'Ref' ) . '</td><td colspan="2">' . $langs -> trans ( 'Draft' ) . '</td></tr>' ;
2006-06-20 11:56:54 +02:00
// Reference client
2006-06-20 14:45:53 +02:00
$refclient = $ref_client ? $ref_client : '' ;
2006-06-20 11:56:54 +02:00
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td><td>' ;
2006-06-20 14:45:53 +02:00
print '<input type="text" name="ref_client" value="' . $refclient . '"></td>' ;
2006-06-20 11:56:54 +02:00
print '</tr>' ;
2005-09-15 02:37:03 +02:00
2006-04-04 02:12:45 +02:00
// Societe
2006-06-03 16:47:05 +02:00
print '<tr><td>' . $langs -> trans ( 'Company' ) . '</td><td colspan="2">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
2006-05-25 16:41:44 +02:00
// Ligne info remises tiers
2006-06-03 18:04:32 +02:00
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td colspan="2">' ;
2006-05-25 16:41:44 +02:00
if ( $soc -> remise_client ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_client );
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
print '. ' ;
2006-05-31 23:53:20 +02:00
if ( $absolute_discount ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , $absolute_discount , $langs -> trans ( " Currency " . $conf -> monnaie ));
2006-05-25 16:41:44 +02:00
else print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
print '.' ;
print '</td></tr>' ;
2006-04-04 02:12:45 +02:00
// Date facture
print '<tr><td>' . $langs -> trans ( 'Date' ) . '</td><td colspan="2">' ;
2006-03-01 17:59:18 +01:00
$html -> select_date ( '' , '' , '' , '' , '' , " add " );
2006-02-12 16:54:21 +01:00
print '</td></tr>' ;
2005-09-15 02:37:03 +02:00
// Conditions de r<> glement
2006-05-15 10:02:27 +02:00
print '<tr><td nowrap>' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td colspan="2">' ;
2006-02-16 18:46:09 +01:00
$html -> select_conditions_paiements ( $cond_reglement_id , 'cond_reglement_id' );
2005-09-15 02:37:03 +02:00
print '</td></tr>' ;
// Mode de r<> glement
2006-04-04 02:12:45 +02:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td colspan="2">' ;
2006-02-16 18:46:09 +01:00
$html -> select_types_paiements ( $mode_reglement_id , 'mode_reglement_id' );
2005-09-15 02:37:03 +02:00
print '</td></tr>' ;
2006-05-25 16:41:44 +02:00
// R<> ductions relatives (Remises-Ristournes-Rabbais)
/* Une r<EFBFBD> duction doit s ' appliquer obligatoirement sur des lignes de factures
et non globalement
2006-04-04 02:12:45 +02:00
print '<tr><td>' . $langs -> trans ( " CustomerRelativeDiscount " ) . '</td>' ;
print '<td>' ;
2006-04-08 15:29:18 +02:00
if ( ! $_GET [ 'propalid' ] && ! $_GET [ 'commandeid' ] && ! $_GET [ 'contratid' ]) print '<input type="text" name="remise_percent" size="1" value="' ;
print $remise_percent ;
if ( ! $_GET [ 'propalid' ] && ! $_GET [ 'commandeid' ] && ! $_GET [ 'contratid' ]) print '">' ;
print ' %' ;
2006-04-04 02:12:45 +02:00
print '</td><td>' . img_info () . ' ' ;
2006-04-08 15:29:18 +02:00
$relative_discount = $soc -> remise_client ;
2006-04-04 02:12:45 +02:00
if ( $relative_discount )
{
print $langs -> trans ( " CompanyHasRelativeDiscount " , $relative_discount );
}
else
{
print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
}
print '</td></tr>' ;
2006-05-25 16:41:44 +02:00
*/
2006-04-04 02:12:45 +02:00
2006-05-21 14:20:36 +02:00
// R<> ductions absolues (Remises-Ristournes-Rabbais)
2006-05-25 16:41:44 +02:00
/* Les remises absolues doivent s ' appliquer par ajout de lignes sp<EFBFBD> cialis<EFBFBD> es
2006-04-04 02:12:45 +02:00
print '<tr><td>' . $langs -> trans ( " CustomerAbsoluteDiscount " ) . '</td>' ;
print '<td>' ;
2006-04-08 15:29:18 +02:00
if ( ! $_GET [ 'propalid' ] && ! $_GET [ 'commandeid' ] && ! $_GET [ 'contratid' ]) print '<input type="text" name="remise_absolue" size="1" value="' ;
print $remise_absolue ;
if ( ! $_GET [ 'propalid' ] && ! $_GET [ 'commandeid' ] && ! $_GET [ 'contratid' ]) print '">' ;
print ' ' . $langs -> trans ( " Currency " . $conf -> monnaie );
2006-04-04 02:12:45 +02:00
print '</td><td>' . img_info () . ' ' ;
2006-04-08 15:29:18 +02:00
$absolute_discount = $soc -> getCurrentDiscount ();
2006-04-04 02:12:45 +02:00
if ( $absolute_discount )
{
print $langs -> trans ( " CompanyHasAbsoluteDiscount " , $absolute_discount , $langs -> trans ( " Currency " . $conf -> monnaie ));
}
else
{
print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
}
print '</td></tr>' ;
2006-05-25 16:41:44 +02:00
*/
2006-04-04 02:12:45 +02:00
2005-09-15 02:37:03 +02:00
// Projet
if ( $conf -> projet -> enabled )
{
$langs -> load ( 'projects' );
2006-04-04 02:12:45 +02:00
print '<tr><td>' . $langs -> trans ( 'Project' ) . '</td><td colspan="2">' ;
2006-04-10 15:18:40 +02:00
$html -> select_projects ( $societe_id , $projetid , 'projetid' );
2005-09-15 02:37:03 +02:00
print '</td></tr>' ;
}
2006-06-27 13:40:14 +02:00
2006-07-02 15:45:06 +02:00
print '<tr><td>' . $langs -> trans ( 'Model' ) . '</td>' ;
print '<td>' ;
2006-06-27 13:40:14 +02:00
// pdf
include_once ( DOL_DOCUMENT_ROOT . '/includes/modules/facture/modules_facture.php' );
$model = new ModelePDFFactures ();
$liste = $model -> liste_modeles ( $db );
2006-07-02 15:45:06 +02:00
$html -> select_array ( 'model' , $liste , $conf -> global -> FACTURE_ADDON_PDF );
2006-06-27 13:40:14 +02:00
print " </td></tr> " ;
2006-02-12 16:54:21 +01:00
// Note publique
2006-04-04 02:12:45 +02:00
print '<tr>' ;
2006-02-12 16:54:21 +01:00
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
2006-04-04 02:12:45 +02:00
print '<td valign="top" colspan="2">' ;
2006-02-12 16:54:21 +01:00
print '<textarea name="note_public" wrap="soft" cols="70" rows="' . ROWS_3 . '">' ;
if ( is_object ( $propal ))
2005-09-15 02:37:03 +02:00
{
2006-02-12 16:54:21 +01:00
print $propal -> note_public ;
2005-09-15 02:37:03 +02:00
}
2006-02-12 16:54:21 +01:00
if ( is_object ( $commande ))
{
print $commande -> note_public ;
}
if ( is_object ( $contrat ))
{
print $contrat -> note_public ;
}
print '</textarea></td></tr>' ;
// Note priv<69> e
2006-04-04 02:12:45 +02:00
print '<tr>' ;
2006-02-12 16:54:21 +01:00
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
2006-04-04 02:12:45 +02:00
print '<td valign="top" colspan="2">' ;
2006-02-12 16:54:21 +01:00
print '<textarea name="note" wrap="soft" cols="70" rows="' . ROWS_3 . '">' ;
if ( is_object ( $propal ))
{
print $propal -> note ;
}
if ( is_object ( $commande ))
{
print $commande -> note ;
}
if ( is_object ( $contrat ))
{
print $contrat -> note ;
}
print '</textarea></td></tr>' ;
2005-09-15 02:37:03 +02:00
2005-10-08 17:54:06 +02:00
/*
\todo
L ' info " Reference commande client " est une carac de la commande et non de la facture .
Elle devrait donc etre stock<EFBFBD> e sur l ' objet commande li<EFBFBD> <EFBFBD> la facture et non sur la facture .
Pour ceux qui utilisent ainsi , positionner la constante FAC_USE_CUSTOMER_ORDER_REF <EFBFBD> 1.
*/
if ( $conf -> global -> FAC_USE_CUSTOMER_ORDER_REF )
{
print '<tr><td>' . $langs -> trans ( 'RefCdeClient' ) . '</td><td>' ;
print '<input type="text" name="ref_client" value="' . $ref_client . '">' ;
print '</td></tr>' ;
}
2005-09-15 02:37:03 +02:00
if ( $_GET [ 'propalid' ] > 0 )
{
print '<input type="hidden" name="amount" value="' . $propal -> price . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $propal -> total . '">' . " \n " ;
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="tva" value="' . $propal -> tva . '">' . " \n " ;
2006-05-25 16:41:44 +02:00
// print '<input type="hidden" name="remise_absolue" value="'.$propal->remise_absolue.'">'."\n";
// print '<input type="hidden" name="remise_percent" value="'.$propal->remise_percent.'">'."\n";
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="propalid" value="' . $propal -> id . '">' ;
2005-09-15 02:37:03 +02:00
2006-06-01 01:05:29 +02:00
print '<tr><td>' . $langs -> trans ( 'Proposal' ) . '</td><td colspan="2"><a href="' . DOL_URL_ROOT . '/comm/propal.php?propalid=' . $propal -> id . '">' . img_object ( $langs -> trans ( " ShowPropal " ), 'propal' ) . ' ' . $propal -> ref . '</a></td></tr>' ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalHT' ) . '</td><td colspan="2">' . price ( $propal -> price ) . '</td></tr>' ;
2006-04-24 18:11:22 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalVAT' ) . '</td><td colspan="2">' . price ( $propal -> total_tva ) . " </td></tr> " ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalTTC' ) . '</td><td colspan="2">' . price ( $propal -> total ) . " </td></tr> " ;
}
elseif ( $_GET [ 'commandeid' ] > 0 )
{
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="amount" value="' . $commande -> total_ht . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $commande -> total_ttc . '">' . " \n " ;
print '<input type="hidden" name="tva" value="' . $commande -> tva . '">' . " \n " ;
2006-05-25 16:41:44 +02:00
// print '<input type="hidden" name="remise_absolue" value="'.$commande->remise_absolue.'">'."\n";
// print '<input type="hidden" name="remise_percent" value="'.$commande->remise_percent.'">'."\n";
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="commandeid" value="' . $commande -> id . '">' ;
2005-09-15 02:37:03 +02:00
2006-06-01 01:05:29 +02:00
print '<tr><td>' . $langs -> trans ( 'Order' ) . '</td><td colspan="2"><a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $commande -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $commande -> ref . '</a></td></tr>' ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalHT' ) . '</td><td colspan="2">' . price ( $commande -> total_ht ) . '</td></tr>' ;
2005-10-08 17:54:06 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalVAT' ) . '</td><td colspan="2">' . price ( $commande -> total_tva ) . " </td></tr> " ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalTTC' ) . '</td><td colspan="2">' . price ( $commande -> total_ttc ) . " </td></tr> " ;
}
elseif ( $_GET [ 'contratid' ] > 0 )
{
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
2006-04-08 15:29:18 +02:00
$contrat -> remise_absolue = $remise_absolue ;
$contrat -> remise_percent = $remise_percent ;
2005-09-15 02:37:03 +02:00
$contrat -> update_price ();
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="amount" value="' . $contrat -> total_ht . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $contrat -> total_ttc . '">' . " \n " ;
print '<input type="hidden" name="tva" value="' . $contrat -> total_tva . '">' . " \n " ;
2006-05-25 16:41:44 +02:00
// print '<input type="hidden" name="remise_absolue" value="'.$contrat->remise_absolue.'">'."\n";
// print '<input type="hidden" name="remise_percent" value="'.$contrat->remise_percent.'">'."\n";
2006-03-18 21:11:54 +01:00
print '<input type="hidden" name="contratid" value="' . $contrat -> id . '">' ;
2005-09-15 02:37:03 +02:00
2006-06-01 01:05:29 +02:00
print '<tr><td>' . $langs -> trans ( 'Contract' ) . '</td><td colspan="2"><a href="' . DOL_URL_ROOT . '/contrat/fiche.php?id=' . $contrat -> id . '">' . img_object ( $langs -> trans ( " ShowContract " ), 'contract' ) . ' ' . $contrat -> ref . '</a></td></tr>' ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalHT' ) . '</td><td colspan="2">' . price ( $contrat -> total_ht ) . '</td></tr>' ;
2005-10-08 17:54:06 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalVAT' ) . '</td><td colspan="2">' . price ( $contrat -> total_tva ) . " </td></tr> " ;
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'TotalTTC' ) . '</td><td colspan="2">' . price ( $contrat -> total_ttc ) . " </td></tr> " ;
}
else
{
print '<tr><td colspan="3">' ;
2006-04-04 02:12:45 +02:00
// Zone de choix des produits pr<70> d<EFBFBD> finis <20> la cr<63> ation
2005-09-15 02:37:03 +02:00
print '<table class="noborder">' ;
2006-05-25 16:41:44 +02:00
print '<tr><td>' . $langs -> trans ( 'ProductsAndServices' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td> </td>' ;
2005-09-15 02:37:03 +02:00
if ( $conf -> service -> enabled )
{
2006-07-01 01:38:12 +02:00
print '<td>' . $langs -> trans ( 'ServiceLimitedDuration' ) . '</td>' ;
2005-09-15 02:37:03 +02:00
}
2006-07-01 01:38:12 +02:00
print '</tr>' ;
2005-09-15 02:37:03 +02:00
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
{
2006-07-01 01:38:12 +02:00
print '<tr>' ;
print '<td>' ;
2006-02-03 17:42:39 +01:00
// multiprix
if ( $conf -> global -> PRODUIT_MULTIPRICES == 1 )
$html -> select_produits ( '' , 'idprod' . $i , '' , $conf -> produit -> limit_size , $soc -> price_level );
else
$html -> select_produits ( '' , 'idprod' . $i , '' , $conf -> produit -> limit_size );
2005-09-15 02:37:03 +02:00
print '</td>' ;
2006-04-04 02:12:45 +02:00
print '<td><input type="text" size="2" name="qty' . $i . '" value="1"></td>' ;
2006-05-25 16:41:44 +02:00
print '<td nowrap="nowrap"><input type="text" size="1" name="remise_percent' . $i . '" value="' . $soc -> remise_client . '">%</td>' ;
2005-09-15 02:37:03 +02:00
print '<td> </td>' ;
// Si le module service est actif, on propose des dates de d<> but et fin <20> la ligne
if ( $conf -> service -> enabled )
{
2005-10-08 17:54:06 +02:00
print '<td nowrap="nowrap">' ;
2006-01-07 18:07:49 +01:00
print $langs -> trans ( 'From' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( '' , 'date_start' . $i , 0 , 0 , 1 , " add " );
2006-01-07 18:07:49 +01:00
print '<br>' . $langs -> trans ( 'to' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( '' , 'date_end' . $i , 0 , 0 , 1 , " add " );
2005-09-15 02:37:03 +02:00
print '</td>' ;
}
print " </tr> \n " ;
}
print '</table>' ;
print '</td></tr>' ;
}
/*
* Factures r<EFBFBD> currentes
*/
2006-05-25 16:41:44 +02:00
if ( ! $conf -> global -> FACTURE_DISABLE_RECUR )
2005-09-15 02:37:03 +02:00
{
2006-05-25 16:41:44 +02:00
if ( $_GET [ 'propalid' ] == 0 && $_GET [ 'commandeid' ] == 0 && $_GET [ 'contratid' ] == 0 )
2005-09-15 02:37:03 +02:00
{
2006-05-25 16:41:44 +02:00
$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 ) )
2005-09-15 02:37:03 +02:00
{
2006-05-25 16:41:44 +02:00
$num = $db -> num_rows ();
$i = 0 ;
if ( $num > 0 )
2005-09-15 02:37:03 +02:00
{
2006-05-25 16:41:44 +02:00
print '<tr><td colspan="3">' . $langs -> trans ( 'CreateFromRepeatableInvoice' ) . ' : <select class="flat" name="fac_rec">' ;
print '<option value="0" selected="true"></option>' ;
while ( $i < $num )
{
$objp = $db -> fetch_object ();
print '<option value="' . $objp -> rowid . '">' . $objp -> titre . ' : ' . $objp -> amount . '</option>' ;
$i ++ ;
}
print '</select></td></tr>' ;
2005-09-15 02:37:03 +02:00
}
2006-05-25 16:41:44 +02:00
$db -> free ();
}
else
{
dolibarr_print_error ( $db );
2005-09-15 02:37:03 +02:00
}
}
}
2006-05-25 16:41:44 +02:00
2005-09-15 02:37:03 +02:00
// Bouton "Create Draft"
print '<tr><td colspan="3" align="center"><input type="submit" class="button" name="bouton" value="' . $langs -> trans ( 'CreateDraft' ) . '"></td></tr>' ;
print " </table> \n " ;
2006-04-04 02:12:45 +02:00
print " </form> \n " ;
2005-09-15 02:37:03 +02:00
// Si creation depuis un propal
if ( $_GET [ 'propalid' ])
{
print '<br>' ;
print_titre ( $langs -> trans ( 'ProductsAndServices' ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Ref' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2006-05-25 16:41:44 +02:00
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
2006-07-01 01:38:12 +02:00
// Lignes de propal
$sql = 'SELECT p.label as product, p.ref, p.rowid as prodid,' ;
$sql .= ' pt.rowid, pt.tva_tx, pt.price, pt.qty, pt.remise_percent, pt.description, pt.info_bits' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'propaldet as pt LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON pt.fk_product = p.rowid' ;
$sql .= ' WHERE pt.fk_propal = ' . $_GET [ 'propalid' ];
$sql .= ' ORDER BY pt.rowid ASC' ;
2005-09-15 02:37:03 +02:00
$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 ;
2006-07-01 01:38:12 +02:00
print '<tr ' . $bc [ $var ] . '><td>' ;
if ( $objp -> info_bits == 2 )
{
print img_object ( $langs -> trans ( '' ), 'reduc' ) . ' ' . $langs -> trans ( " Discount " );
}
else if ( $objp -> prodid )
{
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> prodid . '">' . img_object ( $langs -> trans ( '' ), 'product' ) . ' ' . $objp -> ref . '</a>' ;
print $objp -> product ? ' - ' . $objp -> product : '' ;
}
else
{
print ' ' ;
}
2005-09-15 02:37:03 +02:00
print " </td> \n " ;
print '<td>' ;
2006-07-01 01:38:12 +02:00
print nl2br ( dolibarr_trunc ( $objp -> description , 60 ));
2005-09-15 02:37:03 +02:00
print '</td>' ;
print '<td align="right">' . $objp -> tva_tx . '%</td>' ;
print '<td align="right">' . price ( $objp -> price ) . '</td>' ;
print '<td align="right">' . $objp -> qty . '</td>' ;
2006-07-01 01:38:12 +02:00
print '<td align="right">' ;
print $objp -> info_bits != 2 ? $objp -> remise_percent . '%' : ' ' ;
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
$i ++ ;
}
}
else
{
dolibarr_print_error ( $db );
}
print '</table>' ;
}
// Si creation depuis une commande
if ( $_GET [ 'commandeid' ])
{
print '<br>' ;
print_titre ( $langs -> trans ( 'Products' ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Ref' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2006-05-25 16:41:44 +02:00
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
2006-07-01 01:38:12 +02:00
$sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description, pt.info_bits,' ;
2005-09-15 02:37:03 +02:00
$sql .= ' p.label as product, p.ref, p.rowid as prodid' ;
2006-07-01 01:38:12 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'commandedet as pt LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON pt.fk_product = p.rowid' ;
$sql .= ' WHERE pt.fk_commande = ' . $commande -> id ;
2005-09-15 02:37:03 +02:00
$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 ;
2006-07-01 01:38:12 +02:00
print '<tr ' . $bc [ $var ] . '><td>' ;
if ( $objp -> info_bits == 2 )
{
print img_object ( $langs -> trans ( '' ), 'reduc' ) . ' ' . $langs -> trans ( " Discount " );
}
else if ( $objp -> prodid )
{
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> prodid . '">' . img_object ( $langs -> trans ( '' ), 'product' ) . ' ' . $objp -> ref . '</a>' ;
print $objp -> product ? ' - ' . $objp -> product : '' ;
}
else
{
print ' ' ;
}
2005-09-15 02:37:03 +02:00
print " </td> \n " ;
print '<td>' ;
2006-07-01 01:38:12 +02:00
print nl2br ( dolibarr_trunc ( $objp -> description , 60 ));
2005-09-15 02:37:03 +02:00
print '</td>' ;
print '<td align="right">' . $objp -> tva_tx . '%</td>' ;
print '<td align="right">' . price ( $objp -> subprice ) . '</td>' ;
print '<td align="right">' . $objp -> qty . '</td>' ;
2006-07-01 01:38:12 +02:00
print '<td align="right">' ;
print $objp -> info_bits != 2 ? $objp -> remise_percent . '%' : ' ' ;
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
$i ++ ;
}
}
else
{
dolibarr_print_error ( $db );
}
print '</table>' ;
}
// Si creation depuis un contrat
if ( $_GET [ 'contratid' ])
{
print '<br>' ;
print_titre ( $langs -> trans ( 'Services' ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Ref' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2006-05-25 16:41:44 +02:00
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
// Lignes de contrat produits pr<70> d<EFBFBD> finis
2006-07-01 01:38:12 +02:00
$sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description, pt.info_bits,' ;
2005-09-15 02:37:03 +02:00
$sql .= ' pt.date_ouverture_prevue as date_debut_prevue, pt.date_ouverture as date_debut_reel,' ;
$sql .= ' pt.date_fin_validite as date_fin_prevue, pt.date_cloture as date_fin_reel,' ;
$sql .= ' p.label as product, p.ref, p.rowid as prodid' ;
2006-07-01 01:38:12 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'contratdet as pt LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON pt.fk_product = p.rowid' ;
$sql .= ' WHERE pt.fk_contrat = ' . $contrat -> id ;
2005-09-15 02:37:03 +02:00
$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 ;
2006-07-01 01:38:12 +02:00
print '<tr ' . $bc [ $var ] . '><td>' ;
if ( $objp -> info_bits == 2 )
{
print img_object ( $langs -> trans ( '' ), 'reduc' ) . ' ' . $langs -> trans ( " Discount " );
}
else if ( $objp -> prodid )
{
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> prodid . '">' . img_object ( $langs -> trans ( '' ), 'service' ) . ' ' . $objp -> ref . '</a>' ;
print $objp -> product ? ' - ' . $objp -> product : '' ;
// Plage de dates
$date_start = $objp -> date_debut_prevue ;
if ( $objp -> date_debut_reel ) $date_start = $objp -> date_debut_reel ;
$date_end = $objp -> date_fin_prevue ;
if ( $objp -> date_fin_reel ) $date_end = $objp -> date_fin_reel ;
print_date_range ( $date_start , $date_end );
}
else
{
print ' ' ;
}
2005-09-15 02:37:03 +02:00
print " </td> \n " ;
print '<td>' ;
print dolibarr_trunc ( $objp -> description , 60 );
print '</td>' ;
print '<td align="right">' . $objp -> tva_tx . '%</td>' ;
print '<td align="right">' . price ( $objp -> subprice ) . '</td>' ;
print '<td align="right">' . $objp -> qty . '</td>' ;
2006-07-01 01:38:12 +02:00
print '<td align="right">' ;
print $objp -> info_bits != 2 ? $objp -> remise_percent . '%' : ' ' ;
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
$i ++ ;
}
}
else
{
dolibarr_print_error ( $db );
}
print '</table>' ;
}
2005-09-04 16:52:36 +02:00
2005-08-20 21:02:26 +02:00
}
else
{
2006-06-20 11:56:54 +02:00
$id = $_GET [ 'facid' ];
if ( $id > 0 )
2005-09-15 02:37:03 +02:00
{
/* *************************************************************************** */
/* */
/* Fiche en mode visu */
/* */
/* *************************************************************************** */
if ( $msg ) print $msg . '<br>' ;
$fac = New Facture ( $db );
if ( $fac -> fetch ( $_GET [ 'facid' ], $user -> societe_id ) > 0 )
{
$soc = new Societe ( $db , $fac -> socidp );
$soc -> fetch ( $fac -> socidp );
2006-06-24 15:50:22 +02:00
$absolute_discount = $soc -> getCurrentDiscount ();
2006-04-04 02:12:45 +02:00
2005-09-15 02:37:03 +02:00
$author = new User ( $db );
2005-12-07 03:32:56 +01:00
if ( $fac -> user_author )
{
$author -> id = $fac -> user_author ;
$author -> fetch ();
}
2005-09-15 02:37:03 +02:00
2005-11-30 18:37:01 +01:00
$head = facture_prepare_head ( $fac );
2006-03-14 22:31:59 +01:00
dolibarr_fiche_head ( $head , 0 , $langs -> trans ( 'InvoiceCustomer' ));
2005-09-15 02:37:03 +02:00
/*
2005-11-11 20:22:57 +01:00
* Confirmation de la suppression de la facture
*/
2005-09-15 02:37:03 +02:00
if ( $_GET [ 'action' ] == 'delete' )
{
$html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $langs -> trans ( 'DeleteBill' ), $langs -> trans ( 'ConfirmDeleteBill' ), 'confirm_delete' );
print '<br />' ;
}
/*
2005-10-02 17:14:16 +02:00
* Confirmation de la validation
*/
if ( $_GET [ 'action' ] == 'valid' )
2005-09-15 02:37:03 +02:00
{
2006-07-11 08:42:44 +02:00
// on v<> rifie si la facture est en num<75> rotation provisoire
$facref = substr ( $fac -> ref , 1 , 4 );
if ( $facref == PROV )
{
$numfa = $fac -> getNextNumRef ( $soc );
}
else
{
$numfa = $fac -> ref ;
}
2005-11-04 21:45:02 +01:00
$html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id , $langs -> trans ( 'ValidateBill' ), $langs -> trans ( 'ConfirmValidateBill' , $numfa ), 'confirm_valid' );
2005-09-15 02:37:03 +02:00
print '<br />' ;
}
/*
2005-10-02 17:14:16 +02:00
* Confirmation du classement pay<EFBFBD>
*/
if ( $_GET [ 'action' ] == 'payed' )
2005-09-15 02:37:03 +02:00
{
2005-11-04 21:45:02 +01:00
$html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id , $langs -> trans ( 'ClassifyPayed' ), $langs -> trans ( 'ConfirmClassifyPayedBill' , $fac -> ref ), 'confirm_payed' );
2005-10-02 17:14:16 +02:00
print '<br />' ;
}
/*
* Confirmation du classement abandonn
*/
if ( $_GET [ 'action' ] == 'canceled' )
{
$html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $langs -> trans ( 'CancelBill' ), $langs -> trans ( 'ConfirmCancelBill' , $fac -> ref ), 'confirm_canceled' );
2005-09-15 02:37:03 +02:00
print '<br />' ;
}
2006-06-08 14:40:10 +02:00
/*
* Confirmation de la suppression d ' une ligne produit
*/
if ( $_GET [ 'action' ] == 'delete_product_line' && $conf -> global -> PRODUIT_CONFIRM_DELETE_LINE )
{
$html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&rowid=' . $_GET [ " rowid " ], $langs -> trans ( 'DeleteProductLine' ), $langs -> trans ( 'ConfirmDeleteProductLine' ), 'confirm_deleteproductline' );
print '<br />' ;
}
2005-09-15 02:37:03 +02:00
/*
2006-03-25 15:21:30 +01:00
* Facture
*/
2005-09-15 02:37:03 +02:00
print '<table class="border" width="100%">' ;
2005-11-04 21:45:02 +01:00
2006-07-01 01:38:12 +02:00
// Reference
print '<tr><td width="20%">' . $langs -> trans ( 'Ref' ) . '</td><td colspan="5">' . $fac -> ref . '</td></tr>' ;
// Ref client
2006-06-20 11:56:54 +02:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">' ;
print $langs -> trans ( 'RefCustomer' ) . '</td><td align="left">' ;
print '</td>' ;
2006-06-20 11:56:54 +02:00
if ( $_GET [ 'action' ] != 'refcdeclient' && $fac -> brouillon ) print '<td align="right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=refcdeclient&facid=' . $fac -> id . '">' . img_edit ( $langs -> trans ( 'Edit' )) . '</a></td>' ;
2006-06-20 11:56:54 +02:00
print '</tr></table>' ;
2006-07-01 01:38:12 +02:00
print '</td><td colspan="5">' ;
2006-06-20 11:56:54 +02:00
if ( $user -> rights -> facture -> creer && $_GET [ 'action' ] == 'refcdeclient' )
{
print '<form action="facture.php?facid=' . $id . '" method="post">' ;
print '<input type="hidden" name="action" value="set_ref_client">' ;
print '<input type="text" class="flat" size="20" name="ref_client" value="' . $fac -> ref_client . '">' ;
print ' <input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
2006-06-20 12:02:57 +02:00
print $fac -> ref_client ;
2006-06-20 11:56:54 +02:00
}
print '</td>' ;
print '</tr>' ;
2005-12-03 17:56:04 +01:00
2005-11-04 21:45:02 +01:00
// Soci<63> t<EFBFBD>
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'Company' ) . '</td>' ;
2006-06-03 18:04:32 +02:00
print '<td colspan="5">' . $soc -> getNomUrl ( 1 , 'compta' ) . '</td>' ;
2005-11-04 21:45:02 +01:00
print '</tr>' ;
2005-09-15 02:37:03 +02:00
2006-05-25 16:41:44 +02:00
// Ligne info remises tiers
2006-07-01 01:38:12 +02:00
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td colspan="5">' ;
2006-05-25 16:41:44 +02:00
if ( $soc -> remise_client ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_client );
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
2006-07-01 01:38:12 +02:00
$absolute_discount = $soc -> getCurrentDiscount ();
2006-05-25 16:41:44 +02:00
print '. ' ;
2006-07-01 01:38:12 +02:00
if ( $absolute_discount )
{
if ( $fac -> statut > 0 )
{
print $langs -> trans ( " CompanyHasAbsoluteDiscount " , $absolute_discount , $langs -> trans ( " Currency " . $conf -> monnaie ));
}
else
{
print '<br>' ;
print $html -> form_remise_dispo ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id , 0 , 'remise_id' , $soc -> id , $absolute_discount );
}
}
else print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " ) . '.' ;
2006-05-25 16:41:44 +02:00
print '</td></tr>' ;
2005-11-04 21:45:02 +01:00
// Dates
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td colspan="3">' . dolibarr_print_date ( $fac -> date , '%A %d %B %Y' ) . '</td>' ;
2006-04-04 02:12:45 +02:00
$nbrows = 8 ;
2005-10-08 17:54:06 +02:00
if ( $conf -> global -> FAC_USE_CUSTOMER_ORDER_REF ) $nbrows ++ ;
print '<td rowspan="' . $nbrows . '" colspan="2" valign="top">' ;
2005-09-15 02:37:03 +02:00
/*
2005-11-10 22:04:45 +01:00
* Liste des paiements
2005-09-15 02:37:03 +02:00
*/
2006-03-19 01:39:12 +01:00
$totalpaye = 0 ;
print $langs -> trans ( 'Payments' ) . ' :<br>' ;
2005-09-15 02:37:03 +02:00
$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 );
2006-03-19 01:39:12 +01:00
$i = 0 ;
2005-09-15 02:37:03 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre"><td>' . $langs -> trans ( 'Date' ) . '</td><td>' . $langs -> trans ( 'Type' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Amount' ) . '</td><td> </td></tr>' ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '><td>' ;
2005-12-07 23:17:02 +01:00
print '<a href="' . DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $objp -> rowid . '">' . img_object ( $langs -> trans ( 'ShowPayment' ), 'payment' ) . ' ' ;
print dolibarr_print_date ( $objp -> dp ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td>' . $objp -> paiement_type . ' ' . $objp -> num_paiement . '</td>' ;
print '<td align="right">' . price ( $objp -> amount ) . '</td><td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td>' ;
print '</tr>' ;
$totalpaye += $objp -> amount ;
$i ++ ;
}
2006-01-05 19:57:12 +01:00
print '<tr><td colspan="2" align="right">' . $langs -> trans ( 'AlreadyPayed' ) . ' :</td><td align="right"><b>' . price ( $totalpaye ) . '</b></td><td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
print '<tr><td colspan="2" align="right">' . $langs -> trans ( " Billed " ) . ' :</td><td align="right" style="border: 1px solid;">' . price ( $fac -> total_ttc ) . '</td><td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
2006-01-05 19:57:12 +01:00
$resteapayer = $fac -> total_ttc - $totalpaye ;
print '<tr><td colspan="2" align="right">' . $langs -> trans ( 'RemainderToPay' ) . ' :</td>' ;
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price ( $resteapayer ) . '</b></td><td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
print '</table>' ;
$db -> free ( $result );
}
else
{
dolibarr_print_error ( $db );
}
2006-04-04 02:12:45 +02:00
print '</td></tr>' ;
// Date limite reglement
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DateMaxPayment' ) . '</td>' ;
print '<td colspan="3">' . 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' ));
2005-09-15 02:37:03 +02:00
print '</td></tr>' ;
2006-04-04 02:12:45 +02:00
// Conditions de r<> glement
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
2006-05-15 10:02:27 +02:00
print $langs -> trans ( 'PaymentConditionsShort' );
2006-04-04 02:12:45 +02:00
print '</td>' ;
if ( $_GET [ 'action' ] != 'editconditions' && $fac -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&facid=' . $fac -> id . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $_GET [ 'action' ] == 'editconditions' )
{
$html -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> cond_reglement_id , 'cond_reglement_id' );
}
else
{
$html -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> cond_reglement_id , 'none' );
}
print '</td></tr>' ;
// Mode de reglement
print '<tr><td width="25%">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
if ( $_GET [ 'action' ] != 'editmode' && $fac -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&facid=' . $fac -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $_GET [ 'action' ] == 'editmode' )
{
$html -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> mode_reglement_id , 'mode_reglement_id' );
}
else
{
$html -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> mode_reglement_id , 'none' );
}
print '</td></tr>' ;
2005-10-08 17:54:06 +02:00
/*
\todo
L ' info " Reference commande client " est une carac de la commande et non de la facture .
Elle devrait donc etre stock<EFBFBD> e sur l ' objet commande li<EFBFBD> <EFBFBD> la facture et non sur la facture .
Pour ceux qui utilisent ainsi , positionner la constante FAC_USE_CUSTOMER_ORDER_REF <EFBFBD> 1.
*/
if ( $conf -> global -> FAC_USE_CUSTOMER_ORDER_REF )
{
print '<tr><td>' . $langs -> trans ( 'RefCdeClient' ) . '</td>' ;
if ( $fac -> brouillon == 1 && $user -> rights -> facture -> creer )
{
2006-04-08 13:39:41 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '" method="post">' ;
2005-10-08 17:54:06 +02:00
print '<input type="hidden" name="action" value="set_ref_client">' ;
print '<td colspan="3"><input type="text" name="ref_client" size="20" value="' . $fac -> ref_client . '">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '"></td>' ;
print '</form>' ;
}
else
{
print '<td colspan="3">' . $fac -> ref_client . '</td>' ;
}
}
2005-09-15 02:37:03 +02:00
2006-04-04 02:12:45 +02:00
// Lit lignes de facture pour d<> terminer montant
// On s'en sert pas mais ca sert pour debuggage
$sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,' ;
$sql .= ' l.remise_percent, l.subprice' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facturedet as l ' ;
$sql .= ' WHERE l.fk_facture = ' . $fac -> id ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num_lignes = $db -> num_rows ( $resql );
$i = 0 ;
$total_lignes_ht = 0 ;
$total_lignes_vat = 0 ;
$total_lignes_ttc = 0 ;
while ( $i < $num_lignes )
{
$obj = $db -> fetch_object ( $resql );
$ligne_ht = ( $obj -> price * $obj -> qty );
$ligne_vat = ( $ligne_ht * $obj -> tva_taux / 100 );
$ligne_ttc = ( $ligne_ht + $ligne_vat );
$total_lignes_ht += $ligne_ht ;
$total_lignes_vat += $ligne_vat ;
$total_lignes_ttc += $ligne_ttc ;
$i ++ ;
}
}
// Montants
2005-09-15 02:37:03 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
2006-04-04 02:12:45 +02:00
print '<td align="right" colspan="2" nowrap>' . price ( $fac -> total_ht ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2005-10-08 17:54:06 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td align="right" colspan="2" nowrap>' . price ( $fac -> total_tva ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td align="right" colspan="2" nowrap>' . price ( $fac -> total_ttc ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
// Statut
2006-03-19 01:39:12 +01:00
print '<tr><td>' . $langs -> trans ( 'Status' ) . '</td>' ;
print '<td align="left" colspan="3">' . ( $fac -> getLibStatut ( 4 , $totalpaye )) . '</td></tr>' ;
2005-09-15 02:37:03 +02:00
2006-03-14 22:31:59 +01:00
// Projet
if ( $conf -> projet -> enabled )
2005-09-15 02:37:03 +02:00
{
2006-03-14 22:31:59 +01:00
print '<tr>' ;
$langs -> load ( 'projects' );
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Project' );
print '</td>' ;
if ( $_GET [ 'action' ] != 'classer' )
{
2006-04-08 13:39:41 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=classer&facid=' . $fac -> id . '">' ;
2006-03-14 22:31:59 +01:00
print img_edit ( $langs -> trans ( 'SetProject' ), 1 );
print '</a></td>' ;
}
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $_GET [ 'action' ] == 'classer' )
{
2006-07-04 10:31:38 +02:00
$html -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> socidp , $fac -> projetid , 'projetid' );
2006-03-14 22:31:59 +01:00
}
else
{
2006-07-04 10:31:38 +02:00
$html -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id , $fac -> socidp , $fac -> projetid , 'none' );
2006-03-14 22:31:59 +01:00
}
print '</td>' ;
print '</tr>' ;
2005-09-15 02:37:03 +02:00
}
2006-03-14 22:31:59 +01:00
2005-09-15 02:37:03 +02:00
print '</table><br>' ;
2006-03-25 15:21:30 +01:00
2005-09-15 02:37:03 +02:00
/*
* Lignes de factures
*/
2006-06-07 23:03:19 +02:00
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,' ;
2006-07-01 01:38:12 +02:00
$sql .= ' l.remise_percent, l.subprice, l.info_bits,' ;
2006-06-07 23:03:19 +02:00
$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 .= ' p.description as product_desc' ;
$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' ;
2005-09-15 02:37:03 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num_lignes = $db -> num_rows ( $resql );
$i = 0 ; $total = 0 ;
print '<table class="noborder" width="100%">' ;
2006-03-25 15:21:30 +01:00
2005-09-15 02:37:03 +02:00
if ( $num_lignes )
{
2006-03-25 15:21:30 +01:00
2005-09-15 02:37:03 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right" width="80">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2006-05-25 16:41:44 +02:00
print '<td align="right" width="50">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td align="right" width="50">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
2006-04-08 13:39:41 +02:00
print '<td width="16"> </td>' ;
print '<td width="16"> </td>' ;
2006-05-25 17:53:13 +02:00
print '<td width="12"> </td>' ;
2005-09-15 02:37:03 +02:00
print " </tr> \n " ;
2006-03-25 15:21:30 +01:00
2005-09-15 02:37:03 +02:00
}
$var = true ;
while ( $i < $num_lignes )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
// Ligne en mode visu
if ( $_GET [ 'action' ] != 'editline' || $_GET [ 'rowid' ] != $objp -> rowid )
{
print '<tr ' . $bc [ $var ] . '>' ;
if ( $objp -> fk_product > 0 )
{
2006-07-17 18:49:33 +02:00
print '<td>' ;
print '<a name="' . $objp -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' ;
2005-09-15 02:37:03 +02:00
if ( $objp -> fk_product_type ) print img_object ( $langs -> trans ( 'ShowService' ), 'service' );
else print img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
print ' ' . $objp -> ref . '</a>' ;
print ' - ' . nl2br ( stripslashes ( $objp -> product ));
print_date_range ( $objp -> date_start , $objp -> date_end );
2006-02-12 11:59:11 +01:00
print ( $objp -> description && $objp -> description != $objp -> product ) ? '<br>' . stripslashes ( nl2br ( $objp -> description )) : '' ;
2006-02-11 17:24:55 +01:00
2006-05-22 00:34:15 +02:00
if ( $conf -> global -> FAC_ADD_PROD_DESC && ! $conf -> global -> PRODUIT_CHANGE_PROD_DESC )
2006-02-11 17:24:55 +01:00
{
print '<br>' . nl2br ( stripslashes ( $objp -> product_desc ));
}
2005-09-15 02:37:03 +02:00
print '</td>' ;
}
else
{
2006-07-01 01:38:12 +02:00
print '<td>' ;
2006-07-18 09:54:58 +02:00
print '<a name="' . $objp -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
2006-07-01 01:38:12 +02:00
if (( $objp -> info_bits & 2 ) == 2 )
{
print '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $fac -> socidp . '">' ;
print img_object ( $langs -> trans ( " ShowReduc " ), 'reduc' ) . ' ' . $langs -> trans ( " Discount " );
print '</a>' ;
2006-07-01 15:03:46 +02:00
if ( $objp -> description ) print ' - ' . nl2br ( $objp -> description );
2006-07-01 01:38:12 +02:00
}
else
{
print nl2br ( $objp -> description );
print_date_range ( $objp -> date_start , $objp -> date_end );
}
2005-09-15 02:37:03 +02:00
print " </td> \n " ;
}
print '<td align="right">' . $objp -> tva_taux . '%</td>' ;
print '<td align="right">' . price ( $objp -> subprice ) . " </td> \n " ;
2006-07-01 01:38:12 +02:00
print '<td align="right">' ;
if (( $objp -> info_bits & 2 ) != 2 )
{
print $objp -> qty ;
}
else print ' ' ;
print '</td>' ;
2005-09-15 02:37:03 +02:00
if ( $objp -> remise_percent > 0 )
{
print '<td align="right">' . $objp -> remise_percent . " %</td> \n " ;
}
else
{
print '<td> </td>' ;
}
print '<td align="right">' . price ( $objp -> subprice * $objp -> qty * ( 100 - $objp -> remise_percent ) / 100 ) . " </td> \n " ;
// Icone d'edition et suppression
if ( $fac -> statut == 0 && $user -> rights -> facture -> creer )
{
2006-07-17 18:49:33 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=editline&rowid=' . $objp -> rowid . '#' . $objp -> rowid . '">' ;
2005-09-15 02:37:03 +02:00
print img_edit ();
print '</a></td>' ;
2006-06-08 14:40:10 +02:00
if ( $conf -> global -> PRODUIT_CONFIRM_DELETE_LINE )
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=delete_product_line&rowid=' . $objp -> rowid . '">' ;
}
else
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=deleteline&rowid=' . $objp -> rowid . '">' ;
}
2005-09-15 02:37:03 +02:00
print img_delete ();
print '</a></td>' ;
print '<td align="right">' ;
if ( $i > 0 )
{
2006-04-08 13:39:41 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=up&rowid=' . $objp -> rowid . '">' ;
2005-09-15 02:37:03 +02:00
print img_up ();
print '</a>' ;
}
if ( $i < $num_lignes - 1 )
{
2006-04-08 13:39:41 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=down&rowid=' . $objp -> rowid . '">' ;
2005-09-15 02:37:03 +02:00
print img_down ();
print '</a>' ;
}
print '</td>' ;
}
else
{
print '<td colspan="3"> </td>' ;
}
print '</tr>' ;
}
// Ligne en mode update
if ( $_GET [ 'action' ] == 'editline' && $user -> rights -> facture -> creer && $_GET [ 'rowid' ] == $objp -> rowid )
{
2006-07-17 18:49:33 +02:00
print '<form name="updateligne" action="' . $_SERVER [ " PHP_SELF " ] . '#' . $objp -> rowid . '" method="post">' ;
2005-09-15 02:37:03 +02:00
print '<input type="hidden" name="action" value="updateligne">' ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<input type="hidden" name="rowid" value="' . $_GET [ 'rowid' ] . '">' ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' ;
2006-07-18 09:54:58 +02:00
print '<a name="' . $objp -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
2005-09-15 02:37:03 +02:00
if ( $objp -> fk_product > 0 )
{
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' ;
if ( $objp -> fk_product_type ) print img_object ( $langs -> trans ( 'ShowService' ), 'service' );
else print img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
print ' ' . $objp -> ref . '</a>' ;
2006-07-01 01:38:12 +02:00
print ' - ' . nl2br ( $objp -> product );
2005-09-15 02:37:03 +02:00
print '<br>' ;
}
2006-07-21 15:43:27 +02:00
// <20> diteur wysiwyg
if ( $conf -> fckeditor -> enabled && $conf -> global -> FCKEDITOR_ENABLE_PRODUCTDESC )
{
require_once ( DOL_DOCUMENT_ROOT . " /includes/fckeditor/fckeditor.php " );
$oFCKeditor = new FCKeditor ( 'desc' );
$oFCKeditor -> Value = $objp -> description ;
$oFCKeditor -> Create () ;
}
else
{
print '<textarea name="desc" class="flat" cols="70" rows="' . ROWS_2 . '">' . $objp -> description . '</textarea>' ;
}
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td align="right">' ;
2006-03-16 02:26:49 +01:00
if ( ! $soc -> tva_assuj )
2006-02-21 14:27:07 +01:00
print '<input type="hidden" name="tva_tx" value="0">0' ;
else
print $html -> select_tva ( 'tva_tx' , $objp -> tva_taux , $mysoc , $soc );
2005-09-15 02:37:03 +02:00
print '</td>' ;
2006-07-01 01:38:12 +02:00
print '<td align="right"><input size="6" type="text" class="flat" name="price" value="' . price ( $objp -> subprice ) . '"></td>' ;
print '<td align="right">' ;
if (( $objp -> info_bits & 2 ) != 2 )
{
print '<input size="2" type="text" class="flat" name="qty" value="' . $objp -> qty . '">' ;
}
else print ' ' ;
print '</td>' ;
print '<td align="right" nowrap>' ;
2006-07-17 16:49:46 +02:00
if (( $objp -> info_bits & 2 ) != 2 )
2006-07-01 01:38:12 +02:00
{
print '<input size="2" type="text" class="flat" name="remise_percent" value="' . $objp -> remise_percent . '">%' ;
}
else print ' ' ;
print '</td>' ;
2005-12-07 15:43:38 +01:00
print '<td align="center" rowspan="1" colspan="5" valign="center"><input type="submit" class="button" name="save" value="' . $langs -> trans ( 'Save' ) . '">' ;
2005-09-15 02:37:03 +02:00
print '<br /><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( 'Cancel' ) . '"></td>' ;
print '</tr>' . " \n " ;
if ( $conf -> service -> enabled )
{
print '<tr ' . $bc [ $var ] . '>' ;
2005-12-07 17:13:23 +01:00
print '<td colspan="9">' . $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( $objp -> date_start , 'date_start' , 0 , 0 , $objp -> date_start ? 0 : 1 , " updateligne " );
2005-12-07 17:13:23 +01:00
print ' ' . $langs -> trans ( 'to' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( $objp -> date_end , 'date_end' , 0 , 0 , $objp -> date_end ? 0 : 1 , " updateligne " );
2005-09-01 22:15:06 +02:00
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
}
print " </form> \n " ;
}
$total = $total + ( $objp -> qty * $objp -> price );
$i ++ ;
}
$db -> free ( $resql );
}
else
{
dolibarr_print_error ( $db );
}
2006-04-04 02:12:45 +02:00
/*
* Lignes de remise
*/
2006-05-25 17:48:35 +02:00
// R<> ductions relatives (Remises-Ristournes-Rabbais)
/* Une r<EFBFBD> duction doit s ' appliquer obligatoirement sur des lignes de factures
2006-04-04 02:12:45 +02:00
$var =! $var ;
2006-04-08 13:39:41 +02:00
print '<form name="updateligne" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2006-04-04 02:12:45 +02:00
print '<input type="hidden" name="action" value="setremisepercent">' ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<tr class="liste_total"><td>' ;
print $langs -> trans ( 'CustomerRelativeDiscount' );
if ( $fac -> brouillon ) print ' <font style="font-weight: normal">(' . ( $soc -> remise_client ? $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_client ) : $langs -> trans ( " CompanyHasNoRelativeDiscount " )) . ')</font>' ;
print '</td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td align="right"><font style="font-weight: normal">' ;
if ( $_GET [ 'action' ] == 'editrelativediscount' )
{
print '<input type="text" name="remise_percent" size="2" value="' . $fac -> remise_percent . '">%' ;
}
else
{
print $fac -> remise_percent ? $fac -> remise_percent . '%' : ' ' ;
}
print '</font></td>' ;
print '<td align="right"><font style="font-weight: normal">' ;
if ( $_GET [ 'action' ] != 'editrelativediscount' ) print $fac -> remise_percent ? '-' . price ( $fac -> remise_percent * $total / 100 ) : $langs -> trans ( " DiscountNone " );
else print ' ' ;
print '</font></td>' ;
if ( $_GET [ 'action' ] != 'editrelativediscount' )
{
if ( $fac -> brouillon && $user -> rights -> facture -> creer )
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editrelativediscount&facid=' . $fac -> id . '">' . img_edit ( $langs -> trans ( 'SetRelativeDiscount' ), 1 ) . '</a></td>' ;
}
else
{
print '<td> </td>' ;
}
2006-04-04 02:27:02 +02:00
if ( $fac -> brouillon && $user -> rights -> facture -> creer && $fac -> remise_percent )
{
2006-04-08 13:39:41 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=setremisepercent&rowid=' . $objp -> rowid . '">' ;
2006-04-04 02:27:02 +02:00
print img_delete ();
print '</a></td>' ;
}
else
{
print '<td> </td>' ;
}
2006-04-04 02:12:45 +02:00
print '<td> </td>' ;
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '"></td>' ;
}
print '</tr>' ;
print '</form>' ;
2006-05-25 17:48:35 +02:00
*/
2006-04-04 02:12:45 +02:00
2006-05-25 17:48:35 +02:00
// R<> ductions absolues (Remises-Ristournes-Rabbais)
/* Les remises absolues doivent s ' appliquer par ajout de lignes sp<EFBFBD> cialis<EFBFBD> es
2006-04-04 02:12:45 +02:00
$var =! $var ;
2006-04-08 13:39:41 +02:00
print '<form name="updateligne" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2006-04-04 02:12:45 +02:00
print '<input type="hidden" name="action" value="setremiseabsolue">' ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<tr class="liste_total"><td>' ;
print $langs -> trans ( 'CustomerAbsoluteDiscount' );
2006-06-24 15:50:22 +02:00
if ( $fac -> brouillon ) print ' <font style="font-weight: normal">(' . ( $absolute_discount ? $langs -> trans ( " CompanyHasAbsoluteDiscount " , $absolute_discount , $langs -> trans ( " Currency " . $conf -> monnaie )) : $langs -> trans ( " CompanyHasNoAbsoluteDiscount " )) . ')</font>' ;
2006-04-04 02:12:45 +02:00
print '</td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td align="right"><font style="font-weight: normal">' ;
if ( $_GET [ 'action' ] == 'editabsolutediscount' )
{
print '-<input type="text" name="remise_absolue" size="2" value="' . $fac -> remise_absolue . '">' ;
}
else
{
print $fac -> remise_absolue ? '-' . price ( $fac -> remise_absolue ) : $langs -> trans ( " DiscountNone " );
}
print '</font></td>' ;
if ( $_GET [ 'action' ] != 'editabsolutediscount' )
{
if ( $fac -> brouillon && $user -> rights -> facture -> creer )
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editabsolutediscount&facid=' . $fac -> id . '">' . img_edit ( $langs -> trans ( 'SetAbsoluteDiscount' ), 1 ) . '</a></td>' ;
}
else
{
print '<td> </td>' ;
}
2006-04-04 02:27:02 +02:00
if ( $fac -> brouillon && $user -> rights -> facture -> creer && $fac -> remise_absolue )
{
2006-04-08 13:39:41 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=setremiseabsolue&rowid=' . $objp -> rowid . '">' ;
2006-04-04 02:27:02 +02:00
print img_delete ();
print '</a></td>' ;
}
else
{
print '<td> </td>' ;
}
2006-04-04 02:12:45 +02:00
print '<td> </td>' ;
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '"></td>' ;
}
print '</tr>' ;
print '</form>' ;
2006-05-25 17:48:35 +02:00
*/
2006-04-04 02:12:45 +02:00
2005-09-15 02:37:03 +02:00
/*
* Ajouter une ligne
*/
if ( $fac -> statut == 0 && $user -> rights -> facture -> creer && $_GET [ 'action' ] <> 'valid' )
{
print '<tr class="liste_titre">' ;
2006-07-17 18:49:33 +02:00
print '<td>' ;
print '<a name="add"></a>' ; // ancre
print $langs -> trans ( 'Description' ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2006-05-25 16:41:44 +02:00
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
2005-09-15 02:37:03 +02:00
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
2005-10-08 17:54:06 +02:00
print " </tr> \n " ;
// Ajout produit produits/services personalis<69> s
2006-07-17 18:49:33 +02:00
print '<form name="addligne" action="' . $_SERVER [ 'PHP_SELF' ] . '#add" method="post">' ;
2005-09-15 02:37:03 +02:00
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<input type="hidden" name="action" value="addligne">' ;
2005-10-08 17:54:06 +02:00
$var = true ;
2005-09-15 02:37:03 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2005-12-07 14:47:40 +01:00
print '<td colspan="1">' ;
2005-12-07 11:52:46 +01:00
print '<textarea name="desc" cols="70" rows="' . ROWS_2 . '"></textarea></td>' ;
print '<td align="right">' ;
2006-02-21 14:27:07 +01:00
if ( $soc -> tva_assuj == " 0 " )
print '<input type="hidden" name="tva_tx" value="0">0' ;
else
$html -> select_tva ( 'tva_tx' , $conf -> defaulttx , $mysoc , $soc );
2005-09-15 02:37:03 +02:00
print '</td>' ;
print '<td align="right"><input type="text" name="pu" size="6"></td>' ;
print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>' ;
2006-05-25 17:48:35 +02:00
print '<td align="right" nowrap><input type="text" name="remise_percent" size="1" value="' . $soc -> remise_client . '">%</td>' ;
2006-04-08 13:39:41 +02:00
print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"></td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
if ( $conf -> service -> enabled )
{
print '<tr ' . $bc [ $var ] . '>' ;
2005-12-07 17:13:23 +01:00
print '<td colspan="9">' . $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( '' , 'date_start' , 0 , 0 , 1 , " addligne " );
2005-12-07 17:13:23 +01:00
print ' ' . $langs -> trans ( 'to' ) . ' ' ;
2006-03-01 17:59:18 +01:00
print $html -> select_date ( '' , 'date_end' , 0 , 0 , 1 , " addligne " );
2005-09-15 02:37:03 +02:00
print '</td>' ;
print '</tr>' ;
}
print '</form>' ;
2005-10-08 17:54:06 +02:00
// Ajout de produits/services pr<70> d<EFBFBD> finis
if ( $conf -> produit -> enabled )
{
2006-07-17 18:49:33 +02:00
print '<form name="addligne_predef" action="' . $_SERVER [ 'PHP_SELF' ] . '#add" method="post">' ;
2005-10-08 17:54:06 +02:00
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
2006-03-14 01:53:54 +01:00
print '<input type="hidden" name="action" value="addligne_predef">' ;
2005-10-08 17:54:06 +02:00
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td colspan="2">' ;
2006-02-03 17:42:39 +01:00
// multiprix
if ( $conf -> global -> PRODUIT_MULTIPRICES == 1 )
$html -> select_produits ( '' , 'idprod' , '' , $conf -> produit -> limit_size , $soc -> price_level );
else
$html -> select_produits ( '' , 'idprod' , '' , $conf -> produit -> limit_size );
2006-06-16 02:33:04 +02:00
if ( ! $conf -> use_ajax ) print '<br>' ;
2005-10-10 22:55:21 +02:00
print '<textarea name="desc" cols="70" rows="' . ROWS_2 . '"></textarea></td>' ;
2005-10-08 17:54:06 +02:00
print '<td> </td>' ;
print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>' ;
2006-05-25 17:48:35 +02:00
print '<td align="right" nowrap><input type="text" name="remise_percent" size="1" value="' . $soc -> remise_client . '">%</td>' ;
2005-12-07 14:47:40 +01:00
print '<td align="center" valign="middle" rowspan="2" colspan="5"><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"></td>' ;
2005-10-08 17:54:06 +02:00
print '</tr>' ;
if ( $conf -> service -> enabled )
{
print '<tr ' . $bc [ $var ] . '>' ;
2005-12-07 17:13:23 +01:00
print '<td colspan="5">' . $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ;
2006-03-14 01:53:54 +01:00
print $html -> select_date ( '' , 'date_start_predef' , 0 , 0 , 1 , " addligne_predef " );
2005-12-07 17:13:23 +01:00
print ' ' . $langs -> trans ( 'to' ) . ' ' ;
2006-03-14 01:53:54 +01:00
print $html -> select_date ( '' , 'date_end_predef' , 0 , 0 , 1 , " addligne_predef " );
2005-10-08 17:54:06 +02:00
print '</td>' ;
print '</tr>' ;
}
print '</form>' ;
}
2006-03-25 15:21:30 +01:00
2005-09-15 02:37:03 +02:00
}
print " </table> \n " ;
print " </div> \n " ;
/*
* Boutons actions
*/
if ( $user -> societe_id == 0 && $_GET [ 'action' ] <> 'valid' && $_GET [ 'action' ] <> 'editline' )
{
print '<div class="tabsAction">' ;
2006-07-15 20:29:46 +02:00
2006-07-13 09:46:46 +02:00
// Editer une facture d<> j<EFBFBD> valid<69> e, sans paiement effectu<74> et pas export<72> en compta
2006-07-11 08:42:44 +02:00
if ( $fac -> statut == 1 )
{
2006-07-13 09:46:46 +02:00
// On v<> rifie si les lignes de factures ont <20> t<EFBFBD> export<72> es en compta et/ou ventil<69> es
2006-07-16 14:26:36 +02:00
$ventilExportCompta = $fac -> getVentilExportCompta ();
2006-07-15 20:29:46 +02:00
2006-07-11 08:42:44 +02:00
if ( $conf -> global -> FACTURE_ENABLE_EDITDELETE && $user -> rights -> facture -> modifier
2006-07-13 09:46:46 +02:00
&& ( $resteapayer == $fac -> total_ttc && $fac -> paye == 0 && $ventilExportCompta == 0 ))
2006-07-11 08:42:44 +02:00
{
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=modif">' . $langs -> trans ( 'Edit' ) . '</a>' ;
}
}
2006-07-15 20:29:46 +02:00
2006-05-01 03:08:16 +02:00
// R<> currente
2006-05-25 16:41:44 +02:00
if ( ! $conf -> global -> FACTURE_DISABLE_RECUR )
2006-05-01 03:08:16 +02:00
{
print ' <a class="butAction" href="facture/fiche-rec.php?facid=' . $fac -> id . '&action=create">' . $langs -> trans ( " ChangeIntoRepeatableInvoice " ) . '</a>' ;
}
2006-07-15 20:29:46 +02:00
2005-09-15 02:37:03 +02:00
// Valider
if ( $fac -> statut == 0 && $num_lignes > 0 )
{
if ( $user -> rights -> facture -> valider )
{
2006-04-08 13:39:41 +02:00
print ' <a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=valid">' . $langs -> trans ( 'Validate' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
}
}
else
{
// G<> n<EFBFBD> rer
2006-03-19 01:39:12 +01:00
if ( $fac -> statut == 1 && $user -> rights -> facture -> creer )
2005-09-15 02:37:03 +02:00
{
if ( $fac -> paye == 0 )
{
2006-04-08 13:39:41 +02:00
print ' <a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=builddoc">' . $langs -> trans ( 'BuildPDF' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
}
else
{
2006-04-08 13:39:41 +02:00
print ' <a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=builddoc">' . $langs -> trans ( 'RebuildPDF' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
}
}
}
2006-07-15 20:29:46 +02:00
// On v<> rifie si la facture est supprimable. Si oui, on propose bouton supprimer
2006-07-20 10:57:10 +02:00
if ( $fac -> statut == 0 && $fac -> is_erasable () && $user -> rights -> facture -> supprimer && $_GET [ 'action' ] != 'delete' )
2006-07-15 20:29:46 +02:00
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $fac -> id . '&action=delete">' . $langs -> trans ( 'Delete' ) . '</a>' ;
}
2005-09-15 02:37:03 +02:00
// Envoyer
if ( $fac -> statut == 1 && $user -> rights -> facture -> envoyer )
{
2006-07-01 01:38:12 +02:00
print ' <a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=presend">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
}
2006-07-15 20:29:46 +02:00
2005-09-15 02:37:03 +02:00
// Envoyer une relance
if ( $fac -> statut == 1 && price ( $resteapayer ) > 0 && $user -> rights -> facture -> envoyer )
{
2006-07-01 01:38:12 +02:00
print ' <a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=prerelance">' . $langs -> trans ( 'SendRemindByMail' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
}
2006-07-15 20:29:46 +02:00
2005-09-15 02:37:03 +02:00
// Emettre paiement
if ( $fac -> statut == 1 && $fac -> paye == 0 && $user -> rights -> facture -> paiement )
{
print ' <a class="butAction" href="paiement.php?facid=' . $fac -> id . '&action=create">' . $langs -> trans ( 'DoPaiement' ) . '</a>' ;
}
2006-07-15 20:29:46 +02:00
2005-09-15 02:37:03 +02:00
// Classer 'pay<61> '
2006-07-15 20:29:46 +02:00
if ( $fac -> statut == 1 && $fac -> paye == 0 && $user -> rights -> facture -> paiement
&& price ( $resteapayer ) <= 0 )
2005-09-15 02:37:03 +02:00
{
print ' <a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=payed">' . $langs -> trans ( 'ClassifyPayed' ) . '</a>' ;
}
2006-07-15 20:29:46 +02:00
// Classer 'ferm<72> e' (possible si valid<69> e et pas encore classer pay<61> e)
if ( $fac -> statut == 1 && $fac -> paye == 0 && $user -> rights -> facture -> paiement
&& price ( $resteapayer ) > 0 )
2005-09-15 02:37:03 +02:00
{
2006-07-15 20:29:46 +02:00
if ( $totalpaye > 0 )
{
print ' <a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=canceled">' . $langs -> trans ( 'ClassifyPayedPartially' ) . '</a>' ;
}
else
{
print ' <a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id . '&action=canceled">' . $langs -> trans ( 'ClassifyCanceled' ) . '</a>' ;
2005-09-15 02:37:03 +02:00
2006-07-15 20:29:46 +02:00
// \todo
// Ajouter bouton "Annuler et Cr<43> er facture remplacement"
}
}
2005-09-15 02:37:03 +02:00
print '</div>' ;
}
print '<table width="100%"><tr><td width="50%" valign="top">' ;
2006-07-18 09:54:58 +02:00
print '<a name="builddoc"></a>' ; // ancre
2005-09-15 02:37:03 +02:00
/*
* Documents g<EFBFBD> n<EFBFBD> r<EFBFBD> s
*/
$filename = sanitize_string ( $fac -> ref );
$filedir = $conf -> facture -> dir_output . '/' . sanitize_string ( $fac -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?facid=' . $fac -> id ;
2006-06-27 13:40:14 +02:00
$genallowed = ( $fac -> statut == 1 && $user -> rights -> facture -> creer );
$delallowed = $user -> rights -> facture -> supprimer ;
2005-09-15 02:37:03 +02:00
$var = true ;
print '<br>' ;
2006-06-02 18:54:06 +02:00
$somethingshown = $html -> show_documents ( 'facture' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $fac -> modelpdf );
2005-09-15 02:37:03 +02:00
/*
2005-10-02 21:20:21 +02:00
* Propales rattach<EFBFBD> es
2005-09-15 02:37:03 +02:00
*/
$sql = 'SELECT ' . $db -> pdate ( 'p.datep' ) . ' as dp, p.price, p.ref, p.rowid as propalid' ;
2006-06-01 19:57:42 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'propal as p' ;
if ( ! $conf -> commande -> enabled )
{
$sql .= " , " . MAIN_DB_PREFIX . " fa_pr as fp " ;
$sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = " . $fac -> id ;
}
else
{
$sql .= " , " . MAIN_DB_PREFIX . " co_pr as cp, " . MAIN_DB_PREFIX . " co_fa as cf " ;
2006-06-01 20:05:21 +02:00
$sql .= " WHERE cf.fk_facture = " . $fac -> id . " AND cf.fk_commande = cp.fk_commande AND cp.fk_propale = p.rowid " ;
2006-06-01 19:57:42 +02:00
}
2005-09-15 02:37:03 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
$i = 0 ; $total = 0 ;
2006-05-01 01:59:46 +02:00
if ( $somethingshown ) print '<br>' ;
$somethingshown = 1 ;
2005-09-15 02:37:03 +02:00
print_titre ( $langs -> trans ( 'RelatedCommercialProposals' ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Ref' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Price' ) . '</td>' ;
print '</tr>' ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td><a href="propal.php?propalid=' . $objp -> propalid . '">' . img_object ( $langs -> trans ( 'ShowPropal' ), 'propal' ) . ' ' . $objp -> ref . '</a></td>' ;
print '<td>' . dolibarr_print_date ( $objp -> dp ) . '</td>' ;
print '<td align="right">' . price ( $objp -> price ) . '</td>' ;
print '</tr>' ;
$total = $total + $objp -> price ;
$i ++ ;
}
print '<tr class="liste_total"><td> </td><td align="left">' . $langs -> trans ( 'TotalHT' ) . '</td><td align="right">' . price ( $total ) . '</td></tr>' ;
print '</table>' ;
}
}
else
{
dolibarr_print_error ( $db );
}
2005-09-27 20:10:12 +02:00
/*
* Commandes rattach<EFBFBD> es
*/
if ( $conf -> commande -> enabled )
{
$sql = 'SELECT ' . $db -> pdate ( 'c.date_commande' ) . ' as date_commande, c.total_ht, c.ref, c.ref_client, c.rowid as id' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'commande as c, ' . MAIN_DB_PREFIX . 'co_fa as co_fa WHERE co_fa.fk_commande = c.rowid AND co_fa.fk_facture = ' . $fac -> id ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
$i = 0 ; $total = 0 ;
2006-05-01 01:59:46 +02:00
if ( $somethingshown ) print '<br>' ;
$somethingshown = 1 ;
2005-09-27 20:10:12 +02:00
print_titre ( $langs -> trans ( 'RelatedOrders' ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Ref' ) . '</td>' ;
2006-06-23 19:15:01 +02:00
print '<td>' . $langs -> trans ( 'RefCustomerOrderShort' ) . '</td>' ;
2005-09-27 20:10:12 +02:00
print '<td align="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '</tr>' ;
$var = true ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '><td>' ;
print '<a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $objp -> id . '">' . img_object ( $langs -> trans ( 'ShowOrder' ), 'order' ) . ' ' . $objp -> ref . " </a></td> \n " ;
2006-06-17 01:55:20 +02:00
print '<td>' . $objp -> ref_client . '</td>' ;
2005-09-27 20:10:12 +02:00
print '<td align="center">' . dolibarr_print_date ( $objp -> date_commande ) . '</td>' ;
print '<td align="right">' . price ( $objp -> total_ht ) . '</td>' ;
print " </tr> \n " ;
$total = $total + $objp -> total_ht ;
$i ++ ;
}
2005-10-10 22:55:21 +02:00
print '<tr class="liste_total">' ;
print '<td align="left">' . $langs -> trans ( 'TotalHT' ) . '</td>' ;
2006-06-01 19:57:42 +02:00
print '<td> </td>' ;
print '<td> </td>' ;
2005-10-10 22:55:21 +02:00
print '<td align="right">' . price ( $total ) . '</td></tr>' ;
2005-09-27 20:10:12 +02:00
print '</table>' ;
}
}
else
{
dolibarr_print_error ( $db );
}
}
2005-10-02 21:20:21 +02:00
2005-09-15 02:37:03 +02:00
print '</td><td valign="top" width="50%">' ;
/*
* Liste des actions propres <EFBFBD> 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 '<br>' ;
print_titre ( $langs -> trans ( 'ActionsOnBill' ));
$i = 0 ; $total = 0 ;
print '<table class="border" width="100%">' ;
print '<tr ' . $bc [ $var ] . '><td>' . $langs -> trans ( 'Ref' ) . '</td><td>' . $langs -> trans ( 'Date' ) . '</td><td>' . $langs -> trans ( 'Action' ) . '</td><td>' . $langs -> trans ( 'By' ) . '</td></tr>' ;
print " \n " ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td><a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?id=' . $objp -> id . '">' . img_object ( $langs -> trans ( 'ShowTask' ), 'task' ) . ' ' . $objp -> id . '</a></td>' ;
print '<td>' . dolibarr_print_date ( $objp -> da ) . '</td>' ;
print '<td>' . stripslashes ( $objp -> label ) . '</td>' ;
print '<td>' . $objp -> code . '</td>' ;
print '</tr>' ;
$i ++ ;
}
print '</table>' ;
}
}
else
{
dolibarr_print_error ( $db );
}
print '</td></tr></table>' ;
/*
* Affiche formulaire mail
*/
if ( $_GET [ 'action' ] == 'presend' )
{
2006-05-05 00:58:14 +02:00
$facref = sanitize_string ( $fac -> ref );
$file = $conf -> facture -> dir_output . '/' . $facref . '/' . $facref . '.pdf' ;
// Construit PDF si non existant
if ( ! is_readable ( $file ))
{
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-07-02 15:45:06 +02:00
$result = facture_pdf_create ( $db , $fac -> id , '' , $_REQUEST [ 'model' ], $outputlangs );
2006-05-05 00:58:14 +02:00
if ( $result <= 0 )
{
dolibarr_print_error ( $db , $result );
exit ;
}
}
2005-09-15 02:37:03 +02:00
print '<br>' ;
print_titre ( $langs -> trans ( 'SendBillByMail' ));
$liste [ 0 ] = ' ' ;
foreach ( $soc -> contact_email_array () as $key => $value )
{
$liste [ $key ] = $value ;
}
// Cr<43> <72> 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 ;
2006-06-26 17:15:51 +02:00
$formmail -> withdeliveryreceipt = 1 ;
2005-09-15 02:37:03 +02:00
// Tableau des substitutions
$formmail -> substit [ '__FACREF__' ] = $fac -> ref ;
// Tableau des param<61> tres compl<70> 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 '<br>' ;
}
if ( $_GET [ 'action' ] == 'prerelance' )
{
2006-05-05 00:58:14 +02:00
$facref = sanitize_string ( $fac -> ref );
$file = $conf -> facture -> dir_output . '/' . $facref . '/' . $facref . '.pdf' ;
// Construit PDF si non existant
if ( ! is_readable ( $file ))
{
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-07-02 15:45:06 +02:00
$result = facture_pdf_create ( $db , $fac -> id , '' , $_REQUEST [ 'model' ], $outputlangs );
2006-05-05 00:58:14 +02:00
if ( $result <= 0 )
{
dolibarr_print_error ( $db , $result );
exit ;
}
}
2005-09-15 02:37:03 +02:00
print '<br>' ;
print_titre ( $langs -> trans ( 'SendReminderBillByMail' ));
$liste [ 0 ] = ' ' ;
foreach ( $soc -> contact_email_array () as $key => $value )
{
$liste [ $key ] = $value ;
}
// Cr<43> <72> 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 ( 'SendReminderBillRef' , '__FACREF__' );
$formmail -> withfile = 1 ;
$formmail -> withbody = 1 ;
2006-06-26 17:15:51 +02:00
$formmail -> withdeliveryreceipt = 1 ;
2005-09-15 02:37:03 +02:00
// Tableau des substitutions
$formmail -> substit [ '__FACREF__' ] = $fac -> ref ;
// Tableau des param<61> tres compl<70> 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 '<br>' ;
}
}
else
{
dolibarr_print_error ( $db , $fac -> error );
}
}
else
{
/***************************************************************************
* *
* Mode Liste *
* *
***************************************************************************/
$page = $_GET [ 'page' ];
$sortorder = $_GET [ 'sortorder' ];
$sortfield = $_GET [ 'sortfield' ];
$month = $_GET [ 'month' ];
$year = $_GET [ 'year' ];
2006-03-19 01:39:12 +01:00
$facturestatic = new Facture ( $db );
2005-09-15 02:37:03 +02:00
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' ;
if ( ! $sall ) $sql .= ' ,sum(pf.amount) as am' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
$sql .= ',' . MAIN_DB_PREFIX . 'facture as f' ;
if ( ! $sall ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiement_facture as pf ON f.rowid=pf.fk_facture ' ;
if ( $sall ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facturedet as fd ON f.rowid=fd.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' ])
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND f.facnumber like \'%' . addslashes ( $_GET [ 'search_ref' ]) . '%\'' ;
2005-09-15 02:37:03 +02:00
}
if ( $_GET [ 'search_societe' ])
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND s.nom like \'%' . addslashes ( $_GET [ 'search_societe' ]) . '%\'' ;
2005-09-15 02:37:03 +02:00
}
if ( $_GET [ 'search_montant_ht' ])
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND f.total = \'' . addslashes ( $_GET [ 'search_montant_ht' ]) . '\'' ;
2005-09-15 02:37:03 +02:00
}
if ( $_GET [ 'search_montant_ttc' ])
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND f.total_ttc = \'' . addslashes ( $_GET [ 'search_montant_ttc' ]) . '\'' ;
2005-09-15 02:37:03 +02:00
}
if ( $year > 0 )
{
$sql .= ' AND date_format(f.datef, \'%Y\') = ' . $year ;
}
if ( $_POST [ 'sf_ref' ])
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND f.facnumber like \'%' . addslashes ( $_POST [ 'sf_ref' ]) . '%\'' ;
2005-09-15 02:37:03 +02:00
}
if ( $sall )
{
2006-02-25 01:43:24 +01:00
$sql .= ' AND (s.nom like \'%' . addslashes ( $sall ) . '%\' OR f.facnumber like \'%' . addslashes ( $sall ) . '%\' OR f.note like \'%' . addslashes ( $sall ) . '%\' OR fd.description like \'%' . addslashes ( $sall ) . '%\')' ;
2005-09-15 02:37:03 +02:00
}
$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 '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
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 );
2006-03-19 01:39:12 +01:00
print_liste_field_titre ( $langs -> trans ( 'Status' ), $_SERVER [ 'PHP_SELF' ], 'fk_statut,paye,am' , '' , '&socidp=' . $socidp , 'align="right"' , $sortfield );
2005-09-15 02:37:03 +02:00
print '</tr>' ;
// Lignes des champs de filtre
2006-04-08 13:39:41 +02:00
print '<form method="get" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2005-09-15 02:37:03 +02:00
print '<tr class="liste_titre">' ;
print '<td class="liste_titre" valign="right">' ;
print '<input class="flat" size="10" type="text" name="search_ref" value="' . $_GET [ 'search_ref' ] . '">' ;
print '</td><td class="liste_titre"> </td>' ;
print '<td class="liste_titre" align="left">' ;
print '<input class="flat" type="text" name="search_societe" value="' . $_GET [ 'search_societe' ] . '">' ;
print '</td><td class="liste_titre" align="right">' ;
print '<input class="flat" type="text" size="10" name="search_montant_ht" value="' . $_GET [ 'search_montant_ht' ] . '">' ;
print '</td><td class="liste_titre" align="right">' ;
print '<input class="flat" type="text" size="10" name="search_montant_ttc" value="' . $_GET [ 'search_montant_ttc' ] . '">' ;
print '</td><td class="liste_titre" colspan="2" align="right">' ;
print '<input type="image" class="liste_titre" name="button_search" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/search.png" alt="' . $langs -> trans ( 'Search' ) . '">' ;
print '</td>' ;
print '</tr>' ;
print '</form>' ;
if ( $num > 0 )
{
$var = True ;
$total = 0 ;
$totalrecu = 0 ;
while ( $i < min ( $num , $limit ))
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2006-04-08 13:39:41 +02:00
print '<td nowrap="nowrap"><a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $objp -> facid . '">' . img_object ( $langs -> trans ( 'ShowBill' ), 'bill' ) . '</a> ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $objp -> facid . '">' . $objp -> facnumber . '</a>' . $objp -> increment ;
2005-09-15 02:37:03 +02:00
if ( $objp -> datelimite < ( time () - $conf -> facture -> client -> warning_delay ) && ! $objp -> paye && $objp -> fk_statut == 1 && ! $objp -> am ) print img_warning ( $langs -> trans ( 'Late' ));
print '</td>' ;
if ( $objp -> df > 0 )
{
print '<td align="center" nowrap>' ;
$y = strftime ( '%Y' , $objp -> df );
$m = strftime ( '%m' , $objp -> df );
print strftime ( '%d' , $objp -> df );
2006-04-08 13:39:41 +02:00
print ' <a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $y . '&month=' . $m . '">' ;
2005-09-15 02:37:03 +02:00
print substr ( strftime ( '%B' , $objp -> df ), 0 , 3 ) . '</a>' ;
2006-04-08 13:39:41 +02:00
print ' <a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $y . '">' ;
2005-09-15 02:37:03 +02:00
print strftime ( '%Y' , $objp -> df ) . '</a></td>' ;
}
else
{
print '<td align="center"><b>!!!</b></td>' ;
}
2006-07-02 18:19:57 +02:00
print '<td><a href="fiche.php?socid=' . $objp -> idp . '">' . img_object ( $langs -> trans ( 'ShowCompany' ), 'company' ) . ' ' . dolibarr_trunc ( $objp -> nom , 48 ) . '</a></td>' ;
2005-09-15 02:37:03 +02:00
print '<td align="right">' . price ( $objp -> total ) . '</td>' ;
print '<td align="right">' . price ( $objp -> total_ttc ) . '</td>' ;
print '<td align="right">' . price ( $objp -> am ) . '</td>' ;
// Affiche statut de la facture
2006-03-19 01:39:12 +01:00
print '<td align="right" nowrap="nowrap">' ;
print $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 5 , $objp -> am );
print '</td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
$total += $objp -> total ;
$total_ttc += $objp -> total_ttc ;
$totalrecu += $objp -> am ;
$i ++ ;
}
if (( $offset + $num ) <= $limit )
{
// Print total
print '<tr class="liste_total">' ;
print '<td class="liste_total" colspan="3" align="left">' . $langs -> trans ( 'Total' ) . '</td>' ;
print '<td class="liste_total" align="right">' . price ( $total ) . '</td>' ;
print '<td class="liste_total" align="right">' . price ( $total_ttc ) . '</td>' ;
print '<td class="liste_total" align="right">' . price ( $totalrecu ) . '</td>' ;
print '<td class="liste_total" align="center"> </td>' ;
print '</tr>' ;
}
}
print '</table>' ;
$db -> free ( $resql );
}
else
{
dolibarr_print_error ( $db );
}
}
}
2005-08-20 21:02:26 +02:00
}
$db -> close ();
llxFooter ( '$Date$ - $Revision$' );
?>