Skip to content

Commit d4825f1

Browse files
authored
feat(costcenter): support personal invoice (cn) (#6538)
Signed-off-by: Nixieboluo <me@sagirii.me>
1 parent 1f58fc0 commit d4825f1

File tree

6 files changed

+346
-145
lines changed

6 files changed

+346
-145
lines changed

frontend/providers/costcenter/public/locales/en/common.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,21 @@
157157
"placeholder": "Enter fax number"
158158
},
159159
"invoice_title": {
160-
"placeholder": "Enter invoice title"
160+
"placeholder": "Enter invoice title",
161+
"placeholder_personal": "Personal invoices usually require name"
161162
},
162163
"phone": {
163164
"placeholder": "Enter phone number"
164165
},
165166
"tax_registration_number": {
166-
"placeholder": "Enter tax registration number"
167+
"placeholder": "Enter tax registration number",
168+
"placeholder_personal": "Personal invoices usually require ID number"
167169
},
168170
"type": {
169171
"list": {
170172
"normal": "VAT invoice (Normal)",
171-
"special": "VAT invoice (Special)"
173+
"special": "VAT invoice (Special)",
174+
"personal": "Personal"
172175
}
173176
}
174177
},

frontend/providers/costcenter/public/locales/zh/common.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,21 @@
158158
"placeholder": "填写传真"
159159
},
160160
"invoice_title": {
161-
"placeholder": "填写发票抬头"
161+
"placeholder": "填写发票抬头",
162+
"placeholder_personal": "个人类型发票通常填写姓名"
162163
},
163164
"phone": {
164165
"placeholder": "填写电话"
165166
},
166167
"tax_registration_number": {
167-
"placeholder": "填写税务登记证号"
168+
"placeholder": "填写税务登记证号",
169+
"placeholder_personal": "个人类型发票通常填写身份证号"
168170
},
169171
"type": {
170172
"list": {
171173
"normal": "增值税普通发票",
172-
"special": "增值税专用发票"
174+
"special": "增值税专用发票",
175+
"personal": "个人"
173176
}
174177
}
175178
},

frontend/providers/costcenter/src/components/invoice/InvoiceForm.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,32 @@ const InvoiceForm = ({
6262
}, [remainTime]);
6363

6464
const validateField = (field: keyof InvoiceFormData, value: string): string => {
65+
const isPersonal = formData.invoiceType === 'personal';
66+
6567
switch (field) {
6668
case 'invoiceTitle':
6769
return !value.trim() ? t('common:orders.require') : '';
6870
case 'taxId':
71+
// Personal type: taxId is optional and no validation
72+
if (isPersonal) return '';
6973
if (!value.trim()) return t('common:orders.require');
7074
return !isValidCNTaxNumber(value) ? t('common:orders.tax_number_validation') : '';
7175
case 'bankName':
76+
// Personal type: bankName is not required
77+
if (isPersonal) return '';
7278
return !value.trim() ? t('common:orders.require') : '';
7379
case 'bankAccount':
80+
// Personal type: bankAccount is not required
81+
if (isPersonal) return '';
7482
if (!value.trim()) return t('common:orders.require');
7583
return !isValidBANKAccount(value) ? t('common:orders.bank_account_validation') : '';
7684
case 'address':
85+
// Personal type: address is not required
86+
if (isPersonal) return '';
7787
return !value.trim() ? t('common:orders.require') : '';
7888
case 'phone':
89+
// Personal type: phone is not required
90+
if (isPersonal) return '';
7991
return !value.trim() ? t('common:orders.require') : '';
8092
case 'contactPerson':
8193
return !value.trim() ? t('common:orders.require') : '';
@@ -97,7 +109,26 @@ const InvoiceForm = ({
97109

98110
const validateForm = (): FormErrors => {
99111
const newErrors: FormErrors = {};
100-
Object.keys(formData).forEach((field) => {
112+
const isPersonal = formData.invoiceType === 'personal';
113+
114+
// For personal type, only validate: invoiceTitle, contactPerson, email, mobileNumber, verificationCode
115+
// For normal/special type, validate all fields except fax
116+
const fieldsToValidate = isPersonal
117+
? ['invoiceTitle', 'contactPerson', 'email', 'mobileNumber', 'verificationCode']
118+
: [
119+
'invoiceTitle',
120+
'taxId',
121+
'bankName',
122+
'bankAccount',
123+
'address',
124+
'phone',
125+
'contactPerson',
126+
'email',
127+
'mobileNumber',
128+
'verificationCode'
129+
];
130+
131+
fieldsToValidate.forEach((field) => {
101132
const error = validateField(
102133
field as keyof InvoiceFormData,
103134
formData[field as keyof InvoiceFormData]

0 commit comments

Comments
 (0)