$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $ppf->StartTransaction();
        if ($data['id'] == '') {
            $ppf->setCompany($current_company->getId());
            $ppf->setStatus(10);
            //Open
        } else {
            $ppf->setId($data['id']);
        }
        $ppf->setPayPeriodSchedule($data['pay_period_schedule_id']);
        if (is_object($ppf->getPayPeriodScheduleObject())) {
            $ppf->getPayPeriodScheduleObject()->setPayPeriodTimeZone();
        }
        $ppf->setStartDate($data['start_date']);
        $ppf->setEndDate($data['end_date'] + 59);
        $ppf->setTransactionDate($data['transaction_date'] + 59);
        if (isset($data['advance_end_date'])) {
            $ppf->setAdvanceEndDate($data['advance_end_date']);
        }
        if (isset($data['advance_transaction_date'])) {
            $ppf->setAdvanceTransactionDate($data['advance_transaction_date']);
        }
        $ppf->setEnableImportData(TRUE);
        //Import punches when creating new pay periods.
        if ($ppf->isValid()) {
            $ppf->Save();