Generate Excel reports for outgoing invoices and incoming payments.

This commit is contained in:
2025-01-18 08:53:48 +01:00
parent 5d4766a103
commit f246f80b6b
3 changed files with 224 additions and 5 deletions

View File

@@ -18,6 +18,8 @@
<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"/>
@@ -32,6 +34,9 @@
</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>
@@ -43,6 +48,8 @@
<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') }}",
@@ -50,14 +57,29 @@
},
submit() {
axios.post('/excel', this.data)
let vm = this;
axios.post('/excel', this.data, {responseType: "blob"})
.then(function(response) {
console.log(response.data);
console.log(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';
}
let download = document.querySelector('#download');
download.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}).catch(function(error) {
console.log(error);
vm.error = true;
vm.message = error.response.data.message;
})
}
}
}