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:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import { useForm, zodResolver, z } from '@/lib/form'
|
||||
import { FormField } from '@/components/shared/form-field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@@ -22,14 +22,13 @@ import {
|
||||
} from '@/components/ui/dialog'
|
||||
import { FieldGroup } from '@/components/ui/field'
|
||||
import { toast } from '@/components/ui/toast'
|
||||
import { payments as paymentsApi, sales as salesApi, users as usersApi, getApiError, getPaginatedItems } from '@/lib/api/index'
|
||||
import type { SaleResponse, UserResponse } from '@/types/api'
|
||||
import { payments as paymentsApi, getApiError } from '@/lib/api/index'
|
||||
import type { InvoiceResponse } from '@/types/api'
|
||||
|
||||
const schema = z.object({
|
||||
saleId: z.string().min(1, 'Sale is required'),
|
||||
invoiceId: z.string().min(1, 'Invoice is required'),
|
||||
amount: z.number().min(0.01, 'Amount must be greater than 0'),
|
||||
method: z.enum(['Cash', 'Credit']),
|
||||
collectedByUserId: z.string().min(1, 'Collected by is required'),
|
||||
})
|
||||
|
||||
type FormValues = z.infer<typeof schema>
|
||||
@@ -38,51 +37,31 @@ interface PaymentSheetProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
onSuccess: () => void
|
||||
invoices: InvoiceResponse[]
|
||||
}
|
||||
|
||||
const fmtAmount = (n: number) => `Rs. ${n.toLocaleString()}`
|
||||
const truncId = (id: string) => id.substring(0, 8)
|
||||
|
||||
export function PaymentSheet({ open, onClose, onSuccess }: PaymentSheetProps) {
|
||||
const [salesList, setSalesList] = useState<SaleResponse[]>([])
|
||||
const [usersList, setUsersList] = useState<UserResponse[]>([])
|
||||
|
||||
export function PaymentSheet({ open, onClose, onSuccess, invoices }: PaymentSheetProps) {
|
||||
const form = useForm<FormValues>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
saleId: '',
|
||||
invoiceId: '',
|
||||
amount: 0,
|
||||
method: 'Cash',
|
||||
collectedByUserId: '',
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
|
||||
form.reset({
|
||||
saleId: '',
|
||||
amount: 0,
|
||||
method: 'Cash',
|
||||
collectedByUserId: '',
|
||||
})
|
||||
|
||||
Promise.all([
|
||||
salesApi.list({ pageSize: 200 }),
|
||||
usersApi.list({ pageSize: 200 }),
|
||||
])
|
||||
.then(([salesRes, usersRes]) => {
|
||||
setSalesList(getPaginatedItems(salesRes).filter((s) => s.status !== 'Cancelled'))
|
||||
setUsersList(getPaginatedItems(usersRes))
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.add({ title: 'Failed to load reference data', description: getApiError(err), type: 'error' })
|
||||
})
|
||||
form.reset({ invoiceId: '', amount: 0, method: 'Cash' })
|
||||
}, [open])
|
||||
|
||||
async function onSubmit(values: FormValues) {
|
||||
const { invoiceId, ...rest } = values
|
||||
try {
|
||||
await paymentsApi.create(values)
|
||||
await paymentsApi.create(invoiceId, rest)
|
||||
toast.add({ title: 'Payment recorded', type: 'success' })
|
||||
onSuccess()
|
||||
onClose()
|
||||
@@ -91,31 +70,33 @@ export function PaymentSheet({ open, onClose, onSuccess }: PaymentSheetProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const pendingInvoices = invoices.filter((inv) => inv.paymentStatus !== 'Paid')
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(v) => !v && onClose()}>
|
||||
<DialogContent className="overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Record Payment</DialogTitle>
|
||||
<DialogDescription>Record a cash or credit payment against a sale.</DialogDescription>
|
||||
<DialogDescription>Record a cash or credit payment against an invoice.</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-6">
|
||||
<FieldGroup>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="saleId"
|
||||
label="Sale"
|
||||
name="invoiceId"
|
||||
label="Invoice"
|
||||
required
|
||||
render={({ field }) => (
|
||||
<Select value={field.value as string} onValueChange={field.onChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select sale..." />
|
||||
<SelectValue placeholder="Select invoice..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="" disabled>Select sale...</SelectItem>
|
||||
{salesList.map((sale) => (
|
||||
<SelectItem key={sale.id} value={sale.id}>
|
||||
{truncId(sale.id)} — {fmtAmount(sale.totalAmount)} ({sale.paymentStatus})
|
||||
<SelectItem value="" disabled>Select invoice...</SelectItem>
|
||||
{pendingInvoices.map((inv) => (
|
||||
<SelectItem key={inv.id} value={inv.id}>
|
||||
{inv.storeName} — {fmtAmount(inv.totalAmount)} ({inv.paymentStatus}) [{truncId(inv.id)}]
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -150,10 +131,7 @@ export function PaymentSheet({ open, onClose, onSuccess }: PaymentSheetProps) {
|
||||
label="Payment Method"
|
||||
required
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
value={field.value as string}
|
||||
onValueChange={field.onChange}
|
||||
>
|
||||
<Select value={field.value as string} onValueChange={field.onChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select method" />
|
||||
</SelectTrigger>
|
||||
@@ -164,29 +142,6 @@ export function PaymentSheet({ open, onClose, onSuccess }: PaymentSheetProps) {
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="collectedByUserId"
|
||||
label="Collected By"
|
||||
description="Temporary — required until auth resolves the logged-in user automatically."
|
||||
required
|
||||
render={({ field }) => (
|
||||
<Select value={field.value as string} onValueChange={field.onChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select user..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="" disabled>Select user...</SelectItem>
|
||||
{usersList.map((user) => (
|
||||
<SelectItem key={user.id} value={user.id}>
|
||||
{user.fullName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
</FieldGroup>
|
||||
|
||||
<DialogFooter>
|
||||
|
||||
@@ -26,8 +26,7 @@ interface PaymentViewSheetProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
payment: PaymentResponse | null
|
||||
storeName?: string
|
||||
collectedByName?: string
|
||||
invoiceName?: string
|
||||
}
|
||||
|
||||
function Row({ label, value }: { label: string; value: React.ReactNode }) {
|
||||
@@ -39,7 +38,7 @@ function Row({ label, value }: { label: string; value: React.ReactNode }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function PaymentViewSheet({ open, onClose, payment, storeName, collectedByName }: PaymentViewSheetProps) {
|
||||
export function PaymentViewSheet({ open, onClose, payment, invoiceName }: PaymentViewSheetProps) {
|
||||
if (!payment) return null
|
||||
|
||||
return (
|
||||
@@ -51,12 +50,11 @@ export function PaymentViewSheet({ open, onClose, payment, storeName, collectedB
|
||||
|
||||
<div className="flex flex-col">
|
||||
<Row label="Payment ID" value={<span className="font-mono">{truncId(payment.id)}</span>} />
|
||||
<Row label="Sale ID" value={<span className="font-mono">{truncId(payment.saleId)}</span>} />
|
||||
<Row label="Store" value={storeName ?? <span className="font-mono">{truncId(payment.storeId)}</span>} />
|
||||
<Row label="Invoice" value={invoiceName ?? <span className="font-mono">{truncId(payment.invoiceId)}</span>} />
|
||||
<Row label="Amount" value={fmtAmount(payment.amount)} />
|
||||
<Row label="Method" value={<Badge variant={PAYMENT_METHOD_VARIANT[payment.method]}>{payment.method}</Badge>} />
|
||||
<Row label="Collected At" value={fmtDateTime(payment.collectedAt)} />
|
||||
<Row label="Collected By" value={collectedByName ?? <span className="font-mono">{truncId(payment.collectedBy)}</span>} />
|
||||
<Row label="Collected By" value={<span className="font-mono">{truncId(payment.collectedBy)}</span>} />
|
||||
<Row label="Created At" value={fmtDateTime(payment.createdAt)} />
|
||||
</div>
|
||||
</DialogContent>
|
||||
|
||||
@@ -8,9 +8,10 @@ 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 { Input } from '@/components/ui/input'
|
||||
import { toast } from '@/components/ui/toast'
|
||||
import { payments as paymentsApi, stores as storesApi, users as usersApi, getApiError, getPaginatedItems } from '@/lib/api/index'
|
||||
import type { PaymentResponse, PaymentMethod, StoreResponse, UserResponse } from '@/types/api'
|
||||
import { invoices as invoicesApi, payments as paymentsApi, getApiError, getPaginatedItems } from '@/lib/api/index'
|
||||
import type { PaymentResponse, PaymentMethod, InvoiceResponse } from '@/types/api'
|
||||
|
||||
import { PaymentSheet } from './payment-sheet'
|
||||
import { PaymentViewSheet } from './payment-view-sheet'
|
||||
@@ -27,33 +28,39 @@ const PAYMENT_METHOD_VARIANT: Record<PaymentMethod, 'default' | 'secondary'> = {
|
||||
}
|
||||
|
||||
export function PaymentsClient() {
|
||||
const [invoicesList, setInvoicesList] = useState<InvoiceResponse[]>([])
|
||||
const [selectedInvoiceId, setSelectedInvoiceId] = useState('')
|
||||
const [data, setData] = useState<PaymentResponse[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [total, setTotal] = useState(0)
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(20)
|
||||
const [pageSize] = useState(20)
|
||||
|
||||
const [sheetOpen, setSheetOpen] = useState(false)
|
||||
const [viewOpen, setViewOpen] = useState(false)
|
||||
const [selectedPayment, setSelectedPayment] = useState<PaymentResponse | null>(null)
|
||||
const [storesList, setStoresList] = useState<StoreResponse[]>([])
|
||||
const [usersList, setUsersList] = useState<UserResponse[]>([])
|
||||
|
||||
const storeNameById = useMemo(
|
||||
() => new Map(storesList.map((s) => [s.id, s.storeName])),
|
||||
[storesList]
|
||||
)
|
||||
const userNameById = useMemo(
|
||||
() => new Map(usersList.map((u) => [u.id, u.fullName])),
|
||||
[usersList]
|
||||
const invoiceNameById = useMemo(
|
||||
() => new Map(invoicesList.map((inv) => [inv.id, `${inv.storeName} — ${truncId(inv.id)}`])),
|
||||
[invoicesList]
|
||||
)
|
||||
|
||||
const fetchData = useCallback(async (p: number, ps: number) => {
|
||||
useEffect(() => {
|
||||
invoicesApi.list({ pageSize: 200 })
|
||||
.then((res) => setInvoicesList(getPaginatedItems(res)))
|
||||
.catch((err) => toast.add({ title: 'Failed to load invoices', description: getApiError(err), type: 'error' }))
|
||||
}, [])
|
||||
|
||||
const fetchData = useCallback(async (invoiceId: string) => {
|
||||
if (!invoiceId) {
|
||||
setData([])
|
||||
setTotal(0)
|
||||
return
|
||||
}
|
||||
setLoading(true)
|
||||
try {
|
||||
const res = await paymentsApi.list({ page: p, pageSize: ps })
|
||||
setData(getPaginatedItems(res))
|
||||
setTotal(res.total)
|
||||
const items = await paymentsApi.listByInvoice(invoiceId)
|
||||
setData(items)
|
||||
setTotal(items.length)
|
||||
} catch (err) {
|
||||
toast.add({ title: 'Failed to load payments', description: getApiError(err), type: 'error' })
|
||||
} finally {
|
||||
@@ -62,17 +69,8 @@ export function PaymentsClient() {
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
fetchData(page, pageSize)
|
||||
}, [fetchData, page, pageSize])
|
||||
|
||||
useEffect(() => {
|
||||
storesApi.list({ pageSize: 200 })
|
||||
.then((res) => setStoresList(getPaginatedItems(res)))
|
||||
.catch((err) => toast.add({ title: 'Failed to load stores', description: getApiError(err), type: 'error' }))
|
||||
usersApi.list({ pageSize: 200 })
|
||||
.then((res) => setUsersList(getPaginatedItems(res)))
|
||||
.catch((err) => toast.add({ title: 'Failed to load users', description: getApiError(err), type: 'error' }))
|
||||
}, [])
|
||||
fetchData(selectedInvoiceId)
|
||||
}, [fetchData, selectedInvoiceId])
|
||||
|
||||
function handleView(row: PaymentResponse) {
|
||||
setSelectedPayment(row)
|
||||
@@ -81,9 +79,8 @@ export function PaymentsClient() {
|
||||
|
||||
const tableConfig = useMemo<TableConfig<PaymentResponse>>(() => ({
|
||||
rowKey: 'id',
|
||||
serverSide: true,
|
||||
stickyHeader: true,
|
||||
emptyMessage: 'No payments found.',
|
||||
emptyMessage: selectedInvoiceId ? 'No payments found for this invoice.' : 'Enter an invoice ID to view its payments.',
|
||||
pagination: { enabled: true, pageSize, pageSizeOptions: [10, 20, 50] },
|
||||
columns: [
|
||||
{
|
||||
@@ -96,12 +93,12 @@ export function PaymentsClient() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'storeId',
|
||||
title: 'Store',
|
||||
fields: ['storeId'],
|
||||
minWidth: 160,
|
||||
key: 'invoiceId',
|
||||
title: 'Invoice',
|
||||
fields: ['invoiceId'],
|
||||
minWidth: 180,
|
||||
cellRender: (row) => (
|
||||
<span className="text-sm">{storeNameById.get(row.storeId) ?? truncId(row.storeId)}</span>
|
||||
<span className="text-sm">{invoiceNameById.get(row.invoiceId) ?? truncId(row.invoiceId)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -128,15 +125,6 @@ export function PaymentsClient() {
|
||||
fields: [{ key: 'collectedAt', transform: (v) => fmtDate(v as string) }],
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
key: 'collectedBy',
|
||||
title: 'Collected By',
|
||||
fields: ['collectedBy'],
|
||||
minWidth: 160,
|
||||
cellRender: (row) => (
|
||||
<span className="text-sm text-muted-foreground">{userNameById.get(row.collectedBy) ?? truncId(row.collectedBy)}</span>
|
||||
),
|
||||
},
|
||||
],
|
||||
rowActions: {
|
||||
actions: () => [
|
||||
@@ -147,7 +135,7 @@ export function PaymentsClient() {
|
||||
},
|
||||
],
|
||||
},
|
||||
}), [pageSize, storeNameById, userNameById])
|
||||
}), [pageSize, invoiceNameById])
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -155,7 +143,7 @@ export function PaymentsClient() {
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-foreground">Payments</h1>
|
||||
<p className="text-sm text-muted-foreground mt-0.5">
|
||||
Cash and credit payments collected from stores
|
||||
Cash and credit payments collected against invoices
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => setSheetOpen(true)}>
|
||||
@@ -164,29 +152,38 @@ export function PaymentsClient() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 max-w-sm">
|
||||
<Input
|
||||
placeholder="Paste invoice ID to filter payments..."
|
||||
value={selectedInvoiceId}
|
||||
onChange={(e) => setSelectedInvoiceId(e.target.value.trim())}
|
||||
/>
|
||||
{selectedInvoiceId && (
|
||||
<Button variant="ghost" size="sm" onClick={() => setSelectedInvoiceId('')}>
|
||||
Clear
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
config={tableConfig}
|
||||
data={data}
|
||||
loading={loading}
|
||||
totalCount={total}
|
||||
onServerSideChange={({ page: p }) => {
|
||||
setPage(p.page)
|
||||
setPageSize(p.pageSize)
|
||||
}}
|
||||
/>
|
||||
|
||||
<PaymentSheet
|
||||
open={sheetOpen}
|
||||
onClose={() => setSheetOpen(false)}
|
||||
onSuccess={() => fetchData(page, pageSize)}
|
||||
onSuccess={() => fetchData(selectedInvoiceId)}
|
||||
invoices={invoicesList}
|
||||
/>
|
||||
|
||||
<PaymentViewSheet
|
||||
open={viewOpen}
|
||||
onClose={() => setViewOpen(false)}
|
||||
payment={selectedPayment}
|
||||
storeName={selectedPayment ? storeNameById.get(selectedPayment.storeId) : undefined}
|
||||
collectedByName={selectedPayment ? userNameById.get(selectedPayment.collectedBy) : undefined}
|
||||
invoiceName={selectedPayment ? invoiceNameById.get(selectedPayment.invoiceId) : undefined}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user