Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix #1312
James Cole609c193b8888
diff --git a/app/Api/V1/Controllers/BillController.php b/app/Api/V1/Controllers/BillController.phpindex 562ff6d395..a6aeeda7b9 100644--- a/app/Api/V1/Controllers/BillController.php+++ b/app/Api/V1/Controllers/BillController.php@@ -23,6 +23,7 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Controllers;use FireflyIII\Api\V1\Requests\BillRequest;+use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\Bill;use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Transformers\BillTransformer;@@ -126,10 +127,12 @@ class BillController extends Controller* @param BillRequest $request** @return \Illuminate\Http\JsonResponse+ * @throws FireflyException*/public function store(BillRequest $request){$bill = $this->repository->store($request->getAll());+ if(null !== $bill) {$manager = new Manager();$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';$manager->setSerializer(new JsonApiSerializer($baseUrl));@@ -137,6 +140,8 @@ class BillController extends Controller$resource = new Item($bill, new BillTransformer($this->parameters), 'bills');return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');+ }+ throw new FireflyException('Could not store new bill.');}diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.phpindex ee3e104bde..3befb08701 100644--- a/app/Http/Controllers/BillController.php+++ b/app/Http/Controllers/BillController.php@@ -269,6 +269,11 @@ class BillController extends Controller{$billData = $request->getBillData();$bill = $repository->store($billData);+ if (null === $bill) {+ $request->session()->flash('error', (string)trans('firefly.bill_store_error'));++ return redirect(route('bills.create'))->withInput();+ }$request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name]));Preferences::mark();diff --git a/app/Import/Object/ImportBill.php b/app/Import/Object/ImportBill.phpindex 19996e1058..a364e9e679 100644--- a/app/Import/Object/ImportBill.php+++ b/app/Import/Object/ImportBill.php@@ -56,9 +56,9 @@ class ImportBill}/**- * @return Bill+ * @return Bill|null*/- public function getBill(): Bill+ public function getBill(): ?Bill{if (null === $this->bill) {$this->store();@@ -268,9 +268,14 @@ class ImportBill];Log::debug('Found no bill so must create one ourselves. Assume default values.', $data);-- $this->bill = $this->repository->store($data);- Log::debug(sprintf('Successfully stored new bill #%d: %s', $this->bill->id, $this->bill->name));+ $result = $this->repository->store($data);+ if (null !== $result) {+ $this->bill = $result;+ Log::debug(sprintf('Successfully stored new bill #%d: %s', $this->bill->id, $this->bill->name));+ }+ if (null === $result) {+ Log::error('Could not store new bill.');+ }return true;}diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex e8d64aea43..cba39e1599 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -538,9 +538,9 @@ class BillRepository implements BillRepositoryInterface/*** @param array $data*- * @return Bill+ * @return Bill|null*/- public function store(array $data): Bill+ public function store(array $data): ?Bill{/** @var BillFactory $factory */$factory = app(BillFactory::class);diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.phpindex 1530dab099..cd4bfe3cd7 100644--- a/app/Repositories/Bill/BillRepositoryInterface.php+++ b/app/Repositories/Bill/BillRepositoryInterface.php@@ -183,9 +183,9 @@ interface BillRepositoryInterface/*** @param array $data*- * @return Bill+ * @return Bill|null*/- public function store(array $data): Bill;+ public function store(array $data): ?Bill;/*** @param Bill $billdiff --git a/app/Support/Import/Configuration/File/Roles.php b/app/Support/Import/Configuration/File/Roles.phpindex 2877621c32..a619906114 100644--- a/app/Support/Import/Configuration/File/Roles.php+++ b/app/Support/Import/Configuration/File/Roles.php@@ -70,6 +70,7 @@ class Roles implements ConfigurationInterface$stmt = (new Statement)->limit(1)->offset(0);$records = $stmt->process($reader);$headers = $records->fetchOne(0);+ Log::debug('Detected file headers:', $headers);}// example rows:diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 61c34451dd..17db817fc3 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -648,6 +648,7 @@ return ['bill_expected_between' => 'Expected between :start and :end','bill_will_automatch' => 'Bill will automatically linked to matching transactions','skips_over' => 'skips over',+ 'bill_store_error' => 'An unexpected error occurred while storing your new bill. Please check the log files',// accounts:'details_for_asset' => 'Details for asset account ":name"',