This commit is contained in:
James Cole 2018-04-03 19:12:59 +02:00
parent 03a42976b1
commit 609c193b88
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
7 changed files with 26 additions and 9 deletions

View File

@ -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.');
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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);

View File

@ -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 $bill

View File

@ -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:

View File

@ -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"',