$(document).ready(function () {
  $("#showcredit").hide();
  $("#customeradd").on("change", function () {
    var customer = $(this).val();
    //    ajax for sales type
    $.ajax({
      type: "POST",
      url: "ajaxpath/salestypefetch.php",
      data: { customer: customer },
      success: function (a) {
        //  alert(a);
        // $("#showquantity-with-color").css("display","block");
        $("#salestypeedit").val(a);
        $("#customeradd").css("border", "1px solid skyblue");
        $("#customeradd").css("box-shadow", "2px 1px 3px 1px skyblue");
        //alert(a);.
        //$("#creditadd").val(a);
        //alert(a);
        var type = $("#salestypeedit").val();
        //alert(type);
        if (type == "cash") {
          $(".creditrow").show();
          $("#creditaddlimit").prop("disabled", true);
          $("#showcredit").hide();
          $("#creditaddlimit").val("");
        }
        if (type == "credit") {
          $(".creditrow").show();
          //$("#showcredit").show();
          $.ajax({
            type: "POST",
            url: "ajaxpath/creditbalnce.php",
            data: { customer: customer },
            success: function (a) {
              //  alert(a);
              // $("#showquantity-with-color").css("display","block");
              $("#creditaddlimit").val(a);

              //alert(a);
            },
          });
          //   ajax for creditlimit end
        }
        if (type == "contract") {
          $(".creditrow").show();
          //$("#showcredit").show();
          $.ajax({
            type: "POST",
            url: "ajaxpath/creditbalnce.php",
            data: { customer: customer },
            success: function (a) {
              //  alert(a);
              // $("#showquantity-with-color").css("display","block");
              $("#creditaddlimit").val(a);

              //alert(a);
            },
          });
          //   ajax for creditlimit end
        }
      },
    });
    //   ajax for salestye end
    //    ajax for creditvalue
    $.ajax({
      type: "POST",
      url: "ajaxpath/creditvalue.php",
      data: { customer: customer },
      success: function (a) {
        //  alert(a);
        // $("#showquantity-with-color").css("display","block");
        $("#creditadd").val(a);
      },
    });
    //   ajax for creditvalue end
    //    ajax for creditlimit

    //    ajax for creditlimit
    $.ajax({
      type: "POST",
      url: "ajaxpath/product_ticket.php",
      data: { customer: customer },
      success: function (a) {
        // alert(a);
        // $("#showquantity-with-color").css("display","block");
        //$("#productadd").html(a);
        //alert(a);
      },
    });
    //   ajax for creditlimit end
    //   top close
  });
});
$(document).ready(function () {
  $("#ticketFetch").keyup(function (e) {
    var tkt = $("#ticketFetch").val();
    var print = $("#print").html();
    var edit = $("#edit").html();
    // alert(print);
    if (e.keyCode == 13) {
      $.ajax({
        type: "POST",
        dataType: "json",
        url: "ajaxpath/tktfetchtkt.php",
        data: { tkt: tkt },
        success: function (data) {
          console.log(typeof data);
          console.log(data);
          $("#tableTbody").html("");
          data.map((data) => {
            tablerow = `<td>1</td>
            <td>${data.ticket}</td>
        <td>${data.vehicleno}</td>
        <td>${data.cusname}</td>
        <td>${data.weight}</td>
        <td>
          <!-- spinner -->
         ${
           data.firsttrans != 1
             ? `<div>
             <div class="spinner-grow spinner-grow-sm text-danger"></div>
             <div class="spinner-grow text-success  spinner-grow-sm"></div>
             <div class="spinner-grow text-info  spinner-grow-sm"></div>
             <div class="spinner-grow text-warning  spinner-grow-sm"></div>
           </div>`
             : `<div style="color:green"><i class="fas fa-check"></i></div>`
         }
          <!-- spinner -->
          <!-- tick -->
          
          <!-- tick -->
          <div></div>
        </td>
        <td>
        ${
          data.process != "completed"
            ? `<div>
            <div class="spinner-grow spinner-grow-sm text-danger"></div>
            <div class="spinner-grow text-success  spinner-grow-sm"></div>
            <div class="spinner-grow text-info  spinner-grow-sm"></div>
            <div class="spinner-grow text-warning  spinner-grow-sm"></div>
          </div>`
            : `<div style="color:green"><i class="fas fa-check"></i></div>`
        }
          <!-- tick -->
          <div></div>
        </td>
        ${
          print == 1
            ? `<td><a href="billslipticket.php?print=${data.ticket} " target="_blank"><i class="fas fa-print"></i></a></td>`
            : ""
        }
        ${
          edit == 1
            ? `<td><a href="editticket.php?ticket=${data.ticket}"><i class="fas fa-edit edit"></i></a></td><?php }?>
                <!-- <td><a data-toggle="modal" data-target="#prd-1"><i  class="fas fa-trash-alt dele"></a></i></td>`
            : ""
        }
            </tr>
            <?php
    }}
            ?> `;
          });
          $("#tableTbody").append(tablerow);
        },
      });
    }
  });
});
