26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
32 $langs->loadLangs(array(
'bills',
'banks',
'trips'));
36 $action =
GETPOST(
'action',
'aZ09');
38 $accountid =
GETPOST(
'accountid',
'int');
44 $socid = $user->socid;
52 if ($action ==
'add_payment')
58 $loc = DOL_URL_ROOT.
'/expensereport/card.php?id='.$id;
59 header(
"Location: ".$loc);
64 $result = $expensereport->fetch($id, $ref);
71 $datepaid =
dol_mktime(12, 0, 0, $_POST[
"remonth"], $_POST[
"reday"], $_POST[
"reyear"]);
73 if (!($_POST[
"fk_typepayment"] > 0))
75 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")), null,
'errors');
80 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")), null,
'errors');
83 if (!empty($conf->banque->enabled) && !($accountid > 0))
85 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToDebit")), null,
'errors');
95 foreach ($_POST as $key => $value)
97 if (substr($key, 0, 7) ==
'amount_')
99 $amounts[$expensereport->fk_user_author] =
price2num($_POST[$key]);
104 if (count($amounts) <= 0)
107 $errmsg =
'ErrorNoPaymentDefined';
116 $payment->fk_expensereport = $expensereport->id;
117 $payment->datepaid = $datepaid;
118 $payment->amounts = $amounts;
119 $payment->total = $total;
120 $payment->fk_typepayment =
GETPOST(
"fk_typepayment",
'int');
121 $payment->num_payment =
GETPOST(
"num_payment",
'alphanothtml');
122 $payment->note_public =
GETPOST(
"note_public",
'restricthtml');
126 $paymentid = $payment->create($user);
136 $result = $payment->addPaymentToBank($user,
'payment_expensereport',
'(ExpenseReportPayment)', $accountid,
'',
'');
145 $payment->fetch($paymentid);
146 if ($expensereport->total_ttc - $payment->amount == 0) {
147 $result = $expensereport->set_paid($expensereport->id, $user);
158 $loc = DOL_URL_ROOT.
'/expensereport/card.php?id='.$id;
159 header(
'Location: '.$loc);
177 $form =
new Form($db);
181 if ($action ==
'create' || empty($action))
184 $expensereport->fetch($id, $ref);
186 $total = $expensereport->total_ttc;
189 if (!empty($conf->use_javascript_ajax)) {
190 print "\n".
'<script type="text/javascript" language="javascript">';
192 print ' $(document).ready(function () {';
193 print ' $(".AutoFillAmount").on(\'click touchstart\', function(){
194 var amount = $(this).data("value");
195 document.getElementById($(this).data(\'rowid\')).value = amount ;
203 print '<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
204 print '<input type="hidden" name="token" value="'.newToken().
'">';
205 print '<input type="hidden" name="id" value="'.$expensereport->id.
'">';
206 print '<input type="hidden" name="chid" value="'.$expensereport->id.
'">';
207 print '<input type="hidden" name="action" value="add_payment">';
214 dol_banner_tab($expensereport,
'ref', $linkback, 1,
'ref',
'ref',
'');
216 print '<div class="fichecenter">';
217 print '<div class="underbanner clearboth"></div>';
219 print '<table class="border centpercent">'.
"\n";
221 print '<tr><td class="titlefield">'.$langs->trans(
"Period").
'</td><td>'.
get_date_range($expensereport->date_debut, $expensereport->date_fin,
"", $langs, 0).
'</td></tr>';
222 print '<tr><td>'.$langs->trans(
"Amount").
'</td><td>'.
price($expensereport->total_ttc, 0, $outputlangs, 1, -1, -1, $conf->currency).
'</td></tr>';
224 $sql =
"SELECT sum(p.amount) as total";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as p, ".MAIN_DB_PREFIX.
"expensereport as e";
226 $sql .=
" WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id;
227 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
228 $resql = $db->query($sql);
231 $obj = $db->fetch_object(
$resql);
232 $sumpaid = $obj->total;
235 print '<tr><td>'.$langs->trans(
"AlreadyPaid").
'</td><td>'.
price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).
'</td></tr>';
236 print '<tr><td class="tdtop">'.$langs->trans(
"RemainderToPay").
'</td><td>'.
price($total - $sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).
'</td></tr>';
246 print '<table class="border centpercent">'.
"\n";
248 print '<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
250 $datepayment = ($datepaid ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datepaid);
251 print $form->selectDate($datepayment,
'',
'',
'', 0,
"add_payment", 1, 1);
255 print '<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
256 $form->select_types_paiements(
GETPOSTISSET(
"fk_typepayment") ?
GETPOST(
"fk_typepayment",
'alpha') : $expensereport->fk_c_paiement,
"fk_typepayment");
260 if (!empty($conf->banque->enabled))
263 print '<td class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</td>';
264 print '<td colspan="2">';
265 $form->select_comptes(
GETPOSTISSET(
"accountid") ?
GETPOST(
"accountid",
"int") : $expensereport->accountid,
"accountid", 0,
'', 2);
270 print '<tr><td>'.$langs->trans(
'Numero');
271 print ' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
273 print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment').
'"></td></tr>'.
"\n";
276 print '<td class="tdtop">'.$langs->trans(
"Comments").
'</td>';
277 print '<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
290 print '<table class="noborder centpercent">';
291 print '<tr class="liste_titre">';
292 print '<td>'.$langs->trans(
"ExpenseReport").
'</td>';
293 print '<td class="right">'.$langs->trans(
"Amount").
'</td>';
294 print '<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
295 print '<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
296 print '<td class="center">'.$langs->trans(
"Amount").
'</td>';
304 $objp = $expensereport;
306 print '<tr class="oddeven">';
308 print '<td>'.$expensereport->getNomUrl(1).
"</td>";
309 print '<td class="right">'.price($objp->total_ttc).
"</td>";
310 print '<td class="right">'.price($sumpaid).
"</td>";
311 print '<td class="right">'.price($objp->total_ttc - $sumpaid).
"</td>";
312 print '<td class="center">';
313 if ($sumpaid < $objp->total_ttc)
315 $namef =
"amount_".$objp->id;
316 $nameRemain =
"remain_".$objp->id;
317 if (!empty($conf->use_javascript_ajax))
318 print img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowid='".$namef.
"' data-value='".($objp->total_ttc - $sumpaid).
"'");
319 $remaintopay = $objp->total_ttc - $sumpaid;
320 print '<input type=hidden class="sum_remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
321 print '<input type="text" size="8" name="'.$namef.
'" id="'.$namef.
'">';
329 $total += $objp->total;
330 $total_ttc += $objp->total_ttc;
331 $totalrecu += $objp->am;
337 print '<tr class="oddeven">';
338 print '<td colspan="2" class="left">'.$langs->trans(
"Total").
':</td>';
339 print '<td class="right"><b>'.price($total_ttc).
'</b></td>';
340 print '<td class="right"><b>'.price($totalrecu).
'</b></td>';
341 print '<td class="right"><b>'.price($total_ttc - $totalrecu).
'</b></td>';
342 print '<td class="center"> </td>';
348 print '<br><div class="center">';
349 print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
350 print ' ';
351 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
get_date_range($date_start, $date_end, $format= '', $outputlangs= '', $withparenthesis=1)
Format output for start and end date.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Class to manage Trips and Expenses.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.