CREATE TABLE `bank_accounts` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`name` text NOT NULL,
	`account_label` text NOT NULL,
	`balance` real NOT NULL,
	`minimum_balance` real DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE `cash_flows` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`kind` text NOT NULL,
	`party` text NOT NULL,
	`reference` text NOT NULL,
	`amount` real NOT NULL,
	`due_date` text NOT NULL,
	`planned_date` text NOT NULL,
	`status` text DEFAULT 'planifié' NOT NULL,
	`manual_override` integer DEFAULT false NOT NULL,
	`bank_account_id` integer,
	FOREIGN KEY (`bank_account_id`) REFERENCES `bank_accounts`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `cash_flows_reference_unique` ON `cash_flows` (`reference`);
--> statement-breakpoint
CREATE INDEX `idx_cash_flows_planned_date` ON `cash_flows` (`planned_date`);
--> statement-breakpoint
CREATE INDEX `idx_cash_flows_kind_status` ON `cash_flows` (`kind`,`status`);
--> statement-breakpoint
INSERT INTO `bank_accounts` (`name`,`account_label`,`balance`,`minimum_balance`) VALUES
('Attijariwafa bank','Compte principal · 4821',368400,100000),
('Banque Populaire','Compte exploitation · 1936',201650,75000),
('Bank of Africa','Compte secondaire · 7042',114250,50000);
--> statement-breakpoint
INSERT INTO `cash_flows` (`kind`,`party`,`reference`,`amount`,`due_date`,`planned_date`,`status`,`manual_override`) VALUES
('fournisseur','Atlas Pneumatiques','FA-2026-0841',46500,'2026-08-18','2026-08-18','à valider',false),
('client','TransMaroc Logistique','FV-2026-0318',82400,'2026-08-19','2026-08-19','planifié',false),
('fournisseur','Diesel Parts Services','FA-2026-0794',29800,'2026-08-15','2026-08-20','en retard',true),
('client','Sahara Fret','FV-2026-0297',128600,'2026-08-22','2026-08-22','planifié',false),
('fournisseur','Maghreb Lubrifiants','FA-2026-0862',18750,'2026-08-24','2026-08-25','planifié',true),
('client','Nord Route Distribution','FV-2026-0334',54700,'2026-08-26','2026-08-26','à valider',false);
--> statement-breakpoint
PRAGMA optimize;
