35require 
'../../main.inc.php';
 
   36require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
 
   37require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
 
   38require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
 
   39require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
 
   40require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
 
   41require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
 
   42require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
 
   43require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
 
   44require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
 
   45require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
 
   46require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
 
   47require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
 
   48require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
 
   49require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
 
   50require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
 
   51require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
 
   52require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
 
   53require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
 
   54require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
 
   55require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
 
   56require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
 
   57require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
 
   58require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
 
   59require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
 
   60require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
 
   61require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
 
   62require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
 
   63require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
 
   66$langs->loadLangs(array(
"companies", 
"other", 
"compta", 
"banks", 
"bills", 
"donations", 
"loan", 
"accountancy", 
"trips", 
"salaries", 
"hrm", 
"members"));
 
   69$id_journal = 
GETPOST(
'id_journal', 
'int');
 
   71$date_startmonth = 
GETPOST(
'date_startmonth', 
'int');
 
   72$date_startday = 
GETPOST(
'date_startday', 
'int');
 
   73$date_startyear = 
GETPOST(
'date_startyear', 
'int');
 
   74$date_endmonth = 
GETPOST(
'date_endmonth', 
'int');
 
   75$date_endday = 
GETPOST(
'date_endday', 
'int');
 
   76$date_endyear = 
GETPOST(
'date_endyear', 
'int');
 
   77$in_bookkeeping = 
GETPOST(
'in_bookkeeping', 
'aZ09');
 
   78if ($in_bookkeeping == 
'') {
 
   79  $in_bookkeeping = 
'notyet';
 
   84$action = 
GETPOST(
'action', 
'aZ09');
 
   87if (!isModEnabled(
'accounting')) {
 
   90if ($user->socid > 0) {
 
   93if (!$user->hasRight(
'accounting', 
'mouvements', 
'lire')) {
 
  104$date_start = 
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
 
  105$date_end = 
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
 
  107if (empty($date_startmonth)) {
 
  110  $date_start = $dates[
'date_start'];
 
  111  $pastmonthyear = $dates[
'pastmonthyear'];
 
  112  $pastmonth = $dates[
'pastmonth'];
 
  114if (empty($date_endmonth)) {
 
  117  $date_end = $dates[
'date_end'];
 
  118  $pastmonthyear = $dates[
'pastmonthyear'];
 
  119  $pastmonth = $dates[
'pastmonth'];
 
  122if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) { 
 
  127$sql  = 
"SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
 
  128$sql .= 
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
 
  129$sql .= 
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
 
  131  $sql .= 
" spe.accountancy_code_customer as code_compta,";
 
  132  $sql .= 
" spe.accountancy_code_supplier as code_compta_fournisseur,";
 
  134  $sql .= 
" soc.code_compta,";
 
  135  $sql .= 
" soc.code_compta_fournisseur,";
 
  137$sql .= 
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
 
  138$sql .= 
" bu2.type as typeop_user,";
 
  139$sql .= 
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
 
  140$sql .= 
" FROM ".MAIN_DB_PREFIX.
"bank as b";
 
  141$sql .= 
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
 
  142$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
 
  143$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
 
  144$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
 
  145$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
 
  146$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
 
  148  $sql .= 
" LEFT JOIN " . MAIN_DB_PREFIX . 
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
 
  150$sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
 
  151$sql .= 
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
 
  152$sql .= 
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')'; 
 
  153if ($date_start && $date_end) {
 
  154  $sql .= 
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
 
  158  $sql .= 
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
 
  161if ($in_bookkeeping == 
'already') {
 
  162  $sql .= 
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab  WHERE ab.doc_type='bank') )";
 
  164if ($in_bookkeeping == 
'notyet') {
 
  165  $sql .= 
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab  WHERE ab.doc_type='bank') )";
 
  167$sql .= 
" ORDER BY b.datev";
 
  173$societestatic = 
new Societe($db);
 
  174$userstatic = 
new User($db);
 
  175$bankaccountstatic = 
new Account($db);
 
  178$paymentvatstatic = 
new Tva($db);
 
  193$accountingjournalstatic->fetch($id_journal);
 
  194$journal = $accountingjournalstatic->code;
 
  195$journal_label = $accountingjournalstatic->label;
 
  198dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
 
  199$result = $db->query($sql);
 
  201  $num = $db->num_rows($result);
 
  207  $account_employee = 
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 
'NotDefined'); 
 
  209  $account_pay_donation = 
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT', 
'NotDefined'); 
 
  210  $account_pay_subscription = 
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT', 
'NotDefined'); 
 
  211  $account_transfer = 
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH', 
'NotDefined'); 
 
  213  $tabcompany = array();
 
  219  $tabmoreinfo = array();
 
  228    $obj = $db->fetch_object($result);
 
  230    $lineisapurchase = -1;
 
  233    if ($obj->label == 
'(SupplierInvoicePayment)' || $obj->label == 
'(SupplierInvoicePaymentBack)') {
 
  234      $lineisapurchase = 1;
 
  236    if ($obj->label == 
'(CustomerInvoicePayment)' || $obj->label == 
'(CustomerInvoicePaymentBack)') {
 
  240    if ($lineisapurchase < 0) {
 
  241      if ($obj->typeop_payment_supplier == 
'payment_supplier') {
 
  242        $lineisapurchase = 1;
 
  245    if ($lineisasale < 0) {
 
  246      if ($obj->typeop_payment == 
'payment') {
 
  254    $compta_bank = $obj->account_number;
 
  257    $compta_soc = 
'NotDefined';
 
  258    if ($lineisapurchase > 0) {
 
  259      $compta_soc = (($obj->code_compta_fournisseur != 
"") ? $obj->code_compta_fournisseur : $account_supplier);
 
  261    if ($lineisasale > 0) {
 
  262      $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer);
 
  265    $tabcompany[$obj->rowid] = array(
 
  267      'name' => $obj->name,
 
  268      'code_compta' => $compta_soc,
 
  269      'email' => $obj->email
 
  275    $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : 
'');
 
  277    $tabuser[$obj->rowid] = array(
 
  278      'id' => $obj->userid,
 
  280      'lastname' => $obj->lastname,
 
  281      'firstname' => $obj->firstname,
 
  282      'email' => $obj->useremail,
 
  283      'accountancy_code' => $compta_user,
 
  284      'status' => $obj->userstatus
 
  288    $tabpay[$obj->rowid][
"date"] = $db->jdate($obj->do);
 
  289    $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type; 
 
  290    $tabpay[$obj->rowid][
"ref"] = $obj->label; 
 
  291    $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
 
  292    $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
 
  293    $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
 
  295    if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
 
  296      $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
 
  298      $tabpay[$obj->rowid][
"lib"] = 
dol_trunc($obj->label, 60);
 
  302    $links = $object->get_url($obj->rowid); 
 
  305    $tabpay[$obj->rowid][
'type'] = 
'unknown'; 
 
  306    $tabtype[$obj->rowid] = 
'unknown';
 
  307    $tabmoreinfo[$obj->rowid] = array();
 
  309    $amounttouse = $obj->amount;
 
  310    if (!empty($obj->amount_main_currency)) {
 
  312      $amounttouse = $obj->amount_main_currency;
 
  316    if (is_array($links) && count($links) > 0) {
 
  321      $is_expensereport = 
false;
 
  322      foreach ($links as $v) {
 
  323        if ($v[
'type'] == 
'sc') {
 
  327        if ($v[
'type'] == 
'payment_salary') {
 
  331        if ($v[
'type'] == 
'payment_expensereport') {
 
  332          $is_expensereport = 
true;
 
  338      foreach ($links as $key => $val) {
 
  339        if ($links[$key][
'type'] == 
'user' && !$is_sc && !$is_salary && !$is_expensereport) {
 
  344        if (in_array($links[$key][
'type'], array(
'sc', 
'payment_sc', 
'payment', 
'payment_supplier', 
'payment_vat', 
'payment_expensereport', 
'banktransfert', 
'payment_donation', 
'member', 
'payment_loan', 
'payment_salary', 
'payment_various'))) {
 
  348          $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
 
  349          $tabtype[$obj->rowid] = $links[$key][
'type'];
 
  350        } elseif (in_array($links[$key][
'type'], array(
'company', 
'user'))) {
 
  351          if ($tabpay[$obj->rowid][
'type'] == 
'unknown') {
 
  358        if ($links[$key][
'type'] == 
'withdraw') {
 
  359          $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
 
  362        if ($links[$key][
'type'] == 
'payment') {
 
  363          $paymentstatic->id = $links[$key][
'url_id'];
 
  364          $paymentstatic->ref = $links[$key][
'url_id'];
 
  365          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentstatic->getNomUrl(2, 
'', 
''); 
 
  366          $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
 
  367        } elseif ($links[$key][
'type'] == 
'payment_supplier') {
 
  368          $paymentsupplierstatic->id = $links[$key][
'url_id'];
 
  369          $paymentsupplierstatic->ref = $links[$key][
'url_id'];
 
  370          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentsupplierstatic->getNomUrl(2);
 
  371          $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
 
  372        } elseif ($links[$key][
'type'] == 
'company') {
 
  373          $societestatic->id = $links[$key][
'url_id'];
 
  374          $societestatic->name = $links[$key][
'label'];
 
  375          $societestatic->email = $tabcompany[$obj->rowid][
'email'];
 
  376          $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1, 
'', 30);
 
  378            if (empty($tabtp[$obj->rowid][$compta_soc])) {
 
  379              $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
 
  381              $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
 
  384        } elseif ($links[$key][
'type'] == 
'user') {
 
  385          $userstatic->id = $links[$key][
'url_id'];
 
  386          $userstatic->name = $links[$key][
'label'];
 
  387          $userstatic->email = $tabuser[$obj->rowid][
'email'];
 
  388          $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
 
  389          $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
 
  390          $userstatic->statut = $tabuser[$obj->rowid][
'status'];
 
  391          $userstatic->status = $tabuser[$obj->rowid][
'status'];
 
  392          $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
 
  396          if ($userstatic->id > 0) {
 
  398              $tabpay[$obj->rowid][
"soclib"] .= 
' '.$userstatic->getNomUrl(1, 
'accountancy', 0);
 
  400              $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1, 
'accountancy', 0);
 
  403            $tabpay[$obj->rowid][
"soclib"] = 
'???'; 
 
  410              $tabtp[$obj->rowid][$compta_user] += $amounttouse;
 
  413        } elseif ($links[$key][
'type'] == 
'sc') {
 
  414          $chargestatic->id = $links[$key][
'url_id'];
 
  415          $chargestatic->ref = $links[$key][
'url_id'];
 
  417          $tabpay[$obj->rowid][
"lib"] .= 
' '.$chargestatic->getNomUrl(2);
 
  419          if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
 
  420            if ($reg[1] == 
'socialcontribution') {
 
  421              $reg[1] = 
'SocialContribution';
 
  423            $chargestatic->label = $langs->trans($reg[1]);
 
  425            $chargestatic->label = $links[$key][
'label'];
 
  427          $chargestatic->ref = $chargestatic->label;
 
  428          $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
 
  429          $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
 
  433          $sqlmid = 
"SELECT cchgsoc.accountancy_code";
 
  434          $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
 
  435          $sqlmid .= 
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
 
  436          $sqlmid .= 
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
 
  437          $sqlmid .= 
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
 
  438          $sqlmid .= 
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
 
  440          dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
 
  441          $resultmid = $db->query($sqlmid);
 
  443            $objmid = $db->fetch_object($resultmid);
 
  444            $tabtp[$obj->rowid][$objmid->accountancy_code] += $amounttouse;
 
  446        } elseif ($links[$key][
'type'] == 
'payment_donation') {
 
  447          $paymentdonstatic->id = $links[$key][
'url_id'];
 
  448          $paymentdonstatic->ref = $links[$key][
'url_id'];
 
  449          $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
 
  450          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentdonstatic->getNomUrl(2);
 
  451          $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
 
  452          $tabtp[$obj->rowid][$account_pay_donation] += $amounttouse;
 
  453        } elseif ($links[$key][
'type'] == 
'member') {
 
  454          $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
 
  455          $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
 
  456          $paymentsubscriptionstatic->label = $links[$key][
'label'];
 
  457          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentsubscriptionstatic->getNomUrl(2);
 
  458          $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
 
  459          $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
 
  460          $tabtp[$obj->rowid][$account_pay_subscription] += $amounttouse;
 
  461        } elseif ($links[$key][
'type'] == 
'payment_vat') {        
 
  462          $paymentvatstatic->id = $links[$key][
'url_id'];
 
  463          $paymentvatstatic->ref = $links[$key][
'url_id'];
 
  464          $paymentvatstatic->label = $links[$key][
'label'];
 
  465          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentvatstatic->getNomUrl(2);
 
  466          $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
 
  467          $tabtp[$obj->rowid][$account_pay_vat] += $amounttouse;
 
  468        } elseif ($links[$key][
'type'] == 
'payment_salary') {
 
  469          $paymentsalstatic->id = $links[$key][
'url_id'];
 
  470          $paymentsalstatic->ref = $links[$key][
'url_id'];
 
  471          $paymentsalstatic->label = $links[$key][
'label'];
 
  472          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentsalstatic->getNomUrl(2);
 
  473          $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
 
  477          if (
getDolGlobalString(
'ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
 
  478            $tmpsalary = 
new Salary($db);
 
  479            $tmpsalary->fetch($paymentsalstatic->id);
 
  480            $tmpsalary->fetch_user($tmpsalary->fk_user);
 
  482            $userstatic->id = $tmpsalary->user->id;
 
  483            $userstatic->name = $tmpsalary->user->name;
 
  484            $userstatic->email = $tmpsalary->user->email;
 
  485            $userstatic->firstname = $tmpsalary->user->firstname;
 
  486            $userstatic->lastname = $tmpsalary->user->lastname;
 
  487            $userstatic->statut = $tmpsalary->user->statut;
 
  488            $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
 
  490            if ($userstatic->id > 0) {
 
  491              $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1, 
'accountancy', 0);
 
  493              $tabpay[$obj->rowid][
"soclib"] = 
'???'; 
 
  496            if (empty($obj->typeop_user)) { 
 
  497              $compta_user = $userstatic->accountancy_code;
 
  499                $tabtp[$obj->rowid][$compta_user] += $amounttouse;
 
  500                $tabuser[$obj->rowid] = array(
 
  501                'id' => $userstatic->id,
 
  503                'lastname' => $userstatic->lastname,
 
  504                'firstname' => $userstatic->firstname,
 
  505                'email' => $userstatic->email,
 
  506                'accountancy_code' => $compta_user,
 
  507                'status' => $userstatic->statut
 
  512        } elseif ($links[$key][
'type'] == 
'payment_expensereport') {
 
  513          $paymentexpensereportstatic->id = $links[$key][
'url_id'];
 
  514          $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
 
  515          $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
 
  516        } elseif ($links[$key][
'type'] == 
'payment_various') {
 
  517          $paymentvariousstatic->id = $links[$key][
'url_id'];
 
  518          $paymentvariousstatic->ref = $links[$key][
'url_id'];
 
  519          $paymentvariousstatic->label = $links[$key][
'label'];
 
  520          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentvariousstatic->getNomUrl(2);
 
  521          $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
 
  522          $paymentvariousstatic->fetch($paymentvariousstatic->id);
 
  523          $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 
'NotDefined'); 
 
  524          $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : 
''); 
 
  525          $tabpay[$obj->rowid][
"account_various"] = $account_various;
 
  526          $tabtp[$obj->rowid][$account_subledger] += $amounttouse;
 
  527        } elseif ($links[$key][
'type'] == 
'payment_loan') {
 
  528          $paymentloanstatic->id = $links[$key][
'url_id'];
 
  529          $paymentloanstatic->ref = $links[$key][
'url_id'];
 
  530          $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
 
  531          $tabpay[$obj->rowid][
"lib"] .= 
' '.$paymentloanstatic->getNomUrl(2);
 
  532          $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
 
  534          $sqlmid = 
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
 
  535          $sqlmid .= 
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
 
  536          $sqlmid .= 
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
 
  538          dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
 
  539          $resultmid = $db->query($sqlmid);
 
  541            $objmid = $db->fetch_object($resultmid);
 
  542            $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
 
  543            $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
 
  544            $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
 
  546        } elseif ($links[$key][
'type'] == 
'banktransfert') {
 
  547          $accountLinestatic->fetch($links[$key][
'url_id']);
 
  548          $tabpay[$obj->rowid][
"lib"] .= 
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
 
  549          $tabtp[$obj->rowid][$account_transfer] += $amounttouse;
 
  550          $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
 
  551          $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
 
  556    if (empty($tabbq[$obj->rowid][$compta_bank])) {
 
  557      $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
 
  559      $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
 
  564    if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {  
 
  565      foreach ($links as $key => $val) {
 
  566        if ($links[$key][
'type'] == 
'payment') {
 
  568          $tmppayment->fetch($links[$key][
'url_id']);
 
  569          $arrayofamounts = $tmppayment->getAmountsArray();
 
  570          if (is_array($arrayofamounts)) {
 
  571            foreach ($arrayofamounts as $invoiceid => $amount) {
 
  572              $tmpinvoice->fetch($invoiceid);
 
  573              $tmpinvoice->fetch_thirdparty();
 
  574              if ($tmpinvoice->thirdparty->code_compta) {
 
  575                $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount;
 
  584    if (empty($tabtp[$obj->rowid])) {
 
  585      $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
 
  623if (!$error && $action == 
'writebookkeeping') {
 
  627  $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 
true);
 
  630  $accountingaccountsupplier->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 
true);
 
  633  $accountingaccountpayment->fetch(
null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, 
true);
 
  636  $accountingaccountsuspense->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE, 
true);
 
  639  foreach ($tabpay as $key => $val) {   
 
  657    if (!$errorforline && is_array($tabbq[$key])) {
 
  659      foreach ($tabbq[$key] as $k => $mt) {
 
  661          $accountingaccount->fetch(
null, $k, 
true);  
 
  662          $account_label = $accountingaccount->label;
 
  665          if (!empty($val[
'lib'])) {
 
  669          if (!empty($val[
'soclib'])) {
 
  670            $reflabel .= 
" - ".dol_string_nohtmltag($val[
'soclib']);
 
  674          $bookkeeping->doc_date = $val[
"date"];
 
  675          $bookkeeping->doc_ref = $ref;
 
  676          $bookkeeping->doc_type = 
'bank';
 
  677          $bookkeeping->fk_doc = $key;
 
  678          $bookkeeping->fk_docdet = $val[
"fk_bank"];
 
  680          $bookkeeping->numero_compte = $k;
 
  681          $bookkeeping->label_compte = $account_label;
 
  683          $bookkeeping->label_operation = $reflabel;
 
  684          $bookkeeping->montant = $mt;
 
  685          $bookkeeping->sens = ($mt >= 0) ? 
'D' : 
'C';
 
  686          $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
 
  687          $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
 
  688          $bookkeeping->code_journal = $journal;
 
  689          $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  690          $bookkeeping->fk_user_author = $user->id;
 
  691          $bookkeeping->date_creation = $now;
 
  694          $bookkeeping->subledger_account = 
'';
 
  695          $bookkeeping->label_operation = $reflabel;
 
  696          $bookkeeping->entity = $conf->entity;
 
  698          $totaldebit += $bookkeeping->debit;
 
  699          $totalcredit += $bookkeeping->credit;
 
  701          $result = $bookkeeping->create($user);
 
  703            if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  706              setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', 
null, 
'warnings');
 
  718    if (!$errorforline) {
 
  719      if (is_array($tabtp[$key])) {
 
  721        foreach ($tabtp[$key] as $k => $mt) {
 
  726            if (!empty($val[
'lib'])) {
 
  729            if ($tabtype[$key] == 
'banktransfert') {
 
  730              $reflabel .= 
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
 
  736            $bookkeeping->doc_date = $val[
"date"];
 
  737            $bookkeeping->doc_ref = $ref;
 
  738            $bookkeeping->doc_type = 
'bank';
 
  739            $bookkeeping->fk_doc = $key;
 
  740            $bookkeeping->fk_docdet = $val[
"fk_bank"];
 
  742            $bookkeeping->label_operation = $reflabel;
 
  743            $bookkeeping->montant = $mt;
 
  744            $bookkeeping->sens = ($mt < 0) ? 
'D' : 
'C';
 
  745            $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
 
  746            $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
 
  747            $bookkeeping->code_journal = $journal;
 
  748            $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  749            $bookkeeping->fk_user_author = $user->id;
 
  750            $bookkeeping->date_creation = $now;
 
  752            if ($tabtype[$key] == 
'payment') {  
 
  754              $bookkeeping->subledger_account = $k; 
 
  755              $bookkeeping->subledger_label = $tabcompany[$key][
'name']; 
 
  756              $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
 
  757              $bookkeeping->label_compte = $accountingaccountcustomer->label;
 
  758            } elseif ($tabtype[$key] == 
'payment_supplier') { 
 
  760              $bookkeeping->subledger_account = $k; 
 
  761              $bookkeeping->subledger_label = $tabcompany[$key][
'name']; 
 
  762              $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
 
  763              $bookkeeping->label_compte = $accountingaccountsupplier->label;
 
  764            } elseif ($tabtype[$key] == 
'payment_expensereport') {
 
  765              $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
 
  766              $bookkeeping->subledger_label = $tabuser[$key][
'name'];
 
  767              $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
 
  768              $bookkeeping->label_compte = $accountingaccountpayment->label;
 
  769            } elseif ($tabtype[$key] == 
'payment_salary') {
 
  770              $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
 
  771              $bookkeeping->subledger_label = $tabuser[$key][
'name'];
 
  772              $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
 
  773              $bookkeeping->label_compte = $accountingaccountpayment->label;
 
  774            } elseif (in_array($tabtype[$key], array(
'sc', 
'payment_sc'))) {   
 
  775              $bookkeeping->subledger_account = 
'';
 
  776              $bookkeeping->subledger_label = 
'';
 
  777              $accountingaccount->fetch(
null, $k, 
true);  
 
  778              $bookkeeping->numero_compte = $k;
 
  779              $bookkeeping->label_compte = $accountingaccount->label;
 
  780            } elseif ($tabtype[$key] == 
'payment_vat') {
 
  781              $bookkeeping->subledger_account = 
'';
 
  782              $bookkeeping->subledger_label = 
'';
 
  783              $accountingaccount->fetch(
null, $k, 
true);    
 
  784              $bookkeeping->numero_compte = $k;
 
  785              $bookkeeping->label_compte = $accountingaccount->label;
 
  786            } elseif ($tabtype[$key] == 
'payment_donation') {
 
  787              $bookkeeping->subledger_account = 
'';
 
  788              $bookkeeping->subledger_label = 
'';
 
  789              $accountingaccount->fetch(
null, $k, 
true);    
 
  790              $bookkeeping->numero_compte = $k;
 
  791              $bookkeeping->label_compte = $accountingaccount->label;
 
  792            } elseif ($tabtype[$key] == 
'member') {
 
  793              $bookkeeping->subledger_account = 
'';
 
  794              $bookkeeping->subledger_label = 
'';
 
  795              $accountingaccount->fetch(
null, $k, 
true);    
 
  796              $bookkeeping->numero_compte = $k;
 
  797              $bookkeeping->label_compte = $accountingaccount->label;
 
  798            } elseif ($tabtype[$key] == 
'payment_loan') {
 
  799              $bookkeeping->subledger_account = 
'';
 
  800              $bookkeeping->subledger_label = 
'';
 
  801              $accountingaccount->fetch(
null, $k, 
true);    
 
  802              $bookkeeping->numero_compte = $k;
 
  803              $bookkeeping->label_compte = $accountingaccount->label;
 
  804            } elseif ($tabtype[$key] == 
'payment_various') {
 
  805              $bookkeeping->subledger_account = $k;
 
  806              $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
 
  807              $accountingaccount->fetch(
null, $tabpay[$key][
"account_various"], 
true);  
 
  808              $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
 
  809              $bookkeeping->label_compte = $accountingaccount->label;
 
  810            } elseif ($tabtype[$key] == 
'banktransfert') {
 
  811              $bookkeeping->subledger_account = 
'';
 
  812              $bookkeeping->subledger_label = 
'';
 
  813              $accountingaccount->fetch(
null, $k, 
true);    
 
  814              $bookkeeping->numero_compte = $k;
 
  815              $bookkeeping->label_compte = $accountingaccount->label;
 
  817              if ($tabtype[$key] == 
'unknown') {  
 
  819                $bookkeeping->subledger_account = 
'';
 
  820                $bookkeeping->subledger_label = 
'';
 
  821                $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
 
  822                $bookkeeping->label_compte = $accountingaccountsuspense->label;
 
  825            $bookkeeping->label_operation = $reflabel;
 
  826            $bookkeeping->entity = $conf->entity;
 
  828            $totaldebit += $bookkeeping->debit;
 
  829            $totalcredit += $bookkeeping->credit;
 
  831            $result = $bookkeeping->create($user);
 
  833              if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  836                setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', 
null, 
'warnings');
 
  844                require_once DOL_DOCUMENT_ROOT . 
'/accountancy/class/lettering.class.php';
 
  846                $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
 
  852        foreach ($tabbq[$key] as $k => $mt) {
 
  855            if (!empty($val[
'lib'])) {
 
  861            $bookkeeping->doc_date = $val[
"date"];
 
  862            $bookkeeping->doc_ref = $ref;
 
  863            $bookkeeping->doc_type = 
'bank';
 
  864            $bookkeeping->fk_doc = $key;
 
  865            $bookkeeping->fk_docdet = $val[
"fk_bank"];
 
  866            $bookkeeping->montant = $mt;
 
  867            $bookkeeping->sens = ($mt < 0) ? 
'D' : 
'C';
 
  868            $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
 
  869            $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
 
  870            $bookkeeping->code_journal = $journal;
 
  871            $bookkeeping->journal_label = $langs->transnoentities($journal_label);
 
  872            $bookkeeping->fk_user_author = $user->id;
 
  873            $bookkeeping->date_creation = $now;
 
  874            $bookkeeping->label_compte = 
'';
 
  875            $bookkeeping->label_operation = $reflabel;
 
  876            $bookkeeping->entity = $conf->entity;
 
  878            $totaldebit += $bookkeeping->debit;
 
  879            $totalcredit += $bookkeeping->credit;
 
  881            $result = $bookkeeping->create($user);
 
  884              if ($bookkeeping->error == 
'BookkeepingRecordAlreadyExists') {  
 
  887                setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', 
null, 
'warnings');
 
  902      setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.', 
null, 
'errors');
 
  905    if (!$errorforline) {
 
  912      if ($error >= $MAXNBERRORS) {
 
  913        setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')', 
null, 
'errors');
 
  919  if (empty($error) && count($tabpay) > 0) {
 
  921  } elseif (count($tabpay) == $error) {
 
  924    setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), 
null, 
'warnings');
 
  930  if (count($tabpay) != $error) {
 
  931    $param = 
'id_journal='.$id_journal;
 
  932    $param .= 
'&date_startday='.$date_startday;
 
  933    $param .= 
'&date_startmonth='.$date_startmonth;
 
  934    $param .= 
'&date_startyear='.$date_startyear;
 
  935    $param .= 
'&date_endday='.$date_endday;
 
  936    $param .= 
'&date_endmonth='.$date_endmonth;
 
  937    $param .= 
'&date_endyear='.$date_endyear;
 
  938    $param .= 
'&in_bookkeeping='.$in_bookkeeping;
 
  939    header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ? 
'?'.$param : 
''));
 
  947if ($action == 
'exportcsv') {   
 
  950  $filename = 
'journal';
 
  951  $type_export = 
'journal';
 
  952  include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
 
  955  print 
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
 
  956  print 
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
 
  957  print 
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
 
  958  print 
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
 
  959  print 
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
 
  960  print 
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
 
  961  print 
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
 
  962  print 
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
 
  963  print 
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
 
  964  print 
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
 
  965  print 
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
 
  968  foreach ($tabpay as $key => $val) {
 
  974    foreach ($tabbq[$key] as $k => $mt) {
 
  977        if (!empty($val[
'lib'])) {
 
  981        if (!empty($val[
'soclib'])) {
 
  982          $reflabel .= 
" - ".dol_string_nohtmltag($val[
'soclib']);
 
  985        print 
'"'.$key.
'"'.$sep;
 
  986        print 
'"'.$date.
'"'.$sep;
 
  987        print 
'"'.$val[
"type_payment"].
'"'.$sep;
 
  988        print 
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
 
  989        print 
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
 
  991        print 
'"'.$reflabel.
'"'.$sep;
 
  992        print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"'.$sep;
 
  993        print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"'.$sep;
 
  994        print 
'"'.$journal.
'"'.$sep;
 
  995        print 
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
 
 1001    if (is_array($tabtp[$key])) {
 
 1002      foreach ($tabtp[$key] as $k => $mt) {
 
 1005          if (!empty($val[
'lib'])) {
 
 1008          if ($tabtype[$key] == 
'banktransfert') {
 
 1009            $reflabel .= 
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
 
 1014          print 
'"'.$key.
'"'.$sep;
 
 1015          print 
'"'.$date.
'"'.$sep;
 
 1016          print 
'"'.$val[
"type_payment"].
'"'.$sep;
 
 1017          print 
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
 
 1018          if ($tabtype[$key] == 
'payment_supplier') {
 
 1019            print 
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER').
'"'.$sep;
 
 1020          } elseif ($tabtype[$key] == 
'payment') {
 
 1021            print 
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER').
'"'.$sep;
 
 1022          } elseif ($tabtype[$key] == 
'payment_expensereport') {
 
 1023            print 
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
 
 1024          } elseif ($tabtype[$key] == 
'payment_salary') {
 
 1025            print 
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
 
 1027            print 
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
 
 1029          print 
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
 
 1030          print 
'"'.$reflabel.
'"'.$sep;
 
 1031          print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"'.$sep;
 
 1032          print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"'.$sep;
 
 1033          print 
'"'.$journal.
'"'.$sep;
 
 1034          print 
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
 
 1039      foreach ($tabbq[$key] as $k => $mt) {
 
 1042          if (!empty($val[
'lib'])) {
 
 1047          print 
'"'.$key.
'"'.$sep;
 
 1048          print 
'"'.$date.
'"'.$sep;
 
 1049          print 
'"'.$val[
"type_payment"].
'"'.$sep;
 
 1050          print 
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
 
 1051          print 
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
 
 1053          print 
'"'.$reflabel.
'"'.$sep;
 
 1054          print 
'"'.($mt < 0 ? 
price(-$mt) : 
'').
'"'.$sep;
 
 1055          print 
'"'.($mt >= 0 ? 
price($mt) : 
'').
'"'.$sep;
 
 1056          print 
'"'.$journal.
'"'.$sep;
 
 1057          print 
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
 
 1070$form = 
new Form($db);
 
 1072if (empty($action) || $action == 
'view') {
 
 1073  $invoicestatic = 
new Facture($db);
 
 1076  $vatstatic = 
new Tva($db);
 
 1077  $donationstatic = 
new Don($db);
 
 1078  $loanstatic = 
new Loan($db);
 
 1079  $salarystatic = 
new Salary($db);
 
 1082  $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, 
'', 1);
 
 1089  $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
 
 1091  $listofchoices = array(
 
 1092    'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
 
 1093    'already'=>$langs->trans(
"AlreadyInGeneralLedger")
 
 1095  $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);
 
 1096  $period .= 
' -  '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
 
 1098  $varlink = 
'id_journal='.$id_journal;
 
 1102  journalHead($nom, 
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' => 
''), 
'', $varlink);
 
 1109    $sql = 
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
 
 1110    $resql = $db->query($sql);
 
 1112      $obj = $db->fetch_object($resql);
 
 1113      if ($obj->nb == 0) {
 
 1114        print 
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
 
 1115        $desc = 
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4, 
'{link}');
 
 1116        $desc = str_replace(
'{link}', 
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
 
 1126  $sql = 
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"bank_account WHERE entity = ".((int) $conf->entity).
" AND fk_accountancy_journal IS NULL AND clos=0";
 
 1127  $resql = $db->query($sql);
 
 1129    $obj = $db->fetch_object($resql);
 
 1131      print 
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
 
 1132      $desc = 
' : '.$langs->trans(
"AccountancyAreaDescBank", 6, 
'{link}');
 
 1133      $desc = str_replace(
'{link}', 
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
 
 1146    print($desc ? 
'' : 
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
 
 1147    $desc = 
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4, 
'{link}');
 
 1148    $desc = str_replace(
'{link}', 
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
 
 1154  print 
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
 
 1156  if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 
'notyet') {
 
 1157    print 
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
 
 1162    print 
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
 
 1164    if ($in_bookkeeping == 
'notyet') {
 
 1165      print 
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
 
 1167      print 
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
 
 1175  <script type="text/javascript"> 
 1176    function launch_export() { 
 1177      console.log("Set value into form and submit"); 
 1178      $("div.fiche form input[name=\"action\"]").val("exportcsv"); 
 1179      $("div.fiche form input[type=\"submit\"]").click(); 
 1180      $("div.fiche form input[name=\"action\"]").val(""); 
 1182    function writebookkeeping() { 
 1183      console.log("Set value into form and submit"); 
 1184      $("div.fiche form input[name=\"action\"]").val("writebookkeeping"); 
 1185      $("div.fiche form input[type=\"submit\"]").click(); 
 1186      $("div.fiche form input[name=\"action\"]").val(""); 
 1196  print 
'<div class="div-table-responsive">';
 
 1197  print 
'<table class="noborder centpercent">';
 
 1198  print 
'<tr class="liste_titre">';
 
 1199  print 
"<td>".$langs->trans(
"Date").
"</td>";
 
 1200  print 
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
 
 1201  print 
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
 
 1202  print 
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
 
 1203  print 
"<td>".$langs->trans(
"LabelOperation").
"</td>";
 
 1204  print 
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
 
 1205  print 
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
 
 1206  print 
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
 
 1211  foreach ($tabpay as $key => $val) {       
 
 1217    foreach ($tabbq[$key] as $k => $mt) {
 
 1220        if (!empty($val[
'lib'])) {
 
 1221          $reflabel .= $val[
'lib'].
" - ";
 
 1223        $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
 
 1224        if (!empty($val[
'soclib'])) {
 
 1225          $reflabel .= 
" - ".$val[
'soclib'];
 
 1229        print 
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
 
 1230        print 
'<tr class="oddeven">';
 
 1233        print 
"<td>".$date.
"</td>";
 
 1236        print 
"<td>".dol_escape_htmltag($ref).
"</td>";
 
 1240        if (empty($accounttoshow) || $accounttoshow == 
'NotDefined') {
 
 1241          $accounttoshow = 
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
 
 1243        print 
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
 
 1244        print $accounttoshow;
 
 1248        print 
'<td class="maxwidth300">';
 
 1262        print 
'<td class="center">'.$val[
"type_payment"].
"</td>";
 
 1263        print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
 1264        print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
 1272    if (is_array($tabtp[$key])) {
 
 1273      foreach ($tabtp[$key] as $k => $mt) {
 
 1276          if (!empty($val[
'lib'])) {
 
 1277            $reflabel .= $val[
'lib'].($val[
'soclib'] ? 
" - " : 
"");
 
 1279          if ($tabtype[$key] == 
'banktransfert') {
 
 1280            $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
 
 1282            $reflabel .= $val[
'soclib'];
 
 1285          print 
'<!-- Thirdparty bank.rowid='.$key.
' -->';
 
 1286          print 
'<tr class="oddeven">';
 
 1289          print 
"<td>".$date.
"</td>";
 
 1292          print 
"<td>".dol_escape_htmltag($ref).
"</td>";
 
 1295          $account_ledger = $k;
 
 1297          if ($tabtype[$key] == 
'payment') {
 
 1300          if ($tabtype[$key] == 
'payment_supplier') {
 
 1303          if ($tabtype[$key] == 
'payment_expensereport') {
 
 1306          if ($tabtype[$key] == 
'payment_salary') {
 
 1309          if ($tabtype[$key] == 
'payment_vat') {
 
 1312          if ($tabtype[$key] == 
'member') {
 
 1315          if ($tabtype[$key] == 
'payment_various') {
 
 1316            $account_ledger = $tabpay[$key][
"account_various"];
 
 1319          if (empty($accounttoshow) || $accounttoshow == 
'NotDefined') {
 
 1320            if ($tabtype[$key] == 
'unknown') {
 
 1323                $accounttoshow = 
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
 
 1325                $accounttoshow = 
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty', 
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>'; 
 
 1329              $errorstring = 
'UnknownAccountForThirdpartyBlocking';
 
 1330              if ($tabtype[$key] == 
'payment') {
 
 1331                $errorstring = 
'MainAccountForCustomersNotDefined';
 
 1333              if ($tabtype[$key] == 
'payment_supplier') {
 
 1334                $errorstring = 
'MainAccountForSuppliersNotDefined';
 
 1336              if ($tabtype[$key] == 
'payment_expensereport') {
 
 1337                $errorstring = 
'MainAccountForUsersNotDefined';
 
 1339              if ($tabtype[$key] == 
'payment_salary') {
 
 1340                $errorstring = 
'MainAccountForUsersNotDefined';
 
 1342              if ($tabtype[$key] == 
'payment_vat') {
 
 1343                $errorstring = 
'MainAccountForVatPaymentNotDefined';
 
 1345              if ($tabtype[$key] == 
'member') {
 
 1346                $errorstring = 
'MainAccountForSubscriptionPaymentNotDefined';
 
 1348              $accounttoshow = 
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
 
 1351          print 
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
 
 1352          print $accounttoshow; 
 
 1356          $accounttoshowsubledger = 
'';
 
 1357          if (in_array($tabtype[$key], array(
'payment', 
'payment_supplier', 
'payment_expensereport', 
'payment_salary', 
'payment_various'))) { 
 
 1359            if ($accounttoshow != $accounttoshowsubledger) {
 
 1360              if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 
'NotDefined') {
 
 1365                if (!empty($tabcompany[$key][
'code_compta'])) {
 
 1366                  if (in_array($tabtype[$key], array(
'payment_various', 
'payment_salary'))) {
 
 1368                    $accounttoshowsubledger = 
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
 
 1370                    $accounttoshowsubledger = 
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
 
 1373                  $accounttoshowsubledger = 
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
 
 1377              $accounttoshowsubledger = 
'';
 
 1380          print 
'<td class="maxwidth300">';
 
 1381          print $accounttoshowsubledger;  
 
 1384          print 
"<td>".$reflabel.
"</td>";
 
 1386          print 
'<td class="center">'.$val[
"type_payment"].
"</td>";
 
 1388          print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
 1390          print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
 1398      foreach ($tabbq[$key] as $k => $mt) {
 
 1401          if (!empty($val[
'lib'])) {
 
 1402            $reflabel .= $val[
'lib'].
" - ";
 
 1404          $reflabel .= 
'WaitingAccount';
 
 1406          print 
'<!-- Wait bank.rowid='.$key.
' -->';
 
 1407          print 
'<tr class="oddeven">';
 
 1408          print 
"<td>".$date.
"</td>";
 
 1409          print 
"<td>".$ref.
"</td>";
 
 1428          print 
"<td>".dol_escape_htmltag($reflabel).
"</td>";
 
 1429          print 
'<td class="center">'.$val[
"type_payment"].
"</td>";
 
 1430          print 
'<td class="right nowraponall amount">'.($mt < 0 ? 
price(-$mt) : 
'').
"</td>";
 
 1431          print 
'<td class="right nowraponall amount">'.($mt >= 0 ? 
price($mt) : 
'').
"</td>";
 
 1442    print 
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
 
 1469  if ($ref == 
'(SupplierInvoicePayment)' || $ref == 
'(SupplierInvoicePaymentBack)') {
 
 1470    $ref = $langs->transnoentitiesnoconv(
'Supplier');
 
 1472  if ($ref == 
'(CustomerInvoicePayment)' || $ref == 
'(CustomerInvoicePaymentBack)') {
 
 1473    $ref = $langs->transnoentitiesnoconv(
'Customer');
 
 1475  if ($ref == 
'(SocialContributionPayment)') {
 
 1476    $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
 
 1478  if ($ref == 
'(DonationPayment)') {
 
 1479    $ref = $langs->transnoentitiesnoconv(
'Donation');
 
 1481  if ($ref == 
'(SubscriptionPayment)') {
 
 1482    $ref = $langs->transnoentitiesnoconv(
'Subscription');
 
 1484  if ($ref == 
'(ExpenseReportPayment)') {
 
 1485    $ref = $langs->transnoentitiesnoconv(
'Employee');
 
 1487  if ($ref == 
'(LoanPayment)') {
 
 1488    $ref = $langs->transnoentitiesnoconv(
'Loan');
 
 1490  if ($ref == 
'(payment_salary)') {
 
 1491    $ref = $langs->transnoentitiesnoconv(
'Employee');
 
 1495  if ($typerecord == 
'payment') {
 
 1497      $sqlmid = 
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL', 
'f.ref', 
'f1.ref').
" as ref";
 
 1498      $sqlmid .= 
" FROM ".$db->prefix().
"paiement_facture as payfac";
 
 1499      $sqlmid .= 
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
 
 1500      $sqlmid .= 
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
 
 1501      $sqlmid .= 
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
 
 1502      $sqlmid .= 
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
 
 1504      $sqlmid = 
"SELECT payfac.fk_facture as id, f.ref as ref";
 
 1505      $sqlmid .= 
" FROM ".$db->prefix().
"paiement_facture as payfac";
 
 1506      $sqlmid .= 
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
 
 1507      $sqlmid .= 
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
 
 1509    $ref = $langs->transnoentitiesnoconv(
"Invoice");
 
 1510  } elseif ($typerecord == 
'payment_supplier') {
 
 1511    $sqlmid = 
'SELECT payfac.fk_facturefourn as id, f.ref';
 
 1512    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
 
 1513    $sqlmid .= 
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
 
 1514    $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
 
 1515  } elseif ($typerecord == 
'payment_expensereport') {
 
 1516    $sqlmid = 
'SELECT e.rowid as id, e.ref';
 
 1517    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
 
 1518    $sqlmid .= 
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
 
 1519    $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
 
 1520  } elseif ($typerecord == 
'payment_salary') {
 
 1521    $sqlmid = 
'SELECT s.rowid as ref';
 
 1522    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
 
 1523    $sqlmid .= 
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
 
 1524    $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
 
 1525  } elseif ($typerecord == 
'sc') {
 
 1526    $sqlmid = 
'SELECT sc.rowid as ref';
 
 1527    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
 
 1528    $sqlmid .= 
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
 
 1529    $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
 
 1530  } elseif ($typerecord == 
'payment_vat') {
 
 1531    $sqlmid = 
'SELECT v.rowid as ref';
 
 1532    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"tva as v";
 
 1533    $sqlmid .= 
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
 
 1534    $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
 
 1535  } elseif ($typerecord == 
'payment_donation') {
 
 1536    $sqlmid = 
'SELECT payd.fk_donation as ref';
 
 1537    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
 
 1538    $sqlmid .= 
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
 
 1539    $ref = $langs->transnoentitiesnoconv(
"Donation");
 
 1540  } elseif ($typerecord == 
'payment_loan') {
 
 1541    $sqlmid = 
'SELECT l.rowid as ref';
 
 1542    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
 
 1543    $sqlmid .= 
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
 
 1544    $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
 
 1545  } elseif ($typerecord == 
'payment_various') {
 
 1546    $sqlmid = 
'SELECT v.rowid as ref';
 
 1547    $sqlmid .= 
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
 
 1548    $sqlmid .= 
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
 
 1549    $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
 
 1552  if (empty($sqlmid)) {
 
 1553    dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
 
 1557    dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
 
 1558    $resultmid = $db->query($sqlmid);
 
 1560      while ($objmid = $db->fetch_object($resultmid)) {
 
 1561        $ref .= 
' '.$objmid->ref;
 
 1568  $ref = 
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295); 
 
 
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.
 
getSourceDocRef($val, $typerecord)
Return source for doc_ref of a bank transaction.
 
Class to manage bank accounts.
 
Class to manage bank transaction lines.
 
Class to manage accounting accounts.
 
Class to manage accounting journals.
 
Class to manage Ledger (General Ledger and Subledger)
 
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
 
Class to manage donations.
 
Class to manage Trips and Expenses.
 
Class to manage suppliers invoices.
 
Class to manage invoices.
 
Class to manage payments for supplier invoices.
 
Class to manage payments of customer invoices.
 
Class to manage payments of donations.
 
Class to manage payments of expense report.
 
Class to manage payments of loans.
 
Class to manage payments of salaries.
 
Class to manage various payments.
 
Class to manage salary payments.
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
Class to manage subscriptions of foundation members.
 
Put here description of your class.
 
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...
 
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
 
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...
 
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.
 
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
 
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.