# Ventas

## Listar ventas

<mark style="color:blue;">`GET`</mark> `https://demo.simplefact.pe/v1/sales/orders`

Obtiene las ventas realizadas con el comprobante asociado, por rango de fecha.

#### Query Parameters

| Name      | Type   | Description                                                                                                                      |
| --------- | ------ | -------------------------------------------------------------------------------------------------------------------------------- |
| shortdate | string | Filtrar por rango de fecha predeterminado ejemplo: `today` : ventas de hoy`yesterday` : ventas de ayer, `month` `past_month ...` |
| to        | string | <p>Rango fecha de fin<br></p>                                                                                                    |
| pageSize  | number | Numero de resultados a mostrar, valor por defecto `10`.                                                                          |
| from      | string | <p>Rango fecha de inicio<br></p>                                                                                                 |

#### Headers

| Name           | Type   | Description                                                                                                                          |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| Authentication | string | <p>Authentication token para acceder al recurso, el token es proporcionado por SimpleFact.<br>Ejemplo: <code>Bearer Token</code></p> |

{% tabs %}
{% tab title="200 Response Success" %}

```javascript
{
   "data":[
      {
         "id":409,
         "invoice_type_name":"Factura de Venta Electr\u00f3nica",
         "invoice_type":"01",
         "invoice_type_name_short":"F",
         "serie":"F001",
         "correlative":"141",
         "customer_name":"ACR TECHNOLGIES SAC",
         "status":"processing",
         "tax_total":"6101.69",
         "total":"40000.00",
         "date":"2020-05-06T23:27:59.000000Z",
         "date_formatted":"06\/05\/2020 18:27",
         "due_date":"-",
         "currency":"PEN",
         "currency_symbol":"S\/",
         "xml_url":"https:\/\/demo.simplefact.pe\/app\/download\/invoices\/20601643316-01-F001-141.xml",
         "pdf_url":"https:\/\/demo.simplefact.pe\/app\/download\/invoices\/20601643316-01-F001-141.pdf",
         "bill":{
            "id":276,
            "created_at":"2020-05-06 18:28:00",
            "accepted_at":"2020-05-06 18:28:00",
            "error":null,
            "message":"La Factura numero F001-141, ha sido aceptada",
            "order_id":409,
            "cdr_url":"https:\/\/demo.simplefact.pe\/app\/download\/invoices\/R-20601643316-01-F001-141.zip",
            "status":"accepted"
         },
         "void":null,
         "notes":null,
         "customer":{
            "id":2,
            "name":"ACR TECHNOLGIES SAC",
            "email":"acr@gmail.com",
            "phone":null,
            "status":"active",
            "is_company":false
         },
         "items": [],
         "origin":"api",
         "payment_method":"cash",
         "payment_status":"paid",
         "created_at_formatted":"06\/05\/2020 18:27"
      }
   ],
   "links":{
      "first":"https:\/\/demo.simplefact.pe\/api\/v1\/sales\/orders?page=1",
      "last":"https:\/\/demo.simplefact.pe\/api\/v1\/sales\/orders?page=237",
      "prev":null,
      "next":"https:\/\/demo.simplefact.pe\/api\/v1\/sales\/orders?page=2"
   },
   "meta":{
      "current_page":1,
      "from":1,
      "last_page":237,
      "path":"https:\/\/demo.simplefact.pe\/api\/v1\/sales\/orders",
      "per_page":"1",
      "to":1,
      "total":237
   }
}
```

{% endtab %}
{% endtabs %}

## Detalle de una venta

<mark style="color:blue;">`GET`</mark> `https://demo.simplefact.pe/v1/sales/orders/:id`

Muestra información de una venta y comprobante

#### Path Parameters

| Name | Type   | Description    |
| ---- | ------ | -------------- |
| id   | string | ID de la venta |

#### Headers

| Name          | Type   | Description  |
| ------------- | ------ | ------------ |
| Authorization | string | Bearer token |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "success": true,
    "data": {
        "id": 407,
        "invoice_type": "03",
        "invoice_type_name": "Boleta de Venta Electr\u00f3nica",
        "invoice_number": "B001-97",
        "serie": "B001",
        "correlative": "97",
        "customer": {
           
        },
        "customer_name": "Juan Perez",
        "customer_document_type": "1",
        "customer_document_number": "00000000",
        "customer_document": "DNI",
        "status": "processing",
        "tax_total": "98.24",
        "total": "644.00",
        "date": "2020-04-30T23:14:15.000000Z",
        "date_formatted": "30\/04\/2020 18:14 PM",
        "due_date": "30\/04\/2020",
        "currency": "PEN",
        "currency_symbol": "S\/",
        "items": [
            {
                "id": 2200,
                "order_id": 407,
                "product_id": 2,
                "code": "A001",
                "unity": "NIU",
                "name": "iPhone X",
                "tax_apply_code": "10",
                "qty": "1.00",
                "unit_amount_cost": "33.05",
                "has_discount": 0,
                "discount_base": "0.00",
                "discount_percent": "0.00",
                "discount_amount": "0.00",
                "amount_cost": "33.05",
                "base_amount": "33.05",
                "tax_percent": "18.00",
                "tax": "5.95",
                "tax_total": "5.95",
                "unit_amount_price": "39.00"
            },
            {
                "id": 2201,
                "order_id": 407,
                "product_id": 3,
                "code": "P001",
                "unity": "NIU",
                "name": "Televisor Samsung 20",
                "tax_apply_code": "10",
                "qty": "1.00",
                "unit_amount_cost": "29.66",
                "has_discount": 0,
                "discount_base": "0.00",
                "discount_percent": "0.00",
                "discount_amount": "0.00",
                "amount_cost": "29.66",
                "base_amount": "29.66",
                "tax_percent": "18.00",
                "tax": "5.34",
                "tax_total": "5.34",
                "unit_amount_price": "35.00"
            },
           
        ],
        "xml_url": "https:\/\/demo.simplefact.pe\/cdn\/ZXlKcGRpSTZJamRsZVVkelVHWkJhRElyZUZOSWNsZHZWSGhOYlVFOVBTSXNJblpoYkhWbElqb2ljSGhtUkdSMFNVcG9SRWRQTVd0Mk9FWTVkMVpDY3pGNGFYZFZkREZyUW5jNWIzQm5kRlZOYTFSeGVXaERUREo1YmtSNlp6bGxaR2gwZUdVM2FFcDVTU0lzSW0xaFl5STZJak0zTURRelpUWTBPV0UxWm1RM1ptRTJOVGRrWVRJM1pERmlaakU1T1RWaE5XSTJZbUprTTJVNE56ZGpNVFV5WW1abVpqVXlOelk1TnpGbE1qRXlZV1lpZlE9PQ==",
        "pdf_url": "https:\/\/demo.simplefact.pe\/cdn\/ZXlKcGRpSTZJalpIVVVsdFFsbE5kVEp3VGxCcU5YRkdXV05zYVVFOVBTSXNJblpoYkhWbElqb2liME5vTkhVMVVuWTBSMGRSVUNzNFlWSnZRVWxpYUhoR2MwTjZNalZ4Um1OelJGTldVRU5rTVROVlZIWm9NazkzZURkUVNtWkNObUl4Y0c0elVVTmtSeUlzSW0xaFl5STZJbVEzWm1ZNFpUVmtaak5pTWpka01qbG1ZVEV6TVRBMVpUZGxaV0ppTUdNeU4yWXpZV1kzT1dKbU1qUTNPRFE1TmpNNVpXWmlNVEl5TnpBeVl6ZGtaRElpZlE9PQ==",
        "pdf_url_show": false,
        "taxed_operation": "545.76",
        "unaffected_operation": "0.00",
        "exonerated_operation": "0.00",
        "free_operation": "0.00",
        "total_discount": "0.00",
        "notes": null,
        "origin": "api",
        "address": {
            "shipping": [],
            "billing": []
        },
        "metadata": null,
        "document_type_name": "DNI",
        "payment_method": "cash",
        "payment_status": "paid",
        "bill": {
            "id": 275,
            "order_id": 407,
            "xml_path": "invoices\/20601643316-03-B001-97.xml",
            "cdr_path": null,
            "pdf_path": "invoices\/20601643316-03-B001-97.pdf",
            "status": "pending",
            "error": null,
            "message": "Listo para enviar en el Resumen Diario de Boletas",
            "accepted_at": null,
            "created_at": "2020-04-30 18:14:16",
            "updated_at": "2020-04-30 18:14:16",
            "ticket": null
        },
        "transporter": null
    }
}
```

{% endtab %}
{% endtabs %}

## Anular una venta

<mark style="color:green;">`POST`</mark> `https://demo.simplefact.pe/v1/sales/orders/:id/cancel`

Anula la venta en SimpleFact® y anula comprobante de pago por SUNAT mediante el método baja de comprobante.

#### Path Parameters

| Name | Type   | Description    |
| ---- | ------ | -------------- |
| id   | number | Id de la venta |

#### Headers

| Name          | Type   | Description  |
| ------------- | ------ | ------------ |
| Authorization | string | Bearer token |

#### Request Body

| Name   | Type   | Description         |
| ------ | ------ | ------------------- |
| reason | string | Motivo de anulación |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "success": true, 
    "message": "Anulado correctamente",
    "data": {} //Order Resource
    
}
```

{% endtab %}
{% endtabs %}

## Crear una venta (Factura y Boleta, Nota de venta)

<mark style="color:green;">`POST`</mark> `https://demo.simplefact.pe/v1/sales/orders`

Este método permite realizar un venta con un comprobante electrónico ya sea boleta o factura.

#### Request Body

| Name                       | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| items                      | array   | <p><mark style="color:green;"><code>\[</code></mark></p><p> <mark style="color:green;"><code>{</code></mark> </p><p><mark style="color:green;"><code>"code": "SKU-411",</code></mark></p><p><mark style="color:green;"><code>"name": "FUNDA PARA IPHONE 13",</code></mark> </p><p><mark style="color:green;"><code>"qty": 2,</code></mark> </p><p><mark style="color:green;"><code>"price": 200, "tax\_percent": 18 }</code></mark> </p><p><mark style="color:green;"><code>]</code></mark></p> |
| currency                   | string  | Moneda por defecto `PEN`                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| total                      | number  | Total incluido impuestos                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| discount                   | number  | Descuento                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| tax\_total                 | number  | Total impuestos                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| subtotal                   | number  | Subtotal sin impuestos                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| due\_date                  | string  | Fecha de vencimiento                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| date                       | string  | Fecha de emisión del comprobante en formato ISO                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| invoice\_type              | string  | 01 Factura , 03 Boleta, nv = Nota de venta                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| customer\_address          | string  | Dirección del cliente                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| customer\_document\_number | string  | Numero de documento                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| customer\_document\_type   | number  | Tipo de documento 6: RUC 1: DNI                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| customer\_name             | string  | Nombre del cliente o razón social                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| notes                      | string  | Notas u observaciones                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| email\_send                | boolean | Especifica si se enviara un correo al cliente de forma automática con la factura en PDF y XML.                                                                                                                                                                                                                                                                                                                                                                                                  |
| customer\_email            | string  | Email del cliente                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| customer\_phone            | String  | Celular del cliente                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

{% tabs %}
{% tab title="200 Response Order Resource" %}

```javascript
{
    "success": true,
    "data": {
        "id": 407,
        "invoice_type": "03",
        "invoice_type_name": "Boleta de Venta Electr\u00f3nica",
        "invoice_number": "B001-97",
        "serie": "B001",
        "correlative": "97",
        "customer": {
           
        },
        "customer_name": "Juan Perez",
        "customer_document_type": "1",
        "customer_document_number": "00000000",
        "customer_document": "DNI",
        "status": "processing",
        "tax_total": "98.24",
        "total": "644.00",
        "date": "2020-04-30T23:14:15.000000Z",
        "date_formatted": "30\/04\/2020 18:14 PM",
        "due_date": "30\/04\/2020",
        "currency": "PEN",
        "currency_symbol": "S\/",
        "items": [
            {
                "id": 2200,
                "order_id": 407,
                "product_id": 2,
                "code": "A001",
                "unity": "NIU",
                "name": "Producto 1",
                "tax_apply_code": "10",
                "qty": "1.00",
                "unit_amount_cost": "33.05",
                "has_discount": 0,
                "discount_base": "0.00",
                "discount_percent": "0.00",
                "discount_amount": "0.00",
                "amount_cost": "33.05",
                "base_amount": "33.05",
                "tax_percent": "18.00",
                "tax": "5.95",
                "tax_total": "5.95",
                "unit_amount_price": "39.00"
            },

            {
                "id": 2204,
                "order_id": 407,
                "product_id": 34,
                "code": "E001",
                "unity": "ZZ",
                "name": "Producto 2",
                "tax_apply_code": "10",
                "qty": "1.00",
                "unit_amount_cost": "4.24",
                "has_discount": 0,
                "discount_base": "0.00",
                "discount_percent": "0.00",
                "discount_amount": "0.00",
                "amount_cost": "4.24",
                "base_amount": "4.24",
                "tax_percent": "18.00",
                "tax": "0.76",
                "tax_total": "0.76",
                "unit_amount_price": "5.00"
            }
        ],
        "xml_url": "https:\/\/demo.simplefact.pe\/cdn\/ZXlKcGRpSTZJamRselVHWkJhRElyZUZOSWNsZHZWSGhOYlVFOVBTSXNJblpoYkhWbElqb2ljSGhtUkdSMFNVcG9SRWRQTVd0Mk9FWTVkMVpDY3pGNGFYZFZkREZyUW5jNWIzQm5kRlZOYTFSeGVXaERUREo1YmtSNlp6bGxaR2gwZUdVM2FFcDVTU0lzSW0xaFl5STZJak0zTURRelpUWTBPV0UxWm1RM1ptRTJOVGRrWVRJM1pERmlaakU1T1RWaE5XSTJZbUprTTJVNE56ZGpNVFV5WW1abVpqVXlOelk1TnpGbE1qRXlZV1lpZlE9PQ==",
        "pdf_url": "https:\/\/demo.simplefact.pe\/cdn\/ZXlKcGRpE5kVEp3VGxCcU5YRkdXV05zYVVFOVBTSXNJblpoYkhWbElqb2liME5vTkhVMVVuWTBSMGRSVUNzNFlWSnZRVWxpYUhoR2MwTjZNalZ4Um1OelJGTldVRU5rTVROVlZIWm9NazkzZURkUVNtWkNObUl4Y0c0elVVTmtSeUlzSW0xaFl5STZJbVEzWm1ZNFpUVmtaak5pTWpka01qbG1ZVEV6TVRBMVpUZGxaV0ppTUdNeU4yWXpZV1kzT1dKbU1qUTNPRFE1TmpNNVpXWmlNVEl5TnpBeVl6ZGtaRElpZlE9PQ==",
        "pdf_url_show": false,
        "taxed_operation": "545.76",
        "unaffected_operation": "0.00",
        "exonerated_operation": "0.00",
        "free_operation": "0.00",
        "total_discount": "0.00",
        "notes": null,
        "origin": "api",
        "address": {
            "shipping": [],
            "billing": []
        },
        "metadata": null,
        "document_type_name": "DNI",
        "payment_method": "cash",
        "payment_status": "paid",
        "bill": {
            "id": 275,
            "order_id": 407,
            "xml_path": "invoices\/20601643316-03-B001-97.xml",
            "cdr_path": null,
            "pdf_path": "invoices\/20601643316-03-B001-97.pdf",
            "status": "success",
            "error": null,
            "message": "Enviado a SUNAT",
            "accepted_at": null,
            "created_at": "2020-04-30 18:14:16",
            "updated_at": "2020-04-30 18:14:16",
            "ticket": null
        },
        "transporter": null
    }
}
```

{% endtab %}
{% endtabs %}

## Actualizar Stock

<mark style="color:purple;">`PATCH`</mark> `https://demo.simplefact.pe/v1/sales/orders/id/stock`

#### Path Parameters

| Name | Type   | Description     |
| ---- | ------ | --------------- |
| id   | number | ID del producto |

#### Request Body

| Name   | Type   | Description                     |
| ------ | ------ | ------------------------------- |
| reason | string | Descripción de la operación     |
| qty    | number | Cantidad en negativo o positivo |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}


---

# 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.simplefact.pe/api/sales.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.
