mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
180 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 | |||
| 2cbee23234 | |||
| dca9682c59 | |||
| a7aad5373b | |||
| cad314d6a7 | |||
| 137dfe0669 | |||
| 52b839c741 | |||
| 679bb9978a | |||
| 2c6b8ac7ea | |||
| 9b7a5a6f1e | |||
| 1a318ead7e | |||
| bd8b212f6f | |||
| 59fbdfa789 | |||
| 2bd96075cc | |||
| c046a533d8 | |||
| 8e6c70c67b | |||
| 878e69fdb0 | |||
| e047632de0 | |||
| 8d75da288a | |||
| ab5a94cbc0 | |||
| ba1b287cbb | |||
| 40d133aaab | |||
| d52a52241c | |||
| 218f0f8bca |
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
+35
-1
@@ -28,6 +28,40 @@ class PackingListLimitOneByTypeOrderedByInvoiceDate implements Filter
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,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 . '.');
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,12 @@ class OneTimeTransactionFixBillplzFailedCbV2CommandJob implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - One time fix failled callback from billplz cron ended.');
|
||||
Log::info(Carbon::now() . ': Start job - One time fix failled callback from billplz.');
|
||||
$start = new Carbon();
|
||||
|
||||
//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
|
||||
$transactions = Transaction::whereIn('id', [22008, 6770])->get();
|
||||
Log::info(Carbon::now() . ' : One time fix failled callback from billplz started.');
|
||||
|
||||
foreach ($transactions as $transaction){
|
||||
if($transaction){
|
||||
@@ -40,6 +39,6 @@ class OneTimeTransactionFixBillplzFailedCbV2CommandJob implements ShouldQueue
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - One time fix failled callback from billplz 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,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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,17 @@ 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\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
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;
|
||||
@@ -67,6 +72,13 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
/** @var UpdatesDocumentReference */
|
||||
private $updatesDocumentReference;
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFile;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateCompanyDetailsLogic constructor.
|
||||
* @param CanUpdateCompany $canUpdateCompany
|
||||
@@ -79,7 +91,8 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
* @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo;
|
||||
* @param FetchesDocument $fetchesDocument
|
||||
* @param UpdatesDocumentReference $updatesDocumentReference
|
||||
*
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFile
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateCompany $canUpdateCompany,
|
||||
@@ -92,7 +105,9 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo,
|
||||
UpdatesCompanyModuleName $updatesCompanyModuleName,
|
||||
FetchesDocument $fetchesDocument,
|
||||
UpdatesDocumentReference $updatesDocumentReference
|
||||
UpdatesDocumentReference $updatesDocumentReference,
|
||||
CreatesDocument $createsDocument,
|
||||
CreatesFiles $createsFile
|
||||
)
|
||||
{
|
||||
$this->canUpdateCompany = $canUpdateCompany;
|
||||
@@ -106,6 +121,8 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
$this->updatesCompanyModuleName = $updatesCompanyModuleName;
|
||||
$this->fetchesDocument = $fetchesDocument;
|
||||
$this->updatesDocumentReference = $updatesDocumentReference;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFile = $createsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,6 +163,26 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
|
||||
$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));
|
||||
}
|
||||
|
||||
@@ -101,6 +101,13 @@ class UpdateCompanyEInvoiceInfoLogic extends AbstractControllerLogic
|
||||
$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);
|
||||
|
||||
|
||||
@@ -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
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
|
||||
@@ -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,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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
+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([])));
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ 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 `FetchOrderPackagesV2Logic` instead or write a new one based on FetchOrderPackagesV2Logic
|
||||
* Use `FetchOrderPackagesReceivedV2Logic` instead or write a new one based on FetchOrderPackagesReceivedV2Logic
|
||||
*/
|
||||
class FetchOrderPackagesLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -74,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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,10 +6,11 @@ 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 App\Http\Resources\OrderPackagesResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class FetchOrderPackagesV2Logic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
@@ -49,11 +50,7 @@ class FetchOrderPackagesV2Logic extends AbstractControllerLogic
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -162,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));
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,8 @@ 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;
|
||||
@@ -73,4 +74,4 @@ class CreatePackageProcessor
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+34
-14
@@ -3,6 +3,7 @@
|
||||
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;
|
||||
@@ -19,14 +20,19 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
/** @var CreatesChatGPTResponse */
|
||||
private $createsChatGPTResponse;
|
||||
|
||||
/** @var CreatesClaudeResponse */
|
||||
private $createsClaudeResponse;
|
||||
|
||||
/**
|
||||
* @param FetchesDataFromYDPortal $fetchesDataFRomYDPortal
|
||||
* @param CreatesChatGPTResponse $createsChatGPTResponse
|
||||
* @param CreatesClaudeResponse $createsClaudeResponse
|
||||
*/
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, CreatesChatGPTResponse $createsChatGPTResponse)
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, CreatesChatGPTResponse $createsChatGPTResponse, CreatesClaudeResponse $createsClaudeResponse)
|
||||
{
|
||||
$this->fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal;
|
||||
$this->createsChatGPTResponse = $createsChatGPTResponse;
|
||||
$this->createsClaudeResponse = $createsClaudeResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,9 +135,9 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
else{
|
||||
$isUpdated = false;
|
||||
if($item['tracking']){
|
||||
$isTranslatedPreviouly = $this->checkIfTranslationAlreadyExist(!empty($item['tracking']) ? $item['tracking'] : "");
|
||||
$result = $isTranslatedPreviouly;
|
||||
if (!$isTranslatedPreviouly){
|
||||
$isTranslatedPreviously = $this->checkIfTranslationAlreadyExist(!empty($item['tracking']) ? $item['tracking'] : "");
|
||||
$result = $isTranslatedPreviously;
|
||||
if (!$isTranslatedPreviously){
|
||||
$result = $this->translateTracking($item['tracking']);
|
||||
}
|
||||
if ($result && $existingRecord->tracking_english !== $result) {
|
||||
@@ -143,9 +149,9 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
}
|
||||
|
||||
if($item['remark']) {
|
||||
$isTranslatedPreviouly = $this->checkIfTranslationAlreadyExist(!empty($item['remark']) ? $item['remark'] : "");
|
||||
$result = $isTranslatedPreviouly;
|
||||
if (!$isTranslatedPreviouly){
|
||||
$isTranslatedPreviously = $this->checkIfTranslationAlreadyExist(!empty($item['remark']) ? $item['remark'] : "");
|
||||
$result = $isTranslatedPreviously;
|
||||
if (!$isTranslatedPreviously){
|
||||
$result = $this->translateTracking($item['remark']);
|
||||
}
|
||||
|
||||
@@ -189,7 +195,7 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
$trackingDate = Carbon::parse($trackingtime);
|
||||
$trackingYear = $trackingDate->year;
|
||||
|
||||
if($remark && preg_match('/\b\d{1,2}[-\/.]\d{1,2}\b/', $remark) && $eta === null && $etd === null){
|
||||
if($remark && $eta === null && $etd === null){
|
||||
$existingRecord = YDOrderTracking::where('remark', $remark)->where(function ($query) {
|
||||
$query->whereNotNull('eta')
|
||||
->orWhereNotNull('etd');
|
||||
@@ -203,14 +209,27 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
];
|
||||
}
|
||||
|
||||
$userPrompt = "Show me the answer in json string without escape, e.g. {'ETA': '', 'ETD': ''}. ".$remark." What is the ETA and ETD?";
|
||||
$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->createsChatGPTResponse->execute($userPrompt);
|
||||
$result = $this->createsClaudeResponse->execute($userPrompt);
|
||||
Log::info('result (json_encoded): '.json_encode($result));
|
||||
$content = $result['choices'][0]['message']['content'] ?? null;
|
||||
// $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(str_replace("'", '"', $content), true);
|
||||
$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']);
|
||||
@@ -310,9 +329,10 @@ class FetchByTrakingNoYdPortalV2Processor
|
||||
{
|
||||
$userPrompt = "Please translate mandarin to english and return result in this format, e.g. {'mandarin': '.$textToTranslate.', 'english': ''}. ".$textToTranslate." ";
|
||||
Log::info('prompt: '.$userPrompt);
|
||||
$result = $this->createsChatGPTResponse->execute($userPrompt);
|
||||
$result = $this->createsClaudeResponse->execute($userPrompt);
|
||||
Log::info('result (json_encoded): '.json_encode($result));
|
||||
$content = $result['choices'][0]['message']['content'] ?? null;
|
||||
// $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);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\Commands\V2\ReleaseGoodsToCustomerV2CommandJob;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
@@ -23,7 +24,7 @@ use App\Http\Resources\WalletTransactionResource;
|
||||
use App\Models\Wallet;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateGroupsLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -226,8 +227,11 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $reqBankCode, false);
|
||||
|
||||
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
$pL = $invoice->owner;
|
||||
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
|
||||
// $pL = $invoice->owner;
|
||||
// $this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
|
||||
$obj = json_encode($invoice);
|
||||
Log::info("Preparing to release goods for invoice: {$obj}");
|
||||
ReleaseGoodsToCustomerV2CommandJob::dispatch($invoice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,12 @@ use App\Classes\Modules\Transactions\Services\FetchesGroup;
|
||||
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\DeletesGroup;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeleteGroupLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -48,7 +52,7 @@ class DeleteGroupLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
|
||||
|
||||
@@ -59,7 +63,12 @@ class DeleteGroupLogic extends AbstractControllerLogic
|
||||
|
||||
$this->deletesGroup->execute($group);
|
||||
|
||||
$topUpTransaction = Transaction::where('payment_reference', $group->reference)->first();
|
||||
if($topUpTransaction && $topUpTransaction->type === TransactionType::TOP_UP && $topUpTransaction->status !== ApprovalStatus::APPROVED && $topUpTransaction->status !== ApprovalStatus::COMPLETED){
|
||||
$topUpTransaction->delete();
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesGroup;
|
||||
use App\Classes\Modules\Transactions\Standards\Rules\CanFetchTransaction;
|
||||
use App\Http\Resources\GroupPaidInvoicePNBPageResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchGroupLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Fetched Group',
|
||||
'message' => 'You have successfully retrieved a Group'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchTransaction */
|
||||
private $canFetchTransaction;
|
||||
|
||||
/** @var FetchesGroup */
|
||||
private $fetchesGroup;
|
||||
|
||||
/**
|
||||
* FetchGroupLogic constructor.
|
||||
* @param CanFetchTransaction $canFetchTransaction
|
||||
* @param FetchesGroup $fetchesGroup
|
||||
*/
|
||||
public function __construct(CanFetchTransaction $canFetchTransaction, FetchesGroup $fetchesGroup)
|
||||
{
|
||||
$this->canFetchTransaction = $canFetchTransaction;
|
||||
$this->fetchesGroup = $fetchesGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchTransaction->passes();
|
||||
|
||||
$query = $this->fetchesGroup->execute(['id' => $request->route('group_id')]);
|
||||
|
||||
return $this->resourceResponse(new GroupPaidInvoicePNBPageResource($query));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Standards\Rules\CanFetchTransaction;
|
||||
use App\Http\Resources\TransactionWithStorageResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Fetched Transaction',
|
||||
'message' => 'You have successfully retrieved a Transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchTransaction */
|
||||
private $canFetchTransaction;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/**
|
||||
* FetchTransactionLogic constructor.
|
||||
* @param CanFetchTransaction $canFetchTransaction
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
*/
|
||||
public function __construct(CanFetchTransaction $canFetchTransaction, FetchesTransaction $fetchesTransaction)
|
||||
{
|
||||
$this->canFetchTransaction = $canFetchTransaction;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchTransaction->passes();
|
||||
|
||||
$query = $this->fetchesTransaction->execute(['id' => $request->route('transaction_id')]);
|
||||
|
||||
if($request->input('storages')){
|
||||
$query->storages = $request->input('storages'); //from middleware
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new TransactionWithStorageResource($query));
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsGroups;
|
||||
use App\Http\Resources\GroupPaidInvoicesPNBPageResource;
|
||||
use App\Http\Resources\GroupResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListGroupsLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -34,9 +36,17 @@ class ListGroupsLogic extends AbstractControllerLogic
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$filtersJson = $request->input('filters');
|
||||
$filters = is_string($filtersJson) ? json_decode($filtersJson, true) : $filtersJson;
|
||||
$section = $filters['section'] ?? null;
|
||||
|
||||
$query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(GroupResource::collection($query));
|
||||
if($section === 'customerPaidGroupInvoiceComponent'){
|
||||
return $this->collectionResponse(GroupPaidInvoicesPNBPageResource::collection($query));
|
||||
}
|
||||
else{
|
||||
return $this->collectionResponse(GroupResource::collection($query));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Http\Resources\TransactionWithStorageResource;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -36,11 +35,14 @@ class ListTransactionsLogic extends AbstractControllerLogic
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
||||
foreach ($query->items() as $item) {
|
||||
if($item instanceof \App\Models\Transaction && $item->owner->owner->companyModule){
|
||||
$item['is_einvoice_applicable'] = $item->owner->owner->companyModule->company->e_invoice === 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($request->input('storages')){
|
||||
foreach ($query->items() as $item) {
|
||||
@@ -50,11 +52,7 @@ class ListTransactionsLogic extends AbstractControllerLogic
|
||||
});
|
||||
$item['storages'] = $filteredStorages;
|
||||
}
|
||||
//return $this->collectionResponse(TransactionWithStorageResource::collection($query));
|
||||
}
|
||||
// else{
|
||||
// return $this->collectionResponse(TransactionResource::collection($query));
|
||||
//
|
||||
return $this->collectionResponse(TransactionWithStorageResource::collection($query));
|
||||
}
|
||||
}
|
||||
|
||||
+10
-38
@@ -4,18 +4,12 @@
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
||||
|
||||
class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -29,23 +23,20 @@ class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
/** @var CreateShippingInvoiceTransactionDocProcessor */
|
||||
private $createShippingInvoiceTransactionDocProcessor;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
public function __construct(CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->createShippingInvoiceTransactionDocProcessor = $createShippingInvoiceTransactionDocProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
return $this->response([]); //The business logic to generate normal invoice and e-invoice no longer so straight forward
|
||||
|
||||
$orders = Order::where('company_module_id', $request->route('company_module_id'))->get();
|
||||
|
||||
@@ -53,28 +44,10 @@ class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
$invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get();
|
||||
foreach ($invoices as $invoice){
|
||||
|
||||
$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'
|
||||
);
|
||||
|
||||
$document =$this->createsDocument->execute($invoice, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
$this->createShippingInvoiceTransactionDocProcessor->execute($invoice);
|
||||
|
||||
// dump($document);
|
||||
}
|
||||
@@ -82,5 +55,4 @@ class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateSalesOrderDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
|
||||
class RegenerateSingleSalesOrderLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Regenerate Sales Order',
|
||||
'message' => 'You have successfully regenerated sales order'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateSalesOrderDocProcessor */
|
||||
private $createSalesOrderDocProcessor;
|
||||
|
||||
/**
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreateSalesOrderDocProcessor $createSalesOrderDocProcessor
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateSalesOrderDocProcessor $createSalesOrderDocProcessor)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createSalesOrderDocProcessor = $createSalesOrderDocProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
|
||||
$invoice->documents()->where('document_type', DocumentType::SALES_ORDER)->delete();
|
||||
|
||||
$this->createSalesOrderDocProcessor->execute($invoice);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingEInvoiceDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
|
||||
class RegenerateSingleShippingEInvoiceLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Regenerate Shipping E-Invoice',
|
||||
'message' => 'You have successfully regenerated shipping e-invoice'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateShippingEInvoiceDocProcessor */
|
||||
private $createShippingEInvoiceDocProcessor;
|
||||
|
||||
/**
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreateShippingEInvoiceDocProcessor $createShippingEInvoiceDocProcessor
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateShippingEInvoiceDocProcessor $createShippingEInvoiceDocProcessor)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createShippingEInvoiceDocProcessor = $createShippingEInvoiceDocProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
|
||||
$invoice->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->delete();
|
||||
|
||||
$this->createShippingEInvoiceDocProcessor->execute($invoice);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
+11
-40
@@ -4,19 +4,11 @@
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
||||
|
||||
class RegenerateSingleShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -30,51 +22,30 @@ class RegenerateSingleShippingInvoiceTransactionLogic extends AbstractController
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateShippingInvoiceTransactionDocProcessor */
|
||||
private $createShippingInvoiceTransactionDocProcessor;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles, FetchesTransaction $fetchesTransaction)
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createShippingInvoiceTransactionDocProcessor = $createShippingInvoiceTransactionDocProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
|
||||
$invoice->documents()->delete();
|
||||
// $invoice->documents()->delete();
|
||||
$invoice->documents()->where('document_type', DocumentType::SHIPPING_INVOICE)->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'
|
||||
);
|
||||
|
||||
$document =$this->createsDocument->execute($invoice, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
$this->createShippingInvoiceTransactionDocProcessor->execute($invoice);
|
||||
|
||||
// dump($document);
|
||||
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateStorageEInvoiceDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
|
||||
class RegenerateSingleStorageEInvoiceLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Regenerate Storage E-Invoice',
|
||||
'message' => 'You have successfully regenerated storage e-invoice'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateStorageEInvoiceDocProcessor */
|
||||
private $createStorageEInvoiceDocProcessor;
|
||||
|
||||
/**
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreateStorageEInvoiceDocProcessor $createStorageEInvoiceDocProcessor
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateStorageEInvoiceDocProcessor $createStorageEInvoiceDocProcessor)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createStorageEInvoiceDocProcessor = $createStorageEInvoiceDocProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
|
||||
$invoice->documents()->where('document_type', DocumentType::STORAGE_EINVOICE)->delete();
|
||||
|
||||
$this->createStorageEInvoiceDocProcessor->execute($invoice);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
+14
-15
@@ -8,9 +8,10 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceDocTransactionFixProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceTransactionDocProcessor;
|
||||
use App\Classes\Modules\Transactions\Standards\Rules\CanRegenerateStorageInvoice;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -30,19 +31,21 @@ class RegenerateSingleStorageInvoiceTransactionLogic extends AbstractControllerL
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateStorageInvoiceDocTransactionFixProcessor */
|
||||
private $createStorageInvoiceDocTransactionProcessor;
|
||||
/** @var CreateStorageInvoiceTransactionDocProcessor */
|
||||
private $createStorageInvoiceTransactionDocProcessor;
|
||||
|
||||
/** @var CanRegenerateStorageInvoice */
|
||||
private $canRegenerateStorageInvoice;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreateStorageInvoiceTransactionDocProcessor $createStorageInvoiceTransactionDocProcessor
|
||||
* @param CanRegenerateStorageInvoice $canRegenerateStorageInvoice
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateStorageInvoiceDocTransactionFixProcessor $createStorageInvoiceDocTransactionProcessor, CanRegenerateStorageInvoice $canRegenerateStorageInvoice)
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateStorageInvoiceTransactionDocProcessor $createStorageInvoiceTransactionDocProcessor, CanRegenerateStorageInvoice $canRegenerateStorageInvoice)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createStorageInvoiceDocTransactionProcessor = $createStorageInvoiceDocTransactionProcessor;
|
||||
$this->createStorageInvoiceTransactionDocProcessor = $createStorageInvoiceTransactionDocProcessor;
|
||||
$this->canRegenerateStorageInvoice = $canRegenerateStorageInvoice;
|
||||
}
|
||||
|
||||
@@ -51,17 +54,13 @@ class RegenerateSingleStorageInvoiceTransactionLogic extends AbstractControllerL
|
||||
$this->canRegenerateStorageInvoice->passes();
|
||||
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
$packingList = $invoice->owner;
|
||||
$order = $packingList->owner;
|
||||
$invoices = $order->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->get();
|
||||
$invoice->documents()->where('document_type', DocumentType::STORAGE_INVOICE)->delete();
|
||||
|
||||
foreach ($invoices as $invoice){
|
||||
if($invoice->id === (int) $request->route('invoice_id')){
|
||||
$invoice->documents()->delete();
|
||||
}
|
||||
}
|
||||
/** @var Transaction $invoice_transaction */
|
||||
// $invoice_transaction = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('status', [ApprovalStatus::COMPLETED])->first();
|
||||
|
||||
$this->createStorageInvoiceTransactionDocProcessor->execute($invoice);
|
||||
|
||||
$this->createStorageInvoiceDocTransactionProcessor->execute($packingList, true);
|
||||
Log::info(Auth::user()->email." regenerate storage invoice for transaction with id ".$request->route('invoice_id'));
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
+36
-42
@@ -8,18 +8,15 @@ use App\Classes\Notifications\InvoiceIssuedEmail;
|
||||
use App\Models\Document;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Jobs\CreatePerfexCRMInvoice;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingEInvoiceDocProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateSalesOrderDocProcessor;
|
||||
use App\Models\Order;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ApproveShippingInvoiceTransactionProcessor
|
||||
{
|
||||
@@ -27,27 +24,32 @@ class ApproveShippingInvoiceTransactionProcessor
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $storageInvoiceTransactionProcessor;
|
||||
|
||||
/** @var CreateShippingInvoiceTransactionDocProcessor */
|
||||
private $createShippingInvoiceTransactionDocProcessor;
|
||||
|
||||
/** @var CreateSalesOrderDocProcessor */
|
||||
private $createSalesOrderDocProcessor;
|
||||
|
||||
/** @var CreateShippingEInvoiceDocProcessor */
|
||||
private $createShippingEInvoiceDocProcessor;
|
||||
|
||||
/**
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
* @param CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor
|
||||
* @param CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor
|
||||
* @param CreateSalesOrderDocProcessor $createSalesOrderDocProcessor
|
||||
* @param CreateShippingEInvoiceDocProcessor $createShippingEInvoiceDocProcessor
|
||||
*/
|
||||
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
|
||||
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor, CreateShippingInvoiceTransactionDocProcessor $createShippingInvoiceTransactionDocProcessor, CreateSalesOrderDocProcessor $createSalesOrderDocProcessor, CreateShippingEInvoiceDocProcessor $createShippingEInvoiceDocProcessor)
|
||||
{
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
|
||||
$this->createShippingInvoiceTransactionDocProcessor = $createShippingInvoiceTransactionDocProcessor;
|
||||
$this->createSalesOrderDocProcessor = $createSalesOrderDocProcessor;
|
||||
$this->createShippingEInvoiceDocProcessor = $createShippingEInvoiceDocProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,40 +62,32 @@ class ApproveShippingInvoiceTransactionProcessor
|
||||
/** @var Transaction $invoice_transaction */
|
||||
$invoice_transaction = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::PENDING_SUBMISSION])->first();
|
||||
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice_transaction->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice_transaction->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
Log::info('company module einvoice: ' . json_encode($companyModule->company->e_invoice));
|
||||
|
||||
if($companyModule->company->e_invoice)
|
||||
{
|
||||
// $this->createShippingEInvoiceDocProcessor->execute($invoice_transaction);
|
||||
}
|
||||
else{
|
||||
$this->createShippingInvoiceTransactionDocProcessor->execute($invoice_transaction);
|
||||
}
|
||||
$this->createSalesOrderDocProcessor->execute($invoice_transaction);
|
||||
$this->updatesTransactionStatus->execute($invoice_transaction, ApprovalStatus::APPROVED);
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice_transaction]);
|
||||
|
||||
$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 = $this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
$user = $packingList->owner->companyModule->employees()->first();
|
||||
if(app()->environment(['production'])) {
|
||||
if(app()->environment(['production']) && $companyModule->company->e_invoice === 0) { //invoice issued email is only send to customer who has not opted in E-Invoice
|
||||
$companyModule = $packingList->owner->companyModule;
|
||||
$user = $companyModule->employees()->first();
|
||||
$user->notify(new InvoiceIssuedEmail($user, $packingList));
|
||||
}
|
||||
|
||||
$order = $packingList->owner()->first();
|
||||
if($order instanceof Order){
|
||||
$this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
// $this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
$is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term;
|
||||
$this->storageInvoiceTransactionProcessor->processByPackingList($packingList, $order, $is_credit_term);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+71
-25
@@ -17,8 +17,6 @@ use App\Classes\Modules\Transactions\Services\DeletesGroup;
|
||||
use App\Classes\Modules\Billplzs\Services\DeletesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -30,6 +28,7 @@ use App\Http\Resources\TransactionWithStorageResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\YDOrderTracking;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -68,6 +67,8 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
|
||||
private $defaultPricePerCBM = 3;
|
||||
|
||||
private $defaultNumberOfDaysFree = 5;
|
||||
|
||||
/**
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
@@ -153,24 +154,30 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function processByPackingList(PackingList $packingList, Order $order, bool $is_credit_term){
|
||||
$this->getResults($packingList, $order, $is_credit_term);
|
||||
}
|
||||
|
||||
private function getResults($packingList, $order, $is_credit_term){
|
||||
$results = [];
|
||||
$arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehoue($packingList);
|
||||
$arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehouse($packingList);
|
||||
LogHelper::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse));
|
||||
LogHelper::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList));
|
||||
$eta = $this->getEtaFromPackingList($packingList);
|
||||
if($arrivalDateAtChinaWarehouse && $eta){
|
||||
$dataTimeToCheckNew = $this->getTrackingTimeEnteredDestinationPortWarehouse($packingList); //trackingTimeEnteredDestinationPortWarehouse
|
||||
$dataTimeToCheckOld = $this->getEtaFromPackingList($packingList); //eta
|
||||
if($arrivalDateAtChinaWarehouse && $dataTimeToCheckNew){
|
||||
$transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
|
||||
// $transactions = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->where('transactions.status', ApprovalStatus::APPROVED)->get();
|
||||
|
||||
/** @var Transaction $invoice_transaction */
|
||||
foreach ($transactions as $invoice_transaction){
|
||||
LogHelper::channel('storage_invoices')->info('invoice_transaction bill_no: '. $invoice_transaction->bill_no);
|
||||
$result = null;
|
||||
if(!$is_credit_term){
|
||||
$result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $eta);
|
||||
$result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $dataTimeToCheckOld, $dataTimeToCheckNew);
|
||||
}
|
||||
else{
|
||||
$result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $eta);
|
||||
else {
|
||||
$result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $dataTimeToCheckOld, $dataTimeToCheckNew);
|
||||
}
|
||||
if($result){
|
||||
$results[] = $result;
|
||||
@@ -180,8 +187,9 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function getArrivalDateAtChinaWarehoue($packingList){
|
||||
private function getArrivalDateAtChinaWarehouse($packingList){
|
||||
if($packingList->type === PackingListType::SHIPPING_PACKING_LIST){
|
||||
LogHelper::channel('storage_invoices')->info('packingList reference: '.json_encode($packingList->reference));
|
||||
$receive_packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first();
|
||||
LogHelper::channel('storage_invoices')->info('receive_packing_list: '.json_encode($receive_packing_list->transports));
|
||||
$transport = $receive_packing_list->transports->first();
|
||||
@@ -199,6 +207,17 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getTrackingTimeEnteredDestinationPortWarehouse($packingList){
|
||||
if ($packingList) {
|
||||
$reference = $packingList->reference;
|
||||
$trackingRow = YDOrderTracking::where('tracking_no', $reference)->where('tracking', '货物已进目的港仓库')->first();
|
||||
if ($trackingRow) {
|
||||
return Carbon::parse($trackingRow->tracking_time);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getEtaFromPackingList($packingList){
|
||||
if ($packingList) {
|
||||
$package = $packingList->packages->first();
|
||||
@@ -219,21 +238,30 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
return null;
|
||||
}
|
||||
|
||||
private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $eta){
|
||||
private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $dataTimeToCheckOld, $dataTimeToCheckNew){
|
||||
$resultNumberOfDaysFree = $this->defaultNumberOfDaysFree;
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
LogHelper::channel('storage_invoices')->info('trackingTime: '.json_encode($dataTimeToCheckNew));
|
||||
$dt1 = $dataTimeToCheckNew->copy()->addDay()->startOfDay();
|
||||
$dt2 = Carbon::now()->copy()->addDay()->startOfDay();
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('eta: '.json_encode($eta));
|
||||
LogHelper::channel('storage_invoices')->info('dt1: '.json_encode($dt1));
|
||||
LogHelper::channel('storage_invoices')->info('dt2: '.json_encode($dt2));
|
||||
|
||||
//Goods should arrive first before checking for number of days stored
|
||||
if ($dt1->greaterThan($dt2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('interval: '.json_encode($interval));
|
||||
LogHelper::channel('storage_invoices')->info('Carbon now: '.json_encode(Carbon::now()));
|
||||
|
||||
|
||||
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
|
||||
// to prevent negative number of days exceeded
|
||||
if($resultNumberOfDaysExceeded < 0){
|
||||
$resultNumberOfDaysExceeded = 0;
|
||||
}
|
||||
$storageInvoice = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->first();
|
||||
$storageInvoiceId = 0;
|
||||
$transactionDetailsItems = $transaction->transactionDetails()->get();
|
||||
@@ -280,7 +308,15 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
if($paymentStorageTransaction){
|
||||
$dateStorageInvoicePaid = $paymentStorageTransaction->created_at->copy()->addDay()->startOfDay();
|
||||
LogHelper::channel('storage_invoices')->info('dateStorageInvoicePaid: '.$dateStorageInvoicePaid.', resultCurrentDate: '.$dt2->format('Y-m-d H:i:s'));
|
||||
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1);
|
||||
|
||||
$dateTemp = $dt1->copy();
|
||||
$newStorageInvoiceBusinessLogic = Carbon::parse('2025-09-09 00:00:00');
|
||||
if ($dateStorageInvoicePaid->isBefore($newStorageInvoiceBusinessLogic)){
|
||||
$dateTemp = $dataTimeToCheckOld->copy()->addDay()->startOfDay();
|
||||
$resultNumberOfDaysFree = 10;
|
||||
}
|
||||
|
||||
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dateTemp);
|
||||
$resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
|
||||
@@ -350,15 +386,25 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
|
||||
}
|
||||
|
||||
private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $eta){
|
||||
private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $dataTimeToCheckOld, $dataTimeToCheckNew){
|
||||
$resultNumberOfDaysFree = $this->defaultNumberOfDaysFree;
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
$resultStartDate = $dt1->format('Y-m-d');
|
||||
$currentDatetime = Carbon::now();
|
||||
$dt2 = $currentDatetime->copy()->addDay()->startOfDay();
|
||||
$resultCurrentDate = $dt2->format('Y-m-d H:i:s');
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
$dt2 = Carbon::now()->copy()->addDay()->startOfDay();
|
||||
|
||||
$newStorageInvoiceBusinessLogic = Carbon::parse('2025-09-09 00:00:00');
|
||||
$transactoinCreatedAt = Carbon::parse($transaction->created_at);
|
||||
|
||||
if ($transactoinCreatedAt->isAfter($newStorageInvoiceBusinessLogic)) {
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$dt1 = $dataTimeToCheckNew->copy()->addDay()->startOfDay();
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
}
|
||||
else{
|
||||
$dt1 = $dataTimeToCheckOld->copy()->addDay()->startOfDay();
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
$resultNumberOfDaysFree = 10;
|
||||
}
|
||||
|
||||
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
|
||||
$paidStorageInvoice = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('transactions.status', [ApprovalStatus::COMPLETED])->first();
|
||||
if($paidStorageInvoice){
|
||||
@@ -402,8 +448,8 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
'storageInvoiceId' => $storageInvoiceId,
|
||||
'numberOfDaysExceeded' => $resultNumberOfDaysExceeded,
|
||||
'numberOfDaysFree' => $resultNumberOfDaysFree,
|
||||
'startDate' => $resultStartDate,
|
||||
'currentDate' => $resultCurrentDate,
|
||||
'startDate' => $dt1->format('Y-m-d'),
|
||||
'currentDate' => $dt2->format('Y-m-d H:i:s'),
|
||||
'cbm' => $cbm,
|
||||
'pricePerCBM' => $pricePerCBM,
|
||||
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
|
||||
|
||||
+536
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\LogHelper;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionDetail;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Transactions\Services\DeletesGroup;
|
||||
use App\Classes\Modules\Billplzs\Services\DeletesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PackageType;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TaxPercentage;
|
||||
use App\Classes\ValueObjects\Constants\TransactionDetailType;
|
||||
use App\Http\Resources\TransactionWithStorageResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class CheckStorageInvoiceTransactionV0Processor
|
||||
{
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var CreatesTransactionDetail */
|
||||
private $createsTransactionDetail;
|
||||
|
||||
/** @var UpdatesTransaction */
|
||||
private $updatesTransaction;
|
||||
|
||||
/** @var UpdatesTransactionDetail */
|
||||
private $updatesTransactionDetail;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var DeletesGroup */
|
||||
private $deletesGroup;
|
||||
|
||||
/** @var DeletesBillplzBill */
|
||||
private $deletesBillplzBill;
|
||||
|
||||
private $defaultPricePerCBM = 3;
|
||||
|
||||
/**
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param CreatesTransactionDetail $createsTransactionDetail
|
||||
* @param UpdatesTransaction $updatesTransaction
|
||||
* @param UpdatesTransactionDetail $updatesTransactionDetail
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param DeletesGroup $deletesGroup
|
||||
* @param DeletesBillplzBill $deletesBillplzBill
|
||||
*/
|
||||
public function __construct(FetchesOrder $fetchesOrder, GeneratesTransactionBillNumber $generatesTransactionBillNumber, FetchesTransaction $fetchesTransaction, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, UpdatesTransaction $updatesTransaction, UpdatesTransactionDetail $updatesTransactionDetail, UpdatesTransactionStatus $updatesTransactionStatus, DeletesGroup $deletesGroup, DeletesBillplzBill $deletesBillplzBill)
|
||||
{
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->createsTransactionDetail = $createsTransactionDetail;
|
||||
$this->updatesTransaction = $updatesTransaction;
|
||||
$this->updatesTransactionDetail = $updatesTransactionDetail;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->deletesGroup = $deletesGroup;
|
||||
$this->deletesBillplzBill = $deletesBillplzBill;
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
// Production environment - 23rd September 2024
|
||||
$targetDate = Carbon::create(2024, 9, 23, 0, 0, 0, 'Asia/Kuala_Lumpur');
|
||||
} else {
|
||||
// Non-production environment (development, local, etc.) - 22nd September 2024
|
||||
$targetDate = Carbon::create(2024, 9, 22, 0, 0, 0, 'Asia/Kuala_Lumpur');
|
||||
}
|
||||
|
||||
$nowMalaysia = Carbon::now('Asia/Kuala_Lumpur');
|
||||
if ($nowMalaysia->greaterThanOrEqualTo($targetDate)) {
|
||||
// LogHelper::channel('storage_invoices')->info('new defaultPricePerCBM RM6 true');
|
||||
$this->defaultPricePerCBM = 6;
|
||||
}
|
||||
else{
|
||||
// LogHelper::channel('storage_invoices')->info('new defaultPricePerCBM RM6 not yet');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(int $orderReference)
|
||||
{
|
||||
$order = $this->fetchesOrder->execute(['reference' => $orderReference, 'with_packing_lists' => true]);
|
||||
return $this->executeOrder($order);
|
||||
}
|
||||
|
||||
public function executeOrder(Order $order){
|
||||
$results = [];
|
||||
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term;
|
||||
LogHelper::channel('storage_invoices')->info('orderId: '.$order->id.', orderReference: '.$order->reference.', marking: '.$marking.', is_credit_term: '.$is_credit_term);
|
||||
$packingLists = $order->destinationWarehousePackages;
|
||||
|
||||
foreach ($packingLists as $packingList){
|
||||
$newResults = $this->getResults($packingList, $order, $is_credit_term);
|
||||
$results = array_merge($results, $newResults);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function executeShippingTransaction(Transaction $shippingInvoice){
|
||||
LogHelper::channel('storage_invoices')->info('shippingInvoice: '.json_encode($shippingInvoice));
|
||||
$results = [];
|
||||
$pL = $shippingInvoice->owner;
|
||||
$order = $pL->owner;
|
||||
$is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term;
|
||||
$packingLists = $order->destinationWarehousePackages;
|
||||
|
||||
foreach ($packingLists as $packingList){
|
||||
if($packingList->id === $pL->id){
|
||||
$newResults = $this->getResults($packingList, $order, $is_credit_term);
|
||||
$results = array_merge($results, $newResults);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function processByPackingList(PackingList $packingList, Order $order, bool $is_credit_term){
|
||||
$this->getResults($packingList, $order, $is_credit_term);
|
||||
}
|
||||
|
||||
private function getResults($packingList, $order, $is_credit_term){
|
||||
$results = [];
|
||||
$arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehouse($packingList);
|
||||
LogHelper::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse));
|
||||
LogHelper::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList));
|
||||
$eta = $this->getEtaFromPackingList($packingList);
|
||||
if($arrivalDateAtChinaWarehouse && $eta){
|
||||
$transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
|
||||
// $transactions = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->where('transactions.status', ApprovalStatus::APPROVED)->get();
|
||||
|
||||
/** @var Transaction $invoice_transaction */
|
||||
foreach ($transactions as $invoice_transaction){
|
||||
LogHelper::channel('storage_invoices')->info('invoice_transaction bill_no: '. $invoice_transaction->bill_no);
|
||||
$result = null;
|
||||
if(!$is_credit_term){
|
||||
$result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $eta);
|
||||
}
|
||||
else{
|
||||
$result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $eta);
|
||||
}
|
||||
if($result){
|
||||
$results[] = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function getArrivalDateAtChinaWarehouse($packingList){
|
||||
if($packingList->type === PackingListType::SHIPPING_PACKING_LIST){
|
||||
LogHelper::channel('storage_invoices')->info('packingList reference: '.json_encode($packingList->reference));
|
||||
$receive_packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first();
|
||||
LogHelper::channel('storage_invoices')->info('receive_packing_list: '.json_encode($receive_packing_list->transports));
|
||||
$transport = $receive_packing_list->transports->first();
|
||||
if ($transport) {
|
||||
$arrivalDateAtChinaWarehouse = Carbon::parse($transport->drop_date);
|
||||
$dateToCompare = Carbon::parse(env('STORAGE_FEE_LAUNCH_DATE', '2023-12-11 00:00:00'));
|
||||
// dd($dateToCompare);
|
||||
if ($arrivalDateAtChinaWarehouse->isAfter($dateToCompare)) {
|
||||
LogHelper::channel('storage_invoices')->info('transport: '.json_encode($transport));
|
||||
LogHelper::channel('storage_invoices')->info('dateToCompare: '.$dateToCompare.', arrivalDateAtChinaWarehouse: '.$arrivalDateAtChinaWarehouse);
|
||||
return $arrivalDateAtChinaWarehouse;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getEtaFromPackingList($packingList){
|
||||
if ($packingList) {
|
||||
$package = $packingList->packages->first();
|
||||
if ($package) {
|
||||
$container = $package->container()->first();
|
||||
if ($container) {
|
||||
$transport = $container->transports->first();
|
||||
if ($transport) {
|
||||
$schedule = $transport->schedules->last();
|
||||
if ($schedule) {
|
||||
LogHelper::channel('storage_invoices')->info('schedule: '.json_encode($schedule));
|
||||
return $schedule->eta;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $eta){
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
$dt2 = Carbon::now()->copy()->addDay()->startOfDay();
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('eta: '.json_encode($eta));
|
||||
LogHelper::channel('storage_invoices')->info('dt1: '.json_encode($dt1));
|
||||
LogHelper::channel('storage_invoices')->info('dt2: '.json_encode($dt2));
|
||||
|
||||
//Goods should arrive first before checking for number of days stored
|
||||
if ($dt1->greaterThan($dt2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('interval: '.json_encode($interval));
|
||||
LogHelper::channel('storage_invoices')->info('Carbon now: '.json_encode(Carbon::now()));
|
||||
|
||||
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
|
||||
// to prevent negative number of days exceeded
|
||||
if($resultNumberOfDaysExceeded < 0){
|
||||
$resultNumberOfDaysExceeded = 0;
|
||||
}
|
||||
$storageInvoice = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->first();
|
||||
$storageInvoiceId = 0;
|
||||
$transactionDetailsItems = $transaction->transactionDetails()->get();
|
||||
$cbm = 0.00;
|
||||
foreach ($transactionDetailsItems as $tdItem){
|
||||
$quantity = $tdItem->quantity;
|
||||
if($tdItem->price < 0.00){
|
||||
$quantity = $quantity * -1;
|
||||
}
|
||||
$cbm = $cbm + $quantity;
|
||||
}
|
||||
|
||||
$total_tax = 0;
|
||||
$taxPercentage = TaxPercentage::DEFAULT;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('dateToCompare: '.json_encode($dateToCompare));
|
||||
if(!$storageInvoice && $resultNumberOfDaysExceeded > 0 && $transaction->status != ApprovalStatus::COMPLETED){
|
||||
LogHelper::channel('storage_invoices')->info('Created $transaction->id: '.$transaction->id);
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('STOR-');
|
||||
|
||||
if (Carbon::now()->isAfter($dateToCompare)) {
|
||||
$taxPercentage = TaxPercentage::SIX_PERCENT;
|
||||
$total_tax = $price_cbm * $taxPercentage / 100;
|
||||
$price_cbm = $price_cbm + $total_tax;
|
||||
}
|
||||
|
||||
$storageInvoice = $this->createStorageInvoiceTransaction($destinationWarehousePackage, $billNumber, $company_module_id, $price_cbm, $total_tax);
|
||||
$storageInvoiceId = $storageInvoice->id;
|
||||
$this->createStorageInvoiceTransactionDetails($storageInvoice, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded, $taxPercentage);
|
||||
}
|
||||
else if($storageInvoice){
|
||||
$amount = $storageInvoice->amount;
|
||||
|
||||
//Additional handling for giving selected storage invoice a waiver
|
||||
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
|
||||
$pricePerCBM = 0;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
}
|
||||
|
||||
//Additional handling for calculation of numberOfDaysExceeded in the event of the storage already paid
|
||||
$paymentStorageTransaction = $storageInvoice->transactions()->where('transactions.type', TransactionType::PAYMENT)->where('transactions.status', ApprovalStatus::APPROVED)->first();
|
||||
if($paymentStorageTransaction){
|
||||
$dateStorageInvoicePaid = $paymentStorageTransaction->created_at->copy()->addDay()->startOfDay();
|
||||
LogHelper::channel('storage_invoices')->info('dateStorageInvoicePaid: '.$dateStorageInvoicePaid.', resultCurrentDate: '.$dt2->format('Y-m-d H:i:s'));
|
||||
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1);
|
||||
$resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
|
||||
try{
|
||||
$auditPricePerCbm = floor($amount / ($cbm * $resultNumberOfDaysExceeded));
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm);
|
||||
$pricePerCBM = $auditPricePerCbm;
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (Carbon::now()->isAfter($dateToCompare)) {
|
||||
$taxPercentage = TaxPercentage::SIX_PERCENT;
|
||||
$total_tax = $price_cbm * $taxPercentage / 100;
|
||||
$price_cbm = $price_cbm + $total_tax;
|
||||
}
|
||||
|
||||
$epsilon = 0.0001; // Tolerance for the comparison
|
||||
LogHelper::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id);
|
||||
LogHelper::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status);
|
||||
LogHelper::channel('storage_invoices')->info('price_cbm: '.$price_cbm."-".gettype($price_cbm));
|
||||
LogHelper::channel('storage_invoices')->info('amount: '.$amount);
|
||||
|
||||
$proceedToUpdate = false;
|
||||
|
||||
if(abs($price_cbm - $amount) > $epsilon && $storageInvoice->status !== ApprovalStatus::COMPLETED){
|
||||
$paymentTransactions = $storageInvoice->transactions()->where('transactions.type', TransactionType::PAYMENT)->where('transactions.status', ApprovalStatus::PENDING_SUBMISSION)->get();
|
||||
// if(!$isBackDoorCheck){
|
||||
if(count($paymentTransactions) > 0){
|
||||
$this->updatePaymentTransactionViaNonGroupPayment($paymentTransactions);
|
||||
}
|
||||
else{
|
||||
$this->updatePaymentTransactionViaGroupPayment($storageInvoice);
|
||||
}
|
||||
//}
|
||||
|
||||
$proceedToUpdate = true;
|
||||
}
|
||||
|
||||
if($proceedToUpdate || ($pricePerCBM == 0 && $amount != 0)){
|
||||
LogHelper::channel('storage_invoices')->info('proceedToUpdate');
|
||||
|
||||
$storageInvoice = $this->updateStorageInvoiceTransaction($storageInvoice, $price_cbm, $total_tax);
|
||||
$invoiceTransactionDetails = $storageInvoice->transactionDetails()->first();
|
||||
$this->updateStorageInvoiceTransactionDetails($invoiceTransactionDetails, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded, $taxPercentage);
|
||||
}
|
||||
|
||||
$storageInvoiceId = $storageInvoice->id;
|
||||
}
|
||||
|
||||
if($storageInvoiceId !== 0){
|
||||
$result = [
|
||||
'parentInvoiceId' => $transaction->id,
|
||||
'storageInvoiceId' => $storageInvoiceId,
|
||||
'numberOfDaysExceeded' => $resultNumberOfDaysExceeded,
|
||||
'numberOfDaysFree' => $resultNumberOfDaysFree,
|
||||
'startDate' => $dt1->format('Y-m-d'),
|
||||
'currentDate' => $dt2->format('Y-m-d H:i:s'),
|
||||
'cbm' => $cbm,
|
||||
'pricePerCBM' => $pricePerCBM,
|
||||
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $eta){
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
$resultStartDate = $dt1->format('Y-m-d');
|
||||
$currentDatetime = Carbon::now();
|
||||
$dt2 = $currentDatetime->copy()->addDay()->startOfDay();
|
||||
$resultCurrentDate = $dt2->format('Y-m-d H:i:s');
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
$resultNumberOfDaysExceeded = $interval->days - $resultNumberOfDaysFree;
|
||||
$paidStorageInvoice = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->whereIn('transactions.status', [ApprovalStatus::COMPLETED])->first();
|
||||
if($paidStorageInvoice){
|
||||
$storageInvoice = $paidStorageInvoice;
|
||||
}
|
||||
else{
|
||||
$waivedStorageInvoice = $packingList->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->where('transactions.is_waived', 1)->whereIn('transactions.status', [ApprovalStatus::APPROVED])->first();
|
||||
$storageInvoice = $waivedStorageInvoice;
|
||||
}
|
||||
|
||||
if($storageInvoice){
|
||||
$storageInvoiceId = $storageInvoice->id;
|
||||
|
||||
$transactionDetailsItems = $transaction->transactionDetails()->get();
|
||||
$cbm = 0.00;
|
||||
foreach ($transactionDetailsItems as $tdItem){
|
||||
$quantity = $tdItem->quantity;
|
||||
if($tdItem->price < 0.00){
|
||||
$quantity = $quantity * -1;
|
||||
}
|
||||
$cbm = $cbm + $quantity;
|
||||
}
|
||||
|
||||
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
|
||||
$pricePerCBM = 0;
|
||||
}
|
||||
else{
|
||||
try{
|
||||
$auditPricePerCbm = floor($storageInvoice->amount / ($cbm * $resultNumberOfDaysExceeded));
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm);
|
||||
$pricePerCBM = $auditPricePerCbm;
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex);
|
||||
}
|
||||
}
|
||||
|
||||
if($storageInvoiceId !== 0){
|
||||
$result = [
|
||||
'parentInvoiceId' => $transaction->id,
|
||||
'storageInvoiceId' => $storageInvoiceId,
|
||||
'numberOfDaysExceeded' => $resultNumberOfDaysExceeded,
|
||||
'numberOfDaysFree' => $resultNumberOfDaysFree,
|
||||
'startDate' => $resultStartDate,
|
||||
'currentDate' => $resultCurrentDate,
|
||||
'cbm' => $cbm,
|
||||
'pricePerCBM' => $pricePerCBM,
|
||||
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function updatePaymentTransactionViaGroupPayment($storageInvoice){
|
||||
LogHelper::channel('storage_invoices')->info('updatePaymentTransactionViaGroupPayment');
|
||||
$groups = $storageInvoice->groups()->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED])->get();
|
||||
foreach ($groups as $grp){
|
||||
$groupReference = $grp->reference;
|
||||
$walletTransaction = $this->fetchesTransaction->execute(['payment_reference' => $groupReference]);
|
||||
if($walletTransaction->status === ApprovalStatus::PENDING_SUBMISSION || $walletTransaction->status === ApprovalStatus::PENDING_VERIFICATION){
|
||||
$grp->status = ApprovalStatus::EXPIRED;
|
||||
$grp->save();
|
||||
$this->deletesGroup->execute($grp);
|
||||
$this->updatesTransactionStatus->execute($walletTransaction, ApprovalStatus::EXPIRED);
|
||||
if($walletTransaction->payment_reference){
|
||||
$deletedBillplzBill = $this->deletesBillplzBill->execute($walletTransaction->payment_reference);
|
||||
LogHelper::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function updatePaymentTransactionViaNonGroupPayment($paymentTransactions){
|
||||
LogHelper::channel('storage_invoices')->info('updatePaymentTransactionViaNonGroupPayment');
|
||||
foreach ($paymentTransactions as $paymentTransaction){
|
||||
$this->updatesTransactionStatus->execute($paymentTransaction, ApprovalStatus::EXPIRED);
|
||||
if($paymentTransaction->payment_reference){
|
||||
$deletedBillplzBill = $this->deletesBillplzBill->execute($paymentTransaction->payment_reference);
|
||||
LogHelper::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function updateStorageInvoiceTransaction(Transaction $transaction, float $totalAmount, float $totalTax){
|
||||
|
||||
$object = new TransactionObject(
|
||||
$transaction->bill_no,
|
||||
TransactionType::STORAGE_INVOICE,
|
||||
1,
|
||||
$transaction->receiver,
|
||||
1,
|
||||
PaymentMethodType::CASH,
|
||||
$totalAmount,
|
||||
$totalAmount,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
$totalTax,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::APPROVED
|
||||
);
|
||||
|
||||
/** @var Transaction $invoice_transaction */
|
||||
$invoice_transaction = $this->updatesTransaction->execute($transaction, $object);
|
||||
|
||||
return $invoice_transaction;
|
||||
}
|
||||
|
||||
private function updateStorageInvoiceTransactionDetails($invoice_transaction_details, PackingList $packing_list, $cbm, $pricePerCBM, $numberOfDays, $taxPercentage){
|
||||
$object_detail = new TransactionDetailObject(
|
||||
'STORAGE_FEE',
|
||||
TransactionDetailType::STORAGE_FEE.' for '.$numberOfDays. ' days * RM'.$pricePerCBM.'<br>'.round($packing_list->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum('quantity'), 3).' CTNS - '.round($cbm, 3).' CBM',
|
||||
$cbm,
|
||||
$pricePerCBM * $numberOfDays,
|
||||
$taxPercentage
|
||||
);
|
||||
|
||||
$this->updatesTransactionDetail->execute($invoice_transaction_details, $object_detail);
|
||||
}
|
||||
|
||||
private function createStorageInvoiceTransaction(PackingList $packing_list, string $billNumber, int $companyModuleId, float $totalAmount, float $totalTax){
|
||||
|
||||
$object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::STORAGE_INVOICE,
|
||||
1,
|
||||
$companyModuleId,
|
||||
1,
|
||||
PaymentMethodType::CASH,
|
||||
$totalAmount,
|
||||
$totalAmount,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
$totalTax,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::APPROVED
|
||||
);
|
||||
|
||||
/** @var Transaction $invoice_transaction */
|
||||
$invoice_transaction = $this->createsTransaction->execute($packing_list, $object);
|
||||
|
||||
return $invoice_transaction;
|
||||
}
|
||||
|
||||
private function createStorageInvoiceTransactionDetails($invoice_transaction, PackingList $packing_list, $cbm, $pricePerCBM, $numberOfDays, $taxPercentage){
|
||||
$object_detail = new TransactionDetailObject(
|
||||
'STORAGE_FEE',
|
||||
TransactionDetailType::STORAGE_FEE.' for '.$numberOfDays. ' days * RM'.$pricePerCBM.'<br>'.round($packing_list->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum('quantity'), 3).' CTNS - '.round($cbm, 3).' CBM',
|
||||
$cbm,
|
||||
$pricePerCBM * $numberOfDays,
|
||||
$taxPercentage
|
||||
);
|
||||
|
||||
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,8 @@ class CreateInvoiceTransactionProcessor
|
||||
$order = $packing_list->owner;
|
||||
$companyModule = $order->companyModule;
|
||||
$connection = $companyModule->connections()->first();
|
||||
$address = $order->addresses()->first();
|
||||
// $address = $order->addresses()->first();
|
||||
$address = $order->addresses()->whereIn('status', [2])->first();
|
||||
|
||||
$base_price_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE]);
|
||||
$warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::WAREHOUSE_RATE]);
|
||||
@@ -150,19 +151,32 @@ class CreateInvoiceTransactionProcessor
|
||||
$containerPackingLists = collect();
|
||||
$hasMinimumCharge = null;
|
||||
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if($packingList->owner instanceof CompanyModule) continue;
|
||||
if($packingList->owner->companyModule->id !== $companyModule->id) continue;
|
||||
$containerPackingLists->push($packingList);
|
||||
foreach ($container->packingLists as $singlePL){
|
||||
if($singlePL->owner instanceof CompanyModule) continue;
|
||||
if($singlePL->owner->companyModule->id !== $companyModule->id) continue;
|
||||
$containerPackingLists->push($singlePL);
|
||||
|
||||
if(!$hasMinimumCharge) {
|
||||
$hasMinimumCharge = $packingList->transactions()->whereHas('transactionDetails', function ($query){
|
||||
$hasMinimumCharge = $singlePL->transactions()->whereHas('transactionDetails', function ($query){
|
||||
$query->where('reference', 'MIN_CBM_CHARGES');
|
||||
})->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sameOrderSameContainerPackingLists = $order->packingLists()
|
||||
->where('type', PackingListType::SHIPPING_PACKING_LIST)
|
||||
->whereHas('containers', function ($query) use ($container) {
|
||||
$query->where('reference', $container->reference);
|
||||
})
|
||||
->get();
|
||||
foreach ($sameOrderSameContainerPackingLists as $item) {
|
||||
if (! $containerPackingLists->contains('id', $item['id'])) {
|
||||
$containerPackingLists->push($item);
|
||||
}
|
||||
}
|
||||
Log::info('AUDIT containerPackingLists: ' . json_encode($containerPackingLists));
|
||||
|
||||
$totalContainerCbm = $containerPackingLists->sum(function($packingList){
|
||||
$billable_packing_list = $packingList->packingLists()->first();
|
||||
$billable_packing_list = $billable_packing_list ? $billable_packing_list : $packingList;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Models\Document;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
|
||||
class CreateSalesOrderDocProcessor
|
||||
{
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice_transaction)
|
||||
{
|
||||
$view = 'pages.pdfs.sales_order';
|
||||
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
$user = $companyModule->employees()->first();
|
||||
$brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$documentDate = $invoice_transaction->created_at;
|
||||
$documentIdentifierPrefix = 'S/O No: ';
|
||||
$documentIdentifier = 'SO-'.$invoice_transaction->bill_no;
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice_transaction, 'brn' => $brn, 'document_date' => $documentDate, 'document_identifier' => $documentIdentifier, 'document_identifier_prefix' => $documentIdentifierPrefix]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::SALES_ORDER,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'sales_order'
|
||||
);
|
||||
|
||||
/** @var Document $document */
|
||||
$document =$this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\Document;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
|
||||
class CreateShippingEInvoiceDocProcessor
|
||||
{
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/** @var CreatesKeyValuePair */
|
||||
private $createsKeyValuePair;
|
||||
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
* @param CreatesKeyValuePair $createsKeyValuePair
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles, CreatesKeyValuePair $createsKeyValuePair)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->createsKeyValuePair = $createsKeyValuePair;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice_transaction)
|
||||
{
|
||||
$view = 'pages.pdfs.shipping_einvoice';
|
||||
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
$user = $companyModule->employees()->first();
|
||||
$brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$lastDayOfMonth = $invoice_transaction->created_at->copy()->endOfMonth();
|
||||
$documentDate = $lastDayOfMonth;
|
||||
$documentIdentifierPrefix = 'EI#: ';
|
||||
$autoCountInvoiceId = '';
|
||||
$autoCountEInvoiceValidationLink = 'CIEF';
|
||||
|
||||
$metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if($metadata){
|
||||
$autoCountInvoiceId = $metadata->value;
|
||||
}
|
||||
$metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK)->first();
|
||||
if($metadata){
|
||||
$autoCountEInvoiceValidationLink = $metadata->value;
|
||||
}
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, [
|
||||
'invoice_transaction' => $invoice_transaction,
|
||||
'brn' => $brn,
|
||||
'document_date' => $documentDate,
|
||||
'document_identifier' => $autoCountInvoiceId,
|
||||
'document_identifier_prefix' => $documentIdentifierPrefix,
|
||||
'autocountEInvoiceValidationLink' => $autoCountEInvoiceValidationLink,
|
||||
]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::SHIPPING_EINVOICE,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'shipping_einvoice'
|
||||
);
|
||||
|
||||
/** @var Document $document */
|
||||
$document =$this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
|
||||
$keyValuePairObject = new KeyValuePairObject(KVPKey::EINVOICE_ISSUED, 1);
|
||||
$this->createsKeyValuePair->execute($invoice_transaction, $keyValuePairObject);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Models\Document;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CreateShippingInvoiceTransactionDocProcessor
|
||||
{
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice_transaction)
|
||||
{
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice_transaction->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice_transaction->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
|
||||
$eInvoiceStartDate = Carbon::parse(env('E_INVOICE_START_DATE', '2025-07-01 00:00:00'));
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($eInvoiceStartDate)) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst_v2';
|
||||
}
|
||||
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
$user = $companyModule->employees()->first();
|
||||
$brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$documentDate = $invoice_transaction->created_at;
|
||||
$documentIdentifierPrefix = 'Invoice No: ';
|
||||
$documentIdentifier = $invoice_transaction->bill_no;
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice_transaction, 'brn' => $brn, 'document_date' => $documentDate, 'document_identifier' => $documentIdentifier, 'document_identifier_prefix' => $documentIdentifierPrefix]);
|
||||
|
||||
$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 =$this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\Document;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
|
||||
class CreateStorageEInvoiceDocProcessor
|
||||
{
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/** @var CreatesKeyValuePair */
|
||||
private $createsKeyValuePair;
|
||||
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
* @param CreatesKeyValuePair $createsKeyValuePair
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles, CreatesKeyValuePair $createsKeyValuePair)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->createsKeyValuePair = $createsKeyValuePair;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice_transaction)
|
||||
{
|
||||
$view = 'pages.pdfs.shipping_einvoice';
|
||||
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
$user = $companyModule->employees()->first();
|
||||
$brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$lastDayOfMonth = $invoice_transaction->created_at->copy()->endOfMonth();
|
||||
$documentDate = $lastDayOfMonth;
|
||||
$documentIdentifierPrefix = 'EI#: ';
|
||||
$autoCountInvoiceId = '';
|
||||
$autoCountEInvoiceValidationLink = 'CIEF';
|
||||
|
||||
$metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
||||
if($metadata){
|
||||
$autoCountInvoiceId = $metadata->value;
|
||||
}
|
||||
$metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK)->first();
|
||||
if($metadata){
|
||||
$autoCountEInvoiceValidationLink = $metadata->value;
|
||||
}
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, [
|
||||
'invoice_transaction' => $invoice_transaction,
|
||||
'brn' => $brn,
|
||||
'document_date' => $documentDate,
|
||||
'document_identifier' => $autoCountInvoiceId,
|
||||
'document_identifier_prefix' => $documentIdentifierPrefix,
|
||||
'autocountEInvoiceValidationLink' => $autoCountEInvoiceValidationLink,
|
||||
]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::STORAGE_EINVOICE,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'shipping_einvoice'
|
||||
);
|
||||
|
||||
/** @var Document $document */
|
||||
$document =$this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
|
||||
$keyValuePairObject = new KeyValuePairObject(KVPKey::EINVOICE_ISSUED, 1);
|
||||
$this->createsKeyValuePair->execute($invoice_transaction, $keyValuePairObject);
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Models\Document;
|
||||
use App\Models\Transaction;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CreateStorageInvoiceTransactionDocProcessor
|
||||
{
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Transaction $invoice_transaction
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice_transaction)
|
||||
{
|
||||
if($invoice_transaction->status !== ApprovalStatus::COMPLETED){
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
Log::info('$dateToCompare 2: '.$dateToCompare);
|
||||
$storageInvoiceTransactionCreatedDate = Carbon::parse($invoice_transaction->created_at);
|
||||
Log::info('$storageInvoiceTransactionCreatedDate 2: '.$storageInvoiceTransactionCreatedDate);
|
||||
if ($storageInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice_transaction->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
|
||||
$eInvoiceStartDate = Carbon::parse(env('E_INVOICE_START_DATE', '2025-07-01 00:00:00'));
|
||||
if ($storageInvoiceTransactionCreatedDate->isAfter($eInvoiceStartDate)) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst_v2';
|
||||
}
|
||||
|
||||
$companyModule = $invoice_transaction->owner->owner->companyModule;
|
||||
$brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first();
|
||||
$documentDate = $invoice_transaction->created_at;
|
||||
$documentIdentifierPrefix = 'Invoice No: ';
|
||||
$documentIdentifier = $invoice_transaction->bill_no;
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice_transaction, 'brn' => $brn, 'document_date' => $documentDate, 'document_identifier' => $documentIdentifier, 'document_identifier_prefix' => $documentIdentifierPrefix]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::STORAGE_INVOICE,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'storage_invoice'
|
||||
);
|
||||
|
||||
// $invouce_transaction_document = $invoice_transaction->documents()->where('document_type', DocumentType::STORAGE_INVOICE)->first();
|
||||
// if(!$invouce_transaction_document){
|
||||
/** @var Document $document */
|
||||
$document = $this->createsDocument->execute($invoice_transaction, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
// $user = $packingList->owner->companyModule->employees()->first();
|
||||
// if(app()->environment(['production'])) {
|
||||
// $user->notify(new InvoiceIssuedEmail($user, $packingList));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
|
||||
class CanFetchTransaction extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,5 +25,7 @@ final class DocumentType {
|
||||
|
||||
public const SHIPPING_INVOICE = 'SHIPPING_INVOICE';
|
||||
public const STORAGE_INVOICE = 'STORAGE_INVOICE';
|
||||
|
||||
public const SALES_ORDER = 'SALES_ORDER';
|
||||
public const SHIPPING_EINVOICE = 'SHIPPING_EINVOICE';
|
||||
public const STORAGE_EINVOICE = 'STORAGE_EINVOICE';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
|
||||
class KVPKey
|
||||
{
|
||||
public const EINVOICE_ISSUED = 'EINVOICE_ISSUED';
|
||||
|
||||
public const AUTOCOUNT_DOCNO_INVOICE = 'AUTOCOUNT_DOCNO_I';
|
||||
|
||||
public const AUTOCOUNT_EINVOICE_VALIDATION_LINK = 'AUTOCOUNT_EINVOICE_VALIDATION_LINK';
|
||||
|
||||
public const AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT = 'AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT';
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
@@ -61,29 +62,10 @@ class FixInvoice extends Command
|
||||
|
||||
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,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\V2;
|
||||
|
||||
|
||||
use App\Classes\Jobs\Commands\V2\OneTimeFixWalletGroupTransactionV2CommandJob;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class OneTimeFixWalletGroupTransactionV2Command extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'one-time-fix-wallet-group-transaction-command';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'This is a one time fix of unsuccessful group payment through wallet.';
|
||||
|
||||
protected $output = null;
|
||||
|
||||
protected $outputArray = [];
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return;
|
||||
|
||||
OneTimeFixWalletGroupTransactionV2CommandJob::dispatch();
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class ProcessYDPortalDataV2Command extends Command
|
||||
}
|
||||
|
||||
foreach ($jobs2 as $index => $job) {
|
||||
dispatch($job);
|
||||
dispatch($job)->delay(now()->addSeconds($index * 2));
|
||||
}
|
||||
|
||||
foreach ($jobs3 as $index => $job) {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Classes\General\AWSS3Helper;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use App\Classes\Modules\Exports\Services\ExportsCompanies;
|
||||
use App\Classes\Modules\Exports\Services\ExportsSalesInvoicesReport;
|
||||
use App\Classes\Modules\Exports\Services\ExportsReceivePaymentDepositEntryReport;
|
||||
use App\Classes\Modules\Exports\Services\ExportsReceivePaymentForOrderReport;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExportController
|
||||
{
|
||||
public function companies(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsCompanies($startDate, $endDate);
|
||||
return $this->handleExport($exporter, 'IZYIM - Customers Data Report.xls');
|
||||
}
|
||||
|
||||
public function salesInvoices(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsSalesInvoicesReport($startDate, $endDate);
|
||||
|
||||
//This will merge both paid and unpaid into a single excel sheet
|
||||
// $exporterA = new ExportsSalesInvoicesReport($startDate, $endDate);
|
||||
// $exporterB = new ExportsSalesInvoicesReport($startDate, $endDate, true);
|
||||
// $exporter = $this->buildCombinedInvoices($exporterA, $exporterB);
|
||||
|
||||
return $this->handleExport($exporter, 'IZYIM - Sales Invoice Report.xls');
|
||||
}
|
||||
|
||||
public function salesInvoicesUnpaid(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsSalesInvoicesReport($startDate, $endDate, true);
|
||||
return $this->handleExport($exporter, 'IZYIM - Sales Invoice Report (unpaid).xls');
|
||||
}
|
||||
|
||||
public function receivePaymentDepositEntry(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsReceivePaymentDepositEntryReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, '11D - IZYIM - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY].xls');
|
||||
}
|
||||
|
||||
public function receivePaymentForOrder(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsReceivePaymentForOrderReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, '11R - IZYIM - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT].xls');
|
||||
}
|
||||
|
||||
private function getValidatedDates(Request $request): array
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
// $startDate = isset($validated['startDate']) && $validated['startDate']
|
||||
// ? Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay()
|
||||
// : Carbon::now()->subMonth()->startOfDay();
|
||||
|
||||
// $endDate = isset($validated['endDate']) && $validated['endDate']
|
||||
// ? Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay()
|
||||
// : Carbon::now()->endOfDay();
|
||||
|
||||
$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();
|
||||
|
||||
return [$startDate, $endDate];
|
||||
}
|
||||
|
||||
private function handleExport($exporter, string $exportFileName)
|
||||
{
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
|
||||
if ($filesystemDriver === 's3') {
|
||||
return response([
|
||||
'src' => AWSS3Helper::S3Exportable($exportFileName, $exporter)
|
||||
]);
|
||||
}
|
||||
|
||||
$response = $exporter->download(
|
||||
$exportFileName,
|
||||
Excel::XLS,
|
||||
['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
|
||||
);
|
||||
|
||||
ob_end_clean(); // prevent corrupt download in some environments
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function buildCombinedInvoices($reportA, $reportB)
|
||||
{
|
||||
return new class($reportA, $reportB) implements FromCollection, WithHeadings, ShouldAutoSize {
|
||||
|
||||
use Exportable;
|
||||
|
||||
private $reportA;
|
||||
private $reportB;
|
||||
|
||||
public function __construct($reportA, $reportB)
|
||||
{
|
||||
$this->reportA = $reportA;
|
||||
$this->reportB = $reportB;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$dataA = $this->reportA->query()->get()->map(function ($row) {
|
||||
return $this->reportA->map($row);
|
||||
});
|
||||
|
||||
$dataB = $this->reportB->query()->get()->map(function ($row) {
|
||||
return $this->reportB->map($row);
|
||||
});
|
||||
|
||||
return $dataA->merge($dataB);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return $this->reportA->headings();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Imports;
|
||||
|
||||
use App\Classes\Modules\Imports\ControllersLogic\ImportExcelLogic;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ImportController extends Controller
|
||||
{
|
||||
public function salesInvoices(Request $request, ImportExcelLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
public function officialReceipt(Request $request, ImportExcelLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\Modules\Orders\ControllersLogic\CreateBatchProcessingAutoCountImportLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateBatchProcessingAutoCountImportController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateBatchProcessingAutoCountImportLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function batchProcess(Request $request, CreateBatchProcessingAutoCountImportLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\Modules\Orders\ControllersLogic\FetchOrderPackagesReceivedV2Logic;
|
||||
use App\Classes\Modules\Orders\ControllersLogic\FetchOrderPackagesV2Logic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -10,7 +11,17 @@ class FetchOrderPackagesV2Controller
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchOrderLogic $logic
|
||||
* @param FetchOrderPackagesReceivedV2Logic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetchReceived(Request $request, FetchOrderPackagesReceivedV2Logic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchOrderPackagesV2Logic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchOrderPackagesV2Logic $logic): JsonResponse
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\RemarkTypes;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\CompanyModule;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MoveOrderToCustomerController
|
||||
{
|
||||
public function orderInfo(Request $request): JsonResponse
|
||||
{
|
||||
$ref = $request->query('reference');
|
||||
if (!$ref) {
|
||||
return response()->json(['error' => 'reference required'], 422);
|
||||
}
|
||||
$order = Order::where('reference', $ref)->with('companyModule')->first();
|
||||
if (!$order) {
|
||||
return response()->json(['error' => 'Order not found'], 404);
|
||||
}
|
||||
$cm = $order->companyModule;
|
||||
return response()->json([
|
||||
'order_id' => $order->id,
|
||||
'reference' => $order->reference,
|
||||
'from_company_module_id' => $order->company_module_id,
|
||||
'from_customer_name' => $cm->name ?? '',
|
||||
'from_customer_marking' => $cm->getMarking(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function customers(Request $request): JsonResponse
|
||||
{
|
||||
$list = CompanyModule::where('type', BusinessType::IMPORTER)
|
||||
->whereHas('connections', fn ($q) => $q->whereNotNull('invitee_reference')->where('invitee_reference', '!=', ''))
|
||||
->get()
|
||||
->map(fn ($cm) => ['id' => $cm->id, 'name' => $cm->name, 'marking' => $cm->getMarking()])
|
||||
->filter(fn ($r) => (string) $r['marking'] !== '')
|
||||
->values();
|
||||
|
||||
return response()->json($list);
|
||||
}
|
||||
|
||||
public function move(Request $request): JsonResponse
|
||||
{
|
||||
$ref = $request->input('order_reference');
|
||||
$targetId = (int) $request->input('target_company_module_id');
|
||||
if (!$ref || !$targetId) {
|
||||
return response()->json(['success' => false, 'error' => 'order_reference and target_company_module_id required', 'log' => []]);
|
||||
}
|
||||
|
||||
$order = Order::with('companyModule')->where('reference', $ref)->first();
|
||||
if (!$order) {
|
||||
return response()->json(['success' => false, 'error' => 'Order not found', 'log' => []]);
|
||||
}
|
||||
|
||||
$from = $order->company_module_id;
|
||||
if ($from == $targetId) {
|
||||
return response()->json(['success' => false, 'error' => 'Order already belongs to target customer', 'log' => []]);
|
||||
}
|
||||
|
||||
$target = CompanyModule::find($targetId);
|
||||
if (!$target) {
|
||||
return response()->json(['success' => false, 'error' => 'Target customer not found', 'log' => []]);
|
||||
}
|
||||
|
||||
$log = [];
|
||||
$log[] = 'Changing order: company_module_id ' . $from . ' → ' . $targetId;
|
||||
$log[] = 'Changing order_roles: company_module_id ' . $from . ' → ' . $targetId;
|
||||
$log[] = 'Changing packing list: no update (remain linked to order)';
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$now = now();
|
||||
DB::table('orders')->where('id', $order->id)->update(['company_module_id' => $targetId, 'updated_at' => $now]);
|
||||
DB::table('order_roles')
|
||||
->where('order_id', $order->id)
|
||||
->where('role_id', OrderRoleTypes::IMPORTER)
|
||||
->update(['company_module_id' => $targetId, 'updated_at' => $now]);
|
||||
|
||||
$marking = $target->getMarking() ?: (string) $targetId;
|
||||
DB::table('remarks')->insert([
|
||||
'owner_type' => Order::class,
|
||||
'owner_id' => $order->id,
|
||||
'commenter_id' => auth()->id() ?? 1,
|
||||
'content' => 'Order moved to customer (marking: ' . $marking . ') on ' . $now->toDateTimeString(),
|
||||
'type' => RemarkTypes::INTERNAL,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
$fromMarking = $order->companyModule ? ($order->companyModule->getMarking() ?: (string) $from) : (string) $from;
|
||||
DB::table(config('activitylog.table_name', 'activity_log'))->insert([
|
||||
'log_name' => 'admn_move_order',
|
||||
'description' => 'Order ' . $order->reference . ' moved from customer (marking: ' . $fromMarking . ') to customer (marking: ' . $marking . ')',
|
||||
'subject_type' => Order::class,
|
||||
'subject_id' => $order->id,
|
||||
'causer_type' => auth()->id() ? User::class : null,
|
||||
'causer_id' => auth()->id(),
|
||||
'properties' => json_encode([
|
||||
'from_company_module_id' => $from,
|
||||
'to_company_module_id' => $targetId,
|
||||
'from_marking' => $fromMarking,
|
||||
'to_marking' => $marking,
|
||||
]),
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
$transactions = $order->transactions()->get();
|
||||
$createShipInv = app(\App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor::class);
|
||||
$createSalesOrder = app(\App\Classes\Modules\Transactions\Processors\CreateSalesOrderDocProcessor::class);
|
||||
$createShipEInv = app(\App\Classes\Modules\Transactions\Processors\CreateShippingEInvoiceDocProcessor::class);
|
||||
$createStorageInv = app(\App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceTransactionDocProcessor::class);
|
||||
$createStorageEInv = app(\App\Classes\Modules\Transactions\Processors\CreateStorageEInvoiceDocProcessor::class);
|
||||
|
||||
foreach ($transactions as $tx) {
|
||||
if ($tx->type == TransactionType::SHIPPING_INVOICE) {
|
||||
try {
|
||||
$tx->documents()->where('document_type', DocumentType::SHIPPING_INVOICE)->delete();
|
||||
$createShipInv->execute($tx);
|
||||
$log[] = 'Regenerating Shipping Invoice PDF: transaction #' . $tx->id;
|
||||
} catch (\Throwable $e) {
|
||||
$log[] = 'Regenerating Shipping Invoice PDF: transaction #' . $tx->id . ' — failed: ' . $e->getMessage();
|
||||
}
|
||||
try {
|
||||
$tx->documents()->where('document_type', DocumentType::SALES_ORDER)->delete();
|
||||
$createSalesOrder->execute($tx);
|
||||
$log[] = 'Regenerating Sales Order PDF: transaction #' . $tx->id;
|
||||
} catch (\Throwable $e) {
|
||||
$log[] = 'Regenerating Sales Order PDF: transaction #' . $tx->id . ' — failed: ' . $e->getMessage();
|
||||
}
|
||||
$isEInv = $tx->owner->owner->companyModule->company->e_invoice ?? 0;
|
||||
if ($isEInv == 1) {
|
||||
try {
|
||||
$tx->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->delete();
|
||||
$createShipEInv->execute($tx);
|
||||
$log[] = 'Regenerating E-Invoice PDF: transaction #' . $tx->id;
|
||||
} catch (\Throwable $e) {
|
||||
$log[] = 'Regenerating E-Invoice PDF: transaction #' . $tx->id . ' — failed: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
} elseif ($tx->type == TransactionType::STORAGE_INVOICE) {
|
||||
try {
|
||||
$tx->documents()->where('document_type', DocumentType::STORAGE_INVOICE)->delete();
|
||||
$createStorageInv->execute($tx);
|
||||
$log[] = 'Regenerating Storage Invoice PDF: transaction #' . $tx->id;
|
||||
} catch (\Throwable $e) {
|
||||
$log[] = 'Regenerating Storage Invoice PDF: transaction #' . $tx->id . ' — failed: ' . $e->getMessage();
|
||||
}
|
||||
$isEInv = $tx->owner->owner->companyModule->company->e_invoice ?? 0;
|
||||
if ($isEInv == 1) {
|
||||
try {
|
||||
$tx->documents()->where('document_type', DocumentType::STORAGE_EINVOICE)->delete();
|
||||
$createStorageEInv->execute($tx);
|
||||
$log[] = 'Regenerating Storage E-Invoice PDF: transaction #' . $tx->id;
|
||||
} catch (\Throwable $e) {
|
||||
$log[] = 'Regenerating Storage E-Invoice PDF: transaction #' . $tx->id . ' — failed: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$log[] = 'Done.';
|
||||
DB::commit();
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
$log[] = 'Error: ' . $e->getMessage();
|
||||
return response()->json(['success' => false, 'error' => $e->getMessage(), 'log' => $log]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'log' => $log]);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,11 @@
|
||||
namespace App\Http\Controllers\PackingLists;
|
||||
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsLogic;
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsForWarehouseLogic;
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsPendingInvoiceLogic;
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsPendingApprovalLogic;
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsPendingPaymentLogic;
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\ListPackingListsPaidInvoiceLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -17,4 +22,48 @@ class ListPackingListsController
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListPackingListsForWarehouseLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function warehouseList(Request $request, ListPackingListsForWarehouseLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListPackingListsPendingInvoiceLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function pendingInvoiceList(Request $request, ListPackingListsPendingInvoiceLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListPackingListsPendingApprovalLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function pendingApprovalList(Request $request, ListPackingListsPendingApprovalLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListPackingListsPendingPaymentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function pendingPaymentList(Request $request, ListPackingListsPendingPaymentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListPackingListsPaidInvoiceLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function paidInvoiceList(Request $request, ListPackingListsPaidInvoiceLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ class MonthlyReportController
|
||||
});
|
||||
|
||||
$packages = $packingLists->map(function ($packingList) {
|
||||
$replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first();
|
||||
$userType = Auth() && Auth()->user() ? Auth()->user()->type : RoleTypes::USER;
|
||||
$exceptionUsers = in_array($userType, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
||||
|
||||
$replica = $exceptionUsers ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first();
|
||||
return $replica ? $replica : $packingList;
|
||||
})->flatMap(function ($packingList) {
|
||||
return $packingList->packages;
|
||||
@@ -107,7 +110,9 @@ class MonthlyReportController
|
||||
});
|
||||
|
||||
$packages = $packingLists->map(function ($packingList) {
|
||||
$replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first();
|
||||
$userType = Auth() && Auth()->user() ? Auth()->user()->type : RoleTypes::USER;
|
||||
$exceptionUsers = in_array($userType, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
||||
$replica = $exceptionUsers ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first();
|
||||
return $replica ? $replica : $packingList;
|
||||
})->flatMap(function ($packingList) {
|
||||
return $packingList->packages;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Transactions;
|
||||
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\FetchGroupLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchGroupController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchGroupLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchGroupLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Transactions;
|
||||
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\FetchTransactionLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchTransactionController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchTransactionLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchTransactionLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -6,7 +6,8 @@ namespace App\Http\Controllers\Transactions;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\RegenerateSingleShippingInvoiceTransactionLogic;
|
||||
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\RegenerateSingleSalesOrderLogic;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\RegenerateSingleShippingEInvoiceLogic;
|
||||
|
||||
class RegenerateSingleShippingInvoiceTransactionController
|
||||
{
|
||||
@@ -18,4 +19,22 @@ class RegenerateSingleShippingInvoiceTransactionController
|
||||
public function regenerate(Request $request, RegenerateSingleShippingInvoiceTransactionLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param RegenerateSingleSalesOrderLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function regenerateSalesOrder(Request $request, RegenerateSingleSalesOrderLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param RegenerateSingleShippingEInvoiceLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function regenerateEInvoice(Request $request, RegenerateSingleShippingEInvoiceLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Transactions;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\RegenerateSingleStorageInvoiceTransactionLogic;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\RegenerateSingleStorageEInvoiceLogic;
|
||||
|
||||
|
||||
class RegenerateSingleStorageInvoiceTransactionController
|
||||
@@ -18,4 +19,13 @@ class RegenerateSingleStorageInvoiceTransactionController
|
||||
public function regenerate(Request $request, RegenerateSingleStorageInvoiceTransactionLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param RegenerateSingleStorageEInvoiceLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function regenerateEInvoice(Request $request, RegenerateSingleStorageEInvoiceLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -72,9 +72,10 @@ class Kernel extends HttpKernel
|
||||
'token.check' => \App\Http\Middleware\TokenCheckerMiddleware::class,
|
||||
'auth.check' => \App\Http\Middleware\CheckAuthorizationMiddleware::class,
|
||||
'storage.invoice.check.byorder' => \App\Http\Middleware\CheckForStorageInvoiceByOrderId::class,
|
||||
'storage.invoice.check.bytransaction' => \App\Http\Middleware\CheckForStorageInvoiceByTransactionId::class,
|
||||
'storage.invoice.check.bytransactions' => \App\Http\Middleware\CheckForStorageInvoiceByTransactions::class,
|
||||
'storage.invoice.check.bygroup' => \App\Http\Middleware\CheckForStorageInvoiceByGroup::class,
|
||||
'storage.invoice.check.bypackinglists' => \App\Http\Middleware\CheckForStorageInvoiceByPackingLists::class,
|
||||
'admin' => \App\Http\Middleware\EnsureUserIsAdmin::class, //cief todo: 90 - maintenance
|
||||
'admin' => \App\Http\Middleware\EnsureUserIsAdmin::class, //cief maintenance
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Classes\Jobs\Commands\V2\CheckStorageInvoicesSingleOrderV2CommandJob;
|
||||
use Closure;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
@@ -47,15 +48,25 @@ class CheckForStorageInvoiceByPackingLists
|
||||
// }
|
||||
|
||||
if(isset($filters['check_for_storage_invoice'])){
|
||||
unset($filters['order_by']);
|
||||
$packinglists = $this->listsPackingLists->execute($filters);
|
||||
// unset($filters['order_by']); //cief todo: 90 - DEBUG, original
|
||||
// $packinglists = $this->listsPackingLists->execute($filters); //cief todo: 90 - DEBUG, original
|
||||
|
||||
$packinglists = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters'))); //cief todo: 90 - DEBUG
|
||||
Log::info('CheckForStorageInvoiceByPackingLists $packinglists ' . count($packinglists));
|
||||
Log::info('CheckForStorageInvoiceByPackingLists $packinglists ' . json_encode($packinglists)); //cief todo: 90 - DEBUG
|
||||
foreach($packinglists as $packingList){
|
||||
if($packingList){
|
||||
$order = $packingList->owner()->first();
|
||||
if($order instanceof Order){
|
||||
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
if($storages){
|
||||
$results = array_merge($results, $storages);
|
||||
if(isset($filters['check_for_storage_invoice_asynchronously'])){
|
||||
Log::info("check_for_storage_invoice_asynchronously Order - ID: {$order->id}, Reference: {$order->reference}");
|
||||
CheckStorageInvoicesSingleOrderV2CommandJob::dispatch($order);
|
||||
}
|
||||
else{
|
||||
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
if($storages){
|
||||
$results = array_merge($results, $storages);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\General\LogHelper;
|
||||
|
||||
class CheckForStorageInvoiceByTransactionId
|
||||
{
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $storageInvoiceTransactionProcessor;
|
||||
|
||||
|
||||
public function __construct(CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
|
||||
{
|
||||
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$transactionId = $request->route('transaction_id');
|
||||
LogHelper::channel('storage_invoices')->info('CheckForStorageInvoiceByTransactionId: ' . $transactionId);
|
||||
$storages = [];
|
||||
try{
|
||||
$transaction = Transaction::where('id', $transactionId)->first();
|
||||
if($transaction){
|
||||
$storages = $this->storageInvoiceTransactionProcessor->executeShippingTransaction($transaction);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$storages = [];
|
||||
}
|
||||
$request->merge(['storages' => $storages]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
'move-order/api/move',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,17 +42,6 @@ class ContainerBaseResource extends JsonResource
|
||||
protected function getSortedPackingLists()
|
||||
{
|
||||
$sortedPackingLists = $this->packingLists()->get()->sortBy(fn ($packingList) => $packingList->owner->company_module_id);
|
||||
foreach ($sortedPackingLists as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = false;
|
||||
$item['include_base_only_in_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = false;
|
||||
$item['include_transport_in_packages'] = false;
|
||||
$item['include_container_in_packages'] = false;
|
||||
$item['include_packing_list_reference_in_packages'] = false;
|
||||
}
|
||||
return $this->whenLoaded('packingLists', PackingListBaseResource::collection($sortedPackingLists));
|
||||
return $this->whenLoaded('packingLists', PackingListForContainerBaseResource::collection($sortedPackingLists));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class DistrictResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'city' => $this->name,
|
||||
'city_state' => $this->name . ' - ' . optional($this->state)->name,
|
||||
'state' => $this->state,
|
||||
'country' => $this->country,
|
||||
'postcode' => $this->postcode,
|
||||
|
||||
@@ -4,13 +4,10 @@ namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderV2Resource extends JsonResource
|
||||
class FetchOrderResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
@@ -31,13 +28,16 @@ class OrderV2Resource extends JsonResource
|
||||
'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()),
|
||||
'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()),
|
||||
'invoices' => $this->whenLoaded('packingLists', function() {
|
||||
return TransactionWithStorageResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get());
|
||||
$transactions = $this->transactions()->whereNotIn('transactions.status', [0, 1])->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get();
|
||||
foreach ($transactions as $transaction) {
|
||||
$transaction['is_einvoice_applicable'] = $this->companyModule->company->e_invoice === 1;
|
||||
}
|
||||
return TransactionWithStorageResource::collection($transactions);
|
||||
}),
|
||||
'storages' => $this->storages ? $this->storages : null, //from middleware
|
||||
'remarks' => RemarkResource::collection($this->remarks),
|
||||
'supplier_tax_rebate' => SupplierTaxRebateResource::collection($this->supplierTaxRebate),
|
||||
'created_at' => $this->created_at->format('d-m-Y')
|
||||
'created_at' => $this->created_at->format('d-m-Y'),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
//PNB - Payment And Billing Page
|
||||
//Class based on GroupResource.php
|
||||
class GroupPaidInvoicePNBPageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
// dd($this->groupTransactions);
|
||||
$payment_transaction = Transaction::where('payment_reference', $this->reference)->first();
|
||||
|
||||
return [
|
||||
// 'id' => $this->id,
|
||||
'invoices' => GroupTransactionResource::collection($this->groupTransactions),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
//PNB - Payment And Billing Page
|
||||
//Class based on GroupResource.php
|
||||
class GroupPaidInvoicesPNBPageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
// dd($this->groupTransactions);
|
||||
$payment_transaction = Transaction::where('payment_reference', $this->reference)->first();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'original_amount' => (float) $this->original_amount,
|
||||
'original_currency' => new CurrencyResource($this->original_currency),
|
||||
'issuer_name' => $this->issuerCompany->name,
|
||||
'issuer_id' => $this->issuerCompany->id,
|
||||
'amount' => (float) $this->amount,
|
||||
'service_charge' => (float) $this->amount,
|
||||
'currency' => new CurrencyResource($this->currency),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
||||
'currency_rate' => (float) $this->currency_rate,
|
||||
'status' => $this->status,
|
||||
'status_name' => ApprovalStatus::APPROVAL_STATUS_ID[$this->status],
|
||||
'payment_method' => $this->payment_method,
|
||||
'payment_method_name' => ucwords(PaymentMethodType::PAYMENT_METHODS_ID[$this->payment_method]),
|
||||
'reference' => $this->reference,
|
||||
'payment_transaction' => $payment_transaction ? [
|
||||
'id' => $payment_transaction->id,
|
||||
'status' => $payment_transaction->status,
|
||||
'status_name' => ApprovalStatus::APPROVAL_STATUS_ID[$payment_transaction->status],
|
||||
'documents' => $this->status === ApprovalStatus::APPROVED ? DocumentResource::collection($payment_transaction->documents->where('status', ApprovalStatus::APPROVED)) : DocumentResource::collection($payment_transaction->documents->where('status', ApprovalStatus::PENDING_VERIFICATION)),
|
||||
] : []
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ class GroupTransactionResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
if($this->transaction instanceof \App\Models\Transaction){
|
||||
$this->transaction['is_einvoice_applicable'] = false; //$this->transaction->owner->owner->companyModule->company->e_invoice === 1;
|
||||
}
|
||||
return new TransactionResource($this->transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ListPackingListDetailsJobResource extends JsonResource
|
||||
// 'order' => New OrderResource($this->owner)
|
||||
// ]),
|
||||
'container' => new ContainerResource($this->containers->first()),
|
||||
'packages' => PackageBaseResource::collection($packages),
|
||||
'packages' => PackageDeprecatedResource::collection($packages),
|
||||
$this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]),
|
||||
'shipping_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()),
|
||||
'suspended_invoice' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()),
|
||||
|
||||
@@ -37,7 +37,7 @@ class ListPackingListJobResource extends JsonResource
|
||||
// 'order' => New OrderResource($this->owner)
|
||||
// ]),
|
||||
'container' => new ContainerResource($this->containers->first()),
|
||||
'packages' => PackageBaseResource::collection($packages),
|
||||
'packages' => PackageDeprecatedResource::collection($packages),
|
||||
$this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]),
|
||||
'shipping_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()),
|
||||
'suspended_invoice' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()),
|
||||
|
||||
@@ -45,7 +45,7 @@ class ListPackingListJobWithStorageResource extends JsonResource
|
||||
// 'order' => New OrderResource($this->owner)
|
||||
// ]),
|
||||
'container' => new ContainerResource($this->containers->first()),
|
||||
'packages' => PackageBaseResource::collection($packages),
|
||||
'packages' => PackageDeprecatedResource::collection($packages),
|
||||
$this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]),
|
||||
'shipping_transaction' => count($storages) == 0 ? new TransactionWithStorageResource($shippingTransaction): null,
|
||||
'storages' => $storages,
|
||||
|
||||
+6
-6
@@ -15,7 +15,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
* @deprecated This class is deprecated and should not be used.
|
||||
* Use `OrderPackagesReceivedResource` instead or write a new one based on OrderPackagesReceivedResource
|
||||
*/
|
||||
class OrderPackagesBaseResource extends JsonResource
|
||||
class OrderPackagesDeprecatedResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
@@ -106,19 +106,19 @@ class OrderPackagesBaseResource extends JsonResource
|
||||
'parcels' => $this->whenLoaded('packingLists', function() use ($origin_warehouse_packages, $in_transit_packages, $destination_warehouse_packages, $delivered_packages, $received_packages) {
|
||||
return [
|
||||
$this->mergeWhen($this->include_packages_origin_warehouse, [
|
||||
'origin_warehouse_packages' => PackingListBaseResource::collection($origin_warehouse_packages)
|
||||
'origin_warehouse_packages' => PackingListDeprecatedResource::collection($origin_warehouse_packages)
|
||||
]),
|
||||
$this->mergeWhen($this->include_packages_in_transit, [
|
||||
'in_transit_packages' => PackingListBaseResource::collection($in_transit_packages)
|
||||
'in_transit_packages' => PackingListDeprecatedResource::collection($in_transit_packages)
|
||||
]),
|
||||
$this->mergeWhen($this->include_packages_destination_warehouse, [
|
||||
'destination_warehouse_packages' => PackingListBaseResource::collection($destination_warehouse_packages)
|
||||
'destination_warehouse_packages' => PackingListDeprecatedResource::collection($destination_warehouse_packages)
|
||||
]),
|
||||
$this->mergeWhen($this->include_packages_delivery, [
|
||||
'delivered_packages' => PackingListBaseResource::collection($delivered_packages)
|
||||
'delivered_packages' => PackingListDeprecatedResource::collection($delivered_packages)
|
||||
]),
|
||||
$this->mergeWhen($this->include_packages_received, [
|
||||
'received_packages' => PackingListBaseResource::collection($received_packages)
|
||||
'received_packages' => PackingListDeprecatedResource::collection($received_packages)
|
||||
]),
|
||||
];
|
||||
}),
|
||||
@@ -5,7 +5,7 @@ namespace App\Http\Resources;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
//Originally from OrderPackagesBaseResource
|
||||
//Originally from OrderPackagesDeprecatedResource
|
||||
class OrderPackagesReceivedResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderPackagesResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$origin_warehouse_packages = $this->originWarehousePackages()->get();
|
||||
$in_transit_packages = $this->inTransitPackages()->get();
|
||||
$destination_warehouse_packages = $this->destinationWarehousePackages()->get();
|
||||
$delivered_packages = $this->deliveredPackages()->get();
|
||||
$received_packages = $this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
'reference_contract' => (int) $this->type,
|
||||
'type' => (int) $this->type,
|
||||
'status' => (int) $this->status,
|
||||
'parcels' => $this->whenLoaded('packingLists', function() use ($origin_warehouse_packages, $in_transit_packages, $destination_warehouse_packages, $delivered_packages, $received_packages) {
|
||||
return [
|
||||
'origin_warehouse_packages' => PackingListForPackagesResource::collection($origin_warehouse_packages),
|
||||
'in_transit_packages' => PackingListForPackagesResource::collection($in_transit_packages),
|
||||
'destination_warehouse_packages' => PackingListForPackagesResource::collection($destination_warehouse_packages),
|
||||
'delivered_packages' => PackingListForPackagesResource::collection($delivered_packages),
|
||||
'received_packages' => PackingListForPackagesResource::collection($received_packages),
|
||||
];
|
||||
}),
|
||||
'created_at' => $this->created_at->format('d-m-Y')
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user