public function imprimir($email = null){
//$this->firephp->error($this->input->post());
/*echo"<pre>";
print_r($this->input->post());
echo"</pre>";exit();*/
//seteo las variables
$items = $this->input->post('items');
$desc_gral = $this->input->post('descuento_gral');
if($desc_gral !='' ){
$desc_gral = $this->input->post('descuento_gral');
}
else{
$desc_gral = 0;
}
$nro = $this->input->post('nro');
$subtotal = number_format($this->input->post('subtotal'),2,'.',' '); $empresa = $this->empresas->empresa_usuario($this->session->userdata('ba_id_empresa'));
$cliente = $this->clientes->searchPk($this->input->post('cliente_id'));
$entrega = $this->clientes_direcciones->searchPk($this->input->post('id_cliente_entrega'));
$pais_e = $this->pais->searchPk($entrega['pais_id']);
$facturacion = $this->clientes_direcciones->searchPk($this->input->post('id_cliente_facturacion'));
$pais_f = $this->pais->searchPk($facturacion['pais_id']);
require_once(APPPATH.'libraries/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'es');
//$html = $this->load->view('presupuestos/imprimir',true);
//$this->firephp->info($html2pdf->getHtmlFromPage($html));
$html = '<!DOCTYPE html>';
$html .= '<head>
<link href="'.base_url('assets/css/bootstrap.css').'" rel="stylesheet" type="text/css" />
<link href="'.base_url('assets/css/styling.css').'" rel="stylesheet" type="text/css" />
<link href="'.base_url('assets/css/stylesheet.css').'" rel="stylesheet" type="text/css" />
<link href="'.base_url('assets/css/mystyles.css').'" rel="stylesheet" type="text/css" />';
$html .= '</head>
<html lang="en">
<body class="smw">
<div class="content">
<div class="invoice">
<table style="border:none">
<tr>
<td colspan="3" style="border:none">
<h1 style="color: #42536D;font-size: 30px;line-height: 34px;margin: 0;">Presupuesto #'.$nro.'</h1>
<span style="color: #333333;display: block;font-size: 12px;font-weight: bold;line-height: 16px;margin-bottom: 50px;">Fecha: '.$this->input->post('fecha').'</span>
</td>
</tr>
<tr>
<td style="border:none">
<div class="span3">
<h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Domicilio Entrega</h4>
<address>
<strong>'.$cliente['nombre'].'</strong><br>
'.$entrega['direccion'].'<br>
'.$entrega['ciudad'].', '.$entrega['provincia'].' '.$entrega['cp'].' '.$pais_e['nombre'].'<br>
<span title="Phone">P:</span> '.$cliente['telefono'].'
</address>
</div>
</td>
<td style="border:none">
<div class="span3">
<h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Domicilio Facturación</h4>
<address>
<strong>'.$cliente['nombre'].'</strong><br>
'.$facturacion['direccion'].'<br>
'.$facturacion['ciudad'].', '.$facturacion['provincia'].' '.$facturacion['cp'].' '.$pais_f['nombre'].'<br>
<span title="Phone">P:</span> '.$cliente['telefono'].'
</address>
</div>
</td>
<td style="border:none">
<div class="span3">
<h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Empresa</h4>
<address>
<strong>'.$empresa[0]['nombre'].'</strong><br>
'.$empresa[0]['direccion'].'<br>
'.$empresa[0]['ciudad'].', '.$empresa[0]['provincia'].' ('.$empresa[0]['cp'].') '.$empresa[0]['pais'].'<br>
<span>Tel:</span> '.$empresa[0]['telefono'].'<br/>
Presupuestó: <strong>'.$this->session->userdata('ba_fullname').'</strong>
</address>
</div>
</td>
</tr>
<tr>
<td colspan="3" style="border:none"><h3 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Detalle</h3></td>
</tr>
<tr style="width:600px">
<td style="width:600px" colspan="3" style="border:none;width:600px;" >
<table style="width:600px" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th width="20%">Familia</th>
<th width="55%"></th>
<th width="5%">Cantidad</th>
<th width="10%">Descuento (%)</th>
<th width="10%">Importe</th>
</tr>
</thead>
<tbody>';
$total_item = count($items['item_id']); for($i = 0; $i < $total_item; $i++){
$html .= '<tr>
<td>'.$items['nombre'][$i].'</td>
<td>'.$items['descripcion'][$i].'</td>
<td>'.$items['cantidad'][$i].'</td>
<td style"text-align:right">'.$items['descuento'][$i].'</td>
<td style"text-align:right">'.number_format($items['precio'][$i],2,',','.').'</td> </tr>';
}
$html .= '
<tr>
<td colspan="3" style="border:none"></td>
<td colspan="2" style="border:none">
<p><strong><span>Subtotal:</span> <span>'.number_format($subtotal,2,',','.').'</span> € </strong></p> <p><strong><span>Descuento Gral (%): '.$desc_gral.' %</span></strong></p>
<p><strong><span>Total:</span> <span>'.number_format($total,2,',','.').'</span> € </strong></p> </td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>';
if($email){
try
{
$this->load->helper('date');
$html2pdf->writeHTML($html);
/*$content_PDF = $html2pdf->Output('', true);
return $content_PDF;*/
$nombre = APPPATH.'third_party/presupuesto_'.$this->session->userdata('ba_id_empresa').'_'.$cliente['clientes_id'].'_'.now();
$html2pdf->Output($nombre.'.pdf', 'F');
return $nombre;
}
catch(HTML2PDF_exception $e) {
echo $e;
}
}
else{
try
{
$html2pdf->writeHTML($html);
$html2pdf->Output('my_doc.pdf');
}
catch(HTML2PDF_exception $e) {
echo $e;
}
}
}