32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
43$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"trips",
"errors"));
46$action =
GETPOST(
'action',
'aZ09');
48$date_startmonth =
GETPOST(
'date_startmonth');
49$date_startday =
GETPOST(
'date_startday');
50$date_startyear =
GETPOST(
'date_startyear');
51$date_endmonth =
GETPOST(
'date_endmonth');
52$date_endday =
GETPOST(
'date_endday');
53$date_endyear =
GETPOST(
'date_endyear');
54$in_bookkeeping =
GETPOST(
'in_bookkeeping');
55if ($in_bookkeeping ==
'') {
56 $in_bookkeeping =
'notyet';
61$hookmanager->initHooks(array(
'expensereportsjournal'));
68$tablocaltax1 = array();
69$tablocaltax2 = array();
72if (!isModEnabled(
'accounting')) {
75if ($user->socid > 0) {
78if (!$user->hasRight(
'accounting',
'bind',
'write')) {
83$errorforinvoice = array();
94$accountingjournalstatic->fetch($id_journal);
95$journal = $accountingjournalstatic->code;
96$journal_label = $accountingjournalstatic->label;
98$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
99$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
102$pastmonthyear =
null;
104if (empty($date_startmonth)) {
107 $date_start = $dates[
'date_start'];
108 $pastmonthyear = $dates[
'pastmonthyear'];
109 $pastmonth = $dates[
'pastmonth'];
111if (empty($date_endmonth)) {
114 $date_end = $dates[
'date_end'];
115 $pastmonthyear = $dates[
'pastmonthyear'];
116 $pastmonth = $dates[
'pastmonth'];
119if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
124$sql =
"SELECT er.rowid, er.ref, er.date_debut as de, er.date_fin as df,";
125$sql .=
" erd.rowid as erdid, erd.comments, erd.total_ht, erd.total_tva, erd.total_localtax1, erd.total_localtax2, erd.tva_tx, erd.total_ttc, erd.fk_code_ventilation, erd.vat_src_code, ";
126$sql .=
" u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
127$sql .=
" f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
128$parameters = array();
129$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
130$sql .= $hookmanager->resPrint;
131$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
132$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
133$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
134$sql .=
" JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
135$sql .=
" JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
136$parameters = array();
137$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
138$sql .= $hookmanager->resPrint;
139$sql .=
" WHERE er.fk_statut > 0";
140$sql .=
" AND erd.fk_code_ventilation > 0";
141$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
142if ($date_start && $date_end) {
143 $sql .=
" AND er.date_debut >= '".$db->idate($date_start).
"' AND er.date_debut <= '".$db->idate($date_end).
"'";
147 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
150if ($in_bookkeeping ==
'already') {
151 $sql .=
" AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
153if ($in_bookkeeping ==
'notyet') {
154 $sql .=
" AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
156$parameters = array();
157$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
158$sql .= $hookmanager->resPrint;
159$sql .=
" ORDER BY er.date_debut";
161dol_syslog(
'accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
162$result = $db->query($sql);
169 $tablocaltax1 = array();
170 $tablocaltax2 = array();
173 $num = $db->num_rows($result);
176 $account_salary =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
181 $obj = $db->fetch_object($result);
184 $compta_user = (!empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
185 $compta_fees = $obj->compte;
187 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
188 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
189 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
190 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
193 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
194 $def_tva[$obj->rowid][$compta_tva][
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'')] = (
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
198 $taber[$obj->rowid][
"date"] = $db->jdate($obj->df);
200 $taber[$obj->rowid][
"date"] = $db->jdate($obj->de);
202 $taber[$obj->rowid][
"ref"] = $obj->ref;
203 $taber[$obj->rowid][
"comments"] = $obj->comments;
204 $taber[$obj->rowid][
"fk_expensereportdet"] = $obj->erdid;
207 if (!isset($tabttc[$obj->rowid][$compta_user])) {
208 $tabttc[$obj->rowid][$compta_user] = 0;
210 if (!isset($tabht[$obj->rowid][$compta_fees])) {
211 $tabht[$obj->rowid][$compta_fees] = 0;
213 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
214 $tabtva[$obj->rowid][$compta_tva] = 0;
216 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
217 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
219 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
220 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
223 $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
224 $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
225 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
226 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
227 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
228 $tabuser[$obj->rowid] = array(
231 'user_accountancy_code' => $obj->user_accountancy_account
241$sql =
"SELECT fk_expensereport, COUNT(erd.rowid) as nb";
242$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
243$sql .=
" WHERE erd.fk_code_ventilation <= 0";
244$sql .=
" AND erd.total_ttc <> 0";
245$sql .=
" AND fk_expensereport IN (".$db->sanitize(implode(
",", array_keys($taber))).
")";
246$sql .=
" GROUP BY fk_expensereport";
247$resql = $db->query($sql);
249$num = $db->num_rows($resql);
252 $obj = $db->fetch_object($resql);
254 $errorforinvoice[$obj->fk_expensereport] =
'somelinesarenotbound';
260if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
264 $userstatic =
new User($db);
268 $accountingaccountexpense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT'),
true);
270 foreach ($taber as $key => $val) {
278 $userstatic->id = $tabuser[$key][
'id'];
279 $userstatic->name = $tabuser[$key][
'name'];
280 $userstatic->accountancy_code = $tabuser[$key][
'user_accountancy_code'];
283 if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
286 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
290 if (!$errorforline) {
291 foreach ($tabttc[$key] as $k => $mt) {
294 $bookkeeping->doc_date = $val[
"date"];
295 $bookkeeping->doc_ref = $val[
"ref"];
296 $bookkeeping->date_creation = $now;
297 $bookkeeping->doc_type =
'expense_report';
298 $bookkeeping->fk_doc = $key;
299 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
301 $bookkeeping->subledger_account = $tabuser[$key][
'user_accountancy_code'];
302 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
305 $bookkeeping->label_compte = $accountingaccountexpense->label;
307 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"SubledgerAccount"));
308 $bookkeeping->montant = $mt;
309 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
310 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
311 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
312 $bookkeeping->code_journal = $journal;
313 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
314 $bookkeeping->fk_user_author = $user->id;
315 $bookkeeping->entity = $conf->entity;
317 $totaldebit += $bookkeeping->debit;
318 $totalcredit += $bookkeeping->credit;
320 $result = $bookkeeping->create($user);
322 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
325 $errorforinvoice[$key] =
'alreadyjournalized';
330 $errorforinvoice[$key] =
'other';
339 if (!$errorforline) {
340 foreach ($tabht[$key] as $k => $mt) {
343 if ($accountingaccount->fetch(0, $k,
true)) {
345 $bookkeeping->doc_date = $val[
"date"];
346 $bookkeeping->doc_ref = $val[
"ref"];
347 $bookkeeping->date_creation = $now;
348 $bookkeeping->doc_type =
'expense_report';
349 $bookkeeping->fk_doc = $key;
350 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
352 $bookkeeping->subledger_account =
'';
353 $bookkeeping->subledger_label =
'';
355 $bookkeeping->numero_compte = $k;
356 $bookkeeping->label_compte = $accountingaccount->label;
358 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label);
359 $bookkeeping->montant = $mt;
360 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
361 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
362 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
363 $bookkeeping->code_journal = $journal;
364 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
365 $bookkeeping->fk_user_author = $user->id;
366 $bookkeeping->entity = $conf->entity;
368 $totaldebit += $bookkeeping->debit;
369 $totalcredit += $bookkeeping->credit;
371 $result = $bookkeeping->create($user);
373 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
376 $errorforinvoice[$key] =
'alreadyjournalized';
381 $errorforinvoice[$key] =
'other';
391 if (!$errorforline) {
392 $listoftax = array(0, 1, 2);
393 foreach ($listoftax as $numtax) {
394 $arrayofvat = $tabtva;
396 $arrayofvat = $tablocaltax1;
399 $arrayofvat = $tablocaltax2;
402 foreach ($arrayofvat[$key] as $k => $mt) {
404 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
406 $accountingaccount->fetch(0, $k,
true);
407 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
409 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
412 $account_label = $accountingaccount->label;
416 $bookkeeping->doc_date = $val[
"date"];
417 $bookkeeping->doc_ref = $val[
"ref"];
418 $bookkeeping->date_creation = $now;
419 $bookkeeping->doc_type =
'expense_report';
420 $bookkeeping->fk_doc = $key;
421 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
423 $bookkeeping->subledger_account =
'';
424 $bookkeeping->subledger_label =
'';
426 $bookkeeping->numero_compte = $k;
427 $bookkeeping->label_compte = $account_label;
429 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
430 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
431 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
432 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $labelvataccount);
434 $bookkeeping->montant = $mt;
435 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
436 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
437 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
438 $bookkeeping->code_journal = $journal;
439 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
440 $bookkeeping->fk_user_author = $user->id;
441 $bookkeeping->entity = $conf->entity;
443 $totaldebit += $bookkeeping->debit;
444 $totalcredit += $bookkeeping->credit;
446 $result = $bookkeeping->create($user);
448 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
451 $errorforinvoice[$key] =
'alreadyjournalized';
456 $errorforinvoice[$key] =
'other';
466 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
469 $errorforinvoice[$key] =
'amountsnotbalanced';
470 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.',
null,
'errors');
473 if (!$errorforline) {
479 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
487 if (empty($error) && count($tabpay) > 0) {
489 } elseif (count($tabpay) == $error) {
492 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
498 if (count($tabpay) != $error) {
499 $param =
'id_journal='.$id_journal;
500 $param .=
'&date_startday='.$date_startday;
501 $param .=
'&date_startmonth='.$date_startmonth;
502 $param .=
'&date_startyear='.$date_startyear;
503 $param .=
'&date_endday='.$date_endday;
504 $param .=
'&date_endmonth='.$date_endmonth;
505 $param .=
'&date_endyear='.$date_endyear;
506 $param .=
'&in_bookkeeping='.$in_bookkeeping;
508 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
518$form =
new Form($db);
520$userstatic =
new User($db);
523if ($action ==
'exportcsv' && !$error) {
526 $filename =
'journal';
527 $type_export =
'journal';
528 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
530 $userstatic =
new User($db);
534 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
535 print
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
536 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
537 print
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
538 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
539 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
542 foreach ($taber as $key => $val) {
545 $userstatic->id = $tabuser[$key][
'id'];
546 $userstatic->name = $tabuser[$key][
'name'];
549 foreach ($tabht[$key] as $k => $mt) {
551 $accountingaccount->fetch(0, $k,
true);
553 print
'"'.$date.
'"'.$sep;
554 print
'"'.$val[
"ref"].
'"'.$sep;
555 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
556 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label)).
'"'.$sep;
557 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
558 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
564 foreach ($tabtva[$key] as $k => $mt) {
566 print
'"'.$date.
'"'.$sep;
567 print
'"'.$val[
"ref"].
'"'.$sep;
568 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
569 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %')).
'"'.$sep;
570 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
571 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
577 foreach ($tabttc[$key] as $k => $mt) {
578 print
'"'.$date.
'"'.$sep;
579 print
'"'.$val[
"ref"].
'"'.$sep;
580 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
581 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"Thirdparty"))).
'"'.$sep;
582 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
583 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"';
589if (empty($action) || $action ==
'view') {
590 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
591 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
592 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-expensereportsjournal');
599 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
601 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
602 $period = $form->selectDate($date_start ? $date_start : -1,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end ? $date_end : -1,
'date_end', 0, 0, 0,
'', 1, 0);
603 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
605 $varlink =
'id_journal='.$id_journal;
607 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
612 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
613 $resql = $db->query($sql);
615 $obj = $db->fetch_object($resql);
617 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
618 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
619 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
630 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
631 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
632 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
636 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
638 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
639 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
642 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
644 if ($in_bookkeeping ==
'notyet') {
645 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
647 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
654 <script type="text/javascript">
655 function launch_export() {
656 $("div.fiche form input[name=\"action\"]").val("exportcsv");
657 $("div.fiche form input[type=\"submit\"]").click();
658 $("div.fiche form input[name=\"action\"]").val("");
660 function writebookkeeping() {
661 console.log("click on writebookkeeping");
662 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
663 $("div.fiche form input[type=\"submit\"]").click();
664 $("div.fiche form input[name=\"action\"]").val("");
674 print
'<div class="div-table-responsive">';
675 print
"<table class=\"noborder\" width=\"100%\">";
676 print
"<tr class=\"liste_titre\">";
677 print
"<td>".$langs->trans(
"Date").
"</td>";
678 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
679 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
680 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
681 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
682 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
683 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
692 foreach ($taber as $key => $val) {
693 $expensereportstatic->id = $key;
694 $expensereportstatic->ref = $val[
"ref"];
695 $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
699 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
700 print
'<tr class="oddeven">';
701 print
"<!-- Some lines are not bound -->";
702 print
"<td>".$date.
"</td>";
703 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
706 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
713 print
'<td class="right"></td>';
714 print
'<td class="right"></td>';
721 foreach ($tabht[$key] as $k => $mt) {
722 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
724 $accountingaccount->fetch(0, $k,
true);
725 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
727 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
731 print
'<tr class="oddeven">';
732 print
"<!-- Fees -->";
733 print
"<td>".$date.
"</td>";
734 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
735 $userstatic->id = $tabuser[$key][
'id'];
736 $userstatic->name = $tabuser[$key][
'name'];
740 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
741 print
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
749 $userstatic->id = $tabuser[$key][
'id'];
750 $userstatic->name = $tabuser[$key][
'name'];
751 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $accountingaccount->label) .
"</td>";
752 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
753 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
761 foreach ($tabttc[$key] as $k => $mt) {
762 $userstatic->id = $tabuser[$key][
'id'];
763 $userstatic->name = $tabuser[$key][
'name'];
765 print
'<tr class="oddeven">';
766 print
"<!-- Thirdparty -->";
767 print
"<td>".$date.
"</td>";
768 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
772 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
773 print
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
781 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
782 print
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
787 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $langs->trans(
"SubledgerAccount")) .
"</td>";
788 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
789 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
796 $listoftax = array(0, 1, 2);
797 foreach ($listoftax as $numtax) {
798 $arrayofvat = $tabtva;
800 $arrayofvat = $tablocaltax1;
803 $arrayofvat = $tablocaltax2;
806 foreach ($arrayofvat[$key] as $k => $mt) {
808 print
'<tr class="oddeven">';
809 print
"<!-- VAT -->";
810 print
"<td>".$date.
"</td>";
811 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
815 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
816 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
824 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
825 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
826 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
827 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $labelvatrate) .
"</td>";
828 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
829 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
840 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='', $moreoptions=array())
Show header of a page used to transfer/dispatch data in accounting.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
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 accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class to manage Trips and Expenses.
Class of expense report details lines.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.