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

    break;    
}
   

function UpdateData() {
    global $objAxpDB;
   
    $objAxpDB->Allow_Update(true);
    switch($_REQUEST[mode]) {
        case "update":
            $fnold_status = RetRstField("SELECT fnstatus FROM tlcustomer_type WHERE ftcustomer_type_code='{$_REQUEST['ftcustomer_type_code']}'");
          
            if (($fnold_status == 0) && ($_REQUEST['fnstatus']=1)) { 
                // insert master stock yg tdk ada di harga jual
                $ssql=" SELECT a.ftitem_code AS ftitem_code, a.ftitem_name,a.ftuom_code,b.ftitem_code AS ftitem_code2, b.ftcustomer_type_code 
                        FROM tlstock_hdr a LEFT JOIN tlselling_price b ON a.ftitem_code = b.ftitem_code AND b.ftcustomer_type_code = '{$_REQUEST['ftcustomer_type_code']}'
                        WHERE b.ftitem_code IS NULL and a.fnstatus = 1 ORDER BY a.ftitem_code";
                  
                $rs=mysql_query($ssql);
                while($r1=mysql_fetch_assoc($rs)) {
                    $ssql ="INSERT INTO tlselling_price (ftbranch_code,ftitem_code,ftcustomer_type_code,ftitem_name,
                                ftuom_code,fcold_selling_price,fcselling_price,ffold_selling_discount,
                                ffselling_discount,fncategory,ftcreated_user,fdcreated_date)
                            SELECT '{$_SESSION['strbranch']}','{$r1['ftitem_code']}','{$_REQUEST['ftcustomer_type_code']}','{$r1['ftitem_name']}',
                                a.ftuom_code,0 AS fcold_selling_price,0 AS fcselling_price,0 AS ffold_selling_discount,
                                0 AS ffselling_discount,0 AS fncategory,'{$_SESSION['username']}',NOW()
                            FROM tlstock_hdr a WHERE a.ftitem_code = '{$r1['ftitem_code']}'";
                 
                    mysql_query($ssql);
                }
                
            }    
           
            break;
    }
    return $strSQL;
} 

?>
