Merge branch 'master' into dillon/44-customer-satisfaction-feedback-project

This commit is contained in:
Dillon
2023-10-15 18:07:26 +08:00
15 changed files with 366 additions and 18 deletions
@@ -0,0 +1,20 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class PaymentMethodNotIn implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->whereNotIn('payment_method', $value);
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\ValueObjects\Constants\TransactionType;
class GenerateCreditNotePdfLogic
{
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/**
* GenerateCreditNotePdfLogic constructor.
* @param FetchesTransaction $fetchesTransaction
* @param FetchesCompany $fetchesCompany
*/
public function __construct(FetchesTransaction $fetchesTransaction, FetchesCompanyModule $fetchesCompanyModule)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->fetchesCompanyModule = $fetchesCompanyModule;
}
/**
* @param Request $request
* @return string|\Symfony\Component\HttpFoundation\Response
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Request $request)
{
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
$supplier = $this->fetchesCompanyModule->execute(['id' => $transaction->receiver]);
$pdf = LaravelMpdf::loadView('pages.pdfs.credit_note', ['transaction' => $transaction, 'supplier' => $supplier]);
return $pdf->stream('CreditNote.pdf');
}
}
@@ -10,6 +10,7 @@ use App\Classes\Modules\Wallets\Services\UpdatesWallet;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
@@ -29,6 +30,9 @@ class CreditWalletLogic extends AbstractControllerLogic
}
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/** @var FetchesCompany */
private $fetchesCompany;
@@ -62,6 +66,7 @@ class CreditWalletLogic extends AbstractControllerLogic
*/
public function __construct(
FetchesCompany $fetchesCompany,
FetchesCompanyModule $fetchesCompanyModule,
GeneratesWalletCode $generatesWalletCode,
CreatesWallet $createsWallet,
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
@@ -71,6 +76,7 @@ class CreditWalletLogic extends AbstractControllerLogic
)
{
$this->fetchesCompany = $fetchesCompany;
$this->fetchesCompanyModule = $fetchesCompanyModule;
$this->generatesWalletCode = $generatesWalletCode;
$this->createsWallet = $createsWallet;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
@@ -88,13 +94,13 @@ class CreditWalletLogic extends AbstractControllerLogic
{
$amount = floatval(str_replace(',', '', $request->input('amount')));
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
$companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
$reference = $request->input('reference');
$type = $request->input('transaction_type');
$wallet = $this->creditWalletProcessor->execute($company, $type, $amount, $reference);
$wallet = $this->creditWalletProcessor->execute($companyModule, $type, $amount, $reference);
return $this->resourceResponse(new WalletResource($wallet));
}
@@ -11,9 +11,11 @@ use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionableTransaction;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Models\CompanyModule;
class CreditWalletProcessor
{
@@ -29,6 +31,9 @@ class CreditWalletProcessor
/** @var CreatesTransaction */
private $createsTransaction;
/** @var CreatesTransactionableTransaction */
private $createsTransactionableTransaction;
/** @var UpdatesWallet */
private $updatesWallet;
@@ -38,6 +43,7 @@ class CreditWalletProcessor
* @param CreatesWallet $createsWallet
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
* @param CreatesTransactionableTransaction $createsTransactionableTransaction
* @param UpdatesWallet $updatesWallet
*/
public function __construct(
@@ -45,6 +51,7 @@ class CreditWalletProcessor
CreatesWallet $createsWallet,
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
CreatesTransaction $createsTransaction,
CreatesTransactionableTransaction $createsTransactionableTransaction,
UpdatesWallet $updatesWallet
)
{
@@ -52,32 +59,33 @@ class CreditWalletProcessor
$this->createsWallet = $createsWallet;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->createsTransactionableTransaction = $createsTransactionableTransaction;
$this->updatesWallet = $updatesWallet;
}
/**
* @param Company $company
* @param CompanyModule $companyModule
* @param int $transactionType
* @param float $amount
* @param string $reference
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Company $company, int $transactionType, float $amount, string $reference)
public function execute(CompanyModule $companyModule, int $transactionType, float $amount, string $reference)
{
if (!$company->wallets()->first()) {
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
$this->createsWallet->execute($object, $company);
if (!$companyModule->wallets()->first()) {
$object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute());
$this->createsWallet->execute($object, $companyModule);
}
/** @var Wallet $wallet */
$wallet = $company->wallets()->first();
$wallet = $companyModule->wallets()->first();
$billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-');
$transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference);
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
$transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object);
$updateWalletAmount = $transactionType === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount);
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Transactions;
use Illuminate\Http\Request;
use App\Classes\Modules\Transactions\ControllersLogic\GenerateCreditNotePdfLogic;
use Illuminate\Http\JsonResponse;
class GenerateCreditNotePdfController
{
public function download(Request $request, GenerateCreditNotePdfLogic $logic) {
return $logic->execute($request);
}
}
@@ -26,7 +26,7 @@ class MappableTransactionResource extends JsonResource
$reference = $this->owner->owner->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
}
if($this->type === TransactionType::PAYMENT && $this->owner !== Wallet::class){
if($this->type === TransactionType::PAYMENT && $this->owner_type !== Wallet::class){
$reference = $this->owner->owner->owner->reference;
}
@@ -34,7 +34,7 @@ class MappableTransactionResource extends JsonResource
'status' => 'success',
'system' => 'SHIPPING_PORTAL',
'type' => $this->type,
'owner_type' => $this->owner_type,
'owner_type' => Transaction::class,
'owner_id'=> $this->id,
'owner_reference'=> $reference,
];
@@ -41,10 +41,14 @@ class WalletTransactionResource extends JsonResource
case 11:
$description = 'Debit Voucher for '.$this->payment_reference;
break;
case 15:
$description = (double) $this->amount.' Credit Top up';
break;
}
return [
'id' => (int) $this->id,
'type' => (int) $this->type,
'marking' => $this->owner->owner->reference,
'bill_no' => $this->bill_no,
@@ -17,7 +17,7 @@
<div class="col">
<div class="row" v-if="section === 'customerPendingPaymentInvoiceComponent'">
<div class="col m-b-15">
<wallet-component :company_module_id="company_module_id" section="billingWalletSection"></wallet-component>
<wallet-component :company_module_id="company_module_id" section="billingWalletSection" :creditable=true></wallet-component>
</div>
</div>
<div class="b-a b-grey rounded padding-25 bg-white">
@@ -69,7 +69,7 @@
this.canSubmitChanges = !this.canSubmitChanges;
this.parameters.transaction_details = this.details;
console.log(this.parameters.transaction_details);
// console.log(this.parameters.transaction_details);
this.submit(this.route('api.transaction.invoice.update', this.data.id), 'put', this.section, true, true);
}
@@ -21,8 +21,8 @@
<div class="row bg-white padding-10 m-b-10 rounded align-items-center" v-for="(item, index) in wallet.transactions" v-bind:key="item.id" :data="item">
<div class="col-3 fs-12">{{item.created_at}}</div>
<div class="col fs-12" v-html="item.description"></div>
<div class="col-2 text-success text-center">{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
<div class="col fs-12"><span v-html="item.description"></span> <a target=”_blank” v-if="[9,11].includes(item.type) " :href="route('transaction.credit_note.download', item.id)"><i class="fa fa-download fs-11 m-l-5 text-secondary hover-primary"></i></a></div>
<div class="col-2 text-success text-center">{{[5, 9, 15].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
<div class="col-2 text-danger text-center">{{[2, 11].includes(parseFloat(item.type)) ? '- ' + (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
<div class="col-2 text-right">{{remainingBalance(index)}}</div>
</div>
@@ -52,7 +52,7 @@
</div>
</div>
<div class="col-4">
<wallet-component :data="wallet" :company_module_id="id" section="CompanyWalletTransactionSection"></wallet-component>
<wallet-component :data="wallet" :company_module_id="id" section="CompanyWalletTransactionSection" :creditable=true></wallet-component>
<div class="row m-t-20">
<div class="col">
<div class="row m-b-10">
@@ -15,9 +15,10 @@
</div>
</div>
<div class="row m-t-10 d-flex align-items-center">
<div class="col-auto">
<div class="col-auto" v-if="$store.getters.isSuperAdmin">
<div class="btn btn-xs p-l-15 p-r-20 b-rad-none font-heading btn-rounded bg-white" @click="reload = true"><i class="fa fa-plus fs-8 m-r-5"></i> Reload</div>
</div>
<div class="col-auto p-l-0" v-else="$store.getters.isSuperAdmin"></div>
<div class="col-auto p-l-0" v-if="!mini && wallet && section!=='CompanyWalletTransactionSection'">
<!-- <a class="text-white fs-10" :href="route('wallet.details', wallet.company_module_marking)" target="_blank">Transaction History<i class="fa fa-angle-right p-l-5"></i></a> -->
<a class="text-white fs-10" :href="route('wallet.details', wallet.company_module_marking)">Transaction History<i class="fa fa-angle-right p-l-5"></i></a>
@@ -0,0 +1,114 @@
@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>
<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-reg">(1134596-M)</span><br>
No. 72-3, Jalan Jalil 1,<br>
The Earth Bukit Jalil,<br>
57000 Kuala Lumpur<br>
Tel: 03-8082 1252
</td>
<td class="header-details">
<div class="title">
<strong>
{{ $transaction->type == 9 ? 'Credit' : 'Debit' }} Note
</strong>
</div>
<div class="date">Date: {{ $transaction->created_at }}</div>
<div>&nbsp;</div>
</div>
</td>
<tr>
<td colspan="3" class="bill-to">
<span class="sub-title">
{{ $transaction->type == 9 ? 'Credit' : 'Debit' }} To
</span>
</td>
</tr>
<tr>
<td colspan="3" class="address">
<div class="label">
{{ $supplier->name }}
</div>
<div class="address">
@php
$addresses = $supplier->addresses()->where('type', 1)->first();
@endphp
@if($addresses)
{{ $addresses->street_one }}
{{ $addresses->street_two }} ,
{{ $addresses->district()->first()->name }},
{{ $addresses->postcode }}
{{ $addresses->state()->first()->name }},
{{ $addresses->country()->first()->name }}
@endif
</div>
<div>
@php
$contact = $supplier->contacts()->first();
@endphp
Phone: {{ $contact ? $contact->phone : '' }}
</div>
</td>
</tr>
</table>
<br>
<br>
<table class="line-table" style="overflow: wrap" autosize="1">
<thead>
<tr>
<th width="5%">No</th>
<th class="description">Description</th>
<th width="10%">Quantity</th>
<th width="15%">Unit Price (RM)</th>
<th width="10%">Total Amount<br>(RM)</th>
</tr>
</thead>
<tbody>
<tr>
<td width="5%" class="center top">1</td>
<td class="description">{{ ucfirst($transaction->payment_reference) }}</td>
<td width="10%" class="center top">1</td>
<td width="15%" class="center top">
{{ number_format($transaction->amount, 2) }}
</td>
<td width="20%" class="right top">
{{ number_format($transaction->amount, 2) }}
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<td class="right middle">Total</td>
<td class="total right middle">
{{ number_format($transaction->amount, 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>
@endsection
@@ -0,0 +1,86 @@
<br>
<table>
<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-reg">(1134596-M)</span><br>
No. 72-3, Jalan Jalil 1,<br>
The Earth Bukit Jalil,<br>
57000 Kuala Lumpur<br>
Tel: 03-8082 1252
</td>
<td class="header-details">
<div class="title" style="font-size: 20px; text-transform: uppercase;">
<strong>
Packing List Measurements
</strong>
</div>
<div class="date">Date: {{ $invoice_transaction->created_at }}</div>
</td>
</tr>
</table>
<br>
<br>
<table class="line-table" style="overflow: wrap" autosize="1">
<thead>
<tr>
<th width="5%">No</th>
<th class="description">Description</th>
<th width="15%">Measurement</th>
<th width="15%">CBM</th>
<th width="10%">Quantity</th>
<th width="15%">Total CBM</th>
</tr>
</thead>
<tbody>
@php
$packages = $invoice_transaction->owner->packages;
$totalCBM = 0;
$totalQty = 0;
@endphp
@foreach ($packages as $key => $package)
@php
$measurement = "{$package->length} (L) <br> {$package->width} (W) <br> {$package->height} (H)";
$itemCBM = ($package->width / 100) * ($package->height / 100) * ($package->length / 100);
$itemTotalCBM = $itemCBM * $package->quantity;
$totalCBM += $itemTotalCBM;
$totalQty += $package->quantity;
@endphp
<tr>
<td width="5%" class="center top">{{ $key + 1 }}</td>
<td class="description">{!! $package->description !!}</td>
<td width="15%" class="center top" style="text-align: center">
{!! $measurement !!}
</td>
<td width="15%" class="center top" style="text-align: center">
{{ round($itemCBM, 5) }}
</td>
<td width="10%" class="center top" style="text-align: center">{{ $package->quantity }}</td>
<td width="15%" class="right top">
{{ round($itemTotalCBM, 5) }}
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<td class="right middle">Total</td>
<td class="total" style="text-align: center">
{{ $totalQty }}
</td>
<td class="total right middle">
{{ round($totalCBM, 5) }}
</td>
</tr>
</tfoot>
</table>
@@ -8,6 +8,9 @@
@include('pages.pdfs.shipping_invoice_inner', ['invoice_transaction' => $invoice_transaction])
<pagebreak />
@include('pages.pdfs.packing_list_measurement', ['invoice_transaction' => $invoice_transaction])
<htmlpagefooter name="page-footer">
<table width="100%">
<tr>
+44 -1
View File
@@ -42,6 +42,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use App\Models\Container;
use App\Models\Transaction;
use App\Models\Wallet;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
@@ -1078,7 +1079,8 @@ Route::get('/wallet/audit', function (Request $request) {
foreach ($wallet->transactions as $transaction){
if(!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue;
if((int) $transaction->type === TransactionType::TOP_UP) {
if((int) $transaction->type === TransactionType::TOP_UP || (int) $transaction->type === TransactionType::GROUP_PAYMENT) {
// if((int) $transaction->type === TransactionType::TOP_UP) {
$topups += (float) $transaction->amount;
}
if((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount;
@@ -1203,3 +1205,44 @@ Route::get('/export/feedback', 'Exports\ExportFeedbackDataController@export')->m
Route::get('/404', function () {
abort(404);
})->name('error.404');
Route::get('transaction/{id}/credit_note/download', 'Transactions\GenerateCreditNotePdfController@download')->name('transaction.credit_note.download');
Route::get('/check-successful-payment-or-topup', function () {
$sum = 0 ;
$transactions = Transaction::whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP, TransactionType::GROUP_PAYMENT])->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
foreach ($transactions as $transaction){
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
if($response->successful()){
$sum += $transaction->amount;
dump($transaction->payment_reference . 'Amount : ' . $transaction->amount);
}else{
dump("billplz error</br>");
}
}
dump("Sum is : " . $sum);
});
Route::get('/wallets/active', function(){
$wallets = Wallet::all();
echo '<table>';
foreach ($wallets as $wallet){
$companyMarking = $wallet->owner->getMarking();
echo '<tr>';
echo '<td><a href="'.route('wallet.details', $companyMarking).'" target="_blank">'.$companyMarking.'</a></td>';
echo '<td>'.$wallet->amount.'</td>';
echo '</tr>';
}
echo '</table>';
});
Route::get('/accident-approve-invoice', function(){
$invoices = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->whereDate('updated_at', '2023-10-12')->get();
foreach ($invoices as $invoice) {
$orderMarking = $invoice->owner->owner->reference;
echo '<a href="'.route('order.v2.show', $orderMarking).'" target="_blank">'.$orderMarking.'</a><br>';
}
});