function setBranch($ids)
 {
     Debug::text('Setting IDs...', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($ids, 'Setting Branch IDs...', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids)) {
         $tmp_ids = array();
         if (!$this->isNew()) {
             //If needed, delete mappings first.
             $lf_a = new PremiumPolicyBranchListFactory();
             $lf_a->getByPremiumPolicyId($this->getId());
             foreach ($lf_a as $obj) {
                 $id = $obj->getBranch();
                 Debug::text('Branch ID: ' . $obj->getBranch() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                 //Delete users that are not selected.
                 if (!in_array($id, $ids)) {
                     Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $obj->Delete();
                 } else {
                     //Save ID's that need to be updated.
                     Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $tmp_ids[] = $id;
                 }
             }
             unset($id, $obj);
         }
         //Insert new mappings.
         $lf_b = new BranchListFactory();
         foreach ($ids as $id) {
             if (isset($ids) and $id > 0 and !in_array($id, $tmp_ids)) {
                 $f = new PremiumPolicyBranchFactory();
                 $f->setPremiumPolicy($this->getId());
                 $f->setBranch($id);
                 $obj = $lf_b->getById($id)->getCurrent();
                 if ($this->Validator->isTrue('branch', $f->Validator->isValid(), TTi18n::gettext('Selected Branch is invalid') . ' (' . $obj->getName() . ')')) {
                     $f->save();
                 }
             }
         }
         return TRUE;
     }
     Debug::text('No IDs to set.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
                Debug::Text('DepartmentBranchId: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10);
                if (isset($id)) {
                    //Get User ID's from database.
                    $dbulf = new DepartmentBranchUserListFactory();
                    $dbulf->getByDepartmentBranchId($department_branch->getId());
                    $department_branch_user_ids = array();
                    foreach ($dbulf as $department_branch_user) {
                        $department_branch_user_ids[] = $department_branch_user->getUser();
                        Debug::Text('DepartmentBranchUser: '******'s.
                    $department_branch_user_ids = $department_data['branch_data'][$branch_id];
                }
                $blf = new BranchListFactory();
                $blf->getById($branch_id);
                $branch = $blf->getIterator()->current();
                $branch_data[$branch_id] = array('id' => $branch->getId(), 'name' => $branch->getName(), 'user_ids' => $department_branch_user_ids);
            }
            $department_data = array('id' => $department->getId(), 'company_name' => $current_company->getName(), 'status' => $department->getStatus(), 'name' => $department->getName(), 'branch_list' => $department->getBranch(), 'branch_data' => $branch_data, 'created_date' => $department->getCreatedDate(), 'created_by' => $department->getCreatedBy(), 'updated_date' => $department->getUpdatedDate(), 'updated_by' => $department->getUpdatedBy(), 'deleted_date' => $department->getDeletedDate(), 'deleted_by' => $department->getDeletedBy());
        }
        //Select box options;
        $department_data['branch_list_options'] = BranchListFactory::getByCompanyIdArray($current_company->getId());
        //$ulf = new UserListFactory;
        $department_data['user_options'] = UserListFactory::getByCompanyIdArray($current_company->getId(), FALSE);
        //var_dump($te);
        $smarty->assign_by_ref('department_data', $department_data);
        break;
}
$smarty->assign_by_ref('dbuf', $dbuf);
$smarty->display('department/EditDepartmentBranchUser.tpl');
 foreach ($slf as $user_total_time_obj) {
     $user_obj = $ulf->getById($user_total_time_obj->getColumn('user_id'))->getCurrent();
     Debug::text(' User Name: ' . $user_obj->getFullName(), __FILE__, __LINE__, __METHOD__, 10);
     $user_percent = $user_total_time_obj->getColumn('branch_total_time') / $totals['users'][$user_total_time_obj->getColumn('user_id')];
     if (isset($pay_stub_rows[$user_total_time_obj->getColumn('user_id')])) {
         $user_gross_pay = $pay_stub_rows[$user_total_time_obj->getColumn('user_id')]['entries']['gross_pay'] * $user_percent;
     } else {
         $user_gross_pay = 0;
     }
     $user_entries[$user_total_time_obj->getColumn('branch_id')][] = array('user_id' => $user_total_time_obj->getColumn('user_id'), 'branch_id' => $user_total_time_obj->getColumn('branch_id'), 'full_name' => $user_obj->getFullName(), 'total_time' => $user_total_time_obj->getColumn('branch_total_time'), 'percent' => $user_percent, 'percent_display' => round($user_percent * 100, 2), 'gross_pay' => number_format($user_gross_pay, 2, '.', ''));
     unset($user_percent, $user_gross_pay);
 }
 if (isset($branch_ids)) {
     foreach ($branch_ids as $branch_id) {
         Debug::text(' Branch Done! Branch ID: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10);
         $branch_obj = $blf->getById($branch_id)->getCurrent();
         $branch_percent = $totals['branches'][$branch_id] / $totals['branches']['total'];
         $user_totals = Misc::ArrayAssocSum($user_entries[$branch_id], NULL, 2);
         $user_entries[$branch_id][] = array('full_name' => 'Total', 'total_time' => $totals['branches'][$branch_id], 'percent' => $branch_percent * 100, 'percent_display' => round($branch_percent * 100, 2), 'gross_pay' => number_format($user_totals['gross_pay'], 2, '.', ''));
         $rows[] = array('id' => $branch_id, 'name' => $branch_obj->getName(), 'percent' => $branch_percent, 'percent_display' => round($branch_percent * 100, 2), 'users' => $user_entries[$branch_id]);
         unset($branch_obj, $branch_percent, $user_totals);
     }
 }
 unset($branch_ids);
 //var_dump($rows);
 /*
 		if ( isset($tmp_rows) ) {
 			foreach($tmp_rows as $row) {
 				$rows[] = $row;
 			}
 			$rows = Sort::Multisort($rows, 'last_name');