Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -44,8 +44,6 @@ class CreateController extends Controller
/**
* BillController constructor.
*
*/
public function __construct()
{
@@ -66,17 +64,16 @@ class CreateController extends Controller
/**
* Create a new bill.
*
* @param Request $request
*
* @return Factory|View
*/
public function create(Request $request)
{
$periods = [];
/** @var array $billPeriods */
$billPeriods = config('firefly.bill_periods');
foreach ($billPeriods as $current) {
$periods[$current] = (string)trans('firefly.repeat_freq_' . $current);
$periods[$current] = (string)trans('firefly.repeat_freq_'.$current);
}
$subTitle = (string)trans('firefly.create_new_bill');
$defaultCurrency = app('amount')->getDefaultCurrency();
@@ -92,17 +89,13 @@ class CreateController extends Controller
/**
* Store a new bill.
*
* @param BillStoreRequest $request
*
* @return RedirectResponse
*
*/
public function store(BillStoreRequest $request): RedirectResponse
{
$billData = $request->getBillData();
$billData['active'] = true;
try {
$bill = $this->repository->store($billData);
} catch (FireflyException $e) {
@@ -114,7 +107,7 @@ class CreateController extends Controller
$request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name]));
app('preferences')->mark();
/** @var array|null $files */
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files);

View File

@@ -42,8 +42,6 @@ class DeleteController extends Controller
/**
* BillController constructor.
*
*/
public function __construct()
{
@@ -65,8 +63,6 @@ class DeleteController extends Controller
/**
* Delete a bill.
*
* @param Bill $bill
*
* @return Factory|View
*/
public function delete(Bill $bill)
@@ -81,10 +77,7 @@ class DeleteController extends Controller
/**
* Destroy a bill.
*
* @param Request $request
* @param Bill $bill
*
* @return RedirectResponse|Redirector
* @return Redirector|RedirectResponse
*/
public function destroy(Request $request, Bill $bill)
{

View File

@@ -44,8 +44,6 @@ class EditController extends Controller
/**
* BillController constructor.
*
*/
public function __construct()
{
@@ -66,19 +64,17 @@ class EditController extends Controller
/**
* Edit a bill.
*
* @param Request $request
* @param Bill $bill
*
* @return Factory|View
*/
public function edit(Request $request, Bill $bill)
{
$periods = [];
/** @var array $billPeriods */
$billPeriods = config('firefly.bill_periods');
foreach ($billPeriods as $current) {
$periods[$current] = (string)trans('firefly.' . $current);
$periods[$current] = (string)trans('firefly.'.$current);
}
$subTitle = (string)trans('firefly.edit_bill', ['name' => $bill->name]);
@@ -114,11 +110,6 @@ class EditController extends Controller
/**
* Update a bill.
*
* @param BillUpdateRequest $request
* @param Bill $bill
*
* @return RedirectResponse
*/
public function update(BillUpdateRequest $request, Bill $bill): RedirectResponse
{
@@ -128,7 +119,7 @@ class EditController extends Controller
$request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name]));
app('preferences')->mark();
/** @var array|null $files */
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files);

View File

@@ -50,8 +50,6 @@ class IndexController extends Controller
/**
* BillController constructor.
*
*/
public function __construct()
{
@@ -71,7 +69,7 @@ class IndexController extends Controller
/**
* Show all bills.
*/
public function index(): View | Application | Factory | \Illuminate\Contracts\Foundation\Application
public function index(): Application|Factory|\Illuminate\Contracts\Foundation\Application|View
{
$this->cleanupObjectGroups();
$this->repository->correctOrder();
@@ -85,7 +83,7 @@ class IndexController extends Controller
// sub one day from temp start so the last paid date is one day before it should be.
$tempStart = clone $start;
// 2023-06-23 do not sub one day from temp start, fix is in BillTransformer::payDates instead
//$tempStart->subDay();
// $tempStart->subDay();
$parameters->set('start', $tempStart);
$parameters->set('end', $end);
@@ -99,11 +97,12 @@ class IndexController extends Controller
// make bill groups:
$bills = [
0 => [ // the index is the order, not the ID.
'object_group_id' => 0,
'object_group_title' => (string)trans('firefly.default_group_title_name'),
'bills' => [],
'object_group_id' => 0,
'object_group_title' => (string)trans('firefly.default_group_title_name'),
'bills' => [],
],
];
/** @var Bill $bill */
foreach ($collection as $bill) {
$array = $transformer->transform($bill);
@@ -138,9 +137,24 @@ class IndexController extends Controller
}
/**
* @param array $bills
*
* @return array
* Set the order of a bill.
*/
public function setOrder(Request $request, Bill $bill): JsonResponse
{
$objectGroupTitle = (string)$request->get('objectGroupTitle');
$newOrder = (int)$request->get('order');
$this->repository->setOrder($bill, $newOrder);
if ('' !== $objectGroupTitle) {
$this->repository->setObjectGroup($bill, $objectGroupTitle);
}
if ('' === $objectGroupTitle) {
$this->repository->removeObjectGroup($bill);
}
return response()->json(['data' => 'OK']);
}
/**
* @throws FireflyException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
@@ -180,15 +194,10 @@ class IndexController extends Controller
$sums[$groupOrder][$currencyId]['per_period'] = bcadd($sums[$groupOrder][$currencyId]['per_period'], $this->amountPerPeriod($bill, $range));
}
}
return $sums;
}
/**
* @param array $bill
* @param string $range
*
* @return string
*/
private function amountPerPeriod(array $bill, string $range): string
{
$avg = bcdiv(bcadd((string)$bill['amount_min'], (string)$bill['amount_max']), '2');
@@ -230,17 +239,13 @@ class IndexController extends Controller
return $perPeriod;
}
/**
* @param array $sums
*
* @return array
*/
private function getTotals(array $sums): array
{
$totals = [];
if (count($sums) < 2) {
return [];
}
/**
* @var array $array
*/
@@ -267,27 +272,4 @@ class IndexController extends Controller
return $totals;
}
/**
* Set the order of a bill.
*
* @param Request $request
* @param Bill $bill
*
* @return JsonResponse
*/
public function setOrder(Request $request, Bill $bill): JsonResponse
{
$objectGroupTitle = (string)$request->get('objectGroupTitle');
$newOrder = (int)$request->get('order');
$this->repository->setOrder($bill, $newOrder);
if ('' !== $objectGroupTitle) {
$this->repository->setObjectGroup($bill, $objectGroupTitle);
}
if ('' === $objectGroupTitle) {
$this->repository->removeObjectGroup($bill);
}
return response()->json(['data' => 'OK']);
}
}

View File

@@ -54,8 +54,6 @@ class ShowController extends Controller
/**
* BillController constructor.
*
*/
public function __construct()
{
@@ -77,10 +75,7 @@ class ShowController extends Controller
/**
* Rescan bills for transactions.
*
* @param Request $request
* @param Bill $bill
*
* @return RedirectResponse|Redirector
* @return Redirector|RedirectResponse
*/
public function rescan(Request $request, Bill $bill)
{
@@ -117,10 +112,8 @@ class ShowController extends Controller
/**
* Show a bill.
*
* @param Request $request
* @param Bill $bill
*
* @return Factory|View
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
@@ -129,8 +122,10 @@ class ShowController extends Controller
// add info about rules:
$rules = $this->repository->getRulesForBill($bill);
$subTitle = $bill->name;
/** @var Carbon $start */
$start = session('start');
/** @var Carbon $end */
$end = session('end');
$year = $start->year;
@@ -159,11 +154,11 @@ class ShowController extends Controller
$object = $manager->createData($resource)->toArray();
$object['data']['currency'] = $bill->transactionCurrency;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setBill($bill)->setLimit($pageSize)->setPage($page)->withBudgetInformation()
->withCategoryInformation()->withAccountInformation();
->withCategoryInformation()->withAccountInformation()
;
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('bills.show', [$bill->id]));
@@ -171,7 +166,6 @@ class ShowController extends Controller
$collection = $this->repository->getAttachments($bill);
$attachments = new Collection();
if ($collection->count() > 0) {
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
@@ -182,7 +176,6 @@ class ShowController extends Controller
);
}
return view('bills.show', compact('attachments', 'groups', 'rules', 'yearAverage', 'overallAverage', 'year', 'object', 'bill', 'subTitle'));
}
}