


<?php $__env->startSection('title'); ?>
    Add New Price List
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <ol class="breadcrumb pull-right">
        <li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'list-inventory')): ?>
            <li><a href="<?php echo e(route('pricelist.index')); ?>">All Price List</a></li>
        <?php endif; ?>
        <li class="active">Add Price</li>
    </ol>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>


    <div class="container-fluid">
        <!--.row-->

        <!--./row-->
        <!--.row-->

        <div class="row">

            <div class="col-md-12">
                <?php if($errors->any()): ?>
                    <div class="white-box">
                        <h2>Errors</h2>
                        <ul>
                            <?php echo implode('', $errors->all('<li><span class="help-block"><strong>:message</strong></span></li>')); ?>

                        </ul>
                    </div>
                <?php endif; ?>




                <div class="white-box">

                    <h3 class="box-title m-b-0"><i class="fa fa-info-circle"></i> Add New Price List</h3>
                    <p class="text-muted m-b-30 font-13">Add the information </p>
                    <hr>

                    <form class="form-horizontal" action="<?php echo e(route('pricelist.store')); ?>" method="post">
                        <?php echo e(csrf_field()); ?>

                        
                        <div class="form-group">
                            <h2 style='padding-left:1%'>Type:</h2>
                            
                            <div class="col-sm-12">
                                <div class="input-group" style='width: 38%; margin-left: 90px; margin-top: -45px;'>
                                    <div class="input-group-addon"><i class="fa fa-circle-o"></i></div>
                                    <select style="width: 300px" name="project_type" class="form-control chosen-select"
                                        onchange="updateStatus(this.value)">
                                        <option value="" selected="">None</option>
                                        <?php $__currentLoopData = $project_type; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($p->id); ?>"><?php echo e($p->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>

                                    <?php if($errors->has('project_type')): ?>
                                        <span class="help-block">
                                            <strong><?php echo e($errors->first('project_type')); ?></strong>
                                        </span>
                                    <?php endif; ?>

                                </div>
                            </div>

                        </div>


                        <div id='updatecontent'>
                            <?php
                                $society = false;
                                $highrise = false;
                                
                            ?>

                    <input type='hidden'   id='type'>
                        </div>
                    </form>

                </div>
            </div>
        </div>
        <!--./row-->
    </div>
    <!-- /.container-fluid -->

<?php $__env->stopSection(); ?>


<?php $__env->startSection('js'); ?>

    <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>

    <script>
        function check_post(self) {
            if ($(self).val() == <?php echo e(App\ProjectType::high_rise); ?>) {
                $('#highrise_price').show();
                $('#society_data').hide();
            } else {
                $('#society_data').show();
                $('#highrise_price').hide();
            }
        }

        function removeParentDiv(self) {
            var id = $(self).closest('tr').data("id");


            $('#account_tr_' + id).remove()
            $('#narration_tr_' + id).remove()
        }





        var count = 1;

        function addNewRow(self) {
            $(".chosen-select").chosen("destroy");
            count = count + 1;
            var type = $('#type').val();
            var society = false;
            var highrise = false;
            var size='';
             if (type == <?php echo e(App\ProjectType::society); ?>) {

                society = true;
                size = "<?php echo e(\App\ProjectType::society_size); ?>";
              
                
            }

            if (type == <?php echo e(App\ProjectType::high_rise); ?>) {
                highrise = true;
                size = "<?php echo e(\App\ProjectType::high_rise_size); ?>";
              
               
                
            }
            if (highrise) {
                var account_row = `<tr height="2px" id="account_tr_` + count + `"
                                            data-id="` + count + `" >
                                            <td class="pt-3-half account" style="width: 20%" contenteditable="true">


                                             <select class="form-control chosen-select us_acnt"
                                                 style="width: 80%;height: 26px;font-size: 11px;padding: 0px;padding-left: 18px;cursor: pointer;"
                                                 name="unit_floor[]">
                                              <option  >None</option>
                                             <?php $__currentLoopData = $h_r_floor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                  <option value="<?php echo e($t->id); ?>">
                                                                  <?php echo e($t->name); ?>

                                                                      </option>
                                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                   </select>
                                                    </td>
                                            <td class="pt-3-half account" style="width: 20%" contenteditable="true">


                                                <select class="form-control chosen-select"
                                                    style="width: 80%;height: 26px;font-size: 11px;padding: 0px;padding-left: 18px;cursor: pointer;"
                                                    name="unit_type[]">
                                                    <option  >None</option>
                                                    <?php $__currentLoopData = $h_r_types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($t->id); ?>">
                                                            <?php echo e($t->name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                </select>
                                            </td>
                                           
                                            <td class="pt-3-half name" style='width: 20%;'>
                                                <input class="form-control size unit_quantity" id='per_price_` +
                    count + `' data-id="` + count + `" type="number" name='per_price[]'  >
                                            </td>
                                           
                                             
                                          

                                            <td class="pt-3-half name">

                                                <button type="button" class="btn btn-sm btn-danger btn-sm"
                                                    onclick="removeParentDiv(this)"><i
                                                        class="fa fa-times"></i></button>
                                            </td>
                                           
                                        </tr>
                                             `;
            }

            if (society) {
                var account_row = `<tr height="2px" id="account_tr_` + count + `"
                                            data-id="` + count + `" >

                                            <td class="pt-3-half account" style="width: 40%" contenteditable="true">


                                                <select class="form-control chosen-select"
                                                    style="width: 80%;height: 26px;font-size: 11px;padding: 0px;padding-left: 18px;cursor: pointer;"
                                                    name="unit_type[]">
                                                    <option  >None</option>
                                                    <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($t->id); ?>">
                                                            <?php echo e($t->name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                </select>
                                            </td>
                                            <td class="pt-3-half name" contenteditable="true">
                                                <select class="form-control chosen-select"
                                                    style="width: 80%;height: 26px;font-size: 11px;padding: 0px;padding-left: 18px;cursor: pointer;"
                                                    name="unit_size[]" id='unit_size_` + count +
                    `' onchange="unitChangeFunction(this)" data-id='` + count + `'>
                                                    <option  >None</option>
                                                    <?php $__currentLoopData = $sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option style="font-size: 11px;" value="<?php echo e($s->id); ?>" data-value=<?php echo e($s->name); ?>>
                                                            <?php echo e($s->name); ?> ` + size + `
                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                </select>
                                            </td>
                                            <td class="pt-3-half name" style='width: 20%;'>
                                                <input class="form-control size unit_quantity" id='per_price_` +
                    count + `' data-id="` + count + `" type="number" name='per_price[]' onkeyup="perPriceFunction(this)"  onclick="perPriceFunction(this)" >
                                            </td>
                                            <td class="pt-3-half name" style='width: 20%;'>
                                                <input class="form-control size unit_quantity" id='total_price_` +
                    count + `' data-id="` + count + `" type="number" name='total_price[]' onkeyup="totalPriceFunction(this)" onclick="totalPriceFunction(this)" >
                                            </td>

                                          

                                            <td class="pt-3-half name">

                                                <button type="button" class="btn btn-sm btn-danger btn-sm"
                                                    onclick="removeParentDiv(this)"><i
                                                        class="fa fa-times"></i></button>
                                            </td>

                                        </tr>
                                             `;
            }

            var tr_id = $(self).data("id");
            $('.tr_' + tr_id).after(account_row);
            $('.chosen-select').chosen();
        }

        function perPriceFunction(e) {

            count_val = e.getAttribute("data-id");
            unit_size = $('#unit_size_' + count_val).find(':selected').attr('data-value');
            per_price = $('#per_price_' + count_val).val();
            if (unit_size != undefined) {
                result = parseFloat(per_price) * parseFloat(unit_size);
                $('#total_price_' + count_val).val(result);
            }
        }

        function totalPriceFunction(e) {

            count_val = e.getAttribute("data-id");
            unit_size = $('#unit_size_' + count_val).find(':selected').attr('data-value');
            total_price = $('#total_price_' + count_val).val();
            if (unit_size != undefined) {
                result = parseFloat(total_price) / parseFloat(unit_size);
                $('#per_price_' + count_val).val(result.toFixed(2));
            }

        }

        function unitChangeFunction(e) {
            count_val = e.getAttribute("data-id");
            unit_size = $('#unit_size_' + count_val).find(':selected').attr('data-value');
            total_price = $('#total_price_' + count_val).val();
            per_price = $('#per_price_' + count_val).val();
            if (unit_size != undefined) {
                if (per_price != 0) {

                    result = parseFloat(per_price) * parseFloat(unit_size);
                    $('#total_price_' + count_val).val(result);
                } else if (total_price != 0) {
                    result = parseFloat(total_price) / parseFloat(unit_size);
                    $('#per_price_' + count_val).val(result.toFixed(2));
                }

            }
        }

        async function updateStatus(value) {
            $('.preloader').fadeIn();

            if (value === 'search') {
                $('.preloader').fadeOut();
                return false;
            }

            if (value == "") {
                $('.preloader').fadeOut();
                return false;
            }

            var data = {
                'multipro_type_id': value,
            };



            try {
                const response = await new Promise((resolve, reject) => {
                    $.get('<?php echo e(route('pricelist.create')); ?>', data, function(data) {
                        resolve(data);
                    }).fail(function(xhr, status, error) {
                        reject(error);
                    });
                });

                $('.preloader').fadeOut();

                await new Promise(resolve => {
                    document.getElementById('updatecontent').innerHTML = response;
                    $('.chosen-select').trigger('chosen:updated');
                    $('.chosen-select').chosen({
                        // configuration options for the chosen select box
                    });
                    resolve();
                });

                
               

                toastr.success("List Detail updated");


            } catch (error) {
                // Handle error if the request fails
                console.error(error);
            }

            $('.preloader').fadeOut();
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\abudhabi\resources\views/pricelist/create.blade.php ENDPATH**/ ?>