<?php $__env->startSection('css_page_level'); ?>

    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css')); ?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/datatables/media/css/buttons.dataTables.min.css')); ?>"/>    
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css')); ?>" />
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.css')); ?>" />
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-select/bootstrap-select.min.css')); ?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/select2/css/select2.css')); ?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/select2/css/select2-bootstrap.min.css')); ?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/jquery-multi-select/css/multi-select.css')); ?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css')); ?>"/>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-content-wrapper'); ?>
	<style type="text/css">
		.th_display_none { display: none;}
        .disableInput {
            background-color: #ffee88 !important;
        }
        .readOnlyInput {
            background-color: #ffee88 !important;
        }
        .portlet.light .dataTables_wrapper .dt-buttons {
            margin-top: 0px;
        }
        .dataTables_wrapper .dt-buttons {
            float: left;
        }
	</style>
	<div class="page-content-wrapper" id="main">
		<div class="page-content">                               
			<!-- BEGIN PAGE HEADER-->
			<h3 class="page-title">
			<?php $setting = app('anlutro\LaravelSettings\Facade'); ?>
			<?php echo e($setting::get('system_name','全方位建築智慧化管理系統')); ?> <small><?php echo e($setting::get('company_name','新保科技')); ?></small>
			</h3>
			<div class="page-bar">
				<ul class="page-breadcrumb">
					<li>
						<i class="fa fa-home"></i>
						<a href="index.html">首頁</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="#">取得資產設備建立</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="#">資產設備列表</a>
					</li>
				</ul>
				<div class="page-toolbar">

				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN DASHBOARD STATS -->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet light bordered">
						<div class="portlet-body">
							<div class="table-toolbar" >
								<div class="row">
									<div class="col-md-6">
                                        <div class="btn-group">
											<a id="btn_add_assets" href="javascript:;"  class="btn green">
											新增 <i class="fa fa-plus"></i>
											</a>
                                        </div>
                                        <button id="btn_mass_delete" class="btn red" style="display:none;"> 刪除 <i class="fa fa-trash"></i></button>
									</div>
								</div>
									
							</div>
							<table class="table table-striped table-bordered table-hover" id="table_list">
                                <thead>
                                    <tr>
                                        <?php if($version == 0): ?>
                                        <th>類別</th>
                                        <th>資產編號</th>
                                        <th>資產名稱</th>
                                        <th>廠牌型號</th>
                                        <th>產品序號</th>
                                        <th>取得日期</th>
                                        <th>取得成本</th>
                                        <th>目前狀態</th>
                                        <th>動作</th>
                                        <?php else: ?>
                                        <th>產品序號</th>
                                        <th>設備名稱</th>
                                        <th>設備流水號</th>
                                        <th>設備編號</th>
                                        <th>狀態</th>
                                        <th>動作</th>
                                        <?php endif; ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if($version == 0): ?>
                                    <?php foreach($assets as $one): ?>
                                    <tr>
                                        <td><?php echo e($one->category_name); ?></td>
                                        <td><?php echo e($one->no); ?></td>
                                        <td><?php echo e($one->asset_name); ?></td>
                                        <td><?php echo e($one->model); ?></td>
                                        <td><?php echo e($one->sn); ?></td>
                                        <td><?php echo e($one->purchase_date); ?></td>
                                        <td><?php echo e($one->costs); ?></td>
                                        <td><?php echo $one->status_name; ?></td>
                                        <td>
                                            <div class="btn-group">
                                            <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
                                                動作 <i class="fa fa-angle-down"></i>
                                            </button>
                                                <ul class="dropdown-menu pull-right" role="menu">
                                                    <li>
                                                        <a class="btn_edit" uid="<?php echo e($one->id); ?>" status="4" href="javascript:;">
                                                        <i class="fa fa-pencil"></i>編輯 
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a class="btn_delete" uid="<?php echo e($one->id); ?>" status="4" href="javascript:;">
                                                            <i class="fa fa-trash"></i>刪除 
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                    <?php else: ?>
                                    <?php foreach($assets as $one): ?>
                                    <tr>
                                        <td><?php echo e($one->sn); ?></td>
                                        <td><?php echo e($one->asset_name); ?></td>
                                        <td><?php echo e($one->devorder); ?></td>
                                        <td><?php echo e($one->devuuid); ?></td>
                                        <td><?php echo $one->status_name; ?></td>
                                        <td>
                                            <div class="btn-group">
                                            <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
                                                動作 <i class="fa fa-angle-down"></i>
                                            </button>
                                                <ul class="dropdown-menu pull-right" role="menu">
                                                    <li>
                                                        <a class="btn_edit" uid="<?php echo e($one->id); ?>" status="4" href="javascript:;">
                                                        <i class="fa fa-pencil"></i>編輯 
                                                        </a>
                                                    </li>
                                                    <?php if($one->sensor_id != 0): ?>
                                                    <li>
                                                        <a class="btn_sensor" uid="<?php echo e($one->sensor_id); ?>" href="<?php echo e(route('manage::ba::sensor_index') . '?sensor_id=' . $one->sensor_id); ?>">
                                                            <i class="fa fa-cog"></i>建立BA資料 
                                                        </a>
                                                    </li>
                                                    <?php endif; ?>
                                                    <li>
                                                        <a class="btn_delete" uid="<?php echo e($one->id); ?>" status="4" href="javascript:;">
                                                            <i class="fa fa-trash"></i>刪除 
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                    <?php endif; ?>
                                </tbody>
							</table>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
		</div>
        <div class="modal fade draggable-modal" id="modal_add_assets" role="basic" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                        <h4 class="modal-title">新增資產設備</h4>
                    </div>
                    <form id="form_add" class="form-horizontal" enctype="multipart/form-data" action="<?php echo e(route('manage::asset::add_assets')); ?>" method="POST">
                        <div class="modal-body">
                            <div class="form-body">

                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn dark btn-outline" data-dismiss="modal">關閉</button>
                            <button type="submit" class="btn green btn_query_submit" value="add">新增</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <div class="modal fade draggable-modal" id="modal_edit_assets" role="basic" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                        <h4 class="modal-title">修改資產設備</h4>
                    </div>
                    <form id="form_edit" method="POST" class="form-horizontal" enctype="multipart/form-data" action="<?php echo e(route('manage::asset::update_assets')); ?>">
                        <input type="hidden" name="id" value="" />
                        <div class="modal-body">
                            <div class="form-body">

                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn dark btn-outline" data-dismiss="modal">關閉</button>
                            <button type="submit" class="btn green btn_query_submit" value="add">修改</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <div id="formTemplate" style="display:none;">
            <?php if($version == 0): ?>
            <blockquote>
                <h4>Step 1. 設備資訊</h4>
            </blockquote>
            <div class="form-group">
                <label class="col-md-2 control-label">資產編號</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="no" class="form-control" placeholder="請輸入資產編號">   
                </div>
                </div>                       
                <label class="col-md-2 control-label">廠牌型號</label>
                <div class="col-md-4">
                <div class="input-icon">
                     <i class="fa fa-pencil"></i>
                    <input type="text" name="model" class="form-control" placeholder="請輸入廠牌型號">   
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">資產名稱</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="asset_name" class="form-control" placeholder="請輸入資產名稱">   
                </div>
                </div>
                <label class="col-md-2 control-label">分類類別</label>
                <div class="col-md-4">
                    <select name="c_id" class="form-control mySelect2">   
                        <?php foreach($assetCategories as $category): ?>
                            <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">規格明細</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <textarea name="specification" class="form-control" placeholder="請輸入規格明細"></textarea>   
                </div>
                </div>
                <label class="col-md-2 control-label">附屬設備</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <textarea name="affiliated_asset" class="form-control" placeholder="請輸入附屬設備"></textarea>   
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">產品序號</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="sn" class="form-control" placeholder="請輸入產品序號">   
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">取得日期</label>
                <div class="col-md-4">
                    <div class="input-group date form_datetime date-picker" data-date-format="yyyy-mm-dd">
                        <input type="text" name="purchase_date" readonly class="form-control"> 
                        <span class="input-group-btn">
                            <button class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
                        </span>
                    </div>  
                </div>
                <label class="col-md-2 control-label">取得來源</label>
                <div class="col-md-4">
                    <select name="as_id" class="form-control mySelect2">
                        <?php foreach($acquiredSources as $source): ?>
                            <option value="<?php echo e($source->id); ?>"><?php echo e($source->source); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">取得成本</label>
                <div class="col-md-2">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="costs" class="form-control" placeholder="請輸入成本">   
                </div>
                </div>
                <label class="col-md-2 control-label">耐用年限</label>
                <div class="col-md-2">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="age_limit" class="form-control" placeholder="請輸入年限">   
                </div>
                </div>
                <label class="col-md-2 control-label">現值</label>
                <div class="col-md-2">
                    <input type="text" name="depreciation_price" class="form-control readOnlyInput" value="0">   
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">取得原因</label>
                <div class="col-md-4" style="p">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="purchase_reason" class="form-control" placeholder="請輸入取得原因">   
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">產品現況</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <textarea name="situation" class="form-control" placeholder="請輸入產品現況"></textarea>  
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">保管人</label>
                <div class="col-md-4">
                    <select name="custodian" class="form-control mySelect2"> 
                        <option value="">未選擇</option>
                        <?php foreach($staffs as $staff): ?>
                            <option value="<?php echo e($staff->id); ?>"><?php echo e($staff->employee_no.'  '.$staff->name); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <label class="col-md-2 control-label">姓名</label>
                <div class="col-md-4">
                    <input type="text" name="custodian_name" class="form-control disableInput">  
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">部門群組</label>
                <div class="col-md-2">
                    <input type="text" name="department_no" class="form-control disableInput"> 
                </div>
                <div class="col-md-2">
                    <input type="text" name="department_name" class="form-control disableInput"> 
                </div>
                <label class="col-md-2 control-label">職務名稱</label>
                <div class="col-md-4">
                    <input type="text" name="title" class="form-control disableInput">  
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">存放位置</label>
                <div class="col-md-4">
                    <select name="sp_id" class="form-control mySelect2"> 
                        <?php foreach($storagePlaces as $place): ?>
                            <option value="<?php echo e($place->id); ?>"><?php echo e($place->place); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <blockquote>
                <h4>Step 2. 保固資訊</h4>
            </blockquote>
            <div class="form-group">
                <label class="col-md-2 control-label">銷售/維修廠商</label>
                <div class="col-md-4">
                <div class="input-icon">
                <select name="f_id" class="form-control mySelect2">   
                    <?php foreach($firms as $firm): ?>
                        <?php if($firm->status == 1): ?>
                        <option value="<?php echo e($firm->id); ?>"><?php echo e($firm->no.'-'.$firm->name); ?> (已註銷)</option>
                        <?php else: ?>
                        <option value="<?php echo e($firm->id); ?>"><?php echo e($firm->no.'-'.$firm->name); ?></option>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </select>
                </div>
                </div>
                <label class="col-md-2 control-label">聯絡人</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-user"></i>
                        <input type="text" name="repairer_contact" class="form-control" placeholder="請輸入聯絡人"> 
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">維修電話</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-phone"></i>
                    <input type="text" name="repairer_tel" class="form-control" placeholder="請輸入維修電話"> 
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">保固方式</label>
                <div class="col-md-4">
                <div class="input-icon">
                    <i class="fa fa-pencil"></i>
                    <input type="text" name="warranty_type" class="form-control" placeholder="請輸入保固方式"> 
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">保固到期日</label>
                <div class="col-md-4">
                <div class="input-group date form_datetime date-picker" data-date-format="yyyy-mm-dd">
                    <input type="text" name="warranty_exp_date" readonly class="form-control"> 
                    <span class="input-group-btn">
                        <button class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
                    </span>
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">圖片</label>
                <div class="col-md-8 imageList">
                    <div class="fileinput fileinput-new" data-provides="fileinput" >
                        <input type="hidden" name="image_id" value="" />
                        <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 269.97px; height: 150px;">
                            <img src="" name="image_url" alt=""/>
                        </div>
                        <div>
                            <span class="btn default btn-file">
                            <span class="fileinput-new">
                            選擇圖片 </span>
                            <span class="fileinput-exists">
                            更換 </span>
                            <input type="file" name="image">
                            </span>
                            <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput">
                            移除 </a>
                        </div>
                    </div>
                </div>
            </div>
            <?php else: ?>
            <div class="form-group">
                <label class="col-md-2 control-label">空間名稱</label>
                <div class="col-md-4">
                    <select name="sp_id" class="form-control mySelect2"> 
                        <?php foreach($storagePlaces as $place): ?>
                            <option value="<?php echo e($place->id); ?>"><?php echo e($place->floor); ?>-<?php echo e($place->place); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div id="devuuid_box">
                <label class="col-md-2 control-label">設備編號</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="devuuid" class="form-control" readonly>   
                    </div>
                </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">設備名稱</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="asset_name" class="form-control readonly" placeholder="請輸入設備名稱">   
                    </div>
                </div>
                <label class="col-md-2 control-label">產品序號</label>
                    <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="sn" class="form-control" placeholder="請輸入產品序號">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">安裝日期</label>
                <div class="col-md-4">
                    <div class="input-group date form_datetime date-picker" data-date-format="yyyy-mm-dd">
                        <input type="text" name="installation_date" readonly class="form-control"> 
                        <span class="input-group-btn">
                            <button class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
                        </span>
                    </div>  
                </div>
                <label class="col-md-2 control-label">保固起始日期</label>
                <div class="col-md-4">
                    <div class="input-group date form_datetime date-picker" data-date-format="yyyy-mm-dd">
                        <input type="text" name="warranty_start_date" readonly class="form-control"> 
                        <span class="input-group-btn">
                            <button class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
                        </span>
                    </div>  
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">廠商代碼</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="devuuid" class="form-control readonly devuuid" placeholder="請輸入廠商代碼(三碼)">
                    </div>
                </div>
                <label class="col-md-2 control-label">設備條碼</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="barcode" class="form-control" placeholder="請輸入設備條碼">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">資產識別碼</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="entifier" class="form-control" placeholder="請輸入資產識別碼">   
                    </div>
                </div>
                <label class="col-md-2 control-label">設備種類</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="typename" class="form-control" placeholder="請輸入設備種類">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">製造廠商</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="manufacturer" class="form-control" placeholder="請輸入製造廠商">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">產品型號</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="model" class="form-control" placeholder="請輸入產品型號">   
                    </div>
                </div>
                <label class="col-md-2 control-label">保固廠商</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="warranty_guarantor_labor" class="form-control" placeholder="請輸入保固廠商">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">保固時程</label>
                <div class="col-md-3" style="padding-right: 0px;">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="warranty_duration_labor" class="form-control" placeholder="請輸入保固時程">
                    </div>
                </div>
                <div class="col-md-1" style="padding-left: 0px;">
                    <select name="warranty_duration_unit" class="form-control mySelect2">
                        <option value="年">年</option>
                        <option value="月">月</option>
                    </select>
                </div>
                <label class="col-md-2 control-label">置換成本</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="replacement_cost" class="form-control" placeholder="請輸入置換成本">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">可用期限</label>
                <div class="col-md-3" style="padding-right: 0px;">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="expected_life" class="form-control" placeholder="請輸入可用期限">   
                    </div>
                </div>
                <div class="col-md-1" style="padding-left: 0px;">
                    <select name="duration_unit" class="form-control mySelect2">
                        <option value="年">年</option>
                        <option value="月">月</option>
                    </select>
                </div>
                <label class="col-md-2 control-label">產品別</label>
                <div class="col-md-4">
                    <select name="cust_stand" class="form-control mySelect2">   
                        <?php foreach($assetCategories as $category): ?>
                            <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">型號參照</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="model_reference" class="form-control" placeholder="請輸入型號參照">   
                    </div>
                </div>
                <label class="col-md-2 control-label">設備形狀</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="shape" class="form-control" placeholder="請輸入設備形狀">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">設備大小</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="size" class="form-control" placeholder="請輸入設備大小">   
                    </div>
                </div>
                <label class="col-md-2 control-label">設備顏色</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="color" class="form-control" placeholder="請輸入設備顏色">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">竣工點交日期</label>
                <div class="col-md-4">
                    <div class="input-group date form_datetime date-picker" data-date-format="yyyy-mm-dd">
                        <input type="text" name="finish" readonly class="form-control"> 
                        <span class="input-group-btn">
                            <button class="btn default date-set" type="button">
                                <i class="fa fa-calendar"></i>
                            </button>
                        </span>
                    </div>
                </div>
                <label class="col-md-2 control-label">設備等級</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="grade" class="form-control" placeholder="請輸入設備等級">   
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">設備材質</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="material" class="form-control" placeholder="請輸入設備材質">   
                    </div>
                </div>
                <label class="col-md-2 control-label">系統別</label>
                <div class="col-md-4">
                    <select name="system_type" class="form-control mySelect2">
                        <option value="不帶電">不帶電</option>
                        <option value="帶電">帶電</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">設備合約名稱</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="dev_name2" class="form-control" placeholder="請輸入設備合約名稱">   
                    </div>
                </div>
                <label class="col-md-2 control-label">無障礙功能</label>
                <div class="col-md-4">
                    <div class="input-icon">
                        <i class="fa fa-pencil"></i>
                        <input type="text" name="accessibility_performance" class="form-control" placeholder="請輸入無障礙功能">   
                    </div>
                </div>
            </div>
            <?php if( Sentinel::check()->username == 'admin' ): ?>
            <div class="form-group">
                <label class="col-md-2 control-label">對應BA設備</label>
                <div class="col-md-4">
                    <select name="sensor_id" class="form-control mySelect2">
                        <option value="0">無對應設備</option>
                        <?php foreach($sensor as $one): ?>
                        <option value="<?php echo e($one->id); ?>"><?php echo e($one->sensor_name); ?> - <?php echo e($one->tag); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <?php endif; ?>
            <?php endif; ?>
            <input type="hidden" id="_token" name="_token" value="<?php echo e(csrf_token()); ?>">
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('plugins_page_level'); ?>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-validation/js/jquery.validate.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-validation/js/additional-methods.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/media/js/jquery.dataTables.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/moment.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootbox/bootbox.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-multi-select/js/jquery.multi-select.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/select2/js/select2.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-form/jquery.form.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/media/buttons/dataTables.buttons.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/media/buttons/buttons.print.min.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js_page_level'); ?>
    <script>
        $(document).ready(function(){
            callDataTable();
        });
        
        function initAction() {
            $.fn.modal.Constructor.prototype.enforceFocus = function () {};
            $('#modal_add_assets form').find('.form-body').html($('#formTemplate').html());
            $('#modal_edit_assets form').find('.form-body').html($('#formTemplate').html());
            $('#modal_edit_assets [name="custodian"]').addClass('disableInput');
            $(".mySelect2").select2();
            $('.disableInput').prop('disabled', true);
            $('.readOnlyInput').prop('readonly', true);
            $('.show-tooltip').tooltip();
            $('#type').multiSelect();
            $('#source').multiSelect();
            $('.date-picker').datepicker({
                orientation: "left",
                autoclose: true,
                dateFormat: 'yyyy-mm-dd'
            });
            $(document).on('click','#btn_add_assets',function(){
                $('#devuuid_box').css('display','none');
                $('.readonly').attr('readonly',false);
                $('.devuuid').val('');
                $('#modal_add_assets').modal('show');
            });
            $(document).on('click', '#btn_mass_delete', function(){
                var ids = [];
                $('.checkboxes:checked').each(function() {
                    ids.push($(this).val());                      
                });   
                deleteRecords(ids);
            });
            $('[name="costs"]').change(function() {
                refreshDepreciationPrice($(this).parents('form'));    
            });
            $('[name="age_limit"]').change(function() {
                refreshDepreciationPrice($(this).parents('form'));    
            });
            $('[name="purchase_date"]').change(function() {
                refreshDepreciationPrice($(this).parents('form'));    
            });
            $('.btn_delete').click(function() {
                var id = $(this).attr('uid');
                deleteRecords(id);
            });
            $('.mySelect2[name="custodian"]').change(function() {
                var form = $(this).parents('form');
                var data = $(this).select2('data');
                if (typeof data[0] == 'undefined') return;
                
                $.ajax({
                    type : 'GET',
                    url  : "<?php echo e(route('manage::asset::get_custodian')); ?>",
                    dataType : 'json',
                    data : {
                        'id' : $(this).val()
                    },
                    success: function(sendback){
                        $.each(sendback, function(key, value) {
                            if (key == 'id') { 
                                key = 'custodian';
                                var obj = $("[name='" + key + "']", form);
                                $(obj).val(value); 
                            }
                        });
                    },
                    error: function(){
                        toastr['error']('發生錯誤，請重新整理後再嘗試');
                    }
                });
            });
            $('.btn_edit').click(function(){
                var uid = $(this).attr('uid');
                $("#form_edit [name='image']").val('');
                $("#form_edit [name='image_id']").val('');
                $("#form_edit [name='image_url']").attr('src', '');
                $('#devuuid_box').css('display','block');

                $('.readonly').attr('readonly',true);

                $.ajax({
                    type : 'GET',
                    url  : "<?php echo e(route('manage::asset::get_assets')); ?>",
                    dataType : 'json',
                    data : {
                        'id' : uid
                    },
                    success: function(sendback){
                        $.each(sendback, function(key, value) {
                            var obj = $("#form_edit [name='" + key + "']");
                            if ($(obj).is('img')) {
                                $(obj).attr('src', value);
                            } else if ($(obj).hasClass('mySelect2')) {
                                $(obj).select2("val", value); 
                            } else {
                                if(key == 'devuuid'){
                                    $(obj).val(value);
                                    $('.devuuid').val(value.substr(0,3));
                                }else{
                                    $(obj).val(value);
                                }
                            } 
                            if (key == 'no' || key == 'custodian') {
                                if (value != '' && value != '0') {
                                    $('#modal_edit_assets [name="' + key + '"]').prop('disabled', true);    
                                } else {
                                    $('#modal_edit_assets [name="' + key + '"]').prop('disabled', false);
                                }
                            }    
                        });

                        refreshDepreciationPrice('#form_edit');
                        $('#modal_edit_assets').modal('show');
                    },
                    error: function(){
                        toastr['error']('發生錯誤，請重新整理後再嘗試');
                    }
                });
            });

            <?php if($version == 0): ?>
            $('#form_add').ajaxForm({
                type: "POST",
                dataType: "json",
                beforeSubmit: function () {
                    $('#form_success_alert').show();
                    $('#form_error_alert').hide();
                    return $("#form_add").valid();
                },
                success: function (returnData) {
                    $('#modal_add_assets').modal('hide');
                    window.location.reload();
                },
                error: function(){
                    var errors = data.responseJSON;
                    //以下是目前測試到的可行解，但還是要實際嘗試才知道怎麼使用。
                    $.each(errors, function (key, data) {
                        console.log(key);
                        if( key == 'errors'){
                            $.each(data, function (index, data) {
                                $( "input[name='"+index+"']").closest('.form-group').addClass('has-error');
                                $( "input[name='"+index+"']").closest('.form-control').after( '<span class="help-block help-block-error">'+data+'</span>' )
                            });
                        } else if (key == 'message') {
                                    alert(data);    
                                }
                    });
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                }
            });
            
            $('#form_add').validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block help-block-error', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",  // validate all fields including form hidden input
                rules:{
                    asset_name:{
                        required:true,
                        maxlength:50
                    },
                    specification:{
                        required:true
                    },     
                    model:{
                        required:true,
                        maxlength:50
                    },         
                    affiliated_asset:{
                        required:true
                    },  
                    sn:{
                        required:true,
                        maxlength:50
                    },             
                    c_id:{
                        required:true
                    },              
                    purchase_date:{
                        required:true,
                        date:true
                    },       
                    as_id:{
                        required:true
                    },              
                    age_limit:{
                        required:true,
                        number:true
                    },           
                    costs:{
                        required:true,
                        number:true
                    },               
                    depreciation_price:{
                        required:true,
                        number:true
                    },  
                    purchase_reason:{
                        required:true,
                        maxlength:50
                    }, 
                    situation:{
                        required:true
                    },          
                    custodian:{
                        required:true
                    },           
                    sp_id:{
                        required:true
                    },                  
                    repairer_tel:{
                        required:true,
                        maxlength:15
                    },    
                    repairer_contact:{
                        required:true,
                        maxlength:20
                    }, 
                    warranty_type:{
                        required:true,
                        maxlength:20
                    },   
                    warranty_exp_date:{
                        required:true,
                        date:true
                    }
                },
                messages:{
                    asset_name:{
                        required:'資產名稱不可為空',
                        maxlength:'資產編號長度不能超過50個字元'
                    },
                    specification:{
                        required:'規格明細不可為空'
                    },     
                    model:{
                        required:'廠牌型號不可為空',
                        maxlength:'廠牌型號長度不能超過50個字元'
                    },         
                    affiliated_asset:{
                        required:'附屬設備不可為空'
                    },  
                    sn:{
                        required:'產品序號不可為空',
                        maxlength:'產品序號長度不能超過50個字元'
                    },             
                    c_id:{
                        required:'分類類別未選擇'
                    },              
                    purchase_date:{
                        required:'取得日期未輸入',
                        date:'取得日期必需是日期格式'
                    },       
                    as_id:{
                        required:'取得來源未選擇'
                    },              
                    age_limit:{
                        required:'耐用年限不可為空',
                        number:'耐用年限必需為數字格式'
                    },           
                    costs:{
                        required:'取得成本不可為空',
                        number:'取得成本必需為數字格式'
                    },               
                    depreciation_price:{
                        required:'現值不可為空',
                        number:'現值必需為數字格式',
                    },  
                    purchase_reason:{
                        required:'取得原因不可為空',
                        maxlength:'取得原因長度不能超過50個字元'
                    }, 
                    situation:{
                        required:'產品現況不可為空'
                    },          
                    custodian:{
                        required:'保管人未輸入'
                    },           
                    sp_id:{
                        required:'放置位置未選擇'
                    },                   
                    repairer_tel:{
                        required:'維修電話不可為空',
                        maxlength:'維修電話長度不能超過15個字元'
                    },    
                    repairer_contact:{
                        required:'聯絡人不可為空',
                        maxlength:'聯絡人長度不能超過20個字元'
                    }, 
                    warranty_type:{
                        required:'保固方式不可為空',
                        maxlength:'保固方式長度不能超過20個字元'
                    },   
                    warranty_exp_date:{
                        required:'保固到期日不可為空',
                        date:'保固到期日必需是日期格式'
                    }
                },

                invalidHandler: function (event, validator) { //display error alert on form submit
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                },

                highlight: function (element) { // hightlight error inputs
                   $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    $(element)
                        .closest('.form-group').removeClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label
                        .closest('.form-group').removeClass('has-error'); // set success class to the control group
                },
            });
            
            $('#form_edit').ajaxForm({
                type: "POST",
                dataType: "json",
                beforeSubmit: function () {
                    $('#form_success_alert').show();
                    $('#form_error_alert').hide();
                    return $("#form_edit").valid();
                },
                success: function (returnData) {
                    $('#modal_edit_assets').modal('hide');
                    window.location.reload();
                },
                error: function(){
                    var errors = data.responseJSON;
                    //以下是目前測試到的可行解，但還是要實際嘗試才知道怎麼使用。
                    $.each(errors, function (key, data) {
                        console.log(key);
                        if( key == 'errors'){
                            $.each(data, function (index, data) {
                                $( "input[name='"+index+"']").closest('.form-group').addClass('has-error');
                                $( "input[name='"+index+"']").closest('.form-control').after( '<span class="help-block help-block-error">'+data+'</span>' )
                            });
                        } else if (key == 'message') {
                            toastr['error'](data);    
                        }
                    });
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                }
            });
            
            $('#form_edit').validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block help-block-error', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",  // validate all fields including form hidden input
                rules:{
                    asset_name:{
                        required:true,
                        maxlength:50
                    },
                    specification:{
                        required:true
                    },             
                    affiliated_asset:{
                        required:true
                    },  
                    sn:{
                        required:true,
                        maxlength:50
                    },             
                    c_id:{
                        required:true
                    },              
                    purchase_date:{
                        required:true,
                        date:true
                    },       
                    as_id:{
                        required:true
                    },              
                    age_limit:{
                        required:true,
                        number:true
                    },           
                    costs:{
                        required:true,
                        number:true
                    },               
                    depreciation_price:{
                        required:true,
                        number:true
                    },  
                    purchase_reason:{
                        required:true,
                        maxlength:50
                    }, 
                    situation:{
                        required:true
                    },          
                    custodian:{
                        required:true
                    },           
                    sp_id:{
                        required:true
                    },              
                    repairer:{
                        required:true,
                        maxlength:50
                    },        
                    repairer_tel:{
                        required:true,
                        maxlength:15
                    },    
                    repairer_contact:{
                        required:true,
                        maxlength:20
                    }, 
                    warranty_type:{
                        required:true,
                        maxlength:20
                    },   
                    warranty_exp_date:{
                        required:true,
                        date:true
                    }
                },
                messages:{
                    asset_name:{
                        required:'資產名稱不可為空',
                        maxlength:'資產編號長度不能超過50個字元'
                    },
                    specification:{
                        required:'規格明細不可為空'
                    },            
                    affiliated_asset:{
                        required:'附屬設備不可為空'
                    },  
                    sn:{
                        required:'產品序號不可為空',
                        maxlength:'產品序號長度不能超過50個字元'
                    },             
                    c_id:{
                        required:'分類類別未選擇'
                    },              
                    purchase_date:{
                        required:'取得日期未輸入',
                        date:'取得日期必需是日期格式'
                    },       
                    as_id:{
                        required:'取得來源未選擇'
                    },              
                    age_limit:{
                        required:'耐用年限不可為空',
                        number:'耐用年限必需為數字格式'
                    },           
                    costs:{
                        required:'取得成本不可為空',
                        number:'取得成本必需為數字格式'
                    },               
                    depreciation_price:{
                        required:'現值不可為空',
                        number:'現值必需為數字格式',
                    },  
                    purchase_reason:{
                        required:'取得原因不可為空',
                        maxlength:'取得原因長度不能超過50個字元'
                    }, 
                    situation:{
                        required:'產品現況不可為空'
                    },          
                    custodian:{
                        required:'保管人未輸入'
                    },           
                    sp_id:{
                        required:'放置位置未選擇'
                    },              
                    repairer:{
                        required:'銷售/維修廠商不可為空',
                        maxlength:'銷售/維修廠商長度不能超過50個字元'
                    },        
                    repairer_tel:{
                        required:'維修電話不可為空',
                        maxlength:'維修電話長度不能超過15個字元'
                    },    
                    repairer_contact:{
                        required:'聯絡人不可為空',
                        maxlength:'聯絡人長度不能超過20個字元'
                    }, 
                    warranty_type:{
                        required:'保固方式不可為空',
                        maxlength:'保固方式長度不能超過20個字元'
                    },   
                    warranty_exp_date:{
                        required:'保固到期日不可為空',
                        date:'保固到期日必需是日期格式'
                    }
                },

                invalidHandler: function (event, validator) { //display error alert on form submit
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                },

                highlight: function (element) { // hightlight error inputs
                   $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    $(element)
                        .closest('.form-group').removeClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label
                        .closest('.form-group').removeClass('has-error'); // set success class to the control group
                }
            });
            <?php endif; ?>
        };

        var deleteRecords = function(id) {
            bootbox.confirm("您確定要刪除指定的資產設備?", function(result) {
                if(result == true){
                    $.ajax({
                        type : 'DELETE',
                        dataType : 'json',
                        url  : "<?php echo e(route('manage::asset::delete_assets')); ?>",
                        data : {
                            _token : $('#_token').val(),
                            id     : id
                        },
                        success : function(sendback){
                            toastr['success']('刪除成功');
                            window.location.reload();
                        },
                        error : function(sendback){
                            toastr['error']('刪除失敗，請重新整理後再試');
                        }
                    })
                }
            }); 
        }
        
        var callDataTable = function () {
            var table = $('#table_list');
            initAction();

            // table.on( 'draw.dt', function () {
            //     initAction();
            // });
            
            var oTable = table.dataTable({
                // Internationalisation. For more info refer to http://datatables.net/manual/i18n
                "language": {
                    "aria": {
                        "sortAscending": ": activate to sort column ascending",
                        "sortDescending": ": activate to sort column descending"
                    },
                    "emptyTable": "此列表目前沒有資料",
                    "info": "顯示第 _START_ 到第 _END_ 則 共有 _TOTAL_ 則",
                    "infoEmpty": "沒有找到符合的資料",
                    "infoFiltered": "(從 _MAX_ 筆資料中過濾)",
                    "lengthMenu": "顯示 _MENU_ 則",
                    "search": "快速篩選:",
                    "zeroRecords": "目前沒有任何資料",
                    "paginate": {
                        "previous":"上一頁",
                        "next": "下一頁",
                        "last": "最後",
                        "first": "最前"
                    }
                },
                "bStateSave": false, // save datatable state(pagination, sort, etc) in cookie.
                "lengthMenu": [
                    [10, 20, 100, -1],
                    [10, 20, 100, "All"] // change per page values here
                ],
                // set the initial value
                "pageLength": 10,
                "buttons": [
                    {
                        extend: 'print',
                        text: '列印',
                        message: '<h4>資產設備列表</h4>',
                        exportOptions: {
                            columns: '.printColumn'
                        }
                    }
                ],
            });

            $('.group-checkable', table).change(function () {
                var set     = jQuery(this).attr("data-set");
                var checked = jQuery(this).is(":checked");
                jQuery(set).each(function () {
                    if (checked) {
                        $('#btn_mass_delete').show();
                        $(this).attr("checked", true);
                    } else {
                        $('#btn_mass_delete').hide();
                        $(this).attr("checked", false);
                    }
                });
                jQuery.uniform.update(set);
            });

            $('.checkboxes', table).change(function(){
                var checkedNum = $('.checkboxes:checked').length;
                if(checkedNum > 0){
                    $('#btn_mass_delete').show();
                }else{
                    $('#btn_mass_delete').hide();
                }
            });
        }   
        
        var refreshDepreciationPrice = function(form)
        {
            var price        = 0; 
            var purchaseDate = $('[name="purchase_date"]', form).val();
            var costs        = $('[name="costs"]', form).val();
            var ageLimit     = $('[name="age_limit"]', form).val();
            var today        = new Date();
            var lastDate;
            
            try {
                purchaseDate = purchaseDate.split("-");
                
                lastDate     = new Date(parseInt(purchaseDate[0]) + parseInt(ageLimit), purchaseDate[1] - 1, purchaseDate[2]);
                purchaseDate = new Date(purchaseDate[0], purchaseDate[1] - 1, purchaseDate[2]);
                
                if (today < lastDate) {
                    price = costs / ((lastDate - purchaseDate) / (24 * 60 * 60 * 1000));
                    price = (lastDate - today) / (24 * 60 * 60 * 1000) * price;
                }
               
                $('[name="depreciation_price"]', form).val(Math.ceil(price));
                
            } catch(e) {
                
            }
        }
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.manage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>