mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-22 06:38:21 +02:00
Enable support for multiple products within a single sale
Implements multi-product sales functionality by adding a `sale_products` table, updating the sales form, and modifying server-side logic. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e80fed01-7137-4997-b9af-dad57132d430 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/e80fed01-7137-4997-b9af-dad57132d430/58t7aEc
This commit is contained in:
1 parent
54595e75df
commit
e91b8f1a8b
10 files changed
+1303
-50
No files matched your search
+29
-9
@@ -51,7 +51,7 @@ export const users = pgTable("users", {
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
// Sales table
|
||||
// Sales table - Informations générales de la vente
|
||||
export const sales = pgTable("sales", {
|
||||
id: serial("id").primaryKey(),
|
||||
storeId: integer("store_id").references(() => stores.id).notNull(),
|
||||
@@ -61,12 +61,6 @@ export const sales = pgTable("sales", {
|
||||
// Vendeur
|
||||
vendeur: varchar("vendeur", { length: 255 }).notNull(),
|
||||
|
||||
// Produit
|
||||
typeArticle: varchar("type_article", { length: 255 }).notNull(),
|
||||
categorie: varchar("categorie", { length: 2 }).notNull(),
|
||||
quantite: integer("quantite").notNull(),
|
||||
gencode: varchar("gencode", { length: 13 }).notNull(),
|
||||
|
||||
// Client
|
||||
nom: varchar("nom", { length: 255 }).notNull(),
|
||||
prenom: varchar("prenom", { length: 255 }).notNull(),
|
||||
@@ -77,7 +71,7 @@ export const sales = pgTable("sales", {
|
||||
// Identité
|
||||
typeIdentite: varchar("type_identite", { length: 50 }).notNull(),
|
||||
numeroIdentite: varchar("numero_identite", { length: 100 }).notNull(),
|
||||
autoriteDelivrance: varchar("autorite_delivrance", { length: 255 }).notNull(),
|
||||
autoriteDelivrance: varchar("autorite_delivrance", { length: 255 }),
|
||||
dateDelivrance: varchar("date_delivrance", { length: 10 }).notNull(),
|
||||
|
||||
// Photos
|
||||
@@ -86,6 +80,17 @@ export const sales = pgTable("sales", {
|
||||
photo_ticket: text("photo_ticket"),
|
||||
});
|
||||
|
||||
// Table des produits vendus (nouveau)
|
||||
export const saleProducts = pgTable("sale_products", {
|
||||
id: serial("id").primaryKey(),
|
||||
saleId: integer("sale_id").references(() => sales.id, { onDelete: "cascade" }).notNull(),
|
||||
typeArticle: varchar("type_article", { length: 255 }).notNull(),
|
||||
categorie: varchar("categorie", { length: 2 }).notNull(),
|
||||
quantite: integer("quantite").notNull(),
|
||||
gencode: varchar("gencode", { length: 13 }).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
});
|
||||
|
||||
// Relations
|
||||
export const storesRelations = relations(stores, ({ many }) => ({
|
||||
users: many(users),
|
||||
@@ -100,7 +105,7 @@ export const usersRelations = relations(users, ({ one, many }) => ({
|
||||
sales: many(sales),
|
||||
}));
|
||||
|
||||
export const salesRelations = relations(sales, ({ one }) => ({
|
||||
export const salesRelations = relations(sales, ({ one, many }) => ({
|
||||
store: one(stores, {
|
||||
fields: [sales.storeId],
|
||||
references: [stores.id],
|
||||
@@ -109,6 +114,14 @@ export const salesRelations = relations(sales, ({ one }) => ({
|
||||
fields: [sales.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
products: many(saleProducts),
|
||||
}));
|
||||
|
||||
export const saleProductsRelations = relations(saleProducts, ({ one }) => ({
|
||||
sale: one(sales, {
|
||||
fields: [saleProducts.saleId],
|
||||
references: [sales.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
// Insert schemas
|
||||
@@ -129,6 +142,11 @@ export const insertSaleSchema = createInsertSchema(sales).omit({
|
||||
timestamp: true,
|
||||
});
|
||||
|
||||
export const insertSaleProductSchema = createInsertSchema(saleProducts).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
});
|
||||
|
||||
// Login schema
|
||||
export const loginSchema = z.object({
|
||||
username: z.string().min(1, "Nom d'utilisateur requis"),
|
||||
@@ -142,4 +160,6 @@ export type Store = typeof stores.$inferSelect;
|
||||
export type InsertStore = typeof stores.$inferInsert;
|
||||
export type Sale = typeof sales.$inferSelect;
|
||||
export type InsertSale = typeof sales.$inferInsert;
|
||||
export type SaleProduct = typeof saleProducts.$inferSelect;
|
||||
export type InsertSaleProduct = typeof saleProducts.$inferInsert;
|
||||
export type LoginData = z.infer<typeof loginSchema>;
|
||||
Reference in new issue
Block a user