# Local pricing logic

## Preparations

### Install `git`

Git will be used to download example quote code we'll need.

There are multiple ways to install `git`. But for MAC the easiest one is to install `Xcode` that comes with `git`. To do that, just open `Terminal` application and type (or copy/pase) following command and hit `enter` key:

```sh
git --version
```

It will prompt you to install `Xcode` if you don't have it already.

> More ways to install are described at [getting started with git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) guide.

### Install `node`

`node` can be installed with installer that can be downloaded at <https://nodejs.org/en/download>

To make sure that `node` is installed, type following command in `Terminal`:

```sh
node --version
```

It should show something like `v14.15.4` (depending on the version you downloaded).

### Install `Postman`

`Postman` is application that can be used to trigger API requests. In this case we will trigger requests to our local quote server.

Application can be downloaded and installed from <https://www.postman.com/downloads>

## Setting up local environment

Once required software is installed, we can now setup kasko-quote-example.

### Clone repository from github

We'll need to download kasko-quote-example code. We can do this via `git`.

Just type in following command in `Terminal` and hit `enter` key:

```sh
git clone https://github.com/kasko/kasko-quote-example.git
```

This should create new directory called [`kasko-quote-example`](https://github.com/kasko/kasko-quote-example) with some of required files in it.

### Install required modules

Now that we have source code cloned, we need to install required modules.

Let's navigate into that directory by running this command:

```sh
cd kasko-quote-example
```

and then run:

```sh
npm install
```

Now everything should be ready.

## Updating xlsx files

Everything should now be set for you to update xlsx file.

To open current folder in `Finder` type following command in `Terminal` and hit `enter` key:

```sh
open .
```

This will open `Finder` in directory where `kasko-quote-example` was created.

Excel file is located in `kasko-quote-example/excel/` folder. The name of the file should stay as is. In case you really need to change the name of the file, open `kasko-quote-example/src/index.ts` file in text editor, rename file in path in 4. line and save that file.

## Running local quote server

### Starting

To run local quote server type this command in `Terminal` from `kasko-quote-example` directory:

```sh
npm run start
```

This will run local server and should show something similar to this in `Terminal`:

![server started](/files/UOVdAX7f63SDYQ1H9twX)

This means server is up and running.

If for some reason server crashes, just run start command again.

> NOTE: You don't have to restart server whenever you change xlsx file in Excel, it will automatically be reloaded.

If you encounter error that looks similar to this:

![server errored](/files/7QvkONPQ8jLuXGOoChC5)

It means server crashed because it couldn't find `/excel/kasko-demo.xlsx` file. Make sure file is there and start server again.

### Stopping

To stop server that is running, simply close `Terminal` or hit `control+c` in `Terminal` where server is already running.

## Testing input/output data

Here we gonna use postman to send and receive data to and from local quote server.

Start up `Postman` application.

![Postman screenshot](/files/mitYofsFTmOO7i68jhMC)

* Set request address (blue) to `http://localhost:3001/quotes`;
* Set up 4 fields marked as green to be the same as in screenshot above;

Red square marks "input" data (as [JSON](https://www.json.org/json-en.html)) that will be sent to quote.

Example JSON input:

```json
{
  "data": {
    "duration": "P1Y",
    "partner_coverage": false,
    "main_module": "second"
  }
}
```

Every input field that should go into xlsx calculator goes under `"data"` object.

And response is displayed below red square when `Send` button is pressed. Whenever you change input data and want to see the response, click `Send` button in upper right corner.

### Changing config options

If you want to test with custom tax or other config options that goes into xlsx calculator, you can edit these fields by opening `/config.json` file in `kasko-quote-example` and changing options.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kasko.io/kasko-frontend-documentation/guides/local-pricing-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
