<!--  Author : Ferry / 12-01-2015 -->

	<?php
			//---------Untuk privellege jika dia ada tombol save----------
				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";
				}
				
				//-------------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 width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="left" width="30%">
                        <input type="checkbox" name="chk_suspended" id="chk_suspended" value="3" onClick="suspend(1);" style="margin-top:0px;margin-right:1px;" <?php if($detail->TransStatus == 3){ echo"checked"; } ?> <?=((!in_array($detail->TransStatus,array(0,6,5)))?"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" plain="true" iconCls="icon-currency" onclick="to_transaction()" <?=(in_array($detail->TransStatus,array(1)))?'':'disabled'?>>To Receive Items</a>
                        <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
                    </td>	
                
                    <td align="center" width="40%">
                        <span id="approval_information">
                            <?php if($detail->TransStatus==4){
                                if($this->session->userdata('jobtitle_status') == 1){
                                    echo 'Need Your Approval';
                                }
                                else {
                                    echo 'Need Manager Approval';
                                }
                            }
                            elseif($detail->TransStatus==5){
                                if($this->session->userdata('jobtitle_status') == 0){
                                    echo 'Need Your Approval';
                                }
                                else{
                                    echo 'Need Director Approval';
                                }
                            }
                            elseif($detail->TransStatus==6){
                                 echo 'Need Director and Manager Approval';
                            }
							else if($detail->TransStatus==0){
								echo 'Waiting For Down Payment';
							}
                            elseif($detail->TransStatus==1){
                                echo 'On Progress';
                            }else{
                                echo ' ';
                            }?>
                        </span>
                    </td>
                    
                    <td align="right" width="30%">
                        <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" fit="true" style="padding:5px;">
            <?php if(in_array($detail->TransStatus,array(2,3,9,8))){ ?>
       			<div class="blanket"></div>
                <div class="status-box">
                    <b><?php 
                       if($detail->TransStatus==3){echo 'Suspended';} elseif($detail->TransStatus==9){echo 'Canceled by Dir.';} elseif($detail->TransStatus==2){echo 'Finished';}elseif($detail->TransStatus==8){echo 'Suspended Item';} else{echo 'Unknown';} 
                        ?></b>
                </div>
            <?php } ?>
            
            <form id="fm_purchase_order" name="fm_purchase_order" method="post">
                <input type="hidden" name="detail" id="detail"/>
                <input type="hidden" name="hdn_currency_code" id="hdn_currency_code"/>
                <input type="hidden" name="hdn_ppn10_pcnt" id="hdn_ppn10_pcnt"/>
                <input type="hidden" name="hdn_pph22_pcnt" id="hdn_pph22_pcnt"/>
                <input type="hidden" name="hdn_pph23_pcnt" id="hdn_pph23_pcnt"/>
                
                <input type="hidden" name="detail_id" id="detail_id">
                <input type="hidden" name="detail_qty" id="detail_qty">
                <!-- Form Header -->
                <table width="100%" height="140" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="56%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr height="20">
                                    <td width="167"><b>Vendor Name</b></td>
                                    <td width="12"><b>:</b></td>

                                    <td colspan="5">
                                        <select name="cbg_vendor" class="easyui-combogrid" id="cbg_vendor" style="width:175px;height:20px" required readonly
                                            data-options="
                                                panelWidth: 445,
                                                value:'<?php echo $detail->VendorCode ?>',
                                                idField: 'VendorCode',
                                                textField: 'VendorName',
                                                fitColumns: true,
                                                url: '<?php echo base_url(); ?>custom/get_data/vendor',
                                                method: 'post',
                                                columns: [[
                                                    {field:'VendorCode', title:'Vendor No', halign:'center', align:'center', width:110},
                                                    {field:'VendorName',title:'Vendor Name', halign:'center', width:250}
                                                ]],
                                            ">
                                        </select>

                                        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-sales'" onClick="modal_open('Select Purchase Requisition','dialog-pr');" disabled>Select PR</a>
                                        
                                        <input type="checkbox" name="chk_taxtable" id="chk_taxtable" onClick="<?=(!in_array($detail->TransStatus,array(0,6)))?'return false':'hideppn()'?>" value="1" <?php if ($detail->POrdTaxesStatus == 1) echo "checked" ?> <?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ? 'disabled' : '' ?>>Taxable
                                    
                                        <span class="disableme" style="<?=(($detail->POrdTaxesStatus==1)?"display":"display:none")?>">
                                            <input type="checkbox" name="chk_inclusive" id="chk_inclusive" onClick="calculate_item_intax();" value="1" <?=(($detail->POrdInTaxStatus == 1) ? "checked" : "")?> <?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ? 'disabled' : '' ?> >Inclusive Tax
                                        </span>
                                    </td>
                                </tr>

                                <tr id="rowRate">
                                    <td><b>Rate</b></td>
                                    <td><b>:</b></td>

                                    <td colspan="5">
                                        <input type="text" name="txt_currency_rate" id="txt_currency_rate" class="easyui-numberbox currency" style="width:70px;text-align:right;" value="<?=$detail->CurrencyRate?>" <?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ? 'disabled' : '' ?> 
                                            data-options=" min:1, precision:2, decimalSeparator:',', groupSeparator:'.'"/>
                                        <span id="currency" style="font-weight:bold"></span>                                        
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td><b>Address</b></td>
                                    <td width="12"><b>:</b></td>
                                
                                    <td width="17">&nbsp;</td>
                                    
                                    <td width="176"><b>Shipping Address</b></td>
                                    <td width="11"><b>:</b></td>
                                    
                                    <td width="18">&nbsp;</td>
                                    
                                    <td width="326" rowspan="2">&nbsp;</td>
                                </tr>

                                <tr height="20">
                                    <td colspan="3">
                                        <textarea name="txa_address" cols="30" rows="4" id="txa_address" style="resize:none;" readonly><?php echo $detail->BillingAddress ?></textarea>
                                    </td>

                                    <td colspan="3">
                                        <textarea name="txa_ship_to" cols="30" rows="4" id="txa_ship_to" style="resize:none;" <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'readonly':''?> class="easyui-validatebox" data-options="required:true"><?php echo $detail->ShippingAddress ?></textarea>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    
                        <td width="44%" valign="top">
              <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">                    
                                <tr height="20">
                                    <td rowspan="7" valign="top"><input type="checkbox" id="chk_vendorneeds" name="chk_vendorneeds" onClick="<?=(!in_array($detail->TransStatus,array(0,6)))?'return false':'hidedp()'?>"  value="1" <?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ? 'disabled' : '' ?>/> Vendor needs DP</td>
                                    <td></td>
                                    <td width="190" style="background:#333399;text-align:center;color:#FFF;">PO. No.</td>
                                    
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">Terms</td>
                                </tr>

                                <tr height="20">
                                <td></td>
                                    <td><input name="txt_pord_no" id="txt_pord_no" type="text" class="easyui-validatebox textbox" value="<?=$detail->POrdNumber?>" style="width:190px;height:18px;text-align:center" required readonly /></td>
                                    

                                    <td>
                                        <select class="combo-grid" required="required"
                                            name="cbo_terms" id="cbo_terms" 
                                            style="width:122px;height:20px;" 
                                            <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'disabled':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?=$detail->TermsPaymentID?>',
                                                idField: 'TermspaymentID',
                                                textField: 'TermDesc',
                                                url:'<?=base_url()?>custom/get_data/termspayment',                                        
                                                method: 'get',
                                                columns: [[
                                                    {field:'TermspaymentID',title:'Terms payment ID',width:90,halign:'center'},
                                                    {field:'TermDesc',title:'Term Desc',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>
                                
                                <tr height="20">
                                    <!-- <td style="background:#333399;text-align:center;color:#FFF;">PR. No.</td> -->
                                    <td></td>
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">PO. Date</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">FOB</td>
                                </tr>
                                
                                <tr height="20">
                                    <td><input type="hidden" name="txt_preq_no" id="txt_preq_no" style="width:190px;height:18px;text-align:center" class="easyui-validatebox textbox" value="<?=$detail->PReqNumber?>" required readonly /></td>
                                    <!--<td>--><input name="txt_preq_date" id="txt_preq_date" type="hidden" class="easyui-validatebox textbox" value="<?=$detail->PReqDate?>" style="width:116px;height:18px;padding:0px 2px;" required readonly /><!--</td>-->
                                    <td><input name="txt_pord_date" id="txt_pord_date" type="text" class="easyui-datebox" style="width:190px;height:20px" required="required" editable="false" readonly value="<?= date("d-m-Y", strtotime($detail->POrdDate)) ?>" /></td>
                                    <td>
                                        <select class="easyui-combogrid" required="required"
                                            name="cbo_fob" id="cbo_fob" 
                                            style="width:122px;height:20px;" 
                                            <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'readonly':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?php echo $detail->FOBID; ?>',
                                                idField: 'FobID',
                                                textField: 'FobName',
                                                url:'<?=base_url()?>custom/get_data/fob',                                     
                                                method: 'get',
                                                columns: [[
                                                    {field:'FobID',title:'FOB ID',width:90,halign:'center'},
                                                    {field:'FobName',title:'FOB Name',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td>&nbsp;</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">Expected Date</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">Ship Via</td>
                                </tr>

                                <tr height="20">
                                    <td>&nbsp;</td>
                                    <td><input name="txt_expected_date" id="txt_expected_date" type="text" class="easyui-datebox" style="width:190px;height:20px" editable="false" readonly /></td>
        
                                    <td>
                                        <select class="combo-grid" required="required"
                                            name="cbo_ship_via" id="cbo_ship_via" 
                                            style="width:122px;height:20px;" 
                                            <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'disabled':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?=$detail->ShipmentID?>',
                                                idField: 'ShipmentID',
                                                textField: 'ShipmentName',
                                                url:'<?=base_url()?>custom/get_data/shipment',                                     
                                                method: 'get',
                                                columns: [[
                                                    {field:'ShipmentID',title:'Shipment ID',width:90,halign:'center'},
                                                    {field:'ShipmentName',title:'Shipment Name',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <!-- End of form header -->

                <!--Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div title="Item">
                        <table toolbar="#tb_dtg_item" id="dtg_item"  idField="id" rownumbers="true" fitColumns="true" singleSelect="true" style="height:250px;" 
                            url="<?php echo base_url().$menu_link."/ajax_item_for_edit/".$detail->POrdNumber; ?>"
                        >                        
                            <thead>
                                <tr>
                                    <th field="PReqNumber"       width="60"  data-options="align:'left', halign:'center'" editor="{type:'text'}">Purchase Req. No.</th>
                                    <th field="PReqDate"       	width="70"  data-options="align:'left',halign:'center'" hidden>Purchase Req. Date.</th>
                                    <th field="PReqDesc"       	width="70"  data-options="align:'left',halign:'center'" hidden>Purchase Req. Desc.</th>
                                    
                                    <th field="ItemCode"         width="45"  data-options="align:'left',halign:'center'" editor="{type:'text'}">Item</th>
                                    <th field="ItemCodeVendor"   width="30"  data-options="align:'center',halign:'center'" editor="{type:'text',options:{required:true}}" ><?php echo label_grid('no_seri');?></th>
                                    <th field="ItemDesc"         width="100" data-options="align:'left',halign:'center'">Description</th>
                                    <th field="ItemQty"          width="20"  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="ItemUnit"         width="20"  data-options="align:'center',halign:'center'" >Unit</th>
                                    <th field="ItemPrice"        width="35"  data-options="align:'right',halign:'center'"  editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true,min:0}}" formatter="formatRp" >Unit Price</th>
                                    <th field="ItemDisc"         width="30"  data-options="align:'right',halign:'center'"  editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true,min:0}}" formatter="formatRp">Discount %</th>
                                    <th field="ItemAmount"       width="40"  data-options="align:'right',halign:'center'"  editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true,min:0,disabled:true}}" formatter="formatRp" >Amount</th>

                                    <th field="ItemMax"          width="20"  data-options="align:'center',halign:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true}}" formatter="formatRp" hidden>Item Max</th>
                                    <th field="ItemTaxPPn10"     width="50"  data-options="align:'right',halign:'center'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item PPn 10</th>
                                    <th field="ItemTaxPPh22"     width="50"  data-options="align:'right',halign:'center'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item PPh 22</th>
                                    <th field="ItemTaxPPh23"     width="50"  data-options="align:'right',halign:'center'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item PPh 23</th>
                                    <th field="ItemTotalAmount"  width="50"  data-options="align:'right',halign:'center'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                   hidden >Item Total Amount</th>
                                    
                                    <th field="ItemType"         width="50"  data-options="align:'center',halign:'center'" editor="{type:'numberbox',options:{required:true,min:0,disabled:true}}" hidden>Item Type</th>
                                    <th field="ItemPPh22Status"  width="50"  data-options="align:'right',halign:'center'"  editor="{type:'numberbox',options:{required:true,min:0,disabled:true}}" hidden>Item PPh22 Status</th>
                                    <th field="ItemPPh23Status"  width="70"  data-options="align:'left',halign:'center'"   editor="{type:'numberbox',options:{required:true,min:0,disabled:true}}" hidden>Item PPh23 Status</th>
                                    <th field="ItemAdvNetDueIn"  width="70"  data-options="align:'left',halign:'center'"   hidden>Net Due In</th>
                                    <th field="ItemPriceNTax"       width="50"  data-options="align:'right',halign:'center'"  
                                   	editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item Price NTax</th>
                                    

                                    <th field="ItemQtyRI"        width="20"  data-options="align:'center',halign:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.'}}" formatter="formatRp" >Qty RI</th>
                                    <th field="ItemQtySpd"       width="25"  data-options="align:'center',halign:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true}}" formatter="formatRp" >Qty Spd</th>
                                    <th field="ItemSpdStatus"    width="30"  data-options="align:'center',halign:'center'" editor="{type:'checkbox',options:{on:'Yes',off:'No'}}">Close</th>
                                    <th field="ItemModusType"    width="30"  data-options="align:'center',halign:'center'" editor="{type:'numberbox',min:0}" hidden>Item Modus Type</th>

                                    <th field="ItemQty_Old"      width="30"  data-options="align:'center',halign:'center'" hidden>Qty Old</th>
                                    <th field="PReqDetailID"     width="70"  data-options="align:'left',halign:'center'"   hidden>PReq Detail ID</th>
                                    <th field="POrdDetailID"     width="70"  data-options="align:'left',halign:'center'"   hidden>POrd Detail ID</th>
                                    <th field="ItemCategoryID"   width="70"  data-options="align:'center',halign:'center'" hidden>Item Category ID</th>
                                    <th field="ItemCategoryCode" width="70"  data-options="align:'left',halign:'center'"   hidden>Item Category Code</th>
                                    <th field="IntaxStatus"      width="50"  data-options="align:'right',halign:'center'"  hidden>Intax Status</th>
                                    <th field="ItemStatus"       width="50"  data-options="align:'center',halign:'center'" hidden>Item Status</th>
                                    
                                    <th field="AmountDisc"       width="50"  data-options="align:'right',halign:'center'"  
                                   	editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Amount Disc</th>
                                    
                                    <th width="30"  halign='center'	field="ItemAmount_Hide"  	editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}" hidden>Amount Hide</th>
                                </tr>
                            </thead>
                        </table>

                        <div id="tb_dtg_item">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row();" <?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9))? 'disabled' : '' ?>>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 height="20">
                                    <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 name="txa_description" id="txa_description" rows="4" style="width:335px;resize:none;" <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'readonly':''?>><?php echo $detail->POrdDesc; ?></textarea>
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td><span class="dp" <?=(($detail->POrdTotalDP!=0)?"":"style='display:none'")?>><b>Downpayment</b></span></td>
                                    <td><span class="dp" <?=(($detail->POrdTotalDP!=0)?"":"style='display:none'")?>><b>:</b></span></td>

                                    <td>
                                        <span class="dp" <?=(($detail->POrdTotalDP!=0)?"style=''":" style='display: none;'")?>>
                                            <input type="numberbox" min="0" name="txt_downpayment" id="txt_downpayment" class="easyui-numberbox" value="<?php echo $detail->POrdTotalDP; ?>" style="width:171px;text-align:right;" <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9)))?'readonly':''?>
                                                data-options=" min:0, precision:2, decimalSeparator:',', groupSeparator:'.'"                                                 
                                            />
                                        </span>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        
                        <td width="50%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr height="20">
                                    <td rowspan="7">&nbsp;</td>
                                    <td width="120"><b>Sub Total</b></td>
                                    <td width="10"><b>:</b></td>
                                    
                                    <td width="171">
                                        <input type="text" id="txt_sub_total" name="txt_sub_total" class="easyui-numberbox" value="<?=$detail->POrdSubTotal?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'"
                                        />
                                        
                                        <input type="text" id="txt_sub_total_hide" name="txt_sub_total_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly hidden
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td><b>Discount</b></td>
                                    <td><b>:</b></td>
                                    
                                    <td>
                                        <input type="text" name="txt_discount" id="txt_discount" class="easyui-numberbox" min="0" value="<?=$detail->POrdDiscount?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                        />
                                        
                                        <input type="hidden" id="txt_discount_hide" name="txt_discount_hide" value="0" class="easyui-numberbox" 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;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                                
                                <tr height="20">
                                    <td>
                                        <span id="lbl_ppn10" style="font-weight:bold">PPn (10%)</span>
                                    </td>
                                    
                                    <td><b>:</b></td>
                                    
                                    <td>
                                        <input type="text" min="0" name="txt_ppn10" id="txt_ppn10" class="easyui-numberbox" value="<?php echo $detail->POrdPPn10; ?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                        />
                                        
                                        <input type="hidden" id="txt_ppn10_hide" name="txt_ppn10_hide" value="0" class="easyui-numberbox" 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;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                                
                                <tr height="20">
                                    <td>
                                        <span id="lbl_pph22" style="font-weight:bold">PPh22 (2.5%)</span>
                                    </td>

                                    <td><b>:</b></td>
                                    
                                    <td>
                                        <input type="text" name="txt_pph22" id="txt_pph22" class="easyui-numberbox" value="<?php echo $detail->POrdPPh22; ?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                        />
                                        
                                        <input type="hidden" id="txt_pph22_hide" name="txt_pph22_hide" value="0" class="easyui-numberbox" 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;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                                
                                <tr height="20">
                                    <td>
                                        <span id="lbl_pph23" style="font-weight:bold">PPh23 (2%)</span>
                                    </td>
                                    
                                    <td><b>:</b></td>

                                    <td>
                                        <input type="text" name="txt_pph23" id="txt_pph23" class="easyui-numberbox" value="<?php echo $detail->POrdPPh23; ?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                        />
                                        
                                        <input type="hidden" id="txt_pph23_hide" name="txt_pph23_hide" value="0" class="easyui-numberbox" 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;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td><b>Est. Freight</b></td>
                                    <td><b>:</b></td>
                                    <td>
                                        <input type="text" name="txt_freight" id="txt_freight" class="easyui-numberbox" value="<?=$detail->POrdEstFreight ?>" style="text-align:right;" <?=in_array($detail->TransStatus, array(0,1,2,3,4,5,9)) ? 'disabled' : ''?>
                                            data-options="precision:2,decimalSeparator:',',groupSeparator:'.'"
                                        />
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td><b>Total Purchase</b></td>
                                    <td><b>:</b></td>

                                    <td>
                                        <input type="text" name="txt_total_purchase" id="txt_total_purchase" class="easyui-numberbox" value="<?php echo $detail->POrdTotalAmount ?>" style="text-align:right;" readonly 
                                            data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'"
                                        />
                                        
                                        <input type="hidden" id="txt_total_purchase_hide" name="txt_total_purchase_hide" value="0" class="easyui-numberbox" 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;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    
    <div id="form-footer" data-options="region:'south',border:false">
    	<table width="100%" cellpadding="0" cellspacing="0">
            <tr>
        	<?php if($detail->OldPOrdNumber != ''|| $detail->OldPOrdNumber != null) { ?>
                    <td>
                        <b>Old PO. No. : </b> <?=$detail->OldPOrdNumber?>
                    </td>
                <?php } ?>
                
                <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" onclick="" plain="true">Help</a>
                    <?php
					if($this->session->userdata("jobtitle_status") == 0){
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="approval_bypass_dp(1)" <?=($detail->TransStatus==0)?'':'disabled'?> >Byepass DP.</a>
                    <?php
					}
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="approval_po(2);" <?= (($this->session->userdata("jobtitle_status") != 0 || !in_array($detail->TransStatus, array(5,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->POrdDate))))?'disabled':'' ?>>App. Dir</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="approval_po(1);" <?= (($this->session->userdata("jobtitle_status") != 1 || substr($this->session->userdata('department'), -3) != '005' || !in_array($detail->TransStatus,array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->POrdDate))))?'disabled':''?>>App. Mgr</a>
                    <?php
					if($group_user->ReversePrivillage == 1){
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(($this->session->userdata("jobtitle_status") == 0) && (in_array($detail->TransStatus,array(1,2,8))))?'':'disabled'?>>Reverse</a>  
                    <?php
					}
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="update_data();" <?=(in_array($detail->TransStatus,array(0,1,2,3,4,5,9,8)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                    <!-- <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="link_print('<?php echo $menu_link ?>/to_print_detail/<?php echo $detail->POrdNumber ?>');" <?=(in_array($detail->TransStatus,array(3,9)))?'disabled':''?>>Preview & Print</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->POrdNumber?>');" <?=(in_array($detail->TransStatus,array(1,2,3,6,4,5)))?'':'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\')'?>" <?=(!in_array($detail->TransStatus,array(0,4,5,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div id="dialog-pr" class="easyui-dialog" style="width:725px;height:525px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true, iconCls:'icon-edit'" buttons="#dialogpr-buttons">
    <table id="tt_choose_pr" class="easyui-datagrid" ctrlSelect="true" remoteSort="false" pagination="true" pageSize="40" fit="true" fitColumns="true" rowNumbers="true"
    	url="<?php echo base_url() ?>list/purchases_order/ajax_preg_item" 
    >
        <thead>
            <tr>
                <th field="ck" checkbox="true"></th>
                <th field="PReqNumber" width="147" halign='center' align='center' sortable="true">PR. Number</th>
                <th field="PReqDate" width="90" halign='center' align='center' sortable="true">PR. Date</th>
                <th field="PReqDesc" width="300" halign="center" align="left">Description</th>
            </tr>
        </thead>
    </table>
</div>
<!-- Dialog Button -->

<div id="dialogpr-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_pr();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-pr');">Cancel</a>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">
    if('<?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ?>'){
        dbl_ppn10 = '<?= $detail->POrdPPn10Pcnt ?>';
        dbl_pph22 = '<?= $detail->POrdPPh22Pcnt ?>';
        dbl_pph23 = '<?= $detail->POrdPPh23Pcnt ?>';
    }
    else{
        dbl_ppn10 = '<?= $taxes_ppn10->TaxesRate ?>';
        dbl_pph22 = '<?= $taxes_pph22->TaxesRate ?>';        
    }
	
	var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
	
    $('#hdn_ppn10_pcnt').val(dbl_ppn10);
    $('#hdn_pph22_pcnt').val(dbl_pph22);
    $('#lbl_ppn10').text('PPn (' + dbl_ppn10 + '%)');
    $('#lbl_pph22').text('PPh22 (' + dbl_pph22 + '%)');
	
	/*========================deklar variabel array for remove===================*/
	var array_item = [];
	var new_array_item = {'a':[],'b':[]};
	/*==============================end=========================================*/

    $(document).ready(function(){
        vendor_status       = '<?= $detail->VendorStatus ?>';
        vendor_taxnumber    = '<?= $detail->VendorTaxNumber ?>';
        vendor_currcode     = '<?= $detail->CurrencyCode ?>';
        
        if('<?= $detail->ItemType ?>' == 2){
            $('#txt_freight').attr('readonly',true);
        }
        else{
            $('#txt_freight').attr('readonly',false);            
        }

		if('<?php echo $detail->POrdDPStatus; ?>' == 1) {
				$('#chk_vendorneeds').prop('checked',true);
		}
		else {
				$('#chk_vendorneeds').prop('checked',false);
		}

        $('#hdn_currency_code').val(vendor_currcode);
        $('#currency').text(vendor_currcode + ' / IDR');
        
		if(vendor_currcode != 'IDR'){
			//$('#row_currency_rate').show();
			$('#txt_currency_rate').attr('readonly',false);
		}
		else{
			//$('#row_currency_rate').hide();
			$('#txt_currency_rate').attr('readonly',true);
		}
		
        var url = '<?php echo base_url(); ?>' + 'list/purchases_order/get_vendor_taxes';
        
        if('<?= in_array($detail->TransStatus,array(0,1,2,3,4,5,9)) ?>'){
            $('#hdn_pph23_pcnt').val(dbl_pph23);
            $('#lbl_pph23').text('PPh23 (' + dbl_pph23 + '%)');                
        }
        else{
            if(vendor_status == 0){
                if((vendor_taxnumber != '') && (vendor_taxnumber != null)){
                    taxes_code = 'PPH23-1';
                }
                else{
                    taxes_code = 'PPH23-2';
                }
				
				taxes_pph23 = 'PPh23';
            }
            else{
                if((vendor_taxnumber != '') && (vendor_taxnumber != null)){
                    taxes_code = 'PPH23-3';
                }
                else{
                    taxes_code = 'PPH23-4';
                }
				taxes_pph23 = 'PPh21';
            }

            $.post(url, {TaxesCode:taxes_code}, function(result){
                dbl_pph23 = result.taxes;
                
                $('#hdn_pph23_pcnt').val(dbl_pph23);
                $('#lbl_pph23').text(''+ taxes_pph23 +' (' + dbl_pph23 + '%)');
            },'json');
        }

	$('#dtg_item').edatagrid({
            onLoadSuccess:function(){
                load_vendor();
				//calculate_discount();
            },
            
            onBeginEdit:function(rowIndex,rowDatax){
                var editors = $('#dtg_item').datagrid('getEditors', rowIndex);
                var n0  = $(editors[0].target);  // PReqNumber
                var n01 = $(editors[1].target);  // PReqNumber
				var n15 = $(editors[2].target);  // V Item Code
                var n1  = $(editors[3].target);  // Item Qty
                var n2  = $(editors[4].target);  // Item Price
				var n13 = $(editors[5].target);  // ItemDisc
                var n3  = $(editors[6].target);  // Item Amount
                var n4  = $(editors[7].target);  // Item Max
                var n5  = $(editors[12].target);  // Item Type
                var n6  = $(editors[13].target);  // Item PPh22Status
                var n7  = $(editors[14].target); // Item PPh23Status
                var n8  = $(editors[15].target); // Item PriceNTax
                var n9  = $(editors[16].target); // Item QTY RI
                var n10 = $(editors[17].target); // Item QTY Suspend
                var n11 = $(editors[18].target); // Item Suspend Status
                var n12 = $(editors[19].target); // Item Modus Type
				
				/*==================Disc Loss No Percision=====================*/
				var n14 = $(editors[20].target); // AmountDisc
				/*===============End==========================================*/
				
				if('<?= in_array($detail->TransStatus,array(6))?>'){
					/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
					save_button_begendedit(SavePrivillage);
					/*=================================end============================================================*/
				}
				
                var item_type = n5.numberbox('getValue');
                if(item_type == 2){$(n1).prop('readonly', true);}

                $(n0).prop('readonly', true);
                $(n0).click(function(){
                    var TransNo             = rowDatax.PReqNumber;
                    parent.tab_edit('Edit Purchase Requisition','list/purchases_requisition', 'icon-edit', 'edit',TransNo);
                });

                $(n01).prop('readonly', true);
                $(n01).click(function(){
                    var ItemCode         = rowDatax.ItemCode;
                    ItemCode            = ItemCode.replace(/\//g,"__");
                    parent.tab_add('List Price Item','list/purchases_order','icon-add','view_list_price'+'/'+ItemCode);
                });

                $(n9).prop('readonly', true);
                $(n9).click(function(){
                    var ItemCode        = rowDatax.ItemCode;
                    var POrdNumber      = $('#txt_pord_no').val();
                    POrdNumber          = POrdNumber.replace(/\//g,"__");
                    ItemCode            = ItemCode.replace(/\//g,"__");
                    var qtyri           = n9.numberbox('getValue');
                    if(qtyri > 0){
                        parent.tab_add('List Price Item','list/purchases_order','icon-add','view_list_receipt'+'/'+ItemCode+'/'+POrdNumber);
                    }
                });

                if('<?= in_array($detail->TransStatus, array(0,4,5)) ?>'){
                    $(n1).prop('readonly',true);
                    $(n2).prop('readonly',true);
					$(n13).prop('readonly',true);
					$(n11).prop('disabled',true);
					$(n15).prop('readonly',true);
                }
				else if('<?= in_array($detail->TransStatus, array(6)) ?>'){
					$(n11).prop('disabled',true);
				}
				else if('<?= in_array($detail->TransStatus, array(0,1)) ?>'){
					$(n11).prop('disabled',false);
					$(n1).prop('readonly',true);
                    $(n2).prop('readonly',true);
					$(n13).prop('readonly',true);
					$(n15).prop('readonly',true);
				}
			
                n1.numberbox({
                    onChange:function(){
                        var item_qty            = n1.numberbox('getValue');
                        var item_price          = n2.numberbox('getValue');
                        var item_max            = n4.numberbox('getValue');
                        var item_type           = n5.numberbox('getValue');
                        var item_pph22status    = n6.numberbox('getValue');
                        var item_pph23Status    = n7.numberbox('getValue');
						var Item_disc    		= n13.numberbox('getValue');

                        if(parseFloat(item_qty) > parseFloat(item_max)){
                            $.messager.alert('Warning', 'Quantity tidak boleh lebih dari ' + item_max, 'error', function(){
                                n3.numberbox('setValue', 0);
                                $('#txt_sub_total').numberbox('setValue', 0);
                                $('#txt_discount').numberbox('setValue', 0);
                                $('#txt_ppn10').numberbox('setValue', 0);
                                $('#txt_pph22').numberbox('setValue', 0);
                                $('#txt_pph23').numberbox('setValue', 0);
                                $('#txt_freight').numberbox('setValue', 0);
                                $('#txt_total_purchase').numberbox('setValue', 0);

                                n1.numberbox('setValue', item_max);
                                $('#dtg_item').edatagrid('saveRow');
                            });
                        }
                        else {
                            var item_amount = parseFloat(item_qty) * parseFloat(item_price);
							var Disc 		= parseFloat(item_amount) * parseFloat(Item_disc) / 100;
							
                            //n3.numberbox('setValue', item_amount);
							//n14.numberbox('setValue', Disc);
                            $('#dtg_item').edatagrid('saveRow');
                            
							if(item_qty == ""){
								n1.numberbox('setValue, 0');
							}
							else{
								calculate_item_pph(rowIndex, item_type, item_pph22status, item_pph23Status, item_qty, item_price, 1, Item_disc);
							}
							
                            
                            //calculate_total();
                        }					
                    }
                });

                n2.numberbox({
                    onChange:function(){
                        var item_qty            = n1.numberbox('getValue');
                        var item_price          = n2.numberbox('getValue');
                        var item_type           = n5.numberbox('getValue');
                        var item_pph22status    = n6.numberbox('getValue');
                        var item_pph23status    = n7.numberbox('getValue');
						var Item_disc    		= n13.numberbox('getValue');

                        var item_amount = parseFloat(item_qty) * parseFloat(item_price);
						var Disc 		= parseFloat(item_amount) * parseFloat(Item_disc) / 100;
						
                        n3.numberbox('setValue', item_amount);
                        n8.numberbox('setValue', item_price);
						
						n14.numberbox('setValue', Disc);
                        $('#dtg_item').edatagrid('saveRow');
						
						if(item_price == ""){
							n2.numberbox('setValue, 0');
						}
						else{
							calculate_item_pph(rowIndex, item_type, item_pph22status, item_pph23status, item_qty, item_price, 1, Item_disc);
						}
						 
                        
                        //calculate_total();
                    }
                });
                
                $(n11).click(function(){
                    if($(this).is(':checked')){
                        var itemqty     = n1.numberbox('getValue');
                        var itemqtyri   = n9.numberbox('getValue');
                                                
                        var suspend_qty = parseFloat(itemqty) - parseFloat(itemqtyri);
						
                        n10.numberbox('setValue', suspend_qty);
                        n12.numberbox('setValue', 2);
                       	save_suspend_item(1);                           
                    }
                    else{
                        n10.numberbox('setValue', 0);
                        n12.numberbox('setValue', 2);
                        save_suspend_item(0);
                    }
                });
				
				n13.numberbox({
                    onChange:function(){
                        var item_qty            = n1.numberbox('getValue');
                        var item_price          = n2.numberbox('getValue');
                        var item_type           = n5.numberbox('getValue');
                        var item_pph22status    = n6.numberbox('getValue');
                        var item_pph23status    = n7.numberbox('getValue');
						var Item_disc    		= n13.numberbox('getValue');
						
						if(parseFloat(Item_disc) > 100){
							$.messager.alert('Warning', "Maaf Discount tidak boleh melebihi 100% per Item", 'info');
							n13.numberbox('setValue', 0);
						}
						else{
							var item_amount = parseFloat(item_qty) * parseFloat(item_price);
							var Disc 		= parseFloat(item_amount) * parseFloat(Item_disc) / 100;
							
							//n3.numberbox('setValue', item_amount);
							//n8.numberbox('setValue', item_price);
							//n14.numberbox('setValue', Disc);
							
							$('#dtg_item').edatagrid('saveRow');
							
							if(Item_disc == ""){
								n13.numberbox('setValue, 0');
							}
							else{
								calculate_item_pph(rowIndex, item_type, item_pph22status, item_pph23status, item_qty, item_price, 1, Item_disc);
							}
							 
							//calculate_discount();
						}
                    }
                });
            },
			onEndEdit: function(){
                var selectedrow     = $('#dtg_item').datagrid('getSelected');
				
				if('<?= in_array($detail->TransStatus,array(6))?>'){
					/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
					save_button_endedit(SavePrivillage);
					/*=================================end============================================================*/
				}
            }
	});
	
	$('#fm_purchase_order').click(function(){
            $('#dtg_item').edatagrid('saveRow');
	});
	 
        $('#txt_freight').numberbox({
            onChange:function(){
                freight = $('#txt_freight').numberbox('getValue');

                if(isNaN(freight) || freight == ''){
                    $('#txt_freight').numberbox('setValue', 0);
                }
                
                calculate_es_freight();
            }
        });   
        datagrid_item_type("dtg_item");//untuk warna grid
    });

    function load_vendor(){
//	if('<?php echo $detail->POrdDPStatus; ?>' == 1) {
//            alert();
//            $('#chk_vendorneeds').prop('checked',true);
//	}
//	else {
//            $('#chk_vendorneeds').prop('checked',false);
//	}
//
	if('<?php echo $detail->POrdTaxesStatus; ?>' == 1) {
            $('#chk_taxtable').prop('checked',true);

            if('<?php echo $detail->POrdInTaxStatus; ?>' == 1) {
                $('#chk_inclusive').prop('checked',true);
            }
            else {
                $('#chk_inclusive').prop('checked',false);
            }
	}
	else {
            $('#chk_taxtable').prop('checked',false);
            $('#chk_inclusive').prop('checked',false);
	}

	//$('#cbo_fob').combobox('select','<?php echo $detail->FOBID; ?>');
	//$('#cbo_terms').combobox('select','<?php echo $detail->TermsPaymentID ?>');
	//$('#cbo_ship_via').combobox('select','<?php echo $detail->ShipmentID ?>');
        
	//$('#txt_pord_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->POrdDate)) ?>');
	$('#txt_expected_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->ExpectedDate)) ?>');	
        $('#txt_downpayment').numberbox('setValue','<?php echo $detail->POrdTotalDP ?>');

        if('<?= !in_array($detail->TransStatus,array(0,1,2,3,4,5,6,9)) ?>'){
            dbl_pph23 = $('#hdn_pph23_pcnt').val();

            if((dbl_ppn10 != '<?= $detail->POrdPPn10Pcnt ?>') || (dbl_pph22 != '<?= $detail->POrdPPh22Pcnt ?>') || (dbl_pph23 != '<?= $detail->POrdPPh23Pcnt ?>')){
                re_calculate_item();
            }
        }
		else{
			re_calculate_item();
		}
		
    }
    
    function hidedp(){
	if($('#chk_vendorneeds').is(':checked')){
            $('.dp_line').css('display','');			
            $('.dp').css('display','');
	}
	else{
            $('.dp_line').css('display','none');
            $('.dp').css('display','none');
            $('#txt_downpayment').numberbox('setValue',0);
	}
    }

    function hideppn(){
	if($('#chk_taxtable').is(':checked')){
            $('.disableme').css('display','');		            
	}
	else{
            $('.disableme').css('display','none');
            $("#chk_inclusive").prop("checked",false);
	}

        calculate_item_tax();
    }
	
	function  calculate_item_intax(){
         var item = $('#dtg_item').datagrid('getRows');
        flag = true;
        $.each(item, function(index, value){
			if(value.ItemPrice == 0){
				flag = false;
			}
		});
		
		if(flag != false){
			var item = $('#dtg_item').datagrid('getData').total;
	
			if(item == 0){
				$.messager.alert('Warning', "Silahkan pilih 'Select PR' terlebih dahulu...!!", 'error');
				$("#chk_inclusive").prop("checked",false);
			}
			else{
				calculate_item_tax();
			}
		}
		else{
			$.messager.alert('Warning', "Maaf silahkan isi terlebih dahulu item price di Purchase Order", 'error');
			$("#chk_inclusive").prop("checked",false);
		}
    }

    function calculate_item_tax(){
        var item = $('#dtg_item').datagrid('getRows');

        $.each(item, function(index, value){
            intax       = 0;
            item_ppn    = 0;
            
            item_ppn10  = 0;
            item_pph22  = 0;
            item_pph23  = 0;

            item_amount = 0;
            item_price  = value.ItemPriceNTax;
			item_disc  	= value.ItemDisc;
			item_qty  	= value.ItemQty;
			
			dbl_ppn10 	= parseFloat(dbl_ppn10);
			
			total_price = parseFloat(item_price - (item_price * item_disc) / 100);
			total_disc 	= parseFloat((item_qty * item_price) * (item_disc / 100));

            if(item_price >= 0 || item_price !== null){
                if($('#chk_taxtable').is(':checked')){
                    if($('#chk_inclusive').is(':checked')){                        
                        //item_ppn    = parseFloat(((item_price / 1.1) * (dbl_ppn10 / 100).toFixed(9)));
                        total_price 	= parseFloat((100 / (100 + dbl_ppn10) * total_price).toFixed(9)); 
						
						//item_price  = parseFloat((item_price - item_ppn).toFixed(9));
                        intax = 1;
                    }
                    else{
                        if(value.IntaxStatus == 1){item_price = value.ItemPriceNTax;}
                        intax   = 0;
                    }
                    
					item_amount = parseFloat(value.ItemQty) * parseFloat(total_price);					 
                    item_ppn10  = parseFloat((item_amount * (dbl_ppn10 / 100)).toFixed(9));
					
					if (value.ItemPPh22Status == 1){
						item_pph22 = parseFloat((item_amount * (dbl_pph22 / 100)).toFixed(9));
					}
					else{
						item_pph22  = 0;
					}
                }
                else{
                    if(value.IntaxStatus == 1){
                        item_price  = parseFloat(item_price) + parseFloat((item_price * (dbl_ppn10 / 100)).toFixed(9));
                        intax       = 0;
                    }

                    item_amount = parseFloat(value.ItemQty) * parseFloat(total_price);
                    item_ppn10  = 0;   
					
					if (value.ItemPPh22Status == 1){
						item_pph22 = parseFloat((item_amount * (dbl_pph22 / 100)).toFixed(9));
					}
					else{
						item_pph22  = 0;
					}                  
                }
                
                item_amount = isNaN(item_amount) ? 0 : parseFloat(item_amount);
                item_ppn10  = isNaN(item_ppn10) ? 0 : parseFloat(item_ppn10);
				item_pph22  = isNaN(item_pph22) ? 0 : parseFloat(item_pph22);

                

                if ((value.ItemType == 1) && (value.ItemPPh23Status == 1)){
                    dbl_pph23   = $('#hdn_pph23_pcnt').val();
                    item_pph23  = parseFloat((item_amount * (dbl_pph23 / 100)).toFixed(9));
                }
                else{
                    item_pph23  = 0;
                }

                item_totalamount = parseFloat(item_amount + item_ppn10 + item_pph22 - item_pph23);

                $('#dtg_item').datagrid('updateRow',{
                    index:index,
                    row:{//ItemPrice          : (item_price == 0) ? '0.00' : item_price,
                         ItemAmount         : (item_amount == 0) ? '0.00' : item_amount,
                         ItemTaxPPn10       : item_ppn10,
                         ItemTaxPPh22       : item_pph22,
                         ItemTaxPPh23       : item_pph23,
                         ItemTotalAmount    : item_totalamount,
						 ItemAmount_Hide    : (item_amount == 0) ? '0.00' : item_amount,
						 AmountDisc 		: total_disc,
                         IntaxStatus        : intax}
                });
            }
	});

        calculate_total();
    }

    function calculate_item_pph(rowIndex, item_type, item_pph22status, item_pph23Status, item_qty, item_price, status, Item_disc){
        item_ppn10  = 0;
        intax       = 0;
        dbl_ppn10 	= parseFloat(dbl_ppn10);
		
		total_price = parseFloat(item_price - ((item_price * Item_disc) / 100));
		
        item_amount = parseFloat(item_qty * total_price);
		total_disc 	= parseFloat((item_qty * item_price) * (Item_disc / 100));
		
        if($('#chk_taxtable').is(':checked')){
            if($('#chk_inclusive').is(':checked') && status == 1){
                //item_ppn    = parseFloat(((item_price / 1.1) * (dbl_ppn10 / 100)).toFixed(9));
				item_ppn 	= parseFloat(total_price * (100 / (100 + dbl_ppn10)).toFixed(9)); 
				 
                //item_price  = parseFloat(item_price - item_ppn);
                item_amount = parseFloat(item_qty * item_ppn);
				total_disc 	= parseFloat((item_qty) * parseFloat(item_price) * (Item_disc / 100));
				
                intax       = 1;
            }

            item_ppn10  = parseFloat((item_amount) * (dbl_ppn10 / 100));
			
			if(item_pph22status == 1){
				item_pph22          = parseFloat((item_amount * (dbl_pph22 / 100)).toFixed(9));
				item_totalamount    = parseFloat(item_amount + item_ppn10 + item_pph22);
	
				$('#dtg_item').datagrid('updateRow',{
					index:rowIndex, 
					row:{ItemPrice          : item_price,
						 ItemAmount         : item_amount,
						 ItemTaxPPn10       : item_ppn10,
						 ItemTaxPPh22       : item_pph22,
						 ItemTotalAmount    : item_totalamount,
						 ItemAmount_Hide 	: item_amount,
						 AmountDisc 		: total_disc,
						 IntaxStatus        : intax}
				});
			}
        }
        
		if(item_pph22status == 1){
			item_pph22          = parseFloat((item_amount * (dbl_pph22 / 100)).toFixed(9));
			item_totalamount    = parseFloat(item_amount + item_ppn10 + item_pph22);

			$('#dtg_item').datagrid('updateRow',{
				index:rowIndex, 
				row:{ItemPrice          : item_price,
					 ItemAmount         : item_amount,
					 ItemTaxPPn10       : item_ppn10,
					 ItemTaxPPh22       : item_pph22,
					 ItemTotalAmount    : item_totalamount,
					 ItemAmount_Hide 	: item_amount,
					 AmountDisc 		: total_disc,
					 IntaxStatus        : intax}
			});
		}
			
        if((item_type == 1) && (item_pph23Status == 1)) {
            dbl_pph23           = $('#hdn_pph23_pcnt').val();
            item_pph23          = parseFloat((item_amount * (dbl_pph23 / 100)).toFixed(9));
            item_totalamount    = parseFloat(item_amount + item_ppn10 - item_pph23);
			total_disc 			= parseFloat((item_qty * item_price) * (Item_disc / 100));
			
            $('#dtg_item').datagrid('updateRow',{
                index:rowIndex, 
                row:{ItemPrice          : item_price,
                     ItemAmount         : item_amount,
                     ItemTaxPPn10       : item_ppn10,
                     ItemTaxPPh23       : item_pph23,
                     ItemTotalAmount    : item_totalamount,
					 ItemAmount_Hide 	: item_amount,
					 AmountDisc 		: total_disc,
                     IntaxStatus        : intax}
            });
        }
        else{
            item_totalamount    = parseFloat(item_amount + item_ppn10);

            $('#dtg_item').datagrid('updateRow',{
                index:rowIndex, 
                row:{ItemPrice          : item_price,
                     ItemAmount         : item_amount,
                     ItemTaxPPn10       : item_ppn10,
                     ItemTotalAmount    : item_totalamount,
					 ItemAmount_Hide 	: item_amount,
					 AmountDisc 		: total_disc,
                     IntaxStatus        : intax}
            });
        }
        
        calculate_total();
    }

    function re_calculate_item(){
    	var item        = $('#dtg_item').datagrid('getRows');
        
        item_ppn10_pcnt = $('#hdn_ppn10_pcnt').val();
        item_pph22_pcnt = $('#hdn_pph22_pcnt').val();
        item_pph23_pcnt = $('#hdn_pph23_pcnt').val();
        total_disc 		= 0;
		Item_disc 		= 0;
		item_ppn10 		= 0;
		
	$.each(item, function(index, value) {
            item_amount 	= parseFloat(value.ItemAmount_Hide);
			Item_disc 		= parseFloat(value.ItemDisc);
			ItemPriceNTax 	= parseFloat(value.ItemPriceNTax);
			ItemQty 		= parseFloat(value.ItemQty);
			
			if($('#chk_taxtable').is(':checked')){
            	item_ppn10  = parseFloat((item_amount * (item_ppn10_pcnt / 100)));
			}
			
            item_pph22  = value.ItemPPh22Status == 1 ? parseFloat((item_amount * (item_pph22_pcnt / 100))) : 0;
            item_pph23  = value.ItemPPh23Status == 1 ? parseFloat((item_amount * (item_pph23_pcnt / 100))) : 0;
            item_total  = item_amount + item_ppn10 + item_pph22 + item_pph23;
            total_disc 	= ((ItemPriceNTax * ItemQty) * (Item_disc / 100));
			
            $('#dtg_item').datagrid('updateRow',{
                index:index, 
                row:{ItemTaxPPn10       : item_ppn10,
                     ItemTaxPPh22       : item_pph22,
                     ItemTaxPPh23       : item_pph23,
					 AmountDisc       	: total_disc,
                     ItemTotalAmount    : item_total}
             });
	});

        calculate_total();
    }
	
	function calculate_discount(){
		$('#dtg_item').edatagrid('saveRow');
		var item        = $('#dtg_item').datagrid('getRows');
		var total       = 0;
        var item_amount  = 0;

        var sub_total   = 0;
        var sub_ppn10   = 0;
        var sub_pph22   = 0;
        var sub_pph23   = 0;
		var sub_disc   	= 0;
		$.each(item, function(index, value) {   
			
		   item_amount  = isNaN(value.ItemAmount_Hide) ? 0 : value.ItemAmount_Hide;

           sub_total += parseFloat(item_amount);
           sub_ppn10 += parseFloat(value.ItemTaxPPn10);
           sub_pph22 += parseFloat(value.ItemTaxPPh22);
           sub_pph23 += parseFloat(value.ItemTaxPPh23);
			         
           sub_disc  += parseFloat(value.AmountDisc);
		});
		sub_disc 			= isNaN(sub_disc) ? 0 : parseFloat(sub_disc);
		
		var sub_discount    	 = $('#txt_discount').numberbox('setValue', sub_disc);	
		var sub_discount_hide    = $('#txt_discount_hide').numberbox('setValue', sub_disc);	
		var sub_freight     	 = $('#txt_freight').numberbox('getValue');	
		
		total =  parseFloat(sub_total) + parseFloat(sub_ppn10) + parseFloat(sub_pph22) - parseFloat(sub_pph23) + parseFloat(sub_freight);
		total = isNaN(total) ? 0 : parseFloat(total);
		
		$('#txt_total_purchase').numberbox('setValue', total);
		$('#txt_total_purchase_hide').numberbox('setValue', total);
	}
	
	function calculate_es_freight(){
		$('#dtg_item').edatagrid('saveRow');
		var item        = $('#dtg_item').datagrid('getRows');
		var total       = 0;
        var item_amount  = 0;

        var sub_total   = 0;
        var sub_ppn10   = 0;
        var sub_pph22   = 0;
        var sub_pph23   = 0;
		var sub_disc   	= 0;
		$.each(item, function(index, value) {   
			
		   item_amount  = isNaN(value.ItemAmount_Hide) ? 0 : value.ItemAmount_Hide;

           sub_total += parseFloat(item_amount);
           sub_ppn10 += parseFloat(value.ItemTaxPPn10);
           sub_pph22 += parseFloat(value.ItemTaxPPh22);
           sub_pph23 += parseFloat(value.ItemTaxPPh23);
			         
           sub_disc  += parseFloat(value.AmountDisc);
		});
		sub_disc 			= isNaN(sub_disc) ? 0 : parseFloat(sub_disc);
		
		var sub_discount    	 = $('#txt_discount').numberbox('setValue', sub_disc);	
		var sub_discount_hide    = $('#txt_discount_hide').numberbox('setValue', sub_disc);	
		var sub_freight     	 = $('#txt_freight').numberbox('getValue');	
		
		total =  parseFloat(sub_total) + parseFloat(sub_ppn10) + parseFloat(sub_pph22) - parseFloat(sub_pph23) + parseFloat(sub_freight);
		total = isNaN(total) ? 0 : parseFloat(total);
		
		$('#txt_total_purchase').numberbox('setValue', total);
		$('#txt_total_purchase_hide').numberbox('setValue', total);
	}
	
    function calculate_total(){
	$('#dtg_item').edatagrid('saveRow');
	var item        = $('#dtg_item').datagrid('getRows');

        var total       = 0;
        var sub_total   = 0;
        var sub_ppn10   = 0;
        var sub_pph22   = 0;
        var sub_pph23   = 0;
		var sub_disc   	= 0;
	
	$.each(item, function(index, value) {
            sub_total   += parseFloat(value.ItemAmount_Hide);
            sub_ppn10   += parseFloat(value.ItemTaxPPn10);
            sub_pph22   += parseFloat(value.ItemTaxPPh22);
            sub_pph23   += parseFloat(value.ItemTaxPPh23);
			
			sub_disc  += parseFloat(value.AmountDisc);
	});
	
        if(isNaN(sub_total)){sub_total = 0;}
        if(isNaN(sub_ppn10)){sub_ppn10 = 0;}
        if(isNaN(sub_pph22)){sub_pph22 = 0;}
        if(isNaN(sub_pph23)){sub_pph23 = 0;}
		if(isNaN(sub_disc)){sub_disc = 0;}
	
    $('#txt_sub_total').numberbox('setValue', sub_total);
	$('#txt_sub_total_hide').numberbox('setValue', sub_total);
	
	$('#txt_ppn10').numberbox('setValue', sub_ppn10);
	$('#txt_ppn10_hide').numberbox('setValue', sub_ppn10);
	
	$('#txt_pph22').numberbox('setValue', sub_pph22);
	$('#txt_pph22_hide').numberbox('setValue', sub_pph22);
	
	$('#txt_discount').numberbox('setValue', sub_disc);	
	$('#txt_discount_hide').numberbox('setValue', sub_disc);	
	
	$('#txt_pph23').numberbox('setValue', sub_pph23);
	$('#txt_pph23_hide').numberbox('setValue', sub_pph23);
	
	var sub_freight     = $('#txt_freight').numberbox('getValue');	

	total = parseFloat(sub_total) + parseFloat(sub_ppn10) + parseFloat(sub_pph22) - parseFloat(sub_pph23) + parseFloat(sub_freight);
	total = isNaN(total) ? 0 : parseFloat(total);
	
	$('#txt_total_purchase').numberbox('setValue', total);
	$('#txt_total_purchase_hide').numberbox('setValue', total);
	
    }

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

	var message_text    = '';
	var POrdNumber      = $("#txt_pord_no").val();
	var 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, {POrdNumber:POrdNumber, Detail:Detail}, function(result){
                        if (result.status == true){
                            $.messager.alert('Success',result.message,'info',function(){
                                location.reload();						                    
                            });				
                        } 
                        else {
                            $.messager.alert('Failed',result.message,'error',function(){
                                location.reload();						                    
                            });				
                        }
                    },'json');
                }
                else {
                    $('#dtg_item').datagrid('reload');						                    
                }
            }
	);
    }
	
	function approval_po($status) {
		var url_check           = '<?= base_url();?>custom/custom/checking_approval';
		var no_transaksi    	= $('#txt_pord_no').val();
		modal_open('Progress Bar','dlg_loading');
		
		$.post(url_check, {no_transaksi:no_transaksi}, function(result){
			
			if (result.status === false){
				approval($status);
			} 
			else{
				$.messager.alert('Unseccessfull',result.message,'error',function(){
					location.reload();
				});
			}
		},'json');
	}
	
    function approval($status){
        var url             = base_url + 'list/purchases_order/approval';
		var item            = $('#dtg_item').datagrid('getRows');
        var Detail          = JSON.stringify(item);
        
        var Status          = $status;
        var VendorCode      = $('#cbg_vendor').combogrid('getValue');
		var POrdNumber      = $('#txt_pord_no').val();
        var POrdDate        = $('#txt_pord_date').datebox('getValue');
		var PReqNumber      = $('#txt_preq_no').val();
        var CurrencyCode    = $('#hdn_currency_code').val();
        var CurrencyRate    = $('#txt_currency_rate').numberbox('getValue');
        var DownPayment     = $('#txt_downpayment').numberbox('getValue');
        var SubTotal        = $('#txt_sub_total').numberbox('getValue');

        $.post(url, {Status:Status, VendorCode:VendorCode, POrdNumber:POrdNumber, POrdDate:POrdDate, PReqNumber:PReqNumber,
                     CurrencyCode:CurrencyCode, CurrencyRate:CurrencyRate, DownPayment:DownPayment, SubTotal:SubTotal, Detail:Detail}, function(result){
            if (result.status == true){
                $.messager.alert('Success',result.message,'info',function(){
                    location.reload();						                    
                });		
				modal_close('dlg_loading'); 		
            } 
            else {
                $.messager.alert('Error',result.message,'error',function(){
                    location.reload();						                    
                });				
            }
        },'json');
    }
	
	function approval_bypass_dp($status){
        var url             = base_url + 'list/purchases_order/approval_by_pass';
		var item            = $('#dtg_item').datagrid('getRows');
        var Detail          = JSON.stringify(item);
        
        var Status          = $status;
        var VendorCode      = $('#cbg_vendor').combogrid('getValue');
		var POrdNumber      = $('#txt_pord_no').val();
        var POrdDate        = $('#txt_pord_date').datebox('getValue');
		var PReqNumber      = $('#txt_preq_no').val();
        var CurrencyCode    = $('#hdn_currency_code').val();
        var CurrencyRate    = $('#txt_currency_rate').numberbox('getValue');
        var DownPayment     = $('#txt_downpayment').numberbox('getValue');
        var SubTotal        = $('#txt_sub_total').numberbox('getValue');

        $.post(url, {Status:Status, VendorCode:VendorCode, POrdNumber:POrdNumber, POrdDate:POrdDate, PReqNumber:PReqNumber,
                     CurrencyCode:CurrencyCode, CurrencyRate:CurrencyRate, DownPayment:DownPayment, SubTotal:SubTotal, Detail:Detail}, function(result){
            if (result.status == true){
                $.messager.alert('Success',result.message,'info',function(){
                    location.reload();						                    
                });		
				modal_close('dlg_loading'); 		
            } 
            else {
                $.messager.alert('Error',result.message,'error',function(){
                    location.reload();						                    
                });				
            }
        },'json');
    }
	
	function remove_row(){
		var item 		= $('#dtg_item').datagrid('getData').total;
		var item_row    = $('#dtg_item').datagrid('getRows');
		
		var pr_no       	= new Array();
        var pr_date 		= new Array();
		var pr_desc 		= new Array();
		
		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.POrdDetailID);
						
						new_array_item.a.push(selectedrow.PReqDetailID);
                   		new_array_item.b.push(selectedrow.ItemQty);
						
						$("#detail_id").val(JSON.stringify(array_item));
						$("#detail_qty").val(JSON.stringify(new_array_item));
					
						$('#dtg_item').datagrid('deleteRow', row_index);
						calculate_total();	
						
						$.each(item_row, function(index, value) {
							if(value.PReqNumber != undefined){
								pr_no.push(value.PReqNumber);
								pr_date.push(value.PReqDate);
								pr_desc.push(value.PReqDesc);
							}
						});
						
						$('#txt_preq_no').val(pr_no.array_unique());
						$('#txt_preq_date').val(pr_date.array_unique());
						$('#txa_description').val(pr_desc.array_unique());
						
					
						/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
						save_button_endedit(SavePrivillage);
						/*=================================end============================================================*/
						
						/*====================on beg in edit saat grid di klik maka tombol app disable===================*/
						$('.app-button').linkbutton('disable');
						/*=================================end============================================================*/
					}
				}
			);        
						
		}            
	}
	
	function app_reverse(){
		var no_transaksi    = $('#txt_pord_no').val();
	
		checking_reverse(no_transaksi,function(check){
			
			if(check.status == true){
				var i       = $('#dtg_item').datagrid('getRows');
				var detail  = JSON.stringify(i);
	
				$("#detail").val(detail);
				reverse_data_by_detail('<?php echo $menu_link?>','#fm_purchase_order');
			}else{
			   $.messager.alert('Unseccessfull',check.message,'error',function(){
					location.reload();
				});
			}
		});
	}
	
    function update_data(){
		var cretated_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 department_session 	= '<?php echo $this->session->userdata("department");?>';
		var department_code 	= '<?=$detail->DepartmentCode?>';
		
		var url             = '<?= base_url();?>custom/custom/checking_update';
		var no_transaksi    = $('#txt_pord_no').val();
		var trans_status 	= '<?=$detail->TransStatus?>';
		
		if(job_title == 0){
			proses_update(url, no_transaksi, trans_status);
		}
		else if((job_title == 1) && (department_code == department_session)){
			proses_update(url, no_transaksi, trans_status);
		}
		else if(cretated_by == login_as){
			proses_update(url, no_transaksi, trans_status);
		}
		else{
			$.messager.alert('Warning','Maaf anda tidak berhak merubah transaksi ini, karena transaksi yang dibuat tidak sesuai dengan akun login','warning',function(){
				$('#dtg_item').edatagrid('reload');
			});
		}
    }
	
	function proses_update(url, no_transaksi, trans_status){
		var amount  = true;
		var flag 	= true;
		
		var item    = $('#dtg_item').datagrid('getRows');
	
		$.each(item, function(index, value) {
				if(value.ItemPrice == undefined || value.ItemPrice == 0 ){
					amount = false;
				}			
				
				if(value.ItemType == 2){
					if(value.ItemQty != 1){
						flag = false;
					}
				}	
		});
		
		if(amount == false){
           $.messager.alert('Unseccessfull','Masih ada price yang kosong','error',function(){});
        }
		else if(flag == false){
			$.messager.alert('Unseccessfull','Maaf Item Qty Tidak Boleh Lebih/Kurang Dari (1) Satu, Untuk Adv. Payment','error',function(){		
                $('#dtg_item').edatagrid('reload');
            });
		}
		else if($('#txt_downpayment').numberbox('getValue') == 0 && $('#chk_vendorneeds').is(':checked')){
				$.messager.alert('Unseccessfull',"Nominal DP harus lebih besar daripada Nol (0), disaat 'Vendor needs DP diklik",'error',function(){		
					$('#txt_downpayment').numberbox().focus();
				});
		}
		else if(parseFloat($('#txt_downpayment').numberbox('getValue')) > parseFloat($('#txt_sub_total').numberbox('getValue'))){
				$.messager.alert('Unseccessfull','Down Payment tidak boleh lebih besar dari pada sub total','error',function(){		
					$('#txt_downpayment').numberbox().focus();
				});
		}
		else{
				$('#dtg_item').edatagrid('saveRow');
	
				var item    = $('#dtg_item').datagrid('getRows');
				var detail  = JSON.stringify(item);
	
				$("#detail").val(detail);
				edit_transaction('<?=$menu_link?>','#fm_purchase_order', no_transaksi, url, trans_status);
		}
	}
	
	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_pord_no').val(), 'Purchase Orders', url, created_by, login_as, job_title);
	}

    function to_transaction(){

        var appfinished     = '<?=$detail->TransStatus;?>';
        var no_transaksi    = $('#txt_pord_no').val();
        var vendor_code     = $('#cbg_vendor').combogrid('getValue');
        var no_trans        = no_transaksi.replace(/\//g,"__");
        var vendor_code     = vendor_code.replace(/\//g,"__");

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