Qinvoice_Connect - Version 2.1.3

Version Notes

Minor update

Download this release

Release Info

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


Code changes from version 2.1.2 to 2.1.3

app/code/community/Qinvoice/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
  CHANGELOG
2
 
 
 
 
3
  v2.1.2
4
  - Fixed bug
5
 
1
  CHANGELOG
2
 
3
+ v2.1.3
4
+ - Minor update
5
+
6
  v2.1.2
7
  - Fixed bug
8
 
app/code/community/Qinvoice/Connect/Model/Order/Observer.max4home.php DELETED
@@ -1,724 +0,0 @@
1
- <?php
2
- //class NameSpaceName_ModuleName_Model_ObserverDir_Observer
3
- class Qinvoice_Connect_Model_Order_Observer
4
- {
5
- public function __construct()
6
- {
7
- //parent::__construct();
8
- }
9
-
10
- public function sendOnComplete($observer){
11
- return false;
12
- $order = $observer->getEvent()->getOrder();
13
-
14
-
15
-
16
- // GETTING TRIGGER SETTING
17
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
18
- $varPath = 'invoice_options/invoice/invoice_trigger';
19
- $prefix = Mage::getConfig()->getTablePrefix();
20
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
21
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
22
- $varOnOrder = $rowTwo['value'];
23
-
24
- if($varOnOrder == 'complete' && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
25
- $this->createInvoiceForQinvoice($order->getId(), false);
26
- }else{
27
- return true;
28
- }
29
- }
30
-
31
- public function sendOnShip($observer){
32
- return false;
33
- $shipment = $observer->getEvent()->getShipment();
34
-
35
- $order = $shipment->getOrder();
36
-
37
- // GETTING TRIGGER SETTING
38
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
39
- $varPath = 'invoice_options/invoice/invoice_trigger';
40
- $prefix = Mage::getConfig()->getTablePrefix();
41
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
42
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
43
- $varOnOrder = $rowTwo['value'];
44
-
45
- if($varOnOrder == 'ship'){
46
- $this->createInvoiceForQinvoice($order->getId(), false);
47
- }else{
48
- return true;
49
- }
50
- }
51
-
52
- public function sendOnOrder($observer){
53
- $order = $observer->getEvent()->getOrder();
54
-
55
- // GETTING TRIGGER SETTING
56
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
57
- $varPath = 'invoice_options/invoice/invoice_trigger';
58
- $prefix = Mage::getConfig()->getTablePrefix();
59
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
60
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
61
- $varOnOrder = $rowTwo['value'];
62
-
63
- if($varOnOrder == 'order'){
64
- $this->createInvoiceForQinvoice($order->getId(), false);
65
- }else{
66
- return true;
67
- }
68
- }
69
-
70
- public function sendOnPayment($observer){
71
- // Gets called even when other payment method is choosen.
72
-
73
- $order_ids = $observer->getEvent()->getOrderIds();
74
- $order = $observer->getEvent()->getOrder();
75
-
76
- // GETTING TRIGGER SETTING
77
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
78
- $varPath = 'invoice_options/invoice/invoice_trigger';
79
- $prefix = Mage::getConfig()->getTablePrefix();
80
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
81
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
82
- $varOnOrder = $rowTwo['value'];
83
-
84
- if($varOnOrder == 'payment'){
85
- $this->createInvoiceForQinvoice($order_ids[0], true);
86
- }else{
87
- return true;
88
- }
89
- }
90
- public function createInvoiceForQinvoice($varOrderID,$ifPaid = false)
91
- {
92
-
93
-
94
- $paid = 0;
95
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
96
- // GETTING ORDER ID
97
- //$resultOne = $db->query("SELECT max(entity_id) as LastOrderID FROM sales_flat_order");
98
- //$rowOne = $resultOne->fetch(PDO::FETCH_ASSOC);
99
-
100
- //$varOrderID = $rowOne['LastOrderID'];
101
-
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
-
109
- if($rowOne['status'] == 'processing' || $rowOne['status'] == 'complete' || $rowOne['total_paid'] == $rowOne['grand_total'])
110
- {
111
- $varStatus = 'Paid';
112
- // GETTING API URL
113
- $varURLPath = 'invoice_options/invoice/paid_remark';
114
- $prefix = Mage::getConfig()->getTablePrefix();
115
- $resultURL = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varURLPath."'");
116
- $rowURL = $resultURL->fetch(PDO::FETCH_ASSOC);
117
- $paid_remark = $rowURL['value'];
118
- $paid = 1;
119
- }
120
- else
121
- {
122
- if($ifPaid == true){
123
- // cancel if invoice has to be paid
124
- return;
125
- }
126
- $paid_remark = '';
127
- $varStatus = 'Sent';
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, original_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) {
135
- //return false;
136
- }
137
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
138
- $arrData[] = $row;
139
- }
140
- if(!$arrData) {
141
- //return false;
142
- }
143
- //$comment = '';
144
- //$comment = $data['comment_text'];
145
- // getting po_number
146
- $random_number = rand(0, pow(10, 7));
147
-
148
- // GETTING API USERNAME
149
- $varPath = 'invoice_options/invoice/api_username';
150
- $prefix = Mage::getConfig()->getTablePrefix();
151
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
152
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
153
- $username = $rowTwo['value'];
154
-
155
- // GETTING API PASSWORD
156
- $varPath = 'invoice_options/invoice/api_password';
157
- $prefix = Mage::getConfig()->getTablePrefix();
158
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
159
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
160
- $password = $rowTwo['value'];
161
-
162
- // GETTING LAYOUT CODE
163
- $varPath = 'invoice_options/invoice/layout_code';
164
- $prefix = Mage::getConfig()->getTablePrefix();
165
- $resultTwo = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varPath."'");
166
- $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
167
- $layout_code = $rowTwo['value'];
168
-
169
-
170
- // GETTING CLIENT DETAILS
171
- $prefix = Mage::getConfig()->getTablePrefix();
172
- $resultThree = $db->query("SELECT * FROM {$prefix}sales_flat_order_address WHERE entity_id='".$rowOne['billing_address_id']."'");
173
- $rowThree = $resultThree->fetch(PDO::FETCH_ASSOC);
174
-
175
- $invoice = new qinvoice($username,$password);
176
-
177
- $invoice->companyname = $rowThree['company']; // Your customers company name
178
- $invoice->firstname = $rowThree['firstname']; // Your customers contact name
179
- $invoice->lastname = $rowThree['lastname']; // Your customers contact name
180
- $invoice->email = $rowOne['customer_email']; // Your customers emailaddress (invoice will be sent here)
181
- $invoice->phone = $rowThree['telephone'];
182
- $invoice->address = $rowThree['street']; // Self-explanatory
183
- $invoice->zipcode = $rowThree['postcode']; // Self-explanatory
184
- $invoice->city = $rowThree['city']; // Self-explanatory
185
- $invoice->country = $rowThree['country_id']; // 2 character country code: NL for Netherlands, DE for Germany etc
186
- $invoice->vatnumber = strlen($rowThree['vat_id']) > 3 ? $rowThree['vat_id'] : $rowOne['customer_taxvat'];
187
-
188
- $prefix = Mage::getConfig()->getTablePrefix();
189
- $resultFour = $db->query("SELECT firstname, lastname, company, email, telephone, street, city, region, postcode, country_id FROM {$prefix}sales_flat_order_address WHERE entity_id='".$rowOne['shipping_address_id']."'");
190
- $rowFour = $resultFour->fetch(PDO::FETCH_ASSOC);
191
-
192
- $invoice->delivery_companyname = $rowFour['company']; // Your customers company name
193
- $invoice->delivery_firstname = $rowFour['firstname']; // Your customers contact name
194
- $invoice->delivery_lastname = $rowFour['lastname']; // Your customers contact name
195
- $invoice->delivery_address = $rowFour['street']; // Self-explanatory
196
- $invoice->delivery_zipcode = $rowFour['postcode']; // Self-explanatory
197
- $invoice->delivery_city = $rowFour['city']; // Self-explanatory
198
- $invoice->delivery_country = $rowFour['country_id'];
199
- $invoice->delivery_phone = $rowFour['telephone'];
200
- $invoice->delivery_email = $rowFour['email'];
201
-
202
- $invoice->vat = ''; // Self-explanatory
203
- $invoice->paid = $paid;
204
-
205
- $varActionPath = 'invoice_options/invoice/save_relation';
206
- $prefix = Mage::getConfig()->getTablePrefix();
207
-
208
- $resultAction = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varActionPath."'");
209
- $rowAction = $resultAction->fetch(PDO::FETCH_ASSOC);
210
- $save_relation = $rowAction['value'];
211
-
212
- $invoice->saverelation = $save_relation;
213
-
214
- $varRemarkPath = 'invoice_options/invoice/invoice_remark';
215
- $prefix = Mage::getConfig()->getTablePrefix();
216
- $resultRemark = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varRemarkPath."'");
217
- $rowRemark = $resultRemark->fetch(PDO::FETCH_ASSOC);
218
-
219
- $order_id = $rowOne['increment_id'];
220
- $invoice_remark = $rowRemark['value'];
221
- $invoice_remark = str_replace('{order_id}',$rowOne['increment_id'],$invoice_remark);
222
- $invoice_remark = str_replace('{shipping_description}',$rowOne['shipping_description'],$invoice_remark);
223
-
224
- $order2 = Mage::getModel('sales/order')->load($order_id);
225
-
226
- $checkout = Mage::getSingleton('checkout/type_onepage')->getCheckout();
227
- $dd_data = $checkout->getAmastyDeliveryDate();
228
-
229
- if(method_exists($order2, 'deliverydate') ){
230
-
231
- $dd_comment = $dd_data['comment'];
232
- $invoice_remark = str_replace('{dd_comment}',$dd_comment,$invoice_remark);
233
-
234
- $dd_date = $dd_data['date'];
235
- $invoice_remark = str_replace('{dd_date}',$dd_date,$invoice_remark);
236
-
237
- $dd_time = $dd_data['time'];
238
- $invoice_remark = str_replace('{dd_time}',$dd_time,$invoice_remark);
239
-
240
-
241
- //$dd = explode("-",$order->deliverydate('date'));
242
- //$invoice->delivery_date = $order2->deliverydate('date'); //$dd[2].'-'. $dd[1].'-'. $dd[0];
243
- $invoice->delivery_date = $dd_data['date'];
244
- }
245
-
246
- $invoice->addTag($dd_data['date']);
247
- if(strlen($dd_time) > 6){
248
- $invoice->addTag($dd_data['time']);
249
- }
250
-
251
- // $payment_method_code = $order2->getPayment()->getMethodInstance()->getCode();
252
- // $invoice->addTag($payment_method_code);
253
- // $invoice->addTag($order2->getShippingDescription());
254
-
255
- //$payment = $order2->getPayment();
256
- //$invoice->addTag($payment->getMethod());
257
- $invoice->addTag(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod());
258
- $invoice->addTag(Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getTitle());
259
-
260
-
261
- //$invoice->addTag(Mage::getSingleton('checkout/session')->getQuote()->getInvoiceFee());
262
-
263
-
264
- $invoice->remark = $invoice_remark ."\n". $paid_remark;
265
-
266
- $varActionPath = 'invoice_options/invoice/invoice_action';
267
- $prefix = Mage::getConfig()->getTablePrefix();
268
- $resultAction = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varActionPath."'");
269
- $rowAction = $resultAction->fetch(PDO::FETCH_ASSOC);
270
- $invoice_action = $rowAction['value'];
271
-
272
- $varLayoutPath = 'invoice_options/invoice/layout_code';
273
- $prefix = Mage::getConfig()->getTablePrefix();
274
- $resultLayout = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varLayoutPath."'");
275
- $rowLayout = $resultLayout->fetch(PDO::FETCH_ASSOC);
276
- $invoice_layout = $rowLayout['value'];
277
-
278
- $varCalculationmethodPath = 'invoice_options/invoice/calculation_method';
279
- $prefix = Mage::getConfig()->getTablePrefix();
280
- $resultCalculationmethod = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varCalculationmethodPath."'");
281
- $rowCalculationmethod = $resultCalculationmethod->fetch(PDO::FETCH_ASSOC);
282
- $invoice_calculationmethod = $rowCalculationmethod['value'];
283
-
284
- $invoice->calculation_method = $invoice_calculationmethod;
285
-
286
- $invoice_layout_s = @unserialize($invoice_layout);
287
- if ($invoice_layout_s !== false) {
288
- // serialized
289
- $invoice_layout = @unserialize($invoice_layout);
290
- if(isset($invoice_layout[$rowFour['country_id']])){
291
- $invoice_layout = @$invoice_layout[$rowFour['country_id']];
292
- }else{
293
- $invoice_layout = @$invoice_layout['default'];
294
- }
295
- } else {
296
- // not serialized
297
- $invoice_layout = $invoice_layout;
298
- }
299
-
300
- $invoice->setLayout($invoice_layout);
301
-
302
- $varTagPath = 'invoice_options/invoice/invoice_tag';
303
- $prefix = Mage::getConfig()->getTablePrefix();
304
- $resultTag = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varTagPath."'");
305
- $rowTag = $resultTag->fetch(PDO::FETCH_ASSOC);
306
- $invoice_tag = $rowTag['value'];
307
-
308
- $varTagPath = 'invoice_options/invoice/product_attributes';
309
- $prefix = Mage::getConfig()->getTablePrefix();
310
- $resultTag = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varTagPath."'");
311
- $pa_array = $resultTag->fetch(PDO::FETCH_ASSOC);
312
-
313
-
314
- $invoice->action = $invoice_action;
315
-
316
- // OPTIONAL: Add tags
317
- $invoice->addTag($rowOne['increment_id']);
318
- $invoice->addTag($invoice_tag);
319
-
320
-
321
-
322
- $order = Mage::getModel('sales/order')->loadByIncrementId($varOrderID);
323
- $store_id = $order->getStoreId();
324
-
325
-
326
- $attributes = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
327
- $attributeArray = array();
328
-
329
- foreach($attributes as $attribute){
330
- $attributeArray[$attribute->getData('attribute_code')] = $attribute->getData('frontend_label');
331
- // $attributeArray[] = array(
332
- // 'label' => $attribute->getData('frontend_label'),
333
- // 'value' => $attribute->getData('attribute_code')
334
- // );
335
- }
336
-
337
-
338
- //print_r($order);
339
-
340
- for($i=0;$i<count($arrData);$i++)
341
- {
342
- $category = '';
343
- $_productId = $arrData[$i]['product_id'];
344
- $_product = Mage::getModel('catalog/product')->load($_productId);
345
-
346
-
347
- $category = $_product->getData('qinvoice_category');
348
- $productcode = $_product->getData('qinvoice_productcode');
349
-
350
- $arrItemOptions = unserialize($arrData[$i]['product_options']);
351
-
352
- $varDescription = '';
353
-
354
- //print_r();
355
-
356
- $product_attributes = explode(",",$pa_array['value']);
357
- foreach($product_attributes as $pa){
358
- if(isset($_product[$pa]))
359
- {
360
- $varDescription .= "\n". $attributeArray[$pa] .': '. $_product[$pa];
361
- }
362
- }
363
-
364
-
365
- if(@$arrItemOptions['options'])
366
- {
367
- for($k=0; $k <count($arrItemOptions['options']); $k++)
368
- {
369
- $varDescription .= "\n".$arrItemOptions['options'][$k]['label'].": ".$arrItemOptions['options'][$k]['print_value']."\n";
370
- }
371
- }
372
-
373
- if(@$arrItemOptions['attributes_info'])
374
- {
375
- for($k=0; $k <count($arrItemOptions['attributes_info']); $k++)
376
- {
377
- $varDescription .= "\n".$arrItemOptions['attributes_info'][$k]['label'].": ".$arrItemOptions['attributes_info'][$k]['value']."\n";
378
- }
379
- }
380
-
381
- if(@$arrItemOptions['bundle_options'])
382
- {
383
- foreach($arrItemOptions['bundle_options'] as $option){
384
- foreach($option['value'] as $value){
385
- $varDescription .= "\n".'['. $option['label'] .'] '. $value['qty'] .' x '. $value['title'];
386
- }
387
- }
388
- }
389
-
390
-
391
-
392
-
393
-
394
-
395
- $params = array(
396
- 'code' => $productcode,
397
- 'description' => "[".$arrData[$i]['sku']."] ".trim($arrData[$i]['name']) . $varDescription,
398
- 'price' => $arrData[$i]['base_price']*100,
399
- //'price_incl' => ((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100,
400
- 'price_incl' => $arrData[$i]['original_price']*100,
401
- 'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
402
- 'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
403
- 'discount' => 0,
404
- 'quantity' => $arrData[$i]['qty_ordered']*100,
405
- 'categories' => $category
406
- );
407
-
408
- $invoice->addItem($params);
409
-
410
- }
411
-
412
- if($rowOne['shipping_amount'] > 0)
413
- {
414
- $params = array(
415
- 'code' => 'SHPMNT',
416
- 'description' => trim($rowOne['shipping_description']),
417
- 'price' => $rowOne['shipping_amount']*100,
418
- 'price_incl' => $rowOne['shipping_incl_tax']*100,
419
- 'price_vat' => $rowOne['shipping_tax_amount']*100,
420
- 'vatpercentage' => round(($rowOne['shipping_tax_amount']/$rowOne['shipping_amount'])*100)*100,
421
- 'discount' => 0,
422
- 'quantity' => 100,
423
- 'categories' => 'shipping'
424
- );
425
-
426
- $invoice->addItem($params);
427
-
428
- }
429
-
430
-
431
-
432
- // $order = Mage::getModel('sales/order')->loadByIncrementId($varOrderID);
433
-
434
- // $orderDetails = $order->getData();
435
-
436
- $couponCode = $rowOne['coupon_code'];
437
- //echo $couponCode;
438
- //print_r($order);
439
- // $couponCode = $orderDetails['coupon_code'];
440
-
441
- if($couponCode > ''){
442
- $oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
443
- $oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
444
- //var_dump($oRule->getData());
445
-
446
- $ruleData = $oRule->getData();
447
-
448
- $discount = $ruleData['discount_amount'];
449
- $params = array(
450
- 'code' => 'DSCNT',
451
- 'description' => $couponCode,
452
- // 'price' => ($rowOne['base_subtotal'] * ($discount/100))*100,
453
- // 'price_incl' => ($rowOne['base_subtotal'] * ($discount/100))*100,
454
- 'price' => $discount*100,
455
- 'price_incl' => $discount*100,
456
- 'price_vat' => 0,
457
- 'vatpercentage' => 0,
458
- 'discount' => 0,
459
- 'quantity' => -100,
460
- 'categories' => 'discount'
461
- );
462
-
463
- $invoice->addItem($params);
464
- }
465
-
466
- $invoice_fee = Mage::getSingleton('checkout/session')->getQuote()->getInvoiceFee();
467
- if($invoice_fee > 0){
468
- $price_incl = $invoice_fee*100;
469
- $price = ($invoice_fee/121)*100;
470
-
471
- $params = array(
472
- 'code' => 'FEE',
473
- 'description' => 'Betalingstoeslag',
474
- 'price' => $price,
475
- 'price_incl' => $price_incl,
476
- 'price_vat' => $price_incl - $price,
477
- 'vatpercentage' => 2100,
478
- 'discount' => 0,
479
- 'quantity' => 100,
480
- 'categories' => 'fee'
481
- );
482
-
483
- $invoice->addItem($params);
484
- }
485
-
486
-
487
- // $coupon = Mage::getModel('salesrule/rule');
488
- // $couponCollection = $coupon->getCollection();
489
- // foreach($couponCollection as $c){
490
- // print_r($c);
491
- // echo 'Code:'.$c->getCode().'--->Discount Amount:'.$c->getDiscountAmount().'<br />';
492
-
493
- // $params = array(
494
- // 'code' => 'DSCNT',
495
- // 'description' => $c->getCode(),
496
- // 'price' => $rowOne['base_subtotal'] * ($c->getDiscountAmount()/100),
497
- // 'price_incl' => $rowOne['base_subtotal'] * ($c->getDiscountAmount()/100),
498
- // 'price_vat' => 0,
499
- // 'vatpercentage' => 0,
500
- // 'discount' => 0,
501
- // 'quantity' => -100,
502
- // 'categories' => 'discount'
503
- // );
504
-
505
- // $invoice->addItem($params);
506
-
507
- // }
508
-
509
- $result = $invoice->sendRequest();
510
-
511
-
512
- if($result != 1){
513
- $this->notify_admin('Qinvoice Connect Error','Could not send invoice for order '. $order_id);
514
- }
515
-
516
- return true;
517
-
518
-
519
- //$curlInvoiveResult = $this->sendCurlRequest($createInvoiceXML);
520
- }
521
- public function notify_admin($subject,$msg)
522
- {
523
- $varSubject = 'Qinvoice Notification';
524
-
525
- Mage::log($subject .': '. $msg);
526
-
527
- $mail = Mage::getModel('core/email');
528
- $mail->setToName(Mage::getStoreConfig('trans_email/ident_general/name') );
529
- $mail->setToEmail(Mage::getStoreConfig('trans_email/ident_general/email') );
530
- $mail->setBody($msg);
531
- $mail->setSubject($subject);
532
- $mail->setFromEmail("support@qinvoice.com");
533
- $mail->setFromName("Qinvoice Support");
534
- $mail->setType('text');
535
- $mail->send();
536
- }
537
-
538
- }
539
-
540
-
541
-
542
-
543
- class qinvoice{
544
-
545
- protected $gateway = '';
546
- private $username;
547
- private $password;
548
-
549
- public $companyname;
550
- public $firstname;
551
- public $lastname;
552
- public $email;
553
- public $address;
554
- public $zipcode;
555
- public $city;
556
- public $country;
557
- public $delivery_companyname;
558
- public $delivery_firstname;
559
- public $delivery_lastname;
560
- public $delivery_address;
561
- public $delivery_zipcode;
562
- public $delivery_city;
563
- public $delivery_country;
564
- public $delivery_phone;
565
- public $delivery_email;
566
- public $delivery_date;
567
- public $vatnumber;
568
- public $remark;
569
- public $paid;
570
- public $saverelation = false;
571
- public $action;
572
-
573
- public $layout;
574
-
575
- private $tags = array();
576
- private $items = array();
577
- private $files = array();
578
- private $recurring;
579
-
580
- function __construct($username, $password){
581
- $this->username = $username;
582
- $this->password = $password;
583
- $this->recurring = 'none';
584
-
585
- $db = Mage::getSingleton('core/resource')->getConnection('core_write');
586
-
587
- // GETTING API URL
588
- $varURLPath = 'invoice_options/invoice/api_url';
589
- $prefix = Mage::getConfig()->getTablePrefix();
590
- $resultURL = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varURLPath."'");
591
- $rowURL = $resultURL->fetch(PDO::FETCH_ASSOC);
592
- $apiURL = $rowURL['value'];
593
-
594
- $this->gateway = $apiURL;
595
- }
596
-
597
- public function addTag($tag){
598
- $this->tags[] = $tag;
599
- }
600
-
601
- public function setLayout($code){
602
- $this->layout = $code;
603
- }
604
-
605
- public function setRecurring($recurring){
606
- $this->recurring = strtolower($recurring);
607
- }
608
-
609
- public function addItem($params){
610
- $item['code'] = (isset($params['code']) ? $params['code'] : "");
611
- $item['description'] = $params['description'];
612
- $item['price'] = $params['price'];
613
- $item['price_incl'] = $params['price_incl'];
614
- $item['price_vat'] = $params['price_vat'];
615
- $item['vatpercentage'] = $params['vatpercentage'];
616
- $item['discount'] = $params['discount'];
617
- $item['quantity'] = $params['quantity'];
618
- $item['categories'] = $params['categories'];
619
- $this->items[] = $item;
620
- }
621
-
622
- public function addFile($name, $url){
623
- $this->files[] = array('url' => $url, 'name' => $name);
624
- }
625
-
626
- public function sendRequest() {
627
- $content = "<?xml version='1.0' encoding='UTF-8'?>";
628
- $content .= $this->buildXML();
629
-
630
- $headers = array("Content-type: application/atom+xml");
631
- $ch = curl_init();
632
- curl_setopt($ch, CURLOPT_URL, $this->gateway );
633
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
634
- curl_setopt($ch, CURLOPT_TIMEOUT, 120);
635
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
636
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
637
- curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
638
- $data = curl_exec($ch);
639
- if (curl_errno($ch)) {
640
- print curl_error($ch);
641
- } else {
642
- curl_close($ch);
643
- }
644
- if($data == 1){
645
- return true;
646
- }else{
647
- return false;
648
- }
649
-
650
- }
651
-
652
- private function buildXML(){
653
- $string = '<request>
654
- <login mode="newInvoice">
655
- <username><![CDATA['.$this->username.']]></username>
656
- <password><![CDATA['.$this->password.']]></password>
657
- <identifier><![CDATA[Magento_1.1.2]]></identifier>
658
- </login>
659
- <invoice>
660
- <companyname><![CDATA['. $this->companyname .']]></companyname>
661
- <firstname><![CDATA['. $this->firstname .']]></firstname>
662
- <lastname><![CDATA['. $this->lastname .']]></lastname>
663
- <email><![CDATA['. $this->email .']]></email>
664
- <phone><![CDATA['. $this->phone .']]></phone>
665
- <address><![CDATA['. $this->address .']]></address>
666
- <zipcode><![CDATA['. $this->zipcode .']]></zipcode>
667
- <city><![CDATA['. $this->city .']]></city>
668
- <country><![CDATA['. $this->country .']]></country>
669
-
670
- <delivery_companyname><![CDATA['. $this->delivery_companyname .']]></delivery_companyname>
671
- <delivery_firstname><![CDATA['. $this->delivery_firstname .']]></delivery_firstname>
672
- <delivery_lastname><![CDATA['. $this->delivery_lastname .']]></delivery_lastname>
673
- <delivery_address><![CDATA['. $this->delivery_address .']]></delivery_address>
674
- <delivery_zipcode><![CDATA['. $this->delivery_zipcode .']]></delivery_zipcode>
675
- <delivery_city><![CDATA['. $this->delivery_city .']]></delivery_city>
676
- <delivery_country><![CDATA['. $this->delivery_country .']]></delivery_country>
677
- <delivery_phone><![CDATA['. $this->delivery_phone .']]></delivery_phone>
678
- <delivery_email><![CDATA['. $this->delivery_email .']]></delivery_email>
679
- <delivery_date><![CDATA['. $this->delivery_date .']]></delivery_date>
680
-
681
- <vat><![CDATA['. $this->vatnumber .']]></vat>
682
- <recurring><![CDATA['. $this->recurring .']]></recurring>
683
- <remark><![CDATA['. $this->remark .']]></remark>
684
- <layout><![CDATA['. $this->layout .']]></layout>
685
- <paid><![CDATA['. $this->paid .']]></paid>
686
- <action><![CDATA['. $this->action .']]></action>
687
- <saverelation><![CDATA['. $this->saverelation .']]></saverelation>
688
- <calculation_method><![CDATA['. $this->calculation_method .']]></calculation_method>
689
- <tags>';
690
- foreach($this->tags as $tag){
691
- $string .= '<tag><![CDATA['. $tag .']]></tag>';
692
- }
693
-
694
- $string .= '</tags>
695
- <items>';
696
- foreach($this->items as $i){
697
-
698
- $string .= '<item>
699
- <code><![CDATA['. $i['code'] .']]></code>
700
- <quantity><![CDATA['. $i['quantity'] .']]></quantity>
701
- <description><![CDATA['. $i['description'] .']]></description>
702
- <price>'. $i['price'] .'</price>
703
- <price_incl>'. $i['price_incl'] .'</price_incl>
704
- <price_vat>'. $i['price_vat'] .'</price_vat>
705
- <vatpercentage>'. $i['vatpercentage'] .'</vatpercentage>
706
- <discount>'. $i['discount'] .'</discount>
707
- <categories><![CDATA['. $i['categories'] .']]></categories>
708
-
709
- </item>';
710
- }
711
-
712
- $string .= '</items>
713
- <files>';
714
- foreach($this->files as $f){
715
- $string .= '<file url="'.$f['url'].'">'.$f['name'].'</file>';
716
- }
717
- $string .= '</files>
718
- </invoice>
719
- </request>';
720
- return $string;
721
- }
722
- }
723
-
724
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Qinvoice/Connect/Model/Order/Observer.php CHANGED
@@ -173,22 +173,7 @@ class Qinvoice_Connect_Model_Order_Observer
173
  }
174
  }
175
 
176
- public function sendOnShip($observer){
177
- return false;
178
- $shipment = $observer->getEvent()->getShipment();
179
-
180
- $order = $shipment->getOrder();
181
-
182
- // GETTING TRIGGER SETTING
183
- $invoice_trigger = Mage::getStoreConfig('invoice_options/invoice/invoice_trigger');
184
-
185
- if($invoice_trigger == 'ship'){
186
- $this->createInvoiceForQinvoice($order->getId(), false);
187
- }else{
188
- return true;
189
- }
190
- }
191
-
192
  public function sendOnOrder($observer){
193
  $order = $observer->getEvent()->getOrder();
194
 
@@ -206,14 +191,14 @@ class Qinvoice_Connect_Model_Order_Observer
206
  public function sendOnPayment($observer){
207
  // Gets called even when other payment method is choosen.
208
 
209
- $order_ids = $observer->getEvent()->getOrderIds();
210
- $order = $observer->getEvent()->getOrder();
211
 
212
  // GETTING TRIGGER SETTING
213
  $invoice_trigger = Mage::getStoreConfig('invoice_options/invoice/invoice_trigger');
214
 
215
  if($invoice_trigger == 'payment'){
216
- $this->createInvoiceForQinvoice($order_ids[0], true);
217
  }
218
 
219
  // else{
@@ -227,9 +212,14 @@ class Qinvoice_Connect_Model_Order_Observer
227
  $event = $observer->getEvent();
228
  $order = $event->getOrder();
229
 
 
230
  $invoice_trigger = Mage::getStoreConfig('invoice_options/invoice/invoice_trigger');
 
 
 
 
231
  if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE && $invoice_trigger == 'complete'){
232
- $this->createInvoiceForQinvoice($order->getId(), true);
233
  }
234
  // exit();
235
 
@@ -679,7 +669,7 @@ class qinvoice{
679
  <login mode="newInvoice">
680
  <username><![CDATA['.$this->username.']]></username>
681
  <password><![CDATA['.$this->password.']]></password>
682
- <identifier><![CDATA[Magento_2.1.2]]></identifier>
683
  </login>
684
  <invoice>
685
  <companyname><![CDATA['. $this->companyname .']]></companyname>
173
  }
174
  }
175
 
176
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  public function sendOnOrder($observer){
178
  $order = $observer->getEvent()->getOrder();
179
 
191
  public function sendOnPayment($observer){
192
  // Gets called even when other payment method is choosen.
193
 
194
+ $event = $observer->getEvent();
195
+ $order = $event->getOrder();
196
 
197
  // GETTING TRIGGER SETTING
198
  $invoice_trigger = Mage::getStoreConfig('invoice_options/invoice/invoice_trigger');
199
 
200
  if($invoice_trigger == 'payment'){
201
+ $this->createInvoiceForQinvoice($order->getId(), true);
202
  }
203
 
204
  // else{
212
  $event = $observer->getEvent();
213
  $order = $event->getOrder();
214
 
215
+
216
  $invoice_trigger = Mage::getStoreConfig('invoice_options/invoice/invoice_trigger');
217
+
218
+ // echo $order->getId() .' '. $order->getState() .' '. Mage_Sales_Model_Order::STATE_COMPLETE .' '. $invoice_trigger;
219
+
220
+ // exit();
221
  if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE && $invoice_trigger == 'complete'){
222
+ $this->createInvoiceForQinvoice($order->getId(), false);
223
  }
224
  // exit();
225
 
669
  <login mode="newInvoice">
670
  <username><![CDATA['.$this->username.']]></username>
671
  <password><![CDATA['.$this->password.']]></password>
672
+ <identifier><![CDATA[Magento_2.1.3]]></identifier>
673
  </login>
674
  <invoice>
675
  <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>2.1.2</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
+ <version>2.1.3</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
- <version>2.1.2</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 bug</notes>
12
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
13
- <date>2016-10-13</date>
14
- <time>20:01:49</time>
15
- <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="a5b219d5eacdccb828a227a4467afa46"/><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Webshopsecret.php" hash="2157af67cdcf51307bde5efe5cee46d2"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="141eebc8865ff9c7e231d85df1432e96"/><file name="Observer.max4home.php" hash="1f9b754b2184c0079a0d53ecc2d3fdd8"/><file name="Observer.php" hash="70c3b68728422bd55f821a6c66db6339"/></dir><dir name="Rewrite"><file name="Observer.php" hash="769e4618f69697b8e3ccddbb9b446fea"/><file name="Order.php" hash="1206763b6090a7136fe869b474935c51"/></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="366ba803beda9471e48d5d6da3baa20a"/></dir></dir><dir name="Module"><dir name="Block"><file name="Webshop_Secret_Renderer.php" hash="53039328186fd5c9fe15a3f55b2f8d16"/></dir><file name="Webshop_Secret_Renderer.php" hash="53039328186fd5c9fe15a3f55b2f8d16"/></dir><dir name="etc"><file name="config.xml" hash="f069ed25a278c173cb2223e1303dfd22"/><file name="config_old.xml" hash="dcd8c91d7d5e48154ebe900336d13cab"/><file name="system.xml" hash="ed502b22f018d096417f47e62dbc31a8"/></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>7.0.0</max></php><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
+ <version>2.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>Minor update</notes>
12
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
13
+ <date>2016-10-21</date>
14
+ <time>11:38:20</time>
15
+ <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="217493383a4629a5c59858252ba51866"/><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Webshopsecret.php" hash="2157af67cdcf51307bde5efe5cee46d2"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="141eebc8865ff9c7e231d85df1432e96"/><file name="Observer.php" hash="79b09a59dd8a42af4e85ed8ff9fd4d4b"/></dir><dir name="Rewrite"><file name="Observer.php" hash="769e4618f69697b8e3ccddbb9b446fea"/><file name="Order.php" hash="1206763b6090a7136fe869b474935c51"/></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="366ba803beda9471e48d5d6da3baa20a"/></dir></dir><dir name="Module"><dir name="Block"><file name="Webshop_Secret_Renderer.php" hash="53039328186fd5c9fe15a3f55b2f8d16"/></dir><file name="Webshop_Secret_Renderer.php" hash="53039328186fd5c9fe15a3f55b2f8d16"/></dir><dir name="etc"><file name="config.xml" hash="13f1df593f156863b86f288a3032bfb4"/><file name="config_old.xml" hash="dcd8c91d7d5e48154ebe900336d13cab"/><file name="system.xml" hash="ed502b22f018d096417f47e62dbc31a8"/></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>7.0.0</max></php><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
18
  </package>