<?=$this->tinyMce?>

<center>
  <h3>
    <?=$title?>
  </h3>
</center>
<? if ($this-> session-> flashdata('message')): ?>
<div class='warning'>
  <?=$this-> session-> flashdata('message');?>
</div>
<? endif; ?>
<? if ($order) { ?>
<div>
<h4>Order ID</h4>
<p><?=$order['id']?></p>
<table width="100%" border="0">
  <tr>
    <th>Ποσότητα</th>
    <th>Περιγραφή</th>
    <th>Τιμή</th>
    <th>Υπό-σύνολο</th>
  </tr>
  <?		$order_details = $this->MFuncs->GetOrderDetails($order['id']);
		$userdata = $this->MAdmins->getClient($order['user_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->MAdmins->getProductDetailsbyID($order_det['product_id']); 
        $product_category = $this->MAdmins->getProductCat($order_det['product_id']); 
		
        $product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']); }?>

  <tr>
    <td><?=$order_det['quantity']?></td>
    <? if ($product_sub_category) { ?>
    <td><?=$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']?></td>
    <? } else { ?>
    <td><?=$product_category_name['cat_name']."-".$product_details['name']?></td>
    <? }?>
    <td><?=number_format($order_det['price'], 2, '.', '')?></td>
    <td>&euro;
      <?=number_format($order_det['price']*$order_det['quantity'], 2, '.', '')?></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 ?>
        <? $pay_on_arrival_cost=0; ?>
        <? $can_ship=true; ?>
  <tr>
    <td colspan="2"></td>
    <td><strong>Total</strong></td>
    <td>&euro;
      <?=number_format($total, 2, '.', '')?></td>
  </tr>
<? if ($order['offer_code']!=0) { ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong>Έκπτωση</strong></td>
 <td>&euro; <?=number_format($total*$order['offer_code'], 2, '.', '')?></td>
 </tr>
 <? $total = $total - ($total*$order['offer_code']); ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong>Σύνολο</strong></td>
 <td>&euro; <?=number_format($total, 2, '.', '')?></td>
 </tr>
 <? } ?>
<? if ($order['ship_cost']!=0) { ?>
<? $ship_total = $order['ship_cost']; ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Shippment cost
            </strong></td>
          <td>&euro;
            <?=number_format($ship_total, 2, '.', '')?></td>
        </tr>
 <? if (($order['ship_dest']=='attica') || ($order['ship_dest']=='greece') || ($order['ship_dest']=='crete')) { ?>
	 <? if ($order['pay_method']=='Cash') { ?>
		 <? if ($order['ship_method']=='elta') { ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Pay cash on delivery cost
            </strong></td>
          <td>&euro;
            <?=$pay_on_arrival_cost = number_format(2.30, 2, '.', '');?></td>
        </tr>
         <? } elseif ($order['ship_method']=='courier') { ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Pay cash on delivery cost
            </strong></td>
          <td>&euro;
            <?=$pay_on_arrival_cost = number_format(5.17, 2, '.', '');?></td>
        </tr>
         <? } ?>
     <? } ?>       
 <? } ?>       
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Total
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total + $pay_on_arrival_cost?></td>
        </tr>
<? } else { ?>
        <? if ($order['same_address']=='No') { ?>
 			<? $c_id = $order['country_id']; ?>
        <? } elseif ($order['same_address']=='Yes') { ?>
            <? $c_id = $userdata['country_id']; ?>
        <? } ?>
       <? if ($c_id!='1') { ?>
       <? if ($order['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 ($order['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>
            Shippment cost
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Total
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total?></td>
        </tr>
        <? } else { ?>
		<? if (($order['ship_method']=='courier') || ($order['ship_method']=='elta')){
		   $pack_total = (ceil($bot_num/2))*0.53;
           if ($order['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($order['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($order['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($order['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($order['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($order['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   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.00), 2, '.', '');
//			   }

		   } elseif ($order['ship_dest']=='attica') { ?>
            <? $i = ceil($weight/1000); ?>
			<? if ($order['ship_method']=='courier') { ?>
            <? if ($i>35) { ?>
            <? $can_ship=false; ?>
            <? } else { ?>
            <? $can_ship=true; ?>
            <? } ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } elseif ($order['ship_method']=='elta') { ?>
            <? if ($i>20) { ?>
            <? $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost'); ?>
			<? $remaining_weight = $i - 20; ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } else { ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } ?>
            
            <? } ?>
	   
		  <? } elseif ($order['ship_dest']=='greece') { ?>
            <? $i = ceil($weight/1000); ?>
			<? if ($order['ship_method']=='courier') { ?>
            <? if ($i>35) { ?>
            <? $can_ship=false; ?>
            <? } else { ?>
            <? $can_ship=true; ?>
            <? } ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } elseif ($order['ship_method']=='elta') { ?>
            <? if ($i>20) { ?>
            <? $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost'); ?>
			<? $remaining_weight = $i - 20; ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } else { ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } ?>
            
            <? } ?>
 		  <? } elseif ($order['ship_dest']=='crete') { ?>
            <? $i = ceil($weight/1000); ?>
			<? if ($order['ship_method']=='courier') { ?>
            <? if ($i>35) { ?>
            <? $can_ship=false; ?>
            <? } else { ?>
            <? $can_ship=true; ?>
            <? } ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } elseif ($order['ship_method']=='elta') { ?>
            <? if ($i>20) { ?>
            <? $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); ?>
			<? $remaining_weight = $i - 20; ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } else { ?>
            <? $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); ?>
            <? if ($value_ship) { ?>
            <? $ship_total = number_format($value_ship['price'], 2, '.', ''); ?>
			<? } else { ?>
            <? $ship_total = number_format(0, 2, '.', ''); ?>
            <? } ?>
            <? } ?>
            
            <? } ?>
         
          
          <? } ?>
         <? if ($can_ship==false) { ?>
        <tr>
          <td colspan="1"></td>
          <td colspan="3"><strong>
            <?=$this->lang->line('cannot_ship_txt')?>
            </strong></td>
        </tr>
        <?=$ship_total=0;?>
         <? } else { ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('ship_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <? } ?>
 <? if (($order['ship_dest']=='attica') || ($order['ship_dest']=='greece') || ($order['ship_dest']=='crete')) { ?>
	 <? if ($order['pay_method']=='Cash') { ?>
		 <? if ($order['ship_method']=='elta') { ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('cash_on_delivery_total')?>
            </strong></td>
          <td>&euro;
            <?=$pay_on_arrival_cost = number_format(2.30, 2, '.', '');?></td>
        </tr>
         <? } elseif ($order['ship_method']=='courier') { ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('cash_on_delivery_total')?>
            </strong></td>
          <td>&euro;
            <?=$pay_on_arrival_cost = number_format(5.17, 2, '.', '');?></td>
        </tr>
         <? } ?>
     <? } ?>       
 <? } ?>       
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('gen_total')?>
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total + $pay_on_arrival_cost?></td>
        </tr>
        <? } elseif ($order['ship_method']=='day_delivery') {
        			   $ship_total = number_format(14.76, 2, '.', ''); ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            Shippment cost
            </strong></td>
          <td>&euro;
            <?=number_format($ship_total, 2, '.', '')?></td>
        </tr>
<?php /*?>        <tr>
          <td colspan="2"></td>
          <td><strong>
            VAT
            </strong></td>
            <? $vat_total = ($ship_total - $ship_total) + ($total - $total); ?>
          <td>&euro;
            <?=number_format($vat_total, 2, '.', '')?></td>
        </tr>
<?php */?>        <tr>
          <td colspan="2"></td>
          <td><strong>
            Total
            </strong></td>
          <td>&euro;
            <?=$gen_total = $ship_total + $total?></td>
        </tr>
        <? } ?>
        <?	} ?>
         <?	} ?>
       <?	} ?>
     </table>
<hr />
<h4>Στοιχεία Πελάτη</h4>
<p>
  <?="<strong>Όνομα</strong>: ".$userdata['fname']." ".$userdata['lname'].",<br><strong>Επικοινωνία</strong><br>Τηλέφωνο: ".$userdata['tel'].", Κινητό: ".$userdata['mob'].", E-mail: ".anchor('admin/subscribers/send_mail/'.$userdata['id'],$userdata['email'])?>
</p>
<br />
<Hr />
		<?  if (($order['ship_method']=='courier') || ($order['ship_method']=='day_delivery') || ($order['ship_method']=='elta') || ($order['ship_method']=='courier_economy') || ($order['ship_method']=='courier_express')) { ?>
<h4>Στοιχεία Παράδοσης</h4>
<br />

<? if ($order['ship_method']=='elta') { ?>
		<h4>
        Παράδοση εντός 5 ημερών μέσω των ΕΛΤΑ
      </h4>
<? } ?>
<div class="subcolumns">
  <div class="c50l">
    <div class="subcl">
      <h5>Διεύθυνση Παράδοσης</h5>
      <? if ($order['same_address']=='Yes') { ?>
      <p>
        <?=$userdata['address'].", ".$userdata['city'].", ".$userdata['postal']?>
      </p>
      <? }else { ?>
      <p>
        <?=$order['address'].", ".$order['city'].", ".$order['postal']?>
      </p>
      <? } ?>
    </div>
  </div>
  <div class="c50r">
    <div class="subcl">
      <h5>Η παραγγελία έχει αποσταλλεί?</h5>
      <? if ($order['sent']=='Yes') { ?>
      <?="<p><strong>Ναι</strong></p>"?>
      <?=anchor('admin/categories/update_sent/No/'.$order['id'],'Αλλαγή κατάστασης σε "Οχι"')?>
      <? } elseif ($order['sent']=='No') { ?>
      <?="<p><strong>Οχι</strong></p>"?>
      <?=anchor('admin/categories/update_sent/Yes/'.$order['id'],'Αλλαγή κατάστασης σε "Ναι"')?>
      <? } ?>
    </div>
  </div>
</div>
<hr />
<br />
      <? } else { ?>
<h4>Στοιχεία Παράδοσης</h4>
<br />
<div class="subcolumns">
  <div class="c50l">
    <div class="subcl">
      <h5>Παραλαβή απο την έδρα της εταιρίας</h5>
    </div>
  </div>
  <div class="c50r">
    <div class="subcl">
      <h5>Η παραγγελία έχει παραδοθεί?</h5>
      <? if ($order['sent']=='Yes') { ?>
      <?="<p><strong>Ναι</strong></p>"?>
      <?=anchor('admin/categories/update_sent/No/'.$order['id'],'Αλλαγή κατάστασης σε "Οχι"')?>
      <? } elseif ($order['sent']=='No') { ?>
      <?="<p><strong>Οχι</strong></p>"?>
      <?=anchor('admin/categories/update_sent/Yes/'.$order['id'],'Αλλαγή κατάστασης σε "Ναι"')?>
      <? } ?>
    </div>
  </div>
</div>
<hr />
<br />
      <? } ?>

<h4>Στοιχεία Πληρωμής</h4>
<br />
<div class="subcolumns">
  <div class="c50l">
    <div class="subcl">
      <h5>Τρόπος Πληρωμής</h5>
      <p>
        <? if ($order['pay_method']=='Cash') {
			echo "Αντικαταβολή κατά τη παράδοση";
		} elseif ($order['pay_method']=='Bank') {
			echo "Κατάθεση στη τράπεζα";
		} elseif ($order['pay_method']=='Credit') {
			echo "Πιστωτική Κάρτα";
		} elseif ($order['pay_method']=='PayPal') {
			echo "PayPal";
		} else {
			echo "Δεν έχει επιλεγεί λόγω μη ολοκλήρωσης παραγγελίας";
		}?>
      </p>
    </div>
  </div>
  <div class="c50r">
    <div class="subcl">
      <h5>Η πληρωμή έχει ολοκληρωθεί?</h5>
      <? if ($order['payed']=='Yes') { ?>
      <?="<p><strong>Ναι</strong></p>"?>
      <?=anchor('admin/categories/update_payed/No/'.$order['id'],'Αλλαγή κατάστασης σε "Οχι"')?>
      <? } elseif ($order['payed']=='No') { ?>
      <?="<p><strong>Οχι</strong></p>"?>
      <?=anchor('admin/categories/update_payed/Yes/'.$order['id'],'Αλλαγή κατάστασης σε "Ναι"')?>
      <? } ?>
    </div>
  </div>
</div>
<br />
<? } else { 
echo "There is a problem with your order...";
} ?>
