> 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/purchase/push/generate-rate-difference-and-physical-stock-debit-notes.md).

# Generate Rate Difference and Physical Stock Debit Notes

Creates the **debit notes to the supplier** that are due on one **purchase voucher** – the same job as the **Generate Rate Diff/Phy Stock Debit Notes** screen (Purchase menu) does for a single voucher. You send the voucher's bill number; Logic ERP works out what is pending and saves up to three documents:

* **Rate difference debit note** – when the supplier charged more than the rate agreed on the purchase order. These lines are marked for a debit note when the purchase is saved against the order and the rate charged is above the order rate. The debit note charges the **difference per unit** for the quantity that has been **physically verified** and not yet debited. Saved as a *Purchase Return – Rate Difference* document.
* **Physical stock debit note** – when the physical verification found **less than was billed**. For each line counted short, it returns the missing quantity (billed minus counted) at the rate on the purchase voucher. Saved as a purchase return; made only once per voucher.
* **Rejection / shortage debit note** – for rejected or short quantities still pending, as entered on **Enter Rejection/Replacements Items against Purchase**. Saved as a purchase return.

The physical count comes from [Save Physical Verification of a Purchase Voucher](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/purchase/push/save-physical-verification-of-a-purchase-voucher.md) or the screen – without it no rate difference or physical stock debit note is made.

### **Endpoint**

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

Also accepted: `https://your-server/api/SaveRateDiffDebitNotesAgaintPU` (older spelling, same behaviour).

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).

Field names are matched without regard to upper/lower case; fields not listed below are ignored.

### **Request fields**

| Field             | Type   | Required                      | Default | Meaning                                                                                                                                                                                                                                                                                |
| ----------------- | ------ | ----------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BranchCode`      | number | **Yes**, or `BranchShortName` | `0`     | The branch of the purchase voucher (`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)).                                                                                |
| `Bill_No`         | text   | **Yes**                       | –       | The supplier's bill number as entered on the purchase voucher (`Bill_No` in [Get Purchase Vouchers](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/purchase/pull/get-purchase-vouchers.md)). Must match the bill number on the voucher. |
| `GRN_Prefix`      | text   | No                            | empty   | The voucher's GRN prefix (`GRN_Prefix` in Get Purchase Vouchers). Send it with `GRN_Number` when the bill number is used on more than one document.                                                                                                                                    |
| `GRN_Number`      | number | With `GRN_Prefix`             | `0`     | The voucher's GRN number (`GRN_Number` in Get Purchase Vouchers). Used only when above `0`, and then together with `GRN_Prefix` – sent without a prefix, only vouchers with a blank GRN prefix are matched.                                                                            |
| `BranchShortName` | text   | No                            | empty   | The branch by its short name. Used only when `BranchCode` is `0`.                                                                                                                                                                                                                      |

### **Rules Logic ERP applies**

* **Which voucher.** Logic ERP looks in the branch and the **current financial year** (the year containing today's date on the server) for purchase vouchers with this `Bill_No` – and this `GRN_Prefix` / `GRN_Number` when sent. Purchase returns and other purchase documents are not searched. Exactly one must be found; add the GRN prefix and number when the bill number repeats.
* **Only purchase vouchers.** The document found must be a purchase voucher that is not marked goods-in-transit. Stock transfers in are refused unless your Logic ERP team has allowed debit notes for stock transfers. Otherwise the request is refused with `Bill No. : … is not a purchase voucher eligible for Rate Difference/Physical Stock Debit Notes (goods-in-transit or stock transfer).`
* **Configuration required.** The *Generate Rate Diff/Phy Stock Debit Notes* configuration must name the series and prefix for rate-difference debit notes **and** the series and prefix for physical stock debit notes – both, even if you only need one kind. For rejection debit notes it uses its own series and prefix if set, otherwise the rate-difference series and the prefix `PR`.
* **Nothing pending.** If the voucher has no pending rate difference, no short count without a debit note, and no pending rejection or shortage, nothing is created and the reason is returned.
* **Rate difference needs a count.** A line with a rate difference gets a debit note only for the quantity physically verified beyond what has already been debited. Lines not yet counted are left for later.
* **Vouchers that do not add stock.** For a voucher saved without adding stock, only the rate-difference debit note is made, from the physical count, and only when the pending amount is above ₹10.
* **Numbering and date.** Each debit note gets the next number of its prefix in the branch and the date of the purchase voucher.
* **Each debit note is saved on its own.** If a later one fails, those already made stay saved and the answer is `Status: false`; the message names the debit notes already saved. Check the voucher on the screen before sending again; a repeat only creates what is still pending.
* **Several debit notes.** When more than one debit note is made, `LastSavedCode` and `LastSavedDocNo` hold the last one (order: rate difference, physical stock, rejection); `Message` lists all of them, for example `Debit Notes saved : Rate Difference RD-27, Physical Stock PS-12`.

### **Example request**

```json
{
  "BranchCode": 2,
  "Bill_No": "SR-4471",
  "GRN_Prefix": "GRN",
  "GRN_Number": 318
}
```

### **Response**

| Field            | Type         | Meaning                                                                                                                |
| ---------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `Status`         | true / false | `true` when at least one debit note was made.                                                                          |
| `Message`        | text         | `Debit Notes saved : …` with the debit notes made; otherwise the reason.                                               |
| `LastSavedCode`  | number       | Logic ERP's internal number of the last debit note made.                                                               |
| `LastSavedDocNo` | text         | The last debit note's prefix and number joined by a hyphen, for example `"RD-27"`. `null` when no debit note was made. |
| `request_ID`     | text         | Always empty for this endpoint.                                                                                        |

### **Example response**

```json
{
  "LastSavedDocNo": "RD-27",
  "Status": true,
  "Message": "Debit Notes saved : Rate Difference RD-27",
  "LastSavedCode": 5193,
  "request_ID": ""
}
```

### **Messages you may see**

`Message` holds the reason.

| Message                                                                                                                                                            | Meaning                                                                                                                    | What to do                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| `Branch Code/Branch Short Name not Set.....`                                                                                                                       | Neither `BranchCode` nor `BranchShortName` was sent.                                                                       | Send `BranchCode`.                                     |
| `Branch_Short_Name : … not exists.`                                                                                                                                | No branch has that `BranchShortName`.                                                                                      | Check the short name with Get Branch Info.             |
| `Invalid Bill_No....`                                                                                                                                              | `Bill_No` is empty.                                                                                                        | Send the supplier's bill number.                       |
| `Invalid GRN No....`                                                                                                                                               | `GRN_Prefix` was sent without `GRN_Number`.                                                                                | Send both, or neither.                                 |
| `Unable to found Document againts Bill No. : …`                                                                                                                    | No purchase voucher with that bill number (and GRN) in the branch and current financial year.                              | Check the values and the branch.                       |
| `Bill No. : … found mutiple times.Please Check`                                                                                                                    | Several purchase vouchers carry that bill number.                                                                          | Add `GRN_Prefix` and `GRN_Number`.                     |
| `Bill No. : … is not a purchase voucher eligible for Rate Difference/Physical Stock Debit Notes (goods-in-transit or stock transfer).`                             | The voucher is marked goods-in-transit, or is a stock transfer in and debit notes for stock transfers are not allowed.     | Raise the debit note on the screen if it is due.       |
| `Please Define Configuration for this module........`                                                                                                              | The rate-difference or physical-stock series or prefix is not set.                                                         | Ask your Logic ERP team to complete the configuration. |
| `Unable to Generate Rate Difference/Physical Stock Debit Notes........`                                                                                            | Nothing is pending for this voucher.                                                                                       | Nothing to do; or count the goods first.               |
| `Rate Difference Debit Note could not be generated.`, `Physical Stock Debit Note could not be generated.`, `Rejection/Shortage Debit Note could not be generated.` | That debit note could not be prepared. When an earlier one was already saved, `Already saved : …` follows with its number. | Check the voucher on the screen before sending again.  |
| `No Rate Difference/Physical Stock Debit Note was generated against Bill No. : …`                                                                                  | Something looked pending, but no debit note could be made.                                                                 | Check the voucher on the screen.                       |


---

# 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/purchase/push/generate-rate-difference-and-physical-stock-debit-notes.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.
