1
1
<?php
2
2
namespace App \Crud ;
3
3
4
- use App \Events \ExpenseHistoryBeforeDeleteEvent ;
5
- use Illuminate \Support \Facades \Auth ;
4
+ use App \Events \CashFlowHistoryBeforeDeleteEvent ;
6
5
use Illuminate \Http \Request ;
7
6
use App \Services \CrudService ;
8
- use App \Services \Users ;
9
7
use App \Exceptions \NotAllowedException ;
10
- use App \Models \Expense ;
11
- use App \Models \User ;
8
+ use App \Models \CashFlow ;
12
9
use TorMorten \Eventy \Facades \Events as Hook ;
13
- use Exception ;
14
- use App \Models \ExpenseHistory ;
15
10
16
- class ExpenseHistoryCrud extends CrudService
11
+ class CashFlowHistoryCrud extends CrudService
17
12
{
18
13
/**
19
14
* define the base table
20
15
* @param string
21
16
*/
22
- protected $ table = 'nexopos_expenses_history ' ;
17
+ protected $ table = 'nexopos_cash_flow ' ;
23
18
24
19
/**
25
20
* default identifier
26
21
* @param string
27
22
*/
28
- protected $ identifier = 'expenses /history ' ;
23
+ protected $ identifier = 'cash-flow /history ' ;
29
24
30
25
/**
31
26
* Define namespace
32
27
* @param string
33
28
*/
34
- protected $ namespace = 'ns.expenses -history ' ;
29
+ protected $ namespace = 'ns.cash-flow -history ' ;
35
30
36
31
/**
37
32
* Model Used
38
33
* @param string
39
34
*/
40
- protected $ model = ExpenseHistory ::class;
35
+ protected $ model = CashFlow ::class;
41
36
42
37
/**
43
38
* Define permissions
44
39
* @param array
45
40
*/
46
41
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 ' ,
49
44
'update ' => false ,
50
- 'delete ' => 'nexopos.delete.expenses -history ' ,
45
+ 'delete ' => 'nexopos.delete.cash-flow -history ' ,
51
46
];
52
47
53
48
/**
54
49
* Adding relation
55
50
* @param array
56
51
*/
57
52
public $ relations = [
58
- [ 'nexopos_users as user ' , 'nexopos_expenses_history .author ' , '= ' , 'user.id ' ]
53
+ [ 'nexopos_users as user ' , 'nexopos_cash_flow .author ' , '= ' , 'user.id ' ]
59
54
];
60
55
61
56
/**
@@ -115,14 +110,14 @@ public function __construct()
115
110
public function getLabels ()
116
111
{
117
112
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 . ' ),
126
121
'back_to_list ' => __ ( 'Return to Expenses Histories ' ),
127
122
];
128
123
}
@@ -146,30 +141,15 @@ public function getForm( $entry = null )
146
141
return [
147
142
'main ' => [
148
143
'label ' => __ ( 'Name ' ),
149
- // 'name' => 'name',
150
- // 'value' => $entry->name ?? '',
144
+ 'name ' => 'name ' ,
145
+ 'value ' => $ entry ->name ?? '' ,
151
146
'description ' => __ ( 'Provide a name to the resource. ' )
152
147
],
153
148
'tabs ' => [
154
149
'general ' => [
155
150
'label ' => __ ( 'General ' ),
156
151
'fields ' => [
157
152
[
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
- ], [
173
153
'type ' => 'text ' ,
174
154
'name ' => 'expense_id ' ,
175
155
'label ' => __ ( 'Expense ID ' ),
@@ -179,22 +159,13 @@ public function getForm( $entry = null )
179
159
'name ' => 'expense_name ' ,
180
160
'label ' => __ ( 'Expense Name ' ),
181
161
'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 ?? '' ,
192
162
], [
193
163
'type ' => 'text ' ,
194
164
'name ' => 'value ' ,
195
165
'label ' => __ ( 'Value ' ),
196
166
'value ' => $ entry ->value ?? '' ,
197
- ], ]
167
+ ],
168
+ ]
198
169
]
199
170
]
200
171
];
@@ -215,7 +186,7 @@ public function filterPostInputs( $inputs )
215
186
* @param array of fields
216
187
* @return array of fields
217
188
*/
218
- public function filterPutInputs ( $ inputs , ExpenseHistory $ entry )
189
+ public function filterPutInputs ( $ inputs , CashFlow $ entry )
219
190
{
220
191
return $ inputs ;
221
192
}
@@ -244,10 +215,10 @@ public function hook( $query )
244
215
/**
245
216
* After saving a record
246
217
* @param Request $request
247
- * @param ExpenseHistory $entry
218
+ * @param CashFlow $entry
248
219
* @return void
249
220
*/
250
- public function afterPost ( $ request , ExpenseHistory $ entry )
221
+ public function afterPost ( $ request , CashFlow $ entry )
251
222
{
252
223
return $ request ;
253
224
}
@@ -298,7 +269,7 @@ public function afterPut( $request, $entry )
298
269
* @return void
299
270
*/
300
271
public function beforeDelete ( $ namespace , $ id , $ model ) {
301
- if ( $ namespace == 'ns.expenses -history ' ) {
272
+ if ( $ namespace == 'ns.cash-flow -history ' ) {
302
273
/**
303
274
* Perform an action before deleting an entry
304
275
* In case something wrong, this response can be returned
@@ -314,11 +285,11 @@ public function beforeDelete( $namespace, $id, $model ) {
314
285
throw new NotAllowedException ;
315
286
}
316
287
317
- if ( $ model ->status !== ExpenseHistory ::STATUS_ACTIVE ) {
288
+ if ( $ model ->status !== CashFlow ::STATUS_ACTIVE ) {
318
289
throw new NotAllowedException ( __ ( 'This expense history does \'nt have a status that allow deletion. ' ) );
319
290
}
320
291
321
- event ( new ExpenseHistoryBeforeDeleteEvent ( ExpenseHistory ::find ( $ model ->id ) ) );
292
+ event ( new CashFlowHistoryBeforeDeleteEvent ( CashFlow ::find ( $ model ->id ) ) );
322
293
323
294
return [
324
295
'status ' => 'success ' ,
@@ -333,18 +304,18 @@ public function beforeDelete( $namespace, $id, $model ) {
333
304
*/
334
305
public function getColumns () {
335
306
return [
336
- 'expense_name ' => [
337
- 'label ' => __ ( 'Expense Name ' ),
307
+ 'name ' => [
308
+ 'label ' => __ ( 'Name ' ),
338
309
'$direction ' => '' ,
339
310
'$sort ' => false
340
311
],
341
- 'expense_category_name ' => [
342
- 'label ' => __ ( 'Category Name ' ),
312
+ 'value ' => [
313
+ 'label ' => __ ( 'Value ' ),
343
314
'$direction ' => '' ,
344
315
'$sort ' => false
345
316
],
346
- 'value ' => [
347
- 'label ' => __ ( 'Value ' ),
317
+ 'operation ' => [
318
+ 'label ' => __ ( 'Operation ' ),
348
319
'$direction ' => '' ,
349
320
'$sort ' => false
350
321
],
@@ -371,13 +342,34 @@ public function setActions( $entry, $namespace )
371
342
$ entry ->{ '$toggled ' } = false ;
372
343
$ entry ->{ '$id ' } = $ entry ->id ;
373
344
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
+
374
366
// you can make changes here
375
367
$ entry ->{'$actions ' } = [
376
368
[
377
369
'label ' => __ ( 'Delete ' ),
378
370
'namespace ' => 'delete ' ,
379
371
'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 ),
381
373
'confirm ' => [
382
374
'message ' => __ ( 'Would you like to delete this ? ' ),
383
375
]
@@ -418,7 +410,7 @@ public function bulkAction( Request $request )
418
410
419
411
foreach ( $ request ->input ( 'entries ' ) as $ id ) {
420
412
$ entity = $ this ->model ::find ( $ id );
421
- if ( $ entity instanceof ExpenseHistory ) {
413
+ if ( $ entity instanceof CashFlow ) {
422
414
$ entity ->delete ();
423
415
$ status [ 'success ' ]++;
424
416
} else {
@@ -438,11 +430,11 @@ public function bulkAction( Request $request )
438
430
public function getLinks ()
439
431
{
440
432
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} ' . '' ),
446
438
];
447
439
}
448
440
0 commit comments