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
257 $sql =
"SELECT fk_expensereport, COUNT(erd.rowid) as nb";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
259 $sql .=
" WHERE erd.fk_code_ventilation <= 0";
260 $sql .=
" AND erd.total_ttc <> 0";
261 $sql .=
" AND fk_expensereport IN (".$db->sanitize(implode(
",", array_keys($taber))).
")";
262 $sql .=
" GROUP BY fk_expensereport";
263 $resql = $db->query($sql);
265 $num = $db->num_rows($resql);
268 $obj = $db->fetch_object($resql);
270 $errorforinvoice[$obj->fk_expensereport] =
'somelinesarenotbound';
277if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
281 $userstatic =
new User($db);
285 $accountingaccountexpense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT'),
true);
287 foreach ($taber as $key => $val) {
295 $userstatic->id = $tabuser[$key][
'id'];
296 $userstatic->name = $tabuser[$key][
'name'];
297 $userstatic->accountancy_code = $tabuser[$key][
'user_accountancy_code'];
300 if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
303 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
307 if (!$errorforline) {
308 foreach ($tabttc[$key] as $k => $mt) {
311 $bookkeeping->doc_date = $val[
"date"];
312 $bookkeeping->doc_ref = $val[
"ref"];
313 $bookkeeping->date_creation = $now;
314 $bookkeeping->doc_type =
'expense_report';
315 $bookkeeping->fk_doc = $key;
316 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
318 $bookkeeping->subledger_account = $tabuser[$key][
'user_accountancy_code'];
319 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
322 $bookkeeping->label_compte = $accountingaccountexpense->label;
324 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"SubledgerAccount"));
325 $bookkeeping->montant = $mt;
326 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
327 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
328 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
329 $bookkeeping->code_journal = $journal;
330 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
331 $bookkeeping->fk_user_author = $user->id;
332 $bookkeeping->entity =
$conf->entity;
334 $totaldebit += $bookkeeping->debit;
335 $totalcredit += $bookkeeping->credit;
337 $result = $bookkeeping->create($user);
339 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
342 $errorforinvoice[$key] =
'alreadyjournalized';
347 $errorforinvoice[$key] =
'other';
356 if (!$errorforline) {
357 foreach ($tabht[$key] as $k => $mt) {
360 if ($accountingaccount->fetch(0, $k,
true)) {
362 $bookkeeping->doc_date = $val[
"date"];
363 $bookkeeping->doc_ref = $val[
"ref"];
364 $bookkeeping->date_creation = $now;
365 $bookkeeping->doc_type =
'expense_report';
366 $bookkeeping->fk_doc = $key;
367 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
369 $bookkeeping->subledger_account =
'';
370 $bookkeeping->subledger_label =
'';
372 $bookkeeping->numero_compte = $k;
373 $bookkeeping->label_compte = $accountingaccount->label;
375 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label);
376 $bookkeeping->montant = $mt;
377 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
378 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
379 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
380 $bookkeeping->code_journal = $journal;
381 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
382 $bookkeeping->fk_user_author = $user->id;
383 $bookkeeping->entity =
$conf->entity;
385 $totaldebit += $bookkeeping->debit;
386 $totalcredit += $bookkeeping->credit;
388 $result = $bookkeeping->create($user);
390 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
393 $errorforinvoice[$key] =
'alreadyjournalized';
398 $errorforinvoice[$key] =
'other';
408 if (!$errorforline) {
409 $listoftax = array(0, 1, 2);
410 foreach ($listoftax as $numtax) {
411 $arrayofvat = $tabtva;
413 $arrayofvat = $tablocaltax1;
416 $arrayofvat = $tablocaltax2;
419 foreach ($arrayofvat[$key] as $k => $mt) {
421 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
423 $accountingaccount->fetch(0, $k,
true);
424 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
426 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
429 $account_label = $accountingaccount->label;
433 $bookkeeping->doc_date = $val[
"date"];
434 $bookkeeping->doc_ref = $val[
"ref"];
435 $bookkeeping->date_creation = $now;
436 $bookkeeping->doc_type =
'expense_report';
437 $bookkeeping->fk_doc = $key;
438 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
440 $bookkeeping->subledger_account =
'';
441 $bookkeeping->subledger_label =
'';
443 $bookkeeping->numero_compte = $k;
444 $bookkeeping->label_compte = $account_label;
446 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
447 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
448 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
449 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $labelvataccount);
451 $bookkeeping->montant = $mt;
452 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
453 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
454 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
455 $bookkeeping->code_journal = $journal;
456 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
457 $bookkeeping->fk_user_author = $user->id;
458 $bookkeeping->entity =
$conf->entity;
460 $totaldebit += $bookkeeping->debit;
461 $totalcredit += $bookkeeping->credit;
463 $result = $bookkeeping->create($user);
465 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
468 $errorforinvoice[$key] =
'alreadyjournalized';
473 $errorforinvoice[$key] =
'other';
483 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
486 $errorforinvoice[$key] =
'amountsnotbalanced';
487 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.',
null,
'errors');
490 if (!$errorforline) {
496 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
504 if (empty($error) && count($tabpay) > 0) {
506 } elseif (count($tabpay) == $error) {
509 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
515 if (count($tabpay) != $error) {
516 $param =
'id_journal='.$id_journal;
517 $param .=
'&date_startday='.$date_startday;
518 $param .=
'&date_startmonth='.$date_startmonth;
519 $param .=
'&date_startyear='.$date_startyear;
520 $param .=
'&date_endday='.$date_endday;
521 $param .=
'&date_endmonth='.$date_endmonth;
522 $param .=
'&date_endyear='.$date_endyear;
523 $param .=
'&in_bookkeeping='.$in_bookkeeping;
525 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
535$form =
new Form($db);
537$userstatic =
new User($db);
540if ($action ==
'exportcsv' && !$error) {
543 $filename =
'journal';
544 $type_export =
'journal';
545 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
547 $userstatic =
new User($db);
551 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
552 print
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
553 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
554 print
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
555 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
556 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
559 foreach ($taber as $key => $val) {
562 $userstatic->id = $tabuser[$key][
'id'];
563 $userstatic->name = $tabuser[$key][
'name'];
566 foreach ($tabht[$key] as $k => $mt) {
568 $accountingaccount->fetch(0, $k,
true);
570 print
'"'.$date.
'"'.$sep;
571 print
'"'.$val[
"ref"].
'"'.$sep;
572 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
573 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label)).
'"'.$sep;
574 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
575 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
581 foreach ($tabtva[$key] as $k => $mt) {
583 print
'"'.$date.
'"'.$sep;
584 print
'"'.$val[
"ref"].
'"'.$sep;
585 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
586 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %')).
'"'.$sep;
587 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
588 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
594 foreach ($tabttc[$key] as $k => $mt) {
595 print
'"'.$date.
'"'.$sep;
596 print
'"'.$val[
"ref"].
'"'.$sep;
597 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
598 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"Thirdparty"))).
'"'.$sep;
599 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
600 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"';
606if (empty($action) || $action ==
'view') {
607 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
608 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
609 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-expensereportsjournal');
616 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
618 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
619 $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);
620 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
622 $varlink =
'id_journal='.$id_journal;
624 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
629 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
630 $resql = $db->query($sql);
632 $obj = $db->fetch_object($resql);
634 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
635 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
636 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
647 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
648 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
649 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
653 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
655 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
656 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
659 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
661 if ($in_bookkeeping ==
'notyet') {
662 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
664 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
671 <script type="text/javascript">
672 function launch_export() {
673 $("div.fiche form input[name=\"action\"]").val("exportcsv");
674 $("div.fiche form input[type=\"submit\"]").click();
675 $("div.fiche form input[name=\"action\"]").val("");
677 function writebookkeeping() {
678 console.log("click on writebookkeeping");
679 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
680 $("div.fiche form input[type=\"submit\"]").click();
681 $("div.fiche form input[name=\"action\"]").val("");
691 print
'<div class="div-table-responsive">';
692 print
"<table class=\"noborder\" width=\"100%\">";
693 print
"<tr class=\"liste_titre\">";
694 print
"<td>".$langs->trans(
"Date").
"</td>";
695 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
696 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
697 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
698 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
699 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
700 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
709 foreach ($taber as $key => $val) {
710 $expensereportstatic->id = $key;
711 $expensereportstatic->ref = $val[
"ref"];
712 $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
716 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
717 print
'<tr class="oddeven">';
718 print
"<!-- Some lines are not bound -->";
719 print
"<td>".$date.
"</td>";
720 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
723 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
730 print
'<td class="right"></td>';
731 print
'<td class="right"></td>';
738 foreach ($tabht[$key] as $k => $mt) {
739 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
741 $accountingaccount->fetch(0, $k,
true);
742 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
744 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
748 print
'<tr class="oddeven">';
749 print
"<!-- Fees -->";
750 print
"<td>".$date.
"</td>";
751 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
752 $userstatic->id = $tabuser[$key][
'id'];
753 $userstatic->name = $tabuser[$key][
'name'];
757 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
758 print
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
766 $userstatic->id = $tabuser[$key][
'id'];
767 $userstatic->name = $tabuser[$key][
'name'];
768 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $accountingaccount->label, 1) .
"</td>";
769 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
770 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
778 foreach ($tabttc[$key] as $k => $mt) {
779 $userstatic->id = $tabuser[$key][
'id'];
780 $userstatic->name = $tabuser[$key][
'name'];
782 print
'<tr class="oddeven">';
783 print
"<!-- Thirdparty -->";
784 print
"<td>".$date.
"</td>";
785 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
789 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
790 print
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
798 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
799 print
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
804 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
805 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
806 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
813 $listoftax = array(0, 1, 2);
814 foreach ($listoftax as $numtax) {
815 $arrayofvat = $tabtva;
817 $arrayofvat = $tablocaltax1;
820 $arrayofvat = $tablocaltax2;
823 foreach ($arrayofvat[$key] as $k => $mt) {
825 print
'<tr class="oddeven">';
826 print
"<!-- VAT -->";
827 print
"<td>".$date.
"</td>";
828 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
832 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
833 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
841 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
842 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
843 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
844 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $labelvatrate, 1) .
"</td>";
845 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
846 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
857 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.
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 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.