ALTER TABLE T_JOUR_UEV MODIFY COLUMN DATE_USE DATE NOT NULL;

CREATE TABLE DRIVER_ERROR (
  ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  DRIVER_ID INTEGER(5) NOT NULL,
  ERROR_BEGIN DATE DEFAULT null,
  ERROR_END DATE DEFAULT null,
  TYPE INTEGER UNSIGNED NOT NULL DEFAULT 0,
  DETAIL VARCHAR(256) NOT NULL,
  PRINTED DATETIME NOT NULL,
  USER_ID INTEGER UNSIGNED NOT NULL DEFAULT 0,
  PROCESSED DATETIME,
  PRIMARY KEY (`ID`)
) ENGINE = InnoDB;

ALTER TABLE DRIVER_ERROR ADD FOREIGN KEY (DRIVER_ID) REFERENCES `t_conducteur`(CLE_CHAUFFEUR) ON DELETE CASCADE;

CREATE TABLE VEHICLE_ERROR (
  ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  VEHICLE_ID INTEGER(11) NOT NULL,
  ERROR_BEGIN DATE DEFAULT null,
  ERROR_END DATE DEFAULT null,
  TYPE INTEGER UNSIGNED NOT NULL DEFAULT 0,
  DETAIL VARCHAR(256) NOT NULL,
  PRINTED DATETIME NOT NULL,
  USER_ID INTEGER UNSIGNED NOT NULL DEFAULT 0,
  VEHICLE_FILE_ID INTEGER UNSIGNED NOT NULL DEFAULT 0,
  PROCESSED DATETIME,
  PRIMARY KEY (`ID`)
) ENGINE = InnoDB;

ALTER TABLE VEHICLE_ERROR ADD FOREIGN KEY (VEHICLE_ID) REFERENCES `t_vehicule`(CLE_VEHICULE) ON DELETE CASCADE;

CREATE TABLE EXPENSE_AMOUNT (
  ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  EXPENSE_TYPE_ID INT(11) NOT NULL,
  ENACTED DATE NOT NULL,
  FRENCH_AMOUNT FLOAT NOT NULL,
  FOREIGN_AMOUNT FLOAT NOT NULL,
  PRIMARY KEY (ID)
) ENGINE = InnoDB;
ALTER TABLE EXPENSE_AMOUNT ADD FOREIGN KEY (EXPENSE_TYPE_ID) REFERENCES `t_frais`(CLE) ON DELETE CASCADE;

CREATE TABLE GNSS_PLACE (
  ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  DRIVER_ID INT(11) NOT NULL,
  POINT_TIME DATE NOT NULL,
  TYPE TINYINT NOT NULL,
  ACCURACY TINYINT NOT NULL,
  COORDINATE VARCHAR(6) NOT NULL,
  ODOMETER_VALUE INTEGER(7),
  PRIMARY KEY (ID)
) ENGINE = InnoDB;
ALTER TABLE GNSS_PLACE ADD FOREIGN KEY (DRIVER_ID) REFERENCES `t_conducteur`(CLE_CHAUFFEUR) ON DELETE CASCADE;

INSERT INTO EXPENSE_AMOUNT (EXPENSE_TYPE_ID, ENACTED, FOREIGN_AMOUNT, FRENCH_AMOUNT) select cle, "2010-01-01", MONTANT_ETRANGER, MONTANT_FRANCE from t_frais;