Skip to main content

Sub customer stock import

Introduction

This will import sub customer stock for a lease company (vehicle, contract, customer, address, driver, policy, and ancillary flags onto existing sub customers).

Important

  • Each row must identify a vehicle with at least one of VIN or registration (VRM). Rows with neither are skipped and logged.
  • Customer account number must match an existing sub customer for the lease. The importer resolves the sub customer by account number and then allocates or updates stock on that sub customer (see createSubCustomer.ts in the import-manager repo).
  • If stock for the same VIN/VRM already exists with identical data (hash match), the row is skipped and logged.

File format

Comma Separated Values - *.csv
Encoding - UTF-8

Header names are trimmed and converted to camel case for mapping (see readCSVFile in the import manager). The CLI entry point is importCustomerContract.ts under imports/lease/subCustomerStock/; it validates rows with importCustomerContract.validation.ts and calls createCustomerContract when persist is true.

download sample sub customer stock import file.

Date values

Dates are accepted either as:

  • Eight digits DDMMYYYY (for example 01092022 for 1 September 2022), or
  • Any string that parses as a valid JavaScript Date (for example ISO dates), per toFormattedDate.

Fields

Sub customer stock CSV fields

CSV column (example)DescriptionMax lengthData typeRules / notesMandatoryExample
RegistrationVehicle registration (VRM)9StringValid UK or IE registration formatYAB72YLL
VINVehicle identification number17StringAlphanumeric; whitespace strippedNABHC751CVNU294937
Registration DateFirst registration date8+DateDDMMYYYY or parseable dateY01092022
MakeVehicle make20StringAllowed character set per validationYHYUNDAI
ModelVehicle model100StringRequired; pattern per validationYIONIQ
SpecificationVariant / specification100StringOptionalN
Fuel TypeFuel type50StringOptionalNHYBRID ELECTRIC
Vehicle TypeCategory (e.g. Car, LCV)20StringRequiredYCar
CAPIDCAP identifier20StringOptionalN
Argic CodeARGIC code20StringOptionalN
ColourColour100StringOptionalN
MOT Due DateMOT due dateDateOptional; same date rules as aboveN
MaintainedMaintained flag (drives managed/maintained on vehicle)4StringRequired; alphanumeric (e.g. Y/N)YY
Contract Start DateContract startDateOptionalN12022026
Contract End DateContract endDateOptionalN12022027
Contract Mileage TermContract mileage term6Numeric stringOptionalN
Vehicle ProductVehicle product30StringOptionalN
Service ScheduleService schedule8NumberOptionalN
Warranty Parameter MonthsWarranty monthsNumberOptionalN
Warranty Parameter MileageWarranty mileageNumberOptionalN
Asset NumberAsset number20StringAlphanumericN
SMRSMR / maintenance contract flagStringOptional; letters only (A–Z); typically Y/NNY
TyresTyres contract flagStringOptional; letters only (A–Z); typically Y/NNN
GlassGlass contract flagStringOptional; letters only (A–Z); typically Y/NNN
Accident ManagementAccident management contract flagStringOptional; letters only (A–Z); typically Y/NNN
BreakdownBreakdown contract flagStringOptional; letters only (A–Z); typically Y/NNN
InsuranceInsurance contract flagStringOptional; letters only (A–Z); typically Y/NNN
RentalRental contract flagStringOptional; letters only (A–Z); typically Y/NNN
FridgeFridge fitted (ancillary equipment)StringOptional; letters only (A–Z); typically Y/NNN
Tail LiftTail lift fitted (ancillary equipment)StringOptional; letters only (A–Z); typically Y/NNN
CraneCrane fitted (ancillary equipment)StringOptional; letters only (A–Z); typically Y/NNN
Customer NameCustomer / company display name100StringRequiredYCarFinance247 Limited
Customer Account NumberSub customer account number (must exist on lease)15StringRequired; alphanumeric pattern per validationY402
VAT NumberVAT number on contract9StringOptionalN932900908
TitleTitle (e.g. salutation)50StringOptionalN
Address 1First address line (mapped to ViSN building / number)20StringOptional; allowed character set per validationN
Address 2Second address line50StringOptional; allowed character set per validationN
Address 3Third address line50StringOptional; allowed character set per validationN
Address 4Fourth address line50StringOptional; allowed character set per validationN
PostcodePostcode10StringAlphanumeric patternNM126JH
Customer NumberCustomer reference / phone etc.StringOptional; whitespace stripped from numberN
Customer EmailCustomer email50StringOptionalN
Cost CentreCost centre code10StringOptional; alphanumeric pattern per validationN
Invoice CentreInvoice centre code10StringOptional; alphanumeric pattern per validationN
Customer ContactCustomer contact details100StringOptional; allowed character set per validationN
Customer Policy NotesPolicy notes on the customer250StringOptional; pattern per validationN
Customer Recharge LimitCustomer recharge limitNumberOptionalN
Customer Referral LimitCustomer referral limitNumberOptionalN
Driver First NameDriver given name30StringOptional; letters only when providedNTest
Driver Last NameDriver family name30StringOptional; letters only when providedNTest
Driver EmailDriver email50StringOptionalN
Driver NumberDriver phone numberNumberOptionalN
Employee Start DateDriver employment startDateOptional; if omitted, mapper may default start dateN
Policy NumberPolicy reference100StringOptionalN
Policy Start DatePolicy startDateOptional; same date rules as aboveN12022026
Policy End DatePolicy endDateOptional; same date rules as aboveN12022027
Policy TermPolicy termNumberOptionalN12
Product TypePolicy product type20StringLetters only when providedNWarranty

Further columns and stricter rules are defined in importCustomerContract.validation.ts in the import-manager repo; extend this table if you add columns to the CSV.

Importing a file

Preparation

  1. Create a new branch with the Jira task number in the branch name.
  2. Place the CSV under the import-manager importFiles tree (or another path you pass to --file).
  3. Open package.json in the import-manager repo and locate validate:subCustomerStock (and import:subCustomerStock for persisted runs).
  4. Update --leaseId to the target lease company id.
  5. Update --file to the path of the CSV relative to the import-manager project root.
  6. Save package.json if you keep paths there, or pass the same flags on the command line when invoking the built script.

The CLI is compiled from src/imports/lease/subCustomerStock/importCustomerContract.ts and accepts the standard options from getImportArgumentsFromCommandLine (including --leaseId, --file, and --persist).

Validating locally

  1. In a terminal, from the import-manager repo, run npm run build.
  2. Run npm run validate:subCustomerStock.
  3. Review log output under the import file directory (see logger usage in ImportCSVFile). Fix validation errors before persisting.

Validating in workflow

  1. Go to Actions on the import-manager GitHub repository.
  2. Find <Environment> - on-demand-import (or the equivalent workflow used for other lease imports).
  3. Select the branch that contains your file path updates.
  4. Enter script name validate:subCustomerStock.
  5. Leave Overrides empty unless you need extra flags.

Importing the file (persist)

  1. After validation succeeds, use the same workflow with script name import:subCustomerStock (this runs the validate script with --persist so rows are written to the database).
  2. Alternatively, run locally: npm run import:subCustomerStock after npm run build.

Importing via Cloud Run

Cloud Run exposes POST /sub-customer-contract on the import-manager service. The default schema body field is SUB_CUSTOMER_CONTRACT when omitted (see index.ts).

Typical HTTP target (dev example; URL and bucket vary by environment):

Example scheduler body (validation, no persist)

{
"leaseId": "<leaseCompanyId>",
"leaseCompanyName": "<lease company display name>",
"persist": "false",
"bucket": "biddirect-2.appspot.com",
"appDirectory": "/usr/src/app/",
"importPath": "imports/fileDrop/",
"importFileDropPath": "imports/fileDrop/",
"importFileName": "<yourFile>.csv",
"email": "<notification email>",
"fatalErrorEmailToAddress": "<fatal error email>",
"schema": "SUB_CUSTOMER_CONTRACT"
}

Example scheduler body (import with persist)

Use the same JSON as above but set "persist": "true".

Bucket preparation

As with other import-manager CSV flows, upload the file to the environment’s bucket under the agreed drop path (for example imports/fileDrop/) and set importFileName to the object name. Bucket names differ between environments; align with your platform team.

Automated file validation (Pub/Sub)

When wiring Pub/Sub import file validation, the routine key subCustomerStockValidation maps to SubCustomerStockCSVFile in getImportRoutineSettings.ts. Use that folder or routing convention if your deployment validates files before import using the shared pub/sub handler.

Testing

After a successful persisted import, confirm in ViSN that:

  • Stock exists for the VIN/VRM on the lease.
  • The vehicle is allocated to the sub customer whose customer account number matched the row.
Status: Pending Approval
Category: Protected
Authored By: Jeyakumar Arunagiri on May 13, 2026