Esempio n. 1
0
 public function testHandler_process_subscription()
 {
     midcom::get('auth')->request_sudo('org.openpsa.sales');
     $product = org_openpsa_products_product_dba::get_cached(self::$_product->id);
     $product->delivery = org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION;
     $product->update();
     $deliverable_attributes = array('salesproject' => self::$_salesproject->id, 'product' => self::$_product->id, 'start' => time(), 'continuous' => true, 'unit' => 'q', 'orgOpenpsaObtype' => org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $deliverable->update();
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('order' => true);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $this->assertEquals(org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED, $deliverable->state);
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     $_POST = array('run_cycle' => true, 'at_entry' => $at_entries[0]->guid);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 2
0
 /**
  * Fills the next and previous action properties
  * based on the confirmed relatedto links
  *
  * If optional argument is set only considers actions
  * where said person is involved, NOT IMPLEMENTED
  *
  * @todo Implement $limit_to_person support
  */
 function get_actions($limit_to_person = false)
 {
     $default = array('time' => false, 'obj' => false, 'type' => 'noaction');
     $this->prev_action = $default;
     $this->next_action = $default;
     $mc = new org_openpsa_relatedto_collector($this->guid, array('org_openpsa_calendar_event_dba', 'org_openpsa_projects_task_dba'));
     $related_objects = $mc->get_related_objects();
     if (count($related_objects) == 0) {
         return;
     }
     $sort_prev = array();
     $sort_next = array();
     foreach ($related_objects as $object) {
         $to_sort = $default;
         $to_sort['obj'] = $object;
         switch ($object->__mgdschema_class_name__) {
             case 'org_openpsa_task':
                 $to_sort['type'] = 'task';
                 if ($object->status >= org_openpsa_projects_task_status_dba::COMPLETED) {
                     $to_sort['time'] = $object->status_time;
                     $sort_prev[] = $to_sort;
                 } else {
                     $to_sort['time'] = $object->end;
                     if ($object->end < time()) {
                         //PONDER: Do something ?
                     }
                     $sort_next[] = $to_sort;
                 }
                 break;
             case 'org_openpsa_event':
                 $to_sort['type'] = 'event';
                 if ($object->end < time()) {
                     $to_sort['time'] = $object->end;
                     $sort_prev[] = $to_sort;
                 } else {
                     $to_sort['time'] = $object->start;
                     $sort_next[] = $to_sort;
                 }
                 break;
             default:
                 continue 2;
         }
     }
     usort($sort_prev, array('self', '_sort_action_by_time_reverse'));
     usort($sort_next, array('self', '_sort_action_by_time'));
     debug_print_r("sort_next:", $sort_next);
     debug_print_r("sort_prev:", $sort_prev);
     if (isset($sort_next[0])) {
         $this->next_action = $sort_next[0];
     }
     if (isset($sort_prev[0])) {
         $this->prev_action = $sort_prev[0];
     }
     return;
 }
Esempio n. 3
0
 private function _list_bookings()
 {
     $task_booked_time = 0;
     $task_booked_percentage = 100;
     $bookings = array('confirmed' => array(), 'suspected' => array());
     $mc = new org_openpsa_relatedto_collector($this->_object->guid, 'org_openpsa_calendar_event_dba');
     $mc->add_value_property('status');
     $mc->add_constraint('status', '<>', org_openpsa_relatedto_dba::NOTRELATED);
     // TODO: fromClass too?
     $mc->execute();
     $relations = $mc->list_keys();
     foreach ($relations as $guid => $empty) {
         try {
             $booking = new org_openpsa_calendar_event_dba($mc->get_subkey($guid, 'fromGuid'));
         } catch (midcom_error $e) {
             continue;
         }
         if ($mc->get_subkey($guid, 'status') == org_openpsa_relatedto_dba::CONFIRMED) {
             $bookings['confirmed'][] = $booking;
             $task_booked_time += ($booking->end - $booking->start) / 3600;
         } else {
             $bookings['suspected'][] = $booking;
         }
     }
     usort($bookings['confirmed'], array('self', '_sort_by_time'));
     usort($bookings['suspected'], array('self', '_sort_by_time'));
     $task_booked_time = round($task_booked_time);
     if ($this->_object->plannedHours != 0) {
         $task_booked_percentage = round(100 / $this->_object->plannedHours * $task_booked_time);
     }
     $this->_request_data['task_booked_percentage'] = $task_booked_percentage;
     $this->_request_data['task_booked_time'] = $task_booked_time;
     return $bookings;
 }
Esempio n. 4
0
 /**
  * helper function - contains code to mark invoice as sent,
  * maybe move it to invoice-class ?
  *
  * @param org_openpsa_invoices_invoice_dba $invoice contains invoice
  */
 private function _mark_as_sent(org_openpsa_invoices_invoice_dba $invoice)
 {
     if (!$invoice->sent) {
         $invoice->sent = time();
         if ($invoice->update()) {
             $this->_request_data['message']['message'] = sprintf($this->_l10n->get('marked invoice %s sent'), $invoice->get_label());
         } else {
             $this->_request_data['message']['message'] = sprintf($this->_l10n->get('could not mark invoice %s paid'), $invoice->get_label());
             return false;
         }
         $mc = new org_openpsa_relatedto_collector($invoice->guid, 'org_openpsa_projects_task_dba');
         $tasks = $mc->get_related_objects();
         // Close "Send invoice" task
         foreach ($tasks as $task) {
             if (org_openpsa_projects_workflow::complete($task) && !isset($args["no_redirect"])) {
                 midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.invoices'), sprintf($this->_l10n->get('marked task "%s" finished'), $task->title), 'ok');
             }
         }
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Queries org.openpsa.sales for suspected task links and saves them
  */
 function get_suspected_sales_links()
 {
     debug_add('called');
     //Safety
     if (!$this->_suspects_classes_present()) {
         debug_add('required classes not present, aborting', MIDCOM_LOG_WARN);
         return;
     }
     // Do no seek if we already have confirmed links
     $mc = new org_openpsa_relatedto_collector($this->guid, array('org_openpsa_salesproject_dba', 'org_openpsa_salesproject_deliverable_dba'));
     $mc->add_constraint('status', '=', org_openpsa_relatedto_dba::CONFIRMED);
     $links = $mc->get_related_guids();
     if (!empty($links)) {
         $cnt = count($links);
         debug_add("Found {$cnt} confirmed links already, skipping seek");
         return;
     }
     $link_def = $this->_suspect_defaults();
     $sales_suspect_links = org_openpsa_relatedto_suspect::find_links_object_component($this, 'org.openpsa.sales', $link_def);
     foreach ($sales_suspect_links as $linkdata) {
         debug_add("processing sales link {$linkdata['other_obj']->guid}, (class: " . get_class($linkdata['other_obj']) . ")");
         $stat = $linkdata['link']->create();
         if ($stat) {
             debug_add("saved link to {$linkdata['other_obj']->guid} (link id #{$linkdata['link']->id})", MIDCOM_LOG_INFO);
         } else {
             debug_add("could not save link to {$linkdata['other_obj']->guid}, errstr" . midcom_connection::get_error_string(), MIDCOM_LOG_WARN);
         }
     }
     debug_add('done');
     return;
 }
Esempio n. 6
0
 /**
  * Helper function to alter the schema based on the current operation
  */
 private function _modify_schema()
 {
     $mc = new org_openpsa_relatedto_collector($this->_deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'ASC');
     $mc->set_object_limit(1);
     $at_entries = $mc->get_related_objects();
     if (sizeof($at_entries) != 1) {
         return;
     }
     $entry = $at_entries[0];
     $fields =& $this->_schemadb['subscription']->fields;
     $fields['next_cycle']['hidden'] = false;
     $fields['next_cycle']['default'] = array('next_cycle_date' => date('Y-m-d', $entry->start));
     $fields['at_entry']['default'] = $entry->id;
 }
Esempio n. 7
0
 function get_at_entries()
 {
     $mc = new org_openpsa_relatedto_collector($this->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_constraint('method', '=', 'new_subscription_cycle');
     $at_entries = $mc->get_related_objects();
     return $at_entries;
 }
Esempio n. 8
0
 private function _verify_at_entry($values)
 {
     $mc = new org_openpsa_relatedto_collector($this->_deliverable->guid, 'midcom_services_at_entry_dba');
     $at_entries = $mc->get_related_objects('midcom.services.at');
     $this->register_objects($at_entries);
     $this->assertEquals(1, sizeof($at_entries));
     $at_entry = $at_entries[0];
     foreach ($values as $field => $value) {
         if ($field == 'start') {
             $this->assertEquals(gmstrftime('%x %X', $value), gmstrftime('%x %X', $at_entry->{$field}), 'Difference in at_entry field ' . $field);
         } else {
             $this->assertEquals($value, $at_entry->{$field}, 'Difference in at_entry field ' . $field);
         }
     }
 }
Esempio n. 9
0
midcom::get('auth')->require_admin_user();
// Ensure this is not buffered
midcom::get('cache')->content->enable_live_mode();
while (@ob_end_flush()) {
    midcom::get()->disable_limits();
}
echo "<h1>Cleanup deliverable AT entries:</h1>\n";
$qb = org_openpsa_sales_salesproject_deliverable_dba::new_query_builder();
$qb->add_constraint('orgOpenpsaObtype', '=', org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
$qb->add_constraint('state', '>=', org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED);
$deliverables = $qb->execute();
echo "<pre>\n";
flush();
foreach ($deliverables as $deliverable) {
    $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
    $mc->add_object_order('start', 'DESC');
    $at_entries = $mc->get_related_objects();
    if (sizeof($at_entries) <= 1) {
        continue;
    }
    echo "Removing duplicate AT entries for deliverable #{$deliverable->id} " . $deliverable->title . "\n";
    flush();
    $first = true;
    foreach ($at_entries as $entry) {
        if ($first) {
            $first = false;
            echo "Keeping entry for " . strftime('%x %X', $entry->start) . "\n";
            flush();
            continue;
        }