Skip to content

Commit 9ddcb59

Browse files
committed
cards no dashboard
1 parent eb57f40 commit 9ddcb59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8871
-1415
lines changed

.env.example

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
APP_ENV=local
2-
APP_KEY=
2+
APP_KEY=base64:gmmJg/k7VWyPFE7tIF62ad6iCp1NVV/+P3FqNQnzyIM=
33
APP_DEBUG=true
44
APP_LOG_LEVEL=debug
55
APP_URL=http://localhost
66

77
DB_CONNECTION=mysql
88
DB_HOST=127.0.0.1
99
DB_PORT=3306
10-
DB_DATABASE=homestead
11-
DB_USERNAME=homestead
12-
DB_PASSWORD=secret
10+
DB_DATABASE=son
11+
DB_USERNAME=root
12+
DB_PASSWORD=root
1313

14-
BROADCAST_DRIVER=log
14+
BROADCAST_DRIVER=pusher
1515
CACHE_DRIVER=file
1616
SESSION_DRIVER=file
1717
QUEUE_DRIVER=sync
@@ -27,14 +27,14 @@ MAIL_USERNAME=null
2727
MAIL_PASSWORD=null
2828
MAIL_ENCRYPTION=null
2929

30-
PUSHER_APP_ID=
31-
PUSHER_KEY=
32-
PUSHER_SECRET=
30+
PUSHER_APP_ID=335093
31+
PUSHER_KEY=722fe87d08a56a1d5599
32+
PUSHER_SECRET=7fdb85e10843a494fa8b
3333

3434
URL_ADMIN_LOGIN=/admin/login
3535
URL_ADMIN_LOGOUT=/admin/logout
3636

37-
JWT_SECRET=secret
37+
JWT_SECRET=vndSsxjdHPcGCzKOLwuGVassQDtybcYS
3838

3939
BANK_LOGO_DEFAULT=default.png
4040

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace CodeFin\Events;
4+
5+
use CodeFin\Models\BankAccount;
6+
use Illuminate\Broadcasting\PrivateChannel;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
8+
9+
class BankAccountBalanceUpdatedEvent implements ShouldBroadcast
10+
{
11+
/**
12+
* @var BankAccount
13+
*/
14+
public $bankAccount;
15+
16+
public function __construct(BankAccount $bankAccount)
17+
{
18+
$this->bankAccount = $bankAccount;
19+
}
20+
21+
public function broadcastOn()
22+
{
23+
return new PrivateChannel("client.{$this->bankAccount->client_id}");
24+
}
25+
}

app/Http/Controllers/Api/BankAccountsController.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use CodeFin\Http\Requests\BankAccountCreateRequest;
99
use CodeFin\Http\Requests\BankAccountUpdateRequest;
1010
use CodeFin\Repositories\Interfaces\BankAccountRepository;
11+
use Illuminate\Http\Request;
1112

1213

1314
class BankAccountsController extends Controller
@@ -28,14 +29,18 @@ public function lists()
2829
{
2930
return $this->repository->skipPresenter()->all(['id','name','account']);
3031
}
32+
3133
/**
3234
* Display a listing of the resource.
3335
*
36+
* @param Request $request
3437
* @return \Illuminate\Http\Response
3538
*/
36-
public function index()
39+
public function index(Request $request)
3740
{
38-
return $this->repository->paginate();
41+
$limit = (int)$request->get('limit', null);
42+
$limit = $limit > 0 ? $limit : null;
43+
return $this->repository->paginate($limit);
3944
}
4045

4146
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace CodeFin\Http\Controllers\Api;
4+
5+
use Carbon\Carbon;
6+
7+
trait BillControllerTrait
8+
{
9+
public function findToPayToToday(){
10+
$dateStart = new Carbon();
11+
$dateEnd = $dateStart->copy();
12+
return $this->repository->getTotalFromPeriod($dateStart, $dateEnd);
13+
}
14+
15+
public function findToPayRestOfMonth(){
16+
$dateStart = (new Carbon())->addDays(1);
17+
if($dateStart->month != (new Carbon())->month){
18+
$dateStart->subDays(1);
19+
}
20+
$dateEnd = $dateStart->copy()->day($dateStart->daysInMonth);
21+
return $this->repository->getTotalFromPeriod($dateStart, $dateEnd);
22+
}
23+
}

app/Http/Controllers/Api/BillPaysController.php

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodeFin\Http\Controllers\Api;
44

55
use CodeFin\Criteria\FindBetweenDateBRCriteria;
6+
use CodeFin\Presenters\BillSerializerPresenter;
67
use CodeFin\Criteria\FindByValueBRCriteria;
78
use CodeFin\Http\Controllers\Controller;
89
use CodeFin\Http\Controllers\Response;
@@ -14,6 +15,7 @@
1415

1516
class BillPaysController extends Controller
1617
{
18+
use BillControllerTrait;
1719

1820
/**
1921
* @var BillPayRepository
@@ -36,6 +38,7 @@ public function index(Request $request)
3638
{
3739
$searchParam = config('repository.criteria.params.search');
3840
$search = $request->get($searchParam);
41+
$this->repository->setPresenter(BillSerializerPresenter::class);
3942
$this->repository
4043
->pushCriteria(new FindBetweenDateBRCriteria($search, 'date_due'))
4144
->pushCriteria(new FindByValueBRCriteria($search));

app/Http/Controllers/Api/BillReceivesController.php

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodeFin\Http\Controllers\Api;
44

55
use CodeFin\Criteria\FindBetweenDateBRCriteria;
6+
use CodeFin\Presenters\BillSerializerPresenter;
67
use CodeFin\Criteria\FindByValueBRCriteria;
78
use CodeFin\Http\Controllers\Controller;
89
use CodeFin\Http\Controllers\Response;
@@ -15,6 +16,7 @@
1516

1617
class BillReceivesController extends Controller
1718
{
19+
use BillControllerTrait;
1820

1921
/**
2022
* @var BillReceiveRepository
@@ -37,6 +39,7 @@ public function index(Request $request)
3739
{
3840
$searchParam = config('repository.criteria.params.search');
3941
$search = $request->get($searchParam);
42+
$this->repository->setPresenter(BillSerializerPresenter::class);
4043
$this->repository
4144
->pushCriteria(new FindBetweenDateBRCriteria($search, 'date_due'))
4245
->pushCriteria(new FindByValueBRCriteria($search));

app/Http/Controllers/Api/CashFlowsController.php

+7
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public function index()
2929
$dateEnd = $dateStart->copy()->addMonths(10);
3030
return $this->repository->getCashFlow($dateStart, $dateEnd);
3131
}
32+
33+
public function monthly()
34+
{
35+
$dateStart = new Carbon();
36+
$dateEnd = $dateStart->copy()->addDays(30);
37+
return $this->repository->getCashFlowByPeriod($dateStart,$dateEnd);
38+
}
3239
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace CodeFin\Presenters;
4+
5+
use CodeFin\Serializer\BillSerializer;
6+
use CodeFin\Transformers\BillSerializerTransformer;
7+
use CodeFin\Transformers\BillTransformer;
8+
use Prettus\Repository\Presenter\FractalPresenter;
9+
10+
/**
11+
* Class BillPayPresenter
12+
*
13+
* @package namespace CodeFin\Presenters;
14+
*/
15+
class BillSerializerPresenter extends FractalPresenter
16+
{
17+
/**
18+
* @var BillPresenter
19+
*/
20+
private $presenter;
21+
22+
/**
23+
* BillPaySerializerPresenter constructor.
24+
* @param BillPresenter $presenter
25+
*/
26+
public function __construct(BillPresenter $presenter)
27+
{
28+
parent::__construct();
29+
$this->presenter = $presenter;
30+
}
31+
32+
/**
33+
* Transformer
34+
*
35+
* @return \League\Fractal\TransformerAbstract
36+
*/
37+
public function getTransformer()
38+
{
39+
return new BillSerializerTransformer($this->presenter);
40+
}
41+
}

app/Providers/BroadcastServiceProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class BroadcastServiceProvider extends ServiceProvider
1414
*/
1515
public function boot()
1616
{
17-
Broadcast::routes();
17+
Broadcast::routes(['middleware'=>['web','cors','auth:api']]);
1818

1919
/*
2020
* Authenticate the user's personal channel...
2121
*/
22-
Broadcast::channel('App.User.*', function ($user, $userId) {
23-
return (int) $user->id === (int) $userId;
22+
Broadcast::channel('client.*', function ($user, $clientId) {
23+
return (int) $user->client_id === (int) $clientId;
2424
});
2525
}
2626
}

app/Repositories/BankAccountRepositoryEloquent.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodeFin\Repositories;
44

55
use CodeFin\Criteria\LockTableCriteria;
6+
use CodeFin\Events\BankAccountBalanceUpdatedEvent;
67
use CodeFin\Models\BankAccount;
78
use CodeFin\Presenters\BankAccountPresenter;
89
use CodeFin\Repositories\Interfaces\BankAccountRepository;
@@ -33,7 +34,7 @@ public function addBalance($id, $value)
3334
$model->balance = $model->balance + $value;
3435
$model->save();
3536
\DB::commit();
36-
37+
broadcast(new BankAccountBalanceUpdatedEvent($model));
3738
$this->popCriteria(LockTableCriteria::class);
3839

3940
$this->skipPresenter = $skipPresenter;

app/Repositories/Interfaces/BillPayRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodeFin\Repositories\Interfaces;
44

5+
use Carbon\Carbon;
56
use Prettus\Repository\Contracts\RepositoryCriteriaInterface;
67
use Prettus\Repository\Contracts\RepositoryInterface;
78

@@ -11,5 +12,5 @@
1112
*/
1213
interface BillPayRepository extends RepositoryInterface, RepositoryCriteriaInterface
1314
{
14-
//
15+
public function getTotalFromPeriod(Carbon $dateStart, Carbon $dateEnd);
1516
}

app/Repositories/Interfaces/BillReceiveRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodeFin\Repositories\Interfaces;
44

5+
use Carbon\Carbon;
56
use Prettus\Repository\Contracts\RepositoryCriteriaInterface;
67
use Prettus\Repository\Contracts\RepositoryInterface;
78

@@ -11,5 +12,5 @@
1112
*/
1213
interface BillReceiveRepository extends RepositoryInterface, RepositoryCriteriaInterface
1314
{
14-
//
15+
public function getTotalFromPeriod(Carbon $dateStart, Carbon $dateEnd);
1516
}

app/Repositories/Interfaces/StatementRepository.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ interface StatementRepository extends RepositoryInterface
1313
{
1414
public function getCashFlow(Carbon $dateStart, Carbon $dateEnd);
1515
public function getBalanceByMonth(Carbon $date);
16+
public function getCashFlowByPeriod(Carbon $dateStart, Carbon $dateEnd);
1617
}

app/Repositories/Traits/BillRepositoryTrait.php

+61
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace CodeFin\Repositories\Traits;
44

5+
use Carbon\Carbon;
56
use CodeFin\Events\BillStoredEvent;
7+
use CodeFin\Serializer\BillSerializer;
68

79
trait BillRepositoryTrait
810
{
@@ -49,4 +51,63 @@ public function update(array $attributes, $id)
4951
return $this->parserResult($model);
5052
}
5153

54+
public function paginate($limit = null, $columns = ['*'], $method = "paginate")
55+
{
56+
$skipPresenter = $this->skipPresenter;
57+
$this->skipPresenter();
58+
$collection = parent::paginate($limit,$columns,$method);
59+
$this->skipPresenter($skipPresenter);
60+
return $this->parserResult(new BillSerializer($collection,$this->formatBillsData()));
61+
}
62+
63+
public function getTotalFromPeriod(Carbon $dateStart, Carbon $dateEnd)
64+
{
65+
$result = $this->getQueryTotal()
66+
->whereBetween('date_due',[$dateStart->format('Y-m-d'),$dateEnd->format('Y-m-d')])
67+
->get();
68+
return [
69+
'total' => (float)$result->first()->total
70+
];
71+
}
72+
73+
protected function getTotalByDone($done)
74+
{
75+
$result = $this->getQueryTotalByDone($done)->get();
76+
return (float)$result->first()->total;
77+
}
78+
79+
protected function getQueryTotal()
80+
{
81+
$this->resetModel();
82+
$this->applyCriteria();
83+
return $this->model->selectRaw('SUM(value) as total');
84+
}
85+
86+
protected function getQueryTotalByDone($done)
87+
{
88+
return $this->getQueryTotal()
89+
->where('done','=',$done);
90+
}
91+
92+
protected function getTotalExpired()
93+
{
94+
$result = $this->getQueryTotalByDone(0)
95+
->where('date_due','<',(new Carbon())->format('Y-m-d'))
96+
->get();
97+
return (float)$result->first()->total;
98+
}
99+
100+
protected function formatBillsData()
101+
{
102+
$totalPaid = $this->getTotalByDone(1);
103+
$totalToPay = $this->getTotalByDone(0);
104+
$totalExpired = $this->getTotalExpired();
105+
106+
return [
107+
'total_paid' => $totalPaid,
108+
'total_to_pay' => $totalToPay,
109+
'total_expired' => $totalExpired,
110+
];
111+
}
112+
52113
}

0 commit comments

Comments
 (0)