<script type="text/javascript">


	function getUserList(event,obj)
	{

		event.preventDefault();

		var route = '/userlistwithroles/'+$(obj).val();
        showLoader();

		$.get(route,function(data)
		{
			var view_button = '<div> </div>'

			if(data.type == "Employee")
			{

				$('#view_add_button').html('<small class="btn-sm btn-primary" data-toggle="modal" data-target="#md_add_employee"><i class="fa fa-plus"> </i></small>');
				$('#view_add_button').show();
			}
			else if(data.type == "Dealer")
			{

				$('#view_add_button').html('<small class="btn-sm btn-primary"  data-toggle="modal" data-target="#md_add_dealer"><i class="fa fa-plus"> </i></small>');
				$('#view_add_button').show();


			}
			else if(data.type == "Sub Dealer")
			{

				$('#view_add_button').html('<small class="btn-sm btn-primary"  data-toggle="modal" data-target="#md_add_dealer"><i class="fa fa-plus"> </i></small>');
				$('#view_add_button').show();


			}
			else
			{
				$('#view_add_button').html('');
				$('#view_add_button').hide();

			}

    		$('.user_list').html(data.view);
        removeLoader();

  		});
	}



	function getCommissionAmount(event,obj1,obj2,obj3,flag = true)
	{

		var amount_obj 			= $(obj2);
		var percentage_obj 		= $(obj1);
		var amount_in_words_obj = $(obj3);
		var agreed_amount 	    = isDefaulter("<?php echo e($booking->agreed_amount); ?>");


		if(flag == true) // PERCENTAGE IN CASE TRUE
		{	
			percentage = isDefaulter(percentage_obj.val());

			amount_obj.val('');

			amount_in_words_obj.val('');

			if(percentage > 0 && percentage < 100 && agreed_amount > 0)
			{
				percentage = percentage/100;

				amount = Math.round(percentage * agreed_amount);

				amount_obj.val(amount);

				amount_in_words_obj.val(numberInWords(amount));
			}
			else
	      	{
	      		percentage_obj.val((0));

			    amount_obj.val((0));
			    messageToaster('warning','Invalid Input Field','Invalid Amount');
	      	}
		}
		else if(flag == false) // AMOUNT INCASE FALSE
		{
			amount = isDefaulter(amount_obj.val());

			percentage_obj.val('');

			amount_in_words_obj.val('');

			amount = Math.round(amount_obj.val());

			if(agreed_amount > 0 && amount <= agreed_amount)
			{
				percentage = amount*100;

				percentage = percentage / agreed_amount;

				percentage_obj.val(percentage.toFixed(2));

				amount_in_words_obj.val(numberInWords(amount));
			}
			else
	      	{
	      		percentage_obj.val((0));

			    amount_obj.val((0));
			    messageToaster('warning','Invalid Input Field','Invalid Amount');
	      	}
		}


		//var percentage = 0;
		// var amount = 0;
		// var commission_amount = 0;
		// var amount_field = $(obj2).val();
		// if(boolean == true)
		// {
		// 	$(obj2).val('');
		// 	var obj = $(obj1).val();

		// 	if(obj > 0)
		// 	{
		// 		obj = isDefaulter((obj/100));

		// 		amount = (obj*agreed_amount);

		// 	}

		//    commission_amount = Math.round(amount);

		//    $(obj2).val(commission_amount);

		//    $(obj3).val(numberInWords(commission_amount));
		// }
		// else if(boolean == false && agreed_amount > 0 && amount_field > 0)
		// {
  //           if(agreed_amount < amount_field)
  //           {
  //           	percentage = (amount_field * 100);
  //           	percentage = percentage/agreed_amount;  
  //           	$(obj1).val('');
  //           	$(obj1).val(percentage.toFixed(2));
  //           	$(obj3).val(numberInWords(amount_field));
  //           }
  //           else{
		//         $(obj1).val((0));

		//         $(obj2).val((0));
		//         messageToaster('warning','Invalid Input Field','Invalid Amount');
  //           }
		// }
		// else
  //     	{
  //     		$(obj1).val((0));

		//     $(obj2).val((0));
		//     messageToaster('warning','Invalid Input Field','Invalid Amount');
  //     	}



	}
function updateCharges(event,data,modal)
{
		event.preventDefault();


  	var model_element = '#'+modal;

	// DATA TRANSFROM INTO JSON PARSE FORM
	var form_data = JSON.parse(data);

	if(form_data.charges_type == 'Miscellaneous Charges'||form_data.charges_type == 'Document Charges')
	{
          $('#form_update_charges').show();
          $('#form_update_commission').hide();

          $('.charges_type').val(form_data.charges_type);
          $('.charges_amount').val(form_data.chargesamount);
          $('.amount_in_words').val(numberInWords(form_data.chargesamount));
          $('.updated_description').val(form_data.description);
          $('.charge_id').val(form_data.id);

          if(form_data.charges_type == 'Document Charges')
          {

               $('.charges_amount').prop('readonly', true);
          }
          else
          {

   	           $('.charges_amount').prop('readonly', false);
          }

	}
	else
	{
          $('#form_update_charges').hide();
          $('#form_update_commission').show();
	}
	$('.updated_charges').val(data.charges_type);


	$(model_element).modal('show');



}
function ChargesAmount(event,obj)
{
   event.preventDefault();
   var type = $(obj).val();
   if(type == 'Document Charges')
   {
     $('.charges_amount').val(5000);
     $('.amount_in_words').val(numberInWords(5000));
     $('.charges_amount').prop('readonly', true);
   }
   else
   {
   	 $('.charges_amount').val('');
   	  $('.amount_in_words').val('');
   	 $('.charges_amount').prop('readonly', false);
   }
}



</script>
<?php /**PATH /var/www/skylite/resources/views/scripts/commission.blade.php ENDPATH**/ ?>