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
 /**
  * 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. 4
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. 5
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. 6
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. 7
0
// 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;
        }
        echo "Deleting entry for " . strftime('%x %X', $entry->start) . "\n";
        $entry->delete();