IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/storage/framework/views/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/storage/framework/views/e82ee79b484b5607ed44a525eeb71188f173af2e.php

<?php $__env->startSection('content'); ?>
<div class="row clearfix">
    <div class="col-sm-12">
        <div class="card">
            <div class="header">
                <h2><strong>Add Purchase Return</strong></h2>
                <a class="btn btn-raised btn-info btn-round waves-effect" style="float: right;" href="/school/purchasereturn">Change Vendor/PO</a>
            </div>
            <div class="body">
                <?php if(isset($po)): ?>
                <?php echo Form::open(['url' => 'school/purchasereturn', 'class' => 'form-horizontal','id'=>'form','files'=>true]); ?>

                <div class="row clearfix">
                    <div class="col-sm-3 form-control-label required">
                        <label for="classname">Vendor/Supplier</label>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <?php echo Form::select('idSupplier',[$po->idSupplier => $suppliers[$po->idSupplier]],$po->idSupplier,['class' => 'form-control select2 show-tick ms','required'=>'required']); ?>

                            <span id='vendor_error'></span>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-3 form-control-label required">
                        <label for="classname">Purcahse Order</label>
                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <?php echo Form::text('poNo',$po->poNo,['class' => 'form-control select2 show-tick ms','required'=>'required']); ?>

                            <span id='vendor_error'></span>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-3 form-control-label required">
                        <label for="classname">Date</label>
                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <?php echo Form::text('returnDate',null,['class' => 'form-control datepicker','required'=>'required']); ?>

                            <?php if($errors->has('returnDate')): ?>
                            <label id="minmaxlength-error" class="error" for="minmaxlength">
                                <strong><?php echo e($errors->first('returnDate')); ?></strong>
                            </label>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-3 form-control-label required">
                        <label for="classname">Shipment Preference</label>
                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <?php echo Form::text('shipmentPreference',null,['class' => 'form-control','required'=>'required']); ?>

                            <?php if($errors->has('shipmentPreference')): ?>
                            <label id="minmaxlength-error" class="error" for="minmaxlength">
                                <strong><?php echo e($errors->first('shipmentPreference')); ?></strong>
                            </label>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                   <div class="col-sm-12">
                       <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th></th>
                                <th>Item</th>
                                <th>Quantity<br>Rate</th>
                                <th>Tax</th>
                                <th>Amount</th>
                                <th>Return<br>Quantity</th>
                            </tr>
                        </thead>
                        <tbody  id="optional_list">
                        <input type="hidden" name="idPurchaseOrder" value="<?php echo e($po->idPurchaseOrder); ?>" >
                            <?php $i =1; $k = 1;?>
                            <?php $__currentLoopData = $poDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $var): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $quantity = 0;
                                $product_received = DB::table('product_received')
                                                    ->join('product_received_details', 'product_received_details.idProductReceived', '=', 'product_received.idProductReceived')
                                                    ->join('products', 'products.idProduct', '=', 'product_received_details.idProduct')
                                                    ->where('idPurchaseOrder', '=', $po->idPurchaseOrder)
                                                    ->where('product_received_details.idProduct','=',$var->idProduct)
                                                    ->select('quantity')
                                                    ->first();
                                if($product_received != null)
                                $quantity = $product_received->quantity;
                            ?>
                            <tr>
                                <td class="sno"><?php echo e($k); ?></td>
                                <td>
                                    <?php if($quantity == 0): ?>
                                    <p><?php echo e($var->productName); ?></p>
                                    <?php else: ?>
                                    <?php echo Form::select('products['.$i.'][idProduct]',[ $var->idProduct => $var->productName],null,['class' => 'form-control productlist show-tick ms' ,'onchange'=>'getProductDetails(this,'.$i.')']); ?>

                                    <span id="producterror1" class="help-block"></span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <?php if($quantity == 0): ?>
                                    <p><?php echo e($var->rate); ?> X <?php echo e($var->quantity); ?></p>
                                    <?php else: ?>
                                    <input id="qty<?php echo e($i); ?>" type="hidden" value="<?php echo e($quantity); ?>"/>
                                    <input id="rate<?php echo e($i); ?>" type="hidden" value="<?php echo e($var->rate); ?>"/>
                                    <input id="tax<?php echo e($i); ?>" type="hidden" value="<?php echo e($var->tax); ?>"/>
                                    <?php echo Form::text('products['.$i.'][qty]',$var->quantity,['class' => 'form-control','required'=>'required','readonly'=>'readonly']); ?> <br>
                                    <?php echo Form::text('products['.$i.'][rate]',$var->rate,['class' => 'form-control','id'=>'price'.$i.'','required'=>'required','readonly'=>'readonly']); ?> 
                                    <?php endif; ?>                                  
                                </td>
                                <td>
                                    <?php if($quantity == 0): ?>
                                    <p><?php echo e($var->tax.'%'); ?></p>
                                    <?php else: ?>
                                    <?php echo Form::select('products['.$i.'][tax]',[ $var->tax => $var->tax.'%'],null,['class' => 'form-control show-tick ms','id'=>'tax'.$i.'','required'=>'required','disabled'=>'disabled']); ?>

                                    <?php endif; ?>   
                                </td>
                                <td>
                                    <?php $total = $var->taxAmount + $var->productTotal; ?>
                                    <?php if($quantity == 0): ?>
                                    <p><?php echo e($total); ?></p>
                                    <?php else: ?>
                                    <?php echo Form::text('products['.$i.'][buyTotal]',$total,['class' => 'form-control','required'=>'required','readonly'=>'readonly']); ?>

                                    <?php echo Form::hidden('products['.$i.'][productTotal]',null,['class' => 'form-control amount','required'=>'required','id'=>'productamount'.$i.'','readonly'=>'readonly']); ?>

                                    <?php endif; ?>   
                                </td>
                                <td>
                                    <?php if($quantity == 0): ?>
                                    <p>You have not received item to return</p>
                                    <?php else: ?>
                                    <p>Good Received : <b><?php echo e($quantity); ?></b></p>
                                    <?php echo Form::text('products['.$i.'][quantity]',null,['class' => 'form-control','id' => 'return_'.$i,'onkeyup'=>'checkQty('.$i.')']); ?>

                                    <?php endif; ?>
                                </td>
                            </tr>
                            <?php if($quantity > 0) $i++;
                            $k++; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                       </tbody>
                    </table>
                   </div>
                </div>
                <hr>
                <div class="row">
                    <div class="col-md-6">
                        <div class="row clearfix">
                            <div class="col-sm-4 form-control-label">
                                <label for="classname">Notes</label>
                            </div>
                            <div class="col-sm-8">
                                <div class="form-group">
                                    <?php echo Form::textarea('notes',null,['class' => 'form-control','size'=>'30x2']); ?>

                                    <?php if($errors->has('notes')): ?>
                                    <label id="minmaxlength-error" class="error" for="minmaxlength">
                                        <strong><?php echo e($errors->first('notes')); ?></strong>
                                    </label>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 text-right">
                        <div class="row clearfix">
                            <div class="col-sm-6 form-control-label">
                                <label for="classname"><strong>Sub Total</strong></label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                     <?php echo Form::text('subTotal',null,['class' => 'form-control','id'=>'subtotal','readonly'=>'readonly']); ?>

                                </div>
                            </div>
                        </div> 
                        <div class="row clearfix">
                            <div class="col-sm-6 form-control-label">
                                <label for="classname">Adjustment</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <?php echo Form::text('adjustment',null,['class' => 'form-control','id'=>'adjustment','onblur'=>'calculateAdjustment()']); ?>

                                </div>
                            </div>
                        </div>                                       
                        <div class="row clearfix">
                            <div class="col-sm-6 form-control-label">
                                <label for="classname"><strong>Total Amount</strong></label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <?php echo Form::text('totalAmount',null,['class' => 'form-control','id'=>'netamt','readonly'=>'readonly']); ?>

                                </div>
                            </div>
                        </div> 
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-8 offset-sm-2">
                        <?php echo Form::submit('SAVE',['class' => 'btn btn-raised btn-primary btn-round waves-effect','id'=>'submit-btn']); ?>

                    </div>
                </div>
                <?php echo Form::close(); ?> 
                <?php else: ?>
                <form action="/school/purchasereturn" method="GET">
                    <div class="row clearfix" style="margin-top:20px;">
                        <div class="col-sm-3 form-control-label required">
                            <label for="supplier">Vendor/Supplier</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <?php echo Form::select('idSupplier',$suppliers,null,['class' => 'form-control select2 show-tick ms','required'=>'required','id'=>'supplier']); ?>

                                <span id='vendor_error'></span>
                            </div>
                        </div>
                        <div class="col-sm-3 form-control-label required">
                            <label for="porder">Purchase Order</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <?php echo Form::select('po',['' => '--Select--'],null,['class' => 'form-control purchase show-tick ms','required'=>'required','id'=>'porder']); ?>

                                <span id='vendor_error'></span>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <table style="width: 100%;margin:20px;" class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>PO Number</th>
                                    <th>Party Name</th>
                                    <th>Return Date</th>
                                    <th>Item Name</th>
                                    <th>Item Quantity</th>
                                </tr>
                            </thead>
                            <tbody id="poreturn">
                            </tbody>
                        </table>
                    </div>
                    <?php echo Form::submit('Fetch PO',['class' => 'btn btn-raised btn-primary btn-round waves-effect']); ?>

                </form>

                

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

<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script>
$(document).ready(function() {
    $('select[name="idSupplier"]').on('change', function() {
        var supplierID = $(this).val();
        if(supplierID) {
            $.ajax({
                url: "<?php echo e(url('/school/suppliers')); ?>"+'/' +supplierID + "/po",
                type: "GET",
                dataType: "json",
                success:function(data) {
                    $('.purchase').empty();
                    $('.purchase').append('<option value="">--Select--</option>');
                    $.each(data, function(key, value) {
                       $('.purchase').append('<option value="'+value['idPurchaseOrder']+'">'+value['poNo']+'</option>');
                    });
                }
            });
        }else{
            $('.purchase').empty();
        }
    });
    $('select[name="po"]').on('change', function() {
        var po = $(this).val();
        if(po) {
            $('#poreturn').empty();
            $.ajax({
                url: "<?php echo e(url('/school/purchasereturn')); ?>"+'/' +po,
                type: "GET",
                dataType: "json",
                success:function(data) {
                    $.each(data, function(key, value) {
                       $('#poreturn').append(`
                                <tr>
                                    <td>`+value['po']+`</td>
                                    <td>`+value['party']+`</td>
                                    <td>`+value['rdate']+`</td>
                                    <td>`+value['item_name']+`</td>
                                    <td>`+value['qty']+`</td>
                                </tr>
                        `);
                    });
                    if(data.length == 0)
                    $('#poreturn').append(`
                                <tr>
                                    <td colspan="5">No more record found</td>
                                </tr>
                    `);
                }
            });
        }else{
            $('#poreturn').empty();
        }
    });
});

function calculateAdjustment (){
    var adjustment = $('#adjustment').val();
    var netamt = $('#netamt').val();
    var total = netamt - adjustment;
    $('#netamt').val(total.toFixed(2));
}

function checkQty(k){
    var qty  = $('#qty'+k).val();
    var rt = $('#rate'+k).val();
    var tax = $('#tax'+k).val();
    var returnQty = $('#return_'+k).val();
    console.log(qty);
    console.log(returnQty);
    if(parseFloat(returnQty) > parseFloat(qty)){
        alert('Return quantity cannot be greater than the original quantity');
        $('#return_'+k).val(qty);
    }
    var amt = rt * returnQty;
    var taxable = amt*tax/100;
    var taxedamt = amt + taxable;

    var amount = '#productamount' + k;
    $(amount).val(taxedamt.toFixed(2));
    var grandTotal = 0;
    $(".amount").each(function (){
        var stval = parseFloat($(this).val());
        grandTotal += isNaN(stval) ? 0 : stval;
    });
    $('#subtotal').val(grandTotal.toFixed(2));
    var subtotal = $('#subtotal').val(grandTotal.toFixed(2));
    $('#netamt').val(grandTotal.toFixed(2));
}

<?php if(isset($po)): ?>
$('#form').on('submit',function(e){
    $.ajaxSetup({
    header:$('meta[name="_token"]').attr('content')
});
 var formData =  new FormData($('#form')[0]);
 $("#submit-btn").prop('disabled', true);
    $.ajax({
        type:"POST",
        url: "<?php echo e(url('school/purchasereturn')); ?>",
        processData: false,
        contentType: false,
        data:formData,
        dataType: 'json',
        success:function(data){
            if( data[Object.keys(data)[0]] === 'SUCCESS' ){
                $("#submit-btn").prop('disabled', true);
                window.location = "<?php echo e(url('school/purchasereturn')); ?>";
            }
            else {                  //False Case: With error msg
            $("#msg").html(data);   //$msg is the id of empty msg
            }

        },

        error: function(data){
                    if( data.status === 422 ) {
                        $("#submit-btn").prop('disabled', false);
                        var errors = data.responseJSON.errors;
                        var errorHtml = '<div class="alert alert-danger"><ul>';
                        $.each( errors, function( key, value ) {
                            if (key.split(".")[1] + '.idProduct' === key.split(".")[1] + '.' +key.split(".")[2])
                             {
                                errorrate = '<p class="help-block">' + value + '</p>';
                                $( '#producterror'+key.split(".")[1] ).html( errorrate );
                             }else{
                                errorHtml += '<li>' + value + '</li>'; 
                             }
                             if (key.split(".")[1] + '.noitem' === key.split(".")[1] + '.' +key.split(".")[2])
                             {
                                errorrate = '<p class="help-block">' + value + '</p>';
                                $( '#qtyerror'+key.split(".")[1] ).html( errorrate );
                             }else{
                                errorHtml += '<li>' + value + '</li>'; 
                             }
                             if (key.split(".")[1] + '.rcv_qty' === key.split(".")[1] + '.' +key.split(".")[2])
                             {
                                errorrate = '<p class="help-block">' + value + '</p>';
                                $( '#qtyerror'+key.split(".")[1] ).html( errorrate );
                             }else{
                                errorHtml += '<li>' + value + '</li>'; 
                             }
                             if (key.split(".")[1] + '.aval_qty' === key.split(".")[1] + '.' +key.split(".")[2])
                             {
                                errorrate = '<p class="help-block">' + value + '</p>';
                                $( '#qtyerror'+key.split(".")[1] ).html( errorrate );
                             }else{
                                errorHtml += '<li>' + value + '</li>'; 
                             }
                        });
                        if(errors['idSupplier']=== undefined){
                            $( '#vendor_error' ).empty();
                        }else{
                           errorname = '<span class="help-block"><strong>'+errors['idSupplier']+'</strong></span>';
                           $( '#vendor_error' ).html( errorname );
                        }
                    }
            }
    });
    return false;
});
<?php endif; ?>

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('schools.school_layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

Copyright © 2021 - 2025 IMMREX7