28require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
41$langs->loadLangs(array(
'bills',
'banks',
'trips'));
45$action =
GETPOST(
'action',
'aZ09');
61if ($user->isExternalUser()) {
62 $socid = $user->isExternalUser();
67$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
74if ($action ==
'add_payment' && $permissiontoadd) {
78 $loc = DOL_URL_ROOT.
'/expensereport/card.php?id='.
$id;
79 header(
"Location: ".$loc);
84 $result = $expensereport->fetch($id, $ref);
93 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")),
null,
'errors');
96 if ($datepaid ==
'') {
97 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")),
null,
'errors');
102 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToDebit")),
null,
'errors');
111 foreach ($_POST as $key => $value) {
112 if (substr($key, 0, 7) ==
'amount_') {
114 $amounts[$expensereport->fk_user_author] = (float)
price2num(
GETPOST($key));
120 if (count($amounts) <= 0) {
130 $payment->fk_expensereport = $expensereport->id;
131 $payment->datep = $datepaid;
132 $payment->amounts = $amounts;
135 $payment->fk_typepayment =
GETPOSTINT(
"fk_typepayment");
136 $payment->num_payment =
GETPOST(
"num_payment",
'alphanohtml');
137 $payment->note_public =
GETPOST(
"note_public",
'restricthtml');
138 $payment->fk_bank = $accountid;
141 $paymentid = $payment->create($user);
142 if ($paymentid < 0) {
149 $result = $payment->addPaymentToBank($user,
'payment_expensereport',
'(ExpenseReportPayment)', $accountid,
'',
'');
157 $payment->fetch($paymentid);
158 if ($expensereport->total_ttc - $payment->amount == 0) {
159 $result = $expensereport->setPaid($expensereport->id, $user);
160 if (!($result > 0)) {
169 $loc = DOL_URL_ROOT.
'/expensereport/card.php?id='.
$id;
170 header(
'Location: '.$loc);
192if ($action ==
'create' || empty($action)) {
194 $expensereport->fetch($id, $ref);
196 $total = $expensereport->total_ttc;
199 if (!empty(
$conf->use_javascript_ajax)) {
200 print
"\n".
'<script type="text/javascript">';
202 print
' $(document).ready(function () {';
203 print
' $(".AutoFillAmount").on(\'click touchstart\', function(){
204 var amount = $(this).data("value");
205 document.getElementById($(this).data(\'rowid\')).value = amount ;
213 print
'<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
214 print
'<input type="hidden" name="token" value="'.newToken().
'">';
215 print
'<input type="hidden" name="id" value="'.$expensereport->id.
'">';
216 print
'<input type="hidden" name="chid" value="'.$expensereport->id.
'">';
217 print
'<input type="hidden" name="action" value="add_payment">';
224 dol_banner_tab($expensereport,
'ref', $linkback, 1,
'ref',
'ref',
'');
226 print
'<div class="fichecenter">';
227 print
'<div class="underbanner clearboth"></div>';
229 print
'<table class="border centpercent">'.
"\n";
231 print
'<tr><td class="titlefield">'.$langs->trans(
"Period").
'</td><td>'.
get_date_range($expensereport->date_debut, $expensereport->date_fin,
"", $langs, 0).
'</td></tr>';
232 print
'<tr><td>'.$langs->trans(
"Amount").
'</td><td><span class="amount">'.
price($expensereport->total_ttc, 0, $langs, 1, -1, -1,
$conf->currency).
'</span></td></tr>';
234 $sql =
"SELECT sum(p.amount) as total";
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as p, ".MAIN_DB_PREFIX.
"expensereport as e";
236 $sql .=
" WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".((int) $id);
237 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
239 $resql =
$db->query($sql);
241 $obj =
$db->fetch_object($resql);
242 $sumpaid = $obj->total;
245 print
'<tr><td>'.$langs->trans(
"AlreadyPaid").
'</td><td><span class="amount">'.
price($sumpaid, 0, $langs, 1, -1, -1,
$conf->currency).
'</span></td></tr>';
246 print
'<tr><td class="tdtop">'.$langs->trans(
"RemainderToPay").
'</td><td><span class="amount">'.
price($total - $sumpaid, 0, $langs, 1, -1, -1,
$conf->currency).
'</span></td></tr>';
258 print
'<table class="border centpercent">'.
"\n";
260 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
262 $datepayment = ($datepaid ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datepaid);
263 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_payment", 1, 1);
267 print
'<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
268 $form->select_types_paiements(GETPOSTISSET(
"fk_typepayment") ?
GETPOST(
"fk_typepayment",
'alpha') : $expensereport->fk_c_paiement,
"fk_typepayment");
274 print
'<td class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</td>';
275 print
'<td colspan="2">';
276 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
277 $form->select_comptes(GETPOSTISSET(
"accountid") ?
GETPOSTINT(
"accountid") : 0,
"accountid", 0,
'', 2);
282 print
'<tr><td>'.$langs->trans(
'Numero');
283 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
285 print
'<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment').
'"></td></tr>'.
"\n";
288 print
'<td class="tdtop">'.$langs->trans(
"Comments").
'</td>';
289 print
'<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
302 print
'<table class="noborder centpercent">';
303 print
'<tr class="liste_titre">';
304 print
'<td>'.$langs->trans(
"ExpenseReport").
'</td>';
305 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
306 print
'<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
307 print
'<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
308 print
'<td class="center">'.$langs->trans(
"Amount").
'</td>';
315 $objp = $expensereport;
317 print
'<tr class="oddeven">';
319 print
'<td>'.$expensereport->getNomUrl(1).
"</td>";
320 print
'<td class="right">'.price($objp->total_ttc).
"</td>";
321 print
'<td class="right">'.price($sumpaid).
"</td>";
322 print
'<td class="right">'.price($objp->total_ttc - $sumpaid).
"</td>";
323 print
'<td class="center">';
324 if ($sumpaid < $objp->total_ttc) {
325 $namef =
"amount_".$objp->id;
326 $nameRemain =
"remain_".$objp->id;
327 if (!empty(
$conf->use_javascript_ajax)) {
328 print
img_picto(
"Auto fill",
'rightarrow.png',
"class='AutoFillAmount' data-rowid='".$namef.
"' data-value='".($objp->total_ttc - $sumpaid).
"'");
330 $remaintopay = $objp->total_ttc - $sumpaid;
331 print
'<input type=hidden class="sum_remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
332 print
'<input type="text" class="width75" name="'.$namef.
'" id="'.$namef.
'" value="'.
GETPOST($namef).
'">';
340 $total_ttc += $objp->total_ttc;
341 $totalrecu += $sumpaid;
346 print
'<tr class="oddeven">';
347 print
'<td colspan="2" class="left">'.$langs->trans(
"Total").
':</td>';
348 print
'<td class="right"><b>'.price($total_ttc).
'</b></td>';
349 print
'<td class="right"><b>'.price($totalrecu).
'</b></td>';
350 print
'<td class="right"><b>'.price($total_ttc - $totalrecu).
'</b></td>';
351 print
'<td class="center"> </td>';
357 print $form->buttonsSaveCancel();
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage Trips and Expenses.
Class to manage payments of expense report.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.