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';
52$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"trips",
"errors"));
55$action =
GETPOST(
'action',
'aZ09');
57$date_startmonth =
GETPOSTINT(
'date_startmonth');
63$in_bookkeeping =
GETPOST(
'in_bookkeeping');
64if ($in_bookkeeping ==
'') {
65 $in_bookkeeping =
'notyet';
70$hookmanager->initHooks(array(
'expensereportsjournal'));
77$tablocaltax1 = array();
78$tablocaltax2 = array();
82if (!isModEnabled(
'accounting')) {
85if ($user->socid > 0) {
88if (!$user->hasRight(
'accounting',
'bind',
'write')) {
93$errorforinvoice = array();
104$accountingjournalstatic->fetch($id_journal);
105$journal = $accountingjournalstatic->code;
106$journal_label = $accountingjournalstatic->label;
108$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
109$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
112$pastmonthyear =
null;
114if (empty($date_startmonth)) {
117 $date_start = $dates[
'date_start'];
118 $pastmonthyear = $dates[
'pastmonthyear'];
119 $pastmonth = $dates[
'pastmonth'];
121if (empty($date_endmonth)) {
124 $date_end = $dates[
'date_end'];
125 $pastmonthyear = $dates[
'pastmonthyear'];
126 $pastmonth = $dates[
'pastmonth'];
129if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
134$sql =
"SELECT er.rowid, er.ref, er.date_debut as de, er.date_fin as df,";
135$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, ";
136$sql .=
" u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
137$sql .=
" f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
138$parameters = array();
139$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
140$sql .= $hookmanager->resPrint;
141$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
142$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
143$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
144$sql .=
" JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
145$sql .=
" JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
146$parameters = array();
147$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
148$sql .= $hookmanager->resPrint;
149$sql .=
" WHERE er.fk_statut > 0";
150$sql .=
" AND erd.fk_code_ventilation > 0";
151$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
152if ($date_start && $date_end) {
153 $sql .=
" AND er.date_debut >= '".$db->idate($date_start).
"' AND er.date_debut <= '".$db->idate($date_end).
"'";
157 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
160if ($in_bookkeeping ==
'already') {
161 $sql .=
" AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
163if ($in_bookkeeping ==
'notyet') {
164 $sql .=
" AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
166$parameters = array();
167$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
168$sql .= $hookmanager->resPrint;
169$sql .=
" ORDER BY er.date_debut";
171dol_syslog(
'accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
172$result = $db->query($sql);
179 $tablocaltax1 = array();
180 $tablocaltax2 = array();
183 $num = $db->num_rows($result);
186 $account_salary =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
188 $noTaxDispatchingKeepWithLines =
getDolGlobalInt(
'ACCOUNTING_EXPENSEREPORT_DO_NOT_DISPATCH_TAXES');
192 $obj = $db->fetch_object($result);
195 $compta_user = (!empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
196 $compta_fees = $obj->compte;
198 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
199 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
200 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
201 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
204 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
205 $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.
')' :
''));
209 $taber[$obj->rowid][
"date"] = $db->jdate($obj->df);
211 $taber[$obj->rowid][
"date"] = $db->jdate($obj->de);
213 $taber[$obj->rowid][
"ref"] = $obj->ref;
214 $taber[$obj->rowid][
"comments"] = $obj->comments;
215 $taber[$obj->rowid][
"fk_expensereportdet"] = $obj->erdid;
218 if (!isset($tabttc[$obj->rowid][$compta_user])) {
219 $tabttc[$obj->rowid][$compta_user] = 0;
221 if (!isset($tabht[$obj->rowid][$compta_fees])) {
222 $tabht[$obj->rowid][$compta_fees] = 0;
224 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
225 $tabtva[$obj->rowid][$compta_tva] = 0;
227 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
228 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
230 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
231 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
234 $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
235 if ($noTaxDispatchingKeepWithLines) {
236 $tabht[$obj->rowid][$compta_fees] += $obj->total_ttc;
238 $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
239 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
240 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
241 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
243 $tabuser[$obj->rowid] = array(
246 'user_accountancy_code' => $obj->user_accountancy_account
256$sql =
"SELECT fk_expensereport, COUNT(erd.rowid) as nb";
257$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
258$sql .=
" WHERE erd.fk_code_ventilation <= 0";
259$sql .=
" AND erd.total_ttc <> 0";
260$sql .=
" AND fk_expensereport IN (".$db->sanitize(implode(
",", array_keys($taber))).
")";
261$sql .=
" GROUP BY fk_expensereport";
262$resql = $db->query($sql);
264$num = $db->num_rows($resql);
267 $obj = $db->fetch_object($resql);
269 $errorforinvoice[$obj->fk_expensereport] =
'somelinesarenotbound';
275if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
279 $userstatic =
new User($db);
283 $accountingaccountexpense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT'),
true);
285 foreach ($taber as $key => $val) {
293 $userstatic->id = $tabuser[$key][
'id'];
294 $userstatic->name = $tabuser[$key][
'name'];
295 $userstatic->accountancy_code = $tabuser[$key][
'user_accountancy_code'];
298 if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
301 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
305 if (!$errorforline) {
306 foreach ($tabttc[$key] as $k => $mt) {
309 $bookkeeping->doc_date = $val[
"date"];
310 $bookkeeping->doc_ref = $val[
"ref"];
311 $bookkeeping->date_creation = $now;
312 $bookkeeping->doc_type =
'expense_report';
313 $bookkeeping->fk_doc = $key;
314 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
316 $bookkeeping->subledger_account = $tabuser[$key][
'user_accountancy_code'];
317 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
320 $bookkeeping->label_compte = $accountingaccountexpense->label;
322 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"SubledgerAccount"));
323 $bookkeeping->montant = $mt;
324 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
325 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
326 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
327 $bookkeeping->code_journal = $journal;
328 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
329 $bookkeeping->fk_user_author = $user->id;
330 $bookkeeping->entity =
$conf->entity;
332 $totaldebit += $bookkeeping->debit;
333 $totalcredit += $bookkeeping->credit;
335 $result = $bookkeeping->create($user);
337 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
340 $errorforinvoice[$key] =
'alreadyjournalized';
345 $errorforinvoice[$key] =
'other';
354 if (!$errorforline) {
355 foreach ($tabht[$key] as $k => $mt) {
358 if ($accountingaccount->fetch(0, $k,
true)) {
360 $bookkeeping->doc_date = $val[
"date"];
361 $bookkeeping->doc_ref = $val[
"ref"];
362 $bookkeeping->date_creation = $now;
363 $bookkeeping->doc_type =
'expense_report';
364 $bookkeeping->fk_doc = $key;
365 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
367 $bookkeeping->subledger_account =
'';
368 $bookkeeping->subledger_label =
'';
370 $bookkeeping->numero_compte = $k;
371 $bookkeeping->label_compte = $accountingaccount->label;
373 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label);
374 $bookkeeping->montant = $mt;
375 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
376 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
377 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
378 $bookkeeping->code_journal = $journal;
379 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
380 $bookkeeping->fk_user_author = $user->id;
381 $bookkeeping->entity =
$conf->entity;
383 $totaldebit += $bookkeeping->debit;
384 $totalcredit += $bookkeeping->credit;
386 $result = $bookkeeping->create($user);
388 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
391 $errorforinvoice[$key] =
'alreadyjournalized';
396 $errorforinvoice[$key] =
'other';
406 if (!$errorforline) {
407 $listoftax = array(0, 1, 2);
408 foreach ($listoftax as $numtax) {
409 $arrayofvat = $tabtva;
411 $arrayofvat = $tablocaltax1;
414 $arrayofvat = $tablocaltax2;
417 foreach ($arrayofvat[$key] as $k => $mt) {
419 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
421 $accountingaccount->fetch(0, $k,
true);
422 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
424 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
427 $account_label = $accountingaccount->label;
431 $bookkeeping->doc_date = $val[
"date"];
432 $bookkeeping->doc_ref = $val[
"ref"];
433 $bookkeeping->date_creation = $now;
434 $bookkeeping->doc_type =
'expense_report';
435 $bookkeeping->fk_doc = $key;
436 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
438 $bookkeeping->subledger_account =
'';
439 $bookkeeping->subledger_label =
'';
441 $bookkeeping->numero_compte = $k;
442 $bookkeeping->label_compte = $account_label;
444 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
445 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
446 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
447 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $labelvataccount);
449 $bookkeeping->montant = $mt;
450 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
451 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
452 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
453 $bookkeeping->code_journal = $journal;
454 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
455 $bookkeeping->fk_user_author = $user->id;
456 $bookkeeping->entity =
$conf->entity;
458 $totaldebit += $bookkeeping->debit;
459 $totalcredit += $bookkeeping->credit;
461 $result = $bookkeeping->create($user);
463 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
466 $errorforinvoice[$key] =
'alreadyjournalized';
471 $errorforinvoice[$key] =
'other';
481 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
484 $errorforinvoice[$key] =
'amountsnotbalanced';
485 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.',
null,
'errors');
488 if (!$errorforline) {
494 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
502 if (empty($error) && count($tabpay) > 0) {
504 } elseif (count($tabpay) == $error) {
507 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
513 if (count($tabpay) != $error) {
514 $param =
'id_journal='.$id_journal;
515 $param .=
'&date_startday='.$date_startday;
516 $param .=
'&date_startmonth='.$date_startmonth;
517 $param .=
'&date_startyear='.$date_startyear;
518 $param .=
'&date_endday='.$date_endday;
519 $param .=
'&date_endmonth='.$date_endmonth;
520 $param .=
'&date_endyear='.$date_endyear;
521 $param .=
'&in_bookkeeping='.$in_bookkeeping;
523 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
533$form =
new Form($db);
535$userstatic =
new User($db);
538if ($action ==
'exportcsv' && !$error) {
541 $filename =
'journal';
542 $type_export =
'journal';
543 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
545 $userstatic =
new User($db);
549 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
550 print
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
551 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
552 print
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
553 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
554 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
557 foreach ($taber as $key => $val) {
560 $userstatic->id = $tabuser[$key][
'id'];
561 $userstatic->name = $tabuser[$key][
'name'];
564 foreach ($tabht[$key] as $k => $mt) {
566 $accountingaccount->fetch(0, $k,
true);
568 print
'"'.$date.
'"'.$sep;
569 print
'"'.$val[
"ref"].
'"'.$sep;
570 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
571 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label)).
'"'.$sep;
572 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
573 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
579 foreach ($tabtva[$key] as $k => $mt) {
581 print
'"'.$date.
'"'.$sep;
582 print
'"'.$val[
"ref"].
'"'.$sep;
583 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
584 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %')).
'"'.$sep;
585 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
586 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
592 foreach ($tabttc[$key] as $k => $mt) {
593 print
'"'.$date.
'"'.$sep;
594 print
'"'.$val[
"ref"].
'"'.$sep;
595 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
596 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"Thirdparty"))).
'"'.$sep;
597 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
598 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"';
604if (empty($action) || $action ==
'view') {
605 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
606 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
607 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-expensereportsjournal');
614 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
616 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
617 $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);
618 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
620 $varlink =
'id_journal='.$id_journal;
622 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
627 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
628 $resql = $db->query($sql);
630 $obj = $db->fetch_object($resql);
632 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
633 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
634 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
645 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
646 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
647 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
651 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
653 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
654 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
657 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
659 if ($in_bookkeeping ==
'notyet') {
660 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
662 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
669 <script type="text/javascript">
670 function launch_export() {
671 $("div.fiche form input[name=\"action\"]").val("exportcsv");
672 $("div.fiche form input[type=\"submit\"]").click();
673 $("div.fiche form input[name=\"action\"]").val("");
675 function writebookkeeping() {
676 console.log("click on writebookkeeping");
677 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
678 $("div.fiche form input[type=\"submit\"]").click();
679 $("div.fiche form input[name=\"action\"]").val("");
689 print
'<div class="div-table-responsive">';
690 print
"<table class=\"noborder\" width=\"100%\">";
691 print
"<tr class=\"liste_titre\">";
692 print
"<td>".$langs->trans(
"Date").
"</td>";
693 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
694 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
695 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
696 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
697 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
698 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
707 foreach ($taber as $key => $val) {
708 $expensereportstatic->id = $key;
709 $expensereportstatic->ref = $val[
"ref"];
710 $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
714 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
715 print
'<tr class="oddeven">';
716 print
"<!-- Some lines are not bound -->";
717 print
"<td>".$date.
"</td>";
718 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
721 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
728 print
'<td class="right"></td>';
729 print
'<td class="right"></td>';
736 foreach ($tabht[$key] as $k => $mt) {
737 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
739 $accountingaccount->fetch(0, $k,
true);
740 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
742 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
746 print
'<tr class="oddeven">';
747 print
"<!-- Fees -->";
748 print
"<td>".$date.
"</td>";
749 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
750 $userstatic->id = $tabuser[$key][
'id'];
751 $userstatic->name = $tabuser[$key][
'name'];
755 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
756 print
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
764 $userstatic->id = $tabuser[$key][
'id'];
765 $userstatic->name = $tabuser[$key][
'name'];
766 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $accountingaccount->label) .
"</td>";
767 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
768 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
776 foreach ($tabttc[$key] as $k => $mt) {
777 $userstatic->id = $tabuser[$key][
'id'];
778 $userstatic->name = $tabuser[$key][
'name'];
780 print
'<tr class="oddeven">';
781 print
"<!-- Thirdparty -->";
782 print
"<td>".$date.
"</td>";
783 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
787 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
788 print
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
796 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
797 print
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
802 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $langs->trans(
"SubledgerAccount")) .
"</td>";
803 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
804 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
811 $listoftax = array(0, 1, 2);
812 foreach ($listoftax as $numtax) {
813 $arrayofvat = $tabtva;
815 $arrayofvat = $tablocaltax1;
818 $arrayofvat = $tablocaltax2;
821 foreach ($arrayofvat[$key] as $k => $mt) {
823 print
'<tr class="oddeven">';
824 print
"<!-- VAT -->";
825 print
"<td>".$date.
"</td>";
826 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
830 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
831 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
839 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
840 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
841 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
842 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $labelvatrate) .
"</td>";
843 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
844 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
855 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.