<?php

if(isset($_REQUEST['cod'])&&($_REQUEST['cod']!="")) {
    
    $id = $_REQUEST['cod'];

include ('conexao.php');

$proc_m=mysqli_query($mysqli,"SELECT * FROM instituicao");
$res2m=mysqli_fetch_array($proc_m);
$autarquia=$res2m['instituicao'];
$nuit=$res2m['nuit'];
$telef=$res2m['telefone'];
$celular=$res2m['celular'];
	
$data = date('Y-m-d h:m:i');
	
$d = new DateTime("now", new DateTimeZone("Africa/Maputo"));
$data= $d->format("r");	
$d = date("d");
$m = date("m");
$ano = date("Y");



$sqlx = mysqli_query($mysqli,"SELECT * FROM imovel WHERE id='$id'");
//$ver = mysqli_fetch_array($sqlx); 

while($ver =mysqli_fetch_array($sqlx))
{ 

$agente=$ver['agente'];
$municipe=$ver['proprietario'];
$bairro=$ver['bairro'];

$image="1";

$content="  \n";
$content.=$autarquia."\n";
$content.="NUIT: ".$nuit." \n";
//$content.="Telefone: ".$telef."|".$celular."\n";
$content.="RECIBO REFERENTE A ";
if($ver['final']==1){
    $content.="Imposto Predial Autarquico Antiga Base\n";
}elseif($ver['final']==2){
    $content.="Imposto Predial Autarquico Habitacao\n";
}elseif($ver['final']==3){
    $content.="Imposto Predial Autarquico Comercio e Industria\n";
}elseif($ver['final']==4){
    $content.="Imposto Predial Autarquico Terreno para Construcao\n";
}else{
    $content.="Nao definido\n";
};
$content.="MUNICIPE: ".$municipe."\n";
$content.="BAIRRO: ".$bairro."\n";
$content.="--------------------------------";
$content.=$data." ";
$content.="Taxa                  ".number_format($ver['pago'],2)."MT\n";
$content.="Multa                  ".number_format($ver['multa'],2)."MT\n";
$content.="--------------------------------";
$content.="Total Cobrado         ".number_format($ver['pago']+$ver['multa'],2)."MT\n";
$content.="--------------------------------";
$content.="Operador: ".$agente."\n\n";
$content.="MUITO OBRIGADO \n";
$content.="Pague sempre!!\n";
$valor=$ver['pago']+$ver['multa'];
$cont.="2".$id."400,100,1";
$content.="             ".$id;
}

	$stmt = $mysqli->prepare("INSERT INTO recibos_imovel_impressos (id_pagamento,valor,agente) VALUES ('$id','$valor','$agente')");
		
	if(!$stmt->execute())
		{
			echo("<script>alert('Erro de insercao!');</script>");
		}
		else
		{
		
//you can print text and image by sending request from your website
$a = array();
//sending image entry			
$obj2->type = 1;//image
$obj2->path = 'http://mobile.cacm.co.mz/images/logo.jpg';//complete filepath on your web server; make sure that it is not big size
$obj2->align = 1;//0 if left, 1 if center, 2 if right; set left align for big size images
array_push($a,$obj2);

//sending text entry	
$obj1->type = 0;//text
$obj1->content = $content;//any string	
$obj1->bold = 1;//0 if no, 1 if yes
$obj1->align =0;//0 if left, 1 if center, 2 if right
$obj1->format = 3;//0 if normal, 1 if double Height, 2 if double Height + Width, 3 if double Width
array_push($a,$obj1);

//sending barcode entry			
$obj3->type = 2;//barcode
$obj3->value = $id;//valid barcode value
$obj3->width = 400;//valid barcode width
$obj3->height = 100;//valid barcode height
$obj3->align = 1;//0 if left, 1 if center, 2 if right
array_push($a,$obj3);
//sending QR entry			
$obj4->type = 3;//QR code
$obj4->value = '';//valid QR code value
$obj4->size = 40;//valid QR code size in mm
$obj4->align = 2;//0 if left, 1 if center, 2 if right
array_push($a,$obj4);


echo json_encode($a,JSON_FORCE_OBJECT);

//Note that same sequence will be used for printing data

echo ("<script>alert('Registado com sucesso!');window.location.href='inicio.php';</script>");
	} 
}
else {$id = "SEM INFORMACAO";}
?>
