<?php
$title = 'Edit Deposit';
require_once('header-links.php');
// require_once('../lib/basic-function.php');
// require_once('../lib/user-functions.php');
// require_once('../lib/investment-plan-functions.php');
// require_once('../lib/package-functions.php');
// require_once('../lib/currency-functions.php');
$txn = $basicFunctn->getDataDlt($_GET['txn'],$basicFunctn->transaction_tb);
$investment = $basicFunctn->getDataDlt($txn['investment_type_id'],$basicFunctn->investment_plan_tb);
$coin = $basicFunctn->getDataDlt($txn['coin_type_id'],$basicFunctn->currencies_tb);
$package = $basicFunctn->getDataDlt($txn['plan_id'],$basicFunctn->package_tb);
?>

<body>
    <div class="app">
        <div class="layout">
            <?php require_once('sidebar.php'); ?>

            <!-- Page Container START -->
            <div class="page-container">
                <?php require_once('header.php'); ?>

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-title">
                            <h4>Edit Deposit</h4>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="row">
                                            <div class="col-md-8  ml-auto mr-auto">
                                                <!-- <h4 class="card-title">Basic inputs</h4> -->
                                                <form class="form-horizontal mrg-top-40 edit_txn_form">
                                                    <input type="hidden" name="edit_deposit_txn_id" value="<?php print $_GET['txn']; ?>"></input>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-2 control-label">Investment</label>
                                                        <div class="col-md-4">
                                                            <input type="text" value="<?php print $investment['name']; ?>" class="form-control" name="edit_txn_investment" placeholder="Investment" disabled>
                                                        </div>
                                                        <label for="form-1-2" class="col-md-2 control-label">Package</label>
                                                        <div class="col-md-4">
                                                            <input type="text" value="<?php print $package['name']; ?>" class="form-control" name="package" placeholder="Package" disabled>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-2 control-label">Coin</label>
                                                        <div class="col-md-4">
                                                            <input type="text" value="<?php print $coin['name']; ?>" class="form-control" name="coin" placeholder="Coin" disabled>
                                                        </div>
                                                        <label for="form-1-2" class="col-md-2 control-label">Amount($)</label>
                                                        <div class="col-md-4">
                                                            <input type="text" value="<?php print $txn['amt_in_usd']; ?>" class="form-control" name="amount" placeholder="Amount($)" disabled>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-2 control-label">Status</label>
                                                        <div class="col-md-4">
                                                            <!-- <input type="text" value="<?php //print $txn['status']; ?>" class="form-control" id="form-1-1" placeholder="Status"> -->
                                                            <select name="status" class="form-control">
                                                                <option value="" selected>--Transaction Status--</option>
                                                                <option <?php if($txn['status'] == 'confirmed'){print 'selected';} ?> value="confirmed">Confirmed</option>
                                                                <option <?php if($txn['status'] == 'pending'){print 'selected';} ?> value="pending">Pending</option>
                                                                <option <?php if($txn['status'] == 'completed'){print 'selected';} ?> value="completed">Completed</option>
                                                            </select>
                                                        </div>
                                                        <label for="form-1-2" class="col-md-2 control-label">Interest($)</label>
                                                        <div class="col-md-4">
                                                            <input type="number" value="<?php print $txn['interest_in_usd']; ?>" class="form-control" name="interest" placeholder="Interest">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <div class="col-md-6 col-xs-6">
                                                            <div class="text-right">
                                                                <button type="submit" name="" class="btn btn-primary edit_txn_btn">Edit Deposit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->
                <?php require_once('footer.php'); ?>
                <!-- Footer END -->

            </div>
            <!-- Page Container END -->

        </div>
    </div>

    <?php require_once('footer-links.php'); ?>
    <script>
        
        $('.edit_txn_btn').click(async function(e) {
            e.preventDefault();
            let edit_txn_form = $('.edit_txn_form').serializeArray();
            let form_data = set_form_data(edit_txn_form);
            // console.log(edit_txn_form);
            // console.log(edit_txn_form[0].value);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            throwSweetalert(returned, 'edit-deposit?txn='+edit_txn_form[0].value, 1);
        });
    </script>