<!---- 
    Author 	: Ladur / Tanggal : 12-08-2014	
    Revisi 	: Ferry / Tanggal : 17-02-2014
-->
<?php 
//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete  = "";
	}
	else{
		$cek_autority_delete 	= "disabled";
	}
	
	if($group_user->ReversePrivillage == 1){
		$cek_autority_reverse  = "";
	}
	else{
		$cek_autority_reverse 	= "disabled";
	}
//-------------end----------------------------

if($detail->TransStatus == 0 || $detail->TransStatus == 1) {
	$class_datagrid = "class='easyui-edatagrid'";
	$btn_print 		= "";
	$btn_cancel 	= "";
}
else if($detail->TransStatus == 3 || $detail->TransStatus == 9 || $detail->ItemQtySO > 0) {
	$class_datagrid = "class='easyui-datagrid'";
	$btn_print 		= "";
	$btn_cancel 	= "disabled";
}
else {
	$class_datagrid = "class='easyui-datagrid'";
	$btn_print 		= "";
	$btn_cancel 	= "disabled";
}
?>
<div class="easyui-layout" data-options="fit:true,border:false">
    <!-- top view-->
    <div id="form-header" data-options="region:'north',border:false">
        <div id="form-header-wrapper">
            <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td align="left" width="30%">
                    <input type="checkbox" class="input" name="chk_suspended" id="chk_suspended" value="1" onclick="suspend(1);" <?php if($detail->TransStatus == 3){ echo"checked"; } ?> <?php if(in_array($detail->TransStatus,array(3)) || ($detail->ItemQtySO>0)){echo 'disabled';}?> <?php echo $cek_autority_delete;?>/>
                    <span style="display:inline-block;margin-top:2px;<?=(($detail->TransStatus==3)?'color:gray;':'color:black')?>">Suspend</span>
                    
                    <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload()">Refresh</a>
                   	<a href="#" class="easyui-linkbutton" iconCls="icon-currency" plain="true" onclick="to_transaction()" <?=in_array($detail->TransStatus,array(1))?'':'disabled';?>>To Sales Order</a>
                </td>
                <td align="center" width="40%"><span id="approval_information">
                <?php
				if($detail->TransStatus==4){
					if($this->session->userdata('jobtitle')=='MGR'){
						echo '<span style="color:#F00;font-size:14px;font-weight:bold;text-decoration:underline;">Need Your Approval</span>';
					}
					else{
						echo '<span style="color:#F00;font-size:14px;font-weight:bold;text-decoration:underline;">Need Manager Approval</span>';
					}
				}
				else if($detail->TransStatus==1){
					echo '<span style="color:#F00;font-size:14px;font-weight:bold;text-decoration:underline;">On Progress</span>';
				}
				?>
                </span></td>
                <td align="right" width="30%">
                    <span class="form-title"><?=$menu_label?></span>							
                </td>
            </tr>
            </table>	     	
        </div>			
    </div>
    <!-- end top view -->	

    <!-- center view -->
    <div id="form-body" data-options="region:'center',border:false">
        <div id="form-wrapper" class="easyui-panel" style="padding:5px;" fit="true">
        	<?php if(in_array($detail->TransStatus,array(2,3,8,9))){ ?>
        	<div class="blanket"></div>
            <div class="status-box"><b><?php if($detail->TransStatus==2){ echo 'Finished'; }elseif($detail->TransStatus==3){ echo 'Suspended'; }elseif($detail->TransStatus==8){ echo 'Item Suspended'; }elseif($detail->TransStatus==9){ echo 'Canceled by Dir.'; }else{ echo 'Unknown'; } ?></b></div>
            <?php } ?>
        
            <form id="frm_sales_quotation" name="frm_sales_quotation" method="post">
                <input type="hidden" name="hdn_detail" id="hdn_detail"/>
                <input type="hidden" name="hdn_sq_no" id="hdn_sq_no" value="<?=$detail->SQuoNumber?>"/>
                <input type="hidden" name="detail_id" id="detail_id">
                
            	<!-- Form Header -->
                <table width="100%" height="140" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr height="26">
                            <td width="135"><b>Customer</b></td>
                            <td width="10"><b>:</b></td>
                            <td colspan="5">
                                <select class="easyui-combogrid" id="cbg_customer" 
                                	name="cbg_customer" required readonly 
                                    style="width:320px;height:20px;" 
                                    data-options="
                                    	value:'<?=$detail->CustomerCode?>',
                                        panelWidth: 320,
                                        idField: 'CustomerCode',
                                        textField: 'CustomerName',
                                        url: '<?=base_url()?>custom/get_data/customer',
                                        method: 'get',
                                        columns: [[
                                            {field:'CustomerCode',title:'Customer Code',width:110,halign:'center'},
                                            {field:'CustomerName',title:'Customer Name',width:190,halign:'center'}
                                        ]],
                                        fitColumns: true
                                    ">
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                            <td><b>Billing Address</b></td>
                            <td width="10"><b>:</b></td>
                            <td>&nbsp;</td>
                            <td width="120"><b>Shipping Address</b></td>
                            <td width="10"><b>:</b></td>
                            <td>&nbsp;</td>
                            <td width="114" rowspan="2">&nbsp;</td>
                        </tr>
                        <tr height="20">
                            <td colspan="3">
                                <textarea name="txa_address" id="txa_address" rows="4" style="width:225px;resize:none;" readonly><?php echo $detail->BillingAddress; ?></textarea>
                            </td>
                            <td colspan="3">
                                <textarea name="txa_ship_to" id="txa_ship_to" rows="4" style="width:225px;resize:none;" <?=(in_array($detail->TransStatus,array(2)) || ($detail->ItemQtySO>0))?'readonly':''?>><?php echo $detail->ShippingAddress; ?></textarea>
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr height="20">
                            <td rowspan="7" valign="top">&nbsp;</td>
                            <td width="121">&nbsp;</td>
                            <td width="190" style="background:#333399;text-align:center;color:#FFF;">SQuo. No.</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">SQuo. Date</td>
                        </tr>
                        <tr height="20">
                            <td>&nbsp;</td>
                            <td><input type="text" name="txt_sq_no" id="txt_sq_no" class="easyui-validatebox textbox" value="<?php echo $detail->SQuoNumber; ?>" style="width:190px;height:18px;text-align:center;" required readonly /></td>
                            <td><input type="text" name="txt_sq_date" id="txt_sq_date" class="easyui-datebox" value="<?=convert_to_dmy($detail->SQuoDate)?>" style="width:122px;height:20px" required readonly editable="false" /></td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Cust. POrd. No.</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Cust. POrd. Date</td>
                        </tr>
                        <tr height="20">
                            <td>&nbsp;</td>
                            <td><input type="text" name="txt_po_no" id="txt_po_no" class="easyui-validatebox textbox" value="<?php echo $detail->CustPONumber; ?>" style="width:190px;height:18px;text-align:center;" required <?=($detail->ItemQtySO>0)?'readonly':''?> /></td>
                            <td><input type="text" name="txt_po_date" id="txt_po_date" class="easyui-datebox" style="width:122px;height:20px" required <?=($detail->ItemQtySO>0)?'readonly':''?> editable="false" /></td>
                        </tr>
                        <tr height="20">
                            <td>&nbsp;</td>
                            <td colspan="2">
                            	<b>Salesman : </b>
                            	<select colspan="2" class="combo-grid" 
                                	id="cbg_salesman" name="cbg_salesman" 
                                	required style="width:243px;height:20px;" 
                                    <?=($detail->ItemQtySO>0 or $this->session->userdata('jobtitle_status')==3)?'readonly':''?>
                                    data-options="
                                        panelWidth: 243,
                                        idField: 'EmployeeCode',
                                        textField: 'EmployeeName',
                                        value:'<?=$detail->SalesmanCode?>',
                                        url: '<?php echo base_url(); ?>custom/get_data/sales',
                                        method: 'get',
                                        columns: [[
                                            {field:'EmployeeCode',title:'Employee Code',width:120,halign:'center'},
                                            {field:'EmployeeName',title:'Employee Name',width:150,halign:'center'}
                                        ]],
                                        fitColumns: true
                                    ">
                                </select>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>
                <!-- End of form header -->
		
                <!--Datagrid-->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div id="tab_general" title="Items">
                        <table id="dtg_item" 
                            url="<?=base_url() . $menu_link ."/ajax_item/". $detail->SQuoNumber?>"
                            toolbar="#toolbar" idField="SQuoDetailID" 
                            rowNumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:250px;"
                        >
                            <thead>
                            <tr>
                                <th field="ItemCode" 		width="50" data-options="align:'left',halign:'center'" 		editor="{type:'item_inventory',options:{required:true}}" >Item Code</th>
                                <th field="ItemDesc" 		width="280" data-options="align:'left',halign:'center'" 	editor="description" >Description</th>
                                <th field="ItemQty" 		width="40" 	data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0.01,required:true}}" formatter="formatRp">Qty</th>
                                <th field="ItemQtySO" 		width="40" 	data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:'true'}}" formatter="formatRp" >Qty SO</th>
                                <th field="ItemQtyDO" 		width="40" 	data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:'true'}}" formatter="formatRp">Qty DO</th>
                                <th field="ItemUnit" 		width="30" 	data-options="align:'center',halign:'center'" 	editor="unit">Unit</th>
                                <th field="RequiredDate" 	width="50" 	data-options="align:'center',halign:'center'" 	editor="{type:'datebox',options:{editable:false}}" formatter="formatDate">Required Date</th>
                                <th field="Status" 			width="35" 	data-options="align:'center',halign:'center'"	editor="{type:'checkbox',options:{on:'Yes',off:'No'}}"	halign="center" align="center" >Close</th>
                                <th field="Memo" 			width="100" data-options="align:'left',halign:'center'" 	editor="{type:'text'}">Memo</th>
                                
                                
                                <th field="ItemQtySpd" 			width="50" data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:'true'}}" formatter="formatRp" hidden>Qty Suspend</th>
                                <th field="SQuoDetailID" 		width="50" data-options="align:'center',halign:'center'" 	editor="{type:'numberbox'}" hidden>SQuo Detail ID</th>
                                <th field="ItemCategoryID" 		width="50" data-options="align:'center',halign:'center'" 	editor="{type:'item_category',options:{readonly:true}}" hidden>Category ID</th>
                                <th field="TempQty" 			width="50" data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:'true'}}" formatter="formatRp" hidden>Qty Temp</th>
                                <th field="RowStatus" 			width="50" data-options="align:'center',halign:'center'" 	editor="{type:'numberbox'}" hidden>Row Status</th>
                            	<th field="ItemCategoryCode" 	width="50" data-options="align:'left',halign:'center'" 		editor="{type:'category_code',options:{readonly:true}}" 	hidden>Item Category Code</th>
                                <th field="ItemStatus"       	width="30" data-options="align:'left',halign:'center'" 		editor="{type:'item_status',options:{readonly:true}}" 		hidden>Item Status</th>
                                <th field="ItemQtyOld" 			width="40" data-options="align:'center',halign:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:'true'}}" formatter="formatRp" 	hidden>Qty Old</th>
                            </tr>
                            </thead>
                        </table>
						
                        <div id="toolbar">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row();" <?=($detail->ItemQtySO>0 || ($detail->TransStatus==3 || $detail->TransStatus==9))?'disabled':''?>>Delete</a>
                        </div>
                    </div>					
                </div>

                <div>
                    <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="32%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                            <tr>
                                <td width="120" valign="top" style="padding-top:4px;"><b>Description</b></td>
                                <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>
                                <td>
                                	<textarea id="txa_description" name="txa_description" rows="4" style="width:323px;resize:none;" <?=($detail->ItemQtySO>0)?'readonly':''?>><?=$detail->SQuoDesc?></textarea>
                                </td>
                            </tr>
                            </table>
                        </td>
                        <td width="13%" valign="top">
                        	<input type="hidden" name="hdn_sub_total" id="hdn_sub_total" value="0"/>
                        </td>
                    </tr>
                    </table>
                </div>	
			</form>		
        </div>
    </div>
	
    <div id="form-footer" data-options="region:'south',border:false">
    	<table width="100%" cellpadding="0" cellspacing="0">
        <tr>
        	<td>
                <b>Old SQuo. No. : </b>
                <?=$detail->OldSQuoNumber?>
            </td>
            <td align="right">
            	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-document" onclick="show_legend();" plain="true">Legend</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" plain="true">Help</a>
<!--                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-reload" onclick="reverse_data()" <?=(in_array($detail->TransStatus,array(1)))?'disabled':''?> <?php echo $cek_autority_reverse;?>>Reverse</a> 
-->                <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="update_data()" <?=(in_array($detail->TransStatus,array(0,3,9,8,2)) || ($detail->ItemQtySO>0))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_add('Form <?=$menu_label?>', '<?=$menu_link?>', 'icon-print', 'to_print_detail/<?=$detail->SQuoNumber?>');" <?=(in_array($detail->TransStatus,array(1,0,2,3,4,5,6)))?'':'disabled'?>>Preview & Print</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0?'suspend(2)':'parent.tab_close(\'tt\')')?>" <?=$btn_cancel?>><?=($this->session->userdata('jobtitle_status')==0?'Cancel':'Close')?></a>	
    		</td>
         </tr>
         </table>
    </div>	
</div>
<?php $this->load->view('v_custom_pop_up');?>

<script type="text/javascript">

/*========================deklar variabel array for remove===================*/
var array_item 		= [];
/*==============================end=========================================*/
var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';

$(document).ready(function(){
	suspend_item_checkbox = false;
	
	$('#txt_sq_date').datebox('setValue','<?=convert_to_dmy($detail->SQuoDate)?>');
	$('#txt_po_date').datebox('setValue','<?=convert_to_dmy($detail->CustPODate)?>');

	$("#frm_sales_quotation" ).click(function() {
    	$('#dtg_item').edatagrid('saveRow');
	});
	
	$('#cbg_customer').combogrid({
		onSelect:function(rowIndex, rowData){
			var Address = rowData.CustomerAddress + ', ' + rowData.CustomerCityName + ', ' + rowData.CustomerStateName + ', ' + rowData.CustomerCountryName;

			$('#txa_address').val( Address );
			$('#txa_ship_to').val( Address );	
		}
	});

	$('#txt_sq_date').datebox({
		onChange:function(){
			url 		= base_url +'list/sales_quotation/get_squo_number';                
			SQouDate 	= $('#txt_sq_date').datebox('getValue');

			$.post(url, {SQouDate:SQouDate}, function(result){
				if (result.status === true){
					$('#txt_sq_no').val(result.number);
				} 
			},'json');
		}
	});        
        
	$('#dtg_item').edatagrid({
		/*onLoadSuccess: function(){
			dg          = $('#dtg_item').datagrid('getRows');
			flag = true;
			$.each(dg, function(index, value){
				if(value.ItemQtySO > 0){
					flag = false;
				}
			});
			if(flag == false){
			$('.item_inventory').attr('onClick','return false');
				$('.item_inventory').css({
					'background':'#EBEBE4',
					'cursor':'default'
				});
			}
		},*/
		onBeginEdit:function(index,value){
			var editors = $('#dtg_item').datagrid('getEditors',index);
			var n1 = $(editors[2].target);  //Item Qty
			var n2 = $(editors[7].target);  //Suspend Status
			var n3 = $(editors[8].target);  //Suspend Memo
			var n4 = $(editors[3].target);  //Qty SO
			var n5 = $(editors[9].target);  //Qty Suspend
//          var n7 = $(editors[9].target);  //SQuoDetailID
			var n8 = $(editors[13].target); //Row Status
			var n9 = $(editors[6].target);  //Row Status
			var n10 = $(editors[16].target); //Old Qty
			
			if(suspend_item_checkbox===true){
				n2.prop('disabled',true);
			}
			
			save_button_begendedit(SavePrivillage);
				
			n3.prop('readonly',true);
			if(n4.numberbox('getValue') > 0 || n2.is(':checked')){
				n1.prop('readonly',true);
				n2.attr('onClick','return false');
				n9.datebox('disable');
				$('.item_inventory').attr('onClick','return false');
				$('.item_inventory').css({
					'background':'#EBEBE4',
					'cursor':'default'
				});
			}
			
			n2.click(function(){
				if($(this).is(':checked')){
					var itemqty		= n1.numberbox('getValue');
					var itemqtyso	= n4.numberbox('getValue');
					var itemqty_old	= n10.numberbox('getValue');
											
					var suspend_qty = parseFloat(itemqty_old) - parseFloat(itemqtyso);
					
					n5.numberbox('setValue', suspend_qty);
					n8.numberbox('setValue', 1);
					suspend_item(1);                            
				}
				else{
					n8.numberbox('setValue', 1);
					suspend_item(0);
				}
			});
		},
		onEndEdit:function(){
			
			if('<?php echo $detail->ItemQtySO;?>' == 0){
				save_button_endedit(SavePrivillage);
			}
				
			if(suspend_item_checkbox===true){
				suspend_item_checkbox=false;
			}
		}
	});
	
	datagrid_item_type_status("dtg_item");//untuk warna grid  
});

function remove_row(){
	var item = $('#dtg_item').datagrid('getData').total;

	if(item <= 1){
		$.messager.alert('Warning','Anda tidak dapat menghapus list item, minimum list item adalah satu (1)','error');
	}
	else {
		var selectedrow     = $('#dtg_item').datagrid('getSelected');
		var row_index       = $('#dtg_item').datagrid('getRowIndex', selectedrow);

		$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.ItemCode + '"',  
			function(r){
				if (r){
					array_item.push(selectedrow.SQuoDetailID);
                   	$("#detail_id").val(JSON.stringify(array_item));
                   	$('#dtg_item').datagrid('deleteRow', row_index);
					
					save_button_endedit(SavePrivillage);
				}
			}
		);        
					
	}            
}

function update_data() {
	$('#dtg_item').edatagrid('saveRow');
	check 	= $('#dtg_item').datagrid('getRows');
	err_qty = 0;
	
	var url             	= '<?= base_url();?>custom/custom/checking_update';
	var no_transaksi    	= $('#txt_sq_no').val();
	var trans_status 		= '<?=$detail->TransStatus?>';
	
	var created_by 		= '<?php echo $detail->CreatedBy;?>';
	var login_as 		= '<?php echo$this->session->userdata('username');?>';
	var job_title 		= '<?php echo $this->session->userdata('jobtitle_status');?>';
		
	$.each(check, function(index,value) {
		if(parseFloat(value.ItemQty) == 0) {
			err_qty++;
		}
	});
	
	if(err_qty > 0) {
		$.messager.alert('Unseccessfull','Qty tidak Boleh bernilai 0.','error',function(){	
			$('#dtg_item').datagrid('reload'); 	
		});
	}
	else {
		$('#dtg_item').edatagrid('saveRow');		

		var i       = $('#dtg_item').datagrid('getRows');
		var detail  = JSON.stringify(i);

		$("#hdn_detail").val(detail);
		edit_transaction_not_check('<?=$menu_link?>','#frm_sales_quotation', no_transaksi, url, trans_status,created_by, login_as, job_title);										
	}								
}

function reverse_data(){
	var i       = $('#dtg_item').datagrid('getRows');
	var detail  = JSON.stringify(i);
	
	$("#hdn_detail").val(detail);
	reverse_data_by_detail('<?=$menu_link?>','#frm_sales_quotation', 0);	
}

function suspend_item(status) {        
	$('#dtg_item').edatagrid('saveRow');
	url = base_url +'list/sales_quotation/suspend_item';

	message_text    = '';
	squo_number     = $("#txt_sq_no").val();
	detail          = JSON.stringify($('#dtg_item').datagrid('getRows'));

	if(status == 0) {
    	message_text = 'Anda yakin, ingin melakukan UnSuspend item?';
	}
	else{
    	message_text = 'Anda yakin, ingin melakukan Suspend item?';            
	}

	$.messager.confirm('Warning :', message_text,  
		function(r){
			if (r){
				$.post(url, {squo_number:squo_number, detail:detail}, function(result){
					if (result.status == true){
						$.messager.alert('Success',result.message,'info',function(){
							location.reload();
							//$('#dtg_item').datagrid('reload');						                    
						});				
					} 
					else {
						$.messager.alert('Error',result.message,'error',function(){
							location.reload();
							//$('#dtg_item').datagrid('reload');						                    
						});				
					}
				},'json');
			}
			else {
				//location.reload();
				$('#dtg_item').datagrid('reload');						                    
			}
		}
	);
}

function suspend(type){
	var created_by 		= '<?php echo $detail->CreatedBy;?>';
	var login_as 			= '<?php echo$this->session->userdata('username');?>';
	var job_title 			= '<?php echo $this->session->userdata('jobtitle_status');?>';
	var url             = '<?= base_url();?>custom/custom/checking_suspend';
	
	//suspend_check_trans('F', type, '<?=$menu_link?>', $('#txt_sq_no').val(), 'Sales Quotations', url, created_by, login_as, job_title);
	suspend_data_new('F', type, '<?=$menu_link?>', $('#txt_sq_no').val(), 'Sales Quotations');
}

$.extend($.fn.datagrid.defaults.editors, {
    item_inventory: {
        init: function(container, options){
            var input = $('<input type="text" class="item_inventory" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
            
    item_category: {
        init: function(container, options){
            var input = $('<input type="text" class="item_category" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	
    description: {
        init: function(container, options){
            var input = $('<input type="text" class="description" style="width:350px;height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
            
    unit: {
        init: function(container, options){
            var input = $('<input type="text" class="unit" style="width:82px;height:18px;text-align:center;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
            
    price: {
        init: function(container, options){
            var input = $('<input type="text" class="price" style="height:18px;" onChange="get_amount(this.value)" />').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	  
    qty: {
        init: function(container, options){
            var input = $('<input type="text" class="qty" onChange="get_amount(this.value)" style="height:18px;" />').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	
    item_status: {
        init: function(container, options){
            var input = $('<input type="text" class="item_status" style="height:18px;" readonly/>').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    },
	
    max_item: {
        init: function(container, options){
            var input = $('<input type="text" class="max_item" style="height:18px;" readonly />').appendTo(container);
            return input.validatebox(options);
        },
        destroy: function(target){
            $(target).remove();
        },
        getValue: function(target){
            return $(target).val();
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        resize: function(target, width){
            $(target)._outerWidth(width);
        }
    }
});

function to_transaction(){
    var appfinished         = '<?=$detail->TransStatus;?>';
    var no_transaksi        = $('#txt_sq_no').val();
    var customer_code       = $('#cbg_customer').combogrid('getValue');
    var no_trans            = no_transaksi.replace(/\//g,"__");
    var customer_code       = customer_code.replace(/\//g,"__");


    if(appfinished == 1){
        parent.tab_add('New Sales Order','list/sales_order','icon-add','add/'+no_trans+'/'+customer_code);
    }else{
        $.messager.alert('Unseccessfull','TransStatus Finished. Transaksi selesai.','error',function(){
            //location.reload();
        });
    }
    
}
</script>