我在console.log上获取了所有数据,但是当我在codeigniter中发送给控制器时,表中未插入多行数据,而是插入了其他数据
我已经尝试了所有功能,但是我找不到任何解决方案。
我的jquery代码是
$(document).ready(function(){
var DOMAIN = "http://localhost/admin/";
addNewRow();
$("#add").click(function(){
addNewRow();
})
function addNewRow(){
$.ajax({
url : DOMAIN+"welcome/fetch_single_details",
method : "POST",
data : {getNewOrderItem:1},
success : function(data){
$("#invoice_item").append(data);
var n = 0;
$(".number").each(function(){
$(this).html(++n);
})
}
})
}
$("#remove").click(function(){
$("#invoice_item").children("tr:last").remove();
calculate(0,0);
})
$("#invoice_item").delegate(".sid","change",function(){
var sid = $(this).val();
var id = sid;
//alert(id);
var tr = $(this).parent().parent();
$.ajax({
url : DOMAIN+"welcome/fetchService1",
method : "POST",
dataType : "json",
data : {getSingleRecord:1,id:id},
success : function(data){
//console.log(data);
var detail = '';
//var uname = response[0].username;
var detail = data[0].service_detals;
var detail =($(detail).text());
//var detail = html("detail").text();
var price = data[0].price;
//console.log(price);
//console.log(detail);
tr.find(".service_detals").val(detail);
tr.find(".price").val(price);
tr.find(".amt").html( price );
calculate(0,0);
}
})
})
function calculate(dis,paid){
var sub_total = 0;
var gst = 0;
var net_total = 0;
var discount = dis;
var paid_amt = paid;
var due = 0;
var given_change = 0;
$(".amt").each(function(){
sub_total = sub_total + ($(this).html() * 1);
})
gst = 0.05 * sub_total;
net_total = gst + sub_total;
//console.log(sub_total);
net_total = net_total - discount;
net_total = net_total.toFixed(2);
due = net_total - paid_amt;
gst = gst.toFixed(2);
due = due.toFixed(2);
if(due < 0){
given_change = -1 * due;
due = 0;
} else {
due = due;
}
$("#gst").val(gst);
$("#sub_total").val(sub_total);
$("#discount").val(discount);
$("#net_total").val(net_total);
$("#given_change").val(given_change);
//$("#paid")
$("#due").val(due);
}
$("#discount").keyup(function(){
var discount = $(this).val();
calculate(discount,0);
})
$("#paid").keyup(function(){
var paid = $(this).val();
var discount = $("#discount").val();
calculate(discount,paid);
})
/*Order Accepting*/
$("#order_form").click(function(){
var invoice = $("#get_order_data").serialize();
if ($("#cust_name").val() === "") {
alert("Plaese select customer name");
}else if($("#paid").val() === ""){
alert("Plaese eneter paid amount");
}else{
//console.log(invoice);
//console.log(order_date);
$.ajax({
url : DOMAIN+"welcome/orderUpdates",
method : "POST",
data : $("#get_order_data").serialize(),
//data : invoice,
success : function(data){
if (data < 0) {
alert(data);
}else{
console.log(invoice);
//window.location.href = 'orderUpdate';
//url : DOMAIN+"welcome/orderUpdate",
$("#get_order_data").trigger("reset");
//if (confirm("Do u want to print invoice ?")) {
// window.location.href = DOMAIN+"/includes/invoice_bill.php?invoice_no="+data+"&"+invoice;
//}
}
}
});
}
});
});
我的控制器代码是 公共功能orderUpdate(){
if (isset($_POST["order_date"]) AND isset($_POST["cust_name"])) {
$created_by = 1;
$orderdate = $_POST["order_date"];
$cust_name = $_POST["cust_name"];
//Now getting array from order_form
$ar_service_detals = $_POST["service_detals"];
$ar_name = $_POST["user_name"];
$ar_price = $_POST["price"];
$ar_service_name = $_POST["sid"];
//$order_id = 1;
$sub_total = $_POST["sub_total"];
$gst = $_POST["gst"];
$discount = $_POST["discount"];
$net_total = $_POST["net_total"];
$paid = $_POST["paid"];
$given_change = $_POST["given_change"];
$due = $_POST["due"];
$payment_type = $_POST["payment_type"];
//$orderInfo = array('created_by'=>$created_by,'customer_id'=>$cust_name,'invioce_date'=>$orderdate,'sub_total'=>$sub_total,'vat'=>$gst,'discount'=>$discount,'net_total'=>$net_total,'paid'=>$paid,'given_change'=>$given_change,'due'=>$due,'payment_type'=>$payment_type);
//$result = $this->Test_model->storeCustomerOrderInvoice($orderInfo,$orderdetailInfo);
echo $result = $this->Test_model->storeCustomerOrderInvoice($created_by, $orderdate,$cust_name,$ar_service_detals,$ar_name,$ar_price,$ar_service_name,$sub_total,$gst,$discount,$net_total,$paid,$given_change, $due,$payment_type);
}
} 我的模型代码是 函数storeCustomerOrderInvoice($ created_by,$ orderdate,$ cust_name,$ ar_service_detals,$ ar_name,$ ar_price,$ ar_service_name,$ sub_total,$ gst,$ discount,$ net_total,$ paid,$ given_change,$ due,$ payment_type){< / p>
$orderInfo = array('created_by'=>$created_by,'customer_id'=>$cust_name,'invioce_date'=>$orderdate,'sub_total'=>$sub_total,'vat'=>$gst,'discount'=>$discount,'net_total'=>$net_total,'paid'=>$paid,'given_change'=>$given_change,'due'=>$due,'payment_type'=>$payment_type);
// $this->db->trans_start();
$this->db->insert('tbl_order', $orderInfo);
$insert_id = $this->db->insert_id();
// $this->db->trans_complete();
return $insert_id;
$ar_service_detals = $_POST["service_detals"];
$ar_name = $_POST["user_name"];
$ar_price = $_POST["price"];
$ar_service_name = $_POST["sid"];
$count = count($ar_price);
for($i = 0; $i<$count; $i++){
$entries[] = array(
'order_id'=>$entries['insert_id'][$i],
'service_name_id'=>$entries['ar_service_name'][$i],
'price'=>$entries['ar_price'][$i],
'user_name_id'=>$entries['ar_name'][$i],
'service_detals'=>$entries['ar_service_detals'][$i],
);
}
$this->db->insert_batch('tble_order_details', $entries);
if($this->db->affected_rows() > 0){
return 1;}
else{
return 0;
}