示例#1
0
 public function testCreate_task()
 {
     $organization = $this->create_object('org_openpsa_contacts_group_dba');
     $manager = $this->create_object('midcom_db_person');
     $member = $this->create_object('midcom_db_person');
     $group = $this->create_object('org_openpsa_products_product_group_dba');
     $product_attributes = array('productGroup' => $group->id, 'code' => 'TEST-' . __CLASS__ . time());
     $product = $this->create_object('org_openpsa_products_product_dba', $product_attributes);
     $salesproject_attributes = array('owner' => $manager->id, 'customer' => $organization->id);
     $salesproject = $this->create_object('org_openpsa_sales_salesproject_dba', $salesproject_attributes);
     $member_attributes = array('person' => $member->id, 'objectGuid' => $salesproject->guid, 'role' => ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER);
     $this->create_object('org_openpsa_contacts_role_dba', $member_attributes);
     $deliverable_attributes = array('salesproject' => $salesproject->id, 'product' => $product->id, 'description' => 'TEST DESCRIPTION', 'plannedUnits' => 15);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $start = time();
     $end = $start + 30 * 24 * 60 * 60;
     $title = 'TEST TITLE';
     $start_cmp = mktime(0, 0, 0, date('n', $start), date('j', $start), date('Y', $start));
     $end_cmp = mktime(23, 59, 59, date('n', $end), date('j', $end), date('Y', $end));
     $scheduler = new org_openpsa_invoices_scheduler($deliverable);
     midcom::get('auth')->request_sudo('org.openpsa.invoices');
     $task = $scheduler->create_task($start, $end, $title);
     $this->assertTrue(is_a($task, 'org_openpsa_projects_task_dba'));
     $this->register_object($task);
     $this->assertEquals($deliverable->id, $task->agreement);
     $this->assertEquals($salesproject->customer, $task->customer);
     $this->assertEquals($title, $task->title);
     $this->assertEquals($deliverable->description, $task->description);
     $this->assertEquals($start_cmp, $task->start);
     $this->assertEquals($end_cmp, $task->end);
     $this->assertEquals($deliverable->plannedUnits, $task->plannedHours);
     $this->assertEquals($salesproject->owner, $task->manager);
     $this->assertTrue($task->hoursInvoiceableDefault);
     $mc = org_openpsa_relatedto_dba::new_collector('fromGuid', $task->guid);
     $mc->add_value_property('toGuid');
     $mc->execute();
     $keys = $mc->list_keys();
     $this->assertEquals(1, sizeof($keys));
     $product_guid = $mc->get_subkey(key($keys), 'toGuid');
     $this->assertEquals($product->guid, $product_guid);
     $salesproject->get_members();
     $task->get_members();
     $this->assertEquals($salesproject->contacts, $task->contacts);
     $project = new org_openpsa_projects_project($task->project);
     $this->assertTrue(!empty($project->guid));
     $this->register_object($project);
     $project->get_members();
     $this->assertEquals($salesproject->contacts, $project->contacts);
     $this->assertEquals($salesproject->owner, $project->manager);
     $task->priority = 4;
     $task->manager = $member->id;
     $task->update();
     $task->add_members('resources', array($member->id));
     $task->refresh();
     $task2 = $scheduler->create_task($start, $end, $title, $task);
     $this->register_object($task2);
     $task2->get_members();
     $task->get_members();
     $this->assertEquals(4, $task2->priority);
     $this->assertEquals($member->id, $task2->manager);
     $this->assertEquals($task->resources, $task2->resources);
     midcom::get('auth')->drop_sudo();
 }
示例#2
0
 function order()
 {
     if ($this->state >= org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED) {
         return false;
     }
     // Cache the original cost values intended and reset the fields
     $this->plannedUnits = $this->units;
     $this->plannedCost = $this->cost;
     if ($this->invoiceByActualUnits) {
         $this->cost = 0;
         $this->units = 0;
     }
     // Check what kind of order this is
     $product = org_openpsa_products_product_dba::get_cached($this->product);
     $scheduler = new org_openpsa_invoices_scheduler($this);
     if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
         // This is a new subscription, initiate the cycle but don't send invoice
         if (!$scheduler->run_cycle(1, false)) {
             return false;
         }
     } else {
         // Check if we need to create task or ship goods
         switch ($product->orgOpenpsaObtype) {
             case org_openpsa_products_product_dba::TYPE_SERVICE:
                 $scheduler->create_task($this->start, $this->end, $this->title);
                 break;
             case org_openpsa_products_product_dba::TYPE_GOODS:
                 // TODO: Warehouse management: create new order
             // TODO: Warehouse management: create new order
             default:
                 break;
         }
     }
     $this->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED;
     if ($this->update()) {
         // Update sales project and mark as won
         $salesproject = new org_openpsa_sales_salesproject_dba($this->salesproject);
         if ($salesproject->status != org_openpsa_sales_salesproject_dba::STATUS_WON) {
             $salesproject->status = org_openpsa_sales_salesproject_dba::STATUS_WON;
             $salesproject->update();
         }
         return true;
     }
     return false;
 }