mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 08:30:06 +00:00
New converters for #180 (Bill)
This commit is contained in:
@@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;
|
|||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BillId
|
* Class BillId
|
||||||
@@ -18,11 +19,14 @@ class BillId extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var BillRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
|
||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$bill = Auth::user()->bills()->find($this->mapped[$this->index][$this->value]);
|
$bill = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
} else {
|
||||||
$bill = Auth::user()->bills()->find($this->value);
|
$bill = $repository->find($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bill;
|
return $bill;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BillName
|
* Class BillName
|
||||||
@@ -18,13 +18,15 @@ class BillName extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var BillRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
|
||||||
$bill = null;
|
$bill = null;
|
||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$bill = Auth::user()->bills()->find($this->mapped[$this->index][$this->value]);
|
$bill = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
} else {
|
||||||
|
$bills = $repository->getBills();
|
||||||
$bills = Auth::user()->bills()->get();
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
if ($bill->name == $this->value) {
|
if ($bill->name == $this->value) {
|
||||||
|
|||||||
@@ -49,6 +49,23 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a bill by ID.
|
||||||
|
*
|
||||||
|
* @param int $billId
|
||||||
|
*
|
||||||
|
* @return Bill
|
||||||
|
*/
|
||||||
|
public function find(int $billId) : Bill
|
||||||
|
{
|
||||||
|
$bill = $this->user->bills()->find($billId);
|
||||||
|
if (is_null($bill)) {
|
||||||
|
$bill = new Bill;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bill;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ interface BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Bill $bill): bool;
|
public function destroy(Bill $bill): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a bill by ID.
|
||||||
|
*
|
||||||
|
* @param int $billId
|
||||||
|
*
|
||||||
|
* @return Bill
|
||||||
|
*/
|
||||||
|
public function find(int $billId) : Bill;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user