2008-08-12 20:20:18 +02:00
< ? php
/* Copyright ( C ) 2002 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2010-02-08 13:48:32 +01:00
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2008-08-12 20:20:18 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2011-01-28 12:42:59 +01:00
* Copyright ( C ) 2005 - 2011 Regis Houssin < regis @ dolibarr . fr >
2008-08-12 20:20:18 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2010-04-24 18:00:48 +02:00
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2008-08-12 20:20:18 +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 .
*/
/**
* \file htdocs / compta / facture . php
* \ingroup facture
2010-08-09 19:16:26 +02:00
* \brief Page to create / see an invoice
2008-08-12 20:20:18 +02:00
* \version $Id $
*/
2010-03-27 15:40:39 +01:00
require ( '../main.inc.php' );
2010-05-03 10:43:32 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /core/class/html.formfile.class.php " );
2008-08-12 20:20:18 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/includes/modules/facture/modules_facture.php' );
2010-04-25 16:17:39 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' );
2010-04-28 12:02:54 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' );
2010-04-25 10:47:08 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' );
2009-01-07 11:57:36 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/functions2.lib.php " );
2008-08-12 20:20:18 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/lib/invoice.lib.php' );
2010-05-01 17:33:00 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/date.lib.php " );
2010-04-29 16:34:21 +02:00
if ( $conf -> projet -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' );
2008-08-12 20:20:18 +02:00
if ( $conf -> projet -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/lib/project.lib.php' );
$langs -> load ( 'bills' );
2010-09-12 20:01:29 +02:00
//print 'ee'.$langs->trans('BillsCustomer');exit;
2008-08-12 20:20:18 +02:00
$langs -> load ( 'companies' );
$langs -> load ( 'products' );
$langs -> load ( 'main' );
2010-12-01 23:14:15 +01:00
if ( GETPOST ( 'mesg' , 'int' , 1 ) && isset ( $_SESSION [ 'message' ])) $mesg = $_SESSION [ 'message' ];
2008-08-12 20:20:18 +02:00
$sall = isset ( $_GET [ 'sall' ]) ? trim ( $_GET [ 'sall' ]) : trim ( $_POST [ 'sall' ]);
2010-03-11 15:31:16 +01:00
$projectid = isset ( $_GET [ 'projectid' ]) ? $_GET [ 'projectid' ] : 0 ;
2008-08-12 20:20:18 +02:00
// Security check
2011-01-29 18:26:52 +01:00
$socid = GETPOST ( " socid " );
2010-12-14 00:38:47 +01:00
$facid = GETPOST ( " id " );
if ( empty ( $facid )) $facid = GETPOST ( " facid " ); // For backward compatibility
$ref = GETPOST ( " ref " );
2009-11-28 13:06:11 +01:00
$fieldid = isset ( $_GET [ " ref " ]) ? 'facnumber' : 'rowid' ;
2008-08-12 20:20:18 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2009-11-28 13:06:11 +01:00
$result = restrictedArea ( $user , 'facture' , $facid , '' , '' , 'fk_soc' , $fieldid );
2008-08-12 20:20:18 +02:00
2009-11-28 13:06:11 +01:00
// Nombre de ligne pour choix de produit/service predefinis
2008-08-12 20:20:18 +02:00
$NBLINES = 4 ;
2008-10-02 00:24:31 +02:00
$usehm = $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ;
2010-09-09 18:02:55 +02:00
$object = new Facture ( $db );
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
// Instantiate hooks of thirdparty module
if ( is_array ( $conf -> hooks_modules ) && ! empty ( $conf -> hooks_modules ))
{
$object -> callHooks ( 'objectcard' );
}
2009-02-27 19:35:17 +01:00
2010-09-12 20:01:29 +02:00
2008-08-12 20:20:18 +02:00
/******************************************************************************/
/* Actions */
/******************************************************************************/
2010-09-09 18:02:55 +02:00
// Hook of thirdparty module
if ( ! empty ( $object -> hooks ))
{
foreach ( $object -> hooks as $module )
{
$module -> doActions ( $object );
$mesg = $module -> error ;
}
}
2008-11-20 22:30:23 +01:00
// Action clone object
2009-05-06 19:09:45 +02:00
if ( $_REQUEST [ " action " ] == 'confirm_clone' && $_REQUEST [ 'confirm' ] == 'yes' )
2008-11-20 22:30:23 +01:00
{
if ( 1 == 0 && empty ( $_REQUEST [ " clone_content " ]) && empty ( $_REQUEST [ " clone_receivers " ]))
{
$mesg = '<div class="error">' . $langs -> trans ( " NoCloneOptionsSpecified " ) . '</div>' ;
}
else
{
2010-08-09 19:16:26 +02:00
$result = $object -> createFromClone ( $facid );
2008-11-20 22:30:23 +01:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $result );
exit ;
}
else
{
$mesg = $object -> error ;
$_GET [ 'action' ] = '' ;
}
}
}
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] == 'reopen' && $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$result = $object -> fetch ( $facid );
if ( $object -> statut == 2
|| ( $object -> statut == 3 && $object -> close_code != 'replaced' ))
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$result = $object -> set_unpaid ( $user );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
2010-08-09 19:16:26 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid );
2008-08-12 20:20:18 +02:00
exit ;
}
else
{
2010-09-09 18:02:55 +02:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
}
}
// Suppression de la facture
2009-05-06 17:45:50 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_delete' && $_REQUEST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> supprimer )
2008-08-12 20:20:18 +02:00
{
if ( $user -> rights -> facture -> supprimer )
{
2010-09-09 18:02:55 +02:00
$result = $object -> fetch ( $facid );
$result = $object -> delete ();
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ]);
exit ;
}
else
{
2010-09-09 18:02:55 +02:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
}
}
/*
* Supprime une ligne produit AVEC ou SANS confirmation
*/
2010-09-10 16:35:07 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_deleteline' && $_REQUEST [ 'confirm' ] == 'yes' )
2008-08-12 20:20:18 +02:00
{
if ( $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
2010-02-27 14:37:13 +01:00
2010-09-10 16:35:07 +02:00
$result = $object -> deleteline ( $_GET [ 'lineid' ], $user );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
2010-02-27 14:37:13 +01:00
// Define output language
2008-10-29 00:36:36 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-08-12 20:20:18 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
$result = facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
2010-08-09 19:16:26 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid );
2008-08-12 20:20:18 +02:00
exit ;
}
}
else
{
2010-09-09 18:02:55 +02:00
$mesg = '<div clas="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
$_GET [ 'action' ] = '' ;
}
}
}
// Supprime affectation d'un avoir a la facture
if ( $_GET [ 'action' ] == 'unlinkdiscount' )
{
if ( $user -> rights -> facture -> creer )
{
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( $_GET [ " discountid " ]);
$discount -> unlink_invoice ();
}
}
// Validation
if ( $_GET [ 'action' ] == 'valid' )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
2008-08-12 20:20:18 +02:00
// On verifie signe facture
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 )
2008-08-12 20:20:18 +02:00
{
2009-12-22 23:10:25 +01:00
// Si avoir, le signe doit etre negatif
2010-09-09 18:02:55 +02:00
if ( $object -> total_ht >= 0 )
2008-08-12 20:20:18 +02:00
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorInvoiceAvoirMustBeNegative " ) . '</div>' ;
$_GET [ 'action' ] = '' ;
}
}
else
{
// Si non avoir, le signe doit etre positif
2010-09-09 18:02:55 +02:00
if ( $object -> total_ht < 0 )
2008-08-12 20:20:18 +02:00
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorInvoiceOfThisTypeMustBePositive " ) . '</div>' ;
$_GET [ 'action' ] = '' ;
}
}
}
if ( $_POST [ 'action' ] == 'classin' )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> setProject ( $_POST [ 'projectid' ]);
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'action' ] == 'setmode' )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$result = $object -> mode_reglement ( $_POST [ 'mode_reglement_id' ]);
if ( $result < 0 ) dol_print_error ( $object -> db , $object -> error );
2008-08-12 20:20:18 +02:00
}
2009-01-02 17:08:15 +01:00
if ( $_POST [ 'action' ] == 'setinvoicedate' )
2008-11-20 22:30:23 +01:00
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> date = dol_mktime ( 12 , 0 , 0 , $_POST [ 'invoicedatemonth' ], $_POST [ 'invoicedateday' ], $_POST [ 'invoicedateyear' ]);
2010-09-21 00:11:58 +02:00
if ( $object -> date_lim_reglement < $object -> date ) $object -> date_lim_reglement = $object -> date ;
2010-09-09 18:02:55 +02:00
$result = $object -> update ( $user );
if ( $result < 0 ) dol_print_error ( $object -> db , $object -> error );
2009-01-02 17:08:15 +01:00
}
2010-09-21 00:11:58 +02:00
if ( $_POST [ 'action' ] == 'setpaymentterm' )
{
$object -> fetch ( $facid );
$date_lim_reglement = dol_mktime ( 12 , 0 , 0 , $_POST [ 'paymenttermmonth' ], $_POST [ 'paymenttermday' ], $_POST [ 'paymenttermyear' ]);
$result = $object -> cond_reglement ( $object -> cond_reglement_id , $date_lim_reglement );
if ( $result < 0 ) dol_print_error ( $object -> db , $object -> error );
}
2009-01-02 17:08:15 +01:00
if ( $_POST [ 'action' ] == 'setconditions' )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$result = $object -> cond_reglement ( $_POST [ 'cond_reglement_id' ]);
if ( $result < 0 ) dol_print_error ( $object -> db , $object -> error );
2008-11-20 22:30:23 +01:00
}
2008-08-12 20:20:18 +02:00
if ( $_REQUEST [ 'action' ] == 'setremisepercent' && $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$result = $object -> set_remise ( $user , $_POST [ 'remise_percent' ]);
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'action' ] == " setabsolutediscount " && $user -> rights -> facture -> creer )
{
// POST[remise_id] ou POST[remise_id_for_payment]
if ( ! empty ( $_POST [ " remise_id " ]))
{
2010-09-09 18:02:55 +02:00
$ret = $object -> fetch ( $facid );
2008-08-12 20:20:18 +02:00
if ( $ret > 0 )
{
2010-09-09 18:02:55 +02:00
$result = $object -> insert_discount ( $_POST [ " remise_id " ]);
2008-08-12 20:20:18 +02:00
if ( $result < 0 )
{
2010-09-09 18:02:55 +02:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
}
else
{
2010-09-09 18:02:55 +02:00
dol_print_error ( $db , $object -> error );
2008-08-12 20:20:18 +02:00
}
}
if ( ! empty ( $_POST [ " remise_id_for_payment " ]))
{
2010-06-01 23:33:48 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' );
2008-08-12 20:20:18 +02:00
$discount = new DiscountAbsolute ( $db );
$discount -> fetch ( $_POST [ " remise_id_for_payment " ]);
2010-08-09 19:16:26 +02:00
$result = $discount -> link_to_invoice ( 0 , $facid );
2008-08-12 20:20:18 +02:00
if ( $result < 0 )
{
$mesg = '<div class="error">' . $discount -> error . '</div>' ;
}
}
}
if ( $_POST [ 'action' ] == 'set_ref_client' )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> set_ref_client ( $_POST [ 'ref_client' ]);
2008-08-12 20:20:18 +02:00
}
2009-03-09 19:40:16 +01:00
// Classify to validated
2008-08-12 20:20:18 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_valid' && $_REQUEST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> valider )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$result = $object -> validate ( $user );
2008-08-12 20:20:18 +02:00
if ( $result >= 0 )
{
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
}
2010-07-15 22:48:40 +02:00
// Repasse la facture en mode brouillon (unvalidate)
if ( $_GET [ 'action' ] == 'modif' && $user -> rights -> facture -> unvalidate )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
2009-09-11 17:43:16 +02:00
// On verifie si la facture a des paiements
2008-08-12 20:20:18 +02:00
$sql = 'SELECT pf.amount' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf' ;
2010-09-09 18:02:55 +02:00
$sql .= ' WHERE pf.fk_facture = ' . $object -> id ;
2008-08-12 20:20:18 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$i = 0 ;
$num = $db -> num_rows ( $result );
while ( $i < $num )
{
2010-02-24 16:40:29 +01:00
$objp = $db -> fetch_object ( $result );
$totalpaye += $objp -> amount ;
$i ++ ;
2008-08-12 20:20:18 +02:00
}
}
2010-02-24 16:40:29 +01:00
else
{
dol_print_error ( $db , '' );
}
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$resteapayer = $object -> total_ttc - $totalpaye ;
2008-08-12 20:20:18 +02:00
2009-08-29 17:09:12 +02:00
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
2010-09-09 18:57:53 +02:00
$ventilExportCompta = $object -> getVentilExportCompta ();
2008-08-12 20:20:18 +02:00
2009-08-29 17:09:12 +02:00
// On verifie si aucun paiement n'a ete effectue
2010-09-09 18:02:55 +02:00
if ( $resteapayer == $object -> total_ttc && $object -> paye == 0 && $ventilExportCompta == 0 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$object -> set_draft ( $user );
2008-10-29 00:36:36 +01:00
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2008-08-12 20:20:18 +02:00
}
}
2009-08-29 17:09:12 +02:00
// Classify "paid"
2009-08-19 19:16:47 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_paid' && $_REQUEST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> paiement )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$result = $object -> set_paid ( $user );
2008-08-12 20:20:18 +02:00
}
2009-08-29 17:09:12 +02:00
// Classif "paid partialy"
2009-08-19 19:16:47 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_paid_partially' && $_REQUEST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> paiement )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
2008-08-12 20:20:18 +02:00
$close_code = $_POST [ " close_code " ];
$close_note = $_POST [ " close_note " ];
if ( $close_code )
{
2010-09-09 18:02:55 +02:00
$result = $object -> set_paid ( $user , $close_code , $close_note );
2008-08-12 20:20:18 +02:00
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Reason " )) . '</div>' ;
}
}
2009-08-29 17:09:12 +02:00
// Classify "abandoned"
2009-05-06 19:09:45 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_canceled' && $_REQUEST [ 'confirm' ] == 'yes' )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
2008-08-12 20:20:18 +02:00
$close_code = $_POST [ " close_code " ];
$close_note = $_POST [ " close_note " ];
if ( $close_code )
{
2010-09-09 18:02:55 +02:00
$result = $object -> set_canceled ( $user , $close_code , $close_note );
2008-08-12 20:20:18 +02:00
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Reason " )) . '</div>' ;
}
}
// Convertir en reduc
2009-05-06 19:09:45 +02:00
if ( $_REQUEST [ 'action' ] == 'confirm_converttoreduc' && $_REQUEST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> creer )
2008-08-12 20:20:18 +02:00
{
$db -> begin ();
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
$object -> fetch_lines ();
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
if ( ! $object -> paye ) // protection against multiple submit
2008-08-12 20:20:18 +02:00
{
// Boucle sur chaque taux de tva
$i = 0 ;
2010-09-09 18:02:55 +02:00
foreach ( $object -> lines as $line )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$amount_ht [ $line -> tva_tx ] += $line -> total_ht ;
$amount_tva [ $line -> tva_tx ] += $line -> total_tva ;
$amount_ttc [ $line -> tva_tx ] += $line -> total_ttc ;
2008-08-12 20:20:18 +02:00
$i ++ ;
}
2009-02-24 03:41:21 +01:00
// Insert one discount by VAT rate category
2008-08-12 20:20:18 +02:00
$discount = new DiscountAbsolute ( $db );
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 ) $discount -> description = '(CREDIT_NOTE)' ;
elseif ( $object -> type == 3 ) $discount -> description = '(DEPOSIT)' ;
2009-02-24 03:41:21 +01:00
else {
$this -> error = " CantConvertToReducAnInvoiceOfThisType " ;
return - 1 ;
}
2010-09-09 18:02:55 +02:00
$discount -> tva_tx = abs ( $object -> total_ttc );
$discount -> fk_soc = $object -> socid ;
$discount -> fk_facture_source = $object -> id ;
2008-08-12 20:20:18 +02:00
$error = 0 ;
foreach ( $amount_ht as $tva_tx => $xxx )
{
$discount -> amount_ht = abs ( $amount_ht [ $tva_tx ]);
$discount -> amount_tva = abs ( $amount_tva [ $tva_tx ]);
$discount -> amount_ttc = abs ( $amount_ttc [ $tva_tx ]);
$discount -> tva_tx = abs ( $tva_tx );
$result = $discount -> create ( $user );
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
if ( ! $error )
{
// Classe facture
2010-09-09 18:02:55 +02:00
$result = $object -> set_paid ( $user );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
//$mesg='OK'.$discount->id;
$db -> commit ();
}
else
{
2010-09-09 18:02:55 +02:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
$db -> rollback ();
}
}
else
{
$mesg = '<div class="error">' . $discount -> error . '</div>' ;
$db -> rollback ();
}
}
}
/*
2009-05-27 03:48:31 +02:00
* Insert new invoice in database
2008-08-12 20:20:18 +02:00
*/
if ( $_POST [ 'action' ] == 'add' && $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$object -> socid = $_POST [ 'socid' ];
2008-08-12 20:20:18 +02:00
$db -> begin ();
2010-05-07 20:36:54 +02:00
2008-11-20 22:30:23 +01:00
// Replacement invoice
2008-08-12 20:20:18 +02:00
if ( $_POST [ 'type' ] == 1 )
{
2009-02-20 23:53:15 +01:00
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2008-08-12 20:20:18 +02:00
if ( empty ( $datefacture ))
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Date " )) . '</div>' ;
}
if ( ! ( $_POST [ 'fac_replacement' ] > 0 ))
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " ReplaceInvoice " )) . '</div>' ;
}
if ( ! $error )
{
2008-11-20 22:30:23 +01:00
// This is a replacement invoice
2010-09-09 18:02:55 +02:00
$result = $object -> fetch ( $_POST [ 'fac_replacement' ]);
$object -> fetch_thirdparty ();
$object -> date = $datefacture ;
$object -> note_public = trim ( $_POST [ 'note_public' ]);
$object -> note = trim ( $_POST [ 'note' ]);
$object -> ref_client = $_POST [ 'ref_client' ];
$object -> modelpdf = $_POST [ 'model' ];
$object -> fk_project = $_POST [ 'projectid' ];
$object -> cond_reglement_id = $_POST [ 'cond_reglement_id' ];
$object -> mode_reglement_id = $_POST [ 'mode_reglement_id' ];
$object -> remise_absolue = $_POST [ 'remise_absolue' ];
$object -> remise_percent = $_POST [ 'remise_percent' ];
2008-08-12 20:20:18 +02:00
2009-09-11 17:43:16 +02:00
// Proprietes particulieres a facture de remplacement
2010-09-09 18:02:55 +02:00
$object -> fk_facture_source = $_POST [ 'fac_replacement' ];
$object -> type = 1 ;
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$facid = $object -> createFromCurrent ( $user );
2008-08-12 20:20:18 +02:00
}
}
2009-05-27 03:48:31 +02:00
// Credit note invoice
2008-08-12 20:20:18 +02:00
if ( $_POST [ 'type' ] == 2 )
{
if ( ! $_POST [ 'fac_avoir' ] > 0 )
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " CorrectInvoice " )) . '</div>' ;
}
2009-01-14 16:53:52 +01:00
2009-02-20 23:53:15 +01:00
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2008-08-12 20:20:18 +02:00
if ( empty ( $datefacture ))
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Date " )) . '</div>' ;
}
if ( ! $error )
{
// Si facture avoir
2009-02-20 23:53:15 +01:00
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
//$result=$object->fetch($_POST['fac_avoir']);
2010-12-01 23:14:15 +01:00
$object -> socid = $_POST [ 'socid' ];
2010-09-09 18:02:55 +02:00
$object -> number = $_POST [ 'facnumber' ];
$object -> date = $datefacture ;
$object -> note_public = trim ( $_POST [ 'note_public' ]);
$object -> note = trim ( $_POST [ 'note' ]);
$object -> ref_client = $_POST [ 'ref_client' ];
$object -> modelpdf = $_POST [ 'model' ];
$object -> fk_project = $_POST [ 'projectid' ];
$object -> cond_reglement_id = 0 ;
$object -> mode_reglement_id = $_POST [ 'mode_reglement_id' ];
$object -> remise_absolue = $_POST [ 'remise_absolue' ];
$object -> remise_percent = $_POST [ 'remise_percent' ];
2008-08-12 20:20:18 +02:00
2009-09-11 17:43:16 +02:00
// Proprietes particulieres a facture avoir
2010-09-09 18:02:55 +02:00
$object -> fk_facture_source = $_POST [ 'fac_avoir' ];
$object -> type = 2 ;
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$facid = $object -> create ( $user );
2010-01-09 13:13:22 +01:00
2009-12-22 23:10:25 +01:00
// Add predefined lines
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
{
if ( $_POST [ 'idprod' . $i ])
{
$product = new Product ( $db );
$product -> fetch ( $_POST [ 'idprod' . $i ]);
$startday = dol_mktime ( 12 , 0 , 0 , $_POST [ 'date_start' . $i . 'month' ], $_POST [ 'date_start' . $i . 'day' ], $_POST [ 'date_start' . $i . 'year' ]);
$endday = dol_mktime ( 12 , 0 , 0 , $_POST [ 'date_end' . $i . 'month' ], $_POST [ 'date_end' . $i . 'day' ], $_POST [ 'date_end' . $i . 'year' ]);
2010-09-09 18:02:55 +02:00
$result = $object -> addline ( $facid , $product -> description , $product -> price , $_POST [ 'qty' . $i ], $product -> tva_tx , $product -> localtax1_tx , $product -> localtax2_tx , $_POST [ 'idprod' . $i ], $_POST [ 'remise_percent' . $i ], $startday , $endday , 0 , 0 , '' , $product -> price_base_type , $product -> price_ttc , $product -> type );
2009-12-22 23:10:25 +01:00
}
}
2008-08-12 20:20:18 +02:00
}
}
2010-12-01 23:14:15 +01:00
// Standard invoice or Deposit invoice created from a Predefined invoice
2010-05-07 20:36:54 +02:00
if (( $_POST [ 'type' ] == 0 || $_POST [ 'type' ] == 3 ) && $_POST [ 'fac_rec' ] > 0 )
2008-08-12 20:20:18 +02:00
{
2009-02-20 23:53:15 +01:00
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2009-04-25 00:05:57 +02:00
if ( empty ( $datefacture ))
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Date " )) . '</div>' ;
}
2008-08-12 20:20:18 +02:00
2009-04-25 00:05:57 +02:00
if ( ! $error )
{
2010-09-09 18:02:55 +02:00
$object -> socid = $_POST [ 'socid' ];
$object -> type = $_POST [ 'type' ];
$object -> number = $_POST [ 'facnumber' ];
$object -> date = $datefacture ;
$object -> note_public = trim ( $_POST [ 'note_public' ]);
$object -> note = trim ( $_POST [ 'note' ]);
$object -> ref_client = $_POST [ 'ref_client' ];
$object -> modelpdf = $_POST [ 'model' ];
2008-08-12 20:20:18 +02:00
2010-05-07 20:36:54 +02:00
// Source facture
2010-09-09 18:02:55 +02:00
$object -> fac_rec = $_POST [ 'fac_rec' ];
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$facid = $object -> create ( $user );
2009-04-25 00:05:57 +02:00
}
2008-08-12 20:20:18 +02:00
}
2010-05-17 17:41:17 +02:00
// Standard or deposit or proforma invoice
2009-02-21 18:43:02 +01:00
if (( $_POST [ 'type' ] == 0 || $_POST [ 'type' ] == 3 || $_POST [ 'type' ] == 4 ) && $_POST [ 'fac_rec' ] <= 0 )
2008-08-12 20:20:18 +02:00
{
2009-02-20 23:53:15 +01:00
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2008-08-12 20:20:18 +02:00
if ( empty ( $datefacture ))
{
$error = 1 ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Date " )) . '</div>' ;
}
if ( ! $error )
{
// Si facture standard
2010-09-09 18:02:55 +02:00
$object -> socid = $_POST [ 'socid' ];
$object -> type = $_POST [ 'type' ];
$object -> number = $_POST [ 'facnumber' ];
$object -> date = $datefacture ;
$object -> note_public = trim ( $_POST [ 'note_public' ]);
$object -> note = trim ( $_POST [ 'note' ]);
$object -> ref_client = $_POST [ 'ref_client' ];
$object -> modelpdf = $_POST [ 'model' ];
$object -> fk_project = $_POST [ 'projectid' ];
$object -> cond_reglement_id = ( $_POST [ 'type' ] == 3 ? 1 : $_POST [ 'cond_reglement_id' ]);
$object -> mode_reglement_id = $_POST [ 'mode_reglement_id' ];
$object -> amount = $_POST [ 'amount' ];
$object -> remise_absolue = $_POST [ 'remise_absolue' ];
$object -> remise_percent = $_POST [ 'remise_percent' ];
2008-08-12 20:20:18 +02:00
2010-12-13 14:16:02 +01:00
// If creation from another object of another module (Example: origin=propal, originid=1)
2010-04-28 21:23:36 +02:00
if ( $_POST [ 'origin' ] && $_POST [ 'originid' ])
2008-08-12 20:20:18 +02:00
{
2010-04-28 21:23:36 +02:00
// Parse element/subelement (ex: project_task)
$element = $subelement = $_POST [ 'origin' ];
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $_POST [ 'origin' ], $regs ))
2008-08-12 20:20:18 +02:00
{
2010-04-28 21:23:36 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
2010-04-26 10:54:16 +02:00
}
2010-05-01 16:28:48 +02:00
2010-04-28 21:23:36 +02:00
// For compatibility
if ( $element == 'order' ) { $element = $subelement = 'commande' ; }
if ( $element == 'propal' ) { $element = 'comm/propal' ; $subelement = 'propal' ; }
if ( $element == 'contract' ) { $element = $subelement = 'contrat' ; }
2010-05-01 16:28:48 +02:00
2010-09-09 18:02:55 +02:00
$object -> origin = $_POST [ 'origin' ];
$object -> origin_id = $_POST [ 'originid' ];
2010-05-01 16:28:48 +02:00
2010-09-09 18:02:55 +02:00
$facid = $object -> create ( $user );
2010-12-01 23:14:15 +01:00
2010-04-26 10:54:16 +02:00
if ( $facid > 0 )
{
2010-12-19 03:42:53 +01:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2010-12-17 11:08:31 +01:00
2010-04-28 21:23:36 +02:00
$classname = ucfirst ( $subelement );
2010-09-14 23:27:00 +02:00
$srcobject = new $classname ( $db );
2010-04-28 21:23:36 +02:00
2010-12-13 14:16:02 +01:00
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines " );
$result = $srcobject -> fetch ( $object -> origin_id );
2010-09-14 23:27:00 +02:00
if ( $result > 0 )
2008-08-12 20:20:18 +02:00
{
2010-12-16 19:26:14 +01:00
$lines = $srcobject -> lines ;
2010-09-15 17:07:14 +02:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' )) $lines = $srcobject -> fetch_lines ();
2010-05-01 16:28:48 +02:00
2010-04-26 10:54:16 +02:00
for ( $i = 0 ; $i < sizeof ( $lines ) ; $i ++ )
2008-08-12 20:20:18 +02:00
{
2010-09-14 23:27:00 +02:00
$desc = ( $lines [ $i ] -> desc ? $lines [ $i ] -> desc : $lines [ $i ] -> libelle );
2010-04-28 21:23:36 +02:00
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
2010-04-28 15:49:13 +02:00
2010-04-26 10:54:16 +02:00
// Dates
2010-04-28 21:23:36 +02:00
// TODO mutualiser
$date_start = $lines [ $i ] -> date_debut_prevue ;
if ( $lines [ $i ] -> date_debut_reel ) $date_start = $lines [ $i ] -> date_debut_reel ;
if ( $lines [ $i ] -> date_start ) $date_start = $lines [ $i ] -> date_start ;
$date_end = $lines [ $i ] -> date_fin_prevue ;
if ( $lines [ $i ] -> date_fin_reel ) $date_end = $lines [ $i ] -> date_fin_reel ;
if ( $lines [ $i ] -> date_end ) $date_end = $lines [ $i ] -> date_end ;
2010-04-28 15:49:13 +02:00
2010-09-09 18:02:55 +02:00
$result = $object -> addline (
2010-04-26 10:54:16 +02:00
$facid ,
$desc ,
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
2010-06-21 18:49:41 +02:00
$lines [ $i ] -> localtax1_tx ,
$lines [ $i ] -> localtax2_tx ,
2010-04-26 10:54:16 +02:00
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
$date_start ,
$date_end ,
0 ,
$lines [ $i ] -> info_bits ,
$lines [ $i ] -> fk_remise_except ,
'HT' ,
0 ,
2010-12-16 19:40:02 +01:00
$product_type ,
$lines [ $i ] -> rang ,
$lines [ $i ] -> special_code ,
$object -> origin ,
$lines [ $i ] -> rowid
2010-04-26 10:54:16 +02:00
);
if ( $result < 0 )
2008-08-12 20:20:18 +02:00
{
2010-04-26 10:54:16 +02:00
$error ++ ;
break ;
2008-08-12 20:20:18 +02:00
}
}
}
else
{
2010-12-13 14:16:02 +01:00
$mesg = $srcobject -> error ;
2008-08-12 20:20:18 +02:00
$error ++ ;
}
}
2010-04-26 10:54:16 +02:00
else
{
2010-12-13 14:16:02 +01:00
$mesg = $object -> error ;
2010-04-26 10:54:16 +02:00
$error ++ ;
}
}
// If some invoice's lines already known
else
{
2010-09-09 18:02:55 +02:00
$facid = $object -> create ( $user );
2010-04-26 10:54:16 +02:00
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
{
if ( $_POST [ 'idprod' . $i ])
{
$product = new Product ( $db );
$product -> fetch ( $_POST [ 'idprod' . $i ]);
$startday = dol_mktime ( 12 , 0 , 0 , $_POST [ 'date_start' . $i . 'month' ], $_POST [ 'date_start' . $i . 'day' ], $_POST [ 'date_start' . $i . 'year' ]);
$endday = dol_mktime ( 12 , 0 , 0 , $_POST [ 'date_end' . $i . 'month' ], $_POST [ 'date_end' . $i . 'day' ], $_POST [ 'date_end' . $i . 'year' ]);
2010-09-09 18:02:55 +02:00
$result = $object -> addline ( $facid , $product -> description , $product -> price , $_POST [ 'qty' . $i ], $product -> tva_tx , $product -> localtax1_tx , $product -> localtax2_tx , $_POST [ 'idprod' . $i ], $_POST [ 'remise_percent' . $i ], $startday , $endday , 0 , 0 , '' , $product -> price_base_type , $product -> price_ttc , $product -> type );
2010-04-26 10:54:16 +02:00
}
}
2008-08-12 20:20:18 +02:00
}
}
}
2009-09-11 17:43:16 +02:00
// Fin creation facture, on l'affiche
2008-08-12 20:20:18 +02:00
if ( $facid > 0 && ! $error )
{
$db -> commit ();
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid );
exit ;
}
else
{
$db -> rollback ();
$_GET [ " action " ] = 'create' ;
2010-04-28 21:23:36 +02:00
$_GET [ " origin " ] = $_POST [ " origin " ];
$_GET [ " originid " ] = $_POST [ " originid " ];
2010-09-09 18:02:55 +02:00
if ( ! $mesg ) $mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
}
2009-08-29 17:09:12 +02:00
// Add a new line
2009-05-27 17:52:08 +02:00
if (( $_POST [ 'action' ] == 'addline' || $_POST [ 'action' ] == 'addline_predef' ) && $user -> rights -> facture -> creer )
2008-08-12 20:20:18 +02:00
{
2009-03-10 00:17:00 +01:00
$result = 0 ;
if ( empty ( $_POST [ 'idprod' ]) && $_POST [ " type " ] < 0 )
{
2009-06-04 02:59:06 +02:00
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )) . '</div>' ;
2009-03-10 00:17:00 +01:00
$result = - 1 ;
}
2010-08-09 19:16:26 +02:00
if ( empty ( $_POST [ 'idprod' ]) && ( ! isset ( $_POST [ " np_price " ]) || $_POST [ " np_price " ] == '' )) // Unit price can be 0 but not ''
2009-03-10 00:17:00 +01:00
{
2009-06-04 02:59:06 +02:00
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " UnitPriceHT " )) . '</div>' ;
2009-03-10 00:17:00 +01:00
$result = - 1 ;
}
2010-02-28 15:49:39 +01:00
if ( empty ( $_POST [ 'idprod' ]) && empty ( $_POST [ " np_desc " ]) && empty ( $_POST [ " dp_desc " ]))
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Description " )) . '</div>' ;
$result = - 1 ;
}
2009-08-29 17:09:12 +02:00
if ( ! isset ( $_POST [ 'qty' ]) || $_POST [ 'qty' ] == '' )
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( 'Qty' )) . '</div>' ;
$result = - 1 ;
}
2010-08-09 19:16:26 +02:00
if ( $result >= 0 && ( ( $_POST [ 'np_price' ] != '' && ( $_POST [ 'np_desc' ] || $_POST [ 'dp_desc' ])) || $_POST [ 'idprod' ] ) )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$ret = $object -> fetch ( $facid );
2008-08-12 20:20:18 +02:00
if ( $ret < 0 )
{
2010-09-09 18:02:55 +02:00
dol_print_error ( $db , $object -> error );
2008-08-12 20:20:18 +02:00
exit ;
}
2010-09-09 18:02:55 +02:00
$ret = $object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
2008-10-02 00:24:31 +02:00
$suffixe = $_POST [ 'idprod' ] ? '_predef' : '' ;
2009-02-02 18:19:34 +01:00
$date_start = dol_mktime ( $_POST [ 'date_start' . $suffixe . 'hour' ], $_POST [ 'date_start' . $suffixe . 'min' ], $_POST [ 'date_start' . $suffixe . 'sec' ], $_POST [ 'date_start' . $suffixe . 'month' ], $_POST [ 'date_start' . $suffixe . 'day' ], $_POST [ 'date_start' . $suffixe . 'year' ]);
$date_end = dol_mktime ( $_POST [ 'date_end' . $suffixe . 'hour' ], $_POST [ 'date_end' . $suffixe . 'min' ], $_POST [ 'date_end' . $suffixe . 'sec' ], $_POST [ 'date_end' . $suffixe . 'month' ], $_POST [ 'date_end' . $suffixe . 'day' ], $_POST [ 'date_end' . $suffixe . 'year' ]);
2008-08-12 20:20:18 +02:00
$price_base_type = 'HT' ;
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Ecrase $base_price_type par celui du produit
if ( $_POST [ 'idprod' ])
{
$prod = new Product ( $db , $_POST [ 'idprod' ]);
$prod -> fetch ( $_POST [ 'idprod' ]);
2010-09-09 18:02:55 +02:00
$tva_tx = get_default_tva ( $mysoc , $object -> client , $prod -> id );
$tva_npr = get_default_npr ( $mysoc , $object -> client , $prod -> id );
2008-08-12 20:20:18 +02:00
2009-02-15 18:33:02 +01:00
// We define price for product
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> PRODUIT_MULTIPRICES && $object -> client -> price_level )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$pu_ht = $prod -> multiprices [ $object -> client -> price_level ];
$pu_ttc = $prod -> multiprices_ttc [ $object -> client -> price_level ];
2011-01-28 12:42:59 +01:00
$price_min = $prod -> multiprices_min [ $object -> client -> price_level ];
2010-09-09 18:02:55 +02:00
$price_base_type = $prod -> multiprices_base_type [ $object -> client -> price_level ];
2008-08-12 20:20:18 +02:00
}
else
{
$pu_ht = $prod -> price ;
$pu_ttc = $prod -> price_ttc ;
2011-01-28 12:42:59 +01:00
$price_min = $prod -> price_min ;
2008-08-12 20:20:18 +02:00
$price_base_type = $prod -> price_base_type ;
}
// On reevalue prix selon taux tva car taux tva transaction peut etre different
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
if ( $tva_tx != $prod -> tva_tx )
{
if ( $price_base_type != 'HT' )
{
$pu_ht = price2num ( $pu_ttc / ( 1 + ( $tva_tx / 100 )), 'MU' );
}
else
{
$pu_ttc = price2num ( $pu_ht * ( 1 + ( $tva_tx / 100 )), 'MU' );
}
}
$desc = $prod -> description ;
2010-12-02 00:22:25 +01:00
$desc .= ( $prod -> description && $_POST [ 'np_desc' ]) ? " \n " : " " ;
2008-08-12 20:20:18 +02:00
$desc .= $_POST [ 'np_desc' ];
2010-12-02 00:22:25 +01:00
if ( ! empty ( $prod -> customcode ) || ! empty ( $prod -> country_code ))
{
$tmptxt = '(' ;
if ( ! empty ( $prod -> customcode )) $tmptxt .= $langs -> transnoentitiesnoconv ( " CustomCode " ) . ': ' . $prod -> customcode ;
if ( ! empty ( $prod -> customcode ) && ! empty ( $prod -> country_code )) $tmptxt .= ' - ' ;
if ( ! empty ( $prod -> country_code )) $tmptxt .= $langs -> transnoentitiesnoconv ( " CountryOrigin " ) . ': ' . getCountry ( $prod -> country_code , 0 , $db , $langs , 0 );
$tmptxt .= ')' ;
$desc .= " \n " . $tmptxt ;
}
2009-03-10 00:17:00 +01:00
$type = $prod -> type ;
2008-08-12 20:20:18 +02:00
}
else
{
2010-08-09 19:16:26 +02:00
$pu_ht = $_POST [ 'np_price' ];
$tva_tx = str_replace ( '*' , '' , $_POST [ 'np_tva_tx' ]);
$tva_npr = preg_match ( '/\*/' , $_POST [ 'np_tva_tx' ]) ? 1 : 0 ;
2008-08-12 20:20:18 +02:00
$desc = $_POST [ 'dp_desc' ];
2009-03-10 00:17:00 +01:00
$type = $_POST [ " type " ];
2008-08-12 20:20:18 +02:00
}
2010-07-15 00:23:14 +02:00
2010-09-09 18:02:55 +02:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $object -> client );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $object -> client );
2008-08-12 20:20:18 +02:00
$info_bits = 0 ;
if ( $tva_npr ) $info_bits |= 0x01 ;
2009-03-10 00:17:00 +01:00
if ( $result >= 0 )
2008-08-28 01:00:37 +02:00
{
2011-01-28 12:42:59 +01:00
if ( $price_min && ( price2num ( $pu_ht ) * ( 1 - price2num ( $_POST [ 'remise_percent' ]) / 100 ) < price2num ( $price_min )))
2009-03-10 00:17:00 +01:00
{
2011-01-29 17:26:56 +01:00
$object -> error = $langs -> trans ( " CantBeLessThanMinPrice " , price2num ( $price_min , 'MU' ) . ' ' . $langs -> trans ( " Currency " . $conf -> monnaie )) ;
2009-03-10 00:17:00 +01:00
$result = - 1 ;
}
else
{
// Insert line
2010-09-09 18:02:55 +02:00
$result = $object -> addline (
2010-08-09 19:16:26 +02:00
$facid ,
2009-03-10 00:17:00 +01:00
$desc ,
$pu_ht ,
$_POST [ 'qty' ],
$tva_tx ,
2010-06-21 18:49:41 +02:00
$localtax1_tx ,
$localtax2_tx ,
2009-03-10 00:17:00 +01:00
$_POST [ 'idprod' ],
$_POST [ 'remise_percent' ],
$date_start ,
$date_end ,
0 ,
$info_bits ,
'' ,
$price_base_type ,
$pu_ttc ,
$type
);
}
2008-08-28 01:00:37 +02:00
}
2008-08-12 20:20:18 +02:00
}
if ( $result > 0 )
{
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2009-05-27 17:52:08 +02:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'idprod' ]);
unset ( $_POST [ 'remmise_percent' ]);
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'np_desc' ]);
2010-08-09 19:16:26 +02:00
unset ( $_POST [ 'np_price' ]);
unset ( $_POST [ 'np_tva_tx' ]);
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
if ( empty ( $mesg )) $mesg = '<div class="error">' . $object -> error . '</div>' ;
2008-08-12 20:20:18 +02:00
}
2010-08-09 19:16:26 +02:00
$_POST [ " action " ] = '' ;
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'action' ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ 'save' ] == $langs -> trans ( 'Save' ))
{
2010-09-09 18:02:55 +02:00
if ( ! $object -> fetch ( $facid ) > 0 ) dol_print_error ( $db );
$object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
2009-03-12 01:14:56 +01:00
// Clean parameters
2008-08-12 20:20:18 +02:00
$date_start = '' ;
$date_end = '' ;
2009-02-02 18:19:34 +01:00
$date_start = dol_mktime ( $_POST [ 'date_start' . $suffixe . 'hour' ], $_POST [ 'date_start' . $suffixe . 'min' ], $_POST [ 'date_start' . $suffixe . 'sec' ], $_POST [ 'date_start' . $suffixe . 'month' ], $_POST [ 'date_start' . $suffixe . 'day' ], $_POST [ 'date_start' . $suffixe . 'year' ]);
$date_end = dol_mktime ( $_POST [ 'date_end' . $suffixe . 'hour' ], $_POST [ 'date_end' . $suffixe . 'min' ], $_POST [ 'date_end' . $suffixe . 'sec' ], $_POST [ 'date_end' . $suffixe . 'month' ], $_POST [ 'date_end' . $suffixe . 'day' ], $_POST [ 'date_end' . $suffixe . 'year' ]);
2009-03-12 01:14:56 +01:00
$description = dol_htmlcleanlastbr ( $_POST [ 'desc' ]);
2010-10-31 19:57:11 +01:00
$up_ht = GETPOST ( 'pu' ) ? GETPOST ( 'pu' ) : GETPOST ( 'subprice' );
2009-02-04 23:12:23 +01:00
2008-08-12 20:20:18 +02:00
// Define info_bits
$info_bits = 0 ;
2010-10-16 15:10:24 +02:00
if ( preg_match ( '/\*/' , $_POST [ 'tva_tx' ])) $info_bits |= 0x01 ;
2008-08-12 20:20:18 +02:00
// Define vat_rate
2010-10-16 15:10:24 +02:00
$vat_rate = $_POST [ 'tva_tx' ];
2009-10-21 11:51:52 +02:00
$vat_rate = str_replace ( '*' , '' , $vat_rate );
2010-09-09 18:02:55 +02:00
$localtax1_rate = get_localtax ( $vat_rate , 1 , $object -> client );
$localtax2_rate = get_localtax ( $vat_rate , 2 , $object -> client );
2008-08-12 20:20:18 +02:00
2009-03-10 00:17:00 +01:00
// Check parameters
2010-10-16 15:10:24 +02:00
if ( ! GETPOST ( 'productid' ) && GETPOST ( " type " ) < 0 )
2009-02-02 18:19:34 +01:00
{
2009-03-12 01:14:56 +01:00
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )) . '</div>' ;
2009-03-10 00:17:00 +01:00
$result = - 1 ;
}
// Check minimum price
2010-10-16 15:10:24 +02:00
if ( GETPOST ( 'productid' ))
2009-03-10 00:17:00 +01:00
{
2010-10-16 15:10:24 +02:00
$productid = GETPOST ( 'productid' );
2009-03-12 01:14:56 +01:00
$product = new Product ( $db );
$product -> fetch ( $productid );
$type = $product -> type ;
2011-01-29 17:26:56 +01:00
$price_min = $product -> price_min ;
if ( $conf -> global -> PRODUIT_MULTIPRICES && $object -> client -> price_level ) $price_min = $product -> multiprices_min [ $object -> client -> price_level ];
2008-08-28 01:00:37 +02:00
}
2011-01-29 17:26:56 +01:00
if ( $object -> type != 2 && $price_min && GETPOST ( 'productid' ) && ( price2num ( $up_ht ) * ( 1 - price2num ( GETPOST ( 'remise_percent' )) / 100 ) < price2num ( $price_min )))
2008-08-12 20:20:18 +02:00
{
2010-10-31 19:57:11 +01:00
//print "CantBeLessThanMinPrice ".$up_ht." - ".GETPOST('remise_percent')." - ".$product->price_min;
2011-01-29 17:26:56 +01:00
$mesg = '<div class="error">' . $langs -> trans ( " CantBeLessThanMinPrice " , price2num ( $price_min , 'MU' ) . ' ' . $langs -> trans ( " Currency " . $conf -> monnaie )) . '</div>' ;
2009-03-10 00:17:00 +01:00
$result =- 1 ;
}
// Define params
2010-10-16 15:10:24 +02:00
if ( GETPOST ( 'productid' )) $type = $product -> type ;
else $type = GETPOST ( " type " );
2009-03-10 00:17:00 +01:00
// Update line
if ( $result >= 0 )
2008-08-28 01:00:37 +02:00
{
2010-10-16 15:10:24 +02:00
$result = $object -> updateline ( GETPOST ( 'lineid' ),
2009-03-12 01:14:56 +01:00
$description ,
2010-10-31 19:57:11 +01:00
$up_ht ,
2010-10-16 15:10:24 +02:00
GETPOST ( 'qty' ),
GETPOST ( 'remise_percent' ),
2008-08-28 01:00:37 +02:00
$date_start ,
$date_end ,
$vat_rate ,
2010-06-21 18:49:41 +02:00
$localtax1_rate ,
$localtax2_rate ,
2009-02-02 18:19:34 +01:00
'HT' ,
2009-03-10 00:17:00 +01:00
$info_bits ,
$type
2008-08-28 01:00:37 +02:00
);
2008-12-02 00:09:52 +01:00
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
2010-10-16 15:10:24 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2008-08-28 01:00:37 +02:00
}
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'action' ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ 'cancel' ] == $langs -> trans ( 'Cancel' ))
{
2010-08-09 19:16:26 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $facid ); // Pour reaffichage de la fiche en cours d'edition
2008-08-12 20:20:18 +02:00
exit ;
}
/*
* Ordonnancement des lignes
*/
if ( $_GET [ 'action' ] == 'up' && $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
$object -> line_up ( $_GET [ 'rowid' ]);
2008-10-29 00:36:36 +01:00
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2010-02-27 14:37:13 +01:00
2010-09-09 18:02:55 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '#' . $_GET [ 'rowid' ]);
2008-08-12 20:20:18 +02:00
exit ;
}
if ( $_GET [ 'action' ] == 'down' && $user -> rights -> facture -> creer )
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
$object -> line_down ( $_GET [ 'rowid' ]);
2008-10-29 00:36:36 +01:00
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2010-02-27 14:37:13 +01:00
2010-09-09 18:02:55 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '#' . $_GET [ 'rowid' ]);
2008-08-12 20:20:18 +02:00
exit ;
}
/*
2010-01-13 11:30:33 +01:00
* Add file in email form
2008-08-12 20:20:18 +02:00
*/
if ( $_POST [ 'addfile' ])
{
2010-05-01 16:28:48 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/files.lib.php " );
2010-05-12 13:29:21 +02:00
// Set tmp user directory TODO Use a dedicated directory for temp mails files
2009-10-14 18:13:20 +02:00
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
2009-04-29 20:52:07 +02:00
$upload_dir = $vardir . '/temp/' ;
2008-08-12 20:20:18 +02:00
2010-05-12 13:29:21 +02:00
$mesg = dol_add_file_process ( $upload_dir , 0 , 0 );
2010-05-01 16:28:48 +02:00
2008-08-12 20:20:18 +02:00
$_GET [ " action " ] = 'presend' ;
2010-05-12 13:29:21 +02:00
$_POST [ " action " ] = 'presend' ;
2008-08-12 20:20:18 +02:00
}
2010-01-13 11:30:33 +01:00
/*
* Remove file in email form
*/
if ( ! empty ( $_POST [ 'removedfile' ]))
{
2010-05-12 13:29:21 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/files.lib.php " );
2010-01-13 11:30:33 +01:00
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir = $vardir . '/temp/' ;
2010-05-12 13:29:21 +02:00
$mesg = dol_remove_file_process ( $_POST [ 'removedfile' ], 0 );
2010-01-13 11:30:33 +01:00
$_GET [ " action " ] = 'presend' ;
2010-05-12 13:29:21 +02:00
$_POST [ " action " ] = 'presend' ;
2010-01-13 11:30:33 +01:00
}
2008-08-12 20:20:18 +02:00
/*
* Send mail
*/
2010-01-13 11:30:33 +01:00
if (( $_POST [ 'action' ] == 'send' || $_POST [ 'action' ] == 'relance' ) && ! $_POST [ 'addfile' ] && ! $_POST [ 'removedfile' ] && ! $_POST [ 'cancel' ])
2008-08-12 20:20:18 +02:00
{
$langs -> load ( 'mails' );
2010-10-27 18:49:26 +02:00
$actiontypecode = '' ; $subject = '' ; $actionmsg = '' ; $actionmsg2 = '' ;
2010-09-09 18:02:55 +02:00
$result = $object -> fetch ( $facid );
$result = $object -> fetch_thirdparty ();
2010-05-12 13:29:21 +02:00
2010-05-12 13:58:58 +02:00
if ( $result > 0 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$ref = dol_sanitizeFileName ( $object -> ref );
2008-08-12 20:20:18 +02:00
$file = $conf -> facture -> dir_output . '/' . $ref . '/' . $ref . '.pdf' ;
if ( is_readable ( $file ))
{
if ( $_POST [ 'sendto' ])
{
2009-09-11 17:43:16 +02:00
// Le destinataire a ete fourni via le champ libre
2008-08-12 20:20:18 +02:00
$sendto = $_POST [ 'sendto' ];
$sendtoid = 0 ;
}
elseif ( $_POST [ 'receiver' ])
{
2009-09-11 17:43:16 +02:00
// Le destinataire a ete fourni via la liste deroulante
2008-08-12 20:20:18 +02:00
if ( $_POST [ 'receiver' ] < 0 ) // Id du tiers
{
2010-09-09 18:02:55 +02:00
$sendto = $object -> client -> email ;
2008-08-12 20:20:18 +02:00
$sendtoid = 0 ;
}
else // Id du contact
{
2010-09-09 18:02:55 +02:00
$sendto = $object -> client -> contact_get_email ( $_POST [ 'receiver' ]);
2008-08-12 20:20:18 +02:00
$sendtoid = $_POST [ 'receiver' ];
}
}
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $sendto ))
2008-08-12 20:20:18 +02:00
{
$langs -> load ( " commercial " );
$from = $_POST [ 'fromname' ] . ' <' . $_POST [ 'frommail' ] . '>' ;
$replyto = $_POST [ 'replytoname' ] . ' <' . $_POST [ 'replytomail' ] . '>' ;
$message = $_POST [ 'message' ];
$sendtocc = $_POST [ 'sendtocc' ];
$deliveryreceipt = $_POST [ 'deliveryreceipt' ];
if ( $_POST [ 'action' ] == 'send' )
{
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $_POST [ 'subject' ])) $subject = $_POST [ 'subject' ];
2010-09-09 18:02:55 +02:00
else $subject = $langs -> transnoentities ( 'Bill' ) . ' ' . $object -> ref ;
2008-08-12 20:20:18 +02:00
$actiontypecode = 'AC_FAC' ;
$actionmsg = $langs -> transnoentities ( 'MailSentBy' ) . ' ' . $from . ' ' . $langs -> transnoentities ( 'To' ) . ' ' . $sendto . " . \n " ;
if ( $message )
{
$actionmsg .= $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject . " \n " ;
$actionmsg .= $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : \n " ;
$actionmsg .= $message ;
}
2010-10-27 18:49:26 +02:00
//$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'action' ] == 'relance' )
{
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $_POST [ 'subject' ])) $subject = $_POST [ 'subject' ];
2010-09-09 18:02:55 +02:00
else $subject = $langs -> transnoentities ( 'Relance facture ' . $object -> ref );
2008-08-12 20:20:18 +02:00
$actiontypecode = 'AC_FAC' ;
$actionmsg = $langs -> transnoentities ( 'MailSentBy' ) . ' ' . $from . ' ' . $langs -> transnoentities ( 'To' ) . ' ' . $sendto . " . \n " ;
if ( $message ) {
$actionmsg .= $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject . " \n " ;
$actionmsg .= $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : \n " ;
$actionmsg .= $message ;
}
2010-10-27 18:49:26 +02:00
//$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
2008-08-12 20:20:18 +02:00
}
// Create form object
2010-05-12 13:58:58 +02:00
include_once ( DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' );
2008-08-12 20:20:18 +02:00
$formmail = new FormMail ( $db );
$attachedfiles = $formmail -> get_attached_files ();
$filepath = $attachedfiles [ 'paths' ];
$filename = $attachedfiles [ 'names' ];
$mimetype = $attachedfiles [ 'mimes' ];
// Send mail
require_once ( DOL_DOCUMENT_ROOT . '/lib/CMailFile.class.php' );
2009-05-12 01:32:58 +02:00
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , '' , $deliveryreceipt , - 1 );
2008-08-12 20:20:18 +02:00
if ( $mailfile -> error )
{
$mesg = '<div class="error">' . $mailfile -> error . '</div>' ;
}
else
{
$result = $mailfile -> sendfile ();
if ( $result )
{
2011-01-14 03:02:57 +01:00
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $from , $sendto ); // Must not contain "
2008-08-12 20:20:18 +02:00
$error = 0 ;
// Initialisation donnees
2010-09-09 18:02:55 +02:00
$object -> sendtoid = $sendtoid ;
$object -> actiontypecode = $actiontypecode ;
2010-10-27 18:49:26 +02:00
$object -> actionmsg = $actionmsg ; // Long text
$object -> actionmsg2 = $actionmsg2 ; // Short text
2010-09-09 18:02:55 +02:00
$object -> facid = $object -> id ;
2008-08-12 20:20:18 +02:00
// Appel des triggers
2010-04-28 12:33:16 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /core/class/interfaces.class.php " );
2008-08-12 20:20:18 +02:00
$interface = new Interfaces ( $db );
2010-09-09 18:02:55 +02:00
$result = $interface -> run_triggers ( 'BILL_SENTBYMAIL' , $object , $user , $langs , $conf );
2008-08-12 20:20:18 +02:00
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
if ( $error )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-08-12 20:20:18 +02:00
}
else
{
// Redirect here
// This avoid sending mail twice if going out and then back to page
2010-12-01 23:14:15 +01:00
$_SESSION [ 'message' ] = $mesg ;
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&mesg=1' );
2008-08-12 20:20:18 +02:00
exit ;
}
}
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' ;
if ( $mailfile -> error )
{
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $from , $sendto );
$mesg .= '<br>' . $mailfile -> error ;
}
else
{
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' ;
}
$mesg .= '</div>' ;
}
}
}
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorMailRecipientIsEmpty' ) . '</div>' ;
2009-02-20 23:53:15 +01:00
dol_syslog ( 'Recipient email is empty' );
2008-08-12 20:20:18 +02:00
}
}
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorCantReadFile' , $file ) . '</div>' ;
2009-02-20 23:53:15 +01:00
dol_syslog ( 'Failed to read file: ' . $file );
2008-08-12 20:20:18 +02:00
}
}
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorFailedToReadEntity' , $langs -> trans ( " Invoice " )) . '</div>' ;
2009-09-11 17:43:16 +02:00
dol_syslog ( 'Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.' );
2008-08-12 20:20:18 +02:00
}
2009-05-09 19:13:03 +02:00
$_GET [ 'action' ] = 'presend' ;
2008-08-12 20:20:18 +02:00
}
/*
2010-02-28 23:49:06 +01:00
* Generate document
2008-08-12 20:20:18 +02:00
*/
if ( $_REQUEST [ 'action' ] == 'builddoc' ) // En get ou en post
{
2010-09-09 18:02:55 +02:00
$object -> fetch ( $facid );
$object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
if ( $_REQUEST [ 'model' ])
{
2010-09-09 18:02:55 +02:00
$object -> setDocModel ( $user , $_REQUEST [ 'model' ]);
2008-08-12 20:20:18 +02:00
}
2010-02-27 14:37:13 +01:00
// Define output language
2008-12-02 00:09:52 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-12-02 00:09:52 +01:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-12-02 00:09:52 +01:00
}
2010-09-09 18:02:55 +02:00
$result = facture_pdf_create ( $db , $object , '' , $object -> modelpdf , $outputlangs );
2008-08-12 20:20:18 +02:00
if ( $result <= 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $result );
2008-08-12 20:20:18 +02:00
exit ;
}
else
{
2010-09-09 18:02:55 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#builddoc' ));
2008-11-14 12:56:47 +01:00
exit ;
2008-08-12 20:20:18 +02:00
}
}
/*
* View
*/
2009-08-02 18:16:15 +02:00
llxHeader ( '' , $langs -> trans ( 'Bill' ), 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes' );
2008-08-12 20:20:18 +02:00
$html = new Form ( $db );
$formfile = new FormFile ( $db );
2011-02-19 13:15:17 +01:00
$now = dol_now ();
2008-08-12 20:20:18 +02:00
2010-07-25 23:23:57 +02:00
2008-08-12 20:20:18 +02:00
/*********************************************************************
*
* Mode creation
*
**********************************************************************/
if ( $_GET [ 'action' ] == 'create' )
{
$facturestatic = new Facture ( $db );
2009-08-23 22:15:13 +02:00
print_fiche_titre ( $langs -> trans ( 'NewBill' ));
2008-08-12 20:20:18 +02:00
if ( $mesg ) print $mesg ;
$soc = new Societe ( $db );
2010-09-15 13:17:05 +02:00
if ( $socid ) $res = $soc -> fetch ( $socid );
2008-08-12 20:20:18 +02:00
2010-12-01 23:14:15 +01:00
if ( GETPOST ( 'origin' ) && GETPOST ( 'originid' ))
2010-04-26 12:01:01 +02:00
{
// Parse element/subelement (ex: project_task)
2010-12-01 23:14:15 +01:00
$element = $subelement = GETPOST ( 'origin' );
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' ), $regs ))
2010-04-26 12:01:01 +02:00
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
2010-04-28 17:31:49 +02:00
2010-09-15 13:17:05 +02:00
if ( $element == 'project' )
{
2010-12-01 23:14:15 +01:00
$projectid = GETPOST ( 'originid' );
2010-09-15 13:17:05 +02:00
}
2010-12-17 11:08:31 +01:00
else
2010-09-15 13:17:05 +02:00
{
// For compatibility
2010-12-15 00:40:46 +01:00
if ( $element == 'order' || $element == 'commande' ) { $element = $subelement = 'commande' ; }
2010-12-15 00:27:17 +01:00
if ( $element == 'propal' ) { $element = 'comm/propal' ; $subelement = 'propal' ; }
if ( $element == 'contract' ) { $element = $subelement = 'contrat' ; }
2010-12-14 00:38:47 +01:00
2010-12-19 03:42:53 +01:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2010-12-17 11:08:31 +01:00
2010-12-15 00:27:17 +01:00
$classname = ucfirst ( $subelement );
2010-09-15 15:29:17 +02:00
$objectsrc = new $classname ( $db );
2010-12-01 23:14:15 +01:00
$objectsrc -> fetch ( GETPOST ( 'originid' ));
2010-12-17 11:08:31 +01:00
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) $objectsrc -> fetch_lines ();
2010-12-15 00:27:17 +01:00
$objectsrc -> fetch_thirdparty ();
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $object -> fk_project : '' );
$ref_client = ( ! empty ( $objectsrc -> ref_client ) ? $object -> ref_client : '' );
$soc = $objectsrc -> client ;
$cond_reglement_id = ( ! empty ( $objectsrc -> cond_reglement_id ) ? $objectsrc -> cond_reglement_id : ( ! empty ( $soc -> cond_reglement_id ) ? $soc -> cond_reglement_id : 1 ));
$mode_reglement_id = ( ! empty ( $objectsrc -> mode_reglement_id ) ? $objectsrc -> mode_reglement_id : ( ! empty ( $soc -> mode_reglement_id ) ? $soc -> mode_reglement_id : 0 ));
$remise_percent = ( ! empty ( $objectsrc -> remise_percent ) ? $objectsrc -> remise_percent : ( ! empty ( $soc -> remise_percent ) ? $soc -> remise_percent : 0 ));
$remise_absolue = ( ! empty ( $objectsrc -> remise_absolue ) ? $objectsrc -> remise_absolue : ( ! empty ( $soc -> remise_absolue ) ? $soc -> remise_absolue : 0 ));
2010-09-15 13:17:05 +02:00
$dateinvoice = empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : 0 ;
}
2010-04-26 12:01:01 +02:00
}
2008-08-12 20:20:18 +02:00
else
{
2010-04-28 10:58:41 +02:00
$cond_reglement_id = $soc -> cond_reglement_id ;
$mode_reglement_id = $soc -> mode_reglement_id ;
$remise_percent = $soc -> remise_percent ;
$remise_absolue = 0 ;
2010-04-28 11:25:35 +02:00
$dateinvoice = empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : 0 ;
2008-08-12 20:20:18 +02:00
}
$absolute_discount = $soc -> getAvailableDiscounts ();
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2008-08-12 20:20:18 +02:00
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' . " \n " ;
print '<input name="facnumber" type="hidden" value="provisoire">' ;
2010-12-01 23:14:15 +01:00
print '<input type="hidden" name="origin" value="' . GETPOST ( 'origin' ) . '">' ;
print '<input type="hidden" name="originid" value="' . GETPOST ( 'originid' ) . '">' ;
2008-08-12 20:20:18 +02:00
print '<table class="border" width="100%">' ;
// Ref
print '<tr><td>' . $langs -> trans ( 'Ref' ) . '</td><td colspan="2">' . $langs -> trans ( 'Draft' ) . '</td></tr>' ;
2009-09-11 17:43:16 +02:00
// Factures predefinies
2010-04-26 12:01:01 +02:00
if ( empty ( $_GET [ 'propalid' ]) && empty ( $_GET [ 'commandeid' ]) && empty ( $_GET [ 'contratid' ]) && empty ( $_GET [ 'originid' ]))
2008-11-20 22:30:23 +01:00
{
2010-08-05 09:20:54 +02:00
$sql = 'SELECT r.rowid, r.titre, r.total_ttc' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r' ;
2009-05-27 03:59:33 +02:00
$sql .= ' WHERE r.fk_soc = ' . $soc -> id ;
2010-08-09 19:16:26 +02:00
2009-05-27 03:59:33 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2008-11-20 22:30:23 +01:00
{
2009-05-27 03:59:33 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2008-11-20 22:30:23 +01:00
2009-05-27 03:59:33 +02:00
if ( $num > 0 )
{
print '<tr><td>' . $langs -> trans ( 'CreateFromRepeatableInvoice' ) . '</td><td>' ;
print '<select class="flat" name="fac_rec">' ;
2010-11-01 17:00:38 +01:00
print '<option value="0" selected="selected"></option>' ;
2009-05-27 03:59:33 +02:00
while ( $i < $num )
2008-11-20 22:30:23 +01:00
{
2009-05-27 03:59:33 +02:00
$objp = $db -> fetch_object ( $resql );
print '<option value="' . $objp -> rowid . '"' ;
2010-11-01 17:00:38 +01:00
if ( $_POST [ " fac_rec " ] == $objp -> rowid ) print ' selected="selected"' ;
2010-08-05 09:20:54 +02:00
print '>' . $objp -> titre . ' (' . price ( $objp -> total_ttc ) . ' ' . $langs -> trans ( " TTC " ) . ')</option>' ;
2009-05-27 03:59:33 +02:00
$i ++ ;
2008-11-20 22:30:23 +01:00
}
2009-05-27 03:59:33 +02:00
print '</select></td></tr>' ;
2008-11-20 22:30:23 +01:00
}
2010-02-16 09:57:07 +01:00
$db -> free ( $resql );
2009-05-27 03:59:33 +02:00
}
else
{
dol_print_error ( $db );
2008-11-20 22:30:23 +01:00
}
}
2008-08-12 20:20:18 +02:00
// Tiers
2010-02-20 10:59:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Company' ) . '</td><td colspan="2">' ;
2008-08-12 20:20:18 +02:00
print $soc -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' ;
print '</td>' ;
print '</tr>' . " \n " ;
// Type de facture
$facids = $facturestatic -> list_replacable_invoices ( $soc -> id );
if ( $facids < 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $facturestatic );
2008-08-12 20:20:18 +02:00
exit ;
}
$options = " " ;
foreach ( $facids as $facparam )
{
2008-11-08 23:09:00 +01:00
$options .= '<option value="' . $facparam [ 'id' ] . '"' ;
2010-11-01 17:00:38 +01:00
if ( $facparam [ 'id' ] == $_POST [ 'fac_replacement' ]) $options .= ' selected="selected"' ;
2008-11-08 23:09:00 +01:00
$options .= '>' . $facparam [ 'ref' ];
$options .= ' (' . $facturestatic -> LibStatut ( 0 , $facparam [ 'status' ]) . ')' ;
$options .= '</option>' ;
2008-08-12 20:20:18 +02:00
}
2008-12-02 00:09:52 +01:00
2008-08-12 20:20:18 +02:00
$facids = $facturestatic -> list_qualified_avoir_invoices ( $soc -> id );
2008-11-08 23:09:00 +01:00
if ( $facids < 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $facturestatic );
2008-11-08 23:09:00 +01:00
exit ;
}
2008-08-12 20:20:18 +02:00
$optionsav = " " ;
foreach ( $facids as $key => $value )
{
$newinvoice = new Facture ( $db );
$newinvoice -> fetch ( $key );
2008-11-08 23:09:00 +01:00
$optionsav .= '<option value="' . $key . '"' ;
2010-11-01 17:00:38 +01:00
if ( $key == $_POST [ 'fac_avoir' ]) $optionsav .= ' selected="selected"' ;
2008-11-08 23:09:00 +01:00
$optionsav .= '>' ;
2008-08-12 20:20:18 +02:00
$optionsav .= $newinvoice -> ref ;
$optionsav .= ' (' . $newinvoice -> getLibStatut ( 1 , $value ) . ')' ;
$optionsav .= '</option>' ;
}
2010-02-20 10:59:34 +01:00
print '<tr><td valign="top" class="fieldrequired">' . $langs -> trans ( 'Type' ) . '</td><td colspan="2">' ;
2008-08-12 20:20:18 +02:00
print '<table class="nobordernopadding">' . " \n " ;
2009-02-21 18:43:02 +01:00
// Standard invoice
print '<tr height="18"><td width="16px" valign="middle">' ;
2011-02-19 13:15:17 +01:00
print '<input type="radio" name="type" value="0"' . ( GETPOST ( 'type' ) == 0 ? ' checked="true"' : '' ) . '>' ;
2008-08-12 20:20:18 +02:00
print '</td><td valign="middle">' ;
2009-05-04 21:02:32 +02:00
$desc = $html -> textwithpicto ( $langs -> trans ( " InvoiceStandardAsk " ), $langs -> transnoentities ( " InvoiceStandardDesc " ), 1 );
2008-08-12 20:20:18 +02:00
print $desc ;
print '</td></tr>' . " \n " ;
2009-02-21 18:43:02 +01:00
// Deposit
print '<tr height="18"><td width="16px" valign="middle">' ;
2011-02-19 13:15:17 +01:00
print '<input type="radio" name="type" value="3"' . ( GETPOST ( 'type' ) == 3 ? ' checked="true"' : '' ) . '>' ;
2009-02-21 18:43:02 +01:00
print '</td><td valign="middle">' ;
2009-05-04 21:02:32 +02:00
$desc = $html -> textwithpicto ( $langs -> trans ( " InvoiceDeposit " ), $langs -> transnoentities ( " InvoiceDepositDesc " ), 1 );
2009-02-21 18:43:02 +01:00
print $desc ;
print '</td></tr>' . " \n " ;
2010-05-17 17:41:17 +02:00
// Proforma
2009-02-21 18:43:02 +01:00
if ( $conf -> global -> FACTURE_USE_PROFORMAT )
{
print '<tr height="18"><td width="16px" valign="middle">' ;
2011-02-19 13:15:17 +01:00
print '<input type="radio" name="type" value="4"' . ( GETPOST ( 'type' ) == 4 ? ' checked="true"' : '' ) . '>' ;
2009-02-21 18:43:02 +01:00
print '</td><td valign="middle">' ;
2010-05-17 17:41:17 +02:00
$desc = $html -> textwithpicto ( $langs -> trans ( " InvoiceProForma " ), $langs -> transnoentities ( " InvoiceProFormaDesc " ), 1 );
2009-02-21 18:43:02 +01:00
print $desc ;
print '</td></tr>' . " \n " ;
}
// Replacement
print '<tr height="18"><td valign="middle">' ;
2011-02-19 13:15:17 +01:00
print '<input type="radio" name="type" value="1"' . ( GETPOST ( 'type' ) == 1 ? ' checked=true' : '' );
2008-08-12 20:20:18 +02:00
if ( ! $options ) print ' disabled="true"' ;
print '>' ;
print '</td><td valign="middle">' ;
$text = $langs -> trans ( " InvoiceReplacementAsk " ) . ' ' ;
$text .= '<select class="flat" name="fac_replacement"' ;
if ( ! $options ) $text .= ' disabled="true"' ;
$text .= '>' ;
if ( $options )
{
$text .= '<option value="-1"> </option>' ;
$text .= $options ;
}
else
{
$text .= '<option value="-1">' . $langs -> trans ( " NoReplacableInvoice " ) . '</option>' ;
}
$text .= '</select>' ;
2009-05-04 21:02:32 +02:00
$desc = $html -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceReplacementDesc " ), 1 );
2008-08-12 20:20:18 +02:00
print $desc ;
print '</td></tr>' . " \n " ;
2009-02-21 18:43:02 +01:00
// Credit note
print '<tr height="18"><td valign="middle">' ;
2011-02-19 13:15:17 +01:00
print '<input type="radio" name="type" value="2"' . ( GETPOST ( 'type' ) == 2 ? ' checked=true' : '' );
2008-08-12 20:20:18 +02:00
if ( ! $optionsav ) print ' disabled="true"' ;
print '>' ;
print '</td><td valign="middle">' ;
$text = $langs -> transnoentities ( " InvoiceAvoirAsk " ) . ' ' ;
// $text.='<input type="text" value="">';
$text .= '<select class="flat" name="fac_avoir"' ;
if ( ! $optionsav ) $text .= ' disabled="true"' ;
$text .= '>' ;
if ( $optionsav )
{
$text .= '<option value="-1"> </option>' ;
$text .= $optionsav ;
}
else
{
$text .= '<option value="-1">' . $langs -> trans ( " NoInvoiceToCorrect " ) . '</option>' ;
}
$text .= '</select>' ;
2009-05-04 21:02:32 +02:00
$desc = $html -> textwithpicto ( $text , $langs -> transnoentities ( " InvoiceAvoirDesc " ), 1 );
2008-08-12 20:20:18 +02:00
//.' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1);
print $desc ;
print '</td></tr>' . " \n " ;
print '</table>' ;
print '</td></tr>' ;
// Discounts for third party
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td colspan="2">' ;
if ( $soc -> remise_client ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_client );
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
print '. ' ;
if ( $absolute_discount ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> trans ( " Currency " . $conf -> monnaie ));
else print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
print '.' ;
print '</td></tr>' ;
// Date invoice
2010-02-20 10:59:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Date' ) . '</td><td colspan="2">' ;
2010-02-10 15:08:09 +01:00
$html -> select_date ( $dateinvoice , '' , '' , '' , '' , " add " , 1 , 1 );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2009-02-21 18:43:02 +01:00
// Payment term
2008-08-12 20:20:18 +02:00
print '<tr><td nowrap>' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td colspan="2">' ;
2009-02-21 18:43:02 +01:00
$html -> select_conditions_paiements ( isset ( $_POST [ 'cond_reglement_id' ]) ? $_POST [ 'cond_reglement_id' ] : $cond_reglement_id , 'cond_reglement_id' );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2009-02-21 18:43:02 +01:00
// Payment mode
2008-08-12 20:20:18 +02:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td colspan="2">' ;
2009-02-21 18:43:02 +01:00
$html -> select_types_paiements ( isset ( $_POST [ 'mode_reglement_id' ]) ? $_POST [ 'mode_reglement_id' ] : $mode_reglement_id , 'mode_reglement_id' );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2008-12-28 00:15:47 +01:00
// Project
2008-08-12 20:20:18 +02:00
if ( $conf -> projet -> enabled )
{
$langs -> load ( 'projects' );
print '<tr><td>' . $langs -> trans ( 'Project' ) . '</td><td colspan="2">' ;
2010-03-11 15:31:16 +01:00
select_projects ( $soc -> id , $projectid , 'projectid' );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
}
// Modele PDF
print '<tr><td>' . $langs -> trans ( 'Model' ) . '</td>' ;
print '<td>' ;
include_once ( DOL_DOCUMENT_ROOT . '/includes/modules/facture/modules_facture.php' );
$model = new ModelePDFFactures ();
$liste = $model -> liste_modeles ( $db );
2010-08-19 22:29:55 +02:00
print $html -> selectarray ( 'model' , $liste , $conf -> global -> FACTURE_ADDON_PDF );
2008-08-12 20:20:18 +02:00
print " </td></tr> " ;
// Note publique
print '<tr>' ;
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td valign="top" colspan="2">' ;
print '<textarea name="note_public" wrap="soft" cols="70" rows="' . ROWS_3 . '">' ;
2010-09-15 15:29:17 +02:00
if ( is_object ( $objectsrc )) // Take value from source object
2008-08-12 20:20:18 +02:00
{
2010-12-15 00:27:17 +01:00
print $objectsrc -> note_public ;
2008-08-12 20:20:18 +02:00
}
print '</textarea></td></tr>' ;
2009-09-11 17:43:16 +02:00
// Note privee
2008-08-12 20:20:18 +02:00
if ( ! $user -> societe_id )
{
print '<tr>' ;
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td valign="top" colspan="2">' ;
print '<textarea name="note" wrap="soft" cols="70" rows="' . ROWS_3 . '">' ;
2010-09-15 15:29:17 +02:00
if ( is_object ( $objectsrc )) // Take value from source object
2008-08-12 20:20:18 +02:00
{
2010-12-15 00:27:17 +01:00
print $objectsrc -> note ;
2008-08-12 20:20:18 +02:00
}
print '</textarea></td></tr>' ;
}
2010-09-15 15:29:17 +02:00
if ( is_object ( $objectsrc ))
2010-04-26 12:01:01 +02:00
{
2010-04-28 19:30:59 +02:00
// TODO for compatibility
if ( $_GET [ 'origin' ] == 'contrat' )
{
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
2010-12-15 00:27:17 +01:00
$objectsrc -> remise_absolue = $remise_absolue ;
$objectsrc -> remise_percent = $remise_percent ;
$objectsrc -> update_price ();
2010-04-28 19:30:59 +02:00
}
2010-05-01 16:28:48 +02:00
2010-04-26 12:01:01 +02:00
print " \n <!-- " . $classname . " info --> " ;
print " \n " ;
2010-12-15 00:27:17 +01:00
print '<input type="hidden" name="amount" value="' . $objectsrc -> total_ht . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $objectsrc -> total_ttc . '">' . " \n " ;
print '<input type="hidden" name="tva" value="' . $objectsrc -> total_tva . '">' . " \n " ;
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
print '<tr><td>' . $langs -> trans ( $classname ) . '</td><td colspan="2">' . $objectsrc -> getNomUrl ( 1 ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'TotalHT' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'TotalVAT' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_tva ) . " </td></tr> " ;
2010-07-15 09:23:04 +02:00
if ( $mysoc -> pays_code == 'ES' )
2010-06-21 18:49:41 +02:00
{
if ( $mysoc -> localtax1_assuj == " 1 " ) //Localtax1 RE
2010-07-15 00:23:14 +02:00
{
2010-12-15 00:27:17 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> pays_code ) . '</td><td colspan="2">' . price ( $objectsrc -> total_localtax1 ) . " </td></tr> " ;
2010-06-21 18:49:41 +02:00
}
2010-07-15 00:23:14 +02:00
2010-06-21 18:49:41 +02:00
if ( $mysoc -> localtax2_assuj == " 1 " ) //Localtax2 IRPF
{
2010-12-15 00:27:17 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> pays_code ) . '</td><td colspan="2">' . price ( $objectsrc -> total_localtax2 ) . " </td></tr> " ;
2010-07-15 00:23:14 +02:00
}
2010-06-21 18:49:41 +02:00
}
2010-12-15 00:27:17 +01:00
print '<tr><td>' . $langs -> trans ( 'TotalTTC' ) . '</td><td colspan="2">' . price ( $objectsrc -> total_ttc ) . " </td></tr> " ;
2010-04-26 12:01:01 +02:00
}
2008-08-12 20:20:18 +02:00
else
{
2009-04-21 21:24:12 +02:00
// Show deprecated optional form to add product line here
2008-08-12 20:20:18 +02:00
if ( $conf -> global -> PRODUCT_SHOW_WHEN_CREATE )
{
print '<tr><td colspan="3">' ;
2009-09-11 17:43:16 +02:00
// Zone de choix des produits predefinis a la creation
2009-04-21 21:24:12 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( 'ProductsAndServices' ) . '</td>' ;
2008-08-12 20:20:18 +02:00
print '<td>' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td> </td>' ;
if ( $conf -> service -> enabled )
{
print '<td>' . $langs -> trans ( 'ServiceLimitedDuration' ) . '</td>' ;
}
print '</tr>' ;
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
{
print '<tr>' ;
print '<td>' ;
// multiprix
2009-01-10 02:11:17 +01:00
if ( $conf -> global -> PRODUIT_MULTIPRICES )
2010-06-02 10:34:44 +02:00
$html -> select_produits ( '' , 'idprod' . $i , '' , $conf -> product -> limit_size , $soc -> price_level );
2008-08-12 20:20:18 +02:00
else
2010-06-02 10:34:44 +02:00
$html -> select_produits ( '' , 'idprod' . $i , '' , $conf -> product -> limit_size );
2008-08-12 20:20:18 +02:00
print '</td>' ;
print '<td><input type="text" size="2" name="qty' . $i . '" value="1"></td>' ;
print '<td nowrap="nowrap"><input type="text" size="1" name="remise_percent' . $i . '" value="' . $soc -> remise_client . '">%</td>' ;
print '<td> </td>' ;
2009-09-11 17:43:16 +02:00
// Si le module service est actif, on propose des dates de debut et fin a la ligne
2008-08-12 20:20:18 +02:00
if ( $conf -> service -> enabled )
{
print '<td nowrap="nowrap">' ;
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding" nowrap="nowrap">' ;
print $langs -> trans ( 'From' ) . ' ' ;
print '</td><td class="nobordernopadding" nowrap="nowrap">' ;
2008-10-02 00:24:31 +02:00
print $html -> select_date ( '' , 'date_start' . $i , $usehm , $usehm , 1 , " add " );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
print '<td class="nobordernopadding" nowrap="nowrap">' ;
print $langs -> trans ( 'to' ) . ' ' ;
print '</td><td class="nobordernopadding" nowrap="nowrap">' ;
2008-10-02 00:24:31 +02:00
print $html -> select_date ( '' , 'date_end' . $i , $usehm , $usehm , 1 , " add " );
2008-08-12 20:20:18 +02:00
print '</td></tr></table>' ;
print '</td>' ;
}
print " </tr> \n " ;
}
print '</table>' ;
print '</td></tr>' ;
}
}
// Bouton "Create Draft"
print " </table> \n " ;
2010-12-01 23:14:15 +01:00
print '<br><center><input type="submit" class="button" name="bouton" value="' . $langs -> trans ( 'CreateDraft' ) . '"></center>' ;
2008-08-12 20:20:18 +02:00
print " </form> \n " ;
2010-12-17 11:08:31 +01:00
// Show origin lines
if ( is_object ( $objectsrc ))
2008-08-12 20:20:18 +02:00
{
2010-12-14 10:12:06 +01:00
$title = $langs -> trans ( 'ProductsAndServices' );
print_titre ( $title );
2011-02-19 13:15:17 +01:00
2010-12-14 10:12:06 +01:00
print '<table class="noborder" width="100%">' ;
2011-02-19 13:15:17 +01:00
2010-12-17 11:08:31 +01:00
$objectsrc -> printOriginTitleList ();
$objectsrc -> printOriginLinesList ( $object );
2010-12-14 10:12:06 +01:00
print '</table>' ;
2008-08-12 20:20:18 +02:00
}
}
else
{
2009-01-14 16:53:52 +01:00
/*
* Show object in view mode
*/
2010-08-09 19:16:26 +02:00
$id = $facid ;
2010-12-14 00:38:47 +01:00
$ref = GETPOST ( 'ref' );
2010-05-12 13:29:21 +02:00
2008-11-05 23:34:14 +01:00
if ( $id > 0 || ! empty ( $ref ))
2008-08-12 20:20:18 +02:00
{
if ( $mesg ) print $mesg . '<br>' ;
2010-09-09 18:02:55 +02:00
$result = $object -> fetch ( $id , $ref );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
2010-09-09 18:02:55 +02:00
if ( $user -> societe_id > 0 && $user -> societe_id != $object -> socid ) accessforbidden ( '' , 0 );
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$result = $object -> fetch_thirdparty ();
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$soc = new Societe ( $db , $object -> socid );
$soc -> fetch ( $object -> socid );
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$totalpaye = $object -> getSommePaiement ();
$totalcreditnotes = $object -> getSumCreditNotesUsed ();
$totaldeposits = $object -> getSumDepositsUsed ();
2009-03-02 22:21:49 +01:00
//print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
2008-08-12 20:20:18 +02:00
2010-09-05 15:24:59 +02:00
// We can also use bcadd to avoid pb with floating points
2008-08-12 20:20:18 +02:00
// For example print 239.2 - 229.3 - 9.9; does not return 0.
2010-09-09 18:02:55 +02:00
//$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
2008-08-12 20:20:18 +02:00
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
2010-09-09 18:02:55 +02:00
$resteapayer = price2num ( $object -> total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits , 'MT' );
2009-01-14 16:53:52 +01:00
2010-09-09 18:02:55 +02:00
if ( $object -> paye ) $resteapayer = 0 ;
2008-08-12 20:20:18 +02:00
$resteapayeraffiche = $resteapayer ;
$absolute_discount = $soc -> getAvailableDiscounts ( '' , 'fk_facture_source IS NULL' );
$absolute_creditnote = $soc -> getAvailableDiscounts ( '' , 'fk_facture_source IS NOT NULL' );
2009-05-07 14:13:34 +02:00
$absolute_discount = price2num ( $absolute_discount , 'MT' );
$absolute_creditnote = price2num ( $absolute_creditnote , 'MT' );
2009-01-14 16:53:52 +01:00
2008-08-12 20:20:18 +02:00
$author = new User ( $db );
2010-09-09 18:02:55 +02:00
if ( $object -> user_author )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$author -> fetch ( $object -> user_author );
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
$objectidnext = $object -> getIdReplacingInvoice ();
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
$head = facture_prepare_head ( $object );
2008-08-12 20:20:18 +02:00
2009-08-05 20:22:40 +02:00
dol_fiche_head ( $head , 'compta' , $langs -> trans ( 'InvoiceCustomer' ), 0 , 'bill' );
2008-08-12 20:20:18 +02:00
2008-11-20 22:30:23 +01:00
// Confirmation de la conversion de l'avoir en reduc
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] == 'converttoreduc' )
{
$text = $langs -> trans ( 'ConfirmConvertToReduc' );
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'ConvertToReduc' ), $text , 'confirm_converttoreduc' , '' , " yes " , 2 );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2010-08-18 20:58:14 +02:00
// Confirmation to delete invoice
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] == 'delete' )
{
$text = $langs -> trans ( 'ConfirmDeleteBill' );
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'DeleteBill' ), $text , 'confirm_delete' , '' , 0 , 1 );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2008-11-20 22:30:23 +01:00
// Confirmation de la validation
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] == 'valid' )
{
2010-01-09 15:48:27 +01:00
// on verifie si l'objet est en numerotation provisoire
2010-09-09 18:02:55 +02:00
$objectref = substr ( $object -> ref , 1 , 4 );
if ( $objectref == 'PROV' )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$savdate = $object -> date ;
2010-04-28 17:31:49 +02:00
if ( ! empty ( $conf -> global -> FAC_FORCE_DATE_VALIDATION ))
2009-03-09 19:40:16 +01:00
{
2010-09-09 18:02:55 +02:00
$object -> date = gmmktime ();
$object -> date_lim_reglement = $object -> calculate_date_lim_reglement ();
2009-03-09 19:40:16 +01:00
}
2010-09-09 18:02:55 +02:00
$numref = $object -> getNextNumRef ( $soc );
//$object->date=$savdate;
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
$numref = $object -> ref ;
2008-08-12 20:20:18 +02:00
}
2010-01-09 15:48:27 +01:00
$text = $langs -> trans ( 'ConfirmValidateBill' , $numref );
2008-08-12 20:20:18 +02:00
if ( $conf -> notification -> enabled )
{
2010-04-28 12:11:41 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /core/class/notify.class.php " );
2008-08-12 20:20:18 +02:00
$notify = new Notify ( $db );
$text .= '<br>' ;
2010-09-09 18:02:55 +02:00
$text .= $notify -> confirmMessage ( 'NOTIFY_VAL_FAC' , $object -> socid );
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ValidateBill' ), $text , 'confirm_valid' , '' , " yes " ,( $conf -> notification -> enabled ? 0 : 2 ));
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2009-09-11 17:43:16 +02:00
// Confirmation du classement paye
2009-08-19 19:16:47 +02:00
if ( $_GET [ 'action' ] == 'paid' && $resteapayer <= 0 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ClassifyPaid' ), $langs -> trans ( 'ConfirmClassifyPaidBill' , $object -> ref ), 'confirm_paid' , '' , " yes " , 1 );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2009-08-19 19:16:47 +02:00
if ( $_GET [ 'action' ] == 'paid' && $resteapayer > 0 )
2008-08-12 20:20:18 +02:00
{
// Code
$i = 0 ;
$close [ $i ][ 'code' ] = 'discount_vat' ; $i ++ ;
$close [ $i ][ 'code' ] = 'badcustomer' ; $i ++ ;
// Help
$i = 0 ;
2009-08-19 19:16:47 +02:00
$close [ $i ][ 'label' ] = $langs -> trans ( " HelpEscompte " ) . '<br><br>' . $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonDiscountVatDesc " ); $i ++ ;
$close [ $i ][ 'label' ] = $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonBadCustomerDesc " ); $i ++ ;
2008-08-12 20:20:18 +02:00
// Texte
$i = 0 ;
2009-08-19 19:16:47 +02:00
$close [ $i ][ 'reason' ] = $html -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonDiscountVat " , $resteapayer , $langs -> trans ( " Currency " . $conf -> monnaie )), $close [ $i ][ 'label' ], 1 ); $i ++ ;
$close [ $i ][ 'reason' ] = $html -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonBadCustomer " , $resteapayer , $langs -> trans ( " Currency " . $conf -> monnaie )), $close [ $i ][ 'label' ], 1 ); $i ++ ;
2008-08-12 20:20:18 +02:00
// arrayreasons[code]=reason
foreach ( $close as $key => $val )
{
$arrayreasons [ $close [ $key ][ 'code' ]] = $close [ $key ][ 'reason' ];
}
2009-09-11 17:43:16 +02:00
// Cree un tableau formulaire
2008-08-12 20:20:18 +02:00
$formquestion = array (
2009-08-19 19:16:47 +02:00
'text' => $langs -> trans ( " ConfirmClassifyPaidPartiallyQuestion " ),
2008-08-12 20:20:18 +02:00
array ( 'type' => 'radio' , 'name' => 'close_code' , 'label' => $langs -> trans ( " Reason " ), 'values' => $arrayreasons ),
array ( 'type' => 'text' , 'name' => 'close_note' , 'label' => $langs -> trans ( " Comment " ), 'value' => '' , 'size' => '100' )
);
// Paiement incomplet. On demande si motif = escompte ou autre
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'ClassifyPaid' ), $langs -> trans ( 'ConfirmClassifyPaidPartially' , $object -> ref ), 'confirm_paid_partially' , $formquestion , " yes " );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2008-11-20 22:30:23 +01:00
// Confirmation du classement abandonne
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] == 'canceled' )
{
2009-09-11 17:43:16 +02:00
// S'il y a une facture de remplacement pas encore validee (etat brouillon),
2008-08-12 20:20:18 +02:00
// on ne permet pas de classer abandonner la facture.
2010-09-09 18:02:55 +02:00
if ( $objectidnext )
2008-08-12 20:20:18 +02:00
{
$facturereplacement = new Facture ( $db );
2010-09-09 18:02:55 +02:00
$facturereplacement -> fetch ( $objectidnext );
2008-08-12 20:20:18 +02:00
$statusreplacement = $facturereplacement -> statut ;
}
2010-09-09 18:02:55 +02:00
if ( $objectidnext && $statusreplacement == 0 )
2008-08-12 20:20:18 +02:00
{
print '<div class="error">' . $langs -> trans ( " ErrorCantCancelIfReplacementInvoiceNotValidated " ) . '</div>' ;
}
else
{
// Code
$close [ 1 ][ 'code' ] = 'badcustomer' ;
$close [ 2 ][ 'code' ] = 'abandon' ;
// Help
2009-08-19 19:16:47 +02:00
$close [ 1 ][ 'label' ] = $langs -> trans ( " ConfirmClassifyPaidPartiallyReasonBadCustomerDesc " );
2008-08-12 20:20:18 +02:00
$close [ 2 ][ 'label' ] = $langs -> trans ( " ConfirmClassifyAbandonReasonOtherDesc " );
// Texte
2010-09-09 18:02:55 +02:00
$close [ 1 ][ 'reason' ] = $html -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyPaidPartiallyReasonBadCustomer " , $object -> ref ), $close [ 1 ][ 'label' ], 1 );
2009-05-04 21:02:32 +02:00
$close [ 2 ][ 'reason' ] = $html -> textwithpicto ( $langs -> transnoentities ( " ConfirmClassifyAbandonReasonOther " ), $close [ 2 ][ 'label' ], 1 );
2008-08-12 20:20:18 +02:00
// arrayreasons
$arrayreasons [ $close [ 1 ][ 'code' ]] = $close [ 1 ][ 'reason' ];
$arrayreasons [ $close [ 2 ][ 'code' ]] = $close [ 2 ][ 'reason' ];
2009-09-11 17:43:16 +02:00
// Cree un tableau formulaire
2008-08-12 20:20:18 +02:00
$formquestion = array (
'text' => $langs -> trans ( " ConfirmCancelBillQuestion " ),
array ( 'type' => 'radio' , 'name' => 'close_code' , 'label' => $langs -> trans ( " Reason " ), 'values' => $arrayreasons ),
array ( 'type' => 'text' , 'name' => 'close_note' , 'label' => $langs -> trans ( " Comment " ), 'value' => '' , 'size' => '100' )
);
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $langs -> trans ( 'CancelBill' ), $langs -> trans ( 'ConfirmCancelBill' , $object -> ref ), 'confirm_canceled' , $formquestion , " yes " );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
}
2008-11-20 22:30:23 +01:00
// Confirmation de la suppression d'une ligne produit
2010-09-10 16:35:07 +02:00
if ( $_GET [ 'action' ] == 'ask_deleteline' )
2008-08-12 20:20:18 +02:00
{
2010-09-10 16:35:07 +02:00
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&lineid=' . $_GET [ " lineid " ], $langs -> trans ( 'DeleteProductLine' ), $langs -> trans ( 'ConfirmDeleteProductLine' ), 'confirm_deleteline' , '' , 'no' , 1 );
if ( $ret == 'html' ) print '<br>' ;
}
2010-09-12 20:01:29 +02:00
2010-09-10 16:35:07 +02:00
/*
* TODO ajout temporaire pour test en attendant la migration en template
*/
if ( $_GET [ 'action' ] == 'ask_deletemilestone' )
{
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&lineid=' . $_GET [ " lineid " ], $langs -> trans ( 'DeleteMilestone' ), $langs -> trans ( 'ConfirmDeleteMilestone' ), 'confirm_deletemilestone' , '' , 0 , 1 );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-08-12 20:20:18 +02:00
}
2008-12-02 00:09:52 +01:00
// Clone confirmation
2008-11-20 22:30:23 +01:00
if ( $_GET [ " action " ] == 'clone' )
{
// Create an array for form
$formquestion = array (
2008-12-02 00:09:52 +01:00
//'text' => $langs->trans("ConfirmClone"),
//array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
2008-11-20 22:30:23 +01:00
);
// Paiement incomplet. On demande si motif = escompte ou autre
2010-09-09 18:02:55 +02:00
$ret = $html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , $langs -> trans ( 'CloneInvoice' ), $langs -> trans ( 'ConfirmCloneInvoice' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 );
2009-05-06 15:39:43 +02:00
if ( $ret == 'html' ) print '<br>' ;
2008-11-20 22:30:23 +01:00
}
2009-01-14 16:53:52 +01:00
2008-11-20 22:30:23 +01:00
// Invoice content
2008-08-12 20:20:18 +02:00
print '<table class="border" width="100%">' ;
2009-03-02 22:21:49 +01:00
// Ref
2008-08-12 20:20:18 +02:00
print '<tr><td width="20%">' . $langs -> trans ( 'Ref' ) . '</td>' ;
2008-11-05 23:34:14 +01:00
print '<td colspan="5">' ;
$morehtmlref = '' ;
2008-08-12 20:20:18 +02:00
$discount = new DiscountAbsolute ( $db );
2010-09-09 18:02:55 +02:00
$result = $discount -> fetch ( 0 , $object -> id );
2008-08-12 20:20:18 +02:00
if ( $result > 0 )
{
2008-11-05 23:34:14 +01:00
$morehtmlref = ' (' . $langs -> trans ( " CreditNoteConvertedIntoDiscount " , $discount -> getNomUrl ( 1 , 'discount' )) . ')' ;
2008-08-12 20:20:18 +02:00
}
if ( $result < 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( '' , $discount -> error );
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
print $html -> showrefnav ( $object , 'ref' , '' , 1 , 'facnumber' , 'ref' , $morehtmlref );
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2009-03-02 17:06:52 +01:00
// Third party
2008-08-12 20:20:18 +02:00
print '<tr><td>' . $langs -> trans ( 'Company' ) . '</td>' ;
2010-02-16 09:57:07 +01:00
print '<td colspan="5">' . $soc -> getNomUrl ( 1 , 'compta' );
2010-09-09 18:02:55 +02:00
print ' (<a href="' . DOL_URL_ROOT . '/compta/facture.php?socid=' . $object -> socid . '">' . $langs -> trans ( 'OtherBills' ) . '</a>)</td>' ;
2008-08-12 20:20:18 +02:00
print '</tr>' ;
// Type
print '<tr><td>' . $langs -> trans ( 'Type' ) . '</td><td colspan="5">' ;
2010-09-09 18:02:55 +02:00
print $object -> getLibType ();
if ( $object -> type == 1 )
2008-08-12 20:20:18 +02:00
{
$facreplaced = new Facture ( $db );
2010-09-09 18:02:55 +02:00
$facreplaced -> fetch ( $object -> fk_facture_source );
2008-08-12 20:20:18 +02:00
print ' (' . $langs -> transnoentities ( " ReplaceInvoice " , $facreplaced -> getNomUrl ( 1 )) . ')' ;
}
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 )
2008-08-12 20:20:18 +02:00
{
2009-03-02 19:17:19 +01:00
$facusing = new Facture ( $db );
2010-09-09 18:02:55 +02:00
$facusing -> fetch ( $object -> fk_facture_source );
2009-03-02 19:17:19 +01:00
print ' (' . $langs -> transnoentities ( " CorrectInvoice " , $facusing -> getNomUrl ( 1 )) . ')' ;
2008-08-12 20:20:18 +02:00
}
2009-03-02 19:17:19 +01:00
2010-09-09 18:57:53 +02:00
$facidavoir = $object -> getListIdAvoirFromInvoice ();
2008-08-12 20:20:18 +02:00
if ( sizeof ( $facidavoir ) > 0 )
{
print ' (' . $langs -> transnoentities ( " InvoiceHasAvoir " );
$i = 0 ;
foreach ( $facidavoir as $id )
{
if ( $i == 0 ) print ' ' ;
else print ',' ;
$facavoir = new Facture ( $db );
$facavoir -> fetch ( $id );
print $facavoir -> getNomUrl ( 1 );
}
print ')' ;
}
2010-09-09 18:02:55 +02:00
if ( $objectidnext > 0 )
2008-08-12 20:20:18 +02:00
{
$facthatreplace = new Facture ( $db );
2010-09-09 18:02:55 +02:00
$facthatreplace -> fetch ( $objectidnext );
2008-08-12 20:20:18 +02:00
print ' (' . $langs -> transnoentities ( " ReplacedByInvoice " , $facthatreplace -> getNomUrl ( 1 )) . ')' ;
}
print '</td></tr>' ;
2011-02-19 13:15:17 +01:00
// Relative and absolute discounts
2011-02-19 14:23:49 +01:00
$addabsolutediscount = ' <a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc -> id . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ]) . '?facid=' . $object -> id . '">' . $langs -> trans ( " AddGlobalDiscount " ) . '</a>' ;
$addcreditnote = ' <a href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&socid=' . $soc -> id . '&type=2&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ]) . '?facid=' . $object -> id . '">' . $langs -> trans ( " AddCreditNote " ) . '</a>' ;
print '<tr><td>' . $langs -> trans ( 'Discounts' );
2011-02-19 13:15:17 +01:00
print '</td><td colspan="5">' ;
2008-08-12 20:20:18 +02:00
if ( $soc -> remise_client ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_client );
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
2011-02-19 13:15:17 +01:00
2008-08-12 20:20:18 +02:00
if ( $absolute_discount > 0 )
{
2011-02-19 14:23:49 +01:00
print '. ' ;
if ( $object -> statut > 0 || $object -> type == 2 || $object -> type == 3 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 0 )
2009-03-02 19:17:19 +01:00
{
2011-02-19 13:15:17 +01:00
print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> transnoentities ( " Currency " . $conf -> monnaie ));
print '. ' ;
2009-03-02 19:17:19 +01:00
}
else
{
2010-09-09 18:02:55 +02:00
if ( $object -> statut < 1 || $object -> type == 2 || $object -> type == 3 )
2009-08-07 02:49:43 +02:00
{
$text = $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> transnoentities ( " Currency " . $conf -> monnaie ));
print '<br>' . $text . '.<br>' ;
}
else
{
$text = $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> transnoentities ( " Currency " . $conf -> monnaie ));
$text2 = $langs -> trans ( " AbsoluteDiscountUse " );
print $html -> textwithpicto ( $text , $text2 );
}
2009-03-02 19:17:19 +01:00
}
2008-08-12 20:20:18 +02:00
}
else
{
2011-02-19 13:15:17 +01:00
// Remise dispo de type remise fixe (not credit note)
2008-08-12 20:20:18 +02:00
$filter = 'fk_facture_source IS NULL' ;
print '<br>' ;
2011-02-19 14:23:49 +01:00
$html -> form_remise_dispo ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , 0 , 'remise_id' , $soc -> id , $absolute_discount , $filter , $resteapayer , ' - ' . $addabsolutediscount );
2008-08-12 20:20:18 +02:00
}
}
2011-02-19 14:23:49 +01:00
else
{
2011-02-19 14:38:02 +01:00
if ( $absolute_creditnote > 0 ) // If not linke will be added later
{
if ( $object -> statut == 0 && $object -> type != 2 && $object -> type != 3 ) print ' - ' . $addabsolutediscount . '<br>' ;
}
print '. ' ;
2011-02-19 14:23:49 +01:00
}
2008-08-12 20:20:18 +02:00
if ( $absolute_creditnote > 0 )
{
2011-02-19 14:38:02 +01:00
// If validated, we show link "add credit note to payment"
2010-09-09 18:02:55 +02:00
if ( $object -> statut != 1 || $object -> type == 2 || $object -> type == 3 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 0 && $object -> type != 3 )
2009-03-02 19:17:19 +01:00
{
$text = $langs -> trans ( " CompanyHasCreditNote " , price ( $absolute_creditnote ), $langs -> transnoentities ( " Currency " . $conf -> monnaie ));
2009-05-04 21:02:32 +02:00
print $html -> textwithpicto ( $text , $langs -> trans ( " CreditNoteDepositUse " ));
2009-03-02 19:17:19 +01:00
}
2011-02-19 13:15:17 +01:00
else
{
print $langs -> trans ( " CompanyHasCreditNote " , price ( $absolute_creditnote ), $langs -> transnoentities ( " Currency " . $conf -> monnaie )) . '.' ;
}
2008-08-12 20:20:18 +02:00
}
else
{
// Remise dispo de type avoir
$filter = 'fk_facture_source IS NOT NULL' ;
if ( ! $absolute_discount ) print '<br>' ;
2011-02-19 13:15:17 +01:00
$html -> form_remise_dispo ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , 0 , 'remise_id_for_payment' , $soc -> id , $absolute_creditnote , $filter , $resteapayer );
2008-08-12 20:20:18 +02:00
}
}
2011-02-19 13:15:17 +01:00
if ( ! $absolute_discount && ! $absolute_creditnote )
{
2011-02-19 14:38:02 +01:00
print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
if ( $object -> statut == 0 && $object -> type != 2 && $object -> type != 3 ) print ' - ' . $addabsolutediscount . '<br>' ;
else print '. ' ;
2011-02-19 13:15:17 +01:00
}
2011-02-19 14:23:49 +01:00
/* if ( $object -> statut == 0 && $object -> type != 2 && $object -> type != 3 )
2011-02-19 13:15:17 +01:00
{
if ( ! $absolute_discount && ! $absolute_creditnote ) print '<br>' ;
2011-02-19 14:23:49 +01:00
//print ' - ';
print $addabsolutediscount ;
//print ' - '.$addcreditnote; // We disbale link to credit note
} */
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2009-01-02 17:08:15 +01:00
// Date invoice
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Date' );
print '</td>' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 && $_GET [ 'action' ] != 'editinvoicedate' && $object -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editinvoicedate&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2009-01-02 17:08:15 +01:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2010-01-13 19:51:19 +01:00
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 )
2009-01-02 17:08:15 +01:00
{
if ( $_GET [ 'action' ] == 'editinvoicedate' )
{
2010-09-09 18:02:55 +02:00
$html -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> date , 'invoicedate' );
2009-01-02 17:08:15 +01:00
}
else
{
2010-09-09 18:02:55 +02:00
print dol_print_date ( $object -> date , 'daytext' );
2009-01-02 17:08:15 +01:00
}
}
else
{
2010-09-09 18:02:55 +02:00
print dol_print_date ( $object -> date , 'daytext' );
2009-01-02 17:08:15 +01:00
}
print '</td>' ;
2009-01-14 16:53:52 +01:00
2009-07-19 17:39:25 +02:00
/*
* List of payments
*/
2008-08-12 20:20:18 +02:00
$nbrows = 8 ;
if ( $conf -> projet -> enabled ) $nbrows ++ ;
2010-04-28 15:49:13 +02:00
2010-04-24 18:00:48 +02:00
//Local taxes
2010-07-15 09:23:04 +02:00
if ( $mysoc -> pays_code == 'ES' )
2010-04-24 18:00:48 +02:00
{
if ( $mysoc -> localtax1_assuj == " 1 " ) $nbrows ++ ;
if ( $mysoc -> localtax2_assuj == " 1 " ) $nbrows ++ ;
}
2008-08-12 20:20:18 +02:00
print '<td rowspan="' . $nbrows . '" colspan="2" valign="top">' ;
2009-07-19 17:39:25 +02:00
print '<table class="nobordernopadding" width="100%">' ;
2009-03-02 19:17:19 +01:00
// List of payments already done
print '<tr class="liste_titre">' ;
2010-09-09 18:02:55 +02:00
print '<td>' . ( $object -> type == 2 ? $langs -> trans ( " PaymentsBack " ) : $langs -> trans ( 'Payments' )) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td>' . $langs -> trans ( 'Type' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Amount' ) . '</td>' ;
print '<td width="18"> </td>' ;
print '</tr>' ;
$var = true ;
// Payments already done (from payment on this invoice)
2010-07-25 23:23:57 +02:00
$sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid,' ;
$sql .= ' c.code as payment_code, c.libelle as payment_label,' ;
$sql .= ' pf.amount' ;
2008-08-12 20:20:18 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement as p, ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf' ;
2010-09-09 18:02:55 +02:00
$sql .= ' WHERE pf.fk_facture = ' . $object -> id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid' ;
2008-08-12 20:20:18 +02:00
$sql .= ' ORDER BY dp, tms' ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
2009-01-14 16:53:52 +01:00
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 )
2008-08-12 20:20:18 +02:00
{
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '><td>' ;
print '<a href="' . DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $objp -> rowid . '">' . img_object ( $langs -> trans ( 'ShowPayment' ), 'payment' ) . ' ' ;
2010-05-08 21:21:57 +02:00
print dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . '</a></td>' ;
2010-08-14 03:50:57 +02:00
$label = ( $langs -> trans ( " PaymentType " . $objp -> payment_code ) != ( " PaymentType " . $objp -> payment_code )) ? $langs -> trans ( " PaymentType " . $objp -> payment_code ) : $objp -> payment_label ;
2010-07-25 23:23:57 +02:00
print '<td>' . $label . ' ' . $objp -> num_paiement . '</td>' ;
2008-08-12 20:20:18 +02:00
print '<td align="right">' . price ( $objp -> amount ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
$i ++ ;
}
2009-03-02 19:17:19 +01:00
}
$db -> free ( $result );
}
else
{
dol_print_error ( $db );
}
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 )
2009-03-02 19:17:19 +01:00
{
2009-08-19 19:16:47 +02:00
// Total already paid
2009-03-02 19:17:19 +01:00
print '<tr><td colspan="2" align="right">' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 3 ) print $langs -> trans ( 'AlreadyPaidNoCreditNotesNoDeposits' );
2009-08-19 19:16:47 +02:00
else print $langs -> trans ( 'AlreadyPaid' );
2009-03-02 19:17:19 +01:00
print ' :</td><td align="right">' . price ( $totalpaye ) . '</td><td> </td></tr>' ;
$resteapayeraffiche = $resteapayer ;
// Loop on each credit note or deposit amount applied
$creditnoteamount = 0 ;
$depositamount = 0 ;
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
$sql .= " re.description, re.fk_facture_source, re.fk_facture_source " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
2010-09-09 18:02:55 +02:00
$sql .= " WHERE fk_facture = " . $object -> id ;
2009-03-02 19:17:19 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
$invoice = new Facture ( $db );
while ( $i < $num )
2008-08-12 20:20:18 +02:00
{
2009-03-02 19:17:19 +01:00
$obj = $db -> fetch_object ( $resql );
$invoice -> fetch ( $obj -> fk_facture_source );
print '<tr><td colspan="2" align="right">' ;
if ( $invoice -> type == 2 ) print $langs -> trans ( " CreditNote " ) . ' ' ;
if ( $invoice -> type == 3 ) print $langs -> trans ( " Deposit " ) . ' ' ;
print $invoice -> getNomUrl ( 0 );
print ' :</td>' ;
print '<td align="right">' . price ( $obj -> amount_ttc ) . '</td>' ;
print '<td align="right">' ;
2010-09-09 18:02:55 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=unlinkdiscount&discountid=' . $obj -> rowid . '">' . img_delete () . '</a>' ;
2009-03-02 19:17:19 +01:00
print '</td></tr>' ;
$i ++ ;
if ( $invoice -> type == 2 ) $creditnoteamount += $obj -> amount_ttc ;
if ( $invoice -> type == 3 ) $depositamount += $obj -> amount_ttc ;
2008-08-12 20:20:18 +02:00
}
}
else
{
2009-03-02 19:17:19 +01:00
dol_print_error ( $db );
2008-08-12 20:20:18 +02:00
}
2009-03-02 19:17:19 +01:00
2009-09-11 17:43:16 +02:00
// Paye partiellement 'escompte'
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 2 || $object -> statut == 3 ) && $object -> close_code == 'discount_vat' )
2009-03-02 19:17:19 +01:00
{
print '<tr><td colspan="2" align="right" nowrap="1">' ;
2009-05-04 21:02:32 +02:00
print $html -> textwithpicto ( $langs -> trans ( " Escompte " ) . ':' , $langs -> trans ( " HelpEscompte " ), - 1 );
2010-09-09 18:02:55 +02:00
print '</td><td align="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2009-03-02 19:17:19 +01:00
$resteapayeraffiche = 0 ;
}
2009-09-11 17:43:16 +02:00
// Paye partiellement ou Abandon 'badcustomer'
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 2 || $object -> statut == 3 ) && $object -> close_code == 'badcustomer' )
2009-03-02 19:17:19 +01:00
{
print '<tr><td colspan="2" align="right" nowrap="1">' ;
2009-05-04 21:02:32 +02:00
print $html -> textwithpicto ( $langs -> trans ( " Abandoned " ) . ':' , $langs -> trans ( " HelpAbandonBadCustomer " ), - 1 );
2010-09-09 18:02:55 +02:00
print '</td><td align="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2009-03-02 19:17:19 +01:00
//$resteapayeraffiche=0;
}
2009-09-11 17:43:16 +02:00
// Paye partiellement ou Abandon 'product_returned'
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 2 || $object -> statut == 3 ) && $object -> close_code == 'product_returned' )
2009-03-02 19:17:19 +01:00
{
print '<tr><td colspan="2" align="right" nowrap="1">' ;
2009-05-04 21:02:32 +02:00
print $html -> textwithpicto ( $langs -> trans ( " ProductReturned " ) . ':' , $langs -> trans ( " HelpAbandonProductReturned " ), - 1 );
2010-09-09 18:02:55 +02:00
print '</td><td align="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2009-03-02 19:17:19 +01:00
$resteapayeraffiche = 0 ;
}
2009-09-11 17:43:16 +02:00
// Paye partiellement ou Abandon 'abandon'
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 2 || $object -> statut == 3 ) && $object -> close_code == 'abandon' )
2009-03-02 19:17:19 +01:00
{
print '<tr><td colspan="2" align="right" nowrap="1">' ;
$text = $langs -> trans ( " HelpAbandonOther " );
2010-09-09 18:02:55 +02:00
if ( $object -> close_note ) $text .= '<br><br><b>' . $langs -> trans ( " Reason " ) . '</b>:' . $object -> close_note ;
2009-05-04 21:02:32 +02:00
print $html -> textwithpicto ( $langs -> trans ( " Abandoned " ) . ':' , $text , - 1 );
2010-09-09 18:02:55 +02:00
print '</td><td align="right">' . price ( $object -> total_ttc - $creditnoteamount - $depositamount - $totalpaye ) . '</td><td> </td></tr>' ;
2009-03-02 19:17:19 +01:00
$resteapayeraffiche = 0 ;
}
// Billed
2010-09-09 18:02:55 +02:00
print '<tr><td colspan="2" align="right">' . $langs -> trans ( " Billed " ) . ' :</td><td align="right" style="border: 1px solid;">' . price ( $object -> total_ttc ) . '</td><td> </td></tr>' ;
2009-03-02 19:17:19 +01:00
// Remainder to pay
print '<tr><td colspan="2" align="right">' ;
if ( $resteapayeraffiche >= 0 ) print $langs -> trans ( 'RemainderToPay' );
else print $langs -> trans ( 'ExcessReceived' );
print ' :</td>' ;
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price ( $resteapayeraffiche ) . '</b></td>' ;
print '<td nowrap="nowrap"> </td></tr>' ;
2008-08-12 20:20:18 +02:00
}
else
{
2009-03-02 19:17:19 +01:00
// Sold credit note
print '<tr><td colspan="2" align="right">' . $langs -> trans ( 'TotalTTCToYourCredit' ) . ' :</td>' ;
2010-09-09 18:02:55 +02:00
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price ( abs ( $object -> total_ttc )) . '</b></td><td> </td></tr>' ;
2008-08-12 20:20:18 +02:00
}
2009-03-02 19:17:19 +01:00
print '</table>' ;
2008-08-12 20:20:18 +02:00
print '</td></tr>' ;
2009-01-02 17:08:15 +01:00
// Date payment term
2008-11-20 22:30:23 +01:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'DateMaxPayment' );
print '</td>' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 && $_GET [ 'action' ] != 'editpaymentterm' && $object -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editpaymentterm&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2008-11-20 22:30:23 +01:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 )
2008-08-12 20:20:18 +02:00
{
2008-11-20 22:30:23 +01:00
if ( $_GET [ 'action' ] == 'editpaymentterm' )
{
2010-09-09 18:02:55 +02:00
$html -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> date_lim_reglement , 'paymentterm' );
2008-11-20 22:30:23 +01:00
}
else
{
2010-09-09 18:02:55 +02:00
print dol_print_date ( $object -> date_lim_reglement , 'daytext' );
if ( $object -> date_lim_reglement < ( $now - $conf -> facture -> client -> warning_delay ) && ! $object -> paye && $object -> statut == 1 && ! $object -> am ) print img_warning ( $langs -> trans ( 'Late' ));
2008-11-20 22:30:23 +01:00
}
2008-08-12 20:20:18 +02:00
}
else
{
print ' ' ;
}
print '</td></tr>' ;
2009-09-11 17:43:16 +02:00
// Conditions de reglement
2008-08-12 20:20:18 +02:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'PaymentConditionsShort' );
print '</td>' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 && $_GET [ 'action' ] != 'editconditions' && $object -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
2008-08-12 20:20:18 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 )
2008-08-12 20:20:18 +02:00
{
if ( $_GET [ 'action' ] == 'editconditions' )
{
2010-09-09 18:02:55 +02:00
$html -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> cond_reglement_id , 'cond_reglement_id' );
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
$html -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> cond_reglement_id , 'none' );
2008-08-12 20:20:18 +02:00
}
}
else
{
print ' ' ;
}
print '</td></tr>' ;
// Mode de reglement
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
2010-09-09 18:02:55 +02:00
if ( $_GET [ 'action' ] != 'editmode' && $object -> brouillon && $user -> rights -> facture -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
2008-08-12 20:20:18 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $_GET [ 'action' ] == 'editmode' )
{
2010-09-09 18:02:55 +02:00
$html -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> mode_reglement_id , 'mode_reglement_id' );
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
$html -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> mode_reglement_id , 'none' );
2008-08-12 20:20:18 +02:00
}
print '</td></tr>' ;
// Montants
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
2010-09-09 18:02:55 +02:00
print '<td align="right" colspan="2" nowrap>' . price ( $object -> total_ht ) . '</td>' ;
2008-08-12 20:20:18 +02:00
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2010-09-09 18:02:55 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td align="right" colspan="2" nowrap>' . price ( $object -> total_tva ) . '</td>' ;
2008-08-12 20:20:18 +02:00
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2010-04-28 15:49:13 +02:00
2010-04-24 18:00:48 +02:00
// Amount Local Taxes
2010-07-15 09:23:04 +02:00
if ( $mysoc -> pays_code == 'ES' )
2010-04-24 18:00:48 +02:00
{
if ( $mysoc -> localtax1_assuj == " 1 " ) //Localtax1 RE
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> pays_code ) . '</td>' ;
2010-09-09 18:02:55 +02:00
print '<td align="right" colspan="2" nowrap>' . price ( $object -> total_localtax1 ) . '</td>' ;
2010-04-24 18:00:48 +02:00
print '<td>' . $langs -> trans ( " Currency " . $conf -> monnaie ) . '</td></tr>' ;
}
if ( $mysoc -> localtax2_assuj == " 1 " ) //Localtax2 IRPF
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> pays_code ) . '</td>' ;
2010-09-09 18:02:55 +02:00
print '<td align="right" colspan="2" nowrap>' . price ( $object -> total_localtax2 ) . '</td>' ;
2010-04-24 18:00:48 +02:00
print '<td>' . $langs -> trans ( " Currency " . $conf -> monnaie ) . '</td></tr>' ;
}
}
2010-04-28 15:49:13 +02:00
2010-09-09 18:02:55 +02:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td align="right" colspan="2" nowrap>' . price ( $object -> total_ttc ) . '</td>' ;
2008-08-12 20:20:18 +02:00
print '<td>' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
// Statut
print '<tr><td>' . $langs -> trans ( 'Status' ) . '</td>' ;
2010-09-09 18:02:55 +02:00
print '<td align="left" colspan="3">' . ( $object -> getLibStatut ( 4 , $totalpaye )) . '</td></tr>' ;
2008-08-12 20:20:18 +02:00
2008-12-28 00:40:25 +01:00
// Project
2008-08-12 20:20:18 +02:00
if ( $conf -> projet -> enabled )
{
$langs -> load ( 'projects' );
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Project' );
print '</td>' ;
2009-03-23 20:13:51 +01:00
if ( $_GET [ 'action' ] != 'classin' )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=classin&facid=' . $object -> id . '">' ;
2008-08-12 20:20:18 +02:00
print img_edit ( $langs -> trans ( 'SetProject' ), 1 );
print '</a></td>' ;
}
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2009-03-23 20:13:51 +01:00
if ( $_GET [ 'action' ] == 'classin' )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
$html -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> socid , $object -> fk_project , 'projectid' );
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
$html -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id , $object -> socid , $object -> fk_project , 'none' );
2008-08-12 20:20:18 +02:00
}
print '</td>' ;
print '</tr>' ;
}
print '</table><br>' ;
/*
2010-10-02 22:47:55 +02:00
* Lines
2008-08-12 20:20:18 +02:00
*/
2010-10-02 22:47:55 +02:00
$result = $object -> getLinesArray ();
2010-09-12 20:01:29 +02:00
2010-10-02 22:47:55 +02:00
if ( $conf -> use_javascript_ajax && $object -> statut == 0 )
{
include ( DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php' );
}
2010-09-12 20:01:29 +02:00
2010-10-02 22:47:55 +02:00
print '<table id="tablelines" class="noborder" width="100%">' ;
2010-09-12 20:01:29 +02:00
2010-10-02 22:47:55 +02:00
if ( ! empty ( $object -> lines ))
{
$object -> print_title_list ();
2010-10-16 16:54:09 +02:00
$object -> printLinesList ( 1 , $mysoc , $soc );
2010-10-02 22:47:55 +02:00
}
2008-08-12 20:20:18 +02:00
/*
2009-03-10 00:46:39 +01:00
* Form to add new line
2008-08-12 20:20:18 +02:00
*/
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 0 && $user -> rights -> facture -> creer && $_GET [ 'action' ] <> 'valid' && $_GET [ 'action' ] <> 'editline' )
2008-08-12 20:20:18 +02:00
{
$var = true ;
2010-08-09 19:16:26 +02:00
2010-09-15 15:29:17 +02:00
$object -> showAddFreeProductForm ( 1 , $mysoc , $soc );
2010-08-09 19:16:26 +02:00
2010-08-05 12:07:05 +02:00
// Add predefined products/services
2010-05-10 06:50:39 +02:00
if ( $conf -> product -> enabled || $conf -> service -> enabled )
2008-08-12 20:20:18 +02:00
{
2010-08-05 12:07:05 +02:00
$var =! $var ;
2010-09-15 15:29:17 +02:00
$object -> showAddPredefinedProductForm ( 1 , $mysoc , $soc );
2008-08-12 20:20:18 +02:00
}
2010-09-12 20:01:29 +02:00
2010-09-09 18:57:53 +02:00
// Hook of thirdparty module
if ( ! empty ( $object -> hooks ))
{
foreach ( $object -> hooks as $module )
{
$var =! $var ;
$module -> formAddObject ( $object );
}
}
2008-08-12 20:20:18 +02:00
}
2010-08-09 19:16:26 +02:00
2008-08-12 20:20:18 +02:00
print " </table> \n " ;
print " </div> \n " ;
/*
* Boutons actions
*/
2010-12-14 00:38:47 +01:00
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'action' ] != 'prerelance' && $_GET [ 'action' ] != 'presend' )
{
if ( $user -> societe_id == 0 && $_GET [ 'action' ] <> 'valid' && $_GET [ 'action' ] <> 'editline' )
{
print '<div class="tabsAction">' ;
2009-09-11 17:43:16 +02:00
// Editer une facture deja validee, sans paiement effectue et pas exporte en compta
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 1 )
2008-08-12 20:20:18 +02:00
{
2009-09-11 17:43:16 +02:00
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
2010-09-09 18:02:55 +02:00
$ventilExportCompta = $object -> getVentilExportCompta ();
2008-08-12 20:20:18 +02:00
2010-09-09 18:02:55 +02:00
if ( $resteapayer == $object -> total_ttc && $object -> paye == 0 && $ventilExportCompta == 0 )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( ! $objectidnext )
2008-08-12 20:20:18 +02:00
{
2010-07-15 22:48:40 +02:00
if ( $user -> rights -> facture -> unvalidate )
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=modif">' . $langs -> trans ( 'Modify' ) . '</a>' ;
2010-07-15 22:48:40 +02:00
}
else
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( 'Modify' ) . '</span>' ;
}
2008-08-12 20:20:18 +02:00
}
else
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'Modify' ) . '</span>' ;
}
}
}
2010-01-15 00:21:22 +01:00
// Reopen a standard paid invoice
2010-09-09 18:02:55 +02:00
if (( $object -> type == 0 || $object -> type == 1 ) && ( $object -> statut == 2 || $object -> statut == 3 )) // A paid invoice (partially or completely)
2010-01-15 00:21:22 +01:00
{
2010-09-09 18:02:55 +02:00
if ( ! $objectidnext && $object -> close_code != 'replaced' ) // Not replaced by another invoice
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=reopen">' . $langs -> trans ( 'ReOpen' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
else
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'ReOpen' ) . '</span>' ;
}
}
2008-12-02 00:09:52 +01:00
2009-02-13 23:50:58 +01:00
// Validate
2010-09-12 22:27:40 +02:00
if ( $object -> statut == 0 && sizeof ( $object -> lines ) > 0 &&
2009-03-02 19:17:19 +01:00
(
2010-09-09 18:02:55 +02:00
(( $object -> type == 0 || $object -> type == 1 || $object -> type == 3 || $object -> type == 4 ) && $object -> total_ttc >= 0 )
|| ( $object -> type == 2 && $object -> total_ttc <= 0 ))
2009-03-02 19:17:19 +01:00
)
2008-08-12 20:20:18 +02:00
{
if ( $user -> rights -> facture -> valider )
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=valid"' ;
2008-08-12 20:20:18 +02:00
print '>' . $langs -> trans ( 'Validate' ) . '</a>' ;
}
}
2009-02-13 23:50:58 +01:00
// Send by mail
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 1 || $object -> statut == 2 ) && $user -> rights -> facture -> envoyer )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( $objectidnext )
2008-08-12 20:20:18 +02:00
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'SendByMail' ) . '</span>' ;
}
else
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=presend&mode=init">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
}
2009-02-21 18:43:02 +01:00
if ( $conf -> global -> FACTURE_SHOW_SEND_REMINDER ) // For backward compatibility
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if (( $object -> statut == 1 || $object -> statut == 2 ) && $resteapayer > 0 && $user -> rights -> facture -> envoyer )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( $objectidnext )
2009-02-13 23:50:58 +01:00
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'SendRemindByMail' ) . '</span>' ;
}
else
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=prerelance&mode=init">' . $langs -> trans ( 'SendRemindByMail' ) . '</a>' ;
2009-02-13 23:50:58 +01:00
}
2008-08-12 20:20:18 +02:00
}
}
2009-02-15 18:33:02 +01:00
2009-02-21 18:43:02 +01:00
// Create payment
2010-09-09 18:02:55 +02:00
if ( $object -> type != 2 && $object -> statut == 1 && $object -> paye == 0 && $user -> rights -> facture -> paiement )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
if ( $objectidnext )
2008-08-12 20:20:18 +02:00
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'DoPayment' ) . '</span>' ;
}
else
{
if ( $resteapayer == 0 )
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseRemainderToPayIsZero " ) . '">' . $langs -> trans ( 'DoPayment' ) . '</span>' ;
}
else
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="paiement.php?facid=' . $object -> id . '&action=create">' . $langs -> trans ( 'DoPayment' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
}
}
2009-02-21 18:43:02 +01:00
// Reverse back money or convert to reduction
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 || $object -> type == 3 )
2008-08-12 20:20:18 +02:00
{
2009-02-21 18:43:02 +01:00
// For credit note only
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 && $object -> statut == 1 && $object -> paye == 0 && $user -> rights -> facture -> paiement )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="paiement.php?facid=' . $object -> id . '&action=create">' . $langs -> trans ( 'DoPaymentBack' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
2009-02-21 18:43:02 +01:00
// For credit note
2010-09-09 18:02:55 +02:00
if ( $object -> type == 2 && $object -> statut == 1 && $object -> paye == 0 && $user -> rights -> facture -> creer && $object -> getSommePaiement () == 0 )
2009-02-21 18:43:02 +01:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertToReduc' ) . '</a>' ;
2009-02-21 18:43:02 +01:00
}
// For deposit invoice
2010-09-09 18:02:55 +02:00
if ( $object -> type == 3 && $object -> statut == 1 && $resteapayer == 0 && $user -> rights -> facture -> creer )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=converttoreduc">' . $langs -> trans ( 'ConvertToReduc' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
}
2009-08-19 19:16:47 +02:00
// Classify paid (if not deposit and not credit note. Such invoice are "converted")
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 1 && $object -> paye == 0 && $user -> rights -> facture -> paiement &&
(( $object -> type != 2 && $object -> type != 3 && $resteapayer <= 0 ) || ( $object -> type == 2 && $resteapayer >= 0 )) )
2008-08-12 20:20:18 +02:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=paid">' . $langs -> trans ( 'ClassifyPaid' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
2009-09-11 17:43:16 +02:00
// Classify 'closed not completely paid' (possible si validee et pas encore classee payee)
2010-09-09 18:02:55 +02:00
if ( $object -> statut == 1 && $object -> paye == 0 && $resteapayer > 0
2008-08-12 20:20:18 +02:00
&& $user -> rights -> facture -> paiement )
{
2009-03-02 22:21:49 +01:00
if ( $totalpaye > 0 || $totalcreditnotes > 0 )
2008-08-12 20:20:18 +02:00
{
// If one payment or one credit note was linked to this invoice
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=paid">' . $langs -> trans ( 'ClassifyPaidPartially' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
else
{
2010-09-09 18:02:55 +02:00
if ( $objectidnext )
2008-08-12 20:20:18 +02:00
{
print '<span class="butActionRefused" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'ClassifyCanceled' ) . '</span>' ;
}
else
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=canceled">' . $langs -> trans ( 'ClassifyCanceled' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
}
}
2008-11-20 22:30:23 +01:00
// Clone
2010-09-09 18:02:55 +02:00
if (( $object -> type == 0 || $object -> type == 3 || $object -> type == 4 ) && $user -> rights -> facture -> creer )
2008-11-20 22:30:23 +01:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id . '&action=clone&object=invoice">' . $langs -> trans ( " ToClone " ) . '</a>' ;
2008-11-20 22:30:23 +01:00
}
2009-01-14 16:53:52 +01:00
2008-11-20 22:30:23 +01:00
// Clone as predefined
2010-09-09 18:02:55 +02:00
if (( $object -> type == 0 || $object -> type == 3 || $object -> type == 4 ) && $object -> statut == 0 && $user -> rights -> facture -> creer )
2008-11-20 22:30:23 +01:00
{
2010-09-09 18:02:55 +02:00
if ( ! $objectidnext )
2008-11-20 22:30:23 +01:00
{
2010-09-09 18:02:55 +02:00
print '<a class="butAction" href="facture/fiche-rec.php?facid=' . $object -> id . '&action=create">' . $langs -> trans ( " ChangeIntoRepeatableInvoice " ) . '</a>' ;
2008-11-20 22:30:23 +01:00
}
}
2009-01-14 16:53:52 +01:00
// Delete
2010-12-01 23:14:15 +01:00
if ( $user -> rights -> facture -> supprimer )
2008-08-12 20:20:18 +02:00
{
2010-12-14 00:38:47 +01:00
if ( ! $object -> is_erasable ())
2010-12-01 23:14:15 +01:00
{
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " DisabledBecauseNotErasable " ) . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
}
else if ( $objectidnext )
2008-08-12 20:20:18 +02:00
{
2008-11-20 22:30:23 +01:00
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " DisabledBecauseReplacedInvoice " ) . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
elseif ( $object -> getSommePaiement ())
2010-01-15 00:21:22 +01:00
{
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " DisabledBecausePayments " ) . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
}
2008-08-12 20:20:18 +02:00
else
{
2010-09-09 18:02:55 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id . '&action=delete">' . $langs -> trans ( 'Delete' ) . '</a>' ;
2008-08-12 20:20:18 +02:00
}
}
2010-12-01 23:14:15 +01:00
else
{
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
}
2008-08-12 20:20:18 +02:00
print '</div>' ;
}
}
if ( $_GET [ 'action' ] != 'prerelance' && $_GET [ 'action' ] != 'presend' )
{
print '<table width="100%"><tr><td width="50%" valign="top">' ;
print '<a name="builddoc"></a>' ; // ancre
/*
2009-09-11 17:43:16 +02:00
* Documents generes
2008-08-12 20:20:18 +02:00
*/
2010-09-09 18:02:55 +02:00
$filename = dol_sanitizeFileName ( $object -> ref );
$filedir = $conf -> facture -> dir_output . '/' . dol_sanitizeFileName ( $object -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?facid=' . $object -> id ;
2008-08-12 20:20:18 +02:00
$genallowed = $user -> rights -> facture -> creer ;
$delallowed = $user -> rights -> facture -> supprimer ;
print '<br>' ;
2010-09-09 18:02:55 +02:00
$somethingshown = $formfile -> show_documents ( 'facture' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
2008-08-12 20:20:18 +02:00
/*
2010-04-09 09:23:32 +02:00
* Linked object block
2008-08-12 20:20:18 +02:00
*/
2010-09-09 18:02:55 +02:00
$object -> load_object_linked ( $object -> id , $object -> element );
2010-04-18 23:20:34 +02:00
2010-11-08 02:04:55 +01:00
foreach ( $object -> linked_object as $linked_object => $linked_objectid )
2008-08-12 20:20:18 +02:00
{
2010-11-08 02:04:55 +01:00
if ( $conf -> $linked_object -> enabled && $linked_object != $object -> element )
2008-08-12 20:20:18 +02:00
{
2010-11-08 02:04:55 +01:00
$somethingshown = $object -> showLinkedObjectBlock ( $linked_object , $linked_objectid , $somethingshown );
2008-08-12 20:20:18 +02:00
}
}
print '</td><td valign="top" width="50%">' ;
print '<br>' ;
// List of actions on element
2010-05-03 10:22:35 +02:00
include_once ( DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' );
2008-08-12 20:20:18 +02:00
$formactions = new FormActions ( $db );
2010-09-09 18:02:55 +02:00
$somethingshown = $formactions -> showactions ( $object , 'invoice' , $socid );
2008-08-12 20:20:18 +02:00
print '</td></tr></table>' ;
}
2010-04-21 10:16:10 +02:00
else
2008-08-12 20:20:18 +02:00
{
2010-04-21 10:16:10 +02:00
/*
* Affiche formulaire mail
*/
// By default if $_GET['action']=='presend'
$titreform = 'SendBillByMail' ;
$topicmail = 'SendBillRef' ;
$action = 'send' ;
$modelmail = 'facture_send' ;
if ( $_GET [ 'action' ] == 'prerelance' ) // For backward compatibility
{
$titrefrom = 'SendReminderBillByMail' ;
$topicmail = 'SendReminderBillRef' ;
$action = 'relance' ;
$modelmail = 'facture_relance' ;
}
2010-09-09 18:02:55 +02:00
$ref = dol_sanitizeFileName ( $object -> ref );
2008-08-12 20:20:18 +02:00
$file = $conf -> facture -> dir_output . '/' . $ref . '/' . $ref . '.pdf' ;
// Construit PDF si non existant
if ( ! is_readable ( $file ))
{
2010-02-27 14:37:13 +01:00
// Define output language
2008-10-29 00:36:36 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2010-09-09 18:02:55 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2008-08-12 20:20:18 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2008-08-12 20:20:18 +02:00
}
2010-09-09 18:02:55 +02:00
$result = facture_pdf_create ( $db , $object , '' , $_REQUEST [ 'model' ], $outputlangs );
2008-08-12 20:20:18 +02:00
if ( $result <= 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $result );
2008-08-12 20:20:18 +02:00
exit ;
}
}
print '<br>' ;
2010-04-21 10:16:10 +02:00
print_titre ( $langs -> trans ( $titre ));
2008-08-12 20:20:18 +02:00
2009-09-11 17:43:16 +02:00
// Cree l'objet formulaire mail
2010-05-03 10:43:32 +02:00
include_once ( DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' );
2008-08-12 20:20:18 +02:00
$formmail = new FormMail ( $db );
$formmail -> fromtype = 'user' ;
$formmail -> fromid = $user -> id ;
2010-07-18 12:39:07 +02:00
$formmail -> fromname = $user -> getFullName ( $langs );
2008-08-12 20:20:18 +02:00
$formmail -> frommail = $user -> email ;
$formmail -> withfrom = 1 ;
2009-10-14 18:13:20 +02:00
$formmail -> withto = empty ( $_POST [ " sendto " ]) ? 1 : $_POST [ " sendto " ];
$formmail -> withtosocid = $soc -> id ;
2008-08-12 20:20:18 +02:00
$formmail -> withtocc = 1 ;
2009-10-14 18:13:20 +02:00
$formmail -> withtoccsocid = 0 ;
$formmail -> withtoccc = $conf -> global -> MAIN_EMAIL_USECCC ;
$formmail -> withtocccsocid = 0 ;
2010-04-21 10:16:10 +02:00
$formmail -> withtopic = $langs -> transnoentities ( $topicmail , '__FACREF__' );
2008-08-12 20:20:18 +02:00
$formmail -> withfile = 2 ;
$formmail -> withbody = 1 ;
$formmail -> withdeliveryreceipt = 1 ;
$formmail -> withcancel = 1 ;
// Tableau des substitutions
2010-09-09 18:02:55 +02:00
$formmail -> substit [ '__FACREF__' ] = $object -> ref ;
2009-10-14 18:13:20 +02:00
// Tableau des parametres complementaires du post
2010-04-21 10:16:10 +02:00
$formmail -> param [ 'action' ] = $action ;
$formmail -> param [ 'models' ] = $modelmail ;
2010-09-09 18:02:55 +02:00
$formmail -> param [ 'facid' ] = $object -> id ;
$formmail -> param [ 'returnurl' ] = $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ;
2008-08-12 20:20:18 +02:00
// Init list of files
if ( ! empty ( $_REQUEST [ " mode " ]) && $_REQUEST [ " mode " ] == 'init' )
{
$formmail -> clear_attached_files ();
2011-01-14 02:24:00 +01:00
$formmail -> add_attached_files ( $file , dol_sanitizeFilename ( $ref . '.pdf' ), 'application/pdf' );
2008-08-12 20:20:18 +02:00
}
$formmail -> show_form ();
print '<br>' ;
}
}
else
{
2010-09-09 18:02:55 +02:00
dol_print_error ( $db , $object -> error );
2008-08-12 20:20:18 +02:00
}
}
else
{
/***************************************************************************
* *
* Mode Liste *
* *
***************************************************************************/
2010-09-12 20:01:29 +02:00
$now = dol_now ();
2009-01-07 16:21:16 +01:00
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
$month = GETPOST ( 'month' , 'int' );
$year = GETPOST ( 'year' , 'int' );
2008-08-12 20:20:18 +02:00
2010-11-20 14:08:44 +01:00
$limit = $conf -> liste_limit ;
2008-08-12 20:20:18 +02:00
if ( ! $sortorder ) $sortorder = 'DESC' ;
if ( ! $sortfield ) $sortfield = 'f.datef' ;
$facturestatic = new Facture ( $db );
if ( $page == - 1 ) $page = 0 ;
$sql = 'SELECT ' ;
$sql .= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,' ;
2010-01-15 00:21:22 +01:00
$sql .= ' f.datef as df, f.date_lim_reglement as datelimite,' ;
2008-08-12 20:20:18 +02:00
$sql .= ' f.paye as paye, f.fk_statut,' ;
$sql .= ' s.nom, s.rowid as socid' ;
2010-09-12 20:01:29 +02:00
if ( ! $sall ) $sql .= ' ,SUM(pf.amount) as am' ; // To be able to sort on status
2008-08-12 20:20:18 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2008-08-12 20:20:18 +02:00
$sql .= ', ' . MAIN_DB_PREFIX . 'facture as f' ;
if ( $sall ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facturedet as fd ON fd.fk_facture = f.rowid' ;
2010-09-12 20:01:29 +02:00
if ( ! $sall ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiement_facture as pf ON pf.fk_facture = f.rowid' ;
2008-08-12 20:20:18 +02:00
$sql .= ' WHERE f.fk_soc = s.rowid' ;
2010-04-16 19:21:53 +02:00
$sql .= " AND f.entity = " . $conf -> entity ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
if ( $socid ) $sql .= ' AND s.rowid = ' . $socid ;
2008-08-12 20:20:18 +02:00
if ( $_GET [ 'filtre' ])
{
2009-10-20 15:14:44 +02:00
$filtrearr = explode ( ',' , $_GET [ 'filtre' ]);
2008-08-12 20:20:18 +02:00
foreach ( $filtrearr as $fil )
{
2009-10-20 15:14:44 +02:00
$filt = explode ( ':' , $fil );
2008-08-12 20:20:18 +02:00
$sql .= ' AND ' . trim ( $filt [ 0 ]) . ' = ' . trim ( $filt [ 1 ]);
}
}
if ( $_GET [ 'search_ref' ])
{
2010-04-16 19:21:53 +02:00
$sql .= ' AND f.facnumber LIKE \'%' . addslashes ( trim ( $_GET [ 'search_ref' ])) . '%\'' ;
2008-08-12 20:20:18 +02:00
}
if ( $_GET [ 'search_societe' ])
{
2010-04-16 19:21:53 +02:00
$sql .= ' AND s.nom LIKE \'%' . addslashes ( trim ( $_GET [ 'search_societe' ])) . '%\'' ;
2008-08-12 20:20:18 +02:00
}
if ( $_GET [ 'search_montant_ht' ])
{
2009-12-22 14:50:45 +01:00
$sql .= ' AND f.total = \'' . addslashes ( trim ( $_GET [ 'search_montant_ht' ])) . '\'' ;
2008-08-12 20:20:18 +02:00
}
if ( $_GET [ 'search_montant_ttc' ])
{
2009-12-22 14:50:45 +01:00
$sql .= ' AND f.total_ttc = \'' . addslashes ( trim ( $_GET [ 'search_montant_ttc' ])) . '\'' ;
2008-08-12 20:20:18 +02:00
}
if ( $month > 0 )
{
if ( $year > 0 )
2010-05-01 17:33:00 +02:00
$sql .= " AND f.datef BETWEEN ' " . $db -> idate ( dol_get_first_day ( $year , $month , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $year , $month , false )) . " ' " ;
2008-08-12 20:20:18 +02:00
else
2010-09-12 20:01:29 +02:00
$sql .= " AND date_format(f.datef, '%m') = ' " . $month . " ' " ;
2008-08-12 20:20:18 +02:00
}
2010-05-01 17:33:00 +02:00
else if ( $year > 0 )
2008-08-12 20:20:18 +02:00
{
2010-05-01 17:33:00 +02:00
$sql .= " AND f.datef BETWEEN ' " . $db -> idate ( dol_get_first_day ( $year , 1 , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $year , 12 , false )) . " ' " ;
2008-08-12 20:20:18 +02:00
}
if ( $_POST [ 'sf_ref' ])
{
2010-04-16 19:21:53 +02:00
$sql .= ' AND f.facnumber LIKE \'%' . addslashes ( trim ( $_POST [ 'sf_ref' ])) . '%\'' ;
2008-08-12 20:20:18 +02:00
}
if ( $sall )
{
2010-04-16 19:21:53 +02: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 ) . '%\')' ;
2008-08-12 20:20:18 +02:00
}
2010-09-12 20:01:29 +02:00
if ( ! $sall )
{
$sql .= ' GROUP BY f.rowid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,' ;
$sql .= ' f.datef, f.date_lim_reglement,' ;
$sql .= ' f.paye, f.fk_statut,' ;
$sql .= ' s.nom, s.rowid' ;
}
2009-12-22 14:50:45 +01:00
$sql .= ' ORDER BY ' ;
2009-10-20 15:14:44 +02:00
$listfield = explode ( ',' , $sortfield );
2010-05-01 17:33:00 +02:00
foreach ( $listfield as $key => $value ) $sql .= $listfield [ $key ] . ' ' . $sortorder . ',' ;
2009-12-22 14:50:45 +01:00
$sql .= ' f.rowid DESC ' ;
$sql .= $db -> plimit ( $limit + 1 , $offset );
2010-09-12 20:01:29 +02:00
//print $sql;
2008-08-12 20:20:18 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $socid )
{
$soc = new Societe ( $db );
$soc -> fetch ( $socid );
}
2009-04-09 01:00:16 +02:00
$param = '&socid=' . $socid ;
if ( $month ) $param .= '&month=' . $month ;
if ( $year ) $param .= '&year=' . $year ;
2009-04-09 22:33:23 +02:00
2010-09-12 20:01:29 +02:00
print_barre_liste ( $langs -> trans ( 'BillsCustomers' ) . ' ' . ( $socid ? ' ' . $soc -> nom : '' ), $page , 'facture.php' , $param , $sortfield , $sortorder , '' , $num );
2008-08-12 20:20:18 +02:00
$i = 0 ;
print '<form method="get" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
2009-04-09 01:00:16 +02:00
print_liste_field_titre ( $langs -> trans ( 'Ref' ), $_SERVER [ 'PHP_SELF' ], 'f.facnumber' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Date' ), $_SERVER [ 'PHP_SELF' ], 'f.datef' , '' , $param , 'align="center"' , $sortfield , $sortorder );
2009-04-10 00:07:13 +02:00
print_liste_field_titre ( $langs -> trans ( " DateDue " ), $_SERVER [ 'PHP_SELF' ], " f.date_lim_reglement " , " &socid= $socid " , " " , 'align="center"' , $sortfield , $sortorder );
2009-04-09 01:00:16 +02:00
print_liste_field_titre ( $langs -> trans ( 'Company' ), $_SERVER [ 'PHP_SELF' ], 's.nom' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'AmountHT' ), $_SERVER [ 'PHP_SELF' ], 'f.total' , '' , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'AmountTTC' ), $_SERVER [ 'PHP_SELF' ], 'f.total_ttc' , '' , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Received' ), $_SERVER [ 'PHP_SELF' ], 'am' , '' , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Status' ), $_SERVER [ 'PHP_SELF' ], 'fk_statut,paye,am' , '' , $param , 'align="right"' , $sortfield , $sortorder );
2008-08-12 20:20:18 +02:00
//print '<td class="liste_titre"> </td>';
print '</tr>' ;
// Lignes des champs de filtre
print '<tr class="liste_titre">' ;
print '<td class="liste_titre" align="left">' ;
print '<input class="flat" size="10" type="text" name="search_ref" value="' . $_GET [ 'search_ref' ] . '">' ;
print '<td class="liste_titre" colspan="1" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="' . $month . '">' ;
//print ' '.$langs->trans('Year').': ';
$max_year = date ( " Y " );
$syear = $year ;
//if ($syear == '') $syear = date("Y");
$html -> select_year ( $syear , 'year' , 1 , '' , $max_year );
print '</td>' ;
2009-04-09 22:33:23 +02:00
print '<td class="liste_titre" align="left"> </td>' ;
2008-08-12 20:20:18 +02:00
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>' ;
2009-07-08 19:31:40 +02:00
print '<td class="liste_titre" align="right">' ;
2008-08-12 20:20:18 +02:00
print ' ' ;
print '</td>' ;
2011-02-18 11:45:38 +01:00
print '<td class="liste_titre" align="right"><input type="image" class="liste_titre" name="button_search" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/search.png" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2008-08-12 20:20:18 +02:00
print " </td></tr> \n " ;
if ( $num > 0 )
{
$var = True ;
$total = 0 ;
$totalrecu = 0 ;
while ( $i < min ( $num , $limit ))
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
2010-01-15 00:21:22 +01:00
$datelimit = $db -> jdate ( $objp -> datelimite );
2008-08-12 20:20:18 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
print '<td nowrap="nowrap">' ;
$facturestatic -> id = $objp -> facid ;
$facturestatic -> ref = $objp -> facnumber ;
$facturestatic -> type = $objp -> type ;
2010-04-17 10:22:29 +02:00
$paiement = $facturestatic -> getSommePaiement ();
2008-08-12 20:20:18 +02:00
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
2009-04-09 22:33:23 +02:00
2009-08-05 20:22:40 +02:00
print '<td class="nobordernopadding" nowrap="nowrap">' ;
2008-08-12 20:20:18 +02:00
print $facturestatic -> getNomUrl ( 1 );
print $objp -> increment ;
print '</td>' ;
2009-04-09 22:33:23 +02:00
2008-08-12 20:20:18 +02:00
print '<td width="16" align="right" class="nobordernopadding">' ;
2009-04-29 20:02:50 +02:00
$filename = dol_sanitizeFileName ( $objp -> facnumber );
$filedir = $conf -> facture -> dir_output . '/' . dol_sanitizeFileName ( $objp -> facnumber );
2008-08-12 20:20:18 +02:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?facid=' . $objp -> facid ;
2010-03-27 01:33:28 +01:00
$formfile -> show_documents ( 'facture' , $filename , $filedir , $urlsource , '' , '' , '' , 1 , '' , 1 );
2008-08-12 20:20:18 +02:00
print '</td>' ;
print '</tr></table>' ;
print " </td> \n " ;
2009-04-09 22:33:23 +02:00
// Date
2010-05-01 17:33:00 +02:00
print '<td align="center" nowrap>' ;
print dol_print_date ( $db -> jdate ( $objp -> df ), 'day' );
print '</td>' ;
2009-04-09 22:33:23 +02:00
// Date limit
2010-01-15 00:21:22 +01:00
print '<td align="center" nowrap="1">' . dol_print_date ( $datelimit , 'day' );
2010-04-17 10:22:29 +02:00
if ( $datelimit < ( $now - $conf -> facture -> client -> warning_delay ) && ! $objp -> paye && $objp -> fk_statut == 1 && ! $paiement )
2009-04-09 22:33:23 +02:00
{
print img_warning ( $langs -> trans ( 'Late' ));
}
print '</td>' ;
2010-10-09 21:41:06 +02:00
print '<td>' ;
$thirdparty = new Societe ( $db );
$thirdparty -> id = $objp -> socid ;
$thirdparty -> nom = $objp -> nom ;
print $thirdparty -> getNomUrl ( 1 , 'customer' );
print '</td>' ;
2009-04-09 22:33:23 +02:00
2008-08-12 20:20:18 +02:00
print '<td align="right">' . price ( $objp -> total ) . '</td>' ;
2009-04-09 22:33:23 +02:00
2008-08-12 20:20:18 +02:00
print '<td align="right">' . price ( $objp -> total_ttc ) . '</td>' ;
2009-04-09 22:33:23 +02:00
2010-04-17 10:22:29 +02:00
print '<td align="right">' . price ( $paiement ) . '</td>' ;
2008-08-12 20:20:18 +02:00
// Affiche statut de la facture
print '<td align="right" nowrap="nowrap">' ;
2010-04-17 10:22:29 +02:00
print $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 5 , $paiement , $objp -> type );
2008-08-12 20:20:18 +02:00
print " </td> " ;
//print "<td> </td>";
print " </tr> \n " ;
$total += $objp -> total ;
$total_ttc += $objp -> total_ttc ;
2010-04-17 10:22:29 +02:00
$totalrecu += $paiement ;
2008-08-12 20:20:18 +02:00
$i ++ ;
}
if (( $offset + $num ) <= $limit )
{
// Print total
print '<tr class="liste_total">' ;
2009-04-09 23:53:53 +02:00
print '<td class="liste_total" colspan="4" align="left">' . $langs -> trans ( 'Total' ) . '</td>' ;
2008-08-12 20:20:18 +02:00
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> \n " ;
print " </form> \n " ;
$db -> free ( $resql );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-08-12 20:20:18 +02:00
}
}
}
$db -> close ();
llxFooter ( '$Date$ - $Revision$' );
?>