ajax.php içeriğine ihtiyacımız olacak sanırım ve bununla ilişkili olan js dosyasının içeriği..
birde müşteri bölümünü çekmiyor derken, ekran görüntülerinde müşteriyle alakalı bir şey görünmüyor
Şöyle anlatayım satış sayfası bu görünen kısımda ekleme yapılıyor. Müşteri bölümüde eklemek istiyorum tabloya müşteri adını ekleyip veri tabanına eklemeye çalıştım satış ve satış ekle dosyalarını düzenledim fakat olmadı. Kısacası satış sayfasında tabloda ek olarak müşteri adınıda eklemek istiyorum.
Ajax.php
<?php
require_once('includes/load.php');
if (!$session->isUserLoggedIn(true)) { redirect('index.php', false);}
?>
<?php
// Auto suggetion
$html = '';
if(isset($_POST['product_name']) && strlen($_POST['product_name']))
{
$products = find_product_by_title($_POST['product_name']);
if($products){
foreach ($products as $product):
$html .= "<li class=\"list-group-item\">";
$html .= $product['name'];
$html .= "</li>";
endforeach;
} else {
$html .= '<li onClick=\"fill(\''.addslashes().'\')\" class=\"list-group-item\">';
$html .= 'Not found';
$html .= "</li>";
}
echo json_encode($html);
}
?>
<?php
// find all product
if(isset($_POST['p_name']) && strlen($_POST['p_name']))
{
$product_title = remove_junk($db->escape($_POST['p_name']));
if($results = find_all_product_info_by_title($product_title)){
foreach ($results as $result) {
$html .= "<tr>";
$html .= "<td id=\"s_name\">".$result['name']."</td>";
$html .= "<input type=\"hidden\" name=\"s_id\" value=\"{$result['id']}\">";
$html .= "<td>";
$html .= "<input type=\"text\" class=\"form-control\" name=\"price\" value=\"{$result['sale_price']}\">";
$html .= "</td>";
$html .= "<td id=\"s_qty\">";
$html .= "<input type=\"text\" class=\"form-control\" name=\"quantity\" value=\"1\">";
$html .= "</td>";
$html .= "<td>";
$html .= "<input type=\"text\" class=\"form-control\" name=\"total\" value=\"{$result['sale_price']}\">";
$html .= "</td>";
$html .= "<td>";
$html .= "<input type=\"date\" class=\"form-control datePicker\" name=\"date\" data-date data-date-format=\"yyyy-mm-dd\">";
$html .= "</td>";
$html .= "<td>";
$html .= "<button type=\"submit\" name=\"add_sale\" class=\"btn btn-primary\">Add sale</button>";
$html .= "</td>";
$html .= "</tr>";
}
} else {
$html ='<tr><td>product name not resgister in database</td></tr>';
}
echo json_encode($html);
}
?>function.js
function suggetion() {
$('#sug_input').keyup(function(e) {
var formData = {
'product_name' : $('input[name=title]').val()
};
if(formData['product_name'].length >= 1){
// process the form
$.ajax({
type : 'POST',
url : 'ajax.php',
data : formData,
dataType : 'json',
encode : true
})
.done(function(data) {
//console.log(data);
$('#result').html(data).fadeIn();
$('#result li').click(function() {
$('#sug_input').val($(this).text());
$('#result').fadeOut(500);
});
$("#sug_input").blur(function(){
$("#result").fadeOut(500);
});
});
} else {
$("#result").hide();
};
e.preventDefault();
});
}
$('#sug-form').submit(function(e) {
var formData = {
'p_name' : $('input[name=title]').val()
};
// process the form
$.ajax({
type : 'POST',
url : 'ajax.php',
data : formData,
dataType : 'json',
encode : true
})
.done(function(data) {
//console.log(data);
$('#product_info').html(data).show();
total();
$('.datePicker').datepicker('update', new Date());
}).fail(function() {
$('#product_info').html(data).show();
});
e.preventDefault();
});
function total(){
$('#product_info input').change(function(e) {
var price = +$('input[name=price]').val() || 0;
var qty = +$('input[name=quantity]').val() || 0;
var total = qty * price ;
$('input[name=total]').val(total.toFixed(2));
});
}
$(document).ready(function() {
//tooltip
$('[data-toggle="tooltip"]').tooltip();
$('.submenu-toggle').click(function () {
$(this).parent().children('ul.submenu').toggle(200);
});
//suggetion for finding product names
suggetion();
// Callculate total ammont
total();
$('.datepicker')
.datepicker({
format: 'yyyy-mm-dd',
todayHighlight: true,
autoclose: true
});
});