<?php include '../header.php'; ?>
<?php include '../sidemenu.php'; ?>
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" /> -->
<!-- <style>
	#myTable {
		width: 120%;
	}
	#myTable td{
		width: 10%;
	}
	#myTable td:nth-child(5){
		width: 20%;
	}
	#myTable td:nth-child(1){
		width: 5%;
	}

</style> -->

<div class="content-wrapper" style="min-height: 1203.6px;">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<div class="container-fluid">
			<div class="row mb-2">
				<div class="col-md-6">
					<h3>Sales - Report</h3>
				</div>
				<div class="col-md-6">
				</div>
			</div>
		</div>
	</section>
	<section class="content">
		<div class="container-fluid">
			<div class="row" id="SS">
				<div class="col-md-12">
					<div class="card card-outline card-primary">
						<div class="card-header">
							<h3 class="card-title">Search</h3>
						</div>
						<div class="overlay white" id="loading" style="display:none;position: absolute;width: 100%;height: 100%;z-index: 1000;">
							<i class="fas fa-3x fa-sync-alt rotate360"  style="margin: 70px 45%;"></i>
						</div>
						<form role="form">
							<div class="card-body">
								<div class="row">
									<div class="col-md-6">

										<!-- <div class="form-group row">
											<label class="col-md-4 col-form-label" style="text-align: right;">Date From&nbsp;<input id="chkDateFrom" type="checkbox" checked >:</label>
											<div class="col-md-8">  
												<div class="input-group input-append date" id="datePicker1" data-date="2020-02-17" data-date-format="yyyy-mm-dd">
													<div class="input-group-prepend">
														<span class="input-group-addon input-group-text" style="width: 40px; display: table-cell;">
															<i class="far fa-calendar-alt"></i>
														</span>
													</div>
													<input type="text" name="daterange" value="01/01/2018 - 01/15/2018" />
												</div>
											</div>
										</div> -->
										
										<div class="form-group row">
											<label class="col-md-4 col-form-label" style="text-align: right;">Date From&nbsp;<input id="chkDateFrom" type="checkbox" checked >:</label>
											<div class="col-md-3">  
												<div class="input-group">
													<div class="input-group-prepend">
														<span class="input-group-text" style="width: 40px;">
															<i class="far fa-calendar-alt"></i>
														</span>
													</div>
													<input type="text" class="form-control" id="txtDatePicker" value="2020-02-04" aria-label="Date Picker" placeholder="Select a date">
												</div>
											</div>
											<label class="col-md-2 col-form-label" style="text-align: right;"> Date To: </label>
											<div class="col-md-3">  
												<div class="input-group">
													<div class="input-group-prepend">
														<span class="input-group-text" style="width: 40px;">
															<i class="far fa-calendar-alt"></i>
														</span>
													</div>
													<input type="text" class="form-control" id="txtDatePicker1" value="2020-02-04" aria-label="Date Picker" placeholder="Select a date">
												</div>
											</div>
										</div>
										<div class="form-group row">
											<label class="col-md-4 col-form-label" style="text-align: right;">City:</label>
											<div class="col-md-3">
												<div class="input-group input-group">
													<select type="text" class="form-control" id="cboCity"></select>
												</div>
											</div>
											<label class="col-md-2 col-form-label" style="text-align: right;">Type:</label>
											<div class="col-md-3">
												<div class="input-group input-group">
													<select type="text" class="form-control" id="cboSR">
														<option value=''>All</option>
														<option value='Sales'>Sales</option>
														<option value='Renew'>Renew</option>
													</select>
												</div>
											</div>
										</div>
                                        <div class="form-group row">
											<label class="col-md-4 col-form-label" style="text-align: right;">Invoice No.:</label>
											<div class="col-md-3">
												<input type="text" class="form-control" id="txtInvoiceNo">
											</div>
											<label class="col-md-2 col-form-label" style="text-align: right;">ID No.:</label>
											<div class="col-md-3">
												<input type="text" class="form-control" id="txtIDNo">
											</div>
										</div>

									</div>
									<div class="col-md-6">
										<div class="form-group row">
											<label class="col-md-4 col-form-label" style="text-align: right;">Customer Name:</label>
											<div class="col-md-3">
												<input type="text" class="form-control" id="txtCustomerName">
											</div>
											<label class="col-md-2 col-form-label" style="text-align: right;">Payment:</label>
											<div class="col-md-3">
												<select type="text" class="form-control" id="cboBalance">
													<option value="">All</option>
													<option value="y">Credit</option>
													<option value="n">Cash</option>
												</select>
											</div>	
										</div>
										<div class="form-group row">
										<label class="col-md-4 col-form-label" style="text-align: right;">Internet Plan:</label>
										<div class="col-md-3">
											<select type="text" class="form-control" id="cboMbps">

											</select>
										</div>
											<label class="col-md-2 col-form-label" style="text-align: right;">Months:</label>
											<div class="col-md-3">
												<select type="text" class="form-control" id="cboMonths">
													<option value=""></option>
													<option value=1>1</option>
													<option value=2>2</option>
													<option value=3>3</option>
													<option value=4>4</option>
													<option value=5>5</option>
													<option value=6>6</option>
													<option value=7>7</option>
													<option value=8>8</option>
													<option value=9>9</option>
													<option value=10>10</option>
													<option value=11>11</option>
													<option value=12>12</option>
												</select>
											</div>											
										</div>

										<div class="form-group row">
											<div class="col-md-6"></div>
											<div class="col-md-3" style="padding-bottom: 2px;">
												<button type="button" class="btn btn-primary btn-block" onclick="search()">Search</button>
											</div>
											<div class="col-md-3">
												<button type="button" id="btnExport" value=" Export Table data into Excel " datafrom="myTable" class="btn btn-success btn-block exportToExcel">Export Data</button> 
											</div>
										</div>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="card card-outline card-primary">
				<div class="card-header">
					<h3 class="card-title">Sales List<span id="total_records" style="font-weight:bold;"> </span></h3>
					<h3 class="card-title" style='padding-left:1000px;'> <span id="tb" style="font-weight:bold;"> </span></h3>
					<!-- <div class="card-tools">
						<button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
						<button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fas fa-remove"></i></button>
					</div> -->
				</div>
				<div class="card-body p-0 table-responsive " >
					<table class="table table-striped table-head-fixed table-bordered" id="myTable" style="max-height: 500px;">
						<thead>                  
							<tr>
								
								<th style="width: 3%;">#</th>
								<th style="text-align: center;min-width:100px;">Sales Date</th>
								<th style="text-align: center;min-width:130px;">Invoice No.</th>
								<th style="text-align: center;min-width:100px;">ID No.</th>
								<th style="text-align: center;min-width:200px;">Customer Name</th>
								<th style="text-align: center;min-width:100px;">Plan_Months</th>
								<th style="text-align: center;min-width:100px;">Price</th>
								<th style="text-align: center;min-width:100px;">Fee</th>
								<th style="text-align: center;min-width:100px;">Tax Charges</th>
								<th style="text-align: center;min-width:100px;">Normal Dis</th>
								<th style="text-align: center;min-width:100px;">Member Dis</th>
								<th style="text-align: center;min-width:100px;">Promotion Dis</th>
								<th style="text-align: center;min-width:100px;">Refund</th>
								<th style="text-align: center;min-width:100px;">Extra Charges</th>
								<th style="text-align: center;min-width:100px;">Total Amount</th>
								<th style="text-align: center;min-width:100px;">Payment</th>
								<th style="text-align: center;min-width:100px;">Balance</th>
								<th style="text-align: center;min-width:110px;">Action</th>
								<th style="text-align: center;min-width:200px;">Entry By</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>	

			<div class="modal fade modal-primary" id="myModalPayment">
				<div class="modal-dialog" style="max-width: 100% !important;">
					<div class="modal-content" style="width: 46%; top: 29px; margin-left: 28%;">
						<div class="modal-header">
							<h4 class="modal-title">Payment</h4>
						</div>
						<div class="modal-body">
							<div class="col-md-12">
								<div class="form-group row">
									<label class="col-md-4 col-form-label" style="text-align: right;">Date: </label>
									<div class="col-md-7">  
										<div class="input-group">
											<div class="input-group-prepend">
												<span class="input-group-text" style="width: 40px;">
													<i class="far fa-calendar-alt"></i>
												</span>
											</div>
											<input type="text" class="form-control" id="txtDatePicker2" value="2020-02-04" aria-label="Date Picker" placeholder="Select a date">
										</div>
									</div>
								</div>
								<div class="form-group row">
									<label class="col-md-4 col-form-label" style="text-align: right;">Payment Type</label>
									<div class="col-md-7">
										<select id="cboPaymentType" value='' class="form-control">
											<option value="Cash">Cash</option>
											<option value="KBZ">KBZ</option>
											<option value="KBZ Pay">KBZ Pay</option>
											<option value="AYA">AYA</option>
											<option value="CB">CB</option>
											<option value="OK$">OK$</option>
										</select>
									</div>
									<div class="col-md-1"></div>
								</div>
								<div class="form-group row">
									<label class="col-md-4 col-form-label" style="text-align: right;">Amount</label>
									<div class="col-md-7">
										<!-- <input type="text" class="form-control" id="txtCity1" style="display:none;"> -->
										<input type="text" class="form-control" id="txtAmount1" style="text-align: right;" onkeypress="return isNumber(event)"  value="0">
									</div>
									<div class="col-md-1"></div>
								</div>
								<div class="form-group row">
									<label class="col-md-7 col-form-label"></label>
									<div class="col-md-4">
										<button class="btn btn-primary col-md-12" type="button" onclick="addPayment();">Add</button>
									</div>
									<div class="col-md-1"></div>
								</div>
							</div>
							<div class="col-md-12">
								<div class="card card-outline ">
									<div class="card-body p-0">
										<table class="table table-striped table-bordered" id="myTable1">
											<thead>                  
												<tr>
													<th style="width: 10%;">Date</th>
													<th style="width: 20%;">Payment Type</th>
													<th style="width: 10%;">Amount</th>
													<th style="width: 2%;">Delete</th>
												</tr>
											</thead>
											<tbody>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>
	</section>
</div>
<?php include '../footer.php'; ?>
<script>
	var C = '<?php echo isset($_SESSION['city'])?$_SESSION['city']:"" ?>';
	var code = '<?php echo isset($_SESSION['code'])?$_SESSION['code']:"" ?>';
	var R = '<?php echo isset($_SESSION['userrole'])?$_SESSION['userrole']:"" ?>';
	var d = new Date();
	var mm = (d.getMonth("MM")+1);
	var dd = d.getDate();
	var customDate = d.getFullYear() + "-" + ((mm<10)?"0" + mm:mm) + "-" +  ((dd<10)?"0" + dd:dd);

	$(function(){

		$("body").addClass("sidebar-collapse");	
		$('#txtDatePicker, #txtDatePicker1, #txtDatePicker2').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',
			showButtonPanel: true,
            showAnim: 'clip',
            autoclose: true
        }).val(customDate);
		if(C=='Main Office'){
			getAllCity();
		}else{
			$("#cboCity").append("<option value= '" + C + "'  data-code= '" + code + "' >" + C + "</option>");	
			// getAll();
			getPackage();
		}

	});

	$(".exportToExcel").click(function(){
		exportExcel("#myTable");
	});

	$('#cboCity').change(function() { 
		getPackage();
	});

	function getAllCity(){
		$("#cboCity").find("option").remove();
		$("#cboCity").append("<option value= '' data-id = ''></option>");
		$.ajax({
			url: APP_URL + "api/city/get_all_rows.php"
		}).done(function(data) {
			$.each(data.records, function(i, v) {
				if(v.name!='Main Office'){
					$("#cboCity").append("<option value= '" + v.name + "' data-code= '" + v.code + "' >" + v.name + "</option>");	
				}
			});		
		});
	}

	$("#chkDateFrom").change(function(){
		if($("#chkDateFrom").prop("checked")){
			$("#txtDatePicker").attr("disabled",false);
			$("#txtDatePicker1").attr("disabled",false);
		}else{
			$("#txtDatePicker").attr("disabled",true);
			$("#txtDatePicker1").attr("disabled",true);
		}
	});

	function getPackage(){
		var city = $("#cboCity").val();
		// $("#cboPackage").find("option").remove();
		// $("#cboPackage").append("<option value = '' ></option>");
		$("#cboMbps").find("option").remove();
		$("#cboMbps").append("<option value = '' ></option>");

		$.ajax({
			url: APP_URL + "api/package/get_all_packages.php",
			type: "POST",
			data: JSON.stringify({ city: city })
		}).done(function(data) {	
			var mb = "";
			$.each(data.records, function(i, v) {	
				if(mb != v.mbps){
					$("#cboMbps").append("<option value= '" + v.mbps + "' >" + v.mbps + "</option>");	
				}	
				mb = v.mbps;			
			});
		});
	}	

	function search(){
		$("#loading").css("display","block");
		var df =($("#chkDateFrom").prop("checked"))?$("#txtDatePicker").val():"";
		var dt =($("#chkDateFrom").prop("checked"))?$("#txtDatePicker1").val():"";
		var invoice_no = $("#txtInvoiceNo").val();
		var id_no = $("#txtIDNo").val();
		var name = $("#txtCustomerName").val();
		var mbps = $("#cboMbps").val();
		var months = $("#cboMonths").val();
		var city = $("#cboCity").val();
		var S_R = $("#cboSR").val();
		var bal = $("#cboBalance").val();

		$("#myTable").find("tbody").find("tr").remove();
		$.ajax({
			type: "POST",
			url: APP_URL + "api/sales/search.php",
			data: JSON.stringify({ df: df,dt: dt,invoice_no: invoice_no,id_no: id_no,name: name, mbps: mbps, months: months, city: city, S_R: S_R,bal:bal }),
			error: function(data) {
				$("#loading").css("display","none");
			}
		}).done(function(data) {	
			if(data.records.length>1){
				$("#total_records").text(" - " + data.records.length + " records found.");
			}else{
				$("#total_records").text(" - " + data.records.length + " record found.");
			}
			$("#loading").css("display","none");
			// $("#myTable").find("tbody")
			// .append($('<tr style="font-weight:bold;">')
			// .append("<td colspan='8' style='text-align:right;'>Total:</td>")
			// .append("<td style='text-align:right;'>" + data.pccF + "</td>")
			// .append("<td style='text-align:right;'>" + data.total_amountF + "</td>")
			// .append("<td style='text-align:right;'>" + data.normal_discountF + "</td>")
			// .append("<td style='text-align:right;'>" + data.member_discountF + "</td>")
			// .append("<td style='text-align:right;'>" + data.promotion_discountF + "</td>")
			// .append("<td style='text-align:right;'>" + data.refundF + "</td>")
			// .append("<td style='text-align:right;'>" + data.paymentF + "</td>")
			// .append("<td style='text-align:right;'>" + data.balanceF + "</td>")
  			// );  
			$.each(data.records, function(i, v) {

			  
				$("#myTable").find("tbody")
				.append($('<tr>')
					.append("<td>" + (i+1) + "</td>")
                    .append("<td>" + v.sales_date + "</td>")
                    .append("<td>" + v.invoice_no + "</td>")
					.append("<td>" + v.id_no + "</td>")
					.append("<td>" + v.name + "</td>")
					.append("<td>" + v.package +"</td>")
					.append("<td style='text-align:right'>" + v.price + "</td>")
					.append("<td style='text-align:right'>" + v.fee + "</td>")
					.append("<td style='text-align:right'>" + v.tax_charges + "</td>")
					.append("<td style='text-align:right'>" + v.normal_discount + "</td>")
					.append("<td style='text-align:right'>" + v.member_discount + "</td>")
					.append("<td style='text-align:right'>" + v.promotion_discount + "</td>")
					.append("<td style='text-align:right'>" + v.refund + "</td>")
					.append("<td style='text-align:right'>" + v.pcc + "</td>")
                    .append("<td style='text-align:right'>" + v.total_amount + "</td>")
					.append("<td style='text-align:right;background-color: #b7eea7;cursor:pointer;' onclick='payment(\"" + v.invoice_no + "\",\"" + v.city + "\",this)'>" + v.payment + "</td>")
					.append("<td style='text-align:right'>" + v.balance + "</td>")
					// .append("<td style='text-align:center;'><span class='btn btn-danger btn-sm fas fas fa-trash-alt' style='cursor: pointer;padding: 5px 9px 5px 10px;font-size: 17px;' onclick='delSales(\"" + v.invoice_no + "\",this)' title='Delete'></span></td>")
					// .append("<td style='text-align:center;'><span class='btn btn-success btn-sm' style='cursor:pointer; font-size: 12px; width: 40px;' onclick='payment(\"" + v.invoice_no + "\",\"" + v.city + "\",this)'><i class='fas fa-dollar-sign' title='Payment'></i></span></td>")
					// .append("<td style='text-align:center;'><span class='btn btn-success btn-sm' style='cursor:pointer; font-size: 12px; width: 40px;' onclick='payment(\"" + v.invoice_no + "\",\"" + v.city + "\",this)'><i class='fas fa-dollar-sign' title='Payment'></i></span>&nbsp;"+ ((C=="Main Office")?"<span class='btn btn-primary btn-sm' style='cursor:pointer; font-size: 12px; width: 40px;' onclick='edit(\"" + v.id + "\",this)'><i class='fas fa-edit' title='Edit'></i></span>":"") +"</td>")
                    .append("<td style='text-align:center;' ><span class='btn btn-success btn-sm' style='cursor:pointer; font-size: 13px; width: 40px;' onclick='print(\"" + v.id + "\",this)'><i class='fas fa-print' title='Print'></i></span>&nbsp;"+ ((R.includes("Admin"))?"<span class='btn btn-danger btn-sm' style='cursor:pointer; font-size: 13px; width: 40px;' onclick='deleteS(\"" + v.invoice_no + "\",\"" + v.id_no + "\",this)'><i class='fas fa-trash' title='Delete'></i></span>":"") +"</td>")
					.append("<td>" + v.entry_by + "</td>")
				);
			});	

			$("#myTable").find("tbody")
			.append($('<tr style="font-weight:bold;">')
			.append("<td colspan='8' style='text-align:right;'>Total:</td>")
			.append("<td style='text-align:right;'>" + data.taxF + "</td>")
			.append("<td style='text-align:right;'>" + data.normal_discountF + "</td>")
			.append("<td style='text-align:right;'>" + data.member_discountF + "</td>")
			.append("<td style='text-align:right;'>" + data.promotion_discountF + "</td>")
			.append("<td style='text-align:right;'>" + data.refundF + "</td>")
			.append("<td style='text-align:right;'>" + data.pccF + "</td>")
			.append("<td style='text-align:right;'>" + data.total_amountF + "</td>")
			.append("<td style='text-align:right;'>" + data.paymentF + "</td>")
			.append("<td style='text-align:right;'>" + data.balanceF + "</td>")
  			);  
			//   $("#tb").text("Balance - " + data.balanceF);
       });
	}	

	function print(vid,obj){
		window.open(APP_URL + "print/sales_print.php?vid=" + vid  , "_blank");
		// document.location = APP_URL + "expense/purchase.php?pid=" + id  , "_blank";
	}

		function deleteS(id,idno,obj){
		bootbox.confirm({
			message: "<h4>Are you sure that you want to delete?</h4>",
			buttons: {
				confirm: {
					label: '<span class="glyphicon glyphicon-ok"></span> Yes',
					className: 'btn-danger'
				},
				cancel: {
					label: '<span class="glyphicon glyphicon-remove"></span> No',
					className: 'btn-primary'
				}
			},
			callback: function (result) {
				if(result){
					$.ajax({
					type: "POST",
					url: APP_URL + "api/sales/delete.php",
					data: JSON.stringify({ inv: id, id_no:idno }),
					success: function(data){
						if(data=="deleted"){
							$(obj).parent().parent().remove();
							
						}else{
							bootbox.alert("Error on server side.");
						}
					}
					});
				}
			}
		});
	}


	function payment(ino,cc,obj){
		$("#myModalPayment").modal('show');
		INO = ino;
		CC = cc;
		$("#myTable1").find("tbody tr").remove();
		$.ajax({
			url: APP_URL + "api/payment/get_one_payment.php",
			type: "POST",
			data: JSON.stringify({ ino: ino })
		}).done(function(data){
			console.log(data)
				$.each(data, function(i, v) {
					$("#myTable1").find("tbody")
						.append($('<tr>')
							// .append("<td style='width: 10px'>" + ($("#myTable1P tbody tr").length +1) + "</td>")
							.append("<td>" + v.date + "</td>")
							.append("<td>" + v.payment_type + "</td>")
							.append("<td  style='text-align:right;'>" + v.amount + "</td>")
							.append("<td style='text-align:center'><span class='btn btn-danger btn-sm fas fas fa-trash-alt' style='cursor: pointer;padding: 5px 9px 5px 10px;font-size: 17px;' onclick='del(\"" + v.id + "\",this)' title='Delete'></span></td>")
						)
				});
				// $("#txtTotalAmountP").val(data.t);
		});
		
	}

	function addPayment(){
		var date = $("#txtDatePicker2").val();
		var payment_type = $("#cboPaymentType").val();
		var amount = (parseInt($("#txtAmount1").val().replace(/,/g, '')))? (parseInt($("#txtAmount1").val().replace(/,/g, ''))):0; 

		if(amount == "0" ){
		bootbox.alert("Please fill the amount.");
		}else{
		$.ajax({
			url: APP_URL + "api/payment/create.php",
			type: "POST",
			data: JSON.stringify({ ino: INO, city: CC, date: date, payment_type: payment_type, amount: amount })
		}).done(function(data) {
			if(data.message=="created"){
				$("#myTable1").find("tbody")
				.prepend($('<tr>')
					.append("<td style='width: 10px'>" + date + "</td>")
					.append("<td>" + payment_type + "</td>")
					.append("<td style='text-align:right'>" + parseInt(amount).toLocaleString() + "</td>")
					.append("<td style='text-align:center'><span class='btn btn-danger btn-sm fas fas fa-trash-alt' style='cursor: pointer;padding: 5px 9px 5px 10px;font-size: 17px;' onclick='del(\"" + data.id + "\",this)' title='Delete'></span></td>")
				);
				$("#txtAmount1").val(0);
                // getList();
				// search();
                
			}else{
				bootbox.alert("Error on server side.");
			}
		});
		}
	}

	function delSales(inv, obj){
        // bootbox for good looking 'confirm pop up'
        bootbox.confirm({
        	message: "<h4>Are you sure that you want to delete?</h4>",
        	buttons: {
        		confirm: {
        			label: '<span class="glyphicon glyphicon-ok"></span> Yes',
        			className: 'btn-danger'
        		},
        		cancel: {
        			label: '<span class="glyphicon glyphicon-remove"></span> No',
        			className: 'btn-primary'
        		}
        	},
        	callback: function (result) {
        		if(result){
        			$.ajax({
        				type: "POST",
        				url: APP_URL + "api/sales/delete.php",
        				data: JSON.stringify({ inv: inv }),
        				success: function(data){
        					if(data=="deleted"){
        						$(obj).parent().parent().remove();
        					}else{
        						bootbox.alert("Error on server side.");
        					}
        				}
        			});
        		}
        	}
        });
    }

	function del(id,obj){
		bootbox.confirm({
			message: "<h4>Are you sure that you want to delete?</h4>",
			buttons: {
				confirm: {
					label: '<span class="glyphicon glyphicon-ok"></span> Yes',
					className: 'btn-danger'
				},
				cancel: {
					label: '<span class="glyphicon glyphicon-remove"></span> No',
					className: 'btn-primary'
				}
			},
			callback: function (result) {
				if(result){
					$.ajax({
					type: "POST",
					url: APP_URL + "api/payment/delete.php",
					data: JSON.stringify({ id: id }),
					success: function(data){
						if(data=="deleted"){
							$(obj).parent().parent().remove();
							getList();
						}else{
							bootbox.alert("Error on server side.");
						}
					}
					});
				}
			}
		});
	}

	function goToDetail(id,obj){
		document.location = APP_URL + "entry/sales.php?id=" + id;
	}	

	// function edit(id){
	// 	document.location = APP_URL + "entry/sales_edit.php?id=" + id;
	// }	

	function edit(id,obj){
		window.open(APP_URL + "entry/sales_edit.php?id=" + id  , "_blank");
		// document.location = APP_URL + "expense/purchase.php?pid=" + id  , "_blank";
	}



	function isNumber(evt) {
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if ( (charCode > 31 && charCode < 48) || charCode > 57) {
			return false;
		}
		return true;
	}
	
</script>	
