ถามเรื่อง มี 3 Table ที่มี startdate , enddate แต่ต้องการ นำ 3 table นั้นมา สร้างช่วงวันที่ใหม่ มีตัวอย่างด้านในครับ
เขียน รูปแบบ การแสดงผล ออกมาเป็น ตัวอย่างให้ดูด้วยครับ
Date :
2014-11-27 12:20:50
By :
Chaidhanan
จากรูปน่ะครับต้องการได้ผลลัพธ์ดังนี้ โดยรูปแรกจะเป็นช่วงที่คลุม รูป2,3 น่ะครับ
ค่าที่จะได้คือ
2014-10-01 - 2014-10-03 == 100 THB
2014-10-04 - 2014-10-09 == 130 THB
2014-10-10 - 2014-10-11 == 140 THB
2014-10-12 - 2014-10-15 == 135 THB
2014-10-16 - 2014-10-25 == 110 THB
2014-10-26 - 2014-10-29 == 100 THB
2014-10-30 - 2014-11-05 == 175 THB
2014-11-06 - 2014-11-24 == 120 THB
2014-11-25 - 2014-11-28 == 180 THB
2014-11-29 - 2014-11-30 == 120 THB
Date :
2014-11-27 14:30:55
By :
nut_ch31
นี้คือวิธีคิดครับ จากรูป เลย
ประวัติการแก้ไข 2014-11-27 14:34:04
Date :
2014-11-27 14:33:33
By :
nut_ch31
เขียน คิวรี่ ธรรมดาคงไม่ได้ ครับ ต้องเขียน PHP ช่วยด้วย หรือ ใช้ store procedure ไปเลย
Code (PHP)
<?php
$mysql=new mysqli( 'locathost', 'test', 'test', 'test') or die( mysqli_connect_error());
$rs=$mysql->query('
select * from (
select * from table1
union all select * from table2
union all select * from table3
) as tmp order by startdate' );
$old_st=''; $old_en=''; $sum=0;
while($ro=$rs->fetch_assoc()){
if($old_en<$ro['startdate']){
// new startdate
echo $old_st, ' ถึง ' , $old_en , ' == ' , $sum;
$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
$old_st = $ro['startdate'] ; $old_en = $ro['enddate']; $sum=0;
}elseif( $old_en<$ro['enddate']){
$old_en = $ro['enddate'];
}
$sum += $ro['price'];
}
$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
?>
ประวัติการแก้ไข 2014-11-27 15:55:25 2014-11-27 15:55:33
Date :
2014-11-27 15:54:38
By :
Chaidhanan
แก้ บักนิดนึงครับ
13.echo $old_st, ' ถึง ' , $old_en , ' == ' , $sum;
14.$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
15.$old_st = $ro['startdate'] ; $old_en = $ro['enddate']; $sum=0;
แก้เป็น
Code (PHP)
if($old_st>'') {
echo $old_st, ' ถึง ' , $old_en , ' == ' , $sum;
$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
}
$old_st = $ro['startdate'] ; $old_en = $ro['enddate']; $sum=0;
Date :
2014-11-27 16:15:18
By :
Chaidhanan
Code (PHP)
<?php
$mysql=new mysqli( 'locathost', 'test', 'test', 'test') or die( mysqli_connect_error());
$rs=$mysql->query('
select * from (
select * from table1
union all select * from table2
union all select * from table3
) as tmp order by startdate' );
// กำหนดค่าเริ่มต้น สำหรับตรวสอบรายการ
$old_st=''; $old_en=''; $sum=0;
while($ro=$rs->fetch_assoc()){
if($old_en<$ro['startdate']){
// กรณี ข้อมุลเก่า enddate น้อยกว่า รายการใหม่ startdate แสดงว่า ข้อมูลใหม่ อยู่นอกกรอบวันที่เก่า เป็นวันที่ชุดใหม่
// new startdate
if( $old_st > ''){
// ตรวจสอบว่า เป้นรายการเริ่มต้นหรือเปล่า ถ้าเป้นรายการเริ่มต้นให้ผ่านไป ถ้าไม่ใช่เก็บลง ดาต้าเบส
echo $old_st, ' ถึง ' , $old_en , ' == ' , $sum , "<br>"; // show result
$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
}
// กำหนดค่า ของข้อมูลเพื่อใช้ตรวจสอบรายการต่อไป
$old_st = $ro['startdate'] ; $old_en = $ro['enddate']; $sum=0;
}elseif( $old_en<$ro['enddate']){
// กรณีข้อมูลเป้นชุดเดียวกัน เหลือมกันอยู่ ถ้า enddate > old_en ให้เปลี่ยนค่า old_en
$old_en = $ro['enddate'];
}
$sum += $ro['price'];
}
// นำค่าสุดท้ายเข้า ดาต้าเบส
$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
?>
ถ้ายังไม่เข้าใจ ก็ลองทำดูครับ ปริ้นผลที่ได้
แล้วค่อยไล่โค๊ดทีละบันทัด เมื่อผ่านคำสั่ง echo ให้ติ๊กรายการที่กระดาษ
ศึกษาการทำงานของคำสั่งต่างๆ เดี๋ยวก็เข้าใจเอง
ประวัติการแก้ไข 2014-11-28 06:56:59
Date :
2014-11-28 06:55:18
By :
Chaidhanan
ตอบความคิดเห็นที่ : 8 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-28 06:55:18
รายละเอียดของการตอบ ::
ลองแล้วอ่ะครับไม่ได้อ่ะ ลอง echo ตรง
echo $row."-".$old_en."<BR>";
if($old_en<$ro['start_date']){
}
1-
2-2014-10-31
3-2014-10-31
4-2014-10-31
5-2014-10-31
6-2014-11-05
7-2014-11-05
8-2014-11-30
มันก็ไม่มีอะไรเข้าเงื่อนไขเลยอ่ะครับ
รันแล้วได้ดังนี้
insert into t4 (start_date,end_date,price)value('2014-10-01','2014-11-30','410') อย่างเดียวเลยครับ
ประวัติการแก้ไข 2014-11-28 22:28:33
Date :
2014-11-28 22:20:47
By :
nut_ch31
echo $row."-".$old_st."-".$old_en."-".$ro['start_date']."-".$ro['end_date']."<BR>";
เช็คให้มันทุกอันเลยครับ
เอาโค๊ดที่แก้ไขแล้วมาดูหน่อยครับ แก้ไขฟีลด์ ทุกอัน ตรงกับ database หรือยังครับ
ของผมเป็นแค่โค๊ดตัวอย่าง ตัวแปร ต่าง ต้องแก้ให้ตรงกับของจริงนะครับ
ปล.เห็นส่วนที่ผิดแล้วครับ คือ จำนวนฟีล์ด์ต่อตารางไม่เท่ากัน ใช้ select * ไม่ได้ครับ
ต้องเจาะจง ฟีลด์ ไปเลย ทุกตาราง ที่ union กันครับ
ประวัติการแก้ไข 2014-11-28 22:29:10 2014-11-28 22:31:59
Date :
2014-11-28 22:26:31
By :
Chaidhanan
CREATE TABLE `t1` (
`no_id` int(11) NOT NULL auto_increment,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`price` varchar(100) NOT NULL,
PRIMARY KEY (`no_id`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=3 ;
--
-- dump ตาราง `t1`
--
INSERT INTO `t1` VALUES (1, '2014-10-01', '2014-10-31', '100');
INSERT INTO `t1` VALUES (2, '2014-11-01', '2014-11-30', '120');
CREATE TABLE `t2` (
`no_id` int(11) NOT NULL auto_increment,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`price` varchar(100) NOT NULL,
PRIMARY KEY (`no_id`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=3 ;
--
-- dump ตาราง `t2`
--
INSERT INTO `t2` VALUES (1, '2014-10-10', '2014-10-25', '10');
INSERT INTO `t2` VALUES (2, '2014-10-30', '2014-11-05', '25');
CREATE TABLE `t3` (
`no_id` int(11) NOT NULL auto_increment,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`price` varchar(100) NOT NULL,
PRIMARY KEY (`no_id`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=7 ;
--
-- dump ตาราง `t3`
--
INSERT INTO `t3` VALUES (1, '2014-10-04', '2014-10-11', '30');
INSERT INTO `t3` VALUES (2, '2014-10-12', '2014-10-15', '25');
INSERT INTO `t3` VALUES (3, '2014-10-30', '2014-11-05', '40');
INSERT INTO `t3` VALUES (4, '2014-11-25', '2014-11-28', '60');
CREATE TABLE `t4` (
`no_id` int(11) NOT NULL auto_increment,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`price` varchar(100) NOT NULL,
PRIMARY KEY (`no_id`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=21 ;
Code (PHP)
<?php
$mysql=mysql_connect( 'localhost', 'root', 'root') or die( mysqli_connect_error());
mysql_select_db("test");
$sql="select * from (select * from t1 union all select * from t2 union all select * from t3 ) as tmp order by start_date";
$rs=mysql_query($sql);
// กำหนดค่าเริ่มต้น สำหรับตรวสอบรายการ
$old_st='';
$old_en='';
$sum=0;
$row=0;
while($ro=mysql_fetch_array($rs)){
$row++;
echo $row." - ".$old_st." - ".$old_en." - ".$ro['start_date']." - ".$ro['end_date']."<BR>";
if($old_en<$ro['start_date']){
// กรณี ข้อมุลเก่า enddate น้อยกว่า รายการใหม่ startdate แสดงว่า ข้อมูลใหม่ อยู่นอกกรอบวันที่เก่า เป็นวันที่ชุดใหม่
// new startdate
if( $old_st > ''){
// ตรวจสอบว่า เป้นรายการเริ่มต้นหรือเปล่า ถ้าเป้นรายการเริ่มต้นให้ผ่านไป ถ้าไม่ใช่เก็บลง ดาต้าเบส
//echo $old_st. ' ถึง ' . $old_en . ' == ' . $sum . "<br>"; // show result
$sql = " insert into t4 (start_date,end_date,price)value('".$old_st."','".$old_en."','".$sum."')";
echo $sql."<BR>";
mysql_query($sql);
//$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
}
// กำหนดค่า ของข้อมูลเพื่อใช้ตรวจสอบรายการต่อไป
$old_st = $ro['start_date'] ;
$old_en = $ro['end_date'];
$sum=0;
}else if( $old_en<$ro['end_date']){
// กรณีข้อมูลเป้นชุดเดียวกัน เหลือมกันอยู่ ถ้า enddate > old_en ให้เปลี่ยนค่า old_en
$old_en = $ro['end_date'];
}
$sum += $ro['price'];
}
$sql = " insert into t4 (start_date,end_date,price)value('".$old_st."','".$old_en."','".$sum."')";
mysql_query($sql);
echo "===>".$sql."<BR>";
// นำค่าสุดท้ายเข้า ดาต้าเบส
//$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
?>
ขอบพระคุณมากครับ
ประวัติการแก้ไข 2014-11-28 22:38:33
Date :
2014-11-28 22:32:15
By :
nut_ch31
โค๊ดไม่ได้ผิดหรอกครับ ได้ตามความต้องการ ของผม เน้น ของผม 555555
มีอยู่สองประเด็นถ้าผลออกมาผิดก็คือ
1 คนบอกโจทย์ ผิด ไม่ชัดเจน
2 กับ คนทำตีโจทย์ผิด 55555
Date :
2014-11-28 22:47:22
By :
Chaidhanan
จาก result ที่ได้ รายการแรกคลุม ตั้งแต่ 10-01 ถึง 10-31
รายการ 2-4 อยู่ในขอบเขตของรายการที่ 1
รายการที่ 5 ขยาย ขอบเขตไปจนถึงวันที่ 11-05 ที่ขยายเพราะวันที่เริ่มต้น เหลือมกับ รายการแรก
รายการที่ 6 อยู่ในขอบเขตของรายการที่ 5
รายการที่ 7 ขยาย ขอบเขตไปจนถึงวันที่ 11-30 ที่ขยายเพราะวันที่เริ่มต้น เหลือมกับ รายการที่ 5
รายการที่ 8 อยู่ในขอบเขตของรายการที่ 7
สรุปทั้งหมด อยู่ในขอบเขตเดียวกัน insert แค่รายการเดียว 10-01 to 11-30
Date :
2014-11-28 22:57:30
By :
Chaidhanan
ตอบความคิดเห็นที่ : 17 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-28 22:57:30
รายละเอียดของการตอบ ::
ผมต้องการให้ผลลัพธ์ ในตารางสี่เป็นแบบนี้น่ะสิครับ
2014-10-01 - 2014-10-03 == 100 THB
2014-10-04 - 2014-10-09 == 130 THB
2014-10-10 - 2014-10-11 == 140 THB
2014-10-12 - 2014-10-15 == 135 THB
2014-10-16 - 2014-10-25 == 110 THB
2014-10-26 - 2014-10-29 == 100 THB
2014-10-30 - 2014-11-05 == 175 THB
2014-11-06 - 2014-11-24 == 120 THB
2014-11-25 - 2014-11-28 == 180 THB
2014-11-29 - 2014-11-30 == 120 THB
ไม่เคยเขียน report แบบนี้ T T
Date :
2014-11-28 22:59:37
By :
nut_ch31
แล้วที่มันเหลือมกัน ทำอย่างไรครับ ผมว่าต้องแค้ ข้อมูลให้ถูกต้องก่อน
เป็น format เดียวกันนะครับ ถึงจะใส่โค๊ดได้
ถ้ารวมด้วยมือได้ ก็เขียนโค๊ดได้ครับ
แต่รายการแรก จะทำอย่างไร ครับ เริ่ม 10-01 ถึง 10-31 มันคลุมตั้งหลายวัน 5555
Date :
2014-11-28 23:06:02
By :
Chaidhanan
Code (PHP)
<?php
$mysql=mysql_connect( 'localhost', 'root', 'password3') or die( mysqli_connect_error());
mysql_select_db("test");
$sql="select start_date,end_date,price from (select start_date,end_date,price from t1 union all select start_date,end_date,price from t2 union all select start_date,end_date,price from t3 ) as tmp order by start_date";
$rs=mysql_query($sql);
// กำหนดค่าเริ่มต้น สำหรับตรวสอบรายการ
$old_st='';
$old_en='';
$sum=0;
$row=0;
while($ro=mysql_fetch_array($rs)){
$row++;
echo $row." - ".$old_st." - ".$old_en." - ".$ro['start_date']." - ".$ro['end_date']." - ".$sum."<BR>";
if($old_st<$ro['start_date']){
if( $old_st > ''){
$s="SELECT DATE_ADD('".$ro["start_date"]."', INTERVAL -1 DAY) as s_date";
$q=mysql_query($s);
$r=mysql_fetch_array($q);
$sql = " insert into t4 (start_date,end_date,price)value('".$old_st."','".$r["s_date"]."','".$sum."')";
echo $sql."<BR>";
mysql_query($sql);
$old_st=$ro["start_date"];
}
$old_st = $ro['start_date'] ;
$old_en = $ro['end_date'];
$sum=0;
}else if( $old_en<$ro['end_date']){
$sql = " insert into t4 (start_date,end_date,price)value('".$ro['start_date']."','".$r["end_date"]."','".$sum."')";
echo $sql."<BR>";
mysql_query($sql);
$old_en = $ro['end_date'];
}
$sum += $ro['price'];
}
$sql = " insert into t4 (start_date,end_date,price)value('".$old_st."','".$old_en."','".$sum."')";
mysql_query($sql);
echo "===>".$sql."<BR>";
// นำค่าสุดท้ายเข้า ดาต้าเบส
//$mysql->query($sql = " insert into table4 set startdate='$old_st', enddate='$old_en', price=$sum" ) or die ( $sql . "<br>\n" . $mysql->error);
?>
จากโค้ดนี้เริ่มใกล้เคียงความจริงล่ะพี่ ยังติดอยู่บางช่วงเท่านั้นเอง ผลที่ได้ตอนนี้คือ
insert into t4 (start_date,end_date,price)value('2014-10-01','2014-10-03','100')
insert into t4 (start_date,end_date,price)value('2014-10-04','2014-10-09','30')
insert into t4 (start_date,end_date,price)value('2014-10-10','2014-10-11','10')
insert into t4 (start_date,end_date,price)value('2014-10-12','2014-10-29','25')
insert into t4 (start_date,end_date,price)value('2014-10-30','2014-10-31','65')
insert into t4 (start_date,end_date,price)value('2014-11-01','2014-11-24','120')
===> insert into t4 (start_date,end_date,price)value('2014-11-25','2014-11-28','60')
ที่ต้องการ อย่าเพิ่งไปมองเงินน่ะครับ เงินมันหาไม่ยาก
2014-10-01 - 2014-10-03 == 100 THB
2014-10-04 - 2014-10-09 == 130 THB
2014-10-10 - 2014-10-11 == 140 THB
2014-10-12 - 2014-10-15 == 135 THB
2014-10-16 - 2014-10-25 == 110 THB
2014-10-26 - 2014-10-29 == 100 THB
2014-10-30 - 2014-11-05 == 175 THB
2014-11-06 - 2014-11-24 == 120 THB
2014-11-25 - 2014-11-28 == 180 THB
2014-11-29 - 2014-11-30 == 120 THB
Date :
2014-11-28 23:31:29
By :
nut_ch31
Code (PHP)
<?php session_start();
Include("connection/config.php");
//$hotel_id = $_GET["hotel_id"];
$del="delete from generate_rate1 where hotel_id='".$hotel_id."'";
mysql_query($del);
$sql="select * from contract_rate where hotel_id='".$hotel_id."' order by start_date,room_id";
$query=mysql_query($sql);
while($result=mysql_fetch_array($query)){
if($result["price_trp"]=="" || $result["price_trp"]==0){
$price_trp_sum = $result["price_twn"] + $result["price_exb"];
}else{
$price_trp_sum = $result["price_trp"];
}
//case start date peak between start_date and end_date and end date peak not between start_date and end_date
$sql_case1="select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case1=mysql_query($sql_case1);
$result_case1=mysql_fetch_array($query_case1);
$num_case1=mysql_num_rows($query_case1);
if($num_case1 == 1){
$price_sgl=$result["price_sgl"] + $result_case1["price"];
$price_twn=$result["price_twn"] + $result_case1["price"];
$price_trp=$price_trp_sum + $result_case1["price"];
$price_exb=$result["price_exb"] + $result_case1["price"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
$start_date = $result_case1["start_date"];
$end_date = $result["end_date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case1");
$sql_case1_item1 = "select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case1_item1 = mysql_query($sql_case1_item1);
$num_case1_item1 = mysql_num_rows($query_case1_item1);
if($num_case1_item1 == 0){
$sql_case1_item2 = "select * from contract_rate_peak where start_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."'";
$query_case1_item2 = mysql_query($sql_case1_item2);
$num_case1_item2 = mysql_num_rows($query_case1_item2);
if($num_case1_item2 == 0){
$start_date = $result["start_date"];
$select_date="SELECT ADDDATE('".$result_case1["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date=$result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case1-1");
}//num case1 item2
}//num case1 item1
}//num case1
//case start date peak not between start_date and end_date and end date peak between start_date and end_date
$sql_case2="select * from contract_rate_peak where start_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case2=mysql_query($sql_case2);
$result_case2=mysql_fetch_array($query_case2);
$num_case2=mysql_num_rows($query_case2);
if($num_case2 == 1){
$price_sgl=$result["price_sgl"] + $result_case2["price"];
$price_twn=$result["price_twn"] + $result_case2["price"];
$price_trp=$price_trp_sum + $result_case2["price"];
$price_exb=$result["price_exb"] + $result_case2["price"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
$start_date = $result["start_date"];
$end_date = $result_case2["end_date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case2");
$sql_case2_item1 = "select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."'";
$query_case2_item1 = mysql_query($sql_case2_item1);
$num_case2_item1 = mysql_num_rows($query_case2_item1);
if($num_case2_item1 == 0){
$select_date="SELECT ADDDATE('".$result_case2["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
$sql_check="select * from generate_rate1 where start_date between '".$start_date."' and '".$end_date."' and hotel_id='".$result["hotel_id"]."' and room_id='".$result["room_id"]."' ";
$query_check=mysql_query($sql_check);
$result_check=mysql_fetch_array($query_check);
$num_check=mysql_num_rows($query_check);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_check == 0){
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case2-1");
}else{
$select_date="SELECT ADDDATE('".$result_check["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case2-2");
}
}//case2 item1
}//num case2
//case3 start date peak between start date and end date and end_date peak between start date and end date
$sql_case3="select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date ";
$query_case3=mysql_query($sql_case3);
$row=0;
while($result_case3=mysql_fetch_array($query_case3)){
$row++;
if($row == 1){
if($result["start_date"] == $result_case3["start_date"]){
$start_date = $result["start_date"];
$end_date = $result_case3["end_date"];
$price_sgl=$result["price_sgl"] + $result_case3["price"];
$price_twn=$result["price_twn"] + $result_case3["price"];
$price_trp=$price_trp_sum + $result_case3["price"];
$price_exb=$result["price_exb"] + $result_case3["price"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3");
$sql_case3_item1="select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit 1,1 ";
$query_case3_item1=mysql_query($sql_case3_item1);
$result_case3_item1=mysql_fetch_array($query_case3_item1);
$num_case3_item1=mysql_num_rows($query_case3_item1);
if($num_case3_item1 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-1");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item1["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-2");
}
}else{//end start date peak == start date rate row 1
$start_date = $result["start_date"];
$select_date="SELECT ADDDATE('".$result_case3["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
$sql_check = "select * from generate_rate1 where end_date between '".$start_date."' and '".$end_date."' and hotel_id='".$result["hotel_id"]."' and room_id='".$result["room_id"]."' ";
$query_check = mysql_query($sql_check);
$result_check = mysql_fetch_array($query_check);
$num_check = mysql_num_rows($query_check);
if($num_check == 0){
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-3");
}else{
$select_date="SELECT ADDDATE('".$result_check["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date=$result_date["date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-4");
}
$start_date = $result_case3["start_date"];
$end_date = $result_case3["end_date"];
$price_sgl=$result["price_sgl"] + $result_case3["price"];
$price_twn=$result["price_twn"] + $result_case3["price"];
$price_trp=$price_trp_sum + $result_case3["price"];
$price_exb=$result["price_exb"] + $result_case3["price"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-5");
$sql_case3_item2="select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit 1,1 ";
$query_case3_item2=mysql_query($sql_case3_item2);
$result_case3_item2=mysql_fetch_array($query_case3_item2);
$num_case3_item2=mysql_num_rows($query_case3_item2);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_case3_item2 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-6");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item2["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-7");
}
}////end start date peak != start date rate row 1
}else{//end row 1
$start_date=$result_case3["start_date"];
$end_date=$result_case3["end_date"];
$price_sgl=$result["price_sgl"] + $result_case3["price"];
$price_twn=$result["price_twn"] + $result_case3["price"];
$price_trp=$price_trp_sum + $result_case3["price"];
$price_exb=$result["price_exb"] + $result_case3["price"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-8");
$sql_case3_item3="select * from contract_rate_peak where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit ".$row.",1 ";
$query_case3_item3=mysql_query($sql_case3_item3);
$result_case3_item3=mysql_fetch_array($query_case3_item3);
$num_case3_item3=mysql_num_rows($query_case3_item3);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_case3_item3 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-9");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item3["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-10");
}
}//end row > 1
}//end while case3
//case4 num == 0 start date peak between start date and end date or end_date peak between start date and end date
$sql_case4="select * from contract_rate_peak where hotel_id='".$result["hotel_id"]."' and ((start_date between '".$result["start_date"]."' and '".$result["end_date"]."') or (end_date between '".$result["start_date"]."' and '".$result["end_date"]."')) ";
$query_case4=mysql_query($sql_case4);
$num_case4=mysql_num_rows($query_case4);
if($num_case4 == 0){
$start_date = $result["start_date"];
$end_date = $result["end_date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$price_trp_sum;
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case3-11");
}
}//end while
///-----++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ COMPLUSORY +++++++++++++++++++++++++++++++++++++++---//
echo "<BR><BR>";
$del="delete from report_nc where hotel_id='".$hotel_id."'";
mysql_query($del);
$sql="select * from generate_rate1 where hotel_id='".$hotel_id."' order by start_date,room_id";
$query=mysql_query($sql);
while($result=mysql_fetch_array($query)){
//case start date peak between start_date and end_date and end date peak not between start_date and end_date
$sql_case1="select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case1=mysql_query($sql_case1);
$result_case1=mysql_fetch_array($query_case1);
$num_case1=mysql_num_rows($query_case1);
if($num_case1 == 1){
$price_sgl_complus = 1*$result_case1["price"];
$price_twn_complus = 2*$result_case1["price"];
$price_trp_complus = 3*$result_case1["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
$start_date = $result_case1["start_date"];
$end_date = $result["end_date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus1");
$sql_case1_item1 = "select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case1_item1 = mysql_query($sql_case1_item1);
$num_case1_item1 = mysql_num_rows($query_case1_item1);
if($num_case1_item1 == 0){
$sql_case1_item2 = "select * from contract_rate_compulsory where start_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."'";
$query_case1_item2 = mysql_query($sql_case1_item2);
$num_case1_item2 = mysql_num_rows($query_case1_item2);
if($num_case1_item2 == 0){
$start_date = $result["start_date"];
$select_date="SELECT ADDDATE('".$result_case1["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date=$result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus1-1");
}//num case1 item2
}//num case1 item1
}//num case1
//case start date peak not between start_date and end_date and end date peak between start_date and end_date
$sql_case2="select * from contract_rate_compulsory where start_date not between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' ";
$query_case2=mysql_query($sql_case2);
$result_case2=mysql_fetch_array($query_case2);
$num_case2=mysql_num_rows($query_case2);
if($num_case2 == 1){
$price_sgl_complus = 1*$result_case2["price"];
$price_twn_complus = 2*$result_case2["price"];
$price_trp_complus = 3*$result_case2["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
$start_date = $result["start_date"];
$end_date = $result_case2["end_date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus2");
$sql_case2_item1 = "select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."'";
$query_case2_item1 = mysql_query($sql_case2_item1);
$num_case2_item1 = mysql_num_rows($query_case2_item1);
if($num_case2_item1 == 0){
$select_date="SELECT ADDDATE('".$result_case2["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
$sql_check="select * from report_nc where start_date between '".$start_date."' and '".$end_date."' and hotel_id='".$result["hotel_id"]."' and room_id='".$result["room_id"]."' ";
$query_check=mysql_query($sql_check);
$result_check=mysql_fetch_array($query_check);
$num_check=mysql_num_rows($query_check);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_check == 0){
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus2-1");
}else{
$select_date="SELECT ADDDATE('".$result_check["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus2-2");
}
}//case2 item1
}//num case2
//case3 start date peak between start date and end date and end_date peak between start date and end date
$sql_case3="select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and end_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date ";
$query_case3=mysql_query($sql_case3);
$row=0;
while($result_case3=mysql_fetch_array($query_case3)){
$row++;
if($row == 1){
if($result["start_date"] == $result_case3["start_date"]){
$start_date = $result["start_date"];
$end_date = $result_case3["end_date"];
$price_sgl_complus = 1*$result_case3["price"];
$price_twn_complus = 2*$result_case3["price"];
$price_trp_complus = 3*$result_case3["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3");
$sql_case3_item1="select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit 1,1 ";
$query_case3_item1=mysql_query($sql_case3_item1);
$result_case3_item1=mysql_fetch_array($query_case3_item1);
$num_case3_item1=mysql_num_rows($query_case3_item1);
if($num_case3_item1 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-1");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item1["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-2");
}
}else{//end start date peak == start date rate row 1
$start_date = $result["start_date"];
$select_date="SELECT ADDDATE('".$result_case3["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
$sql_check = "select * from report_nc where end_date between '".$start_date."' and '".$end_date."' and hotel_id='".$result["hotel_id"]."' and room_id='".$result["room_id"]."' ";
$query_check = mysql_query($sql_check);
$result_check = mysql_fetch_array($query_check);
$num_check = mysql_num_rows($query_check);
if($num_check == 0){
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-3");
}else{
$select_date="SELECT ADDDATE('".$result_check["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date=$result_date["date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-4");
}
$start_date = $result_case3["start_date"];
$end_date = $result_case3["end_date"];
$price_sgl_complus = 1*$result_case3["price"];
$price_twn_complus = 2*$result_case3["price"];
$price_trp_complus = 3*$result_case3["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-5");
$sql_case3_item2="select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit 1,1 ";
$query_case3_item2=mysql_query($sql_case3_item2);
$result_case3_item2=mysql_fetch_array($query_case3_item2);
$num_case3_item2=mysql_num_rows($query_case3_item2);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_case3_item2 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-6");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item2["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-7");
}
}////end start date peak != start date rate row 1
}else{//end row 1
$start_date=$result_case3["start_date"];
$end_date=$result_case3["end_date"];
$price_sgl_complus = 1*$result_case3["price"];
$price_twn_complus = 2*$result_case3["price"];
$price_trp_complus = 3*$result_case3["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-8");
$sql_case3_item3="select * from contract_rate_compulsory where start_date between '".$result["start_date"]."' and '".$result["end_date"]."' and hotel_id='".$result["hotel_id"]."' order by start_date limit ".$row.",1 ";
$query_case3_item3=mysql_query($sql_case3_item3);
$result_case3_item3=mysql_fetch_array($query_case3_item3);
$num_case3_item3=mysql_num_rows($query_case3_item3);
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
if($num_case3_item3 == 0){
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$end_date = $result["end_date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-9");
}else{
$select_date="SELECT ADDDATE('".$result_case3["end_date"]."', INTERVAL +1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$start_date = $result_date["date"];
$select_date="SELECT ADDDATE('".$result_case3_item3["start_date"]."', INTERVAL -1 DAY) as date";
$query_date=mysql_query($select_date);
$result_date=mysql_fetch_array($query_date);
$end_date = $result_date["date"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-10");
}
}//end row > 1
}//end while case3
//case4 num == 0 start date peak between start date and end date or end_date peak between start date and end date
$sql_case4="select * from contract_rate_compulsory where hotel_id='".$result["hotel_id"]."' and ((start_date between '".$result["start_date"]."' and '".$result["end_date"]."') or (end_date between '".$result["start_date"]."' and '".$result["end_date"]."')) ";
$query_case4=mysql_query($sql_case4);
$num_case4=mysql_num_rows($query_case4);
if($num_case4 == 0){
$sql_case5="select * from contract_rate_compulsory where hotel_id='".$result["hotel_id"]."' and '".$result["start_date"]."' between start_date and end_date and '".$result["end_date"]."' between start_date and end_date ";
$query_case5=mysql_query($sql_case5);
$result_case5=mysql_fetch_array($query_case5);
$num_case5=mysql_num_rows($query_case5);
$start_date = $result["start_date"];
$end_date = $result["end_date"];
if($num_case5 == 1){
$price_sgl_complus = 1*$result_case5["price"];
$price_twn_complus = 2*$result_case5["price"];
$price_trp_complus = 3*$result_case5["price"];
$price_sgl=$result["price_sgl"] + $price_sgl_complus;
$price_twn=$result["price_twn"] + $price_twn_complus;
$price_trp=$result["price_trp"] + $price_trp_complus;
$price_exb=$result["price_exb"] + $price_trp_complus;
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din="Incl.";
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-11");
}else{
$price_sgl=$result["price_sgl"];
$price_twn=$result["price_twn"];
$price_trp=$result["price_trp"];
$price_exb=$result["price_exb"];
$meals_abf=$result["meals_abf"];
$meals_lun=$result["meals_lun"];
$meals_din=$result["meals_din"];
insert_log_report_report_nc($hotel_id,$result["room_id"],$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,"case-complus3-11");
}
}
}//end while
function insert_log_report($hotel_id,$room_id,$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,$setup){
if($start_date <= $end_date){
$int = "insert generate_rate1 (hotel_id,room_id,price_sgl,price_twn,price_trp,price_exb,start_date,end_date,meals_abf,meals_lun,meals_din,log_user ,date_create,time_create)value('".$hotel_id."','".$room_id."','".$price_sgl."','".$price_twn."','".$price_trp."','".$price_exb."','".$start_date."','".$end_date."','".$meals_abf."','".$meals_lun."','".$meals_din."','".$_COOKIE["user_id"]."',curdate(),curtime())";
echo $int."======>".$setup."<BR>";
mysql_query($int);
}
}
function insert_log_report_report_nc($hotel_id,$room_id,$price_sgl,$price_twn,$price_trp,$price_exb,$start_date,$end_date,$meals_abf,$meals_lun,$meals_din,$setup){
if($start_date <= $end_date){
$int = "insert report_nc (hotel_id,room_id,price_sgl,price_twn,price_trp,price_exb,start_date,end_date,meals_abf,meals_lun,meals_din,log_user ,date_create,time_create)value('".$hotel_id."','".$room_id."','".$price_sgl."','".$price_twn."','".$price_trp."','".$price_exb."','".$start_date."','".$end_date."','".$meals_abf."','".$meals_lun."','".$meals_din."','".$_COOKIE["user_id"]."',curdate(),curtime())";
echo $int."======>".$setup."<BR>";
mysql_query($int);
}
}
?>
เขียนเสร็จแล้วน่ะครับ
ขอบอกว่า ยาวมาก เพราะผม เขียนแบบซับซ้อนไม่เป็น
แต่เอาไปใช้งานได้น่ะครับ :_0
Date :
2014-12-09 14:50:56
By :
nut_ch31
Load balance : Server 00