<?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.'/impressao/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);


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

$pdf->SetFont('Arial','B',13);
$pdf->CellFitScale(0,5,$a_prod[prod_tx_nome],0,1,'');

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

$pdf->Ln(2);
$pdf->SetFont('','',8);
$pdf->CellFitScale(4,10,'R$',0,0,'');
$pdf->SetFont('','',30);
$pdf->CellFitScale(15,10,mostra_valor($a_prod[prod_tx_valorVenda]),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(25,3,' APARTIR DE '.intval($a_atac[atac_tx_qtde]).' UN R$',0,1,1,1);
	$pdf->CellFitScale(22,10,' ',0,0,'');
	$pdf->SetFont('','',30);
	$pdf->CellFitScale(25,8,mostra_valor($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(5,25,$a_prod[prod_tx_codbarras],8,.40);

//-----------------

$pdf->Ln(30);
$pdf->SetFont('Arial','B',13);
$pdf->CellFitScale(0,5,$a_prod[prod_tx_nome],0,1,'');

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

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

if($a_atac[atac_tx_qtde]>0){
	$pdf->SetFont('','',6);
	$pdf->SetTextColor(255,255,255);
	$pdf->CellFitScale(3,2,' ',0);
	$pdf->CellFitScale(25,3,' APARTIR DE '.intval($a_atac[atac_tx_qtde]).' UN R$',0,1,1,1);
	$pdf->CellFitScale(22,10,' ',0,0,'');
	$pdf->SetFont('','',30);
	$pdf->CellFitScale(25,8,mostra_valor($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(5,64,$a_prod[prod_tx_codbarras],8,.40);

// $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");