34require
'../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
53$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"trips"));
56$action =
GETPOST(
'action',
'aZ09');
58$date_startmonth =
GETPOSTINT(
'date_startmonth');
64$in_bookkeeping =
GETPOST(
'in_bookkeeping');
65if ($in_bookkeeping ==
'') {
66 $in_bookkeeping =
'notyet';
71$hookmanager->initHooks(array(
'expensereportsjournal'));
78$tablocaltax1 = array();
79$tablocaltax2 = array();
86if ($user->socid > 0) {
89if (!$user->hasRight(
'accounting',
'bind',
'write')) {
94$errorforinvoice = array();
105$accountingjournalstatic->fetch($id_journal);
106$journal = $accountingjournalstatic->code;
107$journal_label = $accountingjournalstatic->label;
110$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
113$pastmonthyear =
null;
115if (empty($date_startmonth)) {
119 $pastmonthyear = $dates[
'pastmonthyear'];
120 $pastmonth = $dates[
'pastmonth'];
122if (empty($date_endmonth)) {
125 $date_end = $dates[
'date_end'];
126 $pastmonthyear = $dates[
'pastmonthyear'];
127 $pastmonth = $dates[
'pastmonth'];
130if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
132 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
135$sql =
"SELECT er.rowid, er.ref, er.date_debut as de, er.date_fin as df,";
136$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, ";
137$sql .=
" u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
138$sql .=
" f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
139$parameters = array();
140$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
141$sql .= $hookmanager->resPrint;
142$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
143$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
144$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
145$sql .=
" JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
146$sql .=
" JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
147$parameters = array();
148$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
149$sql .= $hookmanager->resPrint;
150$sql .=
" WHERE er.fk_statut > 0";
151$sql .=
" AND erd.fk_code_ventilation > 0";
152$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
153if ($date_start && $date_end) {
154 $sql .=
" AND er.date_debut >= '".$db->idate($date_start).
"' AND er.date_debut <= '".$db->idate($date_end).
"'";
158 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
161if ($in_bookkeeping ==
'already') {
162 $sql .=
" AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
164if ($in_bookkeeping ==
'notyet') {
165 $sql .=
" AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
167$parameters = array();
168$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
169$sql .= $hookmanager->resPrint;
170$sql .=
" ORDER BY er.date_debut";
172dol_syslog(
'accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
173$result = $db->query($sql);
180 $tablocaltax1 = array();
181 $tablocaltax2 = array();
184 $num = $db->num_rows($result);
187 $account_salary =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
189 $noTaxDispatchingKeepWithLines =
getDolGlobalInt(
'ACCOUNTING_EXPENSEREPORT_DO_NOT_DISPATCH_TAXES');
193 $obj = $db->fetch_object($result);
196 $compta_user = (!empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
197 $compta_fees = $obj->compte;
200 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
201 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
202 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
205 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
206 $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.
')' :
''));
210 $taber[$obj->rowid][
"date"] = $db->jdate($obj->df);
212 $taber[$obj->rowid][
"date"] = $db->jdate($obj->de);
214 $taber[$obj->rowid][
"ref"] = $obj->ref;
215 $taber[$obj->rowid][
"comments"] = $obj->comments;
216 $taber[$obj->rowid][
"fk_expensereportdet"] = $obj->erdid;
219 if (!isset($tabttc[$obj->rowid][$compta_user])) {
220 $tabttc[$obj->rowid][$compta_user] = 0;
222 if (!isset($tabht[$obj->rowid][$compta_fees])) {
223 $tabht[$obj->rowid][$compta_fees] = 0;
225 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
226 $tabtva[$obj->rowid][$compta_tva] = 0;
228 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
229 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
231 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
232 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
235 $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
236 if ($noTaxDispatchingKeepWithLines) {
237 $tabht[$obj->rowid][$compta_fees] += $obj->total_ttc;
239 $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
240 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
241 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
242 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
244 $tabuser[$obj->rowid] = array(
247 'user_accountancy_code' => $obj->user_accountancy_account
253 dol_print_error($db);
258 $sql =
"SELECT fk_expensereport, COUNT(erd.rowid) as nb";
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
260 $sql .=
" WHERE erd.fk_code_ventilation <= 0";
261 $sql .=
" AND erd.total_ttc <> 0";
262 $sql .=
" AND fk_expensereport IN (".$db->sanitize(implode(
",", array_keys($taber))).
")";
263 $sql .=
" GROUP BY fk_expensereport";
264 $resql = $db->query($sql);
266 $num = $db->num_rows($resql);
269 $obj = $db->fetch_object($resql);
271 $errorforinvoice[$obj->fk_expensereport] =
'somelinesarenotbound';
278if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
282 $userstatic =
new User($db);
286 $accountingaccountexpense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT'),
true);
288 foreach ($taber as $key => $val) {
296 $userstatic->id = $tabuser[$key][
'id'];
297 $userstatic->name = $tabuser[$key][
'name'];
298 $userstatic->accountancy_code = $tabuser[$key][
'user_accountancy_code'];
301 if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
304 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
308 if (!$errorforline) {
309 foreach ($tabttc[$key] as $k => $mt) {
312 $bookkeeping->doc_date = $val[
"date"];
313 $bookkeeping->doc_ref = $val[
"ref"];
314 $bookkeeping->date_creation = $now;
315 $bookkeeping->doc_type =
'expense_report';
316 $bookkeeping->fk_doc = (int) $key;
317 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
319 $bookkeeping->subledger_account = $tabuser[$key][
'user_accountancy_code'];
320 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
323 $bookkeeping->label_compte = $accountingaccountexpense->label;
325 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"SubledgerAccount"));
326 $bookkeeping->montant = $mt;
327 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
328 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
329 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
330 $bookkeeping->code_journal = $journal;
331 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
332 $bookkeeping->fk_user_author = $user->id;
333 $bookkeeping->entity =
$conf->entity;
335 $totaldebit += $bookkeeping->debit;
336 $totalcredit += $bookkeeping->credit;
338 $result = $bookkeeping->create($user);
340 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
343 $errorforinvoice[$key] =
'alreadyjournalized';
348 $errorforinvoice[$key] =
'other';
349 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
357 if (!$errorforline) {
358 foreach ($tabht[$key] as $k => $mt) {
360 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
362 $accountingaccount->fetch(0, $k,
true);
363 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
365 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
368 $account_label = $accountingaccount->label;
371 if ($accountingaccount->id > 0) {
373 $bookkeeping->doc_date = $val[
"date"];
374 $bookkeeping->doc_ref = $val[
"ref"];
375 $bookkeeping->date_creation = $now;
376 $bookkeeping->doc_type =
'expense_report';
377 $bookkeeping->fk_doc = (int) $key;
378 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
380 $bookkeeping->subledger_account =
'';
381 $bookkeeping->subledger_label =
'';
383 $bookkeeping->numero_compte = $k;
384 $bookkeeping->label_compte = $account_label;
386 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $account_label);
388 $bookkeeping->montant = $mt;
389 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
390 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
391 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
392 $bookkeeping->code_journal = $journal;
393 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
394 $bookkeeping->fk_user_author = $user->id;
395 $bookkeeping->entity =
$conf->entity;
397 $totaldebit += $bookkeeping->debit;
398 $totalcredit += $bookkeeping->credit;
400 $result = $bookkeeping->create($user);
402 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
405 $errorforinvoice[$key] =
'alreadyjournalized';
410 $errorforinvoice[$key] =
'other';
411 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
420 if (!$errorforline) {
421 $listoftax = array(0, 1, 2);
422 foreach ($listoftax as $numtax) {
423 $arrayofvat = $tabtva;
425 $arrayofvat = $tablocaltax1;
428 $arrayofvat = $tablocaltax2;
431 foreach ($arrayofvat[$key] as $k => $mt) {
433 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
435 $accountingaccount->fetch(0, $k,
true);
436 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
438 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
441 $account_label = $accountingaccount->label;
445 $bookkeeping->doc_date = $val[
"date"];
446 $bookkeeping->doc_ref = $val[
"ref"];
447 $bookkeeping->date_creation = $now;
448 $bookkeeping->doc_type =
'expense_report';
449 $bookkeeping->fk_doc = (int) $key;
450 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
452 $bookkeeping->subledger_account =
'';
453 $bookkeeping->subledger_label =
'';
455 $bookkeeping->numero_compte = $k;
456 $bookkeeping->label_compte = $account_label;
458 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
459 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
460 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
461 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $labelvataccount);
463 $bookkeeping->montant = $mt;
464 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
465 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
466 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
467 $bookkeeping->code_journal = $journal;
468 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
469 $bookkeeping->fk_user_author = $user->id;
470 $bookkeeping->entity =
$conf->entity;
472 $totaldebit += $bookkeeping->debit;
473 $totalcredit += $bookkeeping->credit;
475 $result = $bookkeeping->create($user);
477 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
480 $errorforinvoice[$key] =
'alreadyjournalized';
485 $errorforinvoice[$key] =
'other';
486 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
495 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
498 $errorforinvoice[$key] =
'amountsnotbalanced';
499 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.',
null,
'errors');
502 if (!$errorforline) {
508 $langs->load(
'errors');
509 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
517 if (empty($error) && count($tabpay) > 0) {
518 setEventMessages($langs->trans(
"GeneralLedgerIsWritten"),
null,
'mesgs');
519 } elseif (count($tabpay) == $error) {
520 setEventMessages($langs->trans(
"NoNewRecordSaved"),
null,
'warnings');
522 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
528 if (count($tabpay) != $error) {
529 $param =
'id_journal='.$id_journal;
530 $param .=
'&date_startday='.$date_startday;
531 $param .=
'&date_startmonth='.$date_startmonth;
532 $param .=
'&date_startyear='.$date_startyear;
533 $param .=
'&date_endday='.$date_endday;
534 $param .=
'&date_endmonth='.$date_endmonth;
535 $param .=
'&date_endyear='.$date_endyear;
536 $param .=
'&in_bookkeeping='.$in_bookkeeping;
538 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
548$form =
new Form($db);
550$userstatic =
new User($db);
553if ($action ==
'exportcsv' && !$error) {
556 $filename =
'journal';
557 $type_export =
'journal';
558 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
560 $userstatic =
new User($db);
564 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
565 print
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
566 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
567 print
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
568 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
569 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
572 foreach ($taber as $key => $val) {
575 $userstatic->id = $tabuser[$key][
'id'];
576 $userstatic->name = $tabuser[$key][
'name'];
579 foreach ($tabht[$key] as $k => $mt) {
581 $accountingaccount->fetch(0, $k,
true);
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,
'', $accountingaccount->label)).
'"'.$sep;
587 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
588 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
594 foreach ($tabtva[$key] as $k => $mt) {
596 print
'"'.$date.
'"'.$sep;
597 print
'"'.$val[
"ref"].
'"'.$sep;
598 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
599 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"VAT").(isset($def_tva[$key]) ? implode($def_tva[$key][$k]) :
'').
' %')).
'"'.$sep;
600 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
601 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
607 foreach ($tabttc[$key] as $k => $mt) {
608 print
'"'.$date.
'"'.$sep;
609 print
'"'.$val[
"ref"].
'"'.$sep;
610 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
611 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"ThirdParty"))).
'"'.$sep;
612 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
613 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"';
619if (empty($action) || $action ==
'view') {
620 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
621 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
622 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-expensereportsjournal');
629 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
631 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
632 $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);
633 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
635 $varlink =
'id_journal='.$id_journal;
637 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
642 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
643 $resql = $db->query($sql);
645 $obj = $db->fetch_object($resql);
647 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
648 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
649 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
654 dol_print_error($db);
660 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
661 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
662 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
666 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
668 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
669 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
672 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
674 if ($in_bookkeeping ==
'notyet') {
675 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
677 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
684 <script type="text/javascript">
685 function launch_export() {
686 $("div.fiche form input[name=\"action\"]").val("exportcsv");
687 $("div.fiche form input[type=\"submit\"]").click();
688 $("div.fiche form input[name=\"action\"]").val("");
690 function writebookkeeping() {
691 console.log("click on writebookkeeping");
692 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
693 $("div.fiche form input[type=\"submit\"]").click();
694 $("div.fiche form input[name=\"action\"]").val("");
704 print
'<div class="div-table-responsive">';
705 print
"<table class=\"noborder\" width=\"100%\">";
706 print
"<tr class=\"liste_titre\">";
707 print
"<td>".$langs->trans(
"Date").
"</td>";
708 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
709 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
710 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
711 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
712 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
713 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
722 foreach ($taber as $key => $val) {
723 $expensereportstatic->id = (int) $key;
724 $expensereportstatic->ref = $val[
"ref"];
725 $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
729 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
730 print
'<tr class="oddeven">';
731 print
"<!-- Some lines are not bound -->";
732 print
"<td>".$date.
"</td>";
733 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
736 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
743 print
'<td class="right"></td>';
744 print
'<td class="right"></td>';
751 foreach ($tabht[$key] as $k => $mt) {
752 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
754 $accountingaccount->fetch(0, $k,
true);
755 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
757 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
761 print
'<tr class="oddeven">';
762 print
"<!-- Fees -->";
763 print
"<td>".$date.
"</td>";
764 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
765 $userstatic->id = $tabuser[$key][
'id'];
766 $userstatic->name = $tabuser[$key][
'name'];
770 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
771 print
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
779 $userstatic->id = $tabuser[$key][
'id'];
780 $userstatic->name = $tabuser[$key][
'name'];
781 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $accountingaccount->label, 1) .
"</td>";
782 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
783 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
791 foreach ($tabttc[$key] as $k => $mt) {
792 $userstatic->id = $tabuser[$key][
'id'];
793 $userstatic->name = $tabuser[$key][
'name'];
795 print
'<tr class="oddeven">';
796 print
"<!-- Thirdparty -->";
797 print
"<td>".$date.
"</td>";
798 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
802 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
803 print
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
811 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
812 print
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
817 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
818 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
819 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
826 $listoftax = array(0, 1, 2);
827 foreach ($listoftax as $numtax) {
828 $arrayofvat = $tabtva;
830 $arrayofvat = $tablocaltax1;
833 $arrayofvat = $tablocaltax2;
836 foreach ($arrayofvat[$key] as $k => $mt) {
838 print
'<tr class="oddeven">';
839 print
"<!-- VAT -->";
840 print
"<td>".$date.
"</td>";
841 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
845 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
846 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
854 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
855 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
856 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
857 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $labelvatrate, 1) .
"</td>";
858 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
859 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
870 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.