- begin_transaction();
-
- $myrow = get_grn_item_detail($id);
-
- $grn = get_grn_batch($myrow['grn_batch_id']);
-
- $supp = get_supplier($grn["supplier_id"]);
-
- $sql = "UPDATE ".TB_PREF."purch_order_details
- SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
- db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
-
- $sql = "UPDATE ".TB_PREF."grn_items
- SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
- db_query($sql, "The quantity invoiced off the items received record could not be updated");
-
- update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
- $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
-
- $price = $myrow['unit_price'];
- if ($supp['tax_included'])
- $price = get_tax_free_price_for_item($myrow['item_code'], $myrow['unit_price'], $supp['tax_group_id'], $supp['tax_included']);
-
- add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
- -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $price);
-
- $clearing_act = get_company_pref('grn_clearing_act');
- if ($clearing_act) { // otherwise GRN clearing account is not used
- if (is_inventory_item($myrow['item_code']))
- {
- $total = 0;
- $stock_gl_code = get_stock_gl_code($myrow['item_code']);
- $date = sql2date($grn["delivery_date"]);
- $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $stock_gl_code["inventory_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- -$myrow['QtyOstdg'] * $price, $grn["supplier_id"], "", 0, _("GRN Removal"));
- $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $clearing_act,
- 0, 0, -$total, null, "", 0, _("GRN Removal"));
- }
- }
-
- commit_transaction();
+ $invoices = $po_ids = array();
+ foreach($cart->grn_items as $item)
+ $po_ids[] = "'$item->po_detail_item'"; // credit item lines
+
+ if (count($po_ids)) {
+ $sql = "SELECT DISTINCT trans.trans_no, trans.reference, trans.supp_reference
+ FROM ".TB_PREF."supp_invoice_items items
+ LEFT JOIN ".TB_PREF."supp_trans trans ON trans.trans_no=items.supp_trans_no AND trans.`type`=items.supp_trans_type
+ WHERE items.po_detail_item_id IN (" . implode(',', $po_ids). ")"." AND items.supp_trans_type=20";
+ $result = db_query($sql, "cannot find source invoice details");
+ while ($rec = db_fetch($result))
+ {
+ $invoices[$rec['trans_no']] = $rec['supp_reference']; // array($rec['reference'], $rec['supp_reference']);
+ }
+ }
+ return $invoices;