ALTER TABLE `bank_accounts` ADD `account_holder` text;
--> statement-breakpoint
ALTER TABLE `bank_accounts` ADD `rib` text;
--> statement-breakpoint
ALTER TABLE `bank_accounts` ADD `iban` text;
--> statement-breakpoint
ALTER TABLE `bank_accounts` ADD `swift` text;
--> statement-breakpoint
ALTER TABLE `bank_accounts` ADD `branch_address` text;
--> statement-breakpoint
CREATE TABLE `forecast_templates` (
  `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  `company_id` text NOT NULL,
  `label` text NOT NULL,
  `kind` text NOT NULL,
  `default_amount` real DEFAULT 0 NOT NULL,
  `note` text,
  `active` integer DEFAULT true NOT NULL
);
--> statement-breakpoint
CREATE INDEX `idx_forecast_templates_company` ON `forecast_templates` (`company_id`,`active`);
--> statement-breakpoint
INSERT INTO `forecast_templates` (`company_id`,`label`,`kind`,`default_amount`,`note`) VALUES
  ('lotrex','Salaires mensuels','fournisseur',0,'Paie du personnel'),
  ('lotrex','Échéance leasing','fournisseur',0,'Mensualité de leasing'),
  ('lotrex','TVA à décaisser','fournisseur',0,'Déclaration mensuelle de TVA'),
  ('ctl','Salaires mensuels','fournisseur',0,'Paie du personnel'),
  ('ctl','Échéance leasing','fournisseur',0,'Mensualité de leasing');
--> statement-breakpoint
CREATE TABLE `supplier_bank_accounts` (
  `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  `company_id` text NOT NULL,
  `supplier_name` text NOT NULL,
  `beneficiary_name` text NOT NULL,
  `bank_name` text NOT NULL,
  `rib` text NOT NULL,
  `iban` text,
  `swift` text,
  `active` integer DEFAULT true NOT NULL
);
--> statement-breakpoint
CREATE INDEX `idx_supplier_banks_company_supplier` ON `supplier_bank_accounts` (`company_id`,`supplier_name`);
--> statement-breakpoint
CREATE TABLE `transfer_orders` (
  `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  `company_id` text NOT NULL,
  `cash_flow_id` integer,
  `company_bank_id` integer NOT NULL,
  `supplier_bank_id` integer NOT NULL,
  `amount` real NOT NULL,
  `purpose` text NOT NULL,
  `order_date` text NOT NULL,
  `created_at` text NOT NULL,
  `status` text DEFAULT 'préparé' NOT NULL
);
--> statement-breakpoint
CREATE INDEX `idx_transfer_orders_company_date` ON `transfer_orders` (`company_id`,`order_date`);
--> statement-breakpoint
PRAGMA optimize;
