2014-01-24 62 views
0

我正在使用代碼將表單數據上傳到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: [email protected]'; 
$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: [email protected]'; 
$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

檢查我的編輯我已添加sql語句 – user3210029

+0

您現在發佈的代碼與您之前發佈的代碼有什麼關係?他們似乎沒有什麼關係。 – 2014-01-24 07:12:19

回答

0

的完整代碼,我覺得問題就在這裏

while($row1 = mysql_fetch_array($result1)) 
    { 
$balance = $row1['Balance']; 
$tbalance = $balance - $total; 
    } 

這就是爲什麼你得到最後的結果,您需要在計算時計算總餘額,然後在發送時使用。

相關問題