Sales document sample

<!-- Display possible api errors -->
<div>
  {{ range .Data.Errors }}
  <span>{{ . }}</span>
  {{ end }}
</div>

<form method="post">
  <!-- Field used by goErp to state what we want to save -->
  <input type="hidden" name="postActionEntity" value="SalesDocumentInput"/>

  <!-- Need to set the ID of the existing document -->
  <input type="hidden" name="ErplyApi.SalesDocumentInput.ID"
         value="{{ .Data.ErplyApi.SalesDocumentInput.ID }}">

  <table>
    <thead>
    <tr>
      <th>Product ID</th>
      <th>Amount</th>
      <th>Price</th>
    </tr>
    </thead>

    <tbody>
    {{ range $row := .Data.ErplyApi.SalesDocument.Rows }}
    <tr>
      <td>
        <!-- Stable row id is used by erply api to determine existing rows
        the api always replaces all rows so adding a single row means all rows need to be resaved -->
        <input type="hidden" name="ErplyApi.SalesDocumentInput.RowStableRowID"
               value="{{ $row.StableRowID }}">
        <input name="ErplyApi.SalesDocumentInput.RowProductID" value="{{ $row.ProductID }}">
      </td>
      <td><input name="ErplyApi.SalesDocumentInput.RowAmount" value="{{ $row.Amount }}"></td>
      <td><input name="ErplyApi.SalesDocumentInput.RowPrice" value="{{ $row.Price }}"></td>
    </tr>
    {{ end }}
    <tr>
      <td>
        <input type="hidden" name="ErplyApi.SalesDocumentInput.RowStableRowID" value="0">
        <input name="ErplyApi.SalesDocumentInput.RowProductID" value="" placeholder="Product ID">
      </td>
      <td><input name="ErplyApi.SalesDocumentInput.RowAmount" value="0"></td>

      <!-- Manual pricing allowed? -->
      <td><input name="ErplyApi.SalesDocumentInput.RowPrice" value="0"></td>
    </tr>
    </tbody>
  </table>

  <!-- Erply api returns this boolean as a string 0 or 1 for some reason -->
  {{ if eq .Data.ErplyApi.SalesDocument.Confirmed "1" }}
  <h2>Confirmed documents cannot be edited</h2>
  {{ else }}
  <button type="submit">Save</button>
  {{ end }}
</form>