mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 14:04:01 +00:00
Merge branch 'rate-history-refactored' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into development
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
</div>
|
||||
<loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
|
||||
<div class="row" v-if="!isLoading && !hasError">
|
||||
<div class="col-12 mx-auto p-0 " style="width: 800px; height:350px">
|
||||
<canvas id="currency-history-chart"></canvas>
|
||||
<div class="col-12 mx-auto p-0 ">
|
||||
<canvas style="width: 800px; height:350px" id="currency-history-chart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" v-if="hasError">
|
||||
@@ -81,19 +81,125 @@ export default {
|
||||
date_from: null,
|
||||
},
|
||||
chartLebels:[],
|
||||
chartData: []
|
||||
chartData: [],
|
||||
paymentMethodsConst: [],
|
||||
colors: [
|
||||
'red',
|
||||
'pink',
|
||||
'blue',
|
||||
'purple',
|
||||
'black',
|
||||
'yellow'
|
||||
]
|
||||
};
|
||||
},
|
||||
props:{
|
||||
paymentMethods: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
pendingQueue() {
|
||||
return this.$store.getters.isInCompleteQueue(this.section);
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
this.paymentMethodsConst = Object.entries(this.paymentMethods).reduce((acc, [key, value]) => {
|
||||
acc[value] = key;
|
||||
return acc;
|
||||
}, {});
|
||||
},
|
||||
watch: {
|
||||
pendingQueue(inComplete) {
|
||||
if (inComplete) {
|
||||
this.resetSarch();
|
||||
}
|
||||
},
|
||||
rateHistory: function(newVal) {
|
||||
|
||||
const date_from_parts = this.filters.date_from.split("-");
|
||||
const date_from_year = date_from_parts[2];
|
||||
const date_from_month = date_from_parts[1] - 1; // Subtract 1 from month, since it's zero-based in Date objects
|
||||
const date_from_day = date_from_parts[0];
|
||||
const start = new Date(date_from_year, date_from_month, date_from_day);
|
||||
|
||||
const date_to_parts = this.filters.date_to.split("-");
|
||||
const date_to_year = date_to_parts[2];
|
||||
const date_to_month = date_to_parts[1] - 1; // Subtract 1 from month, since it's zero-based in Date objects
|
||||
const date_to_day = date_to_parts[0];
|
||||
const end = new Date(date_to_year, date_to_month, date_to_day);
|
||||
|
||||
// Group rates by payment method type
|
||||
const ratesByType = {};
|
||||
newVal.forEach(rate => {
|
||||
if (!ratesByType[rate.payment_method_type]) {
|
||||
ratesByType[rate.payment_method_type] = [];
|
||||
}
|
||||
ratesByType[rate.payment_method_type].push(rate);
|
||||
});
|
||||
|
||||
const startYear = start.getFullYear();
|
||||
const startMonth = start.getMonth() + 1;
|
||||
const endYear = end.getFullYear();
|
||||
const endMonth = end.getMonth() + 1;
|
||||
|
||||
// Get rates for date range
|
||||
const ratesForRange = {};
|
||||
Object.keys(ratesByType).forEach(type => {
|
||||
ratesForRange[type] = [];
|
||||
for (let i = start.getDate(); i <= end.getDate(); i++) {
|
||||
const dateStr = `${i.toString().padStart(2, '0')}-${startMonth.toString().padStart(2, '0')}-${startYear}`;
|
||||
if (i === end.getDate() && startMonth !== endMonth) {
|
||||
// Handle end month
|
||||
const endMonthDays = new Date(endYear, endMonth, 0).getDate();
|
||||
for (let j = 1; j <= end.getDate(); j++) {
|
||||
const dateStr = `${j.toString().padStart(2, '0')}-${endMonth.toString().padStart(2, '0')}-${endYear}`;
|
||||
const rate = ratesByType[type].find(r => r.created_at === dateStr);
|
||||
ratesForRange[type].push(rate ? rate.rate : '');
|
||||
}
|
||||
} else {
|
||||
// Handle start month and other months in range
|
||||
const rate = ratesByType[type].find(r => r.created_at === dateStr);
|
||||
ratesForRange[type].push(rate ? rate.rate : '');
|
||||
}
|
||||
}
|
||||
});
|
||||
// Generate labels for chart
|
||||
const labels = [];
|
||||
for (let i = start.getDate(); i <= end.getDate(); i++) {
|
||||
if (i === end.getDate() && startMonth !== endMonth) {
|
||||
// Handle end month
|
||||
const endMonthDays = new Date(endYear, endMonth, 0).getDate();
|
||||
for (let j = 1; j <= end.getDate(); j++) {
|
||||
labels.push(`${j.toString().padStart(2, '0')}-${endMonth.toString().padStart(2, '0')}-${endYear}`);
|
||||
}
|
||||
} else {
|
||||
// Handle start month and other months in range
|
||||
labels.push(`${i.toString().padStart(2, '0')}-${startMonth.toString().padStart(2, '0')}-${startYear}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate datasets for chart
|
||||
const datasets = [];
|
||||
Object.keys(ratesForRange).forEach(type => {
|
||||
datasets.push({
|
||||
label: `${this.paymentMethodsConst[type]}`,
|
||||
data: ratesForRange[type],
|
||||
borderColor: this.colors[type],
|
||||
fill: false
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const ctx = document.getElementById("currency-history-chart");
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: datasets
|
||||
},
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -138,31 +244,5 @@ export default {
|
||||
// this.error = error.message;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
rateHistory: function(newVal) {
|
||||
this.chartLebels = [];
|
||||
this.chartData = [];
|
||||
for (var i = 0; i < newVal.length; i++) {
|
||||
this.chartLebels.push(newVal[i].created_at.split("-")[0]);
|
||||
this.chartData.push(newVal[i]["rate"]);
|
||||
}
|
||||
setTimeout(() => {
|
||||
const ctx = document.getElementById("currency-history-chart");
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: this.chartLebels,
|
||||
datasets: [{
|
||||
label: 'Currency Rate History',
|
||||
data: this.chartData,
|
||||
fill: false,
|
||||
borderColor: 'rgb(75, 192, 192)',
|
||||
tension: 0.1
|
||||
}]
|
||||
},
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@section('inner_content')
|
||||
<div class="row">
|
||||
<div class="col p-t-15 p-b-15">
|
||||
<rate-histories-component></rate-histories-component>
|
||||
<rate-histories-component :payment-methods="{{ json_encode($paymentMethods) }}"></rate-histories-component>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
+15
-13
@@ -1,26 +1,27 @@
|
||||
<?php
|
||||
|
||||
use App\Classes\Modules\Bookings\Processors\CreatePurchaseOrderFor1688OrderProcessor;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Bookings\Processors\CreatePurchaseOrderFor1688OrderProcessor;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -543,7 +544,8 @@ Route::get('/refund/fix', function(){
|
||||
});
|
||||
|
||||
Route::get('/currency-rate-history', function () {
|
||||
return view('pages.rate_histories');
|
||||
$paymentMethods = PaymentMethodType::PAYMENT_METHODS;
|
||||
return view('pages.rate_histories')->with('paymentMethods', $paymentMethods);
|
||||
})->name('currency_rate.history');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user