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

<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>Sales Account</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><b>Purchase Account</b></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_purchase_account" name="preference_purchase_account" method="post" class="preference_form">
                        <input type="hidden" name="jobtitle" value="<?php echo $this->session->userdata('jobtitle'); ?>" />						
	
                        <table width="100%" border="0" cellspacing="1" cellpadding="1">
                            <tr>
                                <td align="left" valign="middle"><b>Item Category</b></td>
                                <td width="650" height="15" 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_purchases/item_category'
                                        ">
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <td colspan="2"><hr /></td>
                            </tr>
                            
                            <tr>
                                <td align="left" valign="middle"><b>Account Payable</b></td>
                                <td align="left" valign="middle">
                                    <select id="select_account_pi_payablee" name="select_account_pi_payablee" class="easyui-combobox" style="width:651px;" required="true"
                                        data-options = "
                                            valueField:'AccountNumber',
                                            textField:'AccountName',
                                            url:'<?php echo base_url(); ?>setup/preference_purchases/akun_payable'
                                        ">
                                    </select>
                                </td>
                            </tr>

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

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

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

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

                            <tr>
                                <td align="left" valign="middle"><b>Purchase Freight</b></td>
                                <td align="left" valign="middle">
                                    <select id="select_account_purchase_freight" name="select_account_purchase_freight" class="easyui-combobox" style="width:651px;" required="true"
                                        data-options = "
                                            valueField:'AccountNumber',
                                            textField:'AccountName',
                                            url:'<?php echo base_url(); ?>setup/preference_purchases/akun_purchase_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" name="select_account_realized" class="easyui-combobox" style="width:651px;" required="true"
                                                data-options = "
                                                    valueField:'AccountNumber',
                                                    textField:'AccountName',
                                                    url:'<?php echo base_url(); ?>setup/preference_purchases/akun_purchase_realized'
                                                ">
                                            </select>
                                    </td>
                            </tr>

                            <tr>
                                <td align="left" valign="middle"><b>Unrealized Gained / Loss</b></td>
                                <td align="left" valign="middle">
                                         <select id="select_account_unrealized" name="select_account_unrealized" class="easyui-combobox" style="width:651px;" required="true"
                                                data-options = "
                                                    valueField:'AccountNumber',
                                                    textField:'AccountName',
                                                    url:'<?php echo base_url(); ?>setup/preference_purchases/akun_purchase_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="submit_form();" style="width:110px;" disabled="disabled">App. Mgr</a>-->
            <?php } ?>
    
            <a id="save_button" 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_purchases"; ?>/proses_post_data_prefernce_purchase_account','#preference_purchase_account');
			//$("#preference_purchase_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_purchases/cek_app_purchase",
				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_purchases/combo_list_payable",
				data: "item_id="+item_id,
				cache: false,
				success: function(msg){
					$("#select_account_pi_payablee").combobox('select', msg);
				}
			});
			
			$.ajax({
			    type: "POST",
				url: "<?php echo base_url(); ?>setup/preference_purchases/combo_list_advance_purchase",
				data: "item_id="+item_id,
				cache: false,
				success: function(msg){
					$("#select_account_advance_purchase").combobox('select', msg);
				}
			});
			
			$.ajax({
			    type: "POST",
				url: "<?php echo base_url(); ?>setup/preference_purchases/combo_list_discount_invoice",
				data: "item_id="+item_id,
				cache: false,
				success: function(msg){
					$("#select_account_discount_invoice").combobox('select', msg);
				}
			});
			
			$.ajax({
			    type: "POST",
				url: "<?php echo base_url(); ?>setup/preference_purchases/combo_list_discount_payment",
				data: "item_id="+item_id,
				cache: false,
				success: function(msg){
					$("#select_account_discount_payment").combobox('select', msg);
				}
			});
			
			$.ajax({
			    type: "POST",
				url: "<?php echo base_url(); ?>setup/preference_purchases/combo_list_taxable_purchase",
				data: "item_id="+item_id,
				cache: false,
				success: function(msg){
					$("#select_account_taxable_purchase").combobox('select', msg);
				}
			});

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

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