<style type="text/css">
    .px2p{padding: 2px !important;}
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'mode_process_add_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('/process'); ?>"><?= print_lang($app_lang,'mode_process'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'mode_process_add_breadcrumb'); ?></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="process-form" action="<?php echo url('/process/save'); ?>">
                    <div class="row">

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_invoice'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="invoice" placeholder="<?= print_lang($app_lang,'mode_process_add_input_invoice'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_date'); ?></label>
                                <?php 
                                    $edate = display_true_date( date('y-m-d') );
                                    $edate = true_date_for_inputs($edate);
                                ?>
                                <?php if($branch_calander == 'persian'){ ?>
                                    <input type="text" class="form-control persian-date" name="cn_date" value="<?php echo $edate; ?>" placeholder="<?= print_lang($app_lang,'mode_process_add_input_date'); ?>" readonly="" style="background: #fff;">
                                <?php }else{ ?>
                                    <input type="date" class="form-control" name="cn_date" value="<?php echo date("Y-m-d",strtotime($edate)); ?>">
                                <?php } ?>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_currency'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="currency">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'select_currency'); ?> --</option>
                                    <?php foreach($currencies as $row){ ?>
                                        <option value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['symbol']; ?>)</option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>


                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_item'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="item">
                                    <option disabled="" selected="" value="">-- <?= 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 value="<?= $row['uid']; ?>" data-opt-type="<?= $row['type']; ?>" 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['item_id']; ?> | <?= $ri_warehouse_name; ?> (Avail Units: <?= $wau; ?>)</option>
                                        <?php } ?>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_warehouse'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="warehouse">
                                    <option disabled="" selected="" data-opt-type="default">-- <?= print_lang($app_lang,'select_warehouse'); ?> --</option>
                                    <?php foreach($warehouse as $row){ ?>
                                        <option class="display-none" value="<?= $row['uid']; ?>" data-opt-type="<?= $row['type']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_account'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="account">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mode_process_add_input_account'); ?> --</option>
                                    <?php foreach($accounts as $row){ ?>
                                        <option value="<?= $row['uid']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                    </div>

                    <div class="row">

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_batch'); ?><strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="batch">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mode_process_add_input_batch'); ?> --</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_unit'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="unit">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mode_process_add_input_unit'); ?> --</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_process_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="qty_kg" placeholder="<?= print_lang($app_lang,'mode_process_add_input_process_qty'); ?>">
                            </div>
                        </div>

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_process_kg_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="qty_bokhar" placeholder="<?= print_lang($app_lang,'mode_process_add_input_process_kg_qty'); ?>" readonly>
                            </div>
                        </div>

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_damage_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="damage" placeholder="<?= print_lang($app_lang,'mode_process_add_input_damage_qty'); ?>">
                            </div>
                        </div>

                    </div>
                    
                    <div class="row">

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_item'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="carton_item">
                                    <option disabled="" selected="" value="">-- <?= print_lang($app_lang,'select_item'); ?> --</option>
                                    <?php foreach($items as $row){
                                        $item_stats = json_decode($row['stats'],true);
                                        $item_tp = (float)$item_stats['last_cost'] + (float)$item_stats['last_profit'];
                                    ?>
                                        <option value="<?= $row['uid']; ?>" data-item-cbm-width="<?= $row['item_width']; ?>" data-item-cbm-length="<?= $row['item_length']; ?>" data-item-cbm-height="<?= $row['item_height']; ?>" data-item-cbm="<?= $row['cbm']; ?>" data-item-weight="<?= $row['weight']; ?>" data-last-cost="<?= $item_stats['last_cost']; ?>" data-tp="<?= $item_tp; ?>" data-last-profit="<?= $item_stats['last_profit']; ?>" data-width="<?= $row['width']; ?>" data-height="<?= $row['height']; ?>" 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-opt-type="<?= $row['type']; ?>"><?= $row['name'].', '.$row['item_id']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_warehouse'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="carton_warehouse">
                                    <option disabled="" selected="" data-opt-type="default">-- <?= print_lang($app_lang,'select_warehouse'); ?> --</option>
                                    <?php foreach($warehouse as $row){ ?>
                                        <option class="display-none" value="<?= $row['uid']; ?>" data-opt-type="<?= $row['type']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_batch'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="carton_batch" placeholder="<?= print_lang($app_lang,'mode_process_add_input_carton_batch'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_unit'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="carton_unit">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mode_process_add_input_carton_unit'); ?> --</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="carton_qty" placeholder="<?= print_lang($app_lang,'mode_process_add_input_carton_qty'); ?>">
                            </div>
                        </div>

                    </div>

                    <div class="row">

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_item'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="chigit_item">
                                    <option disabled="" selected="" value="">-- <?= print_lang($app_lang,'select_item'); ?> --</option>
                                    <?php foreach($items as $row){
                                        $item_stats = json_decode($row['stats'],true);
                                        $item_tp = (float)$item_stats['last_cost'] + (float)$item_stats['last_profit'];
                                    ?>
                                        <option value="<?= $row['uid']; ?>" data-item-cbm-width="<?= $row['item_width']; ?>" data-item-cbm-length="<?= $row['item_length']; ?>" data-item-cbm-height="<?= $row['item_height']; ?>" data-item-cbm="<?= $row['cbm']; ?>" data-item-weight="<?= $row['weight']; ?>" data-last-cost="<?= $item_stats['last_cost']; ?>" data-tp="<?= $item_tp; ?>" data-last-profit="<?= $item_stats['last_profit']; ?>" data-width="<?= $row['width']; ?>" data-height="<?= $row['height']; ?>" 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-opt-type="<?= $row['type']; ?>"><?= $row['name'].', '.$row['item_id']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-3 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_warehouse'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="chigit_warehouse">
                                    <option disabled="" selected="" data-opt-type="default">-- <?= print_lang($app_lang,'select_warehouse'); ?> --</option>
                                    <?php foreach($warehouse as $row){ ?>
                                        <option class="display-none" value="<?= $row['uid']; ?>" data-opt-type="<?= $row['type']; ?>"><?= $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_batch'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="chigit_batch" placeholder="<?= print_lang($app_lang,'mode_process_add_input_chigit_batch'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_unit'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select" name="chigit_unit">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mode_process_add_input_chigit_unit'); ?> --</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="chigit_qty" placeholder="<?= print_lang($app_lang,'mode_process_add_input_chigit_qty'); ?>">
                            </div>
                        </div>

                    </div>

                    <div class="row">

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_discount'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="discount" placeholder="<?= print_lang($app_lang,'mode_process_add_input_discount'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_expense'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="expense" placeholder="<?= print_lang($app_lang,'mode_process_add_input_expense'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_amount'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="amount" placeholder="<?= print_lang($app_lang,'mode_process_add_input_amount'); ?>">
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_production_cost'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="total_cost" placeholder="<?= print_lang($app_lang,'mode_process_add_input_production_cost'); ?>" readonly>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_carton_cost'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="total_carton_cost" placeholder="<?= print_lang($app_lang,'mode_process_add_input_carton_cost'); ?>" readonly>
                            </div>
                        </div>

                        <div class="col-md-2 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_input_chigit_cost'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="total_chigit_cost" placeholder="<?= print_lang($app_lang,'mode_process_add_input_chigit_cost'); ?>" readonly>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12 px2p">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mode_process_add_details'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="details" placeholder="<?= print_lang($app_lang,'mode_process_add_details'); ?>">
                            </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('/process'); ?>"><?= print_lang($app_lang,'cancel'); ?></a>
                            <button class="btn btn-w-m btn-primary" type="submit"><?= print_lang($app_lang,'save'); ?></button>
                        </div>
                    </div>

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

</div>
