I want to create export file date-range report using ci.
views.php
<div class="form-group row">
<label for="attn_date" class="col-sm-4 col-form-label">From</label>
<div class="col-sm-8">
<input type="date" class="form-control" id="attn_from" name="attn_from">
<?= form_error('attn_from'); ?>
</div>
</div>
<div class="form-group row">
<label for="attn_date" class="col-sm-4 col-form-label">To</label>
<div class="col-sm-8">
<input type="date" class="form-control" id="attn_to" name="attn_to">
<?= form_error('attn_to'); ?>
</div>
</div>
<div class="form-group row">
<label for="daily_export_file" class="col-sm-4 col-form-label">Export Data</label>
<div class="col-sm-8">
<?= form_dropdown('export_file', ['report' => 'Report'], set_value('export_file'), 'class="form-control" id="export_file"'); ?>
<?= form_error('export_file'); ?>
</div>
</div>
controller.php
$querydata = $this->db->query("select a.*, b.* from db_attn a
LEFT JOIN tbl_wrkhour b
ON b.id_wrkhour = a.wrk_hour WHERE attn_date between '". $this->input->post('attn_from')."'
AND '". $this->input->post('attn_to')."'order by attn_date desc")->result();
$spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet_name = $spreadsheet->getActiveSheet()->setTitle("Attendance Report");
$sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow();
$highestColumm = $sheet->getHighestColumn();
$dataattn = $querydata;
$sheet->setCellValue('A5', 'No');
$sheet->setCellValue('B5', 'Employee Name');
$sheet->setCellValue('C5', 'Date');
$sheet->setCellValue('D5', 'Detail');
$no = 1;
$rowx = 6;
foreach ($dataattn as $rowattn) {
$sheet->setCellValue('A' . $rowx, $no++);
$sheet->setCellValue('B' . $rowx, $rowattn->emp_name);
$sheet->setCellValue('C' . $rowx, $rowattn->date);
$sheet->setCellValue('D' . $rowx, $rowattn->attn_detail);
}
I've successfully show date range of all employee details. How to transpose the detail of each date?
current view in my export excel file:
No
Employee Name
Date
Detail
1
aaaa
03-01-2023
Present
2
bbbb
03-01-2023
leave
3
cccc
03-01-2023
late
4
aaaa
04-01-2023
Present
5
bbbb
04-01-2023
Present
6
cccc
04-01-2023
Present
expected change:
No
Employee Name
03-01-2023
04-01-2023
next column date range
1
aaaa
Present
Present
next
2
bbbb
leave
Present
next
3
cccc
late
Present
next
Any idea? Please help...
You can probably get that from SQL directly
select
no,
emp_name,
case
when exists (select user was present on time on 03-01-2023) then 'Present'
when exists (select user was present late on 03-01-2023) then 'Late'
else 'Absent'
end as '03-01-2023',
....
create a helper array, fill it in foreach function with rules and colums, then set this array to $dataattn.
Related
I have an exists data on database
NewMWU :
id
data1
data2
data3
measurementu
department_id
done_dep
1
10
10
10
measurement1
empty
default: 0
then I pass this data to some Departments Ids.
Controller :
public function storeTS(Request $request)
{
foreach( (array) $request->dep_ids as $dep_id ){
$data = new NewMWU;
$data->measurementu = $request->measurementu;
$data->department_id = $dep_id;
$data->done_dep = 2;
$data->save();
}
Session::flash('success');
return redirect()->route('newMW.index');
After I passed data that will be like this on database at same table :
NewMWU :
id
data1
data2
data3
measurementu
department_id
done_dep
1
10
10
10
measurement1
empty
default: 0
2
empty
empty
empty
measurement1
1
2
3
empty
empty
empty
measurement1
2
2
4
empty
empty
empty
measurement1
3
2
how can I copy data1,data2,data3 to a new columns that created with ids = 2,3,4 from column id = 1.
Blade page :
<form class="m-form m-form--fit" action="{{route('admin.newMW.storeTS')}}" method="POST">
{{ csrf_field() }}
<div id="divt" class="form-group m-form__group">
<div class="row">
<div class="col-sm-6">
<select class="form-control m-input" name="measurementu" required>
<option value="">chose measurement</option>
#foreach ($measurement as $s)
<option value="{{$s->measurementu}}">{{$s->measurementu}}</option>
#endforeach
</select>
</div>
</div>
</div>
<div id="divt" class="m-form__group">
<div class="row">
<div class="col-sm-3">
<select class="form-control m-input" name="dep_ids[]" multiple required>
#foreach ($mnue2 as $d)
<option value="{{$d->id}}">{{$d->name}}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions">
<button type="submit" class="btn btn-success">save</button>
</div>
</div>
</form>
I tried a lot of thinks like I add inputs in blade page for data1,2,3 but that is does not work.
Hope to help me how can I pass data1,2,3 in column 1 to a new columns with a requested data.
var html3 = '<div class="row" id="parent-autor"> <p id="auth-del"><i class="fa fa-minus-square" aria-hidden="true"></i></p> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" name="altautorprenume[]" placeholder="Prename"> </div> </div> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" name="altautornume[]" placeholder="Name"> </div> </div><div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" name="institutie[]" id="institutie" placeholder="Institutions"> </div> </div></div>';
$("#add_aut").click(function(e){
$('#auth-rows').append(html3);
});
$('#auth-rows').on('click', '#auth-del', function(E){
$(this).parent('div').remove();
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
<div class="add-plus"></div>
<div class="col-md-12">
<h5>Add more persons </h5>
<span class="btn btn-primary" id="add_aut" style="">Click here to add</span>
</div>
</div>
<div id="auth-rows"></div>
i have an formular which user can add more clients to invite at party when user click on Add a new row with 3 fields appear he can add how many he want,
these values dynamically i want to show on email, for example:
User fill all fields and add 3 more users where they have Name PreName Instituional,look what i did:
$personName= $_POST['personname'];
$personPrename= $_POST['personprename'];
$institution= $_POST['institution'];
$otherPersonName=" ";
$otherPersonPreName="";
$otherPersonInstitution= "";
foreach($personName as $product) {
$otherPersonPreName.= "$product";
}
foreach($personPrename as $products) {
$altiautoriNume .= "$products";
}
foreach($institution as $productss) {
$otherPersonInstitution.= "$productss";
}
EXAMPLE:
And in email content i want to display like this:
<hr>
John(first name of person added) Doe(first Prename of person added) Microsoft(first Institution of person added)
<hr>
Mike(second name of person added) Stuart(second Prename of person added) Facebook(second Institution of person added)
<hr>
I know i did something wrong.
I put even html to see truly what i want to do, i want to group Name Prename Institution per line
You can use array-map with null as first parameter to group the array and then use implode to concat the strings.
Consider the following:
$arr = array_map(null, $personName, $personPrename, $institution);
foreach($arr as $e)
echo implode(" ", $e) . PHP_EOL;
Live example: 3v4l
Hi I have a form to add members with their birth date. The input field for birth date is:
<div class="form-group">
<label for="data_nascita" class="col-sm-3 control-label">Birth Date</label>
<div class="col-sm-9">
<input name="data_nascita" type="date" class="form-control" id="data_nascita" placeholder="gg/mm/aaaa" />
</div>
</div>
Data are correctly uploaded to MYSQL and date format is
$data_nascita = ($_POST['data_nascita']);
var_dump($data_nascita); => string(10) "2003-04-15"
In the database is stored correctly, and it appears as
2018-12-14 18:50:48
I want to have the possibility to edit the information about the person (i.e. changing the birth date), and I created an edit file where all the database information is retrieved and appears in form fields that can be edited and updated in MYSQL.
Everything works fine except for dates, which appears as gg/mm/aaaa
The code I used for retrieving data is as usual:
<?php
$query = "SELECT data_nascita FROM volontari WHERE id_volontari = '$id'";
$res = $mysqli ->query($query);
$row = $res->fetch_array (MYSQLI_ASSOC);
$data_nascita = gira_data_db($row['data_nascita']);
function gira_data_db($data)
{
$array = explode( "-" , $data);
$array2 = array($array[2], $array[1], $array[0]);
$testo = implode( "/" , $array2);
return $testo;
}
?>
<div class="form-group">
<label for="data_nascita" class="col-sm-3 control-label">Birth Date</label>
<div class="col-sm-9">
<input name="data_nascita" type="date" class="form-control" id="data_nascita" value="<?php echo $data_nascita ?>" />
</div>
</div>
The date retrieved is
var_dump(gira_data_db($row['data_nascita']);) => string(10) "15/04/2003"
However in my form field the data appears as 00/00/0000. If I echo the date in an input field type=text, it appears correct.
Am I doing something wrong?
The problem is when you explode by '-' array[2] is '14 18:50:48' and it's not valid value for input with date type.
simply change gira_data_db function as follows:
function gira_data_db($data)
{
return date("YYYY-MM-DD", strtotime($data));
}
I hope it would help you
So here is my problem, I want to add to my database table an expiration date to a specific row trough HTML and PHP but I dont know what is wrong. For some reason it dont delete the specific row when the time runs out.
And is possible to add something to the database for example, on the php introduce the time to expire in a column?
I'm just starting with this PHP MySQLi interactions so the code will be probabily bad!
HTML:
<div class="modal fade" id="addModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">VIPS</h4>
</div>
<div class="modal-body">
<div class="container">
<form class="form-horizontal" action="insert.php" method="post" onsubmit="setTimeout('location.reload()', 10);">
<div class="form-group">
<label class="control-label col-sm-2" for="full name">SteamID</label>
<input class="form-control" type="text" id="identity" name="identity" placeholder="SteamID" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Name</label>
<input class="form-control" type="text" placeholder="Name" id="Name" name="name" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">immunity</label>
<input class="form-control" type="text" id="immunity" name="immunity" placeholder="Imunidade" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Time</label>
<select id="time" name="time" data-plugin-selectTwo class="form-control populate">
<optgroup label="Staff">
<option value="1">1 minute</option>
<option value="2">2 minute</option>
</optgroup>
</select>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Flags</label>
<select id="flags" name="flags" data-plugin-selectTwo class="form-control populate">
<optgroup label="Staff">
<option value="zo">Founder</option>
<option value="abcdefghjkp">Admin</option>
<option value="abcdfgjkq">Mod</option>
</optgroup>
</select>
<div class="modal-footer">
<button class="btn btn-primary" type="submit" value="ADICIONAR">Add</button>
<button class="btn btn-default" type="button" data-dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
PHP:
<?php
$conn = new mysqli("", "", "", "");
if ($conn->connect_error) {
die("Connection failed");
}
// Escape user inputs for security
$identity = mysqli_real_escape_string($conn, $_REQUEST['identity']);
$name = mysqli_real_escape_string($conn, $_REQUEST['name']);
$flags = mysqli_real_escape_string($conn, $_REQUEST['flags']);
$immunity = mysqli_real_escape_string($conn, $_REQUEST['immunity']);
$time=$_POST['time'];
$sql = "SELECT COUNT(*) FROM sm_admins WHERE identity = ('$identity')";
if($count = $conn->query($sql)){
if($count == 1){
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))
VALUES ('$identity', '$name', '$flags', '$immunity')";
if($conn->query($sql)){
echo "Good Connection";
}
}else{
echo "Identity already exist";
}
}
// close connection
header('Location: panel.php');
mysqli_close($conn);
?>
Your current query is:
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))
VALUES ('$identity', '$name', '$flags', '$immunity')";
it needs to be changed so that the database knows what you want. Since I don't have all the fieldnames for you sm_admin table I'll use f1,f2, f3 etc so you'll need to replace to the appropriate fieldname
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, f1, f2, f3, f4, f5 )
VALUES ('$identity', '$name', '$flags', '$immunity', '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))";
Edit:
Your original sql statement wouldn't work. The above correction will work but you'll need to change f1..f5 to your relevant fieldnames.
As for the automatic deletion of records you could use a cronjob or a mySQL event. Documentation can be found at https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html. Cronjob will depend upon your server.
Here is a skeleton mysql event schedule - read documentation for details.
DELIMITER $$
-- SET GLOBAL event_scheduler = ON$$ -- required for event to execute but not create
CREATE /*[DEFINER = { user | CURRENT_USER }]*/ EVENT `_u3a_work`.`xx`
ON SCHEDULE
/* uncomment the example below you want to use */
-- scheduleexample 1: run once
-- AT 'YYYY-MM-DD HH:MM.SS'/CURRENT_TIMESTAMP { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] }
-- scheduleexample 2: run at intervals forever after creation
-- EVERY 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...]
-- scheduleexample 3: specified start time, end time and interval for execution
/*EVERY 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...]
STARTS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1[HOUR|MONTH|WEEK|DAY|MINUTE|...] }
ENDS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] } */
/*[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE]
[COMMENT 'comment']*/
DO
BEGIN
(sql_statements)
END$$
DELIMITER ;
...delete the specific row when the time runs out.
You can't do this with MySQL. You'll have to come up with a solution using PHP. In this case cron jobs may come in handy.
How to create cron job using PHP?
A work around would be to add a column with DATETIME to your table. Set the default value to NOW(). So when you insert a record to the table inserted date and time will be saved in that column.
Then when you are retrieving data add a condition to the search query to filter information by expiration date and time
... WHERE `dateTime` > '2018-07-22 00:05:48'
I tried this code to output this (Correct Output)
But it gave me this which is wrong output
I need to distinct the name and group the item by brand but it did not happen in my query see the picture above.
$datefilter=mysqli_query($link,"select
SUM(INVOICE_ITEM_AMOUNT_MX) AS totalamount,
INVOICE_NO_MX,
INVOICE_CUSTOMER_NAME
,INVOICE_DATE_MX,ITEM_BRAND_MX
,GROUP_CONCAT(INVOICE_ITEM_CODE_MX SEPARATOR '<BR>') as itemcode
,GROUP_CONCAT(INVOICE_ITEM_QTY_MX SEPARATOR '<BR>') as quantity
,GROUP_CONCAT(INVOICE_ITEM_UPRICE_MX SEPARATOR '<BR>') as price
,GROUP_CONCAT(INVOICE_ITEM_SERIAL_MX SEPARATOR '<BR>') as serial
,GROUP_CONCAT( DISTINCT (INVOICE_SALES_REP_MX) SEPARATOR '<BR>') as salesrep
,GROUP_CONCAT(DISTINCT (ITEM_BRAND_MX) SEPARATOR '<BR>') as brand
from invoice where INVOICE_DATE_MX BETWEEN '" .$datefrom. "' AND '" . $dateto ."' and
BRANCH_CODE_MX='".$display_branchcode."' AND INVOICE_STATUS_MX='PAID' GROUP BY INVOICE_SALES_REP_MX,ITEM_BRAND_MX ");
$count=mysqli_num_rows($datefilter);
echo '<div class="col-xs-12">
<br>
<div class="col-xs-6">
<label> Total Invoice Number: </label> '.$count.'
</div>
<div class="col-xs-6">
<label> Date Range: </label> '.$convertedfrom.' - '.$convertedto.'
</div>
</div>';
while($daterow=mysqli_fetch_array($datefilter)){
$date=$daterow["INVOICE_DATE_MX"];
$customername=$daterow["INVOICE_CUSTOMER_NAME"];
$invoiceref=$daterow["INVOICE_NO_MX"];
$salesrep=$daterow["salesrep"];
$itemcode=$daterow["itemcode"];
$imeiserial=$daterow["serial"];
$totalnotformat=$daterow["totalamount"];
$upricenotformat=$daterow["price"];
$quantity=$daterow["quantity"];
$itembrand=$daterow["brand"];
$total=number_format($totalnotformat,2);
$uprice=number_format($upricenotformat,2);
echo'
<div class="col-xs-12">
<br>
<div class="panel panel-warning">
<div id="shade" class="panel-body"><label>'.$salesrep.'</label></div>
<div id="shade" class="panel-body">
<div class="col-xs-10">
<div class="col-xs-4">';
echo '
<label>Brand</label>: '.$itembrand.'<br>
<div class="col-xs-7">
<label>Item Code</label> <br>'.$itemcode.'
</div>
<div class="col-xs-1">
<label> Quantity</label> <br>'.$quantity.'
</div>
</div>
</div>
</div>
I guess, the following should help and what you wanted I mean to show distinct names. But you could do it with PHP easily:
SELECT CASE WHEN t.id = (SELECT t2.id FROM process t2
WHERE t2.projectNo = t.projectNo
GROUP BY t2.projectNo LIMIT 1) THEN t.projectNo
ELSE
''
END AS Deatils, t.stuff
FROM process t
Sample input and output: