Skip to content

Commit

Permalink
add showFunc feature to show the tool depending on the model status, …
Browse files Browse the repository at this point in the history
…cerate donating page for each entity to show its own projects, edit table component to render links by adding the type of the header, add some translations for the locales file
  • Loading branch information
Ahmed-elhelou committed Jan 20, 2025
1 parent c098fe6 commit 9e13f90
Show file tree
Hide file tree
Showing 22 changed files with 779 additions and 91 deletions.
15 changes: 14 additions & 1 deletion app/Http/Controllers/DonorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\UpdateDonorRequest;
use App\Models\Donor;
use App\Models\Country;
use App\Models\Donation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -52,7 +53,19 @@ public function create()
public function store(StoreDonorRequest $request)
{
$data = $request->validated();
Donor::create($data);
$donor = Donor::firstOrCreate(['phone' => $data['phone']], $data);

// Handle donations if they exist
if (!empty($data['donations'])) {
foreach ($data['donations'] as $donation) {
Donation::create([
'donor_id' => $donor->id,
'proposal_id' => $donation['proposal_id'],
'amount' => $donation['amount'],
'currency_id' => $donation['currency_id'],
]);
}
}

return to_route($this->routeName() . '.index')->with('res', ['message' => __('Donor Saved Seccessfully'), 'type' => 'success']);
}
Expand Down
19 changes: 19 additions & 0 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Inertia\Inertia;
use App\Models\Proposal;

use App\Models\Currency;

use App\Models\Donor;

use App\Models\Country;


class EntityController extends Controller
Expand All @@ -34,6 +41,18 @@ public function index(Request $request)

]);
}
public function donatingForm(Request $request, string $donating_form_path)
{
// dd('hi');
$entity = Entity::where('donating_form_path', $donating_form_path)->firstOrFail();
return Inertia::render(Str::studly("Entity").'/DonatingForm', [
"headers" => Proposal::guestHeaders(),
"entity" => $entity,
"proposals" => Proposal::where('entity_id', $entity->id)->get(),
'countries' => Country::select('id', 'name')->get(),
'genders' => Donor::genders(),
]);
}

/**
* Show the form for creating a new resource.
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/ProposalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use App\Models\ProposalType;
use App\Models\Entity;
use App\Models\Area;
use App\Models\Donor;
use App\Models\Country;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -48,7 +50,9 @@ public function guestIndex(Request $request)

return Inertia::render(Str::studly("Proposal").'/GuestIndex', [
"headers" => Proposal::guestHeaders(),
"items" => Proposal::where('status', '=', Proposal::STATUSES['donatable'])->search($request)->sort($request)->paginate($this->pagination),
"proposals" => Proposal::get(),
'countries' => Country::select('id', 'name')->get(),
'genders' => Donor::genders(),

]);
}
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Requests/StoreDonorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public function rules()
'name' => 'required|string|max:255',
'gender' => 'required|integer|between:1,2',
'phone' => 'required|string|max:15|unique:donors,phone',
'country_id' => 'nullable|integer|exists:countries,id'
'country_id' => 'nullable|integer|exists:countries,id',
'donations' => 'nullable|array', // donations can be empty
'donations.*.proposal_id' => 'required_with:donations|integer|exists:proposals,id',
'donations.*.currency_id' => 'required_with:donations|integer|exists:currencies,id',
'donations.*.amount' => 'required_with:donations|numeric|min:1',
];
}
}
7 changes: 7 additions & 0 deletions app/Listeners/StoreDonationRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public function __construct()
public function handle(ProposalDonatingStatusApprovedWithDonatedAmount $event): void
{
// create donation
$donatino = new Donation();
$donatino->proposal_id = $event->proposal->id;
$donatino->currency_id = $event->proposal->currency_id;
$donatino->amount = $event->donatingAmount;
$donatino->status = 2; //approved

$donatino->save();

}
}
14 changes: 10 additions & 4 deletions app/Models/Donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Donation extends BaseModel
{
use HasFactory;
protected $appends = [ 'donor_name','currency_name', 'status_str', 'donor_phone'];
protected $appends = [ 'donor_name','currency_name', 'status_str', 'donor_phone', 'proposal_title'];
public static $controllable = true;

public const STATUSES = [
Expand All @@ -20,7 +20,9 @@ class Donation extends BaseModel
3 => ('Rejected'),

];

public function proposal(){
return $this->belongsTo(Proposal::class, 'proposal_id');
}
public function donor() {
return $this->belongsTo(Donor::class, 'donor_id');
}
Expand All @@ -38,9 +40,12 @@ public function getDonorPhoneAttribute() {
}

public function getStatusStrAttribute() {
return self::$statuses[$this->status] ?? '';
return self::STATUSES[$this->status] ?? '';
}
public function getProposalTitleAttribute()
{
return $this->proposal->title ?? null;
}

public static function statuses() {
return [
['id' => 0, 'name' => __('Pending')],
Expand All @@ -52,6 +57,7 @@ public static function statuses() {
public static function headers($user = null)
{
return [
['sortable' => true, 'value' => 'Proposal Title', 'key' => 'proposal_title'],
['sortable' => true, 'value' => 'donor name', 'key' => 'donor_name'],
['sortable' => true, 'value' => 'donor phone', 'key' => 'donor_phone'],
['sortable' => true, 'value' => 'currency name', 'key' => 'currency_name'],
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Donor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Donor extends BaseModel
{
use HasFactory;
protected $appends = ['gender_str', 'country_name'];
protected $guarded = ['donations'];
protected $with = ['country'];
public static $controllable = true;

Expand All @@ -29,11 +30,15 @@ public static function genders() {
];
}



public function country()
{
return $this->belongsTo(Country::class, 'country_id', 'id');
}



public function getCountryNameAttribute()
{
return $this->country->name ?? null;
Expand Down
9 changes: 5 additions & 4 deletions app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
class Entity extends BaseModel
{
use HasFactory;
protected $appends = [ 'supervisor_name'];
protected $appends = [ 'supervisor_name', 'donating_form_link'];
protected $with = [ 'supervisor'];
public static $controllable = true;

public function getSupervisorNameAttribute(){
return $this->supervisor->name;
}
// public function getFormLinkAttribute(){
// }
public function getDonatingFormLinkAttribute(){
return url("/donating-form/{$this->donating_form_path}");
}
public function supervisor(){
return $this->belongsTo(User::class, 'supervisor_id');
}
public static function headers($user = null)
{
return [
['sortable' => true, 'value' => 'name', 'key' => 'name'],
['sortable' => true, 'value' => 'donating form path', 'key' => 'donating_form_path'],
['sortable' => true, 'value' => 'donating form path', 'key' => 'donating_form_link', 'type' => 'link'],
['sortable' => true, 'value' => 'supervisor name', 'key' => 'supervisor_name'],
// ['sortable' => true, 'value' => 'description', 'key' => 'description'],
['sortable' => true, 'value' => 'actions', 'key' => 'actions', 'actions' => ['show', 'update', 'delete']],
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function headers($user = null)
['sortable' => true, 'value' => 'entity name', 'key' => 'entity_name'],
['sortable' => true, 'value' => 'proposal type', 'key' => 'proposal_type_type_ar'],
['sortable' => true, 'value' => 'area name', 'key' => 'area_name'],
['sortable' => true, 'value' => 'status', 'key' => 'status_str_ar'],
['sortable' => true, 'value' => 'status', 'key' => 'status_str_ar', 'class_value_name' => 'status', 'has_class' => true],
// ['sortable' => true, 'value' => 'actions', 'key' => 'actions', 'actions' => ['show', 'update', 'delete']],
];
}
Expand Down
10 changes: 9 additions & 1 deletion resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}

@layer base {
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
125 changes: 125 additions & 0 deletions resources/js/Components/Dashboard/GuestAppBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<script setup>
import DropdownLink from "@/Components/DropdownLink.vue";
import ChangeMode from "@/Components/Dashboard/ChangeMode.vue";
import SearchInput from "@/Components/SearchInput.vue";
import { computed } from "vue";
import { usePage } from "@inertiajs/vue3";
import { useI18n } from "vue-i18n";
const { t, locale } = useI18n();
const page = usePage();
</script>
<template>
<nav
class="fixed top-0 z-30 w-full bg-white shadow dark:bg-gray-800 dark:border-gray-700"
>
<div class="px-3 py-3 lg:px-5 lg:pl-3">
<div class="flex items-center justify-between">
<div class="flex items-center justify-start">
<button

aria-controls="logo-sidebar"
type="button"
class="inline-flex items-center p-2 text-sm text-gray-500 rounded-lg sm:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600"
>
<span class="sr-only">Open sidebar</span>
<svg
class="w-6 h-6"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
fill-rule="evenodd"
d="M2 4.75A.75.75 0 012.75 4h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 4.75zm0 10.5a.75.75 0 01.75-.75h7.5a.75.75 0 010 1.5h-7.5a.75.75 0 01-.75-.75zM2 10a.75.75 0 01.75-.75h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 10z"
></path>
</svg>
</button>
</div>
<!-- <div><SearchInput /></div> -->
<div class="flex items-center">
<div class="flex items-center ms-3 dark:text-white">
<ChangeMode />
<div>
<button
type="button"
class="flex text-sm bg-gray-800 rounded-full focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600"
aria-expanded="false"
data-dropdown-toggle="dropdown-user"
>
<span class="sr-only">Open user menu</span>
<img
class="w-8 h-8 rounded-full"
src="@/assets/images/logo.png"
alt="user photo"
/>
</button>
</div>

<div
class="z-50 hidden my-4 text-base list-none bg-white divide-y divide-gray-100 rounded shadow dark:bg-gray-700 dark:divide-gray-600"
id="dropdown-user"
>

<ul class="py-1 min-w-fit" role="none">

<li>
<button
type="button"
class="flex items-center w-full p-2 text-gray-500 transition duration-75 rounded-lg group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700"
aria-controls="dropdown-language-menu"
data-collapse-toggle="dropdown-language-menu"
>
<span
class="flex-1 ml-3 text-start whitespace-nowrap"
sidebar-toggle-item
>{{ $t("language") }}</span
>
<svg
sidebar-toggle-item
class="w-6 h-6"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"
></path>
</svg>
</button>
<ul id="dropdown-language-menu" class="hidden py-2 space-y-2">
<li>
<a
:href="route('change-language', 'ar')"
@click="changeLanguage('ar')"
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white"
role="menuitem"
>{{ $t("arabic") }}</a
>
</li>
<li>
<a
:href="route('change-language', 'en')"
@click="changeLanguage('en')"
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white"
role="menuitem"
>{{ $t("english") }}</a
>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</nav>
</template>

<style></style>
Loading

0 comments on commit 9e13f90

Please sign in to comment.