<?php
    // Script Ajax di form bersangkutan
    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            // Cek Harga    
            case "check_price":
                $ssql="SELECT fcselling_price FROM tlselling_price
                        WHERE ftitem_code='{$_REQUEST['ftitem_code']}' and ftcurrency_code = 'IDR'";
                $fcprice=RetRstField($ssql);
                
                $ssql="SELECT ftitem_name FROM tlstock_hdr
                        WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
                $ftitem_name=RetRstField($ssql);
                
                $ssql="SELECT ftpart_no FROM tlstock_hdr
                        WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
                $ftpart_no=RetRstField($ssql);
                
                ?>
                document.getElementById('fcprice').value='<?php echo $fcprice; ?>';
                document.getElementById('ftitem_name').value='<?php echo $ftitem_name; ?>';
                document.getElementById('ftpart_no').value='<?php echo $ftpart_no; ?>';
                document.getElementById('span_ftitem_code').style.display = "none";
                <?php

                break;
            
            
        }
    }
    
    // Security Hak Akses
    Getsecurity("sales_inquiry");
        
    // -- Section Detail Form --
    // Judul Detail Form
    $objAxpDB->FormName("Sales Inquiry");
    $sql = "SELECT ftitem_code, ftitem_name, ftpart_no, '0.00' AS fcprice
            FROM tlstock_hdr ";
    $objAxpDB->FormSQL($sql);
    $objAxpDB->FormCaption("Kode Barang, Nama Barang, Part No, Harga Jual");
    
    // Posisi Layout Kolom : TL = Top Left, TR = Top Right, BL = Bottom Left, BR = Bottom Right, HD = Hidden
    $objAxpDB->FormPosition("TL, TL, HD, TL");
    $objAxpDB->FormLocked("0, 1, 1, 1");
    $objAxpDB->FormSize(",50,50,");
    
    //$ajaxPrice="OnClick=\"ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=check_price&ftitem_code='+ document.getElementById('ftitem_code').value +'');\"";
    //$price_check = "<input type='button' value='CEK HARGA' {$ajaxPrice}>";
    //$objAxpDB->FormLayout(0,"$price_check");
    
    // Trigger Script Kolom
    $ajaxItem="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=check_price&ftitem_code='+ document.getElementById('ftitem_code').value +'');";
    $objAxpDB->FormScript(0, "onChange=\"{$ajaxItem}\"");
    
    // Tampilkan Grid
    $objAxpDB->GridName(0, "Detail Barang");
    $objAxpDB->GridSQL(0, "SELECT ftwarehouse_code, ftlocation_code, fnqty_available FROM tlstock_det WHERE 0 # ");
    $objAxpDB->GridCaption(0, "Kode Gudang, Kode Lokasi, Qty Available");
    $objAxpDB->GridLocked(0,'1,1,1');
    $objAxpDB->GridAutoAdd(0, False);
        
    // Tampilkan Lookup atau Pulldown Menu
    $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, CASE WHEN IFNULL(ftpart_no,\'\') = \'\' THEN ftitem_name ELSE CONCAT(ftitem_name,\' PART NO: \',IFNULL(ftpart_no,\'\')) END AS ftitem_name FROM tlstock_hdr ORDER by ftitem_name,ftpart_no,ftitem_code ", "ftitem_code", "ftitem_name", -1,false);
            
    $objAxpDB->ButtonShow("reset");
    
    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "check_price":
                    ob_start();
                    $_REQUEST['id']=0.5;
                    
                    $objAxpDB->GridSQL(0, "SELECT ftwarehouse_code, ftlocation_code, fnqty_available FROM tlstock_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}' AND fnqty_available != 0 # ");
                    $objAxpDB->GridCaption(0, "Kode Gudang, Kode Lokasi, Qty Available");
                    $objAxpDB->GridLocked(0,'1,1,1');
                    $objAxpDB->GridAutoAdd(0, False);

                    $objAxpDB->Process();
                    $objAxpDB->setGrid2(0);
                    $html = ob_get_contents();
                    ob_end_clean();
                    ?>
                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");

                    div.innerHTML =m;
                    RowIndex0();
                    reSize();
                    
                    ElementCurrencyALL();
                    <?php

                break;
        }
        
        die("");
        exit;
    }

    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();
     