-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `getsmart_california`
--

-- --------------------------------------------------------

--
-- Table structure for table `clients`
--

CREATE TABLE `clients` (
  `id` int(11) NOT NULL,
  `client` varchar(155) NOT NULL,
  `active` tinyint(4) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `conditions`
--

CREATE TABLE `conditions` (
  `id` int(11) NOT NULL,
  `description` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `conditions`
--

INSERT INTO `conditions` (`id`, `description`, `created_at`, `updated_at`) VALUES
(1, 'Sin daño', '2021-01-26 21:58:55', '2021-01-26 21:58:55'),
(2, 'Dañado', '2021-01-26 21:58:55', '2021-01-26 21:58:55');

-- --------------------------------------------------------

--
-- Table structure for table `containers`
--

CREATE TABLE `containers` (
  `id` int(11) NOT NULL,
  `number` varchar(100) NOT NULL,
  `name` varchar(155) NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `container_movements`
--

CREATE TABLE `container_movements` (
  `id` int(11) NOT NULL,
  `id_container` int(11) NOT NULL,
  `id_container_movement_type` int(11) NOT NULL,
  `id_location` int(11) NOT NULL,
  `id_driver` int(11) NOT NULL,
  `id_type_material` int(11) DEFAULT NULL,
  `reference` varchar(100) DEFAULT NULL,
  `condition_description` varchar(155) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `container_movement_images`
--

CREATE TABLE `container_movement_images` (
  `id` int(11) NOT NULL,
  `id_container_movement` int(11) NOT NULL,
  `image` text NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `container_movement_parts_condition`
--

CREATE TABLE `container_movement_parts_condition` (
  `id` int(11) NOT NULL,
  `id_container_movement` int(11) NOT NULL,
  `id_part` int(11) NOT NULL,
  `id_condition` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `container_movement_repairs`
--

CREATE TABLE `container_movement_repairs` (
  `id` int(11) NOT NULL,
  `id_container_movement` int(11) NOT NULL,
  `id_container_part_inventory` int(11) NOT NULL,
  `requested` int(11) NOT NULL COMMENT 'Cantidad de piezas necesarias',
  `availables` int(11) NOT NULL COMMENT 'Piezas usadas',
  `cost` decimal(10,2) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `container_movement_type`
--

CREATE TABLE `container_movement_type` (
  `id` int(11) NOT NULL,
  `movement_type` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `container_movement_type`
--

INSERT INTO `container_movement_type` (`id`, `movement_type`) VALUES
(1, 'Entrada'),
(2, 'Salida');

-- --------------------------------------------------------

--
-- Table structure for table `container_parts`
--

CREATE TABLE `container_parts` (
  `id` int(11) NOT NULL,
  `part` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `container_parts`
--

INSERT INTO `container_parts` (`id`, `part`, `created_at`, `updated_at`) VALUES
(1, 'Rodillos', '2021-01-26 21:56:02', '2021-01-26 21:56:02'),
(2, 'Puertas', '2021-01-26 21:56:02', '2021-01-26 21:56:02'),
(3, 'Paredes', '2021-01-26 21:56:02', '2021-01-26 21:56:02'),
(4, 'Tapa', '2021-01-26 21:56:02', '2021-01-26 21:56:02'),
(5, 'Piso', '2021-01-26 21:56:02', '2021-01-26 21:56:02');

-- --------------------------------------------------------

--
-- Table structure for table `container_parts_inventory`
--

CREATE TABLE `container_parts_inventory` (
  `id` int(11) NOT NULL,
  `piece` varchar(50) NOT NULL,
  `number` int(11) NOT NULL,
  `stock` int(11) NOT NULL,
  `warning` int(11) NOT NULL DEFAULT '0',
  `cost` decimal(10,2) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `dashboard_roles`
--

CREATE TABLE `dashboard_roles` (
  `id` int(11) NOT NULL,
  `role` varchar(15) NOT NULL,
  `description` text,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `dashboard_roles`
--

INSERT INTO `dashboard_roles` (`id`, `role`, `description`, `status`, `created_at`, `updated_at`) VALUES
(1, 'Administrador', 'Administrador', 1, '2020-12-17 23:38:01', '2021-02-03 23:04:42'),
(2, 'Editor', 'Editor', 1, '2020-12-17 23:38:01', '2020-12-17 23:38:01'),
(3, 'Capturista', 'Capturista', 1, '2020-12-17 23:38:01', '2021-02-03 22:54:31'),
(4, 'Developer', 'Developer', 1, '2020-12-17 23:38:01', '2020-12-22 20:08:21');

-- --------------------------------------------------------

--
-- Table structure for table `drivers`
--

CREATE TABLE `drivers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `lastname` varchar(100) NOT NULL,
  `employee_number` varchar(50) NOT NULL,
  `licence` varchar(50) NOT NULL,
  `active` tinyint(4) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `drivers`
--

INSERT INTO `drivers` (`id`, `name`, `lastname`, `employee_number`, `licence`, `active`, `created_at`, `updated_at`) VALUES
(2, 'Chofer', 'Administracion', '000', '--', 1, '2021-02-04 20:24:20', '2021-02-04 20:24:20');

-- --------------------------------------------------------

--
-- Table structure for table `locations`
--

CREATE TABLE `locations` (
  `id` int(11) NOT NULL,
  `id_client` int(11) NOT NULL,
  `location` text NOT NULL,
  `phone` varchar(15) NOT NULL,
  `lat` varchar(50) NOT NULL,
  `lng` varchar(50) NOT NULL,
  `address` text NOT NULL,
  `state` varchar(100) NOT NULL,
  `city` varchar(100) NOT NULL,
  `id_location_type` int(11) NOT NULL,
  `active` tinyint(4) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `location_types`
--

CREATE TABLE `location_types` (
  `id` int(11) NOT NULL,
  `type` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `location_types`
--

INSERT INTO `location_types` (`id`, `type`, `created_at`, `updated_at`) VALUES
(1, 'Servicio', '2021-01-19 00:06:39', '2021-01-19 00:06:39'),
(2, 'Almancen', '2021-01-19 00:06:39', '2021-01-19 00:06:39');

-- --------------------------------------------------------

--
-- Table structure for table `type_material`
--

CREATE TABLE `type_material` (
  `id` int(11) NOT NULL,
  `description` varchar(100) NOT NULL,
  `active` int(11) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `type_material`
--

INSERT INTO `type_material` (`id`, `description`, `active`, `created_at`, `updated_at`) VALUES
(1, 'Mixto', 1, '2021-03-12 01:02:22', '2021-03-12 01:02:22'),
(2, 'Metal', 1, '2021-03-12 01:02:28', '2021-03-12 01:02:28');

-- --------------------------------------------------------

--
-- Table structure for table `user_movements_log`
--

CREATE TABLE `user_movements_log` (
  `id` int(11) NOT NULL,
  `id_user` int(11) NOT NULL,
  `description` varchar(155) NOT NULL,
  `module` varchar(50) NOT NULL,
  `id_entity` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `clients`
--
ALTER TABLE `clients`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `conditions`
--
ALTER TABLE `conditions`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `containers`
--
ALTER TABLE `containers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `number` (`number`);

--
-- Indexes for table `container_movements`
--
ALTER TABLE `container_movements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_container` (`id_container`),
  ADD KEY `id_container_movement_type` (`id_container_movement_type`),
  ADD KEY `id_location` (`id_location`),
  ADD KEY `id_driver` (`id_driver`),
  ADD KEY `id_type_material` (`id_type_material`);

--
-- Indexes for table `container_movement_images`
--
ALTER TABLE `container_movement_images`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_container_movement` (`id_container_movement`);

--
-- Indexes for table `container_movement_parts_condition`
--
ALTER TABLE `container_movement_parts_condition`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_container_piece` (`id_part`),
  ADD KEY `id_container_movement` (`id_container_movement`),
  ADD KEY `id_condition` (`id_condition`);

--
-- Indexes for table `container_movement_repairs`
--
ALTER TABLE `container_movement_repairs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_container_movement` (`id_container_movement`),
  ADD KEY `id_container_part_inventory` (`id_container_part_inventory`);

--
-- Indexes for table `container_movement_type`
--
ALTER TABLE `container_movement_type`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `container_parts`
--
ALTER TABLE `container_parts`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `container_parts_inventory`
--
ALTER TABLE `container_parts_inventory`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `dashboard_roles`
--
ALTER TABLE `dashboard_roles`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `drivers`
--
ALTER TABLE `drivers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `employee_number` (`employee_number`),
  ADD UNIQUE KEY `licence` (`licence`);

--
-- Indexes for table `locations`
--
ALTER TABLE `locations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_location_type` (`id_location_type`),
  ADD KEY `id_client` (`id_client`);

--
-- Indexes for table `location_types`
--
ALTER TABLE `location_types`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `type_material`
--
ALTER TABLE `type_material`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `user_movements_log`
--
ALTER TABLE `user_movements_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_user` (`id_user`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `clients`
--
ALTER TABLE `clients`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `conditions`
--
ALTER TABLE `conditions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `containers`
--
ALTER TABLE `containers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `container_movements`
--
ALTER TABLE `container_movements`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `container_movement_images`
--
ALTER TABLE `container_movement_images`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `container_movement_parts_condition`
--
ALTER TABLE `container_movement_parts_condition`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `container_movement_repairs`
--
ALTER TABLE `container_movement_repairs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `container_movement_type`
--
ALTER TABLE `container_movement_type`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `container_parts`
--
ALTER TABLE `container_parts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `container_parts_inventory`
--
ALTER TABLE `container_parts_inventory`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `dashboard_roles`
--
ALTER TABLE `dashboard_roles`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `drivers`
--
ALTER TABLE `drivers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `locations`
--
ALTER TABLE `locations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `location_types`
--
ALTER TABLE `location_types`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `type_material`
--
ALTER TABLE `type_material`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `user_movements_log`
--
ALTER TABLE `user_movements_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `container_movements`
--
ALTER TABLE `container_movements`
  ADD CONSTRAINT `container_movements_ibfk_1` FOREIGN KEY (`id_container_movement_type`) REFERENCES `container_movement_type` (`id`),
  ADD CONSTRAINT `container_movements_ibfk_2` FOREIGN KEY (`id_driver`) REFERENCES `drivers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movements_ibfk_3` FOREIGN KEY (`id_container`) REFERENCES `containers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movements_ibfk_4` FOREIGN KEY (`id_location`) REFERENCES `locations` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movements_ibfk_5` FOREIGN KEY (`id_type_material`) REFERENCES `type_material` (`id`);

--
-- Constraints for table `container_movement_images`
--
ALTER TABLE `container_movement_images`
  ADD CONSTRAINT `container_movement_images_ibfk_1` FOREIGN KEY (`id_container_movement`) REFERENCES `container_movements` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `container_movement_parts_condition`
--
ALTER TABLE `container_movement_parts_condition`
  ADD CONSTRAINT `container_movement_parts_condition_ibfk_1` FOREIGN KEY (`id_container_movement`) REFERENCES `container_movements` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movement_parts_condition_ibfk_2` FOREIGN KEY (`id_part`) REFERENCES `container_parts` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movement_parts_condition_ibfk_3` FOREIGN KEY (`id_condition`) REFERENCES `conditions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `container_movement_repairs`
--
ALTER TABLE `container_movement_repairs`
  ADD CONSTRAINT `container_movement_repairs_ibfk_1` FOREIGN KEY (`id_container_part_inventory`) REFERENCES `container_parts_inventory` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `container_movement_repairs_ibfk_2` FOREIGN KEY (`id_container_movement`) REFERENCES `container_movements` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `locations`
--
ALTER TABLE `locations`
  ADD CONSTRAINT `locations_ibfk_1` FOREIGN KEY (`id_location_type`) REFERENCES `location_types` (`id`),
  ADD CONSTRAINT `locations_ibfk_2` FOREIGN KEY (`id_client`) REFERENCES `clients` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `user_movements_log`
--
ALTER TABLE `user_movements_log`
  ADD CONSTRAINT `user_movements_log_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `dashboard_users` (`id`) ON DELETE CASCADE;
COMMIT;

