2004-10-19 22:43:23 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2003 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2020-01-13 15:58:03 +01:00
* Copyright ( C ) 2004 - 2019 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2014 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
* Copyright ( C ) 2010 - 2017 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 >
2020-12-10 13:11:55 +01:00
* Copyright ( C ) 2014 - 2020 Ferran Marcet < fmarcet @ 2 byte . es >
2016-07-23 16:37:21 +02:00
* Copyright ( C ) 2014 - 2016 Marcos García < marcosgdf @ gmail . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2021-02-21 23:30:55 +01:00
* Copyright ( C ) 2018 - 2021 Frédéric France < frederic . france @ netlogic . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// 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
2018-07-26 11:57:25 +02: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' ;
2022-01-23 19:26:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> propal -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
}
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> 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
}
2019-11-16 23:24:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2003-08-03 21:15:39 +02:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
2019-11-16 23:24:29 +01:00
$langs -> loadLangs ( array ( " contracts " , " orders " , " companies " , " bills " , " products " , 'compta' ));
2004-11-26 15:17:48 +01:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-11-16 23:24:29 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2021-03-29 15:07:23 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
$id = GETPOST ( 'id' , 'int' );
2019-11-16 23:24:29 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
$origin = GETPOST ( 'origin' , 'alpha' );
$originid = GETPOST ( 'originid' , 'int' );
2011-09-21 15:44:20 +02:00
2019-11-16 23:24:29 +01:00
$datecontrat = '' ;
$usehm = ( ! empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE : 0 );
2012-07-25 11:46:33 +02:00
2011-09-21 15:44:20 +02:00
// Security check
2021-02-23 21:24:38 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2019-11-16 23:24:29 +01:00
$result = restrictedArea ( $user , 'contrat' , $id );
2006-03-13 14:19:24 +01:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-16 23:24:29 +01: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
2019-11-16 23:24:29 +01:00
if ( $id > 0 || ! empty ( $ref ) && $action != 'add' ) {
2014-09-28 20:39:02 +02:00
$ret = $object -> fetch ( $id , $ref );
2021-02-23 21:24:38 +01:00
if ( $ret > 0 ) {
2014-09-28 20:39:02 +02:00
$ret = $object -> fetch_thirdparty ();
2021-02-23 21:24:38 +01:00
}
if ( $ret < 0 ) {
2014-09-28 20:39:02 +02:00
dol_print_error ( '' , $object -> error );
2021-02-23 21:24:38 +01:00
}
2014-09-28 20:39:02 +02:00
}
2014-07-05 11:17:50 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$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
2019-11-13 19:35:39 +01:00
$extralabelslines = $extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
2015-01-27 12:53:02 +01:00
2019-11-13 19:35:39 +01:00
$permissionnote = $user -> rights -> contrat -> creer ; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user -> rights -> contrat -> creer ; // Used by the include of actions_dellink.inc.php
2014-01-11 13:33:30 +01:00
2021-01-02 17:04:08 +01:00
$error = 0 ;
2009-01-25 18:05:40 +01:00
2018-02-20 19:20:03 +01:00
2008-02-13 00:45:07 +01:00
/*
* Actions
*/
2015-09-03 13:57:38 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 21:24:38 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
if ( empty ( $reshook )) {
2021-09-02 21:35:36 +02:00
$backurlforlist = DOL_URL_ROOT . '/contrat/list.php' ;
if ( empty ( $backtopage ) || ( $cancel && empty ( $id ))) {
if ( empty ( $backtopage ) || ( $cancel && strpos ( $backtopage , '__ID__' ))) {
if ( empty ( $id ) && (( $action != 'add' && $action != 'create' ) || $cancel )) {
$backtopage = $backurlforlist ;
} else {
$backtopage = DOL_URL_ROOT . '/contrat/card.php?id=' . (( ! empty ( $id ) && $id > 0 ) ? $id : '__ID__' );
}
}
}
if ( $cancel ) {
if ( ! empty ( $backtopageforcancel )) {
header ( " Location: " . $backtopageforcancel );
exit ;
} elseif ( ! empty ( $backtopage )) {
header ( " Location: " . $backtopage );
exit ;
}
$action = '' ;
}
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not includ_once
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $action == 'confirm_active' && $confirm == 'yes' && $user -> rights -> contrat -> activer ) {
2021-03-29 15:07:23 +02:00
$result = $object -> active_line ( $user , GETPOST ( 'ligne' , 'int' ), GETPOST ( 'date' ), GETPOST ( 'dateend' ), GETPOST ( 'comment' ));
2017-10-16 08:47:05 +02:00
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2017-10-16 08:47:05 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'confirm_closeline' && $confirm == 'yes' && $user -> rights -> contrat -> activer ) {
if ( ! GETPOST ( 'dateend' )) {
2015-09-03 13:57:38 +02:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DateEnd " )), null , 'errors' );
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
2021-03-29 15:07:23 +02:00
$result = $object -> close_line ( $user , GETPOST ( 'ligne' , 'int' ), GETPOST ( 'dateend' ), urldecode ( GETPOST ( 'comment' )));
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2017-10-16 08:47:05 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-09-03 13:57:38 +02:00
}
2013-03-02 16:50:36 +01:00
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// Si ajout champ produit predefini
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'mode' ) == 'predefined' ) {
2019-11-13 19:35:39 +01:00
$date_start = '' ;
$date_end = '' ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_startmonth' ) && GETPOST ( 'date_startday' ) && GETPOST ( 'date_startyear' )) {
2019-11-13 19:35:39 +01:00
$date_start = dol_mktime ( GETPOST ( 'date_starthour' ), GETPOST ( 'date_startmin' ), 0 , GETPOST ( 'date_startmonth' ), GETPOST ( 'date_startday' ), GETPOST ( 'date_startyear' ));
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_endmonth' ) && GETPOST ( 'date_endday' ) && GETPOST ( 'date_endyear' )) {
2019-11-13 19:35:39 +01:00
$date_end = dol_mktime ( GETPOST ( 'date_endhour' ), GETPOST ( 'date_endmin' ), 0 , GETPOST ( 'date_endmonth' ), GETPOST ( 'date_endday' ), GETPOST ( 'date_endyear' ));
2017-10-16 08:47:05 +02:00
}
2015-02-02 18:03:18 +01:00
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// Param dates
2019-11-13 19:35:39 +01:00
$date_start_update = '' ;
$date_end_update = '' ;
$date_start_real_update = '' ;
$date_end_real_update = '' ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_start_updatemonth' ) && GETPOST ( 'date_start_updateday' ) && GETPOST ( 'date_start_updateyear' )) {
2019-11-13 19:35:39 +01: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' ));
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_end_updatemonth' ) && GETPOST ( 'date_end_updateday' ) && GETPOST ( 'date_end_updateyear' )) {
2019-11-13 19:35:39 +01: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' ));
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_start_real_updatemonth' ) && GETPOST ( 'date_start_real_updateday' ) && GETPOST ( 'date_start_real_updateyear' )) {
2019-11-13 19:35:39 +01: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' ));
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'date_end_real_updatemonth' ) && GETPOST ( 'date_end_real_updateday' ) && GETPOST ( 'date_end_real_updateyear' )) {
2019-11-13 19:35:39 +01: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' ));
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'remonth' ) && GETPOST ( 'reday' ) && GETPOST ( 'reyear' )) {
2017-10-16 08:47:05 +02:00
$datecontrat = dol_mktime ( GETPOST ( 'rehour' ), GETPOST ( 'remin' ), 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
2015-09-03 13:57:38 +02:00
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// Add contract
2021-02-23 21:24:38 +01:00
if ( $action == 'add' && $user -> rights -> contrat -> creer ) {
2015-09-03 13:57:38 +02:00
// Check
2021-02-23 21:24:38 +01:00
if ( empty ( $datecontrat )) {
2015-09-03 13:57:38 +02:00
$error ++ ;
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2019-11-13 19:35:39 +01:00
$action = 'create' ;
2015-09-03 13:57:38 +02:00
}
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $socid < 1 ) {
2016-09-14 19:48:57 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ThirdParty " )), null , 'errors' );
2019-11-13 19:35:39 +01:00
$action = 'create' ;
2015-09-03 13:57:38 +02:00
$error ++ ;
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2015-09-03 13:57:38 +02:00
if ( $ret < 0 ) {
2019-11-13 19:35:39 +01:00
$error ++ ;
2015-09-03 13:57:38 +02:00
$action = 'create' ;
}
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
2019-11-13 19:35:39 +01:00
$object -> socid = $socid ;
$object -> date_contrat = $datecontrat ;
2017-10-16 08:47:05 +02:00
2019-11-13 19:35:39 +01:00
$object -> commercial_suivi_id = GETPOST ( 'commercial_suivi_id' , 'int' );
$object -> commercial_signature_id = GETPOST ( 'commercial_signature_id' , 'int' );
2017-10-16 08:47:05 +02:00
2019-11-13 19:35:39 +01:00
$object -> note_private = GETPOST ( 'note_private' , 'alpha' );
2019-01-27 11:55:16 +01:00
$object -> note_public = GETPOST ( 'note_public' , 'alpha' );
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
2021-09-08 22:09:02 +02:00
$object -> remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2019-11-13 19:35:39 +01:00
$object -> ref = GETPOST ( 'ref' , 'alpha' );
2019-01-27 11:55:16 +01:00
$object -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
2017-10-16 08:47:05 +02:00
// If creation from another object of another module (Example: origin=propal, originid=1)
2021-02-23 21:24:38 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid )) {
2017-10-16 08:47:05 +02:00
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin ;
2021-02-23 21:24:38 +01:00
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $origin , $regs )) {
2017-10-16 08:47:05 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
// For compatibility
2021-02-23 21:24:38 +01:00
if ( $element == 'order' ) {
$element = $subelement = 'commande' ;
}
if ( $element == 'propal' ) {
$element = 'comm/propal' ; $subelement = 'propal' ;
}
2022-01-23 19:26:29 +01:00
if ( $element == 'invoice' || $element == 'facture' ) {
$element = 'compta/facture' ;
$subelement = 'facture' ;
2022-01-13 22:29:48 +01:00
}
2017-10-16 08:47:05 +02:00
$object -> origin = $origin ;
$object -> origin_id = $originid ;
// Possibility to add external linked objects with hooks
$object -> linked_objects [ $object -> origin ] = $object -> origin_id ;
2021-02-23 21:24:38 +01:00
if ( is_array ( $_POST [ 'other_linked_objects' ]) && ! empty ( $_POST [ 'other_linked_objects' ])) {
2017-10-16 08:47:05 +02:00
$object -> linked_objects = array_merge ( $object -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
$id = $object -> create ( $user );
2021-02-23 21:24:38 +01:00
if ( $id > 0 ) {
2017-10-16 08:47:05 +02:00
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 " );
2019-11-13 19:35:39 +01:00
$result = $srcobject -> fetch ( $object -> origin_id );
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2017-10-16 08:47:05 +02:00
$srcobject -> fetch_thirdparty ();
2015-09-03 13:57:38 +02:00
$lines = $srcobject -> lines ;
2021-02-23 21:24:38 +01:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' )) {
2017-10-16 08:47:05 +02:00
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$fk_parent_line = 0 ;
$num = count ( $lines );
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
2019-11-13 19:35:39 +01:00
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
if ( $product_type == 1 || ( ! empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS ) && in_array ( $product_type , array ( 0 , 1 )))) { // TODO Exclude also deee
2015-09-03 13:57:38 +02:00
// service prédéfini
2021-02-23 21:24:38 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2015-09-03 13:57:38 +02:00
$product_static = new Product ( $db );
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// Define output language
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2015-09-03 13:57:38 +02:00
$prod = new Product ( $db );
2019-11-13 19:35:39 +01:00
$prod -> id = $lines [ $i ] -> fk_product ;
2015-09-03 13:57:38 +02:00
$prod -> getMultiLangs ();
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
$outputlangs = $langs ;
2019-11-13 19:35:39 +01:00
$newlang = '' ;
2021-02-23 21:24:38 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( empty ( $newlang )) {
$newlang = $srcobject -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2015-09-03 13:57:38 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ] : $lines [ $i ] -> product_label ;
2020-05-21 15:05:19 +02:00
} else {
2015-09-03 13:57:38 +02:00
$label = $lines [ $i ] -> product_label ;
}
2019-11-13 19:35:39 +01:00
$desc = ( $lines [ $i ] -> desc && $lines [ $i ] -> desc != $lines [ $i ] -> libelle ) ? dol_htmlentitiesbr ( $lines [ $i ] -> desc ) : '' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
$desc = dol_htmlentitiesbr ( $lines [ $i ] -> desc );
}
2017-05-04 01:05:55 +02:00
2017-10-26 09:40:12 +02:00
// Extrafields
$array_options = array ();
2019-10-26 18:23:51 +02:00
// For avoid conflicts if trigger used
2020-04-23 13:21:39 +02:00
if ( method_exists ( $lines [ $i ], 'fetch_optionals' )) {
2020-03-27 16:02:58 +01:00
$lines [ $i ] -> fetch_optionals ();
2017-10-26 09:40:12 +02:00
$array_options = $lines [ $i ] -> array_options ;
}
2017-10-28 22:08:16 +02:00
2019-11-13 19:35:39 +01:00
$txtva = $lines [ $i ] -> vat_src_code ? $lines [ $i ] -> tva_tx . ' (' . $lines [ $i ] -> vat_src_code . ')' : $lines [ $i ] -> tva_tx ;
2017-05-04 01:05:55 +02:00
// View third's localtaxes for now
$localtax1_tx = get_localtax ( $txtva , 1 , $object -> thirdparty );
$localtax2_tx = get_localtax ( $txtva , 2 , $object -> thirdparty );
2017-06-07 16:44:04 +02:00
2017-10-16 08:47:05 +02:00
$result = $object -> addline (
$desc ,
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$txtva ,
$localtax1_tx ,
$localtax2_tx ,
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
$lines [ $i ] -> date_start ,
$lines [ $i ] -> date_end ,
'HT' ,
0 ,
$lines [ $i ] -> info_bits ,
$lines [ $i ] -> fk_fournprice ,
$lines [ $i ] -> pa_ht ,
2017-10-27 02:12:35 +02:00
$array_options ,
2017-10-16 08:47:05 +02:00
$lines [ $i ] -> fk_unit
);
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2017-10-16 08:47:05 +02:00
$error ++ ;
break ;
}
2013-03-22 17:10:17 +01:00
}
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $srcobject -> error , $srcobject -> errors , 'errors' );
$error ++ ;
}
// Hooks
$parameters = array ( 'objFrom' => $srcobject );
$reshook = $hookmanager -> executeHooks ( 'createFrom' , $parameters , $object , $action ); // Note that $action and $object may have been
// modified by hook
2021-02-23 21:24:38 +01:00
if ( $reshook < 0 ) {
2023-01-18 09:53:28 +01:00
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2017-10-16 08:47:05 +02:00
$error ++ ;
2021-02-23 21:24:38 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2022-05-24 15:02:35 +02:00
if ( $error ) {
$action = 'create' ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
$result = $object -> create ( $user );
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2017-10-16 08:47:05 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2019-11-13 19:35:39 +01:00
$action = 'create' ;
2015-09-03 13:57:38 +02:00
}
2017-10-16 08:47:05 +02:00
}
2021-01-02 16:38:19 +01:00
} elseif ( $action == 'classin' && $user -> rights -> contrat -> creer ) {
2017-10-16 08:47:05 +02:00
$object -> setProject ( GETPOST ( 'projectid' ));
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'addline' && $user -> rights -> contrat -> creer ) {
// Add a new line
2015-09-03 13:57:38 +02:00
// Set if we used free entry or predefined product
2019-11-13 19:35:39 +01:00
$predef = '' ;
2021-01-02 16:18:16 +01:00
$product_desc = ( GETPOSTISSET ( 'dp_desc' ) ? GETPOST ( 'dp_desc' , 'restricthtml' ) : '' );
2021-03-02 23:09:55 +01:00
$price_ht = price2num ( GETPOST ( 'price_ht' ), 'MU' , 2 );
$price_ht_devise = price2num ( GETPOST ( 'multicurrency_price_ht' ), 'CU' , 2 );
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'prod_entry_mode' , 'alpha' ) == 'free' ) {
2019-11-13 19:35:39 +01:00
$idprod = 0 ;
2020-01-13 15:58:03 +01:00
$tva_tx = ( GETPOST ( 'tva_tx' , 'alpha' ) ? GETPOST ( 'tva_tx' , 'alpha' ) : 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$idprod = GETPOST ( 'idprod' , 'int' );
2015-09-03 13:57:38 +02:00
$tva_tx = '' ;
}
2017-06-07 16:44:04 +02:00
2021-01-11 13:00:29 +01:00
$qty = price2num ( GETPOST ( 'qty' . $predef , 'alpha' ), 'MS' );
2021-01-31 12:48:40 +01:00
$remise_percent = ( GETPOSTISSET ( 'remise_percent' . $predef ) ? price2num ( GETPOST ( 'remise_percent' . $predef ), 2 ) : 0 );
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $qty == '' ) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Qty " )), null , 'errors' );
$error ++ ;
}
2021-07-04 21:02:02 +02:00
if ( GETPOST ( 'prod_entry_mode' , 'alpha' ) == 'free' && ( empty ( $idprod ) || $idprod < 0 ) && empty ( $product_desc )) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Description " )), null , 'errors' );
$error ++ ;
}
2020-10-31 14:32:18 +01:00
$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' ));
2021-02-23 21:24:38 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end ) && $date_start > $date_end ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " Error " ) . ': ' . $langs -> trans ( " DateStartPlanned " ) . ' > ' . $langs -> trans ( " DateEndPlanned " ), null , 'errors' );
$error ++ ;
}
2017-10-16 08:47:05 +02:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extralabelsline = $extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $predef );
2017-10-16 08:47:05 +02:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
2019-11-13 19:35:39 +01:00
unset ( $_POST [ " options_ " . $key ]);
2017-10-16 08:47:05 +02:00
}
}
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
2015-09-03 13:57:38 +02:00
// Clean parameters
2019-11-13 19:35:39 +01:00
$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' );
2017-06-07 16:44:04 +02:00
2017-10-16 08:47:05 +02:00
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $tva_tx par celui du produit
// Ecrase $base_price_type par celui du produit
2021-02-23 21:24:38 +01:00
if ( $idprod > 0 ) {
2017-10-16 08:47:05 +02:00
$prod = new Product ( $db );
$prod -> fetch ( $idprod );
// Update if prices fields are defined
2019-01-27 11:55:16 +01:00
$tva_tx = get_default_tva ( $mysoc , $object -> thirdparty , $prod -> id );
$tva_npr = get_default_npr ( $mysoc , $object -> thirdparty , $prod -> id );
2021-02-23 21:24:38 +01:00
if ( empty ( $tva_tx )) {
$tva_npr = 0 ;
}
2017-10-16 08:47:05 +02:00
$pu_ht = $prod -> price ;
$pu_ttc = $prod -> price_ttc ;
$price_min = $prod -> price_min ;
$price_base_type = $prod -> price_base_type ;
// On defini prix unitaire
2021-02-23 21:24:38 +01:00
if ( $conf -> global -> PRODUIT_MULTIPRICES && $object -> thirdparty -> price_level ) {
2017-10-16 08:47:05 +02: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 ];
2021-02-23 21:24:38 +01:00
} elseif ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php' ;
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
$prodcustprice = new Productcustomerprice ( $db );
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$filter = array ( 't.fk_product' => $prod -> id , 't.fk_soc' => $object -> thirdparty -> id );
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +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 ;
2016-11-05 11:05:14 +01:00
$tva_tx = $prodcustprice -> lines [ 0 ] -> tva_tx ;
2021-02-23 21:24:38 +01:00
if ( $prodcustprice -> lines [ 0 ] -> default_vat_code && ! preg_match ( '/\(.*\)/' , $tva_tx )) {
$tva_tx .= ' (' . $prodcustprice -> lines [ 0 ] -> default_vat_code . ')' ;
}
2017-11-13 14:02:17 +01:00
$tva_npr = $prodcustprice -> lines [ 0 ] -> recuperableonly ;
2021-02-23 21:24:38 +01:00
if ( empty ( $tva_tx )) {
$tva_npr = 0 ;
}
2015-09-03 13:57:38 +02:00
}
}
}
2017-06-07 16:44:04 +02:00
2017-03-04 21:45:19 +01:00
$tmpvat = price2num ( preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx ));
$tmpprodvat = price2num ( preg_replace ( '/\s*\(.*\)/' , '' , $prod -> tva_tx ));
2017-06-07 16:44:04 +02:00
2022-12-07 12:35:54 +01:00
$pu_ht = price2num ( $price_ht , 'MU' );
2017-03-04 21:45:19 +01:00
// On reevalue prix selon taux tva car taux tva transaction peut etre different
2017-10-16 08:47:05 +02:00
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
2021-02-23 21:24:38 +01:00
if ( $tmpvat != $tmpprodvat ) {
if ( $price_base_type != 'HT' ) {
2019-11-16 23:24:29 +01:00
$pu_ht = price2num ( $pu_ttc / ( 1 + ( $tmpvat / 100 )), 'MU' );
2020-05-21 15:05:19 +02:00
} else {
2019-11-16 23:24:29 +01:00
$pu_ttc = price2num ( $pu_ht * ( 1 + ( $tmpvat / 100 )), 'MU' );
2017-10-16 08:47:05 +02:00
}
}
2021-02-23 21:24:38 +01:00
$desc = $prod -> description ;
2020-10-25 19:13:09 +01:00
//If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
2021-10-25 22:07:31 +02:00
if ( $product_desc == $desc && ! empty ( $conf -> global -> PRODUIT_AUTOFILL_DESC )) {
$product_desc = '' ;
2020-10-25 19:13:09 +01:00
}
2021-02-23 21:24:38 +01:00
if ( ! empty ( $product_desc ) && ! empty ( $conf -> global -> MAIN_NO_CONCAT_DESCRIPTION )) {
$desc = $product_desc ;
} else {
$desc = dol_concatdesc ( $desc , $product_desc , '' , ! empty ( $conf -> global -> MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION ));
}
2020-05-03 21:26:35 +02:00
2017-10-16 08:47:05 +02:00
$fk_unit = $prod -> fk_unit ;
2020-05-21 15:05:19 +02:00
} else {
2022-12-07 12:35:54 +01:00
$pu_ht = price2num ( $price_ht , 'MU' );
2017-10-16 08:47:05 +02:00
$price_base_type = 'HT' ;
2019-11-16 23:24:29 +01:00
$tva_tx = GETPOST ( 'tva_tx' ) ? str_replace ( '*' , '' , GETPOST ( 'tva_tx' )) : 0 ; // tva_tx field may be disabled, so we use vat rate 0
$tva_npr = preg_match ( '/\*/' , GETPOST ( 'tva_tx' )) ? 1 : 0 ;
$desc = $product_desc ;
$fk_unit = GETPOST ( 'units' , 'alpha' );
2017-10-16 08:47:05 +02:00
}
2017-06-07 16:44:04 +02:00
2019-11-16 23:24:29 +01:00
$localtax1_tx = get_localtax ( $tva_tx , 1 , $object -> thirdparty , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $object -> thirdparty , $mysoc , $tva_npr );
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
// ajout prix achat
2022-02-22 23:44:56 +01:00
$fk_fournprice = GETPOST ( 'fournprice' );
if ( GETPOST ( 'buying_price' )) {
$pa_ht = GETPOST ( 'buying_price' );
2021-02-23 21:24:38 +01:00
} else {
$pa_ht = null ;
}
2017-06-07 16:44:04 +02:00
2019-11-16 23:24:29 +01:00
$info_bits = 0 ;
2021-02-23 21:24:38 +01:00
if ( $tva_npr ) {
$info_bits |= 0x01 ;
}
2017-06-07 16:44:04 +02:00
2019-11-16 23:24:29 +01:00
if ((( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> produit -> ignore_price_min_advance ))
2021-02-23 21:24:38 +01:00
|| empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) && ( $price_min && ( price2num ( $pu_ht ) * ( 1 - price2num ( $remise_percent ) / 100 ) < price2num ( $price_min )))) {
2019-01-27 11:55:16 +01:00
$object -> error = $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ));
2019-11-16 23:24:29 +01:00
$result = - 1 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
// Insert line
$result = $object -> addline (
$desc ,
$pu_ht ,
$qty ,
$tva_tx ,
$localtax1_tx ,
$localtax2_tx ,
$idprod ,
$remise_percent ,
$date_start ,
$date_end ,
$price_base_type ,
$pu_ttc ,
$info_bits ,
2021-02-23 21:24:38 +01:00
$fk_fournprice ,
$pa_ht ,
2017-10-16 08:47:05 +02:00
$array_options ,
$fk_unit
);
}
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2017-10-16 08:47:05 +02:00
// Define output language
2021-02-23 21:24:38 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ) && ! empty ( $conf -> global -> CONTRACT_ADDON_PDF )) { // No generation if default type not defined
2015-09-03 13:57:38 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:24:38 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $newlang )) {
2015-09-03 13:57:38 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-07 16:44:04 +02:00
2020-09-10 01:49:09 +02:00
$object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2015-09-03 13:57:38 +02:00
}
2017-06-07 16:44:04 +02:00
2020-01-20 12:25:25 +01:00
unset ( $_POST [ 'prod_entry_mode' ]);
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'price_ht' ]);
2016-04-12 14:10:27 +02:00
unset ( $_POST [ 'multicurrency_price_ht' ]);
2015-09-03 13:57:38 +02:00
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' ]);
2020-01-20 12:25:25 +01:00
unset ( $_POST [ 'np_marginRate' ]);
unset ( $_POST [ 'np_markRate' ]);
2015-09-03 13:57:38 +02:00
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'idprod' ]);
2017-06-07 16:44:04 +02:00
2017-10-16 08:47:05 +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' ]);
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2020-05-21 15:05:19 +02:00
} elseif ( $action == 'updateline' && $user -> rights -> contrat -> creer && ! GETPOST ( 'cancel' , 'alpha' )) {
2018-02-03 18:50:20 +01:00
$error = 0 ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $date_start_update ) && ! empty ( $date_end_update ) && $date_start_update > $date_end_update ) {
2018-02-03 18:50:20 +01:00
setEventMessages ( $langs -> trans ( " Error " ) . ': ' . $langs -> trans ( " DateStartPlanned " ) . ' > ' . $langs -> trans ( " DateEndPlanned " ), null , 'errors' );
$action = 'editline' ;
$_GET [ 'rowid' ] = GETPOST ( 'elrowid' );
$error ++ ;
}
2017-10-16 08:47:05 +02:00
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
2018-02-03 18:50:20 +01:00
$objectline = new ContratLigne ( $db );
2021-02-23 21:24:38 +01:00
if ( $objectline -> fetch ( GETPOST ( 'elrowid' , 'int' )) < 0 ) {
2018-02-03 18:50:20 +01:00
setEventMessages ( $objectline -> error , $objectline -> errors , 'errors' );
$error ++ ;
}
2020-01-25 14:03:24 +01:00
$objectline -> fetch_optionals ();
2018-02-03 18:50:20 +01:00
}
2017-10-16 08:47:05 +02:00
2018-02-03 18:50:20 +01:00
$db -> begin ();
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
if ( $date_start_real_update == '' ) {
$date_start_real_update = $objectline -> date_ouverture ;
}
if ( $date_end_real_update == '' ) {
$date_end_real_update = $objectline -> date_cloture ;
}
2017-10-16 08:47:05 +02:00
2018-02-03 18:50:20 +01:00
$vat_rate = GETPOST ( 'eltva_tx' );
// Define info_bits
$info_bits = 0 ;
2021-02-23 21:24:38 +01:00
if ( preg_match ( '/\*/' , $vat_rate )) {
2017-10-16 08:47:05 +02:00
$info_bits |= 0x01 ;
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
// Define vat_rate
$vat_rate = str_replace ( '*' , '' , $vat_rate );
2019-11-13 19:35:39 +01:00
$localtax1_tx = get_localtax ( $vat_rate , 1 , $object -> thirdparty , $mysoc );
$localtax2_tx = get_localtax ( $vat_rate , 2 , $object -> thirdparty , $mysoc );
2017-10-16 08:47:05 +02:00
2018-02-03 18:50:20 +01:00
$txtva = $vat_rate ;
2017-10-16 08:47:05 +02:00
// Clean vat code
2020-01-25 14:03:24 +01:00
$reg = array ();
2019-11-13 19:35:39 +01:00
$vat_src_code = '' ;
2021-02-23 21:24:38 +01:00
if ( preg_match ( '/\((.*)\)/' , $txtva , $reg )) {
2017-10-16 08:47:05 +02:00
$vat_src_code = $reg [ 1 ];
2019-11-13 19:35:39 +01:00
$txtva = preg_replace ( '/\s*\(.*\)/' , '' , $txtva ); // Remove code into vatrate.
2018-02-03 18:50:20 +01:00
}
2017-10-16 08:47:05 +02:00
// ajout prix d'achat
2021-03-02 23:09:55 +01:00
if ( GETPOST ( 'buying_price' )) {
$pa_ht = price2num ( GETPOST ( 'buying_price' ), '' , 2 );
2021-02-23 21:24:38 +01:00
} else {
$pa_ht = null ;
}
2017-10-16 08:47:05 +02:00
$fk_unit = GETPOST ( 'unit' , 'alpha' );
2020-09-23 18:45:19 +02:00
$objectline -> fk_product = GETPOST ( 'idprod' , 'int' );
2020-09-18 01:29:17 +02:00
$objectline -> description = GETPOST ( 'product_desc' , 'restricthtml' );
2021-01-31 12:48:40 +01:00
$objectline -> price_ht = price2num ( GETPOST ( 'elprice' ), 'MU' );
$objectline -> subprice = price2num ( GETPOST ( 'elprice' ), 'MU' );
$objectline -> qty = price2num ( GETPOST ( 'elqty' ), 'MS' );
$objectline -> remise_percent = price2num ( GETPOST ( 'elremise_percent' ), 2 );
2019-11-13 19:35:39 +01:00
$objectline -> tva_tx = ( $txtva ? $txtva : 0 ); // Field may be disabled, so we use vat rate 0
$objectline -> vat_src_code = $vat_src_code ;
$objectline -> localtax1_tx = is_numeric ( $localtax1_tx ) ? $localtax1_tx : 0 ;
$objectline -> localtax2_tx = is_numeric ( $localtax2_tx ) ? $localtax2_tx : 0 ;
$objectline -> date_ouverture_prevue = $date_start_update ;
$objectline -> date_ouverture = $date_start_real_update ;
$objectline -> date_fin_validite = $date_end_update ;
$objectline -> date_cloture = $date_end_real_update ;
$objectline -> fk_user_cloture = $user -> id ;
$objectline -> fk_fournprice = $fk_fournprice ;
$objectline -> pa_ht = $pa_ht ;
2017-10-16 08:47:05 +02:00
if ( $fk_unit > 0 ) {
2020-10-31 14:32:18 +01:00
$objectline -> fk_unit = GETPOST ( 'unit' );
2017-10-16 08:47:05 +02:00
} else {
2020-10-31 14:32:18 +01:00
$objectline -> fk_unit = null ;
2017-10-16 08:47:05 +02:00
}
2018-02-03 18:50:20 +01:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extralabelsline = $extrafields -> fetch_name_optionals_label ( $objectline -> table_element );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $predef );
2020-01-25 14:03:24 +01:00
if ( is_array ( $array_options ) && count ( $array_options ) > 0 ) {
// We replace values in this->line->array_options only for entries defined into $array_options
2020-01-30 01:48:28 +01:00
foreach ( $array_options as $key => $value ) {
2020-01-25 14:03:24 +01:00
$objectline -> array_options [ $key ] = $array_options [ $key ];
}
}
2018-02-03 18:50:20 +01:00
// TODO verifier price_min si fk_product et multiprix
2019-11-13 19:35:39 +01:00
$result = $objectline -> update ( $user );
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2018-02-03 18:50:20 +01:00
$error ++ ;
2017-10-16 08:47:05 +02:00
setEventMessages ( $objectline -> error , $objectline -> errors , 'errors' );
2018-02-03 18:50:20 +01:00
}
}
2021-02-23 21:24:38 +01:00
if ( ! $error ) {
2018-02-03 18:50:20 +01:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2018-02-03 18:50:20 +01:00
$db -> rollback ();
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'confirm_deleteline' && $confirm == 'yes' && $user -> rights -> contrat -> creer ) {
2021-04-25 15:55:36 +02:00
$result = $object -> deleteline ( GETPOST ( 'lineid' , 'int' ), $user );
2017-10-16 08:47:05 +02:00
2021-02-23 21:24:38 +01:00
if ( $result >= 0 ) {
2017-10-16 08:47:05 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'confirm_valid' && $confirm == 'yes' && $user -> rights -> contrat -> creer ) {
2017-10-16 08:47:05 +02:00
$result = $object -> validate ( $user );
2018-01-26 18:13:55 +01:00
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2018-01-26 18:13:55 +01:00
// Define output language
2021-02-23 21:24:38 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2018-01-26 18:13:55 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-23 21:24:38 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $newlang )) {
2018-01-26 18:13:55 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2018-01-26 18:13:55 +01:00
$ret = $object -> fetch ( $id ); // Reload to get new records
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
2020-05-21 15:05:19 +02:00
} else {
2018-01-26 18:13:55 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'reopen' && $user -> rights -> contrat -> creer ) {
2017-10-16 08:47:05 +02:00
$result = $object -> reopen ( $user );
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2018-02-16 01:19:31 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'confirm_close' && $confirm == 'yes' && $user -> rights -> contrat -> creer ) {
// Close all lines
2018-02-16 01:19:31 +01:00
$result = $object -> closeAll ( $user );
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2018-02-16 01:19:31 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'confirm_activate' && $confirm == 'yes' && $user -> rights -> contrat -> creer ) {
// Close all lines
2018-02-16 01:19:31 +01:00
$result = $object -> activateAll ( $user );
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2018-02-16 01:19:31 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-21 23:30:55 +01:00
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> contrat -> supprimer ) {
2019-11-13 19:35:39 +01:00
$result = $object -> delete ( $user );
2021-02-23 21:24:38 +01:00
if ( $result >= 0 ) {
2018-02-26 21:16:40 +01:00
header ( " Location: list.php?restore_lastsearch_values=1 " );
2012-07-02 19:30:37 +02:00
return ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2012-07-02 19:30:37 +02:00
}
2021-02-21 23:30:55 +01:00
} elseif ( $action == 'confirm_move' && $confirm == 'yes' && $user -> rights -> contrat -> creer ) {
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'newcid' ) > 0 ) {
2015-09-03 13:57:38 +02:00
$contractline = new ContratLigne ( $db );
2021-02-21 23:30:55 +01:00
$result = $contractline -> fetch ( GETPOSTINT ( 'lineid' ));
$contractline -> fk_contrat = GETPOSTINT ( 'newcid' );
2019-11-13 19:35:39 +01:00
$result = $contractline -> update ( $user , 1 );
2021-02-23 21:24:38 +01:00
if ( $result >= 0 ) {
2015-09-03 13:57:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
return ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-07-05 11:17:50 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " RefNewContract " )), null , 'errors' );
2015-09-03 13:57:38 +02:00
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'update_extras' ) {
2018-02-20 19:20:03 +01:00
$object -> oldcopy = dol_clone ( $object );
2015-09-03 13:57:38 +02:00
// Fill array 'array_options' with data from update form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-23 21:24:38 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
if ( ! $error ) {
2018-02-20 18:09:38 +01:00
$result = $object -> insertExtraFields ( 'CONTRACT_MODIFY' );
2021-02-23 21:24:38 +01:00
if ( $result < 0 ) {
2017-10-24 19:04:40 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
2017-06-07 16:44:04 +02:00
2015-09-03 13:57:38 +02:00
if ( $error ) {
$action = 'edit_extras' ;
2014-12-28 18:56:23 +01:00
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'setref_supplier' ) {
2021-09-01 18:46:06 +02:00
if ( ! $cancel ) {
2018-06-22 10:55:36 +02:00
$object -> oldcopy = dol_clone ( $object );
2017-06-07 16:44:04 +02:00
2019-01-27 11:55:16 +01:00
$result = $object -> setValueFrom ( 'ref_supplier' , GETPOST ( 'ref_supplier' , 'alpha' ), '' , null , 'text' , '' , $user , 'CONTRACT_MODIFY' );
2015-09-03 13:57:38 +02:00
if ( $result < 0 ) {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-09-03 13:57:38 +02:00
$action = 'editref_supplier' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2017-10-16 08:47:05 +02:00
exit ;
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'setref_customer' ) {
2021-09-01 18:46:06 +02:00
if ( ! $cancel ) {
2018-06-22 10:55:36 +02:00
$object -> oldcopy = dol_clone ( $object );
2017-06-07 16:44:04 +02:00
2019-01-27 11:55:16 +01:00
$result = $object -> setValueFrom ( 'ref_customer' , GETPOST ( 'ref_customer' , 'alpha' ), '' , null , 'text' , '' , $user , 'CONTRACT_MODIFY' );
2017-10-16 08:47:05 +02:00
if ( $result < 0 ) {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-10-17 00:52:35 +02:00
$action = 'editref_customer' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2017-10-16 08:47:05 +02:00
exit ;
}
2021-02-21 23:30:55 +01:00
} elseif ( $action == 'setref' ) {
2021-09-01 18:46:06 +02:00
if ( ! $cancel ) {
2017-10-16 08:47:05 +02:00
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2018-03-21 11:54:25 +01:00
$old_ref = $object -> ref ;
2018-03-22 14:12:37 +01:00
2020-10-31 14:32:18 +01:00
$result = $object -> setValueFrom ( 'ref' , GETPOST ( 'ref' , 'alpha' ), '' , null , 'text' , '' , $user , 'CONTRACT_MODIFY' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'editref' ;
} else {
2018-03-21 11:54:25 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2021-02-10 12:44:36 +01:00
$old_filedir = $conf -> contrat -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $old_ref );
$new_filedir = $conf -> contrat -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
2018-03-22 14:12:37 +01:00
2018-03-21 11:54:25 +01:00
$files = dol_dir_list ( $old_filedir );
2021-02-23 21:24:38 +01:00
if ( ! empty ( $files )) {
if ( ! is_dir ( $new_filedir )) {
dol_mkdir ( $new_filedir );
}
foreach ( $files as $file ) {
2018-03-21 11:54:25 +01:00
dol_move ( $file [ 'fullname' ], $new_filedir . '/' . $file [ 'name' ]);
}
}
2018-03-22 14:12:37 +01:00
2020-10-31 14:32:18 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
exit ;
}
2021-02-21 23:30:55 +01:00
} elseif ( $action == 'setdate_contrat' ) {
2021-09-01 18:46:06 +02:00
if ( ! $cancel ) {
2017-10-16 08:47:05 +02:00
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2019-11-13 19:35:39 +01:00
$datacontrat = dol_mktime ( GETPOST ( 'date_contrathour' ), GETPOST ( 'date_contratmin' ), 0 , GETPOST ( 'date_contratmonth' ), GETPOST ( 'date_contratday' ), GETPOST ( 'date_contratyear' ));
2017-10-16 08:47:05 +02:00
$result = $object -> setValueFrom ( 'date_contrat' , $datacontrat , '' , null , 'date' , '' , $user , 'CONTRACT_MODIFY' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'editdate_contrat' ;
} else {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2017-10-16 08:47:05 +02:00
exit ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2017-10-16 08:47:05 +02:00
exit ;
2015-09-03 13:57:38 +02:00
}
2014-09-28 20:39:02 +02:00
}
2017-06-07 16:44:04 +02:00
2021-11-28 20:55:17 +01:00
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
2017-06-07 16:44:04 +02:00
2017-09-22 17:48:38 +02:00
// Actions to build doc
2021-02-10 12:44:36 +01:00
$upload_dir = $conf -> contrat -> multidir_output [ $object -> entity ];
2019-11-05 19:41:30 +01:00
$permissiontoadd = $user -> rights -> contrat -> creer ;
2017-09-22 17:48:38 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2016-12-10 12:23:02 +01:00
// Actions to send emails
2019-12-02 09:38:16 +01:00
$triggersendname = 'CONTRACT_SENTBYMAIL' ;
2019-11-13 19:35:39 +01:00
$paramname = 'id' ;
$mode = 'emailfromcontract' ;
$trackid = 'con' . $object -> id ;
2016-12-10 12:23:02 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2017-09-16 01:34:15 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $user -> rights -> contrat -> creer ) {
if ( $action == 'addcontact' ) {
2015-09-03 13:57:38 +02:00
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
2020-11-30 15:18:58 +01:00
$typeid = ( GETPOST ( 'typecontact' ) ? GETPOST ( 'typecontact' ) : GETPOST ( 'type' ));
$result = $object -> add_contact ( $contactid , $typeid , GETPOST ( " source " , 'aZ09' ));
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $result >= 0 ) {
2015-09-03 13:57:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:24:38 +01:00
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2015-09-03 13:57:38 +02:00
$langs -> load ( " errors " );
2015-11-19 13:59:58 +01:00
setEventMessages ( $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-09-03 13:57:38 +02:00
}
2012-07-02 19:30:37 +02:00
}
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'swapstatut' ) {
// bascule du statut d'un contact
2021-03-29 15:07:23 +02:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' , 'int' ));
2021-02-23 21:24:38 +01:00
} elseif ( $action == 'deletecontact' ) {
// Efface un contact
2021-03-29 15:07:23 +02:00
$result = $object -> delete_contact ( GETPOST ( 'lineid' , 'int' ));
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $result >= 0 ) {
2015-09-03 13:57:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-19 13:59:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-09-03 13:57:38 +02:00
}
2012-07-02 19:30:37 +02:00
}
2012-03-18 11:13:01 +01:00
}
2016-10-14 07:54:44 +02:00
// Action clone object
2021-02-23 21:24:38 +01:00
if ( $action == 'confirm_clone' && $confirm == 'yes' ) {
if ( ! GETPOST ( 'socid' , 3 )) {
2016-10-14 07:54:44 +02:00
setEventMessages ( $langs -> trans ( " NoCloneOptionsSpecified " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2016-10-14 07:54:44 +02:00
if ( $object -> id > 0 ) {
2019-04-25 12:11:32 +02:00
$result = $object -> createFromClone ( $user , $socid );
2016-10-14 07:54:44 +02:00
if ( $result > 0 ) {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
2016-10-14 07:54:44 +02:00
exit ();
} else {
2021-02-23 21:24:38 +01:00
if ( count ( $object -> errors ) > 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2016-10-14 07:54:44 +02:00
$action = '' ;
}
}
}
}
2008-09-26 01:30:06 +02:00
}
2004-07-27 18:30:19 +02:00
2016-12-09 15:03:57 +01:00
2008-07-12 12:31:58 +02:00
/*
* View
*/
2003-08-03 21:15:39 +02:00
2021-03-16 13:28:46 +01:00
$help_url = 'EN:Module_Contracts|FR:Module_Contrat' ;
llxHeader ( '' , $langs -> trans ( " Contract " ), $help_url );
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 );
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2021-02-23 21:24:38 +01:00
$formproject = new FormProjets ( $db );
}
2017-06-07 16:44:04 +02:00
2014-08-12 13:26:06 +02:00
// Load object modContract
2019-11-13 19:35:39 +01:00
$module = ( ! empty ( $conf -> global -> CONTRACT_ADDON ) ? $conf -> global -> CONTRACT_ADDON : 'mod_contract_serpis' );
2021-02-23 21:24:38 +01:00
if ( substr ( $module , 0 , 13 ) == 'mod_contract_' && substr ( $module , - 3 ) == 'php' ) {
2019-11-13 19:35:39 +01:00
$module = substr ( $module , 0 , dol_strlen ( $module ) - 4 );
2014-08-12 13:26:06 +02:00
}
2019-11-13 19:35:39 +01:00
$result = dol_include_once ( '/core/modules/contract/' . $module . '.php' );
2021-02-23 21:24:38 +01:00
if ( $result > 0 ) {
2014-08-12 13:26:06 +02:00
$modCodeContract = new $module ();
}
2017-05-18 03:12:29 +02:00
// Create
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2020-04-25 13:49:44 +02:00
print load_fiche_titre ( $langs -> trans ( 'AddContract' ), '' , 'contract' );
2005-06-11 13:33:21 +02:00
2017-10-16 08:47:05 +02:00
$soc = new Societe ( $db );
2021-02-23 21:24:38 +01:00
if ( $socid > 0 ) {
$soc -> fetch ( $socid );
}
2017-10-16 08:47:05 +02:00
2021-07-23 00:02:14 +02:00
if ( GETPOST ( 'origin' ) && GETPOST ( 'originid' , 'int' )) {
2017-10-16 08:47:05 +02:00
// Parse element/subelement (ex: project_task)
2020-01-20 12:25:25 +01:00
$regs = array ();
2017-10-16 08:47:05 +02:00
$element = $subelement = GETPOST ( 'origin' );
2021-02-23 21:24:38 +01:00
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' ), $regs )) {
2017-10-16 08:47:05 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
2021-02-23 21:24:38 +01:00
if ( $element == 'project' ) {
2021-07-23 00:02:14 +02:00
$projectid = GETPOST ( 'originid' , 'int' );
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
// For compatibility
2021-02-23 21:24:38 +01:00
if ( $element == 'order' || $element == 'commande' ) {
$element = $subelement = 'commande' ;
}
if ( $element == 'propal' ) {
$element = 'comm/propal' ; $subelement = 'propal' ;
}
2022-01-23 19:26:29 +01:00
if ( $element == 'invoice' || $element == 'facture' ) {
$element = 'compta/facture' ;
$subelement = 'facture' ;
2022-01-13 22:29:48 +01:00
}
2017-10-16 08:47:05 +02:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
$classname = ucfirst ( $subelement );
$objectsrc = new $classname ( $db );
2020-03-27 16:02:58 +01:00
$objectsrc -> fetch ( $originid );
2021-02-23 21:24:38 +01:00
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) {
$objectsrc -> fetch_lines ();
}
2017-10-16 08:47:05 +02:00
$objectsrc -> fetch_thirdparty ();
2017-12-12 10:37:51 +01:00
2017-11-15 21:20:30 +01:00
// Replicate extrafields
2020-03-27 16:02:58 +01:00
$objectsrc -> fetch_optionals ();
2017-11-15 21:20:30 +01:00
$object -> array_options = $objectsrc -> array_options ;
2017-10-16 08:47:05 +02:00
2019-11-13 19:35:39 +01:00
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $objectsrc -> fk_project : '' );
2017-10-16 08:47:05 +02:00
$soc = $objectsrc -> thirdparty ;
2019-11-13 19:35:39 +01:00
$note_private = ( ! empty ( $objectsrc -> note_private ) ? $objectsrc -> note_private : '' );
$note_public = ( ! empty ( $objectsrc -> note_public ) ? $objectsrc -> note_public : '' );
2017-10-16 08:47:05 +02:00
// Object source contacts list
2019-01-27 11:55:16 +01:00
$srccontactslist = $objectsrc -> liste_contact ( - 1 , 'external' , 1 );
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
$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 " );
}
2017-10-16 08:47:05 +02:00
$object -> date_contrat = dol_now ();
2011-02-18 20:55:48 +01:00
2017-10-16 08:47:05 +02:00
print '<form name="form_contract" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2011-05-03 20:45:37 +02:00
2017-10-16 08:47:05 +02: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
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2015-04-21 15:49:58 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2011-05-03 20:45:37 +02:00
2017-10-16 08:47:05 +02:00
// Ref
2016-12-04 13:30:17 +01:00
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td>' ;
2019-11-13 19:35:39 +01:00
if ( ! empty ( $modCodeContract -> code_auto )) {
$tmpcode = $langs -> trans ( " Draft " );
2017-10-16 08:47:05 +02:00
} else {
2019-11-13 19:35:39 +01:00
$tmpcode = '<input name="ref" class="maxwidth100" maxlength="128" value="' . dol_escape_htmltag ( GETPOST ( 'ref' ) ? GETPOST ( 'ref' ) : $tmpcode ) . '">' ;
2017-10-16 08:47:05 +02:00
}
2016-12-04 13:30:17 +01:00
print $tmpcode ;
print '</td></tr>' ;
2014-09-04 18:58:33 +02:00
2015-10-17 00:52:35 +02:00
// Ref customer
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="' . dol_escape_htmltag ( GETPOST ( 'ref_customer' , 'alpha' )) . '"></td></tr>' ;
2015-10-17 00:52:35 +02:00
2014-11-20 10:48:55 +01:00
// Ref supplier
print '<tr><td>' . $langs -> trans ( 'RefSupplier' ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="' . dol_escape_htmltag ( GETPOST ( 'ref_supplier' , 'alpha' )) . '"></td></tr>' ;
2011-05-03 20:45:37 +02:00
2017-10-16 08:47:05 +02:00
// Thirdparty
2013-03-02 16:50:36 +01:00
print '<tr>' ;
2015-11-04 19:56:12 +01:00
print '<td class="fieldrequired">' . $langs -> trans ( 'ThirdParty' ) . '</td>' ;
2021-02-23 21:24:38 +01:00
if ( $socid > 0 ) {
2016-12-04 13:30:17 +01:00
print '<td>' ;
2013-03-02 16:50:36 +01:00
print $soc -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' ;
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2016-12-04 13:30:17 +01:00
print '<td>' ;
2021-07-23 00:02:14 +02:00
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print $form -> select_company ( '' , 'socid' , '' , 'SelectThirdParty' , 1 , 0 , null , 0 , 'minwidth300 widthcentpercentminusxx maxwidth500' );
2020-06-18 03:32:13 +02:00
print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create' ) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddThirdParty " ) . '"></span></a>' ;
2013-03-02 16:50:36 +01:00
print '</td>' ;
}
print '</tr>' . " \n " ;
2021-02-23 21:24:38 +01:00
if ( $socid > 0 ) {
2013-03-02 16:50:36 +01:00
// Ligne info remises tiers
2016-12-04 13:30:17 +01:00
print '<tr><td>' . $langs -> trans ( 'Discounts' ) . '</td><td>' ;
2021-02-23 21:24:38 +01:00
if ( $soc -> remise_percent ) {
2022-02-08 12:01:48 +01:00
print $langs -> trans ( " CompanyHasRelativeDiscount " , $soc -> remise_percent ) . ' ' ;
2021-02-23 21:24:38 +01:00
} else {
2022-02-08 12:01:48 +01:00
print '<span class="hideonsmartphone">' . $langs -> trans ( " CompanyHasNoRelativeDiscount " ) . '. </span>' ;
2021-02-23 21:24:38 +01:00
}
2019-11-13 19:35:39 +01:00
$absolute_discount = $soc -> getAvailableDiscounts ();
2021-02-23 21:24:38 +01:00
if ( $absolute_discount ) {
2022-02-08 12:01:48 +01:00
print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> trans ( " Currency " . $conf -> currency )) . '.' ;
2021-02-23 21:24:38 +01:00
} else {
2022-02-08 12:01:48 +01:00
print '<span class="hideonsmartphone">' . $langs -> trans ( " CompanyHasNoAbsoluteDiscount " ) . '.</span>' ;
2021-02-23 21:24:38 +01:00
}
2013-03-02 16:50:36 +01:00
print '</td></tr>' ;
}
2011-05-03 20:45:37 +02:00
2017-10-16 08:47:05 +02:00
// Commercial suivi
print '<tr><td class="nowrap"><span class="fieldrequired">' . $langs -> trans ( " TypeContact_contrat_internal_SALESREPFOLL " ) . '</span></td><td>' ;
2021-07-23 00:02:14 +02:00
print img_picto ( '' , 'user' , 'class="pictofixedwidth"' );
2019-11-13 19:35:39 +01:00
print $form -> select_dolusers ( GETPOST ( " commercial_suivi_id " ) ? GETPOST ( " commercial_suivi_id " ) : $user -> id , 'commercial_suivi_id' , 1 , '' );
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
// Commercial signature
print '<tr><td class="nowrap"><span class="fieldrequired">' . $langs -> trans ( " TypeContact_contrat_internal_SALESREPSIGN " ) . '</span></td><td>' ;
2021-07-23 00:02:14 +02:00
print img_picto ( '' , 'user' , 'class="pictofixedwidth"' );
2019-11-13 19:35:39 +01:00
print $form -> select_dolusers ( GETPOST ( " commercial_signature_id " ) ? GETPOST ( " commercial_signature_id " ) : $user -> id , 'commercial_signature_id' , 1 , '' );
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
print '<tr><td><span class="fieldrequired">' . $langs -> trans ( " Date " ) . '</span></td><td>' ;
2018-09-09 09:36:12 +02:00
print $form -> selectDate ( $datecontrat , '' , 0 , 0 , '' , " contrat " );
2017-10-16 08:47:05 +02:00
print " </td></tr> " ;
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2017-12-12 10:37:51 +01:00
$langs -> load ( 'projects' );
2019-11-16 23:24:29 +01:00
$formproject = new FormProjets ( $db );
2017-10-16 08:47:05 +02:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2019-11-16 23:24:29 +01:00
$formproject -> select_projects (( $soc -> id > 0 ? $soc -> id : - 1 ), $projectid , " projectid " , 0 , 0 , 1 , 1 );
2020-06-18 03:32:13 +02:00
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create&status=1&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create&socid=' . $soc -> id ) . '"><span class="fa fa-plus-circle valignmiddle" title="' . $langs -> trans ( " AddProject " ) . '"></span></a>' ;
2017-10-16 08:47:05 +02:00
print " </td></tr> " ;
}
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td><td class="tdtop">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_public' , $note_public , '' , '100' , 'dolibarr_notes' , 'In' , 1 , true , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_3 , '90%' );
2017-10-16 08:47:05 +02:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
2021-02-23 21:24:38 +01:00
if ( empty ( $user -> socid )) {
2017-10-16 08:47:05 +02:00
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td><td class="tdtop">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_private' , $note_private , '' , '100' , 'dolibarr_notes' , 'In' , 1 , true , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_3 , '90%' );
2017-10-16 08:47:05 +02:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
}
// Other attributes
2019-11-16 23:24:29 +01:00
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' , 'cols' => '3' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-10-16 08:47:05 +02:00
print $hookmanager -> resPrint ;
// Other attributes
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook )) {
2020-10-02 21:41:05 +02:00
print $object -> showOptionals ( $extrafields , 'create' , $parameters );
2017-10-16 08:47:05 +02:00
}
print " </table> \n " ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-10-16 08:47:05 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Create " );
2014-12-11 14:15:40 +01:00
2021-02-23 21:24:38 +01:00
if ( is_object ( $objectsrc )) {
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
2013-03-22 17:10:17 +01:00
2021-02-23 21:24:38 +01:00
if ( empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS )) {
2017-10-16 08:47:05 +02:00
print '<br>' . $langs -> trans ( " Note " ) . ': ' . $langs -> trans ( " OnlyLinesWithTypeServiceAreUsed " );
}
2014-12-11 14:15:40 +01:00
}
2015-04-21 15:49:58 +02:00
2017-10-16 08:47:05 +02:00
print " </form> \n " ;
2021-09-06 01:42:54 +02:00
} else {
// View and edit mode
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2009-01-25 18:05:40 +01:00
2021-02-23 21:24:38 +01:00
if ( $object -> id > 0 ) {
2017-10-16 08:47:05 +02:00
$object -> fetch_thirdparty ();
2014-12-11 13:12:05 +01:00
2019-11-13 19:35:39 +01:00
$soc = $object -> thirdparty ; // $soc is used later
2019-02-03 19:54:55 +01:00
2019-11-13 19:35:39 +01:00
$result = $object -> fetch_lines (); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed
2018-09-13 14:22:45 +02:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db , $object -> error );
}
2005-09-09 23:25:53 +02:00
2019-11-13 19:35:39 +01:00
$nbofservices = count ( $object -> lines );
2008-04-07 19:16:45 +02:00
2017-10-16 08:47:05 +02:00
$author = new User ( $db );
$author -> fetch ( $object -> user_author_id );
2009-01-25 18:05:40 +01:00
2017-10-16 08:47:05 +02:00
$commercial_signature = new User ( $db );
$commercial_signature -> fetch ( $object -> commercial_signature_id );
2005-09-04 15:22:50 +02:00
2017-10-16 08:47:05 +02:00
$commercial_suivi = new User ( $db );
$commercial_suivi -> fetch ( $object -> commercial_suivi_id );
2005-09-04 15:22:50 +02:00
2017-10-16 08:47:05 +02:00
$head = contract_prepare_head ( $object );
2005-09-04 15:22:50 +02:00
2020-10-31 14:32:18 +01:00
$hselected = 0 ;
$formconfirm = '' ;
print dol_get_fiche_head ( $head , $hselected , $langs -> trans ( " Contract " ), - 1 , 'contract' );
if ( $action == 'delete' ) {
//Confirmation de la suppression du contrat
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " DeleteAContract " ), $langs -> trans ( " ConfirmDeleteAContract " ), " confirm_delete " , '' , 0 , 1 );
} elseif ( $action == 'valid' ) {
//Confirmation de la validation
$ref = substr ( $object -> ref , 1 , 4 );
if ( $ref == 'PROV' && ! empty ( $modCodeContract -> code_auto )) {
$numref = $object -> getNextNumRef ( $object -> thirdparty );
} else {
$numref = $object -> ref ;
}
$text = $langs -> trans ( 'ConfirmValidateContract' , $numref );
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " ValidateAContract " ), $text , " confirm_valid " , '' , 0 , 1 );
} elseif ( $action == 'close' ) {
// Confirmation de la fermeture
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " CloseAContract " ), $langs -> trans ( " ConfirmCloseContract " ), " confirm_close " , '' , 0 , 1 );
} elseif ( $action == 'activate' ) {
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " ActivateAllOnContract " ), $langs -> trans ( " ConfirmActivateAllOnContract " ), " confirm_activate " , '' , 0 , 1 );
} elseif ( $action == 'clone' ) {
// Clone confirmation
$formquestion = array ( array ( 'type' => 'other' , 'name' => 'socid' , 'label' => $langs -> trans ( " SelectThirdParty " ), 'value' => $form -> select_company ( GETPOST ( 'socid' , 'int' ), 'socid' , '(s.client=1 OR s.client=2 OR s.client=3)' )));
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneContract' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 );
}
// Call Hook formConfirm
$parameters = array (
'formConfirm' => $formconfirm ,
'id' => $id ,
//'lineid' => $lineid,
);
// Note that $action and $object may have been modified by hook
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action );
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
// Print form confirm
print $formconfirm ;
2022-06-29 21:19:37 +02:00
// Contract
2021-02-23 21:24:38 +01:00
if ( ! empty ( $object -> brouillon ) && $user -> rights -> contrat -> creer ) {
2017-10-16 08:47:05 +02:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="setremise">' ;
}
2016-12-04 13:30:17 +01:00
// Contract card
2005-06-11 13:33:21 +02:00
2019-11-16 23:24:29 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/contrat/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2012-07-28 20:59:57 +02:00
2017-06-07 16:44:04 +02:00
2019-11-16 23:24:29 +01:00
$morehtmlref = '' ;
if ( ! empty ( $modCodeContract -> code_auto )) {
$morehtmlref .= $object -> ref ;
2017-10-16 08:47:05 +02:00
} else {
2019-11-16 23:24:29 +01:00
$morehtmlref .= $form -> editfieldkey ( " " , 'ref' , $object -> ref , $object , $user -> rights -> contrat -> creer , 'string' , '' , 0 , 3 );
$morehtmlref .= $form -> editfieldval ( " " , 'ref' , $object -> ref , $object , $user -> rights -> contrat -> creer , 'string' , '' , 0 , 2 );
2017-10-16 08:47:05 +02:00
}
2017-06-07 16:44:04 +02:00
2019-11-16 23:24:29 +01:00
$morehtmlref .= '<div class="refidno">' ;
2016-12-04 13:30:17 +01:00
// Ref customer
2019-11-16 23:24:29 +01:00
$morehtmlref .= $form -> editfieldkey ( " RefCustomer " , 'ref_customer' , $object -> ref_customer , $object , $user -> rights -> contrat -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefCustomer " , 'ref_customer' , $object -> ref_customer , $object , $user -> rights -> contrat -> creer , 'string' , '' , null , null , '' , 1 , 'getFormatedCustomerRef' );
2016-12-04 13:30:17 +01:00
// Ref supplier
2019-11-16 23:24:29 +01:00
$morehtmlref .= '<br>' ;
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> contrat -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> contrat -> creer , 'string' , '' , null , null , '' , 1 , 'getFormatedSupplierRef' );
2016-12-04 13:30:17 +01:00
// Thirdparty
2019-11-16 23:24:29 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
2021-02-23 21:24:38 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) {
$morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/contrat/list.php?socid=' . $object -> thirdparty -> id . '&search_name=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherContracts " ) . '</a>)' ;
}
2017-10-16 08:47:05 +02:00
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2017-10-16 08:47:05 +02:00
$langs -> load ( " projects " );
2019-11-16 23:24:29 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> contrat -> creer ) {
2019-10-27 10:07:47 +01:00
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
2019-10-27 10:07:47 +01:00
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
2019-11-16 23:24:29 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
2019-12-18 23:12:31 +01:00
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-16 23:24:29 +01:00
$morehtmlref .= $formproject -> select_projects ( $object -> thirdparty -> id , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2019-10-27 10:07:47 +01:00
} else {
2019-11-16 23:24:29 +01:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> thirdparty -> id , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-27 10:07:47 +01:00
}
2017-10-16 08:47:05 +02:00
} else {
2019-11-16 23:24:29 +01:00
if ( ! empty ( $object -> fk_project )) {
2017-10-16 08:47:05 +02:00
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2017-10-16 08:47:05 +02:00
} else {
2019-11-16 23:24:29 +01:00
$morehtmlref .= '' ;
2017-10-16 08:47:05 +02:00
}
}
}
2019-11-16 23:24:29 +01:00
$morehtmlref .= '</div>' ;
2017-10-16 08:47:05 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'none' , $morehtmlref );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2019-01-17 19:27:26 +01:00
print '<table class="border tableforfield" width="100%">' ;
2017-10-16 08:47:05 +02:00
2020-05-12 23:44:50 +02:00
// Line info of thirdparty discounts
2017-10-16 08:47:05 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Discount' ) . '</td><td colspan="3">' ;
2021-02-23 21:24:38 +01:00
if ( $object -> thirdparty -> remise_percent ) {
2022-02-08 12:01:48 +01:00
print $langs -> trans ( " CompanyHasRelativeDiscount " , $object -> thirdparty -> remise_percent ) . '. ' ;
2021-02-23 21:24:38 +01:00
} else {
2022-02-08 12:01:48 +01:00
print '<span class="hideonsmartphone">' . $langs -> trans ( " CompanyHasNoRelativeDiscount " ) . '. </span>' ;
2021-02-23 21:24:38 +01:00
}
2019-11-13 19:35:39 +01:00
$absolute_discount = $object -> thirdparty -> getAvailableDiscounts ();
2021-02-23 21:24:38 +01:00
if ( $absolute_discount ) {
2022-02-08 12:01:48 +01:00
print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $absolute_discount ), $langs -> trans ( " Currency " . $conf -> currency )) . '.' ;
2021-02-23 21:24:38 +01:00
} else {
2022-02-08 12:01:48 +01:00
print '<span class="hideonsmartphone">' . $langs -> trans ( " CompanyHasNoAbsoluteDiscount " ) . '.</span>' ;
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
// Date
print '<tr>' ;
2016-12-04 13:30:17 +01:00
print '<td class="titlefield">' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldkey ( " Date " , 'date_contrat' , $object -> date_contrat , $object , $user -> rights -> contrat -> creer );
2015-12-03 10:51:03 +01:00
print '</td><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldval ( " Date " , 'date_contrat' , $object -> date_contrat , $object , $user -> rights -> contrat -> creer , 'datehourpicker' );
2015-12-03 10:51:03 +01:00
print '</td>' ;
print '</tr>' ;
2005-06-11 13:33:21 +02:00
2017-10-16 08:47:05 +02:00
// Other attributes
$cols = 3 ;
2019-11-13 19:35:39 +01:00
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
2017-10-16 08:47:05 +02:00
print " </table> " ;
2005-06-11 13:33:21 +02:00
2017-10-16 08:47:05 +02:00
print '</div>' ;
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $object -> brouillon ) && $user -> rights -> contrat -> creer ) {
2017-10-16 08:47:05 +02:00
print '</form>' ;
}
2005-06-11 13:33:21 +02:00
2017-10-16 08:47:05 +02:00
echo '<br>' ;
2012-04-07 00:22:44 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB )) {
2017-10-16 08:47:05 +02:00
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2012-07-02 19:30:37 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB )) {
2017-10-16 08:47:05 +02:00
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2012-04-07 00:22:44 +02:00
2009-01-25 18:05:40 +01:00
2022-06-21 02:15:22 +02:00
$arrayothercontracts = $object -> getListOfContracts ( 'others' ); // array or -1 if technical error
2009-01-25 18:05:40 +01:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 21:24:38 +01:00
* Lines of contracts
*/
2012-04-07 00:22:44 +02:00
2019-11-13 19:35:39 +01:00
$productstatic = new Product ( $db );
2014-05-12 13:25:36 +02:00
2019-11-13 19:35:39 +01:00
$usemargins = 0 ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $object -> element ) && in_array ( $object -> element , array ( 'facture' , 'propal' , 'commande' ))) {
$usemargins = 1 ;
}
2014-05-12 13:25:36 +02:00
2015-04-10 10:17:20 +02:00
// Title line for service
2019-11-13 19:35:39 +01:00
$cursorline = 1 ;
2018-02-08 14:06:54 +01:00
print '<div id="contrat-lines-container" data-contractid="' . $object -> id . '" data-element="' . $object -> element . '" >' ;
2021-02-23 21:24:38 +01:00
while ( $cursorline <= $nbofservices ) {
2019-11-13 19:35:39 +01:00
print '<div id="contrat-line-container' . $object -> lines [ $cursorline - 1 ] -> id . '" data-contratlineid = "' . $object -> lines [ $cursorline - 1 ] -> id . '" data-element="' . $object -> lines [ $cursorline - 1 ] -> element . '" >' ;
2018-03-01 02:37:18 +01:00
print '<form name="update" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="updateline">' ;
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="elrowid" value="' . $object -> lines [ $cursorline - 1 ] -> id . '">' ;
print '<input type="hidden" name="fournprice" value="' . ( ! empty ( $object -> lines [ $cursorline - 1 ] -> fk_fournprice ) ? $object -> lines [ $cursorline - 1 ] -> fk_fournprice : 0 ) . '">' ;
2017-10-16 08:47:05 +02:00
// Area with common detail of line
2018-04-18 03:26:15 +02:00
print '<div class="div-table-responsive-no-min">' ;
2017-10-16 08:47:05 +02:00
print '<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">' ;
$sql = " SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty, " ;
2019-11-13 19:35:39 +01:00
$sql .= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_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, " ;
$sql .= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht, " ;
$sql .= " cd.fk_unit, " ;
2020-01-20 12:25:25 +01:00
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity, p.tosell, p.tobuy, p.tobatch " ;
2019-11-13 19:35:39 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE cd.rowid = " . (( int ) $object -> lines [ $cursorline - 1 ] -> id );
2017-10-16 08:47:05 +02:00
$result = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $result ) {
2017-10-16 08:47:05 +02:00
$total = 0 ;
2019-11-13 19:35:39 +01:00
print '<tr class="liste_titre' . ( $cursorline ? ' liste_titre_add' : '' ) . '">' ;
2019-01-27 11:55:16 +01:00
print '<td>' . $langs -> trans ( " ServiceNb " , $cursorline ) . '</td>' ;
2019-03-03 09:37:43 +01:00
print '<td width="80" class="center">' . $langs -> trans ( " VAT " ) . '</td>' ;
2019-02-19 17:06:25 +01:00
print '<td width="80" class="right">' . $langs -> trans ( " PriceUHT " ) . '</td>' ;
2019-10-14 15:36:28 +02:00
//if (!empty($conf->multicurrency->enabled)) {
// print '<td width="80" class="right">'.$langs->trans("PriceUHTCurrency").'</td>';
//}
2019-03-03 09:37:43 +01:00
print '<td width="30" class="center">' . $langs -> trans ( " Qty " ) . '</td>' ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
print '<td width="30" class="left">' . $langs -> trans ( " Unit " ) . '</td>' ;
}
2019-02-19 17:06:25 +01:00
print '<td width="50" class="right">' . $langs -> trans ( " ReductionShort " ) . '</td>' ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) {
print '<td width="50" class="right">' . $langs -> trans ( " BuyingPrice " ) . '</td>' ;
}
2017-10-16 08:47:05 +02:00
print '<td width="30"> </td>' ;
print " </tr> \n " ;
$objp = $db -> fetch_object ( $result );
2019-10-14 15:36:28 +02:00
// Line in view mode
2021-02-23 21:24:38 +01:00
if ( $action != 'editline' || GETPOST ( 'rowid' ) != $objp -> rowid ) {
2020-10-31 18:51:30 +01:00
$moreparam = '' ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT ) && $objp -> statut == ContratLigne :: STATUS_CLOSED && $action != 'showclosedlines' ) {
$moreparam = 'style="display: none;"' ;
}
2020-06-16 10:30:10 +02:00
print '<tr class="tdtop oddeven" ' . $moreparam . '>' ;
2017-10-16 08:47:05 +02:00
// Label
2021-02-23 21:24:38 +01:00
if ( $objp -> fk_product > 0 ) {
2019-11-13 19:35:39 +01:00
$productstatic -> id = $objp -> fk_product ;
$productstatic -> type = $objp -> ptype ;
$productstatic -> ref = $objp -> pref ;
$productstatic -> entity = $objp -> pentity ;
$productstatic -> label = $objp -> plabel ;
2020-01-20 12:25:25 +01:00
$productstatic -> status = $objp -> tosell ;
$productstatic -> status_buy = $objp -> tobuy ;
$productstatic -> status_batch = $objp -> tobatch ;
print '<td>' ;
2019-01-27 11:55:16 +01:00
$text = $productstatic -> getNomUrl ( 1 , '' , 32 );
2021-02-23 21:24:38 +01:00
if ( $objp -> plabel ) {
2017-10-16 08:47:05 +02:00
$text .= ' - ' ;
$text .= $objp -> plabel ;
}
$description = $objp -> description ;
// Add description in form
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM )) {
2019-11-13 19:35:39 +01:00
$text .= ( ! empty ( $objp -> description ) && $objp -> description != $objp -> plabel ) ? '<br>' . dol_htmlentitiesbr ( $objp -> description ) : '' ;
$description = '' ; // Already added into main visible desc
2015-04-29 19:15:14 +02:00
}
2019-11-13 19:35:39 +01:00
echo $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $cursorline , 0 , ( ! empty ( $line -> fk_parent_line ) ? img_picto ( '' , 'rightarrow' ) : '' ));
2015-04-29 19:15:14 +02:00
2017-10-16 08:47:05 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
print '<td>' . img_object ( $langs -> trans ( " ShowProductOrService " ), ( $objp -> product_type ? 'service' : 'product' )) . ' ' . dol_htmlentitiesbr ( $objp -> description ) . " </td> \n " ;
}
2019-10-14 15:36:28 +02:00
// VAT
2019-03-03 09:37:43 +01:00
print '<td class="center">' ;
2019-11-13 19:35:39 +01:00
print vatrate ( $objp -> tva_tx . ( $objp -> vat_src_code ? ( ' (' . $objp -> vat_src_code . ')' ) : '' ), '%' , $objp -> info_bits );
2017-10-16 08:47:05 +02:00
print '</td>' ;
// Price
2019-02-19 17:06:25 +01:00
print '<td class="right">' . ( $objp -> subprice != '' ? price ( $objp -> subprice ) : '' ) . " </td> \n " ;
2017-10-16 08:47:05 +02:00
// Price multicurrency
2019-10-14 15:36:28 +02:00
/* if ( ! empty ( $conf -> multicurrency -> enabled )) {
2019-02-19 17:06:25 +01:00
print '<td class="linecoluht_currency nowrap right">' . price ( $objp -> multicurrency_subprice ) . '</td>' ;
2019-10-14 15:36:28 +02:00
} */
// Quantity
2019-03-03 09:37:43 +01:00
print '<td class="center">' . $objp -> qty . '</td>' ;
2017-10-16 08:47:05 +02:00
// Unit
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
print '<td class="left">' . $langs -> trans ( $object -> lines [ $cursorline - 1 ] -> getLabelOfUnit ()) . '</td>' ;
}
2019-10-14 15:36:28 +02:00
// Discount
2021-02-23 21:24:38 +01:00
if ( $objp -> remise_percent > 0 ) {
2019-02-19 17:06:25 +01:00
print '<td class="right">' . $objp -> remise_percent . " %</td> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
print '<td> </td>' ;
}
2013-02-13 10:35:47 +01:00
2014-04-23 13:51:02 +02:00
// Margin
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) {
2022-01-02 12:49:15 +01:00
print '<td class="right nowraponall">' . price ( $objp -> pa_ht ) . '</td>' ;
2021-02-23 21:24:38 +01:00
}
2013-02-13 10:35:47 +01:00
2022-06-21 02:15:22 +02:00
// Icon move, update et delete (status contract 0=draft,1=validated,2=closed)
2022-01-02 12:49:15 +01:00
print '<td class="nowraponall right">' ;
2022-06-21 02:15:22 +02:00
if ( $user -> rights -> contrat -> creer && is_array ( $arrayothercontracts ) && count ( $arrayothercontracts ) && ( $object -> statut >= 0 )) {
2018-03-17 13:21:27 +01:00
print '<!-- link to move service line into another contract -->' ;
2021-09-27 12:24:01 +02:00
print '<a class="reposition marginrightonly" style="padding-left: 5px;" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=move&token=' . newToken () . '&rowid=' . $objp -> rowid . '">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " MoveToAnotherContract " ), 'uparrow' );
2017-10-16 08:47:05 +02:00
print '</a>' ;
}
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> contrat -> creer && ( $object -> statut >= 0 )) {
2021-09-27 12:24:01 +02:00
print '<a class="reposition marginrightonly editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=editline&token=' . newToken () . '&rowid=' . $objp -> rowid . '">' ;
2017-10-16 08:47:05 +02:00
print img_edit ();
print '</a>' ;
}
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> contrat -> creer && ( $object -> statut >= 0 )) {
2021-09-18 22:04:41 +02:00
print '<a class="reposition marginrightonly" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=deleteline&token=' . newToken () . '&rowid=' . $objp -> rowid . '">' ;
2017-10-16 08:47:05 +02:00
print img_delete ();
print '</a>' ;
}
print '</td>' ;
print " </tr> \n " ;
// Dates of service planed and real
2021-02-23 21:24:38 +01:00
if ( $objp -> subprice >= 0 ) {
2017-10-16 08:47:05 +02: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 ;
}
2020-06-16 10:30:10 +02:00
print '<tr class="oddeven" ' . $moreparam . '>' ;
2017-10-16 08:47:05 +02:00
print '<td colspan="' . $colspan . '">' ;
// Date planned
print $langs -> trans ( " DateStartPlanned " ) . ': ' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> date_debut ) {
2017-10-16 08:47:05 +02:00
print dol_print_date ( $db -> jdate ( $objp -> date_debut ), 'day' );
// 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 )) {
2019-11-13 19:35:39 +01:00
$warning_delay = $conf -> contrat -> services -> inactifs -> warning_delay / 3600 / 24 ;
2017-10-16 08:47:05 +02:00
$textlate = $langs -> trans ( " Late " ) . ' = ' . $langs -> trans ( " DateReference " ) . ' > ' . $langs -> trans ( " DateToday " ) . ' ' . ( ceil ( $warning_delay ) >= 0 ? '+' : '' ) . ceil ( $warning_delay ) . ' ' . $langs -> trans ( " days " );
print " " . img_warning ( $textlate );
}
2021-02-23 21:24:38 +01:00
} else {
print $langs -> trans ( " Unknown " );
}
2017-10-16 08:47:05 +02:00
print ' - ' ;
print $langs -> trans ( " DateEndPlanned " ) . ': ' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> date_fin ) {
2017-10-16 08:47:05 +02:00
print dol_print_date ( $db -> jdate ( $objp -> date_fin ), 'day' );
if ( $objp -> statut == 4 && $db -> jdate ( $objp -> date_fin ) < ( $now - $conf -> contrat -> services -> expires -> warning_delay )) {
2019-11-13 19:35:39 +01:00
$warning_delay = $conf -> contrat -> services -> expires -> warning_delay / 3600 / 24 ;
2017-10-16 08:47:05 +02:00
$textlate = $langs -> trans ( " Late " ) . ' = ' . $langs -> trans ( " DateReference " ) . ' > ' . $langs -> trans ( " DateToday " ) . ' ' . ( ceil ( $warning_delay ) >= 0 ? '+' : '' ) . ceil ( $warning_delay ) . ' ' . $langs -> trans ( " days " );
print " " . img_warning ( $textlate );
}
2021-02-23 21:24:38 +01:00
} else {
print $langs -> trans ( " Unknown " );
}
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '</tr>' ;
}
// Display lines extrafields
2019-11-13 19:35:39 +01:00
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
2017-10-16 08:47:05 +02:00
$line = new ContratLigne ( $db );
2020-03-27 16:02:58 +01:00
$line -> id = $objp -> rowid ;
$line -> fetch_optionals ();
2020-10-31 14:32:18 +01:00
print $line -> showOptionals ( $extrafields , 'view' , array ( 'class' => 'oddeven' , 'style' => $moreparam , 'colspan' => $colspan ), '' , '' , 1 );
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
} else {
// Line in mode update
2017-10-16 08:47:05 +02:00
// Ligne carac
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven">' ;
2017-10-16 08:47:05 +02:00
print '<td>' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> fk_product > 0 ) {
2020-09-23 18:45:19 +02:00
$canchangeproduct = 1 ;
if ( empty ( $canchangeproduct )) {
$productstatic -> id = $objp -> fk_product ;
$productstatic -> type = $objp -> ptype ;
$productstatic -> ref = $objp -> pref ;
$productstatic -> entity = $objp -> pentity ;
print $productstatic -> getNomUrl ( 1 , '' , 32 );
print $objp -> label ? ' - ' . dol_trunc ( $objp -> label , 32 ) : '' ;
print '<input type="hidden" name="idprod" value="' . ( ! empty ( $object -> lines [ $cursorline - 1 ] -> fk_product ) ? $object -> lines [ $cursorline - 1 ] -> fk_product : 0 ) . '">' ;
} else {
$senderissupplier = 0 ;
if ( empty ( $senderissupplier )) {
print $form -> select_produits (( ! empty ( $object -> lines [ $cursorline - 1 ] -> fk_product ) ? $object -> lines [ $cursorline - 1 ] -> fk_product : 0 ), 'idprod' );
} else {
print $form -> select_produits_fournisseurs (( ! empty ( $object -> lines [ $cursorline - 1 ] -> fk_product ) ? $object -> lines [ $cursorline - 1 ] -> fk_product : 0 ), 'idprod' );
}
}
2017-10-16 08:47:05 +02:00
print '<br>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-16 23:24:29 +01:00
print $objp -> label ? $objp -> label . '<br>' : '' ;
2020-09-23 18:45:19 +02:00
print '<input type="hidden" name="idprod" value="' . ( ! empty ( $object -> lines [ $cursorline - 1 ] -> fk_product ) ? $object -> lines [ $cursorline - 1 ] -> fk_product : 0 ) . '">' ;
2017-10-16 08:47:05 +02:00
}
// editeur wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-16 23:24:29 +01:00
$nbrows = ROWS_2 ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) {
$nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
}
2019-11-16 23:24:29 +01:00
$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 , '90%' );
2017-10-16 08:47:05 +02:00
$doleditor -> Create ();
print '</td>' ;
2019-10-14 15:36:28 +02:00
// VAT
2019-02-19 17:06:25 +01:00
print '<td class="right">' ;
2019-11-16 23:24:29 +01:00
print $form -> load_tva ( " eltva_tx " , $objp -> tva_tx . ( $objp -> vat_src_code ? ( ' (' . $objp -> vat_src_code . ')' ) : '' ), $mysoc , $object -> thirdparty , $objp -> fk_product , $objp -> info_bits , $objp -> product_type , 0 , 1 );
2017-10-16 08:47:05 +02:00
print '</td>' ;
2019-10-14 15:36:28 +02:00
// Price
2019-02-19 17:06:25 +01:00
print '<td class="right"><input size="5" type="text" name="elprice" value="' . price ( $objp -> subprice ) . '"></td>' ;
2019-10-14 15:36:28 +02:00
// Price multicurrency
/* if ( ! empty ( $conf -> multicurrency -> enabled )) {
print '<td class="linecoluht_currency nowrap right">' . price ( $objp -> multicurrency_subprice ) . '</td>' ;
} */
// Quantity
2019-03-03 09:37:43 +01:00
print '<td class="center"><input size="2" type="text" name="elqty" value="' . $objp -> qty . '"></td>' ;
2019-10-14 15:36:28 +02:00
// Unit
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2019-01-19 12:29:41 +01:00
print '<td class="left">' ;
2017-10-16 08:47:05 +02:00
print $form -> selectUnits ( $objp -> fk_unit , " unit " );
print '</td>' ;
}
2019-10-14 15:36:28 +02:00
// Discount
2019-02-19 17:06:25 +01:00
print '<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="' . $objp -> remise_percent . '">%</td>' ;
2019-10-14 15:36:28 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $usemargins )) {
2019-02-19 17:06:25 +01:00
print '<td class="right">' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> fk_product ) {
print '<select id="fournprice" name="fournprice"></select>' ;
}
2019-01-27 11:55:16 +01:00
print '<input id="buying_price" type="text" size="5" name="buying_price" value="' . price ( $objp -> pa_ht , 0 , '' , 0 ) . '"></td>' ;
2013-02-13 10:35:47 +01:00
}
2019-03-03 09:37:43 +01:00
print '<td class="center">' ;
2020-05-12 23:44:50 +02:00
print '<input type="submit" class="button margintoponly marginbottomonly" name="save" value="' . $langs -> trans ( " Modify " ) . '">' ;
2020-11-23 15:12:52 +01:00
print '<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
2018-03-20 14:52:27 +01:00
print '</tr>' ;
2018-04-17 21:06:26 +02:00
2019-11-13 19:35:39 +01:00
$colspan = 6 ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $conf -> global -> MARGIN_SHOW_ON_CONTRACT )) {
$colspan ++ ;
}
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
$colspan ++ ;
}
2017-10-16 08:47:05 +02:00
2021-07-23 00:02:14 +02:00
// Line dates planed
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven">' ;
2017-10-16 08:47:05 +02:00
print '<td colspan="' . $colspan . '">' ;
print $langs -> trans ( " DateStartPlanned " ) . ' ' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $db -> jdate ( $objp -> date_debut ), " date_start_update " , $usehm , $usehm , ( $db -> jdate ( $objp -> date_debut ) > 0 ? 0 : 1 ), " update " );
2017-10-16 08:47:05 +02:00
print ' ' . $langs -> trans ( " DateEndPlanned " ) . ' ' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $db -> jdate ( $objp -> date_fin ), " date_end_update " , $usehm , $usehm , ( $db -> jdate ( $objp -> date_fin ) > 0 ? 0 : 1 ), " update " );
2017-10-16 08:47:05 +02:00
print '</td>' ;
2018-03-20 10:10:21 +01:00
print '</tr>' ;
2017-10-16 08:47:05 +02:00
2019-11-13 19:35:39 +01:00
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
2017-10-16 08:47:05 +02:00
$line = new ContratLigne ( $db );
2020-03-27 16:02:58 +01:00
$line -> id = $objp -> rowid ;
$line -> fetch_optionals ();
2020-02-21 14:32:23 +01:00
print $line -> showOptionals ( $extrafields , 'edit' , array ( 'style' => 'class="oddeven"' , 'colspan' => $colspan ), '' , '' , 1 );
2017-10-16 08:47:05 +02:00
}
}
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
dol_print_error ( $db );
}
2011-09-21 15:44:20 +02:00
2021-02-23 21:24:38 +01:00
if ( $object -> statut > 0 ) {
2020-10-31 18:51:30 +01:00
$moreparam = '' ;
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT ) && $object -> lines [ $cursorline - 1 ] -> statut == ContratLigne :: STATUS_CLOSED && $action != 'showclosedlines' ) {
$moreparam = 'style="display: none;"' ;
}
2020-06-16 10:30:10 +02:00
print '<tr class="oddeven" ' . $moreparam . '>' ;
2019-11-13 19:35:39 +01:00
print '<td class="tdhrthin" colspan="' . ( $conf -> margin -> enabled ? 7 : 6 ) . '"><hr class="opacitymedium tdhrthin"></td>' ;
2017-10-16 08:47:05 +02:00
print " </tr> \n " ;
}
2011-09-21 15:44:20 +02:00
2017-10-16 08:47:05 +02:00
print " </table> " ;
2018-04-18 03:26:15 +02:00
print '</div>' ;
2013-11-17 23:25:25 +01:00
2017-10-16 08:47:05 +02:00
print " </form> \n " ;
2011-09-21 15:44:20 +02:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 21:24:38 +01:00
* Confirmation to delete service line of contract
*/
if ( $action == 'deleteline' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> creer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'rowid' )) {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &lineid= " . GETPOST ( 'rowid' ), $langs -> trans ( " DeleteContractLine " ), $langs -> trans ( " ConfirmDeleteContractLine " ), " confirm_deleteline " , '' , 0 , 1 );
2021-02-23 21:24:38 +01:00
if ( $ret == 'html' ) {
print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>' ;
}
2017-10-16 08:47:05 +02:00
}
2011-09-21 15:44:20 +02:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 21:24:38 +01:00
* Confirmation to move service toward another contract
*/
if ( $action == 'move' && ! $_REQUEST [ " cancel " ] && $user -> rights -> contrat -> creer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'rowid' )) {
2019-11-13 19:35:39 +01:00
$arraycontractid = array ();
2021-02-23 21:24:38 +01:00
foreach ( $arrayothercontracts as $contractcursor ) {
2019-11-13 19:35:39 +01:00
$arraycontractid [ $contractcursor -> id ] = $contractcursor -> ref ;
2017-10-16 08:47:05 +02:00
}
//var_dump($arraycontractid);
// Cree un tableau formulaire
2019-11-13 19:35:39 +01:00
$formquestion = array (
2008-09-26 01:30:06 +02:00
'text' => $langs -> trans ( " ConfirmMoveToAnotherContractQuestion " ),
2017-10-16 08:47:05 +02:00
array ( 'type' => 'select' , 'name' => 'newcid' , 'values' => $arraycontractid ));
2011-09-21 15:44:20 +02:00
2021-03-29 15:07:23 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &lineid= " . GETPOST ( 'rowid' , 'int' ), $langs -> trans ( " MoveToAnotherContract " ), $langs -> trans ( " ConfirmMoveToAnotherContract " ), " confirm_move " , $formquestion );
2017-10-16 08:47:05 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>' ;
}
2011-09-21 15:44:20 +02:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 21:24:38 +01:00
* Confirmation de la validation activation
*/
2021-03-29 15:07:23 +02:00
if ( $action == 'active' && ! $cancel && $user -> rights -> contrat -> activer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' , 'int' )) {
2017-10-16 08:47:05 +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' ));
2019-01-27 11:55:16 +01:00
$comment = GETPOST ( 'comment' , 'alpha' );
2021-03-29 15:07:23 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &ligne= " . GETPOST ( 'ligne' , 'int' ) . " &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 );
2017-10-16 08:47:05 +02:00
print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>' ;
}
/*
2021-02-23 21:24:38 +01:00
* Confirmation de la validation fermeture
*/
2021-03-29 15:07:23 +02:00
if ( $action == 'closeline' && ! $cancel && $user -> rights -> contrat -> activer && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' , 'int' )) {
2017-10-16 08:47:05 +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' ));
2019-01-27 11:55:16 +01:00
$comment = GETPOST ( 'comment' , 'alpha' );
2017-10-16 08:47:05 +02:00
2021-02-23 21:24:38 +01:00
if ( empty ( $dateactend )) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DateEndReal " )), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &ligne= " . GETPOST ( 'ligne' , 'int' ) . " &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 );
2017-10-16 08:47:05 +02:00
}
print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>' ;
}
// Area with status and activation info of line
2021-02-23 21:24:38 +01:00
if ( $object -> statut > 0 ) {
2019-11-16 23:24:29 +01:00
print '<table class="notopnoleftnoright tableforservicepart2' . ( $cursorline < $nbofservices ? ' boxtablenobottom' : '' ) . '" width="100%">' ;
2017-10-16 08:47:05 +02:00
2020-06-16 10:30:10 +02:00
print '<tr class="oddeven" ' . $moreparam . '>' ;
2021-07-23 00:02:14 +02:00
print '<td><span class="valignmiddle hideonsmartphone">' . $langs -> trans ( " ServiceStatus " ) . ':</span> ' . $object -> lines [ $cursorline - 1 ] -> getLibStatut ( 4 ) . '</td>' ;
2019-02-19 17:06:25 +01:00
print '<td width="30" class="right">' ;
2021-02-23 21:24:38 +01:00
if ( $user -> socid == 0 ) {
if ( $object -> statut > 0 && $action != 'activateline' && $action != 'unactivateline' ) {
2019-11-16 23:24:29 +01:00
$tmpaction = 'activateline' ;
$tmpactionpicto = 'play' ;
$tmpactiontext = $langs -> trans ( " Activate " );
2021-02-23 21:24:38 +01:00
if ( $objp -> statut == 4 ) {
2019-11-16 23:24:29 +01:00
$tmpaction = 'unactivateline' ;
$tmpactionpicto = 'playstop' ;
$tmpactiontext = $langs -> trans ( " Disable " );
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
if (( $tmpaction == 'activateline' && $user -> rights -> contrat -> activer ) || ( $tmpaction == 'unactivateline' && $user -> rights -> contrat -> desactiver )) {
2019-11-16 23:24:29 +01:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . $object -> lines [ $cursorline - 1 ] -> id . '&action=' . $tmpaction . '">' ;
2017-01-22 14:55:41 +01:00
print img_picto ( $tmpactiontext , $tmpactionpicto );
2016-01-26 13:02:21 +01:00
print '</a>' ;
}
2017-10-16 08:47:05 +02:00
}
}
print '</td>' ;
print " </tr> \n " ;
2020-06-16 10:30:10 +02:00
print '<tr class="oddeven" ' . $moreparam . '>' ;
2017-10-16 08:47:05 +02:00
print '<td>' ;
// Si pas encore active
2019-11-13 19:35:39 +01:00
if ( ! $objp -> date_debut_reelle ) {
2017-10-16 08:47:05 +02:00
print $langs -> trans ( " DateStartReal " ) . ': ' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> date_debut_reelle ) {
print dol_print_date ( $db -> jdate ( $objp -> date_debut_reelle ), 'day' );
} else {
print $langs -> trans ( " ContractStatusNotRunning " );
}
2017-10-16 08:47:05 +02:00
}
// Si active et en cours
2019-11-13 19:35:39 +01:00
if ( $objp -> date_debut_reelle && ! $objp -> date_fin_reelle ) {
2017-10-16 08:47:05 +02:00
print $langs -> trans ( " DateStartReal " ) . ': ' ;
2020-10-31 14:32:18 +01:00
print dol_print_date ( $db -> jdate ( $objp -> date_debut_reelle ), 'day' );
2017-10-16 08:47:05 +02:00
}
// Si desactive
if ( $objp -> date_debut_reelle && $objp -> date_fin_reelle ) {
print $langs -> trans ( " DateStartReal " ) . ': ' ;
2020-10-31 14:32:18 +01:00
print dol_print_date ( $db -> jdate ( $objp -> date_debut_reelle ), 'day' );
2017-10-16 08:47:05 +02:00
print ' - ' ;
print $langs -> trans ( " DateEndReal " ) . ': ' ;
2019-03-15 08:42:00 +01:00
print dol_print_date ( $db -> jdate ( $objp -> date_fin_reelle ), 'day' );
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
if ( ! empty ( $objp -> comment )) {
print " - " . $objp -> comment ;
}
2017-10-16 08:47:05 +02:00
print '</td>' ;
2019-03-03 09:37:43 +01:00
print '<td class="center"> </td>' ;
2017-10-16 08:47:05 +02:00
print '</tr>' ;
print '</table>' ;
}
// Form to activate line
2021-03-29 15:07:23 +02:00
if ( $user -> rights -> contrat -> activer && $action == 'activateline' && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' , 'int' )) {
print '<form name="active" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . GETPOST ( 'ligne' , 'int' ) . '&action=active" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
2019-11-13 19:35:39 +01:00
print '<table class="noborder tableforservicepart2' . ( $cursorline < $nbofservices ? ' boxtablenobottom' : '' ) . '" width="100%">' ;
2017-10-16 08:47:05 +02:00
// Definie date debut et fin par defaut
$dateactstart = $objp -> date_debut ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'remonth' )) {
$dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
} elseif ( ! $dateactstart ) {
$dateactstart = time ();
}
2017-10-16 08:47:05 +02:00
$dateactend = $objp -> date_fin ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'endmonth' )) {
$dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
} elseif ( ! $dateactend ) {
if ( $objp -> fk_product > 0 ) {
2019-11-13 19:35:39 +01:00
$product = new Product ( $db );
2017-10-16 08:47:05 +02:00
$product -> fetch ( $objp -> fk_product );
$dateactend = dol_time_plus_duree ( time (), $product -> duration_value , $product -> duration_unit );
}
}
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven">' ;
2017-10-16 08:47:05 +02:00
print '<td class="nohover">' . $langs -> trans ( " DateServiceActivate " ) . '</td><td class="nohover">' ;
2018-09-09 09:36:12 +02:00
print $form -> selectDate ( $dateactstart , '' , $usehm , $usehm , '' , " active " , 1 , 0 );
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '<td class="nohover">' . $langs -> trans ( " DateEndPlanned " ) . '</td><td class="nohover">' ;
2018-09-09 09:36:12 +02:00
print $form -> selectDate ( $dateactend , " end " , $usehm , $usehm , '' , " active " , 1 , 0 );
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '<td class="center nohover">' ;
print '</td>' ;
print '</tr>' ;
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven">' ;
2020-11-23 22:04:21 +01:00
print '<td class="nohover">' . $langs -> trans ( " Comment " ) . '</td><td colspan="3" class="nohover" colspan="' . ( $conf -> margin -> enabled ? 4 : 3 ) . '"><input type="text" class="minwidth300" name="comment" value="' . dol_escape_htmltag ( GETPOST ( " comment " , 'alphanohtml' )) . '"></td>' ;
2017-10-16 08:47:05 +02:00
print '<td class="nohover right">' ;
print '<input type="submit" class="button" name="activate" value="' . $langs -> trans ( " Activate " ) . '"> ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '</tr>' ;
print '</table>' ;
print '</form>' ;
}
2021-03-29 15:07:23 +02:00
if ( $user -> rights -> contrat -> activer && $action == 'unactivateline' && $object -> lines [ $cursorline - 1 ] -> id == GETPOST ( 'ligne' , 'int' )) {
2017-10-16 08:47:05 +02:00
/**
* Disable a contract line
*/
print '<!-- Form to disabled a line -->' . " \n " ;
2019-11-13 19:35:39 +01:00
print '<form name="closeline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&ligne=' . $object -> lines [ $cursorline - 1 ] -> id . '" method="post">' ;
2017-10-16 08:47:05 +02:00
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="closeline">' ;
2019-11-13 19:35:39 +01:00
print '<table class="noborder tableforservicepart2' . ( $cursorline < $nbofservices ? ' boxtablenobottom' : '' ) . '" width="100%">' ;
2017-10-16 08:47:05 +02:00
// Definie date debut et fin par defaut
$dateactstart = $objp -> date_debut_reelle ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'remonth' )) {
$dateactstart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
} elseif ( ! $dateactstart ) {
$dateactstart = time ();
}
2017-10-16 08:47:05 +02:00
$dateactend = $objp -> date_fin_reelle ;
2021-02-23 21:24:38 +01:00
if ( GETPOST ( 'endmonth' )) {
$dateactend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
} elseif ( ! $dateactend ) {
if ( $objp -> fk_product > 0 ) {
2019-11-13 19:35:39 +01:00
$product = new Product ( $db );
2017-10-16 08:47:05 +02:00
$product -> fetch ( $objp -> fk_product );
$dateactend = dol_time_plus_duree ( time (), $product -> duration_value , $product -> duration_unit );
}
}
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2021-02-23 21:24:38 +01:00
if ( $dateactend > $now ) {
$dateactend = $now ;
}
2017-10-16 08:47:05 +02:00
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven"><td colspan="2" class="nohover">' ;
2021-02-23 21:24:38 +01:00
if ( $objp -> statut >= 4 ) {
if ( $objp -> statut == 4 ) {
2017-10-16 08:47:05 +02:00
print $langs -> trans ( " DateEndReal " ) . ' ' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $dateactend , " end " , $usehm , $usehm , ( $objp -> date_fin_reelle > 0 ? 0 : 1 ), " closeline " , 1 , 1 );
2017-10-16 08:47:05 +02:00
}
}
print '</td>' ;
print '<td class="center nohover">' ;
print '</td></tr>' ;
2018-04-19 16:50:47 +02:00
print '<tr class="oddeven">' ;
2017-10-16 08:47:05 +02:00
print '<td class="nohover">' . $langs -> trans ( " Comment " ) . '</td><td class="nohover"><input size="70" type="text" class="flat" name="comment" value="' . dol_escape_htmltag ( GETPOST ( 'comment' , 'alpha' )) . '"></td>' ;
print '<td class="nohover right">' ;
2017-12-28 09:56:40 +01:00
print '<input type="submit" class="button" name="close" value="' . $langs -> trans ( " Disable " ) . '"> ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '</tr>' ;
print '</table>' ;
print '</form>' ;
}
2018-02-08 14:06:54 +01:00
print '</div>' ;
2017-10-16 08:47:05 +02:00
$cursorline ++ ;
}
2018-02-08 14:06:54 +01:00
print '</div>' ;
2013-11-17 23:25:25 +01:00
2012-12-28 11:36:31 +01:00
// Form to add new line
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> contrat -> creer && ( $object -> statut == 0 )) {
2019-11-16 23:24:29 +01:00
$dateSelector = 1 ;
2013-01-26 10:35:30 +01:00
2013-11-17 23:25:25 +01:00
print " \n " ;
2021-04-25 15:55:36 +02:00
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . (( $action != 'editline' ) ? '#add' : '#line_' . GETPOST ( 'lineid' , 'int' )) . ' " method= " POST " >
2019-12-18 23:12:31 +01:00
< input type = " hidden " name = " token " value = " '.newToken().' " >
2019-11-16 23:24:29 +01:00
< input type = " hidden " name = " action " value = " '.(( $action != 'editline') ? 'addline' : 'updateline').' " >
2013-11-17 23:25:25 +01:00
< input type = " hidden " name = " mode " value = " " >
< input type = " hidden " name = " id " value = " '. $object->id .' " >
' ;
2017-10-16 08:47:05 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-16 23:24:29 +01:00
print '<table id="tablelines" class="noborder noshadow" width="100%">' ; // Array with (n*2)+1 lines
2012-12-28 11:36:31 +01:00
2017-10-16 08:47:05 +02:00
// Form to add new line
2021-02-23 21:24:38 +01:00
if ( $action != 'editline' ) {
2019-11-16 23:24:29 +01:00
$forcetoshowtitlelines = 1 ;
2021-02-23 21:24:38 +01:00
if ( empty ( $object -> multicurrency_code )) {
$object -> multicurrency_code = $conf -> currency ; // TODO Remove this when multicurrency supported on contracts
}
2017-06-07 16:44:04 +02:00
2014-05-05 14:30:08 +02:00
// Add free products/services
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formAddObjectLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-04-29 15:32:15 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
2021-04-29 17:36:45 +02:00
$object -> formAddObjectLine ( 1 , $mysoc , $soc );
2014-05-05 14:30:08 +02:00
}
2013-01-26 10:35:30 +01:00
2017-10-16 08:47:05 +02:00
print '</table>' ;
print '</div>' ;
print '</form>' ;
}
2011-09-21 15:44:20 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2005-06-11 13:33:21 +02:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 21:24:38 +01:00
* Buttons
*/
2005-06-11 13:33:21 +02:00
2021-02-23 21:24:38 +01:00
if ( $user -> socid == 0 ) {
2017-10-16 08:47:05 +02:00
print '<div class="tabsAction">' ;
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( empty ( $reshook )) {
2022-03-10 15:56:10 +01:00
$params = array (
'attr' => array (
'title' => '' ,
'class' => 'classfortooltip'
)
);
2017-10-16 08:47:05 +02:00
// Send
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
if ( $object -> statut == 1 ) {
2020-12-10 13:11:55 +01:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> contrat -> creer )) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'SendMail' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&token=' . newToken () . '&mode=init#formmailbeforetitle' , '' , true , $params );
2021-02-23 21:24:38 +01:00
} else {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'SendMail' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:24:38 +01:00
}
2020-04-10 01:37:04 +02:00
}
2017-10-16 08:47:05 +02:00
}
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( $object -> statut == 0 && $nbofservices ) {
if ( $user -> rights -> contrat -> creer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'Validate' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid&token=' . newToken (), '' , true , $params );
2021-02-23 21:24:38 +01:00
} else {
2022-03-10 15:56:10 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " NotEnoughPermissions " );
print dolGetButtonAction ( $langs -> trans ( 'Validate' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
if ( $object -> statut == 1 ) {
if ( $user -> rights -> contrat -> creer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen&token=' . newToken (), '' , true , $params );
2021-02-23 21:24:38 +01:00
} else {
2022-03-10 15:56:10 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " NotEnoughPermissions " );
print dolGetButtonAction ( $langs -> trans ( 'Modify' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
}
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> commande -> enabled ) && $object -> statut > 0 && $object -> nbofservicesclosed < $nbofservices ) {
2017-10-16 08:47:05 +02:00
$langs -> load ( " orders " );
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> commande -> creer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'CreateOrder' ), '' , 'default' , DOL_URL_ROOT . '/commande/card.php?action=create&token=' . newToken () . '&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> thirdparty -> id , '' , true , $params );
2021-02-23 21:24:38 +01:00
} else {
2022-03-10 15:56:10 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " NotEnoughPermissions " );
print dolGetButtonAction ( $langs -> trans ( 'CreateOrder' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
}
2017-06-07 16:44:04 +02:00
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' ) && $object -> statut > 0 ) {
2020-07-04 13:45:28 +02:00
$langs -> load ( " bills " );
2021-02-23 21:24:38 +01:00
if ( $user -> rights -> facture -> creer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'CreateBill' ), '' , 'default' , DOL_URL_ROOT . '/compta/facture/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> thirdparty -> id , '' , true , $params );
2021-02-23 21:24:38 +01:00
} else {
2022-03-10 15:56:10 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " NotEnoughPermissions " );
print dolGetButtonAction ( $langs -> trans ( 'CreateBill' ), '' , 'default' , '#' , '' , false , $params );
2021-02-23 21:24:38 +01:00
}
2017-10-16 08:47:05 +02:00
}
2016-12-10 12:23:02 +01:00
2021-02-23 21:24:38 +01:00
if ( $object -> nbofservicesclosed > 0 || $object -> nbofserviceswait > 0 ) {
if ( $user -> rights -> contrat -> activer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ActivateAllContracts' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=activate&token=' . newToken (), '' , true , $params );
2020-05-21 15:05:19 +02:00
} else {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ActivateAllContracts' ), '' , 'default' , '#' , '' , false , $params );
2018-06-23 14:23:07 +02:00
}
2017-10-16 08:47:05 +02:00
}
2021-02-23 21:24:38 +01:00
if ( $object -> nbofservicesclosed < $nbofservices ) {
if ( $user -> rights -> contrat -> desactiver ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'CloseAllContracts' ), '' , 'default' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=close&token=' . newToken (), '' , true , $params );
2020-05-21 15:05:19 +02:00
} else {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'CloseAllContracts' ), '' , 'default' , '#' , '' , false , $params );
2018-06-23 14:23:07 +02:00
}
2017-10-16 08:47:05 +02:00
//if (! $numactive)
//{
//}
//else
//{
2018-11-13 21:40:17 +01:00
// print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("CloseRefusedBecauseOneServiceActive").'">'.$langs->trans("Close").'</a></div>';
2017-10-16 08:47:05 +02:00
//}
}
2017-06-07 16:44:04 +02:00
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> global -> CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT ) && $object -> nbofservicesclosed > 0 ) {
if ( $action == 'showclosedlines' ) {
print '<div class="inline-block divButAction"><a class="butAction" id="btnhideclosedlines" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=hideclosedlines">' . $langs -> trans ( " HideClosedServices " ) . '</a></div>' ;
} else {
print '<div class="inline-block divButAction"><a class="butAction" id="btnshowclosedlines" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=showclosedlines">' . $langs -> trans ( " ShowClosedServices " ) . '</a></div>' ;
}
2020-10-31 18:51:30 +01:00
}
2020-07-05 14:16:57 +02:00
2020-10-31 18:51:30 +01:00
// Clone
if ( $user -> rights -> contrat -> creer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'ToClone' ), '' , 'default' , $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&socid=' . $object -> socid . '&action=clone&token=' . newToken (), '' , true , $params );
2020-10-31 18:51:30 +01:00
}
2020-07-05 14:16:57 +02:00
2017-10-16 08:47:05 +02:00
// On peut supprimer entite si
// - Droit de creer + mode brouillon (erreur creation)
// - Droit de supprimer
2021-02-23 21:24:38 +01:00
if (( $user -> rights -> contrat -> creer && $object -> statut == $object :: STATUS_DRAFT ) || $user -> rights -> contrat -> supprimer ) {
2022-03-10 15:56:10 +01:00
print dolGetButtonAction ( $langs -> trans ( 'Delete' ), '' , 'delete' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken (), '' , true , $params );
2020-05-21 15:05:19 +02:00
} else {
2022-03-10 15:56:10 +01:00
$params [ 'attr' ][ 'title' ] = $langs -> trans ( " NotAllowed " );
print dolGetButtonAction ( $langs -> trans ( 'Delete' ), '' , 'delete' , $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken (), '' , false , $params );
2017-10-16 08:47:05 +02:00
}
}
2016-12-10 12:23:02 +01:00
2017-10-16 08:47:05 +02:00
print " </div> " ;
}
2016-12-10 12:23:02 +01:00
2017-10-16 08:47:05 +02:00
// Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
2016-12-10 12:23:02 +01:00
2021-02-23 21:24:38 +01:00
if ( $action != 'presend' ) {
2017-10-16 08:47:05 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2016-12-10 12:23:02 +01:00
2017-10-16 08:47:05 +02:00
/*
2021-03-16 04:04:18 +01:00
* Generated documents
*/
2017-10-16 08:47:05 +02:00
$filename = dol_sanitizeFileName ( $object -> ref );
2021-02-10 12:39:14 +01:00
$filedir = $conf -> contrat -> multidir_output [ $object -> entity ] . " / " . dol_sanitizeFileName ( $object -> ref );
2019-11-13 19:35:39 +01:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
2017-10-18 19:51:29 +02:00
$genallowed = $user -> rights -> contrat -> lire ;
$delallowed = $user -> rights -> contrat -> creer ;
2018-04-24 14:46:16 +02:00
2016-12-10 12:23:02 +01:00
2021-02-15 21:46:07 +01:00
print $formfile -> showdocuments ( 'contract' , $filename , $filedir , $urlsource , $genallowed , $delallowed , ( $object -> model_pdf ? $object -> model_pdf : $conf -> global -> CONTRACT_ADDON_PDF ), 1 , 0 , 0 , 28 , 0 , '' , 0 , '' , $soc -> default_lang , '' , $object );
2016-12-10 12:23:02 +01:00
2017-10-16 08:47:05 +02:00
// Show links to link elements
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , array ( 'contrat' ));
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem );
2016-12-10 12:23:02 +01:00
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
2016-12-10 12:23:02 +01:00
2019-07-23 02:45:31 +02:00
$MAXEVENT = 10 ;
2022-05-18 23:11:59 +02:00
$morehtmlcenter = dolGetButtonTitle ( $langs -> trans ( 'SeeAll' ), '' , 'fa fa-bars imgforviewmode' , DOL_URL_ROOT . '/contrat/agenda.php?id=' . $object -> id );
2019-07-23 02:45:31 +02:00
2016-12-10 12:23:02 +01:00
// List of actions on element
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2016-12-10 12:23:02 +01:00
$formactions = new FormActions ( $db );
2020-05-07 22:52:32 +02:00
$somethingshown = $formactions -> showactions ( $object , 'contract' , $socid , 1 , 'listactions' , $MAXEVENT , '' , $morehtmlcenter );
2016-12-10 12:23:02 +01:00
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2016-12-10 12:23:02 +01:00
}
2017-09-22 17:48:38 +02:00
// Presend form
2019-11-13 19:35:39 +01:00
$modelmail = 'contract' ;
$defaulttopic = 'SendContractRef' ;
2021-02-10 12:44:36 +01:00
$diroutput = $conf -> contrat -> multidir_output [ $object -> entity ];
2017-09-22 17:48:38 +02:00
$trackid = 'con' . $object -> id ;
2016-12-10 12:23:02 +01:00
2017-09-22 17:48:38 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2017-10-16 08:47:05 +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
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> margin -> enabled ) && $action == 'editline' ) {
2019-07-23 02:45:31 +02:00
// TODO Why this ? To manage margin on contracts ?
2019-10-27 10:07:47 +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 ();
2020-11-16 14:36:23 +01:00
var token = '<?php echo currentToken(); ?>' ; // For AJAX Call we use old 'token' and not 'newtoken'
2013-02-13 10:35:47 +01:00
if ( idprod > 0 ) {
2019-07-23 02:45:31 +02:00
$ . post ( '<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php' , {
'idprod' : idprod ,
'token' : token
}, function ( data ) {
2021-02-23 21:24:38 +01:00
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 ();
}
2013-02-13 10:35:47 +01:00
},
'json' );
}
2021-02-23 21:24:38 +01:00
else {
$ ( " #fournprice " ) . hide ();
$ ( '#buying_price' ) . show ();
}
2013-02-13 10:35:47 +01:00
});
</ script >
2019-10-27 10:07:47 +01:00
< ? php
2013-11-17 23:25:25 +01:00
}