Finish the cache use in accountancy, remove the TODOs comment

This commit is contained in:
Laurent Destailleur 2024-06-17 10:39:42 +02:00
parent 5037067cdc
commit 045eb7cecb
4 changed files with 57 additions and 14 deletions

View file

@ -667,7 +667,14 @@ if (!$error && $action == 'writebookkeeping') {
// Line into bank account
foreach ($tabbq[$key] as $k => $mt) {
if ($mt) {
$accountingaccount->fetch(null, $k, true); // $k is accounting bank account. TODO We should use a cache here to avoid this fetch
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true); // $k is accounting account of the bank.
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
$account_label = $accountingaccount->label;
$reflabel = '';

View file

@ -383,7 +383,14 @@ if ($action == 'writebookkeeping' && !$error) {
foreach ($arrayofvat[$key] as $k => $mt) {
if ($mt) {
$accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
$account_label = $accountingaccount->label;
// get compte id and label
@ -686,8 +693,13 @@ if (empty($action) || $action == 'view') {
// Fees
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
if ($mt) {
print '<tr class="oddeven">';

View file

@ -407,7 +407,7 @@ if ($action == 'writebookkeeping' && !$error) {
$totalcredit = 0;
$totaldebit = 0;
$db->begin();
$db->begin(); // We accept transaction into loop so if we hang, we can continue transfer from last error
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
@ -506,11 +506,18 @@ if ($action == 'writebookkeeping' && !$error) {
// Product / Service
if (!$errorforline) {
foreach ($tabht[$key] as $k => $mt) {
$resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
$label_account = $accountingaccount->label;
// get compte id and label
if ($resultfetch > 0) {
if ($accountingaccount->id > 0) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->date_lim_reglement = $val["datereg"];
@ -1128,8 +1135,13 @@ if (empty($action) || $action == 'view') {
// Product / Service
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
print '<tr class="oddeven">';
print "<!-- Product -->";

View file

@ -430,7 +430,7 @@ if ($action == 'writebookkeeping' && !$error) {
$totalcredit = 0;
$totaldebit = 0;
$db->begin();
$db->begin(); // We accept transaction into loop so if we hang, we can continue transfer from last error
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
@ -579,11 +579,18 @@ if ($action == 'writebookkeeping' && !$error) {
// Product / Service
if (!$errorforline) {
foreach ($tabht[$key] as $k => $mt) {
$resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
$label_account = $accountingaccount->label;
// get compte id and label
if ($resultfetch > 0) {
if ($accountingaccount->id > 0) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->date_lim_reglement = $val["datereg"];
@ -1220,8 +1227,13 @@ if (empty($action) || $action == 'view') {
// Product / Service
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(0, $k, true);
$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
} else {
$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
}
print '<tr class="oddeven">';
print "<!-- Product -->";