Exemplo n.º 1
0
 public function testCreate()
 {
     midcom::get('auth')->request_sudo('org.openpsa.relatedto');
     $invoice = $this->create_object('org_openpsa_invoices_invoice_dba');
     $salesproject = $this->create_object('org_openpsa_sales_salesproject_dba');
     $relatedto = org_openpsa_relatedto_plugin::create($invoice, 'org.openpsa.invoices', $salesproject, 'org.openpsa.sales');
     $this->assertTrue(is_a($relatedto, 'org_openpsa_relatedto_dba'));
     $this->register_object($relatedto);
     $this->assertEquals($relatedto->status, org_openpsa_relatedto_dba::CONFIRMED);
     $this->assertEquals($relatedto->fromGuid, $invoice->guid);
     $this->assertEquals($relatedto->fromComponent, 'org.openpsa.invoices');
     $this->assertEquals($relatedto->fromClass, 'org_openpsa_invoices_invoice_dba');
     $this->assertEquals($relatedto->toGuid, $salesproject->guid);
     $this->assertEquals($relatedto->toComponent, 'org.openpsa.sales');
     $this->assertEquals($relatedto->toClass, 'org_openpsa_sales_salesproject_dba');
     $relatedto2 = org_openpsa_relatedto_plugin::create($invoice, 'org.openpsa.invoices', $salesproject, 'org.openpsa.sales');
     $this->assertEquals($relatedto2->guid, $relatedto->guid);
     $x = null;
     $stat = org_openpsa_relatedto_plugin::create($x, 'org.openpsa.invoices', $salesproject, 'org.openpsa.sales');
     $this->assertFalse($stat);
     $stat = org_openpsa_relatedto_plugin::create($invoice, 'org.openpsa.invoices', $x, 'org.openpsa.sales');
     $this->assertFalse($stat);
     $relatedto2 = org_openpsa_relatedto_plugin::create($invoice, 'org.openpsa.invoices', $salesproject, 'org.openpsa.sales', org_openpsa_relatedto_dba::NOTRELATED);
     $this->assertEquals($relatedto2->guid, $relatedto->guid);
     $this->assertEquals($relatedto2->status, org_openpsa_relatedto_dba::NOTRELATED);
     $stat = $relatedto->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Exemplo n.º 2
0
 public static function setUpBeforeClass()
 {
     self::$_object_from = self::create_class_object('org_openpsa_invoices_invoice_dba');
     self::$_object_to = self::create_class_object('org_openpsa_sales_salesproject_dba');
     midcom::get('auth')->request_sudo('org.openpsa.relatedto');
     self::$_relation = org_openpsa_relatedto_plugin::create(self::$_object_from, 'org.openpsa.invoices', self::$_object_to, 'org.openpsa.sales');
     midcom::get('auth')->drop_sudo();
 }
Exemplo n.º 3
0
 /**
  * Display possible available resources
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_resourcing($handler_id, array $args, array &$data)
 {
     $this->_task = new org_openpsa_projects_task_dba($args[0]);
     $this->_task->require_do('midgard:create');
     if (array_key_exists('org_openpsa_projects_prospects', $_POST) && $_POST['save']) {
         foreach ($_POST['org_openpsa_projects_prospects'] as $prospect_guid => $slots) {
             try {
                 $prospect = new org_openpsa_projects_task_resource_dba($prospect_guid);
             } catch (midcom_error $e) {
                 continue;
             }
             $update_prospect = false;
             foreach ($slots as $slotdata) {
                 if (!array_key_exists('used', $slotdata) || empty($slotdata['used'])) {
                     // Slot not selected, skip
                     continue;
                 }
                 $prospect->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_PROJECTRESOURCE;
                 $update_prospect = true;
                 // Create event from slot
                 $event = new org_openpsa_calendar_event_dba();
                 $event->start = $slotdata['start'];
                 $event->end = $slotdata['end'];
                 $event->search_relatedtos = false;
                 $event->title = sprintf($this->_l10n->get('work for task %s'), $this->_task->title);
                 if (!$event->create()) {
                     // TODO: error reporting
                     continue;
                 }
                 $participant = new org_openpsa_calendar_event_member_dba();
                 $participant->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_EVENTPARTICIPANT;
                 $participant->uid = $prospect->person;
                 $participant->eid = $event->id;
                 $participant->create();
                 // create relatedto
                 if (!org_openpsa_relatedto_plugin::create($event, 'org.openpsa.calendar', $this->_task, 'org.openpsa.projects')) {
                     // TODO: delete event ???
                 }
             }
         }
         if ($update_prospect) {
             if (!$prospect->update()) {
                 // TODO: error handling
             }
         }
         return new midcom_response_relocate("task/{$this->_task->guid}/");
     } else {
         if (!empty($_POST['cancel'])) {
             return new midcom_response_relocate("task/{$this->_task->guid}/");
         }
     }
     $this->_prepare_request_data($handler_id);
     midcom::get('head')->set_pagetitle($this->_task->title);
     $this->bind_view_to_object($this->_task);
     org_openpsa_projects_viewer::add_breadcrumb_path($data['task'], $this);
     $this->add_breadcrumb("task/resourcing/{$this->_task->guid}/", $this->_l10n->get('resourcing'));
 }
Exemplo n.º 4
0
 /**
  * Function to process the notify date in the passed formdata of the datamanger
  * creates/edits/deletes the corresponding at_entry if needed
  *
  * @param array $formdata The Formdata of the datamanager containing the notify_date
  * @param org_openpsa_sales_salesproject_deliverable_dba $deliverable The current deliverable
  */
 public function process_notify_date($formdata, org_openpsa_sales_salesproject_deliverable_dba $deliverable)
 {
     //check if there is already an at_entry
     $mc_entry = org_openpsa_relatedto_dba::new_collector('toGuid', $deliverable->guid);
     $mc_entry->add_constraint('fromClass', '=', 'midcom_services_at_entry_dba');
     $mc_entry->add_constraint('toClass', '=', 'org_openpsa_sales_salesproject_deliverable_dba');
     $mc_entry->add_constraint('toExtra', '=', 'notify_at_entry');
     $entry_keys = $mc_entry->get_values('fromGuid');
     //check date
     if (!$formdata['notify']->is_empty()) {
         $notification_entry = null;
         if (count($entry_keys) == 0) {
             $notification_entry = new midcom_services_at_entry_dba();
             $notification_entry->create();
             //relatedto from notifcation to deliverable
             org_openpsa_relatedto_plugin::create($notification_entry, 'midcom.services.at', $deliverable, 'org.openpsa.sales', false, array('toExtra' => 'notify_at_entry'));
         } else {
             //get guid of at_entry
             foreach ($entry_keys as $key => $entry) {
                 //check if related at_entry exists
                 try {
                     $notification_entry = new midcom_services_at_entry_dba($entry);
                 } catch (midcom_error $e) {
                     //relatedto links to a non-existing at_entry - so create a new one an link to it
                     $notification_entry = new midcom_services_at_entry_dba();
                     $notification_entry->create();
                     $relatedto = new org_openpsa_relatedto_dba($key);
                     $relatedto->fromGuid = $notification_entry->guid;
                     $relatedto->update();
                 }
                 break;
             }
         }
         $notification_entry->start = $formdata['notify']->value->format('U');
         $notification_entry->method = 'new_notification_message';
         $notification_entry->component = 'org.openpsa.sales';
         $notification_entry->arguments = array('deliverable' => $deliverable->guid);
         $notification_entry->update();
     } else {
         //void date - so delete existing at_entrys for this notify_date
         foreach ($entry_keys as $key => $empty) {
             try {
                 $notification_entry = new midcom_services_at_entry_dba($mc_entry->get_subkey($key, 'fromGuid'));
                 //check if related at_entry exists & delete it
                 $notification_entry->delete();
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
     }
 }
Exemplo n.º 5
0
 public function testHandler_edit()
 {
     midcom::get('auth')->request_sudo('org.openpsa.sales');
     $deliverable_attributes = array('salesproject' => self::$_salesproject->id);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $deliverable->set_parameter('midcom.helper.datamanager2', 'schema_name', 'subscription');
     $year = date('Y') + 1;
     $start = strtotime($year . '-10-15 00:00:00');
     $at_parameters = array('arguments' => array('deliverable' => $deliverable->guid, 'cycle' => 1), 'start' => $start, 'component' => 'org.openpsa.sales', 'method' => 'new_subscription_cycle');
     $at_entry = $this->create_object('midcom_services_at_entry_dba', $at_parameters);
     org_openpsa_relatedto_plugin::create($at_entry, 'midcom.services.at', $deliverable, 'org.openpsa.sales');
     $data = $this->run_handler('org.openpsa.sales', array('deliverable', 'edit', $deliverable->guid));
     $this->assertEquals('deliverable_edit', $data['handler_id']);
     $group = $data['controller']->formmanager->form->getElement('next_cycle');
     $this->assertTrue($group instanceof HTML_Quickform_group, ' next cycle widget missing');
     $elements = $group->getElements();
     $this->assertEquals($year . '-10-15', $elements[0]->getValue());
     midcom::get('auth')->drop_sudo();
 }
Exemplo n.º 6
0
 /**
  * Generate "Send invoice" task
  */
 function generate_invoicing_task($invoicer)
 {
     try {
         $invoice_sender = new midcom_db_person($invoicer);
     } catch (midcom_error $e) {
         return;
     }
     $config = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config');
     $task = new org_openpsa_projects_task_dba();
     $task->get_members();
     $task->resources[$invoice_sender->id] = true;
     $task->manager = midcom_connection::get_user();
     // TODO: Connect the customer as the contact?
     $task->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_TASK;
     $task->title = sprintf(midcom::get('i18n')->get_string('send invoice %s', 'org.openpsa.invoices'), sprintf($config->get('invoice_number_format'), sprintf($config->get('invoice_number_format'), $this->number)));
     // TODO: Store link to invoice into description
     $task->end = time() + 24 * 3600;
     if ($task->create()) {
         org_openpsa_relatedto_plugin::create($task, 'org.openpsa.projects', $this, 'org.openpsa.invoices');
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.invoices', 'org.openpsa.invoices'), sprintf(midcom::get('i18n')->get_string('created "%s" task to %s', 'org.openpsa.invoices'), $task->title, $invoice_sender->name), 'ok');
     }
 }
Exemplo n.º 7
0
 function create_hour_report(&$task, $person_id, &$from_object, $from_component)
 {
     if (!midcom::get('dbfactory')->is_a($task, 'org_openpsa_projects_task_dba')) {
         debug_add('given task is not really a task', MIDCOM_LOG_ERROR);
         return false;
     }
     if (empty($person_id)) {
         debug_add('person_id is "empty"', MIDCOM_LOG_ERROR);
         return false;
     }
     //TODO: this should probably have privileges like midgard:owner set to $person_id
     $hr = new org_openpsa_projects_hour_report_dba();
     $hr->task = $task->id;
     $hr->person = $person_id;
     $hr->invoiceable = $task->hoursInvoiceableDefault;
     switch (true) {
         case midcom::get('dbfactory')->is_a($from_object, 'org_openpsa_calendar_event_dba'):
             $event =& $from_object;
             $hr->date = $event->start;
             $hr->hours = round(($event->end - $event->start) / 3600, 2);
             // TODO: Localize ? better indicator that this is indeed from event ??
             $hr->description = "event: {$event->title} " . $event->format_timeframe() . ", {$event->location}\n";
             $hr->description .= "\n{$event->description}\n";
             break;
         default:
             debug_add("class '" . get_class($from_object) . "' not supported", MIDCOM_LOG_ERROR);
             return false;
     }
     debug_print_r("about to create hour_report", $hr);
     $stat = $hr->create();
     if (!$stat) {
         debug_add("failed to create hour_report to task #{$task->id} for person #{$person_id}", MIDCOM_LOG_ERROR);
         return false;
     }
     debug_add("created hour_report #{$hr->id}");
     // Create a relatedtolink from hour_report to the object it was created from
     org_openpsa_relatedto_plugin::create($hr, 'org.openpsa.projects', $from_object, $from_component);
     return true;
 }
Exemplo n.º 8
0
 /**
  * @todo Check if we already have an open task for this delivery?
  */
 function create_task($start, $end, $title, $source_task = null)
 {
     $salesproject = org_openpsa_sales_salesproject_dba::get_cached($this->_deliverable->salesproject);
     $product = org_openpsa_products_product_dba::get_cached($this->_deliverable->product);
     // Check if we already have a project for the sales project
     $project = $salesproject->get_project();
     // Create the task
     $task = new org_openpsa_projects_task_dba();
     $task->agreement = $this->_deliverable->id;
     $task->customer = $salesproject->customer;
     $task->title = $title;
     $task->description = $this->_deliverable->description;
     $task->start = $start;
     $task->end = $end;
     $task->plannedHours = $this->_deliverable->plannedUnits;
     $task->manager = $salesproject->owner;
     if ($project) {
         $task->project = $project->id;
         $task->orgOpenpsaAccesstype = $project->orgOpenpsaAccesstype;
         $task->orgOpenpsaOwnerWg = $project->orgOpenpsaOwnerWg;
     }
     if (!empty($source_task)) {
         $task->priority = $source_task->priority;
         $task->manager = $source_task->manager;
     }
     // TODO: Figure out if we really want to keep this
     $task->hoursInvoiceableDefault = true;
     if ($task->create()) {
         $task->add_members('contacts', array_keys($salesproject->contacts));
         if (!empty($source_task)) {
             $source_task->get_members();
             $task->add_members('resources', array_keys($source_task->resources));
         }
         org_openpsa_relatedto_plugin::create($task, 'org.openpsa.projects', $product, 'org.openpsa.products');
         // Copy tags from deliverable so we can seek resources
         $tagger = new net_nemein_tag_handler();
         $tagger->copy_tags($this->_deliverable, $task);
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.sales', 'org.openpsa.sales'), sprintf(midcom::get('i18n')->get_string('created task "%s"', 'org.openpsa.sales'), $task->title), 'ok');
         return $task;
     } else {
         throw new midcom_error("The task for this cycle could not be created. Last Midgard error was: " . midcom_connection::get_error_string());
     }
 }