Qinvoice_Connect - Version 1.0.4

Version Notes

Added CDATA tags for products and invoice details

Download this release

Release Info

Developer Casper Mekel
Extension Qinvoice_Connect
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.2 to 1.0.4

app/code/community/Qinvoice/CHANGELOG DELETED
@@ -1,7 +0,0 @@
1
- CHANGELOG
2
-
3
- v1.0.1 - 2013/08/14
4
- - Added support for productgroups/attributes (qinvoice_category)
5
-
6
- v1.0.0 - 2013/08/13
7
- - Initial release
 
 
 
 
 
 
 
app/code/community/Qinvoice/Connect/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Qinvoice_Connect_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/community/Qinvoice/Connect/Model/Order/Observer.php CHANGED
@@ -7,6 +7,41 @@ class Qinvoice_Connect_Model_Order_Observer
7
  //parent::__construct();
8
  }
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  public function sendOnOrder($observer){
11
  $order = $observer->getEvent()->getOrder();
12
 
@@ -122,7 +157,7 @@ class Qinvoice_Connect_Model_Order_Observer
122
 
123
 
124
  // GETTING CLIENT DETAILS
125
- $resultThree = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode FROM sales_flat_order_address WHERE entity_id='".$rowOne['billing_address_id']."'");
126
  $rowThree = $resultThree->fetch(PDO::FETCH_ASSOC);
127
 
128
  $invoice = new qinvoice($username,$password);
@@ -134,18 +169,26 @@ class Qinvoice_Connect_Model_Order_Observer
134
  $invoice->address = $rowThree['street']; // Self-explanatory
135
  $invoice->zipcode = $rowThree['postcode']; // Self-explanatory
136
  $invoice->city = $rowThree['city']; // Self-explanatory
137
- $invoice->country = ''; // 2 character country code: NL for Netherlands, DE for Germany etc
138
-
139
- $resultFour = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode FROM sales_flat_order_address WHERE entity_id='".$rowOne['shipping_address_id']."'");
 
140
  $rowFour = $resultFour->fetch(PDO::FETCH_ASSOC);
141
 
142
  $invoice->delivery_address = $rowFour['street']; // Self-explanatory
143
  $invoice->delivery_zipcode = $rowFour['postcode']; // Self-explanatory
144
  $invoice->delivery_city = $rowFour['city']; // Self-explanatory
145
- $invoice->delivery_country = '';
146
 
147
  $invoice->vat = ''; // Self-explanatory
148
  $invoice->paid = $paid;
 
 
 
 
 
 
 
149
 
150
  $varRemarkPath = 'invoice_options/invoice/invoice_remark';
151
  $resultRemark = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varRemarkPath."'");
@@ -163,6 +206,22 @@ class Qinvoice_Connect_Model_Order_Observer
163
  $rowLayout = $resultLayout->fetch(PDO::FETCH_ASSOC);
164
  $invoice_layout = $rowLayout['value'];
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  $invoice->setLayout($invoice_layout);
167
 
168
  $varTagPath = 'invoice_options/invoice/invoice_tag';
@@ -370,33 +429,33 @@ class qinvoice{
370
  private function buildXML(){
371
  $string = '<request>
372
  <login mode="newInvoice">
373
- <username>'.$this->username.'</username>
374
- <password>'.$this->password.'</password>
375
  </login>
376
  <invoice>
377
- <companyname>'. $this->companyname .'</companyname>
378
- <firstname>'. $this->firstname .'</firstname>
379
- <lastname>'. $this->lastname .'</lastname>
380
- <email>'. $this->email .'</email>
381
- <address>'. $this->address .'</address>
382
- <zipcode>'. $this->zipcode .'</zipcode>
383
- <city>'. $this->city .'</city>
384
- <country>'. $this->country .'</country>
385
-
386
- <delivery_address>'. $this->delivery_address .'</delivery_address>
387
- <delivery_zipcode>'. $this->delivery_zipcode .'</delivery_zipcode>
388
- <delivery_city>'. $this->delivery_city .'</delivery_city>
389
- <delivery_country>'. $this->delivery_country .'</delivery_country>
390
-
391
- <vat>'. $this->vatnumber .'</vat>
392
- <recurring>'. $this->recurring .'</recurring>
393
- <remark>'. $this->remark .'</remark>
394
- <layout>'. $this->layout .'</layout>
395
- <paid>'. $this->paid .'</paid>
396
- <action>'. $this->action .'</action>
397
  <tags>';
398
  foreach($this->tags as $tag){
399
- $string .= '<tag>'. $tag .'</tag>';
400
  }
401
 
402
  $string .= '</tags>
@@ -404,13 +463,13 @@ class qinvoice{
404
  foreach($this->items as $i){
405
 
406
  $string .= '<item>
407
- <code>'. $i['code'] .'</code>
408
- <quantity>'. $i['quantity'] .'</quantity>
409
- <description>'. $i['description'] .'</description>
410
  <price>'. $i['price'] .'</price>
411
  <vatpercentage>'. $i['vatpercentage'] .'</vatpercentage>
412
  <discount>'. $i['discount'] .'</discount>
413
- <categories>'. $i['categories'] .'</categories>
414
 
415
  </item>';
416
  }
7
  //parent::__construct();
8
  }
9
 
10
+ public function sendOnComplete($observer){
11
+ mail('casper@newday.sk', 'sendOnComplete', 'triggered');
12
+ $order = $observer->getEvent()->getOrder();
13
+ // GETTING TRIGGER SETTING
14
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
15
+ $varPath = 'invoice_options/invoice/invoice_trigger';
16
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
17
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
18
+ $varOnOrder = $rowTwo['value'];
19
+
20
+ if($varOnOrder == 'complete' && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
21
+ $this->createInvoiceForQinvoice($order->getId(), false);
22
+ }else{
23
+ return true;
24
+ }
25
+ }
26
+
27
+ public function sendOnShip($observer){
28
+ $shipment = $observer->getEvent()->getShipment();
29
+ $order = $shipment->getOrder();
30
+
31
+ // GETTING TRIGGER SETTING
32
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
33
+ $varPath = 'invoice_options/invoice/invoice_trigger';
34
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
35
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
36
+ $varOnOrder = $rowTwo['value'];
37
+
38
+ if($varOnOrder == 'ship'){
39
+ $this->createInvoiceForQinvoice($order->getId(), false);
40
+ }else{
41
+ return true;
42
+ }
43
+ }
44
+
45
  public function sendOnOrder($observer){
46
  $order = $observer->getEvent()->getOrder();
47
 
157
 
158
 
159
  // GETTING CLIENT DETAILS
160
+ $resultThree = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode, country_id, vat_id FROM sales_flat_order_address WHERE entity_id='".$rowOne['billing_address_id']."'");
161
  $rowThree = $resultThree->fetch(PDO::FETCH_ASSOC);
162
 
163
  $invoice = new qinvoice($username,$password);
169
  $invoice->address = $rowThree['street']; // Self-explanatory
170
  $invoice->zipcode = $rowThree['postcode']; // Self-explanatory
171
  $invoice->city = $rowThree['city']; // Self-explanatory
172
+ $invoice->country = $rowThree['country_id']; // 2 character country code: NL for Netherlands, DE for Germany etc
173
+ $invoice->vatnumber = $rowThree['vat_id'];
174
+
175
+ $resultFour = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode, country_id FROM sales_flat_order_address WHERE entity_id='".$rowOne['shipping_address_id']."'");
176
  $rowFour = $resultFour->fetch(PDO::FETCH_ASSOC);
177
 
178
  $invoice->delivery_address = $rowFour['street']; // Self-explanatory
179
  $invoice->delivery_zipcode = $rowFour['postcode']; // Self-explanatory
180
  $invoice->delivery_city = $rowFour['city']; // Self-explanatory
181
+ $invoice->delivery_country = $rowFour['country_id'];
182
 
183
  $invoice->vat = ''; // Self-explanatory
184
  $invoice->paid = $paid;
185
+
186
+ $varActionPath = 'invoice_options/invoice/save_relation';
187
+ $resultAction = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varActionPath."'");
188
+ $rowAction = $resultAction->fetch(PDO::FETCH_ASSOC);
189
+ $save_relation = $rowAction['value'];
190
+
191
+ $invoice->saverelation = $save_relation;
192
 
193
  $varRemarkPath = 'invoice_options/invoice/invoice_remark';
194
  $resultRemark = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varRemarkPath."'");
206
  $rowLayout = $resultLayout->fetch(PDO::FETCH_ASSOC);
207
  $invoice_layout = $rowLayout['value'];
208
 
209
+
210
+
211
+ $invoice_layout_s = @unserialize($invoice_layout);
212
+ if ($invoice_layout_s !== false) {
213
+ // serialized
214
+ $invoice_layout = @unserialize($invoice_layout);
215
+ if(isset($invoice_layout[$rowFour['country_id']])){
216
+ $invoice_layout = @$invoice_layout[$rowFour['country_id']];
217
+ }else{
218
+ $invoice_layout = @$invoice_layout['default'];
219
+ }
220
+ } else {
221
+ // not serialized
222
+ $invoice_layout = $invoice_layout;
223
+ }
224
+
225
  $invoice->setLayout($invoice_layout);
226
 
227
  $varTagPath = 'invoice_options/invoice/invoice_tag';
429
  private function buildXML(){
430
  $string = '<request>
431
  <login mode="newInvoice">
432
+ <username><![CDATA['.$this->username.']]></username>
433
+ <password><![CDATA['.$this->password.']]></password>
434
  </login>
435
  <invoice>
436
+ <companyname><![CDATA['. $this->companyname .']]></companyname>
437
+ <firstname><![CDATA['. $this->firstname .']]></firstname>
438
+ <lastname><![CDATA['. $this->lastname .']]></lastname>
439
+ <email><![CDATA['. $this->email .']]></email>
440
+ <address><![CDATA['. $this->address .']]></address>
441
+ <zipcode><![CDATA['. $this->zipcode .']]></zipcode>
442
+ <city><![CDATA['. $this->city .']]></city>
443
+ <country><![CDATA['. $this->country .']]></country>
444
+
445
+ <delivery_address><![CDATA['. $this->delivery_address .']]></delivery_address>
446
+ <delivery_zipcode><![CDATA['. $this->delivery_zipcode .']]></delivery_zipcode>
447
+ <delivery_city><![CDATA['. $this->delivery_city .']]></delivery_city>
448
+ <delivery_country><![CDATA['. $this->delivery_country .']]></delivery_country>
449
+
450
+ <vat><![CDATA['. $this->vatnumber .']]></vat>
451
+ <recurring><![CDATA['. $this->recurring .']]></recurring>
452
+ <remark><![CDATA['. $this->remark .']]></remark>
453
+ <layout><![CDATA['. $this->layout .']]></layout>
454
+ <paid><![CDATA['. $this->paid .']]></paid>
455
+ <action><![CDATA['. $this->action .']]></action>
456
  <tags>';
457
  foreach($this->tags as $tag){
458
+ $string .= '<tag><![CDATA['. $tag .']]></tag>';
459
  }
460
 
461
  $string .= '</tags>
463
  foreach($this->items as $i){
464
 
465
  $string .= '<item>
466
+ <code><![CDATA['. $i['code'] .']]></code>
467
+ <quantity><![CDATA['. $i['quantity'] .']]></quantity>
468
+ <description><![CDATA['. $i['description'] .']]></description>
469
  <price>'. $i['price'] .'</price>
470
  <vatpercentage>'. $i['vatpercentage'] .'</vatpercentage>
471
  <discount>'. $i['discount'] .'</discount>
472
+ <categories><![CDATA['. $i['categories'] .']]></categories>
473
 
474
  </item>';
475
  }
app/code/community/Qinvoice/Connect/Model/Source/Relation.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Qinvoice_Connect_Model_Source_Relation
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value' => 0, 'label' => 'No, do nothing'),
8
+ array('value' => 1, 'label' => 'Save or update customer'),
9
+ );
10
+ }
11
+ }
12
+ ?>
app/code/community/Qinvoice/Connect/Model/Source/Trigger.php CHANGED
@@ -5,7 +5,8 @@ class Qinvoice_Connect_Model_Source_Trigger
5
  {
6
  return array(
7
  array('value' => 'order', 'label' =>'On every order'),
8
- array('value' => 'payment', 'label' => 'Only on successful payment')
 
9
  );
10
  }
11
  }
5
  {
6
  return array(
7
  array('value' => 'order', 'label' =>'On every order'),
8
+ array('value' => 'payment', 'label' => 'Only on successful payment'),
9
+ array('value' => 'ship', 'label' => 'When order is shipped')
10
  );
11
  }
12
  }
app/code/community/Qinvoice/Connect/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
- <version>1.0.2</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
@@ -13,6 +13,24 @@
13
  </invoice>
14
  </models>
15
  <events>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  <sales_order_place_after>
17
  <observers>
18
  <connect>
@@ -30,7 +48,11 @@
30
  </observers>
31
  </checkout_onepage_controller_success_action>
32
  </events>
33
-
 
 
 
 
34
  </global>
35
  <adminhtml>
36
  <acl>
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
+ <version>1.0.4</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
13
  </invoice>
14
  </models>
15
  <events>
16
+ <sales_order_status_after>
17
+ <observers>
18
+ <connect>
19
+ <class>invoice/order_observer</class>
20
+ <method>sendOnComplete</method>
21
+ </connect>
22
+ </observers>
23
+ </sales_order_status_after>
24
+
25
+ <sales_order_shipment_save_after>
26
+ <observers>
27
+ <connect>
28
+ <class>invoice/order_observer</class>
29
+ <method>sendOnShip</method>
30
+ </connect>
31
+ </observers>
32
+ </sales_order_shipment_save_after>
33
+
34
  <sales_order_place_after>
35
  <observers>
36
  <connect>
48
  </observers>
49
  </checkout_onepage_controller_success_action>
50
  </events>
51
+ <helpers>
52
+ <invoice>
53
+ <class>Qinvoice_Connect_Helper</class>
54
+ </invoice>
55
+ </helpers>
56
  </global>
57
  <adminhtml>
58
  <acl>
app/code/community/Qinvoice/Connect/etc/system.xml CHANGED
@@ -105,7 +105,16 @@
105
  <show_in_store>1</show_in_store>
106
  <comment><![CDATA[Create invoice and send to customer?]]></comment>
107
  </invoice_action>
108
-
 
 
 
 
 
 
 
 
 
109
  </fields>
110
  </invoice>
111
  </groups>
105
  <show_in_store>1</show_in_store>
106
  <comment><![CDATA[Create invoice and send to customer?]]></comment>
107
  </invoice_action>
108
+ <save_relation translate="label">
109
+ <label>Save customer details</label>
110
+ <frontend_type>select</frontend_type>
111
+ <source_model>invoice/source_relation</source_model>
112
+ <sort_order>9</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ <comment><![CDATA[Save customer details to address book?]]></comment>
117
+ </save_relation>
118
  </fields>
119
  </invoice>
120
  </groups>
package.xml CHANGED
@@ -1,31 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
- <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connects to q-invoice for sending invoices.</summary>
10
  <description>Manage your financial adminstration with q-invoice. All orders are invoiced through q-invoice and automatically added to your administration.</description>
11
- <notes>Added options for invoice action after trigger. &#xD;
12
- 0) Generate concept&#xD;
13
- 1) Finalize invoice&#xD;
14
- 2) Finalize and send&#xD;
15
- &#xD;
16
- Added support for product code&#xD;
17
- - Add attribute qinvoice_productcode &#xD;
18
- - If the product code matches a product in q-invoice, stock will be updated. &#xD;
19
- &#xD;
20
- Added support for delivery address&#xD;
21
- - The delivery address is now sent printed on the invoices and packaging slips&#xD;
22
- &#xD;
23
- *IMPORTANT* &#xD;
24
- Use API version 1.1 with this plugin</notes>
25
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
26
- <date>2013-09-03</date>
27
- <time>15:12:04</time>
28
- <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="260c1b211fcfc288a3973f2031bd79a7"/><dir name="Connect"><dir name="Model"><dir name="Order"><file name="Observer.php" hash="29751a9fea70f5fbd3de979d0e9d31d9"/></dir><dir name="Source"><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Trigger.php" hash="01f98ce71189afa6b0a112ca164c06cb"/></dir></dir><dir name="etc"><file name="config.xml" hash="0d6a10a687de2ebb038e577e2057f5f0"/><file name="system.xml" hash="0bad616d9605f6df51f2a36a69429391"/></dir><file name="readme.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qinvoice_Connect.xml" hash="fbedefa4e926092705c6941ad28f51f8"/></dir></target></contents>
29
  <compatible/>
30
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7.0</max></package><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
31
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connects to q-invoice for sending invoices.</summary>
10
  <description>Manage your financial adminstration with q-invoice. All orders are invoiced through q-invoice and automatically added to your administration.</description>
11
+ <notes>Added CDATA tags for products and invoice details</notes>
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
13
+ <date>2013-11-27</date>
14
+ <time>11:51:22</time>
15
+ <contents><target name="magecommunity"><dir name="Qinvoice"><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.php" hash="b33157d7ab843fc0a6537e4930fc0be8"/></dir><dir name="Source"><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Relation.php" hash="89ab031937b846ab5f0bcac7ccaa31b7"/><file name="Trigger.php" hash="e65427cc9773baaedae2b3897c7bf28a"/></dir></dir><dir name="etc"><file name="config.xml" hash="3e71db5013f78a2e01f4bff30521c561"/><file name="system.xml" hash="7559f766d615a0fa291eaa2c2a85912c"/></dir><file name="readme.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qinvoice_Connect.xml" hash="fbedefa4e926092705c6941ad28f51f8"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7.0</max></package><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
18
  </package>