Getting records from database, FROM a date TO a date - mysql

I'd like to obtain a record of a student's attendance from the "attendance" table. From a date to a date, e.g., from September 23, 2022, to December 10, 2022. Admin will enter the student's class and roll number, as well as a From date to date range.
Using his class and roll number. How to do this in Laravel 9 Thanks
this is the from through which a specific students record will be retirved.
<form class="mt-3" method="POST" action="\record">
#csrf
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Student Class</label>
<input type="number" name="class" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Roll Number</label>
<input type="number" name="roll number" class="form-control" id="exampleInputPassword1">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">From Date</label>
<input type="date" name="from_date" class="form-control" id="exampleInputPassword1">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">To Date</label>
<input type="date" name="to_date" class="form-control" id="exampleInputPassword1">
</div>
<button type="submit" class="btn btn-primary">Generate</button>

You can use the whereBetween in laravel to achieve this.
Suppose you have a model named Student.
You'd then do this in your controller:
$from = now();
$to = now()->addDays(5);
$studentAttendance = Student::whereBetween('date', [$from, $to])->get();
Which will get the students who have a date between $from and $to dates.

Related

Angular Two way binding working wrongly on my form list?

I have a list of persons That I bonded two ways to a form using a for each,
everything works fine, but when I want to bind the person's array of emails, it does not work!!
it sets the same value toall the other persons in my list!
Here is my code:
it works fine for the firstName element, but not for the email
<div class="col-md-3">
<div class="form-group">
<label>Prénom</label><span>*</span>
<input type="text" placeholder="First Name" required [(ngModel)]="listGlobalBeneficiaries[i].firstName"
[ngModelOptions]="{standalone: true}" class="form-control" id="bfirstName"
name="{{i}}_bfirstName" #bfirstName="ngModel">
<div [hidden]="bfirstName.valid || bfirstName.pristine" class="alert alert-danger">
Prénom est obligatoire
</div>
</div>
</div>
<input _ngcontent-fsl-c265="" type="text" placeholder="First Name" required="" id="bfirstName" class="form-control ng-dirty ng-valid ng-touched" ng-reflect-required="" ng-reflect-name="1_bfirstName" ng-reflect-options="[object Object]" ng-reflect-model="name">
<div class="col-md-4" >
<div class="form-group">
<label>E-mail</label><span>*</span>
<input type="email" placeholder="Email" email
required [(ngModel)]="listGlobalBeneficiaries[i].emails![0].address"
[ngModelOptions]="{standalone: true}" class="form-control"
name="{{i}}_emailaddress" id="{{i}}_emailaddress" #emailaddress="ngModel">
<div [hidden]="emailaddress.valid || emailaddress.pristine" class="alert alert-danger">
E-mail est obligatoire
</div>
</div>
</div>
<input _ngcontent-qhm-c265="" type="email" placeholder="Email" email="" required="" class="form-control ng-dirty ng-invalid ng-touched" ng-reflect-required="" ng-reflect-email="" ng-reflect-name="2_emailaddress" id="2_emailaddress" ng-reflect-model="" ng-reflect-options="[object Object]">
Fixed it, the problem was that when initializing the emails array.
Previous:
this.listGlobalBeneficiaries[i].emails = this.init_emails;
Fix:
this.listGlobalBeneficiaries[i].emails = [
{
type: 'WORK',
stillPrimary: true,
valid: true,
address: '',
},
];
because objects are assigned and copied by reference in typescript

Sql Server :- XML parsing: line 3, character 119, equal expected. Why?

Need help in below XML issue.
Create table #temp
( NAME VARCHAR(MAX)
)
Insert Into #temp
select
'<div class="form-group form-row"><label class="col-sm-5 control-label">Account Name</label><div class="form-controls"><div class="form-control-static">Bond</div></div></div><div class="form-group form-row"><label class="col-sm-5 control-label">Account Number</label><div class="form-controls"><div class="form-control-static">PQR</div></div></div><div class="form-group">
<label class="control-label">Specific subject</label>
<input class="input-text form-control" type="text" name="Specific subject" size="20" value="Money Transfer" DISABLED>
</div><div class="form-group">
<label class="control-label mandatory" for="message">Message</label>
<textarea class="textarea form-control" name="message" id="message" cols="30" rows="3" maxlength="5000" DISABLED REQUIRED> The Name is XYZ </textarea><span class="mand">*</span><span class="help-text">Max. 5000 characters</span>
</div>'
select convert(XML, NAME) from #temp
and whenever I am converting the column to XML using
convert(XML, Name)
it is showing me below error
XML parsing: line 3, character 119, equal expected.
Need help.
XML requires fully qualified elements, unlike HTML.
So, your code...
Create table #temp
( NAME VARCHAR(MAX)
)
Insert Into #temp
select
'<div class="form-group form-row"><label class="col-sm-5 control-label">Account Name</label><div class="form-controls"><div class="form-control-static">Bond</div></div></div><div class="form-group form-row"><label class="col-sm-5 control-label">Account Number</label><div class="form-controls"><div class="form-control-static">PQR</div></div></div><div class="form-group">
<label class="control-label">Specific subject</label>
<input class="input-text form-control" type="text" name="Specific subject" size="20" value="Money Transfer" DISABLED>
</div><div class="form-group">
<label class="control-label mandatory" for="message">Message</label>
<textarea class="textarea form-control" name="message" id="message" cols="30" rows="3" maxlength="5000" DISABLED REQUIRED> The Name is XYZ </textarea><span class="mand">*</span><span class="help-text">Max. 5000 characters</span>
</div>'
select convert(XML, NAME) from #temp
May only work if you specify values for the assumed Boolean types of DISABLED and REQUIRED...
Create table #temp
( NAME VARCHAR(MAX)
)
Insert Into #temp
select
'<div class="form-group form-row">
<label class="col-sm-5 control-label">Account Name</label>
<div class="form-controls"><div class="form-control-static">Bond</div></div>
</div>
<div class="form-group form-row">
<label class="col-sm-5 control-label">Account Number</label>
<div class="form-controls"><div class="form-control-static">PQR</div></div>
</div>
<div class="form-group">
<label class="control-label">Specific subject</label>
<input class="input-text form-control" type="text" name="Specific subject" size="20" value="Money Transfer" disabled="true">
</div>
<div class="form-group">
<label class="control-label mandatory" for="message">Message</label>
<textarea class="textarea form-control" name="message" id="message" cols="30" rows="3" maxlength="5000" disabled="true" required="true"> The Name is XYZ </textarea>
<span class="mand">*</span>
<span class="help-text">Max. 5000 characters</span>
</div>'
select convert(XML, NAME) from #temp
I have only picked out the obvious differences, however. I would recommend that you sanitise your data completely, if you are going to process it with SQL.

How to get the value from another table under same DB in LARAVEL?

I want to ask how to call the value from another table under same database ?
Database table name: bit_app_policy_category
Under the database I have these columns:
ID
code
description
parent_id
status
Another Database Table name under same database : company_policy
Under the database i have these columns:
ID
policy_category_id
policy_title
version_no
policy_details
expiry_date
file_path
As for now I want to link the table bit_app_policy_category and get the columns of id's value into company_policy - policy_category_id. I don't know how to write the code.
Here is my current code :
<form method="post" action="{{route('policy.store')}}">
{{csrf_field()}}
#csrf
<div class="form-group">
<label for="bit_app_policy_category_parent">Parent Category</label>
<select id="bit_app_policy_category_parent" name="parent_id" class="form-control">
<option value=" {{"$parents->id"}} </option>n>
</select>
</div>
<div class="form-group">
<label for="company_policy_policy_title">Policy Title<span class="required">*</span></label>
<input id="company_policy_policy_title" type="text" name="policy_title" class="form-control" placeholder="Please Enter the policy title" />
</div>
<div class="form-group">
<label for="company_policy_version-no">Version-no<span class="required">*</span></label>
<input id="company_policy_version-no" type="text" name="version_no" class="form-control" placeholder="Please Enter the Version-no" />
</div>
<div class="form-group">
<label for="company_policy_policy_details">Policy Details<span class="required">*</span></label>
<input id="company_policy_policy_details" type="text" name="policy_details" class="form-control" placeholder="Please Enter the Policy Details" />
</div>
<div class="form-group">
<label for="company_policy_expiry_date">Expiry Date<span class="required">*</span></label>
<input id="company_policy_expiry_date" type="datetime-local" name="expiry_date" class="form-control" placeholder="Please Enter the Expiry Date time" />
</div>
<div class="form-group">
<label for="company_policy_file_path">Policy File Path<span class="required">*</span></label>
<input id="company_policy_file_path" type="text" name="file_path" class="form-control" placeholder="Please Enter the file path" />
</div>
<div class="form-group">
<input type="submit" class="btn btn btn-primary" />
Back</span>
Back to home</span>
</div>
</form>
</div>
</div>
#endsection
First create two model
1. PolicyCategory and put the code in model
public function companyPolicies()
{
return $this->hasMany('App\CompanyPolicy');
}
2.CompanyPolicy
public function policyCategory()
{
return $this->belongsTo('App\PolicyCategory',policy_category_id);
}
and in you controller then you can get all the info of related table. Like say, you have one/two company under the policy_category which id is 1. Now you can get all the companies info like below
$policy_category = PolicyCategory::find(1);
dd($policy_category->companyPolicies);
try this and let me know is this really you want or not

How to put a checkout date and prevent the user from changing it?

I would like to produce something similar to the checkin and checkout for a hotel reservation system. So far, I'm allowing the user to enter the booking date (which is the check in). However, I would like to implement an unedited input with the value of checkin plus number of nights.
So, after the user has selected the booking date and the number of nights, it would add them together and display the checkout date on the side (but the user can't change it). After the duration has finished, the user can book the same hotel again, without telling the user that they have already booked that hotel.
<body>
<form action="" method="POST">
<fieldset>
<legend>Personal Details: </legend>
<label for="phone">Phone:</label><input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number" pattern="[0-9]{4}[0-9]{3}[0-9]{3}" title="Please enter in a phone number in this format:#### ### ###">
<select name="country" required >
<option value=""></option>
<option value="US">US</option>
<option value="UK">UK</option>
<option value="AUS">AUS</option>
</select>
</fieldset>
<br>
<fieldset>
<legend>Booking Details: </legend>
<label for="date">Booking date: </label><input id="date" type="date" name="date" min="2017-01-04">
<label for="numberOfRooms">Number of Rooms:</label><input id="NumberOfRooms" type="number" name="numberOfRooms" min="1" max="4">
<label for="numberOfNights">Number of Nights:</label><input id="NumberOfNights" type="number" name="numberOfNights" min="1" max="60">
<p>Do you require breakfast?</p>
<label for="yesBreakfast">Yes:</label><input id="yesBreakfast" type="radio" name="meals" value="yesBreakfast">
<label for="noBreakfast">No:</label><input id="noBreakfast" type="radio" name="meals" value="noBreakfast">
<br>
<!--<label for="balcony">Do you require a balcony?</label><input id="balcony" type="checkbox" name="balcony" value="yes" checked>-->
<br>
<button name="submit" type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
database tables for the book and the hotel
Book table:
id(int 11)
username(varchar 30)
hotel_id(int11)
phone(varchar 50)
date(datetime)
num_rooms(int 60)
num_nights(int 4)
Table for hotel
id(int 11)
Hotel_name(text)
Hotel_location(text)
Hotel_price(int 11)
image(varchar 500)
description(text)
I suggest you use momentjs to handle date related stuff.
I added change event on both date and NumberOfNights to call updateCheckout(), in that function will handle the checkout date
hope it helps
$(document).ready(function() {
$('#date, #NumberOfNights').on("change", updateCheckout);
$('#price, #NumberOfNights, #NumberOfRooms').on("change", updateTotalPrice);
function updateCheckout() {
var bookingDate = $('#date').val();
var numOfNights = $('#NumberOfNights').val();
if (bookingDate != '' && numOfNights != '') {
var new_date = moment(bookingDate, "YYYY-MM-DD").add(numOfNights, 'days').format("YYYY-MM-DD");
$('#checkout_date').text(new_date);
} else {
$('#checkout_date').text('N/A');
}
}
function updateTotalPrice() {
var price = $('#price').val();
var numOfNights = $('#NumberOfNights').val();
var NumberOfRooms = $('#NumberOfRooms').val();
if (price != '' && numOfNights != '' && NumberOfRooms != '') {
var total_price = +price * +numOfNights * +NumberOfRooms;
$('#total_price').text('$' + total_price);
} else {
$('#total_price').text('N/A');
}
}
});
#checkout_date,
#total_price {
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body>
<form action="" method="POST">
<fieldset>
<legend>Personal Details: </legend>
<label for="phone">Phone:</label>
<input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number" pattern="[0-9]{4}[0-9]{3}[0-9]{3}" title="Please enter in a phone number in this format:#### ### ###">
<select name="country" required>
<option value=""></option>
<option value="US">US</option>
<option value="UK">UK</option>
<option value="AUS">AUS</option>
</select>
</fieldset>
<br>
<fieldset>
<legend>Booking Details: </legend>
<label for="date">Booking date: </label>
<input id="date" type="date" name="date" min="2017-01-04">
<label for="numberOfRooms">Number of Rooms:</label>
<input id="NumberOfRooms" type="number" name="numberOfRooms" min="1" max="4">
<label for="numberOfNights">Number of Nights:</label>
<input id="NumberOfNights" type="number" name="numberOfNights" min="1" max="60">
<label for="price">Single Room Price: </label>
<input id="price" type="number" min="0">
<br>
<br>
<label>Checkout Date:</label>
<span id="checkout_date"> N/A</span>
<p>Do you require breakfast?</p>
<label for="yesBreakfast">Yes:</label>
<input id="yesBreakfast" type="radio" name="meals" value="yesBreakfast">
<label for="noBreakfast">No:</label>
<input id="noBreakfast" type="radio" name="meals" value="noBreakfast">
<br>
<!--<label for="balcony">Do you require a balcony?</label><input id="balcony" type="checkbox" name="balcony" value="yes" checked>-->
<br>
<label>Total Price:</label>
<span id="total_price"> N/A</span>
<br><br>
<button name="submit" type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>

How can you submit departure date and transit mode to google map direction?

Actually I have a form that use the Place API to determine the right address for start address and arrival address
<section class="itineraire section">
<h2 class="sectiontitle"><?php _e( 'Itinéraire', 'mlog_regim' ); ?></h2>
<form method="get" action="https://www.google.com/maps/" target="https://www.google.com/maps/">
<div class="form-group">
<input name="saddr" type="text" id="saddr" class="form-control" placeholder="Adresse de départ" onFocus="geolocate()" >
</div>
<div class="form-group">
<input name="daddr" type="text" id="daddr" class="form-control" placeholder="Adresse d'arrivée">
</div>
<div class="form-group">
<input name="txtDate" type="date" id="txtDate" class="form-control" placeholder="Date'">
</div>
<input type="hidden" name="travel_mode" value="3">
<button type="submit" class="btn btn-default">Rechercher</button>
</form>
</section>
And I would like to force the google map to display travel_mode 3 (transit) and the date to be set at the txtDate value. I can't find in the doc how to do it, but I've found some website that do it and it look not that hard... Do someone could give me some advice ?
Go Transit
RTC Quebec (Your itinerary)
Fill the form with theses inforamtion
Start point : 2220 Boulevard Pie-IX, Montréal, QC H1V 2E2, Canada
End point : Pointe-aux-Trembles, Montréal, QC, Canada
Choose any random date... for Go Transit, RTC Quebec only prove the travel mode.
Thank's for anyone help it will be appreciated !
The expected parameters are
dirflg set it to r for public transport
date format: mm/dd/yyyy
time format: hh:mm
ttype set it to dep(departure) or arr(arrival)
example:
<form method="get" action="https://www.google.com/maps/" target="google-maps">
<br/>
<input name="saddr" placeholder="origin" value="2220 Boulevard Pie-IX, Montréal, QC H1V 2E2, Canada" />
<br/>
<input name="daddr" placeholder="destination" value="Pointe-aux-Trembles, Montréal, QC, Canada" />
<br/>
<input name="date" placeholder="mm/dd/yyyy" />
<br/>
<input name="time" placeholder="hh:mm" />
<br/>
<select name="ttype">
<option value="dep">departure</option>
<option value="arr">arrival</option>
</select>
<br/>
<input type="hidden" name="dirflg" value="r" />
<input type="submit" />
</form>
http://jsfiddle.net/xnn34qL1/