<div id="main_borders">
<div id="main_inner_borders">
    <h2><strong>
      <?=$title?>
      </strong></h2>
    <? if ($this-> session-> flashdata('message')): ?>
    <div class='warning'>
      <?=$this-> session-> flashdata('message');?>
    </div>
    <? endif; ?>
  <? $id=$this->session->userdata('userid');
	 $order_id=$this->session->userdata('orderid'); ?>
<? $orderdata = $this->MFuncs->GetOrderbyID($id, $order_id); ?>
<? if ($orderdata) { ?>
<div>
<h4><?=$this->lang->line('payment_declined')?></h4>
<div id="cart_tbl">
<table width="100%" border="0">
  <tr>
    <th><?=$this->lang->line('cart_qty')?></th>
    <th><?=$this->lang->line('cart_desc')?></th>
    <th><?=$this->lang->line('cart_price')?></th>
    <th><?=$this->lang->line('cart_sub')?></th>
  </tr>

<?		$order_details = $this->MFuncs->GetOrderDetails($orderdata['id']);
		if ($order_details) {
		$total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;
    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
        $product_category = $this->MFuncs->getProductCat($order_det['product_id']); ?>
  <tr>
    <td><?=$order_det['quantity']?></td>
    <td><?=$product_details['name']?></td>
    <td><?=$order_det['price']?></td>
    <td>&euro;<?=$order_det['price']*$order_det['quantity']?></td>
      <? $total = $total + $order_det['price']*$order_det['quantity'];
      $weight = $weight + ($product_details['weight'] * $order_det['quantity']); ?>
          <? if ($product_category['cat_id']!='7') { ?>
          <? $bot_num = $bot_num + $order_det['quantity']; 
		  } ?>
  </tr>
    	<? endforeach ?>
<tr>
  <td colspan="2"> </td>
  <td><strong><?=$this->lang->line('cart_total')?></strong></td>
  <td>&euro;<?=number_format($total, 2, '.', '')?></td>
</tr>
<? if ($orderdata['offer_code']!=0) { ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong><?=$this->lang->line('cart_discount')?></strong></td>
 <td>&euro; <?=number_format($total*$orderdata['offer_code'], 2, '.', '')?></td>
 </tr>
 <? $total = $total - ($total*$orderdata['offer_code']); ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong><?=$this->lang->line('cart_total')?></strong></td>
 <td>&euro; <?=number_format($total, 2, '.', '')?></td>
 </tr>
 <? } ?>
        <? if ($orderdata['same_address']=='No') { ?>
 			<? $c_id = $orderdata['country_id']; ?>
        <? } elseif ($orderdata['same_address']=='Yes') { ?>
            <? $c_id = $userdata['country_id']; ?>
        <? } ?>
       <? if ($c_id!='1') { ?>
       <? if ($orderdata['ship_method']=='courier_economy') { ?>
       <? 	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getTNT_Cost_economy($rounded_weight, $country_zone['tnt_zones']);
			$ship_total = ($value['price']*0.205) + $value['price'];
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', ''); ?>
        <? } elseif ($orderdata['ship_method']=='courier_express') { ?>
       <? 	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			if ($rounded_weight<=30) {
			$value = $this->MFuncs->getTNT_Cost_express($rounded_weight, $country_zone['tnt_zones_express']);
			$total_ship_cost = $value['price'];
			} else {
			$value = $this->MFuncs->getTNT_Cost_express(30, $country_zone['tnt_zones_express']);
			$extra_cost_pk = $this->MFuncs->getTNT_extra_Cost($country_zone['tnt_zones_express']);
			$extra_ship_cost = (($rounded_weight-30) * $extra_cost_pk['price']);
			$total_ship_cost = $extra_ship_cost + $value['price'];
			}
			$ship_total = ($total_ship_cost*0.205) + $total_ship_cost;
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', ''); ?>
        <? }?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('ship_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('gen_total')?>
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total?></td>
        </tr>
        <? } else { ?>
		<? if ($orderdata['ship_method']=='courier') {
           $pack_total = (ceil($bot_num/2))*0.53;
           if ($orderdata['ship_dest']=='attica') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 3000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.57, 2, '.', '');
			   } else {
			   //$ship_total = 3.45 + $pack_total;
			   $ship_total = 3.57;
			   $weight = $weight - 3000;
			   $i = ceil($weight/1000);
			   $ship_total = number_format($ship_total + ($i*1.23), 2, '.', '');
			   }
		   } elseif ($orderdata['ship_dest']=='greece') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 5.90; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 10.58;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 16.48;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   } elseif ($orderdata['ship_dest']=='islands') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 8.86; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 15.87;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 24.60;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   }
		 ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('ship_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('gen_total')?>
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total?></td>
        </tr>
        <? } elseif ($orderdata['ship_method']=='day_delivery') {
        			   $ship_total = number_format(14.76, 2, '.', ''); ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('ship_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('gen_total')?>
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total?></td>
        </tr>
        <? } ?>
        <? } ?>
        <? } ?>
      </table>
<br />
<em><?=$this->lang->line('vat_included_cart')?></em>
</div>
<h4><?=$this->lang->line('delivery_address')?></h4>
<? if ($orderdata['same_address']=='Yes') { ?>
<? $country_zone = $this->MFuncs->getCountryZone($userdata['country_id']); ?>
<p><?=$userdata['address'].", ".$userdata['city'].", ".$userdata['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$userdata['floor'].", ".$this->lang->line('name_bell').": ".$userdata['name_bell']?></p>
<? }else { ?>
<? $country_zone = $this->MFuncs->getCountryZone($orderdata['country_id']); ?>
<p><?=$orderdata['address'].", ".$orderdata['city'].", ".$orderdata['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$orderdata['floor'].", ".$this->lang->line('name_bell').": ".$orderdata['name_bell']?></p>
<? } ?>
<br />
        <br />
        <div class="note">(*) <?=$this->lang->line('change_settings');?></div>
        <div class="buttons">
        <?=anchor("complete_order_2/false", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>
        	<?=anchor("complete_order_3", $this->lang->line('try_pay_again'),array('id'=>'try_again','class'=>'positive'))?>
        <?=anchor("page/cancel_order", $this->lang->line('cancel_order'),array('id'=>'back_btn','class'=>'positive'))?>
      <div style="clear:both">
        &nbsp;
      </div>
    </div>

<? } else { 
echo "There is a problem with your order...";
} ?>
</div>
</div>
</div>