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

                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?> <strong class="text-danger">*</strong></label>
                                <select class="form-control chosen-select cv-required" name="item">
                                    <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?> --</option>
                                    <?php foreach($items as $row){ if($row['type'] == 'raw'){continue;} ?>
                                        <option <?php if($editing_data['item'] == $row['uid']){echo "selected='selected'";}?> data-unit-name="<?= $row['purchase_unit_name']; ?>" value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-6 pointer-none">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control cv-required" name="qty" value="<?= $editing_data['qty']; ?>" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                            </div>
                        </div>

                    </div>


                    <div class="production-relation-produced-items-row">
                        <h3><?= print_lang($app_lang,'mod_production_relation_add_input_add_relational_produced_items'); ?></h3>
                        <?php if(empty($editing_data_produced)){?>
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?></label>
                                        <select class="form-control chosen-select production-relation-produced-items-dp cv-produced-required" name="produced_item[]">
                                            <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?> --</option>
                                            <?php foreach($items as $row){ if($row['type'] == 'raw'){continue;} ?>
                                                <option data-unit-name="<?= $row['purchase_unit_name']; ?>" value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?></label>
                                        <input type="text" class="form-control production-relation-produced-qty-ip cv-produced-required" name="produced_qty[]" value="1" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'mod_production_relation_add_input_percentage'); ?></label>
                                        <input type="text" class="form-control production-relation-produced-cost-percentage-ip cv-produced-required" name="cost_percentage[]" value="1" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_percentage'); ?>">
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <button class="btn btn-primary production-relation-produced-items-trigger" type="button" style="margin-top: 22px;"><?= print_lang($app_lang,'mod_production_relation_add_add_to_list'); ?></button>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                        <?php $psr = 1; foreach($editing_data_produced as $prow){?>
                            <?php if($psr == 1){?>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label><?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?></label>
                                            <select class="form-control chosen-select production-relation-produced-items-dp cv-produced-required" name="produced_item[]">
                                                <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?> --</option>
                                                <?php foreach($items as $row){ if($row['type'] == 'raw'){continue;} ?>
                                                    <option <?php if($prow['item'] == $row['uid']){echo "selected='selected'";}?> data-unit-name="<?= $row['purchase_unit_name']; ?>" value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label><?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?></label>
                                            <input type="text" class="form-control production-relation-produced-qty-ip cv-produced-required" name="produced_qty[]" value="<?= $prow['qty']; ?>" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                                        </div>
                                    </div>

                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label><?= print_lang($app_lang,'mod_production_relation_add_input_percentage'); ?></label>
                                            <input type="text" class="form-control production-relation-produced-cost-percentage-ip cv-produced-required" name="cost_percentage[]" value="<?= $prow['cost_percentage']; ?>" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_percentage'); ?>">
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <button class="btn btn-primary production-relation-produced-items-trigger" type="button" style="margin-top: 22px;"><?= print_lang($app_lang,'mod_production_relation_add_add_to_list'); ?></button>
                                        </div>
                                    </div>
                                </div>
                            <?php }else{?>
                                <div class="row produced-appended-data-rows">
                                    <div class="col-md-4 pointer-none">
                                        <div class="form-group">
                                            <select class="form-control chosen-select appended-chosen" name="produced_item[]">
                                                <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_produced_item'); ?> --</option>
                                                <?php foreach($items as $row){ ?>
                                                    <option <?php if($prow['item'] == $row['uid']){echo "selected='selected'";}?> value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" value="<?= $prow['qty']; ?>" name="produced_qty[]" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                                        </div>
                                    </div>

                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="cost_percentage[]" value="<?= $prow['cost_percentage']; ?>" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_percentage'); ?>">
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <button class="btn btn-danger produced-items-del-btn" type="button"><?= print_lang($app_lang,'mod_production_relation_add_remove'); ?></button>
                                    </div>
                                </div>
                            <?php } ?>
                        <?php $psr++;} ?>
                    </div>


                    <div class="production-relation-raw-items-row">
                        <h3><?= print_lang($app_lang,'mod_production_relation_add_input_add_relational_raw_items'); ?></h3>
                        <?php $rsr = 1; foreach($editing_data_raw as $rrow){?>
                            <?php if($rsr == 1){?>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label><?= print_lang($app_lang,'mod_production_relation_add_input_raw_item'); ?> <strong class="text-danger">*</strong></label>
                                            <select class="form-control chosen-select cv-required production-relation-raw-items-dp cv-raw-required" name="raw_item[]">
                                                <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_raw_item'); ?> --</option>
                                                <?php foreach($items as $row){ if($row['type'] == 'sales'){continue;} ?>
                                                    <option <?php if($rrow['item'] == $row['uid']){echo "selected='selected'";}?> data-unit-name="<?= $row['purchase_unit_name']; ?>" value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label><?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?> <strong class="text-danger">*</strong></label>
                                            <input type="text" class="form-control cv-required production-relation-raw-qty-ip cv-raw-required" name="raw_qty[]" value="<?= $rrow['qty']; ?>" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <button class="btn btn-primary production-relation-raw-items-trigger" type="button" style="margin-top: 22px;"><?= print_lang($app_lang,'mod_production_relation_add_add_to_list'); ?></button>
                                        </div>
                                    </div>
                                </div>
                            <?php }else{ ?>
                                <div class="row raw-appended-data-rows">
                                    <div class="col-md-4 pointer-none">
                                        <div class="form-group">
                                            <select class="form-control chosen-select appended-chosen cv-required" name="raw_item[]">
                                                <option disabled="" selected="">-- <?= print_lang($app_lang,'mod_production_relation_add_input_raw_item'); ?> --</option>
                                                <?php foreach($items as $row){ ?>
                                                    <option <?php if($rrow['item'] == $row['uid']){echo "selected='selected'";}?> value="<?= $row['uid']; ?>"><?= $row['name']; ?> (<?= $row['item_id']; ?>) (<?= $row['purchase_unit_name']; ?>)</option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <input type="text" class="form-control cv-required" value="<?= $rrow['qty']; ?>" name="raw_qty[]" placeholder="<?= print_lang($app_lang,'mod_production_relation_add_input_qty'); ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <button class="btn btn-danger raw-items-del-btn" type="button"><?= print_lang($app_lang,'mod_production_relation_add_remove'); ?></button>
                                    </div>
                                </div>
                            <?php } ?>
                        <?php $rsr++;} ?>
                    </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('/production-relation'); ?>"><?= 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>
