<?php
	$this->load->library('printer');
	$this->load->library('enletras');
	
	$phpPrinter = new Printer();
	$phpInletters = new EnLetras();
	
	$phpPrinter->resetAcum();
	$acum = 0;
	
	/*Init*/
	switch($copias):
		case "0":
			$printer = printer_open("LR2000");
		break;
		case "1":
			$printer = printer_open("LR2000");
		break;
		case "2":
			$printer = printer_open("LR2000");
		break;
	endswitch;

	printer_set_option($printer, PRINTER_MODE, 'RAW');

	printer_start_doc($printer, 'Ticket Numero: '.$doc_numero);

	printer_start_page($printer);
	
	/*Body*/
	
	$font = printer_create_font('Arial', 23, 13, PRINTER_FW_THIN, false, false, false, 0);	
	printer_select_font($printer, $font);
	
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode($nombre_empresa)),28),1,$printer,$acum,13,23);
	
	printer_delete_font($font);
	
	$font = printer_create_font('Arial', 23, 13, PRINTER_FW_THIN, false, false, false, 0);	
	printer_select_font($printer, $font);
	
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode($rsocial_empresa)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode($direcion_empresa)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('NRC: '.$nrc_empresa)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('NIT: '.$nit_empresa)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('Autorizacion segun Resolucion')),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('No '.$doc_resolucion)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('Del '.$doc_desde)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('Al '.$doc_hasta)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(utf8_decode('TICKET '.$doc_numero),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('Caja: '.$caja)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('Vendedor: '.$vendedor)),28),1,$printer,$acum,13,23);
	
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString(strtoupper(utf8_decode('fecha: ')),2,$printer,$acum,13,23,0);
	$phpPrinter->printString(strtoupper(utf8_decode($fecha)),2,$printer,$acum,13,0,80);
	
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString(strtoupper(utf8_decode('Cant')),2,$printer,$acum,13,23,0);
	$phpPrinter->printString(strtoupper(utf8_decode('Desc')),2,$printer,$acum,13,0,100);
	$phpPrinter->printString(strtoupper(utf8_decode('P/U')),2,$printer,$acum,13,0,300);
	$phpPrinter->printString(strtoupper(utf8_decode('Total')),2,$printer,$acum,13,0,400);
	
	$phpPrinter->tabPrinter($acum,10);
	
	foreach($productos_normal as $producto){
		$phpPrinter->printString(number_format($producto->cant,1),2,$printer,$acum,13,23,0);
		$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode(addslashes($producto->desc))),12),2,$printer,$acum,13,0,75,23);
		$phpPrinter->printString(number_format($producto->costo,2),2,$printer,$acum,13,0,380);
		$phpPrinter->printString(number_format($producto->cant * $producto->costo,2),2,$printer,$acum,13,0,450);
		$phpPrinter->tabPrinter($acum,5);
	}
	$phpPrinter->printString("______________________________",2,$printer,$acum,13,23,0);
	$phpPrinter->printString("G=Gravado E=Exento NS=No Sujeto",2,$printer,$acum,13,23,0);
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString(strtoupper(utf8_decode('TOTAL GRAVADO')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString($totales['totalGrabadas'],2,$printer,$acum,13,0,380);
	$phpPrinter->printString(strtoupper(utf8_decode('TOTAL EXENTO')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString($totales['totalExento'],2,$printer,$acum,13,0,380);
	$phpPrinter->printString(strtoupper(utf8_decode('TOTAL NO SUJETO')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString($totales['totalNS'],2,$printer,$acum,13,0,380);
	$phpPrinter->printString(strtoupper(utf8_decode('TOTAL')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString($totales['totalTotal'],2,$printer,$acum,13,0,380);
	$phpPrinter->printString(strtoupper(utf8_decode('EFECTIVO')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString($efectivo,2,$printer,$acum,13,0,380);
	$phpPrinter->printString(strtoupper(utf8_decode('CAMBIO')),2,$printer,$acum,13,23,50);
	$phpPrinter->printString(($efectivo - $totales['totalTotal']),2,$printer,$acum,13,0,380);
	
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('F:__________________________')),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode($cliente)),28),1,$printer,$acum,13,23);

	if($dui_cliente!=""):
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('DUI: '.$dui_cliente)),28),1,$printer,$acum,13,23);
	endif;
	if($nit_cliente!=""):
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('NIT: '.$nit_cliente)),28),1,$printer,$acum,13,23);
	endif;
	if($nrc_cliente!=""):
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode('NRC: '.$nrc_cliente)),28),1,$printer,$acum,13,23);
	endif;
	$phpPrinter->tabPrinter($acum,23);
	
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode($mensaje_ticket)),28),1,$printer,$acum,13,23);
	$phpPrinter->printString($phpPrinter->cutString(strtoupper(utf8_decode("Ref:".$referencia)),28),1,$printer,$acum,13,23);
	
	printer_delete_font($font);
	
	printer_end_page($printer);

	printer_end_doc($printer);

	printer_close($printer);
?>