<?php
session_start();
require('fpdf.php');
require('cellfit.php');
require('ean13.php');
include($_SERVER[DOCUMENT_ROOT].'/kernel/conecta.php');



if( $_SESSION[user_nb_id] == '' )	$ID_USER = rand(1000,9999); else	$ID_USER = $_SESSION[user_nb_id];

define(PASTA_LOCAL,$_SERVER[DOCUMENT_ROOT].$CACTUX_CONF['path']);
$arquivo_pdf = PASTA_LOCAL.'/etiqueta_imprimir_'.$_GET[impressora].'_'.$ID_USER.'.pdf';

// echo $arquivo_pdf;

$sql_prod = selecionar('produto','prod_tx_status',"!inativo"," AND prod_nb_id = '$_GET[id]' LIMIT 1 ");
$a_prod = carrega_array($sql_prod);

// $a_prod[prod_tx_nome] = 'PRODUTO TEST0E PRODUTO TEST0E';
// $a_prod[prod_tx_codigo] = '321123';
// $a_prod[prod_tx_valorVenda] = '99,99';
// $a_atac[atac_tx_qtde] = '3';
// $a_atac[atac_tx_valor] = '99,99';


$pdf=new PDF_EAN13(L,'mm',array(76,50));
$pdf->SetMargins(0,3);
$pdf->SetAutoPageBreak(false);
$pdf->AddPage('L','','180');

$pdf->Image('../../tamarin_local/cactus/imagens/tamarin.jpg',13,2,10,0,'JPG');
$pdf->Image('../../tamarin_local/cactus/imagens/tamarin.jpg',53,2,10,0,'JPG');
$pdf->Ln(10);
// if(strlen($a_prod[prod_tx_nome])<31){
	$pdf->SetFont('Arial','B',13);
	$pdf->CellFitScale(38,5,$a_prod[prod_tx_nome],0,0,'');

	$pdf->SetFont('Arial','B',13);
	$pdf->CellFitScale(38,5,$a_prod[prod_tx_nome],0,1,'');
	
	$pdf->SetFont('Arial','B',7);
	$pdf->Ln(10);
// }else{
// 	$pdf->SetFont('Arial','B',7);
// 	$pdf->Cell(38,5,substr($a_prod[prod_tx_nome],0,30),0,0,'');
// 	$pdf->Cell(38,5,substr($a_prod[prod_tx_nome],0,30),0,1,'');

// 	$pdf->SetFont('Arial','B',7);
// 	$pdf->Cell(40,5,substr($a_prod[prod_tx_nome],30),0,0,'');
// 	$pdf->Cell(40,5,substr($a_prod[prod_tx_nome],30),0,1,'');

// 	$pdf->SetFont('Arial','B',7);
// 	$pdf->Ln(5);
// }




// $pdf->CellFitScale(38,3,'CÓD.: '.$a_prod[prod_tx_codigo],0,0,'');



// $pdf->SetFont('Arial','B',7);
// $pdf->CellFitScale(38,3,'CÓD.: '.$a_prod[prod_tx_codigo],0,1,'');


$pdf->SetFont('','',8);
$pdf->CellFitScale(4,10,'R$',0,0,'');
$pdf->SetFont('','',30);
$pdf->CellFitScale(15,10,($a_prod[prod_tx_valorVenda]),0,0,'');

$pdf->CellFitScale(19,10,' ',0,0,'');

$pdf->SetFont('','',8);
$pdf->CellFitScale(4,10,'R$',0,0,'');
$pdf->SetFont('','',30);
$pdf->CellFitScale(15,10,($a_prod[prod_tx_valorVenda]),0,0,'');

$pdf->CellFitScale(20,10,' ',0,0,'');



// $sql_atacado = selecionar('atacado','atac_tx_status',"!inativo"," AND atac_nb_produto = '$_GET[id]' ORDER BY atac_tx_qtde ASC LIMIT 1 ");
// $a_atac = carrega_array($sql_atacado);

// if($a_atac[atac_tx_qtde]>0){
// 	$pdf->SetFont('','',6);
// 	$pdf->SetTextColor(255,255,255);
// 	$pdf->CellFitScale(3,2,' ',0);
// 	$pdf->CellFitScale(15,3,' APARTIR DE '.intval($a_atac[atac_tx_qtde]).' UN',0,0,1,1);
// 	$pdf->SetTextColor(255,255,255);
// 	$pdf->CellFitScale(22,10,' ',0,0,'');
// 	$pdf->SetFont('','',30);
// 	$pdf->CellFitScale(15,8,($a_atac[atac_tx_valor]),0,1,1,1);
// }





$pdf->SetFillColor(0,0,0);
$pdf->SetTextColor(0,0,0);
// $pdf->SetFont('');
// $pdf->Cell(0,10,$txt_short,1,1);

// $pdf->EAN13(3,40,$a_prod[prod_tx_codbarras],6,.30);
// $pdf->EAN13(40,40,$a_prod[prod_tx_codbarras],6,.30);


$pdf->Code39(3,40,$a_prod[prod_tx_codigo],1,4);
$pdf->Code39(40,40,$a_prod[prod_tx_codigo],1,4);



// $pdf->Output();
// exit;



$pdf->Output($arquivo_pdf,'F');

$id_impressora = id_impressora();

// bat_imprime($arquivo_pdf,$id_impressora);
$comando="\"$CONFIGURA[PDFVIEWER]\" /printto \"$CONFIGURA[IMPRESSORA_ETIQUETA]\" \"$arquivo_pdf\"";
echo $comando;
exec("$comando");