Skip to content

Commit

Permalink
Merge pull request smarty-php#43 from think-ahead/ticket-#5226-if-exi…
Browse files Browse the repository at this point in the history
…sts-out-of-range-reservation-show-error-message

Redmine-#5226: [かんざし連携] 予約が営業時間外となる場合、エラーメッセージを表示する
  • Loading branch information
think-katou authored Apr 16, 2021
2 parents d4c6fdf + d8ce59b commit 6932da3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 15 deletions.
57 changes: 57 additions & 0 deletions app/controllers/components/misc_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,63 @@ function GetDailyKanzashiCustomersLimitFromOldTable(&$controller, $dbname, $stor
return $result;
}

/**
* 営業時間外となる予約が存在する日付の配列を取得する
*
* @param controller $controller
* @param string $dbname
* @param int $kanzashisalonposid
* @param storeHolidayInformation $store_holiday 店舗休日のオブジェクト
* @param _kanzashiCustomersLimit $customers_limits かんざし時間別予約可能数のオブジェクト配列
* @return array 営業時間外となる予約が存在する日付の配列
*/
function GetReservationDatesOutsideBusinessHours(&$controller, $dbname, $kanzashisalonposid, $store_holiday, $customers_limits)
{
$controller->StoreHoliday->set_company_database($dbname, $controller->StoreHoliday);
$daily_times = array();

foreach ($customers_limits as $customers_limit) {
$date = $customers_limit['ymd'];
$daily_times[$date]["start_time"][] = substr($customers_limit['begin_time'], 0, 8);
$daily_times[$date]["end_time"][] = substr($customers_limit['end_time'], 0, 8);
}

$date_queries = array();

foreach ($daily_times as $date => $daily_time) {
$day = date('j', strtotime($date));
$is_holiday = var_export($store_holiday["day{$day}"] !== "", true);
$start_time = min($daily_time['start_time']);
$end_time = max($daily_time['end_time']);
$date_queries[] = "kr.date = '{$date}' AND ({$is_holiday} OR kr.start_time < '{$start_time}' OR kr.end_time > '{$end_time}')";
}

$date_query = implode(' OR ', $date_queries);

$query = "
SELECT DISTINCT kr.date
FROM kanzashi_reservation kr
JOIN sipssbeauty_kanzashi.salon s
ON
s.pos_id = {$kanzashisalonposid} AND
s.kanzashi_id = kr.salon_id
WHERE
kr.deletedate IS NULL AND
({$date_query})
ORDER BY
kr.date
";

$records = $controller->StoreHoliday->query($query);
$result = array();

foreach ($records as $record) {
$result[] = $record['kr']['date'];
}

return $result;
}

/**
* Get the available Facilities
*
Expand Down
51 changes: 36 additions & 15 deletions app/controllers/servers_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ class ServersController extends WebServicesController
'store_holiday' => 'tns:storeHolidayInformation',
'customers_limits' => 'tns:_kanzashiCustomersLimit'
),
'output' => array('return' => 'xsd:boolean')
'output' => array('return' => 'tns:return_updateKanzashiCustomersLimit')
),
'wsPushKanzashiStylist' => array(
'doc' => 'かんざしスタイリストPUSH',
Expand Down Expand Up @@ -2407,6 +2407,17 @@ class ServersController extends WebServicesController
'store_holiday' => 'tns:storeHolidayInformation',
'customers_limits' => 'tns:_kanzashiCustomersLimit'
)
),

// かんざし時間別予約可能数更新結果
'_dates' => array(
'array' => 'xsd:date'
),
'return_updateKanzashiCustomersLimit' => array(
'struct' => array(
'error_dates' => 'tns:_dates',
'updated' => 'xsd:boolean'
)
)

);
Expand Down Expand Up @@ -11316,24 +11327,33 @@ function wsGetMonthlyKanzashiSalonHours($sessionid, $kanzashisalonposid, $storec
* @param boolean $ismainsalon
* @param storeHolidayInformation $store_holiday 店舗休日のオブジェクト
* @param _kanzashiCustomersLimit $customers_limits かんざし時間別予約可能数のオブジェクト配列
* @return return_updateKanzashiCustomersLimit かんざし時間別予約可能数更新結果
*/
function wsUpdateKanzashiCustomersLimit($sessionid, $ismainsalon, $store_holiday, $customers_limits)
{
$result = array('error_dates' => array(), 'updated' => false);
$storeinfo = $this->YoyakuSession->Check($this);

if (!$storeinfo) {
$this->_soap_server->fault(1, '', INVALID_SESSION);
return $result;
}

$storecode = $store_holiday['STORECODE'];

if ($store_holiday['KANZASHI_ENABLED']) {
$kanzashisalonposid = $store_holiday['KANZASHI_SALON_POS_ID'];
}
if ($store_holiday['year'] && $store_holiday['month'] && $storecode) {
$this->wsAddUpdateDeleteStoreHoliday($sessionid, $store_holiday, $ismainsalon);
} else {
$store_info = $this->YoyakuSession->Check($this);

if (!$store_info) {
$this->_soap_server->fault(1, '', INVALID_SESSION);
return;
if ($store_holiday['year'] && $store_holiday['month']) {
// 設定されている場合、営業日のアップデートを行う。
$result['error_dates'] = $this->MiscFunction->GetReservationDatesOutsideBusinessHours($this, $storeinfo['dbname'], $kanzashisalonposid, $store_holiday, $customers_limits);

if ($result['error_dates'] || !$this->wsAddUpdateDeleteStoreHoliday($sessionid, $store_holiday, $ismainsalon)) {
return $result;
}

$this->StoreHoliday->set_company_database($store_info['dbname'], $this->StoreHoliday);
} else {
$this->StoreHoliday->set_company_database($storeinfo['dbname'], $this->StoreHoliday);
}

$delete_values = array();
Expand Down Expand Up @@ -11385,21 +11405,22 @@ function wsUpdateKanzashiCustomersLimit($sessionid, $ismainsalon, $store_holiday
}

$source = $this->StoreHoliday->getDataSource();
$source->begin();

try {
$source->begin();
foreach ($sqlstatements as $sqlstatement) {
if ($this->StoreHoliday->query($sqlstatement) === false) {
throw new Exception();
}
}

$source->commit();
unset($source, $sqlstatements);
return true;
$result['updated'] = true;
} catch (Exception $ex) {
$source->rollback();
unset($source, $sqlstatements);
return false;
}

return $result;
}

/**
Expand Down

0 comments on commit 6932da3

Please sign in to comment.