function deliver($update_deliveries = true) { if ($this->state > org_openpsa_sales_salesproject_deliverable_dba::STATUS_DELIVERED) { return false; } $product = org_openpsa_products_product_dba::get_cached($this->product); if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) { // Subscriptions are ongoing, not one delivery return false; } // Check if we need to create task or ship goods if ($update_deliveries) { switch ($product->orgOpenpsaObtype) { case org_openpsa_products_product_dba::TYPE_SERVICE: // Change status of tasks connected to the deliverable $task_qb = org_openpsa_projects_task_dba::new_query_builder(); $task_qb->add_constraint('agreement', '=', $this->id); $task_qb->add_constraint('status', '<', org_openpsa_projects_task_status_dba::CLOSED); $tasks = $task_qb->execute(); foreach ($tasks as $task) { org_openpsa_projects_workflow::close($task, sprintf(midcom::get('i18n')->get_string('completed from deliverable %s', 'org.openpsa.sales'), $this->title)); } break; case org_openpsa_products_product_dba::TYPE_GOODS: // TODO: Warehouse management: mark product as shipped // TODO: Warehouse management: mark product as shipped default: break; } } $this->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_DELIVERED; $this->end = time(); if ($this->update()) { // Update sales project and mark as delivered (if no other deliverables are active) $salesproject = new org_openpsa_sales_salesproject_dba($this->salesproject); $salesproject->mark_delivered(); midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.sales', 'org.openpsa.sales'), sprintf(midcom::get('i18n')->get_string('marked deliverable "%s" delivered', 'org.openpsa.sales'), $this->title), 'ok'); return true; } return false; }