Ignition_NFEColaborativa - Version 0.1.0

Version Notes

Primeira versão do módulo de emissão

Download this release

Release Info

Developer Ignition Sistemas
Extension Ignition_NFEColaborativa
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Ignition/NFEColaborativa/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ignition_NFEColaborativa_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
3
+
4
+ public function __construct() {
5
+ $this->_addButton('testbutton', array(
6
+ 'label' => Mage::helper('Sales')->__('Emitir NF-e'),
7
+ 'onclick' => 'setLocation(\'' . $this->getEmitirNFEUrl() . '\')',
8
+ 'class' => 'go'
9
+ ), 0, 100, 'header', 'header');
10
+
11
+ parent::__construct();
12
+
13
+ }
14
+ public function getEmitirNFEUrl()
15
+ {
16
+ return $this->getUrl('nfecolaborativa/emissor/index');
17
+ }
18
+ }
app/code/local/Ignition/NFEColaborativa/Block/Adminhtml/Sales/Order/View/Tab/NotasEmitidas.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Block_Adminhtml_Sales_Order_View_Tab_NotasEmitidas extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface {
4
+
5
+ protected function _construct() {
6
+ parent::_construct();
7
+ $this->updateStatus();
8
+ $this->setTemplate('nfecolaborativa/NotasEmitidas.phtml');
9
+ }
10
+
11
+ public function updateStatus() {
12
+ try {
13
+ $order = $this->getOrder();
14
+ $orderID = $order->getEntityId();
15
+ $nfes = Mage::getModel("nfecolaborativa/nFEColaborativa")->getCollection()->addFieldToFilter('pedido_id', $orderID)->load();
16
+
17
+ $serverAddress = "https://www.nfecolaborativa.com.br/services/servicos/NFEService.svc?wsdl";
18
+ //$serverAddress = "https://ignition.no-ip.org:8443/nfeservices/servicos/NFEService.svc?wsdl";
19
+
20
+ $client = $this->createSoapClient($serverAddress);
21
+
22
+ foreach ($nfes as $_item) {
23
+ $this->updateStatusNFE($_item, $client);
24
+ }
25
+ } catch (Exception $ex) {
26
+
27
+ }
28
+ }
29
+
30
+ public function createSoapClient($serverAddress) {
31
+
32
+ //$client = new SoapClient($serverAddress, array("trace" => 0, "soap_version" => SOAP_1_1, "cache_wsdl" => WSDL_CACHE_NONE));
33
+ $client = new SoapClient($serverAddress, array("trace" => 0, "soap_version" => SOAP_1_1));
34
+
35
+ $username = Mage::getStoreConfig('nfecolaborativa/general/usuario_nfecolaborativa'); //value ;
36
+ $password = Mage::getStoreConfig('nfecolaborativa/general/senha_nfecolaborativa'); //value "tapsol";
37
+ $header = new WsseAuthHeader($username, $password);
38
+
39
+ $client->__setSoapHeaders(array($header));
40
+ return $client;
41
+ }
42
+
43
+ public function updateStatusNFE($NFE, $SoapClient) {
44
+
45
+
46
+ $nfeID = $NFE->getNotaServidorId();
47
+ $par = new stdClass();
48
+ $par->ID = $nfeID;
49
+
50
+ $serviceCall = $SoapClient->GetNFEByID($par);
51
+ $resumoNFE = $serviceCall->GetNFEByIDResult;
52
+
53
+ $NFE->
54
+ setCodigoNumericoSequencial($resumoNFE->NumeroDocumento)->
55
+ setSerie($resumoNFE->Serie)->
56
+ setChaveAcesso($resumoNFE->ChaveAcesso)->
57
+ setDescricaoStatus($resumoNFE->DescricaoStatus)->
58
+ save();
59
+ }
60
+
61
+ /**
62
+ * Retrieve order model instance
63
+ *
64
+ * @return Mage_Sales_Model_Order
65
+ */
66
+ public function getOrder() {
67
+ return Mage::registry('current_order');
68
+ }
69
+
70
+ /**
71
+ * Retrieve source model instance
72
+ *
73
+ * @return Mage_Sales_Model_Order
74
+ */
75
+ public function getSource() {
76
+ return $this->getOrder();
77
+ }
78
+
79
+ /**
80
+ * ######################## TAB settings #################################
81
+ */
82
+ public function getTabLabel() {
83
+ return Mage::helper('sales')->__('Notas Emitidas');
84
+ }
85
+
86
+ public function getTabTitle() {
87
+ return Mage::helper('sales')->__('Notas Emitidas');
88
+ }
89
+
90
+ public function canShowTab() {
91
+ return true;
92
+ }
93
+
94
+ public function isHidden() {
95
+ return false;
96
+ }
97
+
98
+ }
99
+
100
+ class WsseAuthHeader extends SoapHeader {
101
+
102
+ private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
103
+
104
+ function __construct($user, $pass, $ns = null) {
105
+ if ($ns) {
106
+ $this->wss_ns = $ns;
107
+ }
108
+
109
+ $auth = new stdClass();
110
+
111
+ $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
112
+ $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
113
+ $username_token = new stdClass();
114
+ $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
115
+ $security_sv = new SoapVar(
116
+ new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
117
+ SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
118
+
119
+ parent::__construct($this->wss_ns, 'Security', $security_sv, true);
120
+ }
121
+
122
+ }
123
+
app/code/local/Ignition/NFEColaborativa/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Ignition/NFEColaborativa/Model/Mysql4/NFEColaborativa.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Model_Mysql4_NFEColaborativa extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the nfecolaborativa_id refers to the key field in your database table.
8
+ $this->_init('nfecolaborativa/nfecolaborativa', 'nota_id');
9
+ }
10
+ }
app/code/local/Ignition/NFEColaborativa/Model/Mysql4/NFEColaborativa/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Model_Mysql4_NFEColaborativa_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('nfecolaborativa/nfecolaborativa');
9
+ }
10
+ }
app/code/local/Ignition/NFEColaborativa/Model/NFEColaborativa.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Model_NFEColaborativa extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('nfecolaborativa/nFEColaborativa');
9
+ }
10
+ }
app/code/local/Ignition/NFEColaborativa/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('nfecolaborativa')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('nfecolaborativa')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/local/Ignition/NFEColaborativa/controllers/EmissorController.php ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ignition_NFEColaborativa_EmissorController extends Mage_Adminhtml_Controller_Action {
4
+
5
+ protected function _initAction() {
6
+ $this->_title($this->__('Nova NF-e'));
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('sales/order');
9
+ //->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction() {
15
+ $invoice = $this->_initAction();
16
+
17
+
18
+ // Injection
19
+ $block = $this->getLayout()->createBlock(
20
+ 'Mage_Core_Block_Template', 'my_block_name_here', array('template' => 'nfecolaborativa/EmitirNFE.phtml')
21
+ );
22
+ $layout = $this->getLayout()->getBlock('content')->append($block);
23
+
24
+ //Release layout stream
25
+ $this->renderLayout();
26
+ }
27
+
28
+ public function downloadpageAction() {
29
+
30
+ $this->_title($this->__('Iniciando sistema de emissão'));
31
+ $this->loadLayout()
32
+ ->_setActiveMenu('sales/order');
33
+
34
+ $block = $this->getLayout()->createBlock(
35
+ 'Mage_Core_Block_Template', 'block_sucesso', array('template' => 'nfecolaborativa/SucessoEmissao.phtml')
36
+ );
37
+
38
+
39
+ $layout = $this->getLayout()->getBlock('content')->append($block);
40
+ //Release layout stream
41
+ $this->renderLayout();
42
+
43
+ //$this->_redirectUrl($url);
44
+ }
45
+
46
+ public function getOrder($OrderID) {
47
+
48
+ $order = Mage::getModel('sales/order')->load($OrderID);
49
+ return $order;
50
+ }
51
+
52
+ private function getNFEInformacaoAdicional($order, $CodigoRegimeTributario) {
53
+
54
+ $inf = new stdClass();
55
+ if ($CodigoRegimeTributario == 1) {
56
+ $inf->InformacoesComplementaresContribuinte = "DOCUMENTO EMITIDO POR ME OU EPP OPTANTE PELO SIMPLES NACIONAL.NÃO GERA DIREITO A CRÉDITO FISCAL DE ICMS, DE ISS E DE IPI";
57
+ }
58
+ return $inf;
59
+ }
60
+
61
+ private function getNFEIdentificacao($NFEColaborativaEmitente) {
62
+
63
+ $Ident = new stdClass();
64
+ $Ident->NaturezaOperacao = "venda";
65
+ $Ident->IndicadorFormaPagamento = 1;
66
+ $Ident->CodigoModeloDocumentoFiscal = "55";
67
+ $Ident->DataEmissao = date('c');
68
+ $Ident->TipoEmissaoNFE = 1;
69
+ $Ident->TipoOperacao = 1;
70
+ $Ident->AmbienteEmissao = 1;
71
+ $Ident->FinalidadeEmissao = 1;
72
+ $Ident->FormatoImpressaoDANFE = 1;
73
+ $Ident->IndicadorFormaPagamento = 0;
74
+ $Ident->ProcessoEmissao = 0;
75
+ $Ident->VersaoProcessoEmissao = "1.00";
76
+ if (is_null($NFEColaborativaEmitente) == false) {
77
+ $Ident->CodigoMunicipio = $NFEColaborativaEmitente->CodigoMunicipioIBGE;
78
+ $Ident->CodigoUF = $NFEColaborativaEmitente->CodigoUF;
79
+ }
80
+ //
81
+ //$Ident->CodigoMunicipio
82
+ //$Ident->CodigoUF
83
+ return $Ident;
84
+ }
85
+
86
+ public function getNFEColaborativaEmitente() {
87
+
88
+ //$address = "https://ignition.no-ip.org:8443/nfeservices/servicos/EmitenteService.svc?wsdl";
89
+ $address = "https://www.nfecolaborativa.com.br/services/servicos/EmitenteService.svc?wsdl";
90
+ $client = $this->createSoapClient($address, true);
91
+
92
+
93
+
94
+ $cnpj = Mage::getStoreConfig('nfecolaborativa/general/cnpj_emitente');
95
+ $search = array(".", ",", "/", "-", "\\");
96
+ $cnpj = str_replace($search, "", $cnpj);
97
+
98
+ $par = new stdClass();
99
+ $par->CNPJ = $cnpj;
100
+ $result = $client->GetEmitenteByCNPJ($par);
101
+
102
+ return $result->GetEmitenteByCNPJResult;
103
+ }
104
+
105
+ public function getNFEEmitente($EmitenteReferencia) {
106
+
107
+ $emitenteEncontrado = $EmitenteReferencia;
108
+ $emit = new stdClass();
109
+ $emit->CNPJ = $emitenteEncontrado->CNPJ;
110
+
111
+ $emit->CodigoRegimeTributario = $emitenteEncontrado->CodigoRegimeTributario;
112
+ $emit->InscricaoEstadual = $emitenteEncontrado->InscricaoEstadual;
113
+ $emit->Nome = $emitenteEncontrado->Nome;
114
+ $emit->NomeFantasia = $emitenteEncontrado->NomeFantasia;
115
+ $emit->Nome = $emitenteEncontrado->Nome_RazaoSocial;
116
+
117
+ $endereco = new stdClass();
118
+
119
+ $endereco->Bairro = $emitenteEncontrado->Bairro;
120
+ $endereco->CEP = $emitenteEncontrado->CEP;
121
+ $endereco->Complemento = $emitenteEncontrado->Complemento;
122
+ $endereco->Logradouro = $emitenteEncontrado->Logradouro;
123
+ $endereco->Numero = $emitenteEncontrado->NumeroMetrico;
124
+ $endereco->Telefone = $emitenteEncontrado->Telefone;
125
+ $endereco->CodigoMunicipio = $emitenteEncontrado->CodigoMunicipioIBGE;
126
+
127
+ $emit->EnderecoEmitente = new SoapVar($endereco, SOAP_ENC_OBJECT,
128
+ 'EnderecoEmitente',
129
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Emitente');
130
+
131
+
132
+ return $emit;
133
+ }
134
+
135
+ public function getLocation($CEP) {
136
+
137
+ $serverAddress = 'https://www.nfecolaborativa.com.br/services/shared/LocationSharedService.svc?wsdl';
138
+ $client = $this->createSoapClient($serverAddress, false);
139
+ $parCEP = new stdClass();
140
+ $parCEP->CEP = $CEP;
141
+ $location = $client->ParseLocation($parCEP)->ParseLocationResult;
142
+ return $location;
143
+ }
144
+
145
+ public function getNFEProdutos($order, $post, $CodigoRegimeTributario) {
146
+ $items = $order->getAllItems();
147
+ $cont = 0;
148
+ $lista_produtos = array();
149
+ foreach ($items as $itemId => $item) {
150
+ $produtoCompilado = $this->getNFEProduto($item, $post, $CodigoRegimeTributario);
151
+ $lista_produtos[$cont] = $produtoCompilado;
152
+ $cont++;
153
+ }
154
+
155
+ return $lista_produtos;
156
+ }
157
+
158
+ public function getNFEProduto($product, $post, $CodigoRegimeTributario) {
159
+ $produto = new stdClass();
160
+ $mage_prod = Mage::getModel('catalog/product')->load($product['product_id']);
161
+ $valor = $product->getPrice();
162
+ $qtde = $product->getQtyToInvoice();
163
+
164
+ $cfop = $post[produtos][$product->getItemId()][cfop];
165
+ $ncm = $post[produtos][$product->getItemId()][ncm];
166
+ $tipi = $post[produtos][$product->getItemId()][tipi];
167
+ $codigoBarras = $post[produtos][$product->getItemId()][ean];
168
+ //$codigoBarras = $mage_prod->getData('codigo_ean');
169
+ if (is_null($codigoBarras) == false) {
170
+ $produto->CodigoBarras = $codigoBarras;
171
+ $produto->CodigoBarrasTributavel = $codigoBarras;
172
+ } else {
173
+ $produto->CodigoBarras = "";
174
+ $produto->CodigoBarrasTributavel = "";
175
+ }
176
+ $produto->CodigoCFOP = $cfop;
177
+
178
+ $produto->CodigoNCM = $ncm;
179
+ $produto->CodigoProduto = $product->getSku();
180
+ $produto->NomeProduto = $product->getName();
181
+ $produto->CodigoEX_TIPI = $tipi;
182
+ $produto->UnidadeComercial = 'UN';
183
+ $produto->UnidadeTributavel = 'UN';
184
+ $produto->QuantidadeComercial = $qtde;
185
+ $produto->QuantidadeTributavel = $qtde;
186
+ $produto->SomarValorProdutoNaNFE = true;
187
+ $produto->ValorTotalBruto = $qtde * $valor;
188
+
189
+ $mage_prod->setCodigoNcm($ncm)->setCodigoExtipi($tipi)->setCodigoEan($codigoBarras)->save();
190
+
191
+ $this->setTributos($produto, $CodigoRegimeTributario);
192
+
193
+ return $produto;
194
+ }
195
+
196
+ public function setTributos($NFEProduto, $CodigoRegimeTributario) {
197
+ if ($CodigoRegimeTributario == 1) {
198
+ $NFEProduto->ICMS = $this->getProdutoICMSSimples($NFEProduto, $CodigoRegimeTributario);
199
+ $NFEProduto->PIS = $this->getProdutoPISSimples($NFEProduto, $CodigoRegimeTributario);
200
+ $NFEProduto->COFINS = $this->getProdutoCOFINSSimples($NFEProduto, $CodigoRegimeTributario);
201
+ } else {
202
+ $NFEProduto->ICMS = $this->getProdutoICMSNormal($NFEProduto, $CodigoRegimeTributario);
203
+ $NFEProduto->PIS = $this->getProdutoPISNormal($NFEProduto, $CodigoRegimeTributario);
204
+ $NFEProduto->COFINS = $this->getProdutoCOFINSNormal($NFEProduto, $CodigoRegimeTributario);
205
+ }
206
+ }
207
+
208
+ public function getProdutoICMSNormal($NFEProduto, $CodigoRegimeTributario) {
209
+ $icms = new stdClass();
210
+ $icms->OrigemMercadoria = 0;
211
+ $icms->ModalidadeBaseCalculo = 0;
212
+ $icms->ValorBaseCalculo = $NFEProduto->getPrice();
213
+
214
+ $icmsCompilado = new SoapVar($icms,
215
+ SOAP_ENC_OBJECT,
216
+ 'ICMS00',
217
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.ICMS.RegimeNormal');
218
+ return $icmsCompilado;
219
+ }
220
+
221
+ public function getProdutoPISNormal($NFEProduto, $CodigoRegimeTributario) {
222
+
223
+ $pisDetalhe = new stdClass();
224
+ $pisDetalhe->CST = "06";
225
+
226
+ $pis = new stdClass();
227
+ $pis->DetalhePIS = new SoapVar($pisDetalhe,
228
+ SOAP_ENC_OBJECT,
229
+ 'PISNT',
230
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.PIS');
231
+ return $pis;
232
+ }
233
+
234
+ public function getProdutoCOFINSNormal($NFEProduto, $CodigoRegimeTributario) {
235
+ $cofinsDetalhe = new stdClass();
236
+ $cofinsDetalhe->CST = "06";
237
+
238
+ $cofins = new stdClass();
239
+ $cofins->DetalheCOFINS = new SoapVar($cofinsDetalhe,
240
+ SOAP_ENC_OBJECT,
241
+ 'COFINSNT',
242
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.COFINS');
243
+ return $cofins;
244
+ }
245
+
246
+ public function getProdutoPISSimples($NFEProduto, $CodigoRegimeTributario) {
247
+
248
+ $pisDetalhe = new stdClass();
249
+ $pisDetalhe->CST = "07";
250
+
251
+ $pis = new stdClass();
252
+ $pis->DetalhePIS = new SoapVar($pisDetalhe,
253
+ SOAP_ENC_OBJECT,
254
+ 'PISNT',
255
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.PIS');
256
+ return $pis;
257
+ }
258
+
259
+ public function getProdutoCOFINSSimples($NFEProduto, $CodigoRegimeTributario) {
260
+ $cofinsDetalhe = new stdClass();
261
+ $cofinsDetalhe->CST = "07";
262
+
263
+ $cofins = new stdClass();
264
+ $cofins->DetalheCOFINS = new SoapVar($cofinsDetalhe,
265
+ SOAP_ENC_OBJECT,
266
+ 'COFINSNT',
267
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.COFINS');
268
+ return $cofins;
269
+ }
270
+
271
+ public function getProdutoICMSSimples($NFEProduto, $CodigoRegimeTributario) {
272
+
273
+ $icms = new stdClass();
274
+ $icms->CSOSN = 102;
275
+ $icms->OrigemMercadoria = 0;
276
+ $icmsCompilado = new SoapVar($icms,
277
+ SOAP_ENC_OBJECT,
278
+ 'ICMSSN102',
279
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Produto.Tributos.ICMS.RegimeSimples');
280
+ return $icmsCompilado;
281
+ }
282
+
283
+ public function getNFEDestinatario($order) {
284
+
285
+ $customerID = $order->getCustomerId();
286
+ $billingAddress = $order->getBillingAddress();
287
+
288
+ $customer = Mage::getModel('customer/customer')->load($customerID);
289
+
290
+ $dest = new stdClass();
291
+ $dest->Nome = $billingAddress->getName();
292
+ $dest->CPF = $customer->getAttribute('taxvat')->getFrontend()->getValue($customer);
293
+ $dest->Email = $customer->getAttribute('email')->getFrontend()->getValue($customer);
294
+
295
+ $CEP = $billingAddress->getPostcode();
296
+
297
+ $endereco = new stdClass();
298
+ $endereco->Logradouro = $billingAddress->getStreet1();
299
+ $cidade = $billingAddress->getCity();
300
+
301
+ $location = $this->getLocation($CEP);
302
+
303
+ $endereco->Numero = "";
304
+ $endereco->Complemento = "";
305
+
306
+ $endereco->Bairro = $location->Bairro;
307
+ $endereco->CodigoMunicipio = $location->CodigoMunicipioIBGE;
308
+ $endereco->CEP = $CEP;
309
+ $endereco->Telefone = $billingAddress->getTelephone();
310
+
311
+
312
+ $dest->EnderecoDestinatario = new SoapVar($endereco, SOAP_ENC_OBJECT,
313
+ 'EnderecoDestinatario',
314
+ 'http://schemas.datacontract.org/2004/07/Ignition.NFE2.BLL.Internal.Destinatario');
315
+
316
+ return $dest;
317
+ }
318
+
319
+ public function getTransporte($order) {
320
+ $transporte = new stdClass();
321
+
322
+ $valorFrete = $order->getShippingAmount();
323
+ if ($valorFrete == 0) {
324
+ //Se o frete for gratuito para o cliente então
325
+ //a modalidade de frete é Por conta do Emitente
326
+ $transporte->ModalidadeFrete = 0;
327
+ } else {
328
+ //Se o frete for pago pelo cliente então
329
+ //a modalidade de frete é Por conta do Destinatário
330
+ $transporte->ModalidadeFrete = 1;
331
+ }
332
+
333
+ $transporte->Transportador = $this->getTransportador($order);
334
+
335
+ return $transporte;
336
+ }
337
+
338
+ public function getTransportador($order) {
339
+
340
+ $transportador = new stdClass();
341
+
342
+ $transportador->CNPJ = "34028316000375";
343
+ $transportador->Nome = "Empresa Brasileira de Correios e Telégrafos";
344
+
345
+ /*
346
+ $transportador->NomeMunicipio="";
347
+ $transportador->SiglaUF="";
348
+ $transportador->Logradouro="";
349
+ *
350
+ * */
351
+
352
+ return $transportador;
353
+ }
354
+
355
+ public function getProdutos($OrderID) {
356
+
357
+ }
358
+
359
+ public function createSoapClient($serverAddress, $useAuthentication) {
360
+
361
+
362
+ //$client = new SoapClient($serverAddress, array("trace" => 0, "soap_version" => SOAP_1_1, "cache_wsdl" => WSDL_CACHE_NONE));
363
+ $client = new SoapClient($serverAddress, array("trace" => 0, "soap_version" => SOAP_1_1));
364
+
365
+ if ($useAuthentication == true) {
366
+ $username = Mage::getStoreConfig('nfecolaborativa/general/usuario_nfecolaborativa'); //value ;
367
+ $password = Mage::getStoreConfig('nfecolaborativa/general/senha_nfecolaborativa'); //value "tapsol";
368
+ $header = new WsseAuthHeader($username, $password);
369
+
370
+ $client->__setSoapHeaders(array($header));
371
+ }
372
+ return $client;
373
+ }
374
+
375
+ public function saveNfe($ResumoNFE, $orderID) {
376
+ $nfeID = $ResumoNFE->ID;
377
+
378
+ $now = Mage::getModel('core/date')->timestamp(time());
379
+
380
+ $data = date('Y-m-d H:i:s', $now);
381
+
382
+ $model = Mage::getModel("nfecolaborativa/nFEColaborativa")
383
+ ->setDataEmissao($data)
384
+ ->setPedidoId($orderID)
385
+ ->setNotaServidorId($nfeID)
386
+ ->save();
387
+ }
388
+
389
+ public function saveNfeTemp($idNFE, $orderID) {
390
+ $nfeID = $idNFE;
391
+
392
+ $now = Mage::getModel('core/date')->timestamp(time());
393
+
394
+ $data = date('Y-m-d H:i:s', $now);
395
+
396
+ $model = Mage::getModel("nfecolaborativa/nFEColaborativa")
397
+ ->setDataEmissao($data)
398
+ ->setPedidoId($orderID)
399
+ ->setNotaServidorId($nfeID)
400
+ ->save();
401
+ }
402
+
403
+ public function postAction() {
404
+
405
+ $post = $this->getRequest()->getPost();
406
+
407
+ try {
408
+ if (empty($post)) {
409
+ Mage::throwException($this->__('Invalid form data.'));
410
+ }
411
+
412
+ $oID = $this->getRequest()->getParam('order_id');
413
+
414
+ $order = $this->getOrder($oID);
415
+
416
+ $emitente = $this->getNFEColaborativaEmitente();
417
+
418
+ if (is_null($emitente)) {
419
+ Mage::throwException($this->__('Não foi possível encontrar o emitente. Por favor verifique as configurações do sistema.'));
420
+ }
421
+
422
+
423
+ $par = new stdClass();
424
+
425
+ $par->NFE = new stdClass();
426
+ $par->NFE->Versao = "2.00";
427
+
428
+ if (is_null($emitente) == false) {
429
+ $par->NFE->Emitente = $this->getNFEEmitente($emitente);
430
+ }
431
+ $par->NFE->Identificacao = $this->getNFEIdentificacao($emitente);
432
+ $par->NFE->Destinatario = $this->getNFEDestinatario($order);
433
+ $par->NFE->ProdutosServicos = $this->getNFEProdutos($order, $post, $par->NFE->Emitente->CodigoRegimeTributario);
434
+ $par->NFE->Transporte = $this->getTransporte($order);
435
+ $par->NFE->InformacoesAdicionais = $this->getNFEInformacaoAdicional($order, $par->NFE->Emitente->CodigoRegimeTributario);
436
+
437
+ $serverAddress = 'https://www.nfecolaborativa.com.br/services/servicos/ExchangeService.svc?wsdl';
438
+ //$serverAddress = 'https://ignition.no-ip.org/nfeservices/servicos/ExchangeService.svc?wsdl';
439
+ $client = $this->createSoapClient($serverAddress, true);
440
+
441
+ $soapResult = $client->ImportarNFE($par);
442
+
443
+ $ResumoNFE = $soapResult->ImportarNFEResult;
444
+
445
+ $this->saveNfe($ResumoNFE, $oID);
446
+
447
+
448
+ $message = $this->__('Sua nota foi enviada com sucesso.');
449
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
450
+
451
+
452
+ $parameters = array("nfe_id" => $ResumoNFE->ID);
453
+
454
+ $this->_redirect('*/*/downloadpage', $parameters);
455
+ } catch (Exception $e) {
456
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
457
+ }
458
+ }
459
+
460
+ }
461
+
462
+ class WsseAuthHeader extends SoapHeader {
463
+
464
+ private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
465
+
466
+ function __construct($user, $pass, $ns = null) {
467
+ if ($ns) {
468
+ $this->wss_ns = $ns;
469
+ }
470
+
471
+ $auth = new stdClass();
472
+
473
+ $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
474
+ $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
475
+ $username_token = new stdClass();
476
+ $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
477
+ $security_sv = new SoapVar(
478
+ new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
479
+ SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
480
+
481
+ parent::__construct($this->wss_ns, 'Security', $security_sv, true);
482
+ }
483
+
484
+ }
485
+
app/code/local/Ignition/NFEColaborativa/controllers/IndexController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ignition_NFEColaborativa_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+
7
+ /*
8
+ * Load an object by id
9
+ * Request looking like:
10
+ * http://site.com/nfecolaborativa?id=15
11
+ * or
12
+ * http://site.com/nfecolaborativa/id/15
13
+ */
14
+ /*
15
+ $nfecolaborativa_id = $this->getRequest()->getParam('id');
16
+
17
+ if($nfecolaborativa_id != null && $nfecolaborativa_id != '') {
18
+ $nfecolaborativa = Mage::getModel('nfecolaborativa/nfecolaborativa')->load($nfecolaborativa_id)->getData();
19
+ } else {
20
+ $nfecolaborativa = null;
21
+ }
22
+ */
23
+
24
+ /*
25
+ * If no param we load a the last created item
26
+ */
27
+ /*
28
+ if($nfecolaborativa == null) {
29
+ $resource = Mage::getSingleton('core/resource');
30
+ $read= $resource->getConnection('core_read');
31
+ $nfecolaborativaTable = $resource->getTableName('nfecolaborativa');
32
+
33
+ $select = $read->select()
34
+ ->from($nfecolaborativaTable,array('nfecolaborativa_id','title','content','status'))
35
+ ->where('status',1)
36
+ ->order('created_time DESC') ;
37
+
38
+ $nfecolaborativa = $read->fetchRow($select);
39
+ }
40
+ Mage::register('nfecolaborativa', $nfecolaborativa);
41
+ */
42
+
43
+
44
+ $this->loadLayout();
45
+ $this->renderLayout();
46
+ }
47
+ }
app/code/local/Ignition/NFEColaborativa/etc/adminhtml.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <nfecolaborativa translate="title">
15
+ <title>Facebook comment</title>
16
+ <sort_order>50</sort_order>
17
+ </nfecolaborativa>
18
+ </children>
19
+ </config>
20
+ </children>
21
+ </system>
22
+ </children>
23
+ </admin>
24
+ </resources>
25
+ </acl>
26
+ </config>
app/code/local/Ignition/NFEColaborativa/etc/config.xml ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Ignition
5
+ * @package Ignition_NFEColaborativa
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Ignition_NFEColaborativa>
13
+ <version>0.1.0</version>
14
+ </Ignition_NFEColaborativa>
15
+ </modules>
16
+ <frontend>
17
+ <routers>
18
+ <nfecolaborativa>
19
+ <use>standard</use>
20
+ <args>
21
+ <module>Ignition_NFEColaborativa</module>
22
+ <frontName>nfecolaborativa</frontName>
23
+ </args>
24
+ </nfecolaborativa>
25
+ </routers>
26
+ <layout>
27
+ <updates>
28
+ <nfecolaborativa>
29
+ <file>nfecolaborativa.xml</file>
30
+ </nfecolaborativa>
31
+ </updates>
32
+ </layout>
33
+ </frontend>
34
+ <admin>
35
+ <routers>
36
+ <nfecolaborativa>
37
+ <use>admin</use>
38
+ <args>
39
+ <module>Ignition_NFEColaborativa</module>
40
+ <frontName>nfecolaborativa</frontName>
41
+ </args>
42
+ </nfecolaborativa>
43
+ </routers>
44
+ </admin>
45
+ <adminhtml>
46
+ <acl>
47
+ <resources>
48
+ <all>
49
+ <title>Allow Everything</title>
50
+ </all>
51
+ <admin>
52
+ <children>
53
+ <Ignition_NFEColaborativa>
54
+ <title>NFEColaborativa Module</title>
55
+ <sort_order>10</sort_order>
56
+ </Ignition_NFEColaborativa>
57
+ </children>
58
+ </admin>
59
+ </resources>
60
+ </acl>
61
+ <layout>
62
+ <updates>
63
+ <nfecolaborativa>
64
+ <file>nfecolaborativa.xml</file>
65
+ </nfecolaborativa>
66
+ </updates>
67
+ <adminhtml_sales_order_view>
68
+ <reference name="sales_order_tabs">
69
+ <action method="addTab"><name>nfeemitidas</name><block>nfeemitidas/adminhtml_sales_order_view_tab_notasEmitidas</block></action>
70
+ </reference>
71
+ </adminhtml_sales_order_view>
72
+ </layout>
73
+ </adminhtml>
74
+ <global>
75
+ <models>
76
+ <nfecolaborativa>
77
+ <class>Ignition_NFEColaborativa_Model</class>
78
+ <resourceModel>nfecolaborativa_mysql4</resourceModel>
79
+ </nfecolaborativa>
80
+ <nfecolaborativa_mysql4>
81
+ <class>Ignition_NFEColaborativa_Model_Mysql4</class>
82
+ <entities>
83
+ <nfecolaborativa>
84
+ <table>nfecolaborativa</table>
85
+ </nfecolaborativa>
86
+ </entities>
87
+ </nfecolaborativa_mysql4>
88
+ </models>
89
+ <resources>
90
+ <nfecolaborativa_setup>
91
+ <setup>
92
+ <module>Ignition_NFEColaborativa</module>
93
+ </setup>
94
+ <connection>
95
+ <use>core_setup</use>
96
+ </connection>
97
+ </nfecolaborativa_setup>
98
+ <nfecolaborativa_write>
99
+ <connection>
100
+ <use>core_write</use>
101
+ </connection>
102
+ </nfecolaborativa_write>
103
+ <nfecolaborativa_read>
104
+ <connection>
105
+ <use>core_read</use>
106
+ </connection>
107
+ </nfecolaborativa_read>
108
+ </resources>
109
+ <blocks>
110
+ <nfecolaborativa>
111
+ <class>Ignition_NFEColaborativa_Block</class>
112
+ </nfecolaborativa>
113
+ <adminhtml>
114
+ <rewrite>
115
+ <sales_order_view>Ignition_NFEColaborativa_Block_Adminhtml_Sales_Order_View</sales_order_view>
116
+ </rewrite>
117
+ </adminhtml>
118
+
119
+ </blocks>
120
+ <helpers>
121
+ <nfecolaborativa>
122
+ <class>Ignition_NFEColaborativa_Helper</class>
123
+ </nfecolaborativa>
124
+ </helpers>
125
+ </global>
126
+ </config>
app/code/local/Ignition/NFEColaborativa/etc/system.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <ignition translate="label">
5
+ <label>Ignition Sistemas</label>
6
+ <sort_order>500</sort_order>
7
+ </ignition>
8
+ </tabs>
9
+ <sections>
10
+ <nfecolaborativa translate="label" module="nfecolaborativa">
11
+ <class>separator-top</class>
12
+ <label>NFEColaborativa</label>
13
+ <tab>ignition</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>300</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <general translate="label">
21
+ <label>Geral</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>0</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>0</show_in_store>
27
+ <fields>
28
+ <usuario_nfecolaborativa translate="label">
29
+ <label>Usuario</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>0</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <comment><![CDATA[<a href="http://www.nfecolaborativa.com.br/planos.aspx" target="_blank">Registre-se!</a>]]>
36
+ </comment>
37
+ </usuario_nfecolaborativa>
38
+ <senha_nfecolaborativa translate="label">
39
+ <label>Senha</label>
40
+ <frontend_type>password</frontend_type>
41
+ <sort_order>1</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </senha_nfecolaborativa>
46
+ <cnpj_emitente translate="label">
47
+ <label>CNPJ do Emitente Preferencial</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>2</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </cnpj_emitente>
54
+ </fields>
55
+ </general>
56
+ </groups>
57
+ </nfecolaborativa>
58
+ </sections>
59
+ </config>
app/code/local/Ignition/NFEColaborativa/sql/nfecolaborativa_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
5
+
6
+ $installer->startSetup();
7
+
8
+ $setup->addAttributeGroup('catalog_product', 'Default', 'NF-e', 1000);
9
+
10
+ $setup->addAttributeGroup('catalog_product', 'Default', 'NF-e Avançada', 1100);
11
+
12
+ $setup->addAttribute('catalog_product', 'codigo_ean',
13
+ array( 'group'=> 'NF-e',
14
+ 'input' => 'text',
15
+ 'type' => 'text',
16
+ 'label' => 'Codigo EAN (Código de Barras)',
17
+ 'backend' => '',
18
+ 'class' => 'validate-number',
19
+ 'visible' => 1,
20
+ 'required' => 0,
21
+ 'user_defined' => 1,
22
+ 'searchable' => 0,
23
+ 'filterable' => 0,
24
+ 'comparable' => 0,
25
+ 'visible_on_front' => 0,
26
+ 'visible_in_advanced_search' => 0,
27
+ 'is_html_allowed_on_front' => 0,
28
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));
29
+
30
+ $setup->addAttribute('catalog_product', 'codigo_ncm',
31
+ array( 'group'=> 'NF-e',
32
+ 'input' => 'text',
33
+ 'type' => 'text',
34
+ 'label' => 'NCM',
35
+ 'backend' => '',
36
+ 'visible' => 1,
37
+ 'class' => 'validate-number',
38
+ 'required' => 0,
39
+ 'user_defined' => 1,
40
+ 'searchable' => 0,
41
+ 'filterable' => 0,
42
+ 'comparable' => 0,
43
+ 'visible_on_front' => 0,
44
+ 'visible_in_advanced_search' => 0,
45
+ 'is_html_allowed_on_front' => 0,
46
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));
47
+
48
+ $setup->addAttribute('catalog_product', 'codigo_extipi',
49
+ array( 'group'=> 'NF-e',
50
+ 'input' => 'text',
51
+ 'type' => 'text',
52
+ 'label' => 'EX TIPI',
53
+ 'class' => 'validate-number',
54
+ 'backend' => '',
55
+ 'visible' => 1,
56
+ 'required' => 0,
57
+ 'user_defined' => 1,
58
+ 'searchable' => 0,
59
+ 'filterable' => 0,
60
+ 'comparable' => 0,
61
+ 'visible_on_front' => 0,
62
+ 'visible_in_advanced_search' => 0,
63
+ 'is_html_allowed_on_front' => 0,
64
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));
65
+
66
+ $setup->addAttribute('catalog_product', 'unidade_tributavel',
67
+ array( 'group'=> 'NF-e Avançada',
68
+ 'input' => 'text',
69
+ 'type' => 'text',
70
+ 'label' => 'Unidade Tributavel',
71
+ 'backend' => '',
72
+ 'default' => 'UN',
73
+ 'visible' => 1,
74
+ 'required' => 0,
75
+ 'user_defined' => 1,
76
+ 'searchable' => 0,
77
+ 'filterable' => 0,
78
+ 'comparable' => 0,
79
+ 'visible_on_front' => 0,
80
+ 'visible_in_advanced_search' => 0,
81
+ 'is_html_allowed_on_front' => 0,
82
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));
83
+
84
+
85
+ $setup->addAttribute('catalog_product', 'qtde_tributavel',
86
+ array( 'group'=> 'NF-e Avançada',
87
+ 'input' => 'text',
88
+ 'type' => 'text',
89
+ 'label' => 'Quantidade Tributavel',
90
+ 'backend' => '',
91
+ 'default' => '1',
92
+ 'class' => 'validate-number',
93
+ 'visible' => 1,
94
+ 'required' => 0,
95
+ 'user_defined' => 1,
96
+ 'searchable' => 0,
97
+ 'filterable' => 0,
98
+ 'comparable' => 0,
99
+ 'visible_on_front' => 0,
100
+ 'visible_in_advanced_search' => 0,
101
+ 'is_html_allowed_on_front' => 0,
102
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));
103
+
104
+ $installer->run("
105
+
106
+ DROP TABLE IF EXISTS {$this->getTable('nfecolaborativa')};
107
+ CREATE TABLE {$this->getTable('nfecolaborativa')} (
108
+ `nota_id` int(11) unsigned NOT NULL auto_increment, `data_emissao` datetime NOT NULL,
109
+ `codigo_numerico_sequencial` varchar(9) NULL default '',
110
+ `serie` varchar(3) NULL default '', `chave_acesso` varchar(44) NULL default '', `descricao_status` varchar(255) NULL default '', `nota_servidor_id` bigint NOT NULL, `pedido_id` bigint NOT NULL,
111
+
112
+ PRIMARY KEY (`nota_id`)
113
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
114
+
115
+ ");
116
+
117
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/nfecolaborativa.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <nfecolaborativa_adminhtml_nfecolaborativa_index>
4
+ <reference name="content">
5
+ <block type="nfecolaborativa/adminhtml_nfecolaborativa" name="nfecolaborativa" />
6
+ </reference>
7
+ </nfecolaborativa_adminhtml_nfecolaborativa_index>
8
+
9
+ <adminhtml_sales_order_view>
10
+ <reference name="sales_order_tabs">
11
+ <block type="nfecolaborativa/adminhtml_sales_order_view_tab_notasEmitidas" name="tab_notasEmitidas"></block>
12
+ <action method="addTab">
13
+ <name>notasEmitidas</name>
14
+ <block>tab_notasEmitidas</block>
15
+ </action>
16
+ </reference>
17
+ </adminhtml_sales_order_view>
18
+ </layout>
app/design/adminhtml/default/default/template/nfecolaborativa/EmitirNFE.phtml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?= $this->__('Configuração de NF-e') ?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Emitir NF-e</span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <form id="edit_form" name="edit_form" method="post" action="<?= $this->getUrl('*/*/post', array('order_id' => $this->getRequest()->getParam('order_id'))) ?>">
13
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
14
+
15
+ <div class="entry-edit">
16
+ <div class="entry-edit-head">
17
+ <h4 class="icon-head head-products">Dados adicionais</h4>
18
+ </div>
19
+ </div>
20
+ <div class="grid np">
21
+ <div class="hor-scroll">
22
+ <table cellspacing="0" class="data order-tables">
23
+ <colgroup><col>
24
+ <col width="1">
25
+ <col width="1">
26
+ <col width="1">
27
+ <col width="1">
28
+ <col width="1">
29
+ <col width="1">
30
+ </colgroup><thead>
31
+ <tr class="headings">
32
+ <th>Produto</th>
33
+ <th>Preço</th>
34
+ <th class="a-center">Qtd</th>
35
+ <th><span class="nobr">Código de Barras</span></th>
36
+ <th><span class="nobr">NCM</span></th>
37
+ <th><span class="nobr">Ex. TIPI</span></th>
38
+ <th><span class="nobr">CFOP</span></th>
39
+ </tr>
40
+ </thead>
41
+ <tbody class="even">
42
+ <?php
43
+ $orderID = $this->getRequest()->getParam('order_id');
44
+ $order = Mage::getModel('sales/order')->load($orderID);
45
+ $_items = $order->getAllItems();
46
+ ?>
47
+ <?php $i = 0;
48
+ foreach ($_items as $_item): ?>
49
+ <?php $i = $_item->getItemId(); ?>
50
+ <?php $prod = Mage::getModel('catalog/product')->load($_item['product_id']); ?>
51
+ <tr class="border">
52
+ <td>
53
+ <h5 class="title"><span id="order_item_1_title"><?php echo $_item->getName(); ?></span></h5>
54
+ <div><strong>SKU:</strong> <?php echo $_item->getSku(); ?></div>
55
+ </td>
56
+ <td class="a-right">
57
+ <span class="price-excl-tax">
58
+
59
+ <span class="price"><?php echo Mage::helper('core')->currency($_item->getPrice(), true, false); ?></span>
60
+
61
+ </span>
62
+ <br>
63
+
64
+ </td>
65
+ <td class="a-center"><table cellspacing="0" class="qty-table">
66
+ <tbody><tr>
67
+ <td>Solicitado</td>
68
+ <td><strong><?php echo $_item->getQtyToInvoice(); ?></strong></td>
69
+ </tr>
70
+ </tbody></table>
71
+ </td>
72
+ <td class="a-center">
73
+ <input type="text" size="18" class="validate-number qty-input" name=<?php echo "produtos[" . $i . "][ean]" ?> value="<?php echo $prod->getData('codigo_ean'); ?>" />
74
+ </td>
75
+ <td class="a-center">
76
+ <input type="text" size="8" class="required-entry validate-number qty-input" name=<?php echo "produtos[" . $i . "][ncm]" ?> value="<?php echo $prod->getData('codigo_ncm'); ?>" />
77
+ </td>
78
+ <td class="a-center">
79
+ <input type="text" size ="3" class="validate-number qty-input" name=<?php echo "produtos[" . $i . "][tipi]" ?> value="<?php echo $prod->getData('codigo_extipi'); ?>" />
80
+ </td>
81
+ <td class="a-center">
82
+ <input type="text" size="4" class="required-entry qty-input" name=<?php echo "produtos[" . $i . "][cfop]" ?> value=""/>
83
+ </td>
84
+ </tr>
85
+ <?php endforeach; ?>
86
+ </tbody>
87
+ </table>
88
+ </div>
89
+ </div>
90
+
91
+ </form>
92
+ </div>
93
+ <script type="text/javascript">
94
+ var editForm = new varienForm('edit_form');
95
+ </script>
app/design/adminhtml/default/default/template/nfecolaborativa/NotasEmitidas.phtml ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="entry-edit">
2
+ <form id="edit_form" name="edit_form" method="post" action="<?= $this->getUrl('*/*/post', array('order_id' => $this->getRequest()->getParam('order_id'))) ?>">
3
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
4
+
5
+ <div class="entry-edit">
6
+ <div class="entry-edit-head">
7
+ <h4 class="icon-head head-products">NF-e emitidas para o pedido</h4>
8
+ </div>
9
+ </div>
10
+ <div class="grid np">
11
+ <div class="hor-scroll">
12
+ <table cellspacing="0" class="data order-tables">
13
+ <colgroup><col>
14
+ <col width="1">
15
+ <col width="100">
16
+ <col width="120">
17
+ <col width="70">
18
+ <col width="1">
19
+ </colgroup><thead>
20
+ <tr class="headings">
21
+ <th>Chave de Acesso</th>
22
+ <th>Série</th>
23
+ <th class="a-center">Número</th>
24
+ <th><span class="nobr">Data</span></th>
25
+ <th><span class="nobr">Status</span></th>
26
+ <th><span class="nobr">Ação</span></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody class="even">
30
+ <?php
31
+ $orderID = $this->getRequest()->getParam('order_id');
32
+
33
+ $nfes = Mage::getModel("nfecolaborativa/nFEColaborativa")->getCollection()->addFieldToFilter('pedido_id', $orderID)->load();
34
+ ?>
35
+ <?php foreach ($nfes as $_item): ?>
36
+ <?php $linknfe="http://nfecolaborativa.com.br/download/Ignition.NFE2.Core.application?id=" . $_item->getData('nota_servidor_id') ; ?>
37
+ <tr class="border">
38
+ <td>
39
+ <h5 class="title"><span id="order_item_1_title"><?php echo $_item->getData('chave_acesso'); ?></span></h5>
40
+ </td>
41
+ <td class="a-right">
42
+ <span class="price-excl-tax">
43
+ <span class="price"><?php echo $_item->getData('serie'); ?></span>
44
+ </span>
45
+ <br>
46
+
47
+ </td>
48
+ <td class="a-center"><table cellspacing="0" class="qty-table">
49
+ <tbody><tr>
50
+ <td><strong><?php echo $_item->getData('codigo_numerico_sequencial'); ?></strong></td>
51
+ </tr>
52
+ </tbody></table>
53
+ </td>
54
+ <td class="a-center">
55
+ <span><?php echo date('d/m/Y H:i',strtotime( $_item->getData('data_emissao'))); ?></span>
56
+ </td>
57
+ <td class="a-center">
58
+ <span><?php echo $_item->getData('descricao_status'); ?></span>
59
+ </td>
60
+ <td class="a-center">
61
+ <span> <a href= <?php echo $linknfe; ?> target="_blank">Exibir</a></span>
62
+ </td>
63
+
64
+ </tr>
65
+ <?php endforeach; ?>
66
+ </tbody>
67
+ </table>
68
+ </div>
69
+ </div>
70
+
71
+ </form>
72
+ </div>
app/design/adminhtml/default/default/template/nfecolaborativa/SucessoEmissao.phtml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?= $this->__('Iniciando o sistema NFEColaborativa') ?></h3></td>
5
+ </tr>
6
+ </table>
7
+ </div>
8
+ <div>
9
+ <?php
10
+ $nfeID = $this->getRequest()->getParam('nfe_id');
11
+ $linknfe = "http://nfecolaborativa.com.br/download/Ignition.NFE2.Core.application?id=" . $nfeID;
12
+ ?>
13
+ <h4>
14
+ Se o sistema não iniciar automaticamente, <a href= <?php echo $linknfe; ?> target="_blank" >clique aqui.</a>
15
+ </h4>
16
+ <br>
17
+ <br>
18
+ <br>
19
+
20
+ </div>
21
+ <div>
22
+ <form id="download_form" name="download_form" method="post" >
23
+ <table style="text-align: left; width: 769px; height: 192px;"
24
+ border="1" cellpadding="2" cellspacing="2">
25
+ <tbody>
26
+ <tr>
27
+ <td>Aten&ccedil;&atilde;o: A NFEColaborativa
28
+ &eacute; compativel com
29
+ <a href="http://www.baixaki.com.br/download/windows-xp-service-pack-3.htm">Windows
30
+ XP SP3</a>, Windows 2003, Vista e Windows 7.
31
+ <br>
32
+ <br>
33
+ Para a inicializa&ccedil;&atilde;o autom&aacute;tica do
34
+ sistema, recomendamos a utiliza&ccedil;&atilde;o do Internet
35
+ Explorer 7 ou superior.
36
+ <br>
37
+ Caso voc&ecirc; utilize o Google Chrome, ser&aacute;
38
+ necess&aacute;rio instalar o plugin&nbsp; <a
39
+ href="https://chrome.google.com/webstore/detail/eeifaoomkminpbeebjdmdojbhmagnncl/related">ClickOnce
40
+ for Google Chrome</a>&nbsp;<br>
41
+ Se o seu navegador for o Mozilla Firefox, ser&aacute;
42
+ necess&aacute;rio instalar o plugin <a
43
+ href="https://addons.mozilla.org/firefox/downloads/file/127966/microsoft_net_framework_assistant-1.3.1-fx-windows.xpi?src=dp-btn-primary">Microsoft
44
+ .NET Framework Assistant.</a><br>
45
+ <br>
46
+ Se voc&ecirc; tiver qualquer d&uacute;vida ou dificuldade,
47
+ entre em contato conosco:<br>
48
+ <b>Skype:</b><br>
49
+ <b>Email:</b> <a href="suporte@ignitionsistemas.com.br">suporte@ignitionsistemas.com.br</a> <br>
50
+ <b>Telefone:</b> (54) 3055-3502</td>
51
+ </tr>
52
+ </tbody>
53
+ </table>
54
+
55
+ </form>
56
+ <script>
57
+ window.open('<?php echo $linknfe ?>' ,'iniciando o sistema', 'width=120,height=300,scrollbars=NO')
58
+ </script>
59
+
60
+
61
+ </div>
app/etc/modules/Ignition_NFEColaborativa.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Ignition
5
+ * @package Ignition_NFEColaborativa
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Ignition_NFEColaborativa>
13
+ <active>true</active>
14
+ <codePool>local</codePool>
15
+ </Ignition_NFEColaborativa>
16
+ </modules>
17
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Ignition_NFEColaborativa</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/copyleft/gpl.html">GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Emiss&#xE3;o de Notas Fiscais Eletr&#xF4;nicas (NF-e) com pouqu&#xED;ssimos cliques.</summary>
10
+ <description>Esse m&#xF3;dulo integra a sua loja virtual ao sistema de emiss&#xE3;o de NF-e da Ignition Sistemas</description>
11
+ <notes>Primeira vers&#xE3;o do m&#xF3;dulo de emiss&#xE3;o</notes>
12
+ <authors><author><name>Ignition Sistemas</name><user>suporteignition</user><email>suporte@ignitionsistemas.com.br</email></author></authors>
13
+ <date>2012-08-06</date>
14
+ <time>13:34:00</time>
15
+ <contents><target name="magelocal"><dir name="Ignition"><dir name="NFEColaborativa"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="View"><dir name="Tab"><file name="NotasEmitidas.php" hash="0e3e08993501838c969c54fcf85a635e"/></dir></dir><file name="View.php" hash="d5c0f4756adeefa8c769d69920e51ef9"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="04c802cdcb67fd55c15a3bea81441764"/></dir><dir name="Model"><dir name="Mysql4"><dir name="NFEColaborativa"><file name="Collection.php" hash="0f7d66bc6dcebfad6da202b708b7b89a"/></dir><file name="NFEColaborativa.php" hash="cd9c9ece952392e79a9902ae98f671d5"/></dir><file name="NFEColaborativa.php" hash="6eb175dc1e89fbf2de660b1eb844a846"/><file name="Status.php" hash="2d9fdf27db4a2a6dee90959a0d59150d"/></dir><dir name="controllers"><file name="EmissorController.php" hash="fdd3a8a50e8421e07171b303a994a720"/><file name="IndexController.php" hash="ed76ee47186bf4323f95380f6dd43c96"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8ca5d8a076822fafcf80d90140baea8c"/><file name="config.xml" hash="37c0714ca48d254ae2fab0102fc399a6"/><file name="system.xml" hash="702b531892a7e91a99b7cef45fec3315"/></dir><dir name="sql"><dir name="nfecolaborativa_setup"><file name="mysql4-install-0.1.0.php" hash="d946d6191cd81d697f90591ce1308300"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="nfecolaborativa.xml" hash="64161f7308519a8f5352f69f9e2e23b4"/></dir><dir name="template"><dir name="nfecolaborativa"><file name="EmitirNFE.phtml" hash="6eeda86eaa731a3f8c7566d3f60f43a8"/><file name="NotasEmitidas.phtml" hash="7ba4157c4aed0e839dcdee3ea8364b99"/><file name="SucessoEmissao.phtml" hash="4e417dee664e3d4051b4dc294cd9f2ba"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ignition_NFEColaborativa.xml" hash="8471a04478485b4808b4f38dfc62bbf2"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>5.4.5</max></php><extension><name>soap</name><min></min><max></max></extension></required></dependencies>
18
+ </package>