Files
project/resources/views/excel.blade.php

94 lines
4.5 KiB
PHP

<x-app-layout>
<x-slot name="header">
<h2 class="grow font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('excel.Excel export') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w" x-data="excelForm">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('excel.Choose data') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __("excel.Choose data hint") }}
</p>
<p class="text-red-600 font-bold" x-text="message" x-show="error"></p>
<div class="flex flex-row space-x-4 items-center mt-8">
<x-input-label for="from" :value="__('invoice.From')"/>
<x-text-input type="date" id="from" name="from" x-model="data.from"/>
<x-input-label for="end" :value="__('invoice.End')"/>
<x-text-input type="date" id="end" name="end" x-model="data.end"/>
<x-input-label for="report" :value="__('excel.Report')"/>
<select name="report" id="report" x-model="data.report" class="border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm w-1/4">
<option value="invoice">{{ __('excel.Outgoing invoices') }}</option>
<option value="payment">{{ __('excel.Incoming payments') }}</option>
<option value="incoming">{{ __('excel.Incoming by issue date') }}</option>
<option value="outgoing">{{ __('excel.Outgoing by pay date') }}</option>
</select>
</div>
</header>
<x-primary-button @click="submit" class="mt-8" x-show="data.report !== ''">{{ __('excel.Generate') }}</x-primary-button>
<div id="download"></div>
</section>
</div>
</div>
</div>
</div>
</x-app-layout>
<script>
function excelForm() {
return {
error: false,
message: '',
data: {
from: "{{ \Illuminate\Support\Facades\Date::now()->firstOfMonth()->format('Y-m-d') }}",
end: "{{ \Illuminate\Support\Facades\Date::now()->format('Y-m-d') }}",
report: 'invoice',
},
submit() {
let vm = this;
axios.post('/excel', this.data, {responseType: "blob"})
.then(function(response) {
let url = window.URL.createObjectURL(response.data);
let a = document.createElement('a');
a.href = url;
a.download = 'Excel.xlsx';
if (vm.data.report === 'invoice') {
a.download = '{{ __('invoice.Invoices') }}' + '.xlsx';
}
if (vm.data.report === 'payment') {
a.download = '{{ __('invoice.Payments') }}' + '.xlsx';
}
if (vm.data.report === 'incoming') {
a.download = '{{ __('incoming.Incoming') }}' + '.xlsx';
}
if (vm.data.report === 'outgoing') {
a.download = '{{ __('incoming.Outgoing') }}' + '.xlsx';
}
let download = document.querySelector('#download');
download.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}).catch(function(error) {
vm.error = true;
vm.message = error.response.data.message;
})
}
}
}
</script>