CREATE TABLE `compte_pv` (`id` INT NOT NULL AUTO_INCREMENT , `du` DATETIME NOT NULL , `au` DATETIME NULL DEFAULT NULL , `id_creation` INT NOT NULL , `date_creation` DATETIME NOT NULL , `id_cloture` INT NULL DEFAULT NULL , `date_cloture` DATETIME NULL DEFAULT NULL , `id_pv` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

CREATE TABLE `compte_pv_base` (`id` INT NOT NULL AUTO_INCREMENT , `nom` VARCHAR(255) NOT NULL , `id_creation` INT NOT NULL , `date_creation` DATETIME NOT NULL , PRIMARY KEY (`id`), UNIQUE (`nom`)) ENGINE = InnoDB;

CREATE TABLE `compte_pv_base_stock` (`id` INT NOT NULL AUTO_INCREMENT , `id_pv` INT NOT NULL , `id_stock` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

CREATE TABLE `compte_pv_ticket` (`id` INT NOT NULL AUTO_INCREMENT , `date_ticket` INT NOT NULL , `id_matricule` INT NOT NULL , `id_creation` INT NOT NULL , `date_creation` DATETIME NOT NULL , `id_cloture` INT NULL DEFAULT NULL , `date_cloture` DATETIME NULL DEFAULT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

CREATE TABLE `compte_pv_ticket_description` (`id` INT NOT NULL AUTO_INCREMENT , `id_ticket` INT NOT NULL , `id_produit` INT NOT NULL , `qte` DECIMAL(20,6) NOT NULL , `prix` DECIMAL(20,6) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

ALTER TABLE `compte_pv_base` ADD `id_caisse` INT NOT NULL AFTER `date_creation`;
ALTER TABLE `compte_pv_ticket` CHANGE `id_matricule` `matricule` VARCHAR(255) NOT NULL;
ALTER TABLE `compte_pv_ticket` CHANGE `date_ticket` `date_ticket` DATETIME NOT NULL;
ALTER TABLE `compte_pv_ticket` ADD `note` VARCHAR(255) NOT NULL AFTER `date_cloture`;
ALTER TABLE `compte_pv_ticket` ADD `id_compte` INT NOT NULL AFTER `numero`;
CREATE TABLE `compte_pv_employe` (`id` INT NOT NULL AUTO_INCREMENT , `id_employe` INT NOT NULL , `id_pv` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `compte_pv_ticket` ADD `id_employe` INT NOT NULL AFTER `id_compte`;
ALTER TABLE `compte_pv_employe` CHANGE `id_pv` `id_compte` INT(11) NOT NULL;
ALTER TABLE `compte_pv_ticket` CHANGE `id_matricule` `id_matricule` INT(22) NOT NULL;
ALTER TABLE `compte_pv_ticket` ADD `date_debut` DATETIME NULL DEFAULT NULL AFTER `id_employe`, ADD `date_fin` DATETIME NULL DEFAULT NULL AFTER `date_debut`;
