<?php
    session_start();
    include("library/conn.php");
    
    $role_rs = array();
	$get_role_mode = mysqli_query($conn, "SELECT * FROM user_role_privileges WHERE userID = '". $_SESSION['userIdd'] ."' AND roleName = 'account_numbers'") or die (mysqli_error($conn));
	if (mysqli_num_rows($get_role_mode) > 0) {
		$role_rs = mysqli_fetch_array($get_role_mode);
	} else {
		$role_rs = ['-1', '-1', '-1', '-1', '-1', '-1'];
	}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <?php include("library/head.php");?>
        <title>Account Numbers | <?php echo $_SESSION['systemName']; ?></title>
    </head>
    <body class="app sidebar-mini">

        <!-- Navbar-->
        <?php include("library/header.php");?>
        <!-- Sidebar menu-->
        <div class="app-sidebar__overlay" data-toggle="sidebar"></div>
        <?php include("library/sidebar.php");?>
    	
        <main class="app-content">
            <div class="app-title">
                <div>
                    <h4 class="text-primary"><i class="fa fa-hashtag fa-lg"></i> ACCOUNT NUMBERS</h4>
                    <p>Account Numbers Page</p>
                </div>
                <ul class="app-breadcrumb breadcrumb">
                    <li class="breadcrumb-item"><i class="fa fa-home"></i></li>
                    <li class="breadcrumb-item"><a href="account-numbers">Account Numbers</a></li>
                </ul>
            </div>
      
            <?php include("models/admin_config.php");?>
            <?php include("models/system_config.php");?>

            <div class="row">

                <div class="col-md-4">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
                                    <h5 class="text-primary"><i class="fa fa-plus-square"></i> Register Account</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
                                    <form action="#" method="POST" id="addNewkAccountNumberForm">
                                        <div class="row">
                                            
                                            <div class="form-group col-md-5">
                                                <label class="control-label">Account Type</label>
                                                <select class="form-control" style="width: 100%;" name="cmbAccountNumbersAccountType" id="cmbAccountNumbersAccountType" required>
                                                    <option selected value="">Select Type</option>
                                                    <option value="1">Bank Account</option>
                                                    <option value="2">Mobile Account</option>
                                                    <option value="3">Cash Account</option>
                                                </select>
                                            </div>
                                            <div class="form-group col-md-7">
                                                <label class="control-label" id="accountGatewayNameLabel"> &nbsp; </label>
                                                <select class="form-control" style="width: 100%;" name="cmbAccountNumbersGatewayName" id="cmbAccountNumbersGatewayName" required>
                                                    
                                                </select>
                                            </div>
                                            <div class="form-group col-md-12">
                                                <label class="control-label" id="bankAccountNameLabel"> &nbsp; </label>
                                                <input class="form-control" type="text" name="txtAccountNumbersAccountName" id="txtAccountNumbersAccountName" placeholder="Example: Salam Somali Bank" required>
                                            </div>
                                            <div class="form-group col-md-12">
                                                <label class="control-label" id="bankAccountNumberLabel"> &nbsp; </label>
                                                <input class="form-control" type="text" name="txtAccountNumbersAccountNumber" id="txtAccountNumbersAccountNumber" placeholder="Example: 30343536" required>
                                            </div>
                                            <div class="form-group col-md-12">
                                                <label class="control-label">Openning Balance</label>
                                                <input class="form-control" type="text" name="txtBankAccountNumberOpenningBalance" id="txtBankAccountNumberOpenningBalance" value="0" required>
                                                <input class="form-control" type="hidden" name="txtUserrIddd" id="txtUserrIddd" value="<?php echo $_SESSION['userIdd']; ?>" required>
                                                <input class="form-control" type="hidden" name="txtBankAccountRegisterDate" id="txtBankAccountRegisterDate" value="<?php echo date("Y-m-d H:i:s"); ?>" required>
                                            </div>
                                            <div class="form-group col-md-12 text-right">
                                                <button type="submit" class="btn btn-success" name="btnRegisterAccountNumber" id="btnRegisterAccountNumber"><i class="fa fa-fw fa-lg fa-save"></i>Register Account Number</button>
											</div>
                                        </div>
                                    </form>						
					            </div>
						    </div>
					    </div>
				    </div>
			    </div>

                <div class="col-md-8">
                    <div class="tile">
                        <div class="tile-body">
                            <div class="row">
								<div class="form-group col-md-12">
									<h5 class="pb-2">
										<span><i class="fa fa-list-ul"></i> Account Numbers List</span>
										<span>
											<button type="button" class="btn btn-success pull-right" data-toggle="modal" data-target="#addNewAccountNumberModal"><i class="fa fa-plus"></i> Register New Account</button>
										</span>
									</h5>
									<hr />
								</div>
							</div>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover table-sm" id="accountNumbersTable">
                                    <thead>
										<tr class="text-center bg-primary text-light" height="35px">
                                            <th class="align-middle">Logo</th>
											<th class="align-middle">Name</th>
											<th class="align-middle">Account Information</th>
											<th class="align-middle">Account Type</th>
											<th class="align-middle">Created By</th>
											<th class="align-middle">Create Date</th>
                                            <th class="align-middle">Action</th>
                                         </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            $getAccountNumbers = mysqli_query($conn, "SELECT account_numbers.accountNoID, payment_gateways.gatewayLogo, payment_gateways.gatewayName, account_numbers.accountNoName, account_numbers.accountNumber, payment_gateways.gatewayType, system_users.userName, account_numbers.registerDate
                                            FROM account_numbers
                                            JOIN payment_gateways ON account_numbers.gatewayID = payment_gateways.gatewayID
                                            JOIN system_users ON account_numbers.registeredBy = system_users.userID
                                            ORDER BY account_numbers.accountNoName ASC") or die(mysqli_error($conn));
                                            $account_type_list = array("Bank Account", "Mobile Account", "Cash Account");
                                            while ($accounts_rs = mysqli_fetch_array($getAccountNumbers)) {?>
                                                    <td class="align-middle text-center py-1"><img class="img-fluid rounded-circle" src="<?php echo $accounts_rs[1]; ?>" width="35px" height="35px"/></td>
                                                    <td class="align-middle text-left"><?php echo $accounts_rs[2]; ?></td>
                                                    <td class="align-middle text-left"><?php echo $accounts_rs[3]. " (". $accounts_rs[4]. ")"; ?></td>
                                                    <td class="align-middle text-left"><?php echo $account_type_list[$accounts_rs[5] - 1]; ?></td>
                                                    <td class="align-middle text-left"><?php echo $accounts_rs[6]; ?></td>
                                                    <td class="align-middle text-center"><?php echo substr($accounts_rs[7], 0, 10); ?></td>
                                                    <td class="align-middle text-center"><span class="btn btn-outline-danger btnDeleteAccountNumber" id="<?php echo "Delete". $accounts_rs[0]; ?>" data-id="<?php echo $accounts_rs[0]; ?>"><i class="fa fa-fw fa-lg fa-trash"></i> Delete Account</span></td>
                                                </tr><?php
                                            }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
	
    	<!-- Essential javascripts for application to work-->
    	<?php include("library/footer.php");?>	
        <?php include("library/scripts.php");?>
        <script type="text/javascript">
            $('#accountNumbersTable').DataTable({"pageLength": 100, "order": []})
            $("#cmbAccountNumbersAccountType, #cmbAccountNumbersGatewayName").select2()
        </script>
    </body>
</html>