<div class="row sets-add-to-list-row">
    <div class="col-md-3">
        <div class="form-group">
            <select class="form-control chosen-select set-add-to-list-item cv-required" name="item[]">
                <option disabled="" selected="">-- <?= print_lang($app_lang,'select_item'); ?> --</option>
                <?php $icount = 1; foreach($items as $row){ ?>
                    <?php
                    $row['stats'] = empty($row['stats']) ? array() : json_decode($row['stats'],true);
                    $ri_warehouse_wise_avail_units = $row['stats']['avail_units'];
                    foreach($ri_warehouse_wise_avail_units as $warehouse_uid => $wau){
                        $ri_warehouse_name = array_key_exists($warehouse_uid, $warehouse) ? $warehouse[$warehouse_uid]['name'] : NULL;
                    ?>
                        <option <?php if($post_data['item'] == $row['uid']){ echo "selected='selected'"; }?> value="<?= $row['uid']; ?>" data-width="<?= $row['width']; ?>" data-height="<?= $row['height']; ?>" 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; ?>" data-usd-equalance="<?= $row['currency_usd_equalance']; ?>" data-item-currency="<?= $row['currency']; ?>" data-opt-ref="item-opt-<?= $icount++; ?>" data-item-name="<?= $row['name']; ?>" data-warehouse="<?= $warehouse_uid; ?>" data-warehouse-name="<?= $ri_warehouse_name; ?>" data-profit="<?= $row['stats']['last_profit']; ?>" data-last-cost="<?= $row['stats']['last_cost']; ?>" data-last-profit="<?= $row['stats']['last_profit']; ?>" data-cost="<?= $row['stats']['avg_cost']; ?>" data-avail-units="<?= $wau; ?>"><?= $row['name'].' - '.$row['details'].' - '.$row['item_id']; ?> | <?= $ri_warehouse_name; ?> (Avail Units: <?= $wau; ?>)</option>
                    <?php } ?>
                <?php } ?>
            </select>
            <input type="hidden" class="set-add-to-list-warehouse" value="<?= $post_data['warehouse']; ?>" name="warehouse[]">
        </div>
    </div>
    <div class="col-md-3">
        <div class="form-group">
            <select class="form-control chosen-select set-add-to-list-batch cv-required" name="batch[]">
                <?php 
                $items_batch = get_item_warehouse_wise_batch($post_data['item'],$post_data['warehouse']);
                ?>
                <?php foreach($items_batch as $row){ ?>
                    <option <?php if($post_data['batch'] == $row['batch']){ echo 'selected="selected"'; } ?> value="<?= $row['batch']; ?>"><?= $row['batch'].' (ava-'.$row['stock_ava'].')'; ?></option>
                <?php } ?>
            </select>
        </div>
    </div>
    <div class="col-md-3">
        <div class="form-group">
            <select class="form-control chosen-select set-add-to-list-unit cv-required" name="unit[]">
                <option disabled="" selected="">-- <?= print_lang($app_lang,'select_unit'); ?> --</option>
                <?php
                    $selected_item = fetch_table_where('items','uid',$post_data['item'],true);
                ?>
                <?php if(!empty($selected_item['purchase_unit'])){ ?>
                    <option value="purchase" <?php if($post_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(!empty($selected_item['sale_unit'])){ ?>
                    <option value="sale" <?php if($post_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(!empty($selected_item['production_unit'])){ ?>
                    <option value="production" <?php if($post_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-2">
        <div class="form-group">
            <input type="number" class="form-control set-add-to-list-qty cv-required" value="<?= $post_data['qty']; ?>" name="qty[]" placeholder="<?= print_lang($app_lang,'mod_items_sets_add_input_qty'); ?>">
        </div>
    </div>
    <div class="col-md-1">
        <button class="btn btn-outline btn-danger dim set-del-to-list-trigger" type="button"><i class="fa fa-times"></i></button>
    </div>
</div>