function postSave()
 {
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Schedule Policy from Schedule/Recurring Schedules...' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         $sf = new ScheduleFactory();
         $rstf = new RecurringScheduleTemplateFactory();
         $query = 'update ' . $sf->getTable() . ' set schedule_policy_id = 0 where schedule_policy_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $rstf->getTable() . ' set schedule_policy_id = 0 where schedule_policy_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     $this->removeCache($this->getId());
     return TRUE;
 }
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Hours from Branch: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         //Unassign hours from this branch.
         $pcf = new PunchControlFactory();
         $udtf = new UserDateTotalFactory();
         $uf = new UserFactory();
         $sf = new StationFactory();
         $sf_b = new ScheduleFactory();
         $udf = new UserDefaultFactory();
         $rstf = new RecurringScheduleTemplateFactory();
         $query = 'update ' . $pcf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udtf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf_b->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $uf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf->getTable() . ' set branch_id = 0 where company_id = ' . $this->getCompany() . ' AND branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $rstf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     return TRUE;
 }
    function getMaximumStartStopWindowByCompanyIdAndRecurringScheduleControlID($company_id, $id, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if ($id == '') {
            return FALSE;
        }
        if ($order == NULL) {
            $order = array('a.name' => 'asc');
            $strict = FALSE;
        } else {
            $strict = TRUE;
        }
        $rstf = new RecurringScheduleTemplateFactory();
        $ph = array('company' => $company_id, 'id' => $id);
        $query = '
					select 	max(start_stop_window)
					from	' . $this->getTable() . ' as spf
					LEFT JOIN ' . $rstf->getTable() . ' as rstf ON ( spf.id = rstf.schedule_policy_id )
					where	spf.company_id = ?
						AND rstf.recurring_schedule_template_control_id = ?
						AND ( spf.deleted = 0 AND rstf.deleted = 0 )';
        $window = $this->db->GetOne($query, $ph);
        if ($window === FALSE) {
            $window = 0;
        }
        Debug::text('Max Start/Stop Window: ' . $window, __FILE__, __LINE__, __METHOD__, 10);
        return $window;
    }