|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package org.openpsa.sales |
|
4
|
|
|
* @author Nemein Oy, http://www.nemein.com/ |
|
5
|
|
|
* @copyright Nemein Oy, http://www.nemein.com/ |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* OpenPSA Sales management component |
|
11
|
|
|
* |
|
12
|
|
|
* @package org.openpsa.sales |
|
13
|
|
|
*/ |
|
14
|
|
|
class org_openpsa_sales_interface extends midcom_baseclasses_components_interface |
|
15
|
|
|
implements midcom_services_permalinks_resolver |
|
16
|
|
|
{ |
|
17
|
|
|
public function resolve_object_link(midcom_db_topic $topic, midcom_core_dbaobject $object) : ?string |
|
18
|
|
|
{ |
|
19
|
|
|
if ($object instanceof org_openpsa_sales_salesproject_dba) { |
|
20
|
|
|
return "salesproject/{$object->guid}/"; |
|
21
|
|
|
} |
|
22
|
|
|
if ($object instanceof org_openpsa_sales_salesproject_deliverable_dba) { |
|
23
|
|
|
return "deliverable/{$object->guid}/"; |
|
24
|
|
|
} |
|
25
|
|
|
return null; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
32 |
|
public function _on_watched_dba_update(midcom_core_dbaobject $object) |
|
29
|
|
|
{ |
|
30
|
32 |
|
if ($agreement = $object->get_agreement()) { |
|
|
|
|
|
|
31
|
|
|
try { |
|
32
|
12 |
|
$agreement = new org_openpsa_sales_salesproject_deliverable_dba($agreement); |
|
33
|
12 |
|
$agreement->update_units(); |
|
34
|
8 |
|
} catch (midcom_error $e) { |
|
35
|
8 |
|
$e->log(); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
32 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* AT handler for handling subscription cycles. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function new_subscription_cycle(array $args, midcom_baseclasses_components_cron_handler $handler) |
|
44
|
|
|
{ |
|
45
|
|
|
if (!isset($args['deliverable'], $args['cycle'])) { |
|
46
|
|
|
$handler->print_error('deliverable GUID or cycle number not set, aborting'); |
|
47
|
|
|
return false; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$deliverable = new org_openpsa_sales_salesproject_deliverable_dba($args['deliverable']); |
|
52
|
|
|
} catch (midcom_error $e) { |
|
53
|
|
|
$handler->print_error("Deliverable {$args['deliverable']} not found: " . midcom_connection::get_error_string()); |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
$scheduler = new org_openpsa_invoices_scheduler($deliverable); |
|
57
|
|
|
|
|
58
|
|
|
return $scheduler->run_cycle($args['cycle']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Function to send a notification to owner of the deliverable - guid of deliverable is passed |
|
63
|
|
|
*/ |
|
64
|
|
|
public function new_notification_message(array $args, midcom_baseclasses_components_cron_handler $handler) |
|
65
|
|
|
{ |
|
66
|
|
|
if (!isset($args['deliverable'])) { |
|
67
|
|
|
$handler->print_error('deliverable GUID not set, aborting'); |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
try { |
|
71
|
|
|
$deliverable = new org_openpsa_sales_salesproject_deliverable_dba($args['deliverable']); |
|
72
|
|
|
} catch (midcom_error $e) { |
|
73
|
|
|
$handler->print_error('no deliverable with passed GUID: ' . $args['deliverable'] . ', aborting'); |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
//get the owner of the salesproject the deliverable belongs to |
|
78
|
|
|
try { |
|
79
|
|
|
$project = new org_openpsa_sales_salesproject_dba($deliverable->salesproject); |
|
80
|
|
|
} catch (midcom_error $e) { |
|
81
|
|
|
$handler->print_error('Failed to load salesproject: ' . $e->getMessage()); |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$message = [ |
|
86
|
|
|
'title' => sprintf($this->_l10n->get('notification for agreement %s'), $deliverable->title), |
|
87
|
|
|
'content' => sprintf( |
|
88
|
|
|
$this->_l10n->get('agreement %s ends on %s. click here: %s'), |
|
89
|
|
|
$deliverable->title, |
|
90
|
|
|
$this->_l10n->get_formatter()->date($deliverable->end), |
|
91
|
|
|
midcom::get()->permalinks->create_permalink($deliverable->guid) |
|
92
|
|
|
) |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
return org_openpsa_notifications::notify('org.openpsa.sales:new_notification_message', $project->owner, $message); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.