2026-09-22 16:13:45 +08:00
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
2026-03-15 15:47:43 +08:00
|
|
|
from typing import Optional, List, Literal
|
|
|
|
|
from datetime import datetime
|
2026-04-19 23:41:35 +08:00
|
|
|
from decimal import Decimal
|
2026-03-15 15:47:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
TxnType = Literal["receipt", "payment"]
|
|
|
|
|
PartnerType = Literal["customer", "supplier"]
|
|
|
|
|
OrderType = Literal["sales", "purchase"]
|
|
|
|
|
TxnStatus = Literal["confirmed", "voided"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinanceAllocationCreate(BaseModel):
|
|
|
|
|
order_type: OrderType
|
|
|
|
|
order_id: int
|
2026-04-19 23:41:35 +08:00
|
|
|
allocated_amount: Decimal = Field(gt=0)
|
2026-03-15 15:47:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinanceTransactionCreate(BaseModel):
|
2026-04-19 23:41:35 +08:00
|
|
|
amount: Decimal = Field(gt=0)
|
2026-03-15 15:47:43 +08:00
|
|
|
txn_date: Optional[datetime] = None
|
|
|
|
|
method: str = "bank"
|
|
|
|
|
account_name: Optional[str] = None
|
|
|
|
|
remark: Optional[str] = None
|
|
|
|
|
allocations: List[FinanceAllocationCreate]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReceiptCreate(FinanceTransactionCreate):
|
|
|
|
|
customer_id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentCreate(FinanceTransactionCreate):
|
|
|
|
|
supplier_id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinanceAllocationResponse(BaseModel):
|
|
|
|
|
id: int
|
|
|
|
|
order_type: str
|
|
|
|
|
order_id: int
|
2026-04-19 23:41:35 +08:00
|
|
|
allocated_amount: Decimal
|
2026-03-15 15:47:43 +08:00
|
|
|
|
2026-09-22 16:13:45 +08:00
|
|
|
model_config = ConfigDict(from_attributes=True)
|
2026-03-15 15:47:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinanceTransactionResponse(BaseModel):
|
|
|
|
|
id: int
|
|
|
|
|
txn_no: str
|
|
|
|
|
txn_type: TxnType
|
|
|
|
|
partner_type: PartnerType
|
|
|
|
|
partner_id: int
|
2026-07-13 17:44:50 +08:00
|
|
|
partner_name: Optional[str] = None
|
2026-04-19 23:41:35 +08:00
|
|
|
amount: Decimal
|
2026-03-15 15:47:43 +08:00
|
|
|
txn_date: datetime
|
|
|
|
|
method: str
|
|
|
|
|
account_name: Optional[str]
|
|
|
|
|
status: TxnStatus
|
|
|
|
|
remark: Optional[str]
|
|
|
|
|
created_at: datetime
|
|
|
|
|
allocations: List[FinanceAllocationResponse] = []
|
|
|
|
|
|
2026-09-22 16:13:45 +08:00
|
|
|
model_config = ConfigDict(from_attributes=True)
|
2026-03-15 15:47:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinanceSummaryResponse(BaseModel):
|
2026-04-19 23:41:35 +08:00
|
|
|
receivable_total: Decimal
|
|
|
|
|
payable_total: Decimal
|
|
|
|
|
monthly_receipt_total: Decimal
|
|
|
|
|
monthly_payment_total: Decimal
|
2026-03-15 22:04:28 +08:00
|
|
|
selected_year: int
|
|
|
|
|
selected_quarter: Optional[int] = None
|
|
|
|
|
period_label: str
|
2026-04-19 23:41:35 +08:00
|
|
|
period_receipt_total: Decimal = Decimal("0")
|
|
|
|
|
period_payment_total: Decimal = Decimal("0")
|
2026-03-15 15:47:43 +08:00
|
|
|
overdue_receivable_count: int = 0
|
|
|
|
|
overdue_payable_count: int = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReceivableItemResponse(BaseModel):
|
|
|
|
|
order_id: int
|
|
|
|
|
order_no: str
|
|
|
|
|
customer_id: int
|
|
|
|
|
customer_name: str
|
|
|
|
|
order_date: datetime
|
2026-04-19 23:41:35 +08:00
|
|
|
total_amount: Decimal
|
|
|
|
|
received_amount: Decimal
|
|
|
|
|
receivable_amount: Decimal
|
2026-03-15 15:47:43 +08:00
|
|
|
status: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PayableItemResponse(BaseModel):
|
|
|
|
|
order_id: int
|
|
|
|
|
order_no: str
|
|
|
|
|
supplier_id: int
|
|
|
|
|
supplier_name: str
|
|
|
|
|
order_date: datetime
|
2026-04-19 23:41:35 +08:00
|
|
|
total_amount: Decimal
|
|
|
|
|
paid_amount: Decimal
|
|
|
|
|
payable_amount: Decimal
|
2026-03-15 15:47:43 +08:00
|
|
|
status: str
|
2026-03-15 22:04:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PartnerStatementItemResponse(BaseModel):
|
|
|
|
|
partner_id: int
|
|
|
|
|
partner_name: str
|
|
|
|
|
order_count: int
|
|
|
|
|
transaction_count: int
|
2026-04-19 23:41:35 +08:00
|
|
|
order_total: Decimal
|
|
|
|
|
settled_total: Decimal
|
|
|
|
|
transaction_total: Decimal
|
|
|
|
|
outstanding_total: Decimal
|
2026-03-15 22:04:28 +08:00
|
|
|
period_year: int
|
|
|
|
|
period_quarter: Optional[int] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinancePartnerStatementResponse(BaseModel):
|
|
|
|
|
partner_type: PartnerType
|
|
|
|
|
year: int
|
|
|
|
|
quarter: Optional[int] = None
|
|
|
|
|
period_label: str
|
2026-04-19 23:41:35 +08:00
|
|
|
order_total: Decimal
|
|
|
|
|
settled_total: Decimal
|
|
|
|
|
transaction_total: Decimal
|
|
|
|
|
outstanding_total: Decimal
|
2026-03-15 22:04:28 +08:00
|
|
|
items: List[PartnerStatementItemResponse] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PartnerProductStatementItemResponse(BaseModel):
|
|
|
|
|
partner_id: int
|
|
|
|
|
partner_name: str
|
|
|
|
|
product_id: int
|
|
|
|
|
product_sku: Optional[str] = None
|
|
|
|
|
product_name: str
|
|
|
|
|
order_count: int
|
2026-04-19 23:41:35 +08:00
|
|
|
order_quantity: Decimal
|
|
|
|
|
order_amount: Decimal
|
|
|
|
|
settled_amount: Decimal
|
|
|
|
|
outstanding_amount: Decimal
|
2026-03-15 22:04:28 +08:00
|
|
|
period_year: int
|
|
|
|
|
period_quarter: Optional[int] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FinancePartnerProductStatementResponse(BaseModel):
|
|
|
|
|
partner_type: PartnerType
|
|
|
|
|
year: int
|
|
|
|
|
quarter: Optional[int] = None
|
|
|
|
|
period_label: str
|
|
|
|
|
partner_id: Optional[int] = None
|
2026-04-19 23:41:35 +08:00
|
|
|
order_amount_total: Decimal
|
|
|
|
|
settled_amount_total: Decimal
|
|
|
|
|
outstanding_amount_total: Decimal
|
2026-03-15 22:04:28 +08:00
|
|
|
items: List[PartnerProductStatementItemResponse] = []
|