<?php
     function SaveData() {   
        global $objAxpDB;
        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":  
             
            if($_REQUEST['fnstatus_giro']!=0) {
                  $ssql="SELECT * 
                          FROM txgiro_hist 
                          WHERE  fnstatus_giro<>'9' AND  ftgiro_no='{$_REQUEST['ftgiro_no']}' AND
                                ftdocument_no='{$_REQUEST['ftdocument_no']}'";
                 $rs=mysql_query($ssql);
                 $r=mysql_fetch_assoc($rs);
                 
                  $strSQL['Update GIRO'][]="UPDATE txgiro_hist 
                                                SET fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."',
                                                ftacc_no='{$_REQUEST['ftacc_no']}',
                                                fnstatus_giro='{$_REQUEST['fnstatus_giro']}' 
                                            WHERE ftgiro_no='{$_REQUEST['ftgiro_no']}' AND 
                                                  ftdocument_no='{$_REQUEST['ftdocument_no']}'";
                  if($r['fttype']=='AR') {
                       $strSQL['Update txar_det1'][]="
                          UPDATE txar_det1 
                          SET fnstatus_giro='{$_REQUEST['fnstatus_giro']}' ,fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."' 
                          WHERE ftar_no='{$_REQUEST['ftdocument_no']}' AND 
                                ftgiro_no='{$_REQUEST['ftgiro_no']}'";
                  }
                  elseif($r['fttype']=='BM') {
                      $strSQL['Update txbankrcp_det'][]="
                          UPDATE txbankrcp_det 
                          SET fnstatus_giro='{$_REQUEST['fnstatus_giro']}' ,fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."' 
                          WHERE ftbankrcp_no='{$_REQUEST['ftdocument_no']}' AND 
                                ftgiro_no='{$_REQUEST['ftgiro_no']}'";
                      
                  }
                  elseif($r['fttype']=='UM') {
                      $strSQL['Update txadvanced_receive'][]="
                          UPDATE txadvanced_receive
                          SET fngiro_status='{$_REQUEST['fnstatus_giro']}' ,fdcliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."'
                          WHERE fttrans_no='{$_REQUEST['ftdocument_no']}' AND ftgiro_no='{$_REQUEST['ftgiro_no']}'";
                  }

                  $status=1;
                  $ssql="SELECT * FROM txgiro_hist
                         WHERE ftdocument_no='{$_REQUEST['ftdocument_no']}'";
                  $rs=mysql_query($ssql);
                  while($r=mysql_fetch_assoc($rs)):
                     if($rs["fnstatus_giro"] != 1){ $status=0; break; }
                  endwhile;
                  $strSQL['Update txar_hdr'][]="UPDATE txar_hdr SET fnstatus2='{$status}' WHERE ftar_no='{$_REQUEST['ftdocument_no']}'";
            } 
         break;
        }
       # pr($strSQL);
	#die("m");
        return $strSQL;
   }


 function UpdateData() {
        global $objAxpDB;
        $objAxpDB->Allow_Update(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "update":

         
                  $ssql="SELECT *
                          FROM txgiro_hist
                          WHERE  fnstatus_giro<>'9' AND  ftgiro_no='{$_REQUEST['ftgiro_no']}' AND
                                ftdocument_no='{$_REQUEST['ftdocument_no']}'";
                 $rs=mysql_query($ssql);
                 $r=mysql_fetch_assoc($rs);

                  $strSQL['Update GIRO'][]="UPDATE txgiro_hist
                                                SET fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."',
                                                ftacc_no='{$_REQUEST['ftacc_no']}',
                                                fnstatus_giro='{$_REQUEST['fnstatus_giro']}'
                                            WHERE ftgiro_no='{$_REQUEST['ftgiro_no']}' AND
                                                  ftdocument_no='{$_REQUEST['ftdocument_no']}'";
                  if($r['fttype']=='AR') {
                       $strSQL['Update txar_det1'][]="
                          UPDATE txar_det1
                          SET fnstatus_giro='{$_REQUEST['fnstatus_giro']}' ,fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."'
                          WHERE ftar_no='{$_REQUEST['ftdocument_no']}' AND
                                ftgiro_no='{$_REQUEST['ftgiro_no']}'";
                  }
                  elseif($r['fttype']=='BM') {
                      $strSQL['Update txbankrcp_det'][]="
                          UPDATE txbankrcp_det
                          SET fnstatus_giro='{$_REQUEST['fnstatus_giro']}' ,fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."'
                          WHERE ftbankrcp_no='{$_REQUEST['ftdocument_no']}' AND
                                ftgiro_no='{$_REQUEST['ftgiro_no']}'";

                  }
                  elseif($r['fttype']=='UM') {
                      $strSQL['Update txadvanced_receive'][]="
                          UPDATE txadvanced_receive
                          SET fngiro_status='{$_REQUEST['fnstatus_giro']}' ,fdcliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."'
                          WHERE fttrans_no='{$_REQUEST['ftdocument_no']}' AND ftgiro_no='{$_REQUEST['ftgiro_no']}'";
                  }

       
         break;
        }
       # pr($strSQL);
	#die("m");
        return $strSQL;
   }