Dec 11, 2020
0
Level 1
view date range data
Hello
I'm building attendance system in Laravel and I have a issue,
I need to view data for a employees with date range i have two database one for employees and another for the attendance
create table employees
(
id bigint unsigned auto_increment
primary key,
emp_id bigint not null,
emp_name varchar(255) not null,
emp_name_fp varchar(255) not null,
emp_section int not null,
emp_schedule int not null,
emp_email varchar(255) not null,
emp_fp longtext not null,
emp_password text not null,
emp_permission int not null,
created_at timestamp null,
updated_at timestamp null
)
collate=utf8mb4_unicode_ci;
+--+------+--------------+------------+-----------+------------+------------------+------------------------------------------------
|id|emp_id|emp_name |emp_name_fp |emp_section|emp_schedule|emp_email |emp_fp |emp_password|emp_permission|
+--+------+--------------+------------+-----------+------------+------------------+------------------------------------------------
|1 |343 |em1 |em1 |1 |1 |[email protected] |y$rtARLeRMab |123123 |0 |
|2 |231 |em2 |em2 |2 |1 |[email protected] |y$F4Kb1bpxAFZ |123123 |0 |
|3 |541 |em3 |em3 |3 |1 |[email protected] |y$adoGPH1SX |123123 |0 |
+--+------+--------------+------------+-----------+------------+------------------+------------------------------------------------
and the record for attendance is
create table devices_records
(
id bigint unsigned auto_increment
primary key,
rec_emp_id int not null,
rec_time varchar(255) not null,
rec_date varchar(255) not null,
rec_dev_id varchar(255) not null,
created_at timestamp null,
updated_at timestamp null
)
collate=utf8mb4_unicode_ci;
+--+----------+--------+----------+----------+-------------------+-------------------+------------------------------+
|id|rec_emp_id|rec_time|rec_date |rec_dev_id|created_at |updated_at |
+--+----------+--------+----------+----------+-------------------+-------------------+------------------------------+
|1 |343 |08:23:20|2020-12-11|15 |2020-12-10 23:57:22|2020-12-10 23:57:22|
|2 |343 |12:40:00|2020-12-11|17 |2020-12-10 23:57:22|2020-12-10 23:57:22|
|3 |343 |15:40:00|2020-12-11|18 |2020-12-10 23:57:22|2020-12-10 23:57:22|
|4 |343 |08:00:00|2020-12-10|15 |2020-12-11 15:10:59|2020-12-11 15:10:59|
|5 |343 |12:10:00|2020-12-10|15 |2020-12-11 15:11:12|2020-12-11 15:11:12|
|6 |343 |15:18:00|2020-12-10|18 |2020-12-11 15:11:23|2020-12-11 15:11:23|
+--+----------+--------+----------+----------+-------------------+-------------------+------------------------------+
I'm using datatable to view the records for database but i need to make a date range to view data
like example to select data 2020-11-01 to 2020-11-20
to get all employee who has record or not and view them
my code is
function getrec($date)
{
$result = self::with(['records' => function ($q) use ($date) {
/**
* @var Builder $q
*/
$q->select('rec_emp_id', 'rec_time', 'rec_date', 'rec_dev_id');
$q->whereBetween('rec_date', ['2020-12-10', '2020-12-11']);
// $q->where('rec_date', 'like','2020-12-11');
$q->orderBy('rec_time');
}])->select(['emp_id', 'emp_name'])->get()->map(function ($it) use ($date) {
$it->date = $date;
$size = sizeof($it->records);
//$it->dev_in = "";
//$it->dev_mid = "";
//$it->dev_out = "";
$it->in = "";
$it->mid = "";
$it->out = "";
switch ($size) {
case "3":
//$it->dev_in = $it->records[0]['dev']['dev_title'];
//$it->dev_mid = $it->records[1]['dev']['dev_title'];
//$it->dev_out = $it->records[2]['dev']['dev_title'];
$it->in = $it->records[0]['rec_time'];
$it->mid = $it->records[1]['rec_time'];
$it->out = $it->records[2]['rec_time'];
break;
case "2":
//$it->dev_in = $it->records[0]['dev']['dev_title'];
//$it->dev_mid = $it->records[1]['dev']['dev_title'];
$it->in = $it->records[0]['rec_time'];
$it->mid = $it->records[1]['rec_time'];
break;
case "1":
$it->dev_in = $it->records[0]['dev']['dev_title'];
$it->in = $it->records[0]['rec_time'];
break;
}
// unset($it->records);
return $it;
});
return $result;
}
function records()
{
return self::hasMany(DevicesRecordsModel::class, "rec_emp_id", "emp_id")->with("dev");
}
there is two modal for employees and for records
Please or to participate in this conversation.