<?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']);


if($_GET[id]>0){
	$extra .= " AND item_nb_id = '$_GET[id]'";
}

if($_GET[id_oferta]>0){
	$extra .= " AND item_nb_oferta = '$_GET[id_oferta]'";
}

$i=0;

$sql_prod = selecionar('itemoferta,produto','item_tx_status',"!inativo"," $extra",0,1);
while($a_prod = carrega_array($sql_prod)){
	$arquivo_pdf = PASTA_LOCAL.'/impressao/oferta_imprimir_'.$_GET[impressora].'_'.$i.'.pdf';

	$pdf=new PDF_EAN13(L,'mm',array(100,30));
	$pdf->SetMargins(5,5);
	$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(25,10,mostra_valor($a_prod[item_tx_valor],1),0,0,'');


	$pdf->SetTextColor(255,255,255);
	$pdf->SetFont('','',30);
	$pdf->CellFitScale(30,10,'OFERTA',1,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(70,15,$a_prod[prod_tx_codbarras],8,.30);
	// $pdf->Output();
	$pdf->Output($arquivo_pdf,'F');

	$id_impressora = id_impressora();

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

	$i++;

}