> For the complete documentation index, see [llms.txt](https://kb.logicerp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-challan.md).

# Cancel a Sale Challan

Cancels a **sale challan** (delivery challan) that is already saved in Logic ERP. The challan is not removed: it stays **marked as cancelled**, its number stays used, and what it had put in place is **reversed** — the stock comes back, sale-order quantities become pending again, its accounting entries (if the challan was posted in accounts) are removed, and loyalty points, discount coupons and gift vouchers linked to it are released. You point to the challan by its **series and number**, by your **party order number**, or by Logic ERP's internal number. A cancel cannot be undone.

### **Endpoint**

| Name          | Detail                                      |
| ------------- | ------------------------------------------- |
| Address       | `https://your-server/api/CancelSaleChallan` |
| Method        | `POST`                                      |
| Authorization | Basic Auth                                  |

The response and the common messages are explained in [How Every API Call Works](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/how-every-api-call-works.md).

This endpoint has its own licence, separate from [Cancel a Sale Invoice](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-invoice.md). Send one challan per request. Field names are matched without regard to upper/lower case; fields not listed below are ignored.

### **Request fields**

| Field           | Type   | Required              | Default | Meaning                                                                                                                                                                                                                                                                                    |
| --------------- | ------ | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Branch_Code`   | number | **Yes** (in practice) | `0`     | The branch the challan belongs to (`Branch_Code` in [Get Branch Info](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/masters/pull/get-branch-info.md)). The challan is looked for in this branch only. A branch short name is not accepted. |
| `DocCode`       | number | One of the three ways | `0`     | Logic ERP's internal number of the challan – the `LastSavedCode` you received when you saved it. When it is above `0`, `BillSeries`, `Bill_No` and `PartyOrderNo` are not used.                                                                                                            |
| `BillSeries`    | text   | One of the three ways | empty   | The challan series as shown in Logic ERP. It must be a **sale challan** series of the branch – a challan **return** series is not accepted here. Use it with `Bill_No`.                                                                                                                    |
| `Bill_No`       | number | With `BillSeries`     | `0`     | The challan number within the series. A number only.                                                                                                                                                                                                                                       |
| `PartyOrderNo`  | text   | One of the three ways | empty   | The party order number saved on the challan. Used when `DocCode` is `0` and the challan was not found by series and number.                                                                                                                                                                |
| `Cancel_Reason` | text   | **Yes**               | –       | Why the challan is cancelled. Stored with the cancellation, together with the Logic ERP user, date and time.                                                                                                                                                                               |
| `DisplayError`  | text   | No                    | `"0"`   | `"1"` = when the cancel fails, `Message` carries the full technical detail.                                                                                                                                                                                                                |

### **Rules Logic ERP applies**

**Finding the challan**

* The challan must belong to the branch in `Branch_Code`. Challans of **any financial year** are found.
* With `DocCode` above `0`, the document with that internal number is used. Otherwise `BillSeries` + `Bill_No` are tried first, then `PartyOrderNo`, which must match exactly one challan or challan return of the branch.
* You must send at least `DocCode`, or `BillSeries` with `Bill_No`, or `PartyOrderNo`.

> **Known issue – challan returns are not excluded.** `DocCode` and the `PartyOrderNo` search look at sale challans and challan returns together. If the number belongs to a **sale challan return** of the same branch, that return is cancelled. Use `BillSeries` and `Bill_No`, or send only the `LastSavedCode` of a sale challan.

**What blocks a cancel**

Nothing is changed when any of these applies:

* The challan is **already cancelled**, or `Cancel_Reason` is empty.
* For a challan **posted in accounts**: it has been **billed** (taken into a sale invoice), or **advances** have been received against it.
* It has been **marked as posted** in Logic ERP's document posting.
* It was transferred to head office or imported from another branch, when the user rights of your API user stop changes to such documents.
* The challan date is in a **locked period**, on or before the **lock date** for modifications, or on or before the last **physical stock entry** date (when that lock is switched on).
* It has been **approved**, when approved documents may not be changed; or it was changed by someone else while the cancel was running.
* Cancelling would make the stock of a lot negative, when negative stock is not allowed.

**What a cancel does**

All of the following happen together, or none of them:

* The challan and its lines are **marked as cancelled** and kept. Its number is **not** freed.
* **Stock** of every line comes back, unless the challan was saved not to affect stock.
* Quantities taken from **sale orders** and **delivery orders** become **pending** again.
* If the challan was **posted in accounts**, its accounting entries are removed, and the advance entry made for it is reversed.
* **Loyalty points** of the challan are removed, **discount coupons** used on it are released, and **gift vouchers** linked to it are unlinked from it.
* Scheme records, alteration details and remarks of the challan are removed; the reason, user, date and time are recorded, and an audit-trail entry is written.

There is no endpoint that un-cancels a challan, and a cancelled challan cannot be cancelled again.

> **Known issue – the reason is sometimes missing from `Message`.** Some refusals come back as *The operation was canceled.*, without the reason, even with `"DisplayError": "1"`. Nothing was cancelled. Check the challan in Logic ERP, or ask your Logic ERP team.

### **Example request**

```json
{
  "Branch_Code": 2,
  "BillSeries": "DCH",
  "Bill_No": 118,
  "Cancel_Reason": "Goods not dispatched"
}
```

### **Response**

| Field            | Type         | Meaning                                                                                                                                |
| ---------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| `Status`         | true / false | `true` when the challan was cancelled.                                                                                                 |
| `Message`        | text         | `"Success"` when cancelled; otherwise the reason.                                                                                      |
| `LastSavedCode`  | number       | Logic ERP's internal number of the cancelled challan.                                                                                  |
| `LastSavedDocNo` | text         | The challan number in Logic ERP's internal form of type, series and number, for example `"CHDCH 118"`. `null` when the request failed. |
| `request_ID`     | text         | As described on the common page. `null` when the request failed before the challan was found.                                          |

### **Example response**

```json
{
  "LastSavedDocNo": "CHDCH 118",
  "Status": true,
  "Message": "Success",
  "LastSavedCode": 5521,
  "request_ID": "0b7e4d21-8c3f-4a9e-b1d2-77a5e9c0f314"
}
```

### **Messages you may see**

| Message                                                                                                                                                            | Meaning                                                                                                                                                 | What to do                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| `Please Define Bill No. Or PartyOrderNo to Continue...`                                                                                                            | None of `DocCode`, `BillSeries` or `PartyOrderNo` was sent.                                                                                             | Send one of them.                                           |
| `Bill No. not defined against Bill Series : …`                                                                                                                     | `BillSeries` sent without `Bill_No`.                                                                                                                    | Send the challan number.                                    |
| `Unable to Retrive Bill Series : …`                                                                                                                                | No sale challan series with that name in the branch (a challan return series gives this too).                                                           | Check the series and `Branch_Code`.                         |
| `Duplicate Bill exists againts Party Order No. : … in Branch Code : …`                                                                                             | More than one challan matched.                                                                                                                          | Send `DocCode` or the series and number.                    |
| `Unable to found Document againts Party Order No. … and Branch Code : …`                                                                                           | No challan matched in that branch – also for a `DocCode` or a series and number that is not found (the message names the party order number even then). | Check the branch and the number.                            |
| `Document No. … was not cancelled.`                                                                                                                                | The cancel ran but the challan is still not cancelled.                                                                                                  | Check the challan in Logic ERP and cancel it there.         |
| `Document has already been cancelled...`                                                                                                                           | Already cancelled.                                                                                                                                      | Nothing to do.                                              |
| `Please Enter Cancel Remarks to Continue...`                                                                                                                       | `Cancel_Reason` is empty.                                                                                                                               | Send a reason.                                              |
| `Cannot allow cancellation.... This document has been posted.....`                                                                                                 | The challan is marked as posted.                                                                                                                        | Ask your Logic ERP team.                                    |
| `This document has been transferred to H.O. Modification not allowed......`, `This document has been imported from other Branches. Modification not allowed......` | The challan was transferred between branches.                                                                                                           | Cancel it where it was created.                             |
| `Entry/Modification is locked for this period....`                                                                                                                 | The challan date is in a locked period.                                                                                                                 | Ask your Logic ERP team.                                    |
| `The operation was canceled.`                                                                                                                                      | Refused by a check that does not return its reason. Nothing was cancelled.                                                                              | Check the challan in Logic ERP, or ask your Logic ERP team. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-challan.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
