Splitter Test written. Doesn't pass.
[order_line_extra.git] / hooks.php
1 <?php
2 // ----------------------------------------------------------------
3 // $ Revision:  1.0 $
4 // Creator: Maxime Bourge
5 // date_:   2013-05-04
6 // Title:   Order Line Extra
7 // Free software under GNU GPL
8 // ----------------------------------------------------------------
9 define ('SS_ORDERLINEX', 100<<8);
10
11 include_once('includes/db_order_lines.inc');
12
13 class hooks_order_line_extra extends hooks {
14         var $module_name = 'order_line_extra';
15
16         /*
17                 Install additonal menu options provided by module
18         */
19     function install_tabs($app) {
20         global $path_to_root;
21
22     }
23
24     function install_options($app) {
25         global $path_to_root;
26                                 switch($app->id) {
27                                         case 'orders':
28                                                 $app->add_rapp_function(0, _('Order Extra'), 
29                                                         $path_to_root.'/modules/order_line_extra/order_lines_view.php', 'SA_SALESTRANSVIEW');
30                                 }
31     }
32
33     function install_access()
34         {
35         $security_sections[SS_ORDERLINEX] =  _("Order Line Extra");
36                 $security_areas['SA_ORDERLINEX_EDIT'] = array(SS_ORDERLINEX|1, _("Edit lines"));
37
38                 return array($security_areas, $security_sections);
39         }
40
41     /* This method is called on extension activation for company.   */
42     function activate_extension($company, $check_only=true)
43     {
44         global $db_connections;
45
46         $updates = array(
47                                                 'alter_sales_order_details.sql' => array('sales_order_details','required_date'),
48                                                 'alter_sales_order_details_2.sql' => array('sales_order_details','expiry_date'),
49                                                 'create_denorm_order_details_queue.sql' => array('denorm_order_details_queue'),
50                                                 'create_denorm_qoh.sql' => array('denorm_qoh'),
51                                                 'create_order_summary_view.sql' => array('order_summary_view'),
52         );
53
54                                 return $this->update_databases($company, $updates, $check_only)
55                                                                 && update_queue_quantities()
56                                                                 && update_qoh_for_item();;
57     }
58
59     function deactivate_extension($company, $check_only=true)
60     {
61         global $db_connections;
62
63         $updates = array(
64             'clean_sales_order_details.sql' => array('ugly_hack') // FIXME: just an ugly hack to clean database on deactivation
65         );
66
67         return $this->update_databases($company, $updates, $check_only);
68     }
69
70                 function get_allowed_quantity($detail_id, $opts) {
71                         $location = array_shift($opts);
72                         $date = array_shift($opts);
73                         $qoh = array_shift($opts);
74
75                         $sql = "select quantity_before from ".TB_PREF."denorm_order_details_queue where id = $detail_id";
76                         $result = db_query($sql);
77                         $quantity_before = 0;
78                         if($row=db_fetch($result)) {
79                                 $quantity_before = $row['quantity_before'];
80                                 }
81
82                         return max($qoh - $quantity_before, 0);
83                 }
84
85                 function db_postwrite($cart, $trans_type) {
86                         if(!is_a($cart, "Cart") ) return;
87
88                         // It's a cart. Find all the stock_id and update the cache table 
89                         foreach($cart->line_items as $line_no => $item) {
90                                 $stock_id = $item->stock_id;
91                                 update_queue_quantity_for_item($stock_id);
92                                 update_qoh_for_item($stock_id);
93                         }
94
95                         // update null fields of new entered orders.
96                         //
97                 $types = array(ST_SALESORDER);
98                 if(in_array($trans_type, $types)) update_order_detail_defaults();
99         
100                 }
101
102
103                 function db_prevoid($cart, $trans_type) {
104                 // Simple version, rebuild everything
105                 $types = array(ST_CUSTCREDIT, ST_CUSTDELIVERY, ST_INVADJUST, ST_PURCHORDER, ST_WORKORDER, ST_MANUISSUE,
106                                 ST_SALESORDER, ST_SALESQUOTE, ST_MANURECEIVE);
107                 if(in_array($trans_type, $types)) {
108                         update_queue_quantities();
109                         update_qoh_for_item();
110                 }
111                 }
112 }
113 ?>