<?php

    function SaveM($m) {

        
    }



    function SaveData() {   
        global $objAxpDB;
        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
        
            $strSQL["Insert txproduction_outstanding_weekly_hdr"][]="
                INSERT INTO txproduction_outstanding_weekly_hdr 
                (
                    fnid,ftbranch_code,ftpow_no,
                    fdtrans_date,ftcustomer_code,fftotal_qty,
                    ftnotes,fntrans_type,fnstatus,
                    ftcreated_user,fdcreated_date,ftmodified_user,
                    fdmodified_date 
                )
                SELECT 
                    '' AS fnid,'{$_SESSION["strbranch"]}' AS ftbranch_code,'{$_REQUEST['ftpow_no']}' AS ftpow_no,
                    '".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date,'{$_REQUEST['ftcustomer_code']}' AS ftcustomer_code,'".CCur($_REQUEST['fftotal_qty'])."' AS fftotal_qty,
                    '{$_REQUEST['ftnotes']}' AS ftnotes, '{$_REQUEST['fntrans_type']}' AS fntrans_type,'{$_REQUEST['fnstatus']}' AS fnstatus,
                    '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
                    NOW() AS fdmodified_date ";
             for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                $_REQUEST['ffqtyD0'][$j]=CCur($_REQUEST['ffqtyD0'][$j]);
                
                $_REQUEST['ffqty_luarkotaD0'][$j]=0;
                $_REQUEST['ffqty_conntainerD0'][$j]=0;
                $_REQUEST['ffqty_jakartaD0'][$j]=0;
                if($_REQUEST['fntrans_type']==0) {
                    $_REQUEST['ffqty_luarkotaD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }
                else if($_REQUEST['fntrans_type']==1) {
                    $_REQUEST['ffqty_conntainerD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }
                else if($_REQUEST['fntrans_type']==2) {
                    $_REQUEST['ffqty_jakartaD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }
                
                //----
              $rs2=mysql_query("select * from tlstock_hdr where ftitem_code='".$_REQUEST['ftitem_codeD0'][$j]."'");
              $r2=mysql_fetch_assoc($rs2);
              $ftstock_group_code=$r2['ftstock_group_code'];
              $ftstock_group_name=RetRstField("select ftstock_group_name
                                                from tlstock_group
                                                where ftstock_group_code='".$r2['ftstock_group_code']."'");

              $ftstock_subgroup_code=$r2['ftstock_subgroup_code'];
              $ftstock_subgroup_name=RetRstField("select ftstock_subgroup_name
                                                from tlstock_subgroup
                                                where ftstock_subgroup_code='".$r2['ftstock_subgroup_code']."'");

              $ftdecal_code=$r2['ftdecal_code'];
              $ftdecal_name=RetRstField("select ftdecal_name
                                                from tldecal
                                                where ftdecal_code='".$r2['ftdecal_code']."'");
              $ftcolor_code=$r2['ftcolor_code'];
              $ftcolor_name=RetRstField("select ftcolor_name
                                                from tlcolor
                                                where ftcolor_code='".$r2['ftcolor_code']."'");
              $ftsize_code=$r2['ftsize_code'];
              $ftsize_name=RetRstField("select ftsize_name
                                                from tlsize
                                                where ftsize_code='".$r2['ftsize_code']."'");



                //--------------------------------------
                $strSQL['Insert txproduction_outstanding_weekly_det'][]="
                      INSERT INTO txproduction_outstanding_weekly_det
                      (
                        fnid,ftbranch_code,ftpow_no,
                        fnindex,ftitem_code,ftitem_name,ftprint_name,ffqty_luarkota,
                        ffqty_conntainer,ffqty_jakarta,ffqty,
                        ftcreated_user,fdcreated_date,ftmodified_user,
                        fdmodified_date,
                        ftstock_group_code,ftstock_group_name,
                        ftstock_subgroup_code,ftstock_subgroup_name,
                        ftdecal_code,ftdecal_name,
                        ftcolor_code,ftcolor_name,
                        ftsize_code,ftsize_name
                      )
                       SELECT
                         '' AS fnid,'{$_SESSION["strbranch"]}' AS ftbranch_code,'{$_REQUEST['ftpow_no']}' AS ftpow_no,
                        '{$j}' AS fnindex,'{$_REQUEST['ftitem_codeD0'][$j]}' AS ftitem_code,'".$r2['ftitem_name']."' as ftitem_name,'".$r2['ftprint_name']."' as ftprint_name,'{$_REQUEST['ffqty_luarkotaD0'][$j]}' AS ffqty_luarkota,
                        '{$_REQUEST['ffqty_conntainerD0'][$j]}' AS ffqty_conntainer,'{$_REQUEST['ffqty_jakartaD0'][$j]}' AS ffqty_jakarta,'{$_REQUEST['ffqtyD0'][$j]}' AS ffqty,
                        '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
                        NOW() AS fdmodified_date,
                        '{$ftstock_group_code}','{$ftstock_group_name}',
                        '{$ftstock_subgroup_code}','{$ftstock_subgroup_name}',
                        '{$ftdecal_code}','{$ftdecal_name}',
                        '{$ftcolor_code}','{$ftcolor_name}',
                        '{$ftsize_code}','{$ftsize_name}'";
                         $fftotal_qty=$fftotal_qty+(float)$_REQUEST['ffqtyD0'][$j];
             }
            $_REQUEST['fftotal_qty']=$fftotal_qty;
            $strSQL['Insert txproduction_outstanding_weekly_hdr'][]="UPDATE txproduction_outstanding_weekly_hdr SET fftotal_qty='{$_REQUEST['fftotal_qty']}' WHERE ftpow_no='{$_REQUEST['ftpow_no']}'";

        break;
        }
        return $strSQL;
    }


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

//            $strSQL["Insert txproduction_outstanding_weekly_hdr"][]="
//                INSERT INTO txproduction_outstanding_weekly_hdr
//                (
//                    fnid,ftbranch_code,ftpow_no,
//                    fdtrans_date,ftcustomer_code,fftotal_qty,
//                    ftnotes,fntrans_type,fnstatus,
//                    ftcreated_user,fdcreated_date,ftmodified_user,
//                    fdmodified_date
//                )
//                SELECT
//                    '' AS fnid,'{$_SESSION["strbranch"]}' AS ftbranch_code,'{$_REQUEST['ftpow_no']}' AS ftpow_no,
//                    '".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date,'{$_REQUEST['ftcustomer_code']}' AS ftcustomer_code,'".CCur($_REQUEST['fftotal_qty'])."' AS fftotal_qty,
//                    '{$_REQUEST['ftnotes']}' AS ftnotes, '{$_REQUEST['fntrans_type']}' AS fntrans_type,'{$_REQUEST['fnstatus']}' AS fnstatus,
//                    '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
//                    NOW() AS fdmodified_date ";
            $strSQL['del txproduction_outstanding_weekly_det'][]="UPDATE txproduction_outstanding_weekly_hdr SET fdtrans_date='".CDate($_REQUEST['fdtrans_date'])."' WHERE ftpow_no='{$_REQUEST['ftpow_no']}' ";

            $strSQL['del txproduction_outstanding_weekly_det'][]="delete from txproduction_outstanding_weekly_det where  ftpow_no='{$_REQUEST['ftpow_no']}'";

             for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                $_REQUEST['ffqtyD0'][$j]=CCur($_REQUEST['ffqtyD0'][$j]);

                $_REQUEST['ffqty_luarkotaD0'][$j]=0;
                $_REQUEST['ffqty_conntainerD0'][$j]=0;
                $_REQUEST['ffqty_jakartaD0'][$j]=0;
                if($_REQUEST['fntrans_type']==0) {
                    $_REQUEST['ffqty_luarkotaD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }
                else if($_REQUEST['fntrans_type']==1) {
                    $_REQUEST['ffqty_conntainerD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }
                else if($_REQUEST['fntrans_type']==2) {
                    $_REQUEST['ffqty_jakartaD0'][$j]=$_REQUEST['ffqtyD0'][$j];
                }

//                $strSQL['Insert txproduction_outstanding_weekly_det'][]="
//                      INSERT INTO txproduction_outstanding_weekly_det
//                      (
//                        fnid,ftbranch_code,ftpow_no,
//                        fnindex,ftitem_code,ffqty_luarkota,
//                        ffqty_conntainer,ffqty_jakarta,ffqty,
//                        ftcreated_user,fdcreated_date,ftmodified_user,
//                        fdmodified_date
//                      )
//                       SELECT
//                         '' AS fnid,'{$_SESSION["strbranch"]}' AS ftbranch_code,'{$_REQUEST['ftpow_no']}' AS ftpow_no,
//                        '{$j}' AS fnindex,'{$_REQUEST['ftitem_codeD0'][$j]}' AS ftitem_code,'{$_REQUEST['ffqty_luarkotaD0'][$j]}' AS ffqty_luarkota,
//                        '{$_REQUEST['ffqty_conntainerD0'][$j]}' AS ffqty_conntainer,'{$_REQUEST['ffqty_jakartaD0'][$j]}' AS ffqty_jakarta,'{$_REQUEST['ffqtyD0'][$j]}' AS ffqty,
//                        '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
//                        NOW() AS fdmodified_date
//
//
//            ";

//----
              $rs2=mysql_query("select * from tlstock_hdr where ftitem_code='".$_REQUEST['ftitem_codeD0'][$j]."'");
              $r2=mysql_fetch_assoc($rs2);
              $ftstock_group_code=$r2['ftstock_group_code'];
              $ftstock_group_name=RetRstField("select ftstock_group_name
                                                from tlstock_group
                                                where ftstock_group_code='".$r2['ftstock_group_code']."'");

              $ftstock_subgroup_code=$r2['ftstock_subgroup_code'];
              $ftstock_subgroup_name=RetRstField("select ftstock_subgroup_name
                                                from tlstock_subgroup
                                                where ftstock_subgroup_code='".$r2['ftstock_subgroup_code']."'");

              $ftdecal_code=$r2['ftdecal_code'];
              $ftdecal_name=RetRstField("select ftdecal_name
                                                from tldecal
                                                where ftdecal_code='".$r2['ftdecal_code']."'");
              $ftcolor_code=$r2['ftcolor_code'];
              $ftcolor_name=RetRstField("select ftcolor_name
                                                from tlcolor
                                                where ftcolor_code='".$r2['ftcolor_code']."'");
              $ftsize_code=$r2['ftsize_code'];
              $ftsize_name=RetRstField("select ftsize_name
                                                from tlsize
                                                where ftsize_code='".$r2['ftsize_code']."'");



                //--------------------------------------
                $strSQL['Insert txproduction_outstanding_weekly_det'][]="
                      INSERT INTO txproduction_outstanding_weekly_det
                      (
                        fnid,ftbranch_code,ftpow_no,
                        fnindex,ftitem_code,ftitem_name,ftprint_name,ffqty_luarkota,
                        ffqty_conntainer,ffqty_jakarta,ffqty,
                        ftcreated_user,fdcreated_date,ftmodified_user,
                        fdmodified_date,
                        ftstock_group_code,ftstock_group_name,
                        ftstock_subgroup_code,ftstock_subgroup_name,
                        ftdecal_code,ftdecal_name,
                        ftcolor_code,ftcolor_name,
                        ftsize_code,ftsize_name
                      )
                       SELECT
                         '' AS fnid,'{$_SESSION["strbranch"]}' AS ftbranch_code,'{$_REQUEST['ftpow_no']}' AS ftpow_no,
                        '{$j}' AS fnindex,'{$_REQUEST['ftitem_codeD0'][$j]}' AS ftitem_code,'".$r2['ftitem_name']."' as ftitem_name,'".$r2['ftprint_name']."' as ftprint_name,'{$_REQUEST['ffqty_luarkotaD0'][$j]}' AS ffqty_luarkota,
                        '{$_REQUEST['ffqty_conntainerD0'][$j]}' AS ffqty_conntainer,'{$_REQUEST['ffqty_jakartaD0'][$j]}' AS ffqty_jakarta,'{$_REQUEST['ffqtyD0'][$j]}' AS ffqty,
                        '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
                        NOW() AS fdmodified_date,
                        '{$ftstock_group_code}','{$ftstock_group_name}',
                        '{$ftstock_subgroup_code}','{$ftstock_subgroup_name}',
                        '{$ftdecal_code}','{$ftdecal_name}',
                        '{$ftcolor_code}','{$ftcolor_name}',
                        '{$ftsize_code}','{$ftsize_name}'";
                        $fftotal_qty=$fftotal_qty+(float)$_REQUEST['ffqtyD0'][$j];
             }
            $_REQUEST['fftotal_qty']=$fftotal_qty;
            $strSQL['Insert txproduction_outstanding_weekly_hdr'][]="UPDATE txproduction_outstanding_weekly_hdr SET fftotal_qty='{$_REQUEST['fftotal_qty']}' WHERE ftpow_no='{$_REQUEST['ftpow_no']}'";
        break;
        }
        return $strSQL;
    }
    
    
 function CancelData() {    
    global $objAxpDB;
//    $objAxpDB->Allow_Cancel(false);
    $strSQL=array();
    switch($_REQUEST[mode]) {
      case "batal":                  
        // batal -%
//          $ssql1="SELECT IFNULL(MAX(ftpow_no),'')  AS M
//                      FROM txproduction_outstanding_weekly_hdr
//                      WHERE ftpow_no LIKE '{$_REQUEST['ftpow_no']}-%'";
//            $no=RetRstField($ssql1);
//            if($no!="") {
//                $no=$no+1;
//                $str1="-{$no}";
//            }
//            else {
//                $str1="-1";
//            }
//
//             $ftpow_no_new="{$_REQUEST['ftpow_no']}{$str1}";
//
//
//             $strSQL["batal"][]="update txproduction_outstanding_weekly_hdr
//                                set fnstatus=9,ftpow_no='{$ftpow_no_new}'
//                                where ftpow_no='{$_REQUEST['ftpow_no']}'";
//
//             $strSQL["batal"][]="update txproduction_outstanding_weekly_det
//                                set ftpow_no='{$ftpow_no_new}'
//                                where ftpow_no='{$_REQUEST['ftpow_no']}'";
//                     
            
    break;
    
    }

    return $strSQL;
 }

 
?>
