NfeController::danfe()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 19
rs 9.4285
1
<?php
2
3
class NfeController extends AppController {
4
5
	public function beforeFilter(){
6
		return true;
7
   	}
8
9
   	public function gerar_danfe() {
10
   		$modulos = array();
11
   		$this->set('modulos', $modulos);
12
13
		$this->layout = 'wadmin';   		
14
   	}
15
16
   	public function danfe() {
0 ignored issues
show
Coding Style introduced by
danfe uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
17
   		require_once('nfephp/libs/NFe/DanfeNFePHP.class.php');
18
19
   		if ($_FILES['nota']['type'] != "text/xml") {
20
			$this->Session->setFlash('O arquivo deve ser do tipo xml! ', 'default');
21
            return $this->redirect('/nfe/gerar_danfe');			
22
   		}
23
24
		$arq = $_FILES["nota"]["tmp_name"];
25
26
		if ( is_file($arq) ){
27
			$docxml = file_get_contents($arq);
28
			$danfe = new DanfeNFePHP($docxml, 'P', 'A4','../images/logo.jpg','I','');
29
			$id = $danfe->montaDANFE();
30
			$imprime_danfe = $danfe->printDANFE($id . '.pdf','I');
31
		}
32
33
		unlink($arq);
34
   	}
35
36
	public function teste() {
37
		/*
38
		 * Exemplo de envio de Nfe já assinada e validada
39
		 */
40
		require_once('nfephp/libs/NFe/ToolsNFePHP.class.php');
41
		$nfe = new ToolsNFePHP;
42
		$modSOAP = '2'; //usando cURL
43
44
		//use isso, este é o modo manual voce tem mais controle sobre o que acontece
45
		$filename = 'nfephp/exemplos/xml/11101284613439000180550010000004881093997017-nfe.xml';
46
		//obter um numero de lote
47
		$lote = substr(str_replace(',', '', number_format(microtime(true)*1000000, 0)), 0, 15);
48
		// montar o array com a NFe
49
		$sNFe = file_get_contents($filename);
50
		//array vazio passado como referencia
51
		$aResp = array();
52
		debug($nfe->autoriza($sNFe, $lote, $aResp));
53
		//enviar o lote
54
		if ($resp = $nfe->autoriza($sNFe, $lote, $aResp)) {
55
		    if ($aResp['bStat']) {
56
		        echo "Numero do Recibo : " . $aResp['nRec'] .", use este numero para obter o protocolo ou informações de erro no xml com testaRecibo.php.";
57
		    } else {
58
		        echo "Houve erro !! $nfe->errMsg";
59
		    }
60
		} else {
61
		    echo "houve erro !!  $nfe->errMsg";
62
		}
63
		debug($nfe);
64
		echo '<BR><BR><h1>DEBUG DA COMUNICAÇÕO SOAP</h1><BR><BR>';
65
		echo '<PRE>';
66
		echo htmlspecialchars($nfe->soapDebug);
67
		echo '</PRE><BR>';
68
		exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method teste() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
69
	}
70
71
}