I hav run into a problem - I am not that familiar with cakephp - but I have taken over a project (A webshop project) - and now I have a bit of a problem - I have a field (tracking id for the package) which writes to DB - that works great - but here is the trouble - when I click the button and save the tracking number to the DB - I wan't the system to send an email to the customer with the tracking id.
I can get the system to send a mail - but there is no tracking number on so I guess the email is send before the DB i updated.
Hope someone can point me in the right direction
public function send($order_id = null, $is_resolved = true)
{
if($this->request->is('post'))
{
$this->Order->id = $this->request->data['Order']['id'];
$this->Order->saveField('state', 'resolved');
$this->Order->saveField('date_resolved', date('Y-m-d H:i:s'));
$this->Order->saveField('delivery_label', $this->request->data['Order']['delivery_label']);
$this->Session->setFlash('Ordren er nu sat til "Sendt".'.$this->Session->read('Message.success.message'), null, array(), 'success');
$this->redirect(array('controller' => 'orders', 'action' => 'index'));
}
$order = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id, 'Order.state' => 'packed'), 'recursive' => 4));
// Does the item exist?
if(empty($order))
{
// Tell the user this item did not exist
$this->Session->setFlash('Ordren findes ikke.'.$this->Session->read('Message.warning.message'), null, array(), 'warning');
return $this->redirect($this->referer());
}
if($is_resolved) {
// Send the email receipt
$Email = new CakeEmail('receipt');
$Email->to($order['Customer']['email_address']);
$Email->template('receipt_send')->viewVars( array('order' => $order));
$Email->send();
}
$this->set('order', $order);
}
Here is the receipt_send code
<table style="width:100%; margin-bottom:30px; border-collapse: collapse; color:#777;">
<tr style="vertical-align:middle; border-bottom:1px solid #777;">
<td colspan="3" style="width:45%; padding:10px 0;"><?php echo $this->Html->image('logo.png', array('style' => 'height:50px; margin-top:-15px; vertical-align:middle;', 'fullBase' => true)); ?></td>
</tr>
<tr style="font-size:1em; border-bottom:1px solid #777;">
<td style="padding: 5px 0;"><strong>Kvittering</strong> fra Bundgaards Garn</td>
<td style="padding: 5px 0;">Ordre nr. <strong><?php echo $order['Order']['id']; ?></strong></td>
</tr>
<p style="width:50%; float:right;">Din ordre er afsendt og har fået trackingnummer: <strong><?php echo $order['Order']['delivery_label']; ?></strong></p>
<table style="text-align: left; width:100%; border-collapse: collapse;">
<tr style="border-bottom:2px solid #dddddd;">
<th style="width:35%; padding: 10px 0;">Vare</th>
<th style="width:25%; padding: 10px 0;">Antal</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Pris</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Total</th>
</tr>
<?php foreach ($order['OrderItem'] as $key => $order_item): ?>
<tr style="border-bottom:1px solid #dddddd;">
<!-- PRODCUT LINK -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $order_item['YarnBatch']['YarnVariant']['Yarn']['name'] . ' - ' . $order_item['YarnBatch']['YarnVariant']['color_code'] . '-' . $order_item['YarnBatch']['batch_code']; ?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $order_item['NeedleVariant']['Needle']['name'] . ' - ' . $order_item['NeedleVariant']['product_code']; ?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
Print af <?php echo $order_item['Recipe']['name']; ?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
Farveprøve af <?php echo $order_item['ColorSample']['name']; ?>
<?php endif; ?>
</td>
<!-- PRODCUT LINK COLLAPSE -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php echo $order_item['amount']; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['YarnBatch']['price'], 'DKK');?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['NeedleVariant']['price'], 'DKK');?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['Recipe']['price'], 'DKK');?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['ColorSample']['price'], 'DKK');?>
<?php endif; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;" >
<?php echo $this->Number->currency($order_item['price'], 'DKK');?>
<?php if($order_item['saving'] > 0) : ?>
<br/>
<span style="color:#5cb85c;"><?php echo $this->Number->currency($order_item['saving'], 'DKK');?>´</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<p>Levering</p>
<?php if($order['Order']['saving'] > 0) : ?>
<p>Rabat</p>
<?php endif; ?>
<p><strong>Subtotal</strong></p>
<p><strong>Moms</strong></p>
</td>
<td style="text-align:right;">
<p><?php echo $this->Number->currency($order['Order']['shipping_price'], 'DKK');?></p>
<?php if($order['Order']['saving'] > 0) : ?>
<p style="color:#5cb85c;"><strong><?php echo $this->Number->currency($order['Order']['saving'], 'DKK');?></strong></p>
<?php endif; ?>
<p><strong><?php echo $this->Number->currency($order['Order']['sub_total'], 'DKK');?></strong></p>
<p><strong><?php echo $this->Number->currency($order['Order']['tax'], 'DKK');?></strong></p>
</td>
</tr>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<h4>Total:</h4>
</td>
<td style="text-align:right; color:#900000;">
<h4><strong><?php echo $this->Number->currency($order['Order']['price'], 'DKK');?></strong></h4>
</td>
</tr>
</table>
<div style="width:50%; float:left;">
<h4>Ordren sendes til:</h4>
<p>
<strong><?php echo $order['Customer']['first_name'] . ' ' . $order['Customer']['last_name']; ?></strong><br>
<?php echo $order['Customer']['ShippingAddress']['street'] . ' ' .
$order['Customer']['ShippingAddress']['zip_code'] . ' ' .
$order['Customer']['ShippingAddress']['city_name']?><br>
<?php echo $order['Customer']['email_address']; ?><br>
<?php echo $order['Customer']['phone_number']; ?><br>
</p>
</div>
<div style="width:50%; float:left;">
<?php if(!empty($order['Order']['customer_note'])) : ?>
<h4>Note til forhandleren:</h4>
<p>
<?php echo $order['Order']['customer_note']; ?>
</p>
<?php endif; ?>
</div>
<hr style="width:100%; border: 0; border-bottom: 1px solid #ddd;">
<p style="color:#999; font-size:0.8em;">
<strong>Bundggards Garn</strong> <br/>
<a style="color:#777;" href="https://bundgaardsgarn.dk">bundgaardsgarn.dk</a> <br/>
kontakt#bundgaardsgarn.dk <br/>
Saltumvej 46 9700 Brønderslev <br/>
30369522 <br/>
<i>CVR:</i> 34526826 <br/>
</p>
Got it to work by creating a controller and make a button to the information.... Works like a charm.
Related
This code outputs the image on the left, and what I'm looking for is the image on the right: https://s27.postimg.org/niua66jqr/archive.jpg
How do I output this table correctly? Is it a problem with the archive code or the style code?
.archive-container {
margin-top: 85px;
}
.archive-container h2 {
font-weight: normal;
margin-bottom: 30px;
}
.archive,
.year,
th {
font-family: 'Georgia', sans-serif;
font-weight: normal;
color: #a6a6a6;
font-size: 16px;
}
.archive:hover th,
.year:hover th {
color: #a6a6a6 !important;
opacity: 1 !important;
}
.archive a:link:hover {
color: #e69900 !important;
}
a:link {
font-weight: normal;
color: black;
/
}
table {
margin-right: 20px;
border-spacing: 25px 3px;
}
<div class="archive-container">
<h2><?php the_title(); ?></h2>
<script type="text/javascript">
var domainroot = "sitetitle.com"
function Gsitesearch(curobj) {
curobj.q.value = "site:" + domainroot + " " + curobj.qfront.value
}
</script>
<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">
<p class="search">Search:
<br />
<input name="q" type="hidden" class="texta" />
<input name="qfront" type="text" style="width: 186px; text-size: 12px; height: 14px;" />
</p>
</form>
<table id=arc>
<?php $query="SELECT YEAR(post_date) AS `year`, MONTH(post_date) as `month`, DAYOFMONTH(post_date) as `dayofmonth`, ID, post_name, post_title FROM $wpdb->posts WHERE post_type = 'article' AND post_status = 'publish' ORDER BY post_date DESC" ; $key=m d5($query);
$cache=w p_cache_get( 'mp_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults=$ wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'mp_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ($arcresults) { $last_year = 0; $last_month = 0; foreach ( $arcresults as $arcresult ) { $year = $arcresult->year;
$month = $arcresult->month; if ($year != $last_year) { $last_year = $year; $last_month = 0; ?>
<tr class=year>
<th>
<br />
<br />
<?php echo $arcresult->year; ?></th>
</tr>
<?php } if ($month !=$ last_month) { $last_month=$ month; ?>
<tr class=archive>
<th>
<?php echo $wp_locale->get_month($arcresult->month); ?></th>
<td></td>
</tr>
<?php } ?>
<tr class=archive>
<th>
<?php echo $arcresult->dayofmonth; ?></th>
<td id=p<?php echo $arcresult->ID; ?>>
<a href="/<?php echo $arcresult->post_name; ?>">
<?php echo strip_tags(apply_filters( 'the_title', $arcresult->post_title)); ?></a>
</td>
</tr>
<?php } } ?>
</table>
</div>
<!-- /end .container -->
Maybe:
<table width="200" border="1">
<tbody>
<tr>
<td>
<div>2017</div>
<div>Januari</div>
<div>1</div>
</td>
<td>Long title here</td>
</tr>
<tr>
<td>
<div>2016</div>
<div>Januari</div>
<div>1</div>
</td>
<td>Long title here</td>
</tr>
</tbody>
</table>
I have a .php file that when I add three extra fields to it to be displayed (which begin with 'Client Vehicle'), it pushes down a 'div class' and it creates a lot of emtpy space. Things end up being on two pages instead of just one. Instead, there is a big empty space where my 'div class' used to be (its a table named 'invoice-details')
If I take away these fields, everything is spaced correctly. How can I add them and push the 'invoice-details' table back up into place?
Here are my css& php files:
.clearfix:after {
content: "";
display: table;
clear: both
}
a {
color: #375bc8;
text-decoration: underline
}
body {
position: relative;
width: 21cm;
height: 29.7cm;
margin: 0 auto;
color: #3A3A3A;
background: #FFFFFF;
font-family: sans-serif;
font-size: 14px
}
header {
padding: 10px 0;
margin-bottom: 30px
}
#logo {
text-align: right;
margin-bottom: 30px
}
#invoice-logo {
max-height: 125px;
text-align: right
}
.invoice-title {
color: #375bc8;
font-size: 2em;
line-height: 1.4em;
font-weight: normal;
margin: 20px 0
}
#company {
float: right;
text-align: right;
width: 40%
}
#client {
float: left;
width: 55%;
margin-right: 5%
}
.invoice-details {
text-align: right
}
.invoice-details table {
border-collapse: collapse;
border-spacing: 0;
text-align: right;
width: 40%;
margin: 0 0 0 auto;
font-size: 12px
}
.invoice-details table td {
width: auto;
margin: 0;
padding: 0 0 0.5em 0
}
table.item-table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
font-size: 12px
}
table.item-table tr:nth-child(2n-1) td {
background: #F5F5F5
}
table.item-table th {
padding: 10px 15px;
border-bottom: 1px solid #606060;
white-space: nowrap;
text-align: left
}
table.item-table th.text-right {
text-align: right
}
table.item-table td {
padding: 10px 15px
}
table.item-table .invoice-sums {
text-align: right
}
footer {
color: #878787;
width: 100%;
border-top: 2px solid #878787;
padding: 8px 0
}
.text-right {
text-align: right
}
.text-red {
color: #ea5340
}
.text-green {
color: #77b632
}
<html lang="<?php echo lang('cldr'); ?>">
<head>
<meta charset="utf-8">
<title>
<?php echo lang( 'invoice'); ?>
</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/templates.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/custom-pdf.css">
</head>
<body>
<header class="clearfix">
<div id="logo">
<?php echo invoice_logo_pdf(); ?>
</div>
<div id="client">
<div>
<b><?php echo $invoice->client_name; ?></b>
</div>
<?php if ($invoice->client_vat_id) { echo '
<div>' . lang('vat_id_short') . ': ' . $invoice->client_vat_id . '</div>'; } if ($invoice->client_tax_code) { echo '
<div>' . lang('tax_code_short') . ': ' . $invoice->client_tax_code . '</div>'; } if ($invoice->client_address_1) { echo '
<div>' . $invoice->client_address_1 . '</div>'; } if ($invoice->client_address_2) { echo '
<div>' . $invoice->client_address_2 . '</div>'; } if ($invoice->client_city && $invoice->client_zip) { echo '
<div>' . $invoice->client_city . ' ' . $invoice->client_zip . '</div>'; } else { if ($invoice->client_city) { echo '
<div>' . $invoice->client_city . '</div>'; } if ($invoice->client_zip) { echo '
<div>' . $invoice->client_zip . '</div>'; } } if ($invoice->client_state) { echo '
<div>' . $invoice->client_state . '</div>'; } if ($invoice->client_country) { echo '
<div>' . get_country_name(lang('cldr'), $invoice->client_country) . '</div>'; } echo '
<br/>'; if ($invoice->client_phone) { echo '
<div>' . lang('phone_abbr') . ': ' . $invoice->client_phone . '</div>'; } ?>
<br/>
<p>
<?php echo 'Client Vehicle'; ?>
</p>
<p>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?></p>
<p>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?></p>
<p>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?></p>
</div>
<div id="company">
<div><b><?php echo $invoice->user_name; ?></b>
</div>
<?php if ($invoice->user_vat_id) { echo '
<div>' . lang('vat_id_short') . ': ' . $invoice->user_vat_id . '</div>'; } if ($invoice->user_tax_code) { echo '
<div>' . lang('tax_code_short') . ': ' . $invoice->user_tax_code . '</div>'; } if ($invoice->user_address_1) { echo '
<div>' . $invoice->user_address_1 . '</div>'; } if ($invoice->user_address_2) { echo '
<div>' . $invoice->user_address_2 . '</div>'; } if ($invoice->user_city && $invoice->user_zip) { echo '
<div>' . $invoice->user_city . ' ' . $invoice->user_zip . '</div>'; } else { if ($invoice->user_city) { echo '
<div>' . $invoice->user_city . '</div>'; } if ($invoice->user_zip) { echo '
<div>' . $invoice->user_zip . '</div>'; } } if ($invoice->user_state) { echo '
<div>' . $invoice->user_state . '</div>'; } if ($invoice->user_country) { echo '
<div>' . get_country_name(lang('cldr'), $invoice->user_country) . '</div>'; } echo '
<br/>'; if ($invoice->user_phone) { echo '
<div>' . lang('phone_abbr') . ': ' . $invoice->user_phone . '</div>'; } if ($invoice->user_fax) { echo '
<div>' . lang('fax_abbr') . ': ' . $invoice->user_fax . '</div>'; } ?>
</div>
</header>
<main>
<div class="invoice-details clearfix">
<table>
<tr>
<td>
<?php echo lang( 'invoice_date') . ':'; ?>
</td>
<td>
<?php echo date_from_mysql($invoice->invoice_date_created, true); ?></td>
</tr>
<tr>
<td>
<?php echo lang( 'due_date') . ': '; ?>
</td>
<td>
<?php echo date_from_mysql($invoice->invoice_date_due, true); ?></td>
</tr>
<tr>
<td>
<?php echo lang( 'amount_due') . ': '; ?>
</td>
<td>
<?php echo format_currency($invoice->invoice_balance); ?></td>
</tr>
<?php if ($payment_method): ?>
<tr>
<td>
<?php echo lang( 'payment_method') . ': '; ?>
</td>
<td<?php echo $payment_method->payment_method_name; ?></td>
</tr>
<?php endif; ?>
</table>
</div>
<h1 class="invoice-title"><?php echo lang('invoice') . ' ' . $invoice->invoice_number; ?></h1>
<table class="item-table">
<thead>
<tr>
<th class="item-name">
<?php echo lang( 'item'); ?>
</th>
<th class="item-desc">
<?php echo lang( 'description'); ?>
</th>
<th class="item-amount text-right">
<?php echo lang( 'qty'); ?>
</th>
<th class="item-price text-right">
<?php echo lang( 'price'); ?>
</th>
<?php if ($show_discounts) : ?>
<th class="item-discount text-right">
<?php echo lang( 'discount'); ?>
</th>
<?php endif; ?>
<th class="item-total text-right">
<?php echo lang( 'total'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item) { ?>
<tr>
<td>
<?php echo $item->item_name; ?></td>
<td>
<?php echo nl2br($item->item_description); ?></td>
<td class="text-right">
<?php echo format_amount($item->item_quantity); ?>
</td>
<td class="text-right">
<?php echo format_currency($item->item_price); ?>
</td>
<?php if ($show_discounts) : ?>
<td class="text-right">
<?php echo format_currency($item->item_discount); ?>
</td>
<?php endif; ?>
<td class="text-right">
<?php echo format_currency($item->item_subtotal); ?>
</td>
</tr>
<?php } ?>
</tbody>
<tbody class="invoice-sums">
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'subtotal'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_subtotal); ?></td>
</tr>
<?php if ($invoice->invoice_item_tax_total > 0) { ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'item_tax'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_tax_total); ?>
</td>
</tr>
<?php } ?>
<?php foreach ($invoice_tax_rates as $invoice_tax_rate) : ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo $invoice_tax_rate->invoice_tax_rate_name . ' (' . $invoice_tax_rate->invoice_tax_rate_percent . '%)'; ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice_tax_rate->invoice_tax_rate_amount); ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<b><?php echo lang('total'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_total); ?></b>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'paid'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_paid); ?>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<b><?php echo lang('balance'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_balance); ?></b>
</td>
</tr>
</tbody>
</table>
</main>
<footer>
<?php if ($invoice->invoice_terms) : ?>
<div class="notes">
<b><?php echo lang('terms'); ?></b>
<br/>
<?php echo nl2br($invoice->invoice_terms); ?>
</div>
<?php endif; ?>
</footer>
</body>
</html>
Here is my updated .php file with the added div. The new revision only works down to the new div I added as I guess because this is nested?
<html lang="<?php echo lang('cldr'); ?>">
<head>
<meta charset="utf-8">
<title><?php echo lang('invoice'); ?></title>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/templates.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/custom-pdf.css">
</head>
<body>
<header class="clearfix">
<div id="logo">
<?php echo invoice_logo_pdf(); ?>
</div>
<div id="client">
<div>
<b><?php echo $invoice->client_name; ?></b>
</div>
<?php if ($invoice->client_vat_id) {
echo '<div>' . lang('vat_id_short') . ': ' . $invoice->client_vat_id . '</div>';
}
if ($invoice->client_tax_code) {
echo '<div>' . lang('tax_code_short') . ': ' . $invoice->client_tax_code . '</div>';
}
if ($invoice->client_address_1) {
echo '<div>' . $invoice->client_address_1 . '</div>';
}
if ($invoice->client_address_2) {
echo '<div>' . $invoice->client_address_2 . '</div>';
}
if ($invoice->client_city && $invoice->client_zip) {
echo '<div>' . $invoice->client_city . ' ' . $invoice->client_zip . '</div>';
} else {
if ($invoice->client_city) {
echo '<div>' . $invoice->client_city . '</div>';
}
if ($invoice->client_zip) {
echo '<div>' . $invoice->client_zip . '</div>';
}
}
if ($invoice->client_state) {
echo '<div>' . $invoice->client_state . '</div>';
}
if ($invoice->client_country) {
echo '<div>' . get_country_name(lang('cldr'), $invoice->client_country) . '</div>';
}
echo '<br/>';
if ($invoice->client_phone) {
echo '<div>' . lang('phone_abbr') . ': ' . $invoice->client_phone . '</div>';} ?>
<br>
<div>
<b><?php echo '<u>Client Vehicle</u>'; ?>:</b>
<br>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?>
</br>
<br>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?>
</br>
<br>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?>
</br>
</div>
</div>
<div id="company">
<div><b><?php echo $invoice->user_name; ?></b></div>
<?php if ($invoice->user_vat_id) {
echo '<div>' . lang('vat_id_short') . ': ' . $invoice->user_vat_id . '</div>';
}
if ($invoice->user_tax_code) {
echo '<div>' . lang('tax_code_short') . ': ' . $invoice->user_tax_code . '</div>';
}
if ($invoice->user_address_1) {
echo '<div>' . $invoice->user_address_1 . '</div>';
}
if ($invoice->user_address_2) {
echo '<div>' . $invoice->user_address_2 . '</div>';
}
if ($invoice->user_city && $invoice->user_zip) {
echo '<div>' . $invoice->user_city . ' ' . $invoice->user_zip . '</div>';
} else {
if ($invoice->user_city) {
echo '<div>' . $invoice->user_city . '</div>';
}
if ($invoice->user_zip) {
echo '<div>' . $invoice->user_zip . '</div>';
}
}
if ($invoice->user_state) {
echo '<div>' . $invoice->user_state . '</div>';
}
if ($invoice->user_country) {
echo '<div>' . get_country_name(lang('cldr'), $invoice->user_country) . '</div>';
}
echo '<br/>';
if ($invoice->user_phone) {
echo '<div>' . lang('phone_abbr') . ': ' . $invoice->user_phone . '</div>';
}
if ($invoice->user_fax) {
echo '<div>' . lang('fax_abbr') . ': ' . $invoice->user_fax . '</div>';
}
?>
</div>
</header>
<main>
<div class="invoice-details clearfix">
<table>
<tr>
<td><?php echo lang('invoice_date') . ':'; ?></td>
<td><?php echo date_from_mysql($invoice->invoice_date_created, true); ?></td>
</tr>
<tr>
<td><?php echo lang('due_date') . ': '; ?></td>
<td><?php echo date_from_mysql($invoice->invoice_date_due, true); ?></td>
</tr>
<tr>
<td><?php echo lang('amount_due') . ': '; ?></td>
<td><?php echo format_currency($invoice->invoice_balance); ?></td>
</tr>
<?php if ($payment_method): ?>
<tr>
<td><?php echo lang('payment_method') . ': '; ?></td>
<td<?php echo $payment_method->payment_method_name; ?></td>
</tr>
<?php endif; ?>
</table>
</div>
<h1 class="invoice-title"><?php echo lang('invoice') . ' ' . $invoice->invoice_number; ?></h1>
<table class="item-table">
<thead>
<tr>
<th class="item-name"><?php echo lang('item'); ?></th>
<th class="item-desc"><?php echo lang('description'); ?></th>
<th class="item-amount text-right"><?php echo lang('qty'); ?></th>
<th class="item-price text-right"><?php echo lang('price'); ?></th>
<?php if ($show_discounts) : ?>
<th class="item-discount text-right"><?php echo lang('discount'); ?></th>
<?php endif; ?>
<th class="item-total text-right"><?php echo lang('total'); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($items as $item) { ?>
<tr>
<td><?php echo $item->item_name; ?></td>
<td><?php echo nl2br($item->item_description); ?></td>
<td class="text-right">
<?php echo format_amount($item->item_quantity); ?>
</td>
<td class="text-right">
<?php echo format_currency($item->item_price); ?>
</td>
<?php if ($show_discounts) : ?>
<td class="text-right">
<?php echo format_currency($item->item_discount); ?>
</td>
<?php endif; ?>
<td class="text-right">
<?php echo format_currency($item->item_subtotal); ?>
</td>
</tr>
<?php } ?>
</tbody>
<tbody class="invoice-sums">
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('subtotal'); ?>
</td>
<td class="text-right"><?php echo format_currency($invoice->invoice_item_subtotal); ?></td>
</tr>
<?php if ($invoice->invoice_item_tax_total > 0) { ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('item_tax'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_tax_total); ?>
</td>
</tr>
<?php } ?>
<?php foreach ($invoice_tax_rates as $invoice_tax_rate) : ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo $invoice_tax_rate->invoice_tax_rate_name . ' (' . $invoice_tax_rate->invoice_tax_rate_percent . '%)'; ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice_tax_rate->invoice_tax_rate_amount); ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<b><?php echo lang('total'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_total); ?></b>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('paid'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_paid); ?>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<b><?php echo lang('balance'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_balance); ?></b>
</td>
</tr>
</tbody>
</table>
</main>
<footer>
<?php if ($invoice->invoice_terms) : ?>
<div class="notes">
<b><?php echo lang('terms'); ?></b><br/>
<?php echo nl2br($invoice->invoice_terms); ?>
</div>
<?php endif; ?>
</footer>
</body>
</html>
Add the div tag for the new added elements
<div>
<p>
<?php echo 'Client Vehicle'; ?>
</p>
<p>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?></p>
<p>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?></p>
<p>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?></p>
</div>
I have view file on my app there is code array I want to get first object of that array without going in loop.
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
$result is array of object I'm getting from a form. In below you can clearly see I'm chunking it to 3 more array and looping though individual objects and getting their details to html for example.
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
I want to get the first object details let's say want get $product->product_name of first object of result array without going in loop how to achieve that.
here is complete view file code.
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 0px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<div class="footer">
Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?>, $ Rate : Rs. <?php echo $usd; ?> </div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
<?php $GLOBALS['a']= $product->product_id; ?>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
ok man as i said u need to change your way of writing codes but about your specific question use this:
$result = array('a', 'b', 'c', 'd', 'e');
reset($array);
$first = current($array);
you can check this:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.current.php
But still about your way of coding. u should soon go to MVC or such ways of programming so u should separate your view and coding logics
like u may have a page like view_profile.php which is going to show user's information. in regular coding u have this:
view_profile.php:
<?php session_start();
// you check sessions to see if the user is logged in and has the right to view this page.
// like:
if ($_SESSIONS['is_user_logged_in']){
$username=$_SESSIONS['username'];
$name=$_SESSIONS['name'];
// ....
}else{
header('location: ./login.php');// if user is not authenticated u redirect to login page
exit();// prevents the rest of codes to be shown and executed
}
?>
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
But in a better way u can do it like this:
you have files like
'view_profile.htm' // holds the HTML
'view_profile.php // holds the PHP logic
'inc.php' // holds some useful functions that help you in writing PHP logic
view_profile.htm
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
inc.php
<?php
function ses_start(){
if(!session_id()){
session_start();
}
}
function ses_get($key){
ses_start();
if(!empty($_SESSION[$key])){
return $_SESSION[$key];
}
return NULL;
}
function ses_set($key,$val){
$_SESSION[$key]=$val;
}
function is_user_loggedin(){
ses_start();
if(!empty(ses_get('is_user_loggedin')){
return true;
}
return false;
}
function go($to){
header('location: '.$to);
exit();
}
//and lots of useful functions that help u connect and work with data base.
view_profile.php
<?php
include('inc.php');
if(is_user_loggedin(){
$username=ses_get('username');
$name=ses_get('name');
//...
}else{
go('login.php);
}
include('view_profile.html); // and u call the .htm file that holds the HTML the view file)
?>
this was a simple sample of separating codes logic(php codes) from views(html tags)
and also u may search about MVC Model-View-Controller and try working with simple MVC frameworks.
I am implementing the printing of pages in HTML.
My aim is if a table will not be accommodated in the same page, the whole table will be transferred to the next page. How do i do this. i have this code.. please help me.
here is my CSS part.
<style type="text/css">
.printOnly {
margin-top: 100px;
display: none;
}
.textSummaryTable { page-break-inside:auto }
.textSummaryTable tr { page-break-inside:avoid; page-break-after:auto }
#media print {
.summaryTable tr:nth-child(odd){ background-color:#E1E4E5;}
.summaryTable tr:nth-child(even) { background-color:#ffffff; }
.printOnly { display: block; }
.panel {
border: 1px solid transparent;
padding: 2px;
margin: 0;
}
.textSummaryTable{ border:1px solid gray; }
.textSummaryTable td{ border:1px solid gray; }
#main {
overflow: hidden;
position: absolute;
padding: 0px;
height: auto;
width: 100%;
}
#title { display: none; }
#line-break { display: block; }
.textSummaryTable { width: 100%; }
}
#media screen {
#line-break { display: none; }
}
</style>
and My tables are here.
<?php
$this->pageTitle = Yii::app()->name . ' - View Evaluation';
$user = LoginForm::getUser();
?>
<?php $participants = $modelE->evaluationDetails; ?>
<style type="text/css">
#media print {
body {
overflow: hidden;
}
}
</style>
<div class=" non-printable">
<div class='pull-right non-printable'>
<button id="btnPrint" type="button" class="btn btn-default pull-right" onclick="window.print();">
<span class="glyphicon glyphicon-print"></span> Print
</button>
</div>
<?php
$startDate = date("M j, Y", strtotime($modelE->start_date));
$endDate = date("M j, Y", strtotime($modelE->end_date));
?>
</div>
<div id='line-break'>
<br>
<br>
<br>
</div>
<div class="container-fluid">
<div class="printable">
<h4><?php echo htmlentities($modelE->evaluationForm->name); ?></h4>
<h5><?php echo $startDate; ?> - <?php echo $endDate; ?></h5>
<h5>Candidate: <?php echo htmlentities($modelE->evaluatee); ?></h5>
<h5>Overall Evaluation: <?php echo htmlentities($modelE->getResult()); ?></h5>
<h5>Participants: <?php echo htmlentities(count($participants)); ?></h5>
<div class="panel panel-default">
<div class="panel-body">
<h5><strong>Instructions: </strong> <?php echo htmlentities($modelE->evaluationForm->description); ?></h5>
<!-- <h4>Results Summary</h4> -->
<?php
$radioFlag = false;
foreach ($modelE->evaluationForm->evaluationFormDetails as $question) {
$criteria = new CDbCriteria;
$criteria->with = 'evalResult';
$criteria->addInCondition('eval_form_question_id', array($question->id));
$criteria->addInCondition('evalResult.eval_id', array($modelE->id));
$resultSet = EvaluationResultsDetails::model()->findAll($criteria);
if ( strtolower($question->field_type) != "radioheader" && $question->field_type != "slider" ) {
if($radioFlag){
echo "</table>";
$radioFlag = false;
}
if( $question->field_type == "text" ) {
echo "<h4>" . $question->field_name . "</h4>";
}
else {
echo "<table class='textSummaryTable'><tr><td style='width: 100%'><label>" . $question->field_name . "</label></td></tr>";
foreach ($resultSet as $answer) {
echo "<tr><td>" . $answer->eval_answer . "</td></tr>";
}
echo "</table>";
}
} else {
if(!$radioFlag){
echo '<table border-size = 0px width=100% class="summaryTable">';
$radioFlag = true;
}
echo "<tr><td style='width: 90%'>" . $question->field_name . "";
echo "</td><td style='width: 10%'>";
$sum = 0;
$count = 0;
foreach ($resultSet as $answer) {
$count++;
$sum += $answer->eval_answer;
}
echo $count == 0 ? "-" : number_format($sum / $count, 2);
echo "</td></tr>";
/*** end here ***/
}
}
if($radioFlag){
echo "</table>";
}
?>
<table class="printOnly">
<tr>
<td colspan="2">
<p> I hereby certify that all information declared in this document are accurate and true. Each item have been discussed with my Immediate Superior and mutually agreed upon.</p>
</td>
</tr>
<tr>
<td>
<p>Prepared by
<?= $modelE->project->manager->family_name . ", " . $modelE->project->manager->first_name ?>
</p>
Date <?= date("Y-m-d"); ?>
</td>
<td>
<p>Conformed by <?= $modelE->evaluatee ?></p>
Date
</td>
</tr>
<tr>
<td colspan="2">
<p>Noted by HR Division</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while ($pF = mysql_fetch_array($stringVisits)) {
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if (checkStatus($BuID) == 1) {
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if (!empty($getByProfile["photo_thumb"])) {
echo $getByProfile["photo_thumb"];
} else {
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php } ?>
</tr>
</table>
This is what i have right now it displays the visiter´s profileimage. Now i would like to have their name under the image too.. but then i need to create another <tr> after this one, and add their name in each <td>. But how can i do that, if i have this while? Should i run another while, to get the names or can i do something smart with this?
Why not just stick the name in the same cell as the image? After you close the image tag, just echo $getByProfile["username"], or whatever?
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while($pF = mysql_fetch_array($stringVisits)){
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'><br/>";
?>
</a>
<br/><?php echo $getByProfile['username']; ?>
</td>
<?php } ?>
</tr>
</table>
Here's a way to do it with minimal changes to your existing code:
<?php
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
$names = array(); // ADDITION #1
while($pF = mysql_fetch_array($stringVisits)){
$names[] = // ADDITION #2 - ADD NEW USER NAME HERE;
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php }
// ADDITION #3:
echo "</tr>
<tr>";
foreach ($names as $username)
echo "<td class=\"username\"><p>$username</p></td>";
?>
</tr>
</table>
Also note that the way you had your code, the </tr> was inside the while loop.
this might not look nice but it should work why do you want 2 loops?
<?php
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >";
while($pF = mysql_fetch_array($stringVisits)){
echo "
<tr>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<a href='profil.php?id=".$BuID."'> <img /> </a>
</td>
</tr>
<tr><td> " . $getByProfile['username'] . " </td></tr>";
}
echo "</table>";
?>