@page
@model FakturyWeb.Pages.Faktury.CreateModel

@{
    ViewData["Title"] = "Create";
}

<h1>Create</h1>

<h4>FAKTURA</h4>
<hr />
<form method="post">
  <div class="accordion" id="accordionFaktura">
    <div class="accordion-item">
      <h2 class="accordion-header" id="headingOne">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseBase" aria-expanded="true" aria-controls="collapseBase">
          Základní údaje
        </button>
      </h2>
      <div id="collapseBase" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionFaktura">
        <div class="accordion-body row g-3">
          <div class="form-group col-md-2">
            <label asp-for="FAKTURA.CISLO" class="control-label"></label>
            <input asp-for="FAKTURA.CISLO" class="form-control" />
            <span asp-validation-for="FAKTURA.CISLO" class="text-danger"></span>
          </div>

          <div asp-validation-summary="ModelOnly" class="text-danger"></div>
          <div class="form-group col-md-8">
            <label asp-for="FAKTURA.ZakaznikID" class="control-label"></label>
            <select id="fakturaZakaznikSelect" asp-for="FAKTURA.ZakaznikID" class="form-select" asp-items="ViewBag.Zakaznici">
              <option value="-1" selected>(vyberte zákazníka)</option>
            </select>
            <span asp-validation-for="FAKTURA.ZakaznikID" class="text-danger"></span>
          </div>

          <div class="form-group col-md-4">
            <label asp-for="FAKTURA.VYSTAVENI" class="control-label"></label>
            <input asp-for="FAKTURA.VYSTAVENI" class="form-control" />
            <span asp-validation-for="FAKTURA.VYSTAVENI" class="text-danger"></span>
          </div>

          <div class="form-group col-md-4">
            <label asp-for="FAKTURA.FORMA_UHRADY" class="control-label"></label>
            <select asp-for="FAKTURA.FORMA_UHRADY" class="form-select" asp-items="ViewBag.FormyUhrady"></select>
          </div>

          <div class="form-group col-md-4">
            <label asp-for="FAKTURA.SPLATNOST" class="control-label"></label>
            <input asp-for="FAKTURA.SPLATNOST" class="form-control" />
            <span asp-validation-for="FAKTURA.SPLATNOST" class="text-danger"></span>
          </div>
        </div>
      </div>
    </div>

    <div class="accordion-item">
      <h2 class="accordion-header" id="headingTwo">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDetail" aria-expanded="false" aria-controls="collapseDetail">
          Detailní informace
        </button>
      </h2>
      <div id="collapseDetail" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionFaktura">
        <div class="accordion-body row">
          <div class="col-sm-6">
            <div class="card">
              <h5 class="card-header">Dodavatel</h5>
              <div class="card-body">
                <div class="row g-3">

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_PRAJM" class="control-label"></label>
                    <input asp-for="FAKTURA.D_PRAJM" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_PRAJM" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_ULICE" class="control-label"></label>
                    <input asp-for="FAKTURA.D_ULICE" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_ULICE" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_MESTO" class="control-label"></label>
                    <input asp-for="FAKTURA.D_MESTO" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_MESTO" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_PSC" class="control-label"></label>
                    <input asp-for="FAKTURA.D_PSC" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_PSC" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_IC" class="control-label"></label>
                    <input asp-for="FAKTURA.D_IC" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_IC" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_DIC" class="control-label"></label>
                    <input asp-for="FAKTURA.D_DIC" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_DIC" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_BANKA" class="control-label"></label>
                    <input asp-for="FAKTURA.D_BANKA" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_BANKA" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_TELEFON" class="control-label"></label>
                    <input asp-for="FAKTURA.D_TELEFON" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_TELEFON" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_EMAIL" class="control-label"></label>
                    <input asp-for="FAKTURA.D_EMAIL" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_EMAIL" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.D_WEB" class="control-label"></label>
                    <input asp-for="FAKTURA.D_WEB" class="form-control" />
                    <span asp-validation-for="FAKTURA.D_WEB" class="text-danger"></span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="col-sm-6">
            <div class="card">
              <h5 class="card-header">Odběratel</h5>
              <div class="card-body">
                <div class="row g-3">

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_PRAJM" class="control-label"></label>
                    <input id="OdberatelPrajmInput" asp-for="FAKTURA.O_PRAJM" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_PRAJM" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_ULICE" class="control-label"></label>
                    <input id="OdberatelUliceInput" asp-for="FAKTURA.O_ULICE" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_ULICE" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_MESTO" class="control-label"></label>
                    <input id="OdberatelMestoInput" asp-for="FAKTURA.O_MESTO" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_MESTO" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_PSC" class="control-label"></label>
                    <input id="OdberatelPSCInput" asp-for="FAKTURA.O_PSC" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_PSC" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_IC" class="control-label"></label>
                    <input id="OdberatelICInput" asp-for="FAKTURA.O_IC" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_IC" class="text-danger"></span>
                  </div>

                  <div class="form-group col-md-4">
                    <label asp-for="FAKTURA.O_DIC" class="control-label"></label>
                    <input id="OdberatelDICInput" asp-for="FAKTURA.O_DIC" class="form-control" />
                    <span asp-validation-for="FAKTURA.O_DIC" class="text-danger"></span>
                  </div>

                </div>
              </div>
            </div>
          </div>
        </div>


      </div>


    </div>
  </div>



  <div class="form-group">
    <label asp-for="FAKTURA.CINNOSTI" class="control-label"></label>
    <input asp-for="FAKTURA.CINNOSTI" class="form-control" />
    <span asp-validation-for="FAKTURA.CINNOSTI" class="text-danger"></span>
  </div>
  <div class="form-group">
    <input type="submit" value="Create" class="btn btn-primary" />
  </div>
</form>

<div>
    <a asp-page="Index">Back to List</a>
</div>


<script type="text/javascript">
  $("#fakturaZakaznikSelect").change(function () {
    var id = $(this).find(':selected').val();
    //alert("Hello: " + id);
    $.ajax({
      type: "GET",
      url: "Create?handler=Zakaznik",
      data: {"ID": id},
      dataType: "json",
      success: function (response) {
        $("#OdberatelPrajmInput").val(response[0].prajm);
        $("#OdberatelUliceInput").val(response[0].ulice);
        $("#OdberatelMestoInput").val(response[0].mesto);
        $("#OdberatelPSCInput").val(response[0].psc);
        $("#OdberatelICInput").val(response[0].ic);
        $("#OdberatelDICInput").val(response[0].dic);
      },
      failure: function (response) {
        alert(response.responseText);
      },
      error: function (response) {
        alert(response.responseText);
      }
    });
  });
</script>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
