*** empty log message ***
[fa-stable.git] / inventory / includes / db / items_trans_db.inc
1 <?php
2
3 //-------------------------------------------------------------------------------------------------------------
4
5 function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_cost,
6         $last_cost)
7 {
8         $mb_flag = get_mb_flag($stock_id);
9     
10     if (is_service($mb_flag))
11     {
12         display_db_error("Cannot do cost update for Service item : $stock_id", "");     
13     }           
14         
15         $update_no = -1;
16         
17         begin_transaction();
18         
19         $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost, 
20                 labour_cost=$labour_cost, 
21                 overhead_cost=$overhead_cost, 
22                 last_cost=$last_cost 
23                 WHERE stock_id='$stock_id'";
24         db_query($sql,"The cost details for the inventory item could not be updated");
25
26         $qoh = get_qoh_on_date($_POST['stock_id']);
27         
28         if ($qoh > 0)
29         {
30     
31                 $update_no = get_next_trans_no(systypes::cost_update());
32                 $date_ = Today();
33                 if (!is_date_in_fiscalyear($date_))
34                         $date_ = end_fiscalyear();
35            
36                 $stock_gl_code = get_stock_gl_code($stock_id);
37          
38                 $new_cost = $material_cost + $labour_cost + $overhead_cost;
39           
40                 $value_of_change = $qoh * ($new_cost - $last_cost);
41            
42                 $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh";
43                 add_gl_trans_std_cost(systypes::cost_update(), $update_no, $date_, $stock_gl_code["adjustment_account"], 
44                         $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], $memo_, (-$value_of_change));     
45
46                 add_gl_trans_std_cost(systypes::cost_update(), $update_no, $date_, $stock_gl_code["inventory_account"], 0, 0, $memo_, 
47                         $value_of_change);         
48         }                               
49
50         commit_transaction();
51         
52         return $update_no;              
53 }
54
55 //-------------------------------------------------------------------------------------------------------------
56
57 ?>