Application de gestion d'un restaurant ب laravel الجزء السادس

فهاد الجزء السادس من Application de gestion d'un restaurant ب laravel غادي نكملوا وندوزو لعرض les ventes ديالنا أيضا غادي نشوفوا كيفاش نديرو تعديل وحذف vente بالإضافة ل table.

نظرة سريعة بالفيديو


1- إضافة table


دائما ف dossier tables زيد fichier سميه create.blade.php لي غادي تكون فيه فورم إضافة table.

الكود لي غادي تزيد فالملف هو :

                                    
                                        @extends('layouts.app')


@section("content")
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                @include('layouts.sidebar')
                            </div>
                            <div class="col-md-8">
                                <h3 class="text-secondary border-bottom mb-3 p-2">
                                    <i class="fas fa-plus"></i> Ajouter une table
                                </h3>
                                <form action="{{ route("tables.store") }}" method="post">
                                    @csrf
                                    <div class="form-group">
                                        <input
                                            type="text" name="name" id="name"
                                            class="form-control"
                                            placeholder="Nom"
                                        >
                                    </div>
                                    <div class="form-group">
                                        <select name="status" class="form-control">
                                            <option value="" selected disabled>
                                                Disponible
                                            </option>
                                            <option value="1">Oui</option>
                                            <option value="0">Non</option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <button class="btn btn-primary">
                                            Valider
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
                                    
                                

2- تعديل table


دائما ف dossier tables زيد fichier سميه edit.blade.php لي غادي تكون فيه فورم تعديل table.

الكود لي غادي تزيد فالملف هو :

                                    
                                        @extends('layouts.app')


@section("content")
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                @include('layouts.sidebar')
                            </div>
                            <div class="col-md-8">
                                <h3 class="text-secondary border-bottom mb-3 p-2">
                                    <i class="fas fa-plus"></i> Modifier la table {{ $table->name }}
                                </h3>
                                <form action="{{ route("tables.update", $table->slug) }}" method="post">
                                    @csrf
                                    @method("PUT")
                                    <div class="form-group">
                                        <input
                                            type="text" name="name" id="name"
                                            class="form-control"
                                            placeholder="Nom"
                                            value="{{  $table->name }}"
                                        >
                                    </div>
                                    <div class="form-group">
                                        <select name="status" class="form-control">
                                            <option value="" disabled>
                                                Disponible
                                            </option>
                                            <option {{ $table->status === 1 ? "selected" : "" }} value="1">Oui</option>
                                            <option {{ $table->status === 0 ? "selected" : "" }} value="0">Non</option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <button class="btn btn-primary">
                                            Valider
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
                                    
                                

3- إضافة وعرض vente ديال اليوم الحالي


ف dossier views زيد dossier payments فيه زيد fichier سميه index.blade.php لي غادي تكون فيه فورم إضافة vente ولي غادي يمكن أيضا من عرض les ventes الخاصين باليوم الحالي.

الكود لي غادي تزيد فالملف هو :


                                      
                                        @extends('layouts.app')


@section("content")
    <div class="container">
        <form id="add-sale" action="{{ route("sales.store") }}" method="post">
            @csrf
            <div class="row justify-content-center">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <a href="/home" class="btn btn-outline-secondary">
                                    <i class="fa fa-chevron-left"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="my-2 col-md-3">
                            <h3 class="text-muted border-bottom">
                                {{ Carbon\Carbon::now() }}
                            </h3>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <a href="{{ route("sales.index") }}" class="btn btn-outline-secondary float-right">
                                    Toutes les ventes
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                @foreach ($tables as $table)
                                    <div class="col-md-3">
                                        <div class="card p-2 mb-2 d-flex
                                                    flex-column justify-content-center
                                                    align-items-center
                                                    list-group-item-action">
                                            <div class="align-self-end">
                                                <input type="checkbox" name="table_id[]"
                                                    id="table"
                                                    value="{{ $table->id }}"
                                                >
                                            </div>
                                            <i class="fa fa-chair fa-5x"></i>
                                            <span class="mt-2 text-muted font-weight-bold">
                                                {{ $table->name }}
                                            </span>
                                            <div class="d-flex
                                                    flex-column justify-content-between
                                                    align-items-center">
                                                <a href="{{ route("tables.edit",$table->slug) }}" class="btn btn-sm btn-warning">
                                                    <i class="fa fa-edit"></i>
                                                </a>
                                            </div>
                                            <hr>
                                            @foreach ($table->sales as $sale)
                                                @if ($sale->created_at >= Carbon\Carbon::today())
                                                    <div style="border : dashed pink" class="mb-2 mt-2 shadow w-100" id="{{ $sale->id }}">
                                                        <div class="card">
                                                            <div class="card-body d-flex
                                                                    flex-column justify-content-center
                                                                    align-items-center">
                                                                @foreach ($sale->menus()->where("sales_id",$sale->id)->get() as $menu)
                                                                    <h5 class="font-weight-bold mt-2">
                                                                        {{ $menu->title }}
                                                                    </h5>
                                                                    <span class="text-muted">
                                                                        {{ $menu->price }} DH
                                                                    </span>
                                                                @endforeach
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-danger">
                                                                        Sérveur : {{ $sale->servant->name }}
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Qté : {{ $sale->quantity }}
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Prix : {{ $sale->total_price }} DH
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Total : {{ $sale->total_received }} DH
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Reste : {{ $sale->change }} DH
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Type de paiement :
                                                                        {{ $sale->payment_type === "cash" ?
                                                                             "Espéce" : "Carte bancaire" }}
                                                                    </span>
                                                                </h5>
                                                                <h5 class="font-weight-bold mt-2">
                                                                    <span class="badge badge-light">
                                                                        Etat de paiement :
                                                                        {{ $sale->payment_status === "paid" ?
                                                                             "Payé" : "Impayé" }}
                                                                    </span>
                                                                </h5>
                                                                <hr>
                                                                <div class="d-flex
                                                                    flex-column justify-content-center
                                                                    align-items-center">
                                                                    <span class="font-weight-bold">
                                                                        Restaurant XXXXX
                                                                    </span>
                                                                    <span>
                                                                        Rue afrah taza
                                                                    </span>
                                                                    <span>
                                                                        0123456789
                                                                    </span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="mt-2 d-flex justify-content-center">
                                                        <a href="{{ route("sales.edit",$sale->id) }}"
                                                            class="btn btn-sm btn-warning mr-1">
                                                            <i class="fa fa-edit"></i>
                                                        </a>
                                                        <a href="#" target="_blank" class="btn btn-sm btn-primary"
                                                            onclick="print({{ $sale->id }})"
                                                            >
                                                            <i class="fas fa-print"></i>
                                                        </a>
                                                    </div>
                                                @endif
                                            @endforeach
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row justify-content-center mt-2">
                <div class="col-md-12 card p-3">
                    <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                        @foreach ($categories as $category)
                            <li class="nav-item">
                                <a href="#{{ $category->slug }}"
                                    class="nav-link mr-1 {{ $category->slug === "salades-marocaines" ? "active" : "" }}"
                                    id="{{ $category->slug }}-tab"
                                    data-toggle="pill"
                                    role="tab"
                                    aria-controls="{{ $category->slug }}"
                                    aria-selected="true"
                                >
                                    {{ $category->title }}
                                </a>
                            </li>
                        @endforeach
                    </ul>
                    <div class="tab-content" id="pills-tabcontent">
                        @foreach ($categories as $category)
                            <div class="tab-pane fade {{ $category->slug === "salades-marocaines" ? "show active" : "" }}"
                                id="{{ $category->slug }}"
                                role="tabpanel"
                                aria-labelledby="pills-home-tab"
                                >
                                <div class="row">
                                    @foreach($category->menus as $menu)
                                        <div class="col-md-4 mb-2">
                                            <div class="card h-100">
                                                <div class="card-body d-flex
                                                flex-column justify-content-center
                                                align-items-center">
                                                    <div class="align-self-end">
                                                        <input type="checkbox" name="menu_id[]"
                                                            id="menu_id"
                                                            value="{{ $menu->id }}"
                                                        >
                                                    </div>
                                                    <img
                                                        src="{{ asset("images/menus/". $menu->image) }}" alt="{{ $menu->title}}"
                                                        class="img-fluid rounded-circle"
                                                        width="100"
                                                        height="100"
                                                    >
                                                    <h5 class="font-weight-bold mt-2">
                                                        {{ $menu->title }}
                                                    </h5>
                                                    <h5 class="text-muted">
                                                        {{ $menu->price }} DH
                                                    </h5>
                                                </div>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        @endforeach
                    </div>
                    <div class="row">
                        <div class="col-md-6 mx-auto">
                            <div class="form-group">
                                <select name="servant_id" class="form-control">
                                    <option value="" selected disabled>
                                        Sérveur
                                    </option>
                                    @foreach ($servants as $servant)
                                        <option value="{{ $servant->id }}">
                                            {{ $servant->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        Qté
                                    </div>
                                </div>
                                <input type="number"
                                    name="quantity"
                                    class="form-control"
                                    placeholder="Qté"
                                >
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="total_price"
                                    class="form-control"
                                    placeholder="Prix"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="total_received"
                                    class="form-control"
                                    placeholder="Total"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="change"
                                    class="form-control"
                                    placeholder="Reste"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <select name="payment_type" class="form-control">
                                    <option value="" selected disabled>
                                        Type de paiement
                                    </option>
                                    <option value="cash">
                                        Espéce
                                    </option>
                                    <option value="card">
                                        Carte bancaire
                                    </option>
                                </select>
                            </div>
                            <div class="form-group">
                                <select name="payment_status" class="form-control">
                                    <option value="" selected disabled>
                                        Etat de paiement
                                    </option>
                                    <option value="paid">
                                        Payé
                                    </option>
                                    <option value="unpaid">
                                        Impayé
                                    </option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button
                                    onclick="event.preventDefault();
                                        document.getElementById("add-sale").submit();
                                    "
                                    class="btn btn-primary"
                                >
                                    Valider
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection
@section("javascript")
    <script>
        function print(el){
            const page = document.body.innerHTML;
            const content = document.getElementById(el).innerHTML;
            document.body.innerHTML = content;
            window.print();
            document.body.innerHTML = page;
        }
    </script>
@endsection
                                      
                                    

4- عرض les ventes ديال أيام الأسبوع


ف dossier views زيد dossier sales فيه زيد fichier سميه index.blade.php لي غادي نعرضوا فيه les ventes ديال أيام الأسبوع كاملة.

الكود لي غادي تزيد فالملف هو :

                                        
                                            @extends('layouts.app')


@section("content")
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="d-flex flex-row justify-content-between align-items-center border-bottom pb-1">
                                    <h3 class="text-secondary">
                                        <i class="fas fa-credit-card"></i> Ventes
                                    </h3>
                                    <a href="{{ route("payments.index") }}" class="btn btn-primary">
                                        <i class="fas fa-plus fa-x2"></i>
                                    </a>
                                </div>
                                <table class="table table-hover table-responsive-sm">
                                    <thead>
                                        <tr>
                                            <th>Id</th>
                                            <th>Menus</th>
                                            <th>Tables</th>
                                            <th>Sérveur</th>
                                            <th>Quantité</th>
                                            <th>Total</th>
                                            <th>Type de paiement</th>
                                            <th>Etat de paiement</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($sales as $sale)
                                            <tr>
                                                <td>
                                                    {{ $sale->id }}
                                                </td>
                                                <td>
                                                    @foreach($sale->menus()->where("sales_id",$sale->id)->get() as $menu)
                                                        <div class="col-md-4 mb-2">
                                                            <div class="h-100">
                                                                <div class="d-flex
                                                                flex-column justify-content-center
                                                                align-items-center">
                                                                    <img
                                                                        src="{{ asset("images/menus/". $menu->image) }}" alt="{{ $menu->title}}"
                                                                        class="img-fluid rounded-circle"
                                                                        width="50"
                                                                        height="50"
                                                                    >
                                                                    <h5 class="font-weight-bold mt-2">
                                                                        {{ $menu->title }}
                                                                    </h5>
                                                                    <h5 class="text-muted">
                                                                        {{ $menu->price }} DH
                                                                    </h5>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    @endforeach
                                                </td>
                                                <td>
                                                    @foreach($sale->tables()->where("sales_id",$sale->id)->get() as $table)
                                                        <div class="col-md-4 mb-2">
                                                            <div class="h-100">
                                                                <div class="d-flex
                                                                flex-column justify-content-center
                                                                align-items-center">
                                                                    <i class="fa fa-chair fa-3x"></i>
                                                                    <h5 class="text-muted mt-2">
                                                                        {{ $table->name }}
                                                                    </h5>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    @endforeach
                                                </td>
                                                <td>
                                                    {{ $sale->servant->name}}
                                                </td>
                                                <td>
                                                    {{ $sale->quantity}}
                                                </td>
                                                <td>
                                                    {{ $sale->total_received}}
                                                </td>
                                                <td>
                                                    {{ $sale->payment_type === "cash" ? "Espéce" : "Carte bancaire"}}
                                                </td>
                                                <td>
                                                    {{ $sale->payment_status === "paid" ? "Payé" : "Impayé"}}
                                                </td>
                                                <td class="d-flex flex-row justify-content-center align-items-center">
                                                    <a href="{{ route("sales.edit",$sale->id) }}" class="btn btn-warning mr-1">
                                                        <i class="fas fa-edit"></i>
                                                    </a>
                                                    <form id="{{ $sale->id }}" action="{{ route("sales.destroy",$sale->id) }}" method="post">
                                                        @csrf
                                                        @method("DELETE")
                                                        <button
                                                            onclick="
                                                                event.preventDefault();
                                                                if(confirm('Voulez vous supprimer la vente {{ $sale->id }} ?'))
                                                                document.getElementById({{ $sale->id }}).submit()
                                                            "
                                                            class="btn btn-danger">
                                                            <i class="fas fa-trash"></i>
                                                        </button>
                                                    </form>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                                <div class="my-3 d-flex justify-content-center align-items-center">
                                    {{ $sales->links() }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
                                        
                                    

5- تعديل vente


دائما ف dossier sales زيد fichier سميه edit.blade.php لي غادي تكون فيه فورم تعديل vente.

الكود لي غادي تزيد فالملف هو :

                                        
                                            @extends('layouts.app')


@section("content")
    <div class="container">
        <form id="add-sale" action="{{ route("sales.update",$sale->id) }}" method="post">
            @csrf
            @method("PUT")
            <div class="row justify-content-center">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <a href="/payments" class="btn btn-outline-secondary">
                                    <i class="fa fa-chevron-left"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                @foreach ($tables as $table)
                                    <div class="col-md-3">
                                        <div class="card p-2 mb-2 d-flex
                                                    flex-column justify-content-center
                                                    align-items-center
                                                    list-group-item-action">
                                            <div class="align-self-end">
                                                <input type="checkbox" name="table_id[]"
                                                    id="table"
                                                    checked
                                                    value="{{ $table->id }}"
                                                >
                                            </div>
                                            <i class="fa fa-chair fa-5x"></i>
                                            <span class="mt-2 text-muted font-weight-bold">
                                                {{ $table->name }}
                                            </span>
                                            <hr>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row justify-content-center mt-2">
                <div class="col-md-12 card p-3">
                    <div class="row">
                        @foreach($menus as $menu)
                            <div class="col-md-4 mb-2">
                                <div class="card h-100">
                                    <div class="card-body d-flex
                                    flex-column justify-content-center
                                    align-items-center">
                                        <div class="align-self-end">
                                            <input type="checkbox" name="menu_id[]"
                                                id="menu_id"
                                                checked
                                                value="{{ $menu->id }}"
                                            >
                                        </div>
                                        <img
                                            src="{{ asset("images/menus/". $menu->image) }}" alt="{{ $menu->title}}"
                                            class="img-fluid rounded-circle"
                                            width="100"
                                            height="100"
                                        >
                                        <h5 class="font-weight-bold mt-2">
                                            {{ $menu->title }}
                                        </h5>
                                        <h5 class="text-muted">
                                            {{ $menu->price }} DH
                                        </h5>
                                    </div>
                                </div>
                            </div>
                        @endforeach
                    </div>
                    <div class="row">
                        <div class="col-md-6 mx-auto">
                            <div class="form-group">
                                <select name="servant_id" class="form-control">
                                    <option value="" selected disabled>
                                        Sérveur
                                    </option>
                                    @foreach ($servants as $servant)
                                        <option
                                            {{ $servant->id === $sale->servant_id ? "selected" : "" }}
                                            value="{{ $servant->id }}">
                                            {{ $servant->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        Qté
                                    </div>
                                </div>
                                <input type="number"
                                    name="quantity"
                                    class="form-control"
                                    placeholder="Qté"
                                    value="{{ $sale->quantity }}"
                                >
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="total_price"
                                    class="form-control"
                                    placeholder="Prix"
                                     value="{{ $sale->total_price }}"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="total_received"
                                    class="form-control"
                                    placeholder="Total"
                                     value="{{ $sale->total_received }}"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <div class="input-group-text">
                                        $
                                    </div>
                                </div>
                                <input type="number"
                                    name="change"
                                    class="form-control"
                                    placeholder="Reste"
                                     value="{{ $sale->change }}"
                                >
                                <div class="input-group-append">
                                    <div class="input-group-text">
                                        .00
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <select name="payment_type" class="form-control">
                                    <option value="" selected disabled>
                                        Type de paiement
                                    </option>
                                    <option value="cash"
                                        {{ $sale->payment_type === "cash" ? "selected" : ""}}
                                        >
                                        Espéce
                                    </option>
                                    <option value="card"
                                    {{ $sale->payment_type === "card" ? "selected" : ""}}
                                    >
                                        Carte bancaire
                                    </option>
                                </select>
                            </div>
                            <div class="form-group">
                                <select name="payment_status" class="form-control">
                                    <option value="" selected disabled>
                                        Etat de paiement
                                    </option>
                                    <option value="paid" {{ $sale->payment_status === "paid" ? "selected" : ""}}>
                                        Payé
                                    </option>
                                    <option value="unpaid" {{ $sale->payment_status === "unpaid" ? "selected" : ""}}>
                                        Impayé
                                    </option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button
                                    onclick="event.preventDefault();
                                        document.getElementById("add-sale").submit();
                                    "
                                    class="btn btn-primary"
                                >
                                    Valider
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection
                                        
                                    

كلمات مفاتيح :