<?
class carrito 
{
   //atributos de la clase
   var $num_prod;
   var $array_id_prod;
   var $array_cars;


   function carrito () 
   {
      $this->num_prod=0;
   }
	
   function ins_car($id_prod,$cod_rentacar,$desc_rentacar,$cod_regiao,$desc_regiao,$cod_categoria,$desc_categoria,$cod_grupo,$desc_grupo,$cod_pick_up_location,$desc_pick_up_location,$address_pick_up,$pick_up_full_data,$pick_up_data,$pick_up_hour,$pick_up_min,$cod_region_dest,$desc_region_dest,$cod_drop_off_location,$desc_drop_off_location,$address_drop_off,$drop_off_full_data,$drop_off_data,$drop_off_hour,$drop_off_min,$nro_dias,$cod_extra1,$desc_extra1,$quantity_extra1,$price_day_extra1,$price_total_extra1,$cod_extra2,$desc_extra2,$quantity_extra2,$price_day_extra2,$price_total_extra2,$cod_extra3,$desc_extra3,$quantity_extra3,$price_day_extra3,$price_total_extra3,$cod_extra4,$desc_extra4,$quantity_extra4,$price_day_extra4,$price_total_extra4,$cod_extra5,$desc_extra5,$quantity_extra5,$price_day_extra5,$price_total_extra5,$cod_extra_fh,$desc_extra_fh,$price_extra_fh,$price_total_extra_fh, $desc_extra_inc1,$desc_extra_inc2,$desc_extra_inc3,$desc_extra_inc4,$desc_extra_inc5,$desc_extra_inc6,$desc_extra_inc7,$desc_extra_inc8,$desc_extra_inc9,$desc_extra_inc10,$desc_extra_inc11,$desc_extra_inc12,$commission,$price_day,$price_total_day,$charged,$balance,$price_total,$trato,$nome_cliente,$nome_hotel,$nro_voo)
   {
      $this->array_id_prod[$this->num_prod][0]=$id_prod;  		
      $this->array_id_prod[$this->num_prod][1]='Car';	
      $this->array_id_prod[$this->num_prod][2]=0;      		
      $this->array_id_prod[$this->num_prod][3]=0;

      $this->array_cars[$this->num_prod][0]=$cod_rentacar;
      $this->array_cars[$this->num_prod][1]=$desc_rentacar;
      $this->array_cars[$this->num_prod][2]=$cod_regiao;
      $this->array_cars[$this->num_prod][3]=$desc_regiao;
      $this->array_cars[$this->num_prod][4]=$cod_categoria;
      $this->array_cars[$this->num_prod][5]=$desc_categoria;
      $this->array_cars[$this->num_prod][6]=$cod_grupo;
      $this->array_cars[$this->num_prod][7]=$desc_grupo;
      $this->array_cars[$this->num_prod][8]=$cod_pick_up_location;
      $this->array_cars[$this->num_prod][9]=$desc_pick_up_location;

      $this->array_cars[$this->num_prod][10]=$pick_up_full_data;
      $this->array_cars[$this->num_prod][11]=$pick_up_data;
      $this->array_cars[$this->num_prod][12]=$pick_up_hour;
      $this->array_cars[$this->num_prod][13]=$pick_up_min;

      $this->array_cars[$this->num_prod][14]=$cod_region_dest;
      $this->array_cars[$this->num_prod][15]=$desc_region_dest;
      $this->array_cars[$this->num_prod][16]=$cod_drop_off_location;
      $this->array_cars[$this->num_prod][17]=$desc_drop_off_location;

      $this->array_cars[$this->num_prod][18]=$drop_off_full_data;
      $this->array_cars[$this->num_prod][19]=$drop_off_data;
      $this->array_cars[$this->num_prod][20]=$drop_off_hour;
      $this->array_cars[$this->num_prod][21]=$drop_off_min;
      $this->array_cars[$this->num_prod][22]=$nro_dias;      

      $this->array_cars[$this->num_prod][23]=$cod_extra1;
      $this->array_cars[$this->num_prod][24]=$desc_extra1;
      $this->array_cars[$this->num_prod][25]=$quantity_extra1;
      $this->array_cars[$this->num_prod][26]=$price_day_extra1;
      $this->array_cars[$this->num_prod][27]=$price_total_extra1;

      $this->array_cars[$this->num_prod][28]=$cod_extra2;
      $this->array_cars[$this->num_prod][29]=$desc_extra2;
      $this->array_cars[$this->num_prod][30]=$quantity_extra2;
      $this->array_cars[$this->num_prod][31]=$price_day_extra2;
      $this->array_cars[$this->num_prod][32]=$price_total_extra2;

      $this->array_cars[$this->num_prod][33]=$cod_extra3;
      $this->array_cars[$this->num_prod][34]=$desc_extra3;
      $this->array_cars[$this->num_prod][35]=$quantity_extra3;
      $this->array_cars[$this->num_prod][36]=$price_day_extra3;
      $this->array_cars[$this->num_prod][37]=$price_total_extra3;

      $this->array_cars[$this->num_prod][38]=$cod_extra4;
      $this->array_cars[$this->num_prod][39]=$desc_extra4;
      $this->array_cars[$this->num_prod][40]=$quantity_extra4;
      $this->array_cars[$this->num_prod][41]=$price_day_extra4;
      $this->array_cars[$this->num_prod][42]=$price_total_extra4;

      $this->array_cars[$this->num_prod][43]=$cod_extra5;
      $this->array_cars[$this->num_prod][44]=$desc_extra5;
      $this->array_cars[$this->num_prod][45]=$quantity_extra5;
      $this->array_cars[$this->num_prod][46]=$price_day_extra5;
      $this->array_cars[$this->num_prod][47]=$price_total_extra5;

      $this->array_cars[$this->num_prod][48]=$cod_extra_fh;
      $this->array_cars[$this->num_prod][49]=$desc_extra_fh;
      $this->array_cars[$this->num_prod][50]=$price_extra_fh;
      $this->array_cars[$this->num_prod][51]=$price_total_extra_fh;

      $this->array_cars[$this->num_prod][52]=$desc_extra_inc1;
      $this->array_cars[$this->num_prod][53]=$desc_extra_inc2;

      $this->array_cars[$this->num_prod][54]=$desc_extra_inc3;
      $this->array_cars[$this->num_prod][55]=$desc_extra_inc4;

      $this->array_cars[$this->num_prod][56]=$desc_extra_inc5;
      $this->array_cars[$this->num_prod][57]=$desc_extra_inc6;

      $this->array_cars[$this->num_prod][58]=$desc_extra_inc7;
      $this->array_cars[$this->num_prod][59]=$desc_extra_inc8;

      $this->array_cars[$this->num_prod][60]=$desc_extra_inc9;
      $this->array_cars[$this->num_prod][61]=$desc_extra_inc10;

      $this->array_cars[$this->num_prod][62]=$desc_extra_inc11;
      $this->array_cars[$this->num_prod][63]=$desc_extra_inc12;

      $this->array_cars[$this->num_prod][64]=$commission;
      $this->array_cars[$this->num_prod][65]=$price_day;
      $this->array_cars[$this->num_prod][66]=$price_total_day; 

      $charged_prod = $price_total_day*$commission/100;      
      $balance_prod = $price_total - $charged_prod; 

      $this->array_cars[$this->num_prod][67]=$charged;
      $this->array_cars[$this->num_prod][68]=$balance; 
      $this->array_cars[$this->num_prod][69]=$price_total; 

      $this->array_cars[$this->num_prod][70]=$trato;
      $this->array_cars[$this->num_prod][71]=$nome_cliente;
      $this->array_cars[$this->num_prod][72]=$nome_hotel;
      $this->array_cars[$this->num_prod][73]=$nro_voo;

      $this->array_cars[$this->num_prod][74]=$address_pick_up;
      $this->array_cars[$this->num_prod][75]=$address_drop_off;           

   }

   function tem_productos()
   {
      $total   = 0;
      $charged = 0;
      $balance = 0;
      $charged_prod = 0;
      $balance_prod = 0;

      $tem_productos = 0;
      for ($i=0;$i<$this->num_prod;$i++)
      {
        if($this->array_id_prod[$i][0]!=0)
        {   
           $tem_productos = $tem_productos + 1;           
        }
      }

      return $tem_productos;
   }

   function total_charged()
   {      
      $charged = 0;      

      for ($i=0;$i<$this->num_prod;$i++)
      {
        if($this->array_id_prod[$i][0]!=0 and $this->array_id_prod[$i][1]=='Car')
        {   
           $charged += $this->array_cars[$i][67];
        }
      }

      $charged = number_format($charged,2,',','.');
      return $charged;
   }

   function total_charged_client()
   {      
      $charged = 0;      

      for ($i=0;$i<$this->num_prod;$i++)
      {
        if($this->array_id_prod[$i][0]!=0 and $this->array_id_prod[$i][1]=='Car')
        {   
           $charged += $this->array_cars[$i][67];
        }
      }

      $charged = number_format($charged,2,'.','');
      return $charged;
   }

   function imprime_carrito()
   {
      $total   = 0;
      $charged = 0;
      $balance = 0;
      $charged_prod = 0;
      $balance_prod = 0;

      echo '<table border=0 cellpadding=0 CELLSPACING=2 width=580px>
              <tr HEIGHT=25 STYLE="background-color: rgb(255,204,102); font-family: Verdana,Tahoma,Arial,Helvetica,Sans-serif,sans-serif; font-size: 11px;">
                <td width=250px align=center><b>Product</b></td>
                <td width=35px align=center><b>%</b></td>
                <td width=65px align=center><b>Charged</b></td>
                <td width=105px align=center><b>To be balanced</b></td>
                <td width=90px align=center><b>Total</b></td>
              </tr>';
			  

      $total_prod   = $this->array_cars[0][69];
      $commission   = $this->array_cars[0][64].' %';
      $charged_prod = $this->array_cars[0][67];
      $balance_prod = $this->array_cars[0][68];

      $desc_pickup  = $this->array_cars[0][9].' - '.$this->array_cars[0][3];
      $desc_dropoff = $this->array_cars[0][17].' - '.$this->array_cars[0][15];
      $data1        = $this->array_cars[0][10];
      $data2        = $this->array_cars[0][18];
      $nro_dias     = $this->array_cars[0][22];
      $dias         = '<b>Number of days:</b> '.$nro_dias;

      $descricao    = '<b>'.$this->array_cars[0][1].'</b><br>'.$this->array_cars[0][7].'<br><br>';
      $descricao    = $descricao.'<b>Pick up information:</b><br>'; 
      $descricao    = $descricao.$desc_pickup.'<br>';
      $descricao    = $descricao.$data1.'<br><br>';
      $descricao    = $descricao.'<b>Drop off information:</b><br>'; 
      $descricao    = $descricao.$desc_dropoff.'<br>';
      $descricao    = $descricao.$data2.'<br><br>';
      $descricao    = $descricao.$dias.'<br>';
      $descricao    = $descricao.'<br>';

      echo '<tr height=19 STYLE="background-color: rgb(255,251,236); font-family: Verdana,Tahoma,Arial,Helvetica,Sans-serif,sans-serif; font-size: 11px;">';
      echo "<td><p style='margin-left: 4pt;'>".$descricao."</p></td>";
      echo "<td><p style='margin-left: 2pt;'>".$commission."</p></td>";
      echo "<td align=right><p style='margin-right: 4pt;'>".number_format($charged_prod,2,',','.')." €</p></td>";
      echo "<td align=right><p style='margin-right: 4pt;'>".number_format($balance_prod,2,',','.')." €</p></td>";
      echo "<td align=right><p style='margin-right: 4pt;'>".number_format($total_prod,2,',','.')." €</p></td>";
      echo '</tr>';

      $charged += $charged_prod;
      $total   += $total_prod;           

      $balance = $total - $charged;
      $charged = number_format($charged,2,',','.');                               
      $balance = number_format($balance,2,',','.'); 
      $total   = number_format($total,2,',','.'); 
               
      echo '<tr height=19 STYLE="background-color: rgb(255,204,102); font-family: Verdana,Tahoma,Arial,Helvetica,Sans-serif,sans-serif; font-size: 11px;">';
      echo "<td><p style='margin-left: 4pt;'><b>TOTAL:</b></p></td>";
      echo "<td align=right>&nbsp;</td>";
      echo "<td align=right><p style='margin-right: 4pt;'><b>" . $charged . " €</b></p></td>";
      echo "<td align=right><p style='margin-right: 4pt;'><b>" . $balance . " €</b></p></td>";
      echo "<td align=right><p style='margin-right: 4pt;'><b>" . $total . " €</b></p></td>";
      echo '</tr>';		
      echo "</table>";
                
   }

} 

session_start();

if (!isset($_SESSION["ocarrito"]))
{
    $_SESSION["ocarrito"] = new carrito();
}

?>