<?php $this->load->view("partial/header"); ?>
<div id="content-header" class="hidden-print">
	<h1 > <i class="fa fa-pencil"></i>  <?php  if(!isset($expence_info) && !$expence_info->expence_id) { echo 'Add Expense'; } else { echo "Update Expense"; }    ?>	</h1>
</div>

<div id="breadcrumb" class="hidden-print">
	<?php echo create_breadcrumb(); ?>
</div>
<div class="clear"></div>

<?php //if (isset($needs_auth) && $needs_auth) {} else {
	
	if(isset($expence_info->expence_id) && $expence_info->expence_id>0){ $max_expence_id = $expence_info->expence_id;}
	
	?>

	<?php echo form_open_multipart('expences/save/'.$expence_info->expence_id,array('id'=>'expence_form','class'=>'form-horizontal','autocomplete'=> 'off')); ?>
		<div class="row" id="form">
			<div class="col-md-12">
				<?php echo lang('common_fields_required_message'); ?>
				
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon">
							<i class="fa fa-align-justify"></i>									
						</span>
						<h5><?php echo "Expense Details"; ?></h5>
					</div>
					<div class="widget-content nopadding">

					<div class="form-group">
							<?php echo form_label('Expense Id:', 'max_expence_id',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'max_expence_id',
									'id'=>'max_expence_id',
									'readonly'=>'readonly',
									'value'=>$max_expence_id)
								);?>
							</div>
						</div>
<div class="form-group">
							<?php echo form_label('Expense Date:', 'expence_time',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
<div class="input-group date datepicker" data-date="<?php echo $expence_info->expence_time ? date(get_date_format(), strtotime($expence_info->expence_time)) : ''; ?>" data-date-format=<?php echo json_encode(get_js_date_format()); ?>>
  					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                                <?php
												echo form_input(array(
				        'name'=>'expence_time',
				        'id'=>'expence_time',
					'class'=>'input-small form-inps',
				        'value'=>$expence_info->expence_time ? date(get_date_format(), strtotime($expence_info->expence_time)) : date(get_date_format(), strtotime(date('d-m-Y'))))
				    );
												?> 
                                                </div>
                                                </div></div>

						<div class="form-group">
							<?php echo form_label('Title:', 'title',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'title',
									'id'=>'title',
									'value'=>$expence_info->title)
								);?>
							</div>
						</div>

						<div class="form-group">
							<?php echo form_label('Expense Type:', 'expence_type',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
                            <select name="expence_type" id="expence_type" class="form-control">
                            	<option  value="">-Select expence type-</option>
                            	<option value="General Expense">General Expense</option>
                            	<option value="Supplies Expense">Supplies Expense</option>
                            	<option value="Petty Cash">Petty Cash</option>
                            	<option value="Insurance">Insurance</option>
                            	<option value="Taxes">Taxes</option>
                            	<option value="Utilities">Utilities</option>
                            	<option value="Travel">Travel</option>
                            	<option value="Maintenance">Maintenance</option>
                            	<option value="Training">Training</option>
                            	<option value="Meal & Entertainment">Meal & Entertainment</option>
                            	<option value="Rent">Rent</option>
                                <?php if($expence_info->expence_type) {?>
									<option value="<?php echo $expence_info->expence_type ?>"><?php echo $expence_info->expence_type; ?></option>
								
								<?php } ?>
                            </select>
								<?php /*?><?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'expence_type',
									'id'=>'expence_type',
									'value'=>$expence_info->expence_type)
								);?><?php */?>
							</div>
						</div>
                        
                        
                        <div class="form-group">
							<?php echo form_label('Reference Voucher # :', 'ref_no',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'ref_no',
									'id'=>'ref_no',
									'value'=>$expence_info->ref_no));?>								
							</div>
						</div>
                         <div class="form-group">
							<?php echo form_label('Paid To:', 'paid_to',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'paid_to',
									'id'=>'paid_to',
									'value'=>$expence_info->paid_to));?>								
							</div>
						</div>
                        
						<div class="form-group">
							<?php echo form_label('Description:', 'comments',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								
								<?php echo form_textarea(array(
									'name'=>'comments',
									'id'=>'comments',
									'class'=>'form-textarea',
									'rows'=>'4',
									'cols'=>'30',
									'value'=>$expence_info->comments));?>								
							</div>
						</div>
                        
                        
                        

						
					

						<div class="form-group">
							<?php echo form_label('Amount:', 'amount',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'amount',
									'id'=>'amount',
									'value'=>$expence_info->amount)
								);?>
							</div>
						</div>

						

						
						
						
                        

						
	
						

						
					
						
					
						<!--End more Taxes Container-->					
						

						

						<?php echo form_hidden('redirect', $redirect); ?>

						<div class="form-actions">
					<?php
					
					
					echo form_submit(array(
						'name'=>'submitf',
						'id'=>'submitf',
						'value'=>lang('common_submit'),
						'class'=>'submit_button btn btn-primary')
					);
					?>
					</div>
				<?php echo form_close(); ?>
			<?php //}?>
			</div>
		</div>
	</div>
</div>
</div>
		

<script type='text/javascript'>
	var submitting = false;
		//validation and submit handling
		$(document).ready(function()
		{
			$('.datepicker').datepicker({
		format: <?php echo json_encode(get_js_date_format()); ?>
	});
			
			var submitting = false;
			$('#expence_form').validate({
				submitHandler:function(form)
				{
					if (submitting) return;
					submitting = true;
					$("#form").mask(<?php echo json_encode(lang('common_wait')); ?>);
					$(form).ajaxSubmit({
					success:function(response)
					{
						$("#form").unmask();
						submitting = false;

						gritter(<?php echo json_encode(lang('common_success')); ?>+' #' + response.expence_id,response.message,response.success ? 'gritter-item-success' : 'gritter-item-error',false,false);

						
						if(response.success)
						{
							window.location.href = '<?php echo site_url('expences/view/-1'); ?>'
						}
										
					},
					<?php if(!$expence_info->expence_id) { ?>
					resetForm: true,
					<?php } ?>
					dataType:'json'
				});

				},
				errorClass: "text-danger",
				errorElement: "span",
					highlight:function(element, errorClass, validClass) {
						$(element).parents('.form-group').removeClass('has-success').addClass('has-error');
					},
					unhighlight: function(element, errorClass, validClass) {
						$(element).parents('.form-group').removeClass('has-error').addClass('has-success');
					},
				rules:
				{
					title:
					{
						required:true,
					},
					comments:
					{
						required:true
					},
					expence_type:
					{
						required:true
					},
					amount:
					{
						required: true
					}
		   		},
				messages:
				{
					title:
					{
						required:<?php echo json_encode("Title For expence is required"); ?>,

					},
					amount:
					{
						required:<?php echo json_encode("Amount To be added for expence"); ?>,
						number:<?php echo json_encode("Please enter valid Aoumt"); ?>
					},
					comments:
					{
						required:<?php echo json_encode('Expence details are required'); ?>
					},
					expence_type:
					{
						required:<?php echo json_encode('Please add expence type'); ?>
					}
				}
			});
			
			
		});

</script>
<?php $this->load->view('partial/footer'); ?>