<?
    global $vis_language;
    $dept_option='';
    $dept_id=0;
    $currecny=$department[0]['currency'];
    for($i=0;$i<count($department);$i++) if($department[$i]['is_paid']==1) {
        if($dept_id==0) $dept_id=(isset($operation['vis_department_id']) && is_numeric($operation['vis_department_id']))?$operation['vis_department_id']:$department[$i]['department_id'];
        $dept_option.='<option value="'.$department[$i]['department_id'].'"';
        if($department[$i]['department_id']==$dept_id) {
            $dept_option.=' selected="selected"';
            $currecny=$department[$i]['currency'];
        }
        $dept_option.='>'.$department[$i]['domain_name'].' : '.$department[$i]['department_name'].'</option>';
    }
    $module_setting=$object->get_module_setting('department_id='.$dept_id.' and module_id='.$module_details['module_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
	<div class="col-sm-6">
		<h3 class="m-b-xs text-black"><span><? echo $vis_language['TXTTICKETORTIMEBASE'];?></h3>
		<ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
			<li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><?echo $vis_language['TXTHOME'];?></a></li>
			<li><a class="link" href="#/setting/setting_menu/<? echo $vis_language['TXTSETTINGS'];?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<?echo $vis_language['TXTSETTINGS'];?>',{'vis_module':'setting','vis_operation':'setting_menu'});"><?echo $vis_language['TXTSETTINGS'];?></a></li>
			<li class="active"><?echo $vis_language['TXTTICKETORTIMEBASE'];?></li>
		</ul>
	</div>
</section>
<? if($dept_option=='')  include(VIS_PATH_TEMPLATE.'no_record_yet.php');   else { ?>
<section class="padder">
	<section class='panel panel-default'>
		<header class="panel-heading sub_header"><? echo $vis_language['TXTTICKETORTIMEBASE']; ?></header>
		<div class="panel-body">
			<form method="post" name="vis_ticket_base" id="vis_ticket_base" class="form-horizontal">
			<input type="hidden" name="vis_module_id" value="5" />
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
               <div class="col-sm-10">
				<select name="vis_department"  class="form-control input-sm selectpicker" onchange="$('#vis_workpanel_div').visExecution('load_area',{'vis_module':'setting', 'vis_operation':'ticket_base', 'vis_module_id':<? echo $module_details['module_id']; ?>, 'vis_department_id':$(this).val()})"><? echo $dept_option; ?></select>
               </div>
            </div>
              <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTBILLINGMETHOD']; ?></label>
               <div class="col-sm-10">
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" value="0" id="vis_billing_method" checked="checked" name="vis_billing_method" onclick="toggleBillingMethod(this.value)"><i></i>
                  <? echo $vis_language['TXTTICKETBASE']; ?></label>  </div>
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" value="1" id="vis_billing_method"  name="vis_billing_method" onclick="toggleBillingMethod(this.value)"><i></i>
                   <? echo $vis_language['TXTTIMEBASE']; ?></label>  </div>
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTINVOICEDUEONDAYS']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_due_time" value="<?= (isset($module_setting['vis_due_time']) && $module_setting['vis_due_time']!='')?$module_setting['vis_due_time']:'24' ?>" >
               </div>
            </div>
            <div class="form-group" id="time_base_area" >
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTBILLRATE'].' ('.$currecny.')'; ?></label>
               <div class="col-sm-10">
			   	  <label class="m-r-lg pull-left"><input class="form-control input-sm" type="text" name="vis_time_rate" value="<? echo $module_setting['vis_time_rate']; ?>" /></label>
				  <label class="m-r-lg pull-left"><? echo $vis_language['TXTPER']; ?></label>
				  <label class="m-r-lg pull-left"><input class="form-control input-sm" type="text" name="vis_bill_time" value="<? echo $module_setting['vis_bill_time']; ?>" /></label>
				  <label class="m-r-lg pull-left"><? echo $vis_language['TXTMIN']; ?></label>
            	</div>
            </div>
            <div id="ticket_base_area">
			<div class="form-group" >
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTBILLRATE'].' ('.$currecny.')'; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_ticket_rate" value="<? echo $module_setting['vis_ticket_rate']; ?>" >
               </div>
            </div>
			<div class="form-group" id="ticket_base_area">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTONTICKETCREATE']; ?></label>
               <div class="col-sm-10">
                  <select name="vis_invoice" class="form-control input-sm selectpicker">
 					 <option value="0"><? echo $vis_language['TXTDONOTGENERATEINVOICE']; ?></option>
                    <option value="1"<? if($module_setting['vis_invoice']==1) echo ' selected="selected"'; ?>><? echo $vis_language['TXTGENERATEINVOICE']; ?></option>
                    <option value="2"<? if($module_setting['vis_invoice']==2) echo ' selected="selected"'; ?>><? echo $vis_language['TXTGENERATEANDSENDINVOICE']; ?></option>									   				 				  </select>
               </div>
            </div>
			<div class="form-group" id="ticket_base_area">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTBALANCEREQUIRED']; ?></label>
               <div class="col-sm-10">
                  <select name="vis_balance" class="form-control input-sm selectpicker">
					<option value="0"><? echo $vis_language['TXTNO']; ?></option><option value="1"<? if($module_setting['vis_balance']==1) echo ' selected="selected"'; ?>><? echo $vis_language['TXTYES']; ?></option>				  </select>
              </div>
            </div>
            </div>
			<div class="line b-b line-lg pull-in"></div>
			<br/>
			<div class="form-group">
			   <div class="col-sm-4 col-sm-offset-2">

				  <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'setting', 'vis_operation':'update_bill_setting', 'vis_form':'vis_ticket_base'})"><? echo $vis_language['TXTSAVE']; ?></button>
                  <button type="button" class="btn btn-primary m-l" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'setting', 'vis_operation':'delete_billing_method_setting', 'vis_form':'vis_ticket_base'})"><? echo $vis_language['TXTDELETE']; ?></button>
			   </div>
			</div>
	  </form>
	</div>
</section>
</section>
<? } ?>
<script>
   $(".selectpicker").selectpicker();

   toggleBillingMethod($("input[name='vis_billing_method']:checked").val());
   function toggleBillingMethod(method_id)
   {
        if(method_id ==0)
        {
			 $('#ticket_base_area').show();
			 $('#time_base_area').hide();
		}
        else if(method_id == 1)
        {
			 $('#ticket_base_area').hide();
			 $('#time_base_area').show();
		}
   }
</script>
