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 >
2014-12-11 14:15:40 +01:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-09-28 20:39:02 +02:00
* Copyright ( C ) 2005 - 2014 Regis Houssin < regis . houssin @ capnetworks . com >
2012-03-18 11:13:01 +01:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2014-07-12 10:56:13 +02:00
* Copyright ( C ) 2010 - 2014 Juanjo Menent < jmenent @ 2 byte . es >
2014-01-07 12:16:16 +01:00
* Copyright ( C ) 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
2014-07-05 11:17:50 +02:00
* Copyright ( C ) 2013 - 2014 Florian Henry < florian . henry @ open - concept . pro >
2014-08-01 13:25:29 +02:00
* Copyright ( C ) 2014 Ferran Marcet < fmarcet @ 2 byte . es >
2014-12-28 18:56:23 +01:00
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
2015-04-18 21:28:55 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
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
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / contrat / card . php
2008-08-07 22:46:15 +02:00
* \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' ;
2015-04-29 19:57:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2012-08-22 23:11:24 +02:00
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
}
2014-07-05 11:17:50 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
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 " );
2014-07-11 16:12:31 +02:00
$langs -> load ( 'compta' );
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
2014-10-06 07:20:58 +02:00
$hookmanager -> initHooks ( array ( 'contractcard' , 'globalcard' ));
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
2011-03-21 18:44:11 +01:00
$object = new Contrat ( $db );
2014-07-05 11:17:50 +02:00
$extrafields = new ExtraFields ( $db );
2014-09-28 20:39:02 +02:00
// Load object
2015-02-02 18:03:18 +01:00
if ( $id > 0 || ! empty ( $ref ) && $action != 'add' ) {
2014-09-28 20:39:02 +02:00
$ret = $object -> fetch ( $id , $ref );
if ( $ret > 0 )
$ret = $object -> fetch_thirdparty ();
if ( $ret < 0 )
dol_print_error ( '' , $object -> error );
}
2014-07-05 11:17:50 +02:00
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2011-03-21 18:44:11 +01:00
2015-02-28 04:59:27 +01:00
// fetch optionals attributes lines and labels
2015-01-27 12:53:02 +01:00
$extrafieldsline = new ExtraFields ( $db );
$extralabelslines = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2014-01-11 13:33:30 +01:00
$permissionnote = $user -> rights -> contrat -> creer ; // Used by the include of actions_setnotes.inc.php
2009-01-25 18:05:40 +01:00
2008-02-13 00:45:07 +01:00
/*
* Actions
*/
2014-01-11 13:33:30 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not includ_once
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-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 {
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
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 )
{
$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 {
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2014-03-02 15:58:02 +01:00
}
}
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 ++ ;
2014-07-05 11:17:50 +02:00
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), 'errors' );
2013-03-02 16:50:36 +01:00
$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
2015-02-02 18:03:18 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 ) {
$error ++ ;
$action = 'create' ;
}
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' );
2014-09-24 10:21:26 +02:00
$object -> ref_supplier = GETPOST ( 'ref_supplier' , '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 ) {
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2013-03-22 17:10:17 +01:00
}
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 ;
2014-09-04 18:58:33 +02:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' ))
{
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
}
2013-03-22 17:10:17 +01:00
$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-12-11 14:15:40 +01:00
if ( $product_type == 1 || ( ! empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS ) && in_array ( $product_type , array ( 0 , 1 )))) { // 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 ))
{
2014-03-12 01:21:18 +01:00
$prod = new Product ( $db );
$prod -> id = $lines [ $i ] -> fk_product ;
$prod -> getMultiLangs ();
2013-03-22 17:10:17 +01:00
$outputlangs = $langs ;
$newlang = '' ;
if ( empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
2014-08-01 16:17:31 +02:00
if ( empty ( $newlang )) $newlang = $srcobject -> thirdparty -> default_lang ;
2013-03-22 17:10:17 +01:00
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 ,
2015-04-19 15:59:49 +02:00
$lines [ $i ] -> pa_ht ,
array (),
$lines [ $i ] -> fk_unit
2013-03-22 17:10:17 +01:00
);
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
}
}
else
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $srcobject -> error , 'errors' );
2013-03-22 17:10:17 +01:00
$error ++ ;
}
}
else
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2013-03-22 17:10:17 +01:00
$error ++ ;
}
}
else
{
2014-07-05 11:17:50 +02:00
$result = $object -> create ( $user );
2013-03-22 17:10:17 +01:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
else {
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2013-03-22 17:10:17 +01:00
}
$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-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
2014-05-05 14:30:08 +02:00
$predef = '' ;
$product_desc = ( GETPOST ( 'dp_desc' ) ? GETPOST ( 'dp_desc' ) : '' );
if ( GETPOST ( 'prod_entry_mode' ) == 'free' )
2013-11-17 23:25:25 +01:00
{
$idprod = 0 ;
$price_ht = GETPOST ( 'price_ht' );
2014-05-05 14:30:08 +02:00
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
2013-11-17 23:25:25 +01:00
}
2014-05-05 14:30:08 +02:00
else
2013-11-17 23:25:25 +01:00
{
$idprod = GETPOST ( 'idprod' , 'int' );
$price_ht = '' ;
$tva_tx = '' ;
}
2014-05-05 14:30:08 +02:00
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 ++ ;
}
2014-05-05 17:59:43 +02:00
if ( GETPOST ( 'prod_entry_mode' ) == 'free' && empty ( $idprod ) && empty ( $product_desc ))
2012-12-28 11:36:31 +01:00
{
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
2015-01-27 12:53:02 +01:00
// Extrafields
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2015-02-28 04:59:27 +01:00
$array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline , $predef );
2015-01-27 12:53:02 +01:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
unset ( $_POST [ " options_ " . $key ]);
}
}
2012-12-28 11:36:31 +01:00
if ( ! $error )
2004-11-26 15:17:48 +01:00
{
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 );
2014-08-01 13:25:29 +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
// 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
}
2014-08-01 13:25:29 +02:00
elseif ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ))
{
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php' ;
$prodcustprice = new Productcustomerprice ( $db );
2014-08-01 16:17:31 +02:00
$filter = array ( 't.fk_product' => $prod -> id , 't.fk_soc' => $object -> thirdparty -> id );
2014-08-01 13:25:29 +02:00
$result = $prodcustprice -> fetch_all ( '' , '' , 0 , 0 , $filter );
if ( $result ) {
if ( count ( $prodcustprice -> lines ) > 0 ) {
$pu_ht = price ( $prodcustprice -> lines [ 0 ] -> price );
$pu_ttc = price ( $prodcustprice -> lines [ 0 ] -> price_ttc );
$price_base_type = $prodcustprice -> lines [ 0 ] -> price_base_type ;
$prod -> tva_tx = $prodcustprice -> lines [ 0 ] -> tva_tx ;
}
}
}
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 );
2015-02-26 14:15:33 +01:00
$fk_unit = $prod -> fk_unit ;
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 ;
2015-04-21 15:49:58 +02:00
$fk_unit = GETPOST ( 'units' , 'alpha' );
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 ,
2015-01-27 12:53:02 +01:00
$pa_ht ,
2015-04-03 15:45:54 +02:00
$array_options ,
2015-02-26 14:15:33 +01:00
$fk_unit
2011-09-21 15:44:20 +02:00
);
}
if ( $result > 0 )
{
2014-10-27 19:37:30 +01:00
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-11-23 13:14:54 +01:00
2014-10-27 19:37:30 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2014-12-11 13:12:05 +01:00
2014-11-23 13:14:54 +01:00
$object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2014-10-27 19:37:30 +01:00
}
2012-12-28 11:36:31 +01:00
2014-05-05 14:30:08 +02:00
unset ( $_POST [ 'prod_entry_mode' ]);
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' ]);
2014-05-05 17:59:43 +02:00
unset ( $_POST [ 'np_marginRate' ]);
unset ( $_POST [ 'np_markRate' ]);
2013-11-17 23:25:25 +01:00
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'idprod' ]);
2014-05-05 17:59:43 +02:00
unset ( $_POST [ 'date_starthour' ]);
unset ( $_POST [ 'date_startmin' ]);
unset ( $_POST [ 'date_startsec' ]);
unset ( $_POST [ 'date_startday' ]);
unset ( $_POST [ 'date_startmonth' ]);
unset ( $_POST [ 'date_startyear' ]);
unset ( $_POST [ 'date_endhour' ]);
unset ( $_POST [ 'date_endmin' ]);
unset ( $_POST [ 'date_endsec' ]);
unset ( $_POST [ 'date_endday' ]);
unset ( $_POST [ 'date_endmonth' ]);
unset ( $_POST [ 'date_endyear' ]);
2011-09-21 15:44:20 +02:00
}
else
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
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
{
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 ;
2015-04-21 15:49:58 +02:00
$fk_unit = GETPOST ( 'unit' , 'alpha' );
2015-02-26 14:15:33 +01:00
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
2015-02-26 14:15:33 +01:00
if ( $fk_unit > 0 ) {
2015-04-21 15:49:58 +02:00
$objectline -> fk_unit = GETPOST ( 'unit' );
2015-02-26 14:15:33 +01:00
} else {
$objectline -> fk_unit = null ;
}
2015-01-27 12:53:02 +01:00
// Extrafields
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $objectline -> table_element );
2015-02-28 04:59:27 +01:00
$array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline , $predef );
$objectline -> array_options = $array_options ;
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
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $objectline -> error , 'errors' );
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
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $objectline -> error , 'errors' );
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-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
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2011-09-21 15:44:20 +02:00
}
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-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
{
2015-02-10 13:32:00 +01:00
$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-07-02 19:30:37 +02:00
$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
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
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
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2012-07-02 19:30:37 +02:00
}
}
else
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " RefNewContract " )), 'errors' );
}
} else if ( $action == 'update_extras' ) {
// Fill array 'array_options' with data from update form
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object , GETPOST ( 'attribute' ));
if ( $ret < 0 )
$error ++ ;
if ( ! $error ) {
2014-09-04 18:58:33 +02:00
2014-07-05 11:17:50 +02:00
$result = $object -> insertExtraFields ();
if ( $result < 0 ) {
$error ++ ;
}
} else if ( $reshook < 0 )
$error ++ ;
if ( $error ) {
$action = 'edit_extras' ;
setEventMessage ( $object -> error , 'errors' );
2012-03-18 11:13:01 +01:00
}
2014-09-24 10:21:26 +02:00
} elseif ( $action == 'setref_supplier' ) {
2014-09-04 18:58:33 +02:00
2014-12-28 18:56:23 +01:00
$cancelbutton = GETPOST ( 'cancel' );
if ( ! $cancelbutton ) {
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
setEventMessage ( $object -> errors , 'errors' );
}
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
$result = $object -> update ( $user );
if ( $result < 0 ) {
setEventMessage ( $object -> errors , 'errors' );
$action = 'editref_supplier' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2014-07-11 11:26:54 +02:00
}
2014-08-12 13:26:06 +02:00
} elseif ( $action == 'setref' ) {
$object -> ref = GETPOST ( 'ref' , 'alpha' );
2014-09-04 18:58:33 +02:00
2014-08-12 13:26:06 +02:00
$result = $object -> update ( $user );
if ( $result < 0 ) {
setEventMessage ( $object -> errors , 'errors' );
$action = 'editref' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2012-03-18 11:13:01 +01:00
}
2014-09-28 20:39:02 +02:00
// Generation doc (depuis lien ou depuis cartouche doc)
else if ( $action == 'builddoc' && $user -> rights -> contrat -> creer ) {
if ( GETPOST ( 'model' )) {
$object -> setDocModel ( $user , GETPOST ( 'model' ));
}
// Define output language
$outputlangs = $langs ;
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
$outputlangs = new Translate ( " " , $conf );
$newlang = ( GETPOST ( 'lang_id' ) ? GETPOST ( 'lang_id' ) : $object -> thirdparty -> default_lang );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result <= 0 ) {
dol_print_error ( $db , $result );
exit ();
} else {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#builddoc' ));
exit ();
}
}
// Remove file in doc form
else if ( $action == 'remove_file' && $user -> rights -> contrat -> creer ) {
if ( $object -> id > 0 ) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$langs -> load ( " other " );
$upload_dir = $conf -> contrat -> dir_output ;
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
if ( $ret )
setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'file' )));
else
setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'file' )), 'errors' );
}
}
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
{
2014-09-28 20:39:02 +02:00
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
$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 " );
2014-07-05 11:17:50 +02:00
setEventMessage ( $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ), 'errors' );
2012-07-02 19:30:37 +02:00
}
else
{
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2012-07-02 19:30:37 +02:00
}
}
}
// 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
{
2014-09-28 20:39:02 +02:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' ));
2012-07-02 19:30:37 +02:00
}
// Efface un contact
2012-10-18 10:35:55 +02:00
else if ( $action == 'deletecontact' )
2012-07-02 19:30:37 +02:00
{
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 {
2014-07-05 11:17:50 +02:00
setEventMessage ( $object -> error , 'errors' );
2012-07-02 19:30:37 +02:00
}
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 );
2014-09-28 20:39:02 +02:00
$formfile = new FormFile ( $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
2014-08-12 13:26:06 +02:00
// Load object modContract
2014-12-11 13:12:05 +01:00
$module = ( ! empty ( $conf -> global -> CONTRACT_ADDON ) ? $conf -> global -> CONTRACT_ADDON : 'mod_contract_serpis' );
2014-08-12 13:26:06 +02:00
if ( substr ( $module , 0 , 13 ) == 'mod_contract_' && substr ( $module , - 3 ) == 'php' )
{
$module = substr ( $module , 0 , dol_strlen ( $module ) - 4 );
}
$result = dol_include_once ( '/core/modules/contract/' . $module . '.php' );
if ( $result > 0 )
{
$modCodeContract = new $module ();
}
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
{
2015-04-18 21:28:55 +02:00
print_fiche_titre ( $langs -> trans ( 'AddContract' ), '' , 'title_commercial.png' );
2005-06-11 13:33:21 +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
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
2015-04-10 10:20:51 +02:00
dol_fiche_head ();
2015-04-21 15:49:58 +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
2014-08-12 13:26:06 +02:00
if ( ! empty ( $modCodeContract -> code_auto )) {
$tmpcode = $langs -> trans ( " Draft " );
} else {
$tmpcode = '<input name="ref" size="20" maxlength="128" value="' . dol_escape_htmltag ( GETPOST ( 'ref' ) ? GETPOST ( 'ref' ) : $tmpcode ) . '">' ;
}
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td colspan="2">' . $tmpcode . '</td></tr>' ;
2014-09-04 18:58:33 +02:00
2014-11-20 10:48:55 +01:00
// Ref supplier
print '<tr><td>' . $langs -> trans ( 'RefSupplier' ) . '</td>' ;
2014-10-27 14:02:37 +01:00
print '<td colspan="2"><input type="text" size="5" name="ref_supplier" id="ref_supplier" value="' . GETPOST ( 'ref_supplier' , 'alpha' ) . '"></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
2014-02-27 10:37:23 +01:00
if ( empty ( $user -> societe_id ))
2011-01-29 18:26:52 +01:00
{
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
2014-07-05 11:17:50 +02:00
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' );
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
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2014-09-04 18:58:33 +02:00
2014-07-05 11:17:50 +02:00
// Other attributes
if ( empty ( $reshook ) && ! empty ( $extrafields -> attribute_label )) {
print $object -> showOptionals ( $extrafields , 'edit' );
}
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
2011-01-29 18:26:52 +01:00
print " </table> \n " ;
2011-08-13 15:03:03 +02:00
2015-04-10 10:20:51 +02:00
dol_fiche_end ();
print '<div align="center"><input type="submit" class="button" value="' . $langs -> trans ( " Create " ) . '"></div>' ;
2014-12-11 14:15:40 +01: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 . '">' ;
2014-12-11 14:15:40 +01:00
if ( empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS ))
{
print '<br>' . $langs -> trans ( " Note " ) . ': ' . $langs -> trans ( " OnlyLinesWithTypeServiceAreUsed " );
}
}
2015-04-21 15:49:58 +02:00
2011-01-29 18:26:52 +01:00
print " </form> \n " ;
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
2014-09-28 20:39:02 +02:00
if ( $object -> id > 0 )
2004-11-26 15:17:48 +01:00
{
2014-12-11 13:12:05 +01:00
$object -> fetch_thirdparty ();
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 );
2005-09-09 23:25:53 +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 );
2014-08-12 13:26:06 +02:00
if ( $ref == 'PROV' && ! empty ( $modCodeContract -> code_auto ))
2013-03-02 16:50:36 +01:00
{
2015-03-04 18:18:55 +01:00
$numref = $object -> getNextNumRef ( $object -> thirdparty );
2013-03-02 16:50:36 +01:00
}
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
2014-09-18 20:33:37 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/contrat/list.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2012-07-28 20:59:57 +02:00
2005-09-27 21:34:03 +02:00
// Ref du contrat
2014-08-12 13:26:06 +02:00
if ( ! empty ( $modCodeContract -> code_auto )) {
print '<tr><td width="25%">' . $langs -> trans ( " Ref " ) . '</td><td colspan="3">' ;
print $form -> showrefnav ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , '' );
print " </td></tr> " ;
} else {
print '<tr>' ;
print '<td width="20%">' ;
print $form -> editfieldkey ( " Ref " , 'ref' , $object -> ref , $object , $user -> rights -> contrat -> creer );
print '</td><td>' ;
print $form -> editfieldval ( " Ref " , 'ref' , $object -> ref , $object , $user -> rights -> contrat -> creer );
print '</td>' ;
print '</tr>' ;
}
2005-06-11 13:33:21 +02:00
2014-07-11 11:26:54 +02:00
print '<tr>' ;
print '<td width="20%">' ;
2014-11-20 10:48:55 +01:00
print $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> contrat -> creer );
2014-07-11 11:26:54 +02:00
print '</td><td>' ;
2014-11-20 10:48:55 +01:00
print $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> contrat -> creer );
2014-07-11 11:26:54 +02:00
print '</td>' ;
print '</tr>' ;
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
{
2015-01-30 19:57:38 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , " projectid " , 0 , 0 , 1 );
2005-09-04 15:22:50 +02:00
}
else
{
2015-01-30 19:57:38 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , " none " , 0 , 0 );
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
2014-10-14 17:00:06 +02:00
$cols = 3 ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
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
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
*/
2012-04-07 00:22:44 +02:00
2015-04-29 19:57:01 +02:00
$productstatic = new Product ( $db );
2014-05-12 13:25:36 +02:00
$usemargins = 0 ;
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $object -> element ) && in_array ( $object -> element , array ( 'facture' , 'propal' , 'commande' ))) $usemargins = 1 ;
2015-04-10 10:17:20 +02:00
$var = false ;
2015-04-21 15:49:58 +02:00
2015-04-10 10:17:20 +02:00
// Title line for service
2011-09-21 15:44:20 +02:00
$cursorline = 1 ;
while ( $cursorline <= $nbofservices )
{
2013-07-31 11:41:25 +02:00
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
2014-05-12 13:25:36 +02:00
print '<table class="notopnoleftnoright allwidth tableforservicepart1" 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, " ;
2015-02-26 14:15:33 +01:00
$sql .= " cd.fk_unit, " ;
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>' ;
2015-04-21 15:49:58 +02:00
if ( $conf -> global -> PRODUCT_USE_UNITS ) print '<td width="30" align="left">' . $langs -> trans ( " Unit " ) . '</td>' ;
2011-09-21 15:44:20 +02:00
print '<td width="50" align="right">' . $langs -> trans ( " ReductionShort " ) . '</td>' ;
2014-04-23 13:51:02 +02:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) 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 " ;
$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 ;
2015-04-29 19:15:14 +02:00
$text = $productstatic -> getNomUrl ( 1 , '' , 20 );
2014-05-05 14:30:08 +02:00
if ( $objp -> label )
{
2015-04-29 19:15:14 +02:00
$text .= ' - ' ;
2014-05-05 14:30:08 +02:00
$productstatic -> ref = $objp -> label ;
2015-04-29 19:15:14 +02:00
$text .= $productstatic -> getNomUrl ( 0 , '' , 16 );
2014-05-05 14:30:08 +02:00
}
2015-04-29 19:15:14 +02:00
$description = $objp -> description ;
// Add description in form
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
{
$text .= ( ! empty ( $objp -> description ) && $objp -> description != $objp -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $objp -> description ) : '' ;
$description = '' ; // Already added into main visible desc
}
echo $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $cursorline , 0 ,( ! empty ( $line -> fk_parent_line ) ? img_picto ( '' , 'rightarrow' ) : '' ));
2011-09-21 15:44:20 +02:00
print '</td>' ;
}
else
2015-04-29 19:15:14 +02:00
{
2015-04-10 10:17:20 +02: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
2015-04-10 10:17:20 +02:00
print '<td align="right">' . ( $objp -> subprice != '' ? price ( $objp -> subprice ) : '' ) . " </td> \n " ;
2011-09-21 15:44:20 +02:00
// Quantite
print '<td align="center">' . $objp -> qty . '</td>' ;
2015-04-21 15:49:58 +02:00
// Unit
if ( $conf -> global -> PRODUCT_USE_UNITS ) print '<td align="left">' . $langs -> trans ( $object -> lines [ $cursorline - 1 ] -> getLabelOfUnit ()) . '</td>' ;
2011-09-21 15:44:20 +02:00
// Remise
if ( $objp -> remise_percent > 0 )
{
2015-04-10 10:17:20 +02:00
print '<td align="right" ' . $bc [ $var ] . '>' . $objp -> remise_percent . " %</td> \n " ;
2011-09-21 15:44:20 +02:00
}
else
{
print '<td> </td>' ;
}
2013-02-13 10:35:47 +01:00
2014-04-23 13:51:02 +02:00
// Margin
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) 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 )
{
2015-02-26 14:15:33 +01:00
$colspan = 6 ;
if ( $conf -> margin -> enabled && $conf -> global -> PRODUCT_USE_UNITS ) {
$colspan = 8 ;
} elseif ( $conf -> margin -> enabled || $conf -> global -> PRODUCT_USE_UNITS ) {
$colspan = 7 ;
}
2011-09-21 15:44:20 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2015-02-26 14:15:33 +01:00
print '<td colspan="' . $colspan . '">' ;
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>' ;
}
2015-02-28 04:59:27 +01:00
2015-01-27 12:53:02 +01:00
//Display lines extrafields
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
print '<tr ' . $bc [ $var ] . '>' ;
$line = new ContratLigne ( $db );
$line -> fetch_optionals ( $objp -> rowid , $extralabelslines );
print $line -> showOptionals ( $extrafieldsline , 'view' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ));
print '</tr>' ;
}
2011-09-21 15:44:20 +02:00
}
// 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>' ;
2015-04-21 15:49:58 +02:00
if ( $conf -> global -> PRODUCT_USE_UNITS )
{
print '<td align="left">' ;
print $form -> selectUnits ( $objp -> fk_unit , " unit " );
print '</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>' ;
2014-05-12 13:25:36 +02:00
if ( ! empty ( $usemargins ))
{
2013-02-13 10:35:47 +01:00
print '<td align="right">' ;
2014-05-12 13:25:36 +02:00
if ( $objp -> fk_product ) print '<select id="fournprice" name="fournprice"></select>' ;
2013-02-13 10:35:47 +01:00
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>' ;
2014-04-23 13:51:02 +02:00
$colspan = 5 ;
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) $colspan ++ ;
2015-02-26 14:15:33 +01:00
if ( $conf -> global -> PRODUCT_USE_UNITS ) $colspan ++ ;
2014-04-23 13:51:02 +02:00
2011-09-21 15:44:20 +02:00
// Ligne dates prevues
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2014-04-23 13:51:02 +02:00
print '<td colspan="' . $colspan . '">' ;
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 " );
2015-04-10 10:17:20 +02:00
print ' ' . $langs -> trans ( " DateEndPlanned " ) . ' ' ;
2011-09-21 15:44:20 +02:00
$form -> select_date ( $db -> jdate ( $objp -> date_fin ), " date_end_update " , $usehm , $usehm ,( $db -> jdate ( $objp -> date_fin ) > 0 ? 0 : 1 ), " update " );
print '</td>' ;
2015-02-28 04:59:27 +01:00
2015-01-27 12:53:02 +01:00
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
print '<tr ' . $bc [ $var ] . '>' ;
$line = new ContratLigne ( $db );
$line -> fetch_optionals ( $objp -> rowid , $extralabelslines );
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ));
print '</tr>' ;
}
2015-02-28 04:59:27 +01:00
2011-09-21 15:44:20 +02:00
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 )
{
2015-04-10 10:17:20 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
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 );
2015-04-10 10:17:20 +02:00
if ( $ret == 'html' ) print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ $var ] . ' height="6"><td></td></tr></table>' ;
2011-09-21 15:44:20 +02:00
}
/*
* 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 );
2015-04-10 10:17:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ $var ] . ' height="6"><td></td></tr></table>' ;
2011-09-21 15:44:20 +02:00
}
/*
* 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 );
2015-04-10 10:17:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ $var ] . ' height="6"><td></td></tr></table>' ;
2011-09-21 15:44:20 +02:00
}
/*
* 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 );
2015-04-10 10:17:20 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr ' . $bc [ $var ] . ' height="6"><td></td></tr></table>' ;
2011-09-21 15:44:20 +02:00
}
// Area with status and activation info of line
if ( $object -> statut > 0 )
{
2014-05-12 13:25:36 +02:00
print '<table class="notopnoleftnoright tableforservicepart2" width="100%">' ;
2011-09-21 15:44:20 +02:00
2015-04-10 10:17:20 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2011-09-21 15:44:20 +02:00
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 " ;
2015-04-10 10:17:20 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2011-09-21 15:44:20 +02:00
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' ] . '">' ;
2015-04-10 10:17:20 +02:00
print '<table class="notopnoleftnoright tableforservicepart2" width="100%">' ;
2011-09-21 15:44:20 +02:00
// 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' ] . '">' ;
2015-04-10 10:17:20 +02:00
print '<table class="noborder tableforservicepart2" width="100%">' ;
2011-09-21 15:44:20 +02:00
// 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>' ;
}
$cursorline ++ ;
}
2013-11-17 23:25:25 +01:00
2012-12-28 11:36:31 +01:00
// Form to add new line
2014-12-28 17:43:25 +01:00
if ( $user -> rights -> contrat -> creer && ( $object -> statut == 0 ))
2011-09-21 15:44:20 +02:00
{
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 ;
2014-05-05 14:30:08 +02:00
if ( empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS )) $conf -> product -> enabled = 0 ;
2012-12-28 11:36:31 +01:00
2012-12-29 13:12:45 +01:00
// Form to add new line
2014-05-05 14:30:08 +02:00
if ( $action != 'editline' )
{
$var = true ;
// Add free products/services
$object -> formAddObjectLine ( 1 , $mysoc , $soc );
$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">' ;
2015-01-30 19:57:38 +01:00
2014-12-11 16:17:37 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
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> " ;
2005-06-11 13:33:21 +02:00
}
2011-06-06 13:35:53 +02:00
2014-09-28 20:39:02 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2014-04-23 13:51:02 +02:00
2014-09-28 20:39:02 +02:00
/*
* Documents generes
*/
$filename = dol_sanitizeFileName ( $object -> ref );
$filedir = $conf -> contrat -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref );
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
$genallowed = $user -> rights -> contrat -> creer ;
$delallowed = $user -> rights -> contrat -> supprimer ;
2014-04-23 13:51:02 +02:00
2014-09-28 20:39:02 +02:00
$var = true ;
$somethingshown = $formfile -> show_documents ( 'contract' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 1 , 0 , 0 , 28 , 0 , '' , 0 , '' , $soc -> default_lang );
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
2014-09-28 20:39:02 +02:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
2011-06-06 13:35:53 +02:00
2014-09-28 20:39:02 +02:00
print '</div></div></div>' ;
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
}