31require 
'../../main.inc.php';
 
   32require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
 
   33require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
 
   34require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
 
   35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
 
   36require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
 
   37require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
 
   38require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
 
   39require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
 
   42$langs->loadLangs(array(
"commercial", 
"compta", 
"bills", 
"other", 
"accountancy", 
"trips", 
"errors"));
 
   44$id_journal = 
GETPOST(
'id_journal', 
'int');
 
   45$action = 
GETPOST(
'action', 
'aZ09');
 
   47$date_startmonth = 
GETPOST(
'date_startmonth');
 
   48$date_startday = 
GETPOST(
'date_startday');
 
   49$date_startyear = 
GETPOST(
'date_startyear');
 
   50$date_endmonth = 
GETPOST(
'date_endmonth');
 
   51$date_endday = 
GETPOST(
'date_endday');
 
   52$date_endyear = 
GETPOST(
'date_endyear');
 
   53$in_bookkeeping = 
GETPOST(
'in_bookkeeping');
 
   54if ($in_bookkeeping == 
'') {
 
   55  $in_bookkeeping = 
'notyet';
 
   60$hookmanager->initHooks(array(
'expensereportsjournal'));
 
   64if (!isModEnabled(
'accounting')) {
 
   67if ($user->socid > 0) {
 
   70if (!$user->hasRight(
'accounting', 
'mouvements', 
'lire')) {
 
   75$errorforinvoice = array();
 
   86$accountingjournalstatic->fetch($id_journal);
 
   87$journal = $accountingjournalstatic->code;
 
   88$journal_label = $accountingjournalstatic->label;
 
   90$date_start = 
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
 
   91$date_end = 
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
 
   93if (empty($date_startmonth)) {
 
   96  $date_start = $dates[
'date_start'];
 
   97  $pastmonthyear = $dates[
'pastmonthyear'];
 
   98  $pastmonth = $dates[
'pastmonth'];
 
  100if (empty($date_endmonth)) {
 
  103  $date_end = $dates[
'date_end'];
 
  104  $pastmonthyear = $dates[
'pastmonthyear'];
 
  105  $pastmonth = $dates[
'pastmonth'];
 
  108if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) { 
 
  113$sql = 
"SELECT er.rowid, er.ref, er.date_debut as de,";
 
  114$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, ";
 
  115$sql .= 
" u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
 
  116$sql .= 
" f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
 
  117$parameters = array();
 
  118$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters); 
 
  119$sql .= $hookmanager->resPrint;
 
  120$sql .= 
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
 
  121$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
 
  122$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
 
  123$sql .= 
" JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
 
  124$sql .= 
" JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
 
  125$parameters = array();
 
  126$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters); 
 
  127$sql .= $hookmanager->resPrint;
 
  128$sql .= 
" WHERE er.fk_statut > 0";
 
  129$sql .= 
" AND erd.fk_code_ventilation > 0";
 
  130$sql .= 
" AND er.entity IN (".getEntity(
'expensereport', 0).
")"; 
 
  131if ($date_start && $date_end) {
 
  132  $sql .= 
" AND er.date_debut >= '".$db->idate($date_start).
"' AND er.date_debut <= '".$db->idate($date_end).
"'";
 
  136  $sql .= 
" AND er.date_debut >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
 
  139if ($in_bookkeeping == 
'already') {
 
  140  $sql .= 
" AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab  WHERE ab.doc_type='expense_report')";
 
  142if ($in_bookkeeping == 
'notyet') {
 
  143  $sql .= 
" AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab  WHERE ab.doc_type='expense_report')";
 
  145$parameters = array();
 
  146$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters); 
 
  147$sql .= $hookmanager->resPrint;
 
  148$sql .= 
" ORDER BY er.date_debut";
 
  150dol_syslog(
'accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
 
  151$result = $db->query($sql);
 
  158  $tablocaltax1 = array();
 
  159  $tablocaltax2 = array();
 
  162  $num = $db->num_rows($result);
 
  165  $account_salary = 
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 
'NotDefined');
 
  170    $obj = $db->fetch_object($result);
 
  173    $compta_user = (!empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
 
  174    $compta_fees = $obj->compte;
 
  176    $vatdata = 
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? 
' ('.$obj->vat_src_code.
')' : 
''), $mysoc, $mysoc, 0);
 
  177    $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
 
  178    $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
 
  179    $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $account_vat);
 
  182    if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
 
  183      $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.
')' : 
''));
 
  186    $taber[$obj->rowid][
"date"] = $db->jdate($obj->de);
 
  187    $taber[$obj->rowid][
"ref"] = $obj->ref;
 
  188    $taber[$obj->rowid][
"comments"] = $obj->comments;
 
  189    $taber[$obj->rowid][
"fk_expensereportdet"] = $obj->erdid;
 
  192    if (!isset($tabttc[$obj->rowid][$compta_user])) {
 
  193      $tabttc[$obj->rowid][$compta_user] = 0;
 
  195    if (!isset($tabht[$obj->rowid][$compta_fees])) {
 
  196      $tabht[$obj->rowid][$compta_fees] = 0;
 
  198    if (!isset($tabtva[$obj->rowid][$compta_tva])) {
 
  199      $tabtva[$obj->rowid][$compta_tva] = 0;
 
  201    if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
 
  202      $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
 
  204    if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
 
  205      $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
 
  208    $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
 
  209    $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
 
  210    $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
 
  211    $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
 
  212    $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
 
  213    $tabuser[$obj->rowid] = array(
 
  216        'user_accountancy_code' => $obj->user_accountancy_account
 
  226$sql = 
"SELECT fk_expensereport, COUNT(erd.rowid) as nb";
 
  227$sql .= 
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
 
  228$sql .= 
" WHERE erd.fk_code_ventilation <= 0";
 
  229$sql .= 
" AND erd.total_ttc <> 0";
 
  230$sql .= 
" AND fk_expensereport IN (".$db->sanitize(join(
",", array_keys($taber))).
")";
 
  231$sql .= 
" GROUP BY fk_expensereport";
 
  232$resql = $db->query($sql);
 
  234$num = $db->num_rows($resql);
 
  237  $obj = $db->fetch_object($resql);
 
  239    $errorforinvoice[$obj->fk_expensereport] = 
'somelinesarenotbound';
 
  245if ($action == 
'writebookkeeping' && !$error) {
 
  250  $accountingaccountexpense->fetch(
null, 
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), 
true);
 
  252  foreach ($taber as $key => $val) {    
 
  261    if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] == 
'somelinesarenotbound') {
 
  264      setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']), 
null, 
'errors');
 
  268    if (!$errorforline) {
 
  269      foreach ($tabttc[$key] as $k => $mt) {
 
  272          $bookkeeping->doc_date = $val[
"date"];
 
  273          $bookkeeping->doc_ref = $val[
"ref"];
 
  274          $bookkeeping->date_creation = $now;
 
  275          $bookkeeping->doc_type = 
'expense_report';
 
  276          $bookkeeping->fk_doc = $key;
 
  277          $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
 
  279          $bookkeeping->subledger_account = $tabuser[$key][
'user_accountancy_code'];
 
  280          $bookkeeping->subledger_label = $tabuser[$key][
'name'];
 
  282          $bookkeeping->numero_compte = 
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
 
  283          $bookkeeping->label_compte = $accountingaccountexpense->label;
 
  285          $bookkeeping->label_operation = $tabuser[$key][
'name'];
 
  286          $bookkeeping->montant = $mt;
 
  287          $bookkeeping->sens = ($mt >= 0) ? 
'C' : 
'D';
 
  288          $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
 
  289          $bookkeeping->credit = ($mt > 0) ? $mt : 0;
 
  290          $bookkeeping->code_journal = $journal;
 
  291          $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  292          $bookkeeping->fk_user_author = $user->id;
 
  293          $bookkeeping->entity = $conf->entity;
 
  295          $totaldebit += $bookkeeping->debit;
 
  296          $totalcredit += $bookkeeping->credit;
 
  298          $result = $bookkeeping->create($user);
 
  300            if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  303              $errorforinvoice[$key] = 
'alreadyjournalized';
 
  308              $errorforinvoice[$key] = 
'other';
 
  317    if (!$errorforline) {
 
  318      foreach ($tabht[$key] as $k => $mt) {
 
  321          if ($accountingaccount->fetch(
null, $k, 
true)) {
 
  323            $bookkeeping->doc_date = $val[
"date"];
 
  324            $bookkeeping->doc_ref = $val[
"ref"];
 
  325            $bookkeeping->date_creation = $now;
 
  326            $bookkeeping->doc_type = 
'expense_report';
 
  327            $bookkeeping->fk_doc = $key;
 
  328            $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
 
  330            $bookkeeping->subledger_account = 
'';
 
  331            $bookkeeping->subledger_label = 
'';
 
  333            $bookkeeping->numero_compte = $k;
 
  334            $bookkeeping->label_compte = $accountingaccount->label;
 
  336            $bookkeeping->label_operation = $accountingaccount->label;
 
  337            $bookkeeping->montant = $mt;
 
  338            $bookkeeping->sens = ($mt < 0) ? 
'C' : 
'D';
 
  339            $bookkeeping->debit = ($mt > 0) ? $mt : 0;
 
  340            $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
 
  341            $bookkeeping->code_journal = $journal;
 
  342            $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  343            $bookkeeping->fk_user_author = $user->id;
 
  344            $bookkeeping->entity = $conf->entity;
 
  346            $totaldebit += $bookkeeping->debit;
 
  347            $totalcredit += $bookkeeping->credit;
 
  349            $result = $bookkeeping->create($user);
 
  351              if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  354                $errorforinvoice[$key] = 
'alreadyjournalized';
 
  359                $errorforinvoice[$key] = 
'other';
 
  369    if (!$errorforline) {
 
  370      $listoftax = array(0, 1, 2);
 
  371      foreach ($listoftax as $numtax) {
 
  372        $arrayofvat = $tabtva;
 
  374          $arrayofvat = $tablocaltax1;
 
  377          $arrayofvat = $tablocaltax2;
 
  380        foreach ($arrayofvat[$key] as $k => $mt) {
 
  382            $accountingaccount->fetch(
null, $k, 
true);  
 
  383            $account_label = $accountingaccount->label;
 
  387            $bookkeeping->doc_date = $val[
"date"];
 
  388            $bookkeeping->doc_ref = $val[
"ref"];
 
  389            $bookkeeping->date_creation = $now;
 
  390            $bookkeeping->doc_type = 
'expense_report';
 
  391            $bookkeeping->fk_doc = $key;
 
  392            $bookkeeping->fk_docdet = $val[
"fk_expensereportdet"];
 
  394            $bookkeeping->subledger_account = 
'';
 
  395            $bookkeeping->subledger_label = 
'';
 
  397            $bookkeeping->numero_compte = $k;
 
  398            $bookkeeping->label_compte = $account_label;
 
  400            $bookkeeping->label_operation = $langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %';
 
  401            $bookkeeping->montant = $mt;
 
  402            $bookkeeping->sens = ($mt < 0) ? 
'C' : 
'D';
 
  403            $bookkeeping->debit = ($mt > 0) ? $mt : 0;
 
  404            $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
 
  405            $bookkeeping->code_journal = $journal;
 
  406            $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  407            $bookkeeping->fk_user_author = $user->id;
 
  408            $bookkeeping->entity = $conf->entity;
 
  410            $totaldebit += $bookkeeping->debit;
 
  411            $totalcredit += $bookkeeping->credit;
 
  413            $result = $bookkeeping->create($user);
 
  415              if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  418                $errorforinvoice[$key] = 
'alreadyjournalized';
 
  423                $errorforinvoice[$key] = 
'other';
 
  433    if (!$errorforline && (
price2num($totaldebit, 
'MT') != 
price2num($totalcredit, 
'MT'))) {
 
  436      $errorforinvoice[$key] = 
'amountsnotbalanced';
 
  437      setEventMessages(
'We tried to insert a non balanced transaction in book for '.$val[
"ref"].
'. Canceled. Surely a bug.', 
null, 
'errors');
 
  440    if (!$errorforline) {
 
  446        setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"), 
null, 
'errors');
 
  454  if (empty($error) && count($tabpay) > 0) {
 
  456  } elseif (count($tabpay) == $error) {
 
  459    setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), 
null, 
'warnings');
 
  465  if (count($tabpay) != $error) {
 
  466    $param = 
'id_journal='.$id_journal;
 
  467    $param .= 
'&date_startday='.$date_startday;
 
  468    $param .= 
'&date_startmonth='.$date_startmonth;
 
  469    $param .= 
'&date_startyear='.$date_startyear;
 
  470    $param .= 
'&date_endday='.$date_endday;
 
  471    $param .= 
'&date_endmonth='.$date_endmonth;
 
  472    $param .= 
'&date_endyear='.$date_endyear;
 
  473    $param .= 
'&in_bookkeeping='.$in_bookkeeping;
 
  475    header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ? 
'?'.$param : 
''));
 
  485$form = 
new Form($db);
 
  487$userstatic = 
new User($db);
 
  490if ($action == 
'exportcsv' && !$error) {    
 
  491  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
 
  493  $filename = 
'journal';
 
  494  $type_export = 
'journal';
 
  495  include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
 
  498  print 
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
 
  499  print 
'"'.$langs->transnoentitiesnoconv(
"Piece").
'"'.$sep;
 
  500  print 
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
 
  501  print 
'"'.$langs->transnoentitiesnoconv(
"LabelOperation").
'"'.$sep;
 
  502  print 
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
 
  503  print 
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
 
  506  foreach ($taber as $key => $val) {
 
  509    $userstatic->id = $tabuser[$key][
'id'];
 
  510    $userstatic->name = $tabuser[$key][
'name'];
 
  513    foreach ($tabht[$key] as $k => $mt) {
 
  515      $accountingaccount->fetch(
null, $k, 
true);
 
  517        print 
'"'.$date.
'"'.$sep;
 
  518        print 
'"'.$val[
"ref"].
'"'.$sep;
 
  519        print 
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
 
  520        print 
'"'.dol_trunc($accountingaccount->label, 32).
'"'.$sep;
 
  521        print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"'.$sep;
 
  522        print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"';
 
  528    foreach ($tabtva[$key] as $k => $mt) {
 
  530        print 
'"'.$date.
'"'.$sep;
 
  531        print 
'"'.$val[
"ref"].
'"'.$sep;
 
  532        print 
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
 
  533        print 
'"'.dol_trunc($langs->trans(
"VAT")).
'"'.$sep;
 
  534        print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"'.$sep;
 
  535        print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"';
 
  541    foreach ($tabttc[$key] as $k => $mt) {
 
  542      print 
'"'.$date.
'"'.$sep;
 
  543      print 
'"'.$val[
"ref"].
'"'.$sep;
 
  544      print 
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
 
  545      print 
'"'.dol_trunc($userstatic->name).
'"'.$sep;
 
  546      print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"'.$sep;
 
  547      print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"';
 
  553if (empty($action) || $action == 
'view') {
 
  554  $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, 
'', 1);
 
  563  $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
 
  565  $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"), 
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
 
  566  $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);
 
  567  $period .= 
' -  '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
 
  569  $varlink = 
'id_journal='.$id_journal;
 
  571  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' => 
''), 
'', $varlink);
 
  576    $sql = 
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
 
  577    $resql = $db->query($sql);
 
  579      $obj = $db->fetch_object($resql);
 
  581        print 
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
 
  582        $desc = 
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4, 
'{link}');
 
  583        $desc = str_replace(
'{link}', 
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
 
  594    print 
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
 
  595    $desc = 
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4, 
'{link}');
 
  596    $desc = str_replace(
'{link}', 
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
 
  600  print 
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
 
  602  if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 
'notyet') {
 
  603    print 
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
 
  606    print 
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
 
  608    if ($in_bookkeeping == 
'notyet') {
 
  609      print 
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
 
  611      print 
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
 
  618  <script type="text/javascript"> 
  619    function launch_export() { 
  620      $("div.fiche form input[name=\"action\"]").val("exportcsv"); 
  621      $("div.fiche form input[type=\"submit\"]").click(); 
  622      $("div.fiche form input[name=\"action\"]").val(""); 
  624    function writebookkeeping() { 
  625      console.log("click on writebookkeeping"); 
  626      $("div.fiche form input[name=\"action\"]").val("writebookkeeping"); 
  627      $("div.fiche form input[type=\"submit\"]").click(); 
  628      $("div.fiche form input[name=\"action\"]").val(""); 
  638  print 
'<div class="div-table-responsive">';
 
  639  print 
"<table class=\"noborder\" width=\"100%\">";
 
  640  print 
"<tr class=\"liste_titre\">";
 
  641  print 
"<td>".$langs->trans(
"Date").
"</td>";
 
  642  print 
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ExpenseReportRef").
")</td>";
 
  643  print 
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
 
  644  print 
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
 
  645  print 
"<td>".$langs->trans(
"LabelOperation").
"</td>";
 
  646  print 
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
 
  647  print 
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
 
  655  foreach ($taber as $key => $val) {
 
  656    $expensereportstatic->id = $key;
 
  657    $expensereportstatic->ref = $val[
"ref"];
 
  658    $expensereportlinestatic->comments = html_entity_decode(
dol_trunc($val[
"comments"], 32));
 
  662    if ($errorforinvoice[$key] == 
'somelinesarenotbound') {
 
  663      print 
'<tr class="oddeven">';
 
  664      print 
"<!-- Some lines are not bound -->";
 
  665      print 
"<td>".$date.
"</td>";
 
  666      print 
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
 
  669      print 
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
 
  676      print 
'<td class="right"></td>';
 
  677      print 
'<td class="right"></td>';
 
  684    foreach ($tabht[$key] as $k => $mt) {
 
  686      $accountingaccount->fetch(
null, $k, 
true);
 
  689        print 
'<tr class="oddeven">';
 
  690        print 
"<!-- Fees -->";
 
  691        print 
"<td>".$date.
"</td>";
 
  692        print 
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
 
  693        $userstatic->id = $tabuser[$key][
'id'];
 
  694        $userstatic->name = $tabuser[$key][
'name'];
 
  698        if (($accountoshow == 
"") || $accountoshow == 
'NotDefined') {
 
  699          print 
'<span class="error">'.$langs->trans(
"FeeAccountNotDefined").
'</span>';
 
  707        $userstatic->id = $tabuser[$key][
'id'];
 
  708        $userstatic->name = $tabuser[$key][
'name'];
 
  709        print 
"<td>".$userstatic->getNomUrl(0, 
'user', 16).
' - '.$accountingaccount->label.
"</td>";
 
  710        print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
  711        print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
  719    foreach ($tabttc[$key] as $k => $mt) {
 
  720      $userstatic->id = $tabuser[$key][
'id'];
 
  721      $userstatic->name = $tabuser[$key][
'name'];
 
  723      print 
'<tr class="oddeven">';
 
  724      print 
"<!-- Thirdparty -->";
 
  725      print 
"<td>".$date.
"</td>";
 
  726      print 
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
 
  730      if (($accountoshow == 
"") || $accountoshow == 
'NotDefined') {
 
  731        print 
'<span class="error">'.$langs->trans(
"MainAccountForUsersNotDefined").
'</span>';
 
  739      if (($accountoshow == 
"") || $accountoshow == 
'NotDefined') {
 
  740        print 
'<span class="error">'.$langs->trans(
"UserAccountNotDefined").
'</span>';
 
  745      print 
"<td>".$userstatic->getNomUrl(0, 
'user', 16).
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
 
  746      print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
  747      print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
  754    $listoftax = array(0, 1, 2);
 
  755    foreach ($listoftax as $numtax) {
 
  756      $arrayofvat = $tabtva;
 
  758        $arrayofvat = $tablocaltax1;
 
  761        $arrayofvat = $tablocaltax2;
 
  764      foreach ($arrayofvat[$key] as $k => $mt) {
 
  766          print 
'<tr class="oddeven">';
 
  767          print 
"<!-- VAT -->";
 
  768          print 
"<td>".$date.
"</td>";
 
  769          print 
"<td>".$expensereportstatic->getNomUrl(1).
"</td>";
 
  773          if (($accountoshow == 
"") || $accountoshow == 
'NotDefined') {
 
  774            print 
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
'</span>';
 
  782          print 
"<td>".$userstatic->getNomUrl(0, 
'user', 16).
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ? 
' - Localtax '.$numtax : 
'');
 
  784          print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
  785          print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
  796    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)
 
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
 
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
 
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()
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 informations (by default a local PHP server timestamp) Re...
 
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
 
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 '.
 
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
 
dol_now($mode='auto')
Return date for now.
 
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.
 
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
 
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 dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.