<?php $this->load->view("partial/header"); ?>

<div class="row">
	<div class="col-md-12">
		<div class="panel panel-piluku">
			<div class="panel-heading"><h3 class="panel-title"><?php echo lang('cierre_config'); ?></h3></div>
			<div class="panel-body">
				<?php if ($this->session->flashdata('manage_success_message')) { ?>
					<div class="alert alert-success"><?php echo H($this->session->flashdata('manage_success_message')); ?></div>
				<?php } ?>

				<h4><?php echo lang('cierre_config_general'); ?></h4>
				<?php echo form_open('cierre/config'); ?>
				<input type="hidden" name="save_general" value="1" />
				<div class="form-group" style="max-width:300px;">
					<label><?php echo lang('cierre_margen_error'); ?></label>
					<input type="number" step="0.01" class="form-control" name="margen_error_usd" value="<?php echo H($margen_error); ?>" />
				</div>
				<button class="btn btn-primary" type="submit"><?php echo lang('common_save'); ?></button>
				<?php echo form_close(); ?>

				<hr />
				<h4><?php echo lang('cierre_config_cajas'); ?></h4>
				<?php echo form_open('cierre/config'); ?>
				<input type="hidden" name="save_cajas" value="1" />
				<div class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th><?php echo lang('cierre_caja'); ?></th>
								<th><?php echo lang('cierre_alias'); ?></th>
								<th><?php echo lang('cierre_orden'); ?></th>
								<th><?php echo lang('common_active'); ?></th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($employees as $e) { 
								$existing = NULL;
								foreach($cajas as $c){ if((int)$c->person_id === (int)$e->person_id){ $existing = $c; break; } }
							?>
							<tr>
								<td><?php echo H($e->first_name.' '.$e->last_name); ?></td>
								<td><input class="form-control" name="cajas[<?php echo (int)$e->person_id; ?>][alias]" value="<?php echo H($existing ? $existing->alias : ''); ?>" /></td>
								<td style="width:120px;"><input type="number" class="form-control" name="cajas[<?php echo (int)$e->person_id; ?>][orden]" value="<?php echo H($existing ? $existing->orden : 0); ?>" /></td>
								<td class="text-center" style="width:120px;">
									<?php $caja_toggle_id = 'caja_activo_'.(int)$e->person_id; ?><input type="checkbox" id="<?php echo $caja_toggle_id; ?>" name="cajas[<?php echo (int)$e->person_id; ?>][activo]" value="1" <?php echo ($existing && $existing->activo) ? 'checked' : ''; ?> /><label for="<?php echo $caja_toggle_id; ?>"><span></span></label>
								</td>
							</tr>
							<?php } ?>
						</tbody>
					</table>
				</div>
				<button class="btn btn-primary" type="submit"><?php echo lang('common_save'); ?></button>
				<?php echo form_close(); ?>

				<hr />
				<h4><?php echo lang('cierre_config_pagos'); ?></h4>
				<p class="help-block"><?php echo lang('cierre_config_pagos_help'); ?></p>
				<?php echo form_open('cierre/config'); ?>
				<input type="hidden" name="save_pagos" value="1" />
				<div class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th><?php echo lang('cierre_tipo_pago'); ?></th>
								<th><?php echo lang('cierre_moneda'); ?></th>
								<th><?php echo lang('cierre_orden'); ?></th>
								<th><?php echo lang('cierre_contar_total'); ?></th>
								<th><?php echo lang('cierre_desglose'); ?></th>
								<th><?php echo lang('cierre_include_in_verification'); ?></th>
								<th><?php echo lang('common_active'); ?></th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($pagos as $p) { ?>
							<tr>
								<td><?php echo H($p->nombre); ?></td>
								<td style="width:120px;">
									<select class="form-control" name="pagos[<?php echo (int)$p->id; ?>][moneda_base]">
										<option value="USD" <?php echo $p->moneda_base=='USD'?'selected':''; ?>>USD</option>
										<option value="BS" <?php echo $p->moneda_base=='BS'?'selected':''; ?>>BS</option>
									</select>
								</td>
								<td style="width:120px;"><input type="number" class="form-control" name="pagos[<?php echo (int)$p->id; ?>][orden]" value="<?php echo H($p->orden); ?>" /></td>
								<td class="text-center" style="width:120px;"><?php $pago_contar_id = 'pago_contar_'.(int)$p->id; ?><input type="checkbox" id="<?php echo $pago_contar_id; ?>" name="pagos[<?php echo (int)$p->id; ?>][contar_en_total]" value="1" <?php echo $p->contar_en_total ? 'checked' : ''; ?> /><label for="<?php echo $pago_contar_id; ?>"><span></span></label></td>
								<td class="text-center" style="width:120px;"><?php $pago_desglose_id = 'pago_desglose_'.(int)$p->id; ?><input type="checkbox" id="<?php echo $pago_desglose_id; ?>" name="pagos[<?php echo (int)$p->id; ?>][enable_breakdown]" value="1" <?php echo !empty($p->enable_breakdown) ? 'checked' : ''; ?> /><label for="<?php echo $pago_desglose_id; ?>"><span></span></label></td>
								<td class="text-center" style="width:120px;"><?php $pago_verif_id = 'pago_verif_'.(int)$p->id; ?><input type="checkbox" id="<?php echo $pago_verif_id; ?>" name="pagos[<?php echo (int)$p->id; ?>][include_in_verification]" value="1" <?php echo !empty($p->include_in_verification) ? 'checked' : ''; ?> /><label for="<?php echo $pago_verif_id; ?>"><span></span></label></td>
								<td class="text-center" style="width:120px;"><?php $pago_activo_id = 'pago_activo_'.(int)$p->id; ?><input type="checkbox" id="<?php echo $pago_activo_id; ?>" name="pagos[<?php echo (int)$p->id; ?>][activo]" value="1" <?php echo $p->activo ? 'checked' : ''; ?> /><label for="<?php echo $pago_activo_id; ?>"><span></span></label></td>
							</tr>
							<?php } ?>
						</tbody>
					</table>
				</div>
				<button class="btn btn-primary" type="submit"><?php echo lang('common_save'); ?></button>
				<?php echo anchor('cierre', lang('common_cancel'), array('class'=>'btn btn-default')); ?>
				<?php echo form_close(); ?>

			</div>
		</div>
	</div>
</div>

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