Waterstone_Winvoice - Version 1.0.4

Version Notes

.

Download this release

Release Info

Developer Waterstone
Extension Waterstone_Winvoice
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.3 to 1.0.4

app/code/community/Waterstone/Winvoice/Model/AddInvoice.php CHANGED
@@ -113,7 +113,7 @@ class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
113
  'item' => $item->getName(), //string (*) Nome do produto/serviço
114
  'type' => 'P', //char (*) Tipo (P ou S) consoante seja produto ou serviço
115
  'quantity' => number_format((float)$item->getQty(), 0, '.', ''), //double (*) Quantidade (ex: 2)
116
- 'price' => number_format((float)$item->getBase_price(), 2, '.', ''), //double (*) Preço (ex: 99.99)
117
  'discount' => $item->getDiscountAmount(), //double Desconto (ex: 19.99)
118
  'tax' => number_format((float)$item->getOrderItem()->getTaxPercent(), 0, '.', ''), //int (*)Taxa de IVA (ex: 23)
119
  'taxreason' => '', // string Motivo de isenção de Taxa, caso aplicável (ver tabela Motivos de isenção de IVA)
@@ -135,7 +135,7 @@ class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
135
  'item' => $invoice->getOrder()->getShippingDescription(),
136
  'type' => 'S',
137
  'quantity' => '1',
138
- 'price' => number_format((float)$invoice->getOrder()->getBaseShippingAmount(), 2, '.', ''),
139
  'discount' => number_format((float)$invoice->getOrder()->getBaseShippingDiscountAmount(), 2, '.', ''),
140
  'tax' => $vat,
141
  'taxreason' => '',
@@ -182,13 +182,20 @@ class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
182
  Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
183
  }
184
  }
185
-
186
- $invoice->setWsinvoiceurl($result['description2']);
 
 
 
 
 
 
 
 
187
  }
188
  }
189
 
190
- $invoice->sendEmail(true, "Factura enviada ao cliente");
191
- Mage::log("Winvoice | Factura enviada ao cliente", null, 'winvoice.log', true);
192
  }
193
 
194
  /**
@@ -350,6 +357,87 @@ class Waterstone_Winvoice_Model_AddInvoice extends Mage_Core_Model_Abstract
350
  $invoice->sendEmail(true, "Factura enviada ao cliente");
351
  }
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  /**
354
  * Is valid nif method.
355
  * - Checks if nif number is valid.
113
  'item' => $item->getName(), //string (*) Nome do produto/serviço
114
  'type' => 'P', //char (*) Tipo (P ou S) consoante seja produto ou serviço
115
  'quantity' => number_format((float)$item->getQty(), 0, '.', ''), //double (*) Quantidade (ex: 2)
116
+ 'price' => round($item->getPriceInclTax()/( 1 + $item->getOrderItem()->getTaxPercent()/100), 6), //double (*) Preço (ex: 99.99)
117
  'discount' => $item->getDiscountAmount(), //double Desconto (ex: 19.99)
118
  'tax' => number_format((float)$item->getOrderItem()->getTaxPercent(), 0, '.', ''), //int (*)Taxa de IVA (ex: 23)
119
  'taxreason' => '', // string Motivo de isenção de Taxa, caso aplicável (ver tabela Motivos de isenção de IVA)
135
  'item' => $invoice->getOrder()->getShippingDescription(),
136
  'type' => 'S',
137
  'quantity' => '1',
138
+ 'price' => round($invoice->getOrder()->getBaseShippingInclTax()/( 1 + $vat/100), 6),
139
  'discount' => number_format((float)$invoice->getOrder()->getBaseShippingDiscountAmount(), 2, '.', ''),
140
  'tax' => $vat,
141
  'taxreason' => '',
182
  Mage::throwException(Mage::helper('adminhtml')->__('Erro ao criar factura.'));
183
  }
184
  }
185
+
186
+ $prefix = Mage::getConfig()->getTablePrefix();
187
+ $resource = Mage::getSingleton('core/resource')->getConnection('core_read');
188
+ $resource->addColumn($prefix.'sales_flat_invoice', 'wsinvoiceurl', 'Varchar(300) NULL');
189
+ $resource->addColumn($prefix.'sales_flat_invoice', 'wsinvoiceid', 'INT NULL');
190
+
191
+ $invoiceId = $result['description1'];
192
+ $invoiceUrl = $result['description2'];
193
+ $invoice->setWsinvoiceurl($invoiceUrl);
194
+ $invoice->setWsinvoiceid($invoiceId);
195
  }
196
  }
197
 
198
+
 
199
  }
200
 
201
  /**
357
  $invoice->sendEmail(true, "Factura enviada ao cliente");
358
  }
359
 
360
+ /**
361
+ * Add credit memo method.
362
+ * - Gets information for the credit memo and sends it outwards.
363
+ *
364
+ * @since 1.0.4
365
+ *
366
+ * @param Varien_Event_Observer $observer
367
+ * @return void
368
+ */
369
+ public function addCreditMemo($observer)
370
+ {
371
+ $creditmemo = $observer->getEvent()->getCreditmemo();
372
+
373
+ $vat = Mage::getStoreConfig('winvoice/wconfig/wshiptax');
374
+
375
+ $prefix = Mage::getConfig()->getTablePrefix();
376
+ $resource = Mage::getSingleton('core/resource')->getConnection('core_read');
377
+ $resource->addColumn($prefix.'sales_flat_creditmemo', 'wscreditmemourl', 'Varchar(300) NULL');
378
+
379
+ $orderId = $creditmemo->getOrder()->getId();
380
+ $table = $prefix.'sales_flat_invoice';
381
+
382
+ $query = "SELECT wsinvoiceid FROM $table WHERE order_id = $orderId";
383
+
384
+ $invoice_id = $resource->fetchOne($query);
385
+ $items = $creditmemo->getAllItems();
386
+
387
+ foreach ($items as $item) {
388
+ if ($item->getBase_price() == 0) {
389
+ continue;
390
+ }
391
+
392
+ $Product = array (
393
+ 'item' => $item->getName(), //string (*) Nome do produto/serviço
394
+ 'type' => 'P', //char (*) Tipo (P ou S) consoante seja produto ou serviço
395
+ 'quantity' => number_format((float)$item->getQty(), 0, '.', ''), //double (*) Quantidade (ex: 2)
396
+ 'price' => round($item->getPriceInclTax()/( 1 + $item->getOrderItem()->getTaxPercent()/100), 6), //double (*) Preço (ex: 99.99)
397
+ 'discount' => $item->getDiscountAmount(), //double Desconto (ex: 19.99)
398
+ 'tax' => number_format((float)$item->getOrderItem()->getTaxPercent(), 0, '.', ''), //int (*)Taxa de IVA (ex: 23)
399
+ 'taxreason' => '', // string Motivo de isenção de Taxa, caso aplicável (ver tabela Motivos de isenção de IVA)
400
+ );
401
+
402
+ $Products[] = $Product;
403
+ }
404
+
405
+
406
+ $Product = array (
407
+ 'item' => $creditmemo->getOrder()->getShippingDescription(),
408
+ 'type' => 'S',
409
+ 'quantity' => '1',
410
+ 'price' => round($creditmemo->getOrder()->getBaseShippingInclTax()/( 1 + $vat/100), 6),
411
+ 'discount' => number_format((float)$creditmemo->getOrder()->getBaseShippingDiscountAmount(), 2, '.', ''),
412
+ 'tax' => $vat,
413
+ 'taxreason' => '',
414
+ );
415
+
416
+ $Products[] = $Product;
417
+
418
+
419
+ $params = array(
420
+ 'client' => $this->getClientNumber($creditmemo),
421
+ 'type' => '6', //Tipo de documento (ver tabela Tipos de Documento)
422
+ 'date' => date("Y-m-d"), //Data do documento (ex: 2011-01-01)
423
+ 'payment_date' => date("Y-m-d"), //date (*) Data de vencimento do documento (ex: 2011-01-01)
424
+ 'description' => '',
425
+ 'footer' => utf8_decode('Nota de crédito: '.$creditmemo->getIncrementId()),
426
+ 'products' => $Products,
427
+ 'password' => $this->password,
428
+ 'custom' => $invoice_id,
429
+ );
430
+
431
+ $result = $this->client->call("AddDocument", $params);
432
+ $url = $result['description2'];
433
+ $creditmemo->setWscreditmemourl($url);
434
+
435
+ }
436
+
437
+
438
+
439
+
440
+
441
  /**
442
  * Is valid nif method.
443
  * - Checks if nif number is valid.
app/code/community/Waterstone/Winvoice/Model/Observer.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Waterstone_Winvoice_Model_Observer
4
+ {
5
+ public function adminhtmlWidgetContainerHtmlBefore(Varien_Event_Observer $observer)
6
+ {
7
+
8
+ //Create creditmemo instance and check if creditmemo exists, if so create print the button
9
+
10
+ // Check if module is enabled on Admin->Configuration->Advanced->Advanced page.
11
+ if (Mage::helper('core')->isModuleOutputEnabled('Waterstone_Winvoice')) {
12
+ $block = $observer->getBlock();
13
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_View) {
14
+ if ($block->getCreditmemo()->getIncrementId()) {
15
+ $block->addButton('creditPrint', array(
16
+ 'label' => Mage::helper('sales')->__('Imprimir Nota de Crédito'),
17
+ 'class' => 'save',
18
+ 'style' => '',
19
+ 'onclick' => 'setLocation(\''.$block->getCreditmemo()->getWscreditmemourl().'\')'
20
+ )
21
+ );
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+
28
+ }
app/code/community/Waterstone/Winvoice/etc/config.xml CHANGED
@@ -21,6 +21,17 @@
21
  <version>1.0.0</version>
22
  </Waterstone_Winvoice>
23
  </modules>
 
 
 
 
 
 
 
 
 
 
 
24
  <global>
25
  <models>
26
  <winvoice>
@@ -81,6 +92,24 @@
81
  </Waterstone_Winvoice_order_pay>
82
  </observers>
83
  </sales_order_shipment_save_after>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  </events>
85
  </global>
86
  </config>
21
  <version>1.0.0</version>
22
  </Waterstone_Winvoice>
23
  </modules>
24
+ <admin>
25
+ <routers>
26
+ <adminhtml>
27
+ <args>
28
+ <modules>
29
+ <Waterstone_Winvoice before="Mage_Adminhtml">Waterstone_Winvoice</Waterstone_Winvoice>
30
+ </modules>
31
+ </args>
32
+ </adminhtml>
33
+ </routers>
34
+ </admin>
35
  <global>
36
  <models>
37
  <winvoice>
92
  </Waterstone_Winvoice_order_pay>
93
  </observers>
94
  </sales_order_shipment_save_after>
95
+ <sales_order_creditmemo_save_before>
96
+ <observers>
97
+ <winvoice_hook_creditmemo_save_before>
98
+ <type>singleton</type>
99
+ <class>Waterstone_Winvoice_Model_AddInvoice</class>
100
+ <method>addCreditMemo</method>
101
+ </winvoice_hook_creditmemo_save_before>
102
+ </observers>
103
+ </sales_order_creditmemo_save_before>
104
+ <adminhtml_widget_container_html_before>
105
+ <observers>
106
+ <winvoice_hook_widget_container>
107
+ <type>singleton</type>
108
+ <class>Waterstone_Winvoice_Model_Observer</class>
109
+ <method>adminhtmlWidgetContainerHtmlBefore</method>
110
+ </winvoice_hook_widget_container>
111
+ </observers>
112
+ </adminhtml_widget_container_html_before>
113
  </events>
114
  </global>
115
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Waterstone_Winvoice</name>
4
- <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
@@ -10,11 +10,11 @@
10
  <description>Get certified invoices in your Magento store (Portuguese legal requirements only).&#xD;
11
  &#xD;
12
  This extension allows you to get a certified invoice when the Magento invoice is generated. It uses an external service (weoInvoice) that automatically generates your certified invoice which is sent to you in PDF, annexed to the Magento invoice email.</description>
13
- <notes>Fixed bugs and errors</notes>
14
- <authors><author><name>Waterstone Consulting</name><user>waterstone</user><email>info@waterstone.pt</email></author></authors>
15
- <date>2015-02-10</date>
16
- <time>18:43:11</time>
17
- <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="f64fe9ec4fc55018ac053c3e8f75c9f5"/><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="5af85479dec05dab223bd53d9400339b"/><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="b987e8146a9ad34b3993a103c764f3e8"/><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><target name="mageetc"><dir name="modules"><file name="Waterstone_Winvoice.xml" hash="b0e049ceaf46088498533b5caa69eae9"/></dir></target></contents>
18
  <compatible/>
19
- <dependencies><required><php><min>5.4.12</min><max>5.5.11</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Waterstone_Winvoice</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
10
  <description>Get certified invoices in your Magento store (Portuguese legal requirements only).&#xD;
11
  &#xD;
12
  This extension allows you to get a certified invoice when the Magento invoice is generated. It uses an external service (weoInvoice) that automatically generates your certified invoice which is sent to you in PDF, annexed to the Magento invoice email.</description>
13
+ <notes>.</notes>
14
+ <authors><author><name>Waterstone</name><user>waterstone</user><email>info@waterstone.pt</email></author></authors>
15
+ <date>2015-04-06</date>
16
+ <time>15:07:09</time>
17
+ <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="a7df3017897b38ee755ab88626462e11"/><dir name="Email"><dir name="Template"><file name="Mailer.php" hash="d990fe62b70529b6fcdb2c3e72cb0480"/></dir></dir><file name="Observer.php" hash="76366af3b68e4a5d913584d3de1b2923"/><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="5af85479dec05dab223bd53d9400339b"/><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="c748e93c92caaca5543170af6c1abcfc"/><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><target name="mageetc"><dir name="modules"><file name="Waterstone_Winvoice.xml" hash="b0e049ceaf46088498533b5caa69eae9"/></dir></target></contents>
18
  <compatible/>
19
+ <dependencies><required><php><min>5.3.0</min><max>5.6.7</max></php></required></dependencies>
20
  </package>