Skip to content

Commit f5ec6a1

Browse files
Added Customer register methods
1 parent 4024068 commit f5ec6a1

File tree

5 files changed

+384
-2
lines changed

5 files changed

+384
-2
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ After this, you can use all the methods available.
9393
The following API methods have been implemented:
9494

9595
- `bookkeeping` Bookkeeping
96-
- `product` Product register
96+
- `products` Product register
9797
- `purchaseInvoices` Purchase invoices
9898
- `chartOfAccounts` Chart of Accounts
9999
- `archive` Archive of files
100100
- `sales` Sales orders
101+
- `customers` Customer register
101102

102103
### Bookkeeping examples
103104

@@ -262,6 +263,64 @@ const { externalBatchId } = await fivaldi.sales.createOrders({
262263
});
263264
```
264265

266+
### Customer register examples
267+
268+
```ts
269+
// Get customer register's basic details
270+
const basicDetails = await fivaldi.customers.getCustomerRegisterBasicDetails();
271+
272+
// Get all customers with optional parameters
273+
const customerList = await fivaldi.customers.getAllCustomers({ searchWord: 'Bank' fromDate: '1.1.2020' });
274+
275+
// Get more detailed customer info with customer id
276+
const customerDetails = await fivaldi.customers.getCustomer('1001');
277+
278+
// Create a new customer
279+
const newCustomer = await fivaldi.customers.createCustomer(customerObject);
280+
281+
// Update customer info giving all fields
282+
const updatedCustomer = await fivaldi.customers.updateCustomerAllFields('1001', customerObject);
283+
284+
// Update customer info only giving updated fields
285+
const updatedCustomer = await fivaldi.customers.updateCustomer('1001', { instantMessagingType: '3' });
286+
287+
// Create a new address to customer
288+
const newAddress = await fivaldi.customers.createAddress('1001', {
289+
streetAddress: 'Mannerheimintie 63',
290+
postalCode: '00250',
291+
postalAddress: 'Helsinki',
292+
countryCode: 'FI',
293+
isMainAddress: true,
294+
addressType: '01'
295+
});
296+
297+
// Update customer's address giving all fields
298+
const updatedAddress = await fivaldi.customers.updateAddressAllFields('1001', '6', {
299+
streetAddress: 'Mannerheimintie 63',
300+
postalCode: '00250',
301+
postalAddress: 'Helsinki',
302+
countryCode: 'FI',
303+
isMainAddress: true,
304+
addressType: '03'
305+
});
306+
307+
// Create a new bank account to customer
308+
const newBankAccount = await fivaldi.customers.createBankAccount('1001', {
309+
bankName: 'Danske',
310+
ibanNumber: 'FI0488888800009998',
311+
countryId: 'FI',
312+
swift: 'DABAFIHH'
313+
});
314+
315+
// Update customer's bank account giving all fields
316+
const updatedBankAccount = await fivaldi.customers.updateBankAccountAllFields('1001', '00000005', {
317+
bankName: 'Danske Bank',
318+
ibanNumber: 'FI0488888800009998',
319+
countryId: 'FI',
320+
swift: 'DABAFIHH'
321+
});
322+
```
323+
265324
## Resources
266325

267326
- Fivaldi website: https://www.visma.fi/visma-fivaldi/
@@ -276,3 +335,4 @@ const { externalBatchId } = await fivaldi.sales.createOrders({
276335
- 0.1.1 Updated dependencies
277336
- 0.2.0 Added Archive of files method
278337
- 0.3.0 Added Sales orders method
338+
- 0.4.0 Added Customer register method

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rantalainen/fivaldi-api-client",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Third party Fivaldi API client.",
55
"main": "dist/index.js",
66
"scripts": {

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IFivaldiApiClientOptions, IGetCompaniesParams, IGetCompaniesResponse }
33
import { ArchiveMethods } from './methods/archive.methods';
44
import { BookkeepingMethods } from './methods/bookkeeping.methods';
55
import { ChartOfAccountsMethods } from './methods/chart-of-accounts.methods';
6+
import { CustomersMethods } from './methods/customers.methods';
67
import { ProductMethods } from './methods/products.methods';
78
import { PurchaseInvoicesMethods } from './methods/purchaseInvoices.methods';
89
import { SalesMethods } from './methods/sales.methods';
@@ -17,6 +18,7 @@ export class FivaldiApiClient {
1718
readonly chartOfAccounts: ChartOfAccountsMethods;
1819
readonly archive: ArchiveMethods;
1920
readonly sales: SalesMethods;
21+
readonly customers: CustomersMethods;
2022

2123
constructor(options: IFivaldiApiClientOptions) {
2224
options.apiBaseUrl = options.apiBaseUrl || 'https://api.fivaldi.net/customer/api';
@@ -38,6 +40,7 @@ export class FivaldiApiClient {
3840
this.chartOfAccounts = new ChartOfAccountsMethods(this);
3941
this.archive = new ArchiveMethods(this);
4042
this.sales = new SalesMethods(this);
43+
this.customers = new CustomersMethods(this);
4144
}
4245

4346
async request(method: Method, url: string, body?: any, params?: any): Promise<any> {
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/// PARAMS INTERFACES ///
2+
3+
export interface IGetAllCustomersParams {
4+
/** Limit results with search word */
5+
searchWord?: string;
6+
/** Limit results with changed at date is given date or newer (dd.mm.yyyy) */
7+
fromDate?: string;
8+
/** Filter fields of the response objects, only ones provided will be included on response */
9+
fields?: string;
10+
}
11+
12+
/// RESPONSE & REQUEST INTERFACES ///
13+
14+
export interface ICustomerEntityDetailsDTO {
15+
/** Customer id is set by Fivaldi as next available customer number. */
16+
customerId?: string;
17+
businessId?: string;
18+
customerName?: string;
19+
customerName2?: string;
20+
email?: string;
21+
email2?: string;
22+
phoneNumber?: string;
23+
phoneNumber2?: string;
24+
changeTime?: string;
25+
changeUser?: string;
26+
accountDimension1?: string;
27+
accountDimension2?: string;
28+
accountDimension3?: string;
29+
accountDimension4?: string;
30+
currency?: string;
31+
customerSegment?: string;
32+
customerInterestPercent?: number;
33+
debtCollectionDisabled?: boolean;
34+
deliveryMethod?: string;
35+
externalId?: string;
36+
/** Buyerpartyidentifier (Ostajan asiakastunnukseksi). selitteet (O = OVT, A = Yritystunnus, M = Verkkolaskuosoitteessa annettu muu tunnus, null = Y-tunnus) */
37+
finvoiceBuyerPartyIdentifier?: 'O' | 'A' | 'M';
38+
/** Finvoice dimensiontext mask for purchase invoice circulation (Seurantakohde-ehdotuksen tulkintasääntö) */
39+
finvoiceDimensionTextMask?: string;
40+
/** Don't handle incoming Finvoice postings (Älä tuo Finvoicen tiliöintirivejä) */
41+
finvoiceNoPostingRows?: boolean;
42+
/** Receivers MessageReceiverDetails ToIdentifier on Finvoice (Vastaanottajan verkkolaskuosoitteen tunnus) */
43+
finvoiceOtherIdentifier?: string;
44+
fivaldiBankAccountId?: string;
45+
/** Customer language code (Asiakkaan kielikoodi). Selitteet (FIN = Suomi, ENG = Englanti, SWE = Ruotsi) */
46+
languageCode?: 'FIN' | 'SWE' | 'ENG';
47+
/** Purchase instant messaging type code (Pankkisiirto-Viestityyppi). Selitteet (1 = Viite, 2 = Viesti, 3 = Veroviesti) */
48+
instantMessagingType?: '1' | '2' | '3';
49+
interestDisabled?: boolean;
50+
intermediatorCode?: string;
51+
isCustomer?: boolean;
52+
ovtIdentifier?: string;
53+
/** Payment pririty for purchases (Ostojen maksuprioriteetti). Selitteet (1 = Kiireellinen, 2 = Tärkeä, 3 = Normaali, 4 = Ei niin tärkeä, 5 = Voi odottaa) */
54+
paymentPriority?: 1 | 2 | 3 | 4 | 5;
55+
purchasePaymentTerm?: string;
56+
supplierCustomerId?: string;
57+
purchasePostingGroup?: string;
58+
additionalInformation?: string;
59+
privateAdditionalInfo?: string;
60+
purchaseDeliveryMethodId?: string;
61+
purchasePostingCode?: string;
62+
salesPostingGroup?: string;
63+
purchaseDeliveryTermId?: string;
64+
responsablePerson?: string;
65+
/** Reference format (Viitenumeron muoto). Selitteet (LV = Laskunumero + vakio, VL = Vakio + laskunumero, VA = Vakioarvo) */
66+
referenceFormat?: 'LV' | 'VL' | 'VA';
67+
referenceDefaultValue?: string;
68+
salesPersonId?: string;
69+
salesPaymentTerm?: string;
70+
isSupplier?: boolean;
71+
salesDeliveryTermId?: string;
72+
transmissionTypeId?: string;
73+
website?: string;
74+
/** SpecificationIdentifier element on Finvoice (EU-normin mukainen verkkolaskukoodi) */
75+
specificationIdentifier?: string;
76+
buyerCountrySubdivision?: string;
77+
classificationCode?: string;
78+
classificationText?: string;
79+
agreementIdentifier?: string;
80+
buyerReferenceIdentifier?: string;
81+
accountDimensionText?: string;
82+
tenderReference?: string;
83+
isConsumer?: boolean;
84+
einvoiceDirectPaymentprintingType?: string;
85+
einvoiceDirectPayment?: boolean;
86+
customerEntityAddressDTOS?: ICustomerEntityAddressDTO[];
87+
customerEntityBankAccountDTOS?: ICustomerEntityBankAccountDTO[];
88+
}
89+
90+
export interface ICustomerEntityAddressDTO {
91+
/** Address type (Osoitetyyppi). Selitteet (01 = Postiosoite, 02 = Käyntiosoite, 03 = Laskutusosoite, 04 = Toimitusosoite) */
92+
addressType?: '01' | '02' | '03' | '04';
93+
/** Fivaldi will set this id to new address */
94+
addressId?: number;
95+
streetAddress?: string;
96+
streetAddress2?: string;
97+
postalCode?: string;
98+
postalAddress?: string;
99+
/** Country code with ISO 3166-1 standard (Osoitteen maakoodi) */
100+
countryCode?: string;
101+
isMainAddress?: boolean;
102+
changeTime?: string;
103+
changeUser?: string;
104+
}
105+
106+
export interface ICustomerEntityBankAccountDTO {
107+
/** Fivaldi will set this id to new bank accounts */
108+
bankAccountId?: string;
109+
/** Fivaldi will set this based on IBAN- number if FI bank account and IBAN is given (Tilinumero) */
110+
bbanNumber?: string;
111+
bankAddress?: string;
112+
bankName?: string;
113+
changeTime?: string;
114+
changeUser?: string;
115+
clearingCode?: string;
116+
/** Country code of bank account with ISO 3166-1 standard (Pankkitilin maakoodi) */
117+
countryId: string;
118+
/** Foreign payment charge code (Valuuttamaksun palvelumaksut). Selitteet (J = Jaettu, T = Maksaja maksaa) */
119+
foreignPaymentCharge?: 'J' | 'T';
120+
/** Foreign payment type code (Valuuttamaksun maksutapa). Selitteet (M = Maksumääräys, P = Pikamääräys, Q = SWIFT- shekki, S = Shekki, T = Pankin sisäinen tilisiirto, K = Konsernimaksu, B = Eu-maksu OP) */
121+
foreignPaymentType?: 'M' | 'P' | 'Q' | 'S' | 'T' | 'K' | 'B';
122+
ibanNumber?: string;
123+
swift?: string;
124+
}
125+
126+
export interface IProductRegisterBasicDetails {
127+
paymentTermDTOList: IPaymentTermDTO[];
128+
deliveryMethodDTOList: IDeliveryMethodDTO[];
129+
deliveryTermDTOList: IDeliveryTermDTO[];
130+
currencyDTOList: ICurrencyDTO[];
131+
salesPersonDTOList: ISalesPersonDTO[];
132+
salesPostingGroupDTOList: ISalesPostingGroupDTO[];
133+
purchasesPostingGroupDTOList: [];
134+
customerGroupAndSegmentsDTOList: [];
135+
fivaldiCompanyBankAccountDTOList: [];
136+
accountDimension1ValueDTOList: IAccountDimensionValueDTO[];
137+
accountDimension2ValueDTOList: IAccountDimensionValueDTO[];
138+
accountDimension3ValueDTOList: IAccountDimensionValueDTO[];
139+
accountDimension4ValueDTOList: IAccountDimensionValueDTO[];
140+
purchasePostingCodeDTOList: IPurchasePostingCodeDTO[];
141+
paymentPriorityDTOList: IPaymentPriorityDTO[];
142+
referenceFormatDTOList: IReferenceFormatDTO[];
143+
instantMessagingTypeDTOList: IInstantMessagingTypeDTO[];
144+
transmissionTypeDTOList: ITransmissionTypeDTO[];
145+
einvoiceDirectPaymentprintingTypeDTOList: ITransmissionTypeDTO[];
146+
addressTypeDTOList: IAddressTypeDTO[];
147+
foreignPaymentTypeDTOList: IForeignPaymentDTO[];
148+
foreignPaymentChargeDTOList: IForeignPaymentDTO[];
149+
}
150+
151+
interface IPaymentTermDTO {
152+
paymentTermId: number;
153+
discountDates: number;
154+
discountPercent: number;
155+
netDueDate: number;
156+
defaultPaymentTerm: boolean;
157+
description: string;
158+
}
159+
160+
interface IDeliveryMethodDTO {
161+
deliveryMethodId: string;
162+
defaultDeliveryMethod: string;
163+
description: string;
164+
}
165+
166+
interface IDeliveryTermDTO {
167+
deliveryTermId: string;
168+
defaultDeliveryTerm: boolean;
169+
description: string;
170+
deliveryTermText: string;
171+
}
172+
173+
interface ICurrencyDTO {
174+
currency: string;
175+
description: string;
176+
currencyRate: number;
177+
}
178+
179+
interface ISalesPersonDTO {}
180+
181+
interface ISalesPostingGroupDTO {
182+
postingGroupId: string;
183+
description: string;
184+
cashSales: boolean;
185+
defaultPostingGroupForSales: boolean;
186+
defaultPostingGroupForPurchases: boolean;
187+
defaultPostingId: string;
188+
accountsReceivableAccount: string;
189+
defaultSk1: string;
190+
defaultSk2: string;
191+
defaultSk3: string;
192+
defaultSk4: string;
193+
}
194+
195+
interface IAccountDimensionValueDTO {
196+
dimension: string;
197+
accountId: string;
198+
finAccountDescription: string;
199+
engAccountDescription: string;
200+
sweAccountDescription: string;
201+
}
202+
203+
interface IPurchasePostingCodeDTO {
204+
accountingCode: string;
205+
accountingDescription: string;
206+
}
207+
208+
interface IPaymentPriorityDTO {
209+
id: string;
210+
description: string;
211+
}
212+
213+
interface IReferenceFormatDTO {
214+
id: string;
215+
description: string;
216+
}
217+
218+
interface IInstantMessagingTypeDTO {
219+
id: string;
220+
description: string;
221+
}
222+
223+
interface ITransmissionTypeDTO {
224+
transmissionTypeId: string;
225+
description: string;
226+
type: string;
227+
}
228+
229+
interface IAddressTypeDTO {
230+
addressType: string;
231+
description: string;
232+
}
233+
234+
interface IForeignPaymentDTO {
235+
type: string;
236+
description: string;
237+
}
238+
239+
export interface ICustomerEntityDTO {
240+
customerId: string;
241+
businessId: string;
242+
customerName: string;
243+
customerName2: string;
244+
email: string;
245+
email2: string;
246+
phoneNumber: string;
247+
phoneNumber2: string;
248+
changeTime: string;
249+
}

0 commit comments

Comments
 (0)