<!--
Author 		  : Tagor
Last update   : 24/09/2014
Revisi        : 
-->

<?php
			//---------Untuk privellege jika dia ada tombol save----------
			if($group_user->AddPrivillage == 1){
				$cek_autority_add 		= "";
			}
			else{
				$cek_autority_add 		= "disabled";
			}
			
			if($group_user->DeletePrivillage == 1){
				$cek_autority_delete 		= "";
			}
			else{
				$cek_autority_delete 		= "disabled";
			}
			
			if($group_user->EditPrivillage == 1){
				$cek_autority_edit 		= "";
			}
			else{
				$cek_autority_edit 		= "disabled";
			}
			
			//-------------end----------------------------
?>	

	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',border:false" style="height:30px">
			<div style="padding:2px">
				<a href="#" class="easyui-linkbutton" id="new-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="parent.tab_add('New <?=$menu_label?>', '<?=$menu_link?>', 'icon-add', 'add')" <?php echo $cek_autority_add;?>>New</a>
				<a href="#" class="easyui-linkbutton" id="edit-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="edit_data()" <?php echo $cek_autority_edit;?>>Edit</a>
           		<a href="#" class="easyui-linkbutton" id="suspend-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="suspen_data()" <?php echo $cek_autority_delete;?>>Suspend</a>
				<a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="tab_reload()">Refresh</a>
				<a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true,iconCls:'icon-print'" onclick="parent.tab_add('Print <?php echo $menu_label; ?>', '<?php echo $menu_link; ?>', 'preview', 'to_preview')">Print Preview</a>
			</div>
		</div>
		
		<div data-options="region:'west',split:true,border:true" title="Filter"style="width:190px; background-color:#CCCCFF;">
			<div style="padding:5px">
				<form class="form-filter">
                <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td style="padding-bottom:8px;">
                        <b>Find</b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="txt_IDNumber" name="txt_IDNumber"  placeholder="< Prod. No. >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="txt_desc" name="txt_desc"  placeholder="< Description >" style="margin:2px 0px 3px;width:172px;height:22px;border:1px solid #CCC">
                    </td>
                </tr>
                <tr><td><div class="tr-divider"></div></td></tr>
                <!-------copy company dari sini------------------------------------------------------------------------->
				<tr>
					<td align="left" style="padding-bottom:8px;">
						<b>by Company</b>
					</td>
				</tr>
				<tr>
					<td align="left">
					  <select name="cmb_company" id="cmb_company" 
						class="easyui-combobox" 
						style="width:174px;"
						data-options="
							value:'<?php echo $this->session->userdata('company');?>',
						   
							valueField:'CompanyCode',
							textField:'CompanyName',
							url:'<?php echo base_url(); ?>custom/get_data/company_find_master',
							onSelect: function(rec){
								var url = '<?php echo base_url(); ?>custom/get_data/branch_by_company_new/'+rec.CompanyCode;
									$('#cmb_branch').combobox('reload', url);
									$('#cmb_branch').combobox('setValue', '');
								}
						"editable="false"
					>
					
					</select>
					</td>
				</tr>
				<!------------end-------------------------------------------------------------------------------->
				
				<!-------copy branch dari sini------------------------------------------------------------------------->
				<tr>
					<td align="left" style="padding-bottom:8px;">
						<b>by Branch/Depo</b>
					</td>
				</tr>
				<tr>
					<td align="left">
					   <select name="cmb_branch" id="cmb_branch" 
							class="easyui-combobox" 
							style="width:174px;"  
							data-options="
								value :'<?php echo $this->session->userdata('branch');?>',
								valueField:'BranchCode', 
								textField:'BranchName', 
								url:'<?php echo base_url(); ?>custom/get_data/branch_by_company_new/<?php echo $this->session->userdata('company');?>'
							" editable="false" 
						>
						
						</select>
					</td>
				</tr>
				<!------------end-------------------------------------------------------------------------------->
				
				<!--ini separator--------------------------------------------->
				<tr><td colspan="2"><div class="tr-divider"></div></td></tr>
				<!--end-------------------------------------------------------->
				
				<!--ini separator--------------------------------------------->
				<tr><td colspan="2"><div class="tr-divider"></div></td></tr>
				<!--end-------------------------------------------------------->
				
				<!-----------------find by date------------------------------------------------------------------------->
				<tr>
					<td style="padding-bottom:8px;">
						<b>by Date</b>
						<input type="checkbox" name="chk_ByDateNew" value="1" id="chk_ByDateNew" style="float:right;" />
					</td>
				</tr>
				<tr>
					<td>
						From
						<span style="float:right;">
							<input name="txt_DateFrom" id="txt_DateFrom" type="text" class="easyui-datebox " style="width:100px;height:22px;" editable="false" disabled />
						</span>
					</td>
				</tr>
				<tr>
					<td>
						To
						<span style="float:right;">
							<input name="txt_DateTo" id="txt_DateTo" type="text" class="easyui-datebox " style="width:100px;height:22px;" editable="false" disabled />
						</span>
					</td>
				</tr>
				<!----------------------------------------------end-------------------------------------------------------------->
				
				<!---------------ini separator------------------------>
				<tr><td><div class="tr-divider"></div></td></tr>
				<!----------------end--------------------------------->
				
				<!----------------------------------ini by status----------------------------------------------------------->
				<tr>
					<td style="padding-bottom:8px;"><b>by Status</b></td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="0" style="margin-left:0px;"  /> Waiting For DP
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="1" style="margin-left:0px;"  /> On Progress
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="2" style="margin-left:0px;"  checked/> Finished
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="3" style="margin-left:0px;"  /> Suspended
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="4" style="margin-left:0px;"  /> Need App. Mgr.
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="5" style="margin-left:0px;"  /> Need App. Dir.
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="6" style="margin-left:0px;"  checked/> App. Dir &amp; Mgr
					</td>
				</tr>
				<tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="7" style="margin-left:0px;"  /> App. Limit
					</td>
				</tr>
				
				 <tr>
					<td>
						<input type="checkbox" name="chk_TransStatus" value="9" style="margin-left:0px;" /> Cancel By Dir.
					</td>
				</tr>
				<!------------------------------------------------------end-------------------------------------------------------------------------------------------->
				
				<!--copy dari sini untuk button reset dan search-->
				<tr>
					<td height="38"><div style="float:right;"><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onClick="location.reload();" >Reset</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onClick="searching_data_transaksi();" >Search</a></div></td>
				</tr>
				<!--end-------------------------->
                </table>
                </form>
			</div>
		</div>
		
		<div data-options="region:'center',border:false,iconCls:'icon-ok'">
			<!-- gaya table baru di grid -->
			<table id="grid" 
				title="" iconCls="icon-edit" 
				singleSelect="true" rowNumbers="true" 
				pageSize="50" 
				fitColumns="true" remoteSort="false" 
				url="<?=base_url($menu_link.'/ajax')?>" 
				style="width:auto;height:560px" 
				data-options = "border:false,view:scrollview,autoRowheight:false"
			> 	
				<thead>
					<tr>
						<th halign="center" data-options="field:'BranchName',width:150,align:'left'" sortable="true">Branch</th>
						<th halign="center" data-options="field:'ProdNumber',width:170,align:'left'" sortable="true">Prod. No.</th>
						<th halign="center" data-options="field:'ProdDate',width:90,align:'center'" sortable="true" formatter="formatDate">Date</th>
						<th halign="center" data-options="field:'ProdDesc',width:350,align:'left'">Description</th>
						<th halign="center" data-options="field:'Status',width:165,align:'center'" sortable="true">Status</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	
<script type="text/javascript">
$(document).ready( function(){
	$('.filter_date').datebox({
		onSelect: function(date){
			search_master();
		}
	});	
	
	/*===chk_ByDateNew jangan lupa ganti ============*/
	$('#chk_ByDateNew').click(function(){
		if( $(this).is(':checked') ){
			$('#txt_DateFrom').datebox('enable', true);
			$('#txt_DateTo').datebox('enable', true);
			$('#txt_DateFrom').datebox('setValue', '<?=date('01-m-Y')?>');
			$('#txt_DateTo').datebox('setValue', 'today');
		}
		else{
			$('#txt_DateFrom').datebox('disable', true);
			$('#txt_DateTo').datebox('disable', true);
			$('#txt_DateFrom').datebox('setValue', '');
			$('#txt_DateTo').datebox('setValue', '');
		}
		
	});
	/*==================end=========================*/
	
	var status_privelage_delete = '<?php echo $group_user->DeletePrivillage;?>';
	var status_privelage_edit 	= '<?php echo $group_user->EditPrivillage;?>';
	$('#grid').datagrid({
		onDblClickRow:function(){
			if(status_privelage_edit == 1){
				parent.tab_edit('Edit Daily Production', '<?php echo $menu_link; ?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').ProdNumber);
			}
		},
		onClickRow:function(index,value){
			if(value.Status !='Need App. Dir & Mgr' || value.Status !='App. Limit' || value.Status != 'Active'){
				$('#suspend-linkbutton').linkbutton('enable');
			}
			else{
				if(status_privelage_delete == 1){
					$('#suspend-linkbutton').linkbutton('enable');
				}
				else{
					$('#suspend-linkbutton').linkbutton('disable');
				}
				
				if(status_privelage_edit == 1){
					$('#edit-linkbutton').linkbutton('enable');
				}
				else{
					$('#edit-linkbutton').linkbutton('disable');
				}
			}
		}
	});
});

function suspen_data(){
	var selected_data=$('#grid').datagrid('getSelected');
	if(selected_data.Status == "Cancel"){
		$.messager.alert('Unseccessfull','Data sudah di cancel','error',function(){	
		$('#grid').datagrid('reload'); 	
		});
	}
	else{
		delete_data('<?php echo $menu_link; ?>', $('#grid').datagrid('getSelected').ProdNumber);
	}
}

function edit_data(){
	var selected_data=$('#grid').datagrid('getSelected');
	if(selected_data.Status == "Cancel"){
		$.messager.alert('Unseccessfull','Data sudah di cancel','error',function(){	
			$('#grid').datagrid('reload'); 	
		});
	}
	else{
		parent.tab_edit('Edit Daily Production', '<?php echo $menu_link; ?>', 'icon-edit', 'edit', $('#grid').datagrid('getSelected').ProdNumber);
	}
}
</script>