// for edit
$(document).ready(function(){
    // ajax for product change
$("#productedit").on('change',function(){
var product = $(this).val();
//alert(product);
//var product = $(".productedit").val();
//alert (product);
$.ajax({
type:'POST',
url:'ajaxpath/secondtrans_productname.php',
data:{product:product},
success:function(a){
 //alert(a);
 // $(".showquantity-with-color").css("display","block");
//  price
  $("#productnameedit").val(a);
  //alert(a);
  var cus = $(".customeredit").val();
  var product = $("#productedit").val();
  //alert (product);
  $.ajax({
    type:'POST',
    url:'ajaxpath/secondtransprice.php',
    data:{cus:cus,product:product},
    success:function(b){
    //alert(b);
     // $(".showquantity-with-color").css("display","block");
      $(".priceedit").val(b);
      $(".priceoriedit").val(b);
     // alert(b);
    //unit

    var product = $("#productedit").val();
    $.ajax({
        type:'POST',
        url:'ajaxpath/secondtrans_unit.php',
        data:{product:product},
        success:function(c){
        //  alert(a);
         // $(".showquantity-with-color").css("display","block");
          $(".unitconversionedit").val(c);
          //alert(c);
          var price = $(".priceedit").val();
          var product = $("#productnameedit").val();
         $(".productdisplay").html(product);
         $(".pricedisplay").html(price);
          $("#editproductdis").click();
          var empty = $(".emptyedit").val();
            var load = $(".loadweightedit").val();
            var netweight = load- empty;
            //alert(netweight);
             if(netweight < 0)
             {
                 var netweightt = empty - load;
             }
             else 
             {
                 var netweightt =   load -empty;
             }
             $(".netweightedit").val(netweightt);
             var nettwe = $(".netweightedit").val();
             var unitcon= $(".unitconversionedit").val();
             var finaluni = nettwe/unitcon;

             $(".netqtyedit").val((finaluni).toFixed(2));
             $(".unitadjori").val((finaluni).toFixed(2));
                var unitco =  $(".netqtyedit").val() ;
                var price = $(".priceedit").val();
                var amount = unitco*price;
                $(".totalamtedit").val(amount);
                //alert(finaluni);

       }
                    });
    //unit

   }
                });
                // price
}
            });
            //ajax for productname
});
$(".editproductnamemo").click(function(){
$(".editproname").modal('hide');
$(".modal").css('overflow', 'auto');

});
});

// for edit
// for edit cus
$(document).ready(function(){
    // ajax for product change
$(".customeredit").on('change',function(){

  var cus = $(".customeredit").val();
  var product = $("#productedit").val();
  //alert (product);
  $.ajax({
    type:'POST',
    url:'ajaxpath/secondtransprice.php',
    data:{cus:cus,product:product},
    success:function(b){
    //  alert(a);
     // $(".showquantity-with-color").css("display","block");
      $(".priceedit").val(b);
      $(".priceoriedit").val(b);
      var price = $(".priceedit").val();
      var product = $("#productnameedit").val();
      $(".productdisplay").html(product);
      $(".pricedisplay").html(price);
     // alert(b);
    //unit

   
    //$("#editproductdis").click();
    

       }
                    });
                  
            //ajax for productname
});
});



// for edit cus
// for edit value

$(document).ready(function(){
    //alert('hai');
    var product = $("#productedit").val();
    $.ajax({
        type:'POST',
        url:'ajaxpath/secondtrans_unit.php',
        data:{product:product},
        success:function(c){
        //  alert(a);
         // $(".showquantity-with-color").css("display","block");
          $(".unitconversionedit").val(c);
          //alert(c);
        
         
       }
                    });
    $(".getweightbuttonedit").click(function(){
        var query=1;
                $.ajax({  
                     url:"ajaxpath/search1.php",  
                     method:"POST",  
                     data:{query:query},
                     success:function(data)  
                     {  
                       //alert(data);
              $(".loadweightedit").val(data);
              //alert(a);
              $(".getweightadd").css("border","1px solid skyblue");
              $(".getweightadd").css("box-shadow","2px 1px 3px 1px skyblue");
            var empty = $(".emptyedit").val();
            var load = $(".loadweightedit").val();
            var netweight = load- empty;
            //alert(netweight);
             if(netweight < 0)
             {
                 var netweightt = empty - load;
             }
             else 
             {
                 var netweightt =   load -empty;
             }
             $(".netweightedit").val(netweightt);
             var nettwe = $(".netweightedit").val();
             var unitcon= $(".unitconversionedit").val();
             var finaluni = nettwe/unitcon;

             $(".netqtyedit").val((finaluni).toFixed(2));
             $(".unitadjori").val((finaluni).toFixed(2));
                var unitco =  $(".netqtyedit").val() ;
                var price = $(".priceedit").val();
                var amount = unitco*price;
                $(".totalamtedit").val(amount);

            }

           
                        });

 
                        // 
    });
    // unitkeyup
    $(".netqtyedit").keyup(function(){
 var netqty = $(this).val();
 var price = $(".priceedit").val();
 var amount = netqty*price;
                $(".totalamtedit").val(amount);
                $("#updatebut").prop('disabled', false);
                //alert(amount);
    });
    // unitkeyup
    // pricekeyup
    $(".priceedit").keyup(function(){
        var netqty = $(".netqtyedit").val();
        if( netqty == '')
        {
            var price = 0;
        }
        else {
            var price = $(".priceedit").val();
        }
        
        var amount = netqty*price;
                       $(".totalamtedit").val(amount);
                       $("#updatebut").prop('disabled', false);
                       //alert(amount);
           });
    // pricekeyup
   
    });

//fpr edit value
// for customer type
$(document).ready(function(){
    var sales = $("#salestypeedit").val();
    var customer = $(".customeredit").val();
    //alert (customer);
    if( sales == 'credit')
    {
        $("#showcredit").show();
        $.ajax({
            type:'POST',
            url:'ajaxpath/creditbalnce.php',
            data:{customer:customer},
            success:function(a){
            //  alert(a);
             // $("#showquantity-with-color").css("display","block");
              $("#creditadd").val(a);
              $("#showcredit").hide();
              //alert(a);
      
           }
                        });
    }
    else{
    $("#showcredit").hide();
    }
      $(".customeredit").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);
           //alert(a);
           
        }
                     });
                  //   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");
        $("#creditaddlimit").val(a);
        //alert(a);
        var balance = a;
        //alert(a);
        if (balance == "")
        {
          $(".creditrow").hide();
          $("#showcredit").hide();
        }
        else
        {
          $(".creditrow").show();
          $("#showcredit").show();
        }
     }
                  });
               //   ajax for creditvalue end
               //    ajax for creditlimit
          $.ajax({
              type:'POST',
              url:'ajaxpath/creditbalnce.php',
              data:{customer:customer},
              success:function(a){
              //  alert(a);
               // $("#showquantity-with-color").css("display","block");
                $("#creditadd").val(a);
                $("#showcredit").hide();
                //alert(a);
        
             }
                          });
                       //   ajax for creditlimit end
                       
              //   top close
       });
    
    
  
  });

// customerr
// credit calculation
$(document).ready(function(){
    $(".totalamtedit").change(function(){
        //alert('hai');
        $("#updatebut").prop('disabled', false);
    });
    $(".alertbutton").hide();
    $("#updatebut").mouseover(function(){
//alert('g');
var total = $(".totalamtedit").val();
    var oldtotal = $(".oldtotalamtedit").val();
var customer = $(".customeredit").val();
var oldbilltype= $("#oldbilltype").val();
var table=$(".table").val();
//alert(oldtotal);
$.ajax({
    type:'POST',
    url:'ajaxpath/billtypefetchedit.php',
    data:{customer:customer,total:total,oldtotal:oldtotal,oldbilltype:oldbilltype,table:table},
    success:function(a){
    //  alert(a);
     // $("#showquantity-with-color").css("display","block");
      $("#billtypeedit").val(a);
      //alert(a);
      
   }
                });
             //   ajax for billtype end
    var salestypeedit = $("#salestypeedit").val();
   if(salestypeedit != 'cash')
   {
var credit =   $("#creditadd").val();
var total = $(".totalamtedit").val();
var finalamt = credit-total;
//alert(finalamt);
if(finalamt <= 0)
{

    // $(".alertbutton").click();
    // $("#updatebut").prop('disabled', true);
}
else {
   // $("#updatebut").prop('disabled', false);
}
   }
});
$("#updatebut").keyup(function(){
    var total = $(".totalamtedit").val();
    var oldtotal = $(".oldtotalamtedit").val();
var customer = $(".customeredit").val();
//alert(oldtotal);
$.ajax({
    type:'POST',
    url:'ajaxpath/billtypefetch.php',
    data:{customer:customer,total:total,oldtotal:oldtotal},
    success:function(a){
    //  alert(a);
     // $("#showquantity-with-color").css("display","block");
      $("#billtypeedit").val(a);
      //alert(a);
      
   }
                });
             //   ajax for billtype end
             var salestypeedit = $("#salestypeedit").val();
    if(salestypeedit != 'cash')
    {
   
    var credit =   $("#creditadd").val(); 
    var total = $(".totalamtedit").val();
    var finalamt = credit-total;
    //alert(finalamt);
    if(finalamt <= 0)
    {
    
        //$(".alertbutton").click();
        //$("#updatebut").prop('disabled', true);
    }
    else {
        //$("#updatebut").prop('disabled', false);
    }
}
    });
    
});
// creditcalculation
$(document).ready(function(){
    // ajax for product change
$(".customeredit").on('change',function(){

 var cus= $(this).val();
 //    ajax for creditlimit
 $.ajax({
    type:'POST',
    url:'ajaxpath/product_ticket.php',
    data:{customer:cus},
    success:function(a){
    //alert(a);
     // $("#showquantity-with-color").css("display","block");
      //$("#productedit").html(a);
      $(".priceedit").val("");
      $(".priceoriedit").val("");
      //alert(a);

   }
                });
             //   ajax for creditlimit end
// alert(cus);
});
});
$(document).ready(function(){
$(".loadweightedit").keyup(function(){
var empty = $(".emptyedit").val();
var load = $(".loadweightedit").val();
var netweight = load- empty;
//alert(netweight);
 if(netweight < 0)
 {
     var netweightt = empty - load;
 }
 else 
 {
     var netweightt =   load -empty;
 }
 $(".netweightedit").val(netweightt);
 var nettwe = $(".netweightedit").val();
 var unitcon= $(".unitconversionedit").val();
 var finaluni = nettwe/unitcon;

 $(".netqtyedit").val((finaluni).toFixed(2));
 
    var unitco =  $(".netqtyedit").val() ;
    var price = $(".priceedit").val();
    var amount = unitco*price;
    $(".totalamtedit").val(amount);
});
});

// loadweight
// emptyweight
$(document).ready(function(){
    $(".emptyedit").keyup(function(){
    var empty = $(".emptyedit").val();
    var load = $(".loadweightedit").val();
    var netweight = load- empty;
    //alert(netweight);
     if(netweight < 0)
     {
         var netweightt = empty - load;
     }
     else 
     {
         var netweightt =   load -empty;
     }
     $(".netweightedit").val(netweightt);
     var nettwe = $(".netweightedit").val();
     var unitcon= $(".unitconversionedit").val();
     var finaluni = nettwe/unitcon;
    
     $(".netqtyedit").val((finaluni).toFixed(2));
     
        var unitco =  $(".netqtyedit").val() ;
        var price = $(".priceedit").val();
        var amount = unitco*price;
        $(".totalamtedit").val(amount);
    });
    });
// emptyweight