diff --git a/attached_assets/Pasted--nocodb-table-id-my7zunxprumahmm-nocodb-table-name-CommandeH-invoice-column-n-1755008314981_1755008314981.txt b/attached_assets/Pasted--nocodb-table-id-my7zunxprumahmm-nocodb-table-name-CommandeH-invoice-column-n-1755008314981_1755008314981.txt new file mode 100644 index 0000000..b51e61a --- /dev/null +++ b/attached_assets/Pasted--nocodb-table-id-my7zunxprumahmm-nocodb-table-name-CommandeH-invoice-column-n-1755008314981_1755008314981.txt @@ -0,0 +1,204 @@ + nocodb_table_id: 'my7zunxprumahmm', + + nocodb_table_name: 'CommandeH', + + invoice_column_name: 'RefFacture', + + group_created_at: '2025-07-22 11:09:08.977622', + + group_updated_at: '2025-08-12 09:39:32.989' + + } + +] + +✅ Processed 1 groups for user _1753266816257 + +🔍 getUserWithGroups called for user: _1753266816257 + +🔍 Querying user_groups for user: _1753266816257 + +🔍 Querying user_groups for user: _1753266816257 + +🔍 Found 1 group assignments for user _1753266816257 + +🔍 Raw query result: [ + + { + + user_id: '_1753266816257', + + group_id: 2, + + group_id_ref: 2, + + group_name: 'Houdemont', + + group_color: '#455A64', + + nocodb_config_id: 1, + + nocodb_table_id: 'my7zunxprumahmm', + + nocodb_table_name: 'CommandeH', + + invoice_column_name: 'RefFacture', + + group_created_at: '2025-07-22 11:09:08.977622', + + group_updated_at: '2025-08-12 09:39:32.989' + + } + +] + +✅ Processed 1 groups for user _1753266816257 + +🔍 getUserWithGroups called for user: _1753266816257 + +🔍 Found 1 group assignments for user _1753266816257 + +🔍 Raw query result: [ + + { + + user_id: '_1753266816257', + + group_id: 2, + + group_id_ref: 2, + + group_name: 'Houdemont', + + group_color: '#455A64', + + nocodb_config_id: 1, + + nocodb_table_id: 'my7zunxprumahmm', + + nocodb_table_name: 'CommandeH', + + invoice_column_name: 'RefFacture', + + group_created_at: '2025-07-22 11:09:08.977622', + + group_updated_at: '2025-08-12 09:39:32.989' + + } + +] + +✅ Processed 1 groups for user _1753266816257 + +🔍 getUserWithGroups called for user: _1753266816257 + +🔍 Querying user_groups for user: _1753266816257 + +🔍 Found 1 group assignments for user _1753266816257 + +🔍 Raw query result: [ + + { + + user_id: '_1753266816257', + + group_id: 2, + + group_id_ref: 2, + + group_name: 'Houdemont', + + group_color: '#455A64', + + nocodb_config_id: 1, + + nocodb_table_id: 'my7zunxprumahmm', + + nocodb_table_name: 'CommandeH', + + invoice_column_name: 'RefFacture', + + group_created_at: '2025-07-22 11:09:08.977622', + + group_updated_at: '2025-08-12 09:39:32.989' + + } + +] + +✅ Processed 1 groups for user _1753266816257 + +🔍 Querying user_groups for user: _1753266816257 + +🔍 Found 1 group assignments for user _1753266816257 + +🔍 Raw query result: [ + + { + + user_id: '_1753266816257', + + group_id: 2, + + group_id_ref: 2, + + group_name: 'Houdemont', + + group_color: '#455A64', + + nocodb_config_id: 1, + + nocodb_table_id: 'my7zunxprumahmm', + + nocodb_table_name: 'CommandeH', + + invoice_column_name: 'RefFacture', + + group_created_at: '2025-07-22 11:09:08.977622', + + group_updated_at: '2025-08-12 09:39:32.989' + + } + +] + +✅ Processed 1 groups for user _1753266816257 + +🔍 DLC Products API called with: { + + userId: '_1753266816257', + + userRole: 'employee', + + userGroups: [ { groupId: 2, groupName: 'Houdemont' } ], + + groupIds: [ 2 ], + + filters: {}, + + queryStoreId: undefined + +} + +GET /api/dlc-products/stats 304 in 18ms + +📋 DLC Products returned: 133 items + +📋 Sample DLC products groupIds: [ + + { id: 178, name: 'Nesta grenier strawberry aloe vera', groupId: 2 }, + + { id: 48, name: 'Gressins sésame', groupId: 2 }, + + { id: 154, name: 'M&m’s crispy 240g', groupId: 2 } + +] + +GET /api/dlc-products 304 in 26ms + +HEAD /api/health 200 in 1ms + + + + + \ No newline at end of file diff --git a/attached_assets/{FB7EC083-1E79-4A38-8599-3300B363A960}_1755008238157.png b/attached_assets/{FB7EC083-1E79-4A38-8599-3300B363A960}_1755008238157.png new file mode 100644 index 0000000..f383fd2 Binary files /dev/null and b/attached_assets/{FB7EC083-1E79-4A38-8599-3300B363A960}_1755008238157.png differ diff --git a/client/src/components/CustomerOrderForm.tsx b/client/src/components/CustomerOrderForm.tsx index 1d0f0a0..53dea96 100644 --- a/client/src/components/CustomerOrderForm.tsx +++ b/client/src/components/CustomerOrderForm.tsx @@ -22,17 +22,13 @@ import { SelectValue, } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; -import { insertCustomerOrderSchema, type CustomerOrderWithRelations, type Group, type Supplier } from "@shared/schema"; +import { insertCustomerOrderFrontendSchema, type CustomerOrderWithRelations, type Group, type Supplier } from "@shared/schema"; import { useStore } from "@/components/Layout"; -const customerOrderFormSchema = insertCustomerOrderSchema.extend({ - deposit: z.string().optional(), - gencode: z.string().min(1, "Le gencode est obligatoire"), - customerName: z.string().min(1, "Le nom du client est obligatoire"), - quantity: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) || 1 : val), - supplierId: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) : val), - groupId: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) : val).optional(), - createdBy: z.string().optional(), // Will be set automatically +const customerOrderFormSchema = insertCustomerOrderFrontendSchema.extend({ + deposit: z.number().optional().default(0), + groupId: z.number().int().positive().optional(), + createdBy: z.string().optional(), }); type CustomerOrderFormData = z.infer; @@ -120,15 +116,22 @@ export function CustomerOrderForm({ return; } - // Prepare data with proper types + // Prepare data with proper types for frontend schema const submitData = { - ...data, - customerName: data.customerName.trim(), // Clean the customer name - deposit: data.deposit || "0.00", // Keep as string for decimal field + customerName: data.customerName.trim(), + contactNumber: (data as any).customerPhone || (data as any).contactNumber || '', + productName: (data as any).productDesignation || (data as any).productName || '', + quantity: data.quantity, groupId: typeof groupId === 'number' ? groupId : parseInt(groupId.toString()), - createdBy: user?.id || '', // Add the current user ID + isPickup: false, + notes: (data as any).notes, + deposit: data.deposit || 0, + isPromotionalPrice: (data as any).isPromotionalPrice || false, + customerEmail: (data as any).customerEmail, + gencode: (data as any).gencode || '', + supplierId: (data as any).supplierId || 1, }; - console.log("Processed submit data:", submitData); + console.log("🔍 Frontend submit data:", submitData); onSubmit(submitData); }; diff --git a/cookies.txt b/cookies.txt index 1fcfe0f..73e7dab 100644 --- a/cookies.txt +++ b/cookies.txt @@ -2,4 +2,4 @@ # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -#HttpOnly_localhost FALSE / FALSE 1755094358 connect.sid s%3AGqqa9KVEFyrrc64iEAkqzrmbLaa9QLvf.xQnlef9xv7BPKRjEnDyFjY%2Buao%2BP669Ftp46tQk6ozI +#HttpOnly_localhost FALSE / FALSE 1755094677 connect.sid s%3AMRvtKRB7l8aU-cxKVAyRLza4Hz26hGS3.B0p70oONarXt57Foz6nSvGoPBIEpN6YNyr22RwYgJEc diff --git a/test-employee-customer-orders-final.js b/test-employee-customer-orders-final.js new file mode 100644 index 0000000..b43392a --- /dev/null +++ b/test-employee-customer-orders-final.js @@ -0,0 +1,73 @@ +#!/usr/bin/env node + +/** + * Test final pour la création de commandes client par employé + */ + +console.log('🔍 Test Final - Création Commande Client Employé'); + +async function testEmployeeCustomerOrder() { + try { + const fetch = require('node-fetch'); + + console.log('\n=== TEST FINAL CRÉATION COMMANDE CLIENT ==='); + + // 1. Login admin + console.log('1. Test admin...'); + const adminLogin = await fetch('http://localhost:5000/api/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username: 'admin', password: 'admin' }) + }); + + if (!adminLogin.ok) { + console.log('❌ Admin login failed'); + return; + } + + const adminCookies = adminLogin.headers.get('set-cookie'); + + // 2. Test création avec nouveau format + const orderData = { + customerName: 'Client Test Final', + contactNumber: '0123456789', + productName: 'Produit Test Final', + quantity: 1, + groupId: 1, + isPickup: false, + notes: 'Test final avec nouveau schema' + }; + + console.log('2. Envoi données:', orderData); + + const createOrder = await fetch('http://localhost:5000/api/customer-orders', { + method: 'POST', + headers: { + 'Cookie': adminCookies, + 'Content-Type': 'application/json' + }, + body: JSON.stringify(orderData) + }); + + console.log('Status:', createOrder.status); + const response = await createOrder.text(); + + if (createOrder.ok) { + console.log('✅ Commande créée avec succès'); + console.log('Réponse:', JSON.parse(response)); + } else { + console.log('❌ Erreur création:', response); + } + + console.log('\n3. Instructions pour test employé en production:'); + console.log('- Se connecter avec un compte employé'); + console.log('- Essayer de créer une commande client'); + console.log('- Vérifier les logs pour "Frontend submit data" et "Backend data mapped"'); + console.log('- Si erreur 403, vérifier que l\'employé est assigné au bon groupe'); + + } catch (error) { + console.log('❌ Erreur test:', error.message); + } +} + +testEmployeeCustomerOrder(); \ No newline at end of file