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) {
359 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
361 $accountingaccount->fetch(0, $k,
true);
362 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
364 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
367 $account_label = $accountingaccount->label;
370 if ($accountingaccount->fetch(0, $k,
true)) {
372 $bookkeeping->doc_date = $val[
"date"];
373 $bookkeeping->doc_ref = $val[
"ref"];
374 $bookkeeping->date_creation = $now;
375 $bookkeeping->doc_type =
'expense_report';
376 $bookkeeping->fk_doc = $key;
377 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
379 $bookkeeping->subledger_account =
'';
380 $bookkeeping->subledger_label =
'';
382 $bookkeeping->numero_compte = $k;
383 $bookkeeping->label_compte = $account_label;
384 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $account_label);
386 $bookkeeping->montant = $mt;
387 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
388 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
389 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
390 $bookkeeping->code_journal = $journal;
391 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
392 $bookkeeping->fk_user_author = $user->id;
393 $bookkeeping->entity =
$conf->entity;
395 $totaldebit += $bookkeeping->debit;
396 $totalcredit += $bookkeeping->credit;
398 $result = $bookkeeping->create($user);
400 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
403 $errorforinvoice[$key] =
'alreadyjournalized';
408 $errorforinvoice[$key] =
'other';
418 if (!$errorforline) {
419 $listoftax = array(0, 1, 2);
420 foreach ($listoftax as $numtax) {
421 $arrayofvat = $tabtva;
423 $arrayofvat = $tablocaltax1;
426 $arrayofvat = $tablocaltax2;
429 foreach ($arrayofvat[$key] as $k => $mt) {
431 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
433 $accountingaccount->fetch(0, $k,
true);
434 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
436 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
439 $account_label = $accountingaccount->label;
443 $bookkeeping->doc_date = $val[
"date"];
444 $bookkeeping->doc_ref = $val[
"ref"];
445 $bookkeeping->date_creation = $now;
446 $bookkeeping->doc_type =
'expense_report';
447 $bookkeeping->fk_doc = $key;
448 $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
450 $bookkeeping->subledger_account =
'';
451 $bookkeeping->subledger_label =
'';
453 $bookkeeping->numero_compte = $k;
454 $bookkeeping->label_compte = $account_label;
456 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
457 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
458 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
459 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $labelvataccount);
461 $bookkeeping->montant = $mt;
462 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
463 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
464 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
465 $bookkeeping->code_journal = $journal;
466 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
467 $bookkeeping->fk_user_author = $user->id;
468 $bookkeeping->entity =
$conf->entity;
470 $totaldebit += $bookkeeping->debit;
471 $totalcredit += $bookkeeping->credit;
473 $result = $bookkeeping->create($user);
475 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
478 $errorforinvoice[$key] =
'alreadyjournalized';
483 $errorforinvoice[$key] =
'other';
493 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
496 $errorforinvoice[$key] =
'amountsnotbalanced';
497 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.',
null,
'errors');
500 if (!$errorforline) {
506 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
514 if (empty($error) && count($tabpay) > 0) {
516 } elseif (count($tabpay) == $error) {
519 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
525 if (count($tabpay) != $error) {
526 $param =
'id_journal='.$id_journal;
527 $param .=
'&date_startday='.$date_startday;
528 $param .=
'&date_startmonth='.$date_startmonth;
529 $param .=
'&date_startyear='.$date_startyear;
530 $param .=
'&date_endday='.$date_endday;
531 $param .=
'&date_endmonth='.$date_endmonth;
532 $param .=
'&date_endyear='.$date_endyear;
533 $param .=
'&in_bookkeeping='.$in_bookkeeping;
535 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
545$form =
new Form($db);
547$userstatic =
new User($db);
550if ($action ==
'exportcsv' && !$error) {
553 $filename =
'journal';
554 $type_export =
'journal';
555 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
557 $userstatic =
new User($db);
561 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
562 print
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
563 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
564 print
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
565 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
566 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
569 foreach ($taber as $key => $val) {
572 $userstatic->id = $tabuser[$key][
'id'];
573 $userstatic->name = $tabuser[$key][
'name'];
576 foreach ($tabht[$key] as $k => $mt) {
578 $accountingaccount->fetch(0, $k,
true);
580 print
'"'.$date.
'"'.$sep;
581 print
'"'.$val[
"ref"].
'"'.$sep;
582 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
583 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $accountingaccount->label)).
'"'.$sep;
584 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
585 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
591 foreach ($tabtva[$key] as $k => $mt) {
593 print
'"'.$date.
'"'.$sep;
594 print
'"'.$val[
"ref"].
'"'.$sep;
595 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
596 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %')).
'"'.$sep;
597 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
598 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"';
604 foreach ($tabttc[$key] as $k => $mt) {
605 print
'"'.$date.
'"'.$sep;
606 print
'"'.$val[
"ref"].
'"'.$sep;
607 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
608 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($userstatic->name,
'', $langs->trans(
"Thirdparty"))).
'"'.$sep;
609 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
610 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"';
616if (empty($action) || $action ==
'view') {
617 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
618 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
619 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-expensereportsjournal');
626 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
628 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
629 $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);
630 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
632 $varlink =
'id_journal='.$id_journal;
634 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
639 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
640 $resql = $db->query($sql);
642 $obj = $db->fetch_object($resql);
644 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
645 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
646 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
657 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
658 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
659 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
663 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
665 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
666 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
669 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
671 if ($in_bookkeeping ==
'notyet') {
672 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
674 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
681 <script type="text/javascript">
682 function launch_export() {
683 $("div.fiche form input[name=\"action\"]").val("exportcsv");
684 $("div.fiche form input[type=\"submit\"]").click();
685 $("div.fiche form input[name=\"action\"]").val("");
687 function writebookkeeping() {
688 console.log("click on writebookkeeping");
689 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
690 $("div.fiche form input[type=\"submit\"]").click();
691 $("div.fiche form input[name=\"action\"]").val("");
701 print
'<div class="div-table-responsive">';
702 print
"<table class=\"noborder\" width=\"100%\">";
703 print
"<tr class=\"liste_titre\">";
704 print
"<td>".$langs->trans(
"Date").
"</td>";
705 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
706 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
707 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
708 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
709 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
710 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
719 foreach ($taber as $key => $val) {
720 $expensereportstatic->id = $key;
721 $expensereportstatic->ref = $val[
"ref"];
722 $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
726 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
727 print
'<tr class="oddeven">';
728 print
"<!-- Some lines are not bound -->";
729 print
"<td>".$date.
"</td>";
730 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
733 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
740 print
'<td class="right"></td>';
741 print
'<td class="right"></td>';
748 foreach ($tabht[$key] as $k => $mt) {
749 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
751 $accountingaccount->fetch(0, $k,
true);
752 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
754 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
758 print
'<tr class="oddeven">';
759 print
"<!-- Fees -->";
760 print
"<td>".$date.
"</td>";
761 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
762 $userstatic->id = $tabuser[$key][
'id'];
763 $userstatic->name = $tabuser[$key][
'name'];
767 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
768 print
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
776 $userstatic->id = $tabuser[$key][
'id'];
777 $userstatic->name = $tabuser[$key][
'name'];
778 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $accountingaccount->label, 1) .
"</td>";
779 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
780 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
788 foreach ($tabttc[$key] as $k => $mt) {
789 $userstatic->id = $tabuser[$key][
'id'];
790 $userstatic->name = $tabuser[$key][
'name'];
792 print
'<tr class="oddeven">';
793 print
"<!-- Thirdparty -->";
794 print
"<td>".$date.
"</td>";
795 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
799 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
800 print
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
808 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
809 print
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
814 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
815 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
816 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
823 $listoftax = array(0, 1, 2);
824 foreach ($listoftax as $numtax) {
825 $arrayofvat = $tabtva;
827 $arrayofvat = $tablocaltax1;
830 $arrayofvat = $tablocaltax2;
833 foreach ($arrayofvat[$key] as $k => $mt) {
835 print
'<tr class="oddeven">';
836 print
"<!-- VAT -->";
837 print
"<td>".$date.
"</td>";
838 print
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
842 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
843 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
851 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
852 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
853 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
854 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($userstatic->getNomUrl(0,
'user'),
'', $labelvatrate, 1) .
"</td>";
855 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
856 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
867 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.