11<?php
22namespace App \Crud ;
33
4- use App \Events \ExpenseHistoryBeforeDeleteEvent ;
5- use Illuminate \Support \Facades \Auth ;
4+ use App \Events \CashFlowHistoryBeforeDeleteEvent ;
65use Illuminate \Http \Request ;
76use App \Services \CrudService ;
8- use App \Services \Users ;
97use App \Exceptions \NotAllowedException ;
10- use App \Models \Expense ;
11- use App \Models \User ;
8+ use App \Models \CashFlow ;
129use 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
0 commit comments