lbx-invoice
Version:
Provides functionality around generating invoices.
79 lines (78 loc) • 4.21 kB
TypeScript
import { juggler } from '@loopback/repository';
import { AddressData } from '../models/invoice/address-data.model';
import { BaseInvoiceRepository, NumberInvoicesRepository } from '../repositories';
/**
* Handles generating unique and consecutive numbers for invoices.
*/
export declare class BaseInvoiceNumberService {
private readonly invoiceRepository;
private readonly numberInvoicesRepository;
/**
* The number of digits used to generate the consecutive number.
* @default 4
*/
protected readonly NUMBER_OF_DIGITS: number;
/**
* The separator for the parts of the invoice number.
* @default '-'
*/
protected readonly SEPARATOR: string;
/**
* How many characters of the company name should be used in the invoice number.
* @default 6
*/
protected readonly NUMBER_COMPANY_ABBREVIATION_CHARACTERS: number;
/**
* How many characters of the private customer first and last name should be used in the invoice number.
* @default 3
*/
protected readonly NUMBER_PRIVATE_CUSTOMER_ABBREVIATION_CHARACTERS: number;
constructor(invoiceRepository: BaseInvoiceRepository, numberInvoicesRepository: NumberInvoicesRepository);
/**
* Generates a new invoice number.
* @param recipientId - The id of the recipient of the invoice.
* @param invoiceAddress - The address data of the customer.
* @param transaction - An optional transaction from outside to make sure any changes only apply when the transaction is committed.
* @param nameAbbreviation - An optional name abbreviation if you don't want to generate one.
* @returns A promise of the new invoice number.
*/
generateInvoiceNumber(recipientId: string, invoiceAddress: AddressData, transaction?: juggler.Transaction, nameAbbreviation?: string): Promise<string>;
/**
* Generates a temporary invoice number with the prefix temp.
* This does not increase the number of invoices which can be helpful if you create an invoice that might not be sent out.
* @param recipientId - The id of the recipient of the invoice.
* @param invoiceAddress - The address data of the customer.
* @param nameAbbreviation - An optional name abbreviation if you don't want to generate one.
* @returns A promise of the new temporary invoice number.
*/
generateTemporaryInvoiceNumber(recipientId: string, invoiceAddress: AddressData, nameAbbreviation?: string): Promise<string>;
/**
* Gets the temporary consecutive number of the invoices in this year and for the provided recipientId.
* Prefixes it with zeroes until the result has the same length as this.NUMBER_OF_DIGITS.
* @param recipientId - The id of the recipient of the invoice.
* @returns The number of invoices over a year filled up with zeroes to match this.NUMBER_OF_DIGITS.
*/
protected getTemporaryConsecutiveNumber(recipientId: string): Promise<string>;
/**
* Gets the consecutive number of the invoices in this year.
* Prefixes it with zeroes until the result has the same length as this.NUMBER_OF_DIGITS.
* @param recipientId - The id of the recipient of the invoice.
* @param transaction - An optional transaction from outside to make sure any changes only apply when the transaction is committed.
* @returns The number of invoices over a year filled up with zeroes to match this.NUMBER_OF_DIGITS.
*/
protected getConsecutiveNumber(recipientId: string, transaction?: juggler.Transaction): Promise<string>;
/**
* Gets the customer name abbreviation.
* @param invoiceAddress - The address data to get the name abbreviation from.
* @returns The first char of first and last name for private customers
* and the first two chars of the company name for company customers.
*/
protected getCustomerNameAbbreviation(invoiceAddress: AddressData): string;
private getPrivateCustomerAbbreviation;
private getCompanyNameAbbreviation;
/**
* Validates the given invoice number.
* @param invoiceNumber - The invoice number to validate.
*/
protected validateInvoiceNumber(invoiceNumber: string): Promise<void>;
}