<!---- 
    Author 	: Ladur / 12-08-2014	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
//-------------end----------------------------
?>
<style>
.datagrid-header-row [field='ck'] input{
	display:none;
}
</style>

<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 cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="left" valign="middle">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Delivery Order', '<?=$menu_link?>', 'icon-add', 'add')">New</a>
                	<a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload()">Refresh</a>
                </td>							
                <td align="right">								
                    <span class="form-title"><?=$menu_label?></span>
                </td>
            </tr>
            </table>	
        </div>			
    </div>
    <!-- End of 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">
            <form id="fm_delivery_order" name="fm_delivery_order" method="post">
				<input type="hidden" name="detail" id="detail" />
                <input type="hidden" min="0" name="do_total_amount" id="do_total_amount" class="easyui-numberbox" value="0" style="text-align:right;" readonly 
                    data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                    formatter:function(v){
                        return v;
                    },
                    parser:function(s){
                        var v = parseFloat(s);
                        return v;
                    }
                    " 
                />	
                <!-- 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="20">
                            <td width="135"><b>Customer</b></td>
                            <td width="10"><b>:</b></td>
                            <td colspan="5">
                                <select class="combo-grid" id="cmb_customer" 
                                	name="cmb_customer" required
                                	style="width:150px;height:20px;" 
                                    data-options="
                                        panelWidth: 370,
                                        idField: 'CustomerCode',
                                        textField: 'CustomerName',
                                        url: '<?=base_url()?>custom/get_data/customer_with_rate',
                                        method: 'get',
                                        columns: [[
                                        {field:'CustomerCode',title:'Customer Code',width:110,halign:'center'},
                                        {field:'CustomerName',title:'Customer Name',width:190,halign:'center'}
                                        ]],
                                        fitColumns: true
                                    "
                                >
                                </select> 
                                <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-sales'" onClick="choose_customer()">Select SOrd.</a>
                          </td>
                        </tr>
                        <tr id="rowRate">
                        	<!--<td><b>Currency Code/Rate</b></td>
                            <td><b>:</b></td>-->
                            <td colspan="5">
                            	<input type="hidden" name="txt_currency_code" id="txt_currency_code" style="width:55px" required readonly />  
                                <input type="hidden" id="txt_rate" name="txt_rate" value="" class="easyui-numberbox" style="width:80px;text-align:right;" required readonly
                                	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                            	<span id="currency_code"></span>
                            </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></textarea>
                            </td>
                            <td colspan="3">
                                <textarea name="txa_ship_to" id="txa_ship_to" rows="4" style="width:225px;resize:none;"></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="190" style="background:#333399;text-align:center;color:#FFF;">SOrd. No.</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">DOrd. Date</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">Ship Via</td>
                        </tr>
                        <tr height="20">
                            <td height="20" width="100" align="center" valign="middle">
                            	<input type="text" name="txt_so_no" id="txt_so_no" class="easyui-validatebox textbox" style="width:190px;height:18px;text-align:center;" required readonly />
                            </td>
                            <td width="100" align="center" valign="middle">
                                <input name="txt_do_date" id="txt_do_date" type="text" class="easyui-datebox validBackward" value="<?=$do_date?>" style="width:122px;height:20px" required editable="false" />
                            </td>
                            <td>
                                <select name="cmb_ship_via" id="cmb_ship_via" 
                                    class="easyui-combobox" editable="false" readonly
                                    data-options="
                                        valueField:'ShipmentID',
                                        textField:'ShipmentName',
                                        url:'<?php echo base_url(); ?>custom/get_data/shipment'
                                    " 
                                    style="width:122px;height:20px;"
                                >
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                            <td style="background:#333399;text-align:center;color:#FFF;">Cust. POrd. No.</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Ship Date</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Driver</td>
                        </tr>
                        <tr height="20">
                            <td><input type="text" name="txt_po_no" id="txt_po_no" class="easyui-validatebox textbox" style="width:190px;height:18px;text-align:center;" required readonly /></td>
                            <td><input name="txt_ship_date" id="txt_ship_date" type="text" class="easyui-datebox validBackward" style="width:122px;height:20px;" required editable="false" /></td>
                            <td><input type="text" name="txt_driver" id="txt_driver" class="easyui-validatebox" style="width:120px;"  /></td>
                        </tr>
                        <tr height="20">
                            <td ></td>
                            <td>&nbsp;</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">License Plate</td>
                        </tr>
                        <tr height="20">
                            <td></td>
                            <td></td>
                            <td><input type="text" name="txt_car_number" id="txt_car_number" class="easyui-validatebox" style="width:120px;" /></td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>

                <!-- End of form header -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div id="tab_item" title="Items">
                        <table id="dg_item"
                        	url="<?=base_url() . $menu_link . "/ajax_item/"?>"
                            toolbar="#toolbar" idField="id" 
                            rownumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:250px;"
                        >
                            <thead>
                            <tr>
                                <th field="ItemCategoryID" 	width="10" 	data-options="halign:'center',align:'center'" hidden>Item Category ID</th>
                                <th field="SOrdDetailID" 	width="10" halign="center" align="left" hidden>SOrdDetailID</th>
                                <th field="SOrdNumber" 		width="40" 	data-options="halign:'center',align:'left'" editor="{type:'text'}">SOrd. No.</th>
                                <th field="ItemCode" 		width="30" 	data-options="halign:'center',align:'left'">Item Code</th>
                                <th field="ItemDesc" 		width="100" data-options="halign:'center',align:'left'">Description</th>
                                <th field="ItemQty" 		width="10" 	data-options="halign:'center',align:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0.01,required:true}}" formatter="formatRp">Qty</th>
                                <th field="ItemUnit" 		width="15" 	data-options="halign:'center',align:'center'">Unit</th>
                                <th field="ItemTaxStatus"	width="15" 	data-options="halign:'center',align:'center'" editor="{type:'numberbox',options:{min:0,readonly:true}}" hidden>Tax Status</th>
                                <th field="ItemPrice"		width="15"	data-options="halign:'center',align:'center'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true, 
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Item Price</th>
                                
                                <th field="TotalAmount" 	width="15"	data-options="halign:'center',align:'center'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Total Amount</th>
                                
                                <th data-options="field:'ItemTax',width:20,halign:'center',align:'center'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Tax Amount</th>
                                
                                <th field="ItemMax"				data-options="width:20,halign:'center',align:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.'}}" formatter="formatRp" hidden>Item Max</th>
                                <th field="InventoryQty"		data-options="width:20,halign:'center',align:'center'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.'}}" formatter="formatRp" hidden>Inventory Qty</th>
                                <th field="IsLock"				data-options="width:20,halign:'center',align:'center'" 	hidden>IsLock</th>
                                <th field="ItemCategoryCode"	data-options="halign:'center',align:'center'" 			width="10" hidden>Item Category Code</th>
                                <th field="ItemStatus"			data-options="halign:'center',align:'center'"			editor="{type:'item_status',options:{readonly:true}}" 	width="30" hidden>Item Status</th>
                                <th field="ItemDiscPcnt"    	data-options="align:'right',halign:'center'"  			editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',min:0}}" formatter="formatRp" hidden>Discount %</th>
                            	<th field="ItemAverage" 		data-options="align:'right',halign:'center'"			width="20" 
                                editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}"
                                hidden>Item Average</th>
                                <th field="AmountDisc"			data-options="width:20,halign:'center',align:'center'" 	editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Amount Disc</th>

                                <th data-options="field:'Item_pph23',width:20,halign:'center',align:'center'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                    return v;
                                },
                                parser:function(s){
                                    var v = parseFloat(s);
                                    return v;
                                }
                                }}" >Tax PPH 23</th>
                            </tr>
                            </thead>
                        </table>
                        
                        <div id="toolbar">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row();">Delete</a>								
                        </div>
                    </div>
                </div>
                <!-- End Item Grid -->
                
                <table width="100%" cellpadding="0" cellspacing="0">                
                <tr>
                	<td width="50%" 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;"></textarea>
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                    	<input type="hidden" name="hdn_taxable" id="hdn_taxable" />
                        <input type="hidden" name="hdn_inclusive" id="hdn_inclusive" />
                        <input type="hidden" name="hdn_ppn_pcnt" id="hdn_ppn_pcnt" />
                    </td>
               	</tr>
                </table>
            </form>
    	</div>
    </div>
    
    <div id="form-footer" data-options="region:'south',border:false">
    	<table width="100%" cellpadding="0" cellspacing="0">
        <tr>
        	<td>&nbsp;</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 id="save_button" href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="insert_data()" <?php echo $cek_autority_save;?>>Save</a> 								
                <a href="javascript:void(0)" class="easyui-linkbutton  form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Close</a>			
    		</td>
        </tr>
        </table>
    </div>
</div>

<div id="dialog-so" class="easyui-dialog" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons" style="width:860px;height:532px;top:27px;background-color:#F8F8F8;padding:5px;"> 
        <div id="tab_purchase_req" class="easyui-tabs" style="width:835px;height:485px; background-color:#F8F8F8;" data-options="fit:true,plain:true">
            <div title="Select Sales Order" style="padding:10px" >
            <table id="tt_choose" 
                url="<?php echo base_url() ?>list/delivery_order/get_data_so"
                remoteSort="false"
                pageSize="150"
                fitColumns="true" 
                rowNumbers="true"
                singleSelect="true"
                style="width:812px;height:400px"
                data-options = "border:true,view:scrollview,autoRowheight:false"
            >
                <thead>
                    <tr>
                        <th field="ck" checkbox="true" width="20"></th>
                        <th field="SOrdNumber" width="150" halign="center" align="left" sortable="true">SOrd. Number</th>
                        <th field="SOrdDate" width="80" halign="center" align="center" formatter="formatDate" sortable="true">SOrd. Date</th>
                        <th field="SOrdDesc" width="300" halign="center" align="left">Description</th>
                    </tr>
                </thead>
            </table>
    
             
            <!-- Dialog Button for Dialog Item-->
            <div style="border:none; margin-top:10px; float:right;">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_item_so();">&nbsp; OK &nbsp; &nbsp;</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-so');">Cancel</a>
            </div>
            <!-- End of Dialog Button for Dialog Item-->
            </div>
         </div>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">
var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
/*==================== Daswan =========================*/
var SOrdNumber      = '<?=$SOrdNumber;?>';
var CustomerCode    = '<?=$CustomerCode;?>';
var load            = 0;
if(SOrdNumber !=''){
    SOrdNumber          = SOrdNumber.replace(/\__/g,"/");
    SOrdNumber          = SOrdNumber.replace(/\_/g,"-");
    CustomerCode        = CustomerCode.replace(/\__/g,"/");
    CustomerCode        = CustomerCode.replace(/\_/g,"-");
}
/*=================== end Daswan =========================*/

$(document).ready(function(){	
	$("#print_button").click(function() { 
		link_print('list/delivery_order/print_preview');
	});
	
	$('#fm_delivery_order').click(function(){
		$('#dg_item').edatagrid('saveRow');
	});
	
	//when vendor selected
	$('#cmb_customer').combogrid({
		onSelect:function(rowIndex, rowData){
			$('#dg_item').datagrid('load',{
				so_number: ''
			});
			
			var Address = rowData.CustomerAddress + ', ' + rowData.CustomerCityName + ', ' + rowData.CustomerStateName + ', ' + rowData.CustomerCountryName;
			
			$('#txa_address').val( Address );
			$('#txa_ship_to').val( Address );

			$('#tt_choose').datagrid('load',{
				cust_code : rowData.CustomerCode
			});
		},onLoadSuccess:function(data){
            if(SOrdNumber !=''){
                $('#cmb_customer').combogrid('setValue',CustomerCode);
            }
        }
	});

	$('#dg_item').edatagrid({
		onLoadSuccess:function(){
			dtg_item = $('#dg_item').datagrid('getRows');
			total_amount 	= 0;
			tax_amount 		= 0;
			ppn_amount 		= 0;
			ppn_pcnt		= parseFloat($('#hdn_ppn_pcnt').val());
			
			$.each(dtg_item,function(index,value){
				var price 	= value.ItemPrice;
				var qty 	= value.ItemQty;
				var disc    = value.ItemDiscPcnt;
				
				/*
					Harga dikurangi discount
				*/
				var total_disc 		= parseFloat((qty * price) * (disc / 100));
				var total_price 	= (parseFloat(price) - (parseFloat(price) * disc / 100)); 
				/*====================End===============================*/
				//alert((parseFloat(price) * disc / 100));
				/*
					Jika dia inclusive
				*/
				if($('#hdn_taxable').val() == 1){
					 if($('#hdn_inclusive').val() == 1){
						total_price 	= parseFloat((100 / (100 + ppn_pcnt) * total_price)); 
					}
				}
				/*===============END=======================*/
									
				var amount          = parseFloat(qty) * parseFloat(total_price).toFixed(9);
				var ppn             = 0;
				
				if($('#hdn_taxable').val()==1){
					ppn = parseFloat(amount) * (ppn_pcnt / 100);
				}
				
				total_amount 	+= amount;
				ppn_amount 		+= ppn;
				
				$('#dg_item').datagrid('updateRow',{
					index: index, 
					row:{
						TotalAmount: parseFloat(amount), 
						ItemTax: parseFloat(ppn),
						AmountDisc: parseFloat(total_disc)
					}
				});
			});
			
			$('#do_total_amount').numberbox('setValue', (total_amount + ppn_amount));
		},
		onBeginEdit:function(rowIndex,rowDatax){
			var editors	= $('#dg_item').datagrid('getEditors', rowIndex);
            var n0      = $(editors[0].target); // Item Qty
			var n1 		= $(editors[1].target); // Item Qty
			var n2 		= $(editors[6].target); // Max Item
			var n3 		= $(editors[3].target); // Item Price
			var n4 		= $(editors[4].target); // Total Amount
			var n5		= $(editors[5].target); // Tax Amount
			var n6		= $(editors[9].target); // Item Disc
			var n7		= $(editors[11].target); // Amount Disc
			
			save_button_begendedit(SavePrivillage);

            $(n0).prop('readonly', true);
            $(n0).click(function(){
                var TransNo             = rowDatax.SOrdNumber;
                parent.tab_edit('Edit Sales Order','list/sales_order', 'icon-edit', 'edit',TransNo);
            });
				
			n1.numberbox({
				onChange:function(){
					var price 	= n3.numberbox('getValue');
					var qty 	= n1.numberbox('getValue');
					var disc    = n6.numberbox('getValue');
					
					if(parseFloat(n1.numberbox('getValue')) > parseFloat(n2.numberbox('getValue'))) {
						$.messager.alert('Error','Qty tidak boleh lebih dari (' + n2.numberbox('getValue') + ')','error',function(){	
							$('#dg_item').datagrid('reload'); 
							
							save_button_endedit(SavePrivillage);
						});	
					}
					else {
						ppn_pcnt 		= parseFloat($('#hdn_ppn_pcnt').val());
						total_disc 		= parseFloat((qty * price) * (disc / 100));
						
						/*
							Harga dikurangi discount
						*/
						var total_price 	= (parseFloat(price) - (parseFloat(price) * disc / 100)); 
						/*====================End===============================*/
						
						/*
							Jika dia inclusive
						*/
						if($('#hdn_taxable').val() == 1){
							 if($('#hdn_inclusive').val() == 1){
								total_price 	= parseFloat((100 / (100 + ppn_pcnt) * total_price)); 
							}
						}
						/*===============END=======================*/
						
						var amount          = parseFloat(qty) * parseFloat(total_price);
                        var ppn             = 0;
						
						if($('#hdn_taxable').val()==1){
							ppn = parseFloat(amount) * (ppn_pcnt / 100);
						}
						
						n4.numberbox('setValue', amount);
						n5.numberbox('setValue', ppn);
						n7.numberbox('setValue', total_disc);
						
						$('#dg_item').edatagrid('saveRow');
					}
				}
			});
		},
		onEndEdit:function(rowIndex, rowData, changes){
			var item 			= $('#dg_item').datagrid('getRows');
			var do_total_amount = 0;
			var item_tax 		= 0;
			
			$.each(item, function( index, value ) {
				do_total_amount		+= parseFloat(value.TotalAmount);
				item_tax			+= parseFloat(value.ItemTax);		
			});
			
			$('#do_total_amount').numberbox('setValue', (do_total_amount + item_tax));
				
			save_button_endedit(SavePrivillage);
        }
	});

    $('#tt_choose').datagrid({
        onLoadSuccess:function(){
            /*==============Daswan======================*/
            if(SOrdNumber!=''){
                if(load == 0){
                    load            = 1;
                    var data_so     = $('#tt_choose').datagrid('getRows');
                    var ind_so      = null;
                    $.each(data_so,function(ind,val){
                        if(val.SOrdNumber == SOrdNumber){
                            ind_so     = ind;
                        }
                    });

                    if(ind_so != null){
                        $('#tt_choose').datagrid('checkRow',ind_so);
                        choose_item_so();
                    }
                }
            }
            /*============ end Daswan =========================*/
        }
    });
	
	datagrid_item_type_status("dg_item");//untuk warna grid  
});

function choose_customer(){
	var Customer            = $('#cmb_customer').combogrid('grid');	// get datagrid object
	var SelectedCustomer    = Customer.datagrid('getSelected'); // get the selected row
	
	if(SelectedCustomer == null ){
		$.messager.alert('Maaf','Silahkan pilih customer terlebih dahulu','warning',function(){});
	}
	else{
		modal_open('Select Sales Order','dialog-so');
	}		
}

function choose_item_so(){
	var so				= $('#tt_choose').datagrid('getSelected').SOrdNumber;
	var po				= $('#tt_choose').datagrid('getSelected').CustPONumber;
	var ship			= $('#tt_choose').datagrid('getSelected').ShipmentID;
	var ship_date		= $('#tt_choose').datagrid('getSelected').ShipingDate;
	var currency_code	= $('#tt_choose').datagrid('getSelected').CurrencyCode;
	var currency_rate	= $('#tt_choose').datagrid('getSelected').CurrencyRate;
	var SOrdDesc		= $('#tt_choose').datagrid('getSelected').SOrdDesc;
	
	$('#dg_item').datagrid('load',{
		so_number: so
	});

	$('#txt_so_no').val(so);
	$('#txt_po_no').val(po);
	$('#cmb_ship_via').combobox('select',ship);
	$('#txt_ship_date').val(convert_to_dmy(ship_date));
	$('#txt_currency_code').val(currency_code);
	$('#txt_rate').numberbox('setValue',currency_rate);
	$('#txa_description').val(SOrdDesc);
	
	$('#hdn_taxable').val($('#tt_choose').datagrid('getSelected').SOrdTaxesStatus);
	$('#hdn_inclusive').val($('#tt_choose').datagrid('getSelected').SOrdInTaxStatus);
	$('#hdn_ppn_pcnt').val($('#tt_choose').datagrid('getSelected').SOrdTaxPcnt);
	
	modal_close('dialog-so');
}

function insert_data(){
	$('#dg_item').edatagrid('saveRow');
	
	var i=$('#dg_item').datagrid('getRows');
	var detail = JSON.stringify(i);
	$("#detail").val(detail);
	save_transaction('<?=$menu_link?>','#fm_delivery_order', 1);
		
	/*var cek = $('#dg_item').datagrid('getRows');
	
	err_qty = 0;
	validate = true
	$.each(cek, function( index, value ) {
		Item_desc = value.ItemDesc;
		
		if(parseInt(value.ItemQty) > parseInt(value.max_item)) {
			err_qty++;
		}
		else if(parseInt(value.ItemQty) > parseInt(value.InventoryQty)){
			validate = false;
		}
	});
	
	if(err_qty > 0) {
		$.messager.alert('Error','Qty tidak boleh lebih dari Qty SO','error',function(){	
			$('#dg').datagrid('reload'); 
		})	
	}
	else if(validate == false){
		$.messager.alert('Peringatan','Stock Produk '+ Item_desc +' yang tersedia kurang dari Qty yang di-input.','error');
	}
	else if(validate != false){
		var i=$('#dg_item').datagrid('getRows');
		var detail = JSON.stringify(i);
		$("#detail").val(detail);
		save_transaction('<?=$menu_link?>','#fm_delivery_order', 1);
	}*/
}

function remove_row(){
	var selectedrow     = $('#dg_item').datagrid('getSelected');
	var row_index       = $('#dg_item').datagrid('getRowIndex', selectedrow);

	$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.ItemCode + '"?',  
		function(r){
			if (r){
				$('#dg_item').datagrid('deleteRow', row_index);
				save_button_endedit(SavePrivillage);
			}
		}
	);
}
</script>