<style type="text/css">
    .chosen-container a.chosen-single{line-height: 24px !important;}
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'edit_fixing_expenses'); ?></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('/fixing-expenses'); ?>"><?= print_lang($app_lang,'fixing_expenses'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'edit_fixing_expenses'); ?></strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-title">
        <h5><?= print_lang($app_lang,'fields_with'); ?> <strong class="text-danger">*</strong> <?= print_lang($app_lang,'are_mandatory'); ?></h5>
    </div>
    <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-fixing-expenses-form">

                    <div class="row" style="margin-bottom: 5px;">
                        <div class="col-md-3 fixed-fields-input pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'currency'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="temp_currency">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'select_currency'); ?> --</option>
                                    <?php foreach($currencies as $row){ ?>
                                        <option value="<?= $row['uid']; ?>" data-usd-equalance="<?= $row['usd_equalance']; ?>" <?php if($editing_data['currency'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?> (<?= $row['symbol']; ?>)</option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3 fixed-fields-input pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'rate'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="temp_rate" value="<?= $editing_data['currency_usd_equalance']; ?>" placeholder="<?= print_lang($app_lang,'rate'); ?>">
                            </div>
                        </div>
                        <div class="col-md-3 fixed-fields-input pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'invoice'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="temp_invoice" value="<?= $editing_data['invoice']; ?>" placeholder="<?= print_lang($app_lang,'invoice_#'); ?>">
                            </div>
                        </div>
                        <div class="col-md-3 fixed-fields-input pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'agent'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="temp_agent">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'select_agent'); ?> --</option>
                                    <?php foreach($accounts as $row){ ?>
                                        <?php if($row['type'] != 'transit'){ continue; } ?>
                                        <option value="<?= $row['uid']; ?>" data-agent-name="<?= $row['name']; ?>" <?php if($editing_data['agent'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="row" style="margin-bottom: 5px;">
                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'car'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="temp_car">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'select_car'); ?> --</option>
                                    <?php foreach($cars as $row){ ?>
                                        <option value="<?= $row['uid']; ?>" data-car-name="<?= $row['car_name']; ?>"><?= $row['car_name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'amount'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="temp_amount" placeholder="<?= print_lang($app_lang,'amount'); ?>">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'details'); ?></label>
                                <input type="text" class="form-control" name="temp_details" placeholder="<?= print_lang($app_lang,'details'); ?>">
                            </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,'add_to_purchase'); ?></button>
                        </div>
                    </div>

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

        <form role="form" id="fixing-expenses-form" action="<?php echo url('/fixing-expenses/update').'/'.$editing_data['uid']; ?>">
            <div id="deleted-items-wrapper"></div>
            <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,'car'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'amount'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'details'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'action'); ?></th>
                                </tr>
                            </thead>
                            <tbody id="fixing-expenses-table-body">
                                <?php foreach($invoice_details as $row){ ?>
                                    <tr class="text-center fixing-expenses-item-row">
                                        <td>
                                            <?= array_key_exists($row['car'], $cars) ? $cars[$row['car']]['car_name'] : NULL; ?>
                                            <input type="hidden" name="uid[]" value="<?= $row['uid']; ?>">
                                            <input type="hidden" name="mode[]" value="existing">
                                            <input type="hidden" name="car[]" value="<?= $row['car']; ?>">
                                            <input type="hidden" name="currency[]" value="<?= $editing_data['currency']; ?>">
                                            <input type="hidden" name="rate[]" value="<?= $editing_data['currency_usd_equalance']; ?>">
                                            <input type="hidden" name="agent[]" value="<?= $editing_data['agent']; ?>">
                                            <input type="hidden" name="invoice[]" value="<?= $editing_data['invoice']; ?>">
                                        </td>
                                        <td class="amount-col"><input type="text" class="fixing-expenses-editable-iputs" name="amount[]" value="<?= $row['amount']; ?>"></td>
                                        <td><?= $row['details']; ?><input type="hidden" name="details[]" value="<?= $row['details']; ?>"></td>
                                        <td style="width: 40px;"><a class="btn btn-danger btn-sm fixing-expenses-item-del-trigger existing-item" data-uid="<?= $row['uid']; ?>" href="javascript:void(0);"><i class="fa fa-trash"></i></a></td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>    
                    </div>
                </div>

                <div class="col-md-12"><hr></div>
                <div class="col-md-12 fixing-expenses-totals-col">
                    <div class="row">
                        <div class="col-md-12 purchase-total-cel fixing-expenses-total-amount-row">
                            <strong><?= print_lang($app_lang,'total_amount'); ?>: </strong>
                            <span class="cals-span"><?= amount_number_format($editing_data['total_amount']); ?></span>
                            <input class="cals-input" type="hidden" name="total_amount" value="<?= $editing_data['total_amount']; ?>">
                        </div>
                    </div>
                </div>
                <div class="col-md-12"><hr></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,'update_print'); ?>">
                </div>

            </div>
        </form>

    </div>

</div>