diff --git a/app/Classes/General/Interfaces/Notifiable.php b/app/Classes/General/Interfaces/Notifiable.php new file mode 100644 index 00000000..b97a08c7 --- /dev/null +++ b/app/Classes/General/Interfaces/Notifiable.php @@ -0,0 +1,15 @@ +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; + } + + +} diff --git a/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php new file mode 100644 index 00000000..d6b077f8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php @@ -0,0 +1,27 @@ +createsNotification = $createsNotification; + } + + public function execute(NotificationObject $object) + { + $notification = $this->createsNotification->execute($object); + return $notification; + } +} diff --git a/app/Classes/Modules/Notifications/Services/CreatesNotification.php b/app/Classes/Modules/Notifications/Services/CreatesNotification.php new file mode 100644 index 00000000..4f5ca5fd --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/CreatesNotification.php @@ -0,0 +1,30 @@ +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; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php index b6edcc5f..e4729533 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php @@ -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([]); } } diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php index 0e852ddf..bdb0f387 100644 --- a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php @@ -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(); diff --git a/app/Classes/ValueObjects/Constants/DocumentType.php b/app/Classes/ValueObjects/Constants/DocumentType.php index 2b053163..75db231a 100644 --- a/app/Classes/ValueObjects/Constants/DocumentType.php +++ b/app/Classes/ValueObjects/Constants/DocumentType.php @@ -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'; + } diff --git a/app/Classes/ValueObjects/Constants/NotificationType.php b/app/Classes/ValueObjects/Constants/NotificationType.php new file mode 100644 index 00000000..0c9ec5a4 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/NotificationType.php @@ -0,0 +1,11 @@ + 'Unknown Action', - 'message' => 'unknown message..' + public const NEW_ARRIVED_PARCEL = [ + 'title' => 'New Arrived Parcel', + 'message' => 'you have received new parcel for your order #-' ]; } \ No newline at end of file diff --git a/app/Http/Resources/CountryResource.php b/app/Http/Resources/CountryResource.php new file mode 100644 index 00000000..f15c41f8 --- /dev/null +++ b/app/Http/Resources/CountryResource.php @@ -0,0 +1,24 @@ + $this->id, + 'name' => $this->name, + 'short_code' => $this->short_code, + 'phone_code' => $this->phone_code, + ]; + } +} diff --git a/app/Http/Resources/PackingListResource.php b/app/Http/Resources/PackingListResource.php index 82065b18..5256e3de 100644 --- a/app/Http/Resources/PackingListResource.php +++ b/app/Http/Resources/PackingListResource.php @@ -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()), ]; } } diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index ef652fd7..05c35038 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -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, diff --git a/app/Models/Notification.php b/app/Models/Notification.php new file mode 100644 index 00000000..06bd6024 --- /dev/null +++ b/app/Models/Notification.php @@ -0,0 +1,18 @@ +BelongsTo(Package::class, 'package_id', 'id'); + } +} diff --git a/app/Models/Order.php b/app/Models/Order.php index 5aabfd44..955e6a4c 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -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'); + // } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 232964d9..9ca9c24f 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -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 { diff --git a/database/migrations/2022_02_18_120837_create_notifications_table.php b/database/migrations/2022_02_18_120837_create_notifications_table.php new file mode 100644 index 00000000..d14cdc89 --- /dev/null +++ b/database/migrations/2022_02_18_120837_create_notifications_table.php @@ -0,0 +1,40 @@ +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'); + } +} diff --git a/resources/views/pages/pdfs/shipping_invoice.blade.php b/resources/views/pages/pdfs/shipping_invoice.blade.php new file mode 100644 index 00000000..cfd491eb --- /dev/null +++ b/resources/views/pages/pdfs/shipping_invoice.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.base_pdf') +@section('inner_content') +
| Bill No | +Packing List | +Total Cbm | +
|---|---|---|
| {{ $invoice_transaction->bill_no }} | +{{ $invoice_transaction->owner()->first()->reference }} | +{{ $invoice_transaction->original_amount }} | +