@@ -17,13 +17,89 @@ import i18n from 'i18next';
1717export function generateRabat ( invoice : Fa ) : Content [ ] {
1818 const faRows : Record < string , FP > [ ] = getTable ( invoice ! . FaWiersze ?. FaWiersz ) ;
1919 const result : Content [ ] = [ ] ;
20- const definedHeader : HeaderDefine [ ] = [
20+ const definedHeaderLp : HeaderDefine [ ] = [
2121 { name : 'NrWierszaFa' , title : i18n . t ( 'invoice.discount.lp' ) , format : FormatTyp . Default , width : 'auto' } ,
22- { name : 'P_7' , title : i18n . t ( 'invoice.discount.productName' ) , format : FormatTyp . Default } ,
23- { name : 'P_8B' , title : i18n . t ( 'invoice.discount.quantity' ) , format : FormatTyp . Default } ,
24- { name : 'P_8A' , title : i18n . t ( 'invoice.discount.unit' ) , format : FormatTyp . Default } ,
2522 ] ;
26- const tabRabat : TableWithFields = getContentTable < ( typeof faRows ) [ 0 ] > ( definedHeader , faRows , '*' ) ;
23+
24+ const definedHeader1 : HeaderDefine [ ] = [
25+ { name : 'P_7' , title : i18n . t ( 'invoice.discount.productName' ) , format : FormatTyp . Default , width : '*' } ,
26+ {
27+ name : 'P_9A' ,
28+ title : i18n . t ( 'invoice.discount.netUnitPrice' ) ,
29+ format : FormatTyp . Currency ,
30+ width : 'auto' ,
31+ } ,
32+ {
33+ name : 'P_9B' ,
34+ title : i18n . t ( 'invoice.discount.grossUnitPrice' ) ,
35+ format : FormatTyp . Currency ,
36+ width : 'auto' ,
37+ } ,
38+ { name : 'P_8B' , title : i18n . t ( 'invoice.discount.quantity' ) , format : FormatTyp . Default , width : 'auto' } ,
39+ { name : 'P_8A' , title : i18n . t ( 'invoice.discount.unit' ) , format : FormatTyp . Default , width : 'auto' } ,
40+ { name : 'P_10' , title : i18n . t ( 'invoice.discount.discount' ) , format : FormatTyp . Currency , width : 'auto' } ,
41+ { name : 'P_12' , title : i18n . t ( 'invoice.discount.taxRate' ) , format : FormatTyp . Default , width : 'auto' } ,
42+ {
43+ name : 'P_12_XII' ,
44+ title : i18n . t ( 'invoice.discount.ossTaxRate' ) ,
45+ format : FormatTyp . Percentage ,
46+ width : 'auto' ,
47+ } ,
48+ {
49+ name : 'P_12_Zal_15' ,
50+ title : i18n . t ( 'invoice.discount.productMarker' ) ,
51+ format : FormatTyp . Default ,
52+ width : 'auto' ,
53+ } ,
54+ {
55+ name : 'P_11' ,
56+ title : i18n . t ( 'invoice.discount.netSalesValue' ) ,
57+ format : FormatTyp . Currency ,
58+ width : 'auto' ,
59+ } ,
60+ {
61+ name : 'P_11A' ,
62+ title : i18n . t ( 'invoice.discount.grossSalesValue' ) ,
63+ format : FormatTyp . Currency ,
64+ width : 'auto' ,
65+ } ,
66+ {
67+ name : 'KursWaluty' ,
68+ title : i18n . t ( 'invoice.discount.currencyRate' ) ,
69+ format : FormatTyp . Currency6 ,
70+ width : 'auto' ,
71+ } ,
72+ ] ;
73+
74+ const definedHeader2 : HeaderDefine [ ] = [
75+ { name : 'GTIN' , title : i18n . t ( 'invoice.discount.gtin' ) , format : FormatTyp . Default , width : 'auto' } ,
76+ { name : 'PKWiU' , title : i18n . t ( 'invoice.discount.pkwiu' ) , format : FormatTyp . Default , width : 'auto' } ,
77+ { name : 'CN' , title : i18n . t ( 'invoice.discount.cn' ) , format : FormatTyp . Default , width : 'auto' } ,
78+ { name : 'PKOB' , title : i18n . t ( 'invoice.discount.pkob' ) , format : FormatTyp . Default , width : 'auto' } ,
79+ {
80+ name : 'KwotaAkcyzy' ,
81+ title : i18n . t ( 'invoice.discount.exciseTaxAmount' ) ,
82+ format : FormatTyp . Currency ,
83+ width : 'auto' ,
84+ } ,
85+ { name : 'GTU' , title : i18n . t ( 'invoice.discount.gtu' ) , format : FormatTyp . Default , width : 'auto' } ,
86+ { name : 'Procedura' , title : i18n . t ( 'invoice.discount.procedure' ) , format : FormatTyp . Default , width : '*' } ,
87+ { name : 'P_6A' , title : i18n . t ( 'invoice.discount.getOrMakeDate' ) , format : FormatTyp . Date , width : 'auto' } ,
88+ { name : 'Indeks' , title : i18n . t ( 'invoice.discount.index' ) , format : FormatTyp . Default , width : 'auto' } ,
89+ {
90+ name : 'UU_ID' ,
91+ title : i18n . t ( 'invoice.discount.uuid' ) ,
92+ format : FormatTyp . Default ,
93+ width : 'auto' ,
94+ } ,
95+ ] ;
96+
97+ let tabRabat : TableWithFields = getContentTable < ( typeof faRows ) [ 0 ] > (
98+ [ ...definedHeaderLp , ...definedHeader1 , ...definedHeader2 ] ,
99+ faRows ,
100+ 'auto'
101+ ) ;
102+
27103 const isNrWierszaFa : boolean = tabRabat . fieldsWithValue . includes ( 'NrWierszaFa' ) ;
28104
29105 result . push (
@@ -39,8 +115,21 @@ export function generateRabat(invoice: Fa): Content[] {
39115 ''
40116 )
41117 ) ;
42- if ( tabRabat . fieldsWithValue . length > 0 && tabRabat . content ) {
118+
119+ if ( tabRabat . fieldsWithValue . length < 1 ) {
120+ result . push ( [ ] ) ;
121+ } else if ( tabRabat . fieldsWithValue . length <= 8 && tabRabat . content ) {
43122 result . push ( tabRabat . content ) ;
123+ } else {
124+ tabRabat = getContentTable < ( typeof faRows ) [ 0 ] > ( [ ...definedHeaderLp , ...definedHeader1 ] , faRows , '*' ) ;
125+ if ( tabRabat . content ) {
126+ result . push ( tabRabat . content ) ;
127+ }
128+ tabRabat = getContentTable < ( typeof faRows ) [ 0 ] > ( [ ...definedHeaderLp , ...definedHeader2 ] , faRows , '*' ) ;
129+ if ( tabRabat . content && tabRabat . fieldsWithValue . length > 1 ) {
130+ result . push ( '\n' ) ;
131+ result . push ( tabRabat . content ) ;
132+ }
44133 }
45134
46135 return createSection ( result , true ) ;
0 commit comments