2014-03-06 21:21:16 +01:00
< ? php
2019-07-19 23:08:24 +02:00
/* Copyright ( C ) 2011 - 2019 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2020-12-03 00:40:41 +01:00
* Copyright ( C ) 2014 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 17:45:29 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2015 Charlie BENKE < charlie @ patas - monkey . com >
2022-03-24 10:51:01 +01:00
* Copyright ( C ) 2018 - 2022 Frédéric France < frederic . france @ netlogic . fr >
2021-02-05 09:29:20 +01:00
* Copyright ( C ) 2021 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2014-03-06 21:21:16 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-03-06 21:21:16 +01:00
*/
/**
2019-07-19 23:08:24 +02:00
* \file htdocs / salaries / card . php
2018-05-20 08:00:42 +02:00
* \ingroup salaries
* \brief Page of salaries payments
2014-03-06 21:21:16 +01:00
*/
2022-01-01 18:15:22 +01:00
2019-07-19 23:08:24 +02:00
require '../main.inc.php' ;
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-02-04 17:21:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/salaries/class/salary.class.php' ;
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/salaries.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2021-03-04 18:57:03 +01:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2022-02-07 09:50:07 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2022-08-29 10:56:06 +02:00
if ( isModEnabled ( 'project' )) {
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2018-07-31 07:45:03 +02:00
}
2015-04-19 13:28:51 +02:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2021-02-04 17:21:08 +01:00
$langs -> loadLangs ( array ( " compta " , " banks " , " bills " , " users " , " salaries " , " hrm " , " trips " ));
2022-08-29 10:56:06 +02:00
if ( isModEnabled ( 'project' )) {
2021-02-26 21:17:52 +01:00
$langs -> load ( " projects " );
}
2014-03-06 21:21:16 +01:00
2021-03-13 13:30:19 +01:00
$id = GETPOSTINT ( 'id' );
2021-04-02 23:23:44 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
2019-12-19 10:01:11 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
$cancel = GETPOST ( 'cancel' , 'aZ09' );
2021-10-31 15:14:15 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
$backtopageforcancel = GETPOST ( 'backtopageforcancel' , 'alpha' );
2021-02-04 17:21:08 +01:00
$confirm = GETPOST ( 'confirm' );
2021-10-31 15:14:15 +01:00
2021-09-28 19:40:41 +02:00
$label = GETPOST ( 'label' , 'alphanohtml' );
2019-01-27 11:55:16 +01:00
$projectid = ( GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : GETPOST ( 'fk_project' , 'int' ));
2021-09-28 19:40:41 +02:00
$accountid = GETPOST ( 'accountid' , 'int' ) > 0 ? GETPOST ( 'accountid' , 'int' ) : 0 ;
2021-02-26 15:59:27 +01:00
if ( GETPOSTISSET ( 'auto_create_paiement' ) || $action === 'add' ) {
$auto_create_paiement = GETPOST ( " auto_create_paiement " , " int " );
} else {
$auto_create_paiement = empty ( $conf -> global -> CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT );
}
2014-03-06 21:21:16 +01:00
2019-12-19 10:01:11 +01:00
$datep = dol_mktime ( 12 , 0 , 0 , GETPOST ( " datepmonth " , 'int' ), GETPOST ( " datepday " , 'int' ), GETPOST ( " datepyear " , 'int' ));
$datev = dol_mktime ( 12 , 0 , 0 , GETPOST ( " datevmonth " , 'int' ), GETPOST ( " datevday " , 'int' ), GETPOST ( " datevyear " , 'int' ));
$datesp = dol_mktime ( 12 , 0 , 0 , GETPOST ( " datespmonth " , 'int' ), GETPOST ( " datespday " , 'int' ), GETPOST ( " datespyear " , 'int' ));
$dateep = dol_mktime ( 12 , 0 , 0 , GETPOST ( " dateepmonth " , 'int' ), GETPOST ( " dateepday " , 'int' ), GETPOST ( " dateepyear " , 'int' ));
2021-03-13 13:30:19 +01:00
$fk_user = GETPOSTINT ( 'userid' );
2019-12-19 10:01:11 +01:00
2021-02-04 17:21:08 +01:00
$object = new Salary ( $db );
2019-07-19 23:08:24 +02:00
$extrafields = new ExtraFields ( $db );
2021-09-08 15:36:51 +02:00
$childids = $user -> getAllChildIds ( 1 );
2019-07-19 23:08:24 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2014-03-06 21:21:16 +01:00
2021-09-09 03:02:18 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'salarycard' , 'globalcard' ));
if ( $id > 0 || ! empty ( $ref )) {
2021-09-08 15:36:51 +02:00
$object -> fetch ( $id , $ref );
2021-09-09 03:02:18 +02:00
// Check current user can read this salary
2021-09-08 15:36:51 +02:00
$canread = 0 ;
if ( ! empty ( $user -> rights -> salaries -> readall )) {
$canread = 1 ;
}
2021-09-09 03:02:18 +02:00
if ( ! empty ( $user -> rights -> salaries -> read ) && $object -> fk_user > 0 && in_array ( $object -> fk_user , $childids )) {
2021-09-08 15:36:51 +02:00
$canread = 1 ;
}
if ( ! $canread ) {
accessforbidden ();
}
}
2021-04-02 23:23:44 +02:00
// Security check
$socid = GETPOSTINT ( 'socid' );
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-10-31 15:14:15 +01:00
2021-04-02 23:23:44 +02:00
restrictedArea ( $user , 'salaries' , $object -> id , 'salary' , '' );
2022-02-07 09:50:07 +01:00
$permissiontoread = $user -> rights -> salaries -> read ;
$permissiontoadd = $user -> rights -> salaries -> write ; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$permissiontodelete = $user -> rights -> salaries -> delete || ( $permissiontoadd && isset ( $object -> status ) && $object -> status == $object :: STATUS_DRAFT );
2019-12-19 10:01:11 +01:00
2014-03-06 21:21:16 +01:00
/**
* Actions
*/
2021-10-31 15:14:15 +01:00
$parameters = array ();
$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' );
}
if ( empty ( $reshook )) {
$error = 0 ;
$backurlforlist = dol_buildpath ( '/salaries/list.php' , 1 );
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_buildpath ( '/salaries/card.php' , 1 ) . '?id=' . ( $id > 0 ? $id : '__ID__' );
}
}
}
if ( $cancel ) {
2022-05-17 14:55:38 +02:00
//var_dump($cancel);
//var_dump($backtopage);exit;
2021-10-31 15:14:15 +01:00
if ( ! empty ( $backtopageforcancel )) {
header ( " Location: " . $backtopageforcancel );
exit ;
} elseif ( ! empty ( $backtopage )) {
header ( " Location: " . $backtopage );
exit ;
}
$action = '' ;
}
2014-03-06 21:21:16 +01:00
}
2018-07-31 07:45:03 +02:00
// Link to a project
2021-02-26 21:17:52 +01:00
if ( $action == 'classin' && $user -> rights -> banque -> modifier ) {
2018-07-31 07:45:03 +02:00
$object -> fetch ( $id );
2019-12-19 10:01:11 +01:00
$object -> setProject ( $projectid );
2018-07-31 07:45:03 +02:00
}
2021-02-05 09:29:20 +01:00
// set label
2021-02-04 17:21:08 +01:00
if ( $action == 'setlabel' && $user -> rights -> salaries -> write ) {
$object -> fetch ( $id );
$object -> label = $label ;
$object -> update ( $user );
}
// Classify paid
2021-03-01 11:12:03 +01:00
if ( $action == 'confirm_paid' && $user -> rights -> salaries -> write && $confirm == 'yes' ) {
2018-07-31 07:45:03 +02:00
$object -> fetch ( $id );
2021-02-04 17:21:08 +01:00
$result = $object -> set_paid ( $user );
}
2021-03-08 17:24:54 +01:00
if ( $action == 'setfk_user' && $user -> rights -> salaries -> write ) {
2021-03-08 10:09:38 +01:00
$result = $object -> fetch ( $id );
2021-03-08 17:24:54 +01:00
if ( $result > 0 ) {
2021-03-08 10:09:38 +01:00
$object -> fk_user = $fk_user ;
$object -> update ( $user );
} else {
dol_print_error ( $db );
exit ;
}
2021-03-03 16:36:21 +01:00
}
2021-02-04 17:21:08 +01:00
if ( $action == 'reopen' && $user -> rights -> salaries -> write ) {
$result = $object -> fetch ( $id );
2021-03-01 11:12:03 +01:00
if ( $object -> paye ) {
2021-02-04 17:21:08 +01:00
$result = $object -> set_unpaid ( $user );
2021-03-01 11:12:03 +01:00
if ( $result > 0 ) {
2021-02-04 17:21:08 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id );
exit ();
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
}
// payment mode
if ( $action == 'setmode' && $user -> rights -> salaries -> write ) {
$object -> fetch ( $id );
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
if ( $result < 0 )
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
// bank account
if ( $action == 'setbankaccount' && $user -> rights -> salaries -> write ) {
$object -> fetch ( $id );
$result = $object -> setBankAccount ( GETPOST ( 'fk_account' , 'int' ));
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2018-07-31 07:45:03 +02:00
}
2021-02-26 21:17:52 +01:00
if ( $action == 'add' && empty ( $cancel )) {
2019-11-13 19:35:39 +01:00
$error = 0 ;
2014-03-25 21:35:52 +01:00
2019-11-13 19:35:39 +01:00
if ( empty ( $datev )) $datev = $datep ;
2017-06-07 06:03:52 +02:00
2021-02-04 17:21:08 +01:00
$type_payment = GETPOST ( " paymenttype " , 'alpha' );
2021-03-04 21:33:29 +01:00
$amount = price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' , 2 );
2017-10-24 15:22:46 +02:00
2019-12-19 10:01:11 +01:00
$object -> accountid = GETPOST ( " accountid " , 'int' ) > 0 ? GETPOST ( " accountid " , " int " ) : 0 ;
$object -> fk_user = GETPOST ( " fk_user " , 'int' ) > 0 ? GETPOST ( " fk_user " , " int " ) : 0 ;
2019-11-13 19:35:39 +01:00
$object -> datev = $datev ;
$object -> datep = $datep ;
2021-03-04 21:33:29 +01:00
$object -> amount = $amount ;
2019-12-19 10:01:11 +01:00
$object -> label = GETPOST ( " label " , 'alphanohtml' );
2019-11-13 19:35:39 +01:00
$object -> datesp = $datesp ;
$object -> dateep = $dateep ;
2020-09-18 01:29:17 +02:00
$object -> note = GETPOST ( " note " , 'restricthtml' );
2019-11-13 19:35:39 +01:00
$object -> type_payment = ( $type_payment > 0 ? $type_payment : 0 );
$object -> fk_user_author = $user -> id ;
2019-12-19 10:01:11 +01:00
$object -> fk_project = $projectid ;
2014-03-25 21:35:52 +01:00
2019-07-19 23:08:24 +02:00
// Set user current salary as ref salary for the payment
2019-11-13 19:35:39 +01:00
$fuser = new User ( $db );
2019-01-27 11:55:16 +01:00
$fuser -> fetch ( GETPOST ( " fk_user " , " int " ));
2019-11-13 19:35:39 +01:00
$object -> salary = $fuser -> salary ;
2015-03-10 10:11:51 +01:00
2020-10-31 14:32:18 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-26 21:17:52 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2019-07-19 23:08:24 +02:00
2021-02-04 17:21:08 +01:00
if ( ! empty ( $auto_create_paiement ) && empty ( $datep )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DATE_PAIEMENT " )), null , 'errors' );
$error ++ ;
}
2021-03-01 11:12:03 +01:00
if ( empty ( $datesp ) || empty ( $dateep )) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
2014-05-10 17:22:12 +02:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( empty ( $object -> fk_user ) || $object -> fk_user < 0 ) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Employee " )), null , 'errors' );
2014-03-25 21:35:52 +01:00
$error ++ ;
}
2021-03-01 11:12:03 +01:00
if ( ! empty ( $auto_create_paiement ) && ( empty ( $type_payment ) || $type_payment < 0 )) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " PaymentMode " )), null , 'errors' );
2014-03-25 21:35:52 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( empty ( $object -> amount )) {
2015-10-17 16:18:33 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Amount " )), null , 'errors' );
2014-03-25 21:35:52 +01:00
$error ++ ;
}
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' ) && ! empty ( $auto_create_paiement ) && ! $object -> accountid > 0 ) {
2016-10-06 17:43:10 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BankAccount " )), null , 'errors' );
2015-05-13 08:57:00 +02:00
$error ++ ;
}
2017-06-07 16:44:04 +02:00
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2021-04-18 16:43:09 +02:00
$db -> begin ();
2019-11-13 19:35:39 +01:00
$ret = $object -> create ( $user );
2021-11-29 19:39:03 +01:00
if ( $ret < 0 ) {
2022-03-24 10:51:01 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-11-29 19:39:03 +01:00
$error ++ ;
}
2021-03-01 11:12:03 +01:00
if ( ! empty ( $auto_create_paiement ) && ! $error ) {
2021-02-04 17:21:08 +01:00
// Create a line of payments
$paiement = new PaymentSalary ( $db );
$paiement -> chid = $object -> id ;
$paiement -> datepaye = $datep ;
$paiement -> datev = $datev ;
$paiement -> amounts = array ( $object -> id => $amount ); // Tableau de montant
$paiement -> paiementtype = $type_payment ;
$paiement -> num_payment = GETPOST ( " num_payment " , 'alphanohtml' );
2022-01-19 15:20:10 +01:00
$paiement -> note = GETPOST ( " note " , 'restricthtml' );
2021-02-04 17:21:08 +01:00
2021-03-01 11:12:03 +01:00
if ( ! $error ) {
2021-02-04 17:21:08 +01:00
$paymentid = $paiement -> create ( $user , ( int ) GETPOST ( 'closepaidsalary' ));
2021-03-01 11:12:03 +01:00
if ( $paymentid < 0 ) {
2021-02-04 17:21:08 +01:00
$error ++ ;
setEventMessages ( $paiement -> error , null , 'errors' );
$action = 'create' ;
}
}
2019-12-19 10:01:11 +01:00
2021-03-01 11:12:03 +01:00
if ( ! $error ) {
2021-02-04 17:21:08 +01:00
$result = $paiement -> addPaymentToBank ( $user , 'payment_salary' , '(SalaryPayment)' , GETPOST ( 'accountid' , 'int' ), '' , '' );
2021-03-01 11:12:03 +01:00
if ( ! ( $result > 0 )) {
2021-02-04 17:21:08 +01:00
$error ++ ;
setEventMessages ( $paiement -> error , null , 'errors' );
}
}
}
2019-12-19 10:01:11 +01:00
2021-02-05 13:08:05 +01:00
if ( empty ( $error )) {
2021-04-18 16:43:09 +02:00
$db -> commit ();
2019-12-19 10:01:11 +01:00
if ( GETPOST ( 'saveandnew' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " RecordSaved " ), '' , 'mesgs' );
2021-02-04 17:21:08 +01:00
header ( " Location: card.php?action=create&fk_project= " . urlencode ( $projectid ) . " &accountid= " . urlencode ( $accountid ) . '&paymenttype=' . urlencode ( GETPOST ( 'paymenttype' , 'az09' )) . '&datepday=' . GETPOST ( " datepday " , 'int' ) . '&datepmonth=' . GETPOST ( " datepmonth " , 'int' ) . '&datepyear=' . GETPOST ( " datepyear " , 'int' ));
2019-12-19 10:01:11 +01:00
exit ;
} else {
2021-02-04 17:21:08 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id );
2019-12-19 10:01:11 +01:00
exit ;
}
2021-04-18 16:43:09 +02:00
} else {
$db -> rollback ();
2014-03-25 21:35:52 +01:00
}
}
2019-11-13 19:35:39 +01:00
$action = 'create' ;
2014-03-06 21:21:16 +01:00
}
2021-03-01 11:12:03 +01:00
if ( $action == 'confirm_delete' ) {
2019-11-13 19:35:39 +01:00
$result = $object -> fetch ( $id );
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
2014-03-06 21:21:16 +01:00
2022-05-22 17:09:08 +02:00
if ( empty ( $totalpaid )) {
2014-03-25 21:35:52 +01:00
$db -> begin ();
2014-03-06 21:21:16 +01:00
2019-11-13 19:35:39 +01:00
$ret = $object -> delete ( $user );
2021-03-04 17:57:08 +01:00
if ( $ret > 0 ) {
2021-02-04 17:21:08 +01:00
$db -> commit ();
header ( " Location: " . DOL_URL_ROOT . '/salaries/list.php' );
exit ;
2021-03-04 17:57:08 +01:00
} else {
2021-02-04 17:21:08 +01:00
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-03-04 17:57:08 +01:00
} else {
2021-02-04 17:21:08 +01:00
setEventMessages ( $langs -> trans ( 'DisabledBecausePayments' ), null , 'errors' );
}
}
2014-03-06 21:21:16 +01:00
2021-02-04 17:21:08 +01:00
2021-03-24 19:06:44 +01:00
if ( $action == 'update' && ! GETPOST ( " cancel " ) && $user -> rights -> salaries -> write ) {
2021-03-04 21:33:29 +01:00
$amount = price2num ( GETPOST ( 'amount' ), 'MT' , 2 );
2021-02-04 17:21:08 +01:00
2021-03-01 11:12:03 +01:00
if ( empty ( $amount )) {
2021-02-04 17:21:08 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
$action = 'edit' ;
2021-03-04 17:57:08 +01:00
} elseif ( ! is_numeric ( $amount )) {
2021-02-04 17:21:08 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldMustBeANumeric " , $langs -> transnoentities ( " Amount " )), null , 'errors' );
$action = 'create' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-04 17:21:08 +01:00
$result = $object -> fetch ( $id );
$object -> amount = price2num ( $amount );
$object -> datesp = price2num ( $datesp );
$object -> dateep = price2num ( $dateep );
$result = $object -> update ( $user );
if ( $result <= 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-03-25 21:35:52 +01:00
}
2021-02-04 17:21:08 +01:00
}
}
if ( $action == 'confirm_clone' && $confirm != 'yes' ) { $action = '' ; }
2021-03-01 11:12:03 +01:00
if ( $action == 'confirm_clone' && $confirm == 'yes' && ( $user -> rights -> salaries -> write )) {
2021-02-04 17:21:08 +01:00
$db -> begin ();
$originalId = $id ;
$object -> fetch ( $id );
2021-03-04 17:57:08 +01:00
if ( $object -> id > 0 ) {
2021-02-04 17:21:08 +01:00
$object -> paye = 0 ;
$object -> id = $object -> ref = null ;
if ( GETPOST ( 'clone_label' , 'alphanohtml' )) {
$object -> label = GETPOST ( 'clone_label' , 'alphanohtml' );
2021-03-04 17:57:08 +01:00
} else {
2021-02-04 17:21:08 +01:00
$object -> label = $langs -> trans ( " CopyOf " ) . ' ' . $object -> label ;
}
$newdatestart = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'clone_date_startmonth' , 'int' ), GETPOST ( 'clone_date_startday' , 'int' ), GETPOST ( 'clone_date_startyear' , 'int' ));
$newdateend = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'clone_date_endmonth' , 'int' ), GETPOST ( 'clone_date_endday' , 'int' ), GETPOST ( 'clone_date_endyear' , 'int' ));
if ( $newdatestart ) $object -> datesp = $newdatestart ;
if ( $newdateend ) $object -> dateep = $newdateend ;
$id = $object -> create ( $user );
2021-03-04 17:57:08 +01:00
if ( $id > 0 ) {
2021-02-04 17:21:08 +01:00
$db -> commit ();
$db -> close ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
2021-03-04 17:57:08 +01:00
} else {
2021-02-04 17:21:08 +01:00
$id = $originalId ;
2014-03-25 21:35:52 +01:00
$db -> rollback ();
2021-02-04 17:21:08 +01:00
2015-11-15 07:47:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-03-25 21:35:52 +01:00
}
2021-03-04 17:57:08 +01:00
} else {
2021-02-04 17:21:08 +01:00
$db -> rollback ();
dol_print_error ( $db , $object -> error );
2014-03-06 21:21:16 +01:00
}
}
2021-09-06 12:30:39 +02:00
// Action to update one extrafield
if ( $action == " update_extras " && ! empty ( $user -> rights -> salaries -> read )) {
$object -> fetch ( GETPOST ( 'id' , 'int' ));
$attributekey = GETPOST ( 'attribute' , 'alpha' );
$attributekeylong = 'options_' . $attributekey ;
if ( GETPOSTISSET ( $attributekeylong . 'day' ) && GETPOSTISSET ( $attributekeylong . 'month' ) && GETPOSTISSET ( $attributekeylong . 'year' )) {
// This is properties of a date
$object -> array_options [ 'options_' . $attributekey ] = dol_mktime ( GETPOST ( $attributekeylong . 'hour' , 'int' ), GETPOST ( $attributekeylong . 'min' , 'int' ), GETPOST ( $attributekeylong . 'sec' , 'int' ), GETPOST ( $attributekeylong . 'month' , 'int' ), GETPOST ( $attributekeylong . 'day' , 'int' ), GETPOST ( $attributekeylong . 'year' , 'int' ));
//var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
} else {
$object -> array_options [ 'options_' . $attributekey ] = GETPOST ( $attributekeylong , 'alpha' );
}
$result = $object -> insertExtraFields ( empty ( $triggermodname ) ? '' : $triggermodname , $user );
if ( $result > 0 ) {
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
$action = 'view' ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'edit_extras' ;
}
}
2014-03-06 21:21:16 +01:00
/*
2014-03-25 21:35:52 +01:00
* View
*/
2014-03-06 21:21:16 +01:00
2022-02-07 09:50:07 +01:00
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2022-08-29 10:56:06 +02:00
if ( isModEnabled ( 'project' )) $formproject = new FormProjets ( $db );
2022-02-07 09:50:07 +01:00
2021-05-17 22:12:01 +02:00
$title = $langs -> trans ( 'Salary' ) . " - " . $langs -> trans ( 'Card' );
$help_url = " " ;
llxHeader ( " " , $title , $help_url );
2014-03-06 21:21:16 +01:00
2021-10-31 15:14:15 +01:00
if ( $id > 0 ) {
2015-05-13 08:57:00 +02:00
$result = $object -> fetch ( $id );
2021-02-26 21:17:52 +01:00
if ( $result <= 0 ) {
2014-03-06 21:21:16 +01:00
dol_print_error ( $db );
exit ;
}
}
2017-04-06 23:28:06 +02:00
// Create
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2019-01-27 11:55:16 +01:00
$year_current = strftime ( " %Y " , dol_now ());
$pastmonth = strftime ( " %m " , dol_now ()) - 1 ;
2014-03-25 21:35:52 +01:00
$pastmonthyear = $year_current ;
2021-02-26 21:17:52 +01:00
if ( $pastmonth == 0 ) {
2014-03-25 21:35:52 +01:00
$pastmonth = 12 ;
$pastmonthyear -- ;
}
2017-10-01 19:38:08 +02:00
$datespmonth = GETPOST ( 'datespmonth' , 'int' );
$datespday = GETPOST ( 'datespday' , 'int' );
$datespyear = GETPOST ( 'datespyear' , 'int' );
$dateepmonth = GETPOST ( 'dateepmonth' , 'int' );
$dateepday = GETPOST ( 'dateepday' , 'int' );
$dateepyear = GETPOST ( 'dateepyear' , 'int' );
2019-11-13 19:35:39 +01:00
$datesp = dol_mktime ( 0 , 0 , 0 , $datespmonth , $datespday , $datespyear );
$dateep = dol_mktime ( 23 , 59 , 59 , $dateepmonth , $dateepday , $dateepyear );
2014-03-25 21:35:52 +01:00
2021-02-26 21:17:52 +01:00
if ( empty ( $datesp ) || empty ( $dateep )) { // We define date_start and date_end
2019-11-13 19:35:39 +01:00
$datesp = dol_get_first_day ( $pastmonthyear , $pastmonth , false ); $dateep = dol_get_last_day ( $pastmonthyear , $pastmonth , false );
2014-03-25 21:35:52 +01:00
}
2014-11-04 20:53:07 +01:00
print '<form name="salary" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2014-03-25 21:35:52 +01:00
print '<input type="hidden" name="action" value="add">' ;
2021-10-31 15:14:15 +01:00
if ( $backtopage ) {
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
}
if ( $backtopageforcancel ) {
print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">' ;
}
2014-03-25 21:35:52 +01:00
2021-03-04 21:33:29 +01:00
print load_fiche_titre ( $langs -> trans ( " NewSalary " ), '' , 'salary' );
2014-03-25 21:35:52 +01:00
2021-03-01 11:12:03 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2021-11-29 15:09:18 +01:00
print " \n " . '<script type="text/javascript">' ;
2021-02-26 15:59:27 +01:00
print /** @lang JavaScript */ '
$ ( document ) . ready ( function () {
let onAutoCreatePaiementChange = function () {
if ( $ ( " #auto_create_paiement " ) . is ( " :checked " )) {
2021-02-04 17:21:08 +01:00
$ ( " #label_fk_account " ) . find ( " span " ) . addClass ( " fieldrequired " );
$ ( " #label_type_payment " ) . find ( " span " ) . addClass ( " fieldrequired " );
$ ( " .hide_if_no_auto_create_payment " ) . show ();
} else {
$ ( " #label_fk_account " ) . find ( " span " ) . removeClass ( " fieldrequired " );
$ ( " #label_type_payment " ) . find ( " span " ) . removeClass ( " fieldrequired " );
$ ( " .hide_if_no_auto_create_payment " ) . hide ();
}
2021-02-26 15:59:27 +01:00
};
$ ( " #radiopayment " ) . click ( function () {
$ ( " #label " ) . val ( $ ( this ) . data ( " label " ));
});
$ ( " #radiorefund " ) . click ( function () {
$ ( " #label " ) . val ( $ ( this ) . data ( " label " ));
});
$ ( " #auto_create_paiement " ) . click ( function () {
onAutoCreatePaiementChange ();
});
onAutoCreatePaiementChange ();
});
' ;
2021-02-04 17:21:08 +01:00
print '</script>' . " \n " ;
}
2014-03-25 21:35:52 +01:00
2021-02-05 09:29:20 +01:00
print dol_get_fiche_head ( '' , '' );
2014-03-25 21:35:52 +01:00
2021-02-04 17:21:08 +01:00
print '<table class="border centpercent">' ;
2014-03-25 21:35:52 +01:00
2020-11-09 14:39:04 +01:00
// Employee
2021-03-10 17:25:26 +01:00
print '<tr><td class="titlefieldcreate">' ;
2020-11-09 14:39:04 +01:00
print $form -> editfieldkey ( 'Employee' , 'fk_user' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
$noactive = 0 ; // We keep active and unactive users
2021-03-04 21:33:29 +01:00
print img_picto ( '' , 'user' , 'class="paddingrighonly"' ) . $form -> select_dolusers ( GETPOST ( 'fk_user' , 'int' ), 'fk_user' , 1 , '' , 0 , '' , '' , 0 , 0 , 0 , 'AND employee=1' , 0 , '' , 'maxwidth300' , $noactive );
2020-11-09 14:39:04 +01:00
print '</td></tr>' ;
2014-03-25 21:35:52 +01:00
// Label
2015-11-02 06:42:17 +01:00
print '<tr><td>' ;
2018-10-27 17:45:29 +02:00
print $form -> editfieldkey ( 'Label' , 'label' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2021-03-04 21:33:29 +01:00
print '<input name="label" id="label" class="minwidth300" value="' . ( GETPOST ( " label " ) ? GETPOST ( " label " ) : $langs -> trans ( " Salary " )) . '">' ;
2015-11-02 06:42:17 +01:00
print '</td></tr>' ;
2014-03-25 21:35:52 +01:00
2015-11-02 06:42:17 +01:00
// Date start period
print '<tr><td>' ;
2018-10-27 17:45:29 +02:00
print $form -> editfieldkey ( 'DateStartPeriod' , 'datesp' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2018-09-09 09:56:33 +02:00
print $form -> selectDate ( $datesp , " datesp " , '' , '' , '' , 'add' );
2014-03-25 21:35:52 +01:00
print '</td></tr>' ;
2015-11-02 06:42:17 +01:00
// Date end period
print '<tr><td>' ;
2018-10-27 17:45:29 +02:00
print $form -> editfieldkey ( 'DateEndPeriod' , 'dateep' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2018-09-09 09:56:33 +02:00
print $form -> selectDate ( $dateep , " dateep " , '' , '' , '' , 'add' );
2014-03-25 21:35:52 +01:00
print '</td></tr>' ;
// Amount
2015-11-02 06:42:17 +01:00
print '<tr><td>' ;
2018-10-27 17:45:29 +02:00
print $form -> editfieldkey ( 'Amount' , 'amount' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2021-09-07 10:39:41 +02:00
print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="' . GETPOST ( " amount " ) . '"> ' ;
2022-05-04 20:36:59 +02:00
print '<button class="dpInvisibleButtons datenow" id="updateAmountWithLastSalary" name="_useless" type="button">' . $langs -> trans ( 'UpdateAmountWithLastSalary' ) . '</a>' ;
2021-09-07 10:39:41 +02:00
print '</td>' ;
print '</tr>' ;
2014-03-25 21:35:52 +01:00
2021-03-04 19:20:16 +01:00
// Project
2022-08-29 10:56:06 +02:00
if ( isModEnabled ( 'project' )) {
2021-02-05 13:08:05 +01:00
$formproject = new FormProjets ( $db );
2021-02-05 11:12:55 +01:00
2021-02-05 13:08:05 +01:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2022-01-01 18:15:22 +01:00
print img_picto ( '' , 'project' , 'class="pictofixedwidth"' );
print $formproject -> select_projects ( - 1 , $projectid , 'fk_project' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 1 );
2021-02-05 13:08:05 +01:00
print '</td></tr>' ;
}
2021-02-05 11:12:55 +01:00
2021-03-04 21:33:29 +01:00
// Comments
2021-03-10 17:25:26 +01:00
print '<tr>' ;
2021-03-04 21:33:29 +01:00
print '<td class="tdtop">' . $langs -> trans ( " Comments " ) . '</td>' ;
print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="' . ROWS_3 . '">' . GETPOST ( 'note' , 'restricthtml' ) . '</textarea></td>' ;
print '</tr>' ;
2021-11-29 19:39:03 +01:00
2021-03-04 21:33:29 +01:00
print '<tr><td colspan="2"><hr></td></tr>' ;
2021-11-29 19:39:03 +01:00
2021-03-04 21:33:29 +01:00
// Auto create payment
2021-11-29 19:39:03 +01:00
print '<tr><td><label for="auto_create_paiement">' . $langs -> trans ( 'AutomaticCreationPayment' ) . '</label></td>' ;
2021-03-04 21:33:29 +01:00
print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . ( empty ( $auto_create_paiement ) ? '' : 'checked="checked"' ) . ' value="1"></td></tr>' . " \n " ; // Date payment
2014-03-25 21:35:52 +01:00
// Bank
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-04 17:21:08 +01:00
print '<tr><td id="label_fk_account">' ;
2021-04-14 23:14:38 +02:00
print $form -> editfieldkey ( 'BankAccount' , 'selectaccountid' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2021-03-04 21:33:29 +01:00
print img_picto ( '' , 'bank_account' , 'class="paddingrighonly"' );
2019-12-19 10:01:11 +01:00
$form -> select_comptes ( $accountid , " accountid " , 0 , '' , 1 ); // Affiche liste des comptes courant
2014-03-25 21:35:52 +01:00
print '</td></tr>' ;
2014-05-10 17:22:12 +02:00
}
// Type payment
2021-02-05 11:12:55 +01:00
print '<tr><td id="label_type_payment">' ;
2021-04-14 23:14:38 +02:00
print $form -> editfieldkey ( 'PaymentMode' , 'selectpaymenttype' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2021-02-05 11:12:55 +01:00
$form -> select_types_paiements ( GETPOST ( " paymenttype " , 'aZ09' ), " paymenttype " , '' );
2015-11-02 06:42:17 +01:00
print '</td></tr>' ;
2014-05-10 17:22:12 +02:00
2021-02-04 17:21:08 +01:00
// Date payment
2021-02-05 11:12:55 +01:00
print '<tr class="hide_if_no_auto_create_payment"><td>' ;
2021-02-04 17:21:08 +01:00
print $form -> editfieldkey ( 'DatePayment' , 'datep' , '' , $object , 0 , 'string' , '' , 1 ) . '</td><td>' ;
2021-02-05 09:29:20 +01:00
print $form -> selectDate (( empty ( $datep ) ? '' : $datep ), " datep " , 0 , 0 , 0 , 'add' , 1 , 1 );
2021-02-04 17:21:08 +01:00
print '</td></tr>' ;
// Date value for bank
2021-02-05 11:12:55 +01:00
print '<tr class="hide_if_no_auto_create_payment"><td>' ;
2021-02-04 17:21:08 +01:00
print $form -> editfieldkey ( 'DateValue' , 'datev' , '' , $object , 0 ) . '</td><td>' ;
print $form -> selectDate (( empty ( $datev ) ? - 1 : $datev ), " datev " , '' , '' , '' , 'add' , 1 , 1 );
2015-11-02 06:42:17 +01:00
print '</td></tr>' ;
2014-05-10 17:22:12 +02:00
2015-11-02 06:42:17 +01:00
// Number
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2014-04-30 06:38:36 +02:00
// Number
2021-02-04 17:21:08 +01:00
print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">' . $langs -> trans ( 'Numero' );
2014-04-30 06:38:36 +02:00
print ' <em>(' . $langs -> trans ( " ChequeOrTransferNumber " ) . ')</em>' ;
2015-09-23 05:47:49 +02:00
print '</label></td>' ;
print '<td><input name="num_payment" id="num_payment" type="text" value="' . GETPOST ( " num_payment " ) . '"></td></tr>' . " \n " ;
2014-04-30 06:38:36 +02:00
}
2014-05-10 17:22:12 +02:00
2021-02-04 17:21:08 +01:00
// Bouton Save payment
2021-04-19 15:30:30 +02:00
/*
print '<tr class="hide_if_no_auto_create_payment"><td>' ;
2021-02-04 17:21:08 +01:00
print $langs -> trans ( " ClosePaidSalaryAutomatically " );
print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>' ;
2021-04-19 15:30:30 +02:00
*/
2020-10-31 14:32:18 +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 ;
2021-02-26 21:17:52 +01:00
if ( empty ( $reshook )) {
2021-10-08 15:58:08 +02:00
print $object -> showOptionals ( $extrafields , 'create' );
2020-10-31 14:32:18 +01:00
}
2014-03-25 21:35:52 +01:00
print '</table>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2014-03-25 21:35:52 +01:00
2014-11-25 20:13:43 +01:00
print '<div class="center">' ;
2021-04-14 23:14:38 +02:00
print '<div class="hide_if_no_auto_create_payment paddingbottom">' ;
print '<input type="checkbox" checked value="1" name="closepaidsalary">' . $langs -> trans ( " ClosePaidSalaryAutomatically " );
print '</div>' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2014-03-25 21:35:52 +01:00
2021-08-20 14:41:30 +02:00
$addition_button = array (
'name' => 'saveandnew' ,
'label_key' => 'SaveAndNew' ,
);
print $form -> buttonsSaveCancel ( " Save " , " Cancel " , $addition_button );
2014-03-25 21:35:52 +01:00
print '</form>' ;
2021-09-07 10:39:41 +02:00
print '<script>' ;
print '$( document ).ready(function() {' ;
2021-09-09 14:29:42 +02:00
print ' $ ( " #updateAmountWithLastSalary " ) . on ( " click " , function updateAmountWithLastSalary () {
console . log ( " We click on link to autofill salary amount " );
2021-09-07 10:39:41 +02:00
var fk_user = $ ( " #fk_user " ) . val ()
var url = " '.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user= " + fk_user ;
2021-09-09 14:29:42 +02:00
if ( fk_user != - 1 ) {
2021-09-07 10:39:41 +02:00
$ . get (
url ,
function ( data ) {
2021-09-09 14:29:42 +02:00
if ( data != null ) {
2021-09-07 10:39:41 +02:00
console . log ( " Data returned: " + data );
item = JSON . parse ( data );
2021-09-09 14:29:42 +02:00
if ( item [ 0 ] . key == " Amount " ) {
2021-09-07 10:39:41 +02:00
value = item [ 0 ] . value ;
2021-09-09 14:29:42 +02:00
if ( value != null ) {
2021-09-07 10:39:41 +02:00
$ ( " #amount " ) . val ( item [ 0 ] . value );
2021-09-09 14:29:42 +02:00
} else {
2021-09-07 10:39:41 +02:00
console . error ( " Error: Ajax url " + url + " has returned a null value. " );
}
2021-09-09 14:29:42 +02:00
} else {
2021-09-07 10:39:41 +02:00
console . error ( " Error: Ajax url " + url + " has returned the wrong key. " );
}
2021-09-09 14:29:42 +02:00
} else {
2021-09-07 10:39:41 +02:00
console . error ( " Error: Ajax url " + url + " has returned an empty page. " );
}
}
);
2021-09-18 19:34:46 +02:00
2021-09-09 14:29:42 +02:00
} else {
2021-11-18 21:37:33 +01:00
alert ( " '.dol_escape_js( $langs->trans ( " FillFieldFirst " )).' " );
2021-09-07 10:39:41 +02:00
}
});
2021-09-18 19:34:46 +02:00
2021-09-07 10:39:41 +02:00
}) ' ;
print '</script>' ;
2014-03-06 21:21:16 +01:00
}
/* ************************************************************************** */
/* */
2015-11-02 06:42:17 +01:00
/* View mode */
2014-03-06 21:21:16 +01:00
/* */
/* ************************************************************************** */
2021-02-26 21:17:52 +01:00
if ( $id ) {
2020-04-10 10:59:32 +02:00
$head = salaries_prepare_head ( $object );
2022-01-24 16:06:02 +01:00
$formconfirm = '' ;
2014-03-06 21:21:16 +01:00
2021-03-01 11:12:03 +01:00
if ( $action === 'clone' ) {
2021-02-04 17:21:08 +01:00
$formquestion = array (
array ( 'type' => 'text' , 'name' => 'clone_label' , 'label' => $langs -> trans ( " Label " ), 'value' => $langs -> trans ( " CopyOf " ) . ' ' . $object -> label ),
);
//$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
$formquestion [] = array ( 'type' => 'date' , 'name' => 'clone_date_start' , 'label' => $langs -> trans ( " DateStart " ), 'value' => - 1 );
$formquestion [] = array ( 'type' => 'date' , 'name' => 'clone_date_end' , 'label' => $langs -> trans ( " DateEnd " ), 'value' => - 1 );
2022-01-24 16:06:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneSalary' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 , 240 );
2021-02-04 17:21:08 +01:00
}
2021-03-01 11:12:03 +01:00
if ( $action == 'paid' ) {
2021-02-04 17:21:08 +01:00
$text = $langs -> trans ( 'ConfirmPaySalary' );
2022-01-24 16:06:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( 'PaySalary' ), $text , " confirm_paid " , '' , '' , 2 );
2021-02-04 17:21:08 +01:00
}
2021-03-01 11:12:03 +01:00
if ( $action == 'delete' ) {
2021-02-04 17:21:08 +01:00
$text = $langs -> trans ( 'ConfirmDeleteSalary' );
2022-01-24 16:06:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteSalary' ), $text , 'confirm_delete' , '' , '' , 2 );
2021-02-04 17:21:08 +01:00
}
2021-03-01 11:12:03 +01:00
if ( $action == 'edit' ) {
2021-02-04 17:21:08 +01:00
print " <form name= \" charge \" action= \" " . $_SERVER [ " PHP_SELF " ] . " ?id= $object->id &action=update \" method= \" post \" > " ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
}
2022-01-24 16:06:02 +01:00
// Call Hook formConfirm
$parameters = array ( 'formConfirm' => $formconfirm );
$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 ;
2021-02-04 20:44:38 +01:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " SalaryPayment " ), - 1 , 'salary' );
2014-03-06 21:21:16 +01:00
2020-04-10 10:59:32 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/salaries/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-05-29 06:22:21 +02:00
2020-04-10 10:59:32 +02:00
$morehtmlref = '<div class="refidno">' ;
2017-05-29 06:22:21 +02:00
2021-03-03 14:13:36 +01:00
// Label
if ( $action != 'editlabel' ) {
$morehtmlref .= $form -> editfieldkey ( " Label " , 'label' , $object -> label , $object , $user -> rights -> salaries -> write , 'string' , '' , 0 , 1 );
$morehtmlref .= $object -> label ;
} else {
2021-09-28 19:40:41 +02:00
$morehtmlref .= $langs -> trans ( 'Label' ) . ' : ' ;
2021-03-03 14:13:36 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="setlabel">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= '<input type="text" name="label" value="' . $object -> label . '"/>' ;
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
}
2021-03-09 11:50:59 +01:00
2021-09-28 19:40:41 +02:00
// Employee
2021-03-09 10:58:11 +01:00
if ( $action != 'editfk_user' ) {
2021-03-09 11:48:25 +01:00
if ( $object -> getSommePaiement () > 0 && ! empty ( $object -> fk_user )) {
2021-03-03 16:36:21 +01:00
$userstatic = new User ( $db );
2021-03-08 10:09:38 +01:00
$result = $userstatic -> fetch ( $object -> fk_user );
2021-03-09 10:58:11 +01:00
if ( $result > 0 ) {
2022-01-03 12:26:57 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Employee' ) . ' : ' . $userstatic -> getNomUrl ( - 1 );
2021-03-09 10:55:10 +01:00
}
} else {
2021-03-10 15:38:01 +01:00
$morehtmlref .= '<br>' . $form -> editfieldkey ( " Employee " , 'fk_user' , $object -> label , $object , $user -> rights -> salaries -> write , 'string' , '' , 0 , 1 );
2021-03-09 10:55:10 +01:00
2021-03-09 10:58:11 +01:00
if ( ! empty ( $object -> fk_user )) {
2021-03-09 10:55:10 +01:00
$userstatic = new User ( $db );
$result = $userstatic -> fetch ( $object -> fk_user );
2021-03-09 10:58:11 +01:00
if ( $result > 0 ) {
2022-01-03 12:26:57 +01:00
$morehtmlref .= $userstatic -> getNomUrl ( - 1 );
2021-03-09 10:55:10 +01:00
} else {
dol_print_error ( $db );
exit ();
}
2021-03-08 10:09:38 +01:00
}
2021-03-03 16:36:21 +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>' ;
}
2018-07-31 07:45:03 +02:00
// Project
2022-08-29 10:56:06 +02:00
if ( isModEnabled ( 'project' )) {
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-26 21:17:52 +01:00
if ( $user -> rights -> salaries -> write ) {
2019-10-27 17:01:23 +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 17:01:23 +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);
2020-04-10 10:59:32 +02: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 () . '">' ;
2021-09-28 19:40:41 +02:00
$morehtmlref .= $formproject -> select_projects ( - 1 , $object -> fk_project , 'projectid' , 0 , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 , 0 , 'maxwidth500' );
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2019-10-27 17:01:23 +01:00
} else {
2020-04-10 10:59:32 +02:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-27 17:01:23 +01:00
}
2018-07-31 07:45:03 +02:00
} else {
2020-04-10 10:59:32 +02:00
if ( ! empty ( $object -> fk_project )) {
2018-07-31 07:45:03 +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 ;
}
2018-07-31 07:45:03 +02:00
} else {
2020-04-10 10:59:32 +02:00
$morehtmlref .= '' ;
2018-07-31 07:45:03 +02:00
}
}
}
2021-02-04 17:21:08 +01:00
2020-04-10 10:59:32 +02:00
$morehtmlref .= '</div>' ;
2017-05-29 06:22:21 +02:00
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
$object -> totalpaid = $totalpaid ;
2021-02-04 17:21:08 +01:00
2017-06-07 06:03:52 +02:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref , '' , 0 , '' , '' );
2017-05-29 06:22:21 +02:00
2017-06-07 06:03:52 +02:00
print '<div class="fichecenter">' ;
2021-02-04 17:21:08 +01:00
print '<div class="fichehalfleft">' ;
2017-04-06 23:28:06 +02:00
print '<div class="underbanner clearboth"></div>' ;
2021-02-04 20:44:38 +01:00
print '<table class="border centpercent tableforfield">' ;
2014-03-17 14:30:55 +01:00
2021-03-01 11:12:03 +01:00
if ( $action == 'edit' ) {
2021-04-11 22:40:07 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DateStartPeriod " ) . " </td><td> " ;
2021-02-04 17:21:08 +01:00
print $form -> selectDate ( $object -> datesp , 'datesp' , 0 , 0 , 0 , 'datesp' , 1 );
print " </td></tr> " ;
} else {
print " <tr> " ;
2021-04-11 22:40:07 +02:00
print '<td class="titlefield">' . $langs -> trans ( " DateStartPeriod " ) . '</td><td>' ;
2021-02-04 17:21:08 +01:00
print dol_print_date ( $object -> datesp , 'day' );
print '</td></tr>' ;
}
2014-03-06 21:21:16 +01:00
2021-03-01 11:12:03 +01:00
if ( $action == 'edit' ) {
2021-02-04 17:21:08 +01:00
print '<tr><td>' . $langs -> trans ( " DateEndPeriod " ) . " </td><td> " ;
print $form -> selectDate ( $object -> dateep , 'dateep' , 0 , 0 , 0 , 'dateep' , 1 );
print " </td></tr> " ;
} else {
print " <tr> " ;
print '<td>' . $langs -> trans ( " DateEndPeriod " ) . '</td><td>' ;
print dol_print_date ( $object -> dateep , 'day' );
print '</td></tr>' ;
}
2014-03-17 14:30:55 +01:00
2021-02-04 17:21:08 +01:00
/* print " <tr> " ;
2017-06-07 16:44:04 +02:00
print '<td>' . $langs -> trans ( " DatePayment " ) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> datep , 'day' );
2014-03-06 21:21:16 +01:00
print '</td></tr>' ;
2017-06-07 16:44:04 +02:00
print '<tr><td>' . $langs -> trans ( " DateValue " ) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> datev , 'day' );
2021-02-04 17:21:08 +01:00
print '</td></tr>' ; */
if ( $action == 'edit' ) {
2021-03-10 17:16:49 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Amount " ) . '</td><td><input name="amount" size="10" value="' . price ( $object -> amount ) . '"></td></tr>' ;
2021-02-04 17:21:08 +01:00
} else {
2021-08-06 13:07:07 +02:00
print '<tr><td>' . $langs -> trans ( " Amount " ) . '</td><td><span class="amount">' . price ( $object -> amount , 0 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</span></td></tr>' ;
2021-02-04 17:21:08 +01:00
}
2014-03-06 21:21:16 +01:00
2021-04-11 22:41:53 +02:00
// Default mode of payment
2021-02-04 17:21:08 +01:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
2021-04-11 22:41:53 +02:00
print $langs -> trans ( 'DefaultPaymentMode' );
2021-02-04 17:21:08 +01:00
print '</td>' ;
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-04 17:21:08 +01:00
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editmode' ) {
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> type_payment , 'mode_reglement_id' );
} else {
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> type_payment , 'none' );
}
print '</td></tr>' ;
2014-03-06 21:21:16 +01:00
2021-04-11 22:41:53 +02:00
// Default Bank Account
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-04 17:21:08 +01:00
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
2021-04-11 22:41:53 +02:00
print $langs -> trans ( 'DefaultBankAccount' );
2021-02-04 17:21:08 +01:00
print '<td>' ;
2021-03-04 17:57:08 +01:00
if ( $action != 'editbankaccount' && $user -> rights -> salaries -> write ) {
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-03-04 17:57:08 +01:00
}
2021-02-04 17:21:08 +01: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' );
2014-03-06 21:21:16 +01:00
}
2021-02-04 17:21:08 +01:00
print '</td>' ;
print '</tr>' ;
2014-03-06 21:21:16 +01:00
}
2020-10-31 14:32:18 +01:00
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2014-03-06 21:21:16 +01:00
print '</table>' ;
2017-05-29 06:35:53 +02:00
2017-04-06 23:28:06 +02:00
print '</div>' ;
2017-05-29 06:35:53 +02:00
2021-02-04 17:21:08 +01:00
print '<div class="fichehalfright">' ;
$nbcols = 3 ;
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-04 17:21:08 +01:00
$nbcols ++ ;
}
/*
* Payments
*/
2021-02-09 11:25:30 +01:00
$sql = " SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount, " ;
2021-02-04 17:21:08 +01:00
$sql .= " c.code as type_code,c.libelle as paiement_type, " ;
$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' ;
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_salary as p " ;
$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' ;
2021-02-09 11:25:30 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON p.fk_typepayment = c.id " ;
2021-02-04 17:21:08 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " salary as salaire " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE p.fk_salary = " . (( int ) $id );
2021-02-04 17:21:08 +01:00
$sql .= " AND p.fk_salary = salaire.rowid " ;
$sql .= " AND salaire.entity IN ( " . getEntity ( 'tax' ) . " ) " ;
$sql .= " ORDER BY dp DESC " ;
//print $sql;
$resql = $db -> query ( $sql );
2021-03-01 11:12:03 +01:00
if ( $resql ) {
2022-05-22 17:09:08 +02:00
$totalpaid = 0 ;
2021-02-04 17:21:08 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ; $total = 0 ;
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
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 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-04 17:21:08 +01:00
print '<td class="liste_titre right">' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
}
print '<td class="right">' . $langs -> trans ( " Amount " ) . '</td>' ;
print '</tr>' ;
2021-03-01 11:12:03 +01:00
if ( $num > 0 ) {
2021-02-04 17:21:08 +01:00
$bankaccountstatic = new Account ( $db );
2021-03-01 11:12:03 +01:00
while ( $i < $num ) {
2021-02-04 17:21:08 +01:00
$objp = $db -> fetch_object ( $resql );
print '<tr class="oddeven"><td>' ;
print '<a href="' . DOL_URL_ROOT . '/salaries/payment_salary/card.php?id=' . $objp -> rowid . '">' . img_object ( $langs -> trans ( " Payment " ), " payment " ) . ' ' . $objp -> rowid . '</a></td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . " </td> \n " ;
$labeltype = $langs -> trans ( " PaymentType " . $objp -> type_code ) != ( " PaymentType " . $objp -> type_code ) ? $langs -> trans ( " PaymentType " . $objp -> type_code ) : $objp -> paiement_type ;
print " <td> " . $labeltype . ' ' . $objp -> num_payment . " </td> \n " ;
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-04 17:21:08 +01:00
$bankaccountstatic -> id = $objp -> baid ;
$bankaccountstatic -> ref = $objp -> baref ;
$bankaccountstatic -> label = $objp -> baref ;
$bankaccountstatic -> number = $objp -> banumber ;
$bankaccountstatic -> currency_code = $objp -> bacurrency_code ;
2022-08-29 10:52:45 +02:00
if ( isModEnabled ( 'accounting' )) {
2021-02-04 17:21:08 +01:00
$bankaccountstatic -> account_number = $objp -> account_number ;
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $objp -> fk_accountancy_journal );
$bankaccountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
}
print '<td class="right">' ;
if ( $bankaccountstatic -> id )
print $bankaccountstatic -> getNomUrl ( 1 , 'transactions' );
print '</td>' ;
}
2022-08-30 16:37:29 +02:00
print '<td class="right nowrap amountcard">' . price ( $objp -> amount ) . " </td> \n " ;
2021-02-04 17:21:08 +01:00
print " </tr> " ;
2022-05-22 17:09:08 +02:00
$totalpaid += $objp -> amount ;
2021-02-04 17:21:08 +01:00
$i ++ ;
}
2021-03-04 19:20:16 +01:00
} else {
2021-02-04 17:21:08 +01:00
print '<tr class="oddeven"><td><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td>' ;
print '<td></td><td></td><td></td><td></td>' ;
print '</tr>' ;
}
2022-08-30 16:37:29 +02:00
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " AlreadyPaid " ) . " :</td><td class= \" right nowrap amountcard \" > " . price ( $totalpaid ) . " </td></tr> \n " ;
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " AmountExpected " ) . " :</td><td class= \" right nowrap amountcard \" > " . price ( $object -> amount ) . " </td></tr> \n " ;
2021-02-04 17:21:08 +01:00
2022-05-22 17:09:08 +02:00
$resteapayer = $object -> amount - $totalpaid ;
2021-02-04 17:21:08 +01:00
$cssforamountpaymentcomplete = 'amountpaymentcomplete' ;
print '<tr><td colspan="' . $nbcols . '" class="right">' . $langs -> trans ( " RemainderToPay " ) . " :</td> " ;
2022-08-30 16:37:29 +02:00
print '<td class="right nowrap' . ( $resteapayer ? ' amountremaintopay' : ( ' ' . $cssforamountpaymentcomplete )) . '">' . price ( $resteapayer ) . " </td></tr> \n " ;
2021-02-04 17:21:08 +01:00
print " </table> " ;
print '</div>' ;
$db -> free ( $resql );
2021-03-04 19:20:16 +01:00
} else {
2021-02-04 17:21:08 +01:00
dol_print_error ( $db );
}
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2021-11-29 19:39:03 +01:00
print dol_get_fiche_end ();
2014-03-06 21:21:16 +01:00
2021-03-01 11:12:03 +01:00
if ( $action == 'edit' ) {
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
print " </form> " ;
2021-02-04 17:21:08 +01:00
}
2021-11-29 19:39:03 +01:00
$resteapayer = price2num ( $resteapayer , 'MT' );
2017-06-07 16:44:04 +02:00
2022-02-07 09:50:07 +01:00
2021-03-16 04:22:55 +01:00
/*
* Action bar
*/
2021-04-02 23:23:44 +02:00
2015-05-13 08:57:00 +02:00
print '<div class="tabsAction">' . " \n " ;
2021-03-01 11:12:03 +01:00
if ( $action != 'edit' ) {
2021-02-04 17:21:08 +01:00
// Reopen
2021-03-01 11:12:03 +01:00
if ( $object -> paye && $user -> rights -> salaries -> write ) {
2022-03-18 16:12:38 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'ReOpen' ), 'default' , $_SERVER [ " PHP_SELF " ] . '?action=reopen&token=' . newToken () . '&id=' . $object -> id , '' );
2014-03-06 21:21:16 +01:00
}
2021-02-04 17:21:08 +01:00
// Edit
2021-03-01 11:12:03 +01:00
if ( $object -> paye == 0 && $user -> rights -> salaries -> write ) {
2022-03-18 16:12:38 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'Modify' ), 'default' , $_SERVER [ " PHP_SELF " ] . '?action=edit&token=' . newToken () . '&id=' . $object -> id , '' );
2021-02-04 17:21:08 +01:00
}
// Emit payment
2021-11-29 19:39:03 +01:00
if ( $object -> paye == 0 && (( price2num ( $object -> amount ) < 0 && $resteapayer < 0 ) || ( price2num ( $object -> amount ) > 0 && $resteapayer > 0 )) && $user -> rights -> salaries -> write ) {
2022-03-18 16:57:42 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'DoPayment' ), 'default' , DOL_URL_ROOT . '/salaries/paiement_salary.php?action=create&token=' . newToken () . '&id=' . $object -> id , '' );
2021-02-04 17:21:08 +01:00
}
// Classify 'paid'
2021-11-29 19:46:43 +01:00
// If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
if ( $object -> paye == 0 && (( $resteapayer <= 0 && $object -> amount > 0 ) || ( $object -> amount <= 0 )) && $user -> rights -> salaries -> write ) {
2022-03-18 16:12:38 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'ClassifyPaid' ), 'default' , $_SERVER [ " PHP_SELF " ] . '?action=paid&token=' . newToken () . '&id=' . $object -> id , '' );
2021-02-04 17:21:08 +01:00
}
// Clone
2021-03-01 11:12:03 +01:00
if ( $user -> rights -> salaries -> write ) {
2022-03-18 16:12:38 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'ToClone' ), 'default' , $_SERVER [ " PHP_SELF " ] . '?action=clone&token=' . newToken () . '&id=' . $object -> id , '' );
2021-02-04 17:21:08 +01:00
}
2022-05-22 17:09:08 +02:00
if ( ! empty ( $user -> rights -> salaries -> delete ) && empty ( $totalpaid )) {
2022-03-18 16:12:38 +01:00
print dolGetButtonAction ( '' , $langs -> trans ( 'Delete' ), 'delete' , $_SERVER [ " PHP_SELF " ] . '?action=delete&token=' . newToken () . '&id=' . $object -> id , '' );
2021-03-04 17:57:08 +01:00
} else {
2022-03-18 16:28:25 +01:00
print dolGetButtonAction ( $langs -> trans ( 'DisabledBecausePayments' ), $langs -> trans ( 'Delete' ), 'default' , $_SERVER [ 'PHP_SELF' ] . '#' , '' , false );
2014-03-06 21:21:16 +01:00
}
}
print " </div> " ;
2022-02-07 09:50:07 +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 -> salaries -> dir_output . '/' . $objref ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
//$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
$genallowed = 0 ; // If you can read, you can build the PDF to read content
$delallowed = $permissiontoadd ; // If you can create/edit, you can remove a file on card
print $formfile -> showdocuments ( 'salaries' , $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 ( 'salaries' ));
$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 );
2022-02-07 09:50:07 +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 = 'salary' ;
$defaulttopic = 'InformationMessage' ;
$diroutput = $conf -> salaries -> dir_output ;
$trackid = 'salary' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2014-03-06 21:21:16 +01:00
}
2018-08-08 12:29:36 +02:00
// End of page
2014-03-06 21:21:16 +01:00
llxFooter ();
2014-03-25 21:35:52 +01:00
$db -> close ();