 |
ผมจะออกเอกสารการลาอะครับทีนี้เอกสารที่ว่ามันมีการคำนวณค่าก่อนหน้าแล้วนำมาบวกกันอะครับ |
|
 |
|
|
 |
 |
|
มันก็อย่ที่การออกแบบฐานข้อมูลอีกนั่นแหล่ะ
คงต้องเอาฐานข้อมูลมาดู เพื่อจะได้เขียน SQL ให้ตรงกับที่ต้องการ
|
 |
 |
 |
 |
Date :
2012-05-22 01:30:53 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำเป็น Quota ในตาราง Budget ดีกว่าครับ เก็บว่าในแต่ล่ะปีได้ทำการลาไปแล้วกี่วัน
|
 |
 |
 |
 |
Date :
2012-05-22 06:16:24 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามคุณวินว่าเลยครับ และขอดูตารางข้อมูลด้วย
|
 |
 |
 |
 |
Date :
2012-05-22 07:28:11 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้คือรูปฟอร์มที่ต้องการให้คำนวณ กับ ฐานข้อมูลนะครับ
ที่มันผิดตอนนี้ก็คือ ทุกเอกสารที่เข้ามา ช่องลามาแล้วมันจะเท่ากันทุกเอกสารอะครับ


Code (PHP)
<?php
/////////// หาค่าวันรวมทั้งหมดที่เคยลามา ////////////
//$strSQL = "select * , sum(dayno) as total from absence WHERE employee_id =" . $_SESSION["employee_id"];
$strSQL = "select * , sum(dayno) as total from absence WHERE absence_no ='$document_id'";
$strSQL1 = $strSQL." "."and type_no = '".$row['type_no']."' and status='A' ";
//echo "strSQL1===".$strSQL1."<br>";
//exit;
$objQuery = mysql_query($strSQL1) or die (mysql_error () );
$objResult = mysql_fetch_array($objQuery);
$total = $objResult["total"]; // วันลาของเก่า
///////////// ค่าวันลาครั้งล่าสุดที่ทำการลามา ///////////////
$strSQL = "select * from absence WHERE absence_no ='$document_id'";
$strSQL1 = $strSQL." "."and type_no = '".$row['type_no']."' ";
//echo "strSQL1===".$strSQL1."<br>";
//exit;
$objQuery = mysql_query($strSQL1) or die (mysql_error () );
$objResult = mysql_fetch_array($objQuery);
$dayno =$row["dayno"];
$result_day = $total+$dayno; /// ผลการลารวมของครั้งเก่า + ครั้งใหม่
|
ประวัติการแก้ไข 2012-05-22 07:58:13
 |
 |
 |
 |
Date :
2012-05-22 07:57:02 |
By :
phongphisut |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แสดงว่าตอนนี้คำนวณวันที่ลาได้แล้วใช่มั๊ย 2012-05-01 <-> 2012-05-08 = 5วัน (1 พ.ค. วันแรงงาน , 5-6 พ.ค. เสาร์ อาทิตย์)
Code (PHP)
select sum(dayno) as total_absence, type_no ,employee_id , "รอบที่ 1"
from absence
where employee_id='123456' and
( (year(stdate) >= '2011' and year(stdate) <= '2012' ) and ( month(stdate) >= '10' and month(stdate) <= '03' ) and (day(stdate) >= '01' and day(stdate) <= '31') ) and
( (year(endate) >= '2011' and year(endate) <= '2012' ) and ( month(endate) >= '01' and month(endate) <= '06' ) and (day(endate) >= '01' and day(endate) <= '31'))
group by employee_id , type_no
select sum(dayno) as total_absence, type_no ,employee_id , "รอบที่ 2"
from absence
where employee_id='123456' and
( year(stdate) == '2012' and ( month(stdate) >= '04' and month(stdate) <= '09' ) and (day(stdate) >= '01' and day(stdate) <= '31') ) and
( year(endate) == '2012' and ( month(endate) >= '04' and month(endate) <= '09' ) and (day(endate) >= '01' and day(endate) <= '31') )
group by employee_id , type_no
|
 |
 |
 |
 |
Date :
2012-05-22 10:00:25 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
select sum(dayno) as total_absence, type_no ,employee_id ,count(*) as ab_number
from absence
where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
order by a_id
limit (ab_number - 1)
|
ประวัติการแก้ไข 2012-05-22 12:11:31
 |
 |
 |
 |
Date :
2012-05-22 11:10:02 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การลาป่วยใน1ปีงบประมาณแบ่งออกเป็น 2 ช่วง
ตัวอย่าง
รอบที่ 1ตุลาคม 2552 - มีนาคม 2553 ลาป่วยได้จำนวน 10 ครั้ง 23 วัน
รอบที่ 2 เมษายน 2553 - กันยายน 2553 ลาป่วยได้จำนวน 10 ครั้ง 23 วัน
|
 |
 |
 |
 |
Date :
2012-05-22 11:30:11 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทดลองคำสั่ง SQL (No.9) กับข้อมูลจำนวนมากๆหน่อยน่ะครับ (หมายถึงให้ป้อนข้อมูลลงฐานฯ มากๆหน่อย)
|
 |
 |
 |
 |
Date :
2012-05-22 11:32:37 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. count(*) as ab_number นับจำนวนทั้งหมดว่ามีใบลากี่ใบ
สมมุตนับได้ 3 ใบ ฉะนั้น ab_number =3
2. order by a_id ให้เรียงลำดับใบลาจากน้อยไปมาก
3. limit (ab_number - 1) กำหนดให้เอามาแค่ 2 ใบ (3-1) แต่จากข้อ (2.) จะเอามาแค่ใบที่ 1และ 2 เท่านั้น
ทดสอบหรือยังครับ
ช่วย export ฐานข้อมูลมาทดลองกันหน่อยครับ ผมเองก็อยากลองเหมือนกัน
|
 |
 |
 |
 |
Date :
2012-05-22 13:28:12 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าโค้ดชุด No.9 ไม่ผ่านก็ลองชุดนี้น่ะครับ
Code (PHP)
select sum(dayno) as total_absence, type_no ,employee_id ,
(select count(*) from absence where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
) as ab_number
from absence
where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
order by a_id
limit (ab_number - 1)
|
 |
 |
 |
 |
Date :
2012-05-22 13:32:28 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|