How to create and update a batch
You need to perform the following GraphQL requests, in this order:
1. Determining the next voucher no
When creating a voucher, you need to provide a voucher number. You can determine this value by reading the nextVoucherNo
value from the VoucherSeries
table. To do so, you must provide the voucherSeriesNo
which should be the same used for creating the batch.
query read_voucher_series($cid : Int!,
$vsn : Int!)
{
useCompany(no : $cid)
{
voucherSeries(filter :
{
voucherSeriesNo : {_eq: $vsn}
}
)
{
totalCount
items
{
voucherSeriesNo
name
lastVoucherNo
nextVoucherNo
}
}
}
}
{
"data": {
"useCompany": {
"voucherSeries": {
"totalCount": 1,
"items": [
{
"voucherSeriesNo": 6,
"name": "Diverse bilag",
"lastVoucherNo": 69999,
"nextVoucherNo": 60003
}
]
}
}
}
}
2. Creating a new batch and voucher
The minimum information you need to provide for creating the batch is:
Field | Type | Description |
---|---|---|
valueDate |
int | The value date as an integer in the form yyyymmdd . For instance, 23 March 2022, is 20220323. |
voucherSeriesNo |
int | The number of the voucher series. |
The minimum information you need to provide in order to create a new voucher is:
Field | Type | Description |
---|---|---|
voucherNo |
int | The number of the voucher. Use the nextVoucherNo value read previously. |
debitAccountNo |
int | The debit account number. |
creditAccountNo |
int | The credit account number. |
amountDomestic |
decimal | The amount value. |
voucherDate |
int | The date of the voucher. |
valueDate |
int | The value date of the voucher. |
mutation create_batch_and_voucher($cid : Int!,
$cno : Int!,
$vno : Int!,
$vdt : Int!,
$valuedt : Int!)
{
useCompany(no : $cid)
{
batch_create(values:[
{
valueDate : $valuedt
vouchers : [
{
voucherNo : $vno
debitAccountNo : 1930
creditAccountNo : $cno
customerNo : $cno
amountDomestic : 100
voucherDate : $vdt
valueDate : $valuedt
}
]
}])
{
affectedRows
items
{
batchNo
valueDate
vouchers : joindown_Voucher_via_Batch
{
items
{
batchNo
lineNo
voucherNo
customerNo
debitAccountNo
creditAccountNo
amountDomestic
voucherDate
valueDate
}
}
}
}
}
}
{
"data": {
"useCompany": {
"batch_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"valueDate": 20251015
"vouchers": {
"items": [
{
"batchNo": 1002,
"lineNo": 1,
"voucherNo": 60003,
"customerNo": 10001,
"debitAccountNo": 1930,
"creditAccountNo": 10001,
"amountDomestic": 100,
"voucherDate": 20250917,
"valueDate": 20251015
}
]
}
}
]
}
}
}
}
Alternatives for creating a batch and voucher
The obsolete way of creating a batch and vouchers is to do it in two separate requests. First, you create the batch, and then you add the vouchers.
1. Two separate requests
Use a mutation with the batch_create
field to create a new batch:
mutation create_batch($cid : Int!,
$vsn : Int!,
$valuedt : Int!)
{
useCompany(no : $cid)
{
batch_create(values:[
{
voucherSeriesNo : $vsn
valueDate : $valuedt
}
])
{
affectedRows
items
{
batchNo
valueDate
}
}
}
}
{
"data": {
"useCompany": {
"batch_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"valueDate": 20220415
}
]
}
}
}
}
You must read and store the batchNo
in order to use it for creating a voucher. Then, use a mutation with the voucher_create
field to create a new voucher:
mutation create_voucher($cid : Int!,
$bno : Int!,
$cno : Int!,
$vno : Int!,
$vdt : Int!,
$valuedt : Int!)
{
useCompany(no : $cid)
{
voucher_create(values: [
{
batchNo : $bno
voucherNo : $vno
debitAccountNo : 1930
creditAccountNo: $cno
amountDomestic : 100
voucherDate : $vdt
valueDate : $valuedt
}
])
{
affectedRows
items
{
batchNo
voucherNo
voucherDate
valueDate
}
}
}
}
{
"data": {
"useCompany": {
"voucher_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"voucherNo": 60003,
"voucherDate": 20220323,
"valueDate": 20220415
}
]
}
}
}
}
2. One request using the @export directive
This is possible using the @export directive.
mutation create_batch($cid : Int!,
$vsn : Int!,
$valuedt : Int!,
$cno : Int!,
$bno : Int! = 0)
{
useCompany(no : $cid)
{
batch_create(values:[
{
voucherSeriesNo : $vsn
valueDate : $valuedt
}]
)
{
affectedRows
items
{
batchNo @export(as: "bno")
valueDate
}
}
voucher_create(values: [
{
batchNo : $bno
voucherNo : null
debitAccountNo : 1930
creditAccountNo: $cno
amountDomestic : 100
voucherDate : null
valueDate : $valuedt
}
])
{
affectedRows
items
{
batchNo
voucherNo
voucherDate
valueDate
}
}
}
}
{
"data": {
"useCompany": {
"batch_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"valueDate": 20220415
}
]
},
"voucher_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"voucherNo": 60003,
"voucherDate": 20220323,
"valueDate": 20220415
}
]
}
}
}
}
Create a new voucher with suggested voucher number
Instead of determining the next voucher number in the series you can request that the system figures out the next value for it. You can also do that for other fields, such as voucher date. This is done with the Suggest Feature.
mutation create_voucher($cid : Int!,
$bno : Int!,
$cno : Int!,
$valuedt : Int!)
{
useCompany(no : $cid)
{
voucher_create(values: [
{
batchNo : $bno
voucherNo : null
debitAccountNo : 1930
creditAccountNo: $cno
amountDomestic : 100
voucherDate : null
valueDate : $valuedt
}
])
{
affectedRows
items
{
batchNo
voucherNo
voucherDate
valueDate
}
}
}
}
{
"data": {
"useCompany": {
"voucher_create": {
"affectedRows": 1,
"items": [
{
"batchNo": 1002,
"voucherNo": 60003,
"voucherDate": 20220323,
"valueDate": 20220415
}
]
}
}
}
}
3. Updating a batch
The minimum information to update a batch is the batch number.
Use a mutation with the batch_processings
field to execute processings on the batch table. Use the updateBatch
field to update the batch:
mutation update_batch($cid : Int!,
$bno : Int!)
{
useCompany(no : $cid)
{
batch_processings
{
updateBatch(filter :
{
batchNo : {_eq : $bno}
}
)
{
succeeded
voucherJournalNo
}
}
}
}
{
"data": {
"useCompany": {
"batch_processings": {
"updateBatch": {
"succeeded": true,
"voucherJournalNo": 193
}
}
}
}