class ChartOfAccountController {

	@PostMapping("/_update")
	@ResponseStatus(HttpStatus.CREATED)
	public ChartOfAccountResponse update(@RequestBody ChartOfAccountRequest chartOfAccountRequest,
			BindingResult errors,@RequestParam String tenantId) {

		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}
		chartOfAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE);
		ModelMapper model = new ModelMapper();
		ChartOfAccountResponse chartOfAccountResponse = new ChartOfAccountResponse();
		List<ChartOfAccount> chartofaccounts = new ArrayList<>();
		chartOfAccountResponse.setResponseInfo(getResponseInfo(chartOfAccountRequest.getRequestInfo()));
		ChartOfAccount chartOfAccount;
		ChartOfAccountContract contract;
		List<ChartOfAccountContract> chartOfAccountContracts = new ArrayList<>();

		for (ChartOfAccountContract chartOfAccountContract : chartOfAccountRequest.getChartOfAccounts()) {
			chartOfAccount = new ChartOfAccount();
			model.map(chartOfAccountContract, chartOfAccount);
			chartOfAccount.setLastModifiedBy(chartOfAccountRequest.getRequestInfo().getUserInfo());
			chartOfAccount.setLastModifiedDate(new Date());
			chartofaccounts.add(chartOfAccount);
		}

		chartofaccounts = chartOfAccountService.update(chartofaccounts, errors);

		for (ChartOfAccount chartOfAccountObj : chartofaccounts) {
			contract = new ChartOfAccountContract();
			model.map(chartOfAccountObj, contract);
			chartOfAccountObj.setLastModifiedDate(new Date());
			chartOfAccountContracts.add(contract);
		}

		chartOfAccountRequest.setChartOfAccounts(chartOfAccountContracts);
		chartOfAccountService.addToQue(chartOfAccountRequest);
		chartOfAccountResponse.setChartOfAccounts(chartOfAccountContracts);

		return chartOfAccountResponse;
	}

}