|
|
@@ -9,11 +9,13 @@
|
|
|
let sortBy = 'date';
|
|
|
let sortDirection = 'desc';
|
|
|
let selectedSale = null;
|
|
|
+ let totalSales = null;
|
|
|
|
|
|
let token = null;
|
|
|
let company = null;
|
|
|
let orderId = null;
|
|
|
let csvDownload = [];
|
|
|
+ let topItems = [];
|
|
|
|
|
|
if (browser) {
|
|
|
token = localStorage.getItem('token');
|
|
|
@@ -29,7 +31,7 @@
|
|
|
const raw = JSON.stringify({
|
|
|
company_id: company,
|
|
|
page: 1,
|
|
|
- limit: 20
|
|
|
+ limit: 10
|
|
|
});
|
|
|
|
|
|
const requestOptions = {
|
|
|
@@ -46,8 +48,7 @@
|
|
|
console.log(result);
|
|
|
|
|
|
if (result.status === 'ok' && result.data) {
|
|
|
- // Converter o formato do endpoint para o formato de sales
|
|
|
- sales = result.data.map((order) => ({
|
|
|
+ sales = result.data.orders.map((order) => ({
|
|
|
id: order.order_id,
|
|
|
timestamp: order.order_finished_at?.trim()
|
|
|
? order.order_finished_at
|
|
|
@@ -55,12 +56,16 @@
|
|
|
tableId: order.table_id,
|
|
|
items: order.items.map((item) => ({
|
|
|
productName: item.product_name,
|
|
|
- quantity: 1, // Se o endpoint não informa quantidade, assumimos 1
|
|
|
+ quantity: 1,
|
|
|
priceAtSale: parseFloat(item.product_price)
|
|
|
})),
|
|
|
totalAmount: order.items.reduce((sum, item) => sum + parseFloat(item.product_price), 0),
|
|
|
- paymentMethod: order.order_flag // Já vem como "Dinheiro", "PIX" etc.
|
|
|
+ paymentMethod: order.order_flag
|
|
|
}));
|
|
|
+
|
|
|
+ totalSales = Number(result.data.total_sales).toFixed(2);
|
|
|
+ topItems = result.data.top_items;
|
|
|
+ console.log(topItems);
|
|
|
} else {
|
|
|
console.error('Erro na resposta da API:', result.msg);
|
|
|
}
|
|
|
@@ -225,16 +230,15 @@
|
|
|
<div class="mb-6 grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4">
|
|
|
<div class="rounded-lg bg-[#2C2C2E] p-4">
|
|
|
<h3 class="mb-2 text-sm text-[#A0A0A0]">Total em Vendas</h3>
|
|
|
- <p class="text-2xl font-bold text-[#D4AF37]">R$ {salesSummary.total.toFixed(2)}</p>
|
|
|
- <p class="mt-1 text-sm text-[#A0A0A0]">{salesSummary.count} itens vendidos</p>
|
|
|
+ <p class="text-2xl font-bold text-[#D4AF37]">R$ {totalSales}</p>
|
|
|
</div>
|
|
|
<div class="rounded-lg bg-[#2C2C2E] p-4">
|
|
|
<h3 class="mb-2 text-sm text-[#A0A0A0]">Produtos Mais Vendidos</h3>
|
|
|
<div class="space-y-1">
|
|
|
- {#each salesSummary.topProducts.slice(0, 3) as [name, data]}
|
|
|
+ {#each topItems as topItem}
|
|
|
<div class="flex justify-between text-sm">
|
|
|
- <span class="text-white">{name}</span>
|
|
|
- <span class="text-[#A0A0A0]">{data.quantity}x</span>
|
|
|
+ <span class="text-white">{topItem.product_name}</span>
|
|
|
+ <span class="text-[#A0A0A0]">{topItem.sold_quantity}x</span>
|
|
|
</div>
|
|
|
{/each}
|
|
|
</div>
|
|
|
@@ -360,13 +364,6 @@
|
|
|
<td class="whitespace-nowrap px-6 py-4 text-sm"
|
|
|
>{getPaymentMethodName(sale.paymentMethod)}</td
|
|
|
>
|
|
|
- <td class="whitespace-nowrap px-6 py-4 text-right">
|
|
|
- <!-- <button
|
|
|
- on:click|stopPropagation={() => handleCancelSale(sale.id)}
|
|
|
- class="rounded-lg p-1.5 text-white"
|
|
|
- >
|
|
|
- </button> basicamente eh um botao para cancelar o item em especifico-->
|
|
|
- </td>
|
|
|
</tr>
|
|
|
{/each}
|
|
|
{/if}
|