mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Add invoice verification functionality to track invoice checks
Implement database operations for managing invoice verification records and their cache, including creation and retrieval. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c52a701b-4841-4d00-b8cf-5a41c12abdf3 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/c52a701b-4841-4d00-b8cf-5a41c12abdf3/3uCfEKb
This commit is contained in:
1 parent
5a16936591
commit
76a6d4c8ae
2 files changed
+105
No files matched your search
@@ -10,6 +10,8 @@ import {
|
||||
customerOrders,
|
||||
dlcProducts,
|
||||
tasks,
|
||||
invoiceVerificationCache,
|
||||
invoiceVerifications,
|
||||
type User,
|
||||
type UpsertUser,
|
||||
type Group,
|
||||
@@ -41,6 +43,10 @@ import {
|
||||
type DlcProductFrontend,
|
||||
type InsertDlcProductFrontend,
|
||||
type DlcProductWithRelations,
|
||||
type InvoiceVerificationCache,
|
||||
type InsertInvoiceVerificationCache,
|
||||
type InvoiceVerification,
|
||||
type InsertInvoiceVerification,
|
||||
type Task,
|
||||
type InsertTask,
|
||||
} from "@shared/schema";
|
||||
@@ -152,6 +158,12 @@ export interface IStorage {
|
||||
updateTask(id: number, task: Partial<InsertTask>): Promise<Task>;
|
||||
deleteTask(id: number): Promise<void>;
|
||||
completeTask(id: number, completedBy?: string): Promise<void>;
|
||||
|
||||
// Invoice Verification operations - Tables existantes en production
|
||||
getInvoiceVerifications(deliveryId?: number): Promise<InvoiceVerification[]>;
|
||||
createInvoiceVerification(verification: InsertInvoiceVerification): Promise<InvoiceVerification>;
|
||||
getInvoiceVerificationCache(cacheKey: string): Promise<InvoiceVerificationCache | undefined>;
|
||||
createInvoiceVerificationCache(cache: InsertInvoiceVerificationCache): Promise<InvoiceVerificationCache>;
|
||||
}
|
||||
|
||||
export class DatabaseStorage implements IStorage {
|
||||
@@ -2026,6 +2038,52 @@ export class DatabaseStorage implements IStorage {
|
||||
})
|
||||
.where(eq(tasks.id, id));
|
||||
}
|
||||
|
||||
// Invoice Verification operations - Utilise les tables existantes en production
|
||||
async getInvoiceVerifications(deliveryId?: number): Promise<InvoiceVerification[]> {
|
||||
const query = db.select().from(invoiceVerifications);
|
||||
if (deliveryId) {
|
||||
return await query.where(eq(invoiceVerifications.deliveryId, deliveryId));
|
||||
}
|
||||
return await query.orderBy(desc(invoiceVerifications.verifiedAt));
|
||||
}
|
||||
|
||||
async createInvoiceVerification(verification: InsertInvoiceVerification): Promise<InvoiceVerification> {
|
||||
const [newVerification] = await db
|
||||
.insert(invoiceVerifications)
|
||||
.values({
|
||||
...verification,
|
||||
verifiedAt: new Date(),
|
||||
lastCheckedAt: new Date(),
|
||||
})
|
||||
.returning();
|
||||
return newVerification;
|
||||
}
|
||||
|
||||
async getInvoiceVerificationCache(cacheKey: string): Promise<InvoiceVerificationCache | undefined> {
|
||||
const [cache] = await db
|
||||
.select()
|
||||
.from(invoiceVerificationCache)
|
||||
.where(
|
||||
and(
|
||||
eq(invoiceVerificationCache.cacheKey, cacheKey),
|
||||
sql`expires_at > NOW()`
|
||||
)
|
||||
);
|
||||
return cache;
|
||||
}
|
||||
|
||||
async createInvoiceVerificationCache(cache: InsertInvoiceVerificationCache): Promise<InvoiceVerificationCache> {
|
||||
const [newCache] = await db
|
||||
.insert(invoiceVerificationCache)
|
||||
.values({
|
||||
...cache,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.returning();
|
||||
return newCache;
|
||||
}
|
||||
}
|
||||
|
||||
// Simple in-memory storage for development
|
||||
|
||||
@@ -217,6 +217,37 @@ export const dlcProducts = pgTable("dlc_products", {
|
||||
updatedAt: timestamp("updated_at").defaultNow(), // Date de mise à jour
|
||||
});
|
||||
|
||||
// Invoice Verification Cache - Table existante en production
|
||||
export const invoiceVerificationCache = pgTable("invoice_verification_cache", {
|
||||
id: serial("id").primaryKey(),
|
||||
cacheKey: varchar("cache_key", { length: 255 }).notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
invoiceReference: varchar("invoice_reference", { length: 255 }).notNull(),
|
||||
supplierName: varchar("supplier_name", { length: 255 }),
|
||||
exists: boolean("exists").notNull(),
|
||||
matchType: varchar("match_type", { length: 50 }).notNull(),
|
||||
errorMessage: text("error_message"),
|
||||
cacheHit: boolean("cache_hit").default(false),
|
||||
apiCallTime: integer("api_call_time"),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
// Invoice Verifications - Table existante en production
|
||||
export const invoiceVerifications = pgTable("invoice_verifications", {
|
||||
id: serial("id").primaryKey(),
|
||||
deliveryId: integer("delivery_id").notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
invoiceReference: varchar("invoice_reference", { length: 255 }).notNull(),
|
||||
supplierName: varchar("supplier_name", { length: 255 }),
|
||||
exists: boolean("exists").notNull(),
|
||||
matchType: varchar("match_type", { length: 50 }),
|
||||
verifiedAt: timestamp("verified_at").defaultNow(),
|
||||
isValid: boolean("is_valid").default(true),
|
||||
lastCheckedAt: timestamp("last_checked_at").defaultNow(),
|
||||
});
|
||||
|
||||
// Tasks table
|
||||
export const tasks = pgTable("tasks", {
|
||||
id: serial("id").primaryKey(),
|
||||
@@ -481,6 +512,18 @@ export const insertDlcProductFrontendSchema = insertDlcProductSchema
|
||||
.omit({ expiryDate: true })
|
||||
.extend({ dlcDate: z.coerce.date() });
|
||||
|
||||
export const insertInvoiceVerificationCacheSchema = createInsertSchema(invoiceVerificationCache).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
export const insertInvoiceVerificationsSchema = createInsertSchema(invoiceVerifications).omit({
|
||||
id: true,
|
||||
verifiedAt: true,
|
||||
lastCheckedAt: true,
|
||||
});
|
||||
|
||||
export const insertTaskSchema = createInsertSchema(tasks).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
@@ -516,6 +559,10 @@ export type DlcProduct = typeof dlcProducts.$inferSelect;
|
||||
export type InsertDlcProduct = z.infer<typeof insertDlcProductSchema>;
|
||||
export type DlcProductFrontend = Omit<DlcProduct, 'expiryDate'> & { dlcDate: Date };
|
||||
export type InsertDlcProductFrontend = z.infer<typeof insertDlcProductFrontendSchema>;
|
||||
export type InvoiceVerificationCache = typeof invoiceVerificationCache.$inferSelect;
|
||||
export type InsertInvoiceVerificationCache = z.infer<typeof insertInvoiceVerificationCacheSchema>;
|
||||
export type InvoiceVerification = typeof invoiceVerifications.$inferSelect;
|
||||
export type InsertInvoiceVerification = z.infer<typeof insertInvoiceVerificationsSchema>;
|
||||
export type Task = typeof tasks.$inferSelect;
|
||||
export type InsertTask = z.infer<typeof insertTaskSchema>;
|
||||
|
||||
|
||||
Reference in new issue
Block a user