Qinvoice_Connect - Version 1.1.3

Version Notes

Fixed issue with multiple products same SKU, different custom option

Download this release

Release Info

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


Code changes from version 1.1.1 to 1.1.3

app/code/community/Qinvoice/CHANGELOG CHANGED
@@ -1,5 +1,14 @@
1
  CHANGELOG
2
 
 
 
 
 
 
 
 
 
 
3
  v1.1.0 - 2014/06/25
4
  - Added attributes for display on item line
5
 
1
  CHANGELOG
2
 
3
+ v1.1.3 - 2015/02/26
4
+ - Fixed issue with multiple products same SKU, different custom option
5
+
6
+ v1.1.2 - 2014/10/25
7
+ - Fixed issue with phone number
8
+
9
+ v1.1.1 - 2014/08/25
10
+ - Bundled products support
11
+
12
  v1.1.0 - 2014/06/25
13
  - Added attributes for display on item line
14
 
app/code/community/Qinvoice/Connect/Model/Order/Observer.Boerdereike.php CHANGED
@@ -362,7 +362,7 @@ class Qinvoice_Connect_Model_Order_Observer
362
  'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
363
  'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
364
  'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
365
- 'discount' => trim(number_format($arrData[$i]['base_discount_amount'], 2, '.', '')/$arrData[$i]['base_price'])*100,
366
  'quantity' => $arrData[$i]['qty_ordered']*100,
367
  'categories' => $category
368
  );
@@ -393,23 +393,51 @@ class Qinvoice_Connect_Model_Order_Observer
393
 
394
  }
395
 
396
- if($rowOne['base_discount_amount'] > 0)
397
- {
398
- $params = array(
399
- 'code' => '',
400
- 'description' => trim($rowOne['coupon_code']),
401
- 'price' => $rowOne['base_discount_amount']*100,
402
- 'price_incl' => $rowOne['base_discount_amount']*100,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  'price_vat' => 0,
404
  'vatpercentage' => 0,
405
  'discount' => 0,
406
- 'quantity' => 100,
407
  'categories' => 'discount'
408
  );
409
 
410
- $invoice->addItem($params);
411
-
412
- }
 
 
413
 
414
 
415
  $result = $invoice->sendRequest();
362
  'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
363
  'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
364
  'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
365
+ 'discount' => 0,
366
  'quantity' => $arrData[$i]['qty_ordered']*100,
367
  'categories' => $category
368
  );
393
 
394
  }
395
 
396
+ // if($rowOne['base_discount_amount'] > 0)
397
+ // {
398
+ // $params = array(
399
+ // 'code' => '',
400
+ // 'description' => trim($rowOne['coupon_code']),
401
+ // 'price' => $rowOne['base_discount_amount']*100,
402
+ // 'price_incl' => $rowOne['base_discount_amount']*100,
403
+ // 'price_vat' => 0,
404
+ // 'vatpercentage' => 0,
405
+ // 'discount' => 0,
406
+ // 'quantity' => 100,
407
+ // 'categories' => 'discount'
408
+ // );
409
+
410
+ // $invoice->addItem($params);
411
+
412
+ // }
413
+
414
+ $couponCode = $rowOne['coupon_code'];
415
+ //echo $couponCode;
416
+ //print_r($order);
417
+ // $couponCode = $orderDetails['coupon_code'];
418
+
419
+ if($couponCode > ''){
420
+ $oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
421
+ $oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
422
+ //var_dump($oRule->getData());
423
+
424
+ $params = array(
425
+ 'code' => 'DSCNT',
426
+ 'description' => $couponCode,
427
+ 'price' => ($rowOne['base_subtotal'] * ($oRule->getDiscountAmount()/100))*100,
428
+ 'price_incl' => ($rowOne['base_subtotal'] * ($oRule->getDiscountAmount()/100))*100,
429
  'price_vat' => 0,
430
  'vatpercentage' => 0,
431
  'discount' => 0,
432
+ 'quantity' => -100,
433
  'categories' => 'discount'
434
  );
435
 
436
+ $invoice->addItem($params);
437
+ }
438
+
439
+
440
+
441
 
442
 
443
  $result = $invoice->sendRequest();
app/code/community/Qinvoice/Connect/Model/Order/Observer.php CHANGED
@@ -102,7 +102,7 @@ class Qinvoice_Connect_Model_Order_Observer
102
  $varCurrenyCode = Mage::app()->getStore()->getCurrentCurrency()->getCode();
103
  // GETTING ORDER STATUS
104
  $prefix = Mage::getConfig()->getTablePrefix();
105
- $resultOne = $db->query("SELECT entity_id, status, customer_email, base_currency_code, shipping_description, shipping_amount, shipping_tax_amount, increment_id, grand_total, total_paid, billing_address_id, shipping_address_id, customer_taxvat FROM {$prefix}sales_flat_order WHERE entity_id=".$varOrderID);
106
  $rowOne = $resultOne->fetch(PDO::FETCH_ASSOC);
107
 
108
 
@@ -128,7 +128,7 @@ class Qinvoice_Connect_Model_Order_Observer
128
  }
129
 
130
  $prefix = Mage::getConfig()->getTablePrefix();
131
- $result = $db->query("SELECT item_id, product_type, product_id, product_options, order_id, sku, name, description, qty_ordered, base_price, tax_percent, tax_amount, base_discount_amount FROM {$prefix}sales_flat_order_item WHERE order_id=".$varOrderID." AND parent_item_id IS NULL GROUP BY sku HAVING (order_id > 0) ORDER BY item_id desc");
132
 
133
 
134
  if(!$result) {
@@ -294,7 +294,7 @@ class Qinvoice_Connect_Model_Order_Observer
294
  }
295
 
296
 
297
-
298
 
299
  for($i=0;$i<count($arrData);$i++)
300
  {
@@ -359,7 +359,7 @@ class Qinvoice_Connect_Model_Order_Observer
359
  'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
360
  'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
361
  'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
362
- 'discount' => trim(number_format($arrData[$i]['base_discount_amount'], 2, '.', '')/$arrData[$i]['base_price'])*100,
363
  'quantity' => $arrData[$i]['qty_ordered']*100,
364
  'categories' => $category
365
  );
@@ -371,7 +371,7 @@ class Qinvoice_Connect_Model_Order_Observer
371
  if($rowOne['shipping_amount'] > 0)
372
  {
373
  $params = array(
374
- 'code' => '',
375
  'description' => trim($rowOne['shipping_description']),
376
  'price' => $rowOne['shipping_amount']*100,
377
  'price_incl' => $rowOne['shipping_incl_tax']*100,
@@ -386,10 +386,64 @@ class Qinvoice_Connect_Model_Order_Observer
386
 
387
  }
388
 
389
-
390
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
 
392
  $result = $invoice->sendRequest();
 
 
393
  if($result != 1){
394
  $this->notify_admin('Qinvoice Connect Error','Could not send invoice for order '. $order_id);
395
  }
@@ -531,7 +585,7 @@ class qinvoice{
531
  <login mode="newInvoice">
532
  <username><![CDATA['.$this->username.']]></username>
533
  <password><![CDATA['.$this->password.']]></password>
534
- <identifier><![CDATA[Magento_1.0.9]]></identifier>
535
  </login>
536
  <invoice>
537
  <companyname><![CDATA['. $this->companyname .']]></companyname>
102
  $varCurrenyCode = Mage::app()->getStore()->getCurrentCurrency()->getCode();
103
  // GETTING ORDER STATUS
104
  $prefix = Mage::getConfig()->getTablePrefix();
105
+ $resultOne = $db->query("SELECT entity_id, status, customer_email, coupon_code, base_currency_code, shipping_description, shipping_amount, shipping_tax_amount, increment_id, grand_total, total_paid, billing_address_id, shipping_address_id, customer_taxvat, base_subtotal FROM {$prefix}sales_flat_order WHERE entity_id=".$varOrderID);
106
  $rowOne = $resultOne->fetch(PDO::FETCH_ASSOC);
107
 
108
 
128
  }
129
 
130
  $prefix = Mage::getConfig()->getTablePrefix();
131
+ $result = $db->query("SELECT item_id, product_type, product_id, product_options, order_id, sku, name, description, qty_ordered, base_price, tax_percent, tax_amount, base_discount_amount FROM {$prefix}sales_flat_order_item WHERE order_id=".$varOrderID." AND parent_item_id IS NULL HAVING (order_id > 0) ORDER BY item_id desc");
132
 
133
 
134
  if(!$result) {
294
  }
295
 
296
 
297
+ //print_r($order);
298
 
299
  for($i=0;$i<count($arrData);$i++)
300
  {
359
  'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
360
  'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
361
  'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
362
+ 'discount' => 0,
363
  'quantity' => $arrData[$i]['qty_ordered']*100,
364
  'categories' => $category
365
  );
371
  if($rowOne['shipping_amount'] > 0)
372
  {
373
  $params = array(
374
+ 'code' => 'SHPMNT',
375
  'description' => trim($rowOne['shipping_description']),
376
  'price' => $rowOne['shipping_amount']*100,
377
  'price_incl' => $rowOne['shipping_incl_tax']*100,
386
 
387
  }
388
 
389
+ // $order = Mage::getModel('sales/order')->loadByIncrementId($varOrderID);
390
+
391
+ // $orderDetails = $order->getData();
392
+
393
+ $couponCode = $rowOne['coupon_code'];
394
+ //echo $couponCode;
395
+ //print_r($order);
396
+ // $couponCode = $orderDetails['coupon_code'];
397
+
398
+ if($couponCode > ''){
399
+ $oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
400
+ $oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
401
+ var_dump($oRule->getData());
402
+
403
+ $ruleData = $oRule->getData();
404
+
405
+ $discount = $ruleData['discount_amount'];
406
+ $params = array(
407
+ 'code' => 'DSCNT',
408
+ 'description' => $couponCode,
409
+ 'price' => ($rowOne['base_subtotal'] * ($discount/100))*100,
410
+ 'price_incl' => ($rowOne['base_subtotal'] * ($discount/100))*100,
411
+ 'price_vat' => 0,
412
+ 'vatpercentage' => 0,
413
+ 'discount' => 0,
414
+ 'quantity' => -100,
415
+ 'categories' => 'discount'
416
+ );
417
+
418
+ $invoice->addItem($params);
419
+ }
420
+
421
+
422
+ // $coupon = Mage::getModel('salesrule/rule');
423
+ // $couponCollection = $coupon->getCollection();
424
+ // foreach($couponCollection as $c){
425
+ // print_r($c);
426
+ // echo 'Code:'.$c->getCode().'--->Discount Amount:'.$c->getDiscountAmount().'<br />';
427
+
428
+ // $params = array(
429
+ // 'code' => 'DSCNT',
430
+ // 'description' => $c->getCode(),
431
+ // 'price' => $rowOne['base_subtotal'] * ($c->getDiscountAmount()/100),
432
+ // 'price_incl' => $rowOne['base_subtotal'] * ($c->getDiscountAmount()/100),
433
+ // 'price_vat' => 0,
434
+ // 'vatpercentage' => 0,
435
+ // 'discount' => 0,
436
+ // 'quantity' => -100,
437
+ // 'categories' => 'discount'
438
+ // );
439
+
440
+ // $invoice->addItem($params);
441
+
442
+ // }
443
 
444
  $result = $invoice->sendRequest();
445
+
446
+
447
  if($result != 1){
448
  $this->notify_admin('Qinvoice Connect Error','Could not send invoice for order '. $order_id);
449
  }
585
  <login mode="newInvoice">
586
  <username><![CDATA['.$this->username.']]></username>
587
  <password><![CDATA['.$this->password.']]></password>
588
+ <identifier><![CDATA[Magento_1.1.2]]></identifier>
589
  </login>
590
  <invoice>
591
  <companyname><![CDATA['. $this->companyname .']]></companyname>
app/code/community/Qinvoice/Connect/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
- <version>1.1.1</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
@@ -13,23 +13,23 @@
13
  </invoice>
14
  </models>
15
  <events>
16
- <sales_order_invoice_register>
17
  <observers>
18
  <connect>
19
  <class>invoice/order_observer</class>
20
  <method>sendOnOrder</method>
21
  </connect>
22
  </observers>
23
- </sales_order_invoice_register>
24
 
25
- <sales_order_invoice_pay>
26
  <observers>
27
  <connect>
28
  <class>invoice/order_observer</class>
29
  <method>sendOnPayment</method>
30
  </connect>
31
  </observers>
32
- </sales_order_invoice_pay>
33
  </events>
34
  <helpers>
35
  <invoice>
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
+ <version>1.1.2</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
13
  </invoice>
14
  </models>
15
  <events>
16
+ <sales_order_place_after>
17
  <observers>
18
  <connect>
19
  <class>invoice/order_observer</class>
20
  <method>sendOnOrder</method>
21
  </connect>
22
  </observers>
23
+ </sales_order_place_after>
24
 
25
+ <sales_order_payment_pay>
26
  <observers>
27
  <connect>
28
  <class>invoice/order_observer</class>
29
  <method>sendOnPayment</method>
30
  </connect>
31
  </observers>
32
+ </sales_order_payment_pay>
33
  </events>
34
  <helpers>
35
  <invoice>
app/code/community/Qinvoice/Invoice/Order/Observer.php ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //class NameSpaceName_ModuleName_Model_ObserverDir_Observer
3
+ class Qinvoice_Invoice_Order_Observer
4
+ {
5
+ public function __contruct()
6
+ {
7
+
8
+ }
9
+
10
+ public function sendOnOrder($observer){
11
+ $order = $observer->getEvent()->getOrder();
12
+
13
+ // GETTING TRIGGER SETTING
14
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
15
+ $varPath = 'invoice_options/invoice/invoice_on_order';
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 == 1){
21
+ $this->createInvoiceForQinvoice($order->getId(), false);
22
+ }else{
23
+ return true;
24
+ }
25
+ }
26
+ /**
27
+ * Exports new orders to an xml file
28
+ * @param Varien_Event_Observer $observer
29
+ * @return Feed_Sales_Model_Order_Observer
30
+ */
31
+ public function sendOnPayment($observer){
32
+ // Gets called even when other payment method is choosen.
33
+
34
+ $order_ids = $observer->getEvent()->getOrderIds();
35
+ $order = $observer->getEvent()->getOrder();
36
+
37
+ // GETTING TRIGGER SETTING
38
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
39
+ $varPath = 'invoice_options/invoice/invoice_on_order';
40
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
41
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
42
+ $varOnOrder = $rowTwo['value'];
43
+
44
+ if($varOnOrder == 0){
45
+ $this->createInvoiceForQinvoice($order_ids[0], true);
46
+ }else{
47
+ return true;
48
+ }
49
+ }
50
+ public function createInvoiceForQinvoice($varOrderID,$ifPaid = false)
51
+ {
52
+ $paid = 0;
53
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
54
+ // GETTING ORDER ID
55
+ //$resultOne = $db->query("SELECT max(entity_id) as LastOrderID FROM sales_flat_order");
56
+ //$rowOne = $resultOne->fetch(PDO::FETCH_ASSOC);
57
+
58
+ //$varOrderID = $rowOne['LastOrderID'];
59
+
60
+ $varCurrenyCode = Mage::app()->getStore()->getCurrentCurrency()->getCode();
61
+ // GETTING ORDER STATUS
62
+ $resultOne = $db->query("SELECT entity_id, status, customer_email, base_currency_code, shipping_description, shipping_amount, shipping_tax_amount, increment_id, grand_total, total_paid FROM sales_flat_order WHERE entity_id=".$varOrderID);
63
+ $rowOne = $resultOne->fetch(PDO::FETCH_ASSOC);
64
+
65
+
66
+ if($rowOne['status'] == 'processing' || $rowOne['status'] == 'complete' || $rowOne['total_paid'] == $rowOne['grand_total'])
67
+ {
68
+ $varStatus = 'Paid';
69
+ // GETTING API URL
70
+ $varURLPath = 'invoice_options/invoice/paid_remark';
71
+ $resultURL = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varURLPath."'");
72
+ $rowURL = $resultURL->fetch(PDO::FETCH_ASSOC);
73
+ $paid_remark = $rowURL['value'];
74
+ $paid = 1;
75
+ }
76
+ else
77
+ {
78
+ if($ifPaid == true){
79
+ // cancel if invoice has to be paid
80
+ return;
81
+ }
82
+ $paid_remark = '';
83
+ $varStatus = 'Sent';
84
+ }
85
+
86
+ $result = $db->query("SELECT item_id, product_type, product_options, order_id, sku, name, description, qty_ordered, base_price, tax_percent, tax_amount, base_discount_amount FROM sales_flat_order_item WHERE order_id=".$varOrderID." AND parent_item_id IS NULL GROUP BY sku HAVING (order_id > 0) ORDER BY item_id desc");
87
+
88
+ if(!$result) {
89
+ //return false;
90
+ }
91
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
92
+ $arrData[] = $row;
93
+ }
94
+ if(!$arrData) {
95
+ //return false;
96
+ }
97
+ //$comment = '';
98
+ //$comment = $data['comment_text'];
99
+ // getting po_number
100
+ $random_number = rand(0, pow(10, 7));
101
+
102
+ // GETTING API USERNAME
103
+ $varPath = 'invoice_options/invoice/api_username';
104
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
105
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
106
+ $username = $rowTwo['value'];
107
+
108
+ // GETTING API PASSWORD
109
+ $varPath = 'invoice_options/invoice/api_password';
110
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
111
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
112
+ $password = $rowTwo['value'];
113
+
114
+ // GETTING LAYOUT CODE
115
+ $varPath = 'invoice_options/invoice/layout_code';
116
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
117
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
118
+ $layout_code = $rowTwo['value'];
119
+
120
+
121
+ // GETTING CLIENT DETAILS
122
+ $resultThree = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode FROM sales_flat_order_address WHERE email='".$rowOne['customer_email']."'");
123
+ $rowThree = $resultThree->fetch(PDO::FETCH_ASSOC);
124
+
125
+ $invoice = new qinvoice($username,$password);
126
+
127
+ $invoice->companyname = $rowThree['firstname'].' '.$rowThree['lastname']; // Your customers company name
128
+ $invoice->contactname = $rowThree['firstname'].' '.$rowThree['lastname']; // Your customers contact name
129
+ $invoice->email = $rowOne['customer_email']; // Your customers emailaddress (invoice will be sent here)
130
+ $invoice->address = $rowThree['street']; // Self-explanatory
131
+ $invoice->zipcode = $rowThree['postcode']; // Self-explanatory
132
+ $invoice->city = $rowThree['city']; // Self-explanatory
133
+ $invoice->country = ''; // 2 character country code: NL for Netherlands, DE for Germany etc
134
+ $invoice->vat = ''; // Self-explanatory
135
+ $invoice->paid = $paid;
136
+
137
+ $varRemarkPath = 'invoice_options/invoice/invoice_remark';
138
+ $resultRemark = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varRemarkPath."'");
139
+ $rowRemark = $resultRemark->fetch(PDO::FETCH_ASSOC);
140
+ $invoice_remark = $rowRemark['value'];
141
+ $invoice->remark = str_replace('{order_id}',$rowOne['increment_id'],$invoice_remark) .' '. $paid_remark; // Self-explanatory
142
+
143
+ $varSendPath = 'invoice_options/invoice/send_mail';
144
+ $resultSend = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varSendPath."'");
145
+ $rowSend = $resultSend->fetch(PDO::FETCH_ASSOC);
146
+ $send_mail = $rowSend['value'];
147
+
148
+ $varLayoutPath = 'invoice_options/invoice/layout_code';
149
+ $resultLayout = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varLayoutPath."'");
150
+ $rowLayout = $resultLayout->fetch(PDO::FETCH_ASSOC);
151
+ $invoice_layout = $rowLayout['value'];
152
+
153
+ $invoice->setLayout($invoice_layout);
154
+
155
+ $varTagPath = 'invoice_options/invoice/invoice_tag';
156
+ $resultTag = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varTagPath."'");
157
+ $rowTag = $resultTag->fetch(PDO::FETCH_ASSOC);
158
+ $invoice_tag = $rowTag['value'];
159
+
160
+ $invoice->send = $send_mail;
161
+
162
+ // OPTIONAL: Add tags
163
+ $invoice->addTag($rowOne['increment_id']);
164
+ $invoice->addTag($invoice_tag);
165
+ // $invoice->addTag('send: '. $send_mail);
166
+ // $invoice->addTag('paid: '. $paid .' '. $rowOne['total_paid']);
167
+
168
+
169
+ for($i=0;$i<count($arrData);$i++)
170
+ {
171
+ $arrItemOptions = unserialize($arrData[$i]['product_options']);
172
+
173
+ $varDescription = '';
174
+ if(@$arrItemOptions['options'])
175
+ {
176
+ for($k=0; $k <count($arrItemOptions['options']); $k++)
177
+ {
178
+ $varDescription .= $arrItemOptions['options'][$k]['label'].": ".$arrItemOptions['options'][$k]['print_value']."\n";
179
+ }
180
+ }
181
+ else
182
+ if(@$arrItemOptions['attributes_info'])
183
+ {
184
+ for($k=0; $k <count($arrItemOptions['attributes_info']); $k++)
185
+ {
186
+ $varDescription .= $arrItemOptions['attributes_info'][$k]['label'].": ".$arrItemOptions['attributes_info'][$k]['value']."\n";
187
+ }
188
+ }
189
+ else
190
+ {
191
+ $varDescription = "[".$arrData[$i]['sku']."] ".trim($arrData[$i]['name']);
192
+ }
193
+
194
+ $price = $arrData[$i]['base_price'];
195
+ $price_incl = round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered']));
196
+ $price_vat = ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered']);
197
+
198
+
199
+ $discount = 0;
200
+ if($invoice->calculation_method == 'incl'){
201
+ // calculate discount over gross price
202
+ $discount = ($arrData[$i]['base_discount_amount']/($price_incl*$arrData[$i]['qty_ordered']))*100;
203
+ }else{
204
+ // calculate discount over net price
205
+ $discount = ($arrData[$i]['base_discount_amount']/($price*$arrData[$i]['qty_ordered']))*100;
206
+ }
207
+
208
+
209
+ $params = array(
210
+ 'description' => $arrData[$i]['name'] ."\n". $varDescription,
211
+ 'price' => $price*100,
212
+ 'price_incl' => $price_incl*100,
213
+ 'price_vat' => $price_vat*100,
214
+ 'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
215
+ 'discount' => $discount*100,
216
+ 'quantity' => $arrData[$i]['qty_ordered']*100,
217
+ 'categories' => ''
218
+ );
219
+ //mail('casper@expertnetwork.nl', 'vat', $arrData[$i]['tax_percent']);
220
+ $invoice->addItem($params);
221
+
222
+ }
223
+ if($rowOne['shipping_amount'] > 0)
224
+ {
225
+ $params = array(
226
+ 'description' => trim($rowOne['shipping_description']),
227
+ 'price' => $rowOne['shipping_amount']*100,
228
+ 'vatpercentage' => ($rowOne['shipping_tax_amount']/$rowOne['shipping_amount'])*100,
229
+ 'discount' => 0,
230
+ 'quantity' => 100,
231
+ 'categories' => 'shipping'
232
+ );
233
+
234
+ $invoice->addItem($params);
235
+
236
+ }
237
+
238
+
239
+ $result = $invoice->sendRequest();
240
+ if($result == 1){
241
+ //notify_to_admin('Casper Mekel','casper@newday.sk','Invoice generated!');
242
+ }else{
243
+ //notify_to_admin('Casper Mekel','casper@newday.sk','Something went wrong!');
244
+ }
245
+ return true;
246
+
247
+
248
+ //$curlInvoiveResult = $this->sendCurlRequest($createInvoiceXML);
249
+
250
+ // GETTING SEND MAIL SETTING
251
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
252
+ $varPath = 'invoice_options/invoice/send_mail';
253
+ $resultTwo = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varPath."'");
254
+ $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
255
+ $varSendMailFlag = $rowTwo['value'];
256
+
257
+ if($varSendMailFlag && 1==2)
258
+ {
259
+ $xml = stripslashes($curlInvoiveResult);
260
+ $objXml = new SimpleXMLElement($xml);
261
+ $arrParamList = $this->objectsIntoArray($objXml);
262
+
263
+ if($arrParamList['@attributes']['status'] == '200')
264
+ {
265
+ $varInvoiceID = $arrParamList['invoice_id'];
266
+
267
+ $varSendInvoiceXml = '<?xml version="1.0" encoding="utf-8"?>
268
+ <request method="sendInvoiceMail">
269
+ <invoice_id>'.$varInvoiceID.'</invoice_id>
270
+ </request>';
271
+ $curlInvoiceSendResult = $this->sendCurlRequest($varSendInvoiceXml);
272
+
273
+ }
274
+
275
+ }
276
+ }
277
+
278
+ public function notify_to_admin($name, $email, $msg)
279
+ {
280
+ $varSubject = 'Qinvoice Notification';
281
+
282
+ //Mage::log($msg);
283
+
284
+ $mail = Mage::getModel('core/email');
285
+ $mail->setToName($name);
286
+ $mail->setToEmail($email);
287
+ $mail->setBody($msg);
288
+ $mail->setSubject($varSubject);
289
+ $mail->setFromEmail("support@qinvoice.com");
290
+ $mail->setFromName("Qinvoice Development");
291
+ $mail->setType('text');
292
+ $mail->send();
293
+ }
294
+ }
295
+
296
+ class qinvoice{
297
+
298
+ protected $gateway = '';
299
+ private $username;
300
+ private $password;
301
+
302
+ public $companyname;
303
+ public $contactname;
304
+ public $email;
305
+ public $address;
306
+ public $city;
307
+ public $country;
308
+ public $vatnumber;
309
+ public $remark;
310
+ public $paid;
311
+ public $send;
312
+
313
+ public $layout;
314
+
315
+ private $tags = array();
316
+ private $items = array();
317
+ private $files = array();
318
+ private $recurring;
319
+
320
+ function __construct($username, $password){
321
+ $this->username = $username;
322
+ $this->password = $password;
323
+ $this->recurring = 'none';
324
+
325
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
326
+
327
+ // GETTING API URL
328
+ $varURLPath = 'invoice_options/invoice/api_url';
329
+ $resultURL = $db->query("SELECT value FROM core_config_data WHERE path LIKE '".$varURLPath."'");
330
+ $rowURL = $resultURL->fetch(PDO::FETCH_ASSOC);
331
+ $apiURL = $rowURL['value'];
332
+
333
+ $this->gateway = $apiURL;
334
+ }
335
+
336
+ public function addTag($tag){
337
+ $this->tags[] = $tag;
338
+ }
339
+
340
+ public function setLayout($code){
341
+ $this->layout = $code;
342
+ }
343
+
344
+ public function setRecurring($recurring){
345
+ $this->recurring = strtolower($recurring);
346
+ }
347
+
348
+ public function addItem($params){
349
+ $item['description'] = $params['description'];
350
+ $item['price'] = $params['price'];
351
+ $item['vatpercentage'] = $params['vatpercentage'];
352
+ $item['discount'] = $params['discount'];
353
+ $item['quantity'] = $params['quantity'];
354
+ $item['categories'] = $params['categories'];
355
+ $this->items[] = $item;
356
+ }
357
+
358
+ public function addFile($name, $url){
359
+ $this->files[] = array('url' => $url, 'name' => $name);
360
+ }
361
+
362
+ public function sendRequest() {
363
+ $content = "<?xml version='1.0' encoding='UTF-8'?>";
364
+ $content .= $this->buildXML();
365
+
366
+ $headers = array("Content-type: application/atom+xml");
367
+ $ch = curl_init();
368
+ curl_setopt($ch, CURLOPT_URL, $this->gateway );
369
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
370
+ curl_setopt($ch, CURLOPT_TIMEOUT, 120);
371
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
372
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
373
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
374
+ $data = curl_exec($ch);
375
+ if (curl_errno($ch)) {
376
+ print curl_error($ch);
377
+ } else {
378
+ curl_close($ch);
379
+ }
380
+ if($data == 1){
381
+ return true;
382
+ }else{
383
+ return false;
384
+ }
385
+
386
+ }
387
+
388
+ private function buildXML(){
389
+ $string = '<request>
390
+ <login mode="newInvoice">
391
+ <username>'.$this->username.'</username>
392
+ <password>'.$this->password.'</password>
393
+ </login>
394
+ <invoice>
395
+ <companyname>'. $this->companyname .'</companyname>
396
+ <contactname>'. $this->contactname .'</contactname>
397
+ <email>'. $this->email .'</email>
398
+ <address>'. $this->address .'</address>
399
+ <zipcode>'. $this->zipcode .'</zipcode>
400
+ <city>'. $this->city .'</city>
401
+ <country>'. $this->country .'</country>
402
+ <vat>'. $this->vatnumber .'</vat>
403
+ <recurring>'. $this->recurring .'</recurring>
404
+ <remark>'. $this->remark .'</remark>
405
+ <layout>'. $this->layout .'</layout>
406
+ <paid>'. $this->paid .'</paid>
407
+ <send>'. $this->send .'</send>
408
+ <tags>';
409
+ foreach($this->tags as $tag){
410
+ $string .= '<tag>'. $tag .'</tag>';
411
+ }
412
+
413
+ $string .= '</tags>
414
+ <items>';
415
+ foreach($this->items as $i){
416
+
417
+ $string .= '<item>
418
+ <quantity>'. $i['quantity'] .'</quantity>
419
+ <description>'. $i['description'] .'</description>
420
+ <price>'. $i['price'] .'</price>
421
+ <vatpercentage>'. $i['vatpercentage'] .'</vatpercentage>
422
+ <discount>'. $i['discount'] .'</discount>
423
+ <categories>'. $i['categories'] .'</categories>
424
+
425
+ </item>';
426
+ }
427
+
428
+ $string .= '</items>
429
+ <files>';
430
+ foreach($this->files as $f){
431
+ $string .= '<file url="'.$f['url'].'">'.$f['name'].'</file>';
432
+ }
433
+ $string .= '</files>
434
+ </invoice>
435
+ </request>';
436
+ return $string;
437
+ }
438
+ }
439
+
440
+ ?>
package.xml CHANGED
@@ -1,19 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
- <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Automatically generate and send PDF invoices for every order to your customers through q-invoice.com</summary>
10
  <description>Invoices can be generated upon a successful payment or order and will be added to your administration. Q-invoice offers you the freedom to run multiple webshops or venues but still have your bookkeeping together at one place. Generate invoices in a layout of your choosing for maximal recognition, upload bankstatements and process payment with the click of your mouse. www.q-invoice.com</description>
11
- <notes>Compatible with v1.9 and 1.8&#xD;
12
- Support for bundled products</notes>
13
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
14
- <date>2014-11-14</date>
15
- <time>11:06:48</time>
16
- <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="fe63e41117f38a39736c3354a7b1d11d"/><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="8ecdeaa4e9a41de7d5debfaf22967761"/><file name="Observer.php" hash="56c978beaeded1e98c65bfdf05554703"/></dir><dir name="Source"><file name="Attribute.php" hash="72f35ffb8cd873d2c5e1e448ff4bf4e2"/><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Method.php" hash="ac6891fc7e403250b24f5b0f2d6199bc"/><file name="Relation.php" hash="89ab031937b846ab5f0bcac7ccaa31b7"/><file name="Trigger.php" hash="be2c0e4bfc32c0bdd57b4b1b58da8d63"/></dir></dir><dir name="etc"><file name="config.xml" hash="2c0d57f3c6a0b7874d8263e268dbc4c6"/><file name="system.xml" hash="0f7c10edfb8942199b277a0170babe30"/></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>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
+ <version>1.1.3</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Automatically generate and send PDF invoices for every order to your customers through q-invoice.com</summary>
10
  <description>Invoices can be generated upon a successful payment or order and will be added to your administration. Q-invoice offers you the freedom to run multiple webshops or venues but still have your bookkeeping together at one place. Generate invoices in a layout of your choosing for maximal recognition, upload bankstatements and process payment with the click of your mouse. www.q-invoice.com</description>
11
+ <notes>Fixed issue with multiple products same SKU, different custom option</notes>
 
12
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
13
+ <date>2015-02-26</date>
14
+ <time>15:05:07</time>
15
+ <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="b505f62586635992441f58e1b48509b6"/><dir name="Connect"><dir name="etc"><file name="config.xml" hash="84a4748dd2b5f37c4a5af69a90aeaa2c"/><file name="system.xml" hash="0f7c10edfb8942199b277a0170babe30"/></dir><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="cdcda959a699ac24eb3f7d8ff906f18e"/><file name="Observer.php" hash="fa3f6bf52536b97c74556a5c78cb7f4c"/></dir><dir name="Source"><file name="Attribute.php" hash="72f35ffb8cd873d2c5e1e448ff4bf4e2"/><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Method.php" hash="ac6891fc7e403250b24f5b0f2d6199bc"/><file name="Relation.php" hash="89ab031937b846ab5f0bcac7ccaa31b7"/><file name="Trigger.php" hash="be2c0e4bfc32c0bdd57b4b1b58da8d63"/></dir></dir><file name="readme.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="Invoice"><dir name="Order"><file name="Observer.php" hash="84e53ee2885045cebb1321901afec083"/></dir></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><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
18
  </package>