2004-10-19 22:35:36 +02:00
< ? php
2022-06-14 09:14:08 +02:00
/* Copyright ( C ) 2004 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2016 - 2018 Frédéric France < frederic . france @ netlogic . fr >
* Copyright ( C ) 2017 - 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
* Copyright ( C ) 2021 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2004-05-02 18:01:35 +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
2004-05-02 18:01:35 +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 />.
2004-05-02 18:01:35 +02:00
*/
2004-10-03 20:31:14 +02:00
2006-08-20 23:09:23 +02:00
/**
2016-08-22 13:43:49 +02:00
* \file htdocs / compta / sociales / card . php
2009-10-25 21:48:44 +01:00
* \ingroup tax
2015-07-15 19:54:51 +02:00
* \brief Social contribution card page
2009-10-25 21:48:44 +01:00
*/
2004-10-03 20:31:14 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2021-12-06 18:18:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formsocialcontrib.class.php' ;
2017-10-07 21:03:46 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
2020-12-14 10:44:51 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/paymentsocialcontribution.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/tax.lib.php' ;
2018-07-17 22:33:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-01-28 16:58:55 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'project' )) {
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2017-03-12 14:32:49 +01:00
}
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'accounting' )) {
2020-01-30 01:48:28 +01:00
include_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2017-10-07 21:03:46 +02:00
}
2004-05-02 18:01:35 +02:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2021-01-28 16:58:55 +01:00
$langs -> loadLangs ( array ( 'compta' , 'bills' , 'banks' , 'hrm' ));
2004-10-03 20:31:14 +02:00
2020-01-30 01:48:28 +01:00
$id = GETPOST ( 'id' , 'int' );
2021-12-06 18:18:31 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
2020-01-30 01:48:28 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-12-06 18:18:31 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'aZ09' );
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'myobjectcard' ; // To manage different context of search
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
$backtopageforcancel = GETPOST ( 'backtopageforcancel' , 'alpha' );
2022-06-14 09:14:08 +02:00
$lineid = GETPOST ( 'lineid' , 'int' );
2021-12-06 18:18:31 +01:00
2021-03-10 14:15:03 +01:00
$fk_project = ( GETPOST ( 'fk_project' ) ? GETPOST ( 'fk_project' , 'int' ) : 0 );
2004-05-02 18:01:35 +02:00
2020-02-11 14:13:08 +01:00
$dateech = dol_mktime ( GETPOST ( 'echhour' ), GETPOST ( 'echmin' ), GETPOST ( 'echsec' ), GETPOST ( 'echmonth' ), GETPOST ( 'echday' ), GETPOST ( 'echyear' ));
$dateperiod = dol_mktime ( GETPOST ( 'periodhour' ), GETPOST ( 'periodmin' ), GETPOST ( 'periodsec' ), GETPOST ( 'periodmonth' ), GETPOST ( 'periodday' ), GETPOST ( 'periodyear' ));
2020-02-11 14:15:23 +01:00
$label = GETPOST ( 'label' , 'alpha' );
2020-02-11 14:13:08 +01:00
$actioncode = GETPOST ( 'actioncode' );
2021-01-28 16:58:55 +01:00
$fk_user = GETPOST ( 'userid' , 'int' );
2020-02-11 14:13:08 +01:00
2022-01-24 16:06:02 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2022-01-25 14:03:29 +01:00
$hookmanager -> initHooks ( array ( 'taxcard' , 'globalcard' ));
2022-01-24 16:06:02 +01:00
2021-12-06 18:18:31 +01:00
// Initialize technical objects
2021-04-03 02:11:16 +02:00
$object = new ChargeSociales ( $db );
2021-12-06 18:18:31 +01:00
$extrafields = new ExtraFields ( $db );
$diroutputmassaction = $conf -> tax -> dir_output . '/temp/massgeneration/' . $user -> id ;
$hookmanager -> initHooks ( array ( 'taxsocialcontributioncard' , 'globalcard' ));
if ( empty ( $action ) && empty ( $id ) && empty ( $ref )) {
$action = 'view' ;
}
// Load object
2021-04-03 02:11:16 +02:00
if ( $id > 0 ) {
$object -> fetch ( $id );
}
2021-12-06 18:18:31 +01:00
$permissiontoread = $user -> rights -> tax -> charges -> lire ;
$permissiontoadd = $user -> rights -> tax -> charges -> creer ; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$permissiontodelete = $user -> rights -> tax -> charges -> supprimer || ( $permissiontoadd && isset ( $object -> status ) && $object -> status == $object :: STATUS_DRAFT );
$permissionnote = $user -> rights -> tax -> charges -> creer ; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user -> rights -> tax -> charges -> creer ; // Used by the include of actions_dellink.inc.php
$upload_dir = $conf -> tax -> multidir_output [ isset ( $object -> entity ) ? $object -> entity : 1 ];
2008-10-13 16:22:10 +02:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-04-03 02:11:16 +02:00
$result = restrictedArea ( $user , 'tax' , $object -> id , 'chargesociales' , 'charges' );
2008-10-13 16:22:10 +02:00
2004-05-02 18:01:35 +02:00
2021-04-03 02:11:16 +02:00
/*
* Actions
*/
2007-01-30 20:58:19 +01:00
2022-01-24 16:06:02 +01:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-03-26 15:41:09 +01:00
// Classify paid
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_paid' && $user -> rights -> tax -> charges -> creer && $confirm == 'yes' ) {
2016-04-22 17:11:12 +02:00
$object -> fetch ( $id );
2021-02-09 10:26:17 +01:00
$result = $object -> setPaid ( $user );
2016-04-22 17:11:12 +02:00
}
if ( $action == 'reopen' && $user -> rights -> tax -> charges -> creer ) {
2017-10-07 13:09:31 +02:00
$result = $object -> fetch ( $id );
2021-02-23 21:09:01 +01:00
if ( $object -> paye ) {
2021-02-09 10:26:17 +01:00
$result = $object -> setUnpaid ( $user );
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2019-11-08 15:51:54 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id );
2017-10-07 13:09:31 +02:00
exit ();
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2004-06-08 17:09:49 +02:00
}
2006-08-20 23:09:23 +02:00
2017-05-21 02:43:51 +02:00
// Link to a project
2021-02-23 21:09:01 +01:00
if ( $action == 'classin' && $user -> rights -> tax -> charges -> creer ) {
2017-10-07 13:09:31 +02:00
$object -> fetch ( $id );
2021-03-10 14:15:03 +01:00
$object -> setProject ( GETPOST ( 'fk_project' ));
2017-05-21 02:43:51 +02:00
}
2021-01-28 17:27:55 +01:00
if ( $action == 'setfk_user' && $user -> rights -> tax -> charges -> creer ) {
2021-01-28 16:58:55 +01:00
$object -> fetch ( $id );
$object -> fk_user = $fk_user ;
$object -> update ( $user );
}
2021-02-23 21:09:01 +01:00
if ( $action == 'setlib' && $user -> rights -> tax -> charges -> creer ) {
2017-10-07 13:09:31 +02:00
$object -> fetch ( $id );
$result = $object -> setValueFrom ( 'libelle' , GETPOST ( 'lib' ), '' , '' , 'text' , '' , $user , 'TAX_MODIFY' );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-02-23 21:09:01 +01:00
}
2016-11-28 23:58:36 +01:00
}
2016-06-19 18:53:19 +02:00
// payment mode
if ( $action == 'setmode' && $user -> rights -> tax -> charges -> creer ) {
2017-10-07 13:09:31 +02:00
$object -> fetch ( $id );
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-02-23 21:09:01 +01:00
}
2016-06-19 18:53:19 +02:00
}
2021-12-06 18:18:31 +01:00
// Bank account
2016-06-19 18:53:19 +02:00
if ( $action == 'setbankaccount' && $user -> rights -> tax -> charges -> creer ) {
2017-10-07 13:09:31 +02:00
$object -> fetch ( $id );
2019-11-08 15:51:54 +01:00
$result = $object -> setBankAccount ( GETPOST ( 'fk_account' , 'int' ));
2017-10-07 13:09:31 +02:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2016-06-19 18:53:19 +02:00
}
2014-03-26 15:41:09 +01:00
// Delete social contribution
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' ) {
2016-04-22 17:11:12 +02:00
$object -> fetch ( $id );
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
if ( empty ( $totalpaid )) {
2021-04-26 10:48:50 +02:00
$result = $object -> delete ( $user );
if ( $result > 0 ) {
header ( " Location: list.php " );
exit ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-21 15:05:19 +02:00
} else {
2021-04-26 10:48:50 +02:00
setEventMessages ( $langs -> trans ( 'DisabledBecausePayments' ), null , 'errors' );
2007-01-30 01:30:48 +01:00
}
}
2004-06-08 17:09:49 +02:00
2009-03-03 00:43:17 +01:00
2014-03-26 15:41:09 +01:00
// Add social contribution
2021-02-23 21:09:01 +01:00
if ( $action == 'add' && $user -> rights -> tax -> charges -> creer ) {
2021-12-06 18:18:31 +01:00
$amount = price2num ( GETPOST ( 'amount' , 'alpha' ), 'MT' );
2017-03-12 14:32:49 +01:00
2021-02-23 21:09:01 +01:00
if ( ! $dateech ) {
2020-01-23 19:37:34 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Date " )), null , 'errors' );
2011-12-21 21:14:10 +01:00
$action = 'create' ;
2021-02-23 21:09:01 +01:00
} elseif ( ! $dateperiod ) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Period " )), null , 'errors' );
2011-12-21 21:14:10 +01:00
$action = 'create' ;
2022-08-12 15:54:50 +02:00
} elseif ( ! ( $actioncode > 0 )) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Type " )), null , 'errors' );
2011-12-21 21:14:10 +01:00
$action = 'create' ;
2021-02-23 21:09:01 +01:00
} elseif ( empty ( $amount )) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
2011-12-21 21:14:10 +01:00
$action = 'create' ;
2020-11-03 21:02:57 +01:00
} elseif ( ! is_numeric ( $amount )) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldMustBeANumeric " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
2015-04-19 23:15:24 +02:00
$action = 'create' ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$object -> type = $actioncode ;
$object -> label = GETPOST ( 'label' , 'alpha' );
$object -> date_ech = $dateech ;
2020-11-03 21:02:57 +01:00
$object -> periode = $dateperiod ;
$object -> amount = $amount ;
2021-01-28 16:58:55 +01:00
$object -> fk_user = $fk_user ;
2020-11-03 21:02:57 +01:00
$object -> mode_reglement_id = ( int ) GETPOST ( 'mode_reglement_id' , 'int' );
$object -> fk_account = ( int ) GETPOST ( 'fk_account' , 'int' );
$object -> fk_project = ( int ) GETPOST ( 'fk_project' , 'int' );
2009-03-03 00:43:17 +01:00
2020-01-30 01:48:28 +01:00
$id = $object -> create ( $user );
2020-11-03 21:02:57 +01:00
if ( $id <= 0 ) {
2016-04-22 17:11:12 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-01-30 01:48:28 +01:00
$action = 'create' ;
2007-06-25 02:02:37 +02:00
}
}
}
2004-06-08 17:09:49 +02:00
2007-01-30 01:30:48 +01:00
2021-03-24 19:06:44 +01:00
if ( $action == 'update' && ! GETPOST ( " cancel " ) && $user -> rights -> tax -> charges -> creer ) {
2021-12-06 18:18:31 +01:00
$amount = price2num ( GETPOST ( 'amount' , 'alpha' ), 'MT' );
2017-10-07 13:09:31 +02:00
2021-02-23 21:09:01 +01:00
if ( ! $dateech ) {
2021-01-07 06:26:24 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Date " )), null , 'errors' );
2017-10-07 13:09:31 +02:00
$action = 'edit' ;
2021-02-23 21:09:01 +01:00
} elseif ( ! $dateperiod ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Period " )), null , 'errors' );
$action = 'edit' ;
2021-02-23 21:09:01 +01:00
} elseif ( empty ( $amount )) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
$action = 'edit' ;
2021-02-23 21:09:01 +01:00
} elseif ( ! is_numeric ( $amount )) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldMustBeANumeric " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
2015-10-18 21:17:19 +02:00
$action = 'create' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$result = $object -> fetch ( $id );
2015-03-10 14:43:13 +01:00
2019-11-08 15:51:54 +01:00
$object -> date_ech = $dateech ;
2020-11-03 21:02:57 +01:00
$object -> periode = $dateperiod ;
$object -> amount = $amount ;
2021-01-28 16:58:55 +01:00
$object -> fk_user = $fk_user ;
2015-03-10 14:43:13 +01:00
2019-11-08 15:51:54 +01:00
$result = $object -> update ( $user );
2020-11-03 21:02:57 +01:00
if ( $result <= 0 ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2007-06-25 02:02:37 +02:00
}
}
2009-03-03 00:43:17 +01:00
2015-04-19 23:15:24 +02:00
// Action clone object
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_clone' && $confirm != 'yes' ) {
$action = '' ;
}
2015-04-19 23:15:24 +02:00
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_clone' && $confirm == 'yes' && ( $user -> rights -> tax -> charges -> creer )) {
2014-10-04 17:20:17 +02:00
$db -> begin ();
$originalId = $id ;
$object -> fetch ( $id );
2021-02-23 21:09:01 +01:00
if ( $object -> id > 0 ) {
2014-10-04 17:20:17 +02:00
$object -> id = $object -> ref = null ;
2021-11-15 19:40:26 +01:00
$object -> paye = 0 ;
if ( GETPOST ( 'amount' , 'alphanohtml' )) {
$object -> amount = price2num ( GETPOST ( 'amount' , 'alphanohtml' ), 'MT' , 2 );
}
2014-10-04 17:20:17 +02:00
2019-10-31 14:06:26 +01:00
if ( GETPOST ( 'clone_label' , 'alphanohtml' )) {
$object -> label = GETPOST ( 'clone_label' , 'alphanohtml' );
2020-05-21 15:05:19 +02:00
} else {
2019-10-31 14:06:26 +01:00
$object -> label = $langs -> trans ( " CopyOf " ) . ' ' . $object -> label ;
}
2021-04-09 00:36:08 +02:00
if ( GETPOST ( 'clone_for_next_month' , 'int' )) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
2018-07-17 22:31:28 +02:00
$object -> periode = dol_time_plus_duree ( $object -> periode , 1 , 'm' );
2019-10-31 14:06:26 +01:00
$object -> date_ech = dol_time_plus_duree ( $object -> date_ech , 1 , 'm' );
2020-05-21 15:05:19 +02:00
} else {
2021-11-15 19:40:26 +01:00
// Note date_ech is often a little bit higher than dateperiod
2019-10-31 14:06:26 +01:00
$newdateperiod = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'clone_periodmonth' , 'int' ), GETPOST ( 'clone_periodday' , 'int' ), GETPOST ( 'clone_periodyear' , 'int' ));
$newdateech = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'clone_date_echmonth' , 'int' ), GETPOST ( 'clone_date_echday' , 'int' ), GETPOST ( 'clone_date_echyear' , 'int' ));
2021-02-23 21:09:01 +01:00
if ( $newdateperiod ) {
$object -> periode = $newdateperiod ;
2021-04-09 00:36:08 +02:00
if ( empty ( $newdateech )) {
$object -> date_ech = $object -> periode ;
}
2021-02-23 21:09:01 +01:00
}
if ( $newdateech ) {
$object -> date_ech = $newdateech ;
2021-04-09 00:36:08 +02:00
if ( empty ( $newdateperiod )) {
// TODO We can here get dol_get_last_day of previous month:
// $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
$object -> periode = $object -> date_ech ;
}
2021-02-23 21:09:01 +01:00
}
2014-10-04 17:20:17 +02:00
}
2021-11-15 19:40:26 +01:00
$resultcheck = $object -> check ();
if ( $resultcheck ) {
2014-10-04 17:20:17 +02:00
$id = $object -> create ( $user );
2021-02-23 21:09:01 +01:00
if ( $id > 0 ) {
2014-10-04 17:20:17 +02:00
$db -> commit ();
$db -> close ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$id = $originalId ;
2014-10-04 17:20:17 +02:00
$db -> rollback ();
2019-01-27 11:55:16 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-10-04 17:20:17 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2014-10-04 17:20:17 +02:00
$db -> rollback ();
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error );
2014-10-04 17:20:17 +02:00
}
2014-09-23 16:52:15 +02:00
}
2009-05-09 21:45:18 +02:00
/*
* View
*/
2012-02-20 10:09:28 +01:00
$form = new Form ( $db );
2021-12-06 18:18:31 +01:00
$formfile = new FormFile ( $db );
2012-02-20 10:09:28 +01:00
$formsocialcontrib = new FormSocialContrib ( $db );
2017-10-07 21:03:46 +02:00
$bankaccountstatic = new Account ( $db );
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'project' )) {
2021-02-23 21:09:01 +01:00
$formproject = new FormProjets ( $db );
}
2012-02-20 10:09:28 +01:00
2019-11-08 15:51:54 +01:00
$title = $langs -> trans ( " SocialContribution " ) . ' - ' . $langs -> trans ( " Card " );
$help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)' ;
2019-01-27 11:55:16 +01:00
llxHeader ( " " , $title , $help_url );
2007-01-30 01:30:48 +01:00
2007-07-31 02:23:30 +02:00
2021-12-06 18:18:31 +01:00
// Form to create a social contribution
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " NewSocialContribution " ));
2009-03-03 00:43:17 +01:00
2017-10-07 13:09:31 +02:00
print '<form name="charge" method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-07 13:09:31 +02:00
print '<input type="hidden" name="action" value="add">' ;
2007-06-25 02:02:37 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2007-06-25 02:02:37 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2016-11-28 21:27:02 +01:00
2017-10-07 13:09:31 +02:00
// Label
print " <tr> " ;
print '<td class="titlefieldcreate fieldrequired">' ;
print $langs -> trans ( " Label " );
print '</td>' ;
2020-12-14 11:28:18 +01:00
print '<td><input type="text" name="label" class="flat minwidth300" value="' . dol_escape_htmltag ( GETPOST ( 'label' , 'alpha' )) . '" autofocus></td>' ;
2017-10-07 13:09:31 +02:00
print '</tr>' ;
print '<tr>' ;
// Type
print '<td class="fieldrequired">' ;
print $langs -> trans ( " Type " );
print '</td>' ;
print '<td>' ;
2019-11-08 15:51:54 +01:00
$formsocialcontrib -> select_type_socialcontrib ( GETPOST ( " actioncode " , 'alpha' ) ? GETPOST ( " actioncode " , 'alpha' ) : '' , 'actioncode' , 1 );
2017-10-07 13:09:31 +02:00
print '</td>' ;
print '</tr>' ;
2016-11-28 21:27:02 +01:00
2020-01-23 19:28:56 +01:00
// Date
2017-10-07 13:09:31 +02:00
print '<tr>' ;
print '<td class="fieldrequired">' ;
2020-01-23 19:28:56 +01:00
print $langs -> trans ( " Date " );
2017-10-07 13:09:31 +02:00
print '</td>' ;
2020-01-23 19:28:56 +01:00
print '<td>' ;
2021-03-08 15:47:02 +01:00
print $form -> selectDate ( ! empty ( $dateech ) ? $dateech : '-1' , 'ech' , 0 , 0 , 0 , 'charge' , 1 , 1 );
2009-05-09 21:45:18 +02:00
print '</td>' ;
2020-01-23 19:28:56 +01:00
print " </tr> \n " ;
2016-11-28 21:27:02 +01:00
2020-01-23 19:28:56 +01:00
// Date end period
2018-04-28 17:18:38 +02:00
print '<tr>' ;
print '<td class="fieldrequired">' ;
2020-01-23 19:28:56 +01:00
print $form -> textwithpicto ( $langs -> trans ( " PeriodEndDate " ), $langs -> trans ( " LastDayTaxIsRelatedTo " ));
2018-04-28 17:18:38 +02:00
print '</td>' ;
print '<td>' ;
2020-01-23 19:28:56 +01:00
print $form -> selectDate ( ! empty ( $dateperiod ) ? $dateperiod : '-1' , 'period' , 0 , 0 , 0 , 'charge' , 1 );
2018-04-28 17:18:38 +02:00
print '</td>' ;
2020-01-23 19:28:56 +01:00
print '</tr>' ;
2018-04-28 17:18:38 +02:00
2017-10-07 13:09:31 +02:00
// Amount
print '<tr>' ;
print '<td class="fieldrequired">' ;
print $langs -> trans ( " Amount " );
print '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input type="text" size="6" name="amount" class="flat" value="' . dol_escape_htmltag ( GETPOST ( 'amount' , 'alpha' )) . '"></td>' ;
2017-10-07 13:09:31 +02:00
print '</tr>' ;
2016-11-28 21:27:02 +01:00
2021-01-28 16:58:55 +01:00
// Employee
print '<tr><td>' ;
print $langs -> trans ( 'Employee' );
print '</td>' ;
2021-02-16 17:05:38 +01:00
print '<td>' . img_picto ( '' , 'user' , 'class="pictofixedwidth"' ) . $form -> select_dolusers ( $fk_user , 'userid' , 1 ) . '</td></tr>' ;
2021-01-28 16:58:55 +01:00
2017-03-12 14:32:49 +01:00
// Project
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'project' )) {
2019-11-08 15:51:54 +01:00
$formproject = new FormProjets ( $db );
2017-03-12 14:32:49 +01:00
// Associated project
$langs -> load ( " projects " );
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2021-03-16 14:57:04 +01:00
print img_picto ( '' , 'project' , 'class="pictofixedwidth"' ) . $formproject -> select_projects ( - 1 , $fk_project , 'fk_project' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 1 );
2017-06-09 09:25:15 +02:00
2017-03-12 14:32:49 +01:00
print '</td></tr>' ;
}
2017-10-07 13:09:31 +02:00
// Payment Mode
2021-03-31 16:57:58 +02:00
print '<tr><td>' . $langs -> trans ( 'DefaultPaymentMode' ) . '</td><td colspan="2">' ;
2021-03-10 14:15:03 +01:00
$form -> select_types_paiements ( GETPOST ( 'mode_reglement_id' , 'int' ), 'mode_reglement_id' );
2017-10-07 13:09:31 +02:00
print '</td></tr>' ;
// Bank Account
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'banque' )) {
2021-03-31 16:57:58 +02:00
print '<tr><td>' . $langs -> trans ( 'DefaultBankAccount' ) . '</td><td colspan="2">' ;
2021-03-16 14:57:04 +01:00
print img_picto ( '' , 'bank_account' , 'class="pictofixedwidth"' ) . $form -> select_comptes ( GETPOST ( 'fk_account' , 'int' ), 'fk_account' , 0 , '' , 2 , '' , 0 , '' , 1 );
2017-10-07 13:09:31 +02:00
print '</td></tr>' ;
}
print '</table>' ;
2007-06-25 02:02:37 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-04-19 23:15:24 +02:00
print '<div class="center">' ;
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button button-add" value="' . $langs -> trans ( " Add " ) . '">' ;
2016-11-28 21:27:02 +01:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="button" class="button button-cancel" value="' . $langs -> trans ( " Cancel " ) . '" onClick="javascript:history.go(-1)">' ;
2016-11-28 21:27:02 +01:00
print '</div>' ;
2015-04-19 23:15:24 +02:00
2017-10-07 13:09:31 +02:00
print '</form>' ;
2007-06-25 02:02:37 +02:00
}
2021-12-06 18:18:31 +01:00
// View mode
2021-02-23 21:09:01 +01:00
if ( $id > 0 ) {
2012-02-11 20:30:16 +01:00
$object = new ChargeSociales ( $db );
2019-11-08 15:51:54 +01:00
$result = $object -> fetch ( $id );
2006-08-20 23:09:23 +02:00
2022-01-24 16:06:02 +01:00
$formconfirm = '' ;
2022-01-24 16:13:40 +01:00
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2019-11-08 15:51:54 +01:00
$head = tax_prepare_head ( $object );
2006-08-20 23:09:23 +02:00
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
2017-06-09 09:25:15 +02:00
2014-09-23 16:52:15 +02:00
// Clone confirmation
2021-02-23 21:09:01 +01:00
if ( $action === 'clone' ) {
2019-11-08 15:51:54 +01:00
$formquestion = array (
2021-04-09 00:36:08 +02:00
array ( 'type' => 'text' , 'name' => 'clone_label' , 'label' => $langs -> trans ( " Label " ), 'value' => $langs -> trans ( " CopyOf " ) . ' ' . $object -> label , 'tdclass' => 'fieldrequired' ),
2014-09-23 16:52:15 +02:00
);
2021-04-09 00:36:08 +02:00
if ( ! empty ( $conf -> global -> TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX )) {
2019-11-08 15:51:54 +01:00
$formquestion [] = array ( 'type' => 'checkbox' , 'name' => 'clone_for_next_month' , 'label' => $langs -> trans ( " CloneTaxForNextMonth " ), 'value' => 1 );
2020-05-21 15:05:19 +02:00
} else {
2021-09-02 19:15:21 +02:00
$formquestion [] = array ( 'type' => 'date' , 'datenow' => 1 , 'name' => 'clone_date_ech' , 'label' => $langs -> trans ( " Date " ), 'value' => - 1 );
2019-11-08 15:51:54 +01:00
$formquestion [] = array ( 'type' => 'date' , 'name' => 'clone_period' , 'label' => $langs -> trans ( " PeriodEndDate " ), 'value' => - 1 );
2021-11-15 19:40:26 +01:00
$formquestion [] = array ( 'type' => 'text' , 'name' => 'amount' , 'label' => $langs -> trans ( " Amount " ), 'value' => price ( $object -> amount ), 'morecss' => 'width100' );
2019-10-31 14:06:26 +01:00
}
2014-10-04 17:20:17 +02:00
2022-01-25 14:45:51 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneTax' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 , 280 );
2014-09-23 16:52:15 +02:00
}
2014-10-04 17:20:17 +02:00
2019-11-04 15:09:43 +01:00
2021-02-23 21:09:01 +01:00
if ( $action == 'paid' ) {
2020-01-30 01:48:28 +01:00
$text = $langs -> trans ( 'ConfirmPaySocialContribution' );
2022-01-24 16:06:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( 'PaySocialContribution' ), $text , " confirm_paid " , '' , '' , 2 );
2006-08-20 23:09:23 +02:00
}
2019-11-04 15:09:43 +01:00
2019-11-04 15:08:43 +01:00
// Confirmation of the removal of the Social Contribution
2021-02-23 21:09:01 +01:00
if ( $action == 'delete' ) {
2020-01-30 01:48:28 +01:00
$text = $langs -> trans ( 'ConfirmDeleteSocialContribution' );
2022-01-24 16:06:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteSocialContribution' ), $text , 'confirm_delete' , '' , '' , 2 );
2007-01-30 20:58:19 +01:00
}
2021-02-23 21:09:01 +01:00
if ( $action == 'edit' ) {
2016-08-22 13:43:49 +02:00
print " <form name= \" charge \" action= \" " . $_SERVER [ " PHP_SELF " ] . " ?id= $object->id &action=update \" method= \" post \" > " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-05-16 14:52:53 +02:00
}
2022-01-24 16:06:02 +01:00
// Call Hook formConfirm
$parameters = array ( 'formConfirm' => $formconfirm , 'lineid' => $lineid );
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
// Print form confirm
print $formconfirm ;
2006-08-20 23:09:23 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " SocialContribution " ), - 1 , 'bill' );
2006-08-20 23:09:23 +02:00
2020-01-30 01:48:28 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-11-28 23:58:36 +01:00
// Ref customer
2020-01-30 01:48:28 +01:00
$morehtmlref .= $form -> editfieldkey ( " Label " , 'lib' , $object -> label , $object , $user -> rights -> tax -> charges -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " Label " , 'lib' , $object -> label , $object , $user -> rights -> tax -> charges -> creer , 'string' , '' , null , null , '' , 1 );
2021-01-28 16:58:55 +01:00
// Employee
2021-01-28 17:27:55 +01:00
if ( $action != 'editfk_user' ) {
2021-03-10 15:12:29 +01:00
if ( $object -> getSommePaiement () > 0 && ! empty ( $object -> fk_user )) {
2021-01-28 16:58:55 +01:00
$userstatic = new User ( $db );
2021-03-10 14:39:04 +01:00
$result = $userstatic -> fetch ( $object -> fk_user );
2021-03-10 15:12:29 +01:00
if ( $result > 0 ) {
2021-03-10 14:39:04 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Employee' ) . ' : ' . $userstatic -> getNomUrl ( 1 );
}
} else {
2021-03-10 15:34:43 +01:00
$morehtmlref .= '<br>' . $form -> editfieldkey ( " Employee " , 'fk_user' , $object -> label , $object , $user -> rights -> salaries -> write , 'string' , '' , 0 , 1 );
2021-03-10 15:12:29 +01:00
if ( ! empty ( $object -> fk_user )) {
2021-03-10 14:39:04 +01:00
$userstatic = new User ( $db );
$result = $userstatic -> fetch ( $object -> fk_user );
2021-03-10 15:12:29 +01:00
if ( $result > 0 ) {
2021-03-10 14:39:04 +01:00
$morehtmlref .= $userstatic -> getNomUrl ( 1 );
} else {
dol_print_error ( $db );
exit ();
}
}
2021-01-28 16:58:55 +01:00
}
} else {
$morehtmlref .= '<br>' . $langs -> trans ( 'Employee' ) . ' : ' ;
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="setfk_user">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $form -> select_dolusers ( $object -> fk_user , 'userid' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
}
2017-05-21 02:43:51 +02:00
// Project
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'project' )) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " projects " );
2020-01-30 01:48:28 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-23 21:09:01 +01:00
if ( $user -> rights -> tax -> charges -> creer ) {
2019-10-26 18:13:20 +02: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-26 18:13:20 +02:00
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
2020-01-30 01:48:28 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2022-06-03 15:25:38 +02:00
$morehtmlref .= $formproject -> select_projects ( 0 , $object -> fk_project , 'fk_project' , 0 , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
2020-01-30 01:48:28 +01:00
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2019-10-26 18:13:20 +02:00
} else {
2022-06-03 15:25:38 +02:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , 0 , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-26 18:13:20 +02:00
}
2017-10-07 13:09:31 +02:00
} else {
2020-01-30 01:48:28 +01:00
if ( ! empty ( $object -> fk_project )) {
2017-10-07 13:09:31 +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-07 13:09:31 +02:00
} else {
2020-01-30 01:48:28 +01:00
$morehtmlref .= '' ;
2017-10-07 13:09:31 +02:00
}
}
2017-06-09 09:25:15 +02:00
}
2020-01-30 01:48:28 +01:00
$morehtmlref .= '</div>' ;
2017-06-09 09:25:15 +02:00
2020-07-09 23:18:19 +02:00
$morehtmlright = '' ;
2020-01-30 01:48:28 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/sociales/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-09 09:25:15 +02:00
2022-05-22 17:09:08 +02:00
$object -> totalpaid = $totalpaid ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2017-06-09 09:25:15 +02:00
2016-11-28 23:58:36 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref , '' , 0 , '' , $morehtmlright );
2017-06-09 09:25:15 +02:00
2016-11-29 06:34:20 +01:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-09 09:25:15 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2017-06-09 09:25:15 +02:00
2009-05-09 21:45:18 +02:00
// Type
2020-01-23 19:28:56 +01:00
print '<tr><td class="titlefield">' ;
print $langs -> trans ( " Type " ) . " </td><td> " . $object -> type_label . " </td> " ;
2006-08-20 23:09:23 +02:00
print " </tr> " ;
2009-03-03 00:43:17 +01:00
2020-01-23 19:28:56 +01:00
// Date
2021-02-23 21:09:01 +01:00
if ( $action == 'edit' ) {
2020-01-23 19:37:34 +01:00
print '<tr><td>' . $langs -> trans ( " Date " ) . " </td><td> " ;
2021-09-02 19:15:21 +02:00
print $form -> selectDate ( $object -> date_ech , 'ech' , 0 , 0 , 0 , 'charge' , 1 , 1 );
2020-01-23 19:28:56 +01:00
print " </td></tr> " ;
} else {
2020-01-23 19:37:34 +01:00
print " <tr><td> " . $langs -> trans ( " Date " ) . " </td><td> " . dol_print_date ( $object -> date_ech , 'day' ) . " </td></tr> " ;
2020-01-23 19:28:56 +01:00
}
2017-10-07 13:09:31 +02:00
// Period end date
2018-04-28 17:18:38 +02:00
print " <tr><td> " . $form -> textwithpicto ( $langs -> trans ( " PeriodEndDate " ), $langs -> trans ( " LastDayTaxIsRelatedTo " )) . " </td> " ;
2013-11-03 15:07:26 +01:00
print " <td> " ;
2021-02-23 21:09:01 +01:00
if ( $action == 'edit' ) {
2018-09-09 09:36:12 +02:00
print $form -> selectDate ( $object -> periode , 'period' , 0 , 0 , 0 , 'charge' , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> periode , " day " );
2013-11-03 15:07:26 +01:00
}
print " </td></tr> " ;
2014-05-06 22:54:33 +02:00
2010-07-27 01:00:39 +02:00
// Amount
2021-02-23 21:09:01 +01:00
if ( $action == 'edit' ) {
2017-10-07 13:09:31 +02:00
print '<tr><td>' . $langs -> trans ( " AmountTTC " ) . " </td><td> " ;
2021-03-08 16:30:32 +01:00
print '<input type="text" name="amount" size="12" class="flat" value="' . price ( $object -> amount ) . '">' ;
2017-10-07 13:09:31 +02:00
print " </td></tr> " ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 22:14:24 +01:00
print '<tr><td>' . $langs -> trans ( " AmountTTC " ) . '</td><td><span class="amount">' . price ( $object -> amount , 0 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</span></td></tr>' ;
2017-10-07 13:09:31 +02:00
}
// Mode of payment
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
2021-03-31 16:57:58 +02:00
print $langs -> trans ( 'DefaultPaymentMode' );
2017-10-07 13:09:31 +02:00
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $action != 'editmode' ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2017-10-07 13:09:31 +02:00
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editmode' ) {
2019-11-08 15:51:54 +01:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'mode_reglement_id' );
2017-10-07 13:09:31 +02:00
} else {
2019-11-08 15:51:54 +01:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'none' );
2017-10-07 13:09:31 +02:00
}
print '</td></tr>' ;
2021-12-06 18:18:31 +01:00
// Bank account
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'banque' )) {
2017-10-07 13:09:31 +02:00
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
2021-03-31 16:57:58 +02:00
print $langs -> trans ( 'DefaultBankAccount' );
2017-10-07 13:09:31 +02:00
print '<td>' ;
2021-02-23 21:09:01 +01:00
if ( $action != 'editbankaccount' && $user -> rights -> tax -> charges -> creer ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editbankaccount&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetBankAccount' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2017-10-07 13:09:31 +02:00
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editbankaccount' ) {
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'fk_account' , 1 );
} else {
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'none' );
}
print '</td>' ;
print '</tr>' ;
}
2016-06-19 18:53:19 +02:00
2021-12-06 18:18:31 +01:00
// Other attributes
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2011-12-21 21:14:10 +01:00
print '</table>' ;
2016-11-29 06:34:20 +01:00
print '</div>' ;
print '<div class="fichehalfright">' ;
2017-10-07 21:03:46 +02:00
$nbcols = 3 ;
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'banque' )) {
2019-11-08 15:51:54 +01:00
$nbcols ++ ;
2017-10-07 21:03:46 +02:00
}
2016-11-29 06:34:20 +01:00
/*
* Payments
*/
2021-12-06 18:18:31 +01:00
$sql = " SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount, " ;
2019-11-08 15:51:54 +01:00
$sql .= " c.code as type_code,c.libelle as paiement_type, " ;
2020-01-17 14:32:22 +01:00
$sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal' ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " paiementcharge as p " ;
2020-10-31 14:32:18 +01:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid' ;
2019-11-08 15:51:54 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON p.fk_typepaiement = c.id " ;
$sql .= " , " . MAIN_DB_PREFIX . " chargesociales as cs " ;
2021-03-30 17:53:25 +02:00
$sql .= " WHERE p.fk_charge = " . (( int ) $id );
2019-11-08 15:51:54 +01:00
$sql .= " AND p.fk_charge = cs.rowid " ;
2021-12-06 18:18:31 +01:00
$sql .= " AND cs.entity IN ( " . getEntity ( 'sc' ) . " ) " ;
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY dp DESC " ;
2016-11-29 06:34:20 +01:00
//print $sql;
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2022-05-22 17:09:08 +02:00
$totalpaid = 0 ;
2017-10-07 13:09:31 +02:00
$num = $db -> num_rows ( $resql );
2021-03-01 20:37:16 +01:00
$i = 0 ;
$total = 0 ;
2019-05-29 12:56:11 +02:00
2019-11-08 15:51:54 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2017-10-07 13:09:31 +02:00
print '<table class="noborder paymenttable">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " RefPayment " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Date " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'banque' )) {
2020-10-31 14:32:18 +01:00
print '<td class="liste_titre right">' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
}
2019-02-12 14:53:35 +01:00
print '<td class="right">' . $langs -> trans ( " Amount " ) . '</td>' ;
2017-10-07 13:09:31 +02:00
print '</tr>' ;
2020-12-14 10:44:51 +01:00
$paymentsocialcontributiontmp = new PaymentSocialContribution ( $db );
2021-02-23 21:09:01 +01:00
if ( $num > 0 ) {
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$objp = $db -> fetch_object ( $resql );
2020-12-14 10:44:51 +01:00
$paymentsocialcontributiontmp -> id = $objp -> rowid ;
$paymentsocialcontributiontmp -> ref = $objp -> rowid ;
$paymentsocialcontributiontmp -> datep = $db -> jdate ( $objp -> dp );
2017-10-07 21:03:46 +02:00
print '<tr class="oddeven"><td>' ;
2020-12-14 10:44:51 +01:00
print $paymentsocialcontributiontmp -> getNomUrl ( 1 );
print '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . " </td> \n " ;
2019-11-08 15:51:54 +01:00
$labeltype = $langs -> trans ( " PaymentType " . $objp -> type_code ) != ( " PaymentType " . $objp -> type_code ) ? $langs -> trans ( " PaymentType " . $objp -> type_code ) : $objp -> paiement_type ;
2020-03-16 19:23:18 +01:00
print " <td> " . $labeltype . ' ' . $objp -> num_payment . " </td> \n " ;
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'banque' )) {
2017-10-07 21:03:46 +02:00
$bankaccountstatic -> id = $objp -> baid ;
$bankaccountstatic -> ref = $objp -> baref ;
$bankaccountstatic -> label = $objp -> baref ;
$bankaccountstatic -> number = $objp -> banumber ;
2020-01-17 14:32:22 +01:00
$bankaccountstatic -> currency_code = $objp -> bacurrency_code ;
2017-10-07 21:03:46 +02:00
2022-08-29 11:26:40 +02:00
if ( isModEnabled ( 'accounting' )) {
2017-10-07 21:03:46 +02:00
$bankaccountstatic -> account_number = $objp -> account_number ;
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $objp -> fk_accountancy_journal );
2019-01-27 11:55:16 +01:00
$bankaccountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-10-07 21:03:46 +02:00
}
2019-02-12 14:53:35 +01:00
print '<td class="right">' ;
2021-02-23 21:09:01 +01:00
if ( $bankaccountstatic -> id ) {
2017-10-07 21:03:46 +02:00
print $bankaccountstatic -> getNomUrl ( 1 , 'transactions' );
2021-02-23 21:09:01 +01:00
}
2017-10-07 21:03:46 +02:00
print '</td>' ;
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $objp -> amount ) . " </span></td> \n " ;
2017-10-07 13:09:31 +02:00
print " </tr> " ;
2022-05-22 17:09:08 +02:00
$totalpaid += $objp -> amount ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-07-21 20:55:12 +02:00
print '<tr class="oddeven"><td><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td>' ;
2017-10-16 20:53:23 +02:00
print '<td></td><td></td><td></td><td></td>' ;
print '</tr>' ;
2017-10-07 13:09:31 +02:00
}
2022-05-22 17:09:08 +02:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " AlreadyPaid " ) . ' :</td><td class="right">' . price ( $totalpaid ) . " </td></tr> \n " ;
2022-01-05 22:14:24 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " AmountExpected " ) . ' :</td><td class="right">' . price ( $object -> amount ) . " </td></tr> \n " ;
2017-10-07 21:03:46 +02:00
2022-05-22 17:09:08 +02:00
$resteapayer = $object -> amount - $totalpaid ;
2017-10-07 21:03:46 +02:00
$cssforamountpaymentcomplete = 'amountpaymentcomplete' ;
2017-10-07 13:09:31 +02:00
2019-02-12 14:53:35 +01:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " RemainderToPay " ) . " :</td> " ;
2019-11-08 15:51:54 +01:00
print '<td class="right' . ( $resteapayer ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $resteapayer ) . " </td></tr> \n " ;
2017-10-07 13:09:31 +02:00
print " </table> " ;
2019-05-29 12:56:11 +02:00
print '</div>' ;
2017-10-07 13:09:31 +02:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
2017-06-09 09:25:15 +02:00
}
2016-11-29 06:34:20 +01:00
print '</div>' ;
print '</div>' ;
2017-06-09 09:25:15 +02:00
2016-11-29 06:34:20 +01:00
print '<div class="clearboth"></div>' ;
2016-11-29 06:43:16 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-11-29 06:34:20 +01:00
2021-02-23 21:09:01 +01:00
if ( $action == 'edit' ) {
2021-12-06 18:18:31 +01:00
print $form -> buttonsSaveCancel ();
2009-03-03 00:43:17 +01:00
2021-02-23 21:09:01 +01:00
print " </form> \n " ;
}
2006-08-20 23:09:23 +02:00
2021-12-06 18:18:31 +01:00
// Buttons for actions
2021-02-23 21:09:01 +01:00
if ( $action != 'edit' ) {
2021-03-31 16:57:58 +02:00
print '<div class="tabsAction">' . " \n " ;
2006-08-20 23:09:23 +02:00
2016-04-22 17:11:12 +02:00
// Reopen
2021-02-23 21:09:01 +01:00
if ( $object -> paye && $user -> rights -> tax -> charges -> creer ) {
2021-09-18 19:34:46 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $object -> id . '&action=reopen&token=' . newToken () . '">' . $langs -> trans ( " ReOpen " ) . '</a></div>' ;
2016-04-22 17:11:12 +02:00
}
2016-11-28 21:27:02 +01:00
2009-05-09 21:45:18 +02:00
// Edit
2021-02-23 21:09:01 +01:00
if ( $object -> paye == 0 && $user -> rights -> tax -> charges -> creer ) {
2021-09-18 19:34:46 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $object -> id . '&action=edit&token=' . newToken () . '">' . $langs -> trans ( " Modify " ) . '</a></div>' ;
2007-01-30 22:20:05 +01:00
}
2015-07-15 19:54:51 +02:00
// Emit payment
2021-02-23 21:09:01 +01:00
if ( $object -> paye == 0 && (( price2num ( $object -> amount ) < 0 && price2num ( $resteapayer , 'MT' ) < 0 ) || ( price2num ( $object -> amount ) > 0 && price2num ( $resteapayer , 'MT' ) > 0 )) && $user -> rights -> tax -> charges -> creer ) {
2021-09-18 19:34:46 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/paiement_charge.php?id=' . $object -> id . '&action=create&token=' . newToken () . '">' . $langs -> trans ( " DoPayment " ) . " </a></div> " ;
2006-08-20 23:09:23 +02:00
}
2009-08-19 19:16:47 +02:00
// Classify 'paid'
2021-02-23 21:09:01 +01:00
if ( $object -> paye == 0 && round ( $resteapayer ) <= 0 && $user -> rights -> tax -> charges -> creer ) {
2021-09-18 19:34:46 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $object -> id . '&action=paid&token=' . newToken () . '">' . $langs -> trans ( " ClassifyPaid " ) . '</a></div>' ;
2006-08-20 23:09:23 +02:00
}
2014-10-04 17:20:17 +02:00
2014-09-23 16:52:15 +02:00
// Clone
2021-02-23 21:09:01 +01:00
if ( $user -> rights -> tax -> charges -> creer ) {
2021-09-18 19:34:46 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $object -> id . '&action=clone&token=' . newToken () . '">' . $langs -> trans ( " ToClone " ) . " </a></div> " ;
2014-09-23 16:52:15 +02:00
}
2006-08-20 23:09:23 +02:00
2009-05-09 21:45:18 +02:00
// Delete
2022-05-22 17:09:08 +02:00
if ( $user -> rights -> tax -> charges -> supprimer && empty ( $totalpaid )) {
2021-09-18 22:04:41 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . DOL_URL_ROOT . '/compta/sociales/card.php?id=' . $object -> id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( " Delete " ) . '</a></div>' ;
2021-04-26 10:48:50 +02:00
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . ( dol_escape_htmltag ( $langs -> trans ( " DisabledBecausePayments " ))) . '">' . $langs -> trans ( " Delete " ) . '</a></div>' ;
2007-01-30 20:58:19 +01:00
}
2006-08-20 23:09:23 +02:00
print " </div> " ;
}
2021-12-06 18:18:31 +01:00
// Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
if ( $action != 'presend' ) {
print '<div class="fichecenter"><div class="fichehalfleft">' ;
print '<a name="builddoc"></a>' ; // ancre
$includedocgeneration = 1 ;
// Documents
if ( $includedocgeneration ) {
$objref = dol_sanitizeFileName ( $object -> ref );
$relativepath = $objref . '/' . $objref . '.pdf' ;
$filedir = $conf -> tax -> dir_output . '/' . $objref ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
//$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
$genallowed = 0 ;
$delallowed = $user -> rights -> tax -> charges -> creer ; // If you can create/edit, you can remove a file on card
print $formfile -> showdocuments ( 'tax' , $objref , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $langs -> defaultlang );
}
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
//$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright">' ;
/*
$MAXEVENT = 10 ;
2022-05-18 23:11:59 +02:00
$morehtmlcenter = dolGetButtonTitle ( $langs -> trans ( 'SeeAll' ), '' , 'fa fa-bars imgforviewmode' , dol_buildpath ( '/mymodule/myobject_agenda.php' , 1 ) . '?id=' . $object -> id );
2021-12-06 18:18:31 +01:00
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , $object -> element . '@' . $object -> module , ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> id : 0 ), 1 , '' , $MAXEVENT , '' , $morehtmlcenter );
*/
print '</div></div>' ;
}
//Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
// Presend form
$modelmail = 'sc' ;
$defaulttopic = 'InformationMessage' ;
$diroutput = $conf -> tax -> dir_output ;
$trackid = 'sc' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2020-05-21 15:05:19 +02:00
} else {
2015-03-10 14:49:36 +01:00
/* Social contribution not found */
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , $object -> error );
2006-08-20 23:09:23 +02:00
}
2004-05-02 18:01:35 +02:00
}
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-11 20:30:16 +01:00
$db -> close ();