|
@@ -9,11 +9,11 @@
|
|
|
let sortBy = 'date';
|
|
let sortBy = 'date';
|
|
|
let sortDirection = 'desc';
|
|
let sortDirection = 'desc';
|
|
|
let selectedSale = null;
|
|
let selectedSale = null;
|
|
|
- let isDayClosingModalOpen = false;
|
|
|
|
|
|
|
|
|
|
let token = null;
|
|
let token = null;
|
|
|
let company = null;
|
|
let company = null;
|
|
|
let orderId = null;
|
|
let orderId = null;
|
|
|
|
|
+ let csvDownload = [];
|
|
|
|
|
|
|
|
if (browser) {
|
|
if (browser) {
|
|
|
token = localStorage.getItem('token');
|
|
token = localStorage.getItem('token');
|
|
@@ -40,6 +40,8 @@
|
|
|
try {
|
|
try {
|
|
|
const response = await fetch('https://dev2.mixtech.dev.br/order_item/get', requestOptions);
|
|
const response = await fetch('https://dev2.mixtech.dev.br/order_item/get', requestOptions);
|
|
|
const result = await response.json();
|
|
const result = await response.json();
|
|
|
|
|
+ csvDownload = result;
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
|
|
|
if (result.status === 'ok' && result.data) {
|
|
if (result.status === 'ok' && result.data) {
|
|
|
// Agrupar itens por order_id e transformar em formato de sales
|
|
// Agrupar itens por order_id e transformar em formato de sales
|
|
@@ -73,6 +75,35 @@
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ function exportarCSV() {
|
|
|
|
|
+ if (!csvDownload.length) return;
|
|
|
|
|
+
|
|
|
|
|
+ const headers = ['order_item_id', 'product_name', 'product_price', 'product_is_kitchen'];
|
|
|
|
|
+
|
|
|
|
|
+ const linhas = [
|
|
|
|
|
+ headers.join(','),
|
|
|
|
|
+ ...csvDownload.map((pedido) => {
|
|
|
|
|
+ const produto = pedido.product_details;
|
|
|
|
|
+ return [
|
|
|
|
|
+ pedido.order_item_id,
|
|
|
|
|
+ JSON.stringify(produto.product_name ?? ''),
|
|
|
|
|
+ produto.product_price,
|
|
|
|
|
+ produto.product_is_kitchen
|
|
|
|
|
+ ].join(',');
|
|
|
|
|
+ })
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ const csvContent = linhas.join('\n');
|
|
|
|
|
+
|
|
|
|
|
+ const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
|
|
+ const link = document.createElement('a');
|
|
|
|
|
+ link.href = url;
|
|
|
|
|
+ link.setAttribute('download', 'csvDownload.csv');
|
|
|
|
|
+ link.click();
|
|
|
|
|
+ URL.revokeObjectURL(url);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function formatDate(dateStr) {
|
|
function formatDate(dateStr) {
|
|
|
const date = new Date(dateStr);
|
|
const date = new Date(dateStr);
|
|
|
return `${date.toLocaleDateString()} ${date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
|
|
return `${date.toLocaleDateString()} ${date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
|
|
@@ -180,11 +211,6 @@
|
|
|
selectedSale = null;
|
|
selectedSale = null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function handleClosingDay() {
|
|
|
|
|
- console.log('Fechamento do dia concluído.');
|
|
|
|
|
- isDayClosingModalOpen = false;
|
|
|
|
|
- }
|
|
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex w-full flex-col rounded-md bg-stone-800 p-4">
|
|
<div class="flex w-full flex-col rounded-md bg-stone-800 p-4">
|
|
@@ -193,16 +219,10 @@
|
|
|
<div class="mb-6 flex flex-col justify-between md:flex-row md:items-center">
|
|
<div class="mb-6 flex flex-col justify-between md:flex-row md:items-center">
|
|
|
<h1 class="mb-4 text-2xl font-bold md:mb-0">Relatório de Vendas</h1>
|
|
<h1 class="mb-4 text-2xl font-bold md:mb-0">Relatório de Vendas</h1>
|
|
|
<div class="flex w-full flex-col gap-2 sm:flex-row sm:justify-end md:w-auto">
|
|
<div class="flex w-full flex-col gap-2 sm:flex-row sm:justify-end md:w-auto">
|
|
|
- <button
|
|
|
|
|
- on:click={() => (isDayClosingModalOpen = true)}
|
|
|
|
|
- class="flex w-full items-center justify-center rounded-lg bg-[#D4AF37] px-4 py-2 text-[#1C1C1E] transition-colors hover:bg-[#D4AF37]/90 sm:w-auto"
|
|
|
|
|
- >
|
|
|
|
|
- Fechamento do Dia
|
|
|
|
|
- </button>
|
|
|
|
|
<button
|
|
<button
|
|
|
on:click={exportToCSV}
|
|
on:click={exportToCSV}
|
|
|
disabled={filteredSales.length === 0}
|
|
disabled={filteredSales.length === 0}
|
|
|
- class="flex w-full items-center justify-center rounded-lg bg-[#2C2C2E] px-4 py-2 transition-colors hover:bg-[#3C3C3E] disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto"
|
|
|
|
|
|
|
+ class=" flex w-full items-center justify-center rounded-lg bg-[#D4AF37] px-4 py-2 text-[#1C1C1E] transition-colors hover:bg-[#3C3C3E] disabled:cursor-not-allowed sm:w-auto"
|
|
|
>
|
|
>
|
|
|
Exportar CSV
|
|
Exportar CSV
|
|
|
</button>
|
|
</button>
|