Bläddra i källkod

add the cancelar on command screen

gdias 4 månader sedan
förälder
incheckning
2814e06afb

+ 17 - 8
src/lib/component/AddProducts.svelte

@@ -109,14 +109,23 @@
 	}
 
 	function addItemToOrder(product, note) {
-		const newItem = {
-			order_item_id: Date.now(),
-			product_details: product,
-			quantity: 1,
-			kitchen_note: note
-		};
-
-		localOrderItems = [...localOrderItems, newItem];
+		if (product.product_is_kitchen) {
+			const newItem = {
+				order_item_id: Date.now(),
+				product_details: product,
+				quantity: 1,
+				kitchen_note: note
+			};
+			localOrderItems = [...localOrderItems, newItem];
+		} else {
+			const newItem = {
+				order_item_id: Date.now(),
+				product_details: product,
+				quantity: 1,
+				kitchen_note: note
+			};
+			localOrderItems = [...localOrderItems, newItem];
+		}
 	}
 
 	function removeItemFromOrder(itemId) {

+ 28 - 4
src/lib/component/Commands.svelte

@@ -90,6 +90,33 @@
 		}
 	};
 
+	function cancelCommand(order_Id) {
+		const myHeaders = new Headers();
+		myHeaders.append('Authorization', `Bearer ${token}`);
+		myHeaders.append('Content-Type', 'application/json');
+
+		const raw = JSON.stringify({
+			order_id: order_Id,
+			company_id: companyId,
+			cancel: true
+		});
+
+		const requestOptions = {
+			method: 'POST',
+			headers: myHeaders,
+			body: raw,
+			redirect: 'follow'
+		};
+
+		fetch('https://dev2.mixtech.dev.br/order/delete', requestOptions)
+			.then((response) => response.json())
+			.then((result) => {
+				(console.log('Pedido cancelado com sucesso:', order_Id, companyId, result),
+					location.reload());
+			})
+			.catch((error) => console.error('Erro ao cancelar comanda:', error));
+	}
+
 	const getElapsedTime = (createdAt) => {
 		if (!createdAt || createdAt.trim() === '') return '';
 		const start = new Date(createdAt.replace(' ', 'T'));
@@ -155,10 +182,7 @@
 					{#if flag == 'admin' || flag == 'cashier'}
 						<button
 							class="w-full rounded bg-red-600 py-2 hover:bg-red-700"
-							on:click={() => {
-								orderToCancel = order.name;
-								showConfirmCancel = true;
-							}}
+							on:click={cancelCommand(order.id)}
 						>
 							Cancelar
 						</button>

+ 3 - 3
src/routes/forgotten/+page.svelte

@@ -11,7 +11,7 @@
 
 	onMount(() => {
 		if (currentUser) {
-			goto('/tables');
+			goto('/login');
 		}
 	});
 
@@ -68,7 +68,7 @@
 						type="email"
 						bind:value={email}
 						placeholder="Digite seu E-mail"
-						class="block w-full rounded-md border border-[#A0A0A0]/20 bg-[#1C1C1E] py-3 pr-3 pl-3 text-white focus:border-[#D4AF37] focus:ring-2 focus:ring-[#D4AF37] focus:outline-none"
+						class="block w-full rounded-md border border-[#A0A0A0]/20 bg-[#1C1C1E] py-3 pl-3 pr-3 text-white focus:border-[#D4AF37] focus:outline-none focus:ring-2 focus:ring-[#D4AF37]"
 					/>
 				</div>
 			</div>
@@ -76,7 +76,7 @@
 			<div>
 				<button
 					type="submit"
-					class="flex w-full cursor-pointer items-center justify-center rounded-md bg-[#D4AF37] px-4 py-3 text-[#1C1C1E] transition-colors hover:bg-[#D4AF37]/90 focus:ring-2 focus:ring-[#D4AF37] focus:ring-offset-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
+					class="flex w-full cursor-pointer items-center justify-center rounded-md bg-[#D4AF37] px-4 py-3 text-[#1C1C1E] transition-colors hover:bg-[#D4AF37]/90 focus:outline-none focus:ring-2 focus:ring-[#D4AF37] focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
 					disabled={loading}
 				>
 					{loading ? 'Enviando' : 'Enviar E-mail'}