1583573542s:22036:"<h1>Version 5.3.4 FRCS XML Upload</h1>
<hr />
<blockquote>
<p>{info} This feature is added to improve adding products to charges table. This feature will avoid any duplications.</p>
</blockquote>
<p><br>
<br></p>
<ul>
<li><a href="#section-1">Route</a></li>
<li><a href="#section-2">CSS</a></li>
<li><a href="#section-3">Controller</a></li>
<li><a href="#section-4">View</a></li>
</ul>
<p><a name="section-1"></a></p>
<h2>Route</h2>
<p>Now add below routes in <code>routes/web.php</code></p>
<pre><code class="language-php">//FRCS XML Routes 
Route::post('ticket.products.search','TicketController@seachProducts');
Route::post('ticket.products.add','TicketController@addProductsToCharges');
Route::post('ticket.product.one.remove','TicketController@removeOneProductsToCharges');
Route::post('ticket.product.remove','TicketController@removeProductsToCharges');
</code></pre>
<p><a name="section-2"></a></p>
<h2>CSS</h2>
<p>Make below changes in <code>css/style.css</code></p>
<pre><code class="language-css">
#product_well{
    width: 670px;
    height: 267px;
    overflow: scroll;
}
</code></pre>
<p><a name="section-3"></a></p>
<h2>Controller</h2>
<p>Add below scripts in <code>TicketController.php</code></p>
<pre><code class="language-php">    public function addProductsToCharges(Request $request)
    {
            if(ConfigController::check_privilege('ACCESS_READ_TICKETS'))
            {

                //Check if there is any existing products in Charge table with the same ticket number

                $checks = Charge::where('ticket_id',$request-&gt;ticket_id)
                               -&gt;where('price_id',$request-&gt;product_id)
                               -&gt;where('patient_id',$request-&gt;patient_id)
                               -&gt;get();

                if(count($checks)== 1)
                {
                    foreach($checks as $check)
                    {
                        $post_charge = Charge::find($check-&gt;id);
                        $post_charge-&gt;quantity = $post_charge-&gt;quantity + 1;
                        $post_charge-&gt;save();
                    }
                }
                else
                {

                    $post_charge = new Charge;
                    $post_charge-&gt;ticket_id = $request-&gt;ticket_id;
                    $post_charge-&gt;price_id = $request-&gt;product_id;
                    $post_charge-&gt;patient_id = $request-&gt;patient_id;
                    $post_charge-&gt;quantity = 1;
                    $post_charge-&gt;save();
                } 

                //collect all data in charges table
                $charges = Charge::where('ticket_id',$request-&gt;ticket_id)
                                 -&gt;get();

                if ($request-&gt;ajax()) {
                    $view = view('tickets.read_data',compact('charges'))-&gt;render();

                    return response()-&gt;json(['html'=&gt;$view]);

                }//Ajax end here

            }
            else
            {
                return response()-&gt;json(['unauthorized_access'=&gt;'Sorry, you do not have access to this service. Please contact Admin.']);
            }
    }

    public function removeOneProductsToCharges(Request $request)
    {
            if(ConfigController::check_privilege('ACCESS_READ_TICKETS'))
            {

                    $data = Charge::find($request-&gt;charge_id);

                    if($data-&gt;quantity == 1)
                    {
                        $data-&gt;delete();
                    }
                    else
                    {
                        $data-&gt;quantity = $data-&gt;quantity -1;
                        $data-&gt;save();
                    }

                $charges = Charge::where('ticket_id',$request-&gt;ticket_id)-&gt;get();
                if ($request-&gt;ajax()) {
                    $view = view('tickets.read_data',compact('charges'))-&gt;render();

                    return response()-&gt;json(['html'=&gt;$view]);

                }//Ajax end here
            }
            else
            {
                return response()-&gt;json(['unauthorized_access'=&gt;'Sorry, you do not have access to this service. Please contact Admin.']);
            }
    }

    public function removeProductsToCharges(Request $request)
    {
            if(ConfigController::check_privilege('ACCESS_READ_TICKETS'))
            {

                    $data = Charge::find($request-&gt;charge_id);      
                    $data-&gt;delete();

                $charges = Charge::where('ticket_id',$request-&gt;ticket_id)-&gt;get();

                if ($request-&gt;ajax()) {
                    $view = view('tickets.read_data',compact('charges'))-&gt;render();

                    return response()-&gt;json(['html'=&gt;$view]);

                }//Ajax end here
            }
            else
            {
                return response()-&gt;json(['unauthorized_access'=&gt;'Sorry, you do not have access to this service. Please contact Admin.']);
            }
    }

    public function seachProducts(Request $request)
    {

                if ($request-&gt;ajax()) {
                    $products = Price::where('name','like','%'.$request-&gt;name.'%')-&gt;get();
                    $view = view('tickets.product_data',compact('products'))-&gt;render();

                    return response()-&gt;json(['products'=&gt;$view]);

                }//Ajax end here
    }</code></pre>
<p>Also edit <code>update_ticket</code> function in <code>TicketController.php</code></p>
<pre><code class="language-php">    public function update_ticket(Request $request){
        //return response()-&gt;json(['status' =&gt; $request-&gt;action]);
        if(ConfigController::check_privilege('ACCESS_UPDATE_TICKETS')){

            //extract products before 
            $products = Price::all();

            switch ($request-&gt;action) {
                //if doctor clicks on close button then it will close the ticket
                case 'close':
                        // v5.0.0
                        $product_counter = Charge::where('ticket_id',$request-&gt;ticket_id)
                                               -&gt;get();
                        // end  v5.0.0  
                        if(count($product_counter) == 0)
                        {
                            return response()-&gt;json(['error_product' =&gt; 'Opps, Ticket not processed. Please select a product']);
                        }

                        if($request-&gt;diagnostic_value == 'yes'){
                            $this-&gt;validate($request,[
                                'sickness' =&gt; 'required',
                                'prescription' =&gt; 'required',
                                'diagnostic_type' =&gt; 'required',
                                'results' =&gt; 'required'
                            ]);

                            //Updating Ticket table
                            Ticket::where('id',$request-&gt;ticket_id)
                                  -&gt;where('status','p')
                                  -&gt;update(['sickness' =&gt; $request-&gt;sickness,
                                            'BP' =&gt; $request-&gt;BP,
                                            'P' =&gt; $request-&gt;P,
                                            'CBG' =&gt; $request-&gt;CBG,
                                            'TEMP' =&gt; $request-&gt;TEMP,
                                            'updated_by' =&gt; Auth::user()-&gt;id,
                                            'closed_by' =&gt; Auth::user()-&gt;id,
                                            'prescription' =&gt; $request-&gt;prescription,
                                            'insurance_id' =&gt; $request-&gt;insurance_id,
                                            'status' =&gt; 'u',
                                            'discount' =&gt; $request-&gt;discount_amount,
                                            'total_amount' =&gt; $request-&gt;total_cost
                            ]); 

                            Diagnostic::create([
                                'ticket_id' =&gt; $request-&gt;ticket_id,
                                'diagnostic_type' =&gt; $request-&gt;diagnostic_type,
                                'result' =&gt; $request-&gt;results,
                                'patient_id' =&gt; $request-&gt;patient_id
                            ]);

                        }
                    else
                        {
                            $this-&gt;validate($request,[
                                'sickness' =&gt; 'required',
                                'prescription' =&gt; 'required'
                            ]);  

                            //Updating the DB
                            Ticket::where('id',$request-&gt;ticket_id)
                                  -&gt;where('status','p')
                                  -&gt;update(['sickness' =&gt; $request-&gt;sickness,
                                            'BP' =&gt; $request-&gt;BP,
                                            'P' =&gt; $request-&gt;P,
                                            'CBG' =&gt; $request-&gt;CBG,
                                            'TEMP' =&gt; $request-&gt;TEMP,
                                            'updated_by' =&gt; Auth::user()-&gt;id,
                                            'closed_by' =&gt; Auth::user()-&gt;id,
                                            'prescription' =&gt; $request-&gt;prescription,
                                            'insurance_id' =&gt; $request-&gt;insurance_id,
                                            'status' =&gt; 'u',
                                            'discount' =&gt; $request-&gt;discount_amount,
                                            'total_amount' =&gt; $request-&gt;total_cost
                            ]); 

                        }

                        return response()-&gt;json(['message' =&gt; 'Ticket has been successfully closed.']);

                    break;

                //if doctor clicks on open button then it will open the ticket
                case 'open':
                            Ticket::where('id',$request-&gt;ticket_id)
                                  -&gt;where('status','p')
                                  -&gt;update(['sickness' =&gt; $request-&gt;sickness,
                                            'updated_by' =&gt; Auth::user()-&gt;id,
                                            'insurance_id' =&gt; $request-&gt;insurance_id,
                                            'prescription' =&gt; $request-&gt;prescription,
                                            'status' =&gt; 'a'
                            ]);     

                            return response()-&gt;json(['message' =&gt; 'Ticket has been successfully updated and transferred to the que.']);         

                    break;

                case 'hold':
                          $this-&gt;validate($request,[
                                'sickness' =&gt; 'required',
                                'prescription' =&gt; 'required'
                          ]);  

                            Ticket::where('id',$request-&gt;ticket_id)
                                  -&gt;where('status','p')
                                  -&gt;update(['sickness' =&gt; $request-&gt;sickness,
                                            'updated_by' =&gt; Auth::user()-&gt;id,
                                            'prescription' =&gt; $request-&gt;prescription,
                                            'insurance_id' =&gt; $request-&gt;insurance_id,
                                            'status' =&gt; 'h'
                            ]);     

                            return response()-&gt;json(['message' =&gt; 'Ticket has been successfully updated and moved to HOLD status.']);         

                    break;

            }
        }
        else
        {
            return response()-&gt;json(['unauthorized_access'=&gt;'Sorry, you do not have access to this service. Please contact Admin.']);
        }
    }</code></pre>
<p><a href="#section-4"></a></p>
<h2>View</h2>
<p>Edit file <code>tickets\read.php</code> with below codes:</p>
<pre><code class="language-php">&lt;!-- Products Items --&gt;
                &lt;div class="form-group" id="div-products"&gt;

                    &lt;label for="results" class="col-md-3 control-label"&gt;Products:&lt;/label&gt;

                    &lt;div class="col-md-8"&gt;
                        &lt;input type="text" name="product_search" id="product_search" placeholder="Search Product" class="form-control"&gt;
                        &lt;br&gt;
                        &lt;div class="well bg-grey form-group" id="product_well"&gt;
                            @include('tickets.product_data')
                        &lt;/div&gt;

                    &lt;/div&gt;

                &lt;/div&gt;

&lt;!-- Products ends here --&gt;
    @endforeach
        &lt;div id="cost-data" class="panel"&gt;
            @include('tickets.read_data')
        &lt;/div&gt;</code></pre>
<p>Also edit the javascript on <code>tickets\read.php</code>:</p>
<pre><code class="language-php">function add_cost(id)
{

    $.ajax({
        url: "{{url('ticket.products.add')}}",
        type:"POST",
        data:{
            '_token': $('input[name=_token]').val(),
            'ticket_id': '{{$ticket_id}}',
            'patient_id': '{{$patient_id}}',
            'product_id': id
        },
        success:function(data){
            console.log(data);
            if(data.html){
                swal({
                        type: 'success',
                        title: 'Yah, Product added !!!',
                        animation: true
                });

                $('#cost-data').html(data.html);
            }

            if(data.unauthorized_access){
                swal({
                        type: 'error',
                        title: 'Oops...',
                        text: data.unauthorized_access,
                        animation: true
                });
            }

        },
        error:function(data){
            swal({
                    type: 'error',
                    title: 'Error!!!',
                    text: 'Something went wrong. Please try again later.',
                    animation: true
            });
        }
    });
}

function minus(id){
        $.ajax({
            type: 'POST',
            url: "{{url('ticket.product.one.remove')}}",
            data:{
                '_token': $('input[name=_token]').val(),
                'charge_id': id,
                'ticket_id':"{{$ticket_id}}"
            },
            success:function(data)
            {
                console.log(data);
                if(data.unauthorized_access){
                    swal({
                        type: 'error',
                        title: 'Oops...',
                        text: data.unauthorized_access,
                        animation: true
                    });
                }

                if(data.html){
                    swal({
                            type: 'success',
                            title: 'One quantity removed',
                            animation: true
                    });

                    $('#cost-data').html(data.html);
                }

            },
            error:function(data){
                swal({
                        type: 'error',
                        title: 'Error!!!',
                        text: 'Something went wrong. Please try again later.',
                        animation: true
                });     
            }
        });
    }

function remove(id){
        $.ajax({
            type: 'POST',
            url: "{{url('ticket.product.remove')}}",
            data:{
                '_token': $('input[name=_token]').val(),
                'charge_id': id,
                'ticket_id':"{{$ticket_id}}"
            },
            success:function(data)
            {
                console.log(data);
                if(data.unauthorized_access){
                    swal({
                        type: 'error',
                        title: 'Oops...',
                        text: data.unauthorized_access,
                        animation: true
                    });
                }

                if(data.html){
                    swal({
                            type: 'success',
                            title: 'Product removed.',
                            animation: true
                    });

                    $('#cost-data').html(data.html);
                }

            },
            error:function(data){
                swal({
                        type: 'error',
                        title: 'Error!!!',
                        text: 'Something went wrong. Please try again later.',
                        animation: true
                });     
            }
        });
    }

    $('#product_search').on('keyup',function(){
        var value = $(this).val();

        $.ajax({
            type:'post',
            url:"{{url('ticket.products.search')}}",
            data:{
                '_token': $('input[name=_token]').val(),
                'name': value
            },
            success:function(data){
                $('#product_well').html(data.products);
            },
            error:function(data){
                swal({
                        type: 'error',
                        title: 'Error!!!',
                        text: 'Something went wrong. Please try again later.',
                        animation: true
                }); 
            }
        });
    });

&lt;/script&gt;</code></pre>
<p>Add a new file named <code>tickets.read_data</code>, and add below code:</p>
<pre><code class="language-php">&lt;?php use App\Http\Controllers\ConfigController; 
$total_amount = 0;
?&gt;    

    &lt;div class="form-group" id="div-cost_breakdown"&gt;

        &lt;label for="results" class="col-md-3 control-label"&gt;Cost Breakdown: &lt;/label&gt;

        &lt;div class="col-md-8 form-group"&gt;
        @if(count($charges) &gt; 0)

           &lt;table class="table table-hover table-striped" style="font-size: 10px;"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;ID&lt;/th&gt;
                    &lt;th&gt;Product Name&lt;/th&gt;
                    &lt;th&gt;QTY&lt;/th&gt;
                    &lt;th&gt;Amount&lt;/th&gt;
                    &lt;th&gt;&lt;/th&gt;
                    &lt;th&gt;&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
            @foreach($charges as $charge)
            &lt;?php
                // calculate total_amount
                $total_amount = $total_amount + (ConfigController::get_product_price($charge-&gt;price_id) * $charge-&gt;quantity);
            ?&gt;
                &lt;tr&gt;
                    &lt;td&gt;{{$charge-&gt;id}}&lt;/td&gt;
                    &lt;td&gt;{{ConfigController::get_product_name($charge-&gt;price_id)}}&lt;/td&gt;
                    &lt;td&gt;{{$charge-&gt;quantity}}&lt;/td&gt;
                    &lt;td&gt;{{ConfigController::get_product_price($charge-&gt;price_id) * $charge-&gt;quantity.' FJD'}}&lt;/td&gt;
                    &lt;td&gt;&lt;span class="btn btn-xs btn-warning" onclick="minus({{$charge-&gt;id}});"&gt;&lt;span class="fa fa-minus"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;span class="btn btn-xs btn-danger" onclick="remove({{$charge-&gt;id}});"&gt;&lt;span class="fa fa-trash"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                &lt;/tr&gt;
            @endforeach
            &lt;/tbody&gt;
           &lt;/table&gt;

        @else
            &lt;div class="alert alert-info"&gt;No Charges for now.&lt;/div&gt;
        @endif
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="form-group has-error" id="div-discount_amount" style="display: none;"&gt;
        &lt;label for="discount_amount" class="col-md-3 control-label"&gt;Discount Amount ($)&lt;/label&gt;

        &lt;div class="col-md-8"&gt;
            &lt;input id="discount_amount" type="text" class="form-control" name="discount_amount"  value="0"&gt;

                &lt;span class="help-block"&gt;
                    &lt;strong id="error_discount_amount"&gt;&lt;/strong&gt;
                &lt;/span&gt;

        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group has-success" id="div-total_cost" &gt;
        &lt;label for="total_cost" class="col-md-3 control-label"&gt;Total Cost ($)&lt;/label&gt;

        &lt;div class="col-md-8"&gt;
            &lt;input id="total_cost" type="text" class="form-control" name="total_cost" readonly="readonly" value="{{$total_amount}}"&gt;
            &lt;input id="total_amount" type="hidden" class="form-control" name="total_amount" readonly="readonly" value="{{$total_amount}}"&gt;

                &lt;span class="help-block"&gt;
                    &lt;strong id="error_total_cost"&gt;&lt;/strong&gt;
                &lt;/span&gt;

        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>
<p>Create <code>tickets\product_data.blade.php</code> and add below codes:</p>
<pre><code class="language-php">
@if(count($products) &gt; 0)

    &lt;div class="row" style="font-size: 10px;"&gt;
    @foreach($products as $product)
        &lt;div class="col-md-3 col-sm-2 col-lg-2 col-xs-6"&gt;
            &lt;button onclick="add_cost({{$product-&gt;id}});" type="button" class="btn btn-xs btn-primary" style="text-align: center; width: 100px; word-wrap: break-word; height:100px; margin-top: 10px;"&gt;{{$product-&gt;name}} &lt;br&gt; {{$product-&gt;amount}}&lt;/button&gt;
        &lt;/div&gt;
    @endforeach
    &lt;/div&gt;  

@else
    &lt;div class="alert alert-danger"&gt;No products defined.&lt;/div&gt;
@endif
</code></pre>";