diff --git a/app/Classes/CodeGenerator/Commands/Scaffold/ScaffoldGeneratorCommand.php b/app/Classes/CodeGenerator/Commands/Scaffold/ScaffoldGeneratorCommand.php index dc370e61..450f82c0 100644 --- a/app/Classes/CodeGenerator/Commands/Scaffold/ScaffoldGeneratorCommand.php +++ b/app/Classes/CodeGenerator/Commands/Scaffold/ScaffoldGeneratorCommand.php @@ -89,7 +89,7 @@ class ScaffoldGeneratorCommand extends BaseCommand */ protected function checkIsThereAnyDataToGenerate() { - if (count($this->commandData->fields) > 1) { + if (count($this->commandData->fields) > 0) { return true; } } diff --git a/app/Classes/CodeGenerator/Schemas/serviceType.json b/app/Classes/CodeGenerator/Schemas/serviceType.json new file mode 100644 index 00000000..c1951a44 --- /dev/null +++ b/app/Classes/CodeGenerator/Schemas/serviceType.json @@ -0,0 +1,13 @@ +[ + { + "name": "name", + "dbType": "string", + "htmlType": "text", + "validations": "required", + "searchable": true, + "fillable": true, + "primary": false, + "inForm": true, + "inIndex": true + } +] diff --git a/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php b/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php new file mode 100644 index 00000000..63e035b5 --- /dev/null +++ b/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php @@ -0,0 +1,34 @@ +save($model)){ + return $model; + } + + } catch (QueryException $exception){ + throw new MalformedRequestException('Unable to update the record due to unexpected error'); + } + } + + + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/CompanyId.php b/app/Classes/General/Eloquent/Filters/CompanyId.php new file mode 100644 index 00000000..379326cf --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/CompanyId.php @@ -0,0 +1,20 @@ +where('company_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Interfaces/Documentable.php b/app/Classes/General/Interfaces/Documentable.php new file mode 100644 index 00000000..bc2baa71 --- /dev/null +++ b/app/Classes/General/Interfaces/Documentable.php @@ -0,0 +1,13 @@ +canCreateAddress = $canCreateAddress; + $this->createsAddress = $createsAddress; + $this->resetsAddressDefault = $resetsAddressDefault; + $this->setsAddressDefault = $setsAddressDefault; + } + /** * @return array @@ -31,16 +49,12 @@ class CreateAddressLogic extends AbstractControllerLogic /** @var CreatesAddress */ private $createsAddress; - /** - * CreateAddressControllerLogic constructor. - * @param CanCreateAddress $canCreateAddress - * @param CreatesAddress $createsAddress - */ - public function __construct(CanCreateAddress $canCreateAddress, CreatesAddress $createsAddress) - { - $this->canCreateAddress = $canCreateAddress; - $this->createsAddress = $createsAddress; - } + /** @var ResetsAddressDefault */ + private $resetsAddressDefault; + + /** @var SetsAddressDefault */ + private $setsAddressDefault; + /** @@ -56,8 +70,13 @@ class CreateAddressLogic extends AbstractControllerLogic $this->canCreateAddress->passes($object); + /** @var Address $query */ $query = $this->createsAddress->execute($object); + $this->resetsAddressDefault->execute($query); + + $this->setsAddressDefault->execute($query); + return $this->resourceResponse(new AddressResource($query)); } catch (\Exception $exception){ diff --git a/app/Classes/Modules/Addresses/ControllersLogic/SetAddressDefaultLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/SetAddressDefaultLogic.php new file mode 100644 index 00000000..c16590e3 --- /dev/null +++ b/app/Classes/Modules/Addresses/ControllersLogic/SetAddressDefaultLogic.php @@ -0,0 +1,79 @@ +fetchesAddress = $fetchesAddress; + $this->resetsAddressDefault = $resetsAddressDefault; + $this->setsAddressDefault = $setsAddressDefault; + } + + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Set Default Address', + 'message' => 'You have successfully updated your default address' + ]; + } + + /** @var FetchesAddress */ + private $fetchesAddress; + + /** @var ResetsAddressDefault */ + private $resetsAddressDefault; + + /** @var SetsAddressDefault */ + private $setsAddressDefault; + + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $address = $this->fetchesAddress->execute(['id' => $request->route('id')]); + + $this->resetsAddressDefault->execute($address); + + $this->setsAddressDefault->execute($address); + + return $this->resourceResponse(new AddressResource($address)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/Services/ResetsAddressDefault.php b/app/Classes/Modules/Addresses/Services/ResetsAddressDefault.php new file mode 100644 index 00000000..bf0cf704 --- /dev/null +++ b/app/Classes/Modules/Addresses/Services/ResetsAddressDefault.php @@ -0,0 +1,23 @@ +company->addresses()->update([ + 'default' => false, + 'billing' => false + ]); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/Services/SetsAddressDefault.php b/app/Classes/Modules/Addresses/Services/SetsAddressDefault.php new file mode 100644 index 00000000..a2799ee9 --- /dev/null +++ b/app/Classes/Modules/Addresses/Services/SetsAddressDefault.php @@ -0,0 +1,24 @@ +default = true; + $model->billing = true; + + $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyIdentificationDocumentLogic.php new file mode 100644 index 00000000..fdb01595 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyIdentificationDocumentLogic.php @@ -0,0 +1,100 @@ + 'Company Identification', + 'message' => 'You have successfully created a new Company Identification Document' + ]; + } + + /** @var FetchesUser */ + private $fetchesUser; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFile */ + private $createsFile; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + /** + * UpdateCompanyIdentificationDocumentLogic constructor. + * @param FetchesUser $fetchesUser + * @param FetchesCompany $fetchesCompany + * @param CreatesDocument $createsDocument + * @param CreatesFile $createsFile + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct(FetchesUser $fetchesUser, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFile $createsFile, UpdatesCompanyStatus $updatesCompanyStatus) + { + $this->fetchesUser = $fetchesUser; + $this->fetchesCompany = $fetchesCompany; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $object = new DocumentObject( + $company->type === CompanyTypes::COMPANY_BUSINESS ? DocumentType::SSM_REGISTRATION: DocumentType::IDENTITY_CARD, + $request->input('files'), $request->input('reference')); + + /** @var Document $document */ + $document = $this->createsDocument->execute($company, $object); + + $this->createsFile->execute($document, $object); + + $this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION); + + return $this->resourceResponse(new DocumentResource($document)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php new file mode 100644 index 00000000..f0c0968b --- /dev/null +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php @@ -0,0 +1,25 @@ +status = $status; + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php new file mode 100644 index 00000000..c6e76803 --- /dev/null +++ b/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php @@ -0,0 +1,84 @@ + 'Approve Document', + 'message' => 'You have successfully approved the Document' + ]; + } + + /** @var CanUpdateDocument */ + private $canUpdateDocument; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateDocument $canUpdateDocument + * @param ApprovesDocument $approvesDocument + * @param FetchesDocument $fetchesDocument + */ + public function __construct( + canUpdateDocument $canUpdateDocument, + ApprovesDocument $approvesDocument, + FetchesDocument $fetchesDocument + ) + { + $this->canUpdateDocument = $canUpdateDocument; + $this->approvesDocument = $approvesDocument; + $this->fetchesDocument = $fetchesDocument; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $document = $this->fetchesDocument->execute(['id' => $request->route('id')]); + + $this->canUpdateDocument->passes($document); + + $document_query = $this->approvesDocument->execute($document); + + + return $this->resourceResponse(new DocumentResource($document_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php new file mode 100644 index 00000000..3c4a3ce1 --- /dev/null +++ b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php @@ -0,0 +1,66 @@ + 'Retrieved Document', + 'message' => 'You have successfully retrieved a list of Document' + ]; + } + + /** @var CanListDocuments */ + private $canListDocuments; + + /** @var ListsDocuments */ + private $listsDocuments; + + /** + * ListStandardSegmentLogic constructor. + * @param CanListDocuments $canListDocuments + * @param ListsDocuments $listsDocuments + */ + public function __construct(CanListDocuments $canListDocuments, ListsDocuments $listsDocuments) + { + $this->canListDocuments = $canListDocuments; + $this->listsDocuments = $listsDocuments; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $this->canListDocuments->passes(); + + $query = $this->listsDocuments->execute($this->listsDocuments->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(DocumentResource::collection($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php new file mode 100644 index 00000000..256477ce --- /dev/null +++ b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php @@ -0,0 +1,61 @@ +document_type = $document_type; + $this->files = $files; + $this->reference = $reference; + } + + + /** + * @return string + */ + public function getDocumentType(): string + { + return $this->document_type; + } + + /** + * @return string|null + */ + public function getReference(): string + { + return $this->reference; + } + + /** + * @return array + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function getFiles(): array + { + return (new ConvertsBase64ToFile())->convert($this->files); + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php b/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php new file mode 100644 index 00000000..ff7b0615 --- /dev/null +++ b/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php @@ -0,0 +1,86 @@ +data = $data; + } + + /** + * @return \Intervention\Image\Image|string + * @throws MalformedRequestException + */ + public function getData() + { + return $this->getExtension() === 'pdf' ? $this->data : (new imageManager())->make($this->data); + } + + /** + * @return string + */ + public function getFileName(): string + { + return (string) Str::uuid(); + } + + /** + * @return string + */ + public function getMimeType(): string + { + return finfo_file(finfo_open(), $this->data, FILEINFO_MIME_TYPE); + } + + /** + * @return string + * @throws MalformedRequestException + */ + public function getExtension(): string + { + if(array_key_exists($this->getMimeType(), File::EXTENSION)){ + return File::EXTENSION[$this->getMimeType()]; + } + + throw new MalformedRequestException('Failed to save file due to Unknown file extension'); + } + + /** + * @return string + * @throws MalformedRequestException + */ + public function getDecodedData(): string + { + return $this->getExtension() === 'pdf' ? + base64_decode((explode('base64,', $this->getData()))[1]): + $this->getData()->encode('data-url')->encoded; + } + + /** + * @param string $data + */ + public function setData(string $data): void + { + $this->data = $data; + } + + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ApprovesDocument.php b/app/Classes/Modules/Documents/Services/ApprovesDocument.php new file mode 100644 index 00000000..3bf39971 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ApprovesDocument.php @@ -0,0 +1,27 @@ +status = ApprovalStatus::ACTIVE; + $model->approved_by = Auth()->user()->id; + $model->approved_date = Carbon::now(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php new file mode 100644 index 00000000..88e078d6 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php @@ -0,0 +1,128 @@ +path = $path; + $this->filesInfo = []; + + File::isDirectory(storage_path($this->path)) or + File::makeDirectory(storage_path($this->path), 0777, true, true); + } + + + /** + * @param array $files + * @return array + * @throws MalformedRequestException + */ + public function convert($files = []){ + foreach ($files as $file) { + + $object = new FileObject($file); + $object->getExtension() === 'pdf' ? $this->generatePDF($object) : $this->generateImage($object); + + } + + return $this->filesInfo; + + } + + /** + * @param FileObject $file + * @throws MalformedRequestException + */ + private function generatePDF(FileObject $file){ + + $filePath = $this->generateFile($file); + $this->updateFiles($file, [ 'original' => [ 'file' => $filePath ] ]); + } + + /** + * @param FileObject $file + * @throws MalformedRequestException + */ + private function generateImage(FileObject $file){ + + $fileInfo = []; + + foreach (['original' => null, 'large' => 800, 'medium' => 480, 'small' => 320] as $size => $value) { + $suffix = $size !== 'original' ? '_'.$size : ''; + + if($size !== 'original') { + $thumbnail = $file->getData()->widen($value, function ($constraint) { + + $constraint->upsize(); + + })->heighten($value, function ($constraint) { + + $constraint->upsize(); + + }); + + $file->setData($thumbnail->encode('data-url')->encoded); + } + + + $filePath = $this->generateFile($file, $suffix); + + $fileInfo[] = [ $size => [ 'file' => $filePath, 'width' => $file->getData()->width(), 'height' => $file->getData()->height() ]]; + + + } + + $this->updateFiles($file, $fileInfo); + + } + + /** + * @param FileObject $file + * @param string $suffix + * @return string + * @throws MalformedRequestException + */ + private function generateFile(FileObject $file, string $suffix = '') { + + $filePath = storage_path($this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension()); + + Storage::put($filePath, $file->getDecodedData()); + + return $filePath; + + } + + /** + * @param FileObject $file + * @param array $fileInfo + * @throws MalformedRequestException + */ + private function updateFiles(FileObject $file, array $fileInfo){ + $this->filesInfo[] = json_encode([ + 'path' => $this->path, + 'filename' => $file->getFileName().'.'.$file->getExtension(), + 'mime_type' => $file->getMimeType(), + 'extension' => $file->getExtension(), + 'file_info' => $fileInfo + ]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/CreatesDocument.php b/app/Classes/Modules/Documents/Services/CreatesDocument.php new file mode 100644 index 00000000..16e7d094 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/CreatesDocument.php @@ -0,0 +1,26 @@ +document_type = $object->getDocumentType(); + $model->reference = $object->getReference(); + + return $this->handler($documentable->documents(), $model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/CreatesFile.php b/app/Classes/Modules/Documents/Services/CreatesFile.php new file mode 100644 index 00000000..9bde4a0e --- /dev/null +++ b/app/Classes/Modules/Documents/Services/CreatesFile.php @@ -0,0 +1,32 @@ +getFiles() as $file) { + + $model = new File(['file' => $file]); + $models[] = $this->handler($document->files(), $model); + + } + + return $models; + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/FetchesDocument.php b/app/Classes/Modules/Documents/Services/FetchesDocument.php new file mode 100644 index 00000000..1aa12c87 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/FetchesDocument.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ListsDocuments.php b/app/Classes/Modules/Documents/Services/ListsDocuments.php new file mode 100644 index 00000000..9f372279 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ListsDocuments.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanCreateDocument.php b/app/Classes/Modules/Documents/Standards/Rules/CanCreateDocument.php new file mode 100644 index 00000000..abac99e3 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanCreateDocument.php @@ -0,0 +1,53 @@ +documentValidation = $documentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param DocumentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->documentValidation->validate($object); + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanCreateFile.php b/app/Classes/Modules/Documents/Standards/Rules/CanCreateFile.php new file mode 100644 index 00000000..d029cf2a --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanCreateFile.php @@ -0,0 +1,53 @@ +fileValidation = $fileValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param FileObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->fileValidation->validate($object); + } + + /** + * @param FileObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php b/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php new file mode 100644 index 00000000..d94068b7 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php @@ -0,0 +1,45 @@ +can('view document')) { + return false; + } + + return true; + + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php b/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php new file mode 100644 index 00000000..f07fb166 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php @@ -0,0 +1,53 @@ +documentValidation = $documentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param DocumentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->documentValidation->validate($object); + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Validators/DocumentValidation.php b/app/Classes/Modules/Documents/Standards/Validators/DocumentValidation.php new file mode 100644 index 00000000..9ff7ef03 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Validators/DocumentValidation.php @@ -0,0 +1,53 @@ + $object->getOwnerId(), + 'owner_type' => $object->getOwnerType(), + 'document_type' => $object->getDocumentType(), + 'reference' => $object->getReference(), + 'status' => $object->getStatus(), + 'approved_by' => $object->getApprovedBy(), + 'issued_date' => $object->getIssuedDate(), + 'expired_date' => $object->getExpiredDate(), + 'approved_date' => $object->getApprovedDate() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'owner_id' => 'required', + 'owner_type' => 'required', + 'document_type' => 'required', + 'reference' => 'required', + 'status' => '', + 'issued_date' => '', + 'expired_date' => '', + 'approved_date' => '', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Validators/FileValidation.php b/app/Classes/Modules/Documents/Standards/Validators/FileValidation.php new file mode 100644 index 00000000..3c429714 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Validators/FileValidation.php @@ -0,0 +1,42 @@ + $object->getDocumentId(), + 'file' => $object->getFile(), + 'file_type' => $object->getFileType() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'document_id' => 'required', + 'file' => 'required', + 'file_type' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Orders/ControllersLogic/createPackagesListLogic.php b/app/Classes/Modules/Orders/ControllersLogic/createPackagesListLogic.php new file mode 100644 index 00000000..79025e08 --- /dev/null +++ b/app/Classes/Modules/Orders/ControllersLogic/createPackagesListLogic.php @@ -0,0 +1,15 @@ +description = $description; + $this->unitOfMeasurment = $unitOfMeasurment; + $this->quantity = $quantity; + $this->price = $price; + $this->currency = $currency; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return string + */ + public function getUnitOfMeasurment(): string + { + return $this->unitOfMeasurment; + } + + /** + * @return float + */ + public function getQuantity(): float + { + return $this->quantity; + } + + /** + * @return float + */ + public function getPrice(): float + { + return $this->price; + } + + /** + * @return string + */ + public function getCurrency(): string + { + return $this->currency; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Orders/DataTransferObjects/PackageObject.php b/app/Classes/Modules/Orders/DataTransferObjects/PackageObject.php new file mode 100644 index 00000000..88da98ce --- /dev/null +++ b/app/Classes/Modules/Orders/DataTransferObjects/PackageObject.php @@ -0,0 +1,83 @@ +type = $type; + $this->width = $width; + $this->height = $height; + $this->lenght = $lenght; + $this->items = $items; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return float + */ + public function getWidth(): float + { + return $this->width; + } + + /** + * @return float + */ + public function getHeight(): float + { + return $this->height; + } + + /** + * @return float + */ + public function getLenght(): float + { + return $this->lenght; + } + + /** + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Orders/DataTransferObjects/PackagesListObject.php b/app/Classes/Modules/Orders/DataTransferObjects/PackagesListObject.php new file mode 100644 index 00000000..da89289b --- /dev/null +++ b/app/Classes/Modules/Orders/DataTransferObjects/PackagesListObject.php @@ -0,0 +1,44 @@ +orderId = $orderId; + $this->packages = $packages; + } + + /** + * @return int + */ + public function getOrderId(): int + { + return $this->orderId; + } + + /** + * @return array + */ + public function getPackages(): array + { + return $this->packages; + } + + + +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/ApprovalStatus.php b/app/Classes/ValueObjects/Constants/ApprovalStatus.php new file mode 100644 index 00000000..2f6a7a4a --- /dev/null +++ b/app/Classes/ValueObjects/Constants/ApprovalStatus.php @@ -0,0 +1,21 @@ + 'gif', + 'image/png' => 'png', + 'image/jpeg' => 'jpeg', + 'application/pdf' => 'pdf', + ]; + +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/OwnerType.php b/app/Classes/ValueObjects/Constants/OwnerType.php new file mode 100644 index 00000000..4e87348a --- /dev/null +++ b/app/Classes/ValueObjects/Constants/OwnerType.php @@ -0,0 +1,7 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateCompanyIdentificationDocumentController.php b/app/Http/Controllers/Companies/UpdateCompanyIdentificationDocumentController.php new file mode 100644 index 00000000..5c452796 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyIdentificationDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Orders/OrderController.php b/app/Http/Controllers/Orders/OrderController.php index 30236117..ee6329bb 100644 --- a/app/Http/Controllers/Orders/OrderController.php +++ b/app/Http/Controllers/Orders/OrderController.php @@ -11,6 +11,7 @@ use App\Models\Company; use App\Models\CompanyConnections; use App\Models\Order; use Illuminate\Http\Request; +use Barryvdh\DomPDF\PDF; class OrderController { @@ -26,8 +27,8 @@ class OrderController $order->company_id = $company->id; $order->order_number = $generatesUniqueOrderNumber->execute(); $order->forwarder_id = 1; - $order->address_id = $company->addresses()->first()->id; - $order->contact_id = $company->contacts()->first()->id; + $order->address_id = $company->addresses->first()->id; + $order->contact_id = $company->contacts->first()->id; $order->current_step = 'MS_WAREHOUSE_RECEIVING'; $order->multiple_batch = false; $order->complete = false; @@ -59,7 +60,7 @@ class OrderController HttpStatus::OK_WITH_MESSAGE, json_decode(OrderResource::collection($orders)->response()->getContent(), true)))->handler(); } - public function download(String $orderId){ + public function download(String $orderId, PDF $pdf){ /** @var Order $order */ $order = order::findOrFail($orderId); /** @var Company $warehouse */ @@ -78,7 +79,7 @@ class OrderController return view('pages.pdf.qr', $data); - return $this->pdf->loadView('pages.pdf.qr', $data)->stream(); + return $pdf->loadView('pages.pdf.qr', $data)->download(); } } \ No newline at end of file diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php deleted file mode 100644 index 45e842ae..00000000 --- a/app/Http/Controllers/TestController.php +++ /dev/null @@ -1,271 +0,0 @@ -getToken(); - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, 'http://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, '{"controller":"WarehouseList","view":"grid1","request":{"PageSize":10000000, "Filter":["ParcelDate:>%js%\"2020-01-10T00:00:00.000\"\u0000"]}}'); - curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); - - $headers = array(); - $headers[] = 'Connection: keep-alive'; - $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'; - $headers[] = 'X-Requested-With: XMLHttpRequest'; - $headers[] = 'Content-Type: application/json; charset=UTF-8'; - $headers[] = 'Accept: */*'; - $headers[] = 'Origin: http://portalvt.azurewebsites.net'; - $headers[] = 'Referer: http://portalvt.azurewebsites.net/Pages/WarehouseList.aspx'; - $headers[] = 'Accept-Language: en-US,en;q=0.9'; - $headers[] = 'Cookie: '.implode('; ', $cookies); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $result = curl_exec($ch); - if (curl_errno($ch)) { - echo 'Error:' . curl_error($ch); - } - curl_close($ch); - dd(json_decode($result)); - } - private function getToken(){ - $cookies = $this->getCookies(); - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, 'http://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, '{"username":"CIEF","password":"0122120880","createPersistentCookie":true}'); - curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); - - $headers = array(); - $headers[] = 'Connection: keep-alive'; - $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'; - $headers[] = 'X-Requested-With: XMLHttpRequest'; - $headers[] = 'Content-Type: application/json; charset=UTF-8'; - $headers[] = 'Accept: */*'; - $headers[] = 'Origin: http://portalvt.azurewebsites.net'; - $headers[] = 'Referer: http://portalvt.azurewebsites.net/Login.aspx?ReturnUrl=%2fPages%2fHome.aspx'; - $headers[] = 'Accept-Language: en-US,en;q=0.9'; - $headers[] = 'Cookie: '.implode('; ', $cookies); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $result = curl_exec($ch); - if (curl_errno($ch)) { - echo 'Error:' . curl_error($ch); - } - curl_close($ch); - $cookies[] = 'AppVTCC='.json_decode($result)->d->Token; - return $cookies; - - } - - private function getCookies(){ - $cookies = []; - $curl_handle = curl_init('http://portalvt.azurewebsites.net/Login.aspx'); - - curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, false); - - curl_setopt($curl_handle, CURLOPT_HEADER, true); - - - $data = curl_exec($curl_handle); - - $responseHeader= substr($data,0, intval(curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE))); - - $endPosition = 0; - while(true) { - $startPosition = strpos($responseHeader, 'Set-Cookie: ', $endPosition); - if (!$startPosition){break;} - $startPosition += 12; - $endPosition = strpos($responseHeader, ';', $startPosition); - $cookies[] = substr($responseHeader,$startPosition,$endPosition-$startPosition); - } - - return $cookies; - } - - public function index2() { -// curl 'http://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login' \ -// -H 'Connection: keep-alive' \ -// -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36' \ -// -H 'X-Requested-With: XMLHttpRequest' \ -// -H 'Content-Type: application/json; charset=UTF-8' \ -// -H 'Accept: */*' \ -// -H 'Origin: http://portalvt.azurewebsites.net' \ -// -H 'Referer: http://portalvt.azurewebsites.net/Login.aspx?ReturnUrl=%2fPages%2fHome.aspx' \ -// -H 'Accept-Language: en-US,en;q=0.9' \ -// -H 'Cookie: ASP.NET_SessionId=cxe2tgbsi03jtg2p0nlfdcrl; ARRAffinity=2950dd3bc3c86410bd48fe08ed3595e06670f25d93c162510d25040b02f01a67' \ -// --data-binary '{"username":"CIEF","password":"0122120880","createPersistentCookie":true}' \ -// --compressed \ -// --insecure - - header('Content-Type: text/plain; charset=utf-8'); - - - - $post = array('createPersistentCookie'=>true, - 'username'=>'CIEF', - 'password'=>'0122120880'); - $request = array(); - $request[] = 'Connection: keep-alive'; - $request[] = 'Pragma: no-cache'; - $request[] = 'Cache-Control: no-cache'; - $request[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; - $request[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'; - $request[] = 'DNT: 1'; - $request[] = 'http://portalvt.azurewebsites.net/Login.aspx?ReturnUrl=%2fPages%2fHome.aspx'; - $request[] = 'Accept-Encoding: gzip, deflate'; - $request[] = 'Accept-Language: en-US,en;q=0.8'; - $request[] = 'Content-Type:multipart/form-data'; - - - $url = 'http://portalvt.azurewebsites.net/Login.aspx'; - $ch = curl_init($url); - - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - curl_setopt($ch, CURLOPT_HTTPHEADER, $request); - curl_setopt($ch, CURLOPT_ENCODING,""); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_TIMEOUT,10); - curl_setopt($ch, CURLOPT_FAILONERROR,true); - curl_setopt($ch, CURLOPT_ENCODING,""); - - curl_setopt($ch, CURLOPT_VERBOSE, true); - curl_setopt($ch, CURLINFO_HEADER_OUT, true); - curl_setopt($ch, CURLOPT_HEADER, true); - - - $data = curl_exec($ch); - - if (curl_errno($ch)){ - $data .= 'Retreive Base Page Error: ' . curl_error($ch); - var_dump($data); - } - else { - $info = rawurldecode(var_export(curl_getinfo($ch),true)); - - - - $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); - $responseHeader= substr($data,0,$skip); - - // The folowing line is for debug -// echo "$info\n$responseHeader\n$data\n\n"; - - - - // Get the cookies: - $e = 0; - while(true){ - $s = strpos($responseHeader,'Set-Cookie: ',$e); - if (!$s){break;} - $s += 12; - $e = strpos($responseHeader,';',$s); - $cookie = substr($responseHeader,$s,$e-$s) ; - $s = strpos($cookie,'='); - $key = substr($cookie,0,$s); - $value = substr($cookie,$s); - $cookies[$key] = $value; - } - - // Create cookie for subsequent Requests: - - $cookie = ''; - $show = ''; - $head = ''; - $delim = ''; - foreach ($cookies as $k => $v){ - $cookie .= "$delim$k$v"; - $delim = '; '; - } - } - -var_dump($cookies); - $request = array(); - $request[] = 'Host: portalvt.azurewebsites.net'; - $request[] = 'Connection: keep-alive'; - $request[] = 'Pragma: no-cache'; - $request[] = 'Cache-Control: no-cache'; - $request[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; - $request[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'; - $request[] = 'DNT: 1'; - $request[] = 'Referer: http://portalvt.azurewebsites.net/Login.aspx?ReturnUrl=%2fPages%2fHome.aspx'; - $request[] = 'Accept-Encoding: gzip, deflate'; - $request[] = 'Accept-Language: en-US,en;q=0.8'; - - - $url = 'http://portalvt.azurewebsites.net/Login.aspx'; - $ch = curl_init($url); - - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - - curl_setopt($ch, CURLOPT_POST, false); - curl_setopt($ch, CURLOPT_HTTPHEADER, $request); - curl_setopt($ch, CURLOPT_ENCODING,""); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_TIMEOUT,10); - curl_setopt($ch, CURLOPT_FAILONERROR,true); - curl_setopt($ch, CURLOPT_ENCODING,""); - - curl_setopt($ch, CURLOPT_VERBOSE, true); - curl_setopt($ch, CURLINFO_HEADER_OUT, false); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_COOKIESESSION , true ); - curl_setopt($ch, CURLOPT_COOKIE, $cookie ); - - $data = curl_exec($ch); - $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); - echo substr($data,$skip); //do not transmit header - - -// if (curl_errno($ch)){ -// $data .= 'Retreive Base Page Error: ' . curl_error($ch); -// var_dump($data); -// } -// else { -// $info = rawurldecode(var_export(curl_getinfo($ch), true)); -// -// // Get the cookies: -// -// $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); -// $responseHeader = substr($data, 0, $skip); -// -// echo "$info\n$responseHeader\n$data\n\n"; -// -// $e = 0; -// while (true) { -// $s = strpos($responseHeader, 'Set-Cookie: ', $e); -// if (!$s) { -// break; -// } -// $s += 12; -// $e = strpos($responseHeader, ';', $s); -// $cookie = substr($responseHeader, $s, $e - $s); -// $s = strpos($cookie, '='); -// $key = substr($cookie, 0, $s); -// $value = substr($cookie, $s); -// $cookies[$key] = $value; -// } -// } - - } - -} diff --git a/app/Http/Controllers/invoiceClass.php b/app/Http/Controllers/invoiceClass.php new file mode 100644 index 00000000..e4b57b7e --- /dev/null +++ b/app/Http/Controllers/invoiceClass.php @@ -0,0 +1,33 @@ +company(); + $price = $company->price(); + $order = Order::fetch(); + $items = $order->items(); + + $deliveryAddress = address(); + + $invoice = Invoice::create([ + $order, + $items + ]); + + + $convertToPdf = $invoice->pdf(); + + $email = email()->pdf(); + +solid + + + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/preformaClass.php b/app/Http/Controllers/preformaClass.php new file mode 100644 index 00000000..f0e06346 --- /dev/null +++ b/app/Http/Controllers/preformaClass.php @@ -0,0 +1,29 @@ +company(); + $price = $company->price(); + $order = Order::fetch(); + $items = $order->items(); + + $deliveryAddress = address(); + + $invoice = Performa::create([ + $order, + $items + ]); + + $convertToPdf = $invoice->pdf(); + + $email = email()->pdf(); + + } + +} \ No newline at end of file diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index ba3ef5d0..a569030e 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -3,6 +3,7 @@ namespace App\Http\Resources; use App\Classes\ValueObjects\Constants\AccountStatus; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Models\CompanyConnections; use Illuminate\Http\Resources\Json\JsonResource; @@ -22,9 +23,10 @@ class CompanyResource extends JsonResource 'marking' => CompanyConnections::where('module_one', $this->modules->first()->id)->first()->marking, 'name' => $this->name, 'type' => $this->type, - 'status' => AccountStatus::STATUS[$this->status], + 'status' => $this->status, 'delivery_address' => new AddressResource($this->deliveryAddress), - 'contact' => new ContactResource($this->contacts->first()) + 'contact' => new ContactResource($this->contacts->first()), + 'total_orders' => count($this->orders) ]; } } diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php new file mode 100644 index 00000000..51aef2e7 --- /dev/null +++ b/app/Http/Resources/DocumentResource.php @@ -0,0 +1,26 @@ + $this->id, + 'document_type' => $this->document_type, + 'reference' => $this->reference, + 'status' => (int) $this->status, + 'approved_by' => (int) $this->approved_by, + 'files' => $this->files()->get() + ]; + } +} diff --git a/app/Models/Address.php b/app/Models/Address.php index 2873ae8f..61e1309d 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; @@ -29,12 +30,12 @@ class Address extends AbstractModel protected $dates = ['deleted_at']; - /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function company(): HasOne + /** + * @return BelongsTo + */ + public function company(): BelongsTo { - return $this->hasOne(Company::class, 'company_id', 'id'); + return $this->BelongsTo(Company::class, 'company_id', 'id'); } } diff --git a/app/Models/Company.php b/app/Models/Company.php index a0237d3d..59cf34a2 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -2,10 +2,11 @@ namespace App\Models; -use App\Models\AbstractModel as Model; +use App\Classes\General\Interfaces\Documentable; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -17,7 +18,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string name * @property integer type */ -class Company extends AbstractModel +class Company extends AbstractModel implements Documentable { use SoftDeletes; @@ -74,6 +75,22 @@ class Company extends AbstractModel return $this->hasManyThrough(Company::class, CompanyConnections::class); } + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + + /** + * @return HasMany + */ + public function orders(): hasMany + { + return $this->hasMany(Order::class); + } + } diff --git a/app/Models/Document.php b/app/Models/Document.php new file mode 100644 index 00000000..2b649776 --- /dev/null +++ b/app/Models/Document.php @@ -0,0 +1,50 @@ +morphTo(); + } + + /** + * @return hasMany + */ + public function files(): hasMany + { + return $this->hasMany(File::class, 'document_id'); + } + +} diff --git a/app/Models/File.php b/app/Models/File.php new file mode 100644 index 00000000..6707fd9f --- /dev/null +++ b/app/Models/File.php @@ -0,0 +1,31 @@ +hasMany(Order::class, 'user_id', 'id'); } + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + } diff --git a/composer.json b/composer.json index 2ed5dcaf..b413bc57 100644 --- a/composer.json +++ b/composer.json @@ -9,15 +9,17 @@ "license": "MIT", "require": { "php": "^7.2.5", + "ext-curl": "*", + "ext-fileinfo": "*", "ext-json": "^1.6", + "barryvdh/laravel-dompdf": "^0.9.0", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", "laravel/framework": "^7.0", "laravel/tinker": "^2.0", "spatie/laravel-activitylog": "^3.14", - "tymon/jwt-auth": "^1.0", - "ext-curl": "*" + "tymon/jwt-auth": "^1.0" }, "require-dev": { "facade/ignition": "^2.0", diff --git a/database/migrations/2020_08_04_042142_create_companies_table.php b/database/migrations/2020_08_04_042142_create_companies_table.php index b9c29ad0..6e6bd793 100644 --- a/database/migrations/2020_08_04_042142_create_companies_table.php +++ b/database/migrations/2020_08_04_042142_create_companies_table.php @@ -1,6 +1,7 @@ bigInteger('reference_no')->unique(); $table->string('name'); $table->integer('type')->comment('business type eg. personal, company'); - $table->integer('status')->default(AccountStatus::PENDING_VERIFICATION); + $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2020_11_03_122319_create_documents_table.php b/database/migrations/2020_11_03_122319_create_documents_table.php new file mode 100644 index 00000000..9b593054 --- /dev/null +++ b/database/migrations/2020_11_03_122319_create_documents_table.php @@ -0,0 +1,43 @@ +id(); + $table->morphs('owner'); + $table->string('document_type'); + $table->string('reference')->nullable(); + $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); + $table->bigInteger('approved_by')->unsigned()->nullable(); + $table->timestamp('issued_date')->nullable(); + $table->timestamp('expired_date')->nullable(); + $table->timestamp('approved_date')->nullable(); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('approved_by')->references('id')->on('users')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('documents'); + } +} diff --git a/database/migrations/2020_11_03_122358_create_files_table.php b/database/migrations/2020_11_03_122358_create_files_table.php new file mode 100644 index 00000000..b1cbf331 --- /dev/null +++ b/database/migrations/2020_11_03_122358_create_files_table.php @@ -0,0 +1,37 @@ +id(); + $table->bigInteger('document_id')->unsigned(); + $table->text('file'); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('document_id')->references('id')->on('documents')->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('files'); + } +} diff --git a/load_font.php b/load_font.php new file mode 100644 index 00000000..066abfe7 --- /dev/null +++ b/load_font.php @@ -0,0 +1,202 @@ +getOptions()->set('fontDir', $fontDir); +} + +/** + * Installs a new font family + * This function maps a font-family name to a font. It tries to locate the + * bold, italic, and bold italic versions of the font as well. Once the + * files are located, ttf versions of the font are copied to the fonts + * directory. Changes to the font lookup table are saved to the cache. + * + * @param Dompdf $dompdf dompdf main object + * @param string $fontname the font-family name + * @param string $normal the filename of the normal face font subtype + * @param string $bold the filename of the bold face font subtype + * @param string $italic the filename of the italic face font subtype + * @param string $bold_italic the filename of the bold italic face font subtype + * + * @throws Exception + */ +function install_font_family($dompdf, $fontname, $normal, $bold = null, $italic = null, $bold_italic = null) { + $fontMetrics = $dompdf->getFontMetrics(); + + // Check if the base filename is readable + if ( !is_readable($normal) ) + throw new Exception("Unable to read '$normal'."); + + $dir = dirname($normal); + $basename = basename($normal); + $last_dot = strrpos($basename, '.'); + if ($last_dot !== false) { + $file = substr($basename, 0, $last_dot); + $ext = strtolower(substr($basename, $last_dot)); + } else { + $file = $basename; + $ext = ''; + } + + if ( !in_array($ext, array(".ttf", ".otf")) ) { + throw new Exception("Unable to process fonts of type '$ext'."); + } + + // Try $file_Bold.$ext etc. + $path = "$dir/$file"; + + $patterns = array( + "bold" => array("_Bold", "b", "B", "bd", "BD"), + "italic" => array("_Italic", "i", "I"), + "bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"), + ); + + foreach ($patterns as $type => $_patterns) { + if ( !isset($$type) || !is_readable($$type) ) { + foreach($_patterns as $_pattern) { + if ( is_readable("$path$_pattern$ext") ) { + $$type = "$path$_pattern$ext"; + break; + } + } + + if ( is_null($$type) ) + echo ("Unable to find $type face file.\n"); + } + } + + $fonts = compact("normal", "bold", "italic", "bold_italic"); + $entry = array(); + + // Copy the files to the font directory. + foreach ($fonts as $var => $src) { + if ( is_null($src) ) { + $entry[$var] = $dompdf->getOptions()->get('fontDir') . '/' . mb_substr(basename($normal), 0, -4); + continue; + } + + // Verify that the fonts exist and are readable + if ( !is_readable($src) ) + throw new Exception("Requested font '$src' is not readable"); + + $dest = $dompdf->getOptions()->get('fontDir') . '/' . basename($src); + + if ( !is_writeable(dirname($dest)) ) + throw new Exception("Unable to write to destination '$dest'."); + + echo "Copying $src to $dest...\n"; + + if ( !copy($src, $dest) ) + throw new Exception("Unable to copy '$src' to '$dest'"); + + $entry_name = mb_substr($dest, 0, -4); + + echo "Generating Adobe Font Metrics for $entry_name...\n"; + + $font_obj = Font::load($dest); + $font_obj->saveAdobeFontMetrics("$entry_name.ufm"); + $font_obj->close(); + + $entry[$var] = $entry_name; + } + + // Store the fonts in the lookup table + $fontMetrics->setFontFamily($fontname, $entry); + + // Save the changes + $fontMetrics->saveFontFamilies(); +} + +// If installing system fonts (may take a long time) +if ( $_SERVER["argv"][1] === "system_fonts" ) { + $fontMetrics = $dompdf->getFontMetrics(); + $files = glob("/usr/share/fonts/truetype/*.ttf") + + glob("/usr/share/fonts/truetype/*/*.ttf") + + glob("/usr/share/fonts/truetype/*/*/*.ttf") + + glob("C:\\Windows\\fonts\\*.ttf") + + glob("C:\\WinNT\\fonts\\*.ttf") + + glob("/mnt/c_drive/WINDOWS/Fonts/"); + $fonts = array(); + foreach ($files as $file) { + $font = Font::load($file); + $records = $font->getData("name", "records"); + $type = $fontMetrics->getType($records[2]); + $fonts[mb_strtolower($records[1])][$type] = $file; + $font->close(); + } + + foreach ( $fonts as $family => $files ) { + echo " >> Installing '$family'... \n"; + + if ( !isset($files["normal"]) ) { + echo "No 'normal' style font file\n"; + } + else { + install_font_family($dompdf, $family, @$files["normal"], @$files["bold"], @$files["italic"], @$files["bold_italic"]); + echo "Done !\n"; + } + + echo "\n"; + } +} +else { + call_user_func_array("install_font_family", array_merge( array($dompdf), array_slice($_SERVER["argv"], 1) )); +} diff --git a/resources/assets/fonts/wts11.ttf b/resources/assets/fonts/wts11.ttf new file mode 100644 index 00000000..cd32345c Binary files /dev/null and b/resources/assets/fonts/wts11.ttf differ diff --git a/resources/assets/images/step_01.png b/resources/assets/images/step_01.png new file mode 100644 index 00000000..896aed0b Binary files /dev/null and b/resources/assets/images/step_01.png differ diff --git a/resources/assets/images/step_02.png b/resources/assets/images/step_02.png new file mode 100644 index 00000000..a7dc3737 Binary files /dev/null and b/resources/assets/images/step_02.png differ diff --git a/resources/assets/images/step_03.png b/resources/assets/images/step_03.png new file mode 100644 index 00000000..063f2c74 Binary files /dev/null and b/resources/assets/images/step_03.png differ diff --git a/resources/assets/vue/components/address/elements/AddressComponent.vue b/resources/assets/vue/components/address/elements/AddressComponent.vue index 589213f2..ca671666 100644 --- a/resources/assets/vue/components/address/elements/AddressComponent.vue +++ b/resources/assets/vue/components/address/elements/AddressComponent.vue @@ -7,7 +7,7 @@ -


No Results Found
+Nothing To Show Here