feat: invoice, estimate and receipt printing.

This commit is contained in:
a.bouhuolia
2021-08-17 10:47:04 +02:00
parent 70939c5741
commit 160b8b6a1b
50 changed files with 3607 additions and 120 deletions

View File

@@ -0,0 +1,64 @@
import moment from "moment";
import { isEmpty, isObject, isUndefined } from 'lodash';
export class Transformer {
/**
*
* @returns
*/
protected includeAttributes = (): string[] => {
return [];
}
/**
*
*/
public transform = (object: any) => {
if (Array.isArray(object)) {
return object.map(this.getTransformation);
} else if (isObject(object)) {
return this.getTransformation(object);
}
return object;
};
/**
*
* @param item
* @returns
*/
protected getTransformation = (item) => {
const attributes = this.getIncludeAttributesTransformed(item);
return {
...!isUndefined(item.toJSON) ? item.toObject() : item,
...attributes
};
};
/**
*
* @param item
* @returns
*/
protected getIncludeAttributesTransformed = (item) => {
const attributes = this.includeAttributes();
return attributes
.filter((attribute) => !isUndefined(this[attribute]))
.reduce((acc, attribute: string) => {
acc[attribute] = this[attribute](item);
return acc;
}, {});
}
/**
*
* @param date
* @returns
*/
protected formatDate(date) {
return date ? moment(date).format('YYYY/MM/DD') : '';
}
}