Skip to content

Commit d5ead66

Browse files
authored
Merge pull request #254 from Blair2004/v4.4.x
V4.4.x
2 parents ec74f1c + e09eb20 commit d5ead66

File tree

119 files changed

+2857
-1106
lines changed

Some content is hidden

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

119 files changed

+2857
-1106
lines changed

app/Console/Commands/ComputeDailyReportCommand.php

100644100755
File mode changed.

app/Crud/ExpenseHistoryCrud.php app/Crud/CashFlowHistoryCrud.php

+63-71
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
11
<?php
22
namespace App\Crud;
33

4-
use App\Events\ExpenseHistoryBeforeDeleteEvent;
5-
use Illuminate\Support\Facades\Auth;
4+
use App\Events\CashFlowHistoryBeforeDeleteEvent;
65
use Illuminate\Http\Request;
76
use App\Services\CrudService;
8-
use App\Services\Users;
97
use App\Exceptions\NotAllowedException;
10-
use App\Models\Expense;
11-
use App\Models\User;
8+
use App\Models\CashFlow;
129
use TorMorten\Eventy\Facades\Events as Hook;
13-
use Exception;
14-
use App\Models\ExpenseHistory;
1510

16-
class ExpenseHistoryCrud extends CrudService
11+
class CashFlowHistoryCrud extends CrudService
1712
{
1813
/**
1914
* define the base table
2015
* @param string
2116
*/
22-
protected $table = 'nexopos_expenses_history';
17+
protected $table = 'nexopos_cash_flow';
2318

2419
/**
2520
* default identifier
2621
* @param string
2722
*/
28-
protected $identifier = 'expenses/history';
23+
protected $identifier = 'cash-flow/history';
2924

3025
/**
3126
* Define namespace
3227
* @param string
3328
*/
34-
protected $namespace = 'ns.expenses-history';
29+
protected $namespace = 'ns.cash-flow-history';
3530

3631
/**
3732
* Model Used
3833
* @param string
3934
*/
40-
protected $model = ExpenseHistory::class;
35+
protected $model = CashFlow::class;
4136

4237
/**
4338
* Define permissions
4439
* @param array
4540
*/
4641
protected $permissions = [
47-
'create' => false,
48-
'read' => 'nexopos.read.expenses-history',
42+
'create' => false, // 'nexopos.create.cash-flow-history',
43+
'read' => 'nexopos.read.cash-flow-history',
4944
'update' => false,
50-
'delete' => 'nexopos.delete.expenses-history',
45+
'delete' => 'nexopos.delete.cash-flow-history',
5146
];
5247

5348
/**
5449
* Adding relation
5550
* @param array
5651
*/
5752
public $relations = [
58-
[ 'nexopos_users as user', 'nexopos_expenses_history.author', '=', 'user.id' ]
53+
[ 'nexopos_users as user', 'nexopos_cash_flow.author', '=', 'user.id' ]
5954
];
6055

6156
/**
@@ -115,14 +110,14 @@ public function __construct()
115110
public function getLabels()
116111
{
117112
return [
118-
'list_title' => __( 'Expenses History List' ),
119-
'list_description' => __( 'Display all Expenses History.' ),
120-
'no_entry' => __( 'No Expense History has been registered' ),
121-
'create_new' => __( 'Add a new Expense history' ),
122-
'create_title' => __( 'Create a new Expense History' ),
123-
'create_description' => __( 'Register a new Expense History and save it.' ),
124-
'edit_title' => __( 'Edit Expense History' ),
125-
'edit_description' => __( 'Modify Expense History.' ),
113+
'list_title' => __( 'Cash Flow List' ),
114+
'list_description' => __( 'Display all Cash Flow.' ),
115+
'no_entry' => __( 'No Cash Flow has been registered' ),
116+
'create_new' => __( 'Add a new Cash Flow' ),
117+
'create_title' => __( 'Create a new Cash Flow' ),
118+
'create_description' => __( 'Register a new Cash Flow and save it.' ),
119+
'edit_title' => __( 'Edit Cash Flow' ),
120+
'edit_description' => __( 'Modify Cash Flow.' ),
126121
'back_to_list' => __( 'Return to Expenses Histories' ),
127122
];
128123
}
@@ -146,30 +141,15 @@ public function getForm( $entry = null )
146141
return [
147142
'main' => [
148143
'label' => __( 'Name' ),
149-
// 'name' => 'name',
150-
// 'value' => $entry->name ?? '',
144+
'name' => 'name',
145+
'value' => $entry->name ?? '',
151146
'description' => __( 'Provide a name to the resource.' )
152147
],
153148
'tabs' => [
154149
'general' => [
155150
'label' => __( 'General' ),
156151
'fields' => [
157152
[
158-
'type' => 'text',
159-
'name' => 'author',
160-
'label' => __( 'Author' ),
161-
'value' => $entry->author ?? '',
162-
], [
163-
'type' => 'text',
164-
'name' => 'created_at',
165-
'label' => __( 'Created At' ),
166-
'value' => $entry->created_at ?? '',
167-
], [
168-
'type' => 'text',
169-
'name' => 'expense_category_name',
170-
'label' => __( 'Expense Category Name' ),
171-
'value' => $entry->expense_category_name ?? '',
172-
], [
173153
'type' => 'text',
174154
'name' => 'expense_id',
175155
'label' => __( 'Expense ID' ),
@@ -179,22 +159,13 @@ public function getForm( $entry = null )
179159
'name' => 'expense_name',
180160
'label' => __( 'Expense Name' ),
181161
'value' => $entry->expense_name ?? '',
182-
], [
183-
'type' => 'text',
184-
'name' => 'id',
185-
'label' => __( 'Id' ),
186-
'value' => $entry->id ?? '',
187-
], [
188-
'type' => 'text',
189-
'name' => 'updated_at',
190-
'label' => __( 'Updated At' ),
191-
'value' => $entry->updated_at ?? '',
192162
], [
193163
'type' => 'text',
194164
'name' => 'value',
195165
'label' => __( 'Value' ),
196166
'value' => $entry->value ?? '',
197-
], ]
167+
],
168+
]
198169
]
199170
]
200171
];
@@ -215,7 +186,7 @@ public function filterPostInputs( $inputs )
215186
* @param array of fields
216187
* @return array of fields
217188
*/
218-
public function filterPutInputs( $inputs, ExpenseHistory $entry )
189+
public function filterPutInputs( $inputs, CashFlow $entry )
219190
{
220191
return $inputs;
221192
}
@@ -244,10 +215,10 @@ public function hook( $query )
244215
/**
245216
* After saving a record
246217
* @param Request $request
247-
* @param ExpenseHistory $entry
218+
* @param CashFlow $entry
248219
* @return void
249220
*/
250-
public function afterPost( $request, ExpenseHistory $entry )
221+
public function afterPost( $request, CashFlow $entry )
251222
{
252223
return $request;
253224
}
@@ -298,7 +269,7 @@ public function afterPut( $request, $entry )
298269
* @return void
299270
*/
300271
public function beforeDelete( $namespace, $id, $model ) {
301-
if ( $namespace == 'ns.expenses-history' ) {
272+
if ( $namespace == 'ns.cash-flow-history' ) {
302273
/**
303274
* Perform an action before deleting an entry
304275
* In case something wrong, this response can be returned
@@ -314,11 +285,11 @@ public function beforeDelete( $namespace, $id, $model ) {
314285
throw new NotAllowedException;
315286
}
316287

317-
if ( $model->status !== ExpenseHistory::STATUS_ACTIVE ) {
288+
if ( $model->status !== CashFlow::STATUS_ACTIVE ) {
318289
throw new NotAllowedException( __( 'This expense history does\'nt have a status that allow deletion.' ) );
319290
}
320291

321-
event( new ExpenseHistoryBeforeDeleteEvent( ExpenseHistory::find( $model->id ) ) );
292+
event( new CashFlowHistoryBeforeDeleteEvent( CashFlow::find( $model->id ) ) );
322293

323294
return [
324295
'status' => 'success',
@@ -333,18 +304,18 @@ public function beforeDelete( $namespace, $id, $model ) {
333304
*/
334305
public function getColumns() {
335306
return [
336-
'expense_name' => [
337-
'label' => __( 'Expense Name' ),
307+
'name' => [
308+
'label' => __( 'Name' ),
338309
'$direction' => '',
339310
'$sort' => false
340311
],
341-
'expense_category_name' => [
342-
'label' => __( 'Category Name' ),
312+
'value' => [
313+
'label' => __( 'Value' ),
343314
'$direction' => '',
344315
'$sort' => false
345316
],
346-
'value' => [
347-
'label' => __( 'Value' ),
317+
'operation' => [
318+
'label' => __( 'Operation' ),
348319
'$direction' => '',
349320
'$sort' => false
350321
],
@@ -371,13 +342,34 @@ public function setActions( $entry, $namespace )
371342
$entry->{ '$toggled' } = false;
372343
$entry->{ '$id' } = $entry->id;
373344

345+
$entry->value = ns()->currency->define( $entry->value )->format();
346+
347+
348+
switch( $entry->operation ) {
349+
case CashFlow::OPERATION_CREDIT :
350+
$entry->{ '$cssClass' } = 'bg-green-100 border-green-200 border text-sm';
351+
break;
352+
case CashFlow::OPERATION_DEBIT :
353+
$entry->{ '$cssClass' } = 'bg-red-100 border-red-200 border text-sm';
354+
break;
355+
}
356+
357+
switch( $entry->operation ) {
358+
case CashFlow::OPERATION_CREDIT :
359+
$entry->operation = "<span class='bg-green-400 text-white rounded-full px-2 py-1 text-sm'>" . __( 'Credit' ) . '</span>';
360+
break;
361+
case CashFlow::OPERATION_DEBIT :
362+
$entry->operation = "<span class='bg-red-400 text-white rounded-full px-2 py-1 text-sm'>" . __( 'Debit' ) . '</span>';
363+
break;
364+
}
365+
374366
// you can make changes here
375367
$entry->{'$actions'} = [
376368
[
377369
'label' => __( 'Delete' ),
378370
'namespace' => 'delete',
379371
'type' => 'DELETE',
380-
'url' => ns()->url( '/api/nexopos/v4/crud/ns.expenses-history/' . $entry->id ),
372+
'url' => ns()->url( '/api/nexopos/v4/crud/ns.cash-flow-history/' . $entry->id ),
381373
'confirm' => [
382374
'message' => __( 'Would you like to delete this ?' ),
383375
]
@@ -418,7 +410,7 @@ public function bulkAction( Request $request )
418410

419411
foreach ( $request->input( 'entries' ) as $id ) {
420412
$entity = $this->model::find( $id );
421-
if ( $entity instanceof ExpenseHistory ) {
413+
if ( $entity instanceof CashFlow ) {
422414
$entity->delete();
423415
$status[ 'success' ]++;
424416
} else {
@@ -438,11 +430,11 @@ public function bulkAction( Request $request )
438430
public function getLinks()
439431
{
440432
return [
441-
'list' => ns()->url( 'dashboard/' . 'expenses/history' ),
442-
'create' => ns()->url( 'dashboard/' . 'expenses/history/create' ),
443-
'edit' => ns()->url( 'dashboard/' . 'expenses/history/edit/' ),
444-
'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.expenses-history' ),
445-
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.expenses-history/{id}' . '' ),
433+
'list' => ns()->url( 'dashboard/' . 'cash-flow/history' ),
434+
'create' => ns()->url( 'dashboard/' . 'cash-flow/history/create' ),
435+
'edit' => ns()->url( 'dashboard/' . 'cash-flow/history/edit/' ),
436+
'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.cash-flow-history' ),
437+
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.cash-flow-history/{id}' . '' ),
446438
];
447439
}
448440

app/Crud/ExpenseCategoryCrud.php

+27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use TorMorten\Eventy\Facades\Events as Hook;
99
use Exception;
1010
use App\Models\ExpenseCategory;
11+
use App\Services\Helper;
1112

1213
class ExpenseCategoryCrud extends CrudService
1314
{
@@ -122,6 +123,22 @@ public function getForm( $entry = null )
122123
'label' => __( 'General' ),
123124
'fields' => [
124125
[
126+
'type' => 'select',
127+
'name' => 'operation',
128+
'label' => __( 'Operation' ),
129+
'description' => __( 'All entities attached to this category will either produce a "credit" or "debit" to the cash flow history.' ),
130+
'options' => Helper::kvToJsOptions([
131+
'credit' => __( 'Credit' ),
132+
'debit' => __( 'Debit' )
133+
]),
134+
'value' => $entry->operation ?? '',
135+
], [
136+
'type' => 'text',
137+
'name' => 'account',
138+
'label' => __( 'Account' ),
139+
'description' => __( 'Provide the accounting number for this category.' ),
140+
'value' => $entry->account ?? '',
141+
], [
125142
'type' => 'textarea',
126143
'name' => 'description',
127144
'label' => __( 'Description' ),
@@ -251,6 +268,16 @@ public function getColumns() {
251268
'$direction' => '',
252269
'$sort' => false
253270
],
271+
'account' => [
272+
'label' => __( 'Account' ),
273+
'$direction' => '',
274+
'$sort' => false
275+
],
276+
'operation' => [
277+
'label' => __( 'Operation' ),
278+
'$direction' => '',
279+
'$sort' => false
280+
],
254281
'nexopos_users_username' => [
255282
'label' => __( 'Author' ),
256283
'$direction' => '',

app/Events/ExpenseHistoryBeforeDeleteEvent.php app/Events/CashFlowAfterCreatedEvent.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Events;
44

5-
use App\Models\ExpenseHistory;
5+
use App\Models\CashFlow;
66
use Illuminate\Broadcasting\Channel;
77
use Illuminate\Broadcasting\InteractsWithSockets;
88
use Illuminate\Broadcasting\PresenceChannel;
@@ -11,19 +11,29 @@
1111
use Illuminate\Foundation\Events\Dispatchable;
1212
use Illuminate\Queue\SerializesModels;
1313

14-
class ExpenseHistoryBeforeDeleteEvent
14+
class CashFlowAfterCreatedEvent
1515
{
1616
use Dispatchable, InteractsWithSockets, SerializesModels;
1717

18-
public $expenseHistory;
18+
public $cashFlow;
1919

2020
/**
2121
* Create a new event instance.
2222
*
2323
* @return void
2424
*/
25-
public function __construct( ExpenseHistory $expenseHistory )
25+
public function __construct( CashFlow $cashFlow )
2626
{
27-
$this->expenseHistory = $expenseHistory;
27+
$this->cashFlow = $cashFlow;
28+
}
29+
30+
/**
31+
* Get the channels the event should broadcast on.
32+
*
33+
* @return \Illuminate\Broadcasting\Channel|array
34+
*/
35+
public function broadcastOn()
36+
{
37+
return new PrivateChannel('channel-name');
2838
}
2939
}

0 commit comments

Comments
 (0)