-- http://www.phpmyadmin.net
--




--
-- Database: `payrollnew`
--

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

--
-- Table structure for table `attendence`
--

CREATE TABLE `attendence` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `company_id` int(10) UNSIGNED NOT NULL,
  `work_date` date NOT NULL,
  `time_in` time NOT NULL,
  `time_out` time NOT NULL,
  `overtime_in` time NOT NULL,
  `overtime_out` time NOT NULL,
  `shift` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `scheduled` tinyint(1) NOT NULL,
  `attendence` tinyint(4) NOT NULL DEFAULT '0',
  `time_sheet_by_company` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `companies`
--

CREATE TABLE `companies` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `shifts` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `workers_ordered` int(11) NOT NULL,
  `overtime` tinyint(4) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `companies`
--

INSERT INTO `companies` (`id`, `name`, `email`, `shifts`, `workers_ordered`, `overtime`, `created_at`, `updated_at`) VALUES
(2, 'ABC Pvt. Ltd.', 'abc@abc.com', '', 0, 1, NULL, NULL),
(3, 'Demo Company Pvt. Ltd.', 'demo@demo.com', '', 0, 0, NULL, NULL),
(4, 'New test1', 'newtest1@test.com', '["day","night"]', 5, 1, '2017-05-17 03:53:04', '2017-05-17 21:36:06');

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

--
-- Table structure for table `expenses`
--

CREATE TABLE `expenses` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `expenses`
--

INSERT INTO `expenses` (`id`, `name`, `created_at`, `updated_at`) VALUES
(1, 'Deduction for Ride', NULL, NULL),
(2, 'Deduction Security & Others', NULL, NULL);

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

--
-- Table structure for table `migrations`
--

CREATE TABLE `migrations` (
  `id` int(10) UNSIGNED NOT NULL,
  `migration` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `batch` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `migrations`
--

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(1, '2014_10_12_000000_create_users_table', 1),
(2, '2014_10_12_100000_create_password_resets_table', 1),
(3, '2017_03_24_062312_entrust_setup_tables', 1),
(4, '2017_03_29_063724_create_companies_table', 1),
(5, '2017_03_29_094334_create_attendence_table', 1),
(6, '2017_04_22_040112_create_expenses_table', 1),
(7, '2017_04_25_074337_create_payroll_table', 1),
(8, '2017_04_26_063316_create_payroll_company_table', 1),
(9, '2017_04_26_063508_create_payroll_attendence_table', 1),
(10, '2017_04_26_064249_create_payroll_attendence_company_table', 1),
(11, '2017_05_04_050935_create_payroll_expenses_table', 1);

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

--
-- Table structure for table `payroll`
--

CREATE TABLE `payroll` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `regular_hours` decimal(3,2) NOT NULL DEFAULT '0.00',
  `total_hours_worked` decimal(3,2) NOT NULL DEFAULT '0.00',
  `overtime_hours` decimal(3,2) NOT NULL DEFAULT '0.00',
  `regular_wages` decimal(10,2) NOT NULL DEFAULT '0.00',
  `overtime_wages` decimal(10,2) NOT NULL DEFAULT '0.00',
  `gross_wages` decimal(10,2) NOT NULL DEFAULT '0.00',
  `net_payable_wages` decimal(10,2) NOT NULL DEFAULT '0.00',
  `payment_status` tinyint(4) NOT NULL DEFAULT '0',
  `payment_mode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `payment_by_cheque` decimal(10,2) NOT NULL DEFAULT '0.00',
  `payment_by_cash` decimal(10,2) NOT NULL DEFAULT '0.00',
  `deductions` text COLLATE utf8_unicode_ci,
  `other_expenses` text COLLATE utf8_unicode_ci,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `payroll_attendence`
--

CREATE TABLE `payroll_attendence` (
  `id` int(10) UNSIGNED NOT NULL,
  `payroll_id` int(10) UNSIGNED NOT NULL,
  `attendence_id` int(10) UNSIGNED NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `payroll_attendence_company`
--

CREATE TABLE `payroll_attendence_company` (
  `id` int(10) UNSIGNED NOT NULL,
  `payroll_id` int(10) UNSIGNED NOT NULL,
  `attendence_id` int(10) UNSIGNED NOT NULL,
  `company_id` int(10) UNSIGNED NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `payroll_company`
--

CREATE TABLE `payroll_company` (
  `id` int(10) UNSIGNED NOT NULL,
  `payroll_id` int(10) UNSIGNED NOT NULL,
  `company_id` int(10) UNSIGNED NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `payroll_expenses`
--

CREATE TABLE `payroll_expenses` (
  `id` int(10) UNSIGNED NOT NULL,
  `payroll_id` int(10) UNSIGNED NOT NULL,
  `meta_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `meta_value` decimal(10,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Table structure for table `permissions`
--

CREATE TABLE `permissions` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `display_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `permissions`
--

INSERT INTO `permissions` (`id`, `name`, `display_name`, `description`, `created_at`, `updated_at`) VALUES
(1, 'user-view', 'View User List', NULL, NULL, NULL),
(2, 'user-create', 'Create New User', NULL, NULL, NULL),
(3, 'user-edit', 'Edit User', NULL, NULL, NULL),
(4, 'user-delete', 'Delete User', NULL, NULL, NULL),
(5, 'permission-view', 'View Permissions', NULL, NULL, NULL),
(6, 'permission-create', 'Create New Permission', NULL, NULL, NULL),
(7, 'permission-edit', 'Edit Permission', NULL, NULL, NULL),
(8, 'permission-delete', 'Delete Permission', NULL, NULL, NULL),
(9, 'role-view', 'View Roles', NULL, NULL, NULL),
(10, 'role-create', 'Create New Role', NULL, NULL, NULL),
(11, 'role-edit', 'Edit Role', NULL, NULL, NULL),
(12, 'role-delete', 'Delete Role', NULL, NULL, NULL),
(13, 'company-view', 'View Companies', NULL, '2017-03-29 03:23:25', '2017-03-29 03:23:25'),
(14, 'company-create', 'Create New Company', NULL, '2017-03-29 03:23:41', '2017-03-29 03:23:41'),
(15, 'company-edit', 'Edit Company', NULL, '2017-03-29 03:23:56', '2017-03-29 03:23:56'),
(16, 'company-delete', 'Delete Company', NULL, '2017-03-29 03:24:22', '2017-03-29 03:24:22'),
(17, 'attendence-view', 'View Attendences', NULL, '2017-03-29 03:24:46', '2017-03-29 03:24:46'),
(18, 'attendence-create', 'Add New Attendence', NULL, '2017-03-29 03:25:07', '2017-03-29 03:25:07'),
(19, 'attendence-edit', 'Update Attendence', NULL, '2017-03-29 03:25:26', '2017-03-29 03:25:26'),
(20, 'attendence-delete', 'Delete Attendence', NULL, '2017-03-29 03:25:47', '2017-03-29 03:25:47'),
(21, 'worker-view', 'View Workers List', NULL, '2017-04-05 19:14:33', '2017-04-05 19:14:33'),
(22, 'worker-create', 'Create New Worker', NULL, '2017-04-05 19:14:49', '2017-04-05 19:14:49'),
(23, 'worker-edit', 'Edit Worker', NULL, '2017-04-05 19:15:06', '2017-04-05 19:15:06'),
(24, 'worker-delete', 'Delete Worker', NULL, '2017-04-05 19:15:22', '2017-04-05 19:15:22'),
(25, 'payroll-view', 'View Payroll List', NULL, '2017-04-12 21:33:48', '2017-04-12 21:33:48'),
(26, 'payroll-create', 'Create Payroll', NULL, '2017-04-12 21:34:03', '2017-04-12 21:34:03'),
(27, 'payroll-edit', 'Edit Payroll', NULL, '2017-04-12 21:34:19', '2017-04-12 21:34:19'),
(28, 'payroll-delete', 'Delete Payroll', NULL, '2017-04-12 21:34:34', '2017-04-12 21:34:34'),
(29, 'expense-view', 'View Expenses List', NULL, '2017-04-21 17:17:52', '2017-04-21 17:17:52'),
(30, 'expense-create', 'Create New Expense', NULL, '2017-04-21 17:18:07', '2017-04-21 17:18:07'),
(31, 'expense-edit', 'Update Expense', NULL, '2017-04-21 17:18:22', '2017-04-21 17:18:22'),
(32, 'expense-delete', 'Delete Expense', NULL, '2017-04-21 17:18:37', '2017-04-21 17:18:37');

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

--
-- Table structure for table `permission_role`
--

CREATE TABLE `permission_role` (
  `permission_id` int(10) UNSIGNED NOT NULL,
  `role_id` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `permission_role`
--

INSERT INTO `permission_role` (`permission_id`, `role_id`) VALUES
(1, 1),
(2, 1),
(3, 1),
(4, 1),
(5, 1),
(6, 1),
(7, 1),
(8, 1),
(9, 1),
(10, 1),
(11, 1),
(12, 1),
(13, 1),
(14, 1),
(15, 1),
(16, 1),
(17, 1),
(18, 1),
(19, 1),
(20, 1),
(21, 1),
(22, 1),
(23, 1),
(24, 1),
(25, 1),
(26, 1),
(27, 1),
(28, 1),
(29, 1),
(30, 1),
(31, 1),
(32, 1);

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

--
-- Table structure for table `roles`
--

CREATE TABLE `roles` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `display_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `roles`
--

INSERT INTO `roles` (`id`, `name`, `display_name`, `description`, `created_at`, `updated_at`) VALUES
(1, 'admin', 'Admin', NULL, NULL, NULL),
(2, 'worker', 'Worker', NULL, NULL, '2017-04-03 20:33:22'),
(3, 'staff', 'Staff', NULL, '2017-05-15 03:46:37', '2017-05-15 03:46:37');

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

--
-- Table structure for table `role_user`
--

CREATE TABLE `role_user` (
  `user_id` int(10) UNSIGNED NOT NULL,
  `role_id` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `role_user`
--

INSERT INTO `role_user` (`user_id`, `role_id`) VALUES
(1, 1),
(13, 2),
(14, 3),
(15, 2),
(16, 2),
(17, 2),
(18, 2);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `attendence`
--
ALTER TABLE `attendence`
  ADD PRIMARY KEY (`id`),
  ADD KEY `attendence_user_id_index` (`user_id`),
  ADD KEY `attendence_company_id_index` (`company_id`);

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

--
-- Indexes for table `expenses`
--
ALTER TABLE `expenses`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `expenses_name_unique` (`name`);

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

--
-- Indexes for table `payroll`
--
ALTER TABLE `payroll`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payroll_user_id_index` (`user_id`);

--
-- Indexes for table `payroll_attendence`
--
ALTER TABLE `payroll_attendence`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payroll_attendence_payroll_id_foreign` (`payroll_id`),
  ADD KEY `payroll_attendence_attendence_id_foreign` (`attendence_id`);

--
-- Indexes for table `payroll_attendence_company`
--
ALTER TABLE `payroll_attendence_company`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payroll_attendence_company_payroll_id_foreign` (`payroll_id`),
  ADD KEY `payroll_attendence_company_attendence_id_foreign` (`attendence_id`),
  ADD KEY `payroll_attendence_company_company_id_foreign` (`company_id`);

--
-- Indexes for table `payroll_company`
--
ALTER TABLE `payroll_company`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payroll_company_payroll_id_foreign` (`payroll_id`),
  ADD KEY `payroll_company_company_id_foreign` (`company_id`);

--
-- Indexes for table `payroll_expenses`
--
ALTER TABLE `payroll_expenses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payroll_expenses_payroll_id_foreign` (`payroll_id`);

--
-- Indexes for table `permissions`
--
ALTER TABLE `permissions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `permissions_name_unique` (`name`);

--
-- Indexes for table `permission_role`
--
ALTER TABLE `permission_role`
  ADD PRIMARY KEY (`permission_id`,`role_id`),
  ADD KEY `permission_role_role_id_foreign` (`role_id`);

--
-- Indexes for table `roles`
--
ALTER TABLE `roles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `roles_name_unique` (`name`);

--
-- Indexes for table `role_user`
--
ALTER TABLE `role_user`
  ADD PRIMARY KEY (`user_id`,`role_id`),
  ADD KEY `role_user_role_id_foreign` (`role_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `attendence`
--
ALTER TABLE `attendence`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `companies`
--
ALTER TABLE `companies`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table `expenses`
--
ALTER TABLE `expenses`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `migrations`
--
ALTER TABLE `migrations`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
--
-- AUTO_INCREMENT for table `payroll`
--
ALTER TABLE `payroll`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `payroll_attendence`
--
ALTER TABLE `payroll_attendence`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `payroll_attendence_company`
--
ALTER TABLE `payroll_attendence_company`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `payroll_company`
--
ALTER TABLE `payroll_company`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `payroll_expenses`
--
ALTER TABLE `payroll_expenses`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `permissions`
--
ALTER TABLE `permissions`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33;
--
-- AUTO_INCREMENT for table `roles`
--
ALTER TABLE `roles`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- Constraints for dumped tables
--

--
-- Constraints for table `attendence`
--
ALTER TABLE `attendence`
  ADD CONSTRAINT `attendence_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `attendence_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payroll`
--
ALTER TABLE `payroll`
  ADD CONSTRAINT `payroll_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payroll_attendence`
--
ALTER TABLE `payroll_attendence`
  ADD CONSTRAINT `payroll_attendence_attendence_id_foreign` FOREIGN KEY (`attendence_id`) REFERENCES `attendence` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `payroll_attendence_payroll_id_foreign` FOREIGN KEY (`payroll_id`) REFERENCES `payroll` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payroll_attendence_company`
--
ALTER TABLE `payroll_attendence_company`
  ADD CONSTRAINT `payroll_attendence_company_attendence_id_foreign` FOREIGN KEY (`attendence_id`) REFERENCES `attendence` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `payroll_attendence_company_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `payroll_attendence_company_payroll_id_foreign` FOREIGN KEY (`payroll_id`) REFERENCES `payroll` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payroll_company`
--
ALTER TABLE `payroll_company`
  ADD CONSTRAINT `payroll_company_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `payroll_company_payroll_id_foreign` FOREIGN KEY (`payroll_id`) REFERENCES `payroll` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payroll_expenses`
--
ALTER TABLE `payroll_expenses`
  ADD CONSTRAINT `payroll_expenses_payroll_id_foreign` FOREIGN KEY (`payroll_id`) REFERENCES `payroll` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `permission_role`
--
ALTER TABLE `permission_role`
  ADD CONSTRAINT `permission_role_permission_id_foreign` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `permission_role_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `role_user`
--
ALTER TABLE `role_user`
  ADD CONSTRAINT `role_user_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `role_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

