|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once(ROOT . DS . 'vendor' . DS . 'autoload.php'); |
|
4
|
|
|
|
|
5
|
|
|
use Dompdf\Dompdf; |
|
6
|
|
|
|
|
7
|
|
|
class OrcamentoController extends AppController |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
View Code Duplication |
public function listar_cadastros() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->layout = 'wadmin'; |
|
13
|
|
|
|
|
14
|
|
|
$this->loadModel('Venda'); |
|
15
|
|
|
|
|
16
|
|
|
$this->set('vendas', $this->Venda->find('all', |
|
17
|
|
|
array('conditions' => |
|
18
|
|
|
array( |
|
19
|
|
|
'ativo' => 1, |
|
20
|
|
|
'id_usuario' => $this->instancia, |
|
21
|
|
|
'orcamento' => 1 |
|
22
|
|
|
) |
|
23
|
|
|
) |
|
24
|
|
|
) |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function salvar_orcamento() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->layout = 'wadmin'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function pdf($vendaId) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->loadModel('Venda'); |
|
36
|
|
|
$this->loadModel('VendaItensProduto'); |
|
37
|
|
|
|
|
38
|
|
|
$dompdf = new Dompdf(); |
|
39
|
|
|
|
|
40
|
|
|
$dadosVenda = $this->Venda->find('all', |
|
41
|
|
|
array('conditions' => |
|
42
|
|
|
array( |
|
43
|
|
|
'Venda.id' => $vendaId |
|
44
|
|
|
) |
|
45
|
|
|
) |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$produtosVenda = $this->VendaItensProduto->find('all', |
|
49
|
|
|
array('conditions' => |
|
50
|
|
|
array( |
|
51
|
|
|
'VendaItensProduto.venda_id' => $vendaId |
|
52
|
|
|
) |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$html = $this->pegar_venda_como_html($dadosVenda, $produtosVenda); |
|
57
|
|
|
|
|
58
|
|
|
$dompdf->loadHtml($html); |
|
59
|
|
|
|
|
60
|
|
|
$dompdf->setPaper('A4'); |
|
61
|
|
|
|
|
62
|
|
|
$dompdf->render(); |
|
63
|
|
|
|
|
64
|
|
|
$dompdf->stream(); |
|
65
|
|
|
|
|
66
|
|
|
exit; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function pegar_venda_como_html($dadosVenda, $produtosVenda) |
|
70
|
|
|
{ |
|
71
|
|
|
$html = ''; |
|
72
|
|
|
$html .= '<html>'; |
|
73
|
|
|
$html .= '<head>'; |
|
74
|
|
|
$html .= ' <title></title>'; |
|
75
|
|
|
$html .= '</head>'; |
|
76
|
|
|
$html .= '<body>'; |
|
77
|
|
|
$html .= ''; |
|
78
|
|
|
$html .= ' <table style="background-color: #cacaca;" width="100%" valign="center" align="center">'; |
|
79
|
|
|
$html .= ' <tr align="center">'; |
|
80
|
|
|
$html .= ' <td>'; |
|
81
|
|
|
$html .= ' <h2>Orçamento Pedido #' . $dadosVenda[0]['Venda']['id'] . '</h2>'; |
|
82
|
|
|
$html .= ' </td>'; |
|
83
|
|
|
$html .= ' </tr> '; |
|
84
|
|
|
$html .= ' </table>'; |
|
85
|
|
|
$html .= ' <br>'; |
|
86
|
|
|
$html .= ' <table width="100%" valign="center" align="center">'; |
|
87
|
|
|
$html .= ' <tr style="background-color: #ccc;">'; |
|
88
|
|
|
$html .= ' <td>Total: </td>'; |
|
89
|
|
|
$html .= ' <td>R$ ' . number_format($dadosVenda[0]['Venda']['valor'], 2, ',', '.') . '</td>'; |
|
90
|
|
|
$html .= ' </tr>'; |
|
91
|
|
|
$html .= ' <tr style="background-color: #ccc;">'; |
|
92
|
|
|
$html .= ' <td>Valor a Pagar: </td>'; |
|
93
|
|
|
$html .= ' <td>R$ ' . number_format($dadosVenda[0]['Venda']['valor'], 2, ',', '.') . '</td>'; |
|
94
|
|
|
$html .= ' </tr>'; |
|
95
|
|
|
$html .= ' </table>'; |
|
96
|
|
|
$html .= ' <br>'; |
|
97
|
|
|
$html .= ' <table width="100%" valign="center" align="center">'; |
|
98
|
|
|
$html .= ' <tr style="background-color: #cacaca;" align="center">'; |
|
99
|
|
|
$html .= ' <td>'; |
|
100
|
|
|
$html .= ' <h2>Produtos</h2>'; |
|
101
|
|
|
$html .= ' </td>'; |
|
102
|
|
|
$html .= ' </tr> '; |
|
103
|
|
|
$html .= ' </table>'; |
|
104
|
|
|
$html .= ' <br>'; |
|
105
|
|
|
$html .= ' <table width="100%" valign="center" align="center">'; |
|
106
|
|
|
$html .= ' <tr>'; |
|
107
|
|
|
$html .= ' <td>'; |
|
108
|
|
|
$html .= ' <table width="100%" valign="center" align="center">'; |
|
109
|
|
|
$html .= ' <tr style="background-color: #cacaca;">'; |
|
110
|
|
|
$html .= ' <td>Nome Produto</td>'; |
|
111
|
|
|
$html .= ' <td>Quantidade</td>'; |
|
112
|
|
|
$html .= ' <td>Valor</td>'; |
|
113
|
|
|
$html .= ' </tr>'; |
|
114
|
|
|
$html .= ''; |
|
115
|
|
|
$desconto = 0; |
|
116
|
|
|
foreach ($produtosVenda as $i => $produto) { |
|
117
|
|
|
$produtoInfos = $this->getInfoProdutos($produto['VendaItensProduto']['produto_id']); |
|
118
|
|
|
|
|
119
|
|
|
$total = $produtoInfos['Produto']['preco'] * $produto['VendaItensProduto']['quantidade_produto']; |
|
120
|
|
|
$total = number_format($total, 2, ',', '.'); |
|
121
|
|
|
|
|
122
|
|
|
$html .= ' <tr>'; |
|
123
|
|
|
$html .= ' <td>' . $produtoInfos['Produto']['nome'] . '</td>'; |
|
124
|
|
|
$html .= ' <td>' . $produto['VendaItensProduto']['quantidade_produto'] . '</td>'; |
|
125
|
|
|
$html .= ' <td>R$ ' . $total . '</td>'; |
|
126
|
|
|
$html .= ' </tr>'; |
|
127
|
|
|
} |
|
128
|
|
|
$html .= ' </table>'; |
|
129
|
|
|
$html .= ' </td>'; |
|
130
|
|
|
$html .= ' </tr>'; |
|
131
|
|
|
$html .= ' </table>'; |
|
132
|
|
|
$html .= ' <br>'; |
|
133
|
|
|
/* $html .= ' <table width="100%" valign="center" align="center">'; |
|
134
|
|
|
$html .= ' <tr style="background-color: #ccc;">'; |
|
135
|
|
|
$html .= ' <td>Total: </td>'; |
|
136
|
|
|
$html .= ' <td>R$ ' . number_format($desconto, 2, ',', '.') . '</td>'; |
|
137
|
|
|
$html .= ' </tr>'; |
|
138
|
|
|
$html .= ' </table>'; */ |
|
139
|
|
|
$html .= ''; |
|
140
|
|
|
$html .= '</body>'; |
|
141
|
|
|
$html .= '</html>'; |
|
142
|
|
|
|
|
143
|
|
|
return $html; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getInfoProdutos($produtoId) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->loadModel('Produto'); |
|
149
|
|
|
|
|
150
|
|
|
$response = $this->Produto->find('first', |
|
151
|
|
|
array('conditions' => array( |
|
152
|
|
|
'Produto.id' => $produtoId |
|
153
|
|
|
) |
|
154
|
|
|
) |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
return $response; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
} |
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
exitexpression 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.