<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'edit_branch_transfer_in'); ?></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('/branch-transfer-in'); ?>"><?= print_lang($app_lang,'branch_transfer_in'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'edit_branch_transfer_in'); ?></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="branch-transfer-in-form" action="<?php echo url('/branch-transfer-in/update').'/'.$editing_data['uid']; ?>">

                    <div class="row extra-mar-botm">
                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'item'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="item" id="branch-transfer-in-items">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'item'); ?> --</option>
                                    <?php $selected_item = array(); ?>
                                    <?php foreach($items as $row){ ?>
                                        <option value="<?= $row['uid']; ?>" <?php if($row['uid'] == $editing_data['item']){ echo 'selected="selected"'; $selected_item = $row; } ?> data-type="<?= $row['type']; ?>" data-purchase-unit-equalance="<?= $row['purchase_unit_equalance']; ?>" data-sale-unit-equalance="<?= $row['sale_unit_equalance']; ?>" data-production-unit-equalance="<?= $row['production_unit_equalance']; ?>" data-purchase-unit="<?= array_key_exists($row['purchase_unit'],$units) ? $units[$row['purchase_unit']]['name'] : NULL; ?>" data-sale-unit="<?= array_key_exists($row['sale_unit'],$units) ? $units[$row['sale_unit']]['name'] : NULL; ?>" data-production-unit="<?= array_key_exists($row['production_unit'],$units) ? $units[$row['production_unit']]['name'] : NULL; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'to_warehouse'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="to_warehouse" id="branch-transfer-in-to-warehouse">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'warehouse'); ?> --</option>
                                    <?php foreach($warehouses as $row){ if($row['branch'] == $active_branch_id){  ?>
                                        <option <?php if($row['type'] != $selected_item['type']){ echo 'class="display-none"'; } ?> value="<?= $row['uid']; ?>" data-type="<?= $row['type']; ?>" <?php if($row['uid'] == $editing_data['to_warehouse']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                    <?php } } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'unit'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="unit" id="branch-transfer-in-units">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'unit'); ?> --</option>
                                    <?php if(isset($selected_item['purchase_unit'])){ ?>
                                    <option value="purchase" <?php if($editing_data['unit'] == 'purchase'){ echo 'selected="selected"'; } ?>><?= array_key_exists($selected_item['purchase_unit'], $units) ? $units[$selected_item['purchase_unit']]['name'] : NULL; ?></option>
                                    <?php } ?>
                                    <?php if(isset($selected_item['sale_unit'])){ ?>
                                    <?php if($selected_item['sale_unit'] != $selected_item['purchase_unit']){ ?>
                                    <option value="sale" <?php if($editing_data['unit'] == 'sale'){ echo 'selected="selected"'; } ?>><?= array_key_exists($selected_item['sale_unit'], $units) ? $units[$selected_item['sale_unit']]['name'] : NULL; ?></option>
                                    <?php } } ?>
                                    <?php if(isset($selected_item['production_unit'])){ ?>
                                    <?php if($selected_item['production_unit'] != $selected_item['sale_unit'] AND $selected_item['production_unit'] != $selected_item['purchase_unit']){ ?>
                                    <option value="production" <?php if($editing_data['unit'] == 'production'){ echo 'selected="selected"'; } ?>><?= array_key_exists($selected_item['production_unit'], $units) ? $units[$selected_item['production_unit']]['name'] : NULL; ?></option>
                                    <?php } } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-3">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'batch'); ?></label>
                                <input type="text" class="form-control" name="batch" value="<?= $editing_data['batch']; ?>" placeholder="<?= print_lang($app_lang,'batch'); ?>">
                            </div>
                        </div>

                    </div>

                    <div class="row extra-mar-botm">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="qty" value="<?= $editing_data['qty']; ?>" placeholder="<?= print_lang($app_lang,'qty'); ?>">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'from_branch'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="from_branch" id="branch-transfer-in-branch">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'branch'); ?> --</option>
                                    <?php foreach($branches as $row){ if($row['uid'] == $active_branch_id){ continue; } ?>
                                        <option value="<?= $row['uid']; ?>" <?php if($row['uid'] == $editing_data['from_branch']){ echo 'selected="selected"'; } ?>><?= $row['branch_name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'from_warehouse'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="from_warehouse" id="branch-transfer-in-from-warehouse">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'warehouse'); ?> --</option>
                                    <?php foreach($warehouses as $row){ if($row['branch'] == $active_branch_id){ continue; } ?>
                                        <option <?php if($row['branch'] != $editing_data['from_branch']){ echo 'class="display-none"'; } ?> value="<?= $row['uid']; ?>" <?php if($row['uid'] == $editing_data['from_warehouse']){ echo 'selected="selected"'; } ?> data-branch="<?= $row['branch']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="row extra-mar-botm">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'narration'); ?></label>
                                <textarea class="form-control" name="narration" rows="3" placeholder="<?= print_lang($app_lang,'narration'); ?>"><?= $editing_data['narration']; ?></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="row extra-mar-botm">
                        <div class="col-md-12 text-right">
                            <a class="btn btn-w-m btn-outline btn-danger url-elem" href="<?php echo url('/branch-transfer-in'); ?>"><?= print_lang($app_lang,'cancel'); ?></a>
                            <button class="btn btn-w-m btn-primary" type="submit"><?= print_lang($app_lang,'update'); ?></button>
                        </div>
                    </div>

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

</div>
