# Query: Correct PIH Selection After a Rejected Invoice

**URL:** <https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337>\
**Category:** General\
**Created:** [January 21, 2025, 2:07pm UTC](https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337 "2025-01-21T14:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjun\_tech24](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@arjun\_tech24](https://zatca1.discourse.group/u/arjun_tech24)\
**Post date:** [January 21, 2025, 2:07pm UTC](https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337/1 "2025-01-21T14:07:44Z")

</div>

**Scenario:**

1. **Invoice 1** : Submitted successfully to ZATCA and marked as “Reported.”
2. **Invoice 2** : Submitted using the hash of Invoice 1 as the **Previous Invoice Hash (PIH)**, but rejected by ZATCA and marked as “Not Reported” due to some mistakes.
3. **Invoice 3** : Now being prepared.

**Question:**  
For Invoice 3, which invoice hash should be used as the **PIH** :

- The hash of Invoice 1 (Reported)?
- Or the hash of Invoice 2 (Not Reported)?

---

<div class="post-metadata">

**Author:** ![hnatividad](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hnatividad](https://zatca1.discourse.group/u/hnatividad)\
**Post date:** [September 15, 2025, 2:14pm UTC](https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337/2 "2025-09-15T14:14:17Z")

</div>

it should be the hash of Invoice 2.

---

<div class="post-metadata">

**Author:** ![arjun\_tech24](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@arjun\_tech24](https://zatca1.discourse.group/u/arjun_tech24)\
**Post date:** [September 17, 2025, 7:46am UTC](https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337/3 "2025-09-17T07:46:17Z")

</div>

@hnatividad Thank you

---

<div class="post-metadata">

**Author:** ![sergei.shishov](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sergei.shishov](https://zatca1.discourse.group/u/sergei.shishov)\
**Post date:** [September 21, 2025, 10:05am UTC](https://zatca1.discourse.group/t/query-correct-pih-selection-after-a-rejected-invoice/5337/4 "2025-09-21T10:05:23Z")

</div>

Hi @arjun_tech24

Do not think about it as reported/not-reported. Think about is as submissions. If submission reached Zatca, then the hash should be stored and then used as PIH.

```auto
Reported --> Failed --> Network Error --> Reported --> ...

```

In this example the document which end-up with network error, you have to RETRY without changing any payload. Why? because you do not know for sure if it was reported or not. It can happen that timout happened on client side but it was reported, it can happen that LoadBalancer on ZATCA side restarted (gateway) but the request was processed by the server etc…

We are following these rules:

- reported, good nothing to do, store
- failed, good nothing to do, store
- error, bad we have to schedule the task to retry but as well store it

At the same time we are implementing our own validation of business rules to not submit “for sure” incorrect data, that’s why failed invoices in our case should happen very rare.

I hope my explanation can help you and someone else in future.

Best regards, Sergei
