<style type="text/css">
    .chosen-container a.chosen-single{line-height: 24px !important;}
    .form-group{margin-bottom: 4px !important;}
</style>
<div id="confirm_msg_div" class="row wrapper border-bottom white-bg page-heading confirm-leave">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'mod_db_cr_nt_edit_breadcrumb'); ?></h2>
        <ol class="breadcrumb">
            <li>
                <a class="url-elem" href="<?php echo url('/dashboard'); ?>"><?= print_lang($app_lang,'home'); ?></a>
            </li>
            <li>
                <a class="url-elem" href="<?php echo url('/debit-credit-note'); ?>"><?= print_lang($app_lang,'mod_db_cr_nt_view_breadcrumb'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'mod_db_cr_nt_edit_breadcrumb'); ?></strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>

<span id="debit-type-account" class="display-none"><?= print_lang($app_lang,'mod_db_cr_nt_add_db_account'); ?></span>
<span id="debit-type-amount" class="display-none"><?= print_lang($app_lang,'mod_db_cr_nt_add_db_amount'); ?></span>
<span id="credit-type-account" class="display-none"><?= print_lang($app_lang,'mod_db_cr_nt_add_cr_account'); ?></span>
<span id="credit-type-amount" class="display-none"><?= print_lang($app_lang,'mod_db_cr_nt_add_cr_amount'); ?></span>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-content">
        <!-- spinner -->
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
        <!-- spinner -->
        <div class="row">
            <div class="col-sm-12 b-r">
                <form role="form" id="temp-debit-credit-form">
                    <div class="row">
                        <div class="col-md-10 text-center pointer-none">
                            <div class="form-group">
                                <div style="margin-top: 10px;">
                                    <label class="checkbox-inline i-checks">
                                        <input type="radio" name="type" value="debit" checked> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'mod_db_cr_nt_add_type_db'); ?>
                                    </label>
                                    <label class="checkbox-inline i-checks" style="margin-left: 30px;">
                                        <input type="radio" name="type" value="credit"> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'mod_db_cr_nt_add_type_cr'); ?>
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-2">
                            <div class="text-<?php if($app_direction == 'rtl'){echo 'left';}else{echo 'right';} ?>">
                                <input style="width: 100px; border: none; background: #e0e0e0; padding: 9px 5px; text-align: center; border-radius: 2px; color: black;" type="text" class="pointer-none" value="<?= print_lang($app_lang,'add_entry_sr_num').' '.$editing_data['serial_id']; ?>" readonly="">
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div class="row " style="margin-bottom: 5px;">
                        <div class="col-md-12">
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'mod_db_cr_nt_add_currency'); ?> <strong class="text-danger">*</strong></label>
                                        <select class="form-control chosen-select" name="temp_currency">
                                            <option disabled="" selected="">-- <?= print_lang($app_lang,'select'); ?> --</option>
                                            <?php foreach($currencies as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($editing_data['currency'] == $row['uid']){echo "selected='selected'";}?>><?= $row['name']; ?> (<?= $row['symbol']; ?>)</option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="main-account-label"><?= print_lang($app_lang,'mod_db_cr_nt_add_db_account'); ?> </label>
                                        <select class="form-control chosen-select" name="temp_account">
                                            <option disabled="" selected="">-- <?= print_lang($app_lang,'select'); ?> --</option>
                                            <?php foreach($accounts as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" data-account-type="<?= $row['type']; ?>" <?php if($editing_data['account'] == $row['uid']){echo "selected='selected'";}?>><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="main-amount-label"><?= print_lang($app_lang,'mod_db_cr_nt_add_db_amount'); ?> </label>
                                        <input type="number" class="form-control" value="<?= $editing_data['amount']; ?>" name="temp_amount" placeholder="1000">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'mod_db_cr_nt_add_narration'); ?></label>
                                        <textarea class="form-control" name="main_temp_narration" placeholder="<?= print_lang($app_lang,'mod_db_cr_nt_add_narration'); ?>"><?= $editing_data['narration']; ?></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <h4 class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_division'); ?></h4>
                    <hr>

                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label class="d-account-label"><?= print_lang($app_lang,'mod_db_cr_nt_add_cr_account'); ?> </label>
                                <select class="form-control chosen-select" name="temp_d_account">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'select'); ?> --</option>
                                    <?php foreach($accounts as $row){ ?>
                                        <option value="<?= $row['uid']; ?>" data-account-type="<?= $row['type']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label class="d-amount-label"><?= print_lang($app_lang,'mod_db_cr_nt_add_cr_amount'); ?> </label>
                                <input type="number" class="form-control" name="temp_d_amount" placeholder="1000">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mod_db_cr_nt_add_narration'); ?></label>
                                <textarea class="form-control" name="temp_narration" placeholder="<?= print_lang($app_lang,'mod_db_cr_nt_add_narration'); ?>"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="row extra-mar-botm">
                        <div class="col-md-12 text-right">
                            <button style="width: 100%;" class="btn btn-w-m btn-primary" type="submit"><?= print_lang($app_lang,'mod_trans_in_add_input_add_to_list'); ?></button>
                        </div>
                    </div>

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

        <form role="form" id="debit-credit-note-form" action="<?php echo url('/debit-credit-note/update').'/'.$editing_data['uid']; ?>">
            <input type="hidden" name="main_narration" class="debit-credit-note-narration" value="<?= $editing_data['narration']; ?>">
            <div class="row" style="margin-top: 10px;">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_tbl_account'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_tbl_type'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_tbl_amount'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_tbl_narration'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_db_cr_nt_add_action'); ?></th>
                                </tr>
                            </thead>
                            <tbody id="debit-credit-note-table-body">
                                <?php
                                    $db_cr_details = json_decode($editing_data['details'],true);
                                    if(count($db_cr_details) > 0){
                                ?>
                                <?php foreach($db_cr_details as $row){ ?>
                                    <tr class="text-center debit-credit-note-row">
                                        <td class="debit-credit-note-self">
                                            <?= array_key_exists($row['d_account'], $accounts) ? $accounts[$row['d_account']]['name'] : NULL; ?>
                                            <input type="hidden" name="d_account[]" value="<?= $row['d_account']; ?>">
                                            <input type="hidden" name="d_account_type[]" value="<?= $row['d_account_type']; ?>">
                                            <input type="hidden" class="debit-credit-note-account" name="account[]" value="<?= $editing_data['account']; ?>">
                                            <input type="hidden" class="debit-credit-note-currency" name="currency[]" value="<?= $editing_data['currency']; ?>">
                                            <input type="hidden" class="debit-credit-note-account-type" name="type[]" value="<?= $editing_data['type']; ?>">
                                        </td>
                                        <td class="debit-credit-note-type">
                                            <span><?= $row['d_type']; ?></span>
                                            <input type="hidden" name="d_type[]" value="<?= $row['d_type']; ?>">
                                        </td>
                                        <td class="debit-credit-note-d-amount">
                                            <input type="number" style="width: 100px; text-align: center;" class="debit-credit-note-editable-iput" name="d_amount[]" value="<?= $row['d_amount']; ?>">
                                        </td>
                                        <td class="debit-credit-note-narration">
                                            <span><?= $row['narration']; ?></span>
                                            <input type="hidden" name="narration[]" value="<?= $row['narration']; ?>">
                                        </td>
                                        <td style="width: 40px;"><a class="btn btn-danger btn-sm debit-credit-note-del-trigger" href="javascript:void(0);"><i class="fa fa-trash"></i></a></td>
                                    </tr>
                                <?php }} ?>
                            </tbody>
                        </table>    
                    </div>
                </div>

                <div class="col-md-12 debit-credit-note-totals-col">
                    <div class="row">
                        <div class="col-md-4 debit-credit-note-total-main-cel">
                            <strong><?= print_lang($app_lang,'mod_db_cr_nt_add_total'); ?>: </strong>
                            <span class="cals-span"><?= round_decimels_digits($editing_data['amount']); ?></span>
                            <input class="cals-input" type="hidden" name="total" value="<?= $editing_data['amount']; ?>">
                        </div>

                        <div class="col-md-4 debit-credit-note-total-cel">
                            <strong><?= print_lang($app_lang,'mod_db_cr_nt_add_total_division'); ?>: </strong>
                            <span class="cals-span"><?= round_decimels_digits($editing_data['d_amount']); ?></span>
                            <input class="cals-input" type="hidden" name="d_total" value="<?= $editing_data['d_amount']; ?>">
                        </div>
                        <div class="col-md-4 debit-credit-note-pending-cel">
                            <strong><?= print_lang($app_lang,'mod_db_cr_nt_add_pending'); ?>: </strong>
                            <span><?= round_decimels_digits($editing_data['pending']); ?></span>
                            <input type="hidden" name="pending" value="<?= $editing_data['pending']; ?>">
                        </div>

                        <div class="col-md-12" style="margin-top: 20px;">
                            <input type="submit" style="width: 100%;" class="btn btn-primary" value="<?= print_lang($app_lang,'mod_db_cr_nt_edit_update'); ?>">
                        </div>
                    </div>
                </div>

            </div>
        </form>

    </div>

</div>