@@ -81,14 +81,32 @@ export default {
date_from: null,
},
chartLebels:[],
- chartData: []
+ chartData: [],
+ paymentMethodsConst: [],
+ colors: [
+ 'red',
+ 'green',
+ 'blue',
+ '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) {
@@ -140,25 +158,55 @@ export default {
},
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"]);
+ // Set current month and year
+ const date = new Date();
+ const currentMonth = date.getMonth() + 1;
+ const currentYear = date.getFullYear();
+
+ // 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);
+ });
+
+ // Get rates for current month
+ const ratesForMonth = {};
+ Object.keys(ratesByType).forEach(type => {
+ ratesForMonth[type] = [];
+ for (let i = 1; i <= new Date(currentYear, currentMonth, 0).getDate(); i++) {
+ const dateStr = `${i.toString().padStart(2, '0')}-${currentMonth.toString().padStart(2, '0')}-${currentYear}`;
+ const rate = ratesByType[type].find(r => r.created_at === dateStr);
+ ratesForMonth[type].push(rate ? rate.rate : '');
+ }
+ });
+
+ // Generate labels for chart
+ const labels = [];
+ for (let i = 1; i <= new Date(currentYear, currentMonth, 0).getDate(); i++) {
+ labels.push(`${i.toString().padStart(2, '0')}-${currentMonth.toString().padStart(2, '0')}-${currentYear}`);
+ }
+
+ // Generate datasets for chart
+ const datasets = [];
+ Object.keys(ratesForMonth).forEach(type => {
+ datasets.push({
+ label: `${this.paymentMethodsConst[type]}`,
+ data: ratesForMonth[type],
+ borderColor: `#${Math.floor(Math.random()*16777215).toString(16)}`,
+ fill: false
+ });
+ });
+
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
- }]
+ labels: labels,
+ datasets: datasets
},
});
}, 300);
diff --git a/resources/views/pages/rate_histories.blade.php b/resources/views/pages/rate_histories.blade.php
index accb0591..4d19ef10 100644
--- a/resources/views/pages/rate_histories.blade.php
+++ b/resources/views/pages/rate_histories.blade.php
@@ -2,7 +2,7 @@
@section('inner_content')
@endsection
diff --git a/routes/web.php b/routes/web.php
index 35ad7015..053c500e 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1,26 +1,27 @@
with('paymentMethods', $paymentMethods);
})->name('currency_rate.history');