|
|
@@ -27,7 +27,9 @@
|
|
|
myHeaders.append('Content-Type', 'application/json');
|
|
|
|
|
|
const raw = JSON.stringify({
|
|
|
- company_id: company
|
|
|
+ company_id: company,
|
|
|
+ page: 1,
|
|
|
+ limit: 20
|
|
|
});
|
|
|
|
|
|
const requestOptions = {
|
|
|
@@ -38,34 +40,26 @@
|
|
|
};
|
|
|
|
|
|
try {
|
|
|
- const response = await fetch('https://dev2.mixtech.dev.br/order_item/get', requestOptions);
|
|
|
+ const response = await fetch('https://dev2.mixtech.dev.br/reports/get', requestOptions);
|
|
|
const result = await response.json();
|
|
|
csvDownload = result;
|
|
|
console.log(result);
|
|
|
|
|
|
if (result.status === 'ok' && result.data) {
|
|
|
- // Agrupar itens por order_id e transformar em formato de sales
|
|
|
- const itemsByOrder = result.data.reduce((acc, item) => {
|
|
|
- const orderId = item.order_id;
|
|
|
- if (!acc[orderId]) {
|
|
|
- acc[orderId] = [];
|
|
|
- }
|
|
|
- acc[orderId].push({
|
|
|
- productName: item.product_details.product_name,
|
|
|
- quantity: 1, // Suposição: quantidade fixa de 1
|
|
|
- priceAtSale: parseFloat(item.product_details.product_price)
|
|
|
- });
|
|
|
- return acc;
|
|
|
- }, {});
|
|
|
-
|
|
|
- // Converter para o formato de sales
|
|
|
- sales = Object.entries(itemsByOrder).map(([orderId, items], index) => ({
|
|
|
- id: parseInt(orderId),
|
|
|
- timestamp: new Date().toISOString(), // Data atual como padrão
|
|
|
- tableId: 1, // Valor fixo como padrão
|
|
|
- items,
|
|
|
- totalAmount: items.reduce((sum, item) => sum + item.priceAtSale * item.quantity, 0),
|
|
|
- paymentMethod: 'CASH' // Valor padrão
|
|
|
+ // Converter o formato do endpoint para o formato de sales
|
|
|
+ sales = result.data.map((order) => ({
|
|
|
+ id: order.order_id,
|
|
|
+ timestamp: order.order_finished_at?.trim()
|
|
|
+ ? order.order_finished_at
|
|
|
+ : new Date().toISOString(),
|
|
|
+ tableId: order.table_id,
|
|
|
+ items: order.items.map((item) => ({
|
|
|
+ productName: item.product_name,
|
|
|
+ quantity: 1, // Se o endpoint não informa quantidade, assumimos 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.
|
|
|
}));
|
|
|
} else {
|
|
|
console.error('Erro na resposta da API:', result.msg);
|
|
|
@@ -74,7 +68,6 @@
|
|
|
console.error('Erro ao buscar dados:', error);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
function exportarCSV() {
|
|
|
if (!csvDownload.length) return;
|
|
|
|
|
|
@@ -339,7 +332,6 @@
|
|
|
</button>
|
|
|
</th>
|
|
|
<th>Pagamento</th>
|
|
|
- <th class="text-right">Ações</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody class="divide-y divide-gray-700 bg-[#2C2C2E]">
|
|
|
@@ -369,11 +361,11 @@
|
|
|
>{getPaymentMethodName(sale.paymentMethod)}</td
|
|
|
>
|
|
|
<td class="whitespace-nowrap px-6 py-4 text-right">
|
|
|
- <button
|
|
|
+ <!-- <button
|
|
|
on:click|stopPropagation={() => handleCancelSale(sale.id)}
|
|
|
- class="rounded-lg p-1.5 text-[#FF3B30] hover:bg-[#FF3B30]/20"
|
|
|
+ class="rounded-lg p-1.5 text-white"
|
|
|
>
|
|
|
- </button>
|
|
|
+ </button> basicamente eh um botao para cancelar o item em especifico-->
|
|
|
</td>
|
|
|
</tr>
|
|
|
{/each}
|
|
|
@@ -411,13 +403,13 @@
|
|
|
Pagamento: <span class="text-white">{getPaymentMethodName(sale.paymentMethod)}</span
|
|
|
>
|
|
|
</div>
|
|
|
- <div class="mt-2 flex justify-end">
|
|
|
+ <!-- <div class="mt-2 flex justify-end">
|
|
|
<button
|
|
|
on:click|stopPropagation={() => handleCancelSale(sale.id)}
|
|
|
class="rounded-lg p-1.5 text-[#FF3B30] hover:bg-[#FF3B30]/20"
|
|
|
>
|
|
|
</button>
|
|
|
- </div>
|
|
|
+ </div> -->
|
|
|
</div>
|
|
|
{/each}
|
|
|
{/if}
|