This commit is contained in:
34
src/utils/business/employeeCollectionActing.ts
Normal file
34
src/utils/business/employeeCollectionActing.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { EmployeeCollectionDebtorSnapshot } from '@/types/api/employeeCollection'
|
||||
|
||||
interface ResponsibleBill {
|
||||
debtor_account_id?: number | null
|
||||
debtor_snapshot?: EmployeeCollectionDebtorSnapshot | null
|
||||
}
|
||||
|
||||
interface CurrentEmployee {
|
||||
id?: number
|
||||
name?: string | null
|
||||
user_type?: number
|
||||
}
|
||||
|
||||
const normalizedName = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
||||
|
||||
export const isEmployeeCollectionBillSelf = (
|
||||
bill: ResponsibleBill | undefined,
|
||||
employee: CurrentEmployee
|
||||
): boolean => {
|
||||
const employeeName = normalizedName(employee.name)
|
||||
const debtorName = normalizedName(bill?.debtor_snapshot?.account_name)
|
||||
// 用户确认:账单负责员工与 me.user.name 同名时,本人办理,不发送代办原因。
|
||||
if (employeeName && debtorName && employeeName === debtorName) return true
|
||||
const debtorId = Number(bill?.debtor_snapshot?.account_id ?? bill?.debtor_account_id)
|
||||
const employeeId = Number(employee.id)
|
||||
return debtorId > 0 && employeeId > 0 && debtorId === employeeId
|
||||
}
|
||||
|
||||
export const requiresEmployeeCollectionActingReason = (
|
||||
bills: Array<ResponsibleBill | undefined>,
|
||||
employee: CurrentEmployee
|
||||
): boolean =>
|
||||
Number(employee.user_type) === 1 &&
|
||||
(bills.length === 0 || bills.some((bill) => !isEmployeeCollectionBillSelf(bill, employee)))
|
||||
Reference in New Issue
Block a user