<?php
   switch($_REQUEST[mode]) {
    case "hapus":
         if(RetRstField("SELECT fnid FROM txdelivery_order_hdr WHERE fttracking_code='{$_REQUEST['fttracking_code']}'")) {
            echo "<script>
                alert('data ini tidak dapat di delete karena sudah digunakan ...');
                window.history.back();
            </script>";   
            die("");            
         }

    break;   	
   }
	
   function SaveData() {
       global $objAxpDB;
        $strSQL=array();
        $objAxpDB->Allow_Save(false);
		if($_REQUEST[mode]=="simpan") {
			if($_REQUEST['fntype']=="single")
			{


					if($_FILES['photos']['name']==""){
						$photoname="";
					}
					else{
						$photoname=$_REQUEST['fttracking_code'].".jpg";
					}
                
				$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
				$fdend_date=getDateYmd($_REQUEST['fdend_date']);
				$fdqc_date=getDateYmd($_REQUEST['fdqc_date']);
				$fdselesai_date=getDateYmd($_REQUEST['fdselesai_date']);	
				$fdtrans_date=getDateYmd($_REQUEST['fdtrans_date']);
				$strSQL["INSERT Tracking Support"][]="INSERT INTO txtracking_det(fttracking_code	,fdtrans_date,ftproject_code,ftusername,ftket_customer,ftket_internal,fnstatus,ftstatus_customer,ftproject_category_name,fdproses_date,fdend_date,fdqc_date,fdselesai_date,ftimg_bugs, ftsupport_code, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
															 VALUES('{$_REQUEST['fttracking_code']}','{$fdtrans_date}','{$_REQUEST['ftproject_code']}','{$_REQUEST['ftusername']}','{$_REQUEST['ftket_customer']}','{$_REQUEST['ftket_internal']}','{$_REQUEST['fnstatus']}','{$_REQUEST['ftstatus_customer']}','{$_REQUEST['ftcreated_user']}','{$fdproses_date}','{$fdend_date}','{$fdqc_date}','{$fdselesai_date}','{$photoname}','{$_REQUEST['ftsupport_code']}','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now());";
				$strSQL['Insert Project no'][]="INSERT INTO txtracking_hdr(ftproject_code,
							  fttracking_code, ftsupport_code,
							  ftcreated_user, fdcreated_date
							  ) SELECT
							  '{$_REQUEST["ftproject_code"]}' AS ftproject_code, '{$_REQUEST["fttracking_code"]}' AS fttracking_code, '{$_REQUEST["ftsupport_code"]}' AS ftsupport_code,
							  '{$_SESSION['username']}' AS ftcreated_user, now() AS fdcreated_date";	

			
				move_uploaded_file($_FILES['photos']['tmp_name'], _APP_PATH."images/img_bugs/{$_REQUEST['fttracking_code']}.jpg");
		   
		   
			}
			else if($_REQUEST['fntype']=="multiple")
			{
				
				
					$strSQL['Insert Project no'][]="
							  INSERT INTO txtracking_hdr(
							  ftproject_code,
							  fttracking_code, ftsupport_code,
							  ftcreated_user, fdcreated_date
							  ) SELECT
							  '{$_REQUEST["ftproject_code"]}' AS ftproject_code, '{$_REQUEST["fttracking_code"]}' AS fttracking_code, '{$_REQUEST["ftsupport_code"]}' AS ftsupport_code,
							  '{$_SESSION['username']}' AS ftcreated_user, now() AS fdcreated_date";
				  
					  for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
							$fdtrans_date=getDateYmd($_REQUEST['fdtrans_date']);
	/* 						$fdproses_date=getDateYmd($_REQUEST['fdproses_dateD0'][$j]);
							$fdqc_date=getDateYmd($_REQUEST['fdqc_dateD0'][$j]);
							$fdselesai_date=getDateYmd($_REQUEST['fdselesai_dateD0'][$j]);		
							ftybugsD01
	 */		

								if($_FILES['ftybugsD0']['name'][$j]==""){
									$photoname="";
								}
								else{
									$photoname=$_REQUEST['fttracking_code']."-".$_REQUEST['fnindexD0'][$j].".jpg";
								}	 
				 
										   $strSQL['INSERT Tracking Support'][]="
												   INSERT INTO txtracking_det
													  (fnindex,fttracking_code	,fdtrans_date,ftproject_code,ftusername,ftket_customer,ftket_internal,fnstatus,ftstatus_customer,ftproject_category_name,fdproses_date,fdend_date,fdqc_date,fdselesai_date,ftimg_bugs, ftsupport_code, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
													SELECT			
													  '{$_REQUEST['fnindexD0'][$j]}','{$_REQUEST['fttracking_code']}','{$fdtrans_date}','{$_REQUEST['ftproject_code']}','{$_REQUEST['ftusernameD0'][$j]}','{$_REQUEST['ftket_customerD0'][$j]}','{$_REQUEST['ftket_internalD0'][$j]}','{$_REQUEST['fnstatusD0'][$j]}',1,'{$_REQUEST['ftproject_category_nameD0'][$j]}','{$fdtrans_date}','{$fdtrans_date}','{$fdtrans_date}','{$fdtrans_date}','{$photoname}','{$_REQUEST["ftsupport_code"]}','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now()";
					  move_uploaded_file($_FILES['ftybugsD0']['tmp_name'][$j], _APP_PATH."images/img_bugs/{$photoname}");
							}				
				}	 
        }
     return $strSQL;
  }

  
  function UpdateData() {
       global $objAxpDB;
        $strSQL=array();
        $objAxpDB->Allow_Update(false);

if($_REQUEST[mode]=="update") {
	if($_REQUEST['ftstatus_customer']==3){
		
		//REVISI		
/* 				$notracking=substr($_REQUEST['notrack'],0,17);

				$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
				$fdqc_date=getDateYmd($_REQUEST['fdqc_date']);
				$fdselesai_date=getDateYmd($_REQUEST['fdselesai_date']);	
				$fdtrans_date=getDateYmd($_REQUEST['fdtrans_date']);
				$strSQL["INSERT Tracking Support"][]="INSERT INTO txtracking_det(fttracking_code	,fdtrans_date,ftproject_code,ftusername,ftket_customer,ftket_internal,fnstatus,ftstatus_customer,ftproject_category_name,fdproses_date,fdqc_date,fdselesai_date, ftimg_bugs, ftsupport_code, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
SELECT IFNULL(CONCAT('PUSAT-TRR1705',LPAD((SUBSTRING_INDEX(MAX(`fnid`), 'PUSAT-TRR1705',-1) + 1), 5, '0')), 'PUSAT-TRR1705') as fttracking_code,'{$fdtrans_date}' as fdtrans_date,'{$_REQUEST['ftproject_code']}' as ftproject_code,'{$_REQUEST['ftusername']}' as ftusername,'{$_REQUEST['ftket_customer']}' as ftket_customer,'{$_REQUEST['ftket_internal']}' as ftket_internal ,0 as fnstatus,1 as ftstatus_customer,'{$_REQUEST['ftcreated_user']}' as ftproject_category_name,'{$fdproses_date}' as fdproses_date,'{$fdqc_date}' as fdqc_date,'{$fdselesai_date}' as fdselesai_date,'{$_REQUEST['ftimg_bugs']}' as ftimg_bugs,'{$_REQUEST['ftsupport_code']}' as ftsupport_code,'{$_SESSION['username']}' as ftcreated_user,now() as fdcreated_date,'{$_SESSION['username']}' as ftmodified_user,now() as fdmodified_date FROM txtracking_det";
															 
															 
				$strSQL['Insert Project hdr'][]="INSERT INTO txtracking_hdr(ftproject_code,
							  fttracking_code, ftsupport_code,
							  ftcreated_user, fdcreated_date
							  ) SELECT
							  '{$_REQUEST["ftproject_code"]}' AS ftproject_code, '{$notracking}-1' AS fttracking_code, '{$_REQUEST["ftsupport_code"]}' AS ftsupport_code,
							  '{$_SESSION['username']}' AS ftcreated_user, now() AS fdcreated_date";	
							  
			$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
			$fdqc_date=getDateYmd($_REQUEST['fdqc_date']);
			$fdselesai_date=getDateYmd($_REQUEST['fdselesai_date']);
			$strSQL["UPDATE"][]="UPDATE txtracking_det set ftstatus_customer='{$_REQUEST['ftstatus_customer']}' where fnid='{$_REQUEST['fnid']}'";			
 */			
        
		}	
	else{
			$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
			$fdend_date=getDateYmd($_REQUEST['fdend_date']);
			$fdqc_date=getDateYmd($_REQUEST['fdqc_date']);
			$fdselesai_date=getDateYmd($_REQUEST['fdselesai_date']);
			$strSQL["UPDATE"][]="UPDATE txtracking_det set ftket_internal='{$_REQUEST['ftket_internal']}',ftket_customer='{$_REQUEST['ftket_customer']}',fnstatus='{$_REQUEST['fnstatus']}',fdproses_date='{$fdproses_date}',fdend_date='{$fdend_date}',fdqc_date='{$fdqc_date}',fdselesai_date='{$fdselesai_date}',ftstatus_customer='{$_REQUEST['ftstatus_customer']}' where fnid='{$_REQUEST['fnid']}'";	
		}
		
}
     return $strSQL;
  }
  
    function FinalData() {
        global $objAxpDB;
        $objAxpDB->Allow_Final(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "final":
		$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
		$fdend_date=getDateYmd($_REQUEST['fdend_date']);
				$strSQL["FINAL"][]="UPDATE txtracking_det set fdproses_date='{$fdproses_date}',fdend_date='{$fdend_date}',ftstatus_final=1 where fnid='{$_REQUEST['fnid']}'";	
		break;		
       case "final_approve":
         if($_REQUEST['ftstatus_customer']!=2) {
            echo "<script>
                alert('silahkan pilih konfirmasi customer ...');
                window.history.back();
            </script>";   
            die("");            
         }	   
				$strSQL["FINAL"][]="UPDATE txtracking_det set ftstatus_customer='{$_REQUEST['ftstatus_customer']}',ftstatus_final=2 where fnid='{$_REQUEST['fnid']}'";	
		break;			
		}
	return $strSQL;
	}	

function CancelData() {
    global $objAxpDB;
   $objAxpDB->Allow_Cancel(false);
    $strSQL=array();
    switch($_REQUEST[mode]) {
      case "batal":
            $strSQL["batal"][]="update txtracking_det set fnstatus=9 where fnid='{$_REQUEST['fnid']}'";
    break;

    }

    return $strSQL;
 }
	/* 
    function approveData() {
        global $objAxpDB;
        $objAxpDB->Allow_Approve(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "approve":
		$fdproses_date=getDateYmd($_REQUEST['fdproses_date']);
		$fdend_date=getDateYmd($_REQUEST['fdend_date']);
				$strSQL["APPROVE"][]="UPDATE txtracking_det set fdproses_date='{$fdproses_date}',fdend_date='{$fdend_date}',ftstatus_final=3 where fnid='{$_REQUEST['fnid']}'";	
		break;		
		
		}
	return $strSQL;
	}		 */
?>
