Skip to content

Commit

Permalink
fulfilment crm store note (but the data not clear yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganes556 committed Jan 7, 2025
1 parent 2034fc1 commit edd3237
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Enums\Fulfilment\FulfilmentCustomer\FulfilmentCustomerStatusEnum;
use App\Enums\UI\Fulfilment\FulfilmentCustomerTabsEnum;
use App\Http\Resources\CRM\CustomersResource;
use App\Http\Resources\Fulfilment\FulfilmentCustomerNoteResource;
use App\Http\Resources\Fulfilment\RentalAgreementClausesResource;
use App\Http\Resources\History\HistoryResource;
use App\Models\CRM\Customer;
Expand Down Expand Up @@ -163,7 +164,7 @@ public function htmlResponse(FulfilmentCustomer $fulfilmentCustomer, ActionReque
[
'type' => 'buttonGroup',
'button' => $additionalActions
]
],
]
],

Expand All @@ -188,9 +189,9 @@ public function htmlResponse(FulfilmentCustomer $fulfilmentCustomer, ActionReque
fn () => HistoryResource::collection(IndexHistory::run($fulfilmentCustomer->customer))
: Inertia::lazy(fn () => HistoryResource::collection(IndexHistory::run($fulfilmentCustomer->customer))),

FulfilmentCustomerTabsEnum::NOTE->value => $this->tab == FulfilmentCustomerTabsEnum::HISTORY->value ?
fn () => HistoryResource::collection(IndexFulfilmentCustomerNote::run($fulfilmentCustomer))
: Inertia::lazy(fn () => HistoryResource::collection(IndexFulfilmentCustomerNote::run($fulfilmentCustomer))),
FulfilmentCustomerTabsEnum::NOTE->value => $this->tab == FulfilmentCustomerTabsEnum::NOTE->value ?
fn () => FulfilmentCustomerNoteResource::collection(IndexFulfilmentCustomerNote::run($fulfilmentCustomer))
: Inertia::lazy(fn () => FulfilmentCustomerNoteResource::collection(IndexFulfilmentCustomerNote::run($fulfilmentCustomer))),

]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use App\Actions\OrgAction;
use App\Enums\Helpers\Audit\AuditEventEnum;
use App\Enums\UI\Fulfilment\FulfilmentCustomerTabsEnum;
use App\Models\Fulfilment\FulfilmentCustomer;
use App\Models\Helpers\History;
use Inertia\Inertia;
Expand All @@ -26,14 +27,18 @@ class StoreFulfilmentCustomerNote extends OrgAction
public function handle(FulfilmentCustomer $fulfilmentCustomer, array $modelData): History
{
data_set($modelData, 'event', AuditEventEnum::CUSTOMER_NOTE->value);
data_set($modelData, 'new_values', ['note' => $modelData['note']]);
data_set($modelData, 'new_values', [
'note' => $modelData['note'],
'details' => json_decode($modelData['details'])
]);
data_set($modelData, 'group_id', $fulfilmentCustomer->group_id);
data_set($modelData, 'organisation_id', $fulfilmentCustomer->organisation_id);
data_set($modelData, 'shop_id', $fulfilmentCustomer->shop_id);
data_set($modelData, 'auditable_id', $fulfilmentCustomer->customer_id);
data_set($modelData, 'auditable_type', class_basename($fulfilmentCustomer->customer));
data_set($modelData, 'customer_id', $fulfilmentCustomer->customer_id);
data_forget($modelData, 'note');
data_forget($modelData, 'details');

return History::create($modelData);
}
Expand All @@ -51,15 +56,17 @@ public function rules(): array
{
return [
'note' => ['required', 'string'],
'details' => ['sometimes', 'string'],
];
}

public function htmlResponse(FulfilmentCustomer $fulfilmentCustomer): Response
public function htmlResponse(History $history): Response
{
return Inertia::location(route('grp.org.fulfilments.show.crm.customers.show', [
'organisation' => $fulfilmentCustomer->organisation->slug,
'fulfilment' => $fulfilmentCustomer->fulfilment->slug,
'fulfilmentCustomer' => $fulfilmentCustomer->slug
'organisation' => $this->fulfilmentCustomer->organisation->slug,
'fulfilment' => $this->fulfilmentCustomer->fulfilment->slug,
'fulfilmentCustomer' => $this->fulfilmentCustomer->slug,
'tab' => FulfilmentCustomerTabsEnum::NOTE->value,
]));
}

Expand All @@ -68,6 +75,7 @@ public function htmlResponse(FulfilmentCustomer $fulfilmentCustomer): Response
*/
public function asController(FulfilmentCustomer $fulfilmentCustomer, ActionRequest $request): History
{
$this->fulfilmentCustomer = $fulfilmentCustomer;
$this->initialisationFromFulfilment($fulfilmentCustomer->fulfilment, $request);

return $this->handle($fulfilmentCustomer, $this->validatedData);
Expand All @@ -79,20 +87,20 @@ public function asController(FulfilmentCustomer $fulfilmentCustomer, ActionReque
public function action(FulfilmentCustomer $fulfilmentCustomer, array $modelData): History
{
$this->asAction = true;
$this->fulfilmentCustomer = $fulfilmentCustomer;
$this->initialisationFromFulfilment($fulfilmentCustomer->fulfilment, $modelData);

return $this->handle($fulfilmentCustomer, $this->validatedData);
}

public string $commandSignature = 'add:fulfilment-customer-note';

public function asCommand($command)
{
$c = FulfilmentCustomer::first();
$this->action($c, [
'note' => 'xxxxxx'
]);
}
// public string $commandSignature = 'add:fulfilment-customer-note';

// public function asCommand($command)
// {
// $c = FulfilmentCustomer::first();
// $this->action($c, [
// 'note' => 'xxxxxx'
// ]);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function handle(FulfilmentCustomer $fulfilmentCustomer, $prefix = null):
return $queryBuilder
->select(
'audits.created_at as datetime',
'audits.new_values->note as note'
'audits.new_values->note as note',
'audits.new_values->details->html as details_html',
'audits.new_values->details->text as details_text',
)
->defaultSort('-audits.created_at')
->allowedSorts(['created_at'])
Expand All @@ -75,8 +77,9 @@ public function tableStructure($prefix = null, ?array $exportLinks = null): Clos
$table
->withGlobalSearch()
->withExportLinks($exportLinks)
->column(key: 'note', label: __('Note'), canBeHidden: false, sortable: true)
->column(key: 'datetime', label: __('Date'), canBeHidden: false, sortable: true)
->column(key: 'note', label: __('Note'), canBeHidden: false, sortable: false)
->column(key: 'details', label: __('Details'), canBeHidden: false, sortable: false)
->defaultSort('-datetime');
};
}
Expand Down
29 changes: 29 additions & 0 deletions app/Http/Resources/Fulfilment/FulfilmentCustomerNoteResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* Author: Ganes <[email protected]>
* Created on: 07-01-2025, Bali, Indonesia
* Github: https://github.com/Ganes556
* Copyright: 2025
*
*/

namespace App\Http\Resources\Fulfilment;

use App\Http\Resources\HasSelfCall;
use Illuminate\Http\Resources\Json\JsonResource;

class FulfilmentCustomerNoteResource extends JsonResource
{
use HasSelfCall;

public function toArray($request): array
{
return [
'author' => $this->author,
'note' => $this->note,
'datetime' => $this->datetime,
'details' => ($this->details_text) ? $this->details_text : $this->details_html,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const props = defineProps<{
state: string
tab?: string
}>()

// const isActionLoading = ref<string | boolean>(false)
const emits = defineEmits<{
(e: 'renderTableKey'): void
Expand All @@ -45,10 +44,13 @@ const event = (event) => {
}

const addNotes = () => {
console.log({ user: layout.user.username, note: notes.value, permanent: permanent.value})
router.post(route('notes.store'),
{ user: layout.value.user.username, note: notes.value, permanent: permanent.value },
{
// console.log({ user: layout.user.username, note: notes.value, permanent: permanent.value}, route(props.data.routeStore))
// TODO: need details value for text or html
router.post(route('grp.models.fulfilment_customer_note.store', [
route().params["fulfilmentCustomer"]
]),
{ details: JSON.stringify({ text: "description" }), note: notes.value, permanent: permanent.value },
{
onSuccess: () => {
console.log('Note added successfully!');
_op.value.hide()
Expand Down
5 changes: 3 additions & 2 deletions routes/grp/web/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use App\Actions\Fulfilment\Fulfilment\UpdateFulfilment;
use App\Actions\Fulfilment\FulfilmentCustomer\AddDeliveryAddressToFulfilmentCustomer;
use App\Actions\Fulfilment\FulfilmentCustomer\StoreFulfilmentCustomer;
use App\Actions\Fulfilment\FulfilmentCustomer\StoreFulfilmentCustomerNote;
use App\Actions\Fulfilment\FulfilmentCustomer\UpdateFulfilmentCustomer;
use App\Actions\Fulfilment\FulfilmentTransaction\DeleteFulfilmentTransaction;
use App\Actions\Fulfilment\FulfilmentTransaction\StoreFulfilmentTransaction;
Expand Down Expand Up @@ -505,10 +506,10 @@
Route::post('website', [StoreWebsite::class, 'inFulfilment'])->name('website.store');
Route::post('fulfilment-customer', StoreFulfilmentCustomer::class)->name('fulfilment_customer.store');
Route::patch('website/{website:id}', [UpdateWebsite::class, 'inFulfilment'])->name('website.update')->withoutScopedBindings();


});

Route::post('fulfilment-customer-note/{fulfilmentCustomer}', StoreFulfilmentCustomerNote::class)->name('fulfilment_customer_note.store');




Expand Down

0 comments on commit edd3237

Please sign in to comment.