Skip to content

Commit

Permalink
order edit wip
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jul 9, 2024
1 parent cf90621 commit d8d0703
Show file tree
Hide file tree
Showing 30 changed files with 1,487 additions and 5 deletions.
13 changes: 12 additions & 1 deletion etc/packages/event_booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Entity\EventAttend;
use App\Entity\EventOrder;
use Lyrasoft\Sequence\Service\SequenceService;

Expand All @@ -27,7 +28,17 @@
'handler' => function (EventOrder $order, SequenceService $sequenceService) {
return $sequenceService->getNextSerialWithPrefix(
'event_order',
'EVT-' . \Windwalker\now('Ym') . '-',
'EVT-' . \Windwalker\now('ym') . '-',
5
);
}
],

'attend_no' => [
'handler' => function (EventOrder $order, EventAttend $attend, SequenceService $sequenceService) {
return $sequenceService->getNextSerialWithPrefix(
'event_attend',
'A-' . \Windwalker\now('ym') . '-',
6
);
}
Expand Down
3 changes: 3 additions & 0 deletions resources/languages/zh-TW/event-booking.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
event.edit.heading="活動: :event | :title"
event.stage.edit.heading="活動: :event | 梯次: :stage | :title"

event.invoice.type.personal="個人"
event.invoice.type.business="公司"
4 changes: 4 additions & 0 deletions resources/menu/admin/sidemenu.menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function (MenuBuilder $menu) use ($nav, $lang) {
->to($nav->to('event_attend_list'))
->icon('fal fa-users');

$menu->link('報名訂單管理')
->to($nav->to('event_order_list'))
->icon('fal fa-files');

// Portfolio
$menu->link('成員管理')
->to($nav->to('member_list'))
Expand Down
3 changes: 3 additions & 0 deletions resources/migrations/2024070509030001_EventInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function (Schema $schema) {
$schema->integer('modified_by');
$schema->json('params')->nullable(true);

$schema->addIndex('no');
$schema->addIndex('user_id');
$schema->addIndex('event_id');
$schema->addIndex('stage_id');
Expand All @@ -169,6 +170,7 @@ function (Schema $schema) {
$schema->integer('stage_id');
$schema->integer('plan_id');
$schema->varchar('plan_title');
$schema->varchar('no');
$schema->decimal('price');
$schema->varchar('name');
$schema->varchar('email');
Expand All @@ -187,6 +189,7 @@ function (Schema $schema) {
$schema->integer('modified_by');
$schema->json('params')->nullable(true);

$schema->addIndex('no');
$schema->addIndex('order_id');
$schema->addIndex('user_id');
$schema->addIndex('event_id');
Expand Down
33 changes: 33 additions & 0 deletions resources/migrations/2024070905230001_EventOrderInit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Migration;

use Windwalker\Core\Console\ConsoleApplication;
use Windwalker\Core\Migration\Migration;
use Windwalker\Database\Schema\Schema;

/**
* Migration UP: 2024070905230001_EventOrderInit.
*
* @var Migration $mig
* @var ConsoleApplication $app
*/
$mig->up(
static function () use ($mig) {
// $mig->updateTable(
// Table::class,
// function (Schema $schema) {}
// );
}
);

/**
* Migration DOWN.
*/
$mig->down(
static function () use ($mig) {
// $mig->dropTableColumns(Table::class, 'column');
}
);
3 changes: 3 additions & 0 deletions resources/seeders/event-order-seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Enum\InvoiceType;
use App\Enum\OrderHistoryType;
use App\EventBookingPackage;
use App\Service\EventAttendeeService;
use App\Service\EventOrderService;
use App\Service\InvoiceService;
use Brick\Math\BigDecimal;
Expand All @@ -38,6 +39,7 @@
$seeder->import(
static function (
EventOrderService $orderService,
EventAttendeeService $attendeeService,
InvoiceService $invoiceService,
EventBookingPackage $eventBooking,
LangService $lang,
Expand Down Expand Up @@ -155,6 +157,7 @@ static function (

foreach ($attends as $attend) {
$attend->setOrderId($item->getId());
$attend->setNo($attendeeService->createNo($item, $attend));

$orm->createOne($attend);

Expand Down
27 changes: 27 additions & 0 deletions routes/admin/event-order.route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Routes;

use App\Module\Admin\EventOrder\EventOrderController;
use App\Module\Admin\EventOrder\EventOrderEditView;
use App\Module\Admin\EventOrder\EventOrderListView;
use Windwalker\Core\Router\RouteCreator;

/** @var RouteCreator $router */

$router->group('event-order')
->extra('menu', ['sidemenu' => 'event_order_list'])
->register(function (RouteCreator $router) {
$router->any('event_order_list', '/event-order/list')
->controller(EventOrderController::class)
->view(EventOrderListView::class)
->postHandler('copy')
->putHandler('filter')
->patchHandler('batch');

$router->any('event_order_edit', '/event-order/edit[/{id}]')
->controller(EventOrderController::class)
->view(EventOrderEditView::class);
});
15 changes: 15 additions & 0 deletions src/Entity/EventAttend.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class EventAttend implements EntityInterface
#[Column('plan_title')]
protected string $planTitle = '';

#[Column('no')]
protected string $no = '';

#[Column('price')]
protected float $price = 0.0;

Expand Down Expand Up @@ -408,4 +411,16 @@ public function setPlanTitle(string $planTitle): static

return $this;
}

public function getNo(): string
{
return $this->no;
}

public function setNo(string $no): static
{
$this->no = $no;

return $this;
}
}
73 changes: 73 additions & 0 deletions src/Module/Admin/EventOrder/EventOrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace App\Module\Admin\EventOrder;

use App\Module\Admin\EventOrder\Form\EditForm;
use App\Repository\EventOrderRepository;
use Unicorn\Controller\CrudController;
use Unicorn\Controller\GridController;
use Windwalker\Core\Application\AppContext;
use Windwalker\Core\Attributes\Controller;
use Windwalker\Core\Router\Navigator;
use Windwalker\DI\Attributes\Autowire;

#[Controller()]
class EventOrderController
{
public function save(
AppContext $app,
CrudController $controller,
Navigator $nav,
#[Autowire] EventOrderRepository $repository,
): mixed {
$form = $app->make(EditForm::class);

$uri = $app->call($controller->saveWithNamespace(...), compact('repository', 'form'));

return match ($app->input('task')) {
'save2close' => $nav->to('event_order_list'),
default => $uri,
};
}

public function delete(
AppContext $app,
#[Autowire] EventOrderRepository $repository,
CrudController $controller
): mixed {
return $app->call($controller->delete(...), compact('repository'));
}

public function filter(
AppContext $app,
#[Autowire] EventOrderRepository $repository,
GridController $controller
): mixed {
return $app->call($controller->filter(...), compact('repository'));
}

public function batch(
AppContext $app,
#[Autowire] EventOrderRepository $repository,
GridController $controller
): mixed {
$task = $app->input('task');
$data = match ($task) {
'publish' => ['state' => 1],
'unpublish' => ['state' => 0],
default => null
};

return $app->call($controller->batch(...), compact('repository', 'data'));
}

public function copy(
AppContext $app,
#[Autowire] EventOrderRepository $repository,
GridController $controller
): mixed {
return $app->call($controller->copy(...), compact('repository'));
}
}
91 changes: 91 additions & 0 deletions src/Module/Admin/EventOrder/EventOrderEditView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace App\Module\Admin\EventOrder;

use App\Entity\Event;
use App\Entity\EventAttend;
use App\Entity\EventOrder;
use App\Entity\EventPlan;
use App\Entity\EventStage;
use App\Module\Admin\EventOrder\Form\EditForm;
use App\Repository\EventOrderRepository;
use Unicorn\View\FormAwareViewModelTrait;
use Unicorn\View\ORMAwareViewModelTrait;
use Windwalker\Core\Application\AppContext;
use Windwalker\Core\Attributes\ViewMetadata;
use Windwalker\Core\Attributes\ViewModel;
use Windwalker\Core\Html\HtmlFrame;
use Windwalker\Core\Language\TranslatorTrait;
use Windwalker\Core\View\View;
use Windwalker\Core\View\ViewModelInterface;
use Windwalker\DI\Attributes\Autowire;

/**
* The EventOrderEditView class.
*/
#[ViewModel(
layout: 'event-order-edit',
js: 'event-order-edit.js'
)]
class EventOrderEditView implements ViewModelInterface
{
use TranslatorTrait;
use ORMAwareViewModelTrait;
use FormAwareViewModelTrait;

public function __construct(
#[Autowire] protected EventOrderRepository $repository,
) {
}

/**
* Prepare
*
* @param AppContext $app
* @param View $view
*
* @return mixed
*/
public function prepare(AppContext $app, View $view): mixed
{
$id = $app->input('id');

/** @var EventOrder $item */
$item = $this->repository->mustGetItem($id);

// $event = $this->orm->mustFindOne(Event::class, $item->getEventId());
// $eventStage = $this->orm->mustFindOne(EventStage::class, $item->getStageId());

$attends = $this->orm->from(EventAttend::class)
->leftJoin(
EventPlan::class,
'plan'
)
->where('event_attend.order_id', $item->getId())
->groupByJoins()
->all(EventAttend::class);

// Bind item for injection
$view[EventOrder::class] = $item;

$form = $this->createForm(EditForm::class)
->fill(
[
'item' => $this->repository->getState()->getAndForget('edit.data')
?: $this->orm->extractEntity($item)
]
);

return compact('form', 'id', 'item', 'attends');
}

#[ViewMetadata]
protected function prepareMetadata(HtmlFrame $htmlFrame): void
{
$htmlFrame->setTitle(
$this->trans('unicorn.title.edit', title: '訂單')
);
}
}
Loading

0 comments on commit d8d0703

Please sign in to comment.