Skip to content

Commit

Permalink
resolve merge conflicts 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-elhelou committed Jan 18, 2025
2 parents 1c854ce + f779753 commit ea831dd
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 24 deletions.
40 changes: 40 additions & 0 deletions app/Events/ProposalDonatingStatusApprovedWithDonatedAmount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Events;

use App\Models\Proposal;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProposalDonatingStatusApprovedWithDonatedAmount
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $proposal;
public $donatingAmount;
/**
* Create a new event instance.
*/
public function __construct(Proposal $proposal, int $donatingAmount)
{
$this->proposal = $proposal;
$this->donatingAmount = $donatingAmount;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
10 changes: 10 additions & 0 deletions app/Http/Controllers/ProposalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Events\ProposalDonatingStatusApprovedWithDonatedAmount;
use App\Models\Proposal;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreProposalRequest;
Expand Down Expand Up @@ -107,7 +108,16 @@ public function update(UpdateProposalRequest $request, Proposal $proposal)
{
$validated = $request->validated();


// check if there is a donatingAmount and a new donation record is needed to be added
if(!empty($request->donatingAmount) && $request->status == 2 && $proposal->status != $request->status){
//create new donation;
// dd($request->donatingAmount);
ProposalDonatingStatusApprovedWithDonatedAmount::dispatch($proposal, $request->donatingAmount);
}

$proposal->update($validated);

return back()->with('res', ['message' => __('Proposal Updated Seccessfully'), 'type' => 'success']);
}

Expand Down
24 changes: 13 additions & 11 deletions app/Http/Requests/UpdateProposalRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ public function authorize()
public function rules()
{
return [
'title' => 'required|string|max:255',
'title' => 'sometimes|string|max:255',
'body' => 'nullable|string',
'title' => 'required|string',
'title' => 'sometimes|string',
'body' => 'nullable|string',
'notes' => 'nullable|string',
'currency_id' => 'required|integer|exists:currencies,id',
'currency_id' => 'sometimes|integer|exists:currencies,id',
'proposal_effects' => 'nullable|string',
'cost' => 'required|numeric',
'share_cost' => 'required|numeric',
'expected_benificiaries_count' => 'required|integer|min:0',
'publishing_date' => 'required|date',
'execution_date' => 'required|date|after_or_equal:publishing_date',
'entity_id' => 'required|integer|exists:entities,id',
'proposal_type_id' => 'required|integer|exists:proposal_types,id',
'area_id' => 'required|integer|exists:areas,id',
'cost' => 'sometimes|numeric',
'share_cost' => 'sometimes|numeric',
'expected_benificiaries_count' => 'sometimes|integer|min:0',
'publishing_date' => 'sometimes|date',
'execution_date' => 'sometimes|date|after_or_equal:publishing_date',
'entity_id' => 'sometimes|integer|exists:entities,id',
'proposal_type_id' => 'sometimes|integer|exists:proposal_types,id',
'area_id' => 'sometimes|integer|exists:areas,id',
'donated_amount' => 'sometimes|numeric',
'status' => 'sometimes|integer',
];
}
}
28 changes: 28 additions & 0 deletions app/Listeners/StoreDonationRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Listeners;

use App\Events\ProposalDonatingStatusApprovedWithDonatedAmount;
use App\Models\Donation;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class StoreDonationRecord
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(ProposalDonatingStatusApprovedWithDonatedAmount $event): void
{
// create donation

}
}
11 changes: 8 additions & 3 deletions app/Models/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class Proposal extends BaseModel
{
use HasFactory;

protected $appends = ['status_str', 'beneficiaries', 'currency_name', 'entity_name', 'proposal_type_type_ar', 'area_name'];
protected $guarded = ['donated_amount'];
protected $appends = ['status_str_ar', 'beneficiaries', 'currency_name', 'entity_name', 'proposal_type_type_ar', 'area_name'];
protected $with = ['entity', 'area', 'proposalType', 'currency'];
public static $controllable = true;

Expand All @@ -33,7 +33,11 @@ class Proposal extends BaseModel

public function getStatusStrAttribute()
{
return [1 => 'accepted', 2 => 'unaccepted', 3 => 'pending', 4 => 'preparing', 8 => 'done'][$this->status] ?? '';
return [1 => 'donating_status', 2 => 'execution_status', 3 => 'read_to_archive_status', 8 => 'done_status'][$this->status] ?? '';
}
public function getStatusStrArAttribute()
{
return [1 => 'مرحلة جمع التبرعات', 2 => 'مرحلة التنفيذ والتوثيق', 3 => 'بحاجة للأرشفة', 8 => 'مكتمل'][$this->status] ?? '';
}

public function getBeneficiariesAttribute()
Expand Down Expand Up @@ -93,6 +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' => 'actions', 'key' => 'actions', 'actions' => ['show', 'update', 'delete']],
];
}
Expand Down
63 changes: 63 additions & 0 deletions app/Observers/ProposalObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Observers;

use App\Models\Proposal;

class ProposalObserver
{
/**
* Handle the Proposal "created" event.
*
* @param \App\Models\Proposal $proposal
* @return void
*/
public function created(Proposal $proposal)
{
//
}

/**
* Handle the Proposal "updated" event.
*
* @param \App\Models\Proposal $proposal
* @return void
*/
public function updated(Proposal $proposal)
{

}

/**
* Handle the Proposal "deleted" event.
*
* @param \App\Models\Proposal $proposal
* @return void
*/
public function deleted(Proposal $proposal)
{
//
}

/**
* Handle the Proposal "restored" event.
*
* @param \App\Models\Proposal $proposal
* @return void
*/
public function restored(Proposal $proposal)
{
//
}

/**
* Handle the Proposal "force deleted" event.
*
* @param \App\Models\Proposal $proposal
* @return void
*/
public function forceDeleted(Proposal $proposal)
{
//
}
}
3 changes: 3 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Providers;

use App\Models\Proposal;
use Illuminate\Cookie\Middleware\EncryptCookies;

use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
use App\Observers\UserObserver;
use App\Models\User;
use App\Observers\ProposalObserver;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -27,6 +29,7 @@ public function boot(): void
EncryptCookies::except('locale');
EncryptCookies::except('laravel_session');
User::observe(UserObserver::class);
// Proposal::observe(ProposalObserver::class);
Vite::prefetch(concurrency: 3);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('proposals', function (Blueprint $table) {
$table->integer('status')->default(1)->change(); //[1 => 'donating_status', 2 => 'execution_status', 3 => 'read_to_archive_status', 8 => 'done_status']

});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};
71 changes: 71 additions & 0 deletions resources/js/Components/Modals/CompleteDonatingStatusModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<Modal :show="complete_donating_status" @close="closeCompleteDonatingStatusModal">
<div class="p-6">
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ $t("Are you sure you want to complete donating status?") }}
</h2>

<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ $t("Once your accept, User will be updated") }}.
</p>

<div class="mt-6 flex justify-end">
<SecondaryButton @click="closeCompleteDonatingStatusModal">
{{ $t("Cancel") }}
</SecondaryButton>
<TextInput
id="donatingAmount"
type="number"
class="mt-1 block w-full"
v-model="form.title"
required
autofocus
autocomplete="name"
>

</TextInput>
<PrimaryButton class="ml-3" @click="confirmCompleteDonatingStatusModal">
{{ $t("approve") }}
</PrimaryButton>
</div>
</div>
</Modal>

</template>

<script>
import SecondaryButton from "@/Components/SecondaryButton.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import TextInput from "@/Components/TextInput.vue";
import Modal from "@/Components/Modal.vue";
import { router } from "@inertiajs/vue3";
export default {
components: {
SecondaryButton,
PrimaryButton,
Modal,
},
props: ["action", "item", "complete_donating_status"],
methods: {
closeCompleteDonatingStatusModal() {
this.complete_donating_status = false;
},
confirmCompleteDonatingStatusModal() {
router.put(route(`${this.action.model}.update`, this.item.id), {
donated_amount: 100,
status: 2,
});
this.closeCompleteDonatingStatusModal();
},
completingDonatingStatus() {
this.complete_donating_status = true;
},
},
};
</script>

<style></style>

Loading

0 comments on commit ea831dd

Please sign in to comment.