019 - PWA
ALTER TABLE `user` ADD `soc_id` INT NULL AFTER `role_id`;
ALTER TABLE `user` ADD CONSTRAINT `user_societe` FOREIGN KEY (`soc_id`) REFERENCES `societe`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

CREATE TABLE `update` (`id` INT NOT NULL AUTO_INCREMENT , `version` VARCHAR(255) NOT NULL , `description` TEXT NULL , `date_update` DATETIME NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

020 - Taxes
CREATE TABLE `taxe` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `nom` VARCHAR(255) NOT NULL , `taux` FLOAT NOT NULL , `deleted` TINYINT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `taxe` ADD CONSTRAINT `taxe_societe` FOREIGN KEY (`societe_id`) REFERENCES `societe`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `produit` ADD `taxe_id` INT NULL AFTER `societe_id`;
ALTER TABLE `produit` ADD CONSTRAINT `produit_taxe` FOREIGN KEY (`taxe_id`) REFERENCES `taxe`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `societe` CHANGE `code_postal` `code_postal` VARCHAR(255) NOT NULL, CHANGE `telephone` `telephone` VARCHAR(255) NULL DEFAULT NULL;
ALTER TABLE `societe` ADD `siren` VARCHAR(255) NULL AFTER `site`, ADD `siret` VARCHAR(255) NULL AFTER `siren`, ADD `tva` TINYINT NULL DEFAULT '0' AFTER `siret`, ADD `rcs` VARCHAR(255) NULL AFTER `tva`, ADD `numero_rcs` VARCHAR(255) NULL AFTER `rcs`, ADD `capital` FLOAT NULL AFTER `numero_rcs`;
ALTER TABLE `facture` ADD `taxable` TINYINT NULL DEFAULT '0' AFTER `devis_id`;
ALTER TABLE `devis` ADD `taxable` TINYINT NULL DEFAULT '0' AFTER `societe_id`;
ALTER TABLE `societe` ADD `logo_crop` VARCHAR(255) NULL AFTER `logo`;

021 - Factures récurrentes
CREATE TABLE `facture_recurrente` (`id` INT NOT NULL AUTO_INCREMENT , `societe_id` INT NOT NULL , `facture_id` INT NOT NULL , `frequence` VARCHAR(255) NOT NULL , `prochaine_generation` DATE NULL , `active` TINYINT NOT NULL DEFAULT '0' , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `facture_recurrente` ADD `idtoken` VARCHAR(255) NULL AFTER `id`;
ALTER TABLE `facture_recurrente` ADD `cycle` INT NULL AFTER `frequence`, ADD `cycle_restant` INT NULL AFTER `cycle`;

022 - Commentaires
CREATE TABLE `commentaire` (`id` INT NOT NULL AUTO_INCREMENT , `societe_id` INT NOT NULL , `projet_id` INT NULL , `tache_id` INT NULL , `ticket_id` INT NULL , `user_id` INT NOT NULL , `contenu` TEXT NOT NULL , `created_at` DATETIME NOT NULL , `deleted` TINYINT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `commentaire` ADD `idtoken` VARCHAR(255) NULL AFTER `id`;
ALTER TABLE `commentaire` ADD `titre` VARCHAR(255) NULL AFTER `user_id`;
ALTER TABLE `produit` CHANGE `description` `description` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `ligne_devis` CHANGE `description` `description` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;
ALTER TABLE `devis` ADD `date_envoi` DATE NULL AFTER `date_validitee`, ADD `date_relance1` DATE NULL AFTER `date_envoi`, ADD `date_relance2` DATE NULL AFTER `date_relance1`, ADD `date_relance3` DATE NULL AFTER `date_relance2`;

CREATE TABLE `banque_enseigne` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `nom` VARCHAR(255) NOT NULL , `logo` VARCHAR(255) NOT NULL , `logo_crop` VARCHAR(255) NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE `banque` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `nom` VARCHAR(255) NOT NULL , `adresse` VARCHAR(255) NOT NULL , `code_postal` INT NOT NULL , `ville` VARCHAR(255) NOT NULL , `iban` VARCHAR(255) NOT NULL , `bic` VARCHAR(255) NOT NULL , `enseigne_id` INT NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`idtoken`)) ENGINE = InnoDB;
ALTER TABLE `banque` CHANGE `adresse` `adresse` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL, CHANGE `code_postal` `code_postal` INT NULL, CHANGE `ville` `ville` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL, CHANGE `iban` `iban` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL, CHANGE `bic` `bic` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL;
ALTER TABLE `banque_enseigne` CHANGE `logo` `logo` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL, CHANGE `logo_crop` `logo_crop` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL;
ALTER TABLE `client` ADD `banque_id` INT NULL AFTER `societe_id`;

023 - Comptabilité
CREATE TABLE `releve_bancaire` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `mois` INT NOT NULL , `annee` INT NOT NULL , `document` VARCHAR(255) NOT NULL , `created_by_id` INT NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `releve_bancaire` ADD `banque_id` INT NOT NULL AFTER `societe_id`;
ALTER TABLE `releve_bancaire` ADD `created_at` DATETIME NOT NULL AFTER `created_by_id`;

CREATE TABLE `export_comptable` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `mois` INT NOT NULL , `annee` INT NOT NULL , `fichier` VARCHAR(255) NOT NULL , `created_by_id` INT NOT NULL , `created_at` DATETIME NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `export_comptable` CHANGE `fichier` `fichier` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL;
CREATE TABLE `capsule`.`ecriture_comptable` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `montant` FLOAT NOT NULL , `paiement_id` INT NULL , `depense_id` INT NULL , `date` DATE NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `ecriture_comptable` ADD `titre` VARCHAR(255) NOT NULL AFTER `societe_id`;
CREATE TABLE `capsule`.`ecriture_bancaire` (`id` INT NOT NULL AUTO_INCREMENT , `idtoken` VARCHAR(255) NOT NULL , `societe_id` INT NOT NULL , `banque_id` INT NOT NULL , `date` DATE NOT NULL , `titre` VARCHAR(255) NOT NULL , `montant` FLOAT NOT NULL , `type` VARCHAR(255) NOT NULL , `created_at` DATETIME NOT NULL , `deleted` TINYINT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `facture` ADD `type_acompte` VARCHAR(255) NULL AFTER `deleted`;

###
