@@ -15,6 +15,8 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
1515 const [ invoice , setInvoice ] = useState ( {
1616 tripId : initialData ?. tripId || '' ,
1717 shopName : initialData ?. shopName || '' ,
18+ shopAddress : initialData ?. shopAddress || '' ,
19+ tel : initialData ?. tel || '' ,
1820 country : initialData ?. country || '' ,
1921 currency : initialData ?. currency || 'HKD' ,
2022 txDate : initialData ?. txDate || new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
@@ -23,7 +25,7 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
2325 } ) ;
2426
2527 const [ items , setItems ] = useState < Partial < Item > [ ] > (
26- initialData ?. items || [ { id : crypto . randomUUID ( ) , nameOriginal : '' , nameChinese : '' , type : '食品' , qty : 1 , price : 0 , currency : 'HKD' } ]
28+ initialData ?. items || [ { id : crypto . randomUUID ( ) , nameOriginal : '' , nameChinese : '' , type : '食品' , qty : 1 , price : 0 , discount : 0 , currency : 'HKD' } ]
2729 ) ;
2830
2931 const [ isTranslating , setIsTranslating ] = useState < string | null > ( null ) ;
@@ -33,7 +35,7 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
3335 } , [ ] ) ;
3436
3537 const addItem = ( ) => {
36- setItems ( [ ...items , { id : crypto . randomUUID ( ) , nameOriginal : '' , nameChinese : '' , type : '食品' , qty : 1 , price : 0 , currency : invoice . currency } ] ) ;
38+ setItems ( [ ...items , { id : crypto . randomUUID ( ) , nameOriginal : '' , nameChinese : '' , type : '食品' , qty : 1 , price : 0 , discount : 0 , currency : invoice . currency } ] ) ;
3739 } ;
3840
3941 const removeItem = ( id : string ) => {
@@ -61,7 +63,7 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
6163 const newInvoice : Invoice = {
6264 ...invoice ,
6365 id : invoiceId ,
64- totalAmount : items . reduce ( ( sum , item ) => sum + ( Number ( item . price ) || 0 ) * ( Number ( item . qty ) || 1 ) , 0 )
66+ totalAmount : items . reduce ( ( sum , item ) => sum + ( ( Number ( item . price ) || 0 ) * ( Number ( item . qty ) || 1 ) ) - ( Number ( item . discount ) || 0 ) , 0 )
6567 } ;
6668
6769 await dbService . saveInvoice ( newInvoice ) ;
@@ -72,7 +74,8 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
7274 id : item . id || crypto . randomUUID ( ) ,
7375 invoiceId,
7476 currency : item . currency || invoice . currency ,
75- status : '未開封'
77+ status : '未開封' ,
78+ discount : Number ( item . discount ) || 0
7679 } ) ;
7780 }
7881
@@ -103,6 +106,23 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
103106 placeholder = "例如:驚安之殿堂"
104107 />
105108 </ div >
109+ < div className = "col-span-2" >
110+ < label className = "text-xs font-bold text-slate-500 mb-1 block" > 商店地址</ label >
111+ < input
112+ type = "text"
113+ value = { invoice . shopAddress }
114+ onChange = { e => setInvoice ( { ...invoice , shopAddress : e . target . value } ) }
115+ placeholder = "例如:東京都新宿區..."
116+ />
117+ </ div >
118+ < div className = "col-span-2" >
119+ < label className = "text-xs font-bold text-slate-500 mb-1 block" > 電話</ label >
120+ < input
121+ type = "text"
122+ value = { invoice . tel }
123+ onChange = { e => setInvoice ( { ...invoice , tel : e . target . value } ) }
124+ />
125+ </ div >
106126 < div >
107127 < label className = "text-xs font-bold text-slate-500 mb-1 block" > 日期</ label >
108128 < input
@@ -185,7 +205,7 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
185205 placeholder = "翻譯或手動輸入"
186206 />
187207 </ div >
188- < div className = "col-span-6 " >
208+ < div className = "col-span-4 " >
189209 < label className = "text-[10px] font-bold text-slate-400 uppercase" > 類別</ label >
190210 < select
191211 value = { item . type }
@@ -200,7 +220,7 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
200220 < option value = "其他" > 其他</ option >
201221 </ select >
202222 </ div >
203- < div className = "col-span-3 " >
223+ < div className = "col-span-2 " >
204224 < label className = "text-[10px] font-bold text-slate-400 uppercase" > 數量</ label >
205225 < input
206226 type = "number"
@@ -216,6 +236,14 @@ export const ManualInvoiceForm: React.FC<ManualInvoiceFormProps> = ({ initialDat
216236 onChange = { e => updateItem ( item . id ! , 'price' , Number ( e . target . value ) ) }
217237 />
218238 </ div >
239+ < div className = "col-span-3" >
240+ < label className = "text-[10px] font-bold text-slate-400 uppercase" > 折扣</ label >
241+ < input
242+ type = "number"
243+ value = { item . discount }
244+ onChange = { e => updateItem ( item . id ! , 'discount' , Number ( e . target . value ) ) }
245+ />
246+ </ div >
219247 </ div >
220248 </ div >
221249 ) ) }
0 commit comments