<?php
/*	
 *	Author 	: Wahyu / Tanggal : 22-07-2014	
 *	Revisi 	: Ferry / Tanggal : 23-03-2015
 */
?>

<div id="cc" class="easyui-layout" data-options="fit:true, border:false">
    <div data-options="region:'west',split:true, border:true" title="" style="width:230px; background-color:#F8F8F8;">
        <div title="" style="padding:10px;overflow:auto;" data-options="selected:true" >				
            <div class="preference_menu">
                <ul>
                    <!--<li><a href="<?php echo site_url('setup/preference_account'); ?>" style="border-top:none;"><img src="<?php echo base_url(); ?>assets/custom/icons/clipboard-invoice.png" alt=""/><span>P/L Account</span></a></li>-->	
                    <li><a href="<?php echo site_url('setup/preference_item'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/clipboard-invoice.png" alt=""/><span>Item Account</span></a></li>	
                    <li><a href="<?php echo site_url('setup/preference_sales'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/moneys.png" alt=""/><span><b>Sales Account</b></span></a></li>                   				   
                    <li><a href="<?php echo site_url('setup/preference_purchases'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/sticky-notes.png" alt=""/><span>Purchases Account</span></a></li>	
                    <li><a href="<?php echo site_url('setup/preference_services'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/calculator.png" alt=""/><span>Expense Account</span></a></li>
                    <li><a href="<?php echo site_url('setup/preference_advances'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/calculator.png" alt=""/><span>Adv. Payment Account</span></a></li>
                    <li><a href="<?php echo site_url('setup/preference_expense'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/calculator.png" alt=""/><span>Cash-Bon Account</span></a></li>
                    <li><a href="<?php echo site_url('setup/preference_others'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/money-coin.png" alt=""/><span>Others Account</span></a></li> 
                    <li><a href="<?php echo site_url('setup/preference_approval'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/property.png" alt=""/><span>Sales Approval Limit</span></a></li>
                    <li><a href="<?php echo site_url('setup/preference_miscellaneous'); ?>"><img src="<?php echo base_url(); ?>assets/custom/icons/folder-stand.png" alt=""/><span>Miscellaneous</span></a></li>
                </ul>
            </div>	
        </div>
    </div>
	
    <div data-options="region:'center',fit:true,plain:true,border:false" style="background:#eee;">
        <div id="form-wrapper" class="easyui-panel" border="false" style="width:1125px;height:520px;background:#FFF;border:#95B8E7 1px solid;">
            <div style="background:linear-gradient(to bottom,#EFF5FF 0,#E0ECFF 100%);height:27px;border-bottom:#95B8E7 1px solid;">
            	<a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
            </div>
                <div style="overflow:hidden;padding:1px;">
                    <form id="preference_sales_account" name="preference_sales_account" method="post" class="preference_form">
                    <input type="hidden" name="jobtitle" value="<?php echo $this->session->userdata('jobtitle'); ?>" />				
                    
                    <table width="100%" cellspacing="1" cellpadding="1">
                        <tr>
                            <td align="left" valign="middle"><b>Item Category</b></td>
                            <td width="650" align="left" valign="middle">
                                <select id="select_item_category" name="select_item_category" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'ItemCategoryID',
                                        textField:'ItemCategoryName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/item_category'
                                    ">
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2"><hr /></td>
                        </tr>

                        <tr>
                            <td align="left" valign="middle"><b>Account Receivable</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_receivable" name="select_account_receivable" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_sr_receiveble'
                                    ">
                                </select>
                                
                            </td>
                        </tr>
                        
                        <tr>
                            <td align="left" valign="middle"><b>Advance Sales</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_advance_sales" name="select_account_advance_sales" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_advance_sales'
                                    ">
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td align="left" valign="middle"><b>Invoice Discount</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_invoice_discount" name="select_account_invoice_discount" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_invoice_discount'
                                    ">
                                </select>
                            </td>
                        </tr>
                    
                        <tr>
                            <td align="left" valign="middle"><b>Receive Discount</b></td>
                            <td align="left" valign="middle">
                                 <select id="select_account_receive_discount" name="select_account_receive_discount" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_receive_discount'
                                    ">
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td align="left" valign="middle"><b>Sales Taxable</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_sales_taxable" name="select_account_sales_taxable" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_sales_taxable'
                                    ">
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td align="left" valign="middle"><b>Sales Freight</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_sales_freight" name="select_account_sales_freight" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_sales_freight'
                                    ">
                                </select>
                            </td>
                        </tr>
                        
                        <tr>
                            <td align="left" valign="middle"><b>Realized Gained / Loss</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_realized_gained" name="select_account_realized_gained" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_realized'
                                    ">
                                </select>
                            </td>
                        </tr>
                    
                        <tr>
                            <td valign="middle"><b>Unrealized Gained / Loss</b></td>
                            <td align="left" valign="middle">
                                <select id="select_account_unrealized_gained" name="select_account_unrealized_gained" class="easyui-combobox" style="width:651px;" required="true"
                                    data-options = "
                                        valueField:'AccountNumber',
                                        textField:'AccountName',
                                        url:'<?php echo base_url(); ?>setup/preference_sales/akun_unrealized'
                                    ">
                                </select>
                            </td>
                        </tr>
                    </table>					
                </form>
            </div>
        </div>
		
        <div style="padding:5px;text-align:right;width:1110px;">
            <?php if($this->session->userdata('jobtitle') == 'MGR'){ ?>
                <!--<a id="app_mgr" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="submit_form()" style="width:110px;">App. Mgr</a>--> 	
            <?php }
            else { ?>
                <!--<a id="app_mgr" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="" style="width:110px;" disabled="disabled">App. Mgr</a>-->
            <?php } ?>					
    
            <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="submit_form();">Save</a> 								
            <a href="javascript:void(0)" class="easyui-linkbutton  form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Cancel</a>							
        </div>	
    </div>
</div>

<script type="text/javascript">	

    function submit_form(){	 
        var categori = $('#select_item_category').combobox('getValues');
	
        if(categori == 0) {
            $.messager.alert('Unseccessfull','Kategori Belum Dipilih','error');
            return false;
        } else {
            custom_data('<?php echo"setup/preference_sales"; ?>/proses_post_data_prefernce_sales_account','#preference_sales_account');
			//$("#preference_sales_account").submit();
        }
    }
	
    $('#select_item_category').combobox({
        //valueField: 'id',

        onSelect: function(rec){						
            var item_id = rec.ItemCategoryID;

//            $.ajax({
//                type: "POST",
//                url: "<?php echo base_url(); ?>setup/preference_sales/cek_app_sales",
//                data: "item_id="+item_id,
//                cache: false,
//                success: function(msg){
//                    var jk = msg;
//                    if(jk == 1){
//                        //$('#save_button').linkbutton('disable');
//                        $('#app_mgr').linkbutton('disable');
//                    } else {
//                        //$('#save_button').linkbutton('enable');
//                        $('#app_mgr').linkbutton('enable');
//                    }
//                }
//            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_sr_receiveble",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_receivable").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_advance_sales",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_advance_sales").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_invoice_diskon",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_invoice_discount").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_receive_diskon",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_receive_discount").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_sales_taxable",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_sales_taxable").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_sales_freight",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_sales_freight").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_realized",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_realized_gained").combobox('select', msg);
                }
            });

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>setup/preference_sales/combo_list_unrealized",
                data: "item_id="+item_id,
                cache: false,
                success: function(msg){
                    $("#select_account_unrealized_gained").combobox('select', msg);
                }
            });
        }
    });
</script>