name: CI/CD - ERP Core Monorepo

on:
  pull_request:
    branches:
      - production
    types:
      - closed

jobs:
  backend-build-and-deploy:
    name: Build & Deploy ERP Core Backend
    runs-on: linux
    if: github.event.pull_request.merged == true
    steps:
      - name: Checkout code
        run: |
          git clone \
            --depth 1 \
            --branch production \
            https://oauth2:${{ secrets.ERPCORE }}@gitea.hexdive.com/New_REP_SYSTEM/ERP-core.git \
            .

      - name: Restore backend
        run: dotnet restore Backend/ERPCore.sln

      - name: Publish backend
        run: |
          rm -rf /tmp/erpcore-deploy
          mkdir -p /tmp/erpcore-deploy
          dotnet publish Backend/ERPCore/ERPCore.csproj \
            -c Release \
            -r linux-x64 \
            --self-contained true \
            -o /tmp/erpcore-deploy

      - name: Stop backend service
        run: systemctl stop erpcore.service

      - name: Copy backend to deploy folder
        run: |
          mkdir -p /home/erp/core/publish
          rm -rf /home/erp/core/publish/*
          cp -r /tmp/erpcore-deploy/* /home/erp/core/publish/

      - name: Fix backend ownership and permissions
        run: |
          chown -R erpuser:erpuser /home/erp/core/publish
          find /home/erp/core/publish -type d -exec chmod 755 {} +
          find /home/erp/core/publish -type f -exec chmod 644 {} +
          chmod +x /home/erp/core/publish/ERPCore

      - name: Restart backend service
        run: systemctl restart erpcore.service

      - name: Verify backend
        run: |
          systemctl is-active erpcore.service && echo "Backend service running" || echo "Backend service failed"

  frontend-build-and-deploy:
    name: Build & Deploy ERP Core Frontend
    runs-on: linux
    needs: backend-build-and-deploy
    if: github.event.pull_request.merged == true
    steps:
      - name: Checkout code
        run: |
          git clone \
            --depth 1 \
            --branch Production \
            https://oauth2:${{ secrets.ERPCORE }}@gitea.hexdive.com/New_REP_SYSTEM/ERP-core.git \
            .

      - name: Build frontend Docker image
        run: docker build -t erpcore-frontend:latest Frontend/erp-system

      - name: Stop & remove existing frontend container
        run: |
          docker stop erpcore-frontend 2>/dev/null || true
          docker rm erpcore-frontend 2>/dev/null || true

      - name: Start frontend container
        run: |
          docker run -d \
            --name erpcore-frontend \
            -p 6702:6702 \
            --add-host=host.docker.internal:host-gateway \
            -e BACKEND_ORIGIN=http://host.docker.internal:6701 \
            --restart unless-stopped \
            --memory="512m" \
            --cpus="1.0" \
            --cap-drop ALL \
            --security-opt no-new-privileges \
            erpcore-frontend:latest

      - name: Remove old frontend images
        run: docker image prune -f

      - name: Verify frontend
        run: |
          docker ps --filter name=erpcore-frontend --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" \
            | grep erpcore-frontend && echo "Frontend container running" || echo "Frontend container failed"
This commit is contained in:
Kalana B. Thilakarathna
2026-09-17 13:59:05 +05:30
parent 93f2f1bd3b
commit 03d01d4c4e
61 changed files with 2195 additions and 1245 deletions
@@ -0,0 +1,113 @@
'use client'
import { useEffect, useState } from 'react'
import { useForm, zodResolver, z } from '@/lib/form'
import { FormField } from '@/components/shared/form-field'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
} from '@/components/ui/dialog'
import { FieldGroup } from '@/components/ui/field'
import { toast } from '@/components/ui/toast'
import { loadingSheets as loadingSheetsApi, rides as ridesApi, getApiError, getPaginatedItems } from '@/lib/api/index'
import type { RideResponse } from '@/types/api'
const schema = z.object({
fK_RideId: z.string().min(1, 'Ride is required'),
})
type FormValues = z.infer<typeof schema>
interface LoadingSheetCreateDialogProps {
open: boolean
onClose: () => void
onSuccess: () => void
}
export function LoadingSheetCreateDialog({ open, onClose, onSuccess }: LoadingSheetCreateDialogProps) {
const [ridesList, setRidesList] = useState<RideResponse[]>([])
const form = useForm<FormValues>({
resolver: zodResolver(schema),
defaultValues: { fK_RideId: '' },
})
useEffect(() => {
if (!open) return
form.reset({ fK_RideId: '' })
ridesApi.list({ status: 'Open', pageSize: 200 })
.then((res) => setRidesList(getPaginatedItems(res)))
.catch((err) => toast.add({ title: 'Failed to load rides', description: getApiError(err), type: 'error' }))
}, [open])
async function onSubmit(values: FormValues) {
try {
await loadingSheetsApi.create(values)
toast.add({ title: 'Loading sheet created', type: 'success' })
onSuccess()
onClose()
} catch (err) {
toast.add({ title: 'Failed to create loading sheet', description: getApiError(err), type: 'error' })
}
}
return (
<Dialog open={open} onOpenChange={(v) => !v && onClose()}>
<DialogContent className="overflow-y-auto sm:max-w-lg">
<DialogHeader>
<DialogTitle>New Loading Sheet</DialogTitle>
<DialogDescription>
Create a loading sheet for an open ride. Only one planned sheet per ride is allowed.
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-6">
<FieldGroup>
<FormField
control={form.control}
name="fK_RideId"
label="Ride"
required
render={({ field }) => (
<Select value={field.value as string} onValueChange={field.onChange}>
<SelectTrigger>
<SelectValue placeholder="Select open ride..." />
</SelectTrigger>
<SelectContent>
<SelectItem value="" disabled>Select open ride...</SelectItem>
{ridesList.map((r) => (
<SelectItem key={r.id} value={r.id}>
{r.vehicleNumberPlate} — {r.driverFullName}
</SelectItem>
))}
</SelectContent>
</Select>
)}
/>
</FieldGroup>
<DialogFooter>
<Button type="button" variant="outline" onClick={onClose}>
Cancel
</Button>
<Button type="submit" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? 'Creating…' : 'Create Sheet'}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}
@@ -11,11 +11,8 @@ import { Separator } from '@/components/ui/separator'
import type { LoadingSheetResponse, LoadingSheetStatus } from '@/types/api'
const LS_STATUS_VARIANT: Record<LoadingSheetStatus, 'default' | 'secondary' | 'destructive'> = {
Pending: 'secondary',
DispatchConfirmed: 'default',
ReceiptConfirmed: 'default',
DiscrepancyFlagged: 'destructive',
Resolved: 'secondary',
Planned: 'secondary',
Confirmed: 'default',
}
const fmtDateTime = (v: string | null) =>
@@ -25,6 +22,8 @@ const fmtDateTime = (v: string | null) =>
})
: '—'
const truncId = (id: string) => id.substring(0, 8)
interface LoadingSheetViewSheetProps {
open: boolean
onClose: () => void
@@ -51,13 +50,12 @@ export function LoadingSheetViewSheet({ open, onClose, sheet }: LoadingSheetView
</DialogHeader>
<div className="flex flex-col">
<Row label="Sheet ID" value={<span className="font-mono">{sheet.id.substring(0, 8)}</span>} />
<Row label="Warehouse" value={sheet.warehouseName} />
<Row label="Sheet ID" value={<span className="font-mono">{truncId(sheet.id)}</span>} />
<Row label="Ride ID" value={<span className="font-mono">{truncId(sheet.fK_RideId)}</span>} />
<Row label="Status" value={<Badge variant={LS_STATUS_VARIANT[sheet.status]}>{sheet.status}</Badge>} />
<Row label="Dispatch Confirmed By" value={sheet.dispatchConfirmedBy ?? '—'} />
<Row label="Dispatch Confirmed At" value={fmtDateTime(sheet.dispatchConfirmedAt)} />
<Row label="Receipt Confirmed By" value={sheet.receiptConfirmedBy ?? '—'} />
<Row label="Receipt Confirmed At" value={fmtDateTime(sheet.receiptConfirmedAt)} />
<Row label="Populated At" value={fmtDateTime(sheet.populatedAt)} />
<Row label="Confirmed At" value={fmtDateTime(sheet.confirmedAt)} />
<Row label="Source POs" value={sheet.orders.length > 0 ? sheet.orders.map(o => truncId(o.shopPOId)).join(', ') : '—'} />
<Row label="Created At" value={fmtDateTime(sheet.createdAt)} />
</div>
@@ -70,15 +68,14 @@ export function LoadingSheetViewSheet({ open, onClose, sheet }: LoadingSheetView
<thead className="bg-muted/50">
<tr>
<th className="text-left font-medium px-3 py-2">Item</th>
<th className="text-right font-medium px-3 py-2">Dispatched</th>
<th className="text-right font-medium px-3 py-2">Received</th>
<th className="text-right font-medium px-3 py-2">Resolved</th>
<th className="text-left font-medium px-3 py-2">Warehouse</th>
<th className="text-right font-medium px-3 py-2">Qty</th>
</tr>
</thead>
<tbody>
{sheet.items.length === 0 ? (
<tr>
<td colSpan={4} className="text-center text-muted-foreground px-3 py-4">
<td colSpan={3} className="text-center text-muted-foreground px-3 py-4">
No items on this sheet.
</td>
</tr>
@@ -86,9 +83,8 @@ export function LoadingSheetViewSheet({ open, onClose, sheet }: LoadingSheetView
sheet.items.map((item) => (
<tr key={item.id} className="border-t">
<td className="px-3 py-2">{item.itemName}</td>
<td className="px-3 py-2 text-muted-foreground">{item.warehouseName}</td>
<td className="text-right px-3 py-2">{item.quantityDispatched}</td>
<td className="text-right px-3 py-2">{item.quantityReceived}</td>
<td className="text-right px-3 py-2">{item.quantityResolved}</td>
</tr>
))
)}
@@ -1,14 +1,19 @@
'use client'
import { useState, useEffect, useCallback, useMemo } from 'react'
import { HugeiconsIcon } from '@hugeicons/react'
import { Add01Icon } from '@hugeicons/core-free-icons'
import { DataTable } from '@/components/shared/data-table'
import type { TableConfig } from '@/components/shared/data-table'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/toast'
import { loadingSheets as loadingSheetsApi, getApiError, getPaginatedItems } from '@/lib/api/index'
import type { LoadingSheetResponse, LoadingSheetStatus } from '@/types/api'
import { LoadingSheetViewSheet } from './loading-sheet-view-sheet'
import { LoadingSheetCreateDialog } from './loading-sheet-create-dialog'
const fmtDate = (v: string) =>
new Date(v).toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' })
@@ -16,11 +21,8 @@ const fmtDate = (v: string) =>
const truncId = (id: string) => id.substring(0, 8)
const LS_STATUS_VARIANT: Record<LoadingSheetStatus, 'default' | 'secondary' | 'destructive'> = {
Pending: 'secondary',
DispatchConfirmed: 'default',
ReceiptConfirmed: 'default',
DiscrepancyFlagged: 'destructive',
Resolved: 'secondary',
Planned: 'secondary',
Confirmed: 'default',
}
export function LoadingSheetsClient() {
@@ -30,6 +32,7 @@ export function LoadingSheetsClient() {
const [page, setPage] = useState(1)
const [pageSize, setPageSize] = useState(20)
const [createOpen, setCreateOpen] = useState(false)
const [viewOpen, setViewOpen] = useState(false)
const [selectedSheet, setSelectedSheet] = useState<LoadingSheetResponse | null>(null)
@@ -55,23 +58,13 @@ export function LoadingSheetsClient() {
setViewOpen(true)
}
async function handleConfirmDispatch(row: LoadingSheetResponse) {
async function handleConfirm(row: LoadingSheetResponse) {
try {
await loadingSheetsApi.confirmDispatch(row.id)
toast.add({ title: 'Dispatch confirmed', type: 'success' })
await loadingSheetsApi.confirm(row.id)
toast.add({ title: 'Loading sheet confirmed — stock committed to vehicle', type: 'success' })
fetchData(page, pageSize)
} catch (err) {
toast.add({ title: 'Failed to confirm dispatch', description: getApiError(err), type: 'error' })
}
}
async function handleConfirmReceipt(row: LoadingSheetResponse) {
try {
await loadingSheetsApi.confirmReceipt(row.id, [])
toast.add({ title: 'Receipt confirmed', type: 'success' })
fetchData(page, pageSize)
} catch (err) {
toast.add({ title: 'Failed to confirm receipt', description: getApiError(err), type: 'error' })
toast.add({ title: 'Failed to confirm loading sheet', description: getApiError(err), type: 'error' })
}
}
@@ -92,33 +85,45 @@ export function LoadingSheetsClient() {
),
},
{
key: 'warehouseName',
title: 'Warehouse',
fields: [{ key: 'warehouseName', primary: true }],
minWidth: 180,
key: 'rideId',
title: 'Ride',
fields: ['fK_RideId'],
width: 140,
cellRender: (row) => (
<span className="font-mono text-sm text-muted-foreground">{truncId(row.fK_RideId)}</span>
),
},
{
key: 'status',
title: 'Status',
fields: ['status'],
width: 180,
width: 140,
cellRender: (row) => (
<Badge variant={LS_STATUS_VARIANT[row.status]}>{row.status}</Badge>
),
},
{
key: 'orders',
title: 'POs',
fields: ['orders'],
width: 80,
cellRender: (row) => (
<span className="text-sm text-muted-foreground">{row.orders.length}</span>
),
},
{
key: 'itemCount',
title: 'Items',
fields: ['items'],
width: 120,
width: 80,
cellRender: (row) => (
<span className="text-sm text-muted-foreground">{row.items.length} items</span>
<span className="text-sm text-muted-foreground">{row.items.length}</span>
),
},
{
key: 'createdAt',
title: 'Created',
fields: [{ key: 'createdAt', transform: (v) => fmtDate(v as string) }],
key: 'populatedAt',
title: 'Populated',
fields: [{ key: 'populatedAt', transform: (v) => fmtDate(v as string) }],
width: 140,
},
],
@@ -131,15 +136,9 @@ export function LoadingSheetsClient() {
},
{
action: 'confirm',
label: 'Confirm dispatch',
onClick: handleConfirmDispatch,
visible: (target) => target.status === 'Pending',
},
{
action: 'confirm',
label: 'Confirm receipt',
onClick: handleConfirmReceipt,
visible: (target) => target.status === 'DispatchConfirmed',
label: 'Confirm & commit stock',
onClick: handleConfirm,
visible: (target) => target.status === 'Planned',
},
],
},
@@ -151,9 +150,13 @@ export function LoadingSheetsClient() {
<div>
<h1 className="text-2xl font-semibold text-foreground">Loading Sheets</h1>
<p className="text-sm text-muted-foreground mt-0.5">
Track goods loaded onto a vehicle before dispatch
Items loaded onto a vehicle before a delivery run
</p>
</div>
<Button onClick={() => setCreateOpen(true)}>
<HugeiconsIcon icon={Add01Icon} size={16} />
New Sheet
</Button>
</div>
<DataTable
@@ -167,6 +170,12 @@ export function LoadingSheetsClient() {
}}
/>
<LoadingSheetCreateDialog
open={createOpen}
onClose={() => setCreateOpen(false)}
onSuccess={() => fetchData(page, pageSize)}
/>
<LoadingSheetViewSheet
open={viewOpen}
onClose={() => setViewOpen(false)}