我正在使用一个代码,用于将表单数据上传到mysql,并通过电子邮件发送给用户。这段代码完美无缺,但它只发送订单的最后一项详细信息而不是所有项目请告诉我该怎么做。
此代码在.inc
文件下运行
这是sales_order_db.inc
文件
$time = date("d/m/y H:i:s", time());
$result1 = mysql_query("SELECT * FROM balance_report WHERE Reg_No IN ($order->customer_id)");
while($row1 = mysql_fetch_array($result1))
{
$balance = $row1['Balance'];
$tbalance = $balance - $total;
}
$from = 'from: smartcard@lotus.edu.in';
$to = $order->delivery_address;
$subject = ("Rs: " . $total . ' , Debit - SmartCard');
$emailBody="";
$emailBody .= ("Dear, " . $order->deliver_to . "\r\n" . "\r\n" . " \r\n"."Tran. No : " . $tran . "\r\n" . "Debit Amount : Rs " . $total . "\r\n" . "Balance : Rs " . $tbalance . "\r\n" . "Date : " . $time . "\r\n" . "\r\n" . "
For more details login to http://162.9.9.9/smartcard" . "\r\n" . "\r\n" . "\r\n" . "Thanks," . "\r\n" . "Lotus Institute of Management.");
$emailBody .= "$line->stock_id"."$line->item_description"."$line->price"."$line->quantity";
mail($to, $subject, $emailBody, $from);
此行$emailBody .= "$line->stock_id"."$line->item_description"."$line->price"."$line->quantity";
仅发送最后一行但不是所有行,我想发送所有订单详情。
这是我的sql语句
foreach ($order->line_items as $line)
{
if ($loc_notification == 1 && is_inventory_item($line->stock_id))
{
$sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "'
AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
$res = db_query($sql,"a location could not be retreived");
$loc = db_fetch($res);
if ($loc['email'] != "")
{
$qoh = get_qoh_on_date($line->stock_id, $order->Location);
$qoh -= get_demand_qty($line->stock_id, $order->Location);
$qoh -= get_demand_asm_qty($line->stock_id, $order->Location);
$qoh -= $line->quantity;
if ($qoh < $loc['reorder_level'])
{
$st_ids[] = $line->stock_id;
$st_names[] = $line->item_description;
$st_num[] = $qoh - $loc['reorder_level'];
$st_reorder[] = $loc['reorder_level'];
}
}
}
$sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, trans_type, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
$sql .= $order_no . ",".$order->trans_type .
",".db_escape($line->stock_id).", "
.db_escape($line->item_description).", $line->price,
$line->quantity,
$line->discount_percent)";
db_query($sql, "order Details Cannot be Added");
这是文件的完整代码
//----------------------------------------------------------------------------------------
function add_sales_order(&$order)
{
global $loc_notification, $path_to_root, $Refs;
begin_transaction();
hook_db_prewrite($order, $order->trans_type);
$order_no = get_next_trans_no($order->trans_type);
$del_date = date2sql($order->due_date);
$order_type = 0; // this is default on new order
$total = $order->get_trans_total();
$sql = "INSERT INTO ".TB_PREF."sales_orders (order_no, type, debtor_no, trans_type, branch_code, customer_ref, reference, comments, ord_date,
order_type, ship_via, deliver_to, delivery_address, contact_phone,
freight_cost, from_stk_loc, delivery_date, payment_terms, total)
VALUES (" .db_escape($order_no) . "," .db_escape($order_type) . "," . db_escape($order->customer_id) .
", " .db_escape($order->trans_type) . "," .db_escape($order->Branch) . ", ".
db_escape($order->cust_ref) .",".
db_escape($order->reference) .",".
db_escape($order->Comments) .",'" .
date2sql($order->document_date) . "', " .
db_escape($order->sales_type) . ", " .
db_escape($order->ship_via)."," .
db_escape($order->deliver_to) . "," .
db_escape($order->delivery_address) . ", " .
db_escape($order->phone) . ", " .
db_escape($order->freight_cost) .", " .
db_escape($order->Location) .", " .
db_escape($del_date) . "," .
db_escape($order->payment) . "," .
db_escape($total). ")";
db_query($sql, "order Cannot be Added");
$order->trans_no = array($order_no=>0);
if ($loc_notification == 1)
{
include_once($path_to_root . "/inventory/includes/inventory_db.inc");
$st_ids = array();
$st_names = array();
$st_num = array();
$st_reorder = array();
}
foreach ($order->line_items as $line)
{
if ($loc_notification == 1 && is_inventory_item($line->stock_id))
{
$sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "'
AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
$res = db_query($sql,"a location could not be retreived");
$loc = db_fetch($res);
if ($loc['email'] != "")
{
$qoh = get_qoh_on_date($line->stock_id, $order->Location);
$qoh -= get_demand_qty($line->stock_id, $order->Location);
$qoh -= get_demand_asm_qty($line->stock_id, $order->Location);
$qoh -= $line->quantity;
if ($qoh < $loc['reorder_level'])
{
$st_ids[] = $line->stock_id;
$st_names[] = $line->item_description;
$st_num[] = $qoh - $loc['reorder_level'];
$st_reorder[] = $loc['reorder_level'];
}
}
}
$sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, trans_type, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
$sql .= $order_no . ",".$order->trans_type .
",".db_escape($line->stock_id).", "
.db_escape($line->item_description).", $line->price,
$line->quantity,
$line->discount_percent)";
db_query($sql, "order Details Cannot be Added");
// Now mark quotation line as processed
if ($order->trans_type == ST_SALESORDER && $line->src_id)
update_parent_line(ST_SALESORDER, $line->src_id, $line->qty_dispatched); // clear all the quote despite all or the part was ordered
} /* inserted line items into sales order details */
add_audit_trail($order->trans_type, $order_no, $order->document_date);
$Refs->save($order->trans_type, $order_no, $order->reference);
hook_db_postwrite($order, $order->trans_type);
commit_transaction();
if ($loc_notification == 1 && count($st_ids) > 0)
{
require_once($path_to_root . "/reporting/includes/class.mail.inc");
$company = get_company_prefs();
$mail = new email($company['coy_name'], $company['email']);
$from = $company['coy_name'] . " <" . $company['email'] . ">";
$to = $loc['location_name'] . " <" . $loc['email'] . ">";
$subject = _("Stocks below Re-Order Level at " . $loc['location_name']);
$msg = "\n";
for ($i = 0; $i < count($st_ids); $i++)
$msg .= $st_ids[$i] . " " . $st_names[$i] . ", " . _("Re-Order Level") . ": " . $st_reorder[$i] . ", " . _("Below") . ": " . $st_num[$i] . "\n";
$msg .= "\n" . _("Please reorder") . "\n\n";
$msg .= $company['coy_name'];
$mail->to($to);
$mail->subject($subject);
$mail->text($msg);
$ret = $mail->send();
}
$result2 = mysql_query("SELECT * FROM 0_debtor_trans WHERE order_ IN ($order_no-1) and type = '10'");
while($row2 = mysql_fetch_array($result2))
{
echo $row2['trans_no'];
$tra = $row2['trans_no'];
$tran = $tra +1;
}
$time = date("d/m/y H:i:s", time());
$result1 = mysql_query("SELECT * FROM balance_report WHERE Reg_No IN ($order->customer_id)");
while($row1 = mysql_fetch_array($result1))
{
$balance = $row1['Balance'];
$tbalance = $balance - $total;
}
$from = 'from: smartcard@lotus.edu.in';
$to = $order->delivery_address;
$subject = ("Rs: " . $total . ' , Debit - SmartCard');
$emailBody="";
$emailBody .= ("Dear, " . $order->deliver_to . "\r\n" . "\r\n" . " \r\n"."Tran. No : " . $tran . "\r\n" . "Debit Amount : Rs " . $total . "\r\n" . "Balance : Rs " . $tbalance . "\r\n" . "Date : " . $time . "\r\n" . "\r\n" . "
For more details login to http://162.9.9.9/smartcard" . "\r\n" . "\r\n" . "\r\n" . "Thanks," . "\r\n" . "Lotus Institute of Management.");
$emailBody .= "$line->stock_id"."$line->item_description"."$line->price"."$line->quantity";
mail($to, $subject, $emailBody, $from);
return $order_no;
}
答案 0 :(得分:0)
我认为问题在这里
while($row1 = mysql_fetch_array($result1))
{
$balance = $row1['Balance'];
$tbalance = $balance - $total;
}
这就是你得到最后一个结果的原因,你需要在while中计算总余额,然后在发送时使用它。