<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?= message_box('success'); ?>
<?= message_box('error'); ?>

<?php
$created = can_action('30', 'created');
$edited = can_action('30', 'edited');
$deleted = can_action('30', 'deleted');
?>

<div class="space-y-4">
	<?php ob_start(); ?>
	<table class="erp-table table table-striped DataTables min-w-[980px] whitespace-nowrap" id="DataTables" cellspacing="0" width="100%">
		<thead>
			<tr>
				<th><?= lang('from_account'); ?></th>
				<th><?= lang('to_account'); ?></th>
				<th class="col-currency"><?= lang('amount'); ?></th>
				<th><?= lang('date'); ?></th>
				<th><?= lang('attachment'); ?></th>
				<th class="col-options no-sort text-right"><?= lang('action'); ?></th>
			</tr>
		</thead>
		<tbody></tbody>
	</table>
	<?php
	$table_markup = ob_get_clean();
	echo $this->load->view('admin/common/erp/table_shell', array(		
		'table' => $table_markup,
	), true);
	?>
</div>

<script>
	list = base_url + "admin/transactions/transferList";

	function reloadTransfers(filter, searchType) {
		var url = list;
		if (filter) {
			url += "/" + filter;
			if (searchType) {
				url += "/" + searchType;
			}
		}
		if (typeof table_url !== "undefined") {
			table_url(url);
		} else if (typeof fire_datatable === "function") {
			fire_datatable(url);
		}
	}

	$(function() {
		window.transferFromAccountFilter = function(id) {
			reloadTransfers(id, 'from_account');
		};
		window.transferToAccountFilter = function(id) {
			reloadTransfers(id, 'to_account');
		};
		$(document).on('click', '[data-transfer-filter-action]', function() {
			var filter = $(this).data('transfer-filter') || '';
			var searchType = $(this).data('transfer-search') || '';
			reloadTransfers(filter, searchType);
		});
	});
</script>
