1

tengo el siguiente problema, deseo sumar dos columnas, como se ve en las imágenes, que recomiendan, hice algunas operaciones en el controlador pero no consigo resultados.

Esta es mi vista:

    <table class="table table-striped table-bordered dt-responsive nowrap" id="table-2">
  <thead>
    <th>Paciente</th>
    <th>Especialista</th>
    <th>Servicios</th>
    <th>Costo</th>
    <th>Detalles</th>
    <th>Pago a Cuenta</th>
    <th>Saldo</th>
    <th>Acciónes</th>
  </thead>
<tbody>
  @if(count($sale))
    @foreach($sale as $sales)
     <tr>
      <td>{{$sales->patient->full_name}}</td>
       <td>{{$sales->specialists->full_name}}</td>
       <td>@foreach($sales->services as $services){{$services->name}}<br>@endforeach</td>
       <td>@foreach($sales->services as $services){{$services->cost}}<br>@endforeach</td>
       <td>{{$sales->bill}}<br></td>
       <td>{{$sales->charged}}<br></td>
       <td>@foreach($sales->services as $services){{$services->cost}}<br>@endforeach-{{$sales->charged}}</td>
      {{--  <td>@if($sales->bill) <span class="btn btn-success"><i class="fa fa-check"></i></span>@else<span class="btn btn-default"><i class="fa fa-minus-circle"></i></span>@endif</td>  --}}
      {{--  <td>@if($sales->charged) <span class="btn btn-success"><i class="fa fa-check"></i></span>@else<span class="btn btn-default"><i class="fa fa-minus-circle"></i></span>@endif</td>  --}}
      <td>
      <a href="{{route('sale.edit', $sales->id)}}" class="btn btn-warning"><i class="fa fa-pencil"></i></a>
          <a type="button" data-href="{{route('sale.destroy',$sales->id)}}" 
                  class="btn btn-round btn-danger btn-delete" 
                  data-confirm-text="Estas seguro de borrar?"
                  data-confirm-delete="Si"
                  title="Borrar" data-toggle="tooltip" data-placement="top">
                    <i class="fa fa-trash-o"></i>
                </a>
      </td>
  </tr>
    @endforeach
  @endif
</tbody>
</table>
<div class="ColVis">
{{ $sale->links() }}
</div>

Y este es mi controlador

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Sale;
use App\Http\Requests\SaveSale;
use App\Http\Requests\UpdateSale;
use App\Patient;
use App\Specialist;
use App\Service;
// use App\Pieza;


class SaleController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('locale'); 
        $this->middleware('timezone'); 
        $this->middleware('permission:acceso.full.editar');
        $this->middleware('session.database', ['only' => ['sessions', 'invalidateSession']]);
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $sale = Sale::orderBy('id','asc')->paginate(10);
        if ( $request->ajax() ) {
            if (count($sale)) {
                return response()->json([
                    'success' => true,
                    'view'    => view('sale.list', compact('sale'))->render(),
                ]);
            } else {
                return response()->json([
                    'success' => false,
                    'message' => trans('app.no_records_found')
                ]);
            }
        }
        return view('sale.index', compact('sale'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $edit = false;
        $patients = Patient::all()->pluck('full_name2', 'id');
        $specialists = Specialist::all()->pluck( 'full_name','id');
        $services = Service::all()->pluck( 'name','id','cost');
        $sales = Sale::all()->pluck('bill','charged');
        // $pieza = Pieza::all()->pluck('nombre','id');
        return view('sale.create', compact('edit','patients','specialists', 'services','sales'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $sale = Sale::create($request->all());
        if ( $sale ) {
            $setservice = $sale->setService($sale->id,$request->service_id);


            return redirect()->route('sale.index', compact('sale'))->withSuccess('Venta creada con exito');

        } else {    
            return back()->withErrors($messages);   
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request, $id)
    {
        $edit = false;
        $patients = Patient::all()->pluck('full_name2', 'id');
        $specialists = Specialist::all()->pluck( 'full_name','id');
        $services = Service::all()->pluck( 'name','id','cost');
        // $piezas = Pieza::all()->pluck('nombre','descripcion','id');
        return view('sale.create', compact('edit','patients','specialists', 'services'));
        // $edit = false;
        // $patients = Patient::findOrFail($request->full_name);
        // $patients = Patient::all()->pluck('full_name2', 'id');
        // $specialists = Specialist::findOrFail($request->full_name2);
        // $specialists = Specialist::all()->pluck( 'full_name','id');
        // $services = Service::findOrFail($request->name);
        // $services = Service::all()->pluck( 'name','id','cost');
        // return view('sale.create', compact('edit','patients','specialists', 'services'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $sale = Sale::find($id)->update($request->all());
        if ( $sale ) {
                return redirect()->route('sale.index', compact('sale'))->withSuccess('Venta actualizada con exito');

        } else {    
            return back()->withErrors($messages);   
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
         $deletesale = Sale::find($id);
        if ( $deletesale->delete() ) {

            return response()->json([
                'success' => true,
                'message' => 'Venta eliminada',
            ]);
        } else {
            return response()->json([
                'success'=> false,
                'message' => trans('app.error_again')
            ]);
        }
    }

    public function getServices()
    {
        $services = Service::all();
        return response()->json([
            'success' => true,
            'services' => $services
            ]);
    }
}

introducir la descripción de la imagen aquí

1 respuesta 1

0

Bien hice la operación, dentro de list.blade.php

Agregue esto:

@php
       $total=$services->cost-$sales->charged
       @endphp
       <td>{{$total}}</td>

Sin embargo se debe sumar antes los costos por cliente como en la imagen: introducir la descripción de la imagen aquí

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.