Laravel image embed failure - php

I am having the problem in embeding images, but for the icon that is working fine and display the icon in mail, but for inside the foreach I am having some problem in displaying the images.
This is the shopping cart details I am trying to send for the customer email address! please help me to fix this !
#foreach($products as $item)
<?php $i++; ?>
<tr>
<td align="center">
**<img src="{{ $message->embed('img/tempEng/{!!$item->imgPath]!!}') }}" style="padding:0px; margin:0px" />**
</td>
<td align="center">
{{$item['name']}}
</td>
<td>
<td align="center">{{ $item['quantity'] }}</td>
<?php $quantity = $quantity + $item['quantity'] ?>
</td>
<td align="center">LKR {{$item['price']}}</td>
<td align="center">{{$item['discount']}}%</td>
<td align="center"><?php $item['price']=$item['price']*$item['quantity'] - ($item['price']*$item['quantity']*$item['discount'])/100.0 ?>LKR {{$item['price']}}</td>
</tr>
<?php $total=$total+$item['price']; ?>
{{--$i++;--}}
#endforeach

Related

Display name of category in td

I want to display subcategory in td but I like the result with some formatting. The output is going on weight column so need help to improve code. How can I display one by one product_name? for each loop create the second td & it will go to the weigh column. I want to display this product_name with auto-increment $i
Excepted result:
product_name
1)face wash
2)face cream
my result:
face wash face cream
Blade file code:
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Order summary</strong></h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<td><strong>Product Name</strong></td>
<td class="text-center"><strong>Weight</strong></td>
<td class="text-center"><strong>Quantity</strong></td>
<td class="text-right"><strong>Price</strong></td>
<td class="text-right"><strong>SubTotal</strong></td>
</tr>
</thead>
<tbody>
<!-- foreach ($order->lineItems as $line) or some such thing here -->
<tr>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
$weight=explode(',', $bill->weight);
$orders_qty=explode(',', $bill->orders_qty);
$price=explode(',', $bill->price);
$orders_subtotal=explode(',', $bill->orders_subtotal);
?>
<td><?php
$subcategory=explode(',', $bill->name_of_subcategory);
for($i=0;$i<count($subcategory);$i++)
{
echo $subcategory[$i];
}
?></td>
<td class="text-center">{{ $bill->weight }}</td>
<td class="text-center">{{ $bill->orders_qty }}</td>
<td class="text-center">{{ $bill->price }}</td>
<td class="text-center">{{ $bill->orders_subtotal }}</td>
</tr>
<tr>
<td class="thick-line"></td>
<td class="thick-line"></td>
<td class="thick-line"></td>
<td class="thick-line text-center"><strong>Subtotal</strong></td>
<td class="thick-line text-right">{{ $bill->total }}</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>SGST</strong></td>
<td class="no-line text-right">{{ $bill->sgst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>CGST</strong></td>
<td class="no-line text-right">{{ $bill->cgst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>IGST</strong></td>
<td class="no-line text-right">{{ $bill->igst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>Total</strong></td>
<td class="no-line text-right">{{ $bill->grand_total }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Try this
<table>
<tr>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
foreach($subcategory as $row){ ?>
<td>{{$row}}</td>
<?php } ?>
</tr>
</table>
you should create a <td> foreach result.
<table>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
for($i=0;$i<count($subcategory);$i++)
{
echo "<tr><td>".$subcategory[$i]."</td></tr>";
}
?>
</table>

Cache is breaking HTML table when refreshing page

I've been battling with this issue for a while now and can't find out why it's happening. I basically have a table which displays Woocommerce variations with each variation being in it's own row. The problem I have is when refreshing the page, the <th> row collapses and doesn't line up with the tbody.
Interestingly, if i change some of the css of the <th> in the console after the page loads, it fixes itself and lines up. The same applies If i open up the console after turn on 'Disable Cache' in the network tab and refresh the page.
My guess is the html is being loaded before the Woocommerce data is being added and doesn't have enough time to get the correct widths. However, this is a recent issue which has only just started happening.
Does anyone know what could cause this?
<table class="variations variations-grid" cellspacing="0">
<thead>
<tr>
<th><img class="camera-icon" src="/wp-content/uploads/2016/10/picture-holder.png"></th>
<th>
Type
</th>
<th>Length</th>
<th class="length">Weight</th>
<th>Height</th>
<th>Depth</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="thumbnail">
<img width="44" height="54" alt="Photinia Red Robin " src="/wp-content/uploads/2016/09/Photinia-Red-Robin-267x325.jpg">
</div>
</td>
<td class="attr attr-attribute_size">
<p>Hedge Bag</p>
</td>
<td class="attr attr-attribute_length">
<p>100cm</p>
</td>
<td class="attr attr-attribute_weight">
<p>75Kg</p>
</td>
<td class="attr attr-attribute_height">
<p>140-150cm+</p>
</td>
<td class="attr attr-attribute_depth">
<p>40cm</p>
</td>
<td class="price">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">£</span>191.00</span></span>
per metre
</td>
<td class="product-actions">
<a class="button" href="#modal0">More info</a>
</td>
</tr>
</tbody>
</table>
This is what is looks like broken:
This is what is looks like if i the disable cache OR change the css once it's loaded. This is how It should look.
I count more <td> in your <tbody> than <th> in your <thead>. Could this be the issue? Try to add empty <td> to match your <th> head count to test.

QR CODE not printing

I generating a QR CODE with url as data content, but when i try to print a page where the qr is generated, the qr does not seem to appear yet other content displays. Here is my snippet
<?php
require_once("qrcode.php");
//---------------------------------------------------------
$qr = new QRCode();
// ƒGƒ‰[’ù³ƒŒƒxƒ‹‚ðÝ’è
// QR_ERROR_CORRECT_LEVEL_L : 7%
// QR_ERROR_CORRECT_LEVEL_M : 15%
// QR_ERROR_CORRECT_LEVEL_Q : 25%
// QR_ERROR_CORRECT_LEVEL_H : 30%
$qr->setErrorCorrectLevel(QR_ERROR_CORRECT_LEVEL_L);
$qr->setTypeNumber(4);
$qr->addData("http:/".$_SERVER['REQUEST_URI']."");
$qr->make();
//---------------------------------------------------------
?>
and below is the other content on the page
<div class="invoice-box" id="invoice-box">
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
and my printing script
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'invoice-box', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
</script>
Assuming I found the correct library, it has an image creator. What you need to do is use an output buffer around the imagegif (or imagepng) call to capture the image's binary data into a string, then base64 encode the string, and echo that as part of a data URI directly in the src attribute of an img tag.
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
In your HTML
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
If you're concerned about support for data URLs, leave out the output buffering, add a unique, random filename as the second parameter to the imagegif call to save it, then echo that filename in the src.
It seems that you're trying to print a black background color which is removed by default from printing. Unfortunately there's no way to force it back programatically in browsers other than Safari and Chrome.
You can force this back for Safari and Chrome by doing:
<div class="invoice-box" id="invoice-box">
<style>
.invoice-box table td: {
-webkit-print-color-adjust: exact !important;
}
</style>
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
For browsers like IE and Firefox unfortunately this requires user interaction. See this question for more answers: Printing background-color in Firefox and IE
Finally, i got a way around this, here is my solution
<?php
require_once("qrcode.php");
$qr = QRCode::getMinimumQRCode("http:/".$_SERVER['REQUEST_URI']."", QR_ERROR_CORRECT_LEVEL_L);
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
?>
Then output the qrcode as image with this;
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
Thanks to #walf for his solution somehow, hope it helps someone else.

how to divide table contents into second page on thujohn pdf using laravel

I have a large single pdf document which consists of multiple records.I need to break or split the table records into second pages in the pdf using laravel.
Using the below codings in the controller the table records are not fully displayed.Some table records are missing in that pdf file.so I need to show the missing table records into second pafe of the pdf file.
private function generatePdf($customerstatement, $content) {
if (!is_dir(RECEIPTS_DIR)){
mkdir(RECEIPTS_DIR, 0755, true);
}
$outputName = $customerstatement->card_id . '-' . strtoupper(date("MY")) .'.pdf';
$pdfFileName = RECEIPTS_DIR.'/' . $outputName;
$view = View::make("admin.document.statement", compact('customerstatement', 'content'))->render();
$pdf = new \Thujohn\Pdf\Pdf();
$bytes_written = File::put($pdfFileName, $pdf->load($view, 'A4', 'portrait')->output());
if ($bytes_written === false) {
throw new \Exception("Unable to produce pdf statement");
}
$customerstatement->pdffile = $outputName;
$customerstatement->save();
return $outputName;
}
The below codings are written in the blade file for showing the records in the pdf.
<tbody>
<tr>
<td colspan="7"><b>{{ $customerstatement->customer->card_id }} - {{ $customerstatement->customer->fullName }} </b>
</td>
</tr>
<tr>
<td colspan="7"><b>Beginning Balance : {{ $customerstatement->beginning_balance }}</b>
</td>
</tr>
#foreach ($customerstatement->statements as $statement)
<tr>
<td width="7em">{{{ $statement->date }}}</td>
<td width="15em">{{{ $statement->memo }}}</td>
<td width="6em" align="center">{{{ $statement->debit }}}</td>
<td width="6em" align="center">{{{ $statement->credit}}}</td>
<td width="6em" align="center">{{{ $statement->closing_balance}}}</td>
</tr>
#endforeach
</tbody>
<tr>
<td colspan="7"><b>
{{ $customerstatement->customer->card_id }} - {{ $customerstatement->customer->fullName }} </b></td>
</tr>
<tr><td colspan="7"><b>Beginning Balance : {{ $customerstatement->beginning_balance }}</b></td></tr>
<?php $i=0 ?>
#foreach ($customerstatement->statements as $statement)
<?php $i++ ?>
<tr>
<td width="7em">{{{ date("d-m-Y", strtotime($statement->date) )}}}</td>
<td width="15em">{{{ $statement->memo }}}</td>
<td width="6em" align="center">{{{ $statement->debit }}}</td>
<td width="6em" align="center">{{{ $statement->credit}}}</td>
<td width="6em" align="center">{{{ $statement->closing_balance}}}</td>
<td ><?php
if($i==25){ ?>
<?php $i=0 ?>
<div style="page-break-after: always;"></div>
<?php }
?></td>
</tr>

Get total value from table row price in Laravel

Just started to working with laravel and found it really cool framework to work with , I'm working with basic Shopping cart and after i do Add to Cart Option , product values goto another table called "customer_items" along with current user ID,
now when I want to call current product which user already added to cart and show it in a table ,
here is the code
#foreach($shoppingCarts as $items)
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total"> <img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
note : {{ $items->product_price }} , usually there is 4, 6 items added by user ,
I want to get total value of product price from each row ,
Thanks in Advance for the help :) !
Used this and worked fine ,
<?php $total = 0; ?>
#foreach($shoppingCarts as $items)
<?php $total += $items->product_price; ?>
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total">{{ $total }}<img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
or
#foreach($shoppingCarts as $items)
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total">{{ $items->sum('product_price') }}<img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
Thanks everyone for the support :) !
Source : https://laracasts.com/discuss/channels/general-discussion/get-total-value-from-table-rows

Categories