+ if ($adj_only)
+ {
+ if ($qty != 0)
+ $costs = $qty * $costs;
+ if ($qoh>0)
+ $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
+ else // Journal Entry if QOH is 0/negative
+ {
+ global $Refs;
+
+ $id = get_next_trans_no(ST_JOURNAL);
+ $ref = $Refs->get_next(ST_JOURNAL);
+
+ $stock_gl_code = get_stock_gl_code($stock_id);
+ $memo = "WO Overhead cost settlement JV for zero/negative respository of ".$stock_id;
+ //Reverse the inventory effect if $qoh <=0
+ add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
+ $stock_gl_code["inventory_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
+ -$costs);
+ //GL Posting to inventory adjustment account
+ add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
+ $stock_gl_code["assembly_account"], // changed 2015.10.14 from adjustment to assembly account. Petros.
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
+ $costs);
+
+ add_audit_trail(ST_JOURNAL, $id, $date_);
+ add_comments(ST_JOURNAL, $id, $date_, $memo);
+ $Refs->save(ST_JOURNAL, $id, $ref);
+ if ($qty != 0) // 27.10.2014 dz
+ $overhead_cost = ($qoh * $overhead_cost + $costs) / $qty;
+ }
+ }
+ else
+ {
+ if ($qoh + $qty != 0)
+ $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty);
+ }
+ $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=overhead_cost+".db_escape($overhead_cost)."