Good day evening my goal here is when the excel has an empty date it will display in the data table an empty output, but it displays 01/01/1970 after I import excel empty data i had use strtotime format
empty data in my excell
Display in my datable
Here is my code below on displaying in the datable
<thead>
<tr>
<th class="text-center align-middle">Action</th>
<th class="text-center align-middle ">Last Name</th>
<th class="text-center align-middle ">First Name</th>
<th class="text-center align-middle ">Middle Name</th>
<th class="text-center align-middle ">Zone</th>
<th class="text-center align-middle ">Birth Day</th>
<th class="text-center align-middle ">Age</th>
<th class="text-center align-middle">Service Give</th>
<th class="text-center align-middle ">LMP</th>
<th class="text-center align-middle ">EDC</th>
<th class="text-center align-middle ">GPA</th>
<th class="text-center align-middle ">REMARKS</th>
<th class="text-center align-middle ">Teenage Pregnancy</th>
</tr>
</thead>
<tbody>
<?php
if($records){
foreach ($records as $record):
?>
<tr>
<td class="text-center align-middle">
<a href="<?php echo base_url('dashboard/editteen/'.$record->id); ?>" class="btn btn-primary "title="Edit Record">
<i class="fas fa-edit"></i>
</a>
</td>
<td class="text-center align-middle"><?php echo $record->lastname;?></td>
<td class="text-center align-middle"><?php echo $record->firstname;?></td>
<td class="text-center align-middle"><?php echo $record->middlename;?></td>
<td class="text-center align-middle"><?php echo $record->zone;?></td>
<td class="text-center align-middle">
<?php echo !empty($record->bday) ? date('m/d/Y', strtotime($record->bday)) : '';?>
</td>
<td class="text-center align-middle"><?php echo $record->age;?></td>
<td class="text-center align-middle"><?php echo $record->servicegive;?></td>
<td class="text-center align-middle">
<?php echo !empty($record->lmp) ? date('m/d/Y', strtotime($record->lmp)) : '';?>
</td>
<td class="text-center align-middle">
<?php echo !empty($record->edc) ? date('m/d/Y', strtotime($record->edc)) : '';?>
</td>
<td class="text-center align-middle"><?php echo $record->gpa;?></td>
<td class="text-center align-middle"><?php echo $record->remarks;?></td>
<td class="text-center align-middle"><?php echo $record->teenagepregnancy;?></td>
</tr>
down here is my code in importing
For loop in
if($sheetcount>1)
{
$data=array();
for ($i=1; $i < $sheetcount; $i++) {
$lastname=$sheetdata[$i][1];
$firstname=$sheetdata[$i][2];
$middlename=$sheetdata[$i][3];
$zone=$sheetdata[$i][4];
$bday=date('y-m-d',strtotime($sheetdata[$i][5]));
$age=$sheetdata[$i][6];
$servicegive=$sheetdata[$i][7];
$lmp=date('y-m-d',strtotime($sheetdata[$i][8]));
$edc=date('y-m-d',strtotime($sheetdata[$i][9]));
$gpa=$sheetdata[$i][10];
$remarks=$sheetdata[$i][11];
$teenagepregnancy=$sheetdata[$i][12];
set of data array
$data[]=array(
'lastname'=>$lastname,
'firstname'=>$firstname,
'middlename'=>$middlename,
'zone'=>$zone,
'bday'=>$bday,
'age'=>$age,
'servicegive'=>$servicegive,
'lmp'=>$lmp,
'edc'=>$edc,
'gpa'=>$gpa,
'remarks'=>$remarks,
'teenagepregnancy'=>$teenagepregnancy,
);
}
$inserdata=$this->m->insert_batch_teen($data);
if($inserdata)
{
$this->session->set_flashdata('message','<div class="alert alert-success">Successfully Added.</div>');
redirect('dashboard/importteen');
} else {
$this->session->set_flashdata('message','<div class="alert alert-danger">Data Not uploaded. Please Try Again.</div>');
redirect('dashboard/importteen');
}
}
}
Just put it in an IF statement.
$lmp=date('y-m-d',strtotime(''));
When strtotime is empty, it always returns 70-01-01.
Change to:
$lmp=$sheetdata[$i][8] ? date('y-m-d',strtotime($sheetdata[$i][8])) : '';
Related
This is my code
#if ($story)
<table class="table-auto my-3 w-full">
<thead class="justify-between">
<tr class="bg-gray-800">
<th class="px-16 py-2">
<span class="text-gray-300">#Id</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Name</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Description</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Actions</span>
</th>
</tr>
</thead>
<tbody class="bg-gray-200">
#foreach ($story as $item)
<tr class="bg-white border-4 border-gray-200">
<td class="px-16 py-2 flex flex-row items-center">
{{ $item->id }}
</td>
<td>
{{ Str::words($item->name, 3, $end = '...') }}
</td>
<td class="px-16 py-2">
{!! Str::words($item->description, 6, $end = '...') !!}
</td>
<td class="px-16 py-2">
<a href="{{ route('dashboard.story.edit', $item->id) }}">
<button class="bg-blue-500 text-white px-4 py-1 border rounded-md hover:bg-white hover:border-blue-500 hover:text-black">
Edit
</button>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
#else
<p>No results found</p>
#endif
This is my controller
public function index()
{
$story = Story::paginate(10);
return view('admin.story.index', ['story' => $story]);
}
I'm using Laravel 8 and I don't want to show table headers when the value is null. Laravel showing tables headers and not showing the 'No results found' message.
Any help would be appreciated.
when you use paginate, your data split. so if you want check this data empty or not just use
#if( $story->total() )
just replace it with
#if ( $story )
I have a table which I have created in a laravel blade, I've used bootstrap for this but my table seems to span off the screen, I have never really used laravel and normally my tables have auto centred as needed, I'm hoping someone can make some suggestions or share snippets to help me out :)
I have this image here:
I thought I should also put my blade in but only put the form-group as it will save your guys time :)
<div class="form-group">
<table id="userTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
<thead>
<tr>
<th scope="col">MESSAGE ID</th>
<th scope="col">MSISDN</th>
<th scope="col">MO/MT</th>
<th scope="col">TYPE</th>
<th scope="col">SENT/RECEIVED</th>
<th scope="col">TITLE</th>
<th scope="col">ORIENTATION</th>
<th scope="col">DESCRIPTION</th>
<th scope="col">IMAGE URL</th>
<th scope="col">ALIGNMENT</th>
<th scope="col">STATUS</th>
</tr>
</thead>
<tbody>
<tr>
<td style='font-size:14px'>{{$message->id}}</td>
<td>{{$message->msisdn}}</td>
<td class="text-center">
#if ($message->direction == 'mo')
<span class='badge badge-warning'>mo</span>
#else
<span class='badge badge-success'>{{$message->direction}}</span>
#endif
</td>
<td>{{$message->type}}</td>
<td>{{$message->created_at}} </td>
<td>{{$message->content->richCard->standaloneCard->cardOrientation}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->title}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->description}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->media->contentInfo->fileUrl}}</td>
<td>{{$message->content->richCard->standaloneCard->thumbnailImageAlignment}}</td>
<td class="text-center">
#if ($message->status == 'NOK')
<span class='badge badge-danger'>NOK</span>
#elseif ($message->status == 'received')
<span class='badge badge-info'>received</span>
#elseif ($message->status == 'delivered')
<span class='badge badge-primary'>delivered</span>
#elseif ($message->status == 'queued')
<span class='badge badge-warning'>queued</span>
#elseif ($message->status == 'read')
<span class='badge badge-success'>read</span>
#elseif ($message->status == 'sent')
<span class='badge badge-success'>sent</span>
#endif
</td>
</tr>
</tbody>
</table>
</div>
Any help would be greatly appreciated as I've never had this before.
before your table tag use
<div class='table-responsive'>
and close the div after closing your table tag.
This worked for me in some cases.
You will have to use table-responsive
<div class="table-responsive">
<table class="table">
...
</table>
</div>
I would like to know how to put a list of the last 5 items in the dashboard using backpack?
I made the table
<div class="table-responsive">
<table class="table table-hover m-0 table-actions-bar">
<thead>
<tr>
<th>
<div class="btn-group dropdown">
<button type="button" class="btn btn-light btn-xs dropdown-toggle waves-effect waves-light"
data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-chevron-down"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</th>
<th>Titolo Post</th>
<th>Data</th>
<th>Stato</th>
<th>Categria</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
<h5 class="m-0 font-weight-medium"></h5>
</td>
<td>
<i class="mdi mdi-map-marker text-primary"></i>
</td>
<td>
<i class="mdi mdi-clock-outline text-success"></i>
</td>
<td>
<i class="mdi mdi-currency-usd text-warning"></i>
</td>
<td>
<i class="mdi mdi-pencil"></i>
<i class="mdi mdi-close"></i>
</td>
</tr>
</tbody>
</table>
</div>
I made the table inside the jumbotron.blade.php then the function that prints you on screen the last 5 posts I put it here? within the dashboard method?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
any other solution?
This line will get you the last 5 articles.
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
You need to pass it to the view. Ex:
return view('dashboard', ['articles' => $articles]);
And loop the articles on the blade file table. Ex:
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
#foreach($articles as $article)
<tr>
<th scope="row">{{ $article->id }}</th>
<td>{{ $article->title }}</td>
<td>{{ $article->author }}</td>
<td>{{ $article->created_at }}</td>
</tr>
#endforeach
</tbody>
</table>
My question is very simple
I am trying to call this source in my public folder in img folder:
src="img/vcc3logo.png"
But I can't display it on my pdf print form
When the customer print for a certification form it needed to display the image. The file of the print.blade.php is located in resources/views/customer-relations/dashboard/print.blade.php
Here is the code in my print.blade.php
{{-- <div class="content">
<div class="clearfix"></div>
<div class="box-body"> --}}
<img src="" height="50" width="50" style="float: right">
<img src="img/vcc3logo.png" height="50" width="50" style="float: left">
<div class="container">
<div class="row">
<div class="text-center">
<p class="text-center maliit">
Republic of the Philippines<br>
National Capital Region<br>
<font>City Government of Valenzuela</font><br>
Office of the City Mayor<br>
Valenzuela City Command and Communications Center<br>
2nd Floor, City ALERT Center, Mc-Arthur Hi-way, Malinta, Valenzuela City<br>
</p>
<h3>Application Number:{{ $application_number }}</h3>
</div>
<h5><b>Business Name:</b> {{ $business_name }}</h5>
<h5><b>Owner:</b> {{ $owner }}</h5>
<h5><b>Location:</b> {{ $location }}</h5>
</span>
<table class="table table-hover">
<thead>
<tr>
<th>Fees</th>
<th></th>
<th class="text-center"></th>
<th class="text-center"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-9"><em>Inspection Fee:</em></h4></td>
<td class="col-md-1" style="text-align: center"></td>
<td class="col-md-1 text-center"></td>
<td class="col-md-1 text-center">{{ $inspection_fee }}</td>
</tr>
<tr>
<td class="col-md-9"><em>Certificate Fee:</em></h4></td>
<td class="col-md-1" style="text-align: center"></td>
<td class="col-md-1 text-center"></td>
<td class="col-md-1 text-center">{{ $cert_fee }}</td>
</tr>
<tr>
<td class="col-md-9"><em>Local Fee:</em></h4></td>
<td class="col-md-1" style="text-align: center"></td>
<td class="col-md-1 text-center"></td>
<td class="col-md-1 text-center">{{ $local_fee }}</td>
</tr>
<tr>
<td class="col-md-9"><em>Others Fee:</em></h4></td>
<td class="col-md-1" style="text-align: center"></td>
<td class="col-md-1 text-center"></td>
<td class="col-md-1 text-center">{{ $others_fee }}</td>
</tr>
</tbody>
</table>
<p><i>Note: Please print and present to Customer Relations Officer</i></p>
</td>
</div>
{{-- </div>
</div>
</div>
--}}
I tried to change it to
src="url('/img/cctv_camera.jpg')"
but ended up with this error:
(1/1) RuntimeException
The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
If image file is located inside public folder then you need to add asset() which give full path of image like
<img src="{{asset('/img/vcc3logo.png')}}" height="50" width="50" style="float: left">
I think you can try this hope its help for you :
<img src="{{url('')}}/img/vcc3logo.png" height="50" width="50" style="float: left">
OR
<img src="{{asset('/img/vcc3logo.png')}}" height="50" width="50" style="float: left">
Hope this work for you !!!
I have the following view which returns some text if the POnumber is null.
What I think I need to have instead of the if(Model.Invoice.PONumber == null) is a check mechanism ( maybe multiple if statements ) that will check the fields LineNumber, Description, UnitOfMeasure, QtyOrdered and if any of them is null it will replace it with N/A or empty space but it will still allow the user to see the rest of information available.
Do you have any sugestions? I am new to MVC and any help will be apreciated.
Thank you in advance for your time and help,Bobby
<div class="contentWrapper2">
<div class="content2">
<div class="clr lfl w100">
<h1>Invoice Detail</h1>
<div class="return-btn">
<a class="btn btnStyleC btn-back-invoice" href="#Url.Action("InvoiceHistory", "Account")">
Back to Invoice List</a>
</div>
</div>
#if (Model.ErpError.Length > 0)
{
<div class="clr lfl w100 error">
#Html.Raw(Model.ErpError)
</div>
}
else
{
if(Model.Invoice.PONumber == null)
{
<div class="lfl w100 clr messaging">
<p>No information available at the moment for current invoice.
Please call our sales department for further assistance.
</p>
</div>
}
else
{
<div class="clr lfl w100">
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Invoice #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Invoice Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Order #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.OrderNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>PO #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.PONumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Due Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.DueDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
</div>
<div class="clr lfl w100">
<div class="bill-ship">
<table>
<tr>
<th>
<h4>Billing Information</h4>
</th>
</tr>
<tr>
<td>#Model.Invoice.BTDisplayName
</td>
</tr>
<tr>
<td>
<#Html.Raw(Model.Invoice.BTAddress1)
</td>
</tr>
#if (!string.IsNullOrEmpty(Model.Invoice.BTAddress2))
{
<tr>
<td>#Html.Raw(Model.Invoice.BTAddress2)
</td>
</tr>
}
<tr>
<td>#Html.CityCommaStateZip(Model.Invoice.BTCity, Model.Invoice.BTState, Model.Invoice.BTZip)</td>
</tr>
<tr>
<td>#Model.Invoice.BTCountry
</td>
</tr>
<tr>
<td>#Model.Invoice.BTPhone1</td>
</tr>
<tr>
<td>#Model.Invoice.BTEmail
</td>
</tr>
</table>
</div>
</div>
if (Model.Invoice.InvoiceLines.Count > 0)
{
<div class="clr lfl w100 line-item-detail">
<table class="info-tbl">
<tr>
<th class="vid-item">Item #</th>
<th class="vid-desc">Description</th>
<th class="vid-um">
U/M
</th>
<th class="vid-qty">
Qty
</th>
<th class="vid-ship">
Ship Date
</th>
#if (Model.ShowPackslip)
{
<th class="vid-pack">Pack Slip</th>
}
<th class="vid-unit">Unit Price</th>
<th class="vid-ext">Ext Price</th>
</tr>
#foreach (var invoiceLine in Model.Invoice.InvoiceLines)
{
<tr>
<td class="vid-line">#invoiceLine.LineNumber</td>
<td class="vid-desc">#invoiceLine.Description</td>
<td class="vid-um">#invoiceLine.UnitOfMeasure</td>
<td class="vid-qty">#invoiceLine.QtyOrdered</td>
<td class="vid-ship">
#if (invoiceLine.ShipDate.ToShortDateString() == "1/1/0001")
{
}
else
{
#invoiceLine.ShipDate.ToShortDateString()
}
</td>
#if (Model.ShowPackslip)
{
<td class="vid-pack">
#invoiceLine.PackSlip
</td>
}
<td class="vid-unit">#invoiceLine.UnitPrice.ToCurrency()
</td>
<td class="vid-ext">#invoiceLine.ExtendedPrice.ToCurrency()
</td>
</tr>
}
</table>
</div>
}
<div class="clr lfl w100">
<table class="tbl-total">
<tr class="subtotal">
<th class="col-1">Subtotal</th>
<td class="col-2">#Model.Invoice.OrderSubTotal.ToCurrency()
</td>
</tr>
#if (Model.Invoice.DollarOffOrder > 0)
{
<tr>
<th class="col-1">Order Discount</th>
<td class="col-2">#Model.Invoice.DollarOffOrder.ToCurrency()</td>
</tr>
}
#if (Model.Invoice.ShippingAndHandling > 0)
{
<tr>
<th class="col-1">Shipping</th>
<td class="col-2">#Model.Invoice.ShippingAndHandling.ToCurrency()
</td>
</tr>
}
#if (Model.Invoice.MiscCharges > 0)
{
<tr>
<th class="col-1">Misc. Charges</th>
<td class="col-2">#Model.Invoice.MiscCharges.ToCurrency()</td>
</tr>
}
<tr>
<th class="col-1">Sales Tax</th>
<td class="col-2">#Model.Invoice.TotalTax.ToCurrency()</td>
</tr>
<tr>
<th class="col-1">Invoice Total</th>
<td class="col-2">#Model.Invoice.InvoiceTotal.ToCurrency()</td>
</tr>
</table>
</div>
<div class="clr lfl w100">
<a class="btn btnStyleB btn-print" href="javascript:window.print();">Print</a>
</div>
}
}
</div>
</div>
You could create a template called for example "nullcheck.cshtml" like:
#if (ViewBag.ValueToCheck == null) {
<div class="lfl w100 clr messaging">
<p>
No information available at the moment for #(ViewBag.Field).
Please call our sales department for further assistance.
</p>
</div>
}
else {
#Html.Partial(ViewBag.TargetTemplate, Model)
}
Then you call it from your main view:
#{
ViewBag.TargetTemplate = "okModel";
ViewBag.Field = "P.O.Number";
ViewBag.ValueToCheck = Model.Invoice.PONumber;
Html.RenderPartial("nullCheck", Model, ViewBag);
}
okModel.cshtml should be the part of your template you will display when the value is not null...
I haven't tested this myself but it should give you some ideas... contact me if things go wrong XD
Cheers!
This seems like something you should take care of in your controller.
public ActionResult YourControllerAction()
{
var myViewModel = SomeService.GetMyViewModel();
if (myViewModel.Invoice.PONumber == null)
{
myViewModel.Invoice.PONumber = "N/A";
}
//etc
}
This leaves your view clearer (my personal preference)
However in the view you could simply use the null coalescing operator like so:
#Model.Invoice.PONumber ?? "NA"