@dvrd/dvr-controls 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -25,7 +25,7 @@ interface Props {
25
25
  height?: number;
26
26
  persistent?: PDFElementPersist;
27
27
  mainFont: PdfFont;
28
- subExclVat?: boolean;
28
+ tableHeaderLabels?: [string, string, string, string, string];
29
29
  }
30
30
 
31
31
  interface State {
@@ -148,10 +148,16 @@ export default class PdfInvoiceTable extends PdfElement<Props, State> {
148
148
  )
149
149
  };
150
150
 
151
+ getTableHeaderLabels = (): [string, string, string, string, string] => {
152
+ const {tableHeaderLabels} = this.props;
153
+ if (tableHeaderLabels) return tableHeaderLabels;
154
+ return ['Omschrijving', 'Aantal', 'Bedrag', 'BTW', 'Subtotaal incl. BTW'];
155
+ }
156
+
151
157
  render = () => {
152
158
  const {dragging, settings} = this.state;
153
- const {draggable, defaultPosition, width, height, onSaveHistory, subExclVat} = this.props;
154
- const subTotalLabel = `Subtotaal ${subExclVat ? 'excl.' : 'incl.'} BTW`;
159
+ const {draggable, defaultPosition, width, height, onSaveHistory} = this.props;
160
+ const headLabels = this.getTableHeaderLabels();
155
161
  return (
156
162
  <WithEvents events={this.event}>
157
163
  <PDFDraggable dragging={dragging} draggable={draggable} onDragStart={this.onDragStart}
@@ -166,11 +172,11 @@ export default class PdfInvoiceTable extends PdfElement<Props, State> {
166
172
  onResized={onSaveHistory} onDragged={onSaveHistory}>
167
173
  <div className='pdf-invoice-table' onClick={this.onClick}>
168
174
  <div className='invoice-line' style={this.getRowStyle(true)}>
169
- <span>Omschrijving</span>
170
- <span>Aantal</span>
171
- <span>Bedrag</span>
172
- <span>BTW</span>
173
- <span className='end'>{subTotalLabel}</span>
175
+ <span>{headLabels[0]}</span>
176
+ <span>{headLabels[1]}</span>
177
+ <span>{headLabels[2]}</span>
178
+ <span>{headLabels[3]}</span>
179
+ <span className='end'>{headLabels[4]}</span>
174
180
  </div>
175
181
  {[1, 2].map(this.renderInvoiceLine)}
176
182
  {this.renderTotals()}
@@ -49,7 +49,7 @@ interface Props {
49
49
  options?: PDFOptions;
50
50
  singleImage: boolean;
51
51
  headerButtons?: Array<ReactElement>;
52
- subExclVat?: boolean;
52
+ tableHeaderLabels?: [string, string, string, string, string];
53
53
  }
54
54
 
55
55
  interface State {
@@ -204,7 +204,7 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
204
204
  };
205
205
  const width = dimensions?.width;
206
206
  const height = dimensions?.height;
207
- const {values, mainFont, subExclVat} = this.props;
207
+ const {values, mainFont, tableHeaderLabels} = this.props;
208
208
  const key: string = generateUUID();
209
209
  const sharedProps = {
210
210
  defaultPosition: position,
@@ -231,7 +231,8 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
231
231
  break;
232
232
  case PDFElementType.INVOICE_TABLE:
233
233
  element = <PdfInvoiceTable {...sharedProps} width={width} height={height} mainFont={mainFont}
234
- persistent={PDFElementPersist.PERSISTENT} subExclVat={subExclVat}/>;
234
+ persistent={PDFElementPersist.PERSISTENT}
235
+ tableHeaderLabels={tableHeaderLabels}/>;
235
236
  break;
236
237
  }
237
238
  return {element, config};
@@ -136,7 +136,11 @@ export const shuffleArray = (arr: any[]): any[] => {
136
136
  return arr;
137
137
  };
138
138
 
139
- export const nullify = <T extends string | Array<any> | Set<any>>(value?: T | null): T | null => {
139
+ export function nullify<T extends string | Array<any> | Set<any> | number>(value?: T | null): T | null {
140
+ if (typeof value === 'number') {
141
+ if (value > 0) return value;
142
+ return null;
143
+ }
140
144
  if (!value) return null;
141
145
  else if (Array.isArray(value) || typeof value === 'string')
142
146
  return value.length ? value : null;