Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into development

This commit is contained in:
edmondlang
2023-08-11 15:14:15 +08:00
20 changed files with 809 additions and 124 deletions
@@ -0,0 +1,44 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Http\Resources\GeneralTypeResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListBusinessTypesLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved Business Types',
'message' => 'You have successfully retrieved a list of Business Types'
];
}
/**
* @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
{
$businessTypes = [];
foreach(BusinessType::BUSINESS_TYPE_LIST as $key => $val) {
$type = (object)["id" => $key, "type" => $val];
array_push($businessTypes, $type);
}
return $this->collectionResponse(GeneralTypeResource::collection($businessTypes));
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Http\Resources\GeneralTypeResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListCompanyTypesLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved Company Types',
'message' => 'You have successfully retrieved a list of Company Types'
];
}
/**
* @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
{
$businessTypes = [];
foreach(CompanyType::COMPANY_TYPE_LIST as $key => $val) {
$type = (object)["id" => $key, "type" => $val];
array_push($businessTypes, $type);
}
return $this->collectionResponse(GeneralTypeResource::collection($businessTypes));
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Http\Resources\CompanyResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyProfileObject;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyProfile;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyProfileLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Update Company Details',
'message' => 'You have successfully updated the Company Details'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var UpdatesCompanyProfile */
private $updatesCompanyProfile;
/**
* UpdateCompanyProfileLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param UpdatesCompanyProfile $updatesCompanyProfile
*/
public function __construct(
FetchesCompany $fetchesCompany,
UpdatesCompanyProfile $updatesCompanyProfile
)
{
$this->fetchesCompany = $fetchesCompany;
$this->updatesCompanyProfile = $updatesCompanyProfile;
}
/**
* @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
{
$object = new CompanyProfileObject($request->input('email'), $request->input('phone'), $request->input('type'));
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$company_query = $this->updatesCompanyProfile->execute($company, $object);
return $this->resourceResponse(new CompanyResource($company_query));
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Classes\Modules\Companies\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
use App\Classes\ValueObjects\Constants\BusinessType;
class CompanyProfileObject implements DataTransferObject
{
/** @var string|null */
private $email;
/** @var string */
private $phone;
/** @var int|null */
private $companyType;
/**
* CompanyObject constructor.
* @param string|null $email
* @param string $phone
* @param int|null $businessType
*/
public function __construct(?string $email, string $phone, int $companyType)
{
$this->email = $email;
$this->phone = $phone;
$this->companyType = $companyType;
}
/**
* @return null|string
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @return string
*/
public function getPhone(): string
{
return $this->phone;
}
/**
* @return int
*/
public function getCompanyType(): int
{
return $this->companyType;
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Classes\Modules\Companies\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyProfileObject;
use App\Models\Company;
class UpdatesCompanyProfile extends AbstractUpdateRecord
{
/**
* @param Company $model
* @param CompanyProfileObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Company $model, CompanyProfileObject $object)
{
$model->type = $object->getCompanyType();
$contact = $model->contacts()->first();
if ($contact) {
$contact->email = $object->getEmail();
$contact->phone = $object->getPhone();
$contact->save();
}
return $this->handler($model);
}
}
@@ -12,4 +12,11 @@ final class BusinessType {
public const TRANSFER_AGENT = 4;
public const BUSINESS_TYPE_LIST = [
self::FREIGHT_FORWARDER => 'Freight Forwarder',
self::IMPORTER => 'Importer',
self::CURRENCY_VENDOR => 'Currency Vendor',
self::TRANSFER_AGENT => 'Transfer Agent',
];
}
@@ -13,4 +13,9 @@ final class CompanyType {
self::COMPANY_BUSINESS => 'COMPANY_BUSINESS',
];
public const COMPANY_TYPE_LIST = [
self::PERSONAL_BUSINESS => 'Personal Business',
self::COMPANY_BUSINESS => 'Company Business',
];
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\ListBusinessTypesLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListBusinessTypesController
{
/**
* @param Request $request
* @param ListBusinessTypesLogic $logic
* @return JsonResponse
*/
public function list(Request $request, ListBusinessTypesLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\ListCompanyTypesLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListCompanyTypesController
{
/**
* @param Request $request
* @param ListBusinessTypesLogic $logic
* @return JsonResponse
*/
public function list(Request $request, ListCompanyTypesLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyProfileLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyProfileController
{
/**
* @param Request $request
* @param UpdateCompanyProfileLogic $logic
* @return JsonResponse
*/
public function update(Request $request, UpdateCompanyProfileLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class GeneralTypeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'type' => $this->type,
];
}
}
@@ -9,6 +9,15 @@
<label :style="minWidth">Business Type</label>
<label>{{this.company_details.business_type ? getBusinessTypeDesc(this.company_details.business_type) : ""}}</label>
</div>
<div class="col-12 p-0">
<label :style="minWidth">Company Type</label>
<label>
{{getCompanyTypeDesc(this.company_details.type)}}
<div class="btn btn-xs b-rad-none pointer requestModal d-inline rounded no-border hover-primary" data-type="changeCompanyType" >
<i class="fa fa-edit pointer fa-fw fs-15 m-l-5"></i>
</div>
</label>
</div>
<div class="col-12 p-0">
<label :style="minWidth">Email</label>
<label><i class="fa fa-envelope text-primary fs-10"></i>&nbsp;{{this.company_details.employee ? this.company_details.employee.email : ""}}</label>
@@ -19,7 +28,12 @@
</div>
<div class="col-12 p-0">
<label :style="minWidth">&nbsp;</label>
<label><i class="fa fa-phone text-primary fs-10"></i>&nbsp;{{this.company_details.contact ? this.company_details.contact.phone : ""}}</label>
<label>
<i class="fa fa-phone text-primary fs-10"></i>&nbsp;{{this.company_details.contact ? this.company_details.contact.phone : ""}}
<div class="btn btn-xs b-rad-none pointer requestModal d-inline rounded no-border hover-primary" data-type="changeCustomerContactNumber" >
<i class="fa fa-edit pointer fa-fw fs-15 m-l-5"></i>
</div>
</label>
</div>
<div class="col-12 p-0" v-if="this.company_details.identification && this.company_details.identification.document_type">
<label class="muted pull-left" :style="minWidth">Identification</label>
@@ -38,6 +52,11 @@
</div>
</div>
</div>
<div class="col-12 p-0 p-b-5 d-none">
<div class="btn btn-xs btn-default bg-master-lighter btn-rounded p-r-20 p-l-15 requestModal" data-type="editProfileInfo">
<i class="fa fa-pencil m-r-10"></i>Edit Profile Info
</div>
</div>
<div class="col-12 p-0">
<label class="muted m-b-0" :style="minWidth">Address&nbsp;</label>
</div>
@@ -61,7 +80,15 @@
<modal-component id="deleteAddressModal">
<address-modal-component section="deleteAddressModal" :address_id="this.address_id"></address-modal-component>
</modal-component>
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="editProfileInfo">
<edit-customer-profile-info-form-component :data="this.company_details" :section="section" v-if="this.company_details.id"></edit-customer-profile-info-form-component>
</modal-component>
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="changeCustomerContactNumber">
<edit-customer-contact-number-form-component :data="this.company_details" :section="section"></edit-customer-contact-number-form-component>
</modal-component>
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="changeCompanyType">
<edit-customer-company-type-form-component :data="this.company_details" :section="section"></edit-customer-company-type-form-component>
</modal-component>
</div>
</template>
@@ -75,6 +102,10 @@
type:Object,
required:true
},
section: {
type: String,
required: true
},
},
mounted(){
this.$root.$on('deleteAddressConfirm', (id) => {
@@ -93,7 +124,7 @@
data(){
return {
minWidth:{
minWidth:'100px',
minWidth:'120px',
},
minWidth150:{
minWidth:'150px',
@@ -173,8 +204,22 @@
backToCompanyList() {
this.$root.$emit('backToCompanyList');
},
getBusinessTypeDesc(type){
return (type==1) ? 'Company Account':'Personal Account';
getBusinessTypeDesc(business_type_id) {
switch (business_type_id) {
case 1:
return 'Freight Forwarder';
case 2:
return 'Importer';
case 3:
return 'Currency Vendor';
case 4:
return 'Transfer Agent';
default:
return null;
}
},
getCompanyTypeDesc(company_type_id) {
return (company_type_id == 1) ? 'Company Business' : 'Personal Business';
},
},
mixins: [componentHandler]
@@ -0,0 +1,71 @@
<template>
<div class="row" @keyup.enter="submitForm">
<div class="col">
<div class="row">
<div class="col">
<div class="row m-b-10">
<div class="col">
<h3 class="all-caps m-b-5 no-margin text-center">Edit Company Type</h3>
<div class="fs-11 text-center">Please double confirm before ediiting the Company Type</div>
</div>
</div>
<div class="row m-b-10">
<div class="col">
<validation-wrapper-component selectable :validator="$v.parameters.type">
<label>Company Type</label>
<selectable-component :endpoint="route('api.company.company_type.list')" section="listCompanyTypeSection" valueColumn="id" :labelColumn="['type']" v-model="parameters.type"></selectable-component>
</validation-wrapper-component>
</div>
</div>
<div class="row">
<div class="col p-r-5">
<div class="btn btn-sm btn-default bg-master-lightest btn-block b-rad-none" data-dismiss="modal">Cancel</div>
</div>
<div class="col p-l-5">
<div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm()">Update</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import modalFormHandler from "../../../general/mixins/modalFormHandler";
import { required, email } from "vuelidate/lib/validators";
export default {
props: {
data: {
type: Object,
default: null
},
},
created() {
this.parameters = {};
this.parameters.type = [0,1].includes(this.data.type) ? this.data.type: 0;
this.parameters.email = this.data.contact ? this.data.contact.email : "";
this.parameters.phone = this.data.contact ? this.data.contact.phone : "";
},
data(){
return {
parameters: {},
}
},
validations: {
parameters: {
type: {
required,
},
}
},
methods: {
submitForm(){
this.submit(route('api.company.profile.update', this.data.id), 'put', this.section, true, true);
},
successHandler(){
window.location.reload();
},
},
mixins: [modalFormHandler]
}
</script>
@@ -0,0 +1,70 @@
<template>
<div class="row" @keyup.enter="submitForm">
<div class="col">
<div class="row">
<div class="col">
<div class="row m-b-10">
<div class="col">
<h3 class="all-caps m-b-5 no-margin text-center">Edit Contact Number</h3>
</div>
</div>
<div class="row m-b-10">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.phone">
<label>Phone</label>
<input type="text" class="form-control" v-model="parameters.phone">
</validation-wrapper-component>
</div>
</div>
<div class="row">
<div class="col p-r-5">
<div class="btn btn-sm btn-default bg-master-lightest btn-block b-rad-none" data-dismiss="modal">Cancel</div>
</div>
<div class="col p-l-5">
<div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm()">Update</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import modalFormHandler from "../../../general/mixins/modalFormHandler";
import { required, email } from "vuelidate/lib/validators";
export default {
props: {
data: {
type: Object,
default: null
},
},
created() {
this.parameters = {};
this.parameters.type = [0,1].includes(this.data.type) ? this.data.type: 0;
this.parameters.email = this.data.contact ? this.data.contact.email : "";
this.parameters.phone = this.data.contact ? this.data.contact.phone : "";
},
data(){
return {
parameters: {},
}
},
validations: {
parameters: {
phone: {
required,
},
}
},
methods: {
submitForm(){
this.submit(route('api.company.profile.update', this.data.id), 'put', this.section, true, true);
},
successHandler(){
window.location.reload();
},
},
mixins: [modalFormHandler]
}
</script>
@@ -0,0 +1,89 @@
<template>
<div class="row" @keyup.enter="submitForm">
<div class="col">
<div class="row">
<div class="col">
<div class="row m-b-10">
<div class="col">
<h3 class="all-caps m-b-5 bold no-margin">Edit Customer Profile</h3>
</div>
</div>
<div class="row m-b-10">
<div class="col">
<validation-wrapper-component selectable :validator="$v.parameters.type">
<label>Company Type</label>
<selectable-component :endpoint="route('api.company.company_type.list')" section="listCompanyTypeSection" valueColumn="id" :labelColumn="['type']" v-model="parameters.type"></selectable-component>
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-10">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.email">
<label>Email</label>
<input type="text" class="form-control" v-model="parameters.email">
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-10">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.phone">
<label>Phone</label>
<input type="text" class="form-control" v-model="parameters.phone">
</validation-wrapper-component>
</div>
</div>
<div class="row">
<div class="col p-r-5">
<div class="btn btn-sm btn-default bg-master-lightest btn-block b-rad-none" data-dismiss="modal">Cancel</div>
</div>
<div class="col p-l-5">
<div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm()">Update</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import modalFormHandler from "../../../general/mixins/modalFormHandler";
import { required, email } from "vuelidate/lib/validators";
export default {
props: {
data: {
type: Object,
default: null
},
},
created() {
this.parameters = {};
this.parameters.type = [0,1].includes(this.data.type) ? this.data.type: 0;
this.parameters.email = this.data.contact ? this.data.contact.email : "";
this.parameters.phone = this.data.contact ? this.data.contact.phone : "";
},
data(){
return {
parameters: {},
}
},
validations: {
parameters: {
type: {
required,
},
email: {
email,
},
phone: {
required,
},
}
},
methods: {
submitForm(){
this.submit(route('api.company.profile.update', this.data.id), 'put', this.section, true, true);
},
},
mixins: [modalFormHandler]
}
</script>
@@ -122,7 +122,7 @@
<div class="col">
<div class="row">
<div class="col">
<company-details-component :company_details="company_details" section="customerProfileSection"></company-details-component>
<company-details-component :company_details="company" section="customerProfileSection"></company-details-component>
</div>
</div>
</div>
@@ -69,6 +69,7 @@
<br>
<br>
<table class="line-table" style="overflow: wrap" autosize="1">
<!-- Table Header -->
<thead>
<tr>
<th width="5%">No</th>
@@ -81,34 +82,37 @@
</thead>
<tbody>
@php
$subtotal = 0;
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
$currencyRate = $transaction->currency_rate;
$subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
$displayedSubtotal = 0;
@endphp
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
@php
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
@endphp
<tr>
<td width="5%" class="center top">{{ $key + 1 }}</td>
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
<td class="description">{{ $transaction_detail->product_name }}</td>
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
<td width="15%" class="center top">
@php
$unitPrice = $transaction_detail->price / $currencyRate;
@endphp
{{ number_format($unitPrice, 2) }}
{{ number_format($exactUnitPrice, 2) }}
</td>
<td width="20%" class="right top">
@php
$itemTotal = $unitPrice * $transaction_detail->quantity;
$subtotal += $itemTotal;
@endphp
{{ number_format($itemTotal, 2) }}
</td>
</tr>
@endforeach
</tbody>
<tfoot>
@php
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
@endphp
<tr class="subtotal">
<td colspan="4"></td>
<td class="right middle">Subtotal</td>
@@ -117,27 +121,17 @@
<tr class="billingcharges">
<td colspan="4"></td>
<td class="right">Service Charges</td>
<td class="right">
{{ number_format($transaction->service_charge, 2) }}
</td>
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
</tr>
@if($voucher_redemption)
<tr class="voucher">
<td colspan="4"></td>
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
<td class="right middle">-{{ $voucherDiscount }}</td>
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
</tr>
@endif
<tr class="billingcharges">
<td colspan="4"></td>
<td class="right">Adjustment</td>
<td class="right">
@php
$adjustment = $transaction->amount - $subtotal;
@endphp
{{ number_format($adjustment, 2) }}
</td>
</tr>
@if($transaction->tax > 0)
<tr class="billingcharges">
<td colspan="4"></td>
@@ -145,13 +139,21 @@
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
</tr>
@endif
@php
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
@endphp
<tr>
<td colspan="4"></td>
<td class="right middle">Adjustment</td>
<td class="right middle">{{ roundUpDo($discrepancy,2) }}</td>
</tr>
<tr>
<td colspan="4"></td>
<td class="right middle">Total</td>
<td class="total right middle">
@php
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
@endphp
{{ number_format($total, 2) }}
</td>
</tr>
@@ -165,4 +167,28 @@
</tr>
</table>
</htmlpagefooter>
@php
function calculateDoSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getDoVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUpDo($number, $decimals) {
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@endphp
@endsection
+80 -60
View File
@@ -1,21 +1,21 @@
@extends('layouts.base_pdf')
@section('inner_content')
<br>
<htmlpageheader name="page-header">
<br><br>
<div class="separator"><strong><i>{{ $transaction->bill_no }}</i></strong></div>
</htmlpageheader>
<table>
<!-- Header Section -->
<tr>
<td class="header-logo">
<img src="{{ asset('images/ri_1.png') }}" alt="logo" id="logo" class="logo">
</td>
<td class="header-cief-address">
<span class="company-name">
<strong>
CIEF WORLDWIDE SDN BHD
</strong>
</span>
<span class="company-name"><strong>CIEF WORLDWIDE SDN BHD</strong></span>
<span class="company-reg">(1134596-M)</span><br>
No. 72-3, Jalan Jalil 1,<br>
The Earth Bukit Jalil,<br>
@@ -23,14 +23,8 @@
Tel: 03-8082 1252
</td>
<td class="header-details">
<div class="title">
<strong>
Invoice
</strong>
</div>
<div class="title"><strong>Invoice</strong></div>
<div class="number">EI#: {{ $transaction->bill_no }}</div>
<div class="ref">Ref# {{ $po_order_transaction->booking->marking }}</div>
<div class="date">Date: {{ $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->booking->created_at }}</div>
<div>&nbsp;</div>
@@ -38,37 +32,34 @@
</tr>
<tr>
<td colspan="3" class="bill-to">
<span class="sub-title">
Bill To
</span>
<span class="sub-title">Bill To</span>
</td>
</tr>
<tr>
<td colspan="3" class="address">
<div class="label">
{{ $supplier->name }}
</div>
<div class="label">{{ $supplier->name }}</div>
@php
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
@endphp
<div class="address">
@php
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
@endphp
{{ $billingAddress->street_one }}
{{ $billingAddress->street_two }} ,
{{ $billingAddress->street_two }},
{{ $billingAddress->district()->first()->name }},
{{ $billingAddress->postcode }}
{{ $billingAddress->state()->first()->name }},
{{ $billingAddress->country()->first()->name }}
</div>
<div>
Phone: {{ $supplier->contacts()->first()->phone }}
</div>
<div>Phone: {{ $supplier->contacts()->first()->phone }}</div>
</td>
</tr>
</table>
<br>
<br>
<!-- Invoice Table -->
<table class="line-table" style="overflow: wrap" autosize="1">
<!-- Table Header -->
<thead>
<tr>
<th width="5%">No</th>
@@ -81,35 +72,37 @@
</thead>
<tbody>
@php
$subtotal = 0;
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
$currencyRate = $transaction->currency_rate;
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$displayedSubtotal = 0;
@endphp
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
@php
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
@endphp
<tr>
<td width="5%" class="center top">{{ $key + 1 }}</td>
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
<td class="description">{{ $transaction_detail->product_name }}</td>
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
<td width="15%" class="center top">
@php
$unitPrice = $transaction_detail->price / $currencyRate;
@endphp
{{ number_format($unitPrice, 2) }}
{{ number_format($exactUnitPrice, 2) }}
</td>
<td width="20%" class="right top">
@php
$itemTotal = $unitPrice * $transaction_detail->quantity;
$subtotal += $itemTotal;
@endphp
{{ number_format($itemTotal, 2) }}
</td>
</tr>
@endforeach
</tbody>
<tfoot>
@php
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
@endphp
<tr class="subtotal">
<td colspan="4"></td>
<td class="right middle">Subtotal</td>
@@ -120,23 +113,15 @@
<td class="right">Service Charges</td>
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
</tr>
@if($voucher_redemption)
<tr class="voucher">
<td colspan="4"></td>
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
<td class="right middle">-{{ $voucherDiscount }}</td>
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
</tr>
@endif
<tr class="billingcharges">
<td colspan="4"></td>
<td class="right">Adjustment</td>
<td class="right">
@php
$adjustment = $transaction->amount - $subtotal;
@endphp
{{ number_format($adjustment, 2) }}
</td>
</tr>
@if($transaction->tax > 0)
<tr class="billingcharges">
<td colspan="4"></td>
@@ -144,24 +129,59 @@
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
</tr>
@endif
@php
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
@endphp
<tr>
<td colspan="4"></td>
<td class="right middle">Adjustment</td>
<td class="right middle">{{ roundUp($discrepancy,2) }}</td>
</tr>
<tr>
<td colspan="4"></td>
<td class="right middle">Total</td>
<td class="total right middle">
@php
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
@endphp
{{ number_format($total, 2) }}
</td>
</tr>
</tfoot>
</table>
<htmlpagefooter name="page-footer">
<table width="100%">
<tr>
<td style="text-align: right; ">This is generated by computer. No signature required.</td>
<td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
</tr>
</table>
</htmlpagefooter>
<br>
<div class="note">
<strong>Note:</strong> All items purchased are subject to our Terms & Conditions. Please refer to our official website for more information.
</div>
<br><br>
<div class="bank-info">
Please transfer the payment to:<br>
Bank: Maybank Berhad<br>
Account Name: CIEF Worldwide Sdn Bhd<br>
Account No: 564892103405<br>
</div>
@php
function calculateSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUp($number, $decimals) {
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@endphp
@endsection
@@ -77,6 +77,7 @@
<br>
<table class="line-table" style="overflow: wrap" autosize="1">
<!-- Table Header -->
<thead>
<tr>
<th width="5%">No</th>
@@ -89,34 +90,37 @@
</thead>
<tbody>
@php
$subtotal = 0;
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
$currencyRate = $transaction->currency_rate;
$subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
$displayedSubtotal = 0;
@endphp
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
@php
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
@endphp
<tr>
<td width="5%" class="center top">{{ $key + 1 }}</td>
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
<td class="description">{{ $transaction_detail->product_name }}</td>
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
<td width="15%" class="center top">
@php
$unitPrice = $transaction_detail->price / $currencyRate;
@endphp
{{ number_format($unitPrice, 2) }}
{{ number_format($exactUnitPrice, 2) }}
</td>
<td width="20%" class="right top">
@php
$itemTotal = $unitPrice * $transaction_detail->quantity;
$subtotal += $itemTotal;
@endphp
{{ number_format($itemTotal, 2) }}
</td>
</tr>
@endforeach
</tbody>
<tfoot>
@php
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
@endphp
<tr class="subtotal">
<td colspan="4"></td>
<td class="right middle">Subtotal</td>
@@ -125,27 +129,17 @@
<tr class="billingcharges">
<td colspan="4"></td>
<td class="right">Service Charges</td>
<td class="right">
{{ number_format($transaction->service_charge, 2) }}
</td>
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
</tr>
@if($voucher_redemption)
<tr class="voucher">
<td colspan="4"></td>
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
<td class="right middle">-{{ $voucherDiscount }}</td>
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
</tr>
@endif
<tr class="billingcharges">
<td colspan="4"></td>
<td class="right">Adjustment</td>
<td class="right">
@php
$adjustment = $transaction->amount - $subtotal;
@endphp
{{ number_format($adjustment, 2) }}
</td>
</tr>
@if($transaction->tax > 0)
<tr class="billingcharges">
<td colspan="4"></td>
@@ -153,13 +147,21 @@
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
</tr>
@endif
@php
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
@endphp
<tr>
<td colspan="4"></td>
<td class="right middle">Adjustment</td>
<td class="right middle">{{ roundUpPo($discrepancy,2) }}</td>
</tr>
<tr>
<td colspan="4"></td>
<td class="right middle">Total</td>
<td class="total right middle">
@php
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
@endphp
{{ number_format($total, 2) }}
</td>
</tr>
@@ -173,4 +175,28 @@
</tr>
</table>
</htmlpagefooter>
@php
function calculatePoSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getPoVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUpPo($number, $decimals) {
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@endphp
@endsection
+4
View File
@@ -7,10 +7,14 @@ Route::group(['prefix' => 'company', 'as' => 'company.', 'namespace' => 'Compani
Route::get('/list', 'ListCompaniesController@list')->name('list');
Route::post('/create', 'CreateCompanyController@create')->name('create');
Route::put('/update/{id}', 'UpdateCompanyController@update')->name('update');
Route::put('/update/{id}/profile', 'UpdateCompanyProfileController@update')->name('profile.update');
Route::put('update/{id}/status', 'UpdateCompanyStatusController@update')->name('status.update');
Route::delete('/delete/{id}', 'DeleteCompanyController@destroy')->name('delete');
Route::put('/name-and-debtor/update/{id}', 'UpdateCompanyNameAndDebtorController@update')->name('update.nameAndDebtor');
Route::get('/business-type/list', 'ListBusinessTypesController@list')->name('business_type.list');
Route::get('/company-type/list', 'ListCompanyTypesController@list')->name('company_type.list');
Route::put('/update/debtor/{id}', 'UpdateCompanyDebtorController@update')->name('delete');
Route::post('/team/create', 'AddNewMemberController@create')->name('team.create');