Waterstone_Winvoice - Version 1.0.2

Version Notes

- Bug fixes.

Download this release

Release Info

Developer Waterstone
Extension Waterstone_Winvoice
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.1.2 to 1.0.2

Files changed (54) hide show
  1. app/code/{local → community}/Waterstone/Winvoice/Helper/Data.php +2 -2
  2. app/code/community/Waterstone/Winvoice/Model/AddInvoice.php +386 -0
  3. app/code/{local → community}/Waterstone/Winvoice/Model/Email/Template/Mailer.php +0 -0
  4. app/code/{local → community}/Waterstone/Winvoice/Model/Order/Invoice.php +0 -0
  5. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/changelog +0 -0
  6. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.nusoap_base.php +0 -0
  7. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_fault.php +0 -0
  8. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_parser.php +0 -0
  9. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_server.php +0 -0
  10. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_transport_http.php +0 -0
  11. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_val.php +0 -0
  12. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soapclient.php +0 -0
  13. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.wsdl.php +0 -0
  14. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.wsdlcache.php +0 -0
  15. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.xmlschema.php +0 -0
  16. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/nusoap.php +0 -0
  17. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/nusoapmime.php +0 -0
  18. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client1.php +0 -0
  19. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client2.php +0 -0
  20. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client3.php +0 -0
  21. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/getfile1client.php +0 -0
  22. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/getfile2client.php +0 -0
  23. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/index.html +0 -0
  24. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/mimeclient.php +0 -0
  25. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/sslclient.php +0 -0
  26. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient1.php +0 -0
  27. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient10.php +0 -0
  28. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient11.php +0 -0
  29. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient12.php +0 -0
  30. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient13.php +0 -0
  31. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient14.php +0 -0
  32. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient15.php +0 -0
  33. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient2.php +0 -0
  34. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3.php +0 -0
  35. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3b.php +0 -0
  36. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3c.php +0 -0
  37. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient4.php +0 -0
  38. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient5.php +0 -0
  39. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient6.php +0 -0
  40. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient7.php +0 -0
  41. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient8.php +0 -0
  42. app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient9.php +0 -0
  43. app/code/{local → community}/Waterstone/Winvoice/etc/adminhtml.xml +0 -0
  44. app/code/{local → community}/Waterstone/Winvoice/etc/config.xml +8 -61
  45. app/code/{local → community}/Waterstone/Winvoice/etc/system.xml +13 -7
  46. app/code/{local → community}/Waterstone/Winvoice/sql/winvoice_setup/mysql4-install-0.1.0.php +3 -6
  47. app/code/local/Waterstone/Winvoice/Model/AddInvoice.php +0 -390
  48. app/code/local/Waterstone/Winvoice/Model/Log.php +0 -65
  49. app/code/local/Waterstone/Winvoice/Model/Mysql4/Winvoice.php +0 -31
  50. app/code/local/Waterstone/Winvoice/Model/Mysql4/Winvoice/Collection.php +0 -31
  51. app/code/local/Waterstone/Winvoice/Model/Status.php +0 -37
  52. app/code/local/Waterstone/Winvoice/controllers/Adminhtml/WinvoiceController.php +0 -335
  53. app/etc/modules/Waterstone_Winvoice.xml +0 -27
  54. package.xml +11 -15
app/code/{local → community}/Waterstone/Winvoice/Helper/Data.php RENAMED
@@ -3,7 +3,7 @@
3
  * DISCLAIMER
4
  *
5
  * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
  * on http://www.waterstone.pt for more information.
8
  *
9
  * @category Waterstone
@@ -15,4 +15,4 @@
15
  class Waterstone_Winvoice_Helper_Data extends Mage_Core_Helper_Abstract
16
  {
17
 
18
- }
3
  * DISCLAIMER
4
  *
5
  * Do not edit or add to this file if you wish to upgrade the extension to newer
6
+ * versions in the future. If you need personal customization please contact us
7
  * on http://www.waterstone.pt for more information.
8
  *
9
  * @category Waterstone
15
  class Waterstone_Winvoice_Helper_Data extends Mage_Core_Helper_Abstract
16
  {
17
 
18
+ }
app/code/community/Waterstone/Winvoice/Model/AddInvoice.php ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DISCLAIMER
5
+ *
6
+ * Do not edit or add to this file if you wish to upgrade the extension to newer
7
+ * versions in the future. If you need personal customization please contact us
8
+ * on http://www.waterstone.pt for more information.
9
+ *
10
+ * @category Waterstone
11
+ * @package Waterstone_Winvoice
12
+ * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+
16
+ class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
17
+ {
18
+ /* Private variables */
19
+ private $client;
20
+ private $password;
21
+
22
+ /**
23
+ * weoInvoice error codes list.
24
+ *
25
+ * @var array
26
+ */
27
+ private $errorMessages = array(
28
+ '300' => 'Falha na autenticação no weoInvoice.',
29
+ '301' => 'Parâmetros insuficientes.',
30
+ '302' => 'Código de cliente já existente ou inválido.',
31
+ '303' => 'Número de contribuinte inválido.',
32
+ '304' => 'Email inválido.',
33
+ '305' => 'Sem permissões para alterar o cliente.',
34
+ '306' => 'Sem permissões para usar o cliente.',
35
+ '307' => 'Empresa sem as informações mínimas necessárias.',
36
+ '308' => 'Empresa sem a tabela de IVA correctamente preenchida.',
37
+ '309' => 'Data inválida.',
38
+ '310' => 'Data de pagamento inválida.',
39
+ '311' => 'Data do documento não sequencial.',
40
+ '312' => 'Tipo de documento inválido.',
41
+ '320' => 'Não é possível criar um documento com um existente em aberto.',
42
+ '321' => 'Documento não disponível.',
43
+ '322' => 'Documento já fechado.',
44
+ '323' => 'Informação de produtos/serviços no documento insuficiente.',
45
+ '324' => 'Taxa de IVA do produto/serviço incorrecta.',
46
+ '325' => 'Sem permissões para usar o documento.',
47
+ '326' => 'Documento ainda está aberto.',
48
+ '327' => 'Motivo da anulação do documento inexistente.',
49
+ '328' => 'Motivo de isenção de IVA incorrecto ou inexistente.',
50
+ '340' => 'Código de cliente inexistente.',
51
+ '341' => 'Erro ao obter dados do cliente.',
52
+ '350' => 'Pagamento de factura com valor inferior a zero.',
53
+ '351' => 'Factura já paga.',
54
+ '352' => 'Recibo com valor inferior a zero.'
55
+ );
56
+
57
+ /**
58
+ * Constructor.
59
+ * - Connect to weoInvoice api using nusoap.
60
+ *
61
+ * @since 1.0.0
62
+ *
63
+ * @return void
64
+ */
65
+ public function __construct()
66
+ {
67
+ date_default_timezone_set('Europe/Berlin');
68
+ require_once(Mage::getModuleDir('', 'Waterstone_Winvoice').'/Model/nusoap/lib/nusoap.php');
69
+
70
+ $this->client = new \nusoap_client(Mage::getStoreConfig('winvoice/wconfig/wapi'));
71
+ $this->password = Mage::getStoreConfig('winvoice/wconfig/wpassword');
72
+
73
+ Mage::log("Winvoice | Foi criado um cliente: ".print_r($this->client), null, 'winvoice.log', true);
74
+ Mage::log("Winvoice | Password do cliente: {$this->password}", null, 'winvoice.log', true);
75
+ }
76
+
77
+ /**
78
+ * Add invoice method.
79
+ * - Gets the client products, creates a winvoice and sends to email.
80
+ *
81
+ * @since 1.0.0
82
+ *
83
+ * @param Mage_Sales_Model_Observer $observer
84
+ * @return void
85
+ */
86
+ public function addInvoice($observer)
87
+ {
88
+ $invoice = $observer->getEvent()->getInvoice();
89
+ $orderNumber = $invoice->getOrder()->getIncrementId();
90
+
91
+ Mage::log("Winvoice | A invoice estah associada ah encomenda numero {$orderNumber}", null, 'winvoice.log', true);
92
+ $useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
93
+ $err = $this->client->getError();
94
+
95
+ if ($err) {
96
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
97
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
98
+ }
99
+
100
+ // Get client items
101
+ $this->client->setUseCurl($useCURL);
102
+ $this->client->soap_defencoding = 'UTF-8';
103
+ $items = $invoice->getAllItems();
104
+
105
+ foreach ($items as $item) {
106
+ if ($item->getBase_price() == 0) {
107
+ continue;
108
+ }
109
+
110
+ $Product = array (
111
+ 'item' => $item->getName(), //string (*) Nome do produto/serviço
112
+ 'type' => 'P', //char (*) Tipo (P ou S) consoante seja produto ou serviço
113
+ 'quantity' => number_format((float)$item->getQty(), 0, '.', ''), //double (*) Quantidade (ex: 2)
114
+ 'price' => number_format((float)$item->getBase_price(), 2, '.', ''), //double (*) Preço (ex: 99.99)
115
+ 'discount' => $item->getDiscountAmount(), //double Desconto (ex: 19.99)
116
+ 'tax' => number_format((float)$item->getOrderItem()->getTaxPercent(), 0, '.', ''), //int (*)Taxa de IVA (ex: 23)
117
+ 'taxreason' => '', // string Motivo de isenção de Taxa, caso aplicável (ver tabela Motivos de isenção de IVA)
118
+ );
119
+
120
+ $Products[] = $Product;
121
+
122
+ Mage::log("Winvoice | A adicionar o item \"{$item->getName()}\" ah invoice, com os dados:", null, 'winvoice.log', true);
123
+ Mage::log("Winvoice | Quantidade: ".number_format((float)$item->getQty(), 0, '.', ''), null, 'winvoice.log', true);
124
+ Mage::log("Winvoice | Preco base: ".number_format((float)$item->getBase_price(), 2, '.', ''), null, 'winvoice.log', true);
125
+ Mage::log("Winvoice | Imposto: ".number_format((float)$item->getOrderItem()->getTaxPercent(), 2, '.', ''), null, 'winvoice.log', true);
126
+ Mage::log("Winvoice | Discontos: ".$item->getDiscountAmount(), null, 'winvoice.log', true);
127
+ }
128
+
129
+ // Shipping tax value in percentage
130
+ $vat = Mage::getStoreConfig('winvoice/wconfig/wshiptax');
131
+
132
+ $Product = array (
133
+ 'item' => $invoice->getOrder()->getShippingDescription(),
134
+ 'type' => 'S',
135
+ 'quantity' => '1',
136
+ 'price' => number_format((float)$invoice->getOrder()->getBaseShippingAmount(), 2, '.', ''),
137
+ 'discount' => '0.00',
138
+ 'tax' => $vat,
139
+ 'taxreason' => '',
140
+ );
141
+
142
+ $Products[] = $Product;
143
+
144
+ $params = array(
145
+ 'client' => $this->getClientNumber($invoice),
146
+ 'type' => '1', //Tipo de documento (ver tabela Tipos de Documento)
147
+ 'date' => date("Y-m-d"), //Data do documento (ex: 2011-01-01)
148
+ 'payment_date' => date("Y-m-d"), //date (*) Data de vencimento do documento (ex: 2011-01-01)
149
+ 'description' => 'F'.$invoice->getEntityId(),
150
+ 'footer' => 'Numero Interno '.$invoice->getEntityId(),
151
+ 'products' => $Products,
152
+ 'password' => $this->password,
153
+ );
154
+
155
+ $result = $this->client->call("AddDocument", $params);
156
+
157
+ if ($this->client->fault) {
158
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
159
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
160
+ } else {
161
+ $err = $this->client->getError();
162
+
163
+ if ($err) {
164
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
165
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
166
+ } else {
167
+ Mage::log("Winvoice | Mensagem retornada pelo weoInvoice: ".$this->errorMessages[$result['answer']], null, 'winvoice.log', true);
168
+ Mage::log("Winvoice | ID retornado pelo weoInvoice: ".$result['description1'], null, 'winvoice.log', true);
169
+ Mage::log("Winvoice | URL retornado pelo weoInvoice: ".$result['description2'], null, 'winvoice.log', true);
170
+
171
+ if ($result['answer'] <> 0 && $result['answer'] <> 1) {
172
+ if (array_key_exists($result['answer'], $this->errorMessages)) {
173
+ Mage::log("Winvoice | Mensagem retornada pelo weoInvoice: ".$this->errorMessages[$result['answer']], null, 'winvoice.log', true);
174
+ Mage::throwException(Mage::helper('adminhtml')->__($this->errorMessages[$result['answer']]));
175
+ } else {
176
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
177
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
178
+ }
179
+ }
180
+
181
+ $invoice->setWsinvoiceurl($result['description2']);
182
+ }
183
+ }
184
+
185
+ $invoice->sendEmail(true, "Factura enviada ao cliente");
186
+ Mage::log("Winvoice | Factura enviada ao cliente", null, 'winvoice.log', true);
187
+ }
188
+
189
+ /**
190
+ * Get invoice url method.
191
+ * - Returns the invoice url from weoInvoice service.
192
+ *
193
+ * @since 1.0.0
194
+ *
195
+ * @param Mage_Sales_Model_Observer $observer
196
+ * @return string
197
+ */
198
+ public function getInvoiceURL($observer)
199
+ {
200
+ $invoice = $observer->getEvent()->getInvoice();
201
+
202
+ return $invoice->getWsinvoiceurl();
203
+ }
204
+
205
+ /**
206
+ * Get client number method.
207
+ * - Returns the invoice url from weoInvoice service.
208
+ *
209
+ * @since 1.0.0
210
+ *
211
+ * @param Mage_Sales_Model_Order_Invoice $invoice
212
+ * @return string
213
+ */
214
+ private function getClientNumber($invoice)
215
+ {
216
+ $address = $invoice->getBillingAddress();
217
+ $vat = $address->getVatId();
218
+
219
+ if (!$address->getCountryId() == 'PT') {
220
+ Mage::log("Winvoice | O NIF do cliente ".$vat." eh invalido", null, 'winvoice.log', true);
221
+ Mage::throwException('Numero de contribuinte invalido: '.Mage::helper('adminhtml')->__($vat));
222
+ }
223
+ if (!$this->isValidNif($vat)) {
224
+ Mage::log("Winvoice | O NIF do cliente ".$vat." eh invalido", null, 'winvoice.log', true);
225
+ Mage::throwException('Numero de contribuinte invalido: '.Mage::helper('adminhtml')->__($vat));
226
+ }
227
+
228
+ $customer = Mage::getModel('customer/customer')->load($invoice->getOrder()->getCustomerId());
229
+
230
+ Mage::log("Winvoice | Os dados do cliente na invoice são:", null, 'winvoice.log', true);
231
+ Mage::log("Winvoice | Nome:".$invoice->getOrder()->getCustomerName(), null, 'winvoice.log', true);
232
+ Mage::log("Winvoice | ID:".$invoice->getOrder()->getCustomerId(), null, 'winvoice.log', true);
233
+ Mage::log("Winvoice | NIF:".$invoice->getOrder()->getCustomerTaxvat(), null, 'winvoice.log', true);
234
+ Mage::log("Winvoice | WSClient do cliente:".$customer->getWsclient(), null, 'winvoice.log', true);
235
+ Mage::log("Winvoice | WSClient da encomenda:".$invoice->getOrder()->getCustomerWsclient(), null, 'winvoice.log', true);
236
+ Mage::log("Winvoice | Morada: ".$address->getStreetFull(), null, 'winvoice.log', true);
237
+ Mage::log("Winvoice | Codigo Postal: ".$address->getPostcode(), null, 'winvoice.log', true);
238
+ Mage::log("Winvoice | Cidade: ".$address->getCity(), null, 'winvoice.log', true);
239
+ Mage::log("Winvoice | Pais: ".$address->getCountryId(), null, 'winvoice.log', true);
240
+
241
+ if (is_numeric($customer->getWsclient())) {
242
+ return $customer->getWsclient();
243
+ }
244
+
245
+ $useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
246
+ $err = $this->client->getError();
247
+
248
+ if ($err) {
249
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
250
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
251
+ exit();
252
+ }
253
+
254
+ $this->client->setUseCurl($useCURL);
255
+ $this->client->soap_defencoding = 'UTF-8';
256
+
257
+ if (is_numeric($vat)) {
258
+ $vatnumber = $vat;
259
+ } else {
260
+ $vatnumber = '999999900';
261
+ }
262
+
263
+ $AddClientIn = array (
264
+ 'code' => "MAG".$invoice->getOrder()->getCustomerId().rand(1, 999999),
265
+ 'name' => $invoice->getOrder()->getCustomerName(),
266
+ 'nif' => $vatnumber,
267
+ // email string Endereço de email
268
+ // url string Página web
269
+ 'address' => $address->getStreetFull(),
270
+ 'postcode' => $address->getPostcode(),
271
+ 'city' => $address->getCity(),
272
+ 'country' => $address->getCountryId(),
273
+ // telephone string Telefone do cliente (ex: 212109902)
274
+ // mobile string Telemóvel do cliente
275
+ // fax string Fax do cliente
276
+ // description string Descrição
277
+ );
278
+
279
+ $params = array(
280
+ 'data' => $AddClientIn,
281
+ 'password'=> $this->password,
282
+ );
283
+
284
+ $result = $this->client->call("AddClient", $params);
285
+
286
+ if ($this->client->fault) {
287
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
288
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
289
+ } else {
290
+ $err = $this->client->getError();
291
+
292
+ if ($err) {
293
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
294
+ Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
295
+ } else {
296
+ if ($invoice->getOrder()->getCustomerId()) {
297
+ $customer = Mage::getModel('customer/customer')->load($invoice->getOrder()->getCustomerId());
298
+ $customer->setWsclient($result['description1']);
299
+ $customer->save();
300
+ } else {
301
+ Mage::log("Winvoice | Erro ao criar factura.", null, 'winvoice.log', true);
302
+ $this->wLog->log("info", "One time costumer processed");
303
+ }
304
+
305
+ Mage::log("Winvoice | Foi criado um novo WSClient com o numero ".$result['description1'], null, 'winvoice.log', true);
306
+ Mage::log("Winvoice | Codigo API do novo WSClient: ".$result['answer'], null, 'winvoice.log', true);
307
+
308
+ return $result['description1'];
309
+ }
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Auto invoice method.
315
+ * - Prepares order to create and send invoice to client.
316
+ *
317
+ * @since 1.0.0
318
+ *
319
+ * @param Mage_Sales_Model_Observer $observer
320
+ * @return void
321
+ */
322
+ public function autoInvoice($observer)
323
+ {
324
+ return;
325
+
326
+ $this->wLog->Log("info", "AutoInvoice trigger for order".$observer->getEvent()->getOrder());
327
+
328
+ $order = $observer->getEvent()->getShipment()->getOrder();
329
+
330
+ $invoice = $order->prepareInvoice();
331
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
332
+ $invoice->register();
333
+ $invoice->getOrder()->setCustomerNoteNotify(true);
334
+ $invoice->getOrder()->setIsInProcess(true);
335
+
336
+ $order->addStatusHistoryComment('AutoInvoice by Winvoice.', false);
337
+
338
+ $transactionSave = Mage::getModel('core/resource_transaction')
339
+ ->addObject($invoice)
340
+ ->addObject($invoice->getOrder());
341
+
342
+ $transactionSave->save();
343
+
344
+ $invoice->sendEmail(true, "Factura enviada ao cliente");
345
+ }
346
+
347
+ /**
348
+ * Is valid nif method.
349
+ * - Checks if nif number is valid.
350
+ *
351
+ * @since 1.0.0
352
+ *
353
+ * @param string $nif
354
+ * @return bool
355
+ */
356
+ public function isValidNif($nif)
357
+ {
358
+ if (!is_numeric($nif) || strlen($nif) != 9) {
359
+ return false;
360
+ }
361
+
362
+ $narray = str_split($nif);
363
+
364
+ if ($narray[0] != 1 && $narray[0] != 2 && $narray[0] != 5 && $narray[0] != 6 && $narray[0] != 8 && $narray[0] != 9) {
365
+ return false;
366
+ }
367
+
368
+ $checkbit = $narray[0] * 9;
369
+
370
+ for ($i=2; $i<=8; $i++) {
371
+ $checkbit += $nif[$i-1] * (10 - $i);
372
+ }
373
+
374
+ $checkbit = 11 - ($checkbit % 11);
375
+
376
+ if ($checkbit >= 10) {
377
+ $checkbit = 0;
378
+ }
379
+
380
+ if ($nif[8] == $checkbit) {
381
+ return true;
382
+ }
383
+
384
+ return false;
385
+ }
386
+ }
app/code/{local → community}/Waterstone/Winvoice/Model/Email/Template/Mailer.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/Order/Invoice.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/changelog RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.nusoap_base.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_fault.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_parser.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_server.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_transport_http.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soap_val.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.soapclient.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.wsdl.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.wsdlcache.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/class.xmlschema.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/nusoap.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/lib/nusoapmime.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client1.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client2.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/client3.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/getfile1client.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/getfile2client.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/index.html RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/mimeclient.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/sslclient.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient1.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient10.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient11.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient12.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient13.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient14.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient15.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient2.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3b.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient3c.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient4.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient5.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient6.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient7.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient8.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/Model/nusoap/samples/wsdlclient9.php RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/etc/adminhtml.xml RENAMED
File without changes
app/code/{local → community}/Waterstone/Winvoice/etc/config.xml RENAMED
@@ -4,7 +4,7 @@
4
  * DISCLAIMER
5
  *
6
  * Do not edit or add to this file if you wish to upgrade the extension to newer
7
- * versions in the future. If you need personal customization please contact us
8
  * on http://www.waterstone.pt for more information.
9
  *
10
  * @category Waterstone
@@ -17,62 +17,14 @@
17
  <config>
18
  <modules>
19
  <Waterstone_Winvoice>
20
- <version>1.0.1.2</version>
21
  </Waterstone_Winvoice>
22
-
23
  </modules>
24
- <frontend>
25
- <routers>
26
- <winvoice>
27
- <use>standard</use>
28
- <args>
29
- <module>Waterstone_Winvoice</module>
30
- <frontName>winvoice</frontName>
31
- </args>
32
- </winvoice>
33
- </routers>
34
- <layout>
35
- <updates>
36
- <winvoice>
37
- <file>winvoice.xml</file>
38
- </winvoice>
39
- </updates>
40
- </layout>
41
- </frontend>
42
- <admin>
43
- <routers>
44
- <winvoice>
45
- <use>admin</use>
46
- <args>
47
- <module>Waterstone_Winvoice</module>
48
- <frontName>winvoice</frontName>
49
- </args>
50
- </winvoice>
51
- </routers>
52
- </admin>
53
- <adminhtml>
54
- <layout>
55
- <updates>
56
- <winvoice>
57
- <file>winvoice.xml</file>
58
- </winvoice>
59
- </updates>
60
- </layout>
61
- </adminhtml>
62
- <global>
63
  <models>
64
  <winvoice>
65
  <class>Waterstone_Winvoice_Model</class>
66
- <resourceModel>winvoice_mysql4</resourceModel>
67
  </winvoice>
68
- <winvoice_mysql4>
69
- <class>Waterstone_Winvoice_Model_Mysql4</class>
70
- <entities>
71
- <winvoice>
72
- <table>winvoice</table>
73
- </winvoice>
74
- </entities>
75
- </winvoice_mysql4>
76
  <core>
77
  <rewrite>
78
  <email_template_mailer>Waterstone_Winvoice_Model_Email_Template_Mailer</email_template_mailer>
@@ -104,12 +56,7 @@
104
  </connection>
105
  </winvoice_read>
106
  </resources>
107
- <blocks>
108
- <winvoice>
109
- <class>Waterstone_Winvoice_Block</class>
110
- </winvoice>
111
- </blocks>
112
- <helpers>
113
  <winvoice>
114
  <class>Waterstone_Winvoice_Helper</class>
115
  </winvoice>
@@ -120,19 +67,19 @@
120
  <Waterstone_Winvoice_order_create>
121
  <type>singleton</type>
122
  <class>Waterstone_Winvoice_Model_AddInvoice</class>
123
- <method>AddInvoice</method>
124
  </Waterstone_Winvoice_order_create>
125
- </observers>
126
  </sales_order_invoice_save_before>
127
  <sales_order_shipment_save_after>
128
  <observers>
129
  <Waterstone_Winvoice_order_pay>
130
  <type>singleton</type>
131
  <class>Waterstone_Winvoice_Model_AddInvoice</class>
132
- <method>AutoInvoice</method>
133
  </Waterstone_Winvoice_order_pay>
134
  </observers>
135
  </sales_order_shipment_save_after>
136
- </events>
137
  </global>
138
  </config>
4
  * DISCLAIMER
5
  *
6
  * Do not edit or add to this file if you wish to upgrade the extension to newer
7
+ * versions in the future. If you need personal customization please contact us
8
  * on http://www.waterstone.pt for more information.
9
  *
10
  * @category Waterstone
17
  <config>
18
  <modules>
19
  <Waterstone_Winvoice>
20
+ <version>1.0.0</version>
21
  </Waterstone_Winvoice>
 
22
  </modules>
23
+ <global>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  <models>
25
  <winvoice>
26
  <class>Waterstone_Winvoice_Model</class>
 
27
  </winvoice>
 
 
 
 
 
 
 
 
28
  <core>
29
  <rewrite>
30
  <email_template_mailer>Waterstone_Winvoice_Model_Email_Template_Mailer</email_template_mailer>
56
  </connection>
57
  </winvoice_read>
58
  </resources>
59
+ <helpers>
 
 
 
 
 
60
  <winvoice>
61
  <class>Waterstone_Winvoice_Helper</class>
62
  </winvoice>
67
  <Waterstone_Winvoice_order_create>
68
  <type>singleton</type>
69
  <class>Waterstone_Winvoice_Model_AddInvoice</class>
70
+ <method>addInvoice</method>
71
  </Waterstone_Winvoice_order_create>
72
+ </observers>
73
  </sales_order_invoice_save_before>
74
  <sales_order_shipment_save_after>
75
  <observers>
76
  <Waterstone_Winvoice_order_pay>
77
  <type>singleton</type>
78
  <class>Waterstone_Winvoice_Model_AddInvoice</class>
79
+ <method>autoInvoice</method>
80
  </Waterstone_Winvoice_order_pay>
81
  </observers>
82
  </sales_order_shipment_save_after>
83
+ </events>
84
  </global>
85
  </config>
app/code/{local → community}/Waterstone/Winvoice/etc/system.xml RENAMED
@@ -4,7 +4,7 @@
4
  * DISCLAIMER
5
  *
6
  * Do not edit or add to this file if you wish to upgrade the extension to newer
7
- * versions in the future. If you need personal customization please contact us
8
  * on http://www.waterstone.pt for more information.
9
  *
10
  * @category Waterstone
@@ -15,10 +15,16 @@
15
  -->
16
 
17
  <config>
 
 
 
 
 
 
18
  <sections>
19
- <winvoice translate="label">
20
  <label>Winvoice</label>
21
- <tab>general</tab>
22
  <frontend_type>text</frontend_type>
23
  <sort_order>1000</sort_order>
24
  <show_in_default>1</show_in_default>
@@ -37,7 +43,7 @@
37
  <wapi translate="label comment">
38
  <label>API weoInvoice</label>
39
  <comment>API fornecida pelo weoInvoice</comment>
40
- <frontend_type>text</frontend_type>
41
  <sort_order>10</sort_order>
42
  <show_in_default>1</show_in_default>
43
  <show_in_website>1</show_in_website>
@@ -47,7 +53,7 @@
47
  <wpassword translate="label comment">
48
  <label>Password weoInvoice</label>
49
  <comment>Password da sua conta weoInvoice</comment>
50
- <frontend_type>password</frontend_type>
51
  <sort_order>20</sort_order>
52
  <show_in_default>1</show_in_default>
53
  <show_in_website>1</show_in_website>
@@ -62,10 +68,10 @@
62
  <show_in_website>1</show_in_website>
63
  <show_in_store>1</show_in_store>
64
  <validate>validate-digits</validate>
65
- </wshiptax>
66
  </fields>
67
  </wconfig>
68
- </groups>
69
  </winvoice>
70
  </sections>
71
  </config>
4
  * DISCLAIMER
5
  *
6
  * Do not edit or add to this file if you wish to upgrade the extension to newer
7
+ * versions in the future. If you need personal customization please contact us
8
  * on http://www.waterstone.pt for more information.
9
  *
10
  * @category Waterstone
15
  -->
16
 
17
  <config>
18
+ <tabs>
19
+ <waterstone translate="label" module="winvoice">
20
+ <label>Waterstone Extensions</label>
21
+ <sort_order>100</sort_order>
22
+ </waterstone>
23
+ </tabs>
24
  <sections>
25
+ <winvoice translate="label" module="winvoice">
26
  <label>Winvoice</label>
27
+ <tab>waterstone</tab>
28
  <frontend_type>text</frontend_type>
29
  <sort_order>1000</sort_order>
30
  <show_in_default>1</show_in_default>
43
  <wapi translate="label comment">
44
  <label>API weoInvoice</label>
45
  <comment>API fornecida pelo weoInvoice</comment>
46
+ <frontend_type>text</frontend_type>
47
  <sort_order>10</sort_order>
48
  <show_in_default>1</show_in_default>
49
  <show_in_website>1</show_in_website>
53
  <wpassword translate="label comment">
54
  <label>Password weoInvoice</label>
55
  <comment>Password da sua conta weoInvoice</comment>
56
+ <frontend_type>password</frontend_type>
57
  <sort_order>20</sort_order>
58
  <show_in_default>1</show_in_default>
59
  <show_in_website>1</show_in_website>
68
  <show_in_website>1</show_in_website>
69
  <show_in_store>1</show_in_store>
70
  <validate>validate-digits</validate>
71
+ </wshiptax>
72
  </fields>
73
  </wconfig>
74
+ </groups>
75
  </winvoice>
76
  </sections>
77
  </config>
app/code/{local → community}/Waterstone/Winvoice/sql/winvoice_setup/mysql4-install-0.1.0.php RENAMED
@@ -3,7 +3,7 @@
3
  * DISCLAIMER
4
  *
5
  * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
  * on http://www.waterstone.pt for more information.
8
  *
9
  * @category Waterstone
@@ -24,7 +24,7 @@ $vCustAttributeSetId = $setup->getDefaultAttributeSetId($vCustomerEntityType);
24
  $vCustAttributeGroupId = $setup->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);
25
 
26
  // Set new attribute for the customer entity
27
- $setup->removeAttribute('customer','wsclient');
28
  $setup->addAttribute('customer', 'wsclient', array(
29
  'label' => 'Cliente Weo',
30
  'input' => 'text',
@@ -32,7 +32,7 @@ $setup->addAttribute('customer', 'wsclient', array(
32
  'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
33
  'required' => 0,
34
  'user_defined' => 1,
35
- ));
36
 
37
  // Add the attribute to the attribute group
38
  $setup->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'wsclient', 0);
@@ -53,6 +53,3 @@ $setup->addAttribute('order', 'wsinvoiceurl', array(
53
  ));
54
 
55
  $setup->endSetup();
56
-
57
- $installer->startSetup();
58
- $installer->endSetup();
3
  * DISCLAIMER
4
  *
5
  * Do not edit or add to this file if you wish to upgrade the extension to newer
6
+ * versions in the future. If you need personal customization please contact us
7
  * on http://www.waterstone.pt for more information.
8
  *
9
  * @category Waterstone
24
  $vCustAttributeGroupId = $setup->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);
25
 
26
  // Set new attribute for the customer entity
27
+ $setup->removeAttribute('customer', 'wsclient');
28
  $setup->addAttribute('customer', 'wsclient', array(
29
  'label' => 'Cliente Weo',
30
  'input' => 'text',
32
  'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
33
  'required' => 0,
34
  'user_defined' => 1,
35
+ ));
36
 
37
  // Add the attribute to the attribute group
38
  $setup->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'wsclient', 0);
53
  ));
54
 
55
  $setup->endSetup();
 
 
 
app/code/local/Waterstone/Winvoice/Model/AddInvoice.php DELETED
@@ -1,390 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * DISCLAIMER
5
- *
6
- * Do not edit or add to this file if you wish to upgrade the extension to newer
7
- * versions in the future. If you need personal customization please contact us
8
- * on http://www.waterstone.pt for more information.
9
- *
10
- * @category Waterstone
11
- * @package Waterstone_Winvoice
12
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
13
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
- */
15
-
16
- class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
17
- {
18
- /* Private variables */
19
- var $client;
20
- var $password;
21
-
22
- /**
23
- * Winvoice internal log class.
24
- *
25
- * @since 1.0.1
26
- *
27
- * @var Waterstone_Winvoice_Model_Log
28
- */
29
- private $wLog;
30
-
31
- /**
32
- * weoInvoice error codes list.
33
- *
34
- * @var array
35
- */
36
- private $errorMessages = array(
37
- '300' => 'Falha na autenticação no weoInvoice.',
38
- '301' => 'Parâmetros insuficientes.',
39
- '302' => 'Código de cliente já existente ou inválido.',
40
- '303' => 'Número de contribuinte inválido.',
41
- '304' => 'Email inválido.',
42
- '305' => 'Sem permissões para alterar o cliente.',
43
- '306' => 'Sem permissões para usar o cliente.',
44
- '307' => 'Empresa sem as informações mínimas necessárias.',
45
- '308' => 'Empresa sem a tabela de IVA correctamente preenchida.',
46
- '309' => 'Data inválida.',
47
- '310' => 'Data de pagamento inválida.',
48
- '311' => 'Data do documento não sequencial.',
49
- '312' => 'Tipo de documento inválido.',
50
- '320' => 'Não é possível criar um documento com um existente em aberto.',
51
- '321' => 'Documento não disponível.',
52
- '322' => 'Documento já fechado.',
53
- '323' => 'Informação de produtos/serviços no documento insuficiente.',
54
- '324' => 'Taxa de IVA do produto/serviço incorrecta.',
55
- '325' => 'Sem permissões para usar o documento.',
56
- '326' => 'Documento ainda está aberto.',
57
- '327' => 'Motivo da anulação do documento inexistente.',
58
- '328' => 'Motivo de isenção de IVA incorrecto ou inexistente.',
59
- '340' => 'Código de cliente inexistente.',
60
- '341' => 'Erro ao obter dados do cliente.',
61
- '350' => 'Pagamento de factura com valor inferior a zero.',
62
- '351' => 'Factura já paga.',
63
- '352' => 'Recibo com valor inferior a zero.'
64
- );
65
-
66
- /**
67
- * Constructor.
68
- * - Connect to weoInvoice api using nusoap.
69
- *
70
- * @since 1.0.0
71
- *
72
- * @return void
73
- */
74
- public function __construct()
75
- {
76
- $this->wLog = Mage::getModel('winvoice/log');
77
- date_default_timezone_set('Europe/Berlin');
78
- require_once(Mage::getBaseDir("code").'/local/Waterstone/Winvoice/Model/nusoap/lib/nusoap.php');
79
-
80
- $this->client = new nusoap_client(Mage::getStoreConfig('winvoice/wconfig/wapi'));
81
- $this->password = Mage::getStoreConfig('winvoice/wconfig/wpassword');
82
-
83
- $this->wLog->log("info", $this->client);
84
- $this->wLog->log("info", $this->password);
85
- }
86
-
87
- /**
88
- * Add invoice method.
89
- * - Gets the client products, creates a winvoice and sends to email.
90
- *
91
- * @since 1.0.0
92
- *
93
- * @param Mage_Sales_Model_Observer $observer
94
- * @return void
95
- */
96
- public function AddInvoice($observer)
97
- {
98
- $invoice = $observer->getEvent()->getInvoice();
99
- $invoiceNumber = $invoice->getEntityId();
100
-
101
- $this->wLog->log("info","Invoice Created $invoiceNumber");
102
- $useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
103
- $err = $this->client->getError();
104
-
105
- if ($err) {
106
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
107
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
108
- }
109
-
110
- // Get client items
111
- $this->client->setUseCurl($useCURL);
112
- $this->client->soap_defencoding = 'UTF-8';
113
- $items = $invoice->getAllItems();
114
-
115
- foreach ($items as $item) {
116
- if ($item->getBase_price() == 0) {
117
- continue;
118
- }
119
-
120
- $Product = array (
121
- 'item' => $item->getName(), //string (*) Nome do produto/serviço
122
- 'type' => 'P', //char (*) Tipo (P ou S) consoante seja produto ou serviço
123
- 'quantity' => number_format((float)$item->getQty(), 0, '.', ''), //double (*) Quantidade (ex: 2)
124
- 'price' => number_format((float)$item->getBase_price(), 2, '.', ''), //double (*) Preço (ex: 99.99)
125
- 'discount' => $item->getDiscountAmount(), //double Desconto (ex: 19.99)
126
- 'tax' => number_format((float)$item->getOrderItem()->getTaxPercent(), 0, '.', ''), //int (*)Taxa de IVA (ex: 23)
127
- 'taxreason' => '', // string Motivo de isenção de Taxa, caso aplicável (ver tabela Motivos de isenção de IVA)
128
- );
129
-
130
- $Products[] = $Product;
131
-
132
-
133
- $this->wLog->log("info","Item: ".$item->getName());
134
- $this->wLog->log("info", "Item Quantity: ".number_format((float)$item->getQty(), 0, '.', ''));
135
- $this->wLog->log("info", "Item Base price: ".number_format((float)$item->getBase_price(), 2, '.', ''));
136
- $this->wLog->log("info", "Item Tax: ".number_format((float)$item->getOrderItem()->getTaxPercent(), 2, '.', ''));
137
- } $this->wLog->log("info","Item discount: ".$item->getDiscountAmount());
138
-
139
- // Shipping tax value in percentage
140
- $vat = Mage::getStoreConfig('winvoice/wconfig/wshiptax');
141
-
142
- $Product = array (
143
- 'item' => $invoice->getOrder()->getShippingDescription(),
144
- 'type' => 'S',
145
- 'quantity' => '1',
146
- 'price' => number_format((float)$invoice->getOrder()->getBaseShippingAmount(), 2, '.', ''),
147
- 'discount' => '0.00',
148
- 'tax' => $vat,
149
- 'taxreason' => '',
150
- );
151
-
152
- $Products[] = $Product;
153
-
154
- $params = array(
155
- 'client' => $this->getClientNumber($invoice),
156
- 'type' => '1', //Tipo de documento (ver tabela Tipos de Documento)
157
- 'date' => date("Y-m-d"), //Data do documento (ex: 2011-01-01)
158
- 'payment_date' => date("Y-m-d"), //date (*) Data de vencimento do documento (ex: 2011-01-01)
159
- 'description' => 'F'.$invoice->getEntityId(),
160
- 'footer' => 'Numero Interno '.$invoice->getEntityId(),
161
- 'products' => $Products,
162
- 'password' => $this->password,
163
- );
164
-
165
- $result = $this->client->call("AddDocument", $params);
166
-
167
- if ($this->client->fault) {
168
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
169
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
170
- } else {
171
- $err = $this->client->getError();
172
-
173
- if ($err) {
174
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
175
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
176
- } else {
177
- $this->wLog->log("info", "Invoice Create Reply: ".$result['answer']);
178
- $this->wLog->log("info", "Invoice id: ".$result['description1']);
179
- $this->wLog->log("info", "Invoice URL: ".$result['description2']);
180
-
181
-
182
- if ( $result['answer'] <> 0 && $result['answer'] <> 1 ) {
183
- if (array_key_exists($result['answer'], $this->errorMessages)){
184
- Mage::throwException(Mage::helper('adminhtml')->__($this->errorMessages[$result['answer']]));
185
- $this->wLog->log("error", Mage::helper('adminhtml')->__($this->errorMessages[$result['answer']]));
186
- } else {
187
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
188
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
189
- }
190
- }
191
- $invoice->setWsinvoiceurl($result['description2']);
192
- }
193
- }
194
- $invoice->sendEmail(true, "Factura enviada ao cliente");
195
- $this->wLog->log("info", "Factura enviada ao cliente");
196
- }
197
-
198
- /**
199
- * Get invoice url method.
200
- * - Returns the invoice url from weoInvoice service.
201
- *
202
- * @since 1.0.0
203
- *
204
- * @param Mage_Sales_Model_Observer $observer
205
- * @return string
206
- */
207
- public function getInvoiceURL($observer)
208
- {
209
- $invoice = $observer->getEvent()->getInvoice();
210
-
211
- return $invoice->getWsinvoiceurl();
212
- }
213
-
214
- /**
215
- * Get client number method.
216
- * - Returns the invoice url from weoInvoice service.
217
- *
218
- * @since 1.0.0
219
- *
220
- * @param Mage_Sales_Model_Order_Invoice $invoice
221
- * @return string
222
- */
223
- private function getClientNumber($invoice)
224
- {
225
- $address = $invoice->getBillingAddress();
226
- if (!$address->getCountryId() == 'PT') {
227
- Mage::throwException(Mage::helper('adminhtml')->__( $invoice->getOrder()->getCustomerTaxvat().' Numero de contribuinte invalido.'));
228
- $this->wLog->log("error", Mage::helper('adminhtml')->__( $invoice->getOrder()->getCustomerTaxvat().' Numero de contribuinte invalido.'));
229
- }
230
- if (!$this->isValidNif($invoice->getOrder()->getCustomerTaxvat())) {
231
- Mage::throwException(Mage::helper('adminhtml')->__( $invoice->getOrder()->getCustomerTaxvat().' Numero de contribuinte invalido.'));
232
- $this->wLog->log("error", Mage::helper('adminhtml')->__( $invoice->getOrder()->getCustomerTaxvat().' Numero de contribuinte invalido.'));
233
- }
234
-
235
- $customer = Mage::getModel('customer/customer')->load($invoice->getOrder()->getCustomerId());
236
-
237
- $this->wLog->log("info", "Invoicing Customer name:".$invoice->getOrder()->getCustomerName());
238
- $this->wLog->log("info", "Invoicing Customer Id:".$invoice->getOrder()->getCustomerId());
239
- $this->wLog->log("info", "Invoicing Customer VAT:".$invoice->getOrder()->getCustomerTaxvat());
240
- $this->wLog->log("info", "Invoicing Customer WSClient:".$customer->getWsclient());
241
- $this->wLog->log("info", "Invoicing Customer WSClient:".$invoice->getOrder()->getCustomerWsclient());
242
- $this->wLog->log("info", "Customer address data: ".$address->getStreetFull());
243
- $this->wLog->log("info", "Customer address data: ".$address->getPostcode());
244
- $this->wLog->log("info", "Customer address data: ".$address->getCity());
245
- $this->wLog->log("info", "Customer address data: ".$address->getCountryId());
246
-
247
- if ( is_numeric( $customer->getWsclient() ) ) {
248
- return $customer->getWsclient();
249
- }
250
-
251
- $useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
252
- $err = $this->client->getError();
253
-
254
- if ($err) {
255
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
256
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
257
- exit();
258
- }
259
-
260
- $this->client->setUseCurl($useCURL);
261
- $this->client->soap_defencoding = 'UTF-8';
262
-
263
- if ( is_numeric($invoice->getOrder()->getCustomerTaxvat()) ) {
264
- $vatnumber = $invoice->getOrder()->getCustomerTaxvat();
265
- } else {
266
- $vatnumber = '999999900';
267
- }
268
-
269
- $AddClientIn = array (
270
- 'code' => "MAG".$invoice->getOrder()->getCustomerId().rand(1,999999),
271
- 'name' => $invoice->getOrder()->getCustomerName(),
272
- 'nif' => $vatnumber,
273
- // email string Endereço de email
274
- // url string Página web
275
- 'address' => $address->getStreetFull(),
276
- 'postcode' => $address->getPostcode(),
277
- 'city' => $address->getCity(),
278
- 'country' => $address->getCountryId(),
279
- // telephone string Telefone do cliente (ex: 212109902)
280
- // mobile string Telemóvel do cliente
281
- // fax string Fax do cliente
282
- // description string Descrição
283
- );
284
-
285
- $params = array(
286
- 'data' => $AddClientIn,
287
- 'password'=> $this->password,
288
- );
289
-
290
- $result = $this->client->call("AddClient", $params);
291
-
292
- if ($this->client->fault) {
293
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
294
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
295
- } else {
296
- $err = $this->client->getError();
297
-
298
- if ($err) {
299
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
300
- $this->wLog->log("error", Mage::helper('adminhtml')->__('Erro ao criar factura.'));
301
- } else {
302
- if ( $invoice->getOrder()->getCustomerId() ) {
303
- $customer = Mage::getModel('customer/customer')->load($invoice->getOrder()->getCustomerId());
304
- $customer->setWsclient($result['description1']);
305
- $customer->save();
306
- } else {
307
- $this->wLog->log("info", "One time costumer processed");
308
- }
309
-
310
- $this->wLog->log("info", "Created new WSClient ".$result['description1']);
311
- $this->wLog->log("info", "Created new WSClient api code ".$result['answer']);
312
-
313
- return $result['description1'];
314
- }
315
- }
316
- }
317
-
318
- /**
319
- * Auto invoice method.
320
- * - Prepares order to create and send invoice to client.
321
- *
322
- * @since 1.0.0
323
- *
324
- * @param Mage_Sales_Model_Observer $observer
325
- * @return void
326
- */
327
- public function AutoInvoice($observer)
328
- {
329
- return;
330
-
331
- $this->wLog->Log("info", "AutoInvoice trigger for order".$observer->getEvent()->getOrder());
332
-
333
- $order = $observer->getEvent()->getShipment()->getOrder();
334
-
335
- $invoice = $order->prepareInvoice();
336
- $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
337
- $invoice->register();
338
- $invoice->getOrder()->setCustomerNoteNotify(true);
339
- $invoice->getOrder()->setIsInProcess(true);
340
-
341
- $order->addStatusHistoryComment('AutoInvoice by Winvoice.', false);
342
-
343
- $transactionSave = Mage::getModel('core/resource_transaction')
344
- ->addObject($invoice)
345
- ->addObject($invoice->getOrder());
346
-
347
- $transactionSave->save();
348
-
349
- $invoice->sendEmail(true, "Factura enviada ao cliente");
350
- }
351
-
352
- /**
353
- * Is valid nif method.
354
- * - Checks if nif number is valid.
355
- *
356
- * @since 1.0.0
357
- *
358
- * @param string $nif
359
- * @return bool
360
- */
361
- public function isValidNif($nif)
362
- {
363
- if (!is_numeric($nif) || strlen($nif) != 9) return false;
364
-
365
- $narray = str_split($nif);
366
-
367
- if ($narray[0] != 1 && $narray[0] != 2 && $narray[0] != 5 && $narray[0] != 6 && $narray[0] != 8 && $narray[0] != 9) {
368
- return false;
369
- }
370
-
371
- $checkbit = $narray[0] * 9;
372
-
373
- for ($i=2; $i<=8; $i++) {
374
- $checkbit += $nif[$i-1] * (10 - $i);
375
- }
376
-
377
- $checkbit = 11 - ($checkbit % 11);
378
-
379
- if ($checkbit >= 10) {
380
- $checkbit = 0;
381
- }
382
-
383
- if($nif[8] == $checkbit) {
384
- return true;
385
- }
386
-
387
- return false;
388
- }
389
-
390
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Waterstone/Winvoice/Model/Log.php DELETED
@@ -1,65 +0,0 @@
1
- <?php
2
- /**
3
- * DISCLAIMER
4
- *
5
- * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
- * on http://www.waterstone.pt for more information.
8
- *
9
- * @category Waterstone
10
- * @package Waterstone_Winvoice
11
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
12
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
- */
14
-
15
- class Waterstone_Winvoice_Model_Log extends Mage_Core_Model_Abstract
16
- {
17
- /**
18
- * construtor para a classe log
19
- *
20
- * @since 1.0.1
21
- *
22
- * @return Waterstone_Winvoice_Model_Log
23
- */
24
- public function __construct() {
25
-
26
- if(!is_dir(Mage::getBaseDir('log'))) {
27
- mkdir(Mage::getBaseDir('var').DS.'log', 0777);
28
- $file = fopen($dir, "a");
29
-
30
- if ($file == false) {
31
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar ficheiro de log.'));
32
- }
33
- } else {
34
- $dir = Mage::getBaseDir('log') . '/winvoice.log';
35
- $file = fopen($dir, "a");
36
-
37
- if ($file == false) {
38
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar ficheiro de log.'));
39
- }
40
- }
41
- }
42
-
43
- /**
44
- * Função chamada noutras classes para efectuar os logs.
45
- *
46
- * @since 1.0.1
47
- *
48
- * @param string $type tipo de log a ser escrito
49
- * @param string $message messagem a ser impressa
50
- * @return file output escrita no ficheiro winvoice.log
51
- */
52
- public function log($type, $message) {
53
-
54
- $date = date("Y-m-d H:i:s");
55
- $file = fopen(Mage::getBaseDir('log').'/winvoice.log', "a");
56
-
57
- if ($file == true) {
58
- $write = fwrite($file, "$date: $type: $message \n");
59
- } else {
60
- Mage::throwException(Mage::helper('adminhtml')->__('Erro ao escrever no ficheiro de log.'));
61
- }
62
-
63
- fclose($file);
64
- }
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Waterstone/Winvoice/Model/Mysql4/Winvoice.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
- /**
3
- * DISCLAIMER
4
- *
5
- * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
- * on http://www.waterstone.pt for more information.
8
- *
9
- * @category Waterstone
10
- * @package Waterstone_Winvoice
11
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
12
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
- */
14
-
15
- class Waterstone_Winvoice_Model_Mysql4_Winvoice extends Mage_Core_Model_Mysql4_Abstract
16
- {
17
-
18
- /**
19
- * Constructor.
20
- *
21
- * @since 1.0.0
22
- *
23
- * @return void
24
- */
25
- public function _construct()
26
- {
27
- // Note that the winvoice_id refers to the key field in your database table.
28
- $this->_init('winvoice/winvoice', 'winvoice_id');
29
- }
30
-
31
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Waterstone/Winvoice/Model/Mysql4/Winvoice/Collection.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
- /**
3
- * DISCLAIMER
4
- *
5
- * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
- * on http://www.waterstone.pt for more information.
8
- *
9
- * @category Waterstone
10
- * @package Waterstone_Winvoice
11
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
12
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
- */
14
-
15
- class Waterstone_Winvoice_Model_Mysql4_Winvoice_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
16
- {
17
- /**
18
- * Constructor.
19
- *
20
- * @since 1.0.0
21
- *
22
- * @return void
23
- */
24
- public function _construct()
25
- {
26
- parent::_construct();
27
-
28
- $this->_init('winvoice/winvoice');
29
- }
30
-
31
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Waterstone/Winvoice/Model/Status.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
- /**
3
- * DISCLAIMER
4
- *
5
- * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
- * on http://www.waterstone.pt for more information.
8
- *
9
- * @category Waterstone
10
- * @package Waterstone_Winvoice
11
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
12
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
- */
14
-
15
- class Waterstone_Winvoice_Model_Status extends Varien_Object
16
- {
17
- /* Constants */
18
- const STATUS_ENABLED = 1;
19
- const STATUS_DISABLED = 2;
20
-
21
- /**
22
- * Get options array method.
23
- * - Returns an array with the model status options.
24
- *
25
- * @since 1.0.0
26
- *
27
- * @return array
28
- */
29
- static public function getOptionArray()
30
- {
31
- return array(
32
- self::STATUS_ENABLED => Mage::helper('winvoice')->__('Enabled'),
33
- self::STATUS_DISABLED => Mage::helper('winvoice')->__('Disabled')
34
- );
35
- }
36
-
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Waterstone/Winvoice/controllers/Adminhtml/WinvoiceController.php DELETED
@@ -1,335 +0,0 @@
1
- <?php
2
- /**
3
- * DISCLAIMER
4
- *
5
- * Do not edit or add to this file if you wish to upgrade the extension to newer
6
- * versions in the future. If you need personal customization please contact us
7
- * on http://www.waterstone.pt for more information.
8
- *
9
- * @category Waterstone
10
- * @package Waterstone_Winvoice
11
- * @copyright Copyright (c) 2014 Waterstone Consulting, Lda. (http://www.waterstone.pt)
12
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
- */
14
-
15
- class Waterstone_Winvoice_Adminhtml_WinvoiceController extends Mage_Adminhtml_Controller_action
16
- {
17
- /**
18
- * Initialization action.
19
- * - Initializes the layout activating the menu and breadcrumbs.
20
- *
21
- * @since 1.0.0
22
- *
23
- * @return Waterstone_Winvoice_Adminhtml_WinvoiceController
24
- */
25
- protected function _initAction()
26
- {
27
- $this->loadLayout()
28
- ->_setActiveMenu('winvoice/items')
29
- ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
30
-
31
- return $this;
32
- }
33
-
34
- /**
35
- * Index action.
36
- * - Renders the layout.
37
- *
38
- * @since 1.0.0
39
- *
40
- * @return void
41
- */
42
- public function indexAction()
43
- {
44
- $this->_initAction()->renderLayout();
45
- }
46
-
47
- /**
48
- * Edit action.
49
- * - Sets the breadcrumb items and layout blocks. Renders the layout.
50
- * - On error redirect to previous url.
51
- *
52
- * @since 1.0.0
53
- *
54
- * @return void
55
- */
56
- public function editAction()
57
- {
58
- $id = $this->getRequest()->getParam('id');
59
- $model = Mage::getModel('winvoice/winvoice')->load($id);
60
-
61
- if ($model->getId() || $id == 0) {
62
-
63
- $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
64
-
65
- if (!empty($data)) {
66
- $model->setData($data);
67
- }
68
-
69
- Mage::register('winvoice_data', $model);
70
-
71
- $this->loadLayout();
72
- $this->_setActiveMenu('winvoice/items');
73
-
74
- $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
75
- $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
76
-
77
- $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
78
-
79
- $this->_addContent($this->getLayout()->createBlock('winvoice/adminhtml_winvoice_edit'))
80
- ->_addLeft($this->getLayout()->createBlock('winvoice/adminhtml_winvoice_edit_tabs'));
81
-
82
- $this->renderLayout();
83
- } else {
84
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('winvoice')->__('Item does not exist'));
85
- $this->_redirect('*/*/');
86
- }
87
- }
88
-
89
- /**
90
- * New action.
91
- * - Forwards to edit action.
92
- *
93
- * @since 1.0.0
94
- *
95
- * @return void
96
- */
97
- public function newAction()
98
- {
99
- $this->_forward('edit');
100
- }
101
-
102
- /**
103
- * Save action.
104
- * - Adds image files to data and redirects to previous url
105
- * - On error redirect to previous url.
106
- *
107
- * @since 1.0.0
108
- *
109
- * @return void
110
- */
111
- public function saveAction()
112
- {
113
- if ($data = $this->getRequest()->getPost()) {
114
-
115
- if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
116
-
117
- try {
118
-
119
- /* Starting upload */
120
- $uploader = new Varien_File_Uploader('filename');
121
-
122
- // Any extention would work
123
- $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
124
- $uploader->setAllowRenameFiles(false);
125
-
126
- // Set the file upload mode
127
- // false -> get the file directly in the specified folder
128
- // true -> get the file in the product like folders
129
- // (file.jpg will go in something like /media/f/i/file.jpg)
130
- $uploader->setFilesDispersion(false);
131
-
132
- // We set media as the upload dir
133
- $path = Mage::getBaseDir('media') . DS ;
134
-
135
- $uploader->save($path, $_FILES['filename']['name']);
136
- } catch (Exception $e) {
137
- // Do nothing
138
- }
139
-
140
- // This way the name is saved in DB
141
- $data['filename'] = $_FILES['filename']['name'];
142
- }
143
-
144
- $model = Mage::getModel('winvoice/winvoice');
145
- $model->setData($data)->setId($this->getRequest()->getParam('id'));
146
-
147
- try {
148
-
149
- if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
150
- $model->setCreatedTime(now())->setUpdateTime(now());
151
- } else {
152
- $model->setUpdateTime(now());
153
- }
154
-
155
- $model->save();
156
-
157
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('winvoice')->__('Item was successfully saved'));
158
- Mage::getSingleton('adminhtml/session')->setFormData(false);
159
-
160
- if ($this->getRequest()->getParam('back')) {
161
- $this->_redirect('*/*/edit', array('id' => $model->getId()));
162
- return;
163
- }
164
-
165
- $this->_redirect('*/*/');
166
- return;
167
-
168
- } catch (Exception $e) {
169
-
170
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
171
- Mage::getSingleton('adminhtml/session')->setFormData($data);
172
-
173
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
174
- return;
175
- }
176
- }
177
-
178
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('winvoice')->__('Unable to find item to save'));
179
- $this->_redirect('*/*/');
180
- }
181
-
182
- /**
183
- * Delete action.
184
- *
185
- * @since 1.0.0
186
- *
187
- * @return void
188
- */
189
- public function deleteAction()
190
- {
191
- if( $this->getRequest()->getParam('id') > 0 ) {
192
-
193
- try {
194
- $model = Mage::getModel('winvoice/winvoice');
195
- $model->setId($this->getRequest()->getParam('id'))->delete();
196
-
197
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
198
- $this->_redirect('*/*/');
199
-
200
- } catch (Exception $e) {
201
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
202
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
203
- }
204
- }
205
-
206
- $this->_redirect('*/*/');
207
- }
208
-
209
- /**
210
- * Mass delete action.
211
- *
212
- * @since 1.0.0
213
- *
214
- * @return void
215
- */
216
- public function massDeleteAction()
217
- {
218
- $winvoiceIds = $this->getRequest()->getParam('winvoice');
219
-
220
- if(!is_array($winvoiceIds)) {
221
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
222
- } else {
223
- try {
224
- foreach ($winvoiceIds as $winvoiceId) {
225
- $winvoice = Mage::getModel('winvoice/winvoice')->load($winvoiceId);
226
- $winvoice->delete();
227
- }
228
-
229
- Mage::getSingleton('adminhtml/session')->addSuccess(
230
- Mage::helper('adminhtml')->__(
231
- 'Total of %d record(s) were successfully deleted', count($winvoiceIds)
232
- )
233
- );
234
-
235
- } catch (Exception $e) {
236
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
237
- }
238
- }
239
-
240
- $this->_redirect('*/*/index');
241
- }
242
-
243
- /**
244
- * Mass status action.
245
- *
246
- * @since 1.0.0
247
- *
248
- * @return void
249
- */
250
- public function massStatusAction()
251
- {
252
- $winvoiceIds = $this->getRequest()->getParam('winvoice');
253
-
254
- if(!is_array($winvoiceIds)) {
255
- Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
256
- } else {
257
- try {
258
- foreach ($winvoiceIds as $winvoiceId) {
259
- $winvoice = Mage::getSingleton('winvoice/winvoice')
260
- ->load($winvoiceId)
261
- ->setStatus($this->getRequest()->getParam('status'))
262
- ->setIsMassupdate(true)
263
- ->save();
264
- }
265
-
266
- $this->_getSession()->addSuccess(
267
- $this->__('Total of %d record(s) were successfully updated', count($winvoiceIds))
268
- );
269
- } catch (Exception $e) {
270
- $this->_getSession()->addError($e->getMessage());
271
- }
272
- }
273
-
274
- $this->_redirect('*/*/index');
275
- }
276
-
277
- /**
278
- * Export CSV action.
279
- *
280
- * @since 1.0.0
281
- *
282
- * @return void
283
- */
284
- public function exportCsvAction()
285
- {
286
- $fileName = 'winvoice.csv';
287
- $content = $this->getLayout()->createBlock('winvoice/adminhtml_winvoice_grid')->getCsv();
288
-
289
- $this->_sendUploadResponse($fileName, $content);
290
- }
291
-
292
- /**
293
- * Export XML action.
294
- *
295
- * @since 1.0.0
296
- *
297
- * @return void
298
- */
299
- public function exportXmlAction()
300
- {
301
- $fileName = 'winvoice.xml';
302
- $content = $this->getLayout()->createBlock('winvoice/adminhtml_winvoice_grid')->getXml();
303
-
304
- $this->_sendUploadResponse($fileName, $content);
305
- }
306
-
307
- /**
308
- * Send upload response action.
309
- * - Sets the document headers for file download.
310
- *
311
- * @since 1.0.0
312
- *
313
- * @param string $fileName
314
- * @param string $content
315
- * @param string $contentType
316
- * @return void
317
- */
318
- protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
319
- {
320
- $response = $this->getResponse();
321
- $response->setHeader('HTTP/1.1 200 OK','');
322
- $response->setHeader('Pragma', 'public', true);
323
- $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
324
- $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
325
- $response->setHeader('Last-Modified', date('r'));
326
- $response->setHeader('Accept-Ranges', 'bytes');
327
- $response->setHeader('Content-Length', strlen($content));
328
- $response->setHeader('Content-type', $contentType);
329
- $response->setBody($content);
330
- $response->sendResponse();
331
-
332
- die;
333
- }
334
-
335
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/etc/modules/Waterstone_Winvoice.xml DELETED
@@ -1,27 +0,0 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/osl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
- *
16
- * @category Waterstone
17
- * @package Waterstone_Winvoice
18
- */
19
- -->
20
- <config>
21
- <modules>
22
- <Waterstone_Winvoice>
23
- <active>true</active>
24
- <codePool>local</codePool>
25
- </Waterstone_Winvoice>
26
- </modules>
27
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,23 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Waterstone_Winvoice</name>
4
- <version>1.0.1.2</version>
5
  <stability>stable</stability>
6
- <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Portuguese certified invoice provider</summary>
10
- <description>.</description>
11
- <notes>Change log:&#xD;
12
- &#xD;
13
- - Added labels for errors.&#xD;
14
- - Added discount field when applicable.&#xD;
15
- - Improved NIF autentication.&#xD;
16
- - VAT now being read from backend.</notes>
17
- <authors><author><name>Waterstone</name><user>waterstone</user><email>info@waterstone.pt</email></author></authors>
18
- <date>2014-06-04</date>
19
- <time>20:18:40</time>
20
- <contents><target name="magelocal"><dir name="Waterstone"><dir name="Winvoice"><dir name="Helper"><file name="Data.php" hash="793437e2a036dae3ab1097f5de91d27d"/></dir><dir name="Model"><file name="AddInvoice.php" hash="2819ed5adc413eb646a69ad5dbcaf62c"/><dir name="Email"><dir name="Template"><file name="Mailer.php" hash="d990fe62b70529b6fcdb2c3e72cb0480"/></dir></dir><file name="Log.php" hash="d9f0200dd7c95dbf9bf5953462932526"/><dir name="Mysql4"><dir name="Winvoice"><file name="Collection.php" hash="2dd253dfae89056b584de8524a329a27"/></dir><file name="Winvoice.php" hash="6c1c7b045b65bddc395c828edb60ebe0"/></dir><dir name="Order"><file name="Invoice.php" hash="3670cfdea82e27da66d32556760c7e22"/></dir><file name="Status.php" hash="0e33254db1775e85fdd95773d9612c5c"/><dir name="nusoap"><dir name="lib"><file name="changelog" hash="3919a6a82b4f75206da9feaf8ceec3ed"/><file name="class.nusoap_base.php" hash="926c4daafe38a19c5d8444c270714741"/><file name="class.soap_fault.php" hash="cfd584361ababce6337b99e5979d7c4d"/><file name="class.soap_parser.php" hash="99ebb296b20d61d0161a037904366759"/><file name="class.soap_server.php" hash="5fd364995957f5c38a535a04a4be4384"/><file name="class.soap_transport_http.php" hash="2fedc17e37799b06e489d6a89c66453e"/><file name="class.soap_val.php" hash="ddd9047b47c42e5cbb2a88897372cb4f"/><file name="class.soapclient.php" hash="682f206b6917a163bc085d5093817767"/><file name="class.wsdl.php" hash="cafbf5025785922c4b6ecb005fd9b387"/><file name="class.wsdlcache.php" hash="89e38c3a9b266bce6ce70953829e0b70"/><file name="class.xmlschema.php" hash="f2a76931ddbd07c85ec882e736c2b90d"/><file name="nusoap.php" hash="675597fb030e84c0a3041bbceff9a2de"/><file name="nusoapmime.php" hash="29d372d39482f75b12655a562a10b822"/></dir><dir name="samples"><file name="client1.php" hash="d409d0bae57e8d4c13fefd63bec70b84"/><file name="client2.php" hash="7b95031a64f7b5975610520385503c37"/><file name="client3.php" hash="c6f1a9a2c44fac36fadcd4631373a998"/><file name="getfile1client.php" hash="c8e9b2d47e157bea50cd4285d6989e3d"/><file name="getfile2client.php" hash="b1338a810f91d58973c95b9d12c579e3"/><file name="index.html" hash="b52de1d66171cade209a651328ac3f97"/><file name="mimeclient.php" hash="0b1196705730ee220b42f1197599dcfa"/><file name="sslclient.php" hash="b790bf099c5d983c848cdd3571ee05df"/><file name="wsdlclient1.php" hash="b114369ba77f166e02da529678f0e74b"/><file name="wsdlclient10.php" hash="b63c4edc9cdbe4fe0ef69ca2250538e8"/><file name="wsdlclient11.php" hash="f3bc441f4b1747612510c3644dd00367"/><file name="wsdlclient12.php" hash="b1413252ca52f96a01b6d30ad1dc341e"/><file name="wsdlclient13.php" hash="d93cbd256bffa0fc637012451466ff0d"/><file name="wsdlclient14.php" hash="496b7d67e53bf2573ca2a35c4f0e696e"/><file name="wsdlclient15.php" hash="7ef02ec40fb271b281a4dc698035ae25"/><file name="wsdlclient2.php" hash="9fd136cd8355714cf3780116d1cb6b2f"/><file name="wsdlclient3.php" hash="5cb748a2989ae8c6c151c43a9b16a51b"/><file name="wsdlclient3b.php" hash="d7eb5f646f946438b034b818098f941d"/><file name="wsdlclient3c.php" hash="22220ca28722857ff04a519b1a89280f"/><file name="wsdlclient4.php" hash="06160017a0748dc2e39d63150a17b869"/><file name="wsdlclient5.php" hash="4503ba03f13e5f75c7a69e09253c5ba9"/><file name="wsdlclient6.php" hash="9376d30095c9572d50cec1294914b51f"/><file name="wsdlclient7.php" hash="92640c4e76c3c024d57434d638fedd78"/><file name="wsdlclient8.php" hash="61fea89801914afc8c99119a5ea090ef"/><file name="wsdlclient9.php" hash="d2111b6ae75bb3fe104a51e845208e4b"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="WinvoiceController.php" hash="cf1aa2e70e3343c8f173bf7bb56d867a"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="28cda20f40db5efb00659ae4bd83f19e"/><file name="config.xml" hash="4facb1261181ee1af3b323e0893d5fbd"/><file name="system.xml" hash="8b75637d21e01e24be2d4c61c7a23ebe"/></dir><dir name="sql"><dir name="winvoice_setup"><file name="mysql4-install-0.1.0.php" hash="92b059cb47ed001e285ff7b11e7311bd"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Waterstone_Winvoice.xml" hash="5a9b97b844970a29a117656cb53b46c0"/></dir></dir></dir></target></contents>
21
  <compatible/>
22
- <dependencies><required><php><min>5.4.12</min><max>5.5.12</max></php><package><name>Mage_Core_Modules</name><channel>core</channel><min>1.5.0</min><max>1.9.0.1</max></package></required></dependencies>
23
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Waterstone_Winvoice</name>
4
+ <version>1.0.2</version>
5
  <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSLv3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Generates shipping documents registered by Portuguese Tax and Customs Authority (Autoridade Tribut&#xE1;ria).</summary>
10
+ <description>This extension allows you to get a registered shipping document when the Magento shipment is created. Each time a shipment is created, the extension communicates with AT via SOAP web service, and saves the returned data. The most important data is the code attributed by AT to the document, which is the legal identification of the shipping document.</description>
11
+ <notes>- Bug fixes.&#xD;
12
+ </notes>
13
+ <authors><author><name>Waterstone Consulting</name><user>waterstone</user><email>info@waterstone.pt</email></author></authors>
14
+ <date>2014-09-15</date>
15
+ <time>18:07:48</time>
16
+ <contents><target name="magecommunity"><dir name="Waterstone"><dir name="Winvoice"><dir name="Helper"><file name="Data.php" hash="4594de10b13553a77b77ea70dea289aa"/></dir><dir name="Model"><file name="AddInvoice.php" hash="e389de4c3ec9666dd1d7e339252936eb"/><dir name="Email"><dir name="Template"><file name="Mailer.php" hash="d990fe62b70529b6fcdb2c3e72cb0480"/></dir></dir><dir name="Order"><file name="Invoice.php" hash="3670cfdea82e27da66d32556760c7e22"/></dir><dir name="nusoap"><dir name="lib"><file name="changelog" hash="3919a6a82b4f75206da9feaf8ceec3ed"/><file name="class.nusoap_base.php" hash="926c4daafe38a19c5d8444c270714741"/><file name="class.soap_fault.php" hash="cfd584361ababce6337b99e5979d7c4d"/><file name="class.soap_parser.php" hash="99ebb296b20d61d0161a037904366759"/><file name="class.soap_server.php" hash="5fd364995957f5c38a535a04a4be4384"/><file name="class.soap_transport_http.php" hash="2fedc17e37799b06e489d6a89c66453e"/><file name="class.soap_val.php" hash="ddd9047b47c42e5cbb2a88897372cb4f"/><file name="class.soapclient.php" hash="682f206b6917a163bc085d5093817767"/><file name="class.wsdl.php" hash="cafbf5025785922c4b6ecb005fd9b387"/><file name="class.wsdlcache.php" hash="89e38c3a9b266bce6ce70953829e0b70"/><file name="class.xmlschema.php" hash="f2a76931ddbd07c85ec882e736c2b90d"/><file name="nusoap.php" hash="675597fb030e84c0a3041bbceff9a2de"/><file name="nusoapmime.php" hash="29d372d39482f75b12655a562a10b822"/></dir><dir name="samples"><file name="client1.php" hash="d409d0bae57e8d4c13fefd63bec70b84"/><file name="client2.php" hash="7b95031a64f7b5975610520385503c37"/><file name="client3.php" hash="c6f1a9a2c44fac36fadcd4631373a998"/><file name="getfile1client.php" hash="c8e9b2d47e157bea50cd4285d6989e3d"/><file name="getfile2client.php" hash="b1338a810f91d58973c95b9d12c579e3"/><file name="index.html" hash="b52de1d66171cade209a651328ac3f97"/><file name="mimeclient.php" hash="0b1196705730ee220b42f1197599dcfa"/><file name="sslclient.php" hash="b790bf099c5d983c848cdd3571ee05df"/><file name="wsdlclient1.php" hash="b114369ba77f166e02da529678f0e74b"/><file name="wsdlclient10.php" hash="b63c4edc9cdbe4fe0ef69ca2250538e8"/><file name="wsdlclient11.php" hash="f3bc441f4b1747612510c3644dd00367"/><file name="wsdlclient12.php" hash="b1413252ca52f96a01b6d30ad1dc341e"/><file name="wsdlclient13.php" hash="d93cbd256bffa0fc637012451466ff0d"/><file name="wsdlclient14.php" hash="496b7d67e53bf2573ca2a35c4f0e696e"/><file name="wsdlclient15.php" hash="7ef02ec40fb271b281a4dc698035ae25"/><file name="wsdlclient2.php" hash="9fd136cd8355714cf3780116d1cb6b2f"/><file name="wsdlclient3.php" hash="5cb748a2989ae8c6c151c43a9b16a51b"/><file name="wsdlclient3b.php" hash="d7eb5f646f946438b034b818098f941d"/><file name="wsdlclient3c.php" hash="22220ca28722857ff04a519b1a89280f"/><file name="wsdlclient4.php" hash="06160017a0748dc2e39d63150a17b869"/><file name="wsdlclient5.php" hash="4503ba03f13e5f75c7a69e09253c5ba9"/><file name="wsdlclient6.php" hash="9376d30095c9572d50cec1294914b51f"/><file name="wsdlclient7.php" hash="92640c4e76c3c024d57434d638fedd78"/><file name="wsdlclient8.php" hash="61fea89801914afc8c99119a5ea090ef"/><file name="wsdlclient9.php" hash="d2111b6ae75bb3fe104a51e845208e4b"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="28cda20f40db5efb00659ae4bd83f19e"/><file name="config.xml" hash="ec82de303eb439432573a3caaca0464a"/><file name="system.xml" hash="b0ecef65a0b7a75b0d3f91abe112cc73"/></dir><dir name="sql"><dir name="winvoice_setup"><file name="mysql4-install-0.1.0.php" hash="ef4bb8d83cdaadf47cdb23244eaad6bc"/></dir></dir></dir></dir></target></contents>
 
 
 
 
17
  <compatible/>
18
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.8</min><max>1.9</max></package></required></dependencies>
19
  </package>