Compare commits

...

192 Commits

Author SHA1 Message Date
edmondlang 924f4f2ace fix qr api issue 2024-04-10 22:27:09 +08:00
edmondlang 6369282b38 update qr code config 2024-04-10 18:22:11 +08:00
jiasheng224 1991cf2c57 fix qr api issue 2024-04-09 17:42:10 +08:00
Omair Saleh e5347f56b7 change bank in details 2024-04-04 08:22:47 +08:00
Omair Saleh 6673a44137 fix invoice date for april 2024-04-03 12:22:32 +08:00
Omair Saleh 4d3345f613 Merge remote-tracking branch 'origin/master' 2024-04-03 12:17:54 +08:00
Omair Saleh 60b8657773 fix invoice date for april 2024-04-03 12:17:40 +08:00
edmondlang 9f7a8d0d4b hide deletePaidGroupTransaction 2024-03-31 23:12:38 +08:00
edmondlang a87ab6c27f logging delete paid group transaction 2024-03-31 21:41:42 +08:00
edmondlang 462a4776cd delete paid group transaction 2024-03-31 17:36:12 +08:00
edmondlang 7e029c5610 delete paid group transaction 2024-03-30 00:49:55 +08:00
edmondlang 0719285286 show all extra payments from customer 2024-03-29 00:59:30 +08:00
edmondlang 64400d1524 fix ExportsCustomersWalletTransactionHistory 2024-03-29 00:06:22 +08:00
edmondlang be0279f56b fix ExportsCustomersWalletTransactionHistory 2024-03-29 00:02:13 +08:00
Dillon Ngo e15170bc7f Merge branch 'dillon/46.9-warehouse-storage-charges-fixes' into 'master'
Multiple fixes related to storage invoices

See merge request CIEFWorldwideSdnBhd/shipping-portal!212
2024-03-26 00:44:33 +00:00
Dillon Ngo 59f527aee7 Enable back manual payment that was temporary disable at order page for invoices with storage fee 2024-03-26 08:10:34 +08:00
Dillon Ngo d7aa248972 Merge branch 'dillon/55-billplz-fix' into 'master'
Update info log location for vue polling related stuff + perfexcrm integration

See merge request CIEFWorldwideSdnBhd/shipping-portal!211
2024-03-18 12:17:11 +00:00
Dillon Ngo 8e4ff6093e Update info log location for VuePolling JobResourceNotFoundException and PerfexCRM 2024-03-18 14:06:30 +08:00
Dillon Ngo 584169e173 Update info log location for VuePolling JobResourceNotFoundException and PerfexCRM 2024-03-18 13:54:09 +08:00
Dillon Ngo 1679d1ecf4 Fix a problem of unsuccessful payment when shipping invoice is paid first before storage invoice appear 2024-03-16 15:49:02 +08:00
Dillon Ngo 7ca48e9638 Fix a problem in info display inaccurate in payment history for manual payment 2024-03-16 15:17:28 +08:00
Dillon Ngo 14278a888a Merge branch 'dillon/55-billplz-fix' into 'master'
Long term solution to prevent customer making payment to a shipping invoice...

See merge request CIEFWorldwideSdnBhd/shipping-portal!210
2024-03-16 05:52:58 +00:00
Dillon Ngo 5de2554d63 Fix a problem with storage invoice checking when a payment related transaction is deleted at order page 2024-03-15 03:33:58 +08:00
edmondlang 033a835fce update SendPermitsReminderEmails logging 2024-03-14 12:48:25 +08:00
edmondlang 66ddb5da23 update send permits reminder 2024-03-14 12:46:47 +08:00
Dillon Ngo 65782ebf8a Long term solution to prevent customer making payment to a shipping invoice when there is a ongoing dispute 2024-03-14 12:43:58 +08:00
Dillon Ngo 96a089df16 Long term solution to prevent customer making payment to a shipping invoice when there is a ongoing dispute 2024-03-14 12:32:03 +08:00
edmondlang f95545a985 update container remark in order page 2024-03-13 00:20:39 +08:00
edmondlang 9e8685bd02 update container remark in order page 2024-03-13 00:02:52 +08:00
edmondlang 1224735ba8 Merge branch 'master' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal 2024-03-12 23:52:22 +08:00
edmondlang 11e2390059 update container and container remarks 2024-03-12 23:52:07 +08:00
Dillon Ngo c280da36d7 Merge branch 'dillon/55-billplz-fix' into 'master'
Fix a problem reported by Yien where order shipping invoice pending payment despite payment made

See merge request CIEFWorldwideSdnBhd/shipping-portal!209
2024-03-12 06:32:13 +00:00
Dillon Ngo 27529e90ca Fix a problem reported by Yien where order shipping invoice pending payment despite payment made 2024-03-12 14:20:19 +08:00
Dillon Ngo 2e9b0f918c Merge branch 'dillon/46.8-warehouse-storage-charges-fixes' into 'master'
Change log location, 404 page

See merge request CIEFWorldwideSdnBhd/shipping-portal!208
2024-03-09 13:26:32 +00:00
Dillon Ngo 5565d0b39b Update log location JobResourceNotFoundException 2024-03-09 21:17:49 +08:00
Dillon Ngo f1b8c6a556 When a pending verification group payment is deleted, do not display the group with no payment transaction(group payment) 2024-03-09 02:20:34 +08:00
Dillon Ngo 6d210d3713 Fix a problem with deleting a pending verification group payment at order page 2024-03-09 02:16:32 +08:00
Dillon Ngo 5dd2df02fd Hide 'Make Payment' button when there is a group payment pending verification from Admin 2024-03-09 01:22:13 +08:00
Dillon Ngo b207b11336 Fix missing group payment info on order page 2024-03-08 23:53:54 +08:00
Dillon Ngo ffd95ee1cc Fix missing group payment info on order page 2024-03-08 23:31:37 +08:00
Dillon Ngo 73b3995367 Merge branch 'dillon/46.9-warehouse-storage-charges-fixes' into 'master'
Temporary disable manual payment at order page for invoices with storage fee

See merge request CIEFWorldwideSdnBhd/shipping-portal!207
2024-03-08 13:12:33 +00:00
Dillon Ngo 45a2544b9d Temporary disable manual payment at order page for invoices with storage fee 2024-03-08 20:43:38 +08:00
Dillon Ngo 252636a7df Fix 404 exception caught at production laravel logs 2024-03-08 08:46:05 +08:00
Dillon Ngo 3e679fef23 Merge branch 'dillon/46.8-warehouse-storage-charges-fixes' into 'master'
UI Update (Payment and Billing 2 page) on Admin view to see shipping invoices...

See merge request CIEFWorldwideSdnBhd/shipping-portal!206
2024-03-03 11:16:07 +00:00
Dillon Ngo 758498f486 Fix a duplication problem in Pending Payment listing as a result of storage invoices 2024-03-02 14:09:06 +08:00
Dillon Ngo b55e32aece Fix missing container info at admin payment and billing page 2024-03-02 13:26:46 +08:00
Dillon Ngo 00bf7c0cf4 Fix when customer isCreditTerm is updated, waive storage invoices instead of deleting it 2024-03-01 11:47:21 +08:00
edmondlang 24a4d269b3 add edmond in the permits reminder email 2024-03-01 11:27:46 +08:00
Dillon Ngo f191979a53 Hide 'Your Payment Proof' at the order page when does not need to appear 2024-02-29 22:28:18 +08:00
Dillon Ngo c9998029b0 Fix a non functioning group payment delete at order page meant for shipping invoice with storage invoice 2024-02-29 21:10:37 +08:00
Dillon Ngo a442c78156 Refresh page after a payment transaction is suspended/deleted 2024-02-29 17:19:17 +08:00
Dillon Ngo 03c5ced77b Remove code no longer necessary - isBackDoorCheck flag 2024-02-29 16:32:37 +08:00
Dillon Ngo 5c6418cb1f When customer isCreditTerm status is updated to true, all existing storage invoices that is not paid but approve will be deleted 2024-02-29 16:30:57 +08:00
edmondlang 5e636862bb check if the address district name is null 2024-02-27 21:31:14 +08:00
Dillon Ngo e97cbfa618 Fix a problem with missing paid storage invoice when customer credit term status is updated 2024-02-26 16:36:43 +08:00
Dillon Ngo a448172521 UI Update (Payment and Billing 2 page) on Admin view to see shipping invoices with storage invoices on Pending Payment tab and Paid Invoice tab 2024-02-26 16:35:17 +08:00
Dillon Ngo 72ac055ec5 Merge branch 'dillon/46.6-warehouse-storage-charges-fixes' into 'master'
UI Update (Payment and Billing page) on Admin view to see shipping invoices...

See merge request CIEFWorldwideSdnBhd/shipping-portal!205
2024-02-25 07:44:39 +00:00
Dillon Ngo 09383a45a6 UI Update (Payment and Billing page) on Admin view to see shipping invoices with storage invoices on Pending Payment tab and Paid Invoice tab 2024-02-25 15:44:03 +08:00
Dillon Ngo bb1540116c Merge branch 'dillon/46.6-warehouse-storage-charges-fixes' into 'master'
UI Update (Payment and Billing page) on Admin view to see shipping invoices...

See merge request CIEFWorldwideSdnBhd/shipping-portal!204
2024-02-25 07:28:15 +00:00
Dillon Ngo 141062a7bf Fix storage invoice not allow to be regenerated if not yet pay 2024-02-25 15:21:04 +08:00
Dillon Ngo 4179706e04 UI Update (Payment and Billing page) on Admin view to see shipping invoices with storage invoices on Pending Payment tab and Paid Invoice tab 2024-02-25 14:26:54 +08:00
Dillon Ngo eaa21beb83 UI Update (Payment and Billing page) on Admin view to see shipping invoices with storage invoices on Pending Payment tab and Paid Invoice tab 2024-02-25 14:04:19 +08:00
Dillon Ngo 1acc02eb93 UI Update (Payment and Billing page) on Admin view to see shipping invoices with storage invoices on Pending Payment tab and Paid Invoice tab 2024-02-25 13:52:22 +08:00
Dillon Ngo 1f2959a5d2 Merge branch 'dillon/46.7-warehouse-storage-charges-fixes' into dillon/46.6-warehouse-storage-charges-fixes 2024-02-25 13:15:49 +08:00
Dillon Ngo 9b7b7068e1 Merge branch 'dillon/46.5-warehouse-storage-charges-fixes' into dillon/46.6-warehouse-storage-charges-fixes 2024-02-25 13:15:35 +08:00
Dillon Ngo 41e1c346f6 Rename a component 2024-02-25 13:13:09 +08:00
Dillon Ngo 74e9b23f91 Merge branch 'dillon/46.7-warehouse-storage-charges-fixes' into 'master'
Create a regenerate storage invoice feature to debug problem in reading and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!203
2024-02-24 03:49:50 +00:00
Dillon Ngo f949877a7f Create a regenerate storage invoice feature to debug problem in reading and downloading storage invoice 2024-02-24 11:40:51 +08:00
Dillon Ngo 1e876dd103 Merge branch 'dillon/46.7-warehouse-storage-charges-fixes' into 'master'
Create a regenerate storage invoice feature to debug problem in reading and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!202
2024-02-24 03:20:17 +00:00
Dillon Ngo 3d79d0f5e5 Merge branch 'dillon/46.5-warehouse-storage-charges-fixes' into 'master'
User interface to allow admin to update company whether is a credit term...

See merge request CIEFWorldwideSdnBhd/shipping-portal!201
2024-02-24 03:17:12 +00:00
Dillon Ngo 2dc037c8fd Create a regenerate storage invoice feature to debug problem in reading and downloading storage invoice 2024-02-24 11:08:19 +08:00
Dillon Ngo aaae8bcafa Create a regenerate storage invoice feature to debug problem in reading and downloading storage invoice 2024-02-24 10:48:26 +08:00
Dillon Ngo b66dfa8649 Implement authorization module for update customer credit term status 2024-02-24 10:08:24 +08:00
Dillon Ngo 2689296a2c Implement authorization module for update customer credit term status 2024-02-23 11:09:30 +08:00
Dillon Ngo 62191c2711 Undo a changes made on previous commit 2024-02-23 10:49:09 +08:00
Dillon Ngo 02cb21bd5a User interface to allow admin to update company whether is a credit term customer for warehoue storage charges 2024-02-18 10:10:57 +08:00
Dillon Ngo 78573db17d User interface to allow admin to update company whether is a credit term customer for warehoue storage charges 2024-02-18 10:00:35 +08:00
Dillon Ngo af1b6ac373 Merge branch 'dillon/46.4-warehouse-storage-charges' into 'master'
User interface to allow admin to waive warehouse storage invoice transaction

See merge request CIEFWorldwideSdnBhd/shipping-portal!200
2024-02-15 13:47:31 +00:00
Dillon Ngo d807e5d4fd User interface to allow admin to waive warehouse storage invoice transaction 2024-02-15 21:21:08 +08:00
Dillon Ngo c427ae42a0 User interface to allow admin to waive warehouse storage invoice transaction 2024-02-15 21:18:02 +08:00
Dillon Ngo 8a7a4ce38a User interface to allow admin to waive warehouse storage invoice transaction 2024-02-15 21:01:50 +08:00
Dillon Ngo 1b6fe7445e User interface to allow admin to waive warehouse storage invoice transaction 2024-02-15 20:45:32 +08:00
Dillon Ngo 7b2d0c4e2b Merge branch 'dillon/51.4-explore-multiple-queues' into 'master'
Vue Polling - Explore multiple laravel queue with priority settings

See merge request CIEFWorldwideSdnBhd/shipping-portal!199
2024-02-13 23:36:24 +00:00
Dillon Ngo 1bcad555a0 Second high priority queue through database 2024-02-13 22:06:38 +08:00
Dillon Ngo 2973547e76 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Vue Polling - Solve a problem where query of packing list with contaienrs and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!198
2024-02-08 10:43:44 +00:00
Dillon Ngo 0b415e2e33 Vue Polling - Solve a problem where query of packing list with contaienrs and packages data is taking too long to complete + pagination problem 2024-02-08 18:41:57 +08:00
edmondlang 1110838e35 Merge branch 'master' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into permits-reminder 2024-02-06 10:55:32 +08:00
edmondlang 9d87987488 code update - permits reminder - send email only at production 2024-02-06 10:55:19 +08:00
Omair Saleh 4c0984c9b8 fix container reschedule component 2024-02-05 15:08:51 +08:00
Omair Saleh 5517f16684 fix container reschedule component 2024-02-05 13:24:25 +08:00
Omair Saleh 4b967981dd fix container reschedule component 2024-02-05 12:56:30 +08:00
Omair Saleh e63b959714 fix container reschedule component 2024-02-05 12:52:07 +08:00
Omair Saleh a1751f274d Merge remote-tracking branch 'origin/master' 2024-02-05 12:48:54 +08:00
Omair Saleh ef6538feca fix container reschedule component 2024-02-05 12:47:51 +08:00
edmondlang de61d9a9fd add anitha email for premits reminder 2024-01-30 12:41:51 +08:00
edmondlang 2c1b857255 update permits reminder view 2024-01-30 12:37:34 +08:00
edmondlang 5b4a3507a3 add cron job to send permits reminder at daily 9.30 am 2024-01-30 00:48:23 +08:00
edmondlang 3d6543e467 add sample file 2024-01-30 00:42:21 +08:00
edmondlang 006a327a5f Merge branch 'master' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into permits-reminder 2024-01-30 00:34:51 +08:00
edmondlang 295e6454b1 add cron job command to send permits reminder 2024-01-30 00:34:39 +08:00
edmondlang f389efa6af add permits edit 2024-01-30 00:07:31 +08:00
Dillon Ngo f83c89b5f3 Second high priority queue through database 2024-01-26 04:03:06 +08:00
Dillon Ngo 4ea3132334 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Vue Polling - Solve a problem where query of packing list with contaienrs and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!197
2024-01-25 19:19:45 +00:00
Dillon Ngo 8fc3ac1b55 Vue Polling - Solve a problem where query of packing list with contaienrs and packages data is taking too long to complete 2024-01-26 03:18:58 +08:00
Dillon Ngo ed252e630b Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Vue Polling - Solve a problem where query of packing list with contaienrs and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!196
2024-01-25 18:21:17 +00:00
Dillon Ngo b6c9c8843d Vue Polling - Solve a problem where query of packing list with contaienrs and packages data is taking too long to complete 2024-01-26 02:19:31 +08:00
Dillon Ngo d80e996d02 Merge branch 'dillon/46.4-warehouse-storage-charges' into 'master'
Implement a solution to selectively waived a selected storage invoice

See merge request CIEFWorldwideSdnBhd/shipping-portal!195
2024-01-25 13:47:10 +00:00
Dillon Ngo 064ee3e41a Implement a solution to selectively waived a selected storage invoice 2024-01-24 06:50:18 +08:00
Dillon Ngo 3bda84dac5 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Vue Polling - Solve a problem where query of packing list with contaienrs and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!194
2024-01-21 14:49:24 +00:00
Dillon Ngo e2b378e197 Vue Polling - Solve a problem where query of packing list with contaienrs and packages data is taking too long to complete 2024-01-21 22:48:48 +08:00
Dillon Ngo 0f2e1297e1 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Vue Polling - Solve a problem where query of packing list with contaienrs and...

See merge request CIEFWorldwideSdnBhd/shipping-portal!193
2024-01-21 14:35:45 +00:00
Dillon Ngo d034a285fc Vue Polling - Solve a problem where query of packing list with contaienrs and packages data is taking too long to complete 2024-01-21 22:31:16 +08:00
Dillon Ngo ee94943d00 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Experimental solution (Vue Polling) to solve an AWS API Gateway problem limitation for Laravel Vapor in the event of a emergency rollback to Google

See merge request CIEFWorldwideSdnBhd/shipping-portal!192
2024-01-21 02:54:47 +00:00
Dillon Ngo a9e89a45bd Experimental solution (Vue Polling) to solve an AWS API Gateway problem limitation for Laravel Vapor in the event of a emergency rollback to Google 2024-01-21 10:53:23 +08:00
Dillon Ngo f6b10b5763 Merge branch 'dillon/51.3-vue-polling-experimental' into 'master'
Experimental solution (Vue Polling) to solve an AWS API Gateway problem limitation for Laravel Vapor in the event of a emergency rollback to Google

See merge request CIEFWorldwideSdnBhd/shipping-portal!191
2024-01-21 02:32:55 +00:00
Dillon Ngo 9b9057ea81 Experimental solution (Vue Polling) to solve an AWS API Gateway problem limitation for Laravel Vapor in the event of a emergency rollback to Google 2024-01-21 10:31:39 +08:00
Dillon Ngo 33d2d02cb0 Merge branch 'dillon/51-vue-polling-experimental-2' into 'master'
Undo Experimental solution (Vue Polling)

See merge request CIEFWorldwideSdnBhd/shipping-portal!190
2024-01-20 19:16:33 +00:00
Dillon Ngo e5be6eaceb Undo Experimental solution (Vue Polling) 2024-01-21 03:15:46 +08:00
edmondlang a545e6bad6 add bill_no in transaction details page 2024-01-17 17:19:37 +08:00
edmondlang b64b25ff05 code update 2024-01-17 17:06:31 +08:00
edmondlang d1426c7f05 all api and ui to create permits reminder 2024-01-17 00:43:17 +08:00
edmondlang 3375934651 Merge branch 'master' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into permits-reminder
# Conflicts:
#	routes/api.php
2024-01-16 21:16:11 +08:00
edmondlang c79f58d246 permits reminder first commit 2024-01-16 21:15:29 +08:00
Dillon Ngo ee17ac0b0c Merge branch 'dillon/51-vue-polling-experimental-2' into 'master'
Experimental solution (Vue Polling) to solve an AWS API Gateway problem limitation for Laravel Vapor in the event of a emergency rollback to Google

See merge request CIEFWorldwideSdnBhd/shipping-portal!189
2024-01-15 16:43:45 +00:00
Dillon Ngo 26742a7335 Merge branch 'dillon/46.3.1-warehouse-storage-charges-fixes' into 'master'
Fix a problem with manual payment options not available when paying for invoices with warehouse storage charges

See merge request CIEFWorldwideSdnBhd/shipping-portal!188
2024-01-15 16:28:47 +00:00
Dillon Ngo 0e822ff1dd UI/UX amendment for order page when paying with storage invoice 2024-01-15 08:38:13 +08:00
Dillon Ngo 085b8b349f UI/UX amendment for order page when paying with storage invoice 2024-01-15 06:41:41 +08:00
edmondlang c1164397e8 fix errors diplaying in console in settings - warehouse 2024-01-14 22:56:45 +08:00
Dillon Ngo 3c16253795 Fix manual payment not showing in single order page when storage invoice is present 2024-01-14 09:33:31 +08:00
edmondlang 18a201611e add bind key for postcode array 2024-01-11 17:50:43 +08:00
edmondlang 7e754a9c7b add search postcode 2024-01-11 17:37:01 +08:00
edmondlang beb200fd6a Merge branch 'steve/account-mapping' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal 2024-01-11 10:59:40 +08:00
Steve Ng f0cb7828c3 invoice date for shipping portal when export invoice to autocount 2024-01-10 19:10:21 +08:00
Dillon Ngo 1956a4095d Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2024-01-08 17:49:42 +08:00
Dillon Ngo 71559701f4 Merge branch 'dillon/46.3-warehouse-storage-charges-fixes' into 'master'
Fix attempt on storage invoice pdf not able to be downloaded by user

See merge request CIEFWorldwideSdnBhd/shipping-portal!187
2024-01-05 21:55:59 +00:00
Dillon Ngo 9ceba30680 Fix attempt on storage invoice pdf not able to be downloaded by user 2024-01-06 05:53:59 +08:00
Dillon Ngo 3b2d06ed8f Fix attempt on storage invoice pdf not able to be downloaded by user 2024-01-06 05:52:55 +08:00
Dillon Ngo 81e04e9cb0 Fix attempt on storage invoice pdf not able to be downloaded by user 2024-01-06 05:52:26 +08:00
Dillon Ngo 286ca64413 Merge branch 'dillon/46.3-warehouse-storage-charges-fixes' into 'master'
Fix attempt on storage invoice pdf not able to be downloaded by user

See merge request CIEFWorldwideSdnBhd/shipping-portal!186
2024-01-05 21:11:33 +00:00
Dillon Ngo 51a96812fd Fix attempt on storage invoice pdf not able to be downloaded by user 2024-01-06 05:10:50 +08:00
Dillon Ngo 07459b9a1b Merge branch 'dillon/46.3-warehouse-storage-charges-fixes' into 'master'
Fix attempt on storage invoice pdf not able to be downloaded by user

See merge request CIEFWorldwideSdnBhd/shipping-portal!185
2024-01-05 21:08:00 +00:00
Dillon Ngo ee69f9123c Fix attempt on storage invoice pdf not able to be downloaded by user 2024-01-06 05:05:59 +08:00
Steve Ng 7a2ed92147 change posting date to invoice date for shipping portal when export invoice to autocount 2024-01-05 11:10:42 +08:00
Dillon Ngo 894481591d Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2024-01-04 13:52:11 +08:00
Dillon Ngo e5580c2abd Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2024-01-04 02:50:55 +08:00
Dillon Ngo 47ee304da1 Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2024-01-04 02:10:04 +08:00
Steve Ng 6427e2996f change posting date to invoice date for shipping portal when export invoice to autocount 2024-01-03 09:05:07 +08:00
Dillon Ngo f54aae5dc9 Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2024-01-03 05:39:43 +08:00
Dillon Ngo f0ef9a5602 Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2023-12-30 19:13:40 +08:00
Dillon Ngo 4d682c2ac6 Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2023-12-26 04:21:46 +08:00
Dillon Ngo 8ea00e0383 Proof of concept - Vue Polling - Performance Improvement and tweaking for better user experience 2023-12-24 21:59:41 +08:00
Dillon Ngo e0805a9601 Merge branch 'dillon/46-warehouse-storage-charges-2-merge-conflict' into 'master'
Emergency fix problem with group payment (reported by Eileen)

See merge request CIEFWorldwideSdnBhd/shipping-portal!184
2023-12-20 18:19:08 +00:00
Dillon Ngo 6f36c4b7ee Emergency fix problem with group payment (reported by Eileen) 2023-12-21 02:17:04 +08:00
Dillon Ngo 87194794f2 Merge branch 'dillon/46-warehouse-storage-charges-2-merge-conflict' into 'master'
Emergency fix problem with group payment (reported by Eileen)

See merge request CIEFWorldwideSdnBhd/shipping-portal!183
2023-12-20 16:06:34 +00:00
Dillon Ngo b4eca67a2f Emergency fix problem with group payment (reported by Eileen) 2023-12-20 23:58:56 +08:00
Dillon Ngo 1770b06498 Merge branch 'dillon/46-warehouse-storage-charges-2-merge-conflict' into 'master'
Emergency fix problem with group payment (reported by Eileen)

See merge request CIEFWorldwideSdnBhd/shipping-portal!182
2023-12-20 12:58:32 +00:00
Dillon Ngo 5c9fd6e2a6 Emergency fix problem with group payment (reported by Eileen) 2023-12-20 20:52:24 +08:00
Dillon Ngo 18df1c0c7b Proof of concept - Vue Polling a workaround for AWS API Gateway limitation 2023-12-20 14:47:56 +08:00
Dillon Ngo 359c103d01 Code sync from Exchange 2023-12-17 17:23:04 +08:00
Dillon Ngo ed7a636a18 Merge branch 'dillon/46-warehouse-storage-charges-2-merge-conflict' into 'master'
Fix a typo error

See merge request CIEFWorldwideSdnBhd/shipping-portal!181
2023-12-11 17:08:06 +00:00
Dillon Ngo 19bd548127 Fix a typo error 2023-12-12 01:07:06 +08:00
Dillon Ngo 55ac8064b1 Merge branch 'dillon/46-warehouse-storage-charges-2-merge-conflict' into 'master'
Warehouse Storage Charges - Effective From 11/12/2023 onwards

See merge request CIEFWorldwideSdnBhd/shipping-portal!180
2023-12-11 13:36:41 +00:00
Dillon Ngo e7279ec4d0 Merge branch 'master' into dillon/46-warehouse-storage-charges-2-merge-conflict 2023-12-11 21:29:06 +08:00
Dillon Ngo a7d4299897 Fix a typo error 2023-12-10 22:59:49 +08:00
Dillon Ngo 2b507d1006 Fix a typo error 2023-12-10 22:56:05 +08:00
Dillon Ngo 138a4f1cf6 Deleted some lines of codes 2023-12-07 17:17:39 +08:00
Dillon Ngo b54d897060 Remove <br> from payment transaction exported to excel file 2023-12-07 16:50:05 +08:00
Dillon Ngo c12959b4a8 Deleted some lines of codes 2023-12-07 16:44:06 +08:00
Dillon Ngo f94f380c16 Deleted some lines of codes 2023-12-07 16:42:52 +08:00
Dillon Ngo f46ec19f01 Update effective date for warehouse storage charges + commands to check for storage invoices 2023-12-07 16:35:51 +08:00
Omair Saleh c7a6a5b020 remove the 2 days delay for the ETA 2023-12-06 16:42:22 +08:00
Omair Saleh 8f64769214 remove the 2 days delay for the ETA 2023-12-06 16:38:57 +08:00
Dillon Ngo cb74228a68 Fix a problem reported by Yien where storage invoice number of days kept updated even though storage invoice already paid 2023-12-05 13:19:45 +08:00
Dillon Ngo b22cc0f7e3 Yien requested for some text description in invoice to be updated 2023-11-30 16:00:43 +08:00
Dillon Ngo 2e8ba4f630 Fix an error to export payment transaction in excel file 2023-11-30 13:56:35 +08:00
Dillon Ngo e987838d5a Fix 2 problem with generating storage invoice and export payment transaction in excel by date range 2023-11-30 13:36:38 +08:00
Dillon Ngo 48fa67ae8c Fix a problem with starting date should be done on arrival date of goods to china warehouse 2023-11-27 19:29:13 +08:00
Dillon Ngo 1e9e94b581 Fix a problem with starting date should be done on arrival date of goods to china warehouse 2023-11-27 19:20:45 +08:00
Dillon Ngo 67653b60fb Fix a problem with starting date should be done on arrival date of goods to china warehouse 2023-11-27 19:14:32 +08:00
Dillon Ngo 26fffb8af1 Fix decimal number to lengthy 2023-11-27 09:35:34 +08:00
Dillon Ngo fb0c74d645 Handling of dispute for warehouse storage fee 2023-11-24 13:44:28 +08:00
Dillon Ngo 53293f26d6 Amendment for Yien to do testing at dev environment 2023-11-24 02:29:05 +08:00
Dillon Ngo 56fe5520ad Amendment for Yien to do testing at dev environment 2023-11-24 00:33:07 +08:00
Dillon Ngo 61c801e216 Fix storage invoice with outdated info 2023-11-17 14:43:22 +08:00
Dillon Ngo 6f0acec390 Rename file, function + disable delete function for expired group payment 2023-11-17 14:16:02 +08:00
Dillon Ngo 76e3668563 20231109 Meeting Feedback 1 Fixes for warehouse storage charges 2023-11-16 22:40:26 +08:00
Dillon Ngo ce94dd1393 Fix for invoice status update using common function 2023-11-09 12:08:43 +08:00
Dillon Ngo c1ea087c58 Fix for storage invoice get to be generated even when the packingList not yet have APPROVED status 2023-11-09 08:34:03 +08:00
Dillon Ngo 8595d0987f Typo fix 2023-11-04 17:12:42 +08:00
Dillon Ngo 48d0460eef Debug billplz callback 2023-11-04 16:41:23 +08:00
Dillon Ngo 06751fdc78 New Warehouse Storage Fee 2023-11-04 14:58:50 +08:00
Dillon Ngo b5bcd5c553 Quick test on dev server 2023-10-27 04:18:39 +08:00
206 changed files with 8425 additions and 257 deletions
@@ -0,0 +1,11 @@
<?php
namespace App\Classes\Exceptions;
use App\Classes\ValueObjects\Constants\HttpStatus;
final class JobResourceNotFoundException extends ServiceApiException {
public function __construct(?string $message = null) {
parent::__construct($message ?? 'Unable to find the requested resource', HttpStatus::RESOURCE_NOT_FOUND);
}
}
@@ -15,6 +15,8 @@ use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Facades\DB;
use App\Classes\Exceptions\JobResourceNotFoundException;
use Illuminate\Support\Facades\Log;
abstract class AbstractControllerLogic
{
@@ -62,6 +64,19 @@ abstract class AbstractControllerLogic
return $response;
} catch (ErrorException|GeneralExceptions|TypeError $exception){
if ($exception instanceof JobResourceNotFoundException) {
Log::channel('vue_polling')->info(sprintf(
"Uncaught exception '%s' with message '%s' in %s:%d",
get_class($exception),
$exception->getMessage(),
$exception->getTrace()[0]['file'],
$exception->getTrace()[0]['line']
));
}
else{
Log::error($exception);
}
return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(),
!in_array($exception->getCode(), [0, 42000]) ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler();
@@ -6,6 +6,8 @@ namespace App\Classes\General\Eloquent;
use App\Classes\Exceptions\ResourceNotFoundException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use App\Classes\Exceptions\JobResourceNotFoundException;
abstract class AbstractFetchRecord extends AbstractGetRecord
{
@@ -26,12 +28,18 @@ abstract class AbstractFetchRecord extends AbstractGetRecord
* @return Model
* @throws ResourceNotFoundException
*/
public function getResults(Builder $query): Model {
public function getResults(Builder $query, array $param = []): Model {
if(!$query->exists()){
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
$table = $query->getModel()->getTable();
if($table ==='job_results'){
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
}
else{
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
}
}
return $query->first();
}
}
}
@@ -50,9 +50,9 @@ abstract class AbstractGetRecord
* @param array $filters
* @return mixed
*/
public function handler(array $filters){
public function handler(array $filters, array $params = []){
$this->filters = collect($filters);
return $this->getResults($this->applyFiltersToQuery());
return $this->getResults($this->applyFiltersToQuery(), $params);
}
@@ -65,6 +65,6 @@ abstract class AbstractGetRecord
* @param Builder $query
* @return mixed
*/
abstract function getResults(Builder $query);
abstract function getResults(Builder $query, array $params = []);
}
}
@@ -16,11 +16,10 @@ abstract class AbstractListRecord extends AbstractGetRecord
* @return mixed
* @throws MalformedRequestException
*/
public function execute(array $filters = []){
public function execute(array $filters = [], array $param = []){
try{
return $this->handler($filters);
return $this->handler($filters, $param);
} catch (QueryException $exception){
throw new MalformedRequestException('Unable to fetch the list of records due to unexpected error');
@@ -32,7 +31,7 @@ abstract class AbstractListRecord extends AbstractGetRecord
* @param Builder $query
* @return mixed
*/
public function getResults(Builder $query) {
public function getResults(Builder $query, array $param = []) {
$filters = $this->getDecorationFilters();
if($filters->has('order_by')){
@@ -44,8 +43,12 @@ abstract class AbstractListRecord extends AbstractGetRecord
}
//dd($query->toSql());
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
if(!empty($param)){
return $filters->has('per_page') ? $query->paginate($filters->get('per_page'), ['*'], 'page', $param['page']) : $query->get(); //page data from query parameters e.g ?page=1
}
else{
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
}
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class JobId implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->where('job_id', $value);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class OrderByIdDesc implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->orderBy('id', 'desc');
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class OrderByUpdatedAtDesc implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->orderBy('updated_at', 'desc');
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\PackingList;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
class PackingListLimitOneByTypeOrderedByInvoiceDate implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->select('packing_lists.*')->join('transactions', function($join){
$join->on('transactions.owner_id', '=', 'packing_lists.id');
$join->where('transactions.owner_type', '=', PackingList::class);
$join->where('transactions.status', '=', ApprovalStatus::APPROVED);
$join->whereRaw('(transactions.type <> 16 OR transactions.id = (
SELECT id FROM transactions WHERE owner_id = packing_lists.id AND type = 16 LIMIT 1
))');
})->orderBy('transactions.updated_at', 'DESC');
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class PostcodeLike implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->where('postcode', 'LIKE', '%'.$value.'%');
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class RequestSignature implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->where('request_signature', $value);
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class ResultNotNull implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->whereNotNull('result');
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Log;
class WithContainersPackages implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return mixed
*/
public static function apply(Builder $builder, $value)
{
// Log::info('WithContainersPackages: '.$value);
// return $builder->with(['containers', 'packages']);
return null;
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class WithTrashed implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->withTrashed();
}
}
+9
View File
@@ -2,6 +2,7 @@
namespace App\Classes\General;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
@@ -40,4 +41,12 @@ class Helper
}
}
}
/**
* @param ResourceCollection $collection
* @return array
*/
static function collectionResponse(ResourceCollection $collection){
return json_decode($collection->response()->getContent(), true);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\ListPackingListsJobProcessor;
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ListPackingListsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 900;
/** @var ListGenericJobObject */
private $listGenericJobObject;
/**
* ListPackingListsJob constructor.
* @param ListGenericJobObject $listGenericJobObject
*/
public function __construct(ListGenericJobObject $listGenericJobObject)
{
$this->listGenericJobObject = $listGenericJobObject;
}
public function handle()
{
$rawPayload = $this->job->payload();
if(isset($rawPayload['data']['commandName'])){
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
}
if(isset($rawPayload['data']['command'])){
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
}
$result = (App()->make(ListPackingListsJobProcessor::class))->execute($this->listGenericJobObject);
}
}
+2 -2
View File
@@ -47,7 +47,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
$invoiceId = 0;
$invoiceStatus = 0;
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no);
Log::error('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
Log::channel('perfex_crm')->info('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
if(is_null($invoice)){
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction->owner, $this->updatePerfexCRMInvoiceObject->getIsPaid());
@@ -55,7 +55,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
$invoiceId = $result->payload['id'];
} else {
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
Helper::debugLogger('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
Log::channel('perfex_crm')->info('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
}
}
else{
@@ -18,11 +18,13 @@ use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Group;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class CallbackBillplzLogic
{
@@ -50,6 +52,9 @@ class CallbackBillplzLogic
/** @var CallbackBillplzProcessor */
private $callbackBillplzProcessor;
/** @var CheckStorageInvoiceTransactionProcessor */
private $storageInvoiceTransactionProcessor;
/**
* CallbackBillplzLogic constructor.
* @param GetBillplzBill $getBillplzBill
@@ -59,8 +64,9 @@ class CallbackBillplzLogic
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
* @param CallbackBillplzProcessor $callbackBillplzProcessor
* @param CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor
*/
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, CallbackBillplzProcessor $callbackBillplzProcessor)
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, CallbackBillplzProcessor $callbackBillplzProcessor, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
{
$this->getBillplzBill = $getBillplzBill;
$this->fetchesTransaction = $fetchesTransaction;
@@ -70,6 +76,7 @@ class CallbackBillplzLogic
$this->updatesWalletBalance = $updatesWalletBalance;
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
}
@@ -109,10 +116,13 @@ class CallbackBillplzLogic
$status = $billplzXSignatureObject->getStatus() === 'failed' ? ApprovalStatus::REJECTED : ApprovalStatus::PENDING_VERIFICATION;
}
Log::info('Debug billPlz status: '.$status);
$token = Auth::fromUser(User::find(1));
$request->headers->set('Authorization', 'Bearer '.$token);
$this->callbackBillplzProcessor->execute($transaction, $status);
$this->storageInvoiceBackDoorPreventionCheck($transaction, $status);
$result = $this->callbackBillplzProcessor->execute($transaction, $status);
$company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null;
@@ -123,6 +133,22 @@ class CallbackBillplzLogic
$company_module_marking = $order->companyModule->connections? $order->companyModule->connections->first()->invitee_reference: null;
}
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]);
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status, 'result' => $result]);
}
private function storageInvoiceBackDoorPreventionCheck($transaction, $status){
if ($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED) {
$group = Group::where('reference', $transaction->payment_reference)->first();
if ($group) {
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
$pL = $invoice->owner;
$order = $pL->owner;
if($order){
$this->storageInvoiceTransactionProcessor->executeOrder($order);
}
}
}
}
}
}
@@ -6,13 +6,14 @@ use Illuminate\Http\Request;
use App\Models\Wallet;
use App\Models\Group;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
use Illuminate\Support\Facades\Log;
class CallbackBillplzProcessor
{
@@ -31,6 +32,9 @@ class CallbackBillplzProcessor
/** @var CreatePaymentTransactionProcessor */
private $createPaymentTransactionProcessor;
/** @var ReleaseGoodsToCustomerProcessor */
private $releaseGoodsToCustomerProcessor;
/**
* CreateUserProcessor constructor.
* @param UpdatesTransactionStatus $updatesTransactionStatus
@@ -38,14 +42,16 @@ class CallbackBillplzProcessor
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
* @param UpdatesWalletBalance $updatesWalletBalance
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
* @param ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
*/
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor)
{
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
$this->updatesWalletBalance = $updatesWalletBalance;
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
}
@@ -58,6 +64,9 @@ class CallbackBillplzProcessor
$invoice = $transaction->owner;
$packingList = $invoice->owner;
$proceed = $this->checkForGroupPayment($transaction);
if(!$proceed) return false;
$this->updatesTransactionStatus->execute($transaction, $status);
// check if is wallet top up
@@ -66,33 +75,57 @@ class CallbackBillplzProcessor
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
$group = Group::where('reference', $transaction->payment_reference)->first();
// check if is group payment
if ($group) {
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null);
if($invoice->status !== ApprovalStatus::COMPLETED){
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null, false);
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
$pL = $invoice->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
}
}
}
$group->status = $status;
$group->save();
}
}
if (!$transaction->owner instanceof Wallet) {
$totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
$this->releaseGoodsToCustomerProcessor->execute($packingList, $invoice);
}
if (($invoice->amount - $totalPaidAmount) < 0.01) {
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
return true;
}
$packingList->status = ApprovalStatus::APPROVED;
$packingList->save();
private function checkForGroupPayment($transaction){
//This check is targetting group payment that expired and soft deleted
//command:check-storage-invoices must already run for this part of the code to work properly
$group = Group::withTrashed()->where('reference', $transaction->payment_reference)->first();
if ($group) {
$totalAmountToBePaid = 0;
$actualAmountPaid = $transaction->amount;
if (app()->environment('production')) {
$this->updateDoFromVTPortalProcessor->execute($packingList);
$this->updateDoFromYDPortalProcessor->execute($packingList);
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
if($invoice->status !== ApprovalStatus::COMPLETED){
$totalAmountToBePaid += $invoice->amount;
}
}
if(($totalAmountToBePaid - $actualAmountPaid) < 0.01){
}
else{
Log::channel('storage_invoices')->info('Total amount from current transaction: '.$totalAmountToBePaid); //cief todo: to be removed
Log::channel('storage_invoices')->info('Total amount from paid transaction: '.$transaction->amount); //cief todo: to be removed
return false;
}
}
return true;
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Classes\Modules\Billplzs\Services;
use Illuminate\Support\Facades\Http;
use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Support\Facades\Log;
class DeletesBillplzBill
{
/**
* @param string $billID
* @throws MalformedRequestException
*/
public function execute(string $billID) {
try{
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->delete(config('billplz.base_url').'/api/v3/bills/'.$billID);
Log::channel('storage_invoices')->info('DeletesBillplzBill response: '.json_encode($response));
if($response->successful()){
$data = $response->json();
// $data['url'] = $data['url'].'?auto_submit=true';
return (object) $data;
}else{
return null;
}
}catch(\Exception $exception){
throw new MalformedRequestException('Unable to get correct response from billplz server: ' . $exception->getMessage());
}
}
}
@@ -0,0 +1,121 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyModuleIsCreditTerm;
use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompanyModule;
use App\Classes\Modules\Transactions\Services\ListsTransactions;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionIsWaived;
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Order;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class UpdateCompanyCreditTermStatusLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Update Company Credit Term Status',
'message' => 'You have successfully updated Company Credit Term Status'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var UpdatesCompanyModuleIsCreditTerm */
private $updatesCompanyModuleIsCreditTerm;
/** @var CanUpdateCompanyModule */
private $canUpdateCompanyModule;
/** @var ListsTransactions */
private $listsTransactions;
/** @var UpdatesTransactionIsWaived */
private $updatesTransactionIsWaived;
/** @var CheckStorageInvoiceTransactionProcessor */
private $storageInvoiceTransactionProcessor;
/**
* UpdateCompanyCreditTermStatusLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param UpdatesCompanyModuleIsCreditTerm $updatesCompanyModuleIsCreditTerm
* @param CanUpdateCompanyModule $canUpdateCompanyModule
* @param UpdatesTransactionIsWaived $updatesTransactionIsWaived
* @param ListsTransactions $listsTransactions
* @param CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor
*/
public function __construct(FetchesCompany $fetchesCompany, UpdatesCompanyModuleIsCreditTerm $updatesCompanyModuleIsCreditTerm, CanUpdateCompanyModule $canUpdateCompanyModule, UpdatesTransactionIsWaived $updatesTransactionIsWaived, ListsTransactions $listsTransactions, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
{
$this->fetchesCompany = $fetchesCompany;
$this->updatesCompanyModuleIsCreditTerm = $updatesCompanyModuleIsCreditTerm;
$this->canUpdateCompanyModule = $canUpdateCompanyModule;
$this->listsTransactions = $listsTransactions;
$this->updatesTransactionIsWaived = $updatesTransactionIsWaived;
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
$this->canUpdateCompanyModule->passes();
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$companyModule = $company->companyModules()->first();
$isCreditTerm = $companyModule->connections()->first()->is_credit_term;
if ($isCreditTerm == 1) {
$isCreditTerm = 0;
} else {
$isCreditTerm = 1;
}
if($isCreditTerm === 1){
//{"per_page":10,"order_by":{"column":"id","DESC":true},"status_in":[2],"receiver":190,"type_in":[1],"does_not_have_payment_status_in":[0,1],"does_not_have_groups":1,"check_for_storage_invoice":1}
$filters = [
'status_in' => [2],
'receiver' => $companyModule->id,
'type_in' => [TransactionType::STORAGE_INVOICE]
];
$transactions = $this->listsTransactions->execute($filters);
foreach($transactions as $transaction){
$this->updatesTransactionIsWaived->execute($transaction);
$packingList = $transaction->owner()->first();
if($packingList){
$order = $packingList->owner()->first();
if($order instanceof Order){
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
}
}
}
}
$this->updatesCompanyModuleIsCreditTerm->execute($company->companyModules()->first()->connections()->first(), $isCreditTerm);
Log::info(Auth::user()->email." updated credit term status for customer with id: " .$request->route('id'). " to status " . $isCreditTerm);
$result = ['is_credit_term' => $isCreditTerm];
return $this->response(['data' => $result]);
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Classes\Modules\Companies\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\CompanyConnection;
class UpdatesCompanyModuleIsCreditTerm extends AbstractUpdateRecord
{
/**
* @param CompanyConnection $model
* @param int $isCreditTerm
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(CompanyConnection $model, int $isCreditTerm)
{
$model->is_credit_term = $isCreditTerm;
return $this->handler($model);
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Classes\Modules\Companies\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
use App\Classes\ValueObjects\Constants\RoleTypes;
class CanUpdateCompanyModule extends AbstractRule
{
/**
* CanUpdateCompanyModule constructor.
*/
public function __construct()
{
}
/**
* @return bool
*/
protected function authorized($object): bool
{
$user = Auth()->user();
if($user){
$roleToCheck = Auth()->user()->type;
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
return true;
}
}
return false;
}
/**
* @param $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return true;
}
/**
* @param CompanyObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -70,15 +70,31 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading
$description = 'Credit Voucher for ' . $transaction->payment_reference;
break;
case TransactionType::PAYMENT:
$booking = Transaction::where('payment_reference', $transaction->bill_no)->first()->owner;
if (!$booking) {
$description = 'Payment for unknown booking, please contact tech support.';
$payment = Transaction::where('payment_reference', $transaction->bill_no)->first();
if (!$payment) {
$description = 'Payment not found, please contact tech support.';
break;
}
$marking = $booking->marking;
$description = 'Payment For booking refs' . $marking;
$invoice = $payment->owner;
if (!$invoice) {
$description = 'Invoice not found, please contact tech support.';
break;
}
$packingList = $invoice->owner;
if (!$packingList) {
$description = 'Packing List not found, please contact tech support.';
break;
}
$order = $packingList->owner;
if (!$order) {
$description = 'Order not found, please contact tech support.';
break;
}
$description = 'Payment For booking refs ' . $order->reference;
break;
case TransactionType::DEBIT_NOTE:
$description = 'Debit Voucher for ' . $transaction->payment_reference;
@@ -74,7 +74,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
$approvalStatus = ApprovalStatus::APPROVED;
}
$query->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [$approvalStatus]);
// $query->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [$approvalStatus]);
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->whereIn('status', [$approvalStatus]);
if($start_date && $end_date) {
$query->whereBetween('updated_at', [
@@ -102,7 +103,12 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
$container = $transaction->owner->containers()->first();
$order = $transaction->owner->owner;
$company = $order->companyModule->company;
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'SHIPPING_FEE')->first();
if($transaction->type === TransactionType::STORAGE_INVOICE){
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'STORAGE_FEE')->first();
}
else{
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'SHIPPING_FEE')->first();
}
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
$contact = $order->companyModule->company->contacts->first();
$userName = $order->companyModule->employees()->first();
@@ -118,6 +124,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
elseif($item->reference === 'MIN_CBM_CHARGES')
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
elseif($item->reference === 'STORAGE_FEE')
$furtherDescription .= str_replace('<br>', ' | ', $item->name).' '."\n";
else
$furtherDescription .= $item->name.' '.$item->quantity.' X '.$item->price."\n";
}
@@ -0,0 +1,23 @@
<?php
namespace App\Classes\Modules\Imports\Services;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class GenericImport implements ToCollection, WithHeadingRow
{
function headingRow(): int { return 1; }
public $rows;
/**
* @param Collection $collection
*/
public function collection(Collection $collection)
{
$this->rows = $collection;
}
}
@@ -0,0 +1,52 @@
<?php
namespace App\Classes\Modules\Jobs\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Jobs\Processors\FetchesJobResultProcessor;
use App\Http\Resources\JobResultResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchJobResultLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved Data',
'message' => 'You have successfully retrieved data'
];
}
/** @var FetchesJobResultProcessor */
private $fetchesJobResultProcessor;
/**
* FetchJobResultLogic constructor.
* @param FetchesJobResultProcessor $fetchesJobResultProcessor
*/
public function __construct(FetchesJobResultProcessor $fetchesJobResultProcessor)
{
$this->fetchesJobResultProcessor = $fetchesJobResultProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
$query = $this->fetchesJobResultProcessor->execute($request);
return $this->resourceResponse(new JobResultResource($query));
}
}
@@ -0,0 +1,118 @@
<?php
namespace App\Classes\Modules\Jobs\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class ListGenericJobObject implements DataTransferObject
{
/** @var string */
private $name;
/** @var array */
private $payload;
/** @var string */
private $jobId;
/** @var string */
private $requestSignature;
/** @var string */
private $resultSignature;
/** @var object */
private $userInfo;
/** @var string */
private $jobCommandName;
/** @var string */
private $jobCommand;
public function __construct(string $name, array $payload, string $requestSignature, ?string $resultSignature, string $jobId, object $userInfo = null)
{
$this->name = $name;
$this->payload = $payload;
$this->jobId = $jobId;
$this->requestSignature = $requestSignature;
$this->resultSignature = $resultSignature;
$this->userInfo = $userInfo;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return array
*/
public function getPayload(): array
{
return $this->payload;
}
/**
* @return string
*/
public function getJobId(): string
{
return $this->jobId;
}
/**
* @return string
*/
public function getRequestSignature(): string
{
return $this->requestSignature;
}
/**
* @return string
*/
public function getResultSignature(): ?string
{
return $this->resultSignature;
}
/**
* @return object
*/
public function getUserInfo(): object
{
return $this->userInfo;
}
/**
* @return string
*/
public function getJobCommandName(): string
{
return $this->jobCommandName;
}
/**
* @return string
*/
public function getJobCommand(): string
{
return $this->jobCommand;
}
public function setJobCommandName(string $jobCommandName)
{
$this->jobCommandName = $jobCommandName;
}
public function setJobCommand(string $jobCommand)
{
$this->jobCommand = $jobCommand;
}
}
@@ -0,0 +1,60 @@
<?php
namespace App\Classes\Modules\Jobs\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class UpdateJobResultObject implements DataTransferObject
{
/** @var string */
private $result;
/** @var string */
private $resultSignature;
/** @var string */
private $jobCommandName;
/** @var string */
private $jobCommand;
public function __construct(string $result, string $resultSignature, string $jobCommandName, string $jobCommand)
{
$this->result = $result;
$this->resultSignature = $resultSignature;
$this->jobCommandName = $jobCommandName;
$this->jobCommand = $jobCommand;
}
/**
* @return string
*/
public function getResult(): string
{
return $this->result;
}
/**
* @return array
*/
public function getResultSignature(): string
{
return $this->resultSignature;
}
/**
* @return string
*/
public function getJobCommandName(): string
{
return $this->jobCommandName;
}
/**
* @return string
*/
public function getJobCommand(): string
{
return $this->jobCommand;
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Classes\Modules\Jobs\Processors;
use App\Classes\Exceptions\JobResourceNotFoundException;
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
use Illuminate\Http\Request;
class FetchesJobResultProcessor
{
/** @var FetchesJobResult */
private $fetchesJobResult;
/**
* FetchesJobResultProcessor constructor.
* @param FetchesJobResult $fetchesJobResult
*/
public function __construct(FetchesJobResult $fetchesJobResult)
{
$this->fetchesJobResult = $fetchesJobResult;
}
/**
* @param Request $request
* @return Model
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
* @throws \App\Classes\Exceptions\ResourceNotFoundException
*/
public function execute(Request $request){
$res1 = $this->fetchesJobResult->execute(['job_id' => $request->route('job_id')]);
if($request->route('is_last')){
$res2 = $this->fetchesJobResult->execute(['request_signature' => $res1->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
return $res2;
}
if(!$res1->result){
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
}
return $res1;
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Classes\Modules\Jobs\Processors;
use App\Classes\Modules\Jobs\Services\UpdatesJobResult;
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
use App\Classes\Exceptions\JobResourceNotFoundException;
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
class UpdateJobResultProcessor
{
/** @var FetchesJobResult */
private $fetchesJobResult;
/** @var UpdatesJobResult */
private $updatesJobResult;
/**
* UpdateJobResultProcessor constructor.
* @param FetchesJobResult $fetchesJobResult
* @param UpdatesJobResult $updatesJobResult
*/
public function __construct(FetchesJobResult $fetchesJobResult, UpdatesJobResult $updatesJobResult)
{
$this->fetchesJobResult = $fetchesJobResult;
$this->updatesJobResult = $updatesJobResult;
}
/**
* @param ListGenericJobObject $listGenericJobObject
* @param array $resultCurrent
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
*/
public function execute(ListGenericJobObject $listGenericJobObject, $resultCurrent) {
$jobResultCurrent = $this->fetchesJobResult->execute(['job_id' => $listGenericJobObject->getJobId()]);
$resultCurrentJson = json_encode($resultCurrent);
$resultSignatureCurrent = md5($resultCurrentJson);
try{
$jobResultExisting = $this->fetchesJobResult->execute(['request_signature' => $jobResultCurrent->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
$resultSignatureExisting = $jobResultExisting->result_signature;
//if($resultSignatureExisting != $resultSignatureCurrent){
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
//}
} catch (JobResourceNotFoundException $exception){
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
}
}
private function updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $jobCommandName, $jobCommand){
$updateJobResultObject = new UpdateJobResultObject(
$resultCurrentJson,
$resultSignatureCurrent,
$jobCommandName,
$jobCommand
);
$create = $this->updatesJobResult->execute($jobResultCurrent, $updateJobResultObject);
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Classes\Modules\Jobs\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\JobResult;
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
class CreatesJobResult extends AbstractUpdateRecord
{
/**
* @param ListGenericJobObject $listGenericJobObject
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(ListGenericJobObject $listGenericJobObject)
{
$model = new JobResult();
$model->job_id = $listGenericJobObject->getJobId();
$model->request_signature = $listGenericJobObject->getRequestSignature();
$model->result_signature = $listGenericJobObject->getResultSignature();
$model->url = $listGenericJobObject->getName();
return $this->handler($model);
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Jobs\Services;
use App\Classes\General\Eloquent\AbstractFetchRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\JobResult;
class FetchesJobResult extends AbstractFetchRecord
{
/** @var JobResult */
private $repository;
/**
* FetchesJobResult constructor.
* @param JobResult $repository
*/
public function __construct(JobResult $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Jobs\Services;
use App\Classes\General\Eloquent\AbstractListRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\JobResult;
class ListsJobResult extends AbstractListRecord
{
/** @var JobResult */
private $repository;
/**
* ListsJobResult constructor.
* @param JobResult $repository
*/
public function __construct(JobResult $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Classes\Modules\Jobs\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
use App\Models\JobResult;
class UpdatesJobResult extends AbstractUpdateRecord
{
/**
* @param JobResult $model
* @param UpdateJobResultObject $updateJobResultObject
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(JobResult $model, UpdateJobResultObject $updateJobResultObject) {
$model->result = $updateJobResultObject->getResult();
$model->result_signature = $updateJobResultObject->getResultSignature();
$model->job_command_name = $updateJobResultObject->getJobCommandName();
$model->job_command = $updateJobResultObject->getJobCommand();
return $this->handler($model);
}
}
@@ -53,8 +53,12 @@ class FetchOrderV2Logic extends AbstractControllerLogic
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
if($request->input('storages')){
$query->storages = $request->input('storages'); //from middleware
}
return $this->resourceResponse(new OrderV2Resource($query));
}
}
}
@@ -38,6 +38,7 @@ class UpdateDoFromYDPortalProcessor
*/
public function execute(PackingList $packingList) {
Log::info('Trying to Call UpdateDoFromYDPortalProcessor');
Log::channel('storage_invoices')->info('UpdateDoFromYDPortalProcessor: '.json_encode($packingList));
if(!app()->environment(['production'])){
return;
@@ -0,0 +1,78 @@
<?php
namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Jobs\ListPackingListsJob;
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
class ListPackingListsJobLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Job Retrieving PackingLists',
'message' => 'You have successfully submit a job to retrieve a list of PackingLists'
];
}
/** @var CreatesJobResult */
private $createsJobResult;
/**
* ListPackingListsJobLogic constructor.
* @param CreatesJobResult $createsJobResult
*/
public function __construct(CreatesJobResult $createsJobResult)
{
$this->createsJobResult = $createsJobResult;
}
/**
* @param Request $request
* @return JsonResponse
*/
public function logic(Request $request) : JsonResponse
{
$jobId = uniqid();
$user = Auth::user();
$userInfo = (object) [
// 'email' => $user->email,
'type' => $user->type,
];
$userInfoJson = json_encode($userInfo);
$requestSignature = md5($userInfoJson . $request->fullUrl());
$listGenericJobObject = new ListGenericJobObject(
$request->fullUrl(),
$request->all(),
$requestSignature,
null,
$jobId,
$userInfo
);
ListPackingListsJob::dispatch($listGenericJobObject)->onQueue('high_priority');
$result = [];
$result['job_id'] = $jobId;
$this->createsJobResult->execute($listGenericJobObject);
return $this->response(['data' => $result]);
}
}
@@ -6,8 +6,8 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists;
use App\Http\Resources\PackingListNullOrderResource;
use App\Http\Resources\PackingListResource;
use App\Http\Resources\PackingListWithStorageResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -54,7 +54,14 @@ class ListPackingListsLogic extends AbstractControllerLogic
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
return $this->collectionResponse(PackingListResource::collection($query));
if($request->input('storages')){
foreach ($query->items() as $item) {
$item['storages'] = $request->input('storages');
}
return $this->collectionResponse(PackingListWithStorageResource::collection($query));
}
else{
return $this->collectionResponse(PackingListResource::collection($query));
}
}
}
@@ -121,7 +121,7 @@ class FetchContainersFromYdPortalProcessor
$containerReference = explode('预计到港时间', $tracking[1])[0];
$loadingDate = Carbon::parse($trackingRow->trackingtime);
$etd = Carbon::parse($tracking[2])->subDays(5);
$eta = Carbon::parse($tracking[2])->addDays(2);
$eta = Carbon::parse($tracking[2]);
}
}
@@ -147,7 +147,6 @@ class FetchContainersUpdatesFromYdPortalProcessor
if($delayDate){
$delayDate = $delayDate->addDays(2);
$transport = $container->transports()->first();
if(!$transport->schedules()->whereDate('eta', '>=', $delayDate)->first()) {
@@ -162,7 +162,7 @@ class FetchLoadedContainersFromVTPortalProcessor
$container = $this->createContainerProcessor->execute($containerObject, $originWarehouse);
}
$eta = Carbon::parse($containerInfo[4])->addDays(2);
$eta = Carbon::parse($containerInfo[4]);
$etd = Carbon::parse($eta)->subDays(7);
$delayDate = $containerInfo[7];
@@ -183,7 +183,7 @@ class FetchLoadedContainersFromVTPortalProcessor
}
if($delayDate){
$delayDate = Carbon::parse($delayDate)->addDays(2);
$delayDate = Carbon::parse($delayDate);
$transport = $container->transports()->first();
if(!$transport->schedules()->where('eta', '=', $delayDate)->first()) {
@@ -199,7 +199,7 @@ class FetchOrderListsFromYdPortalProcessor
$containerReference = explode('预计到港时间', $tracking[1])[0];
$loadingDate = Carbon::parse($trackingRow->trackingtime);
$etd = Carbon::parse($tracking[2])->subDays(5);
$eta = Carbon::parse($tracking[2])->addDays(2);
$eta = Carbon::parse($tracking[2]);
}
$rescheduleETD = strpos($trackingRow->remark, '开') || strpos($trackingRow->remark, '到港');
@@ -415,7 +415,7 @@ class FetchOrderListsFromYdPortalProcessor
}
if($delayDate){
$delayDate = $delayDate->addDays(2);
$delayDate = $delayDate;
$transport = $container->transports()->first();
if(!$transport->schedules()->whereDate('eta', '>=', $delayDate)->first()) {
@@ -0,0 +1,87 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
use App\Classes\General\Helper;
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
use App\Http\Middleware\CheckForStorageInvoiceByPackingLists;
use App\Http\Resources\ListPackingListJobResource;
use App\Http\Resources\ListPackingListDetailsJobResource;
use App\Http\Resources\ListPackingListJobWithStorageResource;
use Illuminate\Support\Facades\Log;
class ListPackingListsJobProcessor
{
/** @var ListsPackingLists */
private $listsPackingLists;
/** @var UpdateJobResultProcessor */
private $updateJobResultProcessor;
/** @var CheckForStorageInvoiceByPackingLists */
private $checkForStorageInvoiceByPackingLists;
/**
* ListPackingListsJobProcessor constructor.
* @param ListsPackingLists $listsPackingLists
* @param UpdateJobResultProcessor $updateJobResultProcessor
*/
public function __construct(ListsPackingLists $listsPackingLists, UpdateJobResultProcessor $updateJobResultProcessor, CheckForStorageInvoiceByPackingLists $checkForStorageInvoiceByPackingLists)
{
$this->listsPackingLists = $listsPackingLists;
$this->updateJobResultProcessor = $updateJobResultProcessor;
$this->checkForStorageInvoiceByPackingLists = $checkForStorageInvoiceByPackingLists;
}
/**
* @param ListGenericJobObject $listGenericJobObject
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
*/
public function execute(ListGenericJobObject $listGenericJobObject) {
// $query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page'], 'with_containers_packages' => true]);
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
// $query = $this->listsPackingLists->execute(array_merge($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page'], 'with_containers_packages' => true]));
$filtersArray = json_decode($listGenericJobObject->getPayload()['filters'], true);
$storages = [];
if(isset($filtersArray['check_for_storage_invoice']))
{
$myRequest = new \Illuminate\Http\Request();
$myRequest->setMethod('POST');
$myRequest->request->add($listGenericJobObject->getPayload());
$next = function ($request) {
return $request;
};
$response = $this->checkForStorageInvoiceByPackingLists->handle($myRequest, $next);
$storages = $response->input('storages');
}
foreach ($query->items() as &$item) {
$item['userInfo'] = $listGenericJobObject->getUserInfo();
$item['storages'] = $storages;
}
if(isset($filtersArray['does_not_have_transaction_type'])){ //For Payment and Billing page > Pending Invoice tab
$resultCurrent = Helper::collectionResponse(ListPackingListDetailsJobResource::collection($query));
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
}
else{
if($storages){ //For Payment and Billing page > Pending Payment tab, Paid Invoice tab
$resultCurrent = Helper::collectionResponse(ListPackingListJobWithStorageResource::collection($query));
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
}
else{
$resultCurrent = Helper::collectionResponse(ListPackingListJobResource::collection($query));
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
}
}
}
}
@@ -61,7 +61,7 @@ class FetchPerfexCRMInvoiceProcessor
$invoiceId = $result->payload['id'];
} else {
$log['message'] = 'FetchPerfexCRMInvoiceProcessor failed for transaction > bill_no: '.$number;
Helper::debugLogger($log);
Log::channel('perfex_crm')->info($log);
}
}
else{
@@ -25,7 +25,7 @@ class ConvertsPerfexCRMLeadToCustomer
return (object) $data;
}else{
Log::error('ConvertsPerfexCRMLeadToCustomer: '.$response);
Log::channel('perfex_crm')->info('ConvertsPerfexCRMLeadToCustomer: '.$response);
return null;
}
}
@@ -28,7 +28,7 @@ class CreatesPerfexCRMCustomer
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMCustomer: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomer: '.$response);
return null;
}
}
@@ -35,7 +35,7 @@ class CreatesPerfexCRMCustomerContact
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMCustomerContact: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomerContact: '.$response);
return null;
}
}
@@ -34,7 +34,7 @@ class CreatesPerfexCRMCustomerProject
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMCustomerProject: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomerProject: '.$response);
return null;
}
}
@@ -54,7 +54,7 @@ class CreatesPerfexCRMInvoice
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMInvoice: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMInvoice: '.$response);
return null;
}
}
@@ -34,7 +34,7 @@ class CreatesPerfexCRMInvoicePayment
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMInvoicePayment: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMInvoicePayment: '.$response);
return null;
}
}
@@ -41,7 +41,7 @@ class CreatesPerfexCRMLead
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMLead: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMLead: '.$response);
return null;
}
}
@@ -37,7 +37,7 @@ class CreatesPerfexCRMMilestone
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMMilestone: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMMilestone: '.$response);
return null;
}
}
@@ -34,7 +34,7 @@ class CreatesPerfexCRMSupportTicket
$data = $response->json();
return (object) $data;
}else{
Log::error($response);
Log::channel('perfex_crm')->info($response);
return null;
}
}
@@ -58,7 +58,7 @@ class CreatesPerfexCRMTask
$data = $response->json();
return (object) $data;
}else{
Log::error('CreatesPerfexCRMTask: '.$response);
Log::channel('perfex_crm')->info('CreatesPerfexCRMTask: '.$response);
return null;
}
}
@@ -25,7 +25,7 @@ class FetchesPerfexCRMCustomer
return (object) $data;
}else{
Log::error('FetchesPerfexCRMCustomer: '.$response);
Log::channel('perfex_crm')->info('FetchesPerfexCRMCustomer: '.$response);
return null;
}
}
@@ -27,7 +27,7 @@ class FetchesPerfexCRMInvoice
return (object) $data;
}else{
Log::error('FetchesPerfexCRMInvoice: '.$response);
Log::channel('perfex_crm')->info('FetchesPerfexCRMInvoice: '.$response);
return null;
}
}
@@ -25,7 +25,7 @@ class FetchesPerfexCRMLead
return (object) $data;
}else{
Log::error('FetchesPerfexCRMLead: '.$response);
Log::channel('perfex_crm')->info('FetchesPerfexCRMLead: '.$response);
return null;
}
}
@@ -31,7 +31,7 @@ class FetchesPerfexCRMMilestone
return (object) $data;
}else{
Log::error('FetchesPerfexCRMMilestone: '.$response);
Log::channel('perfex_crm')->info('FetchesPerfexCRMMilestone: '.$response);
return null;
}
}
@@ -31,7 +31,7 @@ class FetchesPerfexCRMProject
return (object) $data;
}else{
Log::error('FetchesPerfexCRMProject: '.$response);
Log::channel('perfex_crm')->info('FetchesPerfexCRMProject: '.$response);
return null;
}
}
@@ -45,7 +45,7 @@ class FetchesPerfexCRMTask
return (object) $data;
}else{
Helper::debugLogger($response);
Log::channel('perfex_crm')->info($response);
return null;
}
}
@@ -39,7 +39,7 @@ class UpdatesPerfexCRMCustomer
$data = $response->json();
return (object) $data;
}else{
// Helper::debugLogger($response);
// Log::channel('perfex_crm')->info($response);
return null;
}
}
@@ -61,7 +61,7 @@ class UpdatesPerfexCRMInvoice
$data = $response->json();
return (object) $data;
}else{
Log::error('UpdatesPerfexCRMInvoice: '.$response);
Log::channel('perfex_crm')->info('UpdatesPerfexCRMInvoice: '.$response);
return null;
}
}
@@ -42,7 +42,7 @@ class UpdatesPerfexCRMLead
$data = $response->json();
return (object) $data;
}else{
Log::error('UpdatesPerfexCRMLead: '.$response);
Log::channel('perfex_crm')->info('UpdatesPerfexCRMLead: '.$response);
return null;
}
}
@@ -34,7 +34,7 @@ class UpdatesPerfexCRMProject
$data = $response->json();
return (object) $data;
}else{
Log::error('UpdatesPerfexCRMProject: '.$response);
Log::channel('perfex_crm')->info('UpdatesPerfexCRMProject: '.$response);
return null;
}
}
@@ -39,7 +39,7 @@ class UpdatesPerfexCRMTask
$data = $response->json();
return (object) $data;
}else{
Log::error('UpdatesPerfexCRMTask: '.$response);
Log::channel('perfex_crm')->info('UpdatesPerfexCRMTask: '.$response);
return null;
}
}
@@ -21,6 +21,8 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\GroupTransaction;
use App\Http\Resources\WalletTransactionResource;
use App\Models\Wallet;
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
class CreateGroupsLogic extends AbstractControllerLogic
{
@@ -55,13 +57,18 @@ class CreateGroupsLogic extends AbstractControllerLogic
/** @var CreatesGroup */
private $createsGroup;
/** @var ReleaseGoodsToCustomerProcessor */
private $releaseGoodsToCustomerProcessor;
public function __construct(
FetchesTransaction $fetchesTransaction,
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
FetchesTransaction $fetchesTransaction,
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
FetchesCompanyModule $fetchesCompanyModule,
CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor,
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
CreatesGroup $createsGroup
CreatesGroup $createsGroup,
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
)
{
$this->fetchesTransaction = $fetchesTransaction;
@@ -70,20 +77,40 @@ class CreateGroupsLogic extends AbstractControllerLogic
$this->createWalletTopUpTransactionProcessor = $createWalletTopUpTransactionProcessor;
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
$this->createsGroup = $createsGroup;
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
}
public function logic(Request $request) : JsonResponse
{
$payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')];
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
$invoice_ids = json_decode($request->route('transaction_ids'));
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
// todo-new: check why is this not working
// $invoices = $this->fetchesTransaction->execute(['id_in' => $invoice_ids]);
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
$isInvoicesApprove = $this->checkIfInvoicesAreApprove($invoices);
if(!$isInvoicesApprove){
$response = ['message' => 'One of the transactions might be suspended; please check if there are any disputes in progress.'];
return $this->response(['data' => $response]);
}
else{
$paymentMethodStr = $request->input('payment_method');
$paymentMethod = PaymentMethodType::PAYMENT_METHODS[$paymentMethodStr];
$amount = $request->input('amount');
$bankCode = $request->input('bank_code');
$result = $this->processInvoices($invoices, $paymentMethodStr, $amount, $bankCode);
if ($paymentMethod === PaymentMethodType::PAYMENT_GATEWAY) {
return $this->resourceResponse(new WalletTransactionResource($result));
}
}
return $this->response([]);
}
private function processInvoices($invoices, $reqPaymentMethod, $reqAmount, $reqBankCode){
$result = [];
$payment_method = PaymentMethodType::PAYMENT_METHODS[$reqPaymentMethod];
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
foreach ($invoices as $invoice) {
$order = null;
if ($invoice->owner instanceof Transaction) {
@@ -110,7 +137,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
$wallet = Wallet::where('owner_id', $companyModuleId)->first();
// todo-new: verify currently checking wallet amount based on 'amount' value passed by frontend
if((float) number_format(($wallet->amount - $request->input('amount')),2) < 0){
if((float) number_format(($wallet->amount - $reqAmount),2) < 0){
throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.');
}
@@ -146,7 +173,12 @@ class CreateGroupsLogic extends AbstractControllerLogic
foreach ($invoices as $invoice) {
if ($payment_method == PaymentMethodType::WALLET) {
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $request->input('bank_code'));
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $reqBankCode, false);
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
$pL = $invoice->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
}
}
$issuer = $invoice->issuer;
@@ -168,11 +200,12 @@ class CreateGroupsLogic extends AbstractControllerLogic
if (in_array($payment_method, [PaymentMethodType::PAYMENT_GATEWAY, PaymentMethodType::CASH])) {
// create only one billplz payment for wallet top up
$amount = floatval(str_replace(',', '', $request->input('amount')));
$amount = floatval(str_replace(',', '', $reqAmount));
$companyModuleId = $invoice->receiver;
$companyModule = $this->fetchesCompanyModule->execute(['id' => $companyModuleId]);
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), $payment_method, $billNumber, true);
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $reqBankCode, $payment_method, $billNumber, true);
$result = $topUpTransaction;
}
$group->issuer = $issuer;
@@ -188,11 +221,15 @@ class CreateGroupsLogic extends AbstractControllerLogic
$group->status = $groupPyamentStatus;
$group->save();
if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) {
return $this->resourceResponse(new WalletTransactionResource($topUpTransaction));
return $result;
}
} else {
return $this->response([]);
private function checkIfInvoicesAreApprove($invoices){
foreach ($invoices as $invoice) {
if($invoice->status !== ApprovalStatus::APPROVED && $invoice->status !== ApprovalStatus::COMPLETED){
return false;
}
}
return true;
}
}
@@ -10,6 +10,8 @@ use App\Http\Resources\TransactionResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
class CreatePaymentTransactionLogic extends AbstractControllerLogic
{
@@ -30,13 +32,18 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
/** @var CreatePaymentTransactionProcessor */
private $createPaymentTransactionProcessor;
/** @var ReleaseGoodsToCustomerProcessor */
private $releaseGoodsToCustomerProcessor;
public function __construct(
FetchesTransaction $fetchesTransaction,
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
}
public function logic(Request $request) : JsonResponse
@@ -45,22 +52,20 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'));
if($invoice_transaction->status === ApprovalStatus::APPROVED){
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'), false);
//cief todo: at exchange there is a transition step - starts
// if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){
// $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
// }
if($payment_transaction && $payment_transaction->status === ApprovalStatus::APPROVED){
$pL = $invoice_transaction->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice_transaction);
}
return $this->resourceResponse(new TransactionResource($payment_transaction));
}
// if(config('perfexcrm.is_enabled') == 'true'){
// $this->transactionToPerfexCRMV2Processor->execute($transaction, $status);
// }
//To use
//ApprovalStatus::PENDING_VERIFICATION;
//use this to trigger $this->transactionToPerfexCRMV2Processor->execute > defineTasks > defineTasks_handlePendingVerificationStatus > definePaymentTasks
//cief todo: at exchange there is a transition step - ends
return $this->resourceResponse(new TransactionResource($payment_transaction));
$response = ['message' => 'A transaction might be suspended; please check if there is any dispute in progress.'];
return $this->response(['data' => $response]);
}
}
@@ -48,6 +48,8 @@ class DeleteGroupLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
ini_set('memory_limit', '-1');
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
foreach ($group->groupTransactions as $groupTransaction) {
@@ -0,0 +1,90 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\General\Eloquent\Filters\PaymentMethod;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\Modules\Transactions\Services\FetchesGroup;
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
use App\Classes\Modules\Transactions\Services\DeletesGroup;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Transaction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class DeletePaidGroupLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification(): array
{
return [
'title' => 'Delete Paid Group Transaction',
'message' => 'You have successfully deleted this Group Transaction'
];
}
/** @var FetchesGroup */
private $fetchesGroup;
/** @var DeletesGroup */
private $deletesGroup;
/**
* DeleteGroupLogic constructor.
* @param updatesTransactionStatus $updatesTransactionStatus
* @param FetchesGroup $fetchesGroup
* @param DeletesTransaction $deletesTransaction
*/
public function __construct(FetchesGroup $fetchesGroup, DeletesGroup $deletesGroup)
{
$this->fetchesGroup = $fetchesGroup;
$this->deletesGroup = $deletesGroup;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request): JsonResponse
{
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
$paymentTransaction = $invoice->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
if ($paymentTransaction->payment_method == PaymentMethodType::WALLET) {
// Store the transaction ID before deleting
$transactionId = Transaction::where('bill_no', $paymentTransaction->payment_reference)->first()->id;
// Delete the transaction
Transaction::where('id', $transactionId)->first()->delete();
// Now you have the transaction ID available in $transactionId
Log::channel('deletePaidGroupOrder')->info("Deleted payment reference transaction ID: " . $transactionId);
} else {
Log::channel('deletePaidGroupOrder')->info("no transaction found. Invoice Id ->" . $invoice->id);
}
// Store the transaction ID before deleting
$transactionId = $paymentTransaction->id;
// Delete the payment transaction
$paymentTransaction->delete();
Log::channel('deletePaidGroupOrder')->info("Deleted payment transaction ID: " . $transactionId);
}
Log::channel('deletePaidGroupOrder')->info("Deleted Group -> " . $group->id);
$this->deletesGroup->execute($group);
return $this->response([]);
}
}
@@ -6,9 +6,13 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Transactions\Services\FetchesGroup;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\Transaction;
use App\Models\Wallet;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class DeletePaymentTransactionLogic extends AbstractControllerLogic
{
@@ -23,6 +27,9 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic
];
}
/** @var FetchesGroup */
private $fetchesGroup;
/** @var FetchesTransaction */
private $fetchesTransaction;
@@ -34,11 +41,13 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic
* SuspendTransactionLogic constructor.
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param FetchesGroup $fetchesGroup
*/
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus)
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesGroup $fetchesGroup)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->fetchesGroup = $fetchesGroup;
}
@@ -46,11 +55,23 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic
{
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
if($transaction->owner instanceof Wallet){
try{
$group = $this->fetchesGroup->execute(['reference' => $transaction->payment_reference]);
$group->status = ApprovalStatus::SUSPENDED;
$group->save();
}
catch(\Exception $excaption){
Log::info('No group associated with transaction with payment_reference - '.$transaction->payment_reference);
}
}
$transaction->delete();
$invoice = $transaction->owner;
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::APPROVED);
if ($invoice instanceof Transaction) {
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::APPROVED);
}
return $this->response([]);
}
@@ -30,7 +30,7 @@ class DeleteTransactionLogic extends AbstractControllerLogic
/**
* SuspendTransactionLogic constructor.
* DeleteTransactionLogic constructor.
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
*/
@@ -5,10 +5,12 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\ListsTransactions;
use App\Http\Resources\BookingResource;
use App\Http\Resources\TransactionWithStorageResource;
use App\Http\Resources\TransactionResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class ListTransactionsLogic extends AbstractControllerLogic
{
@@ -38,13 +40,21 @@ class ListTransactionsLogic extends AbstractControllerLogic
public function logic(Request $request) : JsonResponse
{
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
return $this->collectionResponse(TransactionResource::collection($query));
if($request->input('storages')){
foreach ($query->items() as $item) {
$transactionId = $item['id'];
$filteredStorages = array_filter($request->input('storages'), function ($storage) use ($transactionId) {
return isset($storage['parentInvoiceId']) && $storage['parentInvoiceId'] == $transactionId;
});
$item['storages'] = $filteredStorages;
}
//return $this->collectionResponse(TransactionWithStorageResource::collection($query));
}
// else{
// return $this->collectionResponse(TransactionResource::collection($query));
//
return $this->collectionResponse(TransactionWithStorageResource::collection($query));
}
}
@@ -0,0 +1,67 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceDocTransactionFixProcessor;
use App\Classes\Modules\Transactions\Standards\Rules\CanRegenerateStorageInvoice;
use App\Classes\ValueObjects\Constants\TransactionType;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class RegenerateSingleStorageInvoiceTransactionLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Regenerate Storage Invoice',
'message' => 'You have successfully regenerated storage invoice'
];
}
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var CreateStorageInvoiceDocTransactionFixProcessor */
private $createStorageInvoiceDocTransactionProcessor;
/** @var CanRegenerateStorageInvoice */
private $canRegenerateStorageInvoice;
/**
* @param CreatesDocument $createsDocument
*/
public function __construct(FetchesTransaction $fetchesTransaction, CreateStorageInvoiceDocTransactionFixProcessor $createStorageInvoiceDocTransactionProcessor, CanRegenerateStorageInvoice $canRegenerateStorageInvoice)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->createStorageInvoiceDocTransactionProcessor = $createStorageInvoiceDocTransactionProcessor;
$this->canRegenerateStorageInvoice = $canRegenerateStorageInvoice;
}
public function logic(Request $request) : JsonResponse
{
$this->canRegenerateStorageInvoice->passes();
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
$packingList = $invoice->owner;
$order = $packingList->owner;
$invoices = $order->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->get();
foreach ($invoices as $invoice){
$invoice->documents()->delete();
}
$this->createStorageInvoiceDocTransactionProcessor->execute($packingList, true);
Log::info(Auth::user()->email." regenerate storage invoice for transaction with id ".$request->route('invoice_id'));
return $this->response([]);
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\DataTransferObjects\WaiveTransactionObject;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionIsWaived;
use App\Classes\Modules\Transactions\Standards\Rules\CanWaiveTransaction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class WaiveTransactionLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Waive Transaction',
'message' => 'You have successfully waived the transaction'
];
}
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var UpdatesTransactionIsWaived */
private $updatesTransactionIsWaived;
/** @var CanWaiveTransaction */
private $canWaiveTransaction;
/**
* WaiveTransactionLogic constructor.
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionIsWaived $updatesTransactionIsWaived
* @param CanWaiveTransaction $canWaiveTransaction
*/
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionIsWaived $updatesTransactionIsWaived, CanWaiveTransaction $canWaiveTransaction)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionIsWaived = $updatesTransactionIsWaived;
$this->canWaiveTransaction = $canWaiveTransaction;
}
public function logic(Request $request) : JsonResponse
{
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
$object = new WaiveTransactionObject($transaction->id, $transaction->bill_no, $transaction->type, $transaction->status);
$this->canWaiveTransaction->passes($object);
$this->updatesTransactionIsWaived->execute($transaction);
Log::info(Auth::user()->email." waive storage invoice charges with bill_no: ".$transaction->bill_no);
return $this->response([]);
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Classes\Modules\Transactions\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class WaiveTransactionObject implements DataTransferObject
{
/** @var int */
private $id;
/** @var string */
private $billNo;
/** @var int */
private $type;
/** @var int */
private $status;
public function __construct(int $id, string $billNo, int $type, int $status)
{
$this->id = $id;
$this->billNo = $billNo;
$this->type = $type;
$this->status = $status;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getBillNo(): string
{
return $this->billNo;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @return int
*/
public function getStatus(): int
{
return $this->status;
}
}
@@ -17,6 +17,8 @@ use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Jobs\CreatePerfexCRMInvoice;
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
use App\Models\Order;
class ApproveShippingInvoiceTransactionProcessor
{
@@ -30,17 +32,21 @@ class ApproveShippingInvoiceTransactionProcessor
/** @var CreatesFiles */
private $createsFiles;
/** @var CheckStorageInvoiceTransactionProcessor */
private $storageInvoiceTransactionProcessor;
/**
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFiles
*/
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles)
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
{
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->createsDocument = $createsDocument;
$this->createsFiles = $createsFiles;
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
}
@@ -50,7 +56,6 @@ class ApproveShippingInvoiceTransactionProcessor
*/
public function execute(PackingList $packingList)
{
/** @var Transaction $invoice_transaction */
$invoice_transaction = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::PENDING_SUBMISSION])->first();
@@ -75,6 +80,11 @@ class ApproveShippingInvoiceTransactionProcessor
$user->notify(new InvoiceIssuedEmail($user, $packingList));
}
$order = $packingList->owner()->first();
if($order instanceof Order){
$this->storageInvoiceTransactionProcessor->executeOrder($order);
}
return;
}
@@ -0,0 +1,432 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
use App\Classes\Modules\Transactions\Services\UpdatesTransaction;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionDetail;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Transactions\Services\DeletesGroup;
use App\Classes\Modules\Billplzs\Services\DeletesBillplzBill;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransactionDetailType;
use App\Http\Resources\TransactionWithStorageResource;
use App\Models\Order;
use App\Models\PackingList;
use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class CheckStorageInvoiceTransactionProcessor
{
/** @var FetchesOrder */
private $fetchesOrder;
/** @var GeneratesTransactionBillNumber */
private $generatesTransactionBillNumber;
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var CreatesTransaction */
private $createsTransaction;
/** @var CreatesTransactionDetail */
private $createsTransactionDetail;
/** @var UpdatesTransaction */
private $updatesTransaction;
/** @var UpdatesTransactionDetail */
private $updatesTransactionDetail;
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var DeletesGroup */
private $deletesGroup;
/** @var DeletesBillplzBill */
private $deletesBillplzBill;
/**
* @param FetchesOrder $fetchesOrder
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param FetchesTransaction $fetchesTransaction
* @param CreatesTransaction $createsTransaction
* @param CreatesTransactionDetail $createsTransactionDetail
* @param UpdatesTransaction $updatesTransaction
* @param UpdatesTransactionDetail $updatesTransactionDetail
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param DeletesGroup $deletesGroup
* @param DeletesBillplzBill $deletesBillplzBill
*/
public function __construct(FetchesOrder $fetchesOrder, GeneratesTransactionBillNumber $generatesTransactionBillNumber, FetchesTransaction $fetchesTransaction, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, UpdatesTransaction $updatesTransaction, UpdatesTransactionDetail $updatesTransactionDetail, UpdatesTransactionStatus $updatesTransactionStatus, DeletesGroup $deletesGroup, DeletesBillplzBill $deletesBillplzBill)
{
$this->fetchesOrder = $fetchesOrder;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->fetchesTransaction = $fetchesTransaction;
$this->createsTransaction = $createsTransaction;
$this->createsTransactionDetail = $createsTransactionDetail;
$this->updatesTransaction = $updatesTransaction;
$this->updatesTransactionDetail = $updatesTransactionDetail;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->deletesGroup = $deletesGroup;
$this->deletesBillplzBill = $deletesBillplzBill;
}
/**
* @throws MalformedRequestException
*/
public function execute(int $orderReference)
{
$order = $this->fetchesOrder->execute(['reference' => $orderReference, 'with_packing_lists' => true]);
return $this->executeOrder($order);
}
public function executeOrder(Order $order){
$results = [];
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
$is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term;
Log::channel('storage_invoices')->info('orderId: '.$order->id.', orderReference: '.$order->reference.', marking: '.$marking.', is_credit_term: '.$is_credit_term);
$packingLists = $order->destinationWarehousePackages;
foreach ($packingLists as $packingList){
$arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehoue($packingList);
Log::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse));
Log::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList));
$eta = $this->getEtaFromPackingList($packingList);
if($arrivalDateAtChinaWarehouse && $eta){
$transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
// $transactions = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->where('transactions.status', ApprovalStatus::APPROVED)->get();
/** @var Transaction $invoice_transaction */
foreach ($transactions as $invoice_transaction){
$result = null;
if(!$is_credit_term){
$result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $eta);
}
else{
$result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $eta);
}
if($result){
$results[] = $result;
}
}
}
}
return $results;
}
private function getArrivalDateAtChinaWarehoue($packingList){
if($packingList->type === PackingListType::SHIPPING_PACKING_LIST){
$receive_packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first();
Log::channel('storage_invoices')->info('receive_packing_list: '.json_encode($receive_packing_list->transports));
$transport = $receive_packing_list->transports->first();
if ($transport) {
$arrivalDateAtChinaWarehouse = Carbon::parse($transport->drop_date);
$dateToCompare = Carbon::parse(env('STORAGE_FEE_LAUNCH_DATE', '2023-12-11 00:00:00'));
// dd($dateToCompare);
if ($arrivalDateAtChinaWarehouse->isAfter($dateToCompare)) {
Log::channel('storage_invoices')->info('transport: '.json_encode($transport));
Log::channel('storage_invoices')->info('dateToCompare: '.$dateToCompare.', arrivalDateAtChinaWarehouse: '.$arrivalDateAtChinaWarehouse);
return $arrivalDateAtChinaWarehouse;
}
}
}
return null;
}
private function getEtaFromPackingList($packingList){
if ($packingList) {
$package = $packingList->packages->first();
if ($package) {
$container = $package->container()->first();
if ($container) {
$transport = $container->transports->first();
if ($transport) {
$schedule = $transport->schedules->last();
if ($schedule) {
return $schedule->eta;
}
}
}
}
}
return null;
}
private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $eta){
$pricePerCBM = 3;
$resultNumberOfDaysFree = 10;
$dt1 = $eta->copy()->addDay()->startOfDay();
$resultStartDate = $dt1->format('Y-m-d');
$currentDatetime = Carbon::now();
$dt2 = $currentDatetime->copy()->addDay()->startOfDay();
$resultCurrentDate = $dt2->format('Y-m-d H:i:s');
$interval = Carbon::parse($dt2)->diff($dt1);
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
$storageInvoice = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->first();
$storageInvoiceId = 0;
$transactionDetailsItems = $transaction->transactionDetails()->get();
$cbm = 0.00;
foreach ($transactionDetailsItems as $tdItem){
$quantity = $tdItem->quantity;
if($tdItem->price < 0.00){
$quantity = $quantity * -1;
}
$cbm = $cbm + $quantity;
}
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
Log::channel('storage_invoices')->info('storageInvoice: '.json_encode($storageInvoice).', $transaction->status: '.$transaction->status);
if(!$storageInvoice && $resultNumberOfDaysExceeded > 0 && $transaction->status != ApprovalStatus::COMPLETED){
Log::channel('storage_invoices')->info('Created $transaction->id: '.$transaction->id);
$billNumber = $this->generatesTransactionBillNumber->execute('STOR-');
$storageInvoice = $this->createStorageInvoiceTransaction($destinationWarehousePackage, $billNumber, $company_module_id, $price_cbm);
$storageInvoiceId = $storageInvoice->id;
$this->createStorageInvoiceTransactionDetails($storageInvoice, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded);
}
else if($storageInvoice){
//Additional handling for giving selected storage invoice a waiver
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
$pricePerCBM = 0;
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
}
//Additional handling for calculation of numberOfDaysExceeded in the event of the storage already paid
$paymentStorageTransaction = $storageInvoice->transactions()->where('transactions.type', TransactionType::PAYMENT)->where('transactions.status', ApprovalStatus::APPROVED)->first();
if($paymentStorageTransaction){
$dateStorageInvoicePaid = $paymentStorageTransaction->created_at->copy()->addDay()->startOfDay();
Log::channel('storage_invoices')->info('dateStorageInvoicePaid: '.$dateStorageInvoicePaid.', resultCurrentDate: '.$resultCurrentDate);
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1);
$resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree;
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
}
$amount = $storageInvoice->amount;
$epsilon = 0.0001; // Tolerance for the comparison
Log::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id);
Log::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status);
Log::channel('storage_invoices')->info('price_cbm: '.$price_cbm."-".gettype($price_cbm));
Log::channel('storage_invoices')->info('amount: '.$amount);
$proceedToUpdate = false;
if(abs($price_cbm - $amount) > $epsilon && $storageInvoice->status !== ApprovalStatus::COMPLETED){
$paymentTransactions = $storageInvoice->transactions()->where('transactions.type', TransactionType::PAYMENT)->where('transactions.status', ApprovalStatus::PENDING_SUBMISSION)->get();
// if(!$isBackDoorCheck){
if(count($paymentTransactions) > 0){
$this->updatePaymentTransactionViaNonGroupPayment($paymentTransactions);
}
else{
$this->updatePaymentTransactionViaGroupPayment($storageInvoice);
}
//}
$proceedToUpdate = true;
}
if($proceedToUpdate || ($pricePerCBM == 0 && $amount != 0)){
Log::channel('storage_invoices')->info('proceedToUpdate');
$storageInvoice = $this->updateStorageInvoiceTransaction($storageInvoice, $price_cbm);
$invoiceTransactionDetails = $storageInvoice->transactionDetails()->first();
$this->updateStorageInvoiceTransactionDetails($invoiceTransactionDetails, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded);
}
$storageInvoiceId = $storageInvoice->id;
}
if($storageInvoiceId !== 0){
$result = [
'parentInvoiceId' => $transaction->id,
'storageInvoiceId' => $storageInvoiceId,
'numberOfDaysExceeded' => $resultNumberOfDaysExceeded,
'numberOfDaysFree' => $resultNumberOfDaysFree,
'startDate' => $resultStartDate,
'currentDate' => $resultCurrentDate,
'cbm' => $cbm,
'pricePerCBM' => $pricePerCBM,
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
];
return $result;
}
}
private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $eta){
$pricePerCBM = 3;
$resultNumberOfDaysFree = 10;
$dt1 = $eta->copy()->addDay()->startOfDay();
$resultStartDate = $dt1->format('Y-m-d');
$currentDatetime = Carbon::now();
$dt2 = $currentDatetime->copy()->addDay()->startOfDay();
$resultCurrentDate = $dt2->format('Y-m-d H:i:s');
$interval = Carbon::parse($dt2)->diff($dt1);
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
$paidStorageInvoice = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('transactions.status', [ApprovalStatus::COMPLETED])->first();
if($paidStorageInvoice){
$storageInvoice = $paidStorageInvoice;
}
else{
$waivedStorageInvoice = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->where('transactions.is_waived', 1)->whereIn('transactions.status', [ApprovalStatus::APPROVED])->first();
$storageInvoice = $waivedStorageInvoice;
}
if($storageInvoice){
$storageInvoiceId = $storageInvoice->id;
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
$pricePerCBM = 0;
}
$transactionDetailsItems = $transaction->transactionDetails()->get();
$cbm = 0.00;
foreach ($transactionDetailsItems as $tdItem){
$quantity = $tdItem->quantity;
if($tdItem->price < 0.00){
$quantity = $quantity * -1;
}
$cbm = $cbm + $quantity;
}
if($storageInvoiceId !== 0){
$result = [
'parentInvoiceId' => $transaction->id,
'storageInvoiceId' => $storageInvoiceId,
'numberOfDaysExceeded' => $resultNumberOfDaysExceeded,
'numberOfDaysFree' => $resultNumberOfDaysFree,
'startDate' => $resultStartDate,
'currentDate' => $resultCurrentDate,
'cbm' => $cbm,
'pricePerCBM' => $pricePerCBM,
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
];
return $result;
}
}
return [];
}
private function updatePaymentTransactionViaGroupPayment($storageInvoice){
Log::channel('storage_invoices')->info('updatePaymentTransactionViaGroupPayment');
$groups = $storageInvoice->groups()->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED])->get();
foreach ($groups as $grp){
$groupReference = $grp->reference;
$walletTransaction = $this->fetchesTransaction->execute(['payment_reference' => $groupReference]);
if($walletTransaction->status === ApprovalStatus::PENDING_SUBMISSION || $walletTransaction->status === ApprovalStatus::PENDING_VERIFICATION){
$grp->status = ApprovalStatus::EXPIRED;
$grp->save();
$this->deletesGroup->execute($grp);
$this->updatesTransactionStatus->execute($walletTransaction, ApprovalStatus::EXPIRED);
if($walletTransaction->payment_reference){
$deletedBillplzBill = $this->deletesBillplzBill->execute($walletTransaction->payment_reference);
Log::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
}
}
}
}
private function updatePaymentTransactionViaNonGroupPayment($paymentTransactions){
Log::channel('storage_invoices')->info('updatePaymentTransactionViaNonGroupPayment');
foreach ($paymentTransactions as $paymentTransaction){
$this->updatesTransactionStatus->execute($paymentTransaction, ApprovalStatus::EXPIRED);
if($paymentTransaction->payment_reference){
$deletedBillplzBill = $this->deletesBillplzBill->execute($paymentTransaction->payment_reference);
Log::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
}
}
}
private function updateStorageInvoiceTransaction(Transaction $transaction, float $totalAmount){
$object = new TransactionObject(
$transaction->bill_no,
TransactionType::STORAGE_INVOICE,
1,
$transaction->receiver,
1,
PaymentMethodType::CASH,
$totalAmount,
$totalAmount,
1,
1,
0,
0,
0,
null,
ApprovalStatus::APPROVED
);
/** @var Transaction $invoice_transaction */
$invoice_transaction = $this->updatesTransaction->execute($transaction, $object);
return $invoice_transaction;
}
private function updateStorageInvoiceTransactionDetails($invoice_transaction_details, PackingList $packing_list, $cbm, $pricePerCBM, $numberOfDays){
$object_detail = new TransactionDetailObject(
'STORAGE_FEE',
TransactionDetailType::STORAGE_FEE.' for '.$numberOfDays. ' days * RM'.$pricePerCBM.'<br>'.round($packing_list->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum('quantity'), 3).' CTNS - '.round($cbm, 3).' CBM',
$cbm,
$pricePerCBM * $numberOfDays
);
$this->updatesTransactionDetail->execute($invoice_transaction_details, $object_detail);
}
private function createStorageInvoiceTransaction(PackingList $packing_list, string $billNumber, int $companyModuleId, float $totalAmount){
$object = new TransactionObject(
$billNumber,
TransactionType::STORAGE_INVOICE,
1,
$companyModuleId,
1,
PaymentMethodType::CASH,
$totalAmount,
$totalAmount,
1,
1,
0,
0,
0,
null,
ApprovalStatus::APPROVED
);
/** @var Transaction $invoice_transaction */
$invoice_transaction = $this->createsTransaction->execute($packing_list, $object);
return $invoice_transaction;
}
private function createStorageInvoiceTransactionDetails($invoice_transaction, PackingList $packing_list, $cbm, $pricePerCBM, $numberOfDays){
$object_detail = new TransactionDetailObject(
'STORAGE_FEE',
TransactionDetailType::STORAGE_FEE.' for '.$numberOfDays. ' days * RM'.$pricePerCBM.'<br>'.round($packing_list->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum('quantity'), 3).' CTNS - '.round($cbm, 3).' CBM',
$cbm,
$pricePerCBM * $numberOfDays
);
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
}
}
@@ -85,7 +85,7 @@ class CreatePaymentTransactionProcessor
/**
* @throws MalformedRequestException
*/
public function execute(Transaction $invoice, $payment_method, $bank_code)
public function execute(Transaction $invoice, $payment_method, $bank_code, $run = true)
{
$amount = $invoice->amount;
Log::info($invoice->owner);
@@ -127,22 +127,26 @@ class CreatePaymentTransactionProcessor
$this->updatesWalletBalance->execute($wallet, ($amount * -1));
$packingList = $invoice->owner;
$order = $packingList->owner;
$packingList->status = ApprovalStatus::APPROVED;
$packingList->save();
if($run)
{
$packingList = $invoice->owner;
$order = $packingList->owner;
$packingList->status = ApprovalStatus::APPROVED;
$packingList->save();
if(app()->environment('production')){
$this->updateDoFromVTPortalProcessor->execute($packingList);
$this->updateDoFromYDPortalProcessor->execute($packingList);
if(app()->environment('production')){
$this->updateDoFromVTPortalProcessor->execute($packingList);
$this->updateDoFromYDPortalProcessor->execute($packingList);
}
}
// later use this variabke to create a approved payment transaction
$approvalStatus = ApprovalStatus::APPROVED;
// update invoice to completed
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
if($run){
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
}
}
else {
$payment_method = PaymentMethodType::CASH;
@@ -0,0 +1,79 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Notifications\InvoiceIssuedEmail;
use App\Models\Document;
use App\Models\PackingList;
use App\Models\Transaction;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
class CreateStorageInvoiceDocTransactionFixProcessor
{
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFiles;
/**
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFiles
*/
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles)
{
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->createsDocument = $createsDocument;
$this->createsFiles = $createsFiles;
}
/**
* @throws MalformedRequestException
*/
public function execute(PackingList $packingList)
{
/** @var Transaction $invoice_transaction */
$invoice_transaction = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('status', [ApprovalStatus::COMPLETED])->first();
// $this->updatesTransactionStatus->execute($invoice_transaction, ApprovalStatus::APPROVED);
$transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice_transaction]);
$document_object = new DocumentObject(
DocumentType::STORAGE_INVOICE,
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'storage_invoice'
);
// $invouce_transaction_document = $invoice_transaction->documents()->where('document_type', DocumentType::STORAGE_INVOICE)->first();
// if(!$invouce_transaction_document){
/** @var Document $document */
$document = $this->createsDocument->execute($invoice_transaction, $document_object);
$this->createsFiles->execute($document, $document_object);
// $user = $packingList->owner->companyModule->employees()->first();
// if(app()->environment(['production'])) {
// $user->notify(new InvoiceIssuedEmail($user, $packingList));
// }
// }
}
}
@@ -0,0 +1,79 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Notifications\InvoiceIssuedEmail;
use App\Models\Document;
use App\Models\PackingList;
use App\Models\Transaction;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
class CreateStorageInvoiceDocTransactionProcessor
{
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFiles;
/**
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFiles
*/
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles)
{
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->createsDocument = $createsDocument;
$this->createsFiles = $createsFiles;
}
/**
* @throws MalformedRequestException
*/
public function execute(PackingList $packingList)
{
/** @var Transaction $invoice_transaction */
$invoice_transaction = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('status', [ApprovalStatus::COMPLETED])->first();
// $this->updatesTransactionStatus->execute($invoice_transaction, ApprovalStatus::APPROVED);
$transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice_transaction]);
$document_object = new DocumentObject(
DocumentType::STORAGE_INVOICE,
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'storage_invoice'
);
$invouce_transaction_document = $invoice_transaction->documents()->where('document_type', DocumentType::STORAGE_INVOICE)->first();
if(!$invouce_transaction_document){
/** @var Document $document */
$document = $this->createsDocument->execute($invoice_transaction, $document_object);
$this->createsFiles->execute($document, $document_object);
$user = $packingList->owner->companyModule->employees()->first();
if(app()->environment(['production'])) {
$user->notify(new InvoiceIssuedEmail($user, $packingList));
}
}
}
}
@@ -0,0 +1,94 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use Illuminate\Http\Request;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceDocTransactionProcessor;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
use Illuminate\Support\Facades\Log;
class ReleaseGoodsToCustomerProcessor
{
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var UpdateDoFromVTPortalProcessor */
private $updateDoFromVTPortalProcessor;
/** @var UpdateDoFromYDPortalProcessor */
private $updateDoFromYDPortalProcessor;
/** @var CreateStorageInvoiceDocTransactionProcessor */
private $createStorageInvoiceDocTransactionProcessor;
/**
* ReleaseGoodsToCustomerProcessor constructor.
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
* @param CreateStorageInvoiceDocTransactionProcessor $createStorageInvoiceDocTransactionProcessor
*/
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, CreateStorageInvoiceDocTransactionProcessor $createStorageInvoiceDocTransactionProcessor)
{
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
$this->createStorageInvoiceDocTransactionProcessor = $createStorageInvoiceDocTransactionProcessor;
}
/**
* @param $packingList
* @param $invoice
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute($packingList, $invoice = null)
{
$result = false;
$totalInvoicesAmountPaid = 0.00;
$totalInvoicesAmount = 0.00;
$invoiceTransactions = $packingList->transactions()->where('status', [ApprovalStatus::APPROVED])->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get();
//Part 1: Process each single invoice type and get the total of all invoices
foreach($invoiceTransactions as $invoiceTransaction){
$totalInvoiceAmountPaid = $invoiceTransaction->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
if ($invoice && $invoice->type == $invoiceTransaction->type) {
if(($invoice->amount - $totalInvoiceAmountPaid) < 0.01){
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
if($invoice->type == TransactionType::STORAGE_INVOICE){
$this->createStorageInvoiceDocTransactionProcessor->execute($packingList);
}
}
}
$totalInvoicesAmount = $totalInvoicesAmount + $invoiceTransaction->amount;
$totalInvoicesAmountPaid = $totalInvoicesAmountPaid + $totalInvoiceAmountPaid;
}
Log::channel('storage_invoices')->info('Total invoice amount paid 1: '.$totalInvoicesAmount); //cief todo: to be removed
Log::channel('storage_invoices')->info('Total invoice amount paid 2: '.$totalInvoicesAmountPaid); //cief todo: to be removed
//Part 2: Based on the collected info for all the total of all invoices
if (($totalInvoicesAmount - $totalInvoicesAmountPaid) < 0.01 && $totalInvoicesAmountPaid > 0.01) {
Log::channel('storage_invoices')->info('Total invoice amount paid 3: '.$totalInvoicesAmountPaid); //cief todo: to be removed
$packingList->status = ApprovalStatus::APPROVED;
$packingList->save();
if (app()->environment('production')) {
$this->updateDoFromVTPortalProcessor->execute($packingList);
$this->updateDoFromYDPortalProcessor->execute($packingList);
}
$result = true;
}
return $result;
}
}
@@ -5,8 +5,10 @@ namespace App\Classes\Modules\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\PackingList;
use App\Models\Transaction;
use Carbon\Carbon;
class CreatesTransaction extends AbstractUpdateRelationshipRecord
{
@@ -33,6 +35,11 @@ class CreatesTransaction extends AbstractUpdateRelationshipRecord
$model->expires_on = $object->getExpiresOn();
$model->status = $object->getStatus();
if((int)$object->getTransactionType() === TransactionType::SHIPPING_INVOICE){
$model->created_at = Carbon::now()->subDays(10);
$model->updated_at = Carbon::now()->subDays(10);
}
return $this->handler($packing_list->transactions(), $model);
}
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Classes\Modules\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\Transaction;
class UpdatesTransactionIsWaived extends AbstractUpdateRecord
{
/**
* @param Transaction $model
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Transaction $model)
{
$model->is_waived = 1;
return $this->handler($model);
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\ValueObjects\Constants\RoleTypes;
class CanRegenerateStorageInvoice extends AbstractRule
{
/**
* @return bool
*/
protected function authorized($object): bool
{
$user = Auth()->user();
if($user){
$roleToCheck = Auth()->user()->type;
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
return true;
}
}
return false;
}
/**
* @param $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return true;
}
/**
* @param $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,58 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Transactions\DataTransferObjects\WaiveTransactionObject;
use App\Classes\Modules\Transactions\Standards\Validators\WaiveTransactionValidation;
use App\Classes\ValueObjects\Constants\RoleTypes;
class CanWaiveTransaction extends AbstractRule
{
/** @var WaiveTransactionValidation */
private $waiveTransactionValidation;
public function __construct(WaiveTransactionValidation $waiveTransactionValidation)
{
$this->waiveTransactionValidation = $waiveTransactionValidation;
}
/**
* @return bool
*/
protected function authorized($object): bool
{
$user = Auth()->user();
if($user){
$roleToCheck = Auth()->user()->type;
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
return true;
}
}
return false;
}
/**
* @param WaiveTransactionObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->waiveTransactionValidation->validate($object);
}
/**
* @param $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,46 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Transactions\DataTransferObjects\WaiveTransactionObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
class WaiveTransactionValidation extends AbstractValidation
{
/**
* @param WaiveTransactionObject $object
* @return array
*/
protected function data($object): array {
return [
'id' => $object->getId(),
'billNo' => $object->getBillNo(),
'type' => $object->getType(),
'status' => $object->getStatus(),
];
}
/**
* @return array
*/
protected function rules(): array {
return [
'id' => 'required',
'type' => ['required', 'numeric', 'in:'.TransactionType::STORAGE_INVOICE], //Only storage invoice (type 16) can be waived
'status' => ['required', 'numeric', 'in:'.ApprovalStatus::APPROVED], //Approve storage invoice only, paid invoice stricly forbidden
// 'billNo' => 'required',
];
}
/**
* @return array
*/
protected function messages(): array {
return [];
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Classes\Notifications;
use App\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
class PermitsReminderEmail extends AbstractEmail
{
/** @var User */
private $user;
private $reminders;
/**
* SendResetPasswordEmail constructor.
* @param User $user
* @param PasswordReset $attempt
*/
public function __construct(User $user, $reminders)
{
$this->user = $user;
$this->reminders = $reminders;
}
public function toMail()
{
return (new MailMessage)
->subject('Permits Renew Remidner Email')
->view('emails.reminder.permits_reminder', ['user' => $this->user, 'reminders' => $this->reminders]);
}
}
@@ -24,5 +24,6 @@ final class DocumentType {
public const SHIPPING_INVOICE = 'SHIPPING_INVOICE';
public const STORAGE_INVOICE = 'STORAGE_INVOICE';
}
@@ -11,4 +11,6 @@ final class TransactionDetailType {
public const MIN_CBM_CHARGES = 'Minimum Charge for 0.3 CBM Per Container';
public const CUSTOM_CHARGES = 'Custom charges';
public const STORAGE_FEE = 'Malaysia Warehouse Storage Fee';
}
@@ -5,9 +5,9 @@ namespace App\Classes\ValueObjects\Constants;
final class TransactionType {
// public const PAYMENT_ATTEMPT = 0;
public const SHIPPING_INVOICE = 1;
public const PAYMENT = 2;
// public const BILL = 3;
@@ -35,10 +35,11 @@ final class TransactionType {
// public const SHIPPING_COST = 14;
public const GROUP_PAYMENT = 15;
public const TRANSACTION_TYPE_ID = [
self::SHIPPING_INVOICE => "Shipping Invoice",
self::PAYMENT => "Payment",
];
public const STORAGE_INVOICE = 16;
}
@@ -0,0 +1,85 @@
<?php
namespace App\Console\Commands;
use App\Classes\Modules\Transactions\Services\ListsGroups;
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Console\Command;
class CheckStorageInvoicesGroupTransactions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check-storage-invoices-group-transactions';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check all storage invoices due to make sure that they are up to date daily, prevent \'back door\' cases';
/** @var ListsGroups */
private $listsGroups;
/** @var CheckStorageInvoiceTransactionProcessor */
private $storageInvoiceTransactionProcessor;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(ListsGroups $listsGroups, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
{
parent::__construct();
$this->listsGroups = $listsGroups;
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('memory_limit', '-1');
$this->info(Carbon::now() . ': Start Check all pending group payment with storage invoice is valid.');
$start = new Carbon();
$newfilters['order_by_updated_at_desc'] = true;
$newfilters['status_in'] = [0, 1];
$groups = $this->listsGroups->execute($newfilters);
foreach ($groups as $group){
$this->info('CheckForStorageInvoiceByTransactions group: '.json_encode($group));
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
$packingList = $invoice->owner()->first();
if($packingList){
$order = $packingList->owner()->first();
if($order instanceof Order){
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
}
}
}
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
$this->info(Carbon::now() . ': Done Check all pending group payment with storage invoice is valid. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,82 @@
<?php
namespace App\Console\Commands;
use App\Classes\Modules\Orders\Services\ListsOrders;
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
use App\Classes\ValueObjects\Constants\OrderType;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Console\Command;
class CheckStorageInvoicesOrders extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check-storage-invoices-orders';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check all storage invoices due to make sure that they are up to date daily, prevent \'back door\' cases';
/** @var ListsOrders */
private $listsOrders;
/** @var CheckStorageInvoiceTransactionProcessor */
private $storageInvoiceTransactionProcessor;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(ListsOrders $listsOrders, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
{
parent::__construct();
$this->listsOrders = $listsOrders;
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('memory_limit', '-1');
$this->info(Carbon::now() . ': Start Check all orders for storage invoice.');
$start = new Carbon();
$orders = $this->listsOrders->execute(['with_parcels' => true, 'type_in' => [OrderType::SHARED_CONTAINER, OrderType::DEDICATED_CONTAINER]]);
$count = 0;
foreach ($orders as $order){
try{
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
$count = $count + 1;
$this->info('Order '.$count);
}
catch(\Exception $ex){
$this->info('Exception '.$ex->getMessage());
break;
}
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
$this->info(Carbon::now() . ': Done Check all orders for storage invoice. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,95 @@
<?php
namespace App\Console\Commands;
use App\Classes\Modules\Transactions\Services\FetchesGroup;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceDocTransactionFixProcessor;
use Carbon\Carbon;
use Illuminate\Console\Command;
class FixGroupPaymentProblem extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix-group-payment-problem';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This is a one time data patch for a problem result from Storage Invoice Implementation';
/** @var FetchesGroup */
private $fetchesGroup;
/** @var ReleaseGoodsToCustomerProcessor */
private $releaseGoodsToCustomerProcessor;
/** @var FetchesOrder */
private $fetchesOrder;
/** @var CreateStorageInvoiceDocTransactionFixProcessor */
private $createStorageInvoiceDocTransactionProcessor;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(FetchesGroup $fetchesGroup, ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor, FetchesOrder $fetchesOrder, CreateStorageInvoiceDocTransactionFixProcessor $createStorageInvoiceDocTransactionProcessor)
{
parent::__construct();
$this->fetchesGroup = $fetchesGroup;
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
$this->fetchesOrder = $fetchesOrder;
$this->createStorageInvoiceDocTransactionProcessor = $createStorageInvoiceDocTransactionProcessor;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('memory_limit', '-1');
$this->info(Carbon::now() . ': Start data patch.');
$start = new Carbon();
/*
$group = $this->fetchesGroup->execute(['id' => 325]);
$this->info('FixGroupPaymentProblem group: '.json_encode($group));
if ($group) {
foreach ($group->groupTransactions as $groupTransaction) {
$invoice = $groupTransaction->transaction;
$this->info('FixGroupPaymentProblem group: '.json_encode($invoice));
$pL = $invoice->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
}
}
*/
$order = $this->fetchesOrder->execute(['reference' => '729251424']);
$packingLists = $order->destinationWarehousePackages;
foreach ($packingLists as $packingList){
$this->createStorageInvoiceDocTransactionProcessor->execute($packingList, true);
dd(json_encode($packingList));
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
$this->info(Carbon::now() . ': Done data patch. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Console\Command;
class OneTimeTransactionFixBillplzFailedCallback extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'one-time-transaction-fix-billplz-failed-callback';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This is a one time fix billplz failed callback for transaction with id 15205';
protected $output = null;
protected $outputArray = [];
/** @var CallbackBillplzProcessor */
private $callbackBillplzProcessor;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(CallbackBillplzProcessor $callbackBillplzProcessor)
{
parent::__construct();
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('memory_limit', '-1');
$this->outputArray = [];
$start = new Carbon();
//This transaction, 15205 has approve payment but not its owner, shipping invoice
$transaction = Transaction::whereIn('id', [15205])->first();
$this->info(Carbon::now() . ' : One time fix failled callback from billplz for transaction with id 15205 cron started.');
if($transaction && $transaction->id == 15205){
$status = ApprovalStatus::APPROVED;
$this->callbackBillplzProcessor->execute($transaction, $status);
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
$this->info(Carbon::now() . ' : One time fix failled callback from billplz for transaction with id 15205 cron ended. ElapsedTime: ' . $elapsedTime);
}
}
@@ -0,0 +1,83 @@
<?php
namespace App\Console\Commands;
use App\Classes\Notifications\PermitsReminderEmail;
use App\Models\PermitsReminder;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class SendPermitsReminderEmails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'permitsReminder:send';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send Permits Reminders Email';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$currentDateTime = now();
$startRange = $currentDateTime->subDays(3)->startOfDay();
$endRange = $currentDateTime->copy()->addDays(6)->endOfDay();
$reminders = PermitsReminder::whereDate('reminder_date', '>=', $startRange)
->whereDate('reminder_date', '<=', $endRange)
->orWhere('reminder_date', '<', now())
->pluck('model');
if ($reminders->isEmpty()) {
$this->info('No reminders expiring within the specified range.');
return;
}
$this->info($this->getTimeStamp() . 'Reminders: ' . $reminders->toJson());
$users = User::whereIn('email', $this->getEmailList())->get();
foreach ($users as $user) {
$this->info($this->getTimeStamp() . 'Reminder email sent to ' . $user->email);
if (app()->environment('production')) {
$user->notify(new PermitsReminderEmail($user, $reminders));
}
}
}
public function getTimeStamp()
{
return '[' . Carbon::now()->format('Y-m-d H:i:s') . '] - ';
}
protected function getEmailList(): array
{
return [
'edmond.wuiming2021@gmail.com',
'anithagurl96@gmail.com'
];
}
}
+10
View File
@@ -62,6 +62,16 @@ class Kernel extends ConsoleKernel
->hourly()
->withoutOverlapping()
->appendOutputTo (storage_path().'/logs/fix_failed_callback_from_billplz.log');
$schedule->command('check-storage-invoices-group-transactions')
->dailyAt('0:01')
->withoutOverlapping()
->appendOutputTo(storage_path().'/logs/check_storage_invoices.log');
$schedule->command('permitsReminder:send')
->dailyAt('09:30')
->withoutOverlapping()
->appendOutputTo(storage_path().'/logs/permits-reminder-send.log');
}
/**
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyCreditTermStatusLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyCreditTermStatusController
{
/**
* @param Request $request
* @param UpdateCompanyCreditTermStatusLogic $logic
* @return JsonResponse
*/
public function update(Request $request, UpdateCompanyCreditTermStatusLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Http\Controllers\Imports;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Imports\Services\GenericImport;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\PermitsReminder;
use Carbon\Carbon;
use DateTime;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class ImportPermitsReminderController
{
/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function import(Request $request)
{
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
$file = json_decode($object->getFiles()[0])->file_info->original->file;
$file = storage_path('app/documents/' . $file);
$import = new GenericImport();
Excel::import($import, $file);
$excelRows = $import->rows->toArray();
$successRows = [];
$returnArray = []; // Initialize the return array
foreach ($excelRows as $row) {
if (is_null($row['expiry_date']) && is_null($row['reminder_date'])) {
continue;
}
$row['expiry_date'] = $this->changeExcelDate($row['expiry_date']);
$row['reminder_date'] = $this->changeExcelDate($row['reminder_date']);
$validator = Validator::make($row, [
'model' => 'required|unique:permits_reminders,model',
'expiry_date' => 'required|date|after_or_equal:today',
'reminder_date' => 'required|date|after_or_equal:today',
]);
if ($validator->fails()) {
$row['status'] = 'failed';
$row['message'] = $validator->errors()->all();
$returnArray[] = $row;
} else {
$row['created_at'] = Carbon::now();
$row['updated_at'] = Carbon::now();
$successRows[] = $row;
}
}
if (!empty($successRows)) {
PermitsReminder::insert($successRows); // Insert only if there are successful rows
}
$successCount = count($successRows);
return response()->json([
'completedRows' => $successCount,
'failedRows' => count($returnArray),
'remark' => "Successful Imported {$successCount} data.",
'data' => $returnArray
]);
}
public function changeExcelDate($date)
{
$formatedDate = DateTime::createFromFormat('d/m/Y', $date);
if ($formatedDate instanceof DateTime) {
return $formatedDate->format('Y-m-d');
}
$unixTime = (($date - 25569) * 86400);
return (new DateTime("@$unixTime"))->format('Y-m-d');
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Jobs;
use App\Classes\Modules\Jobs\ControllersLogic\FetchJobResultLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchJobResultController
{
/**
* @param Request $request
* @param FetchJobResultLogic $logic
* @return JsonResponse
*/
public function fetch(Request $request, FetchJobResultLogic $logic): JsonResponse {
return $logic->execute($request);
}
}

Some files were not shown because too many files have changed in this diff Show More