2004-10-19 22:43:23 +02:00
< ? php
2012-03-18 11:13:01 +01:00
/* Copyright ( C ) 2003 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-03-18 11:13:01 +01:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2014-01-07 12:16:16 +01:00
* Copyright ( C ) 2010 - 2013 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
2013-04-09 17:18:07 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2009-04-27 22:37:50 +02:00
*
2003-08-03 21:15:39 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-03 21:15:39 +02:00
* ( 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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-08-03 21:15:39 +02:00
*/
2009-01-25 18:05:40 +01:00
2005-04-23 00:39:11 +02:00
/**
2008-08-07 22:46:15 +02:00
* \file htdocs / contrat / fiche . php
* \ingroup contrat
2011-06-06 13:35:53 +02:00
* \brief Page of a contract
2008-08-07 22:46:15 +02:00
*/
2003-08-03 21:15:39 +02:00
2010-03-27 15:50:05 +01:00
require ( " ../main.inc.php " );
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/contract.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/contract/modules_contract.php' ;
2013-04-09 17:18:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2012-08-22 23:11:24 +02:00
if ( ! empty ( $conf -> produit -> enabled ) || ! empty ( $conf -> service -> enabled )) require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
if ( ! empty ( $conf -> propal -> enabled )) require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> projet -> enabled )) {
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2013-06-14 22:33:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2012-07-25 11:46:33 +02:00
}
2003-08-03 21:15:39 +02:00
2004-10-30 14:45:08 +02:00
$langs -> load ( " contracts " );
2004-11-26 15:17:48 +01:00
$langs -> load ( " orders " );
$langs -> load ( " companies " );
2006-05-25 16:41:44 +02:00
$langs -> load ( " bills " );
2008-02-13 00:45:07 +01:00
$langs -> load ( " products " );
2004-11-26 15:17:48 +01:00
2012-03-18 11:13:01 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2012-03-18 11:13:01 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2011-09-21 15:44:20 +02:00
2012-07-25 11:46:33 +02:00
$datecontrat = '' ;
2011-09-21 15:44:20 +02:00
// Security check
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2012-03-18 11:13:01 +01:00
$result = restrictedArea ( $user , 'contrat' , $id );
2006-03-13 14:19:24 +01:00
2012-07-25 11:46:33 +02:00
$usehm = ( ! empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE : 0 );
2008-02-13 00:45:07 +01:00
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'contractcard' ));
2011-03-21 18:44:11 +01:00
$object = new Contrat ( $db );
2009-01-25 18:05:40 +01:00
2008-02-13 00:45:07 +01:00
/*
* Actions
*/
2012-03-18 11:13:01 +01:00
if ( $action == 'confirm_active' && $confirm == 'yes' && $user -> rights -> contrat -> activer )
2008-02-13 00:45:07 +01:00
{
2012-03-18 11:13:01 +01:00
$object -> fetch ( $id );
2012-07-25 11:46:33 +02:00
$result = $object -> active_line ( $user , GETPOST ( 'ligne' ), GETPOST ( 'date' ), GETPOST ( 'dateend' ), GETPOST ( 'comment' ));
2008-02-13 00:45:07 +01:00
if ( $result > 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2008-02-13 00:45:07 +01:00
exit ;
}
else {
2011-03-21 18:44:11 +01:00
$mesg = $object -> error ;
2008-02-13 00:45:07 +01:00
}
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_closeline' && $confirm == 'yes' && $user -> rights -> contrat -> activer )
2008-02-13 00:45:07 +01:00
{
2014-03-02 15:58:02 +01:00
if ( ! GETPOST ( 'dateend' ))
{
$error ++ ;
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DateEnd " )), 'errors' );
}
if ( ! $error )
{
$object -> fetch ( $id );
$result = $object -> close_line ( $user , GETPOST ( 'ligne' ), GETPOST ( 'dateend' ), urldecode ( GETPOST ( 'comment' )));
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
else {
$mesg = $object -> error ;
}
}
2008-02-13 00:45:07 +01:00
}
// Si ajout champ produit predefini
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'mode' ) == 'predefined' )
2005-09-24 03:25:19 +02:00
{
2011-09-21 15:44:20 +02:00
$date_start = '' ;
$date_end = '' ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_startmonth' ) && GETPOST ( 'date_startday' ) && GETPOST ( 'date_startyear' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$date_start = dol_mktime ( GETPOST ( 'date_starthour' ), GETPOST ( 'date_startmin' ), 0 , GETPOST ( 'date_startmonth' ), GETPOST ( 'date_startday' ), GETPOST ( 'date_startyear' ));
2011-09-21 15:44:20 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_endmonth' ) && GETPOST ( 'date_endday' ) && GETPOST ( 'date_endyear' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$date_end = dol_mktime ( GETPOST ( 'date_endhour' ), GETPOST ( 'date_endmin' ), 0 , GETPOST ( 'date_endmonth' ), GETPOST ( 'date_endday' ), GETPOST ( 'date_endyear' ));
2011-09-21 15:44:20 +02:00
}
2005-09-24 03:25:19 +02:00
}
2006-04-12 17:09:54 +02:00
// Si ajout champ produit libre
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'mode' ) == 'libre' )
2005-09-24 03:25:19 +02:00
{
2011-09-21 15:44:20 +02:00
$date_start_sl = '' ;
$date_end_sl = '' ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_start_slmonth' ) && GETPOST ( 'date_start_slday' ) && GETPOST ( 'date_start_slyear' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$date_start_sl = dol_mktime ( GETPOST ( 'date_start_slhour' ), GETPOST ( 'date_start_slmin' ), 0 , GETPOST ( 'date_start_slmonth' ), GETPOST ( 'date_start_slday' ), GETPOST ( 'date_start_slyear' ));
2011-09-21 15:44:20 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_end_slmonth' ) && GETPOST ( 'date_end_slday' ) && GETPOST ( 'date_end_slyear' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$date_end_sl = dol_mktime ( GETPOST ( 'date_end_slhour' ), GETPOST ( 'date_end_slmin' ), 0 , GETPOST ( 'date_end_slmonth' ), GETPOST ( 'date_end_slday' ), GETPOST ( 'date_end_slyear' ));
2011-09-21 15:44:20 +02:00
}
2005-09-24 03:25:19 +02:00
}
2006-04-12 17:09:54 +02:00
2010-01-12 10:48:19 +01:00
// Param dates
$date_contrat = '' ;
2005-09-02 01:17:42 +02:00
$date_start_update = '' ;
$date_end_update = '' ;
2005-09-24 03:25:19 +02:00
$date_start_real_update = '' ;
$date_end_real_update = '' ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_start_updatemonth' ) && GETPOST ( 'date_start_updateday' ) && GETPOST ( 'date_start_updateyear' ))
2005-09-02 01:17:42 +02:00
{
2012-07-25 11:46:33 +02:00
$date_start_update = dol_mktime ( GETPOST ( 'date_start_updatehour' ), GETPOST ( 'date_start_updatemin' ), 0 , GETPOST ( 'date_start_updatemonth' ), GETPOST ( 'date_start_updateday' ), GETPOST ( 'date_start_updateyear' ));
2005-09-02 01:17:42 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_end_updatemonth' ) && GETPOST ( 'date_end_updateday' ) && GETPOST ( 'date_end_updateyear' ))
2005-09-02 01:17:42 +02:00
{
2012-07-25 11:46:33 +02:00
$date_end_update = dol_mktime ( GETPOST ( 'date_end_updatehour' ), GETPOST ( 'date_end_updatemin' ), 0 , GETPOST ( 'date_end_updatemonth' ), GETPOST ( 'date_end_updateday' ), GETPOST ( 'date_end_updateyear' ));
2005-09-02 01:17:42 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_start_real_updatemonth' ) && GETPOST ( 'date_start_real_updateday' ) && GETPOST ( 'date_start_real_updateyear' ))
2005-09-02 01:17:42 +02:00
{
2012-07-25 11:46:33 +02:00
$date_start_real_update = dol_mktime ( GETPOST ( 'date_start_real_updatehour' ), GETPOST ( 'date_start_real_updatemin' ), 0 , GETPOST ( 'date_start_real_updatemonth' ), GETPOST ( 'date_start_real_updateday' ), GETPOST ( 'date_start_real_updateyear' ));
2005-09-02 01:17:42 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'date_end_real_updatemonth' ) && GETPOST ( 'date_end_real_updateday' ) && GETPOST ( 'date_end_real_updateyear' ))
2005-09-02 01:17:42 +02:00
{
2012-07-25 11:46:33 +02:00
$date_end_real_update = dol_mktime ( GETPOST ( 'date_end_real_updatehour' ), GETPOST ( 'date_end_real_updatemin' ), 0 , GETPOST ( 'date_end_real_updatemonth' ), GETPOST ( 'date_end_real_updateday' ), GETPOST ( 'date_end_real_updateyear' ));
2005-09-02 01:17:42 +02:00
}
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'remonth' ) && GETPOST ( 'reday' ) && GETPOST ( 'reyear' ))
2010-01-12 10:48:19 +01:00
{
2012-07-25 11:46:33 +02:00
$datecontrat = dol_mktime ( GETPOST ( 'rehour' ), GETPOST ( 'remin' ), 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
2010-01-12 10:48:19 +01:00
}
2005-06-19 20:37:38 +02:00
2013-11-17 23:25:25 +01:00
// Add contract
2012-04-07 00:22:44 +02:00
if ( $action == 'add' && $user -> rights -> contrat -> creer )
2004-11-26 15:17:48 +01:00
{
2013-03-02 16:50:36 +01:00
// Check
if ( empty ( $datecontrat ))
{
$error ++ ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )) . '</div>' ;
$action = 'create' ;
}
2013-04-03 18:37:54 +02:00
2013-03-02 16:50:36 +01:00
if ( $socid < 1 )
{
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Customer " )), 'errors' );
$action = 'create' ;
$error ++ ;
}
2013-04-03 18:37:54 +02:00
2013-03-02 16:50:36 +01:00
if ( ! $error )
{
2013-03-22 17:10:17 +01:00
$object -> socid = $socid ;
2013-03-02 16:50:36 +01:00
$object -> date_contrat = $datecontrat ;
2005-09-17 15:58:47 +02:00
2013-03-02 16:50:36 +01:00
$object -> commercial_suivi_id = GETPOST ( 'commercial_suivi_id' , 'int' );
$object -> commercial_signature_id = GETPOST ( 'commercial_signature_id' , 'int' );
2005-06-11 13:33:21 +02:00
2013-04-09 17:18:07 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'alpha' );
2013-03-22 17:10:17 +01:00
$object -> note_public = GETPOST ( 'note_public' , 'alpha' );
2013-03-02 16:50:36 +01:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> remise_percent = GETPOST ( 'remise_percent' , 'alpha' );
$object -> ref = GETPOST ( 'ref' , 'alpha' );
2011-06-06 13:35:53 +02:00
2013-03-22 17:10:17 +01:00
// If creation from another object of another module (Example: origin=propal, originid=1)
if ( $_POST [ 'origin' ] && $_POST [ 'originid' ])
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $_POST [ 'origin' ];
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $_POST [ 'origin' ], $regs ))
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
// For compatibility
if ( $element == 'order' ) { $element = $subelement = 'commande' ; }
if ( $element == 'propal' ) { $element = 'comm/propal' ; $subelement = 'propal' ; }
$object -> origin = $_POST [ 'origin' ];
$object -> origin_id = $_POST [ 'originid' ];
// Possibility to add external linked objects with hooks
$object -> linked_objects [ $object -> origin ] = $object -> origin_id ;
if ( is_array ( $_POST [ 'other_linked_objects' ]) && ! empty ( $_POST [ 'other_linked_objects' ]))
{
$object -> linked_objects = array_merge ( $object -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
$id = $object -> create ( $user );
if ( $id < 0 ) {
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
if ( $id > 0 )
{
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
$classname = ucfirst ( $subelement );
$srcobject = new $classname ( $db );
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines " );
$result = $srcobject -> fetch ( $object -> origin_id );
if ( $result > 0 )
{
$srcobject -> fetch_thirdparty ();
$lines = $srcobject -> lines ;
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' )) $lines = $srcobject -> fetch_lines ();
$fk_parent_line = 0 ;
$num = count ( $lines );
for ( $i = 0 ; $i < $num ; $i ++ )
{
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
2014-03-02 15:50:26 +01:00
2014-01-28 15:24:30 +01:00
if ( $product_type == 1 ) { //only services // TODO Exclude also deee
2013-03-22 17:10:17 +01:00
// service prédéfini
if ( $lines [ $i ] -> fk_product > 0 )
{
$product_static = new Product ( $db );
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
$prod = new Product ( $db , $lines [ $i ] -> fk_product );
$outputlangs = $langs ;
$newlang = '' ;
if ( empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
if ( empty ( $newlang )) $newlang = $srcobject -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ] : $lines [ $i ] -> product_label ;
}
else
{
$label = $lines [ $i ] -> product_label ;
}
if ( $conf -> global -> PRODUIT_DESC_IN_FORM )
$desc .= ( $lines [ $i ] -> desc && $lines [ $i ] -> desc != $lines [ $i ] -> libelle ) ? dol_htmlentitiesbr ( $lines [ $i ] -> desc ) : '' ;
}
else {
$desc = dol_htmlentitiesbr ( $lines [ $i ] -> desc );
}
$result = $object -> addline (
$desc ,
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
$lines [ $i ] -> localtax1_tx ,
$lines [ $i ] -> localtax2_tx ,
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
2014-01-28 15:24:30 +01:00
$lines [ $i ] -> date_start ,
$lines [ $i ] -> date_end ,
2013-03-22 17:10:17 +01:00
'HT' ,
0 ,
$lines [ $i ] -> info_bits ,
$lines [ $i ] -> fk_fournprice ,
$lines [ $i ] -> pa_ht
);
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
}
}
else
{
$mesg = $srcobject -> error ;
$error ++ ;
}
}
else
{
$mesg = $object -> error ;
$error ++ ;
}
}
else
{
$result = $object -> create ( $user , $langs , $conf );
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
else {
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
$action = 'create' ;
}
2005-06-21 21:30:15 +02:00
}
2004-11-26 15:17:48 +01:00
}
2005-06-11 13:33:21 +02:00
2012-03-18 11:13:01 +01:00
else if ( $action == 'classin' && $user -> rights -> contrat -> creer )
2003-08-03 21:54:46 +02:00
{
2012-03-18 11:13:01 +01:00
$object -> fetch ( $id );
2012-07-25 11:46:33 +02:00
$object -> setProject ( GETPOST ( 'projectid' ));
2003-08-03 21:54:46 +02:00
}
2013-11-17 23:25:25 +01:00
// Add a new line
2012-03-18 11:13:01 +01:00
else if ( $action == 'addline' && $user -> rights -> contrat -> creer )
2003-08-03 21:54:46 +02:00
{
2013-11-17 23:25:25 +01:00
// Set if we used free entry or predefined product
if ( GETPOST ( 'addline_libre' ))
{
$predef = '' ;
$idprod = 0 ;
$product_desc = ( GETPOST ( 'dp_desc' ) ? GETPOST ( 'dp_desc' ) : '' );
$price_ht = GETPOST ( 'price_ht' );
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
}
if ( GETPOST ( 'addline_predefined' ))
{
$predef = (( $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) ? '_predef' : '' );
$idprod = GETPOST ( 'idprod' , 'int' );
$product_desc = ( GETPOST ( 'product_desc' ) ? GETPOST ( 'product_desc' ) : ( GETPOST ( 'np_desc' ) ? GETPOST ( 'np_desc' ) : '' ));
$price_ht = '' ;
$tva_tx = '' ;
}
2013-11-19 17:54:36 +01:00
if ( GETPOST ( 'usenewaddlineform' )) {
$idprod = GETPOST ( 'idprod' , 'int' );
$product_desc = ( GETPOST ( 'product_desc' ) ? GETPOST ( 'product_desc' ) : ( GETPOST ( 'np_desc' ) ? GETPOST ( 'np_desc' ) : ( GETPOST ( 'dp_desc' ) ? GETPOST ( 'dp_desc' ) : '' )));
$price_ht = GETPOST ( 'price_ht' );
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
}
2013-11-17 23:25:25 +01:00
$qty = GETPOST ( 'qty' . $predef );
$remise_percent = GETPOST ( 'remise_percent' . $predef );
if ( $qty == '' )
2012-12-28 11:36:31 +01:00
{
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Qty " )), 'errors' );
$error ++ ;
}
if (( GETPOST ( 'price_ht' ) == '' || ! GETPOST ( 'dp_desc' )) && ! GETPOST ( 'idprod' ))
{
2012-12-29 13:12:45 +01:00
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Description " )), 'errors' );
$error ++ ;
2012-12-28 11:36:31 +01:00
}
2013-01-26 10:35:30 +01:00
2012-12-28 11:36:31 +01:00
if ( ! $error )
2004-11-26 15:17:48 +01:00
{
2012-03-18 11:13:01 +01:00
$ret = $object -> fetch ( $id );
2007-11-12 02:15:20 +01:00
if ( $ret < 0 )
2011-09-21 15:44:20 +02:00
{
2012-01-19 09:20:00 +01:00
dol_print_error ( $db , $object -> error );
2011-09-21 15:44:20 +02:00
exit ;
}
$ret = $object -> fetch_thirdparty ();
2013-11-17 23:25:25 +01:00
// Clean parameters
$date_start = dol_mktime ( GETPOST ( 'date_start' . $predef . 'hour' ), GETPOST ( 'date_start' . $predef . 'min' ), GETPOST ( 'date_start' . $predef . 'sec' ), GETPOST ( 'date_start' . $predef . 'month' ), GETPOST ( 'date_start' . $predef . 'day' ), GETPOST ( 'date_start' . $predef . 'year' ));
$date_end = dol_mktime ( GETPOST ( 'date_end' . $predef . 'hour' ), GETPOST ( 'date_end' . $predef . 'min' ), GETPOST ( 'date_end' . $predef . 'sec' ), GETPOST ( 'date_end' . $predef . 'month' ), GETPOST ( 'date_end' . $predef . 'day' ), GETPOST ( 'date_end' . $predef . 'year' ));
$price_base_type = ( GETPOST ( 'price_base_type' , 'alpha' ) ? GETPOST ( 'price_base_type' , 'alpha' ) : 'HT' );
2011-09-21 15:44:20 +02:00
// 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
2013-11-17 23:25:25 +01:00
if ( $idprod > 0 )
2005-09-02 00:53:08 +02:00
{
2011-09-11 20:35:38 +02:00
$prod = new Product ( $db );
2013-11-17 23:25:25 +01:00
$prod -> fetch ( $idprod );
2007-11-12 02:15:20 +01:00
2012-01-19 09:20:00 +01:00
$tva_tx = get_default_tva ( $mysoc , $object -> thirdparty , $prod -> id );
$tva_npr = get_default_npr ( $mysoc , $object -> thirdparty , $prod -> id );
2007-11-12 02:15:20 +01:00
// On defini prix unitaire
2012-01-19 09:20:00 +01:00
if ( $conf -> global -> PRODUIT_MULTIPRICES && $object -> thirdparty -> price_level )
2007-11-12 02:15:20 +01:00
{
2012-01-19 09:20:00 +01:00
$pu_ht = $prod -> multiprices [ $object -> thirdparty -> price_level ];
$pu_ttc = $prod -> multiprices_ttc [ $object -> thirdparty -> price_level ];
$price_min = $prod -> multiprices_min [ $object -> thirdparty -> price_level ];
$price_base_type = $prod -> multiprices_base_type [ $object -> thirdparty -> price_level ];
2007-11-12 02:15:20 +01:00
}
else
{
2011-09-21 15:44:20 +02:00
$pu_ht = $prod -> price ;
$pu_ttc = $prod -> price_ttc ;
$price_min = $prod -> price_min ;
$price_base_type = $prod -> price_base_type ;
2007-11-12 02:15:20 +01:00
}
2011-09-21 15:44:20 +02:00
// 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
2013-11-17 23:25:25 +01:00
{
2011-09-21 15:44:20 +02:00
$pu_ttc = price2num ( $pu_ht * ( 1 + ( $tva_tx / 100 )), 'MU' );
}
}
2009-01-25 18:05:40 +01:00
2013-11-17 23:25:25 +01:00
$desc = $prod -> description ;
$desc = dol_concatdesc ( $desc , $product_desc );
2005-09-02 00:53:08 +02:00
}
2007-11-12 02:15:20 +01:00
else
2013-11-17 23:25:25 +01:00
{
2012-12-28 11:36:31 +01:00
$pu_ht = GETPOST ( 'price_ht' );
2011-09-21 15:44:20 +02:00
$price_base_type = 'HT' ;
2013-04-03 18:37:54 +02:00
$tva_tx = GETPOST ( 'tva_tx' ) ? str_replace ( '*' , '' , GETPOST ( 'tva_tx' )) : 0 ; // tva_tx field may be disabled, so we use vat rate 0
2012-07-25 11:46:33 +02:00
$tva_npr = preg_match ( '/\*/' , GETPOST ( 'tva_tx' )) ? 1 : 0 ;
2013-11-17 23:25:25 +01:00
$desc = $product_desc ;
2007-11-12 02:15:20 +01:00
}
2014-01-07 12:16:16 +01:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $object -> thirdparty );
2010-07-22 23:16:29 +02:00
2013-02-13 10:35:47 +01:00
// ajout prix achat
$fk_fournprice = $_POST [ 'fournprice' ];
if ( ! empty ( $_POST [ 'buying_price' ]) )
$pa_ht = $_POST [ 'buying_price' ];
else
$pa_ht = null ;
2011-09-21 15:44:20 +02:00
$info_bits = 0 ;
if ( $tva_npr ) $info_bits |= 0x01 ;
2013-11-17 23:25:25 +01:00
if ( $price_min && ( price2num ( $pu_ht ) * ( 1 - price2num ( $remise_percent ) / 100 ) < price2num ( $price_min )))
2011-09-21 15:44:20 +02:00
{
2013-06-17 11:58:55 +02:00
$object -> error = $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ));
2011-09-21 15:44:20 +02:00
$result = - 1 ;
}
else
2013-11-17 23:25:25 +01:00
{
2011-09-21 15:44:20 +02:00
// Insert line
$result = $object -> addline (
2011-10-14 16:44:22 +02:00
$desc ,
$pu_ht ,
2013-11-17 23:25:25 +01:00
$qty ,
2011-10-14 16:44:22 +02:00
$tva_tx ,
$localtax1_tx ,
$localtax2_tx ,
2013-11-17 23:25:25 +01:00
$idprod ,
$remise_percent ,
2011-10-14 16:44:22 +02:00
$date_start ,
$date_end ,
$price_base_type ,
$pu_ttc ,
2013-02-13 10:35:47 +01:00
$info_bits ,
$fk_fournprice ,
$pa_ht
2011-09-21 15:44:20 +02:00
);
}
if ( $result > 0 )
{
/*
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$ret = $object -> fetch ( $id ); // Reload to get new records
contrat_pdf_create ( $db , $object -> id , $object -> modelpdf , $outputlangs );
}
2011-09-21 15:44:20 +02:00
*/
2012-12-28 11:36:31 +01:00
2013-02-13 10:35:47 +01:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'price_ht' ]);
unset ( $_POST [ 'price_ttc' ]);
unset ( $_POST [ 'tva_tx' ]);
unset ( $_POST [ 'product_ref' ]);
unset ( $_POST [ 'product_label' ]);
unset ( $_POST [ 'product_desc' ]);
unset ( $_POST [ 'fournprice' ]);
unset ( $_POST [ 'buying_price' ]);
2013-11-17 23:25:25 +01:00
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'idprod' ]);
unset ( $_POST [ 'qty_predef' ]);
unset ( $_POST [ 'remise_percent_predef' ]);
unset ( $_POST [ 'fournprice_predef' ]);
unset ( $_POST [ 'buying_price_predef' ]);
unset ( $_POST [ 'np_marginRate_predef' ]);
unset ( $_POST [ 'np_markRate_predef' ]);
unset ( $_POST [ 'np_desc' ]);
2011-09-21 15:44:20 +02:00
}
else
{
2011-03-21 18:44:11 +01:00
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2011-09-21 15:44:20 +02:00
}
2004-11-26 15:17:48 +01:00
}
2003-08-03 21:54:46 +02:00
}
2012-07-25 11:46:33 +02:00
else if ( $action == 'updateligne' && $user -> rights -> contrat -> creer && ! GETPOST ( 'cancel' ))
2004-05-06 13:14:09 +02:00
{
2012-03-18 11:13:01 +01:00
$ret = $object -> fetch ( $id );
2012-01-19 09:20:00 +01:00
if ( $ret < 0 )
{
dol_print_error ( $db , $object -> error );
exit ;
}
$object -> fetch_thirdparty ();
2011-03-21 18:44:11 +01:00
$objectline = new ContratLigne ( $db );
2012-07-25 11:46:33 +02:00
if ( $objectline -> fetch ( GETPOST ( 'elrowid' )))
2004-11-26 15:17:48 +01:00
{
2011-09-21 15:44:20 +02:00
$db -> begin ();
2009-01-25 18:05:40 +01:00
2011-09-21 15:44:20 +02:00
if ( $date_start_real_update == '' ) $date_start_real_update = $objectline -> date_ouverture ;
if ( $date_end_real_update == '' ) $date_end_real_update = $objectline -> date_cloture ;
2011-03-21 18:44:11 +01:00
2012-07-25 11:46:33 +02:00
$localtax1_tx = get_localtax ( GETPOST ( 'eltva_tx' ), 1 , $object -> thirdparty );
$localtax2_tx = get_localtax ( GETPOST ( 'eltva_tx' ), 2 , $object -> thirdparty );
2011-03-21 18:44:11 +01:00
2013-02-13 10:35:47 +01:00
// ajout prix d'achat
$fk_fournprice = $_POST [ 'fournprice' ];
if ( ! empty ( $_POST [ 'buying_price' ]) )
$pa_ht = $_POST [ 'buying_price' ];
else
$pa_ht = null ;
2012-12-28 11:36:31 +01:00
$objectline -> description = GETPOST ( 'product_desc' );
2012-07-25 11:46:33 +02:00
$objectline -> price_ht = GETPOST ( 'elprice' );
$objectline -> subprice = GETPOST ( 'elprice' );
$objectline -> qty = GETPOST ( 'elqty' );
$objectline -> remise_percent = GETPOST ( 'elremise_percent' );
2013-03-05 18:13:27 +01:00
$objectline -> tva_tx = GETPOST ( 'eltva_tx' ) ? GETPOST ( 'eltva_tx' ) : 0 ; // Field may be disabled, so we use vat rate 0
2011-09-21 15:44:20 +02:00
$objectline -> localtax1_tx = $localtax1_tx ;
$objectline -> localtax2_tx = $localtax2_tx ;
$objectline -> date_ouverture_prevue = $date_start_update ;
$objectline -> date_ouverture = $date_start_real_update ;
$objectline -> date_fin_validite = $date_end_update ;
2011-03-21 18:44:11 +01:00
$objectline -> date_cloture = $date_end_real_update ;
2011-09-21 15:44:20 +02:00
$objectline -> fk_user_cloture = $user -> id ;
2013-02-13 10:35:47 +01:00
$objectline -> fk_fournprice = $fk_fournprice ;
$objectline -> pa_ht = $pa_ht ;
2011-05-03 20:45:37 +02:00
2011-09-21 15:44:20 +02:00
// TODO verifier price_min si fk_product et multiprix
2009-01-25 18:05:40 +01:00
2011-09-21 15:44:20 +02:00
$result = $objectline -> update ( $user );
2005-06-19 20:37:38 +02:00
if ( $result > 0 )
{
$db -> commit ();
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , 'Failed to update contrat_det' );
2005-06-19 20:37:38 +02:00
$db -> rollback ();
2009-01-25 18:05:40 +01:00
}
2004-11-26 15:17:48 +01:00
}
2005-06-11 13:33:21 +02:00
else
2004-11-26 15:17:48 +01:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2004-11-26 15:17:48 +01:00
}
2004-05-06 13:14:09 +02:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_deleteline' && $confirm == 'yes' && $user -> rights -> contrat -> creer )
2004-11-26 15:17:48 +01:00
{
2012-03-18 11:13:01 +01:00
$object -> fetch ( $id );
2012-07-25 11:46:33 +02:00
$result = $object -> deleteline ( GETPOST ( 'lineid' ), $user );
2004-05-06 13:14:09 +02:00
2008-02-25 01:33:14 +01:00
if ( $result >= 0 )
2005-06-11 13:33:21 +02:00
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2006-05-25 16:41:44 +02:00
exit ;
2004-11-26 15:17:48 +01:00
}
2011-09-21 15:44:20 +02:00
else
{
$mesg = $object -> error ;
}
2004-11-26 15:17:48 +01:00
}
2003-08-04 15:28:09 +02:00
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_valid' && $confirm == 'yes' && $user -> rights -> contrat -> creer )
2004-11-26 15:17:48 +01:00
{
2012-03-18 11:13:01 +01:00
$object -> fetch ( $id );
2012-06-10 10:29:43 +02:00
$result = $object -> validate ( $user );
2004-11-26 15:17:48 +01:00
}
2003-08-04 15:28:09 +02:00
2009-07-08 12:10:35 +02:00
// Close all lines
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_close' && $confirm == 'yes' && $user -> rights -> contrat -> creer )
2003-08-03 21:15:39 +02:00
{
2012-03-18 11:13:01 +01:00
$object -> fetch ( $id );
2012-06-10 10:29:43 +02:00
$result = $object -> cloture ( $user );
2004-11-26 15:17:48 +01:00
}
2004-09-27 01:02:40 +02:00
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> contrat -> supprimer )
2004-11-26 15:17:48 +01:00
{
2012-06-09 18:37:54 +02:00
$object -> fetch ( $id );
2012-07-02 19:30:37 +02:00
$object -> fetch_thirdparty ();
$result = $object -> delete ( $user );
if ( $result >= 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: index.php " );
2012-07-02 19:30:37 +02:00
return ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
2012-03-18 11:13:01 +01:00
}
2003-08-03 21:15:39 +02:00
}
2004-11-26 15:17:48 +01:00
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_move' && $confirm == 'yes' && $user -> rights -> contrat -> creer )
2008-09-26 01:30:06 +02:00
{
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'newcid' ) > 0 )
2012-07-02 19:30:37 +02:00
{
$contractline = new ContratLigne ( $db );
2012-07-25 11:46:33 +02:00
$result = $contractline -> fetch ( GETPOST ( 'lineid' ));
$contractline -> fk_contrat = GETPOST ( 'newcid' );
2012-07-02 19:30:37 +02:00
$result = $contractline -> update ( $user , 1 );
if ( $result >= 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2012-07-02 19:30:37 +02:00
return ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " RefNewContract " )) . '</div>' ;
2012-03-18 11:13:01 +01:00
}
}
2012-07-02 19:30:37 +02:00
else if ( $action == 'setnote_public' && $user -> rights -> contrat -> creer )
{
2013-04-10 10:58:38 +02:00
$result = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_public' ), ENT_QUOTES ), '_public' );
2012-07-02 19:30:37 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
2013-04-09 17:18:07 +02:00
else if ( $action == 'setnote_private' && $user -> rights -> contrat -> creer )
2012-07-02 19:30:37 +02:00
{
2013-04-10 10:58:38 +02:00
$result = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_private' ), ENT_QUOTES ), '_private' );
2012-07-02 19:30:37 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2012-03-18 11:13:01 +01:00
}
2012-10-18 10:35:55 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $user -> rights -> contrat -> creer )
2012-03-18 11:13:01 +01:00
{
2012-10-18 10:35:55 +02:00
if ( $action == 'addcontact' )
2012-07-02 19:30:37 +02:00
{
$result = $object -> fetch ( $id );
if ( $result > 0 && $id > 0 )
{
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
2012-12-29 13:12:45 +01:00
$result = $object -> add_contact ( $contactid , GETPOST ( 'type' ), GETPOST ( 'source' ));
2012-07-02 19:30:37 +02:00
}
if ( $result >= 0 )
2012-03-18 14:06:55 +01:00
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2012-07-02 19:30:37 +02:00
exit ;
}
else
{
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$langs -> load ( " errors " );
$mesg = '<div class="error">' . $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ) . '</div>' ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
}
// bascule du statut d'un contact
2012-10-18 10:35:55 +02:00
else if ( $action == 'swapstatut' )
2012-07-02 19:30:37 +02:00
{
if ( $object -> fetch ( $id ))
{
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' ));
}
else
{
dol_print_error ( $db );
}
}
// Efface un contact
2012-10-18 10:35:55 +02:00
else if ( $action == 'deletecontact' )
2012-07-02 19:30:37 +02:00
{
$object -> fetch ( $id );
2012-07-25 11:46:33 +02:00
$result = $object -> delete_contact ( GETPOST ( 'lineid' ));
2012-07-02 19:30:37 +02:00
if ( $result >= 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2012-07-02 19:30:37 +02:00
exit ;
}
else {
dol_print_error ( $db );
}
2012-03-18 11:13:01 +01:00
}
2008-09-26 01:30:06 +02:00
}
2004-07-27 18:30:19 +02:00
2003-08-03 21:15:39 +02:00
2008-07-12 12:31:58 +02:00
/*
* View
*/
2003-08-03 21:15:39 +02:00
2005-07-03 04:37:16 +02:00
llxHeader ( '' , $langs -> trans ( " ContractCard " ), " Contrat " );
2003-08-03 21:15:39 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2008-02-13 00:45:07 +01:00
2011-03-21 18:44:11 +01:00
$objectlignestatic = new ContratLigne ( $db );
2005-04-23 00:39:11 +02:00
2008-01-20 23:37:52 +01:00
2004-11-26 15:17:48 +01:00
/*********************************************************************
*
* Mode creation
*
2005-06-11 13:33:21 +02:00
*********************************************************************/
2011-06-06 13:35:53 +02:00
if ( $action == 'create' )
2003-08-03 21:15:39 +02:00
{
2012-07-25 11:46:33 +02:00
dol_fiche_head ( '' , '' , $langs -> trans ( " AddContract " ), 0 , 'contract' );
2005-06-11 13:33:21 +02:00
2011-06-18 00:24:52 +02:00
dol_htmloutput_errors ( $mesg , '' );
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
$soc = new Societe ( $db );
2013-03-02 16:50:36 +01:00
if ( $socid > 0 ) $soc -> fetch ( $socid );
2011-05-03 20:45:37 +02:00
2013-03-22 17:10:17 +01:00
if ( GETPOST ( 'origin' ) && GETPOST ( 'originid' ))
{
// Parse element/subelement (ex: project_task)
$element = $subelement = GETPOST ( 'origin' );
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' ), $regs ))
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
if ( $element == 'project' )
{
$projectid = GETPOST ( 'originid' );
}
else
{
// For compatibility
if ( $element == 'order' || $element == 'commande' ) { $element = $subelement = 'commande' ; }
if ( $element == 'propal' ) { $element = 'comm/propal' ; $subelement = 'propal' ; }
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
$classname = ucfirst ( $subelement );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( GETPOST ( 'originid' ));
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) $objectsrc -> fetch_lines ();
$objectsrc -> fetch_thirdparty ();
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $objectsrc -> fk_project : '' );
$soc = $objectsrc -> client ;
2013-04-09 17:18:07 +02:00
$note_private = ( ! empty ( $objectsrc -> note_private ) ? $objectsrc -> note_private : '' );
2013-03-22 17:10:17 +01:00
$note_public = ( ! empty ( $objectsrc -> note_public ) ? $objectsrc -> note_public : '' );
// Object source contacts list
$srccontactslist = $objectsrc -> liste_contact ( - 1 , 'external' , 1 );
}
}
else {
$projectid = GETPOST ( 'projectid' , 'int' );
2013-04-09 17:18:07 +02:00
$note_private = GETPOST ( " note_private " );
2013-03-22 17:10:17 +01:00
$note_public = GETPOST ( " note_public " );
}
2011-09-21 15:44:20 +02:00
$object -> date_contrat = dol_now ();
2011-02-18 20:55:48 +01:00
2011-09-21 15:44:20 +02:00
$numct = $object -> getNextNumRef ( $soc );
2011-05-03 20:45:37 +02:00
2012-03-18 11:13:01 +01:00
print '<form name="form_contract" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2011-01-29 18:26:52 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' . " \n " ;
print '<input type="hidden" name="remise_percent" value="0">' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
print '<table class="border" width="100%">' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
// Ref
2013-03-02 16:50:36 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td colspan="2">' . $langs -> trans ( " Draft " ) . '</td></tr>' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
// Customer
2013-03-02 16:50:36 +01:00
print '<tr>' ;
print '<td class="fieldrequired">' . $langs -> trans ( 'Customer' ) . '</td>' ;
if ( $socid > 0 )
{
print '<td colspan="2">' ;
print $soc -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' ;
print '</td>' ;
}
else
{
print '<td colspan="2">' ;
2013-03-23 12:33:25 +01:00
print $form -> select_company ( '' , 'socid' , 's.client = 1 OR s.client = 3' , 1 );
2013-03-02 16:50:36 +01:00
print '</td>' ;
}
print '</tr>' . " \n " ;
if ( $socid > 0 )
{
// Ligne info remises tiers
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td colspan="2">' ;
2013-06-16 21:31:21 +02:00
if ( $soc -> remise_percent ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_percent );
2013-03-02 16:50:36 +01:00
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
print '. ' ;
$absolute_discount = $soc -> getAvailableDiscounts ();
if ( $absolute_discount ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> trans ( " Currency " . $conf -> currency ));
else print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
print '.' ;
print '</td></tr>' ;
}
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
// Commercial suivi
print '<tr><td width="20%" nowrap><span class="fieldrequired">' . $langs -> trans ( " TypeContact_contrat_internal_SALESREPFOLL " ) . '</span></td><td>' ;
2013-07-27 14:10:57 +02:00
print $form -> select_dolusers ( GETPOST ( " commercial_suivi_id " ) ? GETPOST ( " commercial_suivi_id " ) : $user -> id , 'commercial_suivi_id' , 1 , '' );
2011-01-29 18:26:52 +01:00
print '</td></tr>' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
// Commercial signature
print '<tr><td width="20%" nowrap><span class="fieldrequired">' . $langs -> trans ( " TypeContact_contrat_internal_SALESREPSIGN " ) . '</span></td><td>' ;
2013-07-27 14:10:57 +02:00
print $form -> select_dolusers ( GETPOST ( " commercial_signature_id " ) ? GETPOST ( " commercial_signature_id " ) : $user -> id , 'commercial_signature_id' , 1 , '' );
2011-01-29 18:26:52 +01:00
print '</td></tr>' ;
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
print '<tr><td><span class="fieldrequired">' . $langs -> trans ( " Date " ) . '</span></td><td>' ;
$form -> select_date ( $datecontrat , '' , 0 , 0 , '' , " contrat " );
print " </td></tr> " ;
2011-05-03 20:45:37 +02:00
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> projet -> enabled ))
2004-11-26 15:17:48 +01:00
{
2013-06-14 22:33:01 +02:00
$formproject = new FormProjets ( $db );
2013-06-16 21:31:21 +02:00
2011-09-21 15:44:20 +02:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2013-06-14 22:33:01 +02:00
$formproject -> select_projects ( $soc -> id , $projectid , " projectid " );
2011-09-21 15:44:20 +02:00
print " </td></tr> " ;
2011-01-29 18:26:52 +01:00
}
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td><td valign="top">' ;
2012-10-14 13:18:52 +02:00
2013-05-25 16:50:55 +02:00
2013-03-22 17:10:17 +01:00
$doleditor = new DolEditor ( 'note_public' , $note_public , '' , '100' , 'dolibarr_notes' , 'In' , 1 , true , true , ROWS_3 , 70 );
2012-10-18 10:36:53 +02:00
print $doleditor -> Create ( 1 );
2013-05-25 16:50:55 +02:00
2011-05-03 20:45:37 +02:00
2011-01-29 18:26:52 +01:00
if ( ! $user -> societe_id )
{
2011-09-21 15:44:20 +02:00
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td><td valign="top">' ;
2013-04-09 17:18:07 +02:00
$doleditor = new DolEditor ( 'note_private' , $note_private , '' , '100' , 'dolibarr_notes' , 'In' , 1 , true , true , ROWS_3 , 70 );
2012-10-18 10:36:53 +02:00
print $doleditor -> Create ( 1 );
2012-10-14 13:18:52 +02:00
print '</td></tr>' ;
2011-01-29 18:26:52 +01:00
}
2011-05-03 20:45:37 +02:00
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
// Other attributes
$parameters = array ( 'colspan' => ' colspan="3"' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2011-01-29 18:26:52 +01:00
print " </table> \n " ;
2011-08-13 15:03:03 +02:00
2013-03-22 17:10:17 +01:00
if ( is_object ( $objectsrc ))
{
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
}
2011-08-13 15:03:03 +02:00
print '<br><center><input type="submit" class="button" value="' . $langs -> trans ( " Create " ) . '"></center>' ;
2011-01-29 18:26:52 +01:00
print " </form> \n " ;
2005-10-31 06:19:56 +01:00
2011-08-13 15:03:03 +02:00
dol_fiche_end ();
2005-06-11 13:33:21 +02:00
}
else
2004-11-26 15:17:48 +01:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2005-06-11 13:33:21 +02:00
{
2011-09-21 15:44:20 +02:00
$now = dol_now ();
2009-01-25 18:05:40 +01:00
2011-09-21 15:44:20 +02:00
if ( $id > 0 || ! empty ( $ref ))
2004-11-26 15:17:48 +01:00
{
2012-03-18 11:13:01 +01:00
$result = $object -> fetch ( $id , $ref );
2013-07-31 11:27:56 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2014-03-02 15:50:26 +01:00
$result = $object -> fetch_lines (); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed
2013-07-31 11:27:56 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
$result = $object -> fetch_thirdparty ();
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2005-09-09 23:25:53 +02:00
2011-06-18 00:24:52 +02:00
dol_htmloutput_errors ( $mesg , '' );
2012-04-07 00:22:44 +02:00
2011-09-21 15:44:20 +02:00
$nbofservices = count ( $object -> lines );
2008-04-07 19:16:45 +02:00
2005-09-04 15:22:50 +02:00
$author = new User ( $db );
2011-03-21 18:44:11 +01:00
$author -> fetch ( $object -> user_author_id );
2009-01-25 18:05:40 +01:00
2005-09-04 15:22:50 +02:00
$commercial_signature = new User ( $db );
2011-03-21 18:44:11 +01:00
$commercial_signature -> fetch ( $object -> commercial_signature_id );
2005-09-04 15:22:50 +02:00
$commercial_suivi = new User ( $db );
2011-03-21 18:44:11 +01:00
$commercial_suivi -> fetch ( $object -> commercial_suivi_id );
2005-09-04 15:22:50 +02:00
2011-09-21 15:44:20 +02:00
$head = contract_prepare_head ( $object );
2005-09-04 15:22:50 +02:00
2006-02-17 00:25:41 +01:00
$hselected = 0 ;
2005-09-04 15:22:50 +02:00
2009-08-05 20:22:40 +02:00
dol_fiche_head ( $head , $hselected , $langs -> trans ( " Contract " ), 0 , 'contract' );
2005-09-04 15:22:50 +02:00
/*
* Confirmation de la suppression du contrat
*/
2011-06-06 13:35:53 +02:00
if ( $action == 'delete' )
2005-09-04 15:22:50 +02:00
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " DeleteAContract " ), $langs -> trans ( " ConfirmDeleteAContract " ), " confirm_delete " , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
/*
* Confirmation de la validation
*/
2011-06-06 13:35:53 +02:00
if ( $action == 'valid' )
2005-09-04 15:22:50 +02:00
{
2013-03-02 16:50:36 +01:00
$ref = substr ( $object -> ref , 1 , 4 );
if ( $ref == 'PROV' )
{
$numref = $object -> getNextNumRef ( $soc );
}
else
{
$numref = $object -> ref ;
}
2013-04-03 18:37:54 +02:00
2013-03-02 16:50:36 +01:00
$text = $langs -> trans ( 'ConfirmValidateContract' , $numref );
2013-04-03 18:37:54 +02:00
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " ValidateAContract " ), $text , " confirm_valid " , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
/*
* Confirmation de la fermeture
*/
2011-06-06 13:35:53 +02:00
if ( $action == 'close' )
2005-09-04 15:22:50 +02:00
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " CloseAContract " ), $langs -> trans ( " ConfirmCloseContract " ), " confirm_close " , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
/*
* Contrat
*/
2012-07-25 11:46:33 +02:00
if ( ! empty ( $object -> brouillon ) && $user -> rights -> contrat -> creer )
2005-09-04 15:22:50 +02:00
{
2012-03-18 11:13:01 +01:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '" method="POST">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2005-09-04 15:22:50 +02:00
print '<input type="hidden" name="action" value="setremise">' ;
}
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
print '<table class="border" width="100%">' ;
2005-06-11 13:33:21 +02:00
2012-07-28 20:59:57 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/contrat/liste.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2005-09-27 21:34:03 +02:00
// Ref du contrat
2005-09-17 04:09:36 +02:00
print '<tr><td width="25%">' . $langs -> trans ( " Ref " ) . '</td><td colspan="3">' ;
2012-07-28 20:59:57 +02:00
print $form -> showrefnav ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , '' );
2005-09-04 15:22:50 +02:00
print " </td></tr> " ;
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
// Customer
print " <tr><td> " . $langs -> trans ( " Customer " ) . " </td> " ;
2012-03-18 11:13:01 +01:00
print '<td colspan="3">' . $object -> thirdparty -> getNomUrl ( 1 ) . '</td></tr>' ;
2005-06-11 13:33:21 +02:00
2011-09-21 15:44:20 +02:00
// Ligne info remises tiers
2007-03-26 01:22:10 +02:00
print '<tr><td>' . $langs -> trans ( 'Discount' ) . '</td><td colspan="3">' ;
2013-06-16 21:31:21 +02:00
if ( $object -> thirdparty -> remise_percent ) print $langs -> trans ( " CompanyHasRelativeDiscount " , $object -> thirdparty -> remise_percent );
2011-09-21 15:44:20 +02:00
else print $langs -> trans ( " CompanyHasNoRelativeDiscount " );
2012-03-18 11:13:01 +01:00
$absolute_discount = $object -> thirdparty -> getAvailableDiscounts ();
2011-09-21 15:44:20 +02:00
print '. ' ;
2011-11-23 14:55:36 +01:00
if ( $absolute_discount ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> trans ( " Currency " . $conf -> currency ));
2011-09-21 15:44:20 +02:00
else print $langs -> trans ( " CompanyHasNoAbsoluteDiscount " );
print '.' ;
print '</td></tr>' ;
2006-05-25 16:41:44 +02:00
2005-09-04 15:22:50 +02:00
// Statut contrat
print '<tr><td>' . $langs -> trans ( " Status " ) . '</td><td colspan="3">' ;
2011-03-21 18:44:11 +01:00
if ( $object -> statut == 0 ) print $object -> getLibStatut ( 2 );
2011-09-21 15:44:20 +02:00
else print $object -> getLibStatut ( 4 );
2005-09-04 15:22:50 +02:00
print " </td></tr> " ;
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
// Date
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td>' ;
2011-03-21 18:44:11 +01:00
print '<td colspan="3">' . dol_print_date ( $object -> date_contrat , " dayhour " ) . " </td></tr> \n " ;
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
// Projet
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> projet -> enabled ))
2005-09-04 15:22:50 +02:00
{
$langs -> load ( " projects " );
print '<tr><td>' ;
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( " Project " );
print '</td>' ;
2012-03-18 11:13:01 +01:00
if ( $action != " classify " && $user -> rights -> projet -> creer ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( " SetProject " )) . '</a></td>' ;
2005-09-04 15:22:50 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2011-08-23 20:40:45 +02:00
if ( $action == " classify " )
2005-09-04 15:22:50 +02:00
{
2012-03-18 11:13:01 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , " projectid " );
2005-09-04 15:22:50 +02:00
}
else
{
2012-03-18 11:13:01 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , " none " );
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
print " </td></tr> " ;
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
// Other attributes
$parameters = array ( 'colspan' => ' colspan="3"' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2005-09-04 15:22:50 +02:00
print " </table> " ;
2005-06-11 13:33:21 +02:00
2012-07-25 11:46:33 +02:00
if ( ! empty ( $object -> brouillon ) && $user -> rights -> contrat -> creer )
2005-09-04 15:22:50 +02:00
{
print '</form>' ;
}
2005-06-11 13:33:21 +02:00
2011-09-21 15:44:20 +02:00
echo '<br>' ;
2012-04-07 00:22:44 +02:00
2012-07-02 19:30:37 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ))
{
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
2012-08-23 02:04:35 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
2012-07-02 19:30:37 +02:00
}
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB ))
{
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
2012-08-23 02:04:35 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
2012-03-18 11:13:01 +01:00
}
2012-04-07 00:22:44 +02:00
2009-01-25 18:05:40 +01:00
2011-09-21 15:44:20 +02:00
$colorb = '666666' ;
2008-04-06 21:34:55 +02:00
2011-09-21 15:44:20 +02:00
$arrayothercontracts = $object -> getListOfContracts ( 'others' );
2009-01-25 18:05:40 +01:00
2011-09-21 15:44:20 +02:00
/*
2009-05-06 20:07:34 +02:00
* Lines of contracts
2005-09-04 15:22:50 +02:00
*/
2011-05-03 20:45:37 +02:00
$productstatic = new Product ( $db );
2012-04-07 00:22:44 +02:00
2011-09-21 15:44:20 +02:00
// Title line for service
2013-07-31 11:41:25 +02:00
//print '<table class="notopnoleft allwidth">'; // Array with (n*2)+1 lines
2011-09-21 15:44:20 +02:00
$cursorline = 1 ;
while ( $cursorline <= $nbofservices )
{
2013-07-31 11:41:25 +02:00
//print '<tr '.$bc[false].'>';
//print '<td width="90" style="border-left: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';">';
//print $langs->trans("ServiceNb",$cursorline).'</td>';
2011-09-21 15:44:20 +02:00
2013-07-31 11:41:25 +02:00
// print '<td class="tab" style="border-right: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';" rowspan="2">';
print '<form name="update" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="updateligne">' ;
print '<input type="hidden" name="elrowid" value="' . GETPOST ( 'rowid' ) . '">' ;
print '<input type="hidden" name="idprod" value="' . ( $objp -> fk_product ? $objp -> fk_product : '0' ) . '">' ;
print '<input type="hidden" name="fournprice" value="' . ( $objp -> fk_fournprice ? $objp -> fk_fournprice : '0' ) . '">' ;
2011-09-21 15:44:20 +02:00
// Area with common detail of line
2013-07-31 11:41:25 +02:00
print '<table class="notopnoleft allwidth" width="100%">' ;
2011-09-21 15:44:20 +02:00
$sql = " SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty, " ;
$sql .= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice, " ;
$sql .= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle, " ;
$sql .= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle, " ;
2013-02-13 10:35:47 +01:00
$sql .= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht, " ;
2011-09-21 15:44:20 +02:00
$sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
$sql .= " WHERE cd.rowid = " . $object -> lines [ $cursorline - 1 ] -> id ;
$result = $db -> query ( $sql );
if ( $result )
{
$total = 0 ;
print '<tr class="liste_titre">' ;
2013-07-31 11:41:25 +02:00
print '<td>' . $langs -> trans ( " ServiceNb " , $cursorline ) . '</td>' ;
2011-09-21 15:44:20 +02:00
print '<td width="50" align="center">' . $langs -> trans ( " VAT " ) . '</td>' ;
print '<td width="50" align="right">' . $langs -> trans ( " PriceUHT " ) . '</td>' ;
print '<td width="30" align="center">' . $langs -> trans ( " Qty " ) . '</td>' ;
print '<td width="50" align="right">' . $langs -> trans ( " ReductionShort " ) . '</td>' ;
2013-02-13 10:35:47 +01:00
if ( $conf -> margin -> enabled )
print '<td width="50" align="right">' . $langs -> trans ( " BuyingPrice " ) . '</td>' ;
2011-09-21 15:44:20 +02:00
print '<td width="30"> </td>' ;
print " </tr> \n " ;
$var = true ;
$objp = $db -> fetch_object ( $result );
$var =! $var ;
2012-07-25 11:46:33 +02:00
if ( $action != 'editline' || GETPOST ( 'rowid' ) != $objp -> rowid )
2011-09-21 15:44:20 +02:00
{
print '<tr ' . $bc [ $var ] . ' valign="top">' ;
// Libelle
if ( $objp -> fk_product > 0 )
{
print '<td>' ;
2011-05-03 20:45:37 +02:00
$productstatic -> id = $objp -> fk_product ;
$productstatic -> type = $objp -> ptype ;
$productstatic -> ref = $objp -> pref ;
print $productstatic -> getNomUrl ( 1 , '' , 20 );
print $objp -> label ? ' - ' . dol_trunc ( $objp -> label , 16 ) : '' ;
2011-09-21 15:44:20 +02:00
if ( $objp -> description ) print '<br>' . dol_nl2br ( $objp -> description );
print '</td>' ;
}
else
{
2012-12-28 11:36:31 +01:00
print " <td> " . dol_htmlentitiesbr ( $objp -> description ) . " </td> \n " ;
2011-09-21 15:44:20 +02:00
}
// TVA
print '<td align="center">' . vatrate ( $objp -> tva_tx , '%' , $objp -> info_bits ) . '</td>' ;
// Prix
print '<td align="right">' . price ( $objp -> subprice ) . " </td> \n " ;
// Quantite
print '<td align="center">' . $objp -> qty . '</td>' ;
// Remise
if ( $objp -> remise_percent > 0 )
{
print '<td align="right">' . $objp -> remise_percent . " %</td> \n " ;
}
else
{
print '<td> </td>' ;
}
2013-02-13 10:35:47 +01:00
if ( $conf -> margin -> enabled )
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . price ( $objp -> pa_ht ) . '</td>' ;
2013-02-13 10:35:47 +01:00
2011-09-21 15:44:20 +02:00
// Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2011-09-21 15:44:20 +02:00
if ( $user -> rights -> contrat -> creer && count ( $arrayothercontracts ) && ( $object -> statut >= 0 ))
{
2012-03-18 11:13:01 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=move&rowid=' . $objp -> rowid . '">' ;
2011-09-21 15:44:20 +02:00
print img_picto ( $langs -> trans ( " MoveToAnotherContract " ), 'uparrow' );
print '</a>' ;
}
else {
print ' ' ;
}
if ( $user -> rights -> contrat -> creer && ( $object -> statut >= 0 ))
{
2012-03-18 11:13:01 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=editline&rowid=' . $objp -> rowid . '">' ;
2011-09-21 15:44:20 +02:00
print img_edit ();
print '</a>' ;
}
else {
print ' ' ;
}
if ( $user -> rights -> contrat -> creer && ( $object -> statut >= 0 ))
{
print ' ' ;
2012-03-18 11:13:01 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=deleteline&rowid=' . $objp -> rowid . '">' ;
2011-09-21 15:44:20 +02:00
print img_delete ();
print '</a>' ;
}
print '</td>' ;
print " </tr> \n " ;
// Dates de en service prevues et effectives
if ( $objp -> subprice >= 0 )
{
print '<tr ' . $bc [ $var ] . '>' ;
2013-02-13 10:35:47 +01:00
print '<td colspan="' . ( $conf -> margin -> enabled ? 7 : 6 ) . '">' ;
2011-09-21 15:44:20 +02:00
// Date planned
print $langs -> trans ( " DateStartPlanned " ) . ': ' ;
if ( $objp -> date_debut )
{
print dol_print_date ( $db -> jdate ( $objp -> date_debut ));
// Warning si date prevu passee et pas en service
if ( $objp -> statut == 0 && $db -> jdate ( $objp -> date_debut ) < ( $now - $conf -> contrat -> services -> inactifs -> warning_delay )) { print " " . img_warning ( $langs -> trans ( " Late " )); }
}
else print $langs -> trans ( " Unknown " );
print ' - ' ;
print $langs -> trans ( " DateEndPlanned " ) . ': ' ;
if ( $objp -> date_fin )
{
print dol_print_date ( $db -> jdate ( $objp -> date_fin ));
if ( $objp -> statut == 4 && $db -> jdate ( $objp -> date_fin ) < ( $now - $conf -> contrat -> services -> expires -> warning_delay )) { print " " . img_warning ( $langs -> trans ( " Late " )); }
}
else print $langs -> trans ( " Unknown " );
print '</td>' ;
print '</tr>' ;
}
}
// Ligne en mode update
else
2013-07-31 11:41:25 +02:00
{
2011-09-21 15:44:20 +02:00
// Ligne carac
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2011-09-21 15:44:20 +02:00
print '<td>' ;
if ( $objp -> fk_product )
{
2011-05-03 20:45:37 +02:00
$productstatic -> id = $objp -> fk_product ;
$productstatic -> type = $objp -> ptype ;
$productstatic -> ref = $objp -> pref ;
print $productstatic -> getNomUrl ( 1 , '' , 20 );
print $objp -> label ? ' - ' . dol_trunc ( $objp -> label , 16 ) : '' ;
2011-09-21 15:44:20 +02:00
print '<br>' ;
}
else
{
print $objp -> label ? $objp -> label . '<br>' : '' ;
}
2012-12-28 11:36:31 +01:00
2012-12-29 13:12:45 +01:00
// editeur wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
$enable = ( isset ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS ) ? $conf -> global -> FCKEDITOR_ENABLE_DETAILS : 0 );
$doleditor = new DolEditor ( 'product_desc' , $objp -> description , '' , 92 , 'dolibarr_details' , '' , false , true , $enable , $nbrows , 70 );
$doleditor -> Create ();
2012-12-28 11:36:31 +01:00
print '</td>' ;
2011-09-21 15:44:20 +02:00
print '<td align="right">' ;
2012-03-18 11:13:01 +01:00
print $form -> load_tva ( " eltva_tx " , $objp -> tva_tx , $mysoc , $object -> thirdparty );
2011-09-21 15:44:20 +02:00
print '</td>' ;
print '<td align="right"><input size="5" type="text" name="elprice" value="' . price ( $objp -> subprice ) . '"></td>' ;
print '<td align="center"><input size="2" type="text" name="elqty" value="' . $objp -> qty . '"></td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap"><input size="1" type="text" name="elremise_percent" value="' . $objp -> remise_percent . '">%</td>' ;
2013-02-13 10:35:47 +01:00
if ( $conf -> margin -> enabled ) {
print '<td align="right">' ;
if ( $objp -> fk_product )
print '<select id="fournprice" name="fournprice"></select>' ;
print '<input id="buying_price" type="text" size="5" name="buying_price" value="' . price ( $objp -> pa_ht , 0 , '' , 0 ) . '"></td>' ;
}
2012-03-04 16:48:05 +01:00
print '<td align="center" rowspan="2" valign="middle"><input type="submit" class="button" name="save" value="' . $langs -> trans ( " Modify " ) . '">' ;
2011-09-21 15:44:20 +02:00
print '<br><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</td>' ;
// Ligne dates prevues
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2013-02-13 10:35:47 +01:00
print '<td colspan="' . ( $conf -> margin -> enabled ? 6 : 5 ) . '">' ;
2011-09-21 15:44:20 +02:00
print $langs -> trans ( " DateStartPlanned " ) . ' ' ;
$form -> select_date ( $db -> jdate ( $objp -> date_debut ), " date_start_update " , $usehm , $usehm ,( $db -> jdate ( $objp -> date_debut ) > 0 ? 0 : 1 ), " update " );
print '<br>' . $langs -> trans ( " DateEndPlanned " ) . ' ' ;
$form -> select_date ( $db -> jdate ( $objp -> date_fin ), " date_end_update " , $usehm , $usehm ,( $db -> jdate ( $objp -> date_fin ) > 0 ? 0 : 1 ), " update " );
print '</td>' ;
print '</tr>' ;
}
$db -> free ( $result );
}
else
2013-07-31 11:41:25 +02:00
{
2011-09-21 15:44:20 +02:00
dol_print_error ( $db );
}
if ( $object -> statut > 0 )
{
print '<tr ' . $bc [ false ] . '>' ;
2013-02-13 10:35:47 +01:00
print '<td colspan="' . ( $conf -> margin -> enabled ? 7 : 6 ) . '"><hr></td>' ;
2011-09-21 15:44:20 +02:00
print " </tr> \n " ;
}
print " </table> " ;
2013-11-17 23:25:25 +01:00
2013-07-31 11:41:25 +02:00
print " </form> \n " ;
2011-09-21 15:44:20 +02:00
/*
* Confirmation to delete service line of contract
*/
2012-07-25 11:46:33 +02:00
if ( $action == 'deleteline' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> creer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'rowid' ))
2011-09-21 15:44:20 +02:00
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &lineid= " . GETPOST ( 'rowid' ), $langs -> trans ( " DeleteContractLine " ), $langs -> trans ( " ConfirmDeleteContractLine " ), " confirm_deleteline " , '' , 0 , 1 );
2011-09-21 15:44:20 +02:00
if ( $ret == 'html' ) print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ false ] . ' height="6"><td></td></tr></table>' ;
}
/*
* Confirmation to move service toward another contract
*/
2012-07-25 11:46:33 +02:00
if ( $action == 'move' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> creer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'rowid' ))
2011-09-21 15:44:20 +02:00
{
$arraycontractid = array ();
foreach ( $arrayothercontracts as $contractcursor )
{
$arraycontractid [ $contractcursor -> id ] = $contractcursor -> ref ;
}
//var_dump($arraycontractid);
// Cree un tableau formulaire
$formquestion = array (
2008-09-26 01:30:06 +02:00
'text' => $langs -> trans ( " ConfirmMoveToAnotherContractQuestion " ),
2011-09-21 15:44:20 +02:00
array ( 'type' => 'select' , 'name' => 'newcid' , 'values' => $arraycontractid ));
2012-07-25 11:46:33 +02:00
$form -> form_confirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &lineid= " . GETPOST ( 'rowid' ), $langs -> trans ( " MoveToAnotherContract " ), $langs -> trans ( " ConfirmMoveToAnotherContract " ), " confirm_move " , $formquestion );
2011-09-21 15:44:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ false ] . ' height="6"><td></td></tr></table>' ;
}
/*
* Confirmation de la validation activation
*/
2012-07-25 11:46:33 +02:00
if ( $action == 'active' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> activer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
$dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
$comment = GETPOST ( 'comment' );
$form -> form_confirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &ligne= " . GETPOST ( 'ligne' ) . " &date= " . $dateactstart . " &dateend= " . $dateactend . " &comment= " . urlencode ( $comment ), $langs -> trans ( " ActivateService " ), $langs -> trans ( " ConfirmActivateService " , dol_print_date ( $dateactstart , " %A %d %B %Y " )), " confirm_active " , '' , 0 , 1 );
2011-09-21 15:44:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ false ] . ' height="6"><td></td></tr></table>' ;
}
/*
* Confirmation de la validation fermeture
*/
2012-07-25 11:46:33 +02:00
if ( $action == 'closeline' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> activer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' ))
2011-09-21 15:44:20 +02:00
{
2012-07-25 11:46:33 +02:00
$dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
$dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
$comment = GETPOST ( 'comment' );
$form -> form_confirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &ligne= " . GETPOST ( 'ligne' ) . " &date= " . $dateactstart . " &dateend= " . $dateactend . " &comment= " . urlencode ( $comment ), $langs -> trans ( " CloseService " ), $langs -> trans ( " ConfirmCloseService " , dol_print_date ( $dateactend , " %A %d %B %Y " )), " confirm_closeline " , '' , 0 , 1 );
2011-09-21 15:44:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ false ] . ' height="6"><td></td></tr></table>' ;
}
// Area with status and activation info of line
if ( $object -> statut > 0 )
{
print '<table class="notopnoleft" width="100%">' ;
print '<tr ' . $bc [ false ] . '>' ;
print '<td>' . $langs -> trans ( " ServiceStatus " ) . ': ' . $object -> lines [ $cursorline - 1 ] -> getLibStatut ( 4 ) . '</td>' ;
print '<td width="30" align="right">' ;
if ( $user -> societe_id == 0 )
{
2012-03-18 11:13:01 +01:00
if ( $object -> statut > 0 && $action != 'activateline' && $action != 'unactivateline' )
2011-09-21 15:44:20 +02:00
{
2012-04-07 01:03:55 +02:00
$tmpaction = 'activateline' ;
if ( $objp -> statut == 4 ) $tmpaction = 'unactivateline' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . $object -> lines [ $cursorline - 1 ] -> id . '&action=' . $tmpaction . '">' ;
2011-09-21 15:44:20 +02:00
print img_edit ();
print '</a>' ;
}
}
print '</td>' ;
print " </tr> \n " ;
print '<tr ' . $bc [ false ] . '>' ;
print '<td>' ;
// Si pas encore active
if ( ! $objp -> date_debut_reelle ) {
print $langs -> trans ( " DateStartReal " ) . ': ' ;
if ( $objp -> date_debut_reelle ) print dol_print_date ( $objp -> date_debut_reelle );
else print $langs -> trans ( " ContractStatusNotRunning " );
}
// Si active et en cours
if ( $objp -> date_debut_reelle && ! $objp -> date_fin_reelle ) {
print $langs -> trans ( " DateStartReal " ) . ': ' ;
print dol_print_date ( $objp -> date_debut_reelle );
}
// Si desactive
if ( $objp -> date_debut_reelle && $objp -> date_fin_reelle ) {
print $langs -> trans ( " DateStartReal " ) . ': ' ;
print dol_print_date ( $objp -> date_debut_reelle );
print ' - ' ;
print $langs -> trans ( " DateEndReal " ) . ': ' ;
print dol_print_date ( $objp -> date_fin_reelle );
}
if ( ! empty ( $objp -> comment )) print " <br> " . $objp -> comment ;
print '</td>' ;
print '<td align="center"> </td>' ;
print '</tr>' ;
print '</table>' ;
}
2012-07-25 11:46:33 +02:00
if ( $user -> rights -> contrat -> activer && $action == 'activateline' && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' ))
2011-09-21 15:44:20 +02:00
{
/**
* Activer la ligne de contrat
*/
2012-07-25 11:46:33 +02:00
print '<form name="active" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . GETPOST ( 'ligne' ) . '&action=active" method="post">' ;
2011-09-21 15:44:20 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="noborder" width="100%">' ;
//print '<tr class="liste_titre"><td colspan="5">'.$langs->trans("Status").'</td></tr>';
// Definie date debut et fin par defaut
$dateactstart = $objp -> date_debut ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'remonth' )) $dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
2011-09-21 15:44:20 +02:00
elseif ( ! $dateactstart ) $dateactstart = time ();
$dateactend = $objp -> date_fin ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'endmonth' )) $dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
2011-09-21 15:44:20 +02:00
elseif ( ! $dateactend )
{
if ( $objp -> fk_product > 0 )
{
$product = new Product ( $db );
$product -> fetch ( $objp -> fk_product );
2011-10-14 16:44:22 +02:00
$dateactend = dol_time_plus_duree ( time (), $product -> duration_value , $product -> duration_unit );
2011-09-21 15:44:20 +02:00
}
}
print '<tr ' . $bc [ $var ] . '><td>' . $langs -> trans ( " DateServiceActivate " ) . '</td><td>' ;
2011-11-08 10:18:45 +01:00
print $form -> select_date ( $dateactstart , '' , $usehm , $usehm , '' , " active " );
2011-09-21 15:44:20 +02:00
print '</td>' ;
print '<td>' . $langs -> trans ( " DateEndPlanned " ) . '</td><td>' ;
2011-11-08 10:18:45 +01:00
print $form -> select_date ( $dateactend , " end " , $usehm , $usehm , '' , " active " );
2011-09-21 15:44:20 +02:00
print '</td>' ;
print '<td align="center" rowspan="2" valign="middle">' ;
print '<input type="submit" class="button" name="activate" value="' . $langs -> trans ( " Activate " ) . '"><br>' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</td>' ;
print '</tr>' ;
2013-02-13 10:35:47 +01:00
print '<tr ' . $bc [ $var ] . '><td>' . $langs -> trans ( " Comment " ) . '</td><td colspan="' . ( $conf -> margin -> enabled ? 4 : 3 ) . '"><input size="80" type="text" name="comment" value="' . $_POST [ " comment " ] . '"></td></tr>' ;
2011-09-21 15:44:20 +02:00
print '</table>' ;
print '</form>' ;
}
2012-07-25 11:46:33 +02:00
if ( $user -> rights -> contrat -> activer && $action == 'unactivateline' && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' ))
2011-09-21 15:44:20 +02:00
{
/**
* Desactiver la ligne de contrat
*/
print '<form name="closeline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . $object -> lines [ $cursorline - 1 ] -> id . '&action=closeline" method="post">' ;
2013-11-17 23:25:25 +01:00
2011-09-21 15:44:20 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="noborder" width="100%">' ;
// Definie date debut et fin par defaut
$dateactstart = $objp -> date_debut_reelle ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'remonth' )) $dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
2011-09-21 15:44:20 +02:00
elseif ( ! $dateactstart ) $dateactstart = time ();
$dateactend = $objp -> date_fin_reelle ;
2012-07-25 11:46:33 +02:00
if ( GETPOST ( 'endmonth' )) $dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
2011-09-21 15:44:20 +02:00
elseif ( ! $dateactend )
{
if ( $objp -> fk_product > 0 )
{
$product = new Product ( $db );
$product -> fetch ( $objp -> fk_product );
2011-10-14 16:44:22 +02:00
$dateactend = dol_time_plus_duree ( time (), $product -> duration_value , $product -> duration_unit );
2011-09-21 15:44:20 +02:00
}
}
2012-04-30 15:01:25 +02:00
$now = dol_now ();
2011-09-21 15:44:20 +02:00
if ( $dateactend > $now ) $dateactend = $now ;
print '<tr ' . $bc [ $var ] . '><td colspan="2">' ;
if ( $objp -> statut >= 4 )
{
if ( $objp -> statut == 4 )
{
print $langs -> trans ( " DateEndReal " ) . ' ' ;
2014-03-02 15:58:02 +01:00
$form -> select_date ( $dateactend , " end " , $usehm , $usehm ,( $objp -> date_fin_reelle > 0 ? 0 : 1 ), " closeline " , 1 , 1 );
2011-09-21 15:44:20 +02:00
}
}
print '</td>' ;
print '<td align="right" rowspan="2"><input type="submit" class="button" name="close" value="' . $langs -> trans ( " Close " ) . '"><br>' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</td></tr>' ;
2012-07-25 11:46:33 +02:00
print '<tr ' . $bc [ $var ] . '><td>' . $langs -> trans ( " Comment " ) . '</td><td><input size="70" type="text" class="flat" name="comment" value="' . GETPOST ( 'comment' ) . '"></td></tr>' ;
2011-09-21 15:44:20 +02:00
print '</table>' ;
print '</form>' ;
}
2013-07-31 11:41:25 +02:00
/* print '</td>' ; // End td if line is 1
2011-09-21 15:44:20 +02:00
print '</tr>' ;
2013-07-31 11:41:25 +02:00
print '<tr><td style="border-right: 1px solid #' . $colorb . '"> </td></tr>' ; */
2011-09-21 15:44:20 +02:00
$cursorline ++ ;
}
2013-07-31 11:41:25 +02:00
//print '</table>';
2011-09-21 15:44:20 +02:00
2013-11-17 23:25:25 +01:00
2012-12-28 11:36:31 +01:00
// Form to add new line
2011-09-21 15:44:20 +02:00
if ( $user -> rights -> contrat -> creer && ( $object -> statut >= 0 ))
{
2012-12-28 11:36:31 +01:00
$dateSelector = 1 ;
2013-01-26 10:35:30 +01:00
2013-11-17 23:25:25 +01:00
print " \n " ;
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . (( $action != 'editline' ) ? '#add' : '#line_' . GETPOST ( 'lineid' )) . ' " method= " POST " >
< input type = " hidden " name = " token " value = " '. $_SESSION['newtoken'] .' " >
< input type = " hidden " name = " action " value = " '.(( $action != 'editline')?'addline':'updateligne').' " >
< input type = " hidden " name = " mode " value = " " >
< input type = " hidden " name = " id " value = " '. $object->id .' " >
' ;
print '<br>' ;
print '<table id="tablelines" class="noborder noshadow" width="100%">' ; // Array with (n*2)+1 lines
2012-12-28 11:36:31 +01:00
// Trick to not show product entries
$savproductenabled = $conf -> product -> enabled ;
$conf -> product -> enabled = 0 ;
2012-12-29 13:12:45 +01:00
// Form to add new line
if ( $action != 'editline' )
{
$var = true ;
if ( $conf -> global -> MAIN_FEATURES_LEVEL > 1 )
{
// Add free or predefined products/services
2013-01-26 10:35:30 +01:00
$object -> formAddObjectLine ( $dateSelector , $mysoc , $object -> thirdparty );
2012-12-29 13:12:45 +01:00
}
else
{
// Add free products/services
2013-01-26 10:35:30 +01:00
$object -> formAddFreeProduct ( $dateSelector , $mysoc , $object -> thirdparty );
2012-12-29 13:12:45 +01:00
// Add predefined products/services
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))
{
$var =! $var ;
2013-01-26 10:35:30 +01:00
$object -> formAddPredefinedProduct ( $dateSelector , $mysoc , $object -> thirdparty );
2012-12-29 13:12:45 +01:00
}
}
2013-01-26 10:35:30 +01:00
2012-12-29 13:12:45 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formAddObjectLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
}
2013-01-26 10:35:30 +01:00
2012-12-28 11:36:31 +01:00
// Restore correct setup
$conf -> product -> enabled = $savproductenabled ;
2013-01-26 10:35:30 +01:00
2011-09-21 15:44:20 +02:00
print '</table>' ;
2013-11-17 23:25:25 +01:00
print '</form>' ;
}
2011-09-21 15:44:20 +02:00
2013-11-17 23:25:25 +01:00
dol_fiche_end ();
2005-06-11 13:33:21 +02:00
2012-12-28 11:36:31 +01:00
/*
* Buttons
*/
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
if ( $user -> societe_id == 0 )
{
print '<div class="tabsAction">' ;
2005-06-11 13:33:21 +02:00
2011-03-21 18:44:11 +01:00
if ( $object -> statut == 0 && $nbofservices )
2005-09-04 15:22:50 +02:00
{
2013-04-03 18:37:54 +02:00
if ( $user -> rights -> contrat -> creer ) print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a></div>' ;
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " Validate " ) . '</a></div>' ;
2005-09-04 15:22:50 +02:00
}
2005-06-11 13:33:21 +02:00
2012-09-15 11:21:22 +02:00
if ( ! empty ( $conf -> facture -> enabled ) && $object -> statut > 0 && $object -> nbofservicesclosed < $nbofservices )
2005-09-04 15:22:50 +02:00
{
$langs -> load ( " bills " );
2013-04-03 18:37:54 +02:00
if ( $user -> rights -> facture -> creer ) print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> thirdparty -> id . '">' . $langs -> trans ( " CreateBill " ) . '</a></div>' ;
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " CreateBill " ) . '</a></div>' ;
2005-09-04 15:22:50 +02:00
}
2005-07-04 00:56:13 +02:00
2011-09-21 15:44:20 +02:00
if ( $object -> nbofservicesclosed < $nbofservices )
2005-09-04 15:22:50 +02:00
{
2011-09-21 15:44:20 +02:00
//if (! $numactive)
//{
2013-04-03 18:37:54 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=close">' . $langs -> trans ( " CloseAllContracts " ) . '</a></div>' ;
2011-09-21 15:44:20 +02:00
//}
//else
//{
2013-04-03 18:37:54 +02:00
// print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("CloseRefusedBecauseOneServiceActive").'">'.$langs->trans("Close").'</a></div>';
2011-09-21 15:44:20 +02:00
//}
2005-09-04 15:22:50 +02:00
}
2009-01-25 18:05:40 +01:00
2007-02-22 21:45:16 +01:00
// On peut supprimer entite si
2011-09-21 15:44:20 +02:00
// - Droit de creer + mode brouillon (erreur creation)
// - Droit de supprimer
if (( $user -> rights -> contrat -> creer && $object -> statut == 0 ) || $user -> rights -> contrat -> supprimer )
2005-09-04 15:22:50 +02:00
{
2013-04-03 18:37:54 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a></div>' ;
2005-06-11 13:33:21 +02:00
}
2012-12-28 11:36:31 +01:00
else
{
2013-04-03 18:37:54 +02:00
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NotAllowed " )) . '">' . $langs -> trans ( " Delete " ) . '</a></div>' ;
2012-12-28 11:36:31 +01:00
}
2005-06-11 13:33:21 +02:00
2005-09-04 15:22:50 +02:00
print " </div> " ;
2011-09-21 15:44:20 +02:00
print '<br>' ;
2005-06-11 13:33:21 +02:00
}
2011-06-06 13:35:53 +02:00
2011-05-06 20:27:18 +02:00
print '<table width="100%"><tr><td width="50%" valign="top">' ;
2010-05-05 19:36:20 +02:00
2011-09-21 15:44:20 +02:00
/*
* Linked object block
*/
2011-05-06 20:27:18 +02:00
$somethingshown = $object -> showLinkedObjectBlock ();
2011-06-06 13:35:53 +02:00
2011-05-06 20:27:18 +02:00
print '</td><td valign="top" width="50%">' ;
print '</td></tr></table>' ;
2005-06-11 13:33:21 +02:00
}
2003-08-03 21:15:39 +02:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-12-28 11:36:31 +01:00
2012-03-18 11:13:01 +01:00
$db -> close ();
2003-08-03 21:15:39 +02:00
?>
2013-11-17 23:25:25 +01:00
2013-02-13 10:35:47 +01:00
< ? php
2013-11-17 23:25:25 +01:00
if ( $conf -> margin -> enabled && $action == 'editline' )
{
2013-02-13 10:35:47 +01:00
?>
2013-11-17 23:25:25 +01:00
2013-02-13 10:35:47 +01:00
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
var idprod = $ ( " input[name='idprod'] " ) . val ();
var fournprice = $ ( " input[name='fournprice'] " ) . val ();
if ( idprod > 0 ) {
$ . post ( '<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php' , { 'idprod' : idprod }, function ( data ) {
if ( data . length > 0 ) {
var options = '' ;
var trouve = false ;
$ ( data ) . each ( function () {
options += '<option value="' + this . id + '" price="' + this . price + '"' ;
if ( fournprice > 0 ) {
if ( this . id == fournprice ) {
options += ' selected' ;
$ ( " #buying_price " ) . val ( this . price );
trouve = true ;
}
}
options += '>' + this . label + '</option>' ;
});
options += '<option value=null' + ( trouve ? '' : ' selected' ) + '><?php echo $langs->trans("InputPrice"); ?></option>' ;
$ ( " #fournprice " ) . html ( options );
if ( trouve ) {
$ ( " #buying_price " ) . hide ();
$ ( " #fournprice " ) . show ();
}
else {
$ ( " #buying_price " ) . show ();
}
$ ( " #fournprice " ) . change ( function () {
var selval = $ ( this ) . find ( 'option:selected' ) . attr ( " price " );
if ( selval )
$ ( " #buying_price " ) . val ( selval ) . hide ();
else
$ ( '#buying_price' ) . show ();
});
}
else {
$ ( " #fournprice " ) . hide ();
$ ( '#buying_price' ) . show ();
}
},
'json' );
}
else {
$ ( " #fournprice " ) . hide ();
$ ( '#buying_price' ) . show ();
}
});
</ script >
2013-11-17 23:25:25 +01:00
< ? php
}
?>