-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.php
322 lines (253 loc) · 10.3 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
require 'vendor/autoload.php';
session_start();
use Onetoweb\Unit4\Unit4Client;
use Onetoweb\Unit4\Token;
use Onetoweb\Unit4\Exception\RequestException;
// client parameters
$clientId = 'client_id';
$clientSecret = 'client_secret';
$redirectUrl = 'redirect_url';
$version = 22;
$sandbox = true;
// setup client
$client = new Unit4Client($clientId, $clientSecret, $redirectUrl, $version, $sandbox);
// set database
$database = 'database';
$client->setDatabase($database);
// set token callback to store token
$client->setUpdateTokenCallback(function(Token $token) {
$_SESSION['token'] = [
'accessToken' => $token->getAccessToken(),
'refreshToken' => $token->getRefreshToken(),
'expires' => $token->getExpires(),
];
});
// load token or request token to gain access to unit 4
if (!isset($_SESSION['token']) and !isset($_GET['code'])) {
// request permission with authorization link
echo '<a href="'.$client->getAuthorizationLink().'">Unit4 login</a>';
} else if (!isset($_SESSION['token']) and isset($_GET['code'])) {
// request access token
$client->requestAccessToken($_GET['code']);
} else {
// load token from storage
$token = new Token(
$_SESSION['token']['accessToken'],
$_SESSION['token']['refreshToken'],
$_SESSION['token']['expires']
);
$client->setToken($token);
}
// make unit 4 request after token is set
if ($client->getToken()) {
try {
// get administration info list
$administrationInfoList = $client->getAdministrationInfoList();
// get product info list
$productInfoList = $client->getProductInfoList();
// create product
$product = $client->createProduct([
'accountId' => '8020',
'discountAccountId' => '8020',
'productId' => '42',
'pricePer' => 3.14,
'description' => 'test product',
'shortName' => 'TEST'
]);
// get product
$productId = 'product_id';
$product = $client->getProduct($productId);
// get customer info list
$customerInfoList = $client->getCustomerInfoList();
// create customer
$customer = $client->createCustomer([
'name' => 'Customer name',
'shortName' => 'CN',
]);
// get customer
$customerId = 'customer_id';
$customer = $client->getCustomer($customerId);
// delete customer
$customerId = 'customer_id';
$client->deleteCustomer($customerId);
// create order
$customerId = 'customer_id';
$deliveryAddressId = 'delivery_address_id';
$productId = 'product_id';
$order = $client->createOrder([
'customerId' => $customerId,
'reference' => 'test order',
'orderDate' => date('d-m-Y'),
'paymentConditionId' => '1',
'deliveryAddressId' => $deliveryAddressId,
'orderLines' => [[
'productId' => $productId,
'quantityOrdered' => 1,
]],
]);
// get shipping order document command
$orderId = 'order_id';
$shippingOrderDocument = $client->getShippingOrderDocumentCommand([
'orderId' => $orderId,
'format' => 1
]);
// get open orders
$openOrders = $client->getOrderInfoListOpenOrders();
// get orders ready to print invoice
$ordersReadyToPrintInvoice = $client->getOrderInfoListOrdersReadyToPrintInvoice();
// get order
$orderId = 'order_id';
$order = $client->getOrder($orderId);
// get order state NVL
$orderStates = $client->getOrderStateNVL();
// get order type NVL
$orderTypes = $client->getOrderTypeNVL();
// get order line types
$orderLineTypes = $client->getOrderLineTypeNVL();
// process order command
$journalId = 'V';
$orderId = 'order_id';
$fiscalYear = 2020;
$periodNumber = 12;
$result = $client->processOrderCommand([
'journalId' => $journalId,
'fiscalYear' => $fiscalYear,
'periodNumber' => 12,
'invoiceDate' => date('d-m-Y'),
'orderId' => $orderId,
]);
// create address
$organizationId = 'organization_id';
$address = $client->createAddress([
'organizationId' => $organizationId,
'street1' => 'street 1',
'telephone' => '0123456789',
'zipCode' => '1000AA',
'city' => 'city',
]);
// get address list
$organizationId = 'organization_id';
$addressList = $client->getAddressList($organizationId);
// get accounts
$fiscalYear = 2020;
$accounts = $client->getAccountInfoList($fiscalYear);
// get account managers
$accountManagers = $client->getAccountManagerNVL();
// get account category
$accountCategory = $client->getAccountCategoryNVL();
// get period info list
$periodInfoList = $client->getPeriodInfoList();
// get payment condition info list
$paymentConditionInfoList = $client->getPaymentConditionInfoList();
// get document types
$documentTypes = $client->getDocumentTypeInfoList();
// get document type
$documentType = 'document_type';
$documentType = $client->getDocumentTypeInfo($documentType);
// get fiscal year info list
$fiscalYearInfoList = $client->getFiscalYearInfoList();
// get journal info list
$journalInfoList = $client->getJournalInfoList();
//get journal transaction info list
$journalId = 'V';
$fiscalYear = 2020;
$journalTransactionInfoList = $client->getJournalTransactionInfoList($journalId, $fiscalYear);
// get journal type nvl
$journalTypeNVL = $client->getJournalTypeNVL();
// create customer invoice
$customerId = 'customer_id';
$customerInvoice = $client->createCustomerInvoice([
'customerId' => $customerId,
'fiscalYear' => 2020,
'journalId' => 'V',
'journalTransaction' => 26,
'paymentConditionId' => '1',
'periodNumber' => 12,
'invoiceDate' => '2020-12-01',
]);
// get customer invoice
$invoiceId = 'invoice_id';
$invoice = $client->getCustomerInvoice($invoiceId);
// get customer invoice info list by fiscal year
$fiscalYear = 2020;
$invoiceState = 1;
$customerInvoices = $client->getCustomerInvoiceInfoListByFiscalYear($fiscalYear, $invoiceState);
// get company contact person list
$companyContactPerson = $client->getCompanyContactPersonList();
// get report template configuration list
$reportTemplateConfigurationList = $client->getReportTemplateConfigurationList();
// get report template configuration
$configurationId = 'configuration_id';
$reportTemplateConfiguration = $client->getReportTemplateConfiguration($configurationId);
// get mail message info list
$mailMessageInfoList = $client->getMailMessageInfoList();
// get mail templates
$mailTemplates = $client->getMailTemplateList();
// get document invoice by order id
$orderId = 'order_id';
$documentInvoice = $client->getDocumentInvoiceByOrderId($orderId, [
'format' => 1
]);
// get document invoice by invoice id
$documentInvoice = $client->getDocumentInvoiceByInvoiceId($invoiceId, [
'format' => 1
]);
// get document invoice by order id for web
$orderId = 'order_id';
$invoice = $client->getDocumentInvoiceByOrderIdForWeb($orderId, [
'format' => 1,
]);
// get document invoice for web
$invoiceId = 'invoice_id';
$invoice = $client->getDocumentInvoiceForWeb($orderId, [
'format' => 1,
]);
// get next journal transaction command
$fiscalYear = 2020;
$journalId = 'K';
$journalTransaction = $client->getNextJournalTransactionCommand([
'fiscalYear' => $fiscalYear,
'journalId' => $journalId,
]);
// create fin trans
$invoiceId = 'invoice_id';
$customerId = 'customer_id';
$periodNumber = 1;
$finTrans = $client->createFinTrans([
'journalId' => $journalId,
'fiscalYear' => $fiscalYear,
'periodNumber' => $periodNumber,
'journalTransaction' => $journalTransaction,
'transactionDate' => date('d-m-Y'),
'description' => 'description',
'finTransEntries' => [[
'$type' => 'UNIT4.Multivers.API.BL.Financial.Edit.CustomerEntryProxy, UNIT4.Multivers.API.Web.WebApi.Model',
'customerEntryPayments' => [[
'amountPaidCur' => 100,
'description' => 'invoice '.$invoiceId,
'invoiceId' => $invoiceId
]],
'customerId' => $customerId,
'transactionDate' => date('d-m-Y'),
]],
]);
// get fin trans
$fiscalYear = 2020;
$journalId = 'K';
$journalTransaction = 'journal_transaction';
$finTrans = $client->getFinTrans($fiscalYear, $journalId, $journalTransaction);
// get company details
$companyDetails = $client->getCompanyDetails();
// approve invoice payment command
$invoiceId = 'invoice_id';
$approverId = 'approver_id';
$result = $client->approveInvoicePaymentCommand([
'invoiceId' => $invoiceId,
'approverId' => $approverId,
]);
} catch (RequestException $requestException) {
// get json error message
$errors = json_decode($requestException->getMessage());
}
}