2011-10-28 12:17:53 +02:00
< ? php
2018-09-09 09:56:33 +02:00
/* Copyright ( C ) 2011 - 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2011-10-28 12:17:53 +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
2011-10-28 12:17:53 +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 />.
2011-10-28 12:17:53 +02:00
*/
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / compta / localtax / card . php
2011-10-28 12:17:53 +02:00
* \ingroup tax
2016-03-25 14:49:48 +01:00
* \brief Page of second or third tax payments ( like IRPF for spain , ... )
2011-10-28 12:17:53 +02:00
*/
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/localtax/class/localtax.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2018-04-28 18:43:29 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/vat.lib.php' ;
2011-10-28 12:17:53 +02:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'compta' , 'banks' , 'bills' ));
2011-10-28 12:17:53 +02:00
2020-04-10 10:59:32 +02:00
$id = GETPOST ( " id " , 'int' );
2022-04-24 18:39:26 +02:00
$action = GETPOST ( " action " , " aZ09 " );
$cancel = GETPOST ( 'cancel' , 'aZ09' );
2021-03-25 16:59:47 +01:00
2020-04-10 10:59:32 +02:00
$refund = GETPOST ( " refund " , " int " );
2021-02-23 21:09:01 +01:00
if ( empty ( $refund )) {
$refund = 0 ;
}
2016-03-25 14:49:48 +01:00
2020-04-10 10:59:32 +02:00
$lttype = GETPOST ( 'localTaxType' , 'int' );
2011-10-28 12:17:53 +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 ;
}
2011-10-28 12:17:53 +02:00
$result = restrictedArea ( $user , 'tax' , '' , '' , 'charges' );
2018-04-28 18:43:29 +02:00
$object = new Localtax ( $db );
2016-03-25 14:49:48 +01:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2020-04-10 10:59:32 +02:00
$hookmanager -> initHooks ( array ( 'localtaxvatcard' , 'globalcard' ));
2016-03-25 14:49:48 +01:00
/**
2012-08-27 18:00:59 +02:00
* Actions
2011-10-28 12:17:53 +02:00
*/
2021-03-25 16:59:47 +01:00
if ( $cancel && ! $id ) {
2018-03-15 10:24:45 +01:00
header ( " Location: list.php?localTaxType= " . $lttype );
2014-07-04 12:50:55 +02:00
exit ;
}
2021-10-20 19:33:28 +02:00
if ( $action == 'add' && ! $cancel ) {
2020-10-27 19:46:07 +01:00
$db -> begin ();
2011-10-28 12:17:53 +02:00
2021-03-25 16:59:47 +01:00
$datev = dol_mktime ( 12 , 0 , 0 , GETPOST ( " datevmonth " ), GETPOST ( " datevday " ), GETPOST ( " datevyear " ));
$datep = dol_mktime ( 12 , 0 , 0 , GETPOST ( " datepmonth " ), GETPOST ( " datepday " ), GETPOST ( " datepyear " ));
2019-11-14 12:09:15 +01:00
2021-03-25 16:59:47 +01:00
$object -> accountid = GETPOST ( " accountid " , 'int' );
2020-10-27 19:46:07 +01:00
$object -> paymenttype = GETPOST ( " paiementtype " );
$object -> datev = $datev ;
$object -> datep = $datep ;
$object -> amount = price2num ( GETPOST ( " amount " ));
2019-11-14 12:09:15 +01:00
$object -> label = GETPOST ( " label " );
$object -> ltt = $lttype ;
2020-10-27 19:46:07 +01:00
$ret = $object -> addPayment ( $user );
2021-02-23 21:09:01 +01:00
if ( $ret > 0 ) {
2020-10-27 19:46:07 +01:00
$db -> commit ();
header ( " Location: list.php?localTaxType= " . $lttype );
exit ;
} else {
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$_GET [ " action " ] = " create " ;
}
2011-10-28 12:17:53 +02:00
}
//delete payment of localtax
2021-02-23 21:09:01 +01:00
if ( $action == 'delete' ) {
2020-10-27 19:46:07 +01:00
$result = $object -> fetch ( $id );
2011-10-28 12:17:53 +02:00
2021-02-23 21:09:01 +01:00
if ( $object -> rappro == 0 ) {
2020-10-27 19:46:07 +01:00
$db -> begin ();
2011-10-28 12:17:53 +02:00
2020-10-27 19:46:07 +01:00
$ret = $object -> delete ( $user );
2021-02-23 21:09:01 +01:00
if ( $ret > 0 ) {
if ( $object -> fk_bank ) {
2019-11-14 12:09:15 +01:00
$accountline = new AccountLine ( $db );
$result = $accountline -> fetch ( $object -> fk_bank );
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
$result = $accountline -> delete ( $user ); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
}
2011-10-28 12:17:53 +02:00
}
2021-02-23 21:09:01 +01:00
if ( $result >= 0 ) {
2011-10-28 12:17:53 +02:00
$db -> commit ();
2018-04-28 18:43:29 +02:00
header ( " Location: " . DOL_URL_ROOT . '/compta/localtax/list.php?localTaxType=' . $object -> ltt );
2011-10-28 12:17:53 +02:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-14 12:09:15 +01:00
$object -> error = $accountline -> error ;
2011-10-28 12:17:53 +02:00
$db -> rollback ();
2018-04-28 18:43:29 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2011-10-28 12:17:53 +02:00
}
2020-10-27 19:46:07 +01:00
} else {
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-27 19:46:07 +01:00
$mesg = 'Error try do delete a line linked to a conciliated bank transaction' ;
setEventMessages ( $mesg , null , 'errors' );
2011-10-28 12:17:53 +02:00
}
}
/*
2018-04-28 18:43:29 +02:00
* View
*/
2011-10-28 12:17:53 +02:00
2021-02-23 21:09:01 +01:00
if ( $id ) {
2018-04-28 18:43:29 +02:00
$result = $object -> fetch ( $id );
2021-02-23 21:09:01 +01:00
if ( $result <= 0 ) {
2011-10-28 12:17:53 +02:00
dol_print_error ( $db );
exit ;
}
}
2018-04-28 18:43:29 +02:00
$form = new Form ( $db );
2019-11-14 12:09:15 +01:00
$title = $langs -> trans ( " LT " . $object -> ltt ) . " - " . $langs -> trans ( " Card " );
$help_url = '' ;
2022-04-24 18:39:26 +02:00
llxHeader ( '' , $title , $helpurl );
2018-04-28 18:43:29 +02:00
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2020-10-27 19:46:07 +01:00
print load_fiche_titre ( $langs -> transcountry ( $lttype == 2 ? " newLT2Payment " : " newLT1Payment " , $mysoc -> country_code ));
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" name="formlocaltax" method="post">' . " \n " ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="localTaxType" value="' . $lttype . '">' ;
print '<input type="hidden" name="action" value="add">' ;
2011-10-28 12:17:53 +02:00
2020-10-27 19:46:07 +01:00
print dol_get_fiche_head ();
2011-10-28 12:17:53 +02:00
2020-10-27 19:46:07 +01:00
print '<table class="border centpercent">' ;
2011-10-28 12:17:53 +02:00
2022-04-24 18:39:26 +02:00
// Date of payment
2020-10-27 19:46:07 +01:00
print " <tr> " ;
print '<td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " DatePayment " ) . '</td><td>' ;
print $form -> selectDate ( $datep , " datep " , '' , '' , '' , 'add' , 1 , 1 );
print '</td></tr>' ;
2011-10-28 12:17:53 +02:00
2022-04-24 18:39:26 +02:00
// End date of period
2020-10-27 19:46:07 +01:00
print '<tr><td class="fieldrequired">' . $form -> textwithpicto ( $langs -> trans ( " PeriodEndDate " ), $langs -> trans ( " LastDayTaxIsRelatedTo " )) . '</td><td>' ;
print $form -> selectDate ( $datev , " datev " , '' , '' , '' , 'add' , 1 , 1 );
print '</td></tr>' ;
2011-10-28 12:17:53 +02:00
// Label
2021-03-25 16:59:47 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Label " ) . '</td><td><input name="label" class="minwidth200" value="' . ( GETPOSTISSET ( " label " ) ? GETPOST ( " label " , '' , 2 ) : $langs -> transcountry (( $lttype == 2 ? " LT2Payment " : " LT1Payment " ), $mysoc -> country_code )) . '"></td></tr>' ;
2011-10-28 12:17:53 +02:00
// Amount
2016-12-18 13:27:14 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Amount " ) . '</td><td><input name="amount" size="10" value="' . GETPOST ( " amount " ) . '"></td></tr>' ;
2011-10-28 12:17:53 +02:00
2022-08-29 11:24:54 +02:00
if ( isModEnabled ( 'banque' )) {
2022-04-24 18:39:26 +02:00
// Type payment
2020-10-31 14:32:18 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " PaymentMode " ) . '</td><td>' ;
2022-04-28 18:46:52 +02:00
$form -> select_types_paiements ( GETPOST ( " paiementtype " ), " paiementtype " , '' , 0 , 1 , 0 , 0 , 1 , 'maxwidth500 widthcentpercentminusx' );
2020-10-31 14:32:18 +01:00
print " </td> \n " ;
print " </tr> " ;
2022-04-28 18:46:52 +02:00
2022-04-24 18:39:26 +02:00
// Bank account
print '<tr><td class="fieldrequired" id="label_fk_account">' . $langs -> trans ( " Account " ) . '</td><td>' ;
print img_picto ( '' , 'bank_account' , 'pictofixedwidth' );
$form -> select_comptes ( GETPOST ( " accountid " , " int " ), " accountid " , 0 , " courant=1 " , 2 , '' , 0 , 'maxwidth500 widthcentpercentminusx' ); // Affiche liste des comptes courant
print '</td></tr>' ;
2017-06-07 16:44:04 +02:00
2016-03-25 14:49:48 +01:00
// Number
print '<tr><td>' . $langs -> trans ( 'Numero' );
print ' <em>(' . $langs -> trans ( " ChequeOrTransferNumber " ) . ')</em>' ;
print '<td><input name="num_payment" type="text" value="' . GETPOST ( " num_payment " ) . '"></td></tr>' . " \n " ;
2020-10-31 14:32:18 +01:00
}
2022-04-24 18:39:26 +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 ;
2016-03-25 14:49:48 +01:00
2020-10-31 14:32:18 +01:00
print '</table>' ;
2011-10-28 12:17:53 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2011-10-28 12:17:53 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2011-10-28 12:17:53 +02:00
2020-10-31 14:32:18 +01:00
print '</form>' ;
2011-10-28 12:17:53 +02:00
}
2018-04-28 18:43:29 +02:00
// View mode
2021-02-23 21:09:01 +01:00
if ( $id ) {
2011-10-28 12:17:53 +02:00
$h = 0 ;
2018-04-28 18:43:29 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/localtax/card.php?id=' . $object -> id ;
2011-10-28 12:17:53 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Card' );
$head [ $h ][ 2 ] = 'card' ;
$h ++ ;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> transcountry ( " LT " . $object -> ltt , $mysoc -> country_code ), - 1 , 'payment' );
2011-10-28 12:17:53 +02:00
2018-04-28 18:43:29 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/localtax/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref , '' , 0 , '' , '' );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2011-10-28 12:17:53 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2011-10-28 12:17:53 +02:00
print " <tr> " ;
2018-04-28 18:43:29 +02:00
print '<td class="titlefield">' . $langs -> trans ( " Ref " ) . '</td><td>' ;
print $object -> ref ;
2011-10-28 12:17:53 +02:00
print '</td></tr>' ;
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' );
2011-10-28 12:17:53 +02:00
print '</td></tr>' ;
2018-04-28 18:43:29 +02:00
print '<tr><td>' . $form -> textwithpicto ( $langs -> trans ( " PeriodEndDate " ), $langs -> trans ( " LastDayTaxIsRelatedTo " )) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> datev , 'day' );
2011-10-28 12:17:53 +02:00
print '</td></tr>' ;
2018-04-28 18:43:29 +02:00
print '<tr><td>' . $langs -> trans ( " Amount " ) . '</td><td>' . price ( $object -> amount ) . '</td></tr>' ;
2011-10-28 12:17:53 +02:00
2022-08-29 11:24:54 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
if ( $object -> fk_account > 0 ) {
$bankline = new AccountLine ( $db );
2020-10-31 14:32:18 +01:00
$bankline -> fetch ( $object -> fk_bank );
2011-10-28 12:17:53 +02:00
2020-10-31 14:32:18 +01:00
print '<tr>' ;
print '<td>' . $langs -> trans ( 'BankTransactionLine' ) . '</td>' ;
2017-06-07 16:44:04 +02:00
print '<td>' ;
2019-01-27 11:55:16 +01:00
print $bankline -> getNomUrl ( 1 , 0 , 'showall' );
2020-10-31 14:32:18 +01:00
print '</td>' ;
print '</tr>' ;
2011-10-28 12:17:53 +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 ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
print '</table>' ;
2011-10-28 12:17:53 +02:00
2020-10-31 14:32:18 +01:00
print '</div>' ;
2018-04-28 18:43:29 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2017-06-07 16:44:04 +02:00
2011-10-28 12:17:53 +02:00
/*
2021-03-16 04:22:55 +01:00
* Action bar
2018-04-28 18:43:29 +02:00
*/
2011-10-28 12:17:53 +02:00
print " <div class= \" tabsAction \" > \n " ;
2021-02-23 21:09:01 +01:00
if ( $object -> rappro == 0 ) {
2020-10-01 10:50:54 +02:00
print '<a class="butActionDelete" href="card.php?id=' . $object -> id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( " Delete " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " LinkedToAConcialitedTransaction " ) . '">' . $langs -> trans ( " Delete " ) . '</a>' ;
2018-04-28 18:43:29 +02:00
}
2011-10-28 12:17:53 +02:00
print " </div> " ;
}
2018-08-08 12:29:36 +02:00
// End of page
2011-10-28 12:17:53 +02:00
llxFooter ();
2015-12-11 14:19:38 +01:00
$db -> close ();