Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

報告未登録の申請取得APIの作成 #824

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,26 @@ const docTemplate = `{
}
},
},
"/purchaseorders/details/unregistered/{year}": {
"get": {
tags: ["purchase_order"],
"description": "年度で指定されたreportsに未登録のpurchase_orderに紐づくuserとpurchase_itemを取得",
"parameters": [
{
"name": "year",
"in": "path",
"description": "year",
"required": true,
"type": "integer"
}
],
"responses": {
"200": {
"description": "IDで指定されたreportsに未登録のpurchase_orderに紐づくuserとpurchase_itemを取得",
}
}
},
},
"/purchasereports": {
"get": {
tags: ["purchase_report"],
Expand Down
10 changes: 10 additions & 0 deletions api/externals/controller/purhcase_order_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type PurchaseOrderController interface {
IndexOrderDetail(echo.Context) error
ShowOrderDetail(echo.Context) error
IndexOrderDetailByYear(echo.Context) error
IndexUnregisteredOrderDetailByYear(echo.Context) error
}

func NewPurchaseOrderController(u usecase.PurchaseOrderUseCase) PurchaseOrderController {
Expand Down Expand Up @@ -109,3 +110,12 @@ func (p *purchaseOrderController) IndexOrderDetailByYear(c echo.Context) error {
}
return c.JSON(http.StatusOK, orderDetails)
}

func (p *purchaseOrderController) IndexUnregisteredOrderDetailByYear(c echo.Context) error {
year := c.Param("year")
orderDetails, err := p.u.GetUnregisteredPurchaseOrderDetailsByYear(c.Request().Context(), year)
if err != nil {
return err
}
return c.JSON(http.StatusOK, orderDetails)
}
34 changes: 34 additions & 0 deletions api/externals/repository/purchase_order_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PurchaseOrderRepository interface {
DeleteItems(context.Context, string) error
DeleteReport(context.Context, string) error
AllUserInfoByYear(context.Context, string) (*sql.Rows, error)
AllUnregisteredUserInfoByYear(context.Context, string) (*sql.Rows, error)
}

func NewPurchaseOrderRepository(c db.Client, ac abstract.Crud) PurchaseOrderRepository {
Expand Down Expand Up @@ -189,3 +190,36 @@ func (p *purchaseOrderRepository) AllUserInfoByYear(c context.Context, year stri
return p.crud.Read(c, query)
}

func (p *purchaseOrderRepository) AllUnregisteredUserInfoByYear(c context.Context, year string) (*sql.Rows, error) {
query := `
SELECT
orders.*,
users.*
FROM
purchase_orders AS orders
INNER JOIN
users
ON
orders.user_id = users.id
INNER JOIN
year_periods AS yp
ON
orders.created_at > yp.started_at
AND
orders.created_at < yp.ended_at
INNER JOIN
years
ON
yp.year_id = years.id
LEFT OUTER JOIN
purchase_reports AS reports
ON
orders.id = reports.purchase_order_id
WHERE
years.year = `+ year +`
AND
reports.purchase_order_id IS NULL
ORDER BY
orders.id`
return p.crud.Read(c, query)
}
61 changes: 61 additions & 0 deletions api/internals/usecase/purchase_order_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type PurchaseOrderUseCase interface {
GetPurchaseOrderDetails(context.Context) ([]domain.OrderDetail, error)
GetPurchaseOrderDetailByID(context.Context, string) (domain.OrderDetail, error)
GetPurchaseOrderDetailsByYear(context.Context, string) ([]domain.OrderDetail, error)
GetUnregisteredPurchaseOrderDetailsByYear(context.Context, string) ([]domain.OrderDetail, error)
}

func NewPurchaseOrderUseCase(rep rep.PurchaseOrderRepository) PurchaseOrderUseCase {
Expand Down Expand Up @@ -300,3 +301,63 @@ func (p *purchaseOrderUseCase) GetPurchaseOrderDetailsByYear(c context.Context,
}
return orderDetails, nil
}

// reports未登録の購入申請取得
func (p *purchaseOrderUseCase) GetUnregisteredPurchaseOrderDetailsByYear(c context.Context, year string) ([]domain.OrderDetail, error) {
orderDetail := domain.OrderDetail{}
var orderDetails []domain.OrderDetail
purchaseItem := domain.PurchaseItem{}
var purchaseItems []domain.PurchaseItem
rows, err := p.rep.AllUnregisteredUserInfoByYear(c, year)
if err != nil {
return nil, err
}

defer rows.Close()

for rows.Next() {
err := rows.Scan(
&orderDetail.PurchaseOrder.ID,
&orderDetail.PurchaseOrder.DeadLine,
&orderDetail.PurchaseOrder.UserID,
&orderDetail.PurchaseOrder.ExpenseID,
&orderDetail.PurchaseOrder.FinanceCheck,
&orderDetail.PurchaseOrder.CreatedAt,
&orderDetail.PurchaseOrder.UpdatedAt,
&orderDetail.User.ID,
&orderDetail.User.Name,
&orderDetail.User.BureauID,
&orderDetail.User.RoleID,
&orderDetail.User.IsDeleted,
&orderDetail.User.CreatedAt,
&orderDetail.User.UpdatedAt,
)
if err != nil {
return nil, err
}
rows, err := p.rep.FindPurchaseItem(c, strconv.Itoa(int(orderDetail.PurchaseOrder.ID)))
defer rows.Close()
for rows.Next() {
err := rows.Scan(
&purchaseItem.ID,
&purchaseItem.Item,
&purchaseItem.Price,
&purchaseItem.Quantity,
&purchaseItem.Detail,
&purchaseItem.Url,
&purchaseItem.PurchaseOrderID,
&purchaseItem.FinanceCheck,
&purchaseItem.CreatedAt,
&purchaseItem.UpdatedAt,
)
if err != nil {
return nil, err
}
purchaseItems = append(purchaseItems, purchaseItem)
}
orderDetail.PurchaseItem = purchaseItems
orderDetails = append(orderDetails, orderDetail)
purchaseItems = nil
}
return orderDetails, nil
}
1 change: 1 addition & 0 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (r router) ProvideRouter(e *echo.Echo) {
e.GET("/purchaseorders/details", r.purchaseOrderController.IndexOrderDetail)
e.GET("/purchaseorders/:id/details", r.purchaseOrderController.ShowOrderDetail)
e.GET("/purchaseorders/details/:year", r.purchaseOrderController.IndexOrderDetailByYear)
e.GET("/purchaseorders/details/unregistered/:year", r.purchaseOrderController.IndexUnregisteredOrderDetailByYear)

// purchasereportsのRoute
e.GET("/purchasereports", r.purchaseReportController.IndexPurchaseReport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function PurchaseItemNumModal() {
useEffect(() => {
if (router.isReady) {
const getPurchaseOrderViewUrl =
process.env.CSR_API_URI + '/purchaseorders/details/' + String(selectedYear);
process.env.CSR_API_URI + '/purchaseorders/details/unregistered/' + String(selectedYear);
const getExpensesUrl = process.env.CSR_API_URI + '/expenses';

const getPurchaseOrderView = async (url: string) => {
Expand Down Expand Up @@ -98,7 +98,7 @@ export default function PurchaseItemNumModal() {
};

return (
<Modal className='mt-32 overflow-scroll md:m-0 md:h-5/6'>
<Modal className='mt-32 overflow-scroll md:h-5/6 md:w-3/4'>
<div className={clsx('w-full ')}>
<div className={clsx('mr-5 grid w-full justify-items-end')}>
<CloseButton onClick={closeModal} />
Expand Down Expand Up @@ -128,7 +128,7 @@ export default function PurchaseItemNumModal() {
</div>
</div>
</div>
<div className={clsx('mb-4 grid h-2/3 grid-cols-12 gap-4 overflow-scroll')}>
<div className={clsx('max-h-2/3 mb-4 grid grid-cols-12 gap-4 overflow-scroll')}>
<div className={clsx('col-span-1 grid')} />
<div className={clsx('col-span-10 grid')}>
<div className={clsx('mb-2 w-full p-5')}>
Expand Down
Loading