akaunting/resources/assets/js/components/AkauntingRecurring.vue

293 lines
9.0 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
2022-06-01 10:15:55 +03:00
<div class="sm:col-span-6 space-y-8 sm:space-y-2">
<div class="flex flex-wrap lg:flex-nowrap items-center space-y-3 lg:space-y-0" :class="{ 'justify-between sm:justify-start': frequency == 'custom' }">
2022-06-01 10:15:55 +03:00
<div class="w-60 px-2 text-sm">
{{ frequencyText }}
</div>
<el-select class="w-36" v-model="frequency" @input="change">
<el-option
v-for="(label, value) in frequencies"
:key="value"
2019-11-16 10:21:14 +03:00
:label="label"
:value="value">
</el-option>
</el-select>
2022-06-01 10:15:55 +03:00
<div class="w-20 px-2 text-sm text-center" v-if="frequency == 'custom'">
{{ frequencyEveryText }}
</div>
<input type="text" class="w-20 text-sm px-3 py-2.5 mt-1 rounded-lg border border-light-gray text-black placeholder-light-gray bg-white disabled:bg-gray-200 focus:outline-none focus:ring-transparent focus:border-purple" v-model="interval" @input="change" v-if="frequency == 'custom'">
2022-06-01 10:15:55 +03:00
<el-select class="w-36 ml-2" v-model="customFrequency" @input="change" v-if="frequency == 'custom'">
<el-option
v-for="(label, value) in customFrequencies"
:key="value"
:label="label"
:value="value">
</el-option>
</el-select>
</div>
<div class="flex flex-wrap lg:flex-nowrap items-center space-y-3 lg:space-y-0" :class="{ 'justify-between sm:justify-start': limit !== 'never' }">
2022-06-01 10:15:55 +03:00
<div class="w-60 px-2 text-sm">
{{ startText }}
</div>
<el-date-picker
class="w-36 recurring-invoice-data"
v-model="started_at"
@input="change"
type="date"
align="right"
:format="formatDate"
value-format="yyyy-MM-dd"
:picker-options="{
disabledDate(time) {
return time.getTime() < Date.now();
},
shortcuts: [
{
text: dateRangeText['today'],
onClick(picker) {
picker.$emit('pick', new Date());
}
},
{
text: dateRangeText['yesterday'],
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24);
picker.$emit('pick', date);
}
},
{
text: dateRangeText['week_ago'],
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', date);
}
}
]
}">
</el-date-picker>
<div class="w-20 px-2 text-sm text-center">
{{ middleText }}
</div>
<el-select class="w-20" v-model="limit" @input="change">
<el-option
v-for="(label, value) in limits"
:key="value"
2019-11-16 10:21:14 +03:00
:label="label"
:value="value">
</el-option>
</el-select>
2022-06-01 10:15:55 +03:00
<input type="text" class="w-20 text-sm px-3 py-2.5 mt-1 ml-2 rounded-lg border border-light-gray text-black placeholder-light-gray bg-white disabled:bg-gray-200 focus:outline-none focus:ring-transparent focus:border-purple" v-model="limitCount" v-if="limit == 'after'" @input="change">
2022-06-01 10:15:55 +03:00
<div class="pl-2 text-sm" v-if="limit == 'after'">
{{ endText }}
</div>
<el-date-picker
class="w-36 ml-2 recurring-invoice-data"
2022-06-01 10:15:55 +03:00
v-model="limitDate"
type="date"
align="right"
:format="formatDate"
value-format="yyyy-MM-dd"
v-if="limit == 'on'"
@input="change"
>
</el-date-picker>
</div>
2019-11-16 10:21:14 +03:00
</div>
</template>
<script>
2022-06-01 10:15:55 +03:00
import { Select, Option, DatePicker } from 'element-ui';
2019-11-16 10:21:14 +03:00
export default {
name: 'akaunting-recurring',
components: {
[Select.name]: Select,
[Option.name]: Option,
2022-06-01 10:15:55 +03:00
[DatePicker.name]: DatePicker,
2019-11-16 10:21:14 +03:00
},
props: {
2022-06-01 10:15:55 +03:00
startText: {
2019-11-16 10:21:14 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'Create first invoice on',
description: "Default reccuring text"
2019-11-16 10:21:14 +03:00
},
2022-06-01 10:15:55 +03:00
dateRangeText: {
type: Object,
default: {
today : 'Today',
yesterday : 'Yesterday',
week_ago : 'A week ago',
},
description: "Default reccuring text"
2021-11-11 12:02:47 +03:00
},
2022-06-01 10:15:55 +03:00
middleText: {
2021-11-11 12:02:47 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'and end',
description: "Default reccuring text"
2021-11-11 12:02:47 +03:00
},
2022-06-01 10:15:55 +03:00
endText: {
2021-11-11 12:02:47 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'invoices',
description: "Default reccuring text"
2021-11-11 12:02:47 +03:00
},
2022-06-01 10:15:55 +03:00
frequencies: null,
frequencyText: {
2021-11-11 12:02:47 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'Repeat this invoice',
description: "Default reccuring text"
2021-11-11 12:02:47 +03:00
},
2022-06-01 10:15:55 +03:00
frequencyEveryText: {
2019-11-16 10:21:14 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'every',
description: "Default reccuring text"
2019-11-16 10:21:14 +03:00
},
2022-06-01 10:15:55 +03:00
frequencyValue: {
type: String,
default: 'monthly',
description: "Default reccuring type"
},
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
customFrequencies: null,
customFrequencyValue: {
type: String,
default: 'monthly',
description: "Default reccuring type"
},
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
startedValue: {
type: String,
default: 'never',
description: "Default reccuring limit"
2020-04-22 14:50:30 +03:00
},
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
limits: null,
limitValue: {
type: String,
default: 'never',
description: "Default reccuring limit"
},
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
limitCountValue: {
type: [Number, String],
default: 0,
2022-06-01 10:15:55 +03:00
description: "Default reccuring limit"
2020-04-22 14:50:30 +03:00
},
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
limitDateValue: {
2019-11-16 10:21:14 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: '',
description: "Default reccuring limit"
2021-11-11 12:02:47 +03:00
},
2022-06-01 10:15:55 +03:00
dateFormat: {
2021-11-11 12:02:47 +03:00
type: String,
2022-06-01 10:15:55 +03:00
default: 'dd MM yyyy',
description: "Default date format"
2021-11-11 12:02:47 +03:00
},
2019-11-16 10:21:14 +03:00
},
data() {
return {
2022-06-01 10:15:55 +03:00
frequency: '',
interval: '',
customFrequency: '',
started_at: '',
limit: '',
limitCount: 0,
2022-06-01 10:15:55 +03:00
limitDate: '',
formatDate: 'dd MM YYYY',
2019-11-16 10:21:14 +03:00
}
},
2022-06-01 10:15:55 +03:00
created() {
this.formatDate = this.convertToDarteFormat(this.dateFormat);
2020-04-22 14:50:30 +03:00
},
2019-11-16 10:21:14 +03:00
mounted() {
2022-06-01 10:15:55 +03:00
this.frequency = this.frequencyValue;
this.customFrequency = this.customFrequencyValue;
this.started_at = this.startedValue;
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
this.limit = this.limitValue;
this.limitCount = this.limitCountValue;
this.limitDate = this.limitDateValue;
2022-06-01 10:15:55 +03:00
if (this.limit == 'count') {
if (this.limitCount > 0) {
2022-06-01 10:15:55 +03:00
this.limit = 'after';
} else {
this.limit = 'never';
2022-06-01 10:15:55 +03:00
}
} else {
this.limit = 'on';
}
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
setTimeout(function() {
this.change();
}.bind(this), 800);
2019-11-16 10:21:14 +03:00
},
methods: {
change() {
2022-06-01 10:15:55 +03:00
this.$emit('change', this.frequency);
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
this.$emit('frequency', this.frequency);
this.$emit('interval', this.interval);
this.$emit('custom_frequency', this.customFrequency);
this.$emit('started', this.started_at);
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
switch (this.limit) {
case 'after':
this.$emit('limit', 'count');
this.$emit('limit_count', this.limitCount);
this.$emit('limit_date', null);
2022-06-01 10:15:55 +03:00
break;
case 'on':
this.$emit('limit', 'date');
this.$emit('limit_date', this.limitDate);
this.$emit('limit_count', 0);
2022-06-01 10:15:55 +03:00
break;
case 'never':
default:
this.$emit('limit', 'count');
this.$emit('limit_count', 0);
break;
}
2019-11-16 10:21:14 +03:00
},
2022-06-01 10:15:55 +03:00
convertToDarteFormat(format) {
return format.replace('d', 'dd')
.replace('M', 'MMM')
.replace('m', 'MM')
.replace('F', 'MMMM')
.replace('y', 'yyyy')
.replace('Y', 'yyyy');
},
2019-11-16 10:21:14 +03:00
}
}
</script>
2022-06-01 10:15:55 +03:00
<style>
.el-input__inner {
height: 42px;
}
</style>