--- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_bankjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_bankjournal.php @@ -7,7 +7,7 @@ * Copyright (C) 2013-2019 Alexandre Spangaro * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2013-2014 Olivier Geffroy - * Copyright (C) 2017-2020 Frédéric France + * Copyright (C) 2017-2018 Frédéric France * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Eric Seigne * @@ -73,18 +73,15 @@ $date_endday = GETPOST('date_endday', 'int'); $date_endyear = GETPOST('date_endyear', 'int'); $in_bookkeeping = GETPOST('in_bookkeeping', 'aZ09'); -if ($in_bookkeeping == '') { - $in_bookkeeping = 'notyet'; -} +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; $now = dol_now(); $action = GETPOST('action', 'aZ09'); // Security check -if ($user->socid > 0 && empty($id_journal)) { +if ($user->socid > 0 && empty($id_journal)) accessforbidden(); -} /* @@ -93,19 +90,19 @@ $error = 0; +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); -if (empty($date_startmonth) || empty($date_endmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} - -if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form +if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form +{ $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false); $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); } @@ -125,18 +122,15 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on bu2.url_id=u.rowid"; $sql .= " WHERE ba.fk_accountancy_journal=".$id_journal; $sql .= ' AND b.amount != 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy -if ($date_start && $date_end) { +if ($date_start && $date_end) $sql .= " AND b.dateo >= '".$db->idate($date_start)."' AND b.dateo <= '".$db->idate($date_end)."'"; -} -// Define begin binding date -if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { - $sql .= " AND b.dateo >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Already in bookkeeping or not -if ($in_bookkeeping == 'already') { +if ($in_bookkeeping == 'already') +{ $sql .= " AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )"; } -if ($in_bookkeeping == 'notyet') { +if ($in_bookkeeping == 'notyet') +{ $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )"; } $sql .= " ORDER BY b.datev"; @@ -177,9 +171,9 @@ //print $sql; // Variables - $account_supplier = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER != "") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word - $account_customer = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'); // NotDefined is a reserved word - $account_employee = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'); // NotDefined is a reserved word + $account_supplier = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER != "") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word + $account_customer = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'); // NotDefined is a reserved word + $account_employee = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'); // NotDefined is a reserved word $account_pay_vat = (!empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : 'NotDefined'); // NotDefined is a reserved word $account_pay_donation = (!empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word $account_pay_subscription = (!empty($conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT) ? $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word @@ -198,28 +192,23 @@ // one line for bank record = tabbq // one line for thirdparty record = tabtp $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $db->fetch_object($result); $lineisapurchase = -1; $lineisasale = -1; // Old method to detect if it's a sale or purchase - if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') { - $lineisapurchase = 1; - } - if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') { - $lineisasale = 1; - } + if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') $lineisapurchase = 1; + if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') $lineisasale = 1; // Try a more reliable method to detect if record is a supplier payment or a customer payment - if ($lineisapurchase < 0) { - if ($obj->typeop_payment_supplier == 'payment_supplier') { - $lineisapurchase = 1; - } - } - if ($lineisasale < 0) { - if ($obj->typeop_payment == 'payment') { - $lineisasale = 1; - } + if ($lineisapurchase < 0) + { + if ($obj->typeop_payment_supplier == 'payment_supplier') $lineisapurchase = 1; + } + if ($lineisasale < 0) + { + if ($obj->typeop_payment == 'payment') $lineisasale = 1; } //var_dump($obj->type_payment); var_dump($obj->type_payment_supplier); //var_dump($lineisapurchase); //var_dump($lineisasale); @@ -229,30 +218,28 @@ // Set accountancy code for thirdparty (example: '411CU...' or '411' if no subledger account defined on customer) $compta_soc = 'NotDefined'; - if ($lineisapurchase > 0) { + if ($lineisapurchase > 0) $compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $account_supplier); - } - if ($lineisasale > 0) { + if ($lineisasale > 0) $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer); - } $tabcompany[$obj->rowid] = array( - 'id' => $obj->socid, - 'name' => $obj->name, - 'code_compta' => $compta_soc, - 'email' => $obj->email + 'id' => $obj->socid, + 'name' => $obj->name, + 'code_compta' => $compta_soc, + 'email' => $obj->email ); // Set accountancy code for user - $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : ''); + $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee); $tabuser[$obj->rowid] = array( - 'id' => $obj->userid, - 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), - 'lastname' => $obj->lastname, - 'firstname' => $obj->firstname, - 'email' => $obj->useremail, - 'accountancy_code' => $compta_user + 'id' => $obj->userid, + 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), + 'lastname' => $obj->lastname, + 'firstname' => $obj->firstname, + 'email' => $obj->useremail, + 'accountancy_code' => $compta_user ); // Variable bookkeeping ($obj->rowid is Bank Id) @@ -267,9 +254,11 @@ } else { $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60); } - - // Load of url links to the line into llx_bank $links = $object->get_url($obj->rowid); // Get an array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) + + //var_dump($i); + //var_dump($tabpay); + //var_dump($tabcompany); // By default $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or any old record with no links in bank_url. @@ -280,14 +269,18 @@ if (is_array($links) && count($links) > 0) { // Now loop on each link of record in bank. foreach ($links as $key => $val) { - 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'))) { + 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'))) + { // So we excluded 'company' and 'user' here. We want only payment lines // We save tabtype for a future use, to remember what kind of payment it is $tabpay[$obj->rowid]['type'] = $links[$key]['type']; $tabtype[$obj->rowid] = $links[$key]['type']; - } elseif (in_array($links[$key]['type'], array('company', 'user'))) { - if ($tabpay[$obj->rowid]['type'] == 'unknown') { + } + elseif (in_array($links[$key]['type'], array('company', 'user'))) + { + if ($tabpay[$obj->rowid]['type'] == 'unknown') + { // We can guess here it is a bank record for a thirdparty company or a user. // But we won't be able to record somewhere else than into a waiting account, because there is no other journal to record the contreparty. } @@ -312,33 +305,24 @@ $societestatic->name = $links[$key]['label']; $societestatic->email = $tabcompany[$obj->rowid]['email']; $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30); - if ($compta_soc) { - $tabtp[$obj->rowid][$compta_soc] += $obj->amount; - } + if ($compta_soc) $tabtp[$obj->rowid][$compta_soc] += $obj->amount; } elseif ($links[$key]['type'] == 'user') { $userstatic->id = $links[$key]['url_id']; $userstatic->name = $links[$key]['label']; $userstatic->email = $tabuser[$obj->rowid]['email']; $userstatic->firstname = $tabuser[$obj->rowid]['firstname']; $userstatic->lastname = $tabuser[$obj->rowid]['lastname']; - if ($userstatic->id > 0) { - $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30); - } else { - $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment. - } - if ($compta_user) { - $tabtp[$obj->rowid][$compta_user] += $obj->amount; - } + if ($userstatic->id > 0) $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30); + else $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment. + if ($compta_user) $tabtp[$obj->rowid][$compta_user] += $obj->amount; } elseif ($links[$key]['type'] == 'sc') { $chargestatic->id = $links[$key]['url_id']; $chargestatic->ref = $links[$key]['url_id']; $tabpay[$obj->rowid]["lib"] .= ' '.$chargestatic->getNomUrl(2); - $reg = array(); if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) { - if ($reg[1] == 'socialcontribution') { + if ($reg[1] == 'socialcontribution') $reg[1] = 'SocialContribution'; - } $chargestatic->label = $langs->trans($reg[1]); } else { $chargestatic->label = $links[$key]['label']; @@ -347,13 +331,11 @@ $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30); $tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id; - // Retrieve the accounting code of the social contribution of the payment from link of payment. - // Note: We have the social contribution id, it can be faster to get accounting code from social contribution id. $sqlmid = 'SELECT cchgsoc.accountancy_code'; - $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc"; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc "; $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; - $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'"; + $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; $sqlmid .= " WHERE bkurl.fk_bank=".$obj->rowid; dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG); @@ -402,9 +384,9 @@ $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id; $paymentvariousstatic->fetch($paymentvariousstatic->id); $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 'NotDefined'); // NotDefined is a reserved word - $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word - $tabpay[$obj->rowid]["account_various"] = $account_various; - $tabtp[$obj->rowid][$account_subledger] += $obj->amount; + $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word + $tabpay[$obj->rowid]["account_various"] = $account_various; + $tabtp[$obj->rowid][$account_subledger] += $obj->amount; } elseif ($links[$key]['type'] == 'payment_loan') { $paymentloanstatic->id = $links[$key]['url_id']; $paymentloanstatic->ref = $links[$key]['url_id']; @@ -438,19 +420,20 @@ // If no links were found to know the amount on thirdparty, we try to guess it. // This may happens on bank entries without the links lines to 'company'. - if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) { // If we dont find 'company' link because it is an old 'withdraw' record + if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) // If we dont find 'company' link because it is an old 'withdraw' record + { foreach ($links as $key => $val) { if ($links[$key]['type'] == 'payment') { // Get thirdparty $tmppayment->fetch($links[$key]['url_id']); $arrayofamounts = $tmppayment->getAmountsArray(); - if (is_array($arrayofamounts)) { - foreach ($arrayofamounts as $invoiceid => $amount) { - $tmpinvoice->fetch($invoiceid); - $tmpinvoice->fetch_thirdparty(); - if ($tmpinvoice->thirdparty->code_compta) { - $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount; - } + foreach ($arrayofamounts as $invoiceid => $amount) + { + $tmpinvoice->fetch($invoiceid); + $tmpinvoice->fetch_thirdparty(); + if ($tmpinvoice->thirdparty->code_compta) + { + $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount; } } } @@ -458,9 +441,7 @@ } // If no links were found to know the amount on thirdparty, we init it to account 'NotDefined'. - if (empty($tabtp[$obj->rowid])) { - $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank]; - } + if (empty($tabtp[$obj->rowid])) $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank]; // Check account number is ok /*if ($action == 'writebookkeeping') // Make test now in such a case @@ -501,7 +482,8 @@ $now = dol_now(); $error = 0; - foreach ($tabpay as $key => $val) { // $key is rowid into llx_bank + foreach ($tabpay as $key => $val) // $key is rowid into llx_bank + { $date = dol_print_date($db->jdate($val["date"]), 'day'); $ref = getSourceDocRef($val, $tabtype[$key]); @@ -519,18 +501,17 @@ var_dump($tabbq);exit;*/ // Bank - if (!$errorforline && is_array($tabbq[$key])) { + if (!$errorforline && is_array($tabbq[$key])) + { // Line into bank account - foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + foreach ($tabbq[$key] as $k => $mt) + { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']); - if (!empty($val['soclib'])) { - $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); - } + if (!empty($val['soclib'])) $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; @@ -549,7 +530,7 @@ $bookkeeping->debit = ($mt >= 0 ? $mt : 0); $bookkeeping->credit = ($mt < 0 ? -$mt : 0); $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_creation = $now; @@ -563,11 +544,14 @@ $result = $bookkeeping->create($user); if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { $error++; $errorforline++; setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -578,18 +562,22 @@ } // Third party - if (!$errorforline) { - if (is_array($tabtp[$key])) { + if (!$errorforline) + { + if (is_array($tabtp[$key])) + { // Line into thirdparty account foreach ($tabtp[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { + $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer); } - if ($tabtype[$key] == 'banktransfert') { - $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer); - } else { + else + { $reflabel .= dol_string_nohtmltag($val['soclib']); } @@ -605,7 +593,7 @@ $bookkeeping->debit = ($mt < 0 ? -$mt : 0); $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_creation = $now; @@ -674,7 +662,7 @@ $bookkeeping->label_compte = $accountingaccount->label; } elseif ($tabtype[$key] == 'payment_various') { $bookkeeping->subledger_account = $k; - $bookkeeping->subledger_label = $tabcompany[$key]['name']; + $bookkeeping->subledger_label = $tabcompany[$key]['name']; $bookkeeping->numero_compte = $tabpay[$key]["account_various"]; $accountingaccount->fetch(null, $bookkeeping->numero_compte, true); @@ -687,7 +675,8 @@ $accountingaccount->fetch(null, $k, true); $bookkeeping->label_compte = $accountingaccount->label; } else { - if ($tabtype[$key] == 'unknown') { // Unknown transaction, we will use a waiting account for thirdparty. + if ($tabtype[$key] == 'unknown') // Unknown transaction, we will use a waiting account for thirdparty. + { // Temporary account $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; @@ -705,11 +694,14 @@ $result = $bookkeeping->create($user); if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { $error++; $errorforline++; setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -717,13 +709,13 @@ } } } - } else { // If thirdparty unknown, output the waiting account + } + else { // If thirdparty unknown, output the waiting account foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; $reflabel .= dol_string_nohtmltag('WaitingAccount'); $bookkeeping = new BookKeeping($db); @@ -737,7 +729,7 @@ $bookkeeping->debit = ($mt < 0 ? -$mt : 0); $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_creation = $now; $bookkeeping->label_compte = ''; @@ -750,11 +742,14 @@ $result = $bookkeeping->create($user); if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { $error++; $errorforline++; setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -765,20 +760,25 @@ } } - if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) { + if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) + { $error++; $errorforline++; setEventMessages('Try to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors'); } - if (!$errorforline) { + if (!$errorforline) + { $db->commit(); - } else { + } + else + { //print 'KO for line '.$key.' '.$error.'
'; $db->rollback(); $MAXNBERRORS = 5; - if ($error >= $MAXNBERRORS) { + if ($error >= $MAXNBERRORS) + { setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors'); break; // Break in the foreach } @@ -787,16 +787,21 @@ if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); - } else { + } + else + { setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } $action = ''; // Must reload data, so we make a redirect - if (count($tabpay) != $error) { + if (count($tabpay) != $error) + { $param = 'id_journal='.$id_journal; $param .= '&date_startday='.$date_startday; $param .= '&date_startmonth='.$date_startmonth; @@ -834,28 +839,26 @@ print '"'.$langs->transnoentitiesnoconv("Note").'"'.$sep; print "\n"; - foreach ($tabpay as $key => $val) { + foreach ($tabpay as $key => $val) + { $date = dol_print_date($db->jdate($val["date"]), 'day'); $ref = getSourceDocRef($val, $tabtype[$key]); // Bank foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']); - if (!empty($val['soclib'])) { - $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); - } + if (!empty($val['soclib'])) $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); print '"'.$key.'"'.$sep; print '"'.$date.'"'.$sep; print '"'.$val["type_payment"].'"'.$sep; print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; print " ".$sep; print '"'.$reflabel.'"'.$sep; print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; @@ -869,21 +872,23 @@ // Third party if (is_array($tabtp[$key])) { foreach ($tabtp[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); - } - if ($tabtype[$key] == 'banktransfert') { + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer); - } else { + } + else + { $reflabel .= dol_string_nohtmltag($val['soclib']); } print '"'.$key.'"'.$sep; print '"'.$date.'"'.$sep; print '"'.$val["type_payment"].'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; if ($tabtype[$key] == 'payment_supplier') { print '"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.'"'.$sep; } elseif ($tabtype[$key] == 'payment') { @@ -893,7 +898,7 @@ } elseif ($tabtype[$key] == 'payment_salary') { print '"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.'"'.$sep; } else { - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; } print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; print '"'.$reflabel.'"'.$sep; @@ -906,18 +911,17 @@ } } else { // If thirdparty unkown, output the waiting account foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; $reflabel .= dol_string_nohtmltag('WaitingAccount'); print '"'.$key.'"'.$sep; print '"'.$date.'"'.$sep; print '"'.$val["type_payment"].'"'.$sep; print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).'"'.$sep; - print '"'.length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).'"'.$sep; + print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).'"'.$sep; print "".$sep; print '"'.$reflabel.'"'.$sep; print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; @@ -956,8 +960,8 @@ $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); - $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); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $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); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal='.$id_journal; @@ -967,18 +971,16 @@ // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) $sql = 'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'bank_account WHERE entity = '.$conf->entity.' AND fk_accountancy_journal IS NULL AND clos=0'; $resql = $db->query($sql); - if ($resql) { + if ($resql) + { $obj = $db->fetch_object($resql); - if ($obj->nb > 0) { - print '
'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount"); - $desc = ' : '.$langs->trans("AccountancyAreaDescBank", 9, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } + if ($obj->nb > 0) + { + print '
'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount"); + print ' : '.$langs->trans("AccountancyAreaDescBank", 9, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").''); + } + } + else dol_print_error($db); // Button to write into Ledger @@ -992,19 +994,15 @@ print '
'; - if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') { - print ''; - } + if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1' - || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { - print ''; - } else { - if ($in_bookkeeping == 'notyet') { - print ''; - } else { - print ''.$langs->trans("WriteBookKeeping").''; - } + || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { + print ''; + } + else { + if ($in_bookkeeping == 'notyet') print ''; + else print ''.$langs->trans("WriteBookKeeping").''; } print '
'; @@ -1047,22 +1045,21 @@ $r = ''; - foreach ($tabpay as $key => $val) { // $key is rowid in llx_bank + foreach ($tabpay as $key => $val) // $key is rowid in llx_bank + { $date = dol_print_date($db->jdate($val["date"]), 'day'); $ref = getSourceDocRef($val, $tabtype[$key]); // Bank - foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + foreach ($tabbq[$key] as $k => $mt) + { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= $val['lib']." - "; - } + if (!empty($val['lib'])) $reflabel .= $val['lib']." - "; $reflabel .= $langs->trans("Bank").' '.$val['bank_account_ref']; - if (!empty($val['soclib'])) { - $reflabel .= " - ".$val['soclib']; - } + if (!empty($val['soclib'])) $reflabel .= " - ".$val['soclib']; //var_dump($tabpay[$key]); print ''; @@ -1072,11 +1069,11 @@ // Ledger account print ""; $accounttoshow = length_accountg($k); - if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { print ''.$langs->trans("BankAccountNotDefined").''; - } else { - print $accounttoshow; } + else print $accounttoshow; print ""; // Subledger account print ""; @@ -1100,14 +1097,16 @@ // Third party if (is_array($tabtp[$key])) { foreach ($tabtp[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= $val['lib'].($val['soclib'] ? " - " : ""); - } - if ($tabtype[$key] == 'banktransfert') { + if (!empty($val['lib'])) $reflabel .= $val['lib'].($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { $reflabel .= $langs->trans('TransitionalAccount').' '.$account_transfer; - } else { + } + else + { $reflabel .= $val['soclib']; } @@ -1119,87 +1118,72 @@ print ""; $account_ledger = $k; // Try to force general ledger account depending on type - if ($tabtype[$key] == 'payment') { - $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - } - if ($tabtype[$key] == 'payment_supplier') { - $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; - } - if ($tabtype[$key] == 'payment_expensereport') { - $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; - } - if ($tabtype[$key] == 'payment_salary') { - $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; - } - if ($tabtype[$key] == 'payment_vat') { - $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT; - } - if ($tabtype[$key] == 'member') { - $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT; - } - if ($tabtype[$key] == 'payment_various') { - $account_ledger = $tabpay[$key]["account_various"]; - } - $accounttoshow = length_accountg($account_ledger); - if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { - if ($tabtype[$key] == 'unknown') { + if ($tabtype[$key] == 'payment') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + if ($tabtype[$key] == 'payment_supplier') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + if ($tabtype[$key] == 'payment_expensereport') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_salary') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_vat') $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT; + if ($tabtype[$key] == 'member') $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT; + if ($tabtype[$key] == 'payment_various') $account_ledger = $tabpay[$key]["account_various"]; + $accounttoshow = length_accounta($account_ledger); + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { + if ($tabtype[$key] == 'unknown') + { // We will accept writing, but into a waiting account - if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE == '-1') { + if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE == '-1') + { print ''.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').''; - } else { + } + else + { print ''.$langs->trans('UnknownAccountForThirdparty', length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).''; // We will use a waiting account } - } else { + } + else + { // We will refuse writing $errorstring = 'UnknownAccountForThirdpartyBlocking'; - if ($tabtype[$key] == 'payment') { - $errorstring = 'MainAccountForCustomersNotDefined'; - } - if ($tabtype[$key] == 'payment_supplier') { - $errorstring = 'MainAccountForSuppliersNotDefined'; - } - if ($tabtype[$key] == 'payment_expensereport') { - $errorstring = 'MainAccountForUsersNotDefined'; - } - if ($tabtype[$key] == 'payment_salary') { - $errorstring = 'MainAccountForUsersNotDefined'; - } - if ($tabtype[$key] == 'payment_vat') { - $errorstring = 'MainAccountForVatPaymentNotDefined'; - } - if ($tabtype[$key] == 'member') { - $errorstring = 'MainAccountForSubscriptionPaymentNotDefined'; - } + if ($tabtype[$key] == 'payment') $errorstring = 'MainAccountForCustomersNotDefined'; + if ($tabtype[$key] == 'payment_supplier') $errorstring = 'MainAccountForSuppliersNotDefined'; + if ($tabtype[$key] == 'payment_expensereport') $errorstring = 'MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_salary') $errorstring = 'MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_vat') $errorstring = 'MainAccountForVatPaymentNotDefined'; + if ($tabtype[$key] == 'member') $errorstring = 'MainAccountForSubscriptionPaymentNotDefined'; print ''.$langs->trans($errorstring).''; } - } else { - print $accounttoshow; - } + } + else print $accounttoshow; print ""; // Subledger account print ""; - if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) { // Type of payment with subledger + if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) // Type of payment with subledger + { $accounttoshowsubledger = length_accounta($k); - if ($accounttoshow != $accounttoshowsubledger) { - if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') { + if ($accounttoshow != $accounttoshowsubledger) + { + if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') + { /*var_dump($tabpay[$key]); var_dump($tabtype[$key]); var_dump($tabbq[$key]);*/ //print ''.$langs->trans("ThirdpartyAccountNotDefined").''; - if (!empty($tabcompany[$key]['code_compta'])) { + if (!empty($tabcompany[$key]['code_compta'])) + { if (in_array($tabtype[$key], array('payment_various'))) { // For such case, if subledger is not defined, we won't use subledger accounts. print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").''; } else { print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).''; } - } else { + } + else + { print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").''; } - } else { - print $accounttoshowsubledger; } + else print $accounttoshowsubledger; } } print ""; @@ -1212,11 +1196,10 @@ } } else { // Waiting account foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + if ($mt) + { $reflabel = ''; - if (!empty($val['lib'])) { - $reflabel .= $val['lib']." - "; - } + if (!empty($val['lib'])) $reflabel .= $val['lib']." - "; $reflabel .= 'WaitingAccount'; print ''; @@ -1300,67 +1283,87 @@ } $sqlmid = ''; - if ($typerecord == 'payment') { + if ($typerecord == 'payment') + { $sqlmid = 'SELECT payfac.fk_facture as id, f.ref as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac, ".MAIN_DB_PREFIX."facture as f"; $sqlmid .= " WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=".$val["paymentid"]; $ref = $langs->transnoentitiesnoconv("Invoice"); - } elseif ($typerecord == 'payment_supplier') { + } + elseif ($typerecord == 'payment_supplier') + { $sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f"; $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".$val["paymentsupplierid"]; $ref = $langs->transnoentitiesnoconv("SupplierInvoice"); - } elseif ($typerecord == 'payment_expensereport') { + } + elseif ($typerecord == 'payment_expensereport') + { $sqlmid = 'SELECT e.rowid as id, e.ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as pe, ".MAIN_DB_PREFIX."expensereport as e"; $sqlmid .= " WHERE pe.rowid=".$val["paymentexpensereport"]." AND pe.fk_expensereport = e.rowid"; $ref = $langs->transnoentitiesnoconv("ExpenseReport"); - } elseif ($typerecord == 'payment_salary') { + } + elseif ($typerecord == 'payment_salary') + { $sqlmid = 'SELECT s.rowid as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; $sqlmid .= " WHERE s.rowid=".$val["paymentsalid"]; $ref = $langs->transnoentitiesnoconv("SalaryPayment"); - } elseif ($typerecord == 'sc') { + } + elseif ($typerecord == 'sc') + { $sqlmid = 'SELECT sc.rowid as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementcharge as sc"; $sqlmid .= " WHERE sc.rowid=".$val["paymentscid"]; $ref = $langs->transnoentitiesnoconv("SocialContribution"); - } elseif ($typerecord == 'payment_vat') { + } + elseif ($typerecord == 'payment_vat') + { $sqlmid = 'SELECT v.rowid as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."tva as v"; $sqlmid .= " WHERE v.rowid=".$val["paymentvatid"]; $ref = $langs->transnoentitiesnoconv("PaymentVat"); - } elseif ($typerecord == 'payment_donation') { + } + elseif ($typerecord == 'payment_donation') + { $sqlmid = 'SELECT payd.fk_donation as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_donation as payd"; $sqlmid .= " WHERE payd.fk_donation=".$val["paymentdonationid"]; $ref = $langs->transnoentitiesnoconv("Donation"); - } elseif ($typerecord == 'payment_loan') { + } + elseif ($typerecord == 'payment_loan') + { $sqlmid = 'SELECT l.rowid as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_loan as l"; $sqlmid .= " WHERE l.rowid=".$val["paymentloanid"]; $ref = $langs->transnoentitiesnoconv("LoanPayment"); - } elseif ($typerecord == 'payment_various') { + } + elseif ($typerecord == 'payment_various') + { $sqlmid = 'SELECT v.rowid as ref'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_various as v"; $sqlmid .= " WHERE v.rowid=".$val["paymentvariousid"]; $ref = $langs->transnoentitiesnoconv("VariousPayment"); } // Add warning - if (empty($sqlmid)) { + if (empty($sqlmid)) + { dol_syslog("Found a typerecord=".$typerecord." not supported", LOG_WARNING); } - if ($sqlmid) { + if ($sqlmid) + { dol_syslog("accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG); $resultmid = $db->query($sqlmid); - if ($resultmid) { - while ($objmid = $db->fetch_object($resultmid)) { + if ($resultmid) + { + while ($objmid = $db->fetch_object($resultmid)) + { $ref .= ' '.$objmid->ref; } - } else { - dol_print_error($db); - } + } + else dol_print_error($db); } $ref = dol_trunc($langs->transnoentitiesnoconv("BankId").' '.$val['fk_bank'].' - '.$ref, 295); // 295 + 3 dots (...) is < than max size of 300 --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_expensereportsjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_expensereportsjournal.php @@ -70,18 +70,16 @@ $journal = $accountingjournalstatic->code; $journal_label = $accountingjournalstatic->label; +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); - -if (empty($date_startmonth) || empty($date_endmonth)) -{ - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form { @@ -103,18 +101,14 @@ $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND er.date_debut >= '".$db->idate($date_start)."' AND er.date_debut <= '".$db->idate($date_end)."'"; -// Define begin binding date -if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { - $sql .= " AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Already in bookkeeping or not if ($in_bookkeeping == 'already') { - $sql .= " AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; + $sql .= " AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; } if ($in_bookkeeping == 'notyet') { - $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; + $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; } $sql .= " ORDER BY er.date_debut"; @@ -223,7 +217,7 @@ $bookkeeping->debit = ($mt <= 0) ? -$mt : 0; $bookkeeping->credit = ($mt > 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -237,7 +231,9 @@ $error++; $errorforline++; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -269,9 +265,9 @@ $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; - $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -285,7 +281,9 @@ $error++; $errorforline++; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -327,9 +325,9 @@ $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; - $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -343,7 +341,9 @@ $error++; $errorforline++; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); @@ -365,13 +365,15 @@ if (!$errorforline) { $db->commit(); - } else { + } + else + { $db->rollback(); if ($error >= 10) { - setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); - break; // Break in the foreach + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach } } } @@ -380,10 +382,13 @@ if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); - } elseif (count($tabpay) == $error) + } + elseif (count($tabpay) == $error) { setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); - } else { + } + else + { setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } @@ -433,48 +438,48 @@ print "\n"; foreach ($taber as $key => $val) { - $date = dol_print_date($val["date"], 'day'); - - $userstatic->id = $tabuser[$key]['id']; - $userstatic->name = $tabuser[$key]['name']; - - // Fees - foreach ($tabht[$key] as $k => $mt) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(null, $k, true); - if ($mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($accountingaccount->label, 32).'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'; - print "\n"; - } - } - // VAT - foreach ($tabtva[$key] as $k => $mt) { - if ($mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($langs->trans("VAT")).'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'; - print "\n"; - } - } - - // Third party - foreach ($tabttc[$key] as $k => $mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($userstatic->name).'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'; - } - print "\n"; + $date = dol_print_date($val["date"], 'day'); + + $userstatic->id = $tabuser[$key]['id']; + $userstatic->name = $tabuser[$key]['name']; + + // Fees + foreach ($tabht[$key] as $k => $mt) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(null, $k, true); + if ($mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($accountingaccount->label, 32).'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'; + print "\n"; + } + } + // VAT + foreach ($tabtva[$key] as $k => $mt) { + if ($mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($langs->trans("VAT")).'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'; + print "\n"; + } + } + + // Third party + foreach ($tabttc[$key] as $k => $mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($userstatic->name).'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'; + } + print "\n"; } } @@ -489,8 +494,8 @@ $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); - $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); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $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); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal='.$id_journal; @@ -506,7 +511,8 @@ if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { print ''; - } else { + } + else { if ($in_bookkeeping == 'notyet') print ''; else print ''.$langs->trans("WriteBookKeeping").''; } @@ -576,7 +582,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("FeeAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; // Subledger account print ""; @@ -605,7 +612,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForUsersNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print ""; @@ -613,10 +621,11 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("UserAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; print "".$userstatic->getNomUrl(0, 'user', 16).' - '.$langs->trans("SubledgerAccount").""; - print ''.($mt < 0 ? price(-$mt) : '').""; + print ''.($mt < 0 ? -price(-$mt) : '').""; print ''.($mt >= 0 ? price($mt) : '').""; print ""; } @@ -640,7 +649,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("VATAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print ""; --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_purchasesjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_purchasesjournal.php @@ -75,18 +75,16 @@ $journal = $accountingjournalstatic->code; $journal_label = $accountingjournalstatic->label; +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); - -if (empty($date_startmonth) || empty($date_endmonth)) -{ - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form { @@ -113,10 +111,6 @@ } if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; -// Define begin binding date -if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { - $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Already in bookkeeping or not if ($in_bookkeeping == 'already') { @@ -158,9 +152,8 @@ if (empty($compta_prod)) { if ($obj->product_type == 0) $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : 'NotDefined'; - else { + else $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : 'NotDefined'; - } } $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0); @@ -233,7 +226,8 @@ { $errorforinvoice[$key] = 'somelinesarenotbound'; } - } else dol_print_error($db); + } + else dol_print_error($db); } //var_dump($errorforinvoice);exit; @@ -322,7 +316,7 @@ $bookkeeping->debit = ($mt <= 0) ? -$mt : 0; $bookkeeping->credit = ($mt > 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -337,7 +331,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -372,7 +368,7 @@ $bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -387,7 +383,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -433,7 +431,7 @@ $bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -448,7 +446,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -484,7 +484,7 @@ $bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -499,7 +499,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -522,7 +524,9 @@ if (!$errorforline) { $db->commit(); - } else { + } + else + { $db->rollback(); if ($error >= 10) @@ -537,10 +541,13 @@ if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); - } elseif (count($tabpay) == $error) + } + elseif (count($tabpay) == $error) { setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); - } else { + } + else + { setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } @@ -669,7 +676,7 @@ print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; print '""'.$sep; - print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep; + print '"'.$langs->trans("VAT").' - '.$def_tva[$key].'"'.$sep; print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$val["refsuppliersologest"].' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; @@ -719,8 +726,8 @@ } $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); - $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); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $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); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal='.$id_journal; @@ -736,7 +743,8 @@ if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { print ''; - } else { + } + else { if ($in_bookkeeping == 'notyet') print ''; else print ''.$langs->trans("WriteBookKeeping").''; } @@ -863,7 +871,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForSuppliersNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; // Subledger account print ""; @@ -871,7 +880,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("ThirdpartyAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; print "".$companystatic->getNomUrl(0, 'supplier', 16).' - '.$invoicestatic->ref_supplier.' - '.$langs->trans("SubledgerAccount").""; print ''.($mt < 0 ? price(-$mt) : '').""; @@ -894,7 +904,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("ProductAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print ""; @@ -926,7 +937,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Purchase").')'; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print ""; @@ -956,7 +968,8 @@ if ($accountoshow == '' || $accountoshow == 'NotDefined') { print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account'; - } else print $accountoshow; + } + else print $accountoshow; print ''; // Subledger account print ""; --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_sellsjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_sellsjournal.php @@ -78,18 +78,16 @@ $journal = $accountingjournalstatic->code; $journal_label = $accountingjournalstatic->label; +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); - -if (empty($date_startmonth) || empty($date_endmonth)) -{ - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form { @@ -117,10 +115,6 @@ $sql .= " AND fd.product_type IN (0,1)"; if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; -// Define begin binding date -if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { - $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; -} // Already in bookkeeping or not if ($in_bookkeeping == 'already') { @@ -130,7 +124,7 @@ if ($in_bookkeeping == 'notyet') { $sql .= " AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; - // $sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account + // $sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account } $sql .= " ORDER BY f.datef"; //print $sql; @@ -164,9 +158,8 @@ if (empty($compta_prod)) { if ($obj->product_type == 0) $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : 'NotDefined'; - else { + else $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : 'NotDefined'; - } } $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0); @@ -247,7 +240,8 @@ { $errorforinvoice[$key] = 'somelinesarenotbound'; } - } else dol_print_error($db); + } + else dol_print_error($db); } //var_dump($errorforinvoice);exit; @@ -333,7 +327,7 @@ $bookkeeping->debit = ($mt >= 0) ? $mt : 0; $bookkeeping->credit = ($mt < 0) ? -$mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -348,7 +342,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -383,7 +379,7 @@ $bookkeeping->debit = ($mt < 0) ? -$mt : 0; $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -398,7 +394,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -443,7 +441,7 @@ $bookkeeping->debit = ($mt < 0) ? -$mt : 0; $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->entity = $conf->entity; @@ -458,7 +456,9 @@ $errorforline++; $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { + } + else + { $error++; $errorforline++; $errorforinvoice[$key] = 'other'; @@ -482,7 +482,9 @@ if (!$errorforline) { $db->commit(); - } else { + } + else + { $db->rollback(); if ($error >= 10) @@ -497,9 +499,13 @@ if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); - } else { + } + else + { setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } @@ -628,7 +634,7 @@ print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; print '""'.$sep; - print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep; + print '"'.$langs->trans("VAT").' - '.$def_tva[$key].' %"'.$sep; print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; @@ -653,13 +659,12 @@ $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded"); - else { + else $description .= $langs->trans("DepositsAreIncluded"); - } $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); - $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); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $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); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal='.$id_journal; @@ -675,7 +680,8 @@ if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { print ''; - } else { + } + else { if ($in_bookkeeping == 'notyet') print ''; else print ''.$langs->trans("WriteBookKeeping").''; } @@ -801,7 +807,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForCustomersNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; // Subledger account print ""; @@ -809,7 +816,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("ThirdpartyAccountNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ''; print "".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount").""; print ''.($mt >= 0 ? price($mt) : '').""; @@ -833,7 +841,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("ProductNotDefined").''; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print ""; @@ -866,7 +875,8 @@ if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Sale").')'; - } else print $accountoshow; + } + else print $accountoshow; print ""; // Subledger account print "";