2016-05-20 01:57:45 -05:00
|
|
|
<?php
|
2016-05-20 05:27:31 -05:00
|
|
|
/**
|
|
|
|
* JsonController.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-04 23:52:15 -05:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 05:27:31 -05:00
|
|
|
*/
|
|
|
|
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-20 01:57:45 -05:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-24 15:53:38 -06:00
|
|
|
|
2015-03-06 01:20:27 -06:00
|
|
|
use Amount;
|
2015-04-09 14:36:58 -05:00
|
|
|
use Carbon\Carbon;
|
2016-12-28 04:34:00 -06:00
|
|
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
2017-04-16 15:15:05 -05:00
|
|
|
use FireflyIII\Models\TransactionType;
|
2015-03-06 01:20:27 -06:00
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
2017-01-22 02:15:53 -06:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
2017-01-20 12:50:22 -06:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2015-04-28 03:36:13 -05:00
|
|
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
2015-06-03 11:22:47 -05:00
|
|
|
use FireflyIII\Support\CacheProperties;
|
2016-12-28 06:02:56 -06:00
|
|
|
use Illuminate\Http\Request;
|
2015-02-24 15:53:38 -06:00
|
|
|
use Response;
|
2015-03-29 00:51:56 -05:00
|
|
|
|
2015-02-24 15:53:38 -06:00
|
|
|
/**
|
|
|
|
* Class JsonController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
2015-03-06 01:20:27 -06:00
|
|
|
class JsonController extends Controller
|
|
|
|
{
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
|
|
|
* JsonController constructor.
|
|
|
|
*/
|
2016-01-08 11:29:47 -06:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 13:40:48 -06:00
|
|
|
parent::__construct();
|
2016-01-08 11:29:47 -06:00
|
|
|
}
|
2015-03-06 01:20:27 -06:00
|
|
|
|
2016-01-14 09:41:15 -06:00
|
|
|
/**
|
2016-12-28 06:02:56 -06:00
|
|
|
* @param Request $request
|
|
|
|
*
|
2016-01-14 09:41:15 -06:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2016-12-28 06:02:56 -06:00
|
|
|
public function action(Request $request)
|
2016-01-14 09:41:15 -06:00
|
|
|
{
|
2016-12-28 06:02:56 -06:00
|
|
|
$count = intval($request->get('count')) > 0 ? intval($request->get('count')) : 1;
|
2016-04-26 14:40:15 -05:00
|
|
|
$keys = array_keys(config('firefly.rule-actions'));
|
2016-01-14 09:41:15 -06:00
|
|
|
$actions = [];
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$actions[$key] = trans('firefly.rule_action_' . $key . '_choice');
|
|
|
|
}
|
2016-01-24 09:12:59 -06:00
|
|
|
$view = view('rules.partials.action', compact('actions', 'count'))->render();
|
2016-01-14 09:41:15 -06:00
|
|
|
|
|
|
|
|
|
|
|
return Response::json(['html' => $view]);
|
|
|
|
}
|
|
|
|
|
2017-01-22 02:15:53 -06:00
|
|
|
/**
|
|
|
|
* @param BudgetRepositoryInterface $repository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function budgets(BudgetRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$return = array_unique($repository->getBudgets()->pluck('name')->toArray());
|
|
|
|
sort($return);
|
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
|
2015-02-24 15:53:38 -06:00
|
|
|
/**
|
|
|
|
* Returns a list of categories.
|
|
|
|
*
|
2017-01-22 02:15:53 -06:00
|
|
|
* @param CategoryRepositoryInterface $repository
|
2015-05-03 05:58:55 -05:00
|
|
|
*
|
2015-02-24 15:53:38 -06:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2017-01-22 02:15:53 -06:00
|
|
|
public function categories(CategoryRepositoryInterface $repository)
|
2015-02-24 15:53:38 -06:00
|
|
|
{
|
2017-01-20 12:50:22 -06:00
|
|
|
$return = array_unique($repository->getCategories()->pluck('name')->toArray());
|
|
|
|
sort($return);
|
2015-02-24 15:53:38 -06:00
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
|
2015-05-05 05:57:27 -05:00
|
|
|
/**
|
|
|
|
* Returns a JSON list of all beneficiaries.
|
|
|
|
*
|
|
|
|
* @param TagRepositoryInterface $tagRepository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function tags(TagRepositoryInterface $tagRepository)
|
|
|
|
{
|
2017-01-20 12:50:22 -06:00
|
|
|
$return = array_unique($tagRepository->get()->pluck('tag')->toArray());
|
|
|
|
sort($return);
|
2015-05-05 05:57:27 -05:00
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-20 12:50:22 -06:00
|
|
|
/**
|
2017-02-24 22:57:01 -06:00
|
|
|
* @param JournalRepositoryInterface $repository
|
2017-01-20 12:50:22 -06:00
|
|
|
*
|
2017-02-24 22:57:01 -06:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-01-20 12:50:22 -06:00
|
|
|
*/
|
|
|
|
public function transactionTypes(JournalRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$return = array_unique($repository->getTransactionTypes()->pluck('type')->toArray());
|
|
|
|
sort($return);
|
2015-03-10 11:26:31 -05:00
|
|
|
|
2017-01-20 12:50:22 -06:00
|
|
|
return Response::json($return);
|
2015-03-10 11:26:31 -05:00
|
|
|
}
|
|
|
|
|
2016-01-24 08:58:16 -06:00
|
|
|
/**
|
2016-12-28 06:02:56 -06:00
|
|
|
* @param Request $request
|
|
|
|
*
|
2016-01-24 08:58:16 -06:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2016-12-28 06:02:56 -06:00
|
|
|
public function trigger(Request $request)
|
2016-01-24 08:58:16 -06:00
|
|
|
{
|
2016-12-28 06:02:56 -06:00
|
|
|
$count = intval($request->get('count')) > 0 ? intval($request->get('count')) : 1;
|
2016-04-26 14:40:15 -05:00
|
|
|
$keys = array_keys(config('firefly.rule-triggers'));
|
2016-01-24 08:58:16 -06:00
|
|
|
$triggers = [];
|
|
|
|
foreach ($keys as $key) {
|
2017-07-15 09:41:07 -05:00
|
|
|
if ($key !== 'user_action') {
|
2016-01-24 08:58:16 -06:00
|
|
|
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
|
|
|
}
|
|
|
|
}
|
2017-09-03 03:16:45 -05:00
|
|
|
asort($triggers);
|
2016-01-24 08:58:16 -06:00
|
|
|
|
2016-01-24 09:12:59 -06:00
|
|
|
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
|
2016-01-24 08:58:16 -06:00
|
|
|
|
|
|
|
|
|
|
|
return Response::json(['html' => $view]);
|
|
|
|
}
|
|
|
|
|
2015-02-24 15:53:38 -06:00
|
|
|
}
|