public function preProcess() { parent::preProcess(); // if (!Tools::hasFunction('room_plan_edit')) Tools::redirect('index.php'); $rpid = Tools::getValue("rpid"); $roomplan_sales = RoomPlan::getRoomPlanSales($rpid); // $roomplan_sales['Nights'] =(strtotime($roomplan_sales['ConToTime']) - strtotime($roomplan_sales['ConFromTime'])) / (24 * 60 * 60); // diff day self::$smarty->assign("roomplan_sales", $roomplan_sales); parent::displayContent(); self::$smarty->display(_TAS_THEME_DIR_ . 'roomplan_sales.tpl'); exit; }
public static function calculation_roomplan_price($rpid, $checkin, $checkout, $companyId) { $price_result = array(); $price_result['Price'] = 0; $price_result['OrgPrice'] = 0; $price_result['PriceString'] = ''; $continentCode = Tools::getUserContinentCode($companyId); // @TODO validation room plan info // // fetch roomplan info for consecutive information $rp_sales = RoomPlan::getRoomPlanSales($rpid); // fetch roomplan price info list $sql = "\n SELECT DATE_FORMAT(A.ApplyDate, '%Y-%m-%d') as ApplyDate, (\n\n \t\t\t\t\t\tIF('{$continentCode}' = 'AS',\n \t\t\t\t\t\t\t\tIF(A.`Asia` > 0, A.Asia, A.Price) ,\n \t\t\t\t\t\t\t\tIF('{$continentCode}' = 'EU',\n \t\t\t\t\t\t\t\t\tIF(A.`Euro` > 0, A.Euro, A.Price) ,\n \t\t\t\t\t\t\t\t\tA.Price) )\n \t\t\t\t\t) as Price\n FROM HT_RoomStockAndPrice as A, HT_RoomPlan as B\n WHERE A.`ApplyDate` between '{$checkin}' and DATE_SUB('{$checkout}', INTERVAL 1 DAY) and A.`RoomPlanId` = {$rpid} and B.RoomPlanId = {$rpid}\n ORDER BY A.`ApplyDate`\n "; //echo $sql; $price_list = Db::getInstance()->ExecuteS($sql); // @TODO refactoring grouping code // sales duration recalc for checkin-checkout if ($rp_sales['ConFromTime'] < $checkin) { $rp_sales['ConFromTime'] = $checkin; } if ($rp_sales['ConToTime'] > $checkout && $checkout >= $rp_sales['ConFromTime']) { $rp_sales['ConToTime'] = $checkout; } // calc var that we can apply consecutive price $apply_con_var = 0; if ($rp_sales['UseCon'] == 1) { $diff_days = (strtotime($rp_sales['ConToTime']) - strtotime($rp_sales['ConFromTime'])) / (24 * 60 * 60); $apply_con_var = (int) ($diff_days / $rp_sales['Nights']); // echo 'apply : '.$apply_con_var; } // ============================================================ // grouping price string // ============================================================ // each price will be demonstrated by [Price]/[Days]. For example 100$ / 1 day, 200$ / 2 days // we will group each values for showing. Grouping condition is that price and days value are all the same and sequential. // For example : // 100$/1day + 100$/1day + 200$/3days + 200$/3days + 200$/1day + 100$/1day will be // 100$/1day * 2 + 200$/3days * 2 + 200$/1day + 100$/1day // // initialize variables $rp_price = 0; // roomplan total price $rp_price_string = ''; // roomplan total price string // calc price / [n per day] $price = 0; // current price value $per_day = 1; // day $prev_price = 0; // previous price val $prev_per_day = 1; // previous day val $prev_day_count = 0; // counting previous same price/day pair $check_0 = 1; $shoushu_price = 0; $shoushu_prev_price = 0; foreach ($price_list as $price_info) { // if there is sales price if ($rp_sales['UseCon'] == 1 && $price_info['ApplyDate'] >= $rp_sales['ConFromTime'] && $price_info['ApplyDate'] <= $rp_sales['ConToTime']) { // check we can apply sales condition espetially nights $diff_days = (strtotime($price_info['ApplyDate']) - strtotime($rp_sales['ConFromTime'])) / (24 * 60 * 60); if ($diff_days / $rp_sales['Nights'] < $apply_con_var) { // sales price if ($diff_days % $rp_sales['Nights'] == 0) { if ($continentCode == 'AS') { $price_info['Price'] = $rp_sales['PriceAsia'] > 0 ? $rp_sales['PriceAsia'] : $rp_sales['PriceAll']; } else { if ($continentCode == 'EU') { $price_info['Price'] = $rp_sales['PriceEuro'] > 0 ? $rp_sales['PriceEuro'] : $rp_sales['PriceAll']; } else { $price_info['Price'] = $rp_sales['PriceAll']; } } $price = $price_info['Price']; $per_day = $rp_sales['Nights']; // sales day price } else { // other sales day, we can skip that continue; } } else { // Even sales day, the sales condition is not acceptable so that we can't apply sales price. $price = $price_info['Price']; // room stock price $per_day = 1; } } else { // normal day, we apply room stock price $price = $price_info['Price']; $per_day = 1; } // check grouping if ($prev_price == $price && $prev_per_day == $per_day) { $prev_day_count++; // } else { // the pair isn't same, the price string will be generated. if ($prev_day_count > 0) { $rp_price_string .= "+ [ " . Tools::money(self::shoushuliao($prev_price, $rpid)) . "/{$prev_per_day}day(s) X {$prev_day_count} ]"; } // $prev_price = $price; $prev_per_day = $per_day; $prev_day_count = 1; } $rp_price += $price_info['Price']; if ($check_0 == '0') { continue; } $check_0 = $price_info['Price']; } // finally we recheck price string. if ($prev_day_count > 0) { $rp_price_string .= "+ [ " . Tools::money(self::shoushuliao($prev_price, $rpid)) . "/{$prev_per_day}day(s) X {$prev_day_count} ]"; } $price_result['OrgPrice'] = $rp_price; $price_result['Price'] = self::shoushuliao($rp_price, $rpid); //$rp_price; $price_result['PriceString'] = "" . trim($rp_price_string, '+') . " = " . Tools::money($price_result['Price']); $price_result['check_0'] = $check_0; //echo $check_0; return $price_result; }