// JavaScript Document
//here all method and function that control bill
var supplierpagename = 'sellbillAjaxController.php';
var storepagename = 'sellbillAjaxController.php';
var productpricepagename = 'sellbillAjaxController.php';
var billtype = 0;


var calcuproduct;
var totalprice;
var selltotalprice;
var thegeneraldiscount;
var checkthepayed;
var thegeneralpayed;
var therestofdebt;
var addrow;
var formatResult;


var sprydate;
var spryclient;
var sprytempname;


//the common itration and the start // 2
$aw_i =  document.getElementById("hidden_itr").value;
$aw_i ++;
//the tabindex to increment in dynmaic load
$tabindexnum = 15;


jQuery(document).ready(function() {

  



    //to start the itration with default value // 1
   // document.getElementById("hidden_itr").value = 1;



    //add new row in bill
    //on click the add button
    /************************/
    $("#addpro").click(function() {

        $("#addunit").empty();

        addrow($aw_i, $tabindexnum);

        // fill the iltration filed with common iltration
        document.getElementById("hidden_itr").value = $aw_i;

        // incrementaion of row number and tab index
        $aw_i++
        $tabindexnum++;

        //reload the dropdownlist and jquery files
        $('select').select2();


        return false;

    });
    /************************/




    //add new row in bill
    /**************************/
    addrow = function($aw_if, $tabindexnumf)
    {
      
//alert('userstoreid'+userstoreid);
//alert('morestore'+morestore);
        $xx = '';
      


    



	//البيع من اكثر من مخزن
				
					//alert(morestore);
					
					//alert('userstoreid'+userstoreid);
				
				
					//alert(2222);
				$xx += '<tr><td ><div id="prstoridsiv'+ $aw_if + '">'
						+ ' <select class="select2 wdt100" name="prstorid'+ $aw_if + '" id="prstorid'+ $aw_if + '" >'
					
						+'   </select></div></td>'
				
			
		

        $xx += '<td>'
                + '<div id="productdiv' + $aw_if + '">'
               	+ ' <select class="select2 wdt100" name="product'+ $aw_if + '" id="product'+ $aw_if + '" >'
				+' <option >fff</option>'	
				+'   </select>'
                + '</div>'
                + '</td>';


    
       
            $xx += '<td>';
      
       

        $xx += '<textarea class="form-control txt-nonraduis enteraction" name="comment' + $aw_if + '" id="comment' + $aw_if + '" rows="1" tabindex="' + $tabindexnumf + '"></textarea>'

                + '</td>';




     
         
      

    

               $xx += '<td>'
                + '<input type="text" name="pronum' + $aw_if + '" id="pronum' + $aw_if + '"  class="form-control txt-nonraduis getprototal enteraction numberinput"  value="1" tabindex="' + $tabindexnumf + '" />'
                + '</td>'

                + '<td><div id="propricechange' + $aw_if + '">'
                + '<input type="text" name="proprice' + $aw_if + '" id="proprice' + $aw_if + '"  class="form-control getprototal enteraction numberinput txt-nonraduis" value="0" tabindex="' + $tabindexnumf + '"  />'

                + '</div></td>';

		
//alert('xx3'+$xx);
       
            $xx += '<td>';
     
      
        $xx += '<input type="text" name="prodis' + $aw_if + '" id="prodis' + $aw_if + '"  class="form-control txt-nonraduis getprototal enteraction numberinput" value="0" tabindex="' + $tabindexnumf + '"  />'
                + '</td>';



        $xx += '<td>'
                + '<div id="prototal' + $aw_if + '" class="form-control-static">0</div>'
                + '<input name="hidden_prototal' + $aw_if + '" id="hidden_prototal' + $aw_if + '" type="hidden" value="0" />'
                + '</td>'


                + '<td>'
                + '	<button id="remove' + $aw_if + '" type="button" class="close flt-none removeicon removeproduct" aria-hidden="true">&times;</button>'
                + '</td>'
                + '</tr>';



        $("#containerpros").append($xx);

        $(".numberinput").forceNumeric();


        // varaible to contains the common itration
        var n = $aw_if;
        var tbindexn = $tabindexnumf;



        //assign select2 properties
	

    }
    /**************************/


    // the delete action that delete row of products
    /************************/
    $(document).on('click', '.removeproduct', function() {

        // delete by partents
        $(this).parent().parent().remove();

        // get the itration from itration colum
        $remitr = document.getElementById("hidden_itr").value


      
        return false;
    });
    /************************/

    // calculating the product price
    // on keyup action
    /************************/
    $(document).on('keyup', ".getprototal", function() {});
    /************************/



    //assign select2 properties
	
		//storeid: document.getElementById("prstorid"+n).value ,
	
    // here the frist action on frist dropdownlist
    /************************/
  
    /************************/


    // get the total price
    /************************/
    selltotalprice = function($ix)
    {}
    /************************/


    // get the total price
    /************************/
    totalprice = function()
    {}
    /************************/


    // method that calculate discount
    /************************/
    thegeneraldiscount = function()
    {}
    /************************/


    // general pay , calaclution in key up
    /************************/
    $(document).on('keyup', "#genpay", function() {});
    /************************/


    // calculate the general payed
    /************************/
    thegeneralpayed = function()
    {}

    $(document).on("keyup", "#genpay", function() {});
    /************************/

    //calculate the rest of debt
    /************************/
    therestofdebt = function()
    {}
    /************************/

    // calculate general discount
    /***********************/
    $(document).on('keyup', "#gendis", function() {});
    /**********************/

    //action of loading the dropdwonlist with new record
    /***********************/
    // the action will determine later
    $("#suppliernotuse").select2().change(function() {});
    /***********************/

    //action of supplier dropdownlist
    /**********************/
    $("#supplier").select2().change(function() {});

    /**********************/

    // action of edit debt
    /************************/
    $("#editdebt").click(function() {});
    /************************/

    // the main method to calucalte products price
    /***************************/
    calcuproduct = function(thecolnmux)
    {}
    /***************************/

    //use enter action do new row
    /*****************************/
    $(document).on('keypress', ".enteraction", function(e) {});
    /*****************************/

    //to use enter and click to submit the form
    /*******************************/
   
    /******************************/

    // using esc to delete row
    /*****************************/
    $(document).keypress(function(e) {});
    /*******************************/

    /////////////////////add by sara////////////////
    checkthepayed = function() {}
    /*******************************/

    //action of store dropdownlist
    /**********************/
 
    /*************************************/
});





function getunitprice(n)
{
}




function checkdisValue()
{
}


function calculateremain(payed)
{}





function printData()
{
    print_Custom('mycustomheader');
}