FIX compatibility with Mysql <= 5.7

This commit is contained in:
Regis Houssin 2022-09-28 22:32:55 +02:00
parent fe37658f66
commit 36c54a140f
2 changed files with 31 additions and 19 deletions

View File

@ -449,7 +449,8 @@ class AccountingJournal extends CommonObject
} }
$sql = ""; $sql = "";
// FIXME sql error
// FIXME sql error with Mysql 5.7
/*if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') { /*if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') {
$sql .= "WITH in_accounting_bookkeeping(fk_docdet) AS ("; $sql .= "WITH in_accounting_bookkeeping(fk_docdet) AS (";
$sql .= " SELECT DISTINCT fk_docdet"; $sql .= " SELECT DISTINCT fk_docdet";
@ -457,15 +458,23 @@ class AccountingJournal extends CommonObject
$sql .= " WHERE doc_type = 'asset'"; $sql .= " WHERE doc_type = 'asset'";
$sql .= ")"; $sql .= ")";
}*/ }*/
$sql .= "SELECT ad.fk_asset AS rowid, a.ref AS asset_ref, a.label AS asset_label, a.acquisition_value_ht AS asset_acquisition_value_ht"; $sql .= "SELECT ad.fk_asset AS rowid, a.ref AS asset_ref, a.label AS asset_label, a.acquisition_value_ht AS asset_acquisition_value_ht";
$sql .= ", a.disposal_date AS asset_disposal_date, a.disposal_amount_ht AS asset_disposal_amount_ht, a.disposal_subject_to_vat AS asset_disposal_subject_to_vat"; $sql .= ", a.disposal_date AS asset_disposal_date, a.disposal_amount_ht AS asset_disposal_amount_ht, a.disposal_subject_to_vat AS asset_disposal_subject_to_vat";
$sql .= ", ad.rowid AS depreciation_id, ad.depreciation_mode, ad.ref AS depreciation_ref, ad.depreciation_date, ad.depreciation_ht, ad.accountancy_code_debit, ad.accountancy_code_credit"; $sql .= ", ad.rowid AS depreciation_id, ad.depreciation_mode, ad.ref AS depreciation_ref, ad.depreciation_date, ad.depreciation_ht, ad.accountancy_code_debit, ad.accountancy_code_credit";
$sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation as ad"; $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation as ad";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "asset as a ON a.rowid = ad.fk_asset"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "asset as a ON a.rowid = ad.fk_asset";
if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') { // FIXME sql error with Mysql 5.7
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid"; /*if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') {
} $sql .= " LEFT JOIN in_accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid";
}*/
$sql .= " WHERE a.entity IN (" . getEntity('asset', 0) . ')'; // We don't share object for accountancy, we use source object sharing $sql .= " WHERE a.entity IN (" . getEntity('asset', 0) . ')'; // We don't share object for accountancy, we use source object sharing
// Compatibility with Mysql 5.7
if ($in_bookkeeping == 'already') {
$sql .= " AND EXISTS (SELECT iab.fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS iab WHERE iab.fk_docdet = ad.rowid AND doc_type = 'asset')";
} else if ($in_bookkeeping == 'notyet') {
$sql .= " AND NOT EXISTS (SELECT iab.fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS iab WHERE iab.fk_docdet = ad.rowid AND doc_type = 'asset')";
}
$sql .= " AND ad.ref != ''"; // not reversal lines $sql .= " AND ad.ref != ''"; // not reversal lines
if ($date_start && $date_end) { if ($date_start && $date_end) {
$sql .= " AND ad.depreciation_date >= '" . $this->db->idate($date_start) . "' AND ad.depreciation_date <= '" . $this->db->idate($date_end) . "'"; $sql .= " AND ad.depreciation_date >= '" . $this->db->idate($date_start) . "' AND ad.depreciation_date <= '" . $this->db->idate($date_end) . "'";
@ -475,9 +484,10 @@ class AccountingJournal extends CommonObject
$sql .= " AND ad.depreciation_date >= '" . $this->db->idate($conf->global->ACCOUNTING_DATE_START_BINDING) . "'"; $sql .= " AND ad.depreciation_date >= '" . $this->db->idate($conf->global->ACCOUNTING_DATE_START_BINDING) . "'";
} }
// Already in bookkeeping or not // Already in bookkeeping or not
if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') { // FIXME sql error with Mysql 5.7
/*if ($in_bookkeeping == 'already' || $in_bookkeeping == 'notyet') {
$sql .= " AND iab.fk_docdet IS" . ($in_bookkeeping == 'already' ? " NOT" : "") . " NULL"; $sql .= " AND iab.fk_docdet IS" . ($in_bookkeeping == 'already' ? " NOT" : "") . " NULL";
} }*/
$sql .= " ORDER BY ad.depreciation_date"; $sql .= " ORDER BY ad.depreciation_date";
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);

View File

@ -289,19 +289,21 @@ print '<td class="right">' . $langs->trans("Debit") . '</td>';
print '<td class="right">' . $langs->trans("Credit") . '</td>'; print '<td class="right">' . $langs->trans("Credit") . '</td>';
print "</tr>\n"; print "</tr>\n";
foreach ($journal_data as $element_id => $element) { if (is_array($journal_data) && !empty($journal_data)) {
foreach ($element['blocks'] as $lines) { foreach ($journal_data as $element_id => $element) {
foreach ($lines as $line) { foreach ($element['blocks'] as $lines) {
print '<tr class="oddeven">'; foreach ($lines as $line) {
print '<td>' . $line['date'] . '</td>'; print '<tr class="oddeven">';
print '<td>' . $line['piece'] . '</td>'; print '<td>' . $line['date'] . '</td>';
print '<td>' . $line['account_accounting'] . '</td>'; print '<td>' . $line['piece'] . '</td>';
print '<td>' . $line['subledger_account'] . '</td>'; print '<td>' . $line['account_accounting'] . '</td>';
print '<td>' . $line['label_operation'] . '</td>'; print '<td>' . $line['subledger_account'] . '</td>';
if ($object->nature == 4) print '<td class="center">' . $line['payment_mode'] . '</td>'; print '<td>' . $line['label_operation'] . '</td>';
print '<td class="right nowraponall">' . $line['debit'] . '</td>'; if ($object->nature == 4) print '<td class="center">' . $line['payment_mode'] . '</td>';
print '<td class="right nowraponall">' . $line['credit'] . '</td>'; print '<td class="right nowraponall">' . $line['debit'] . '</td>';
print '</tr>'; print '<td class="right nowraponall">' . $line['credit'] . '</td>';
print '</tr>';
}
} }
} }
} }