+ $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'], $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();
+}
+
+function find_src_invoices($cart)
+{
+ $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;
+}