2 // ----------------------------------------------------------------
4 // Creator: Maxime Bourge
6 // Title: Order Line Extra
7 // Free software under GNU GPL
8 // ----------------------------------------------------------------
9 define ('SS_ORDERLINEX', 100<<8);
11 include_once('includes/db_order_lines.inc');
13 class hooks_order_line_extra extends hooks {
14 var $module_name = 'order_line_extra';
17 Install additonal menu options provided by module
19 function install_tabs($app) {
24 function install_options($app) {
28 $app->add_rapp_function(0, _('Order Extra'),
29 $path_to_root.'/modules/order_line_extra/order_lines_view.php', 'SA_SALESTRANSVIEW');
33 function install_access()
35 $security_sections[SS_ORDERLINEX] = _("Order Line Extra");
36 $security_areas['SA_ORDERLINEX_EDIT'] = array(SS_ORDERLINEX|1, _("Edit lines"));
38 return array($security_areas, $security_sections);
41 /* This method is called on extension activation for company. */
42 function activate_extension($company, $check_only=true)
44 global $db_connections;
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'),
54 return $this->update_databases($company, $updates, $check_only)
55 && update_queue_quantities()
56 && update_qoh_for_item();;
59 function deactivate_extension($company, $check_only=true)
61 global $db_connections;
64 'clean_sales_order_details.sql' => array('ugly_hack') // FIXME: just an ugly hack to clean database on deactivation
67 return $this->update_databases($company, $updates, $check_only);
70 function get_allowed_quantity($detail_id, $opts) {
71 $location = array_shift($opts);
72 $date = array_shift($opts);
73 $qoh = array_shift($opts);
75 $sql = "select quantity_before from ".TB_PREF."denorm_order_details_queue where id = $detail_id";
76 $result = db_query($sql);
78 if($row=db_fetch($result)) {
79 $quantity_before = $row['quantity_before'];
82 return max($qoh - $quantity_before, 0);
85 function db_postwrite($cart, $trans_type) {
86 if(!is_a($cart, "Cart") ) return;
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);
95 // update null fields of new entered orders.
97 $types = array(ST_SALESORDER);
98 if(in_array($trans_type, $types)) update_order_detail_defaults();
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();