/** * Update the status of an existing journal voucher * * @param int $id Voucher id * @param App\Kwaai\Security\Repositories\Journal\JournalInterface $Journal * * @return string */ public function updateJournalVoucherStatus($id, $Journal = null, $JournalVoucher = null, $newStatus = null) { if (empty($newStatus)) { $debitSum = $this->JournalEntry->getJournalVoucherDebitSum($id); $creditSum = $this->JournalEntry->getJournalVoucherCreditSum($id); // var_dump((string) $debitSum, (string) $creditSum, $debitSum == $creditSum, round($debitSum) == round($creditSum), (string) $debitSum == (string) $creditSum ); if ((string) $debitSum == (string) $creditSum) { $status = 'B'; } else { $status = 'A'; } } else { $status = $newStatus; } if (empty($JournalVoucher)) { $JournalVoucher = $this->JournalVoucher->byId($id); } $currentStatus = $JournalVoucher->status; if ($currentStatus != $status) { $this->JournalVoucher->update(array('status' => $status), $JournalVoucher); if (!empty($Journal)) { $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::journal-management.status'), 'field_lang_key' => 'decima-accounting::journal-management.status', 'old_value' => $this->Lang->get('decima-accounting::journal-management.' . $currentStatus), 'new_value' => $this->Lang->get('decima-accounting::journal-management.' . $status)), $Journal); } } return $status; }