How to create and update a batch

Guide on creating and updating a batch using GraphQL. Includes steps for batch creation, determining voucher number, voucher creation, and batch update.

You need to perform the following GraphQL requests, in this order:

1. Creating a new batch

The minimum information you need to provide 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.

Use a mutation with the batch_create field to create a new batch:

Query

mutation create_batch($cid : Int!,
                      $vsn : Int!,
                      $valuedt : Int!)
{
   useCompany(no : $cid)
   {
      batch_create(values:[
         {
            voucherSeriesNo : $vsn
            valueDate : $valuedt
         }
      ])
      {
         affectedRows
         items
         {
            batchNo
            valueDate
         }
      }
   }
}
Result

{
  "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.

2. 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

query read_voucher_series($cid : Int!,
                          $vsn : Int!)
{
   useCompany(no : $cid)
   {
      voucherSeries(filter :
         {
            voucherSeriesNo : {_eq: $vsn}
         }
      )
      {
         totalCount
         items
         {
            voucherSeriesNo
            name
            lastVoucherNo
            nextVoucherNo
         }
      }
   }
}
Result

{
  "data": {
    "useCompany": {
      "voucherSeries": {
        "totalCount": 1,
        "items": [
          {
            "voucherSeriesNo": 6,
            "name": "Diverse bilag",
            "lastVoucherNo": 69999,
            "nextVoucherNo": 60003
          }
        ]
      }
    }
  }
}

3. Creating a new voucher

The minimum information you need to provide in order to create a new voucher is:

Field Type Description
batchNo int The number of the batch. Use the batchNo returned from the first mutation.
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.

Use a mutation with the voucher_create field to create a new voucher:

Query

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
         }
      }
}
}
Result

{
  "data": {
    "useCompany": {
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}

Alternative: 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.

Query

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
         }
      }
   }
}
Result

{
  "data": {
    "useCompany": {
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}

Alternative: Create the batch and the voucher in a single request

This is possible using the @export directive.

Query

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
         }
      }
   }
}
Result

{
  "data": {
    "useCompany": {
      "batch_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "valueDate": 20220415
          }
        ]
      },
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}

4. 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:

Query

mutation update_batch($cid : Int!,
                      $bno : Int!)
{
   useCompany(no : $cid)
   {
      batch_processings
      {
         updateBatch(filter :
           {
             batchNo : {_eq : $bno}
           }
         )
         {
            succeeded
            voucherJournalNo
         }
      }
   }
}
Result

{
  "data": {
    "useCompany": {
      "batch_processings": {
        "updateBatch": {
          "succeeded": true,
          "voucherJournalNo": 193
        }
      }
    }
  }
Last modified September 24, 2024