Fix displayed required date
[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                                                 'create_denorm_order_details_queue.sql' => array('denorm_order_details_queue'),
49                                                 'create_denorm_qoh.sql' => array('denorm_qoh'),
50                                                 'create_order_summary_view.sql' => array('order_summary_view'),
51         );
52
53                                 return $this->update_databases($company, $updates, $check_only)
54                                                                 && update_queue_quantities()
55                                                                 && update_qoh_for_item();;
56     }
57
58     function deactivate_extension($company, $check_only=true)
59     {
60         global $db_connections;
61
62         $updates = array(
63             'clean_sales_order_details.sql' => array('ugly_hack') // FIXME: just an ugly hack to clean database on deactivation
64         );
65
66         return $this->update_databases($company, $updates, $check_only);
67     }
68
69                 function get_allowed_quantity($detail_id, $opts) {
70                         $location = array_shift($opts);
71                         $date = array_shift($opts);
72                         $qoh = array_shift($opts);
73
74                         $sql = "select quantity_before from ".TB_PREF."denorm_order_details_queue where id = $detail_id";
75                         $result = db_query($sql);
76                         $quantity_before = 0;
77                         if($row=db_fetch($result)) {
78                                 $quantity_before = $row['quantity_before'];
79                                 }
80
81                         return max($qoh - $quantity_before, 0);
82                 }
83 }
84 ?>