Merge branch 'transaction-invoice' into 'development'

notification

See merge request CIEFWorldwideSdnBhd/shipping-portal!106
This commit is contained in:
Leong Chee Siong
2022-03-06 06:46:50 +00:00
17 changed files with 383 additions and 33 deletions
@@ -0,0 +1,15 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Notifiable
{
public function subject(): morphMany;
public function target(): morphMany;
public function causer(): morphMany;
}
@@ -0,0 +1,101 @@
<?php
namespace App\Classes\Modules\Notifications\DataTransferObjects;
use App\Classes\General\Interfaces\Notifiable;
use App\Classes\General\Interfaces\DataTransferObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
class NotificationObject implements DataTransferObject
{
/** @var string */
private $title;
/** @var string */
private $description;
/** @var Notifiable */
private $subject;
/** @var Notifiable */
private $target;
/** @var Notifiable */
private $causer;
/** @var int|null */
private $status;
/**
* OrderObject constructor.
* @param string $reference
* @param int $type
* @param int|null $status
*/
public function __construct(
string $title,
string $description,
Notifiable $subject,
Notifiable $target,
Notifiable $causer,
?int $status = ApprovalStatus::PENDING_VERIFICATION
)
{
$this->title = $title;
$this->description = $description;
$this->subject = $subject;
$this->target = $target;
$this->causer = $causer;
$this->status = $status;
}
/**
* @return int
*/
public function getTitle(): string
{
return $this->title;
}
/**
* @return int
*/
public function getDescription(): string
{
return $this->description;
}
/**
* @return Notifiable
*/
public function getSubject(): Notifiable
{
return $this->subject;
}
/**
* @return Notifiable
*/
public function getTarget(): Notifiable
{
return $this->target;
}
/**
* @return Notifiable
*/
public function getCauser(): Notifiable
{
return $this->causer;
}
/**
* @return int
*/
public function getStatus(): int
{
return $this->status;
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Notifications\Processors;
use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
use App\Classes\Modules\Notifications\Services\CreatesNotification;
class CreateNotificationProcessor
{
/** @var CreatesNotification */
private $createsNotification;
/**
* CreateNotificationProcessor constructor.
* @param CreatesNotification $createsNotification
*/
public function __construct(CreatesNotification $createsNotification)
{
$this->createsNotification = $createsNotification;
}
public function execute(NotificationObject $object)
{
$notification = $this->createsNotification->execute($object);
return $notification;
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Notifications\Services;
use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
use App\Models\Notification;
class CreatesNotification
{
/**
* @param NotificationObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(NotificationObject $object) {
$model = new Notification();
$model->title = $object->getTitle();
$model->description = $object->getDescription();
$model->status = $object->getStatus();
$model->subject_type = get_class($object->getSubject());
$model->subject_id = $object->getSubject()->id;
$model->target_type = get_class($object->getTarget());
$model->target_id = $object->getTarget()->id;
$model->causer_type = get_class($object->getCauser());
$model->causer_id = $object->getCauser()->id;
$model->save();
return $model;
}
}
@@ -8,29 +8,37 @@ use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
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\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
// use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
// use App\Classes\Modules\Transactions\Services\FetchesTransaction;
// use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
// use App\Classes\Modules\Documents\Services\CreatesDocument;
// use App\Classes\Modules\Documents\Services\CreatesFiles;
// use App\Classes\ValueObjects\Constants\DocumentType;
// use App\Models\Document;
// use App\Models\Transaction;
// use Barryvdh\DomPDF\PDF;
// use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
// use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf;
// use Meneses\LaravelMpdf\Facades\LaravelMpdf;
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
{
@@ -58,8 +66,16 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
/** @var CreatesTransaction */
private $createsTransaction;
/** @var CreatesTransactionDetail */
private $createsTransactionDetail;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
// /** @var FetchesTransaction */
// private $fetchesTransaction;
// /** @var UpdatesTransactionStatus */
// private $updatesTransactionStatus;
// /** @var CreatesDocument */
@@ -68,23 +84,16 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
// private $createsFile;
// /** @var PDF */
// private $pdf;
/**
* CreateSupplierTransactionLogic constructor.
* @param FetchesPackingList $fetchesPackingList
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param PDF $pdf
*/
public function __construct(
FetchesPackingList $fetchesPackingList,
FetchesSegmentConstant $fetchesSegmentConstant,
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
CreatesTransaction $createsTransaction
CreatesTransaction $createsTransaction,
CreatesTransactionDetail $createsTransactionDetail,
CreatesDocument $createsDocument,
CreatesFiles $createsFile
// UpdatesTransactionStatus $updatesTransactionStatus,
// CreatesDocument $createsDocument,
// CreatesFiles $createsFile,
// PDF $pdf
@@ -95,6 +104,9 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->createsTransactionDetail = $createsTransactionDetail;
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
// $this->updatesTransactionStatus = $updatesTransactionStatus;
// $this->createsDocument = $createsDocument;
@@ -185,8 +197,31 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
ApprovalStatus::PENDING_SUBMISSION
);
$transactions = $this->createsTransaction->execute($packing_list, $object);
$invoice_transaction = $this->createsTransaction->execute($packing_list, $object);
$object_detail = new TransactionDetailObject(
$invoice_transaction->bill_no,
$invoice_transaction->bill_no,
1,
$invoice_transaction->amount,
$invoice_transaction->amount
);
$transaction_detail = $this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
$transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['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->createsFile->execute($document, $document_object);
dd('yess');
return $this->response([]);
}
}
@@ -18,8 +18,8 @@ class CreatesTransactionDetail extends AbstractUpdateRelationshipRecord
*/
public function execute(Transaction $transaction, TransactionDetailObject $object) {
$model = new TransactionDetail();
$model->product_code = $object->getCode();
$model->product_name = $object->getName();
$model->reference = $object->getReference();
$model->name = $object->getName();
$model->quantity = $object->getQuantity();
$model->price = $object->getPrice();
$model->amount = $object->getAmount();
@@ -21,4 +21,8 @@ final class DocumentType {
public const DELIVER_ORDER = 'DELIVER_ORDER';
public const INVOICE = 'INVOICE';
public const SUPPLIER_DELIVER_ORDER = 'SUPPLIER_DELIVER_ORDER';
public const SHIPPING_INVOICE = 'SHIPPING_INVOICE';
}
@@ -0,0 +1,11 @@
<?php
namespace App\Classes\ValueObjects\Constants;
final class NotificationType
{
public const SUPERVISOR = 0;
}
@@ -2,13 +2,11 @@
namespace App\Classes\ValueObjects\Constants;
class Notifications
{
public const UNDEFINED = [
'title' => 'Unknown Action',
'message' => 'unknown message..'
public const NEW_ARRIVED_PARCEL = [
'title' => 'New Arrived Parcel',
'message' => 'you have received new parcel for your order #-'
];
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class CountryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'short_code' => $this->short_code,
'phone_code' => $this->phone_code,
];
}
}
+3 -1
View File
@@ -3,6 +3,7 @@
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Models\Order;
use App\Models\PackingList;
@@ -32,7 +33,8 @@ class PackingListResource extends JsonResource
'packages' => PackageResource::collection($packages),
$this->mergeWhen($this->owner instanceof Order, [
'order' => New OrderResource($this->owner)
])
]),
'shippng_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->first()),
];
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ class TransactionResource extends JsonResource
return [
'id' => $this->id,
'booking' => new BookingResource($this->booking),
// 'booking' => new BookingResource($this->booking),
'type' => (int) $this->type,
'bill_no' => $this->bill_no,
'amount' => (double) $this->amount,
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Notification extends AbstractModel
{
use SoftDeletes;
protected $table = 'notifications';
public function package(): BelongsTo
{
return $this->BelongsTo(Package::class, 'package_id', 'id');
}
}
+31 -5
View File
@@ -6,6 +6,7 @@ use App\Classes\General\Interfaces\Addressable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\Packable;
use App\Classes\General\Interfaces\Remarkable;
use App\Classes\General\Interfaces\Notifiable;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
@@ -16,7 +17,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Order extends AbstractModel implements Addressable, Packable, Remarkable
class Order extends AbstractModel implements Addressable, Packable, Remarkable, Notifiable
{
use SoftDeletes;
@@ -33,6 +34,31 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable
return $this->belongsTo(CompanyModule::class, 'company_module_id', 'id');
}
/**
* @return MorphMany
*/
public function subject(): morphMany
{
return $this->morphMany(Notification::class, 'subject_type');
}
/**
* @return MorphMany
*/
public function target(): morphMany
{
return $this->morphMany(Notification::class, 'target');
}
/**
* @return MorphMany
*/
public function causer(): morphMany
{
return $this->morphMany(Notification::class, 'causer');
}
/**
* @return MorphMany
*/
@@ -153,8 +179,8 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable
/**
* @return morphMany
*/
public function transactions(): morphMany
{
return $this->morphMany(Transaction::class, 'owner');
}
// public function transactions(): morphMany
// {
// return $this->morphMany(Transaction::class, 'owner');
// }
}
+1 -1
View File
@@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Transaction extends AbstractModel implements Documentable
{
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
class CreateNotificationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('description');
$table->morphs('subject');
$table->morphs('target');
$table->morphs('causer');
$table->integer('status')->default(ApprovalStatus::APPROVED);
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notifications');
}
}
@@ -0,0 +1,19 @@
@extends('layouts.base_pdf')
@section('inner_content')
<table>
<thead>
<tr>
<th>Bill No</th>
<th>Packing List</th>
<th>Total Cbm</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $invoice_transaction->bill_no }}</td>
<td>{{ $invoice_transaction->owner()->first()->reference }}</td>
<td>{{ $invoice_transaction->original_amount }}</td>
</tr>
</tbody>
</table>
@endsection