/** * Get a static reference to the storage object associated with this model object * * @return the storage object */ public static function get_so() { if (self::$so == null) { self::$so = CreateObject('logistic.sorequirement'); } return self::$so; }
public function save() { $requirement_id = phpgw::get_var('requirement_id'); if ($requirement_id && is_numeric($requirement_id)) { $requirement = $this->so_requirement->get_single($requirement_id); $activity_id = $requirement->get_activity_id(); } $user_id = $GLOBALS['phpgw_info']['user']['id']; $chosen_resources = phpgw::get_var('chosen_resources'); $inventory_ids = phpgw::get_var('inventory_ids'); $allocations = phpgw::get_var('allocations'); //FIXME: Bruk 'allocation_id' i staden. //_debug_array($inventory_ids_orig);die(); $filters = array('requirement_id' => $requirement->get_id()); $num_allocated = $this->so->get_count($search_for, $search_type, $filters); $num_required = $requirement->get_no_of_items(); $num_allowed_bookings = $num_required - $num_allocated; if ($inventory_ids) { foreach ($inventory_ids as $resource => $allocated_amount) { if ($allocated_amount) { $resource_arr = explode('_', $resource); $resource_id = $resource_arr[0]; $inventory_id = $resource_arr[1]; $resource_alloc = new logistic_requirement_resource_allocation(); $resource_alloc->set_requirement_id($requirement->get_id()); $resource_alloc->set_resource_id($resource_id); $resource_alloc->set_inventory_id($inventory_id); $resource_alloc->set_allocated_amount($allocated_amount); $resource_alloc->set_id($allocations[$resource]); $resource_alloc->set_location_id($requirement->get_location_id()); $resource_alloc->set_create_user($user_id); $resource_alloc->set_start_date($requirement->get_start_date()); $resource_alloc->set_end_date($requirement->get_start_date()); $resource_alloc_id = $this->so->store($resource_alloc); } } } else { if (count($chosen_resources) <= $num_allowed_bookings) { foreach ($chosen_resources as $resource_id) { $resource_alloc = new logistic_requirement_resource_allocation(); $resource_alloc->set_requirement_id($requirement->get_id()); $resource_alloc->set_resource_id($resource_id); $resource_alloc->set_location_id($requirement->get_location_id()); $resource_alloc->set_create_user($user_id); $resource_alloc->set_start_date($requirement->get_start_date()); $resource_alloc->set_end_date($requirement->get_start_date()); $resource_alloc_id = $this->so->store($resource_alloc); } } } $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'logistic.uiactivity.view_resource_allocation', 'activity_id' => $requirement->get_activity_id())); }
protected function populate(int $allocation_id, &$allocation) { if ($allocation == null) { $allocation = new logistic_requirement_resource_allocation((int) $allocation_id); $allocation->set_location_id($this->unmarshal($this->db->f('location_id'), 'int')); $allocation->set_requirement_id($this->unmarshal($this->db->f('requirement_id'), 'string')); $allocation->set_resource_id($this->unmarshal($this->db->f('resource_id'), 'int')); $allocation->set_resource_type_descr($this->unmarshal($this->db->f('resource_type_descr'), 'string')); $allocation->set_location_code($this->unmarshal($this->db->f('location_code'), 'string')); $allocation->set_fm_bim_item_address($this->unmarshal($this->db->f('fm_bim_item_address'), 'string')); $allocation->set_allocated_amount($this->unmarshal($this->db->f('count'), 'int')); $allocation->set_inventory_id($this->unmarshal($this->db->f('inventory_id'), 'int')); $allocation->set_ticket_id($this->unmarshal($this->db->f('ticket_id'), 'int')); $fm_bim_name = $this->unmarshal($this->db->f('fm_bim_item_name'), 'string'); $allocation->set_fm_bim_item_name($fm_bim_name); } return $allocation; }