/** * Delete an existing journal entry (soft delete) * * @param array $input * An array as follows: array($id0, $id1,…); * * @return JSON encoded string * A string as follows: * In case of success: {"success" : form.defaultSuccessDeleteMessage} */ public function deleteJournalEntry(array $input) { $count = 0; $periodIsClosed = false; $this->DB->transaction(function () use($input, &$count, &$status, &$periodIsClosed, &$Period) { $loggedUserId = $this->AuthenticationManager->getLoggedUserId(); $organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id'); foreach ($input['id'] as $key => $id) { $count++; $JournalEntry = $this->JournalEntry->byId($id); if ($count == 1) { $JournalVoucher = $this->JournalVoucher->byId($JournalEntry->journal_voucher_id); $Period = $this->Period->byId($JournalVoucher->period_id); if ($Period->is_closed) { $periodIsClosed = true; return; } $JournalVoucher = $this->JournalVoucher->byId($JournalEntry->journal_voucher_id); $Journal = $this->Journal->create(array('journalized_id' => $JournalEntry->journal_voucher_id, 'journalized_type' => $this->JournalVoucher->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId)); } $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::journal-management.journalEntryDeletedJournal', array('number' => $JournalVoucher->number)), $Journal)); $this->JournalEntry->delete($input['id']); } $status = $this->updateJournalVoucherStatus($JournalVoucher->id, $Journal, $JournalVoucher); }); if ($periodIsClosed) { return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::journal-management.closedPeriodValidationMessage2', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month))))); } return json_encode(array('success' => $this->Lang->get('form.defaultSuccessDeleteMessage'), 'status' => $status, 'statusLabel' => $this->Lang->get('decima-accounting::journal-management.' . $status))); }