1
|
|
|
<?php |
2
|
|
|
class Install_Helper_Debtor |
3
|
|
|
{ |
4
|
|
|
private $kernel; |
5
|
|
|
private $db; |
6
|
|
|
|
7
|
|
|
public function __construct($kernel, $db) |
8
|
|
|
{ |
9
|
|
|
$this->kernel = $kernel; |
10
|
|
|
$this->db = $db; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
View Code Duplication |
public function createInvoice() |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
require_once dirname (__FILE__) . '/Contact.php'; |
|
|
|
|
16
|
|
|
$contact = new Install_Helper_Contact($this->kernel, $this->db); |
17
|
|
|
$contact_id = $contact->create(); |
|
|
|
|
18
|
|
|
|
19
|
|
|
require_once dirname(__FILE__) . '/Product.php'; |
20
|
|
|
$product = new Install_Helper_Product($this->kernel, $this->db); |
21
|
|
|
$product_id = $product->create(); |
22
|
|
|
|
23
|
|
|
require_once 'Intraface/modules/invoice/Invoice.php'; |
24
|
|
|
$debtor = new Invoice($this->kernel); |
25
|
|
|
$id = $debtor->update(array( |
|
|
|
|
26
|
|
|
'contact_id' => $contact_id, |
27
|
|
|
'description' => 'Test invoice', |
28
|
|
|
'this_date' => date('d-m-Y'), |
29
|
|
|
'due_date' => date('d-m-Y', time()+14*60*60*24))); |
30
|
|
|
|
31
|
|
|
$debtor->loadItem(); |
32
|
|
|
$debtor->item->save(array('product_id' => $product_id, 'quantity' => 3, 'description' => 'Test description on product')); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function createOrder() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
require_once dirname(__FILE__) . '/Contact.php'; |
38
|
|
|
$contact = new Install_Helper_Contact($this->kernel, $this->db); |
39
|
|
|
$contact_id = $contact->create(); |
|
|
|
|
40
|
|
|
|
41
|
|
|
require_once dirname(__FILE__) . '/Product.php'; |
42
|
|
|
$product = new Install_Helper_Product($this->kernel, $this->db); |
43
|
|
|
$product_id = $product->create(); |
44
|
|
|
|
45
|
|
|
require_once 'Intraface/modules/order/Order.php'; |
46
|
|
|
$debtor = new Order($this->kernel); |
47
|
|
|
$id = $debtor->update(array( |
|
|
|
|
48
|
|
|
'contact_id' => $contact_id, |
49
|
|
|
'description' => 'Test invoice', |
50
|
|
|
'this_date' => date('d-m-Y'), |
51
|
|
|
'due_date' => date('d-m-Y', time()+14*60*60*24))); |
52
|
|
|
|
53
|
|
|
$debtor->loadItem(); |
54
|
|
|
$debtor->item->save(array('product_id' => $product_id, 'quantity' => 3, 'description' => 'Test description on product')); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function createOrderFromShop() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
require_once dirname(__FILE__) . '/Contact.php'; |
60
|
|
|
$contact = new Install_Helper_Contact($this->kernel, $this->db); |
61
|
|
|
$contact_id = $contact->create(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
require_once dirname(__FILE__) . '/Product.php'; |
64
|
|
|
$product = new Install_Helper_Product($this->kernel, $this->db); |
65
|
|
|
$product_id = $product->create(); |
66
|
|
|
|
67
|
|
|
require_once 'Intraface/modules/order/Order.php'; |
68
|
|
|
$debtor = new Order($this->kernel); |
69
|
|
|
$id = $debtor->update(array( |
|
|
|
|
70
|
|
|
'contact_id' => $contact_id, |
71
|
|
|
'description' => 'From shop', |
72
|
|
|
'this_date' => date('d-m-Y'), |
73
|
|
|
'due_date' => date('d-m-Y', time()+14*60*60*24)), 'webshop', 1); |
74
|
|
|
|
75
|
|
|
$debtor->loadItem(); |
76
|
|
|
$debtor->item->save(array('product_id' => $product_id, 'quantity' => 3, 'description' => 'Test description on product')); |
|
|
|
|
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.