Private Sub INT_Data()
Dim rs As ADODB.Recordset
Dim sSql As String, sEmp As String
On Error GoTo msgErr:
If cboCust_type.Text <> "" Then
sSql = "SELECT DISTINCT b.SEQ, f.CUST_NAME,b.REF_NO, g.GOODS_ID, g.QTY,b.AGENT_NAME, f.TEL2, f.AMPHUR1,b.CUST_TYPE, " & _
" e.EMP_NAME,b.time_confirm,b.in_time,b.out_time,b.staff_in,b.job_num,b.output,b.descr,b.problem,b.sale_inform,a.pl_no,nvl(b.amount,0)amount,to_char(a.pl_date,'dd/mm/yyyy')pl_date " & _
" FROM SER_PLAN_MASTER a inner join SER_PLAN_DETAIL b On a.pl_no=b.pl_no " & _
" left outer join SER_JOB c On b.ref_no = c.job_no " & _
" left outer join SER_PLAN_EMP d On b.pl_no=d.pl_no " & _
" left outer join SER_EMPLOYEE e On d.emp_id = e.emp_id " & _
" left outer join SER_CUSTOMER f On c.cust_no = f.cust_no " & _
" left outer join SER_JOB_DETAIL g On c.job_no = g.job_no " & _
" Where nvl(a.pl_status,'N')='N' and a.pl_date between to_date('" & Left(dtpDate1, 6) & Year(dtpDate1) & "','dd/mm/yyyy') and to_date('" & Left(dtpDate2, 6) & Year(dtpDate2) & "','dd/mm/yyyy')" & _
" and b.cust_type = '" & cboCust_type.Text & "'"
Else 'All
sSql = "SELECT DISTINCT b.SEQ, f.CUST_NAME,b.REF_NO, g.GOODS_ID, g.QTY,b.AGENT_NAME, f.TEL2, f.AMPHUR1,b.CUST_TYPE, " & _
" e.EMP_NAME,b.time_confirm,b.in_time,b.out_time,b.staff_in,b.job_num,b.output,b.descr,b.problem,b.sale_inform,a.pl_no,nvl(b.amount,0)amount,to_char(a.pl_date,'dd/mm/yyyy')pl_date " & _
" FROM SER_PLAN_MASTER a inner join SER_PLAN_DETAIL b On a.pl_no=b.pl_no " & _
" left outer join SER_JOB c On b.ref_no = c.job_no " & _
" left outer join SER_PLAN_EMP d On b.pl_no=d.pl_no " & _
" left outer join SER_EMPLOYEE e On d.emp_id = e.emp_id " & _
" left outer join SER_CUSTOMER f On c.cust_no = f.cust_no " & _
" left outer join SER_JOB_DETAIL g On c.job_no = g.job_no " & _
" Where nvl(a.pl_status,'N')='N' and a.pl_date between to_date('" & Left(dtpDate1, 6) & Year(dtpDate1) & "','dd/mm/yyyy') and to_date('" & Left(dtpDate2, 6) & Year(dtpDate2) & "','dd/mm/yyyy')"
End If
If cboResult.Text <> "" Then
If cboResult.Text = "จบ" Then sSql = sSql & " and b.output in ('สั่งผลิต','เสนอราคา')"
If cboResult.Text = "ไม่จบ" Then sSql = sSql & " and nvl(b.output,'ไม่จบ') in ('ไม่จบ','เข้าอีก')"
End If
If Left(sSiteCode, 1) = "b" Then
sSql = sSql & " And a.pl_type = '" & Cbo_TrimString(cboPL_type) & "'"
End If
sSql = sSql & " And a.site_code = '" & Left(sSiteCode, 1) & "'"
sSql = sSql & " ORDER BY a.pl_no,b.seq"
'Debug.Print sSql ให้ได้ค่า sSql แบบนำมาต่อกันในรูปแบบของ PHP ครับ
$strSQL = "
SELECT DISTINCT b.SEQ, f.CUST_NAME,b.REF_NO, g.GOODS_ID, g.QTY,b.AGENT_NAME, f.TEL2, f.AMPHUR1,b.CUST_TYPE,
e.EMP_NAME,b.time_confirm,b.in_time,b.out_time,b.staff_in,b.job_num,b.output,b.descr,b.problem,b.sale_inform,a.pl_no,nvl(b.amount,0)amount,to_char(a.pl_date,'dd/mm/yyyy')pl_date
FROM SER_PLAN_MASTER a inner join SER_PLAN_DETAIL b On a.pl_no=b.pl_no
left outer join SER_JOB c On b.ref_no = c.job_no
";
if($_GET["listType"]=="ORC" && $_GET["custType"]!="All"){
echo "case1";
$strSQL = "SELECT DISTINCT b.SEQ,f.CUST_NAME,b.REF_NO,b.evl_no,g.GOODS_ID, g.QTY,b.fg_status, f.TEL2, f.AMPHUR1,b.CUST_TYPE,i.cust_name cust_name1, a.car_driver,b.time_confirm,b.in_time,b.out_time,b.job_num,b.output,nvl(d.grand_total,0)evl_amount,b.descr,b.problem,b.fixed_detail,a.pl_no,nvl(b.amount,0)amount ,i.tel2 tel,i.amphur1 amphur,h.goods_id pm_fg,nvl(c.warranty,'-')warranty,c.cust_no,h.cust_no cust_no_pm,nvl(g.sc_no,'-')sc_no,to_char(a.pl_date,'dd/mm/yyyy')pl_date FROM SER_PLAN_MASTER a
inner join SER_PLAN_DETAIL b on a.pl_no=b.pl_no
left outer join SER_JOB c on b.ref_no=c.job_no
left outer join SER_EVALUATION_MASTER d on b.evl_no=d.evl_no
left outer join SER_CUSTOMER f on c.Cust_No=f.cust_no
left join SER_JOB_DETAIL g on c.job_no=g.job_no
left outer join SER_PM_MASTER h on b.ref_no=h.pm_no
left outer join SER_CUSTOMER i on h.cust_no=i.cust_no
Where nvl(a.pl_status,'N')='N' and a.pl_type='".$_GET["listType"]."' and to_char(a.pl_date,'yyyy/mm/dd')between '".$_GET["dateStart"]."' and '".$_GET["dateEnd"]."' and b.cust_Type='".$_GET["custType"]."' ORDER BY a.pl_no ASC ";
}else {
echo "case2";
$strSQL = "SELECT DISTINCT b.SEQ,f.CUST_NAME,b.REF_NO,b.evl_no,g.GOODS_ID, g.QTY,b.fg_status, f.TEL2, f.AMPHUR1,b.CUST_TYPE,i.cust_name cust_name1, a.car_driver,b.time_confirm,b.in_time,b.out_time,b.job_num,b.output,nvl(d.grand_total,0)evl_amount,b.descr,b.problem,b.fixed_detail,a.pl_no,nvl(b.amount,0)amount ,i.tel2 tel,i.amphur1 amphur,h.goods_id pm_fg,nvl(c.warranty,'-')warranty,c.cust_no,h.cust_no cust_no_pm,nvl(g.sc_no,'-')sc_no,to_char(a.pl_date,'dd/mm/yyyy')pl_date FROM SER_PLAN_MASTER a inner join SER_PLAN_DETAIL b on a.pl_no=b.pl_no left outer join SER_JOB c on b.ref_no=c.job_no left outer join SER_EVALUATION_MASTER d on b.evl_no=d.evl_no left outer join SER_CUSTOMER f on c.Cust_No=f.cust_no left join SER_JOB_DETAIL g on c.job_no=g.job_no left outer join SER_PM_MASTER h on b.ref_no=h.pm_no left outer join SER_CUSTOMER i on h.cust_no=i.cust_no Where nvl(a.pl_status,'N')='N' and to_char(a.pl_date,'yyyy/mm/dd')between '".$_GET["dateStart"]."' and '".$_GET["dateEnd"]."' ORDER BY a.pl_no ASC ";
}
///If cboResult.Text <> "" Then
/// If cboResult.Text = "จบ" Then sSql = sSql & " and b.output in ('สั่งผลิต','เสนอราคา')"
/// If cboResult.Text = "ไม่จบ" Then sSql = sSql & " and nvl(b.output,'ไม่จบ') in ('ไม่จบ','เข้าอีก')"
/// End If
// 1.ปัญหาจะนำ $strSQL ด้านล่างที่อยู่ในเงื่อนไขไปต่อกับ $strSQL ด้านบนครับ แต่มันยัง error จะเขียนโค้ดอย่างไรครับ
If($_GET["jobStatus"]!="All" {
If($_GET["jobStatus"]=="จบ" { $strSQL = $strSQL & " and b.output in ('สั่งผลิต','เสนอราคา')";{
If($_GET["jobStatus"]=="ไม่จบ" { $strSQL = $strSQL & " and nvl(b.output,'ไม่จบ') in ('ไม่จบ','เข้าอีก')";{
}