<?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="erp-page">
	<div id="transaction_deposit_state_report_div"></div>

	<?php
	$page_actions = '';
	if (!empty($created) || !empty($edited)) {
		$page_actions .= '<a href="' . base_url('admin/transactions/create_deposit') . '" class="erp-btn erp-btn-primary"><i data-lucide="plus" class="h-4 w-4"></i><span>' . lang('new_deposit') . '</span></a>';
		$page_actions .= '<a href="' . base_url('admin/transactions/import/Income') . '" class="erp-btn"><i data-lucide="upload" class="h-4 w-4"></i><span>' . lang('import') . ' ' . lang('deposit') . '</span></a>';
	}

	ob_start();
	?>
	<table class="erp-table table table-striped DataTables bulk_table min-w-[980px] whitespace-nowrap" id="DataTables" cellspacing="0" width="100%">
		<thead>
			<tr>
				<?php if (!empty($edited) || !empty($deleted)) { ?>
					<th data-orderable="false">
						<div class="checkbox c-checkbox">
							<label class="needsclick">
								<input id="select_all" type="checkbox">
							</label>
						</div>
					</th>
				<?php } ?>
				<th><?= lang('deposit') . ' ' . lang('prefix'); ?></th>
				<th><?= lang('name') . '/' . lang('title'); ?></th>
				<th><?= lang('date'); ?></th>
				<th><?= lang('account'); ?></th>
				<th><?= lang('paid_by'); ?></th>
				<th><?= lang('tags'); ?></th>
				<th><?= lang('amount'); ?></th>
				<th><?= lang('balance'); ?></th>
				<?php $show_custom_fields = custom_form_table(1, null);
				if (!empty($show_custom_fields)) {
					foreach ($show_custom_fields as $c_label => $v_fields) {
						if (!empty($c_label)) { ?>
							<th><?= $c_label; ?></th>
				<?php }
					}
				}
				?>
				<th><?= lang('attachment'); ?></th>
				<?php if (!empty($edited) || !empty($deleted)) { ?>
					<th class="col-options no-sort text-right"><?= lang('action'); ?></th>
				<?php } ?>
			</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/depositList";
	bulk_url = base_url + "admin/transactions/bulk_delete_deposit";

	function reloadDeposits(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.depositAccountFilter = function(id) {
			reloadDeposits(id, 'by_account');
		};
		window.depositCategoryFilter = function(id) {
			reloadDeposits(id, 'by_category');
		};

		ins_data(base_url + 'admin/transactions/transaction_deposit_state_report');
	});
</script>
