<!-- Dialog Item -->
<div id="dialog-item" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" 
    closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons"
>

    <form id="form_account" method="post" novalidate>
    	<input type="hidden" name="hdn_item_category" id="hdn_item_category" value="" />
        
        <table width="100%">            
            <tr>
        	<td width="310">&nbsp;</td>
                <td width="10">&nbsp;</td>
                
                <td>
                    <input type="radio" name="rdo_ItemToggle" value="0" checked /> Item 
                    <input type="radio" name="rdo_ItemToggle" value="1" /> Services / Expenses 
                    <input type="radio" name="rdo_ItemToggle" value="2" /> Adv. Payment
                </td>
            </tr>
        
            <tr>
                <td><b>Item Category</b></td>
                <td><b>:</b></td>

                <td>
                    <select name="cmb_item_category" id="cmb_item_category" class="easyui-combobox" style="width:502px;" editable="false" 
                        data-options="
                            valueField:'ItemCategoryID',
                            textField:'ItemCategoryName',
                            url:'<?php echo base_url(); ?>custom/get_data/itemcategory',
                            onSelect: function(rec){
                                var id = rec.ItemCategoryID;
                                search_choose_item2();
                            }
                        ">
                    </select>
                </td>
            </tr>

            <tr>
                <td><b><span class="header_code">Item Code</span></b></td>
                <td><b>:</b></td>
                
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_item_code" id="txt_item_code" class="easyui-validatebox" onkeyup="search_choose_item2();" />
                </td>
            </tr>
            
            <tr>
                <td><b><span class="header_name">Item Name</span></b></td>
                <td><b>:</b></td>
                
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_item_desc" id="txt_item_desc" class="easyui-validatebox" onkeyup="search_choose_item2();" />
                </td>
            </tr>
        
            <tr>
                <td colspan="3">
                    <table id="tt_choose_item" class="easyui-datagrid" singleSelect="true" remoteSort="false" pagesize="50" fitColumns="true" style="width:830px;height:340px" 
                        data-options = "border:false,view:scrollview,autoRowheight:false"
                        url="<?=base_url()?>custom/get_data/search_item"                    
                    >                        
                        <thead>
                            <tr>
                                <th field="ItemCode" width="150" sortable="true" halign='center'><span class="header_code">Item Code</span></th>
                                <th field="ItemDesc" width="573" sortable="true" halign='center'><span class="header_name">Item Name</span></th>
                                <th field="ItemCategoryID" width="200" sortable="true" halign='center' hidden><span class="header_name">Item Category</span></th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button for Dialog Item-->
<div id="dialog-buttons" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_item();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-item');">Cancel</a>
</div>
<!-- End of Dialog Button for Dialog Item-->

<!-- Dialog Inventory -->
<div id="dialog-inventory" class="easyui-dialog" 
    style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" 
    closed="true" data-options="modal:true, iconCls:'icon-save'"  buttons="#dialog-buttons-inventory" 
>
    <form id="form_account" method="post" novalidate>
    	<input type="hidden" name="hdn_item_category" id="hdn_item_category" value="" />
        
        <table width="100%">            
            <tr>
        	<td width="310">&nbsp;</td>
                <td width="10">&nbsp;</td>
                
                <td>
                    <input type="radio" name="rdo_ItemToggle" value="0" checked /> Item 
                    <input type="radio" name="rdo_ItemToggle" value="1" /> Services / Expenses 
                </td>
            </tr>
        
            <tr>
                <td><b>Item Category</b></td>
                <td><b>:</b></td>

                <td>
                    <select name="cmb_inventory_category" id="cmb_inventory_category" class="easyui-combobox" style="width:502px;" editable="false" 
                        data-options="
                            valueField:'ItemCategoryID',
                            textField:'ItemCategoryName',
                            url:'<?=base_url()?>custom/get_data/itemcategory',
                            onSelect: function(rec){
                                var id = rec.ItemCategoryID;
                                search_inventory();
                            }
                        ">
                    </select>
                </td>
            </tr>

            <tr>
                <td><b><span class="header_code">Item Code</span></b></td>
                <td><b>:</b></td>
                
                <td>
                      <input type="text" style="width:500px;height:20px" name="txt_inventory_code" id="txt_inventory_code" class="easyui-validatebox" onkeyup="search_inventory();" />

                </td>
            </tr>
            
            <tr>
                <td><b><span class="header_name">Item Name</span></b></td>
                <td><b>:</b></td>
                
                <td>
                     <input type="text" style="width:500px;height:20px" name="txt_inventory_desc" id="txt_inventory_desc" class="easyui-validatebox" onkeyup="search_inventory();" />
                </td>
            </tr>
        
            <tr>
                <td colspan="3">
                    <table id="tt_choose_inventory" class="easyui-datagrid" singleSelect="true" remoteSort="false" pagesize="50" fitColumns="true" style="width:830px;height:340px" 
                       url="<?=base_url()?>custom/get_data/search_inventory" data-options = "border:false,view:scrollview,autoRowheight:false"
                    >                        
                        <thead>
                            <tr>
                                <th field="ItemCode" width="150" sortable="true" halign='center'><span class="header_code">Item Code</span></th>
                                <th field="ItemDesc" width="573" sortable="true" halign='center'><span class="header_name">Item Name</span></th>
                                <th field="ItemCategoryID" width="200" sortable="true" halign='center' hidden><span class="header_name">Item Category</span></th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button for Dialog Inventori-->
<div id="dialog-buttons-inventory" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_inventory();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-inventory');">Cancel</a>
</div>

<!--  Tagor Dialog Payment AccountName -->
<div id="dialog-payment-account" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons-account-payment">
    <form id="form_payment_account" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="308" align="left" valign="middle"><b>Account Number</b></td>
                <td width="10"><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:500px;height:20px" name="txt_account_number" id="txt_account_number" class="easyui-validatebox" placeholder="< Account Number >" onkeyup="search_payment_account_popup();" />
                </td>
            </tr>

            <tr>
                <td width="308" align="left" valign="middle"><b>Account Name</b></td>
                <td><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:500px;height:20px" name="txt_account_name" id="txt_account_name" class="easyui-validatebox" placeholder="< Account Name >" onkeyup="search_payment_account_popup();" />
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <table id="tt_choose_account_payment" class="easyui-datagrid" 
                        url="<?php echo base_url(); ?>list/payment/all_accountpembiayaan/<?php echo $this->session->userdata('company');?>" 
                        singleSelect="true" fitColumns="true"
                        style="width:828px;height:380px" data-options = "border:false,view:scrollview,autoRowheight:false"
                    >
                        <thead>
                            <tr>
                                <th field="AccountNumber" width="150" sortable="true">Account Number</th>
                                <th field="AccountName" width="460" sortable="true">Name</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-account-payment" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_account_payment();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-payment-account');">Cancel</a>
</div>

<!-- Dialog Payment Department -->
<div id="dialog-payment-department" class="easyui-dialog" style="width:450px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons-department-payment">
    <form id="form_payment_department" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="120" align="left" valign="middle"><b>Department Code</b></td>
                <td width="10"><b>:</b></td>
                
                <td colspan="2">
                    <input type="text" style="width:288px;height:20px" name="txt_department_code" id="txt_department_code" class="easyui-validatebox" placeholder="< Department Code >" onkeyup="search_payment_department_popup();" />
                </td>
            </tr>

            <tr>
                <td width="120" align="left" valign="middle"><b>Department Name</b></td>
                <td><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:288px;height:20px" name="txt_department_name" id="txt_department_name" class="easyui-validatebox" placeholder="< Department Name >" onkeyup="search_payment_department_popup();" />
                </td>
            </tr>
            
            <tr>
                <td colspan="3">
                    <table id="tt_choose_department_payment" class="easyui-datagrid" 
                        url="<?php echo base_url(); ?>list/payment/all_department/<?php echo $this->session->userdata('company');?>" 
                        singleSelect="true" fitColumns="true" 
                        style="width:428px;height:388px;"
                    >
                        <thead>
                            <tr>
                                <th halign="center" width="170" field="DepartmentCode" sortable="true">Department Code</th>
                                <th halign="center" width="375" field="DepartmentName" sortable="true">Name</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-department-payment" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_department_payment();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-payment-department');">Cancel</a>
</div>
<!-- End Tagor -->

<!-- Dialog Production Amount-->
<div id="dialog-production-amount" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-productions-amount">
    <form id="form_account" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="308" align="left" valign="middle"><b>Item Category</b></td>
                <td width="10"><b>:</b></td>

                <td colspan="2">
                    <select name="cmb_item_category_production" id="cmb_item_category_production" class="easyui-combobox" style="width:502px;" editable="false" 
                        data-options = "
                            valueField:'ItemCategoryID',
                            textField:'ItemCategoryName',
                            url:'<?php echo base_url(); ?>custom/get_data/itemcategory',
                            onSelect: function(rec){
                                var id = rec.ItemCategoryID;
                                search_production();	
                            }
                        ">
                    </select>
                </td>
            </tr>
            <tr>
                <td width="50" align="left" valign="middle"><b>Item Code</b></td>
                <td><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:500px;height:20px" name="txt_item_code_production" id="txt_item_code_production" class="easyui-validatebox" placeholder="< Item Code >" onkeyup="search_production_amount();" />
                </td>
            </tr>

            <tr>
                <td width="50" align="left" valign="middle"><b>Description</b></td>
                <td><b>:</b></td>

                <td colspan="2">
                    <input type="text" style="width:500px;height:20px" name="txt_item_desc_production" id="txt_item_desc_production" class="easyui-validatebox" placeholder="< Item Name >" onkeyup="search_production_amount();" />
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <table id="tt_choose_production_amount" class="easyui-datagrid" 
                        url="<?Php echo base_url()?>custom/get_data/search_production_not_in" 
                        singleSelect="true" fitColumns="true" 
                        pageSize="50" data-options = "border:false,view:scrollview,autoRowheight:false"
                        style="width:828px;height:360px"
                    >
                        <thead>
                            <tr>
                                <th field="ItemCode" width="150" sortable="true">Item Code</th>
                                <th field="ItemDesc" width="200" sortable="true">Name</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dialog-productions-amount" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_production_amount();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-production-amount');">Cancel</a>
</div>

<!-- Job Costing -->
<div id="dialog-job-costing" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#job_costing">
    <form id="form_job_costing" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="308"><b>Persedian Barang Dalam Proses</b></td>
                <td width="10"><b>:</b></td>

                <td>
                    <select name="cmb_item_job_costing" id="cmb_item_job_costing" class="easyui-combobox" style="width:502px;" editable="false" 
                        data-options = "
                            valueField:'ItemCategory',
                            textField:'AccountName',
                            url:'<?php echo base_url(); ?>custom/get_data/persedian_barang_dalam_proses',
                            onSelect: function(rec){
                                var id = rec.ItemCategory;
                                
                                search_job_costing(id );	
                            }
                        ">
                    </select>
                </td>
            </tr>

            <tr>
                <td><b>Item Code</b></td>
                <td width="10"><b>:</b></td>
                
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_item_code_job_costing" id="txt_item_code_job_costing" class="easyui-validatebox" placeholder="Item Code" onkeyup="search_job_costing();" />
                </td>
            </tr>
            
            <tr>
                <td><b>Item Name</b></td>
                <td><b>:</b></td>
            
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_item_desc_job_costing" id="txt_item_desc_job_costing" class="easyui-validatebox" placeholder="Item Name" onkeyup="search_job_costing();" />
                </td>
            </tr>
            
            <tr>
                <td colspan="3">
                    <table id="tt_choose_job_costing" class="easyui-datagrid" singleSelect="true" style="width:828px;height:360px;"
                        url="<?Php echo base_url()?>custom/get_data/search_job_costing" 
                    >
                        <thead>
                            <tr bgcolor="">
                                <th halign="center" field="ItemCode" width="100%" sortable="true">Item Code</th>
                                <th halign="center" field="ItemDesc" width="100%" sortable="true">Name</th>
                                <th field="ItemUnit" width="200" sortable="true">Item Unit</th>
                                <th halign="center" field="ItemAverage" width="100%" sortable="true" hidden="true">Item Average</th>
                                <th halign="center" field="IsLock" width="200" sortable="true">Status</th>
                                <th halign="center" field="ItemCategoryID" width="200" sortable="true" hidden="true">ItemCategoryID</th>
                                <th halign="center" field="ItemQty" width="200" sortable="true" hidden="true">Item Qty</th>
                                <th halign="center" field="ItemLockId" width="200" sortable="true" hidden="true">Item Lock Id</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="job_costing">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_job_costing_ok();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-job-costing');">Cancel</a>
</div>

<script>
    //Horizontal position
    $(document).ready(function(){
//        page_width = parseInt($(document).width());
//        left_menu_width = 180; // Value from v_mainpage.php(custom/views/v_mainpage.php)
//        mainframe_width = page_width - left_menu_width;
//
//        $('.easyui-dialog').each(function(){
//            temp = mainframe_width - $(this).outerWidth();
//            temp = temp/2;
//            left_pos = left_menu_width + temp;
//        });
//        
//        //popup_width = $('.easyui-dialog:visible').width();
//        //alert(popup_width);
//        $('.easyui-dialog').css('left',left_pos);
    });

    $('#tt_choose_item').datagrid({
	onDblClickRow:function(){		
            choose_item();
	}
    });

    $('#tt_choose_inventory').datagrid({
	onDblClickRow:function(){
		
		var selected_data=$('#tt_choose_inventory').datagrid('getSelected');	
		
		flag = true;
		item = $('#dtg_item').datagrid('getRows');
	
		$.each(item, function(index,value){
			if(selected_data.ItemCode == value.ItemCode){
				$.messager.alert('Unseccessfull','Item sudah tersedia.','error',function(){	
					$('#tt_choose_inventory').datagrid('reload'); 	
				});
				flag = false;
			}
		});		
        
		if(flag != false){
			choose_inventory();
		}
	}
    });

    $('#tt_choose_account_payment').datagrid({
	onDblClickRow:function(){		
            choose_account_payment();
	}
    });

    $('#tt_choose_department_payment').datagrid({
	onDblClickRow:function(){		
            choose_department_payment();
	}
    });
	
	/* Author : Fachri / fungsi untuk search job cos, daily production dan daily production amount */

	
	$('#tt_choose_production_amount').datagrid({
	onDblClickRow:function(){
        	choose_production_amount();
        }
    });
	
    function choose_job_costing_ok(){
        var selected_data=$('#tt_choose_job_costing').datagrid('getSelected');
        
        if(selected_data.ItemLockId == 1){
            $.messager.alert('Unseccessfull','Item sedang proses Adjustment','error',function(){	
                $('#tt_choose_job_costing').datagrid('reload'); 
            });
        }
        else{
			choose_job_costing();
		}
    }
	
    $('#tt_choose_job_costing').datagrid({
        onDblClickRow:function(){	
            var selected_data=$('#tt_choose_job_costing').datagrid('getSelected');

            if(selected_data.ItemLockId == 1){
                $.messager.alert('Unseccessfull','Item sedang proses Adjustment','error',function(){	
                    $('#tt_choose_job_costing').datagrid('reload'); 
                });
            }
            else{
                choose_job_costing();
            }
        }
    });
	/* end*/
	
    $('input[name="rdo_ItemToggle"]').click(function(){    
        if($(this).val() == 0){
            $('#cmb_item_category').combobox('enable');
            $('#cmb_inventory_category').combobox('enable');
            
            $('#tt_choose_item').datagrid({
                url:'<?=base_url()?>custom/get_data/search_item'
            });
			
            //SQ Item inventori
            $('#tt_choose_inventory').datagrid({
                url:'<?=base_url()?>custom/get_data/search_inventory'
            });
            
            $('span.header_code').text('Item Code');
            $('span.header_name').text('Item Name');
            $('span#theader_code').text('Item Code');
            $('span#theader_name').text('Description');
        }
        else if($(this).val() == 1){
            $('#cmb_item_category').combobox('disable');
            $('#cmb_inventory_category').combobox('disable');
            
            $('#tt_choose_item').datagrid({
                url:'<?=base_url()?>custom/get_data/search_service'
            });
			
            //SQ expense inventori
            $('#tt_choose_inventory').datagrid({
                url:'<?=base_url()?>custom/get_data/search_service'
            });
            
            $('span.header_code').text('Service / Expense Name');
            $('span.header_name').text('Description');
            $('span#theader_code').text('Item Code');
            $('span#theader_name').text('Description');
        }
        else if($(this).val() == 2){
            $('#cmb_item_category').combobox('disable');
            
            $('#tt_choose_item').datagrid({
                url:'<?=base_url()?>custom/get_data/search_advance'
            });
            
            $('span.header_code').text('Adv. Payment Name');
            $('span.header_name').text('Description');
            $('span#theader_code').text('Item Code');
            $('span#theader_name').text('Description');
        }
    });
</script>