5b9bea5268e659b927119039a09aebc90ef48890
[fa-stable.git] / manufacturing / includes / db / work_orders_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 //--------------------------------------------------------------------------------------
13
14 function add_material_cost($stock_id, $qty, $date_, $advanced=false, $woid=0)
15 {
16         $m_cost = 0;
17     $result = get_bom($stock_id);
18         while ($bom_item = db_fetch($result))
19         {
20                 $standard_cost = get_standard_cost($bom_item['component']);
21                 $m_cost += ($bom_item['quantity'] * $standard_cost);
22         }
23         $bom_cost = $m_cost;
24         // new Joe Hunt 2015.10.15      
25         // additilnal costs.
26         $i_cost = 0;
27         if ($woid != 0 && work_order_has_issues($woid))
28         {
29                 $res = get_additional_issues($woid);
30                 while ($issue = db_fetch($res))
31                 {
32                         $standard_cost = get_standard_cost($issue['stock_id']);
33                         $i_cost += ($issue['qty_issued'] * $standard_cost) / $qty;
34                 }
35         }
36         $sql = "SELECT material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
37                 .db_escape($stock_id);
38         $result = db_query($sql);
39         $myrow = db_fetch($result);
40         $material_cost =  $myrow['material_cost'] - $i_cost; // $i_cost was already added to material cost
41         $m_cost += $i_cost;
42         /* no, why will we do that?? Joe Hunt 2015.10.17
43         if ($advanced)
44         {
45                 //reduce overhead_cost and labour_cost from price as those will remain as is
46                 $m_cost = $m_cost - $myrow['labour_cost'] - $myrow['overhead_cost'];
47         }
48         */
49         $qoh = get_qoh_on_date($stock_id);
50         $cost_adjust = false;
51         if ($qoh < 0)
52         {
53                 if ($qoh + $qty >= 0)
54                         $cost_adjust = true;
55                 $qoh = 0;
56         }               
57         if ($qoh + $qty != 0)
58         {
59                 if ($qoh == 0) // 27.10.2014 apmuthu and dz.
60                         $material_cost = $m_cost;
61                 else    
62                         $material_cost = ($qoh * $material_cost + $qty * $m_cost) /     ($qoh + $qty);
63         }
64         if ($advanced && $cost_adjust) // new 2010-02-10
65                 adjust_deliveries($stock_id, $bom_cost, $date_);        
66         
67         $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
68                     WHERE stock_id=".db_escape($stock_id);
69         db_query($sql,"The cost details for the inventory item could not be updated");
70 }
71
72 function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
73 {
74         if ($qty != 0)
75                 $costs /= $qty;
76         $sql = "SELECT overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
77                 .db_escape($stock_id);
78         $result = db_query($sql);
79         $myrow = db_fetch($result);
80         $overhead_cost =  $myrow['overhead_cost'];
81         $qoh = get_qoh_on_date($stock_id);
82         if ($qoh < 0)
83                 $qoh = 0;
84         if ($adj_only)
85         {
86                 if ($qoh>0)
87                 {
88                         if ($qoh + $qty != 0)   
89                                 $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);
90                         elseif ($qty == 0)
91                                 $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
92                 }                       
93                 else // Journal Entry if QOH is 0/negative 
94                 {
95                         global $Refs;
96
97                         $id = get_next_trans_no(ST_JOURNAL);
98                         $ref = $Refs->get_next(ST_JOURNAL);
99                         
100                         $stock_gl_code = get_stock_gl_code($stock_id);
101                         $memo = "WO Overhead cost settlement JV for zero/negative respository of ".$stock_id;
102                         //Reverse the inventory effect if $qoh <=0
103                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
104                                 $stock_gl_code["inventory_account"],
105                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, 
106                                 -$costs);
107                         //GL Posting to inventory adjustment account
108                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
109                                 $stock_gl_code["assembly_account"], // changed 2015.10.14 from adjustment to assembly account. Petros.
110                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
111                                 $costs);
112                                 
113                         add_audit_trail(ST_JOURNAL, $id, $date_);
114                         add_comments(ST_JOURNAL, $id, $date_, $memo);
115                         $Refs->save(ST_JOURNAL, $id, $ref);
116                         if ($qty != 0) // 27.10.2014 dz
117                                 $overhead_cost = ($qoh * $overhead_cost + $costs) / $qty;
118                 }
119         }
120         else
121         {               
122                 if ($qoh + $qty != 0)   
123                         $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);
124         }
125         $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=".db_escape($overhead_cost)."
126                 WHERE stock_id=".db_escape($stock_id);
127         db_query($sql,"The cost details for the inventory item could not be updated");
128 }
129
130 function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
131 {
132         if ($qty != 0)
133                 $costs /= $qty;
134         $sql = "SELECT labour_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
135                 .db_escape($stock_id);
136         $result = db_query($sql);
137         $myrow = db_fetch($result);
138         $labour_cost =  $myrow['labour_cost'];
139         $qoh = get_qoh_on_date($stock_id);
140         if ($qoh < 0)
141                 $qoh = 0;
142         if ($adj_only)
143         {
144                 if ($qoh>0)
145                 {
146                         if ($qoh + $qty != 0)   
147                                 $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);
148                         elseif ($qty == 0)
149                                 $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;
150                 }               
151                 else // Journal Entry if QOH is 0/negative 
152                 {
153                         global $Refs;
154
155                         $id = get_next_trans_no(ST_JOURNAL);
156                         $ref = $Refs->get_next(ST_JOURNAL);
157                         
158                         $stock_gl_code = get_stock_gl_code($stock_id);
159                         $memo = "WO labour cost settlement JV for zero/negative respository of ".$stock_id;
160                         //Reverse the inventory effect if $qoh <=0
161                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
162                                 $stock_gl_code["inventory_account"],
163                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, 
164                                 -$costs);
165                         //GL Posting to inventory adjustment account
166                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
167                                 $stock_gl_code["assembly_account"], // changed 2015.10.14 from adjustment to assembly account. Petros.
168                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
169                                 $costs);
170                                 
171                         add_audit_trail(ST_JOURNAL, $id, $date_);
172                         add_comments(ST_JOURNAL, $id, $date_, $memo);
173                         $Refs->save(ST_JOURNAL, $id, $ref);     
174                         if ($qty != 0) // 27.10.2014 dz
175                                 $labour_cost = ($qoh * $labour_cost + $costs) / $qty;
176                 }
177         }
178         else
179         {               
180                 if ($qoh + $qty != 0)   
181                         $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);
182         }       
183         $sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=".db_escape($labour_cost)."
184                 WHERE stock_id=".db_escape($stock_id);
185         db_query($sql,"The cost details for the inventory item could not be updated");
186 }
187
188 function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
189 {
190         if ($qty != 0)
191                 $costs /= $qty;
192         $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
193                 .db_escape($stock_id);
194         $result = db_query($sql);
195         $myrow = db_fetch($result);
196         $material_cost =  $myrow['material_cost'];
197         $qoh = get_qoh_on_date($stock_id);
198         if ($qoh < 0)
199                 $qoh = 0;
200         if ($adj_only)
201         {
202                 if ($qoh>0)
203                         $material_cost = ($qoh * $material_cost + $costs) / $qoh;
204                 else // Journal Entry if QOH is 0/negative
205                 {
206                         global $Refs;
207
208                         $id = get_next_trans_no(ST_JOURNAL);
209                         $ref = $Refs->get_next(ST_JOURNAL);
210                         
211                         $stock_gl_code = get_stock_gl_code($stock_id);
212                         $memo = "WO Issue settlement JV for zero/negative respository of ".$stock_id;
213                         //Reverse the inventory effect if $qoh <=0
214                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
215                                 $stock_gl_code["inventory_account"],
216                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, 
217                                 -$costs);
218                         //GL Posting to inventory adjustment account
219                         add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
220                                 $stock_gl_code["assembly_account"], // changed 2015.10.14 from adjustment to assembly account. Petros.
221                                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
222                                 $costs);
223                                 
224                         add_audit_trail(ST_JOURNAL, $id, $date_);
225                         add_comments(ST_JOURNAL, $id, $date_, $memo);
226                         $Refs->save(ST_JOURNAL, $id, $ref);
227                         if ($qty != 0) // 27.10.2014 dz
228                                 $material_cost = $costs / $qty; 
229                 }
230         }
231         else
232         {
233                 if ($qoh + $qty != 0)   
234                         $material_cost = ($qoh * $material_cost + $qty * $costs) /      ($qoh + $qty);
235         }       
236         $sql = "UPDATE ".TB_PREF."stock_master SET material_cost="
237                 .db_escape($material_cost)
238                 ." WHERE stock_id=".db_escape($stock_id);
239         db_query($sql,"The cost details for the inventory item could not be updated");
240 }
241
242 function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
243         $type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
244 {
245         global $Refs;
246
247         if (!($type == WO_ADVANCED))
248                 return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc);
249
250         begin_transaction();
251         $args = func_get_args();
252         $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id',
253                 'type', 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
254         $args->woid = 0;
255         hook_db_prewrite($args, ST_WORKORDER);
256
257         $date = date2sql($date_);
258         $required = date2sql($required_by);
259
260         $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, stock_id,
261                 type, date_, required_by)
262         VALUES (".db_escape($wo_ref).", ".db_escape($loc_code).", "
263         .db_escape($units_reqd).", ".db_escape($stock_id).",
264                 ".db_escape($type).", '$date', ".db_escape($required).")";
265         db_query($sql, "could not add work order");
266
267         $woid = db_insert_id();
268
269         add_comments(ST_WORKORDER, $woid, $required_by, $memo_);
270
271         $Refs->save(ST_WORKORDER, $woid, $wo_ref);
272         add_audit_trail(ST_WORKORDER, $woid, $date_);
273
274         $args->woid = $woid;
275         hook_db_postwrite($args, ST_WORKORDER);
276         commit_transaction();
277
278         return $woid;
279 }
280
281 //--------------------------------------------------------------------------------------
282
283 function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
284                                         $date_, $required_by, $memo_)
285 {
286         begin_transaction();
287         $args = func_get_args();
288         $args = (object)array_combine(array('woid', 'loc_code', 'units_reqd', 'stock_id',
289                 'date_', 'required_by', 'memo_'), $args);
290         hook_db_prewrite($args, ST_WORKORDER);
291
292         $date = date2sql($date_);
293         $required = date2sql($required_by);
294
295         $sql = "UPDATE ".TB_PREF."workorders SET loc_code=".db_escape($loc_code).",
296                 units_reqd=".db_escape($units_reqd).", stock_id=".db_escape($stock_id).",
297                 required_by=".db_escape($required).",
298                 date_='$date'
299                 WHERE id = ".db_escape($woid);
300
301         db_query($sql, "could not update work order");
302
303         update_comments(ST_WORKORDER, $woid, null, $memo_);
304         add_audit_trail(ST_WORKORDER, $woid, $date_, _("Updated."));
305
306         hook_db_postwrite($args, ST_WORKORDER);
307         commit_transaction();
308 }
309
310 function delete_work_order($woid)
311 {
312         begin_transaction();
313         hook_db_prevoid(ST_WORKORDER, $woid);
314
315         // delete the work order requirements
316         delete_wo_requirements($woid);
317
318         // delete the actual work order
319         $sql = "DELETE FROM ".TB_PREF."workorders WHERE id=".db_escape($woid);
320         db_query($sql,"The work order could not be deleted");
321
322         delete_comments(ST_WORKORDER, $woid);
323         add_audit_trail(ST_WORKORDER, $woid, $_POST['date_'], _("Canceled."));
324
325         commit_transaction();
326 }
327
328 //--------------------------------------------------------------------------------------
329
330 function get_work_order($woid, $allow_null=false)
331 {
332     $sql = "SELECT wo.*,st.description As StockItemName,l.location_name,
333                 l.delivery_address,l.email, l.contact
334                 FROM ".TB_PREF."workorders wo, ".TB_PREF."stock_master st, ".TB_PREF."locations l
335                 WHERE st.stock_id=wo.stock_id
336                 AND     l.loc_code=wo.loc_code
337                 AND wo.id=".db_escape($woid)."
338                 GROUP BY wo.id";
339
340         $result = db_query($sql, "The work order issues could not be retrieved");
341
342         if (!$allow_null && db_num_rows($result) == 0)
343                 display_db_error("Could not find work order $woid", $sql);
344
345         return db_fetch($result);
346 }
347
348 //--------------------------------------------------------------------------------------
349
350 function work_order_has_productions($woid)
351 {
352         $sql = "SELECT COUNT(*) FROM ".TB_PREF."wo_manufacture WHERE workorder_id=".db_escape($woid);
353         $result = db_query($sql, "query work order for productions");
354
355         $myrow = db_fetch_row($result);
356         return ($myrow[0] > 0);
357 }
358
359
360 //--------------------------------------------------------------------------------------
361
362 function work_order_has_issues($woid)
363 {
364         $sql = "SELECT COUNT(*) FROM ".TB_PREF."wo_issues WHERE workorder_id=".db_escape($woid);
365         $result = db_query($sql, "query work order for issues");
366
367         $myrow = db_fetch_row($result);
368         return ($myrow[0] > 0);
369 }
370
371 //--------------------------------------------------------------------------------------
372
373 function work_order_has_payments($woid)
374 {
375         $result = get_gl_wo_cost_trans($woid);
376
377     return (db_num_rows($result) != 0);
378 }
379
380 //--------------------------------------------------------------------------------------
381
382 function release_work_order($woid, $releaseDate, $memo_)
383 {
384         begin_transaction();
385
386         $myrow = get_work_order($woid);
387         $stock_id = $myrow["stock_id"];
388
389         $date = date2sql($releaseDate);
390
391         $sql = "UPDATE ".TB_PREF."workorders SET released_date='$date',
392                 released=1 WHERE id = ".db_escape($woid);
393         db_query($sql, "could not release work order");
394
395         // create Work Order Requirements based on the bom
396         create_wo_requirements($woid, $stock_id);
397
398         add_comments(ST_WORKORDER, $woid, $releaseDate, $memo_);
399         add_audit_trail(ST_WORKORDER, $woid, $releaseDate,_("Released."));
400
401         commit_transaction();
402 }
403
404 //--------------------------------------------------------------------------------------
405
406 function close_work_order($woid)
407 {
408         $sql = "UPDATE ".TB_PREF."workorders SET closed=1 WHERE id = ".db_escape($woid);
409         db_query($sql, "could not close work order");
410 }
411
412 //--------------------------------------------------------------------------------------
413
414 function work_order_is_closed($woid)
415 {
416         $sql = "SELECT closed FROM ".TB_PREF."workorders WHERE id = ".db_escape($woid);
417         $result = db_query($sql, "could not query work order");
418         $row = db_fetch_row($result);
419         return ($row[0] > 0);
420 }
421
422 //--------------------------------------------------------------------------------------
423
424 function work_order_update_finished_quantity($woid, $quantity, $force_close=0)
425 {
426         $sql = "UPDATE ".TB_PREF."workorders SET units_issued = units_issued + ".db_escape($quantity).",
427                 closed = ((units_issued >= units_reqd) OR ".db_escape($force_close).")
428                 WHERE id = ".db_escape($woid);
429
430         db_query($sql, "The work order issued quantity couldn't be updated");
431 }
432
433 //--------------------------------------------------------------------------------------
434
435 function void_work_order($woid)
436 {
437         begin_transaction();
438         hook_db_prevoid(ST_WORKORDER, $woid);
439
440         $work_order = get_work_order($woid);
441         if (!($work_order["type"] == WO_ADVANCED))
442         {
443                 $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
444                         .db_escape($woid);
445                 db_query($sql, "The work order couldn't be voided");
446
447                 // void all related stock moves
448                 void_stock_move(ST_WORKORDER, $woid);
449
450                 // void any related bank/gl trans
451                 void_bank_trans(ST_WORKORDER, $woid, true);
452
453                 // clear the requirements units received
454                 void_wo_requirements($woid);
455         }
456         else
457         {
458                 // void everything inside the work order : issues, productions, payments
459                 $date = sql2date($work_order['date_']);
460                 
461                 $result = get_work_order_productions($woid); // check the produced quantity
462                 while ($row = db_fetch($result))
463                 {
464                         void_work_order_produce($row['id']);
465                         
466                         //Post voided entry if not prevoided explicitly
467                         $void_entry = get_voided_entry(ST_MANURECEIVE, $row['id']);
468                         if ($void_entry)
469                                 continue;
470                         $memo_ = _("Voiding Work Order Trans # ").$woid;
471                         add_audit_trail(ST_MANURECEIVE, $row['id'], today(), _("Voided.")."\n".$memo_);
472                         add_voided_entry(ST_MANURECEIVE, $row['id'], today(), $memo_);
473                 }
474
475                 $result = get_work_order_issues($woid);
476                 $cost = 0;
477                 while ($row = db_fetch($result))
478                 {
479                         void_work_order_issue($row['issue_no']);
480                         
481                         //Post voided entry if not prevoided explicitly
482                         $void_entry = get_voided_entry(ST_MANUISSUE, $row['issue_no']);
483                         if ($void_entry)
484                                 continue;
485                         $memo_ = _("Voiding Work Order Trans # ").$woid;
486                         add_audit_trail(ST_MANUISSUE, $row['issue_no'], today(), _("Voided.")."\n".$memo_);
487                         add_voided_entry(ST_MANUISSUE, $row['issue_no'], today(), $memo_);                              
488                 }
489
490                 //Adust avg labour cost
491                 $cost = get_gl_wo_cost($woid, WO_LABOUR); 
492                 if ($cost != 0)
493                         add_labour_cost($work_order['stock_id'], 1, $date, -$cost, true);
494                         
495                 //Adust avg overhead cost
496                 $cost = get_gl_wo_cost($woid, WO_OVERHEAD); 
497                 if ($cost != 0)
498                         add_overhead_cost($work_order['stock_id'], 1, $date, -$cost, true);
499                 
500                 $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
501                         .db_escape($woid);
502                 db_query($sql, "The work order couldn't be voided");
503
504                 // void all related stock moves
505                 void_stock_move(ST_WORKORDER, $woid);
506
507                 // void any related bank/gl trans
508                 void_bank_trans(ST_WORKORDER, $woid, true);
509
510                 // clear the requirements units received
511                 void_wo_requirements($woid);
512         }
513         commit_transaction();
514 }
515
516 function get_sql_for_work_orders($outstanding_only, $all_items)
517 {
518         $sql = "SELECT
519                 workorder.id,
520                 workorder.wo_ref,
521                 workorder.type,
522                 location.location_name,
523                 item.description,
524                 workorder.units_reqd,
525                 workorder.units_issued,
526                 workorder.date_,
527                 workorder.required_by,
528                 workorder.released_date,
529                 workorder.closed,
530                 workorder.released,
531                 workorder.stock_id,
532                 unit.decimals
533                 FROM ".TB_PREF."workorders as workorder,"
534                         .TB_PREF."stock_master as item,"
535                         .TB_PREF."item_units as unit,"
536                         .TB_PREF."locations as location
537                 WHERE workorder.stock_id=item.stock_id 
538                         AND workorder.loc_code=location.loc_code
539                         AND item.units=unit.abbr";
540
541         if (check_value('OpenOnly') || $outstanding_only != 0)
542         {
543                 $sql .= " AND workorder.closed=0";
544         }
545
546         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
547         {
548                 $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']);
549         }
550
551         if (isset($_POST['OrderId']) && $_POST['OrderId'] != "")
552         {
553                 $sql .= " AND workorder.id LIKE ".db_escape('%'.$_POST['OrderId'].'%');
554         }
555
556         if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
557         {
558                 $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%');
559         }
560
561         if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
562         {
563                 $sql .= " AND workorder.stock_id=".db_escape($_POST['SelectedStockItem']);
564         }
565
566         if (check_value('OverdueOnly'))
567         {
568                 $Today = date2sql(Today());
569
570                 $sql .= " AND workorder.required_by < '$Today' ";
571         }
572         $sql .= " ORDER BY workorder.id DESC";
573         return $sql;
574 }
575
576 function get_sql_for_where_used()
577 {
578         $sql = "SELECT 
579                         bom.parent,
580                         workcentre.name As WorkCentreName,
581                         location.location_name,
582                         bom.quantity,
583                         parent.description
584                         FROM ".TB_PREF."bom as bom, "
585                                 .TB_PREF."stock_master as parent, "
586                                 .TB_PREF."workcentres as workcentre, "
587                                 .TB_PREF."locations as location
588                         WHERE bom.parent = parent.stock_id 
589                                 AND bom.workcentre_added = workcentre.id
590                                 AND bom.loc_code = location.loc_code
591                                 AND bom.component=".db_escape($_POST['stock_id']);
592         return $sql;                    
593 }
594 //--------------------------------------------------------------------------------------
595 function get_gl_wo_cost($woid, $cost_type)
596 {
597         $cost = 0;
598         $result = get_gl_wo_cost_trans($woid, $cost_type);
599         while ($row = db_fetch($result))
600                 $cost += -$row['amount'];
601         return $cost;   
602 }
603
604 ?>