mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
391 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c291134a1 | |||
| 66576b6eea | |||
| 7be3614f96 | |||
| 9a1b33a413 | |||
| 70ad358e5d | |||
| c8249b9276 | |||
| 0484eabb0e | |||
| 7a5cf5f2ce | |||
| 49a31a743c | |||
| f3d6521e2c | |||
| f7a9358202 | |||
| db499bfecf | |||
| 0538653bca | |||
| 9147a4cfec | |||
| a20f4ed9be | |||
| d542a20f76 | |||
| 6d20c8d49e | |||
| f02220fda8 | |||
| 2bf511a1cb | |||
| 4242777e7d | |||
| 65bd979b31 | |||
| e0213108d2 | |||
| 71f50b646b | |||
| 2a662b42e0 | |||
| 024e0d666a | |||
| 37119344f3 | |||
| 37cb4fca18 | |||
| 37e8bf4d9a | |||
| 0df85daf2e | |||
| 650cfba74a | |||
| 7f94148ed9 | |||
| 539da4f551 | |||
| 7c8f5fe791 | |||
| 60c083a9cf | |||
| 5b32fe9d6f | |||
| d315880067 | |||
| 9cd2051cac | |||
| 8c3e8fdeaf | |||
| c31e7aaf37 | |||
| 5b6f419d9e | |||
| c7f00a7ce2 | |||
| 35932e5351 | |||
| 012b88ee37 | |||
| 88869dcadb | |||
| df1d80756a | |||
| 066f5f52d5 | |||
| 4d76ffd545 | |||
| 58f62de2e8 | |||
| 773b30d224 | |||
| 74811f177c | |||
| 82de9ae6f9 | |||
| 6cb27096f7 | |||
| 10660b8350 | |||
| 5c42d383d0 | |||
| d3966e8b28 | |||
| 6a4570442a | |||
| 300f7b6642 | |||
| c28ee64878 | |||
| ce6b47763c | |||
| 881dd71ef0 | |||
| beec9aef24 | |||
| fcd6f2d6a8 | |||
| ae15575b0a | |||
| 4a66578380 | |||
| ffbf6b0f9c | |||
| 1e4d2c8031 | |||
| 2122d18be5 | |||
| 0e9ef67121 | |||
| c2511e2467 | |||
| e663165654 | |||
| e80e52d04e | |||
| eed5559cbf | |||
| 7fdb579ab8 | |||
| 6c5c5a9d34 | |||
| 1d45a7aadf | |||
| 81474625eb | |||
| 769becfc16 | |||
| 6ee296ef06 | |||
| e0e6e53e63 | |||
| 9a90e8cf80 | |||
| 4db8b24b22 | |||
| d5e008d4f3 | |||
| 7a6655c3d9 | |||
| 7fbee7b047 | |||
| 2edd44a218 | |||
| a8d86eebd6 | |||
| 6f2b374cbd | |||
| 3fb7befd62 | |||
| 8607caa84f | |||
| 47d564ec09 | |||
| 8031db446e | |||
| 62177bd3d0 | |||
| 76512b107b | |||
| b8f284c2c0 | |||
| 5db1579c36 | |||
| 7615c3ef3e | |||
| d8f1262ec2 | |||
| 5b8893068c | |||
| 1810809113 | |||
| 9d4daeeb46 | |||
| 84e23ec80f | |||
| 5b2e3a1828 | |||
| c52b577c19 | |||
| 8f6443d536 | |||
| 5414be594d | |||
| 0625c37cdc | |||
| bdc45282a4 | |||
| a716a7a38b | |||
| b3d904f3c8 | |||
| d8f3f50bb0 | |||
| 6d26f690c0 | |||
| f061b5eb86 | |||
| e83e8aa5c8 | |||
| b6e4bbd94c | |||
| ca8e69b17a | |||
| d99566a431 | |||
| 6ce38e5751 | |||
| 8564667c62 | |||
| 7da665ca5b | |||
| 2cee63789b | |||
| 8fbd377965 | |||
| 11ac78881c | |||
| cc49336a4d | |||
| 1380d99109 | |||
| 42e6e82df8 | |||
| 7cac5b937f | |||
| 812f16a191 | |||
| 1073b6484c | |||
| 549bf98725 | |||
| e3afc2b008 | |||
| d0decc6c7b | |||
| 312b467564 | |||
| 7adf03cf06 | |||
| 018c3eb755 | |||
| b8707fbb0d | |||
| 134e0d86ea | |||
| 3d70a42758 | |||
| 9ef56454a0 | |||
| ea1c447fa1 | |||
| 79679fe2e0 | |||
| 5c1a4536f6 | |||
| 345c8d24ca | |||
| d986787c4c | |||
| 3281625e92 | |||
| 71e9a479d9 | |||
| 5fef38a04b | |||
| bf22b86a02 | |||
| 3b0738219f | |||
| 18434903ac | |||
| c2d51fc502 | |||
| be0d10416b | |||
| 9cc80e6965 | |||
| 9991524a2e | |||
| 7808d0d5ae | |||
| 3d7d571370 | |||
| 955b454630 | |||
| f45ea797d6 | |||
| efd734bbdb | |||
| 0c849ee302 | |||
| 9c9d4fe594 | |||
| 167216c26f | |||
| d97796d885 | |||
| 2bd66f6786 | |||
| c64f6f5da5 | |||
| da7843c5df | |||
| 2463e419c8 | |||
| 2cbee23234 | |||
| dca9682c59 | |||
| b417ba074e | |||
| 5767ab1853 | |||
| a7aad5373b | |||
| cad314d6a7 | |||
| 137dfe0669 | |||
| 52b839c741 | |||
| d8ee9f1e67 | |||
| 620b9651a3 | |||
| c37ed89a73 | |||
| f56548efa7 | |||
| 679bb9978a | |||
| 2c6b8ac7ea | |||
| 9b7a5a6f1e | |||
| fbf5fb290e | |||
| 63902e9266 | |||
| 1a318ead7e | |||
| bd8b212f6f | |||
| 59fbdfa789 | |||
| 2bd96075cc | |||
| c046a533d8 | |||
| 8e6c70c67b | |||
| 878e69fdb0 | |||
| e047632de0 | |||
| 8d75da288a | |||
| ab5a94cbc0 | |||
| 17d8c82cff | |||
| 8f80c7ac8c | |||
| 9c09b1e01d | |||
| 6911eba119 | |||
| c564a8ed70 | |||
| 273f81f9a8 | |||
| ba1b287cbb | |||
| 40d133aaab | |||
| d52a52241c | |||
| df9468d568 | |||
| 6d12f2d239 | |||
| fe18d8bf5a | |||
| 3913d3c738 | |||
| be9df4afe3 | |||
| 82512bf4f6 | |||
| a9d4f3c839 | |||
| 218f0f8bca | |||
| 79db1dedc9 | |||
| 2aabd07ec4 | |||
| 1d2eac806e | |||
| 8d0fba2d21 | |||
| b4c239f8a9 | |||
| b3e8e5ea54 | |||
| ed4ec29d63 | |||
| ba5fd5f92d | |||
| e6028701db | |||
| fb2ca65168 | |||
| 8ab9a0ba2d | |||
| 78ac0dbd8f | |||
| e9c3af51c4 | |||
| d6cfd85aa2 | |||
| 844527417a | |||
| f725933f7e | |||
| d5a5f9e730 | |||
| 62f892dfd1 | |||
| 82f5d4c2bc | |||
| a1eebe7f65 | |||
| 18bd36217b | |||
| 772fd583b5 | |||
| 57812656fd | |||
| 3933728a19 | |||
| 8ce8ed813a | |||
| 50b2f00bdc | |||
| 54c23c9f38 | |||
| 15570de9fb | |||
| b21cdba5ae | |||
| fe8395b250 | |||
| 61f01ed39b | |||
| 6e2b2e5f65 | |||
| b4b509b0d1 | |||
| 6bafc49a22 | |||
| 4e4bf96a07 | |||
| 2e9c3000a6 | |||
| 3e4d52d2ff | |||
| f25f5ebb41 | |||
| 404758c851 | |||
| f6d00383cb | |||
| 33dfdde9a0 | |||
| 9b1a5b633c | |||
| b0cd0cca4d | |||
| c0e60e5d3b | |||
| d093b774c2 | |||
| 3fa4b498e9 | |||
| ccd06ff740 | |||
| c209f6e4ed | |||
| f4d8ece23f | |||
| 215e4c72d3 | |||
| 386f5740f4 | |||
| 78c43fd7a4 | |||
| d076892176 | |||
| 06b9695528 | |||
| 0a54f46b91 | |||
| 83b3d0c725 | |||
| de7331547c | |||
| 4daaac476d | |||
| fbf036d4b8 | |||
| 055e720e9f | |||
| 5a0b2d5a86 | |||
| 8f6f9893bb | |||
| 3255020f11 | |||
| 8c16277c6c | |||
| 87aeb0ae59 | |||
| 76b14cd667 | |||
| 6affa86c92 | |||
| a8c4661b2d | |||
| acb42ef3ab | |||
| 21f1a14e6f | |||
| d5a9e3923e | |||
| 7416aa00ac | |||
| 437765bdbb | |||
| 9c7ed93a54 | |||
| a3b08a7c11 | |||
| e3bc918bd8 | |||
| a23a632b87 | |||
| 651092aa65 | |||
| fe79d5bcef | |||
| 6ea7517187 | |||
| 4e68eefe4d | |||
| 48fc02f2d2 | |||
| 942c94c821 | |||
| bfb76bc512 | |||
| 8e3cdef4e1 | |||
| c798d96238 | |||
| 64d1b91fa3 | |||
| 2ff63c8d0d | |||
| b57a7cb2bb | |||
| bf5c5574d6 | |||
| 74a1f2af4c | |||
| 95d230d64f | |||
| 88564c661f | |||
| 6ce7f7dc91 | |||
| b91a8635d5 | |||
| 236b3769f8 | |||
| 3c4a19d4be | |||
| 269fbcbd66 | |||
| 603a67c770 | |||
| bb0832b8b0 | |||
| 8276fef3e1 | |||
| aa4fcae07e | |||
| 05adf091a8 | |||
| b5e5e88a6a | |||
| 32bad3bf07 | |||
| 1508fb5f1a | |||
| 70a2bdec48 | |||
| f5df0c9f1f | |||
| e50bab014d | |||
| 1933787fc3 | |||
| 5535f13aff | |||
| 3a2131a04d | |||
| c8e8c9cb0e | |||
| 0e617f5ce2 | |||
| ccb77ce56c | |||
| 8f8c3ca660 | |||
| 922718f7c2 | |||
| 54e6041fe5 | |||
| 141f1ed9d5 | |||
| 61d7ad22e7 | |||
| 798bf4e70e | |||
| aa833f7a9f | |||
| 8dd3fbf97a | |||
| 63e1b767fc | |||
| 60ff1c5130 | |||
| 22aac2df04 | |||
| 33d65be53b | |||
| d2f6f4e8a1 | |||
| 299c384cb2 | |||
| be171f550b | |||
| 8295b80f73 | |||
| 67969c63d3 | |||
| 2074c8661a | |||
| 9518928b7d | |||
| 634a39b1ea | |||
| 5808fd0b2f | |||
| d7ce1df29b | |||
| eac3f31351 | |||
| 95a9cba32d | |||
| 26812f723a | |||
| 0734447937 | |||
| e3f57fffd6 | |||
| b4bc441a5b | |||
| d678440032 | |||
| 4f95520826 | |||
| 33a271a54c | |||
| 3e3728a089 | |||
| dc8a1b0325 | |||
| 4a6e5f7130 | |||
| 6b78ca3d46 | |||
| 38612253d0 | |||
| 2fccdf4f7e | |||
| 56d48598df | |||
| 4f77da822b | |||
| cf6fd2dad9 | |||
| 6cb1ec82f3 | |||
| 733b9cdfcc | |||
| 4a2860449f | |||
| 6fbea32761 | |||
| 50624b3d75 | |||
| dddbeb2ebd | |||
| 22714a2763 | |||
| bc2c9610ee | |||
| 3dc234321c | |||
| 4a65031aa3 | |||
| 4dd30b29c0 | |||
| ac6211cf5f | |||
| 65a622cd7b | |||
| bba600725e | |||
| 4fa80a2a88 | |||
| 64f52f2c11 | |||
| 72c1b2fb2e | |||
| b4f5328a21 | |||
| 7aee324294 | |||
| 7930e45393 | |||
| 052dc4e5a0 | |||
| 450d2c15f9 | |||
| 7b6ed51ce8 | |||
| 30d99b8d79 | |||
| e6db981d5e | |||
| d4e008380b |
@@ -66,3 +66,7 @@ COMMANDS_V2_ENABLED=false
|
||||
|
||||
STORAGE_FEE_LAUNCH_DATE="2023-12-11 00:00:00"
|
||||
SST_START_DATE="2024-04-01 00:00:00"
|
||||
|
||||
E_INVOICE_START_DATE="2025-07-01 00:00:00"
|
||||
MAINTENANCE_MESSAGE_TITLE="We'll be back online on 00:00 1/7/2025"
|
||||
MAINTENANCE_MESSAGE="Sorry for the inconvenience but we're performing some maintenance at the moment."
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Site Under Maintenance</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
text-align: center;
|
||||
padding: 50px;
|
||||
}
|
||||
.content {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
display: inline-block;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<h1>We'll be back soon!</h1>
|
||||
<p>Sorry for the inconvenience but we're performing some maintenance at the moment. We'll be back online shortly!</p>
|
||||
<p>— CIEF IZYIM</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Vendored
+13
@@ -17,6 +17,9 @@ pipeline {
|
||||
}
|
||||
environment {
|
||||
HOME = '.'
|
||||
DB_CONNECTION = 'mysql'
|
||||
DB_DATABASE = 'portal_development'
|
||||
APP_ENV = 'testing'
|
||||
}
|
||||
stages {
|
||||
stage('Download source code from Git') {
|
||||
@@ -59,6 +62,16 @@ pipeline {
|
||||
stage('Tests') {
|
||||
steps {
|
||||
//sh 'vendor/bin/phpunit tests/Unit'
|
||||
withCredentials([
|
||||
usernamePassword(
|
||||
credentialsId: 'shipping-portal-dev-db-credential',
|
||||
usernameVariable: 'DB_USERNAME',
|
||||
passwordVariable: 'DB_PASSWORD'
|
||||
),
|
||||
string(credentialsId: 'shipping-portal-dev-db-host', variable: 'DB_HOST')
|
||||
]) {
|
||||
// sh 'vendor/bin/phpunit --filter ListOrderTrackingLogicTest'
|
||||
}
|
||||
script{
|
||||
currentBuild.description = 'Step 4 of 6 Completed'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
|
||||
final class CriteriaNotFulfilledException extends ServiceApiException {
|
||||
public function __construct(?string $message = null) {
|
||||
parent::__construct(
|
||||
$message ?? 'One or more required criteria were not fulfilled.',
|
||||
HttpStatus::VALIDATION_FAILED
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class HasParcelWithTransportBetweenDate implements Filter
|
||||
{
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = json_decode($value, true) ?? [];
|
||||
}
|
||||
|
||||
$startDate = Carbon::make(data_get($value, 'start_date'));
|
||||
$endDate = Carbon::make(data_get($value, 'end_date'));
|
||||
|
||||
$start = $startDate ? $startDate->startOfDay() : null;
|
||||
$end = $endDate ? $endDate->endOfDay() : null;
|
||||
|
||||
if (!$start && !$end) return $builder;
|
||||
if ($start && $end && $start->gt($end)) [$start, $end] = [$end, $start];
|
||||
|
||||
return $builder->whereHas('transports', function (Builder $q) use ($start, $end) {
|
||||
if ($start && $end && $start->isSameDay($end)) {
|
||||
return $q->whereDate('drop_date', $start->toDateString());
|
||||
}
|
||||
if ($start && $end) {
|
||||
return $q->whereBetween('drop_date', [$start, $end]);
|
||||
}
|
||||
return $start
|
||||
? $q->where('drop_date', '>=', $start)
|
||||
: $q->where('drop_date', '<=', $end);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OrderTrackingId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('order_tracking_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
+36
-1
@@ -23,10 +23,45 @@ class PackingListLimitOneByTypeOrderedByInvoiceDate implements Filter
|
||||
$join->on('transactions.owner_id', '=', 'packing_lists.id');
|
||||
$join->where('transactions.owner_type', '=', PackingList::class);
|
||||
$join->where('transactions.status', '=', ApprovalStatus::APPROVED);
|
||||
$join->whereNull('transactions.deleted_at');
|
||||
$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');
|
||||
}
|
||||
|
||||
//Original with problem
|
||||
// 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->whereNull('transactions.deleted_at');
|
||||
// $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');
|
||||
|
||||
//Attempt 1
|
||||
// return $builder->with(['transactions' => function ($query) {
|
||||
// $query->where('status', ApprovalStatus::APPROVED)
|
||||
// ->whereNull('deleted_at')
|
||||
// ->whereRaw('(
|
||||
// transactions.type <> 16 OR transactions.id = (
|
||||
// SELECT id FROM transactions AS t2
|
||||
// WHERE t2.owner_id = transactions.owner_id
|
||||
// AND t2.owner_type = ?
|
||||
// AND t2.type = 16
|
||||
// LIMIT 1
|
||||
// )
|
||||
// )', [PackingList::class])
|
||||
// ->orderBy('updated_at', 'DESC');
|
||||
// }]);
|
||||
|
||||
//Attempt 2
|
||||
// return $builder->with(['transactions' => function ($query) {
|
||||
// $query->where('status', ApprovalStatus::APPROVED)
|
||||
// ->where('type', '<>', 16 )
|
||||
// ->whereNull('deleted_at')
|
||||
// ->orderBy('updated_at', 'DESC');
|
||||
// }]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class PackingListOrderedByInvoiceDate implements Filter
|
||||
$join->on('transactions.owner_id', '=', 'packing_lists.id');
|
||||
$join->where('transactions.owner_type', '=', PackingList::class);
|
||||
$join->where('transactions.status', '=', ApprovalStatus::APPROVED);
|
||||
$join->whereNull('transactions.deleted_at');
|
||||
})->orderBy('transactions.updated_at', 'DESC');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TrackingNo implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('tracking_no', $value)
|
||||
->where(function ($query) {
|
||||
$query->whereNotNull('tracking_english')
|
||||
->orWhereNotNull('remark_english');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TypeNotIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotIn('type', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,4 +57,71 @@ class Helper
|
||||
static function deserializeFilters(?string $json): array {
|
||||
return $json !== null ? collect(json_decode($json))->toArray() : [];
|
||||
}
|
||||
|
||||
public static function getLHDNStateCodeByName($name)
|
||||
{
|
||||
$path = resource_path('data/lhdn/StateCodes.json');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$json = file_get_contents($path);
|
||||
$data = json_decode($json, true);
|
||||
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = strtolower(trim($name));
|
||||
|
||||
// Step 1: Try exact match
|
||||
foreach ($data as $item) {
|
||||
if (
|
||||
isset($item['State']) &&
|
||||
strtolower(trim($item['State'])) === $name
|
||||
) {
|
||||
return $item['Code'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Try partial match
|
||||
foreach ($data as $item) {
|
||||
if (
|
||||
isset($item['State']) &&
|
||||
str_contains(strtolower($item['State']), $name)
|
||||
) {
|
||||
return $item['Code'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getLHDNMsicDescriptionByCode($code)
|
||||
{
|
||||
$path = resource_path('data/lhdn/MSICSubCategoryCodes.json');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$json = file_get_contents($path);
|
||||
$data = json_decode($json, true);
|
||||
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($data as $item) {
|
||||
if (
|
||||
isset($item['Code']) &&
|
||||
$item['Code'] === $code
|
||||
) {
|
||||
return $item['Description'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Interfaces;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface KeyValueInterface
|
||||
{
|
||||
|
||||
public function attributesKVP(): morphMany;
|
||||
}
|
||||
@@ -19,7 +19,11 @@ class LogHelper
|
||||
{
|
||||
$envVar = env('LARAVEL_VAPOR_ENABLED');
|
||||
$isLocal = env('VAPOR_ENV') === 'local';
|
||||
Log::info("LogHelper.info: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
if($envVar)
|
||||
{
|
||||
Log::info("Info: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
}
|
||||
|
||||
if ($envVar && !$isLocal) {
|
||||
Log::channel($this->channelName.'_vapor')->info($message);
|
||||
}
|
||||
@@ -32,7 +36,11 @@ class LogHelper
|
||||
{
|
||||
$envVar = env('LARAVEL_VAPOR_ENABLED');
|
||||
$isLocal = env('VAPOR_ENV') === 'local';
|
||||
Log::info("LogHelper.warning: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
if($envVar)
|
||||
{
|
||||
Log::info("Warning: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
}
|
||||
|
||||
if ($envVar && !$isLocal) {
|
||||
Log::channel($this->channelName . '_vapor')->warning($message);
|
||||
} else {
|
||||
@@ -44,7 +52,11 @@ class LogHelper
|
||||
{
|
||||
$envVar = env('LARAVEL_VAPOR_ENABLED');
|
||||
$isLocal = env('VAPOR_ENV') === 'local';
|
||||
Log::info("LogHelper.error: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
if($envVar)
|
||||
{
|
||||
Log::info("Error: {$message}, channelName: {$this->channelName}, envVar {$envVar}");
|
||||
}
|
||||
|
||||
if ($envVar && !$isLocal) {
|
||||
Log::channel($this->channelName . '_vapor')->error($message);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrders;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CheckStorageInvoicesSingleOrderV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $order;
|
||||
|
||||
public function __construct($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Check single order for storage invoice.');
|
||||
$start = new Carbon();
|
||||
|
||||
try{
|
||||
Log::info("Processing Order - ID: {$this->order->id}, Reference: {$this->order->reference}");
|
||||
(App()->make(CheckStorageInvoiceTransactionProcessor::class))->executeOrder($this->order);
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
Log::info('Exception '.$ex->getMessage());
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Check single order for storage invoice. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,12 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\FixInvoiceV2CommandObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\CompanyConnection;
|
||||
use App\Models\Order;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FixInvoiceV2CommandJob implements ShouldQueue
|
||||
@@ -52,29 +48,10 @@ class FixInvoiceV2CommandJob implements ShouldQueue
|
||||
|
||||
dump($invoice->id);
|
||||
|
||||
$invoice->documents()->delete();
|
||||
// $invoice->documents()->delete();
|
||||
$invoice->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->delete();
|
||||
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::SHIPPING_INVOICE,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'shipping_invoice'
|
||||
);
|
||||
|
||||
/** @var Document $document */
|
||||
$document = (App()->make(CreatesDocument::class))->execute($invoice, $document_object);
|
||||
|
||||
(App()->make(CreatesFiles::class))->execute($document, $document_object);
|
||||
(App()->make(CreateShippingInvoiceTransactionDocProcessor::class))->execute($invoice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
||||
use App\Classes\Modules\Documents\Services\ApprovesDocument;
|
||||
use App\Classes\Modules\Documents\Services\RejectsDocument;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Group;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FixPaymentApprovalTimedOutErrorV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Fix payment approval timed out error (status 504: Endpoint request timed out).');
|
||||
$start = new Carbon();
|
||||
|
||||
$status= 'approve';
|
||||
$transactionId = 23160;
|
||||
|
||||
$transaction = (App()->make(FetchesTransaction::class))->execute(['id' => $transactionId]);
|
||||
$document = $transaction->documents()
|
||||
->where('status', ApprovalStatus::PENDING_VERIFICATION)
|
||||
->first();
|
||||
|
||||
Log::info("FixApprovedPaymentFailedGroupV2CommandJob document: ".json_encode($document));
|
||||
|
||||
if($status === 'approve') {
|
||||
// (App()->make(ApprovesDocument::class))->execute($document);
|
||||
$document->status = ApprovalStatus::APPROVED;
|
||||
// $document->approver = Auth()->user()->id;
|
||||
$document->approval_date = Carbon::now();
|
||||
$document->save();
|
||||
}
|
||||
else {
|
||||
(App()->make(RejectsDocument::class))->execute($document);
|
||||
}
|
||||
|
||||
(App()->make(UpdatesTransactionStatus::class))->execute($transaction, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
if ($status === 'approve') {
|
||||
(App()->make(CallbackBillplzProcessor::class))->execute($transaction, ApprovalStatus::APPROVED);
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Fix payment approval timed out error (status 504: Endpoint request timed out). ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Group;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OneTimeFixWalletGroupTransactionV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - This is a one time fix of unsuccessful group payment through wallet.');
|
||||
$start = new Carbon();
|
||||
$invoice_ids = [31493]; //31493
|
||||
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
|
||||
if($invoice->status == ApprovalStatus::APPROVED){
|
||||
$paymentTransaction = (App()->make(CreatePaymentTransactionProcessor::class))->execute($invoice, PaymentMethodType::WALLET, '', false);
|
||||
|
||||
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
$pL = $invoice->owner;
|
||||
(App()->make(ReleaseGoodsToCustomerProcessor::class))->execute($pL, $invoice);
|
||||
}
|
||||
}
|
||||
}
|
||||
$group = Group::where('id', 1569)->first(); //1569
|
||||
$group->status = ApprovalStatus::APPROVED;
|
||||
$group->save();
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - This is a one time fix of unsuccessful group payment through wallet. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
||||
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzDataPatchProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Transaction;
|
||||
@@ -19,26 +20,25 @@ class OneTimeTransactionFixBillplzFailedCbV2CommandJob implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - One time fix failled callback from billplz for transaction with id 17310 cron ended.');
|
||||
Log::info(Carbon::now() . ': Start job - One time fix failled callback from billplz.');
|
||||
$start = new Carbon();
|
||||
|
||||
// ini_set('memory_limit', '-1');
|
||||
|
||||
//Transaction fix with this one time fix command: 15205, 16803, 17310
|
||||
//Transaction fix with this one time fix command: 15205, 16803, 17310, 22008, 6770
|
||||
//This transaction, 16803 has approve payment but not its owner, shipping invoice
|
||||
$transaction = Transaction::whereIn('id', [17310])->first();
|
||||
Log::info(Carbon::now() . ' : One time fix failled callback from billplz for transaction with id 17310 cron started.');
|
||||
$transactions = Transaction::whereIn('id', [22008, 6770])->get();
|
||||
|
||||
if($transaction && $transaction->id == 17310){
|
||||
foreach ($transactions as $transaction){
|
||||
if($transaction){
|
||||
|
||||
Log::info(Carbon::now() . ' : 17310.');
|
||||
$status = ApprovalStatus::APPROVED;
|
||||
// $this->callbackBillplzProcessor->execute($transaction, $status);
|
||||
(App()->make(CallbackBillplzDataPatchProcessor::class))->execute($transaction, $status);
|
||||
Log::info(Carbon::now() . ' : '.$transaction->id);
|
||||
$status = ApprovalStatus::APPROVED;
|
||||
(App()->make(CallbackBillplzProcessor::class))->execute($transaction, $status);
|
||||
// (App()->make(CallbackBillplzDataPatchProcessor::class))->execute($transaction, $status);
|
||||
}
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - One time fix failled callback from billplz for transaction with id 17310 cron ended. ElapsedTime: ' . $elapsedTime . '.');
|
||||
Log::info(Carbon::now() . ': End job - One time fix failled callback from billplz. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Modules\Accounts\Services\UpdatesKeyValuePair;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\KeyValuePair;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ProcessPaymentReportV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var array */
|
||||
private $details;
|
||||
|
||||
/**
|
||||
* ProcessPaymentReportV2CommandJob constructor.
|
||||
* @param array $details
|
||||
*/
|
||||
public function __construct(array $details)
|
||||
{
|
||||
$this->details = $details;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Processing single record from 11R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT] Import.');
|
||||
$start = new Carbon();
|
||||
|
||||
$docNo = $this->details['docno'] ?? null;
|
||||
$docDate = $this->details['docdate'] ?? null;
|
||||
$debtorCode = $this->details['debtorcode'] ?? null;
|
||||
$description = $this->details['description'] ?? null;
|
||||
$paymentMethod = $this->details['paymentmethod'] ?? null;
|
||||
$paymentAmt = $this->details['paymentamt'] ?? null;
|
||||
$knockOffDocNo = $this->details['knockoffdocno'] ?? null;
|
||||
|
||||
Log::info("Processing Payment Report:", [
|
||||
'DocNo' => $docNo,
|
||||
'DocDate' => $docDate,
|
||||
'DebtorCode' => $debtorCode,
|
||||
'Description' => $description,
|
||||
'PaymentMethod' => $paymentMethod,
|
||||
'PaymentAmt' => $paymentAmt,
|
||||
'KnockOffDocNo' => $knockOffDocNo,
|
||||
]);
|
||||
|
||||
if($knockOffDocNo){
|
||||
$kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $knockOffDocNo)->first();
|
||||
if($kvp){
|
||||
$transaction = $kvp->owner;
|
||||
if($transaction){
|
||||
if($docNo != "" && $docNo != "<<New>>"){
|
||||
$this->updateOrCreateKeyValuePair($transaction, KVPKey::AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT, $docNo);
|
||||
}
|
||||
// if($eInvoiceValidationLink){
|
||||
// $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Processing single record from 11R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT] Import. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
|
||||
|
||||
private function updateOrCreateKeyValuePair($booking, $key, $value)
|
||||
{
|
||||
$keyValuePairObject = new KeyValuePairObject($key, $value);
|
||||
$metadata = $booking->attributesKVP()->where('key', $key)->first();
|
||||
|
||||
if ($metadata) {
|
||||
(App()->make(UpdatesKeyValuePair::class))->execute($metadata, $keyValuePairObject);
|
||||
} else {
|
||||
(App()->make(CreatesKeyValuePair::class))->execute($booking, $keyValuePairObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Modules\Accounts\Services\UpdatesKeyValuePair;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Order;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ProcessSalesInvoiceReportV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var array */
|
||||
private $details;
|
||||
|
||||
/**
|
||||
* ProcessSalesInvoiceReportV2CommandJob constructor.
|
||||
* @param array $details
|
||||
*/
|
||||
public function __construct(array $details)
|
||||
{
|
||||
$this->details = $details;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Processing single record for E-Invoice from Sales Invoice Report Import.');
|
||||
$start = new Carbon();
|
||||
|
||||
$docNo = $this->details['docno'] ?? null;
|
||||
$docDate = $this->details['docdate'] ?? null;
|
||||
$debtorCode = $this->details['debtorcode'] ?? null;
|
||||
$ref = $this->details['ref'] ?? null;
|
||||
$shipInfo = $this->details['shipinfo'] ?? null;
|
||||
$accNo = $this->details['accno'] ?? null;
|
||||
$detailDescription = $this->details['detaildescription'] ?? null;
|
||||
$furtherDescription = $this->details['furtherdescription'] ?? null;
|
||||
$classification = $this->details['classification'] ?? null;
|
||||
$projNo = $this->details['projno'] ?? null;
|
||||
$deptNo = $this->details['deptno'] ?? null;
|
||||
$qty = $this->details['qty'] ?? null;
|
||||
$unitPrice = $this->details['unitprice'] ?? null;
|
||||
$taxCode = $this->details['taxcode'] ?? null;
|
||||
$taxableAmt = $this->details['taxableamt'] ?? null;
|
||||
$taxRate = $this->details['taxrate'] ?? null;
|
||||
$submitEinvoice = $this->details['submiteinvoice'] ?? null;
|
||||
$consolidatedEinvoice = $this->details['consolidatedeinvoice'] ?? null;
|
||||
$eInvoiceValidationLink = $this->details['einvoicevalidationlink'] ?? null;
|
||||
|
||||
// Log for debugging
|
||||
Log::info("Processing Sales Invoice Report:", [
|
||||
'DocNo' => $docNo,
|
||||
'DocDate' => $docDate,
|
||||
'DebtorCode' => $debtorCode,
|
||||
'Ref' => $ref,
|
||||
'ShipInfo' => $shipInfo,
|
||||
'AccNo' => $accNo,
|
||||
'DetailDescription' => $detailDescription,
|
||||
'FurtherDescription' => $furtherDescription,
|
||||
'Classification' => $classification,
|
||||
'ProjNo' => $projNo,
|
||||
'DeptNo' => $deptNo,
|
||||
'Qty' => $qty,
|
||||
'UnitPrice' => $unitPrice,
|
||||
'TaxCode' => $taxCode,
|
||||
'TaxableAmt' => $taxableAmt,
|
||||
'TaxRate' => $taxRate,
|
||||
'SubmitEinvoice' => $submitEinvoice,
|
||||
'ConsolidatedEinvoice' => $consolidatedEinvoice,
|
||||
'EInvoiceValidationLink' => $eInvoiceValidationLink,
|
||||
]);
|
||||
|
||||
|
||||
// $order = Order::where('reference', $ref)->first();
|
||||
// $transactions = $order->transactions()->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get();
|
||||
// $matchedTransaction = null;
|
||||
// foreach ($transactions as $transaction) {
|
||||
// $transactionDetails = $transaction->transactionDetails;
|
||||
// foreach ($transactionDetails as $detail) {
|
||||
// $detailName = str_replace('<br>', ' ', $detail->name);
|
||||
// if (
|
||||
// $detailName === $furtherDescription &&
|
||||
// $detail->quantity == $qty &&
|
||||
// $detail->price == $unitPrice
|
||||
// ) {
|
||||
// $matchedTransaction = $transaction;
|
||||
// break 2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
$matchedTransaction = Transaction::where('bill_no', $ref)->first();
|
||||
if($matchedTransaction){
|
||||
if($docNo != "" && $docNo != "<<New>>"){
|
||||
$this->updateOrCreateKeyValuePair($matchedTransaction, KVPKey::AUTOCOUNT_DOCNO_INVOICE, $docNo);
|
||||
}
|
||||
if($eInvoiceValidationLink){
|
||||
$this->updateOrCreateKeyValuePair($matchedTransaction, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
|
||||
}
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Processing single record for E-Invoice from Sales Invoice Report Import. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
|
||||
|
||||
private function updateOrCreateKeyValuePair($booking, $key, $value)
|
||||
{
|
||||
$keyValuePairObject = new KeyValuePairObject($key, $value);
|
||||
$metadata = $booking->attributesKVP()->where('key', $key)->first();
|
||||
|
||||
if ($metadata) {
|
||||
(App()->make(UpdatesKeyValuePair::class))->execute($metadata, $keyValuePairObject);
|
||||
} else {
|
||||
(App()->make(CreatesKeyValuePair::class))->execute($booking, $keyValuePairObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingEInvoiceDocProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateStorageEInvoiceDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ProcessTransactionForEInvoiceV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var Transaction */
|
||||
private $transaction;
|
||||
|
||||
/**
|
||||
* ProcessTransactionForEInvoiceV2CommandJob constructor.
|
||||
* @param Transaction $transaction
|
||||
*/
|
||||
public function __construct(Transaction $transaction)
|
||||
{
|
||||
$this->transaction = $transaction;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Processing single transaction for E-Invoice.');
|
||||
$start = new Carbon();
|
||||
|
||||
$isGenerated = false;
|
||||
$companyModule = $this->transaction->owner->owner->companyModule;
|
||||
if($companyModule->company->e_invoice === 1){
|
||||
$document = $this->transaction->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->first();
|
||||
$kvp = $this->transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if(!$document && $kvp && $this->transaction->type == TransactionType::SHIPPING_INVOICE){
|
||||
(App()->make(CreateShippingEInvoiceDocProcessor::class))->execute($this->transaction);
|
||||
$isGenerated = true;
|
||||
}
|
||||
else {
|
||||
$document2 = $this->transaction->documents()->where('document_type', DocumentType::STORAGE_EINVOICE)->first();
|
||||
$kvp2 = $this->transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if(!$document2 && $kvp2 && $this->transaction->type == TransactionType::STORAGE_INVOICE){
|
||||
(App()->make(CreateStorageEInvoiceDocProcessor::class))->execute($this->transaction);
|
||||
$isGenerated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$isGenerated){
|
||||
Log::info("NO E-Invoice generated for transaction with id: " . $this->transaction->id . ', order: ' . $this->transaction->owner->owner->reference );
|
||||
}
|
||||
else{
|
||||
Log::info("E-Invoice generated for transaction with id: " . $this->transaction->id . ', order: ' . $this->transaction->owner->owner->reference );
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Processing single transaction for E-Invoice. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrders;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ReleaseGoodsToCustomerV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $invoice;
|
||||
|
||||
public function __construct($invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Release goods to customer.');
|
||||
$start = new Carbon();
|
||||
|
||||
try{
|
||||
$obj = json_encode($this->invoice);
|
||||
Log::info("Processing Order - ID: {$this->invoice->id}, invoice: {$obj}");
|
||||
$pL = $this->invoice->owner;
|
||||
(App()->make(ReleaseGoodsToCustomerProcessor::class))->execute($pL, $this->invoice);
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
Log::info('Exception '.$ex->getMessage());
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Release goods to customer. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2\YD;
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\V2\FetchByTrakingNoYdPortalV2Processor;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchTrakingInfoYDByPackingListV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $packingList;
|
||||
|
||||
public function __construct(PackingList $packingList)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Processing FetchTrakingInfoYDByPackingListV2CommandJob');
|
||||
$processor = app(FetchByTrakingNoYdPortalV2Processor::class);
|
||||
$processor->execute($this->packingList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2\YD;
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\V2\FetchByTrakingNoYdPortalV2Processor;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchTrakingInfoYDByTrackingNoV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $trackingNo;
|
||||
|
||||
public function __construct(string $trackingNo)
|
||||
{
|
||||
$this->trackingNo = $trackingNo;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Processing FetchTrakingInfoYDByTrackingNoV2CommandJob');
|
||||
$processor = app(FetchByTrakingNoYdPortalV2Processor::class);
|
||||
$processor->processTrackingNo($this->trackingNo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2\YD;
|
||||
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class ProcessYDByTrakingNoDataV2Job implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $trackingNo;
|
||||
|
||||
public function __construct($trackingNo)
|
||||
{
|
||||
$this->trackingNo = $trackingNo;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Artisan::call('process-yd-by-traking-no-data-command', [
|
||||
'trackingNo' => $this->trackingNo
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2\YD;
|
||||
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class ProcessYDPortalDataV2Job implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $start;
|
||||
protected $end;
|
||||
|
||||
public function __construct($start, $end)
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Artisan::call('process-yd-portal-data-command', [
|
||||
'start_date' => $this->start,
|
||||
'end_date' => $this->end
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V3\YD;
|
||||
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\V3\FetchContainersUpdatesYdPortalV3Processor;
|
||||
use App\Models\Container;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchContainersUpdatesYdPortalV3CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Processing FetchContainersUpdatesYdPortalV3CommandJob');
|
||||
$processor = app(FetchContainersUpdatesYdPortalV3Processor::class);
|
||||
$processor->execute($this->container);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V3\YD;
|
||||
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\V3\FetchContainersYdPortalV3Processor;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchContainersYdPortalV3CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $packingList;
|
||||
|
||||
public function __construct(PackingList $packingList)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Processing FetchContainersYdPortalV3CommandJob');
|
||||
$processor = app(FetchContainersYdPortalV3Processor::class);
|
||||
$processor->execute($this->packingList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class KeyValuePairObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $key;
|
||||
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
|
||||
/**
|
||||
* KeyValuePairObject constructor.
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function __construct(string $key, string $value)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\General\Interfaces\KeyValueInterface;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class CreatesKeyValuePair extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param KeyValueInterface $kv
|
||||
* @param KeyValuePairObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
|
||||
public function execute(KeyValueInterface $kv, KeyValuePairObject $object) {
|
||||
$model = new KeyValuePair();
|
||||
$model->key = $object->getKey();
|
||||
$model->value = $object->getValue();
|
||||
|
||||
return $this->handler($kv->attributesKVP(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class DeletesKeyValuePair extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param KeyValuePair $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(KeyValuePair $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class UpdatesKeyValuePair extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param KeyValuePair $model
|
||||
* @param KeyValuePairObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(KeyValuePair $model, KeyValuePairObject $object) {
|
||||
$model->key = $object->getKey();
|
||||
$model->value = $object->getValue();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,10 @@ use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
||||
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
|
||||
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RemarkTypes;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Models\Address;
|
||||
use Carbon\Carbon;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -100,6 +102,24 @@ class CreateAddressLogic extends AbstractControllerLogic
|
||||
$this->createRemarkProcessor->execute($address, $remarkObject);
|
||||
}
|
||||
|
||||
if ($request->input('pickup_time_to') <= $request->input('pickup_time_from')) {
|
||||
$pickupTimeFrom = Carbon::parse($request->input('pickup_time_from'));
|
||||
$request->merge([
|
||||
'pickup_time_to' => $pickupTimeFrom->addHour()->format('H:i') // Format to hh:mm
|
||||
]);
|
||||
}
|
||||
|
||||
$addressExtraFields = [
|
||||
'property_type' => $request->input('property_type'),
|
||||
'receive_goods_working_hours' => $request->input('receive_goods_working_hours'),
|
||||
'receive_goods_after_hours' => $request->input('receive_goods_after_hours'),
|
||||
'receive_goods_on_saturday' => $request->input('receive_goods_on_saturday'),
|
||||
];
|
||||
|
||||
$address->addressExtraFields()->delete();
|
||||
$addressExtraFieldsObject = new RemarkObject(json_encode($addressExtraFields), Auth()->user()->id, RemarkTypes::ADDRESS_EXTRA_COLUMNS);
|
||||
$remark = $this->createRemarkProcessor->execute($address, $addressExtraFieldsObject);
|
||||
|
||||
return $this->resourceResponse(new AddressResource($address));
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\AccessForbiddenException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\CreatesAddress;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
@@ -11,6 +11,7 @@ use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Models\Address;
|
||||
use App\Models\CompanyModule;
|
||||
@@ -67,7 +68,15 @@ class CreateBillingAddressLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
|
||||
|
||||
|
||||
//cief todo: 90 - move this into canCreateAddress
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (!in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
if($companyModule->company->e_invoice === 1){
|
||||
throw new AccessForbiddenException('Update of billing address not allowed.');
|
||||
}
|
||||
}
|
||||
|
||||
$address = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]);
|
||||
|
||||
if ($address->type !== AddressType::BILLING || $address->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) {
|
||||
@@ -83,4 +92,4 @@ class CreateBillingAddressLogic extends AbstractControllerLogic
|
||||
return $this->resourceResponse(new AddressResource($address));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\ListsAddresses;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -51,13 +52,12 @@ class ListAddressesLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$this->canListAddresses->passes();
|
||||
|
||||
$query = $this->listsAddresses->execute($this->listsAddresses->deserializeFilters($request->input('filters')));
|
||||
//$query = $this->listsAddresses->execute($this->listsAddresses->deserializeFilters($request->input('filters')));
|
||||
$query = $this->listsAddresses->execute(array_merge($this->listsAddresses->deserializeFilters($request->input('filters')), ['type_not_in' => [AddressType::E_INVOICE]]));
|
||||
|
||||
return $this->collectionResponse(AddressResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class AddressObject implements DataTransferObject
|
||||
/** @var int */
|
||||
private $districtId;
|
||||
|
||||
/** @var int */
|
||||
/** @var string */
|
||||
private $postCode;
|
||||
|
||||
/** @var int */
|
||||
@@ -42,12 +42,12 @@ class AddressObject implements DataTransferObject
|
||||
* @param int $countryId
|
||||
* @param int $stateId
|
||||
* @param int $districtId
|
||||
* @param int $postCode
|
||||
* @param string $postCode
|
||||
* @param int $type
|
||||
* @param int $status
|
||||
* @param null|string $reference
|
||||
*/
|
||||
public function __construct(string $streetOne, ?string $streetTwo, int $countryId, int $stateId, int $districtId, int $postCode, int $type, int $status, ?string $reference = null)
|
||||
public function __construct(string $streetOne, ?string $streetTwo, int $countryId, int $stateId, int $districtId, string $postCode, int $type, int $status, ?string $reference = null)
|
||||
{
|
||||
$this->streetOne = $streetOne;
|
||||
$this->streetTwo = $streetTwo;
|
||||
@@ -101,9 +101,9 @@ class AddressObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getPostCode(): int
|
||||
public function getPostCode(): string
|
||||
{
|
||||
return $this->postCode;
|
||||
}
|
||||
@@ -133,4 +133,4 @@ class AddressObject implements DataTransferObject
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\General\Interfaces\Addressable;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Models\Address;
|
||||
use App\Models\CompanyModule;
|
||||
|
||||
class UpsertsAddress extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* Create or update the company's address.
|
||||
*
|
||||
* @param Addressable $addressable
|
||||
* @param AddressObject $object
|
||||
* @param int $id
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Addressable $addressable, AddressObject $object, int $id)
|
||||
{
|
||||
//Create new or update?
|
||||
$model = $addressable->addresses()->where('id', $id)->first() ?? new Address();
|
||||
|
||||
$model->reference = $object->getReference();
|
||||
$model->street_one = $object->getStreetOne();
|
||||
$model->street_two = $object->getStreetTwo();
|
||||
$model->country_id = $object->getCountryId();
|
||||
$model->state_id = $object->getStateId();
|
||||
$model->district_id = $object->getDistrictId();
|
||||
$model->postcode = $object->getPostCode();
|
||||
$model->status = $object->getStatus();
|
||||
$model->type = $object->getType();
|
||||
|
||||
return $this->handler($addressable->addresses(), $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Anthropic\Services;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\ConnectionErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatesClaudeResponse
|
||||
{
|
||||
/**
|
||||
* @param string $userPrompt
|
||||
* @param string $model
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $userPrompt, string $model = "") {
|
||||
try {
|
||||
$content = [];
|
||||
|
||||
$content[] = [
|
||||
'type' => 'text',
|
||||
'text' => $userPrompt,
|
||||
];
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'x-api-key' => config('anthropic.api_key'),
|
||||
'anthropic-version' => config('anthropic.api_version', '2023-06-01'),
|
||||
'Content-Type' => 'application/json',
|
||||
])->post(config('anthropic.base_url') . '/v1/messages', [
|
||||
'model' => config('anthropic.default_model', 'claude-sonnet-4-5-20250929'),
|
||||
'max_tokens' => 8192,
|
||||
'messages' => [
|
||||
[
|
||||
'role' => 'user',
|
||||
'content' => $content,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
} else {
|
||||
Log::info('CreatesClaudeResponse error: ' . $response->body());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (\Illuminate\Http\Client\ConnectionException $exception) {
|
||||
Log::info('ConnectionException' . json_encode($exception));
|
||||
throw new ConnectionErrorException(
|
||||
'Failed to connect to Claude API',
|
||||
$exception->getMessage(),
|
||||
$userPrompt,
|
||||
$exception->getTraceAsString()
|
||||
);
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
Log::info('Exception' . json_encode($exception));
|
||||
throw new MalformedRequestException(
|
||||
'Unable to get correct response from Claude API: ' . $exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Anthropic\Services;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\ConnectionErrorException;
|
||||
|
||||
class CreatesClaudeResponseWithFiles
|
||||
{
|
||||
public function execute(string $userPrompt, array $fileIds)
|
||||
{
|
||||
try {
|
||||
$content = [];
|
||||
|
||||
// User prompt
|
||||
$content[] = [
|
||||
'type' => 'text',
|
||||
'text' => $userPrompt,
|
||||
];
|
||||
|
||||
// Attach files
|
||||
foreach ($fileIds as $fileId) {
|
||||
$content[] = [
|
||||
'type' => 'document',
|
||||
'source' => [
|
||||
'type' => 'file',
|
||||
'file_id' => $fileId,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'x-api-key' => config('anthropic.api_key'),
|
||||
'anthropic-version' => config('anthropic.api_version', '2023-06-01'),
|
||||
'anthropic-beta' => 'files-api-2025-04-14',
|
||||
'Content-Type' => 'application/json',
|
||||
])->post(config('anthropic.base_url') . '/v1/messages', [
|
||||
'model' => config('anthropic.default_model', 'claude-sonnet-4-5-20250929'),
|
||||
'max_tokens' => 16384,
|
||||
'messages' => [
|
||||
[
|
||||
'role' => 'user',
|
||||
'content' => $content,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
catch (\Illuminate\Http\Client\ConnectionException $exception) {
|
||||
$error = 'Failed to connect to Claude API';
|
||||
throw new ConnectionErrorException(
|
||||
$error,
|
||||
$exception->getMessage(),
|
||||
$userPrompt,
|
||||
$exception->getTraceAsString()
|
||||
);
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
throw new MalformedRequestException(
|
||||
'Unable to get correct response from Claude API: ' . $exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Anthropic\Services;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\ConnectionErrorException;
|
||||
|
||||
class UploadsClaudeFiles
|
||||
{
|
||||
public function execute(array $paths): array
|
||||
{
|
||||
try {
|
||||
$ids = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$response = Http::withHeaders([
|
||||
'x-api-key' => config('anthropic.api_key'),
|
||||
'anthropic-version' => '2023-06-01',
|
||||
'anthropic-beta' => 'files-api-2025-04-14',
|
||||
])->attach(
|
||||
'file',
|
||||
fopen($path, 'r'),
|
||||
basename($path)
|
||||
)->post(config('anthropic.base_url') . '/v1/files');
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if ($response->successful() && isset($data['id'])) {
|
||||
$ids[] = $data['id'];
|
||||
} else {
|
||||
Log::error('Claude file upload failed', [
|
||||
'path' => $path,
|
||||
'response' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
catch (\Illuminate\Http\Client\ConnectionException $exception) {
|
||||
$error = 'Failed to connect to Claude API';
|
||||
throw new ConnectionErrorException(
|
||||
$error,
|
||||
$exception->getMessage(),
|
||||
$exception->getTraceAsString()
|
||||
);
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
throw new MalformedRequestException(
|
||||
'Unable to get correct response from Claude API: ' . $exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,14 +88,14 @@ class CallbackBillplzDataPatchProcessor
|
||||
$invoice = $groupTransaction->transaction;
|
||||
Log::info('CallbackBillplzDataPatchProcessor 3: '.json_encode($invoice));
|
||||
|
||||
//if($invoice->status !== ApprovalStatus::COMPLETED){
|
||||
// $paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null, false);
|
||||
if($invoice->status !== ApprovalStatus::COMPLETED){
|
||||
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null, false);
|
||||
|
||||
// if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
$pL = $invoice->owner;
|
||||
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice, true);
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
|
||||
+33
-30
@@ -8,15 +8,12 @@ use App\Classes\Modules\Documents\Standards\Rules\CanApproveDocument;
|
||||
use App\Classes\Modules\Orders\Services\UpdatesOrdersStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
||||
|
||||
use App\Classes\Modules\Documents\Services\ApprovesDocument;
|
||||
use App\Classes\Modules\Documents\Services\PendingVerificationDocument;
|
||||
use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
|
||||
Use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor;
|
||||
|
||||
use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -27,10 +24,11 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Approve Document',
|
||||
'message' => 'You have successfully approved the Document'
|
||||
'title' => 'Update Document Status',
|
||||
'message' => 'You have successfully updated the Document Status'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,6 +41,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
/** @var RejectsDocument */
|
||||
private $rejectsDocument;
|
||||
|
||||
/** @var PendingVerificationDocument */
|
||||
private $pendingVerificationDocument;
|
||||
|
||||
/** @var FetchesDocument */
|
||||
private $fetchesDocument;
|
||||
|
||||
@@ -61,11 +62,12 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
* @param ApprovesDocument $approvesDocument
|
||||
* @param RejectsDocument $rejectsDocument
|
||||
* @param FetchesDocument $fetchesDocument
|
||||
* @param PendingVerificationDocument $pendingVerificationDocument
|
||||
* @param UpdatesCompanyStatus $updatesCompanyStatus
|
||||
* @param UpdatesOrdersStatus $updatesOrdersStatus
|
||||
* @param CreateNotificationProcessor $createNotificationProcessor
|
||||
*/
|
||||
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, UpdatesOrdersStatus $updatesOrdersStatus, CreateNotificationProcessor $createNotificationProcessor)
|
||||
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, UpdatesOrdersStatus $updatesOrdersStatus, CreateNotificationProcessor $createNotificationProcessor, PendingVerificationDocument $pendingVerificationDocument)
|
||||
{
|
||||
$this->canApproveDocument = $canApproveDocument;
|
||||
$this->approvesDocument = $approvesDocument;
|
||||
@@ -74,6 +76,7 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
$this->updatesCompanyStatus = $updatesCompanyStatus;
|
||||
$this->updatesOrdersStatus = $updatesOrdersStatus;
|
||||
$this->createNotificationProcessor = $createNotificationProcessor;
|
||||
$this->pendingVerificationDocument = $pendingVerificationDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,37 +86,37 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
$status = $request->route('status');
|
||||
|
||||
/** @var Document $document */
|
||||
$document = $this->fetchesDocument->execute(['id' => $request->route('document_id')]);
|
||||
|
||||
$this->canApproveDocument->passes();
|
||||
|
||||
$document = $status === 'approve' ? $this->approvesDocument->execute($document) : $this->rejectsDocument->execute($document);
|
||||
|
||||
$this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
// $object = new NotificationObject(
|
||||
// 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ),
|
||||
// ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ),
|
||||
// $document->owner,
|
||||
// $document->owner->companyModules()->first()->employees()->first(),
|
||||
// $document,
|
||||
// );
|
||||
//
|
||||
// $this->createNotificationProcessor->execute($object);
|
||||
|
||||
if($status === 'approve'){
|
||||
$orders = $this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED);
|
||||
if ($status === 'approve') {
|
||||
$document = $this->approvesDocument->execute($document);
|
||||
$this->updatesCompanyStatus->execute($document->owner, ApprovalStatus::APPROVED);
|
||||
$this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED);
|
||||
} elseif ($status === 'reject') {
|
||||
$document = $this->rejectsDocument->execute($document);
|
||||
$this->updatesCompanyStatus->execute($document->owner, ApprovalStatus::REJECTED);
|
||||
} elseif ($status === 'pending') {
|
||||
$document = $this->pendingVerificationDocument->execute($document);
|
||||
$this->updatesCompanyStatus->execute($document->owner, ApprovalStatus::PENDING_VERIFICATION);
|
||||
}
|
||||
|
||||
// $object = new NotificationObject(
|
||||
// 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ),
|
||||
// ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ),
|
||||
// $document->owner,
|
||||
// $document->owner->companyModules()->first()->employees()->first(),
|
||||
// $document,
|
||||
// );
|
||||
|
||||
// $this->createNotificationProcessor->execute($object);
|
||||
|
||||
return $this->resourceResponse(new DocumentResource($document));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Contacts\Services\CreatesContact;
|
||||
use App\Http\Resources\ContactResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
|
||||
class CreateCompanyContactNumberLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Company Contact Number',
|
||||
'message' => 'You have successfully created the Company Contact Number'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CreatesContact */
|
||||
private $createsContact;
|
||||
|
||||
/** @var CreateContactProcessor */
|
||||
private $createContactProcessor;
|
||||
|
||||
/**
|
||||
* UpdateCompanyControllersLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesContact $createsContact
|
||||
* @param CreateContactProcessor $createContactProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, CreatesContact $createsContact, CreateContactProcessor $createContactProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsContact = $createsContact;
|
||||
$this->createContactProcessor = $createContactProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('companyId')]);
|
||||
|
||||
$contact = new ContactObject(
|
||||
$company->reference,
|
||||
$request->input('contactNumber'),
|
||||
$company->email,
|
||||
$company->wechat_id
|
||||
);
|
||||
|
||||
$this->createContactProcessor->execute($contact, $company);
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($company));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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\Standards\Rules\CanFetchCompany;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Http\Resources\EInvoiceInfoResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchCompanyEInvoiceInfoLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Company E-Invoice Info',
|
||||
'message' => 'You have successfully retrieved a Company E-Invoice Info'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchCompany */
|
||||
private $canFetchCompany;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/**
|
||||
* FetchCompanyEInvoiceInfoLogic constructor.
|
||||
* @param CanFetchCompany $canFetchCompany
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
*/
|
||||
public function __construct(CanFetchCompany $canFetchCompany, FetchesCompany $fetchesCompany)
|
||||
{
|
||||
$this->canFetchCompany = $canFetchCompany;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchCompany->passes();
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
$eInvoiceInfo = $company->companyModules()->first()->addresses()->where('type', '=', AddressType::E_INVOICE)->latest()->first();
|
||||
|
||||
if($eInvoiceInfo){
|
||||
$eInvoiceInfo->tin = $company->tin;
|
||||
$eInvoiceInfo->msic_code = $company->msic_code;
|
||||
$eInvoiceInfo->e_invoice = $company->e_invoice;
|
||||
}
|
||||
else{
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new EInvoiceInfoResource($eInvoiceInfo));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\Contacts\Services\FetchesContact;
|
||||
use App\Classes\Modules\Contacts\Services\UpdatesContact;
|
||||
use App\Http\Resources\ContactResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCompanyContactNumberLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Company Contact Number',
|
||||
'message' => 'You have successfully updated the Company Contact Number'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesContact */
|
||||
private $fetchesContact;
|
||||
|
||||
/** @var UpdatesContact */
|
||||
private $updatesContact;
|
||||
|
||||
/**
|
||||
* UpdateCompanyControllersLogic constructor.
|
||||
* @param FetchesContact $fetchesContact
|
||||
* @param UpdatesContact $updatesContact
|
||||
*/
|
||||
public function __construct(FetchesContact $fetchesContact, UpdatesContact $updatesContact)
|
||||
{
|
||||
$this->fetchesContact = $fetchesContact;
|
||||
$this->updatesContact = $updatesContact;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->fetchesContact->execute(['id' => $request->input('id')]);
|
||||
|
||||
$contact = new ContactObject(
|
||||
$query->reference,
|
||||
$request->input('contactNumber'),
|
||||
$query->email,
|
||||
$query->wechat_id
|
||||
);
|
||||
|
||||
$this->updatesContact->execute($query, $contact);
|
||||
|
||||
return $this->resourceResponse(new ContactResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?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\UpdatesCompany;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyDebtor;
|
||||
use App\Classes\Modules\Addresses\Services\UpsertsAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyModuleName;
|
||||
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
||||
use App\Classes\Modules\Documents\Services\UpdatesDocumentReference;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceInfo;
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompany;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\UpdateCompanyDetailsDTO;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Company Details',
|
||||
'message' => 'You have successfully updated the Company Details'
|
||||
];
|
||||
}
|
||||
/** @var CanUpdateCompany */
|
||||
private $canUpdateCompany;
|
||||
|
||||
/** @var UpdatesCompany */
|
||||
private $updatesCompany;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var UpdatesCompanyDebtor */
|
||||
private $updatesCompanyDebtor;
|
||||
|
||||
/** @var CanCreateAddress */
|
||||
private $canCreateAddress;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var UpsertsAddress */
|
||||
private $upsertsAddress;
|
||||
|
||||
/** @var UpdatesCompanyEInvoiceInfo */
|
||||
private $updatesCompanyEInvoiceInfo;
|
||||
|
||||
/** @var UpdatesCompanyModuleName */
|
||||
private $updatesCompanyModuleName;
|
||||
|
||||
/** @var FetchesDocument */
|
||||
private $fetchesDocument;
|
||||
|
||||
/** @var UpdatesDocumentReference */
|
||||
private $updatesDocumentReference;
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFile;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateCompanyDetailsLogic constructor.
|
||||
* @param CanUpdateCompany $canUpdateCompany
|
||||
* @param UpdatesCompany $updatesCompany
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param UpdatesCompanyDebtor $updatesCompanyDebtor
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param UpsertsAddress $upsertsAddress
|
||||
* @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo;
|
||||
* @param FetchesDocument $fetchesDocument
|
||||
* @param UpdatesDocumentReference $updatesDocumentReference
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFile
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateCompany $canUpdateCompany,
|
||||
UpdatesCompany $updatesCompany,
|
||||
FetchesCompany $fetchesCompany,
|
||||
UpdatesCompanyDebtor $updatesCompanyDebtor,
|
||||
CanCreateAddress $canCreateAddress,
|
||||
FetchesDistrict $fetchesDistrict,
|
||||
UpsertsAddress $upsertsAddress,
|
||||
UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo,
|
||||
UpdatesCompanyModuleName $updatesCompanyModuleName,
|
||||
FetchesDocument $fetchesDocument,
|
||||
UpdatesDocumentReference $updatesDocumentReference,
|
||||
CreatesDocument $createsDocument,
|
||||
CreatesFiles $createsFile
|
||||
)
|
||||
{
|
||||
$this->canUpdateCompany = $canUpdateCompany;
|
||||
$this->updatesCompany = $updatesCompany;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->updatesCompanyDebtor = $updatesCompanyDebtor;
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->upsertsAddress = $upsertsAddress;
|
||||
$this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo;
|
||||
$this->updatesCompanyModuleName = $updatesCompanyModuleName;
|
||||
$this->fetchesDocument = $fetchesDocument;
|
||||
$this->updatesDocumentReference = $updatesDocumentReference;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFile = $createsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$dto = new UpdateCompanyDetailsDTO($request->all());
|
||||
$object = new CompanyObject($dto->name, $dto->reference, $dto->type);
|
||||
|
||||
$this->canUpdateCompany->passes($object);
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->updatesCompanyModuleName->execute($company->companyModules()->first(), $object->getName());
|
||||
|
||||
//Update Name and Debtor, Type
|
||||
$company = $this->updatesCompany->execute($company, $object);
|
||||
|
||||
if ($request->input('debtor') || $company->first()->debtor !== null) {
|
||||
$this->updatesCompanyDebtor->execute($company, $request->input('debtor'));
|
||||
}
|
||||
|
||||
//Update EInvoice Related Info
|
||||
if($company->e_invoice){
|
||||
$district = $this->fetchesDistrict->execute(['id' => $dto->districtId]);
|
||||
$addObj = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode, AddressType::E_INVOICE, ApprovalStatus::APPROVED, 'E-Invoice');
|
||||
|
||||
$this->canCreateAddress->passes($addObj);
|
||||
|
||||
$this->upsertsAddress->execute($company->companyModules()->first(), $addObj, $dto->addressId);
|
||||
$this->updatesCompanyEInvoiceInfo->execute($company, $dto->tin, $dto->msicCode);
|
||||
}
|
||||
|
||||
//Update Identification Card / SSM Registration
|
||||
if($dto->identificationId){
|
||||
$document = $this->fetchesDocument->execute(['id' => $dto->identificationId]);
|
||||
$this->updatesDocumentReference->execute($document, $dto->identificationReference);
|
||||
}
|
||||
else{
|
||||
if($dto->identificationReference){
|
||||
$pathToFile = base_path('resources/assets/images/ssm_ic_placeholder.png');
|
||||
$mimeType = mime_content_type($pathToFile);
|
||||
$fileContents = file_get_contents($pathToFile);
|
||||
$base64 = base64_encode($fileContents);
|
||||
$base64File = "data:$mimeType;base64,$base64";
|
||||
$files = [$base64File];
|
||||
|
||||
/** @var Document $document */
|
||||
$company = $this->fetchesCompany->execute(['id' => $dto->id]);
|
||||
|
||||
$object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ?
|
||||
DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $files,
|
||||
$dto->identificationReference, ApprovalStatus::PENDING_VERIFICATION, 'identifications');
|
||||
|
||||
$document = $this->createsDocument->execute($company, $object);
|
||||
$this->createsFile->execute($document, $object);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($company));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\CriteriaNotFulfilledException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\CreatesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceInfo;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceInfoDTO;
|
||||
use App\Classes\Modules\Rules\Services\RuleEvaluator;
|
||||
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCompanyEInvoiceInfoLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'EInvoice Info Update',
|
||||
'message' => 'You have successfully updated company E-Invoice information'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateAddress */
|
||||
private $canCreateAddress;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var CreatesAddress */
|
||||
private $createsAddress;
|
||||
|
||||
/** @var RuleEvaluator */
|
||||
private $ruleEvaluator;
|
||||
|
||||
/** @var UpdatesCompanyEInvoiceInfo */
|
||||
private $updatesCompanyEInvoiceInfo;
|
||||
|
||||
/** @var CanPassEInvoicePromptedRule */
|
||||
private $canPassEInvoicePromptedRule;
|
||||
|
||||
/**
|
||||
* UpdateCompanyEInvoiceInfoLogic constructor.
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param CreatesAddress $createsAddress
|
||||
* @param RuleEvaluator $ruleEvaluator;
|
||||
* @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo;
|
||||
* @param CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule
|
||||
*/
|
||||
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompanyModule $fetchesCompanyModule, CreatesAddress $createsAddress, RuleEvaluator $ruleEvaluator, UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo, CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule)
|
||||
{
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->createsAddress = $createsAddress;
|
||||
$this->ruleEvaluator = $ruleEvaluator;
|
||||
$this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo;
|
||||
$this->canPassEInvoicePromptedRule = $canPassEInvoicePromptedRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
* @throws \App\Classes\Exceptions\CriteriaNotFulfilledException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$dto = new EInvoiceInfoDTO($request->all());
|
||||
$result = $this->ruleEvaluator->evaluate([
|
||||
$this->canPassEInvoicePromptedRule,
|
||||
], $dto);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new CriteriaNotFulfilledException("- " . implode("<br>- ", $result->messages()));
|
||||
}
|
||||
|
||||
$district = $this->fetchesDistrict->execute(['id' => $dto->districtId]);
|
||||
$object = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode, AddressType::E_INVOICE, ApprovalStatus::APPROVED, 'E-Invoice');
|
||||
|
||||
//Update Address
|
||||
$this->canCreateAddress->passes($object);
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $dto->companyModuleId]);
|
||||
$this->createsAddress->execute($companyModule, $object);
|
||||
|
||||
// create billing address if not exists
|
||||
$billingAddress = $companyModule->addresses->where('type', AddressType::BILLING)->where('status', ApprovalStatus::APPROVED)->first();
|
||||
if (!$billingAddress) {
|
||||
$billingAddress = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode, AddressType::BILLING, ApprovalStatus::APPROVED, 'Billing Address');
|
||||
$this->createsAddress->execute($companyModule, $billingAddress);
|
||||
}
|
||||
|
||||
//Update tin, msic code
|
||||
$this->updatesCompanyEInvoiceInfo->execute($companyModule->company, $dto->tin, $dto->msicCode);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceRequest;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceRequestDTO;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCompanyEInvoiceRequestChangeLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated EInvoice Request',
|
||||
'message' => 'You have successfully updated company E-Invoice request'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var UpdatesCompanyEInvoiceRequest */
|
||||
private $updatesCompanyEInvoiceRequest;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateCompanyEInvoiceRequestChangeLogic constructor.
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest
|
||||
*/
|
||||
public function __construct(FetchesCompanyModule $fetchesCompanyModule, UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest)
|
||||
{
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->updatesCompanyEInvoiceRequest = $updatesCompanyEInvoiceRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$dto = new EInvoiceRequestDTO($request->all());
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $dto->companyModuleId]);
|
||||
|
||||
if($companyModule->company->e_invoice === 1){
|
||||
$this->updatesCompanyEInvoiceRequest->execute($companyModule->company, $dto->eInvoiceRequest);
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceRequest;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceRequestDTO;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCompanyEInvoiceRequestLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated EInvoice Request',
|
||||
'message' => 'You have successfully updated company E-Invoice request'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var UpdatesCompanyEInvoiceRequest */
|
||||
private $updatesCompanyEInvoiceRequest;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateCompanyEInvoiceRequestLogic constructor.
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest
|
||||
*/
|
||||
public function __construct(FetchesCompanyModule $fetchesCompanyModule, UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest)
|
||||
{
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->updatesCompanyEInvoiceRequest = $updatesCompanyEInvoiceRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$dto = new EInvoiceRequestDTO($request->all());
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $dto->companyModuleId]);
|
||||
$this->updatesCompanyEInvoiceRequest->execute($companyModule->company, $dto->eInvoiceRequest);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class EInvoiceInfoDTO implements DataTransferObject
|
||||
{
|
||||
public string $tin;
|
||||
public string $msicCode;
|
||||
public int $districtId;
|
||||
public int $stateId;
|
||||
public int $companyModuleId;
|
||||
public string $streetOne;
|
||||
public string $streetTwo;
|
||||
public string $postCode;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->tin = (string) ($data['tin'] ?? '');
|
||||
$this->msicCode = (string) ($data['msic_code'] ?? '');
|
||||
$this->districtId = (int) ($data['district_id'] ?? 0);
|
||||
$this->stateId = (int) ($data['state_id'] ?? 0);
|
||||
$this->companyModuleId = (int) ($data['company_module_id'] ?? 0);
|
||||
$this->streetOne = (string) ($data['street_one'] ?? '');
|
||||
$this->streetTwo = (string) ($data['street_two'] ?? '');
|
||||
$this->postCode = (string) ($data['post_code'] ?? '');
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'tin' => $this->tin,
|
||||
'msic_code' => $this->msicCode,
|
||||
'district_id' => $this->districtId,
|
||||
'state_id' => $this->stateId,
|
||||
'company_module_id' => $this->companyModuleId,
|
||||
'street_one' => $this->streetOne,
|
||||
'street_two' => $this->streetTwo,
|
||||
'post_code' => $this->postCode,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class EInvoiceRequestDTO implements DataTransferObject
|
||||
{
|
||||
public bool $eInvoiceRequest;
|
||||
public int $companyModuleId;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->eInvoiceRequest = $data['e_invoice_request'];
|
||||
$this->companyModuleId = $data['company_module_id'];
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'e_invoice_request' => $this->eInvoiceRequest,
|
||||
'company_module_id' => $this->companyModuleId,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class UpdateCompanyDetailsDTO implements DataTransferObject
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public string $debtor;
|
||||
public string $reference;
|
||||
public int $type;
|
||||
|
||||
public string $tin;
|
||||
public string $msicCode;
|
||||
public int $addressId;
|
||||
public int $districtId;
|
||||
public int $stateId;
|
||||
public int $companyId;
|
||||
public string $streetOne;
|
||||
public string $streetTwo;
|
||||
public string $postCode;
|
||||
|
||||
public string $identificationReference;
|
||||
public int $identificationId;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int) ($data['id'] ?? 0);
|
||||
$this->name = (string) ($data['name'] ?? '');
|
||||
$this->debtor = (string) ($data['debtor'] ?? '');
|
||||
$this->reference = (string) ($data['reference'] ?? '');
|
||||
$this->type = (int) ($data['type'] ?? 0);
|
||||
|
||||
$this->tin = (string) ($data['tin'] ?? 0);
|
||||
$this->msicCode = (string) ($data['msic_code'] ?? '');
|
||||
$this->addressId = (int) ($data['address_id'] ?? 0);
|
||||
$this->districtId = (int) ($data['district_id'] ?? 0);
|
||||
$this->stateId = (int) ($data['state_id'] ?? 0);
|
||||
$this->companyId = (int) ($data['company_id'] ?? 0);
|
||||
$this->streetOne = (string) ($data['street_one'] ?? '');
|
||||
$this->streetTwo = (string) ($data['street_two'] ?? '');
|
||||
$this->postCode = (string) ($data['post_code'] ?? '');
|
||||
$this->identificationReference = (string) ($data['identification_reference'] ?? '');
|
||||
$this->identificationId = (int) ($data['identification_id'] ?? 0);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'debtor' => $this->debtor,
|
||||
'reference' => $this->reference,
|
||||
'type' => $this->type,
|
||||
|
||||
'tin' => $this->tin,
|
||||
'msic_code' => $this->msicCode,
|
||||
'address_id' => $this->addressId,
|
||||
'district_id' => $this->districtId,
|
||||
'state_id' => $this->stateId,
|
||||
'company_id' => $this->companyId,
|
||||
'street_one' => $this->streetOne,
|
||||
'street_two' => $this->streetTwo,
|
||||
'post_code' => $this->postCode,
|
||||
|
||||
'identification_reference' => $this->identificationReference,
|
||||
'identification_id' => $this->identificationId,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Company;
|
||||
|
||||
class UpdatesCompanyEInvoiceInfo extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $model
|
||||
* @param string $tin
|
||||
* @param string $msicCode
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $model, string $tin, string $msicCode)
|
||||
{
|
||||
$model->tin = $tin;
|
||||
$model->msic_code = $msicCode;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Company;
|
||||
|
||||
class UpdatesCompanyEInvoiceRequest extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $model
|
||||
* @param bool $eInvoice
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $model, bool $eInvoice)
|
||||
{
|
||||
if($eInvoice){
|
||||
if (is_null($model->e_invoice_requested_at)) {
|
||||
if($eInvoice){
|
||||
$model->e_invoice_requested_at = now();
|
||||
}
|
||||
}
|
||||
$model->e_invoice = 1;
|
||||
}
|
||||
else{
|
||||
$model->e_invoice_requested_at = null;
|
||||
$model->e_invoice = 0;
|
||||
}
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PendingVerificationDocument extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Document $model
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Document $model)
|
||||
{
|
||||
$model->status = ApprovalStatus::PENDING_VERIFICATION;
|
||||
$model->approver = Auth()->user()->id;
|
||||
$model->approval_date = Carbon::now();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\CompanyConnection;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $deduplicateMarking;
|
||||
protected $request;
|
||||
|
||||
public function __construct(Request $request, $deduplicateMarking = true)
|
||||
{
|
||||
$this->deduplicateMarking = $deduplicateMarking;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Marking',
|
||||
'Name',
|
||||
'Phone Number',
|
||||
'Email',
|
||||
'Registration Date',
|
||||
'Last Order Date',
|
||||
'Debtor Code',
|
||||
'Credit Term Customer',
|
||||
'Custom Segments',
|
||||
];
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
$baseQuery = CompanyConnection::has('invitee.company');
|
||||
|
||||
if ($this->deduplicateMarking) {
|
||||
$baseQuery->whereIn('id', function ($sub) {
|
||||
$sub->selectRaw('min(id)')
|
||||
->from('company_connections')
|
||||
->groupBy('invitee_reference');
|
||||
});
|
||||
}
|
||||
|
||||
return $baseQuery->with([
|
||||
'invitee.company.contacts',
|
||||
'invitee.company.companyModules.employees',
|
||||
'segments'
|
||||
]);
|
||||
}
|
||||
|
||||
public function map($connection): array
|
||||
{
|
||||
$company = optional(optional($connection)->invitee)->company;
|
||||
$companyModule = optional($company)->companyModules->first();
|
||||
$employee = optional($companyModule)->employees->first();
|
||||
$contact = optional($company)->contacts->first();
|
||||
|
||||
$marking = $connection->invitee_reference;
|
||||
$creditTermCustomer = $connection->is_credit_term ? 'YES' : 'NO';
|
||||
$employeeEmail = optional($employee)->email ?? '';
|
||||
$contactPhone = optional($contact)->phone ?? '';
|
||||
$segments = optional($connection->segments)->pluck('name')->implode(', ') ?: '';
|
||||
|
||||
return [
|
||||
$marking,
|
||||
optional($company)->name ?? '',
|
||||
$contactPhone,
|
||||
$employeeEmail,
|
||||
optional($company)->created_at ? $company->created_at->toDateString() : '',
|
||||
optional($company)->updated_at ? $company->updated_at->toDateString() : '',
|
||||
optional($company)->debtor ?? '',
|
||||
$creditTermCustomer,
|
||||
$segments,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
'transports'
|
||||
])
|
||||
->where('type', '=', 1)
|
||||
->where('status', '=', 2)
|
||||
// ->where('status', '=', 2)
|
||||
->where('owner_type', Order::class)
|
||||
->whereBetween('created_at', [Carbon::now()->subMonths(12), Carbon::now()]); //Limit, 'expensive' query
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Helper;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Models\Company;
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsCompanies implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'TIN',
|
||||
'IdentityNo',
|
||||
'Name',
|
||||
'IdentityType',
|
||||
'TaxClassification',
|
||||
'MSICCode',
|
||||
'BusinessActivityDesc',
|
||||
'DebtorCode',
|
||||
'TradeName',
|
||||
'Address',
|
||||
'PostCode',
|
||||
'Phone',
|
||||
'EmailAddress',
|
||||
'City',
|
||||
'CountryCode',
|
||||
'StateCode'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Company::whereBetween('e_invoice_requested_at', [$this->startDate, $this->endDate]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($company): array
|
||||
{
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
|
||||
$identityNo = $company->documents->where('document_type', DocumentType::IDENTITY_CARD)->first();
|
||||
$identityType = DocumentType::IDENTITY_CARD;
|
||||
if(!$identityNo){
|
||||
$identityNo = $company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$identityType = DocumentType::SSM_REGISTRATION;
|
||||
}
|
||||
$identityReference = "";
|
||||
if($identityNo){
|
||||
$identityReference = preg_replace('/\s*\(.*?\)/', '', $identityNo->reference);
|
||||
}
|
||||
$address = $companyModule->addresses()->where('type', AddressType::E_INVOICE)->latest()->first();
|
||||
if(!$address){
|
||||
$address = $companyModule->addresses()->where('type', AddressType::BILLING)->first();
|
||||
}
|
||||
|
||||
return [
|
||||
$company->tin, // 'TIN',
|
||||
$identityReference, // 'IdentityNo',
|
||||
$company->name, // 'Name',
|
||||
$identityType === DocumentType::IDENTITY_CARD ? 'MyKAD' : '', // 'IdentityType',
|
||||
$company->type !== null ? (string) $company->type : '0', // 'TaxClassification',
|
||||
$company->msic_code, // 'MSICCode',
|
||||
$company->msic_code ? Helper::getLHDNMsicDescriptionByCode($company->msic_code) : '', // 'BusinessActivityDesc',
|
||||
$company->debtor, // 'DebtorCode',
|
||||
$company->name, // 'TradeName',
|
||||
$address ? $address->street_one . ',' . $address->street_two : '',// 'Address',
|
||||
$address ? $address->postcode : '', // 'PostCode',
|
||||
$company->contacts()->first() ? $company->contacts()->first()->phone : '', // 'Phone',
|
||||
$employee ? $employee->email : '', // 'EmailAddress',
|
||||
$address ? $address->district()->first()->name : '', // 'City',
|
||||
'MYS', // 'CountryCode',
|
||||
$address ? Helper::getLHDNStateCodeByName($address->state()->first()->name) : '', // 'StateCode'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,8 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit
|
||||
public function map($company): array
|
||||
{
|
||||
$marking = $company->companyModules()->where('type', BusinessType::IMPORTER)->first()->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
|
||||
return [
|
||||
'<<New>>',
|
||||
@@ -87,7 +89,7 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',//EmailAddress
|
||||
$employee->email,//EmailAddress
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\Modules\Exports\Sheets\ContainersSheet;
|
||||
use App\Classes\Modules\Exports\Sheets\PackingListsSheet;
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;;
|
||||
|
||||
@@ -11,6 +12,14 @@ class ExportsParcel implements WithMultipleSheets
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -19,10 +28,10 @@ class ExportsParcel implements WithMultipleSheets
|
||||
{
|
||||
$sheets = [];
|
||||
|
||||
$sheets[] = new ContainersSheet();
|
||||
$sheets[] = new PackingListsSheet();
|
||||
$sheets[] = new ContainersSheet($this->startDate, $this->endDate);
|
||||
$sheets[] = new PackingListsSheet($this->startDate, $this->endDate);
|
||||
|
||||
return $sheets;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,8 +143,10 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
// Prepare each row based on the transaction detail
|
||||
$rows[] = [
|
||||
$firstItem ? '<<New>>' : '',
|
||||
$transaction->created_at->format('m/d/Y H:m'),
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
// $transaction->created_at->format('m/d/Y H:m'),
|
||||
$transaction->created_at->format('m/d/Y'),
|
||||
// $transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
@@ -169,7 +171,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
|
||||
return [
|
||||
'<<New>>',
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
// $transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
@@ -188,7 +191,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
];
|
||||
return [
|
||||
'<<New>>',
|
||||
$transaction->updated_at->format('m/d/Y H:m'),
|
||||
// $transaction->updated_at->format('m/d/Y H:m'),
|
||||
$transaction->updated_at->format('m/d/Y'),
|
||||
$company->debtor,
|
||||
$container->reference,
|
||||
'500-0000',
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsReceivePaymentDepositEntryReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'Description',
|
||||
'DeptNo',
|
||||
'DepositPaymentMethod',
|
||||
'PaymentMethod',
|
||||
'PaymentAmt',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$type = TransactionType::PAYMENT;
|
||||
$query = Transaction::query();
|
||||
// $query->where('owner_type', '!=', Wallet::class);
|
||||
$query->where('type', $type);
|
||||
$query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
$query->whereBetween('created_at', [$this->startDate, $this->endDate]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @return array
|
||||
*/
|
||||
public function map($transaction): array
|
||||
{
|
||||
$formattedDocumentDate = Carbon::parse($transaction->created_at)->format('m/d/Y');
|
||||
|
||||
$order = null;
|
||||
$owner = $transaction->owner;
|
||||
|
||||
if(!$owner) return[];
|
||||
|
||||
if($owner instanceof Wallet){
|
||||
$company = $owner->owner->company;
|
||||
}
|
||||
else{
|
||||
$order = $owner->owner->owner;
|
||||
$company = $order->companyModule->company;
|
||||
}
|
||||
|
||||
$paymentMethod = '';
|
||||
if($transaction->payment_method == PaymentMethodType::WALLET){
|
||||
$paymentMethod = 'WALLET DEPOSIT-IZYIM';
|
||||
if($owner instanceof Transaction){
|
||||
return[];
|
||||
}
|
||||
}
|
||||
else{
|
||||
$paymentMethod = 'MBB';
|
||||
}
|
||||
|
||||
return [
|
||||
'<<New>>', //DocNo
|
||||
$formattedDocumentDate, //DocDate
|
||||
$company ? $company->debtor : '', //DebtorCode
|
||||
$order ? $order->reference : '', //Description
|
||||
'C', //DeptNo
|
||||
'SALES DEPOSIT - IZYI', //DepositPaymentMethod
|
||||
$paymentMethod, //PaymentMethod
|
||||
number_format($transaction->amount, 2), //PaymentAmt
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsReceivePaymentForOrderReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'DocNo',
|
||||
'Docdate',
|
||||
'DebtorCode',
|
||||
'Description',
|
||||
'DeptNo',
|
||||
'PaymentMethod',
|
||||
'PaymentAmt',
|
||||
'KnockOffDocType',
|
||||
'KnockOffDocNo',
|
||||
'KnockOffAmt',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$type = TransactionType::PAYMENT;
|
||||
$query = Transaction::query();
|
||||
// $query->where('owner_type', '!=', Wallet::class);
|
||||
$query->where('type', $type);
|
||||
$query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
$query->whereBetween('created_at', [$this->startDate, $this->endDate]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @return array
|
||||
*/
|
||||
public function map($transaction): array
|
||||
{
|
||||
$autoCountSalesInvoiceId = null;
|
||||
$formattedDocumentDate = Carbon::parse($transaction->created_at)->format('m/d/Y');
|
||||
|
||||
$order = null;
|
||||
$invoice = null;
|
||||
$owner = $transaction->owner;
|
||||
|
||||
if($owner instanceof Wallet){
|
||||
$company = $owner->company;
|
||||
}
|
||||
else{
|
||||
$invoice = $transaction->owner;
|
||||
$order = $invoice->owner->owner;
|
||||
$company = $order->companyModule->company;
|
||||
}
|
||||
|
||||
if($invoice){
|
||||
$metadata = $invoice->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if($metadata){
|
||||
$autoCountSalesInvoiceId = $metadata->value;
|
||||
}
|
||||
}
|
||||
|
||||
if($transaction->payment_method == PaymentMethodType::WALLET){
|
||||
if($owner instanceof Wallet){
|
||||
return[];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'<<New>>', //DocNo
|
||||
$formattedDocumentDate, //DocDate
|
||||
$company ? $company->debtor : '', //DebtorCode
|
||||
'Payment for ' . $autoCountSalesInvoiceId ?? '', //Description
|
||||
'C', //DeptNo
|
||||
'SALES DEPOSIT - IZYI', //PaymentMethod
|
||||
number_format($transaction->amount, 2), //PaymentAmt
|
||||
'RI', //KnockOffDocType
|
||||
$autoCountSalesInvoiceId ?? '', //KnockOffDocNo
|
||||
number_format($transaction->amount, 2), //KnockOffAmt
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Models\Transaction;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsSalesInvoicesReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
protected $isUnpaid;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null, $isUnpaid = false) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
$this->isUnpaid = $isUnpaid;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'ShipInfo',
|
||||
'AccNo',
|
||||
'DetailDescription',
|
||||
'FurtherDescription',
|
||||
'Classification',
|
||||
'ProjNo',
|
||||
'DeptNo',
|
||||
'Qty',
|
||||
'UnitPrice',
|
||||
'TaxCode',
|
||||
'TaxableAmt',
|
||||
'TaxRate',
|
||||
'SubmitEinvoice',
|
||||
'ConsolidatedEInvoice',
|
||||
// 'PaymentDate',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$start_date = $this->startDate;
|
||||
$end_date = $this->endDate;
|
||||
|
||||
$query = Transaction::with([
|
||||
'transactionDetails',
|
||||
'transactions',
|
||||
'attributesKVP',
|
||||
'owner.containers',
|
||||
'owner.owner.companyModule.company.contacts',
|
||||
'owner.owner.companyModule.inviters',
|
||||
'owner.owner.companyModule.employees'
|
||||
]);
|
||||
|
||||
|
||||
// if($this->isUnpaid){
|
||||
// $approvalStatus = ApprovalStatus::COMPLETED;
|
||||
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
// ->whereNotIn('status', [$approvalStatus])
|
||||
// ->whereBetween('created_at', [$start_date, $end_date]);
|
||||
// }
|
||||
// else{
|
||||
// $approvalStatus = ApprovalStatus::COMPLETED;
|
||||
// $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
// ->where('status', $approvalStatus)
|
||||
// ->whereBetween('created_at', [$start_date, $end_date]);
|
||||
|
||||
// $query->whereHas('transactions', function($transaction) {
|
||||
// $transaction->where('type', TransactionType::PAYMENT)
|
||||
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
// });
|
||||
// }
|
||||
|
||||
if($this->isUnpaid){
|
||||
$approvalStatus = ApprovalStatus::COMPLETED;
|
||||
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
->whereNotIn('status', [$approvalStatus])
|
||||
->whereBetween('created_at', [$start_date, $end_date]);
|
||||
}
|
||||
else{
|
||||
//This will query everything both paid and unpaid unlike previously paid only
|
||||
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
->whereBetween('created_at', [$start_date, $end_date]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function map($transaction): array
|
||||
{
|
||||
$container = $transaction->owner ? $transaction->owner->containers->first() : null;
|
||||
$packingList = $transaction->owner;
|
||||
if(!$packingList) return[];
|
||||
$order = $packingList->owner;
|
||||
|
||||
$company = $order->companyModule->company;
|
||||
|
||||
// if(!$this->isUnpaid){
|
||||
// $lastPaymentTransaction = $transaction->transactions
|
||||
// ->whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP])
|
||||
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
// ->sortByDesc('created_at')
|
||||
// ->first();
|
||||
|
||||
// $documentDate = Carbon::parse($lastPaymentTransaction->created_at);
|
||||
// if($company->e_invoice === 1){
|
||||
// $documentDate = $documentDate->copy()->endOfMonth();
|
||||
// }
|
||||
// $formattedDocumentDate = Carbon::parse($documentDate)->format('m/d/Y');
|
||||
// }
|
||||
|
||||
$documentDate = Carbon::parse($transaction->created_at);
|
||||
if($company->e_invoice === 1){
|
||||
$documentDate = $documentDate->copy()->endOfMonth();
|
||||
}
|
||||
$formattedDocumentDate = Carbon::parse($documentDate)->format('m/d/Y');
|
||||
|
||||
// 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();
|
||||
// $link = route('customer.payment-and-billing', $marking);
|
||||
|
||||
$furtherDescription = '';
|
||||
foreach ($transaction->transactionDetails as $item){
|
||||
|
||||
if($item->reference === 'SHIPPING_FEE')
|
||||
$furtherDescription .= str_replace('X1 Freight Service Charge<br>', '', $item->name)."\n";
|
||||
elseif($item->reference === 'OVER_WEIGHT_CHARGES')
|
||||
$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";
|
||||
}
|
||||
|
||||
$transactionDetails = $transaction->transactionDetails;
|
||||
|
||||
$firstItem = true;
|
||||
|
||||
$docNo = '<<New>>';
|
||||
$firstItem = true;
|
||||
if($transaction){
|
||||
$transactionKVP = $transaction->attributesKVP->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if($transactionKVP){
|
||||
$docNo = $transactionKVP->value;
|
||||
}
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
foreach ($transactionDetails as $detail) {
|
||||
$rows[] = [
|
||||
$firstItem ? $docNo : '', //DocNo
|
||||
$formattedDocumentDate ?? '', //DocDate
|
||||
$company->debtor, //DebtorCode
|
||||
$transaction->bill_no, //Ref
|
||||
$order->reference, //ShipInfo
|
||||
'500-0000', //AccNo
|
||||
'SERVICE OR ITEM :', //DetailDescription
|
||||
str_replace('<br>', ' ', $detail->name), //FurtherDescription
|
||||
'022', //Classification
|
||||
$container->reference, //ProjNo
|
||||
'C ', //DeptNo
|
||||
$detail->quantity, //Qty
|
||||
$detail->price, //UnitPrice
|
||||
floatval($detail->tax_percentage) > 0 ? 'SV-6' : '', //TaxCode
|
||||
floatval($detail->tax_percentage) > 0 ? number_format($detail->amount, 2) : '0.00', //TaxableAmt
|
||||
$detail->tax_percentage, //TaxRate
|
||||
$firstItem ? 'T' : '', //SubmitEinvoice
|
||||
$company->e_invoice === 1 ? 'F' : 'T', //ConsolidatedEInvoice
|
||||
// $transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y'), //PaymentDate
|
||||
];
|
||||
|
||||
if($firstItem) {
|
||||
$firstItem = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use App\Classes\General\Eloquent\ApplyFiltersToQuery;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsSegmentCustomers implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $filters;
|
||||
protected $customerMarking;
|
||||
protected $segment;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function setParameters($customerMarking, $segment)
|
||||
{
|
||||
$this->customerMarking = $customerMarking;
|
||||
$this->segment = $segment;
|
||||
|
||||
$this->filters = [
|
||||
"company_segments_in" => [$this->segment],
|
||||
];
|
||||
|
||||
if ($this->customerMarking != 0) {
|
||||
$this->filters['marking_in'] = [$this->customerMarking];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Company Name',
|
||||
'Company Marking',
|
||||
'Is Credit Term Customers',
|
||||
'Auto Release',
|
||||
'Latest Order Creation Date',
|
||||
];
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
return (new ApplyFiltersToQuery())->execute(Company::query(), $this->filters);
|
||||
}
|
||||
|
||||
|
||||
public function map($list): array
|
||||
{
|
||||
$companyModule = $list->companyModules()->first();
|
||||
$marking = $companyModule->getMarking();
|
||||
|
||||
$isCreditTermCustomer = false;
|
||||
$segments = $companyModule->connections()->first()->segments()->pluck('name')->toArray();
|
||||
|
||||
$isCreditTermCustomer = in_array('Credit Term Customer', $segments);
|
||||
$autoRelease = in_array('Auto Release', $segments);
|
||||
|
||||
$lastestOrder = $companyModule->orders()->orderBy('id', 'desc')->first();
|
||||
|
||||
return [
|
||||
$list->name,
|
||||
$marking,
|
||||
$isCreditTermCustomer ? 'TRUE' : 'FALSE',
|
||||
$autoRelease ? 'TRUE' : 'FALSE',
|
||||
$lastestOrder ? $lastestOrder->created_at : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,16 @@ use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class ContainersSheet implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery, WithTitle
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(3);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
@@ -47,7 +54,7 @@ class ContainersSheet implements WithHeadings, WithHeadingRow, WithMapping, Shou
|
||||
public function query()
|
||||
{
|
||||
return Container::query()
|
||||
->whereBetween('created_at', [Carbon::now()->subMonths(3), Carbon::now()]); //Limit, 'expensive' query
|
||||
->whereBetween('created_at', [$this->startDate, $this->endDate]); //Limit, 'expensive' query
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,14 @@ class PackingListsSheet implements WithHeadings, WithHeadingRow, WithMapping, Sh
|
||||
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(3);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
@@ -55,7 +63,7 @@ class PackingListsSheet implements WithHeadings, WithHeadingRow, WithMapping, Sh
|
||||
{
|
||||
$packingLists = PackingList::where('status', '=', 2)
|
||||
->whereIn('type', [PackingListType::WAREHOUSE_RECEIVE_LIST, PackingListType::SHIPPING_PACKING_LIST])
|
||||
->whereBetween('created_at', [Carbon::now()->subMonths(3), Carbon::now()]) //Limit, 'expensive' query
|
||||
->whereBetween('created_at', [$this->startDate, $this->endDate]) //Limit, 'expensive' query
|
||||
->get();
|
||||
|
||||
return $packingLists->filter(function ($packingList) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Imports\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Imports\Services\AutoCountDataImport;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ImportExcelLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Import Excel',
|
||||
'message' => 'You have successfully imported data from excel file'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$reportType = $request->input('report_type');
|
||||
|
||||
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
|
||||
|
||||
$files = $object->getFiles();
|
||||
|
||||
if (count($files) > 1) {
|
||||
throw new MalformedRequestException('Import function can only process one file at a time.');
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filePath = json_decode($file)->file_info->original->file;
|
||||
$import = new AutoCountDataImport($reportType);
|
||||
Excel::import($import, $filePath);
|
||||
}
|
||||
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Imports\Services;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Jobs\Commands\V2\ProcessSalesInvoiceReportV2CommandJob;
|
||||
use App\Classes\Jobs\Commands\V2\ProcessPaymentReportV2CommandJob;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AutoCountDataImport implements ToCollection, WithHeadingRow, WithChunkReading
|
||||
{
|
||||
protected $reportType;
|
||||
|
||||
public function __construct($reportType)
|
||||
{
|
||||
$this->reportType = $reportType;
|
||||
}
|
||||
|
||||
public function headingRow(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
static $headerProcessed = false;
|
||||
foreach ($collection as $row) {
|
||||
if (!$headerProcessed) {
|
||||
$header = $row->keys()->map(fn($h) => strtolower(trim($h)))->toArray();
|
||||
$this->validateHeader($header, $this->reportType);
|
||||
$headerProcessed = true;
|
||||
}
|
||||
|
||||
if ($this->reportType === 'Sales Invoice Report') {
|
||||
ProcessSalesInvoiceReportV2CommandJob::dispatch($row->toArray());
|
||||
}
|
||||
elseif ($this->reportType === '11R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]') {
|
||||
ProcessPaymentReportV2CommandJob::dispatch($row->toArray());
|
||||
}
|
||||
else{
|
||||
throw new MalformedRequestException('Cannot process report type: ' . $this->reportType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function chunkSize(): int
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
private function validateHeader(array $header, String $reportType)
|
||||
{
|
||||
$optionalColumn = 'einvoicevalidationlink';
|
||||
$salesInvoiceHeader =
|
||||
['docno', 'docdate', 'debtorcode', 'ref',
|
||||
'shipinfo', 'accno', 'detaildescription', 'furtherdescription', 'classification', 'projno', 'deptno',
|
||||
'qty', 'unitprice', 'taxcode', 'taxableamt', 'taxrate', 'submiteinvoice', 'consolidatedeinvoice'];
|
||||
|
||||
$paymentReportHeader = [
|
||||
'docno',
|
||||
'docdate',
|
||||
'debtorcode',
|
||||
'description',
|
||||
'paymentmethod',
|
||||
'paymentamt',
|
||||
'knockoffdocno'
|
||||
];
|
||||
|
||||
if ($reportType === 'Sales Invoice Report' &&
|
||||
$header !== $salesInvoiceHeader &&
|
||||
$header !== [...$salesInvoiceHeader, $optionalColumn]) {
|
||||
throw new MalformedRequestException('Uploaded Excel file format is incorrect. Column headers do not match expected format.');
|
||||
}
|
||||
elseif ($reportType === '11R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]' && $header !== $paymentReportHeader) {
|
||||
throw new MalformedRequestException('Uploaded Excel file format is incorrect. Column headers do not match expected format.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\OpenAI\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\ConnectionErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatesChatGPTResponse
|
||||
{
|
||||
/**
|
||||
* @param string $userPrompt
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $userPrompt) {
|
||||
try {
|
||||
$data = [
|
||||
'model' => 'gpt-4-turbo', //gpt-4-turbo, gpt-4o-mini
|
||||
'messages' => [
|
||||
[
|
||||
'role' => 'user',
|
||||
'content' => $userPrompt
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . config('openai.api_key')
|
||||
])->post(config('openai.base_url') . '/v1/chat/completions', $data);
|
||||
|
||||
if ($response->successful()) {
|
||||
$data = $response->json();
|
||||
return $data;
|
||||
} else {
|
||||
Log::info('CreatesChatGPTResponse: ' . $response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (\Illuminate\Http\Client\ConnectionException $exception) {
|
||||
$error = 'Failed to connect to ChatGPT API';
|
||||
throw new ConnectionErrorException($error, $exception->getMessage(), $userPrompt, $exception->getTraceAsString());
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
throw new MalformedRequestException('Unable to get correct response from ChatGPT API: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\Commands\V2\ProcessTransactionForEInvoiceV2CommandJob;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateBatchProcessingAutoCountImportLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
protected int $processedCount = 0;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Generate E-Invoices',
|
||||
'message' => sprintf(
|
||||
'You have successfully submitted %d transaction%s for E-Invoices processing.',
|
||||
$this->processedCount,
|
||||
$this->processedCount === 1 ? '' : 's'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
|
||||
$startDate = isset($validated['startDate']) && $validated['startDate']
|
||||
? Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay()
|
||||
: Carbon::now()->startOfMonth()->startOfDay();
|
||||
|
||||
$endDate = isset($validated['endDate']) && $validated['endDate']
|
||||
? Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay()
|
||||
: Carbon::now()->endOfMonth()->endOfDay();
|
||||
|
||||
$query = Transaction::query();
|
||||
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
|
||||
// $transactions = $query->whereHas('transactions', function($transaction) use ($startDate, $endDate) {
|
||||
// $transaction->where('type', TransactionType::PAYMENT)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
// })->get();
|
||||
|
||||
$transactions = $query->whereBetween('created_at', [$startDate, $endDate])->get();
|
||||
|
||||
$count = 0;
|
||||
foreach ($transactions as $transaction) {
|
||||
ProcessTransactionForEInvoiceV2CommandJob::dispatch($transaction);
|
||||
// $count = $count + 1;
|
||||
// if($count > 15){
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
$this->processedCount = count($transactions);
|
||||
|
||||
return $this->resourceResponse(JsonResource::collection(collect([])));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\ChecksIfOrderNumberExists;
|
||||
use App\Classes\Modules\Orders\Services\RestoresOrder;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Http\Resources\OrderResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\SupplierTaxRebate;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateSupplierTaxRebateLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Create Supplier Tax Refund',
|
||||
'message' => 'You have successfully created a Supplier Tax Refund'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var RestoresOrder */
|
||||
private $restoresOrder;
|
||||
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/** @var ChecksIfOrderNumberExists */
|
||||
private $checkIfOrderNumberExists;
|
||||
|
||||
/**
|
||||
* CancelOrderLogic constructor.
|
||||
* @param RestoresOrder $restoresOrder
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
*/
|
||||
public function __construct(RestoresOrder $restoresOrder, FetchesOrder $fetchesOrder, ChecksIfOrderNumberExists $checkIfOrderNumberExists)
|
||||
{
|
||||
$this->restoresOrder = $restoresOrder;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
$this->checkIfOrderNumberExists = $checkIfOrderNumberExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
/** @var Order $order */
|
||||
$order = $this->fetchesOrder->execute(['id' => $request->route('id')]);
|
||||
|
||||
$taxRebate = SupplierTaxRebate::create([
|
||||
'order_id' => $order->id,
|
||||
'supplier_name' => $request->input('supplier_name'),
|
||||
'supplier_contact_number' => $request->input('supplier_contact_number'),
|
||||
'reference_number' => $this->generateUniqueReferenceNumber(),
|
||||
]);
|
||||
|
||||
return $this->resourceResponse(new OrderResource($order));
|
||||
}
|
||||
|
||||
public function generateUniqueReferenceNumber(?string $prefix = '', ?int $length = 9): string
|
||||
{
|
||||
// regenerate new reference number until a new unique reference is found
|
||||
do {
|
||||
$reference = $prefix . rand((int)('1' . str_repeat('0', $length - 2) . '1'), (int) str_repeat('9', $length));
|
||||
} while (
|
||||
SupplierTaxRebate::where('reference_number', $reference)->exists() || $this->checkIfOrderNumberExists->execute($reference)
|
||||
);
|
||||
|
||||
return $reference;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Models\SupplierTaxRebate;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteSupplierTaxRebateLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Delete Supplier Tax Refund',
|
||||
'message' => 'You have successfully deleted a Supplier Tax Refund'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* DeleteSupplierTaxRebateLogic constructor.
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
SupplierTaxRebate::find($request->route('id'))->delete();
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,14 @@ namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\OrderPackagesBaseResource;
|
||||
use App\Http\Resources\OrderPackagesDeprecatedResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* @deprecated This class is deprecated and should not be used.
|
||||
* Use `FetchOrderPackagesReceivedV2Logic` instead or write a new one based on FetchOrderPackagesReceivedV2Logic
|
||||
*/
|
||||
class FetchOrderPackagesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
@@ -70,7 +74,7 @@ class FetchOrderPackagesLogic extends AbstractControllerLogic
|
||||
$query->include_packages_received = $filters['include_packages_received'];
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new OrderPackagesBaseResource($query));
|
||||
return $this->resourceResponse(new OrderPackagesDeprecatedResource($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\OrderPackagesReceivedResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchOrderPackagesReceivedV2Logic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Order Packages Received',
|
||||
'message' => 'You have successfully retrieved an order packages'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchOrder */
|
||||
private $canFetchOrder;
|
||||
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/**
|
||||
* FetchOrderPackagesReceivedV2Logic constructor.
|
||||
* @param CanFetchOrder $canFetchOrder
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
*/
|
||||
public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder)
|
||||
{
|
||||
$this->canFetchOrder = $canFetchOrder;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchOrder->passes();
|
||||
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
|
||||
//Can refer FetchOrderPackagesLogic for different type of OrderPackages Resources
|
||||
return $this->resourceResponse(new OrderPackagesReceivedResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\OrderPackagesResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class FetchOrderPackagesV2Logic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Order Packages',
|
||||
'message' => 'You have successfully retrieved an order packages'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchOrder */
|
||||
private $canFetchOrder;
|
||||
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/**
|
||||
* FetchOrderPackagesV2Logic constructor.
|
||||
* @param CanFetchOrder $canFetchOrder
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
*/
|
||||
public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder)
|
||||
{
|
||||
$this->canFetchOrder = $canFetchOrder;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchOrder->passes();
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
return $this->resourceResponse(new OrderPackagesResource($query));
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\OrderV2Resource;
|
||||
use App\Http\Resources\FetchOrderResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -48,7 +48,6 @@ class FetchOrderV2Logic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$this->canFetchOrder->passes();
|
||||
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
@@ -56,9 +55,6 @@ class FetchOrderV2Logic extends AbstractControllerLogic
|
||||
if($request->input('storages')){
|
||||
$query->storages = $request->input('storages'); //from middleware
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new OrderV2Resource($query));
|
||||
|
||||
return $this->resourceResponse(new FetchOrderResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrderTracking;
|
||||
use App\Http\Resources\OrderTrackingResource;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanListTrackings;
|
||||
|
||||
class ListOrderTrackingLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Order Tracking',
|
||||
'message' => 'You have successfully retrieved order tracking info'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsOrderTracking */
|
||||
private $listsOrderTracking;
|
||||
|
||||
/** @var CanListTrackings */
|
||||
private $canListTrackings;
|
||||
|
||||
/**
|
||||
* ListOrderTrackingLogic constructor.
|
||||
* @param CanListTrackings $canListTrackings
|
||||
* @param ListsOrderTracking $listsOrderTracking
|
||||
*/
|
||||
public function __construct(CanListTrackings $canListTrackings, ListsOrderTracking $listsOrderTracking)
|
||||
{
|
||||
$this->canListTrackings = $canListTrackings;
|
||||
$this->listsOrderTracking = $listsOrderTracking;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = null;
|
||||
$filters = json_decode($request->input('filters'), true);
|
||||
$trackingNo = $filters['tracking_no'];
|
||||
|
||||
try {
|
||||
$trackingNo = Crypt::decryptString($trackingNo);
|
||||
$trackingNo = str_replace('_01', '', $trackingNo);
|
||||
} catch (DecryptException $e) {
|
||||
Log::info('Decryption failed, string might already be decrypted or invalid.');
|
||||
$this->canListTrackings->passes();
|
||||
// if(!in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN])){
|
||||
// abort(404);
|
||||
// }
|
||||
}
|
||||
|
||||
if (preg_match('/^\d{9}$/', $trackingNo)) {
|
||||
$order = Order::where('reference', $trackingNo)->first();
|
||||
if($order){
|
||||
$packingList = $order->packingLists()->first();
|
||||
$trackingNo = $packingList->reference;
|
||||
Artisan::call('process-yd-by-traking-no-data-command', [
|
||||
'trackingNo' => $trackingNo
|
||||
]);
|
||||
$query = $this->listsOrderTracking->execute(array_merge($this->listsOrderTracking->deserializeFilters($request->input('filters')), ['tracking_no' => $trackingNo]));
|
||||
}
|
||||
}
|
||||
else{
|
||||
Artisan::call('process-yd-by-traking-no-data-command', [
|
||||
'trackingNo' => $trackingNo
|
||||
]);
|
||||
$query = $this->listsOrderTracking->execute(array_merge($this->listsOrderTracking->deserializeFilters($request->input('filters')), ['tracking_no' => $trackingNo]));
|
||||
}
|
||||
|
||||
return $this->collectionResponse(OrderTrackingResource::collection($query));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ use App\Classes\Modules\Orders\Services\ListsOrders;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanListOrders;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use App\Http\Resources\OrderBaseResource;
|
||||
use App\Http\Resources\OrderV2Resource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -65,9 +64,5 @@ class ListOrdersV2Logic extends AbstractControllerLogic
|
||||
}
|
||||
|
||||
return $this->collectionResponse(OrderBaseResource::collection($query));
|
||||
//return $this->collectionResponse(OrderV2Resource::collection($query));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -69,10 +69,8 @@ class UpdateDoFromYDPortalProcessor
|
||||
'cellphone' => $phone,
|
||||
'postcode' => $address->postcode,
|
||||
'streetAddress' => $address->street_one . ' ' . $address->street_two . ' '. $address->district->name.' '. $address->post_code.' '.$address->state->name.' '.$address->country->name.' '.$address->postcode.' || '.$remark
|
||||
|
||||
]);
|
||||
|
||||
|
||||
]
|
||||
);
|
||||
} catch (\Exception $exception){
|
||||
log::debug($exception);
|
||||
throw new InternalServerErrorException('failed to approve address due to an error related to YD portal');
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use App\Models\YDOrderTracking;
|
||||
|
||||
class ListsOrderTracking extends AbstractListRecord
|
||||
{
|
||||
/** @var YDOrderTracking */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsOrderTracking constructor.
|
||||
* @param YDOrderTracking $repository
|
||||
*/
|
||||
public function __construct(YDOrderTracking $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Orders\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
|
||||
class CanListTrackings extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\Commands\V2\YD\FetchPackingListsFromYdPortalV2CommandJob;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
|
||||
@@ -23,9 +24,11 @@ use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
|
||||
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use Carbon\Carbon;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AssignPackingListOrderLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -107,8 +110,17 @@ class AssignPackingListOrderLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
// $warehouse_packing_list = $this->fetchesPackingList->execute([
|
||||
// 'id' => $request->route('id'),
|
||||
// 'type' => PackingListType::WAREHOUSE_RECEIVE_LIST
|
||||
// ]);
|
||||
|
||||
$packing_list = $this->fetchesPackingList->execute([
|
||||
'id' => $request->route('id'),
|
||||
]);
|
||||
|
||||
$warehouse_packing_list = $this->fetchesPackingList->execute([
|
||||
'id' => $request->route('id'),
|
||||
'reference' => $packing_list->reference,
|
||||
'type' => PackingListType::WAREHOUSE_RECEIVE_LIST
|
||||
]);
|
||||
|
||||
@@ -153,7 +165,43 @@ class AssignPackingListOrderLogic extends AbstractControllerLogic
|
||||
|
||||
}
|
||||
|
||||
// Update Packing Lists' packages info,
|
||||
// Important for markup 'No Extra Centimeter Charged' reevaluation as a result of packing list is now 'Claimed' to an order (before this was Unclaimed Packing Lists)
|
||||
// See CreatePackageProcessor.php
|
||||
$jobs1 = $this->fetchPackingListsFromYdPortalV2CommandJobs();
|
||||
foreach ($jobs1 as $index => $job) {
|
||||
dispatch($job)->delay(now()->addSeconds($index * 2));
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($warehouse_packing_list));
|
||||
}
|
||||
|
||||
private function fetchPackingListsFromYdPortalV2CommandJobs(){
|
||||
$jobs = [];
|
||||
|
||||
$from = 0;
|
||||
$to = 10;
|
||||
|
||||
$count = 0;
|
||||
for ($x = $from; $x <= $to; $x++) {
|
||||
|
||||
$startDate = Carbon::today()->subDays($x);
|
||||
$startLimit = Carbon::parse('01-12-2021');
|
||||
|
||||
if($startDate->isBefore($startLimit)){
|
||||
$startDate = $startLimit;
|
||||
}
|
||||
|
||||
$endDate = Carbon::today()->subDays($x - 1);
|
||||
|
||||
$jobs[] = new FetchPackingListsFromYdPortalV2CommandJob($startDate, $endDate);
|
||||
|
||||
Log::info('(AssignPackingListOrderLogic) Dispatched FetchPackingListsFromYdPortalV2CommandJob for start date: ' . $startDate . ', end date: ' . $endDate);
|
||||
$count++;
|
||||
}
|
||||
Log::info('(AssignPackingListOrderLogic) Total FetchPackingListsFromYdPortalV2CommandJob dispatched: ' . $count);
|
||||
|
||||
return $jobs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
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\PackingListForWarehouseResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListPackingListsForWarehouseLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingLists for Warehouse',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists for warehouse'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsForWarehouseLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
return $this->collectionResponse(PackingListForWarehouseResource::collection($query));
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ 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\PackingListBaseResource;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -52,57 +51,7 @@ class ListPackingListsLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
$data = json_encode($request->input('storages'));
|
||||
Log::info("ListPackingListsLogic storages A");
|
||||
|
||||
// if($request->input('storages')){
|
||||
// Log::info("ListPackingListsLogic storages B");
|
||||
// foreach ($query->items() as $item) {
|
||||
// $item['storages'] = $request->input('storages');
|
||||
// }
|
||||
// return $this->collectionResponse(PackingListWithStorageResource::collection($query));
|
||||
// }
|
||||
|
||||
$filters = json_decode($request->input('filters'), true);
|
||||
$useNew = false;
|
||||
foreach ($query->items() as $item) {
|
||||
//from middleware
|
||||
if($request->input('storages')){
|
||||
$item['storages'] = $request->input('storages');
|
||||
}
|
||||
|
||||
//from front end component
|
||||
if(isset($filters['include_packages'])){
|
||||
//'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
$item['include_packages'] = $filters['include_packages'];
|
||||
$useNew = true;
|
||||
}
|
||||
|
||||
if(isset($filters['include_receive_packing_list'])){
|
||||
//'include_receive_packing_list' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
$item['include_receive_packing_list'] = $filters['include_receive_packing_list'];
|
||||
$useNew = true;
|
||||
}
|
||||
|
||||
if(isset($filters['include_shipping_transaction'])){
|
||||
$item['include_shipping_transaction'] = $filters['include_shipping_transaction'];
|
||||
$useNew = true;
|
||||
}
|
||||
|
||||
if(isset($filters['include_suspended_invoice'])){
|
||||
$item['include_suspended_invoice'] = $filters['include_suspended_invoice'];
|
||||
$useNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($useNew){
|
||||
return $this->collectionResponse(PackingListBaseResource::collection($query));
|
||||
}
|
||||
|
||||
//Fallback
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
}
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
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\PackingListPaidInvoiceResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListPackingListsPaidInvoiceLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '(Paid Invoice) Retrieved PackingLists',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsPaidInvoiceLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
foreach ($query->items() as $item) {
|
||||
//from middleware
|
||||
if($request->input('storages')){
|
||||
$item['storages'] = $request->input('storages');
|
||||
}
|
||||
}
|
||||
return $this->collectionResponse(PackingListPaidInvoiceResource::collection($query));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
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\PackingListPendingApprovalResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListPackingListsPendingApprovalLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '(Pending Approval) Retrieved PackingLists',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsPendingApprovalLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
return $this->collectionResponse(PackingListPendingApprovalResource::collection($query));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
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\PackingListPendingInvoiceResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListPackingListsPendingInvoiceLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '(Pending Invoice) Retrieved PackingLists',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsPendingInvoiceLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
return $this->collectionResponse(PackingListPendingInvoiceResource::collection($query));
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
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\PackingListPendingPaymentResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListPackingListsPendingPaymentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '(Pending Payment) Retrieved PackingLists',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsPendingPaymentLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListPackingLists->passes();
|
||||
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
foreach ($query->items() as $item) {
|
||||
//from middleware
|
||||
if($request->input('storages')){
|
||||
$item['storages'] = $request->input('storages');
|
||||
}
|
||||
}
|
||||
return $this->collectionResponse(PackingListPendingPaymentResource::collection($query));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ use App\Classes\Modules\PackingLists\Standards\Rules\Packages\CanCreatePackage;
|
||||
use App\Classes\ValueObjects\Constants\WarehouseReferences;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatePackageProcessor
|
||||
{
|
||||
@@ -52,7 +54,16 @@ class CreatePackageProcessor
|
||||
$modificationValue = 1;
|
||||
|
||||
if($replica->owner->owner instanceof Order){
|
||||
$modificationValue = in_array( $replica->owner->owner->companyModule->id, WarehouseReferences::REPLICA_WHITE_LIST) ? 0 : 1;
|
||||
// $modificationValue = in_array( $replica->owner->owner->companyModule->id, WarehouseReferences::REPLICA_WHITE_LIST) ? 0 : 1;
|
||||
$modificationValue = 1;
|
||||
|
||||
// if customer in segment 'No Extra Centimeter Charged'
|
||||
$segmentId = Segment::where('name', 'No Extra Centimeter Charged')->first()->id;
|
||||
$companySegments = $replica->owner->owner->companyModule->connections()->first()->segments->pluck('id')->toArray();
|
||||
if (in_array($segmentId, $companySegments)) {
|
||||
$modificationValue = 0;
|
||||
Log::info('No Extra Centimeter Charged segment working');
|
||||
}
|
||||
}
|
||||
|
||||
$packageObject = new PackageObject($object->getType(), $object->getDescription(), $object->getWidth() + $modificationValue, $object->getHeight() + $modificationValue, $object->getLength() + $modificationValue, $object->getWeight(), $object->getQuantity(), $object->getStatus());
|
||||
@@ -63,4 +74,4 @@ class CreatePackageProcessor
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Processors\V2;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Anthropic\Services\CreatesClaudeResponse;
|
||||
use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal;
|
||||
use App\Classes\Modules\OpenAI\Services\CreatesChatGPTResponse;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\YDOrderTracking;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchByTrakingNoYdPortalV2Processor
|
||||
{
|
||||
/** @var FetchesDataFromYDPortal */
|
||||
private $fetchesDataFRomYDPortal;
|
||||
|
||||
/** @var CreatesChatGPTResponse */
|
||||
private $createsChatGPTResponse;
|
||||
|
||||
/** @var CreatesClaudeResponse */
|
||||
private $createsClaudeResponse;
|
||||
|
||||
/**
|
||||
* @param FetchesDataFromYDPortal $fetchesDataFRomYDPortal
|
||||
* @param CreatesChatGPTResponse $createsChatGPTResponse
|
||||
* @param CreatesClaudeResponse $createsClaudeResponse
|
||||
*/
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, CreatesChatGPTResponse $createsChatGPTResponse, CreatesClaudeResponse $createsClaudeResponse)
|
||||
{
|
||||
$this->fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal;
|
||||
$this->createsChatGPTResponse = $createsChatGPTResponse;
|
||||
$this->createsClaudeResponse = $createsClaudeResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingList $packingList
|
||||
* @return void
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $packingList)
|
||||
{
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor starts with packingList id ' . $packingList->id);
|
||||
// return;
|
||||
|
||||
$reference = $packingList->reference;
|
||||
Log::info('reference ' . $reference);
|
||||
|
||||
$oneHourAgo = Carbon::now()->subHour();
|
||||
$check1 = YDOrderTracking::where('tracking_no', $reference)
|
||||
->orderBy('updated_at', 'desc')
|
||||
->first();
|
||||
|
||||
if ($check1 && $check1->updated_at >= $oneHourAgo) {
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor SKIPPED: Record updated within the last hour');
|
||||
Log::info('---');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processTrackingNo($reference);
|
||||
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor ends with packingList id ' . $packingList->id);
|
||||
Log::info('---');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reference
|
||||
* @return void
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function processTrackingNo(string $reference){
|
||||
$time_start = microtime(true);
|
||||
|
||||
$check2 = YDOrderTracking::where('tracking_no', $reference)
|
||||
->where('tracking', '第三方提货')
|
||||
->first();
|
||||
|
||||
// if ($check2) {
|
||||
// Log::info('FetchByTrakingNoYdPortalV2Processor SKIPPED: 第三方提货');
|
||||
// Log::info('---');
|
||||
// return;
|
||||
// }
|
||||
|
||||
$trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [
|
||||
'trakingno' => $reference
|
||||
]);
|
||||
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest);
|
||||
|
||||
$this->processData(json_encode($rows), $reference);
|
||||
|
||||
$time_end = microtime(true);
|
||||
|
||||
$execution_time = ($time_end - $time_start)/60;
|
||||
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor ends with reference ' . $reference . ' => Total Execution Time: '.$execution_time.' Mins.');
|
||||
}
|
||||
|
||||
private function processData($jsonData, $reference)
|
||||
{
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
if ($data['res'] == 1 && isset($data['data'])) {
|
||||
Log::info('package_id: '.$data['data'][0]['package_id']);
|
||||
foreach (array_reverse($data['data']) as $item) {
|
||||
$existingRecord = YDOrderTracking::where('order_tracking_id', $item['Id'])
|
||||
->where('tracking_no', $reference)
|
||||
->first();
|
||||
|
||||
// Log::info('tracking: '.$item['tracking']);
|
||||
// Log::info('remark: '.$item['remark']);
|
||||
|
||||
if (!$existingRecord) {
|
||||
$etdEta = $this->parseEtdEta($item['remark'], $item['tracking'], $item['trackingtime']);
|
||||
$isTrackingTranslatedPreviouly = $this->checkIfTranslationAlreadyExist(!empty($item['tracking']) ? $item['tracking'] : "");
|
||||
$isRemarkTranslatedPreviouly = $this->checkIfTranslationAlreadyExist(!empty($item['remark']) ? $item['remark'] : "");
|
||||
YDOrderTracking::create([
|
||||
'order_tracking_id' => $item['Id'],
|
||||
'tracking_no' => $reference,
|
||||
'package_id' => $item['package_id'],
|
||||
'tracking' => $item['tracking'] ?? null,
|
||||
'tracking_english' => $isTrackingTranslatedPreviouly ? $isTrackingTranslatedPreviouly : $this->translateTracking($item['tracking']),
|
||||
'tracking_time' => $item['trackingtime'] ?? null,
|
||||
'add_time' => $item['addtime'] ?? null,
|
||||
'remark' => $item['remark'] ?? null,
|
||||
'remark_english' => $item['remark'] ? ($isRemarkTranslatedPreviouly ? $isRemarkTranslatedPreviouly : $this->translateTracking($item['remark'])) : null,
|
||||
'etd' => $etdEta['etd'],
|
||||
'eta' => $etdEta['eta']
|
||||
]);
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor RECORD CREATED');
|
||||
}
|
||||
else{
|
||||
$isUpdated = false;
|
||||
if($item['tracking']){
|
||||
$isTranslatedPreviously = $this->checkIfTranslationAlreadyExist(!empty($item['tracking']) ? $item['tracking'] : "");
|
||||
$result = $isTranslatedPreviously;
|
||||
if (!$isTranslatedPreviously){
|
||||
$result = $this->translateTracking($item['tracking']);
|
||||
}
|
||||
if ($result && $existingRecord->tracking_english !== $result) {
|
||||
$existingRecord->update([
|
||||
'tracking_english' => $result
|
||||
]);
|
||||
$isUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($item['remark']) {
|
||||
$isTranslatedPreviously = $this->checkIfTranslationAlreadyExist(!empty($item['remark']) ? $item['remark'] : "");
|
||||
$result = $isTranslatedPreviously;
|
||||
if (!$isTranslatedPreviously){
|
||||
$result = $this->translateTracking($item['remark']);
|
||||
}
|
||||
|
||||
if ($result && $existingRecord->remark_english !== $result) {
|
||||
$existingRecord->update([
|
||||
'remark_english' => $result
|
||||
]);
|
||||
$isUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($isUpdated){
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor RECORD UPDATED');
|
||||
}
|
||||
else{
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor RECORD EXIST');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function parseEtdEta($remark, $tracking, $trackingtime)
|
||||
{
|
||||
$etd = null;
|
||||
$eta = null;
|
||||
$etaString = '';
|
||||
$etdString = '';
|
||||
|
||||
if($remark && $tracking !== '第三方提货'){
|
||||
if (preg_match('/(?:预计|延)(\d+\.\d+)(?:号)?开/', $remark, $matches)) {
|
||||
$etdString = $matches[1];
|
||||
}
|
||||
|
||||
if (preg_match('/(?:预计)?(\d+\.\d+)(?:号)?到港/', $remark, $matches)) {
|
||||
$etaString = $matches[1];
|
||||
}
|
||||
Log::info('remark: '.$remark);
|
||||
|
||||
$currentYear = Carbon::now()->year;
|
||||
$trackingDate = Carbon::parse($trackingtime);
|
||||
$trackingYear = $trackingDate->year;
|
||||
|
||||
if($remark && $eta === null && $etd === null){
|
||||
$existingRecord = YDOrderTracking::where('remark', $remark)->where(function ($query) {
|
||||
$query->whereNotNull('eta')
|
||||
->orWhereNotNull('etd');
|
||||
})
|
||||
->first();
|
||||
if($existingRecord){
|
||||
Log::info('FetchByTrakingNoYdPortalV2Processor SAVER');
|
||||
return [
|
||||
'etd' => $existingRecord->etd,
|
||||
'eta' => $existingRecord->eta,
|
||||
];
|
||||
}
|
||||
|
||||
$userPrompt = "You must respond with raw JSON only.
|
||||
No explanations.
|
||||
No markdown.
|
||||
No code fences.
|
||||
No comments.
|
||||
Only this JSON structure:
|
||||
{\"ETA\":\"\", \"ETD\":\"\"}
|
||||
Dates must be strings in YYYY-MM-DD format.
|
||||
|
||||
{$remark}
|
||||
What are the ETA and ETD?";
|
||||
Log::info('prompt: '.$userPrompt);
|
||||
$result = $this->createsClaudeResponse->execute($userPrompt);
|
||||
Log::info('result (json_encoded): '.json_encode($result));
|
||||
// $content = $result['choices'][0]['message']['content'] ?? null;
|
||||
$content = $result['content'][0]['text'] ?? '[]';
|
||||
Log::info('content (json_encoded):'. json_encode($content));
|
||||
if ($content) {
|
||||
$parsedContent = json_decode($content, true);
|
||||
|
||||
// $parsedContent = json_decode(str_replace("'", '"', $content), true);
|
||||
if (is_array($parsedContent) && isset($parsedContent['ETA'], $parsedContent['ETD'])) {
|
||||
Log::info('parsedContent ETA:'. $parsedContent['ETA']);
|
||||
Log::info('parsedContent ETD:'. $parsedContent['ETD']);
|
||||
$etaString = $parsedContent['ETA'];
|
||||
$etdString = $parsedContent['ETD'];
|
||||
$dateParts = explode('-', $etaString);
|
||||
if (count($dateParts) === 3) {
|
||||
$etaString = $dateParts[1] . '-' . $dateParts[2];
|
||||
}
|
||||
|
||||
$dateParts = explode('-', $etdString);
|
||||
if (count($dateParts) === 3) {
|
||||
$etdString = $dateParts[1] . '-' . $dateParts[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($etaString) && preg_match('/\b\d{1,2}[-\/.]\d{1,2}\b/', $etaString)) {
|
||||
$etaString = str_replace(['.', '-', '/'], '/', $etaString);
|
||||
$etaParts = explode('/', $etaString);
|
||||
$etaMonth = intval($etaParts[0]);
|
||||
$etaDay = intval($etaParts[1]);
|
||||
$etaDate = DateTime::createFromFormat("Y/m/d", "$currentYear/$etaString");
|
||||
|
||||
if($trackingYear < $currentYear){
|
||||
$etaDate = DateTime::createFromFormat("Y/m/d", ($trackingYear) . "/$etaString");
|
||||
}
|
||||
else{
|
||||
$etaYear = $currentYear;
|
||||
if ($etaMonth <= 2 && $trackingDate->month == 12) {
|
||||
$etaYear = $trackingDate->year + 1;
|
||||
}
|
||||
$etaDate = Carbon::createFromDate($etaYear, $etaMonth, $etaDay);
|
||||
}
|
||||
|
||||
if($etaDate){
|
||||
$eta = $etaDate->format('Y-m-d');
|
||||
}
|
||||
Log::info('ETA: '.$eta);
|
||||
Log::info('ETD: '.$etd);
|
||||
}
|
||||
|
||||
if (!empty($etdString) && preg_match('/\b\d{1,2}[-\/.]\d{1,2}\b/', $etdString)) {
|
||||
$etdString = str_replace(['.', '-', '/'], '/', $etdString);
|
||||
$etdParts = explode('/', $etdString);
|
||||
$etdMonth = intval($etdParts[0]);
|
||||
$etdDay = intval($etdParts[1]);
|
||||
$etdDate = DateTime::createFromFormat("Y/m/d", "$currentYear/$etdString");
|
||||
|
||||
if($trackingYear < $currentYear){
|
||||
$etdDate = DateTime::createFromFormat("Y/m/d", ($trackingYear) . "/$etdString");
|
||||
}
|
||||
else{
|
||||
$etdYear = $currentYear;
|
||||
if ($etdMonth <= 1 && $trackingDate->month == 12) {
|
||||
$etdYear = $trackingDate->year + 1;
|
||||
}
|
||||
$etdDate = Carbon::createFromDate($etdYear, $etdMonth, $etdDay);
|
||||
}
|
||||
|
||||
if($etdDate){
|
||||
$etd = $etdDate->format('Y-m-d');
|
||||
}
|
||||
Log::info('ETD: '.$etd);
|
||||
Log::info('ETA: '.$eta);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'etd' => $etd ? date('Y-m-d', strtotime($etd)) : null,
|
||||
'eta' => $eta ? date('Y-m-d', strtotime($eta)) : null,
|
||||
];
|
||||
}
|
||||
|
||||
private function checkIfTranslationAlreadyExist($textToTranslate)
|
||||
{
|
||||
$returnText = "";
|
||||
Log::info('textToTranslate: '.$textToTranslate);
|
||||
if(!$textToTranslate) return $returnText;
|
||||
|
||||
$translationFound = YDOrderTracking::where('tracking', $textToTranslate)->whereNotNull('tracking_english')->first();
|
||||
if(!$translationFound){
|
||||
$translationFound = YDOrderTracking::where('remark', $textToTranslate)->whereNotNull('remark_english')->first();
|
||||
if($translationFound){
|
||||
$returnText = $translationFound->remark_english;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$returnText = $translationFound->tracking_english;
|
||||
}
|
||||
Log::info('FOUND EXISTING TRANSLATION: '.$returnText);
|
||||
return $returnText;
|
||||
}
|
||||
|
||||
private function translateTracking($textToTranslate)
|
||||
{
|
||||
$userPrompt = "Please translate mandarin to english and return result in this format, e.g. {'mandarin': '.$textToTranslate.', 'english': ''}. ".$textToTranslate." ";
|
||||
Log::info('prompt: '.$userPrompt);
|
||||
$result = $this->createsClaudeResponse->execute($userPrompt);
|
||||
Log::info('result (json_encoded): '.json_encode($result));
|
||||
// $content = $result['choices'][0]['message']['content'] ?? null;
|
||||
$content = $result['content'][0]['text'] ?? '[]';
|
||||
Log::info('content (json_encoded):'. json_encode($content));
|
||||
$parsedContent = json_decode(str_replace("'", '"', $content), true);
|
||||
|
||||
if($parsedContent && $parsedContent['english']){
|
||||
Log::info('Translated Text: ' . $parsedContent['english']);
|
||||
return $parsedContent['english'];
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -105,10 +105,12 @@ class FetchContainersFromYdPortalV2Processor
|
||||
$loadingDate = null;
|
||||
$etd = null;
|
||||
$eta = null;
|
||||
$reference = $packingList->reference;
|
||||
|
||||
$trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [
|
||||
'trakingno' => $packingList->reference
|
||||
'trakingno' => $reference
|
||||
]);
|
||||
Log::info('YDContainer reference ' . $reference);
|
||||
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest);
|
||||
|
||||
@@ -117,22 +119,24 @@ class FetchContainersFromYdPortalV2Processor
|
||||
}
|
||||
|
||||
foreach (array_reverse($rows->data) as $trackingRow) {
|
||||
Log::info('YDContainer trackingRow ' . json_encode($trackingRow));
|
||||
if (strpos($trackingRow->tracking, '货物装柜完成。') !== false) {
|
||||
$tracking = explode(':', $trackingRow->tracking);
|
||||
$containerReference = explode('预计到港时间', $tracking[1])[0];
|
||||
$loadingDate = Carbon::parse($trackingRow->trackingtime);
|
||||
$etd = Carbon::parse($tracking[2])->subDays(5);
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if($containerReference) {
|
||||
try {
|
||||
Log::info('YDContainer try ' . json_encode($containerReference));
|
||||
$container = $this->fetchesContainer->execute(['reference' => $containerReference]);
|
||||
$container->packingLists()->detach($packingList);
|
||||
$container->packingLists()->attach($packingList);
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
|
||||
Log::info('YDContainer catch ' . json_encode($containerReference));
|
||||
if(!($packingList->owner instanceof Order)) return;
|
||||
|
||||
$originWarehouse = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee;
|
||||
|
||||
+8
-3
@@ -61,11 +61,13 @@ class FetchContainersUpdatesFromYdPortalV2Processor
|
||||
$time_start = microtime(true);
|
||||
|
||||
$packingList = $container->packingLists()->first();
|
||||
|
||||
$reference = $packingList->reference;
|
||||
$trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [
|
||||
'trakingno' => $packingList->reference
|
||||
'trakingno' => $reference
|
||||
]);
|
||||
|
||||
Log::info('YDContainerUpdates reference ' . $reference);
|
||||
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest);
|
||||
|
||||
if(!$rows->data){
|
||||
@@ -78,6 +80,8 @@ class FetchContainersUpdatesFromYdPortalV2Processor
|
||||
$checkShipArrivalDate = null;
|
||||
|
||||
foreach (array_reverse($rows->data) as $trackingRow) {
|
||||
Log::info('YDContainerUpdates trackingRow ' . json_encode($trackingRow));
|
||||
|
||||
$rescheduleETD = strpos($trackingRow->remark, '开') || strpos($trackingRow->remark, '到港');
|
||||
$rescheduleETA = strpos($trackingRow->remark, '到港');
|
||||
|
||||
@@ -150,9 +154,10 @@ class FetchContainersUpdatesFromYdPortalV2Processor
|
||||
if($delayDate){
|
||||
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
Log::info('YDContainerUpdates delayDate ' . json_encode($transport));
|
||||
if(!$transport->schedules()->whereDate('eta', '>=', $delayDate)->first()) {
|
||||
$etd = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()->etd;
|
||||
Log::info('YDContainerUpdates etd ' . json_encode($etd));
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $delayDate, ApprovalStatus::APPROVED));
|
||||
foreach ($container->packingLists as $packingList){
|
||||
|
||||
+6
@@ -159,17 +159,21 @@ class FetchPackingListsFromYdPortalV2Processor
|
||||
|
||||
try{
|
||||
$packingList = $this->fetchesPackingList->execute(['reference' => $row->expressno, 'type' => PackingListType::SHIPPING_PACKING_LIST]);
|
||||
Log::info('Fetch SHIPPING_PACKING_LIST id: ' . $packingList->id);
|
||||
|
||||
$packingList->packages()->delete();
|
||||
$replica = $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first();
|
||||
if($replica) $replica->packages()->delete();
|
||||
|
||||
$warehouseReceiveList = $this->fetchesPackingList->execute(['reference' => $row->expressno, 'type' => PackingListType::WAREHOUSE_RECEIVE_LIST]);
|
||||
Log::info('Fetch WAREHOUSE_RECEIVE_LIST id: ' . $warehouseReceiveList->id);
|
||||
|
||||
$warehouseReceiveList->packages()->delete();
|
||||
$replica = $warehouseReceiveList->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA)->first();
|
||||
if($replica) $replica->packages()->delete();
|
||||
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
Log::info('SHIPPING_PACKING_LIST/WAREHOUSE_RECEIVE_LIST NOT FOUND');
|
||||
|
||||
if (!$allow_contract) {
|
||||
$appointee_id = 2307;
|
||||
@@ -181,6 +185,7 @@ class FetchPackingListsFromYdPortalV2Processor
|
||||
|
||||
/** @var PackingList $warehouseReceiveList */
|
||||
$warehouseReceiveList = $this->createPackingListProcessor->execute($warehouseReceiveObject, $order);
|
||||
Log::info('Create WAREHOUSE_RECEIVE_LIST id: ' . $warehouseReceiveList->id);
|
||||
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
$transport = $this->createsTransport->execute($transportObject, $warehouseReceiveList);
|
||||
@@ -209,6 +214,7 @@ class FetchPackingListsFromYdPortalV2Processor
|
||||
|
||||
/** @var PackingList $packingList */
|
||||
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
|
||||
Log::info('Create SHIPPING_PACKING_LIST id: ' . $packingList->id);
|
||||
|
||||
if ($allow_contract) {
|
||||
foreach ($contractObligations as $obligation) {
|
||||
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Processors\V3;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
||||
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\Notifications\ShipmentRescheduleEmail;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Models\Container;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\YDOrderTracking;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchContainersUpdatesYdPortalV3Processor
|
||||
{
|
||||
|
||||
/** @var UpdatesContractObligation */
|
||||
private $updatesContractObligations;
|
||||
|
||||
/** @var CreatesSchedule */
|
||||
private $createsSchedule;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* @param UpdatesContractObligation $updatesContractObligations
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(UpdatesContractObligation $updatesContractObligations, CreatesSchedule $createsSchedule, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
{
|
||||
$this->updatesContractObligations = $updatesContractObligations;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
* @return void
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Container $container)
|
||||
{
|
||||
Log::info('FetchContainersUpdatesFromYdPortalV2Processor starts with container id ' . $container->id . ' created_at ' . $container->created_at);
|
||||
// return;
|
||||
|
||||
$time_start = microtime(true);
|
||||
|
||||
$packingList = $container->packingLists()->first();
|
||||
$reference = $packingList->reference;
|
||||
|
||||
Log::info('FetchContainersUpdatesFromYdPortalV2Processor starts with packingList id ' . $packingList->id . ' created_at ' . $packingList->created_at);
|
||||
Log::info('FetchContainersUpdatesFromYdPortalV2Processor starts with reference ' . $reference);
|
||||
if (!$container->created_at->greaterThanOrEqualTo(Carbon::now()->subYear())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trackingRows = YDOrderTracking::where('tracking_no', $reference)->get();
|
||||
Log::info('YDContainerUpdates trackingRows ' . (count($trackingRows) > 0 ? json_encode($trackingRows) : 'NOT FOUND'));
|
||||
Log::info('YDContainerUpdates order ' . json_encode($packingList->owner));
|
||||
|
||||
$unstuffingDate = null;
|
||||
$delayETADate = null;
|
||||
$delayETDDate = null;
|
||||
$checkShipSailDate = null;
|
||||
$checkShipArrivalDate = null;
|
||||
|
||||
foreach ($trackingRows as $trackingRow) {
|
||||
if($trackingRow->eta){
|
||||
if(!$delayETADate){
|
||||
$delayETADate = Carbon::parse($trackingRow->eta);
|
||||
}
|
||||
if(Carbon::parse($trackingRow->eta) > $delayETADate){
|
||||
$delayETADate = Carbon::parse($trackingRow->eta);
|
||||
}
|
||||
}
|
||||
|
||||
if($trackingRow->etd){
|
||||
if(!$delayETDDate){
|
||||
$delayETDDate = Carbon::parse($trackingRow->etd);
|
||||
}
|
||||
if(Carbon::parse($trackingRow->etd) > $delayETDDate){
|
||||
$delayETDDate = Carbon::parse($trackingRow->etd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($delayETDDate && $delayETADate && $delayETDDate->isAfter($delayETADate)){
|
||||
$delayETADate = null;
|
||||
}
|
||||
|
||||
foreach ($trackingRows as $trackingRow) {
|
||||
if ($trackingRow->tracking === '到港') {
|
||||
Log::info('YDContainerUpdates - 到港 delayDate ' . $delayETADate);
|
||||
Log::info('YDContainerUpdates - 到港 $trackingRow->tracking_time ' . $trackingRow->tracking_time);
|
||||
$delayETADate = Carbon::parse($trackingRow->tracking_time);
|
||||
$checkShipArrivalDate = Carbon::parse($trackingRow->tracking_time);
|
||||
}
|
||||
|
||||
if ($trackingRow->tracking === '已开船') {
|
||||
Log::info('YDContainerUpdates - 已开船 delayDate ' . $delayETADate);
|
||||
if(!$delayETADate){
|
||||
Log::info('YDContainerUpdates - 已开船 $trackingRow->tracking_time add 5 days ' . $trackingRow->tracking_time);
|
||||
$delayETADate = Carbon::parse($trackingRow->tracking_time)->addDays('5');
|
||||
}
|
||||
$checkShipSailDate = Carbon::parse($trackingRow->tracking_time);
|
||||
}
|
||||
|
||||
if ($trackingRow->tracking === '货物已进目的港仓库' || $trackingRow->tracking === '第三方提货') {
|
||||
Log::info('YDContainerUpdates - 货物已进目的港仓库 delayDate ' . $delayETADate);
|
||||
$unstuffingDate = Carbon::parse($trackingRow->tracking_time);
|
||||
}
|
||||
}
|
||||
|
||||
if($checkShipSailDate){
|
||||
//check if ship has sailed
|
||||
if($checkShipSailDate->isPast()){
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::SHIP_SAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($checkShipArrivalDate){
|
||||
//check if ship has arrived at destination
|
||||
if($checkShipArrivalDate->isPast()){
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::SHIP_ARRIVED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($delayETADate){
|
||||
Log::info('YDContainerUpdates delayETADate ' . $delayETADate);
|
||||
$transport = $container->transports()->first();
|
||||
Log::info('YDContainerUpdates transport ' . json_encode($transport));
|
||||
if(!$transport->schedules()->whereDate('eta', '>=', $delayETADate)->first()) { //If no record
|
||||
$etd = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()->etd;
|
||||
if($delayETDDate > Carbon::parse($etd)){
|
||||
$etd = $delayETDDate;
|
||||
Log::info('YDContainerUpdates new etd');
|
||||
}
|
||||
Log::info('YDContainerUpdates etd ' . json_encode($etd));
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $delayETADate, ApprovalStatus::APPROVED));
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(!($packingList->owner instanceof Order)) continue;
|
||||
$user = $packingList->owner->companyModule->employees()->first();
|
||||
if(app()->environment(['production'])) {
|
||||
$user->notify(new ShipmentRescheduleEmail($user, $packingList));
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
Log::info('YDContainerUpdates NO DELAY (ETA)');
|
||||
}
|
||||
}
|
||||
else if($delayETDDate){
|
||||
//Runs when delayETDDate is available but NOT delayETADate
|
||||
Log::info('YDContainerUpdates delayETDDate ' . $delayETDDate);
|
||||
$transport = $container->transports()->first();
|
||||
Log::info('YDContainerUpdates transport ' . json_encode($transport));
|
||||
if(!$transport->schedules()->whereDate('etd', '>=', $delayETDDate)->first()) { //If no record
|
||||
$eta = $delayETDDate->copy()->addDays(5);
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($delayETDDate, $eta, ApprovalStatus::APPROVED));
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(!($packingList->owner instanceof Order)) continue;
|
||||
$user = $packingList->owner->companyModule->employees()->first();
|
||||
if(app()->environment(['production'])) {
|
||||
$user->notify(new ShipmentRescheduleEmail($user, $packingList));
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
Log::info('YDContainerUpdates NO DELAY (ETD)');
|
||||
}
|
||||
}
|
||||
|
||||
if($unstuffingDate){
|
||||
$container->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
$container->transports()->first()->update(['drop_date' => $unstuffingDate, 'status' => ApprovalStatus::COMPLETED]);
|
||||
|
||||
/** @var PackingList $packingList */
|
||||
foreach($container->packingLists as $packingList){
|
||||
|
||||
if($packingList->status === ApprovalStatus::PENDING_VERIFICATION){
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
}
|
||||
|
||||
if(!($packingList->owner instanceof Order)) continue;
|
||||
|
||||
$signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture;
|
||||
foreach($packingList->steps()->where('reference', '!=', 'DELIVERY')->get() as $step){
|
||||
if(app()->environment(['production'])) {
|
||||
$this->updatesContractObligations->execute($signature, $step->obligation_hash_id);
|
||||
}
|
||||
$step->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
}
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::UNSTUFFING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$time_end = microtime(true);
|
||||
|
||||
$execution_time = ($time_end - $time_start)/60;
|
||||
|
||||
Log::info('FetchContainersUpdatesFromYdPortalV2Processor ends with container id ' . $container->id . ' => Total Execution Time: '.$execution_time.' Mins.');
|
||||
Log::info('---');
|
||||
}
|
||||
}
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Processors\V3;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\AccessForbiddenException;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\RequestValidationException;
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\Modules\PackingLists\Processors\CreateContainerProcessor;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
|
||||
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
||||
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
|
||||
use App\Classes\Modules\Transports\Services\CreatesTransport;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\ContainerTypes;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Models\Container;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transport;
|
||||
use App\Models\YDOrderTracking;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchContainersYdPortalV3Processor
|
||||
{
|
||||
/** @var CreatesTransport */
|
||||
private $createsTransport;
|
||||
|
||||
/** @var CreatesSchedule */
|
||||
private $createsSchedule;
|
||||
|
||||
/** @var FetchesContainer */
|
||||
private $fetchesContainer;
|
||||
|
||||
/** @var CreateContainerProcessor */
|
||||
private $createContainerProcessor;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* @param CreatesTransport $createsTransport
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param FetchesContainer $fetchesContainer
|
||||
* @param CreateContainerProcessor $createContainerProcessor
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, FetchesContainer $fetchesContainer, CreateContainerProcessor $createContainerProcessor, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
{
|
||||
$this->createsTransport = $createsTransport;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->fetchesContainer = $fetchesContainer;
|
||||
$this->createContainerProcessor = $createContainerProcessor;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingList $packingList
|
||||
* @return void
|
||||
* @throws MalformedRequestException
|
||||
* @throws AccessForbiddenException
|
||||
* @throws RequestValidationException
|
||||
*/
|
||||
public function execute(PackingList $packingList)
|
||||
{
|
||||
Log::info('FetchContainersFromYdPortalV2Processor starts with packingList id '. $packingList->id);
|
||||
// return;
|
||||
|
||||
$time_start = microtime(true);
|
||||
|
||||
$containerReference = null;
|
||||
$loadingDate = null;
|
||||
$etd = null;
|
||||
$eta = null;
|
||||
$reference = $packingList->reference;
|
||||
|
||||
Log::info('YDContainer reference ' . $reference);
|
||||
$trackingRows = YDOrderTracking::where('tracking_no', $reference)->get();
|
||||
Log::info('YDContainer trackingRows ' . json_encode($trackingRows));
|
||||
|
||||
foreach ($trackingRows as $trackingRow) {
|
||||
if (strpos($trackingRow->tracking, '货物装柜完成。') !== false) {
|
||||
$tracking = explode(':', $trackingRow->tracking);
|
||||
$containerReference = explode('预计到港时间', $tracking[1])[0];
|
||||
$loadingDate = Carbon::parse($trackingRow->tracking_time);
|
||||
$etd = Carbon::parse($tracking[2])->subDays(5);
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('YDContainer containerReference ' . json_encode($containerReference));
|
||||
|
||||
if($containerReference) {
|
||||
try {
|
||||
Log::info('YDContainer try');
|
||||
$container = $this->fetchesContainer->execute(['reference' => $containerReference]);
|
||||
$container->packingLists()->detach($packingList);
|
||||
$container->packingLists()->attach($packingList);
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
Log::info('YDContainer catch');
|
||||
if(!($packingList->owner instanceof Order)) return;
|
||||
|
||||
$originWarehouse = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee;
|
||||
|
||||
|
||||
$containerObject = new ContainerObject($containerReference, '', '', ContainerTypes::FORTY_FEET_DRY_CONTAINER, $loadingDate, ApprovalStatus::PENDING_VERIFICATION);
|
||||
|
||||
/** @var Container $container */
|
||||
$container = $this->createContainerProcessor->execute($containerObject, $originWarehouse);
|
||||
|
||||
$container->packingLists()->detach($packingList);
|
||||
$container->packingLists()->attach($packingList);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::LOAD_CONTAINER);
|
||||
}
|
||||
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport){
|
||||
$transportObject = new TransportObject(TransportType::SEA, null, null, $etd, null, ApprovalStatus::APPROVED);
|
||||
/** @var Transport $transport */
|
||||
$transport = $this->createsTransport->execute($transportObject, $container);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $eta, ApprovalStatus::APPROVED));
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('YDContainer loadingDate ' . $loadingDate);
|
||||
Log::info('YDContainer etd ' . $etd);
|
||||
Log::info('YDContainer eta ' . $eta);
|
||||
}
|
||||
|
||||
$time_end = microtime(true);
|
||||
|
||||
$execution_time = ($time_end - $time_start)/60;
|
||||
|
||||
Log::info('FetchContainersFromYdPortalV2Processor ends with packingList id '. $packingList->id . ' => Total Execution Time: '.$execution_time.' Mins.');
|
||||
Log::info('---');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rules\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\CriteriaNotFulfilledException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rules\DataTransferObjects\CheckEInvoiceRuleDTO;
|
||||
use App\Classes\Modules\Rules\Services\RuleEvaluator;
|
||||
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
|
||||
use App\Classes\Modules\Rules\Standards\Rules\CanPassTINRule;
|
||||
use App\Http\Resources\RuleResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckEInvoiceRuleLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Rule Check E-Invoice',
|
||||
'message' => 'You have successfully passed all rules evaluated'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var RuleEvaluator */
|
||||
private $ruleEvaluator;
|
||||
|
||||
/** @var CanPassEInvoicePromptedRule */
|
||||
private $canPassEInvoicePromptedRule;
|
||||
|
||||
/** @var CanPassTINRule */
|
||||
private $canPassTINRule;
|
||||
|
||||
/**
|
||||
* CheckEInvoiceRuleLogic constructor.
|
||||
*/
|
||||
public function __construct(RuleEvaluator $ruleEvaluator, CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule, CanPassTINRule $canPassTINRule)
|
||||
{
|
||||
$this->ruleEvaluator = $ruleEvaluator;
|
||||
$this->canPassEInvoicePromptedRule = $canPassEInvoicePromptedRule;
|
||||
$this->canPassTINRule = $canPassTINRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
* @throws \App\Classes\Exceptions\CriteriaNotFulfilledException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$dto = new CheckEInvoiceRuleDTO($request->all());
|
||||
|
||||
$result = $this->ruleEvaluator->evaluate([
|
||||
$this->canPassEInvoicePromptedRule,
|
||||
$this->canPassTINRule,
|
||||
], $dto);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new CriteriaNotFulfilledException("- " . implode("<br>- ", $result->messages()));
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new RuleResource((object)$result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rules\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class CheckEInvoiceRuleDTO implements DataTransferObject
|
||||
{
|
||||
public int $companyModuleId;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->companyModuleId = $data['company_module_id'];
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'company_module_id' => $this->companyModuleId,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rules\Services;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\Exceptions\AccessForbiddenException;
|
||||
use App\Classes\Exceptions\CriteriaNotFulfilledException;
|
||||
use App\Classes\Exceptions\RequestValidationException;
|
||||
use App\Classes\ValueObjects\Response\RuleEvaluationResult;
|
||||
|
||||
class RuleEvaluator //For using AbstractRule
|
||||
{
|
||||
/**
|
||||
* Evaluate multiple rules.
|
||||
*
|
||||
* @param AbstractRule[] $rules
|
||||
* @param DataTransferObject|null $object
|
||||
* @return RuleEvaluationResult
|
||||
*/
|
||||
public function evaluate(array $rules, ?DataTransferObject $object = null): RuleEvaluationResult
|
||||
{
|
||||
$messages = [];
|
||||
$success = true;
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
try {
|
||||
if (!$rule->passes($object)) {
|
||||
$success = false;
|
||||
$messages[] = get_class($rule) . ' failed without exception';
|
||||
}
|
||||
} catch (AccessForbiddenException | RequestValidationException | CriteriaNotFulfilledException $e) {
|
||||
$success = false;
|
||||
$messages[] = $e->getMessage();
|
||||
} catch (\Exception $e) {
|
||||
$success = false;
|
||||
$messages[] = 'Unexpected error in ' . get_class($rule) . ': ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return new RuleEvaluationResult($success, $messages);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rules\Standards\Rules;
|
||||
|
||||
use App\Classes\Exceptions\CriteriaNotFulfilledException;
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CanPassEInvoicePromptedRule extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/**
|
||||
* CanPassEInvoicePromptedRule constructor.
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
*/
|
||||
public function __construct(FetchesCompanyModule $fetchesCompanyModule)
|
||||
{
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
//Check if account requires E-Invoice
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $object->companyModuleId]);
|
||||
if($companyModule->company->e_invoice === null){
|
||||
throw new CriteriaNotFulfilledException("Please refresh page to answer question related to E-Invoice.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user