PageRenderTime 728ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/inventory/pages/popup_inv/pre_process.php

http://phreedom.googlecode.com/
PHP | 130 lines | 84 code | 13 blank | 33 comment | 21 complexity | a413fa79be3e5265c3b5fba66d18f04a MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. <?php
  2. // +-----------------------------------------------------------------+
  3. // | PhreeBooks Open Source ERP |
  4. // +-----------------------------------------------------------------+
  5. // | Copyright (c) 2008, 2009, 2010, 2011, 2012 PhreeSoft, LLC |
  6. // | http://www.PhreeSoft.com |
  7. // +-----------------------------------------------------------------+
  8. // | This program is free software: you can redistribute it and/or |
  9. // | modify it under the terms of the GNU General Public License as |
  10. // | published by the Free Software Foundation, either version 3 of |
  11. // | the License, or any later version. |
  12. // | |
  13. // | This program is distributed in the hope that it will be useful, |
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  16. // | GNU General Public License for more details. |
  17. // +-----------------------------------------------------------------+
  18. // Path: /modules/inventory/pages/popup_inv/pre_process.php
  19. //
  20. $security_level = validate_user(0, true);
  21. /************** include page specific files *********************/
  22. require(DIR_FS_WORKING . 'defaults.php');
  23. require(DIR_FS_WORKING . 'functions/inventory.php');
  24. /************** page specific initialization *************************/
  25. $account_type = isset($_GET['type']) ? $_GET['type'] : 'c'; // current types are c (customer) and v (vendor)
  26. $rowID = isset($_GET['rowID']) ? $_GET['rowID'] : 0;
  27. $store_id = isset($_GET['storeID']) ? $_GET['storeID'] : 0;
  28. $contactID = isset($_GET['cID']) ? $_GET['cID'] : 0;
  29. $assembly = isset($_GET['asy']) ? true : false;
  30. // load the filters
  31. $f0 = $_GET['f0'] = isset($_POST['f0']) ? $_POST['f0'] : $_GET['f0']; // show inactive checkbox
  32. $f1 = $_GET['f0'] = isset($_POST['f1']) ? $_POST['f1'] : $_GET['f1']; // inventory_type dropdown
  33. $f2 = $_GET['f0'] = isset($_POST['f2']) ? $_POST['f2'] : $_GET['f2']; // limit to preferred_vendor checkbox
  34. // save the filters for page jumps
  35. $_GET['f0'] = $f0;
  36. $_GET['f1'] = $f1;
  37. $_GET['f2'] = $f2;
  38. $search_text = ($_POST['search_text']) ? db_input($_POST['search_text']) : db_input($_GET['search_text']);
  39. if ($search_text == TEXT_SEARCH) $search_text = '';
  40. $action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
  41. if (!$action && $search_text <> '') $action = 'search'; // if enter key pressed and search not blank
  42. switch ($account_type) {
  43. default:
  44. case 'c': $terms_type = 'AR'; break;
  45. case 'v': $terms_type = 'AP';
  46. }
  47. // load the sort fields
  48. $_GET['sf'] = $_POST['sort_field'] ? $_POST['sort_field'] : $_GET['sf'];
  49. $_GET['so'] = $_POST['sort_order'] ? $_POST['sort_order'] : $_GET['so'];
  50. /*************** hook for custom actions ***************************/
  51. $custom_path = DIR_FS_WORKING . 'custom/pages/popup_inv/extra_actions.php';
  52. if (file_exists($custom_path)) { include($custom_path); }
  53. /*************** Act on the action request *************************/
  54. switch ($action) {
  55. case 'go_first': $_GET['list'] = 1; break;
  56. case 'go_previous': $_GET['list']--; break;
  57. case 'go_next': $_GET['list']++; break;
  58. case 'go_last': $_GET['list'] = 99999; break;
  59. case 'search':
  60. case 'search_reset':
  61. case 'go_page':
  62. default:
  63. }
  64. /***************** prepare to display templates *************************/
  65. // build the type filter list
  66. $type_select_list = array( // add some extra options
  67. array('id' => '0', 'text' => TEXT_ALL),
  68. array('id' => 'cog', 'text' => TEXT_INV_MANAGED),
  69. );
  70. foreach ($inventory_types as $key => $value) $type_select_list[] = array('id' => $key, 'text' => $value);
  71. // build the list header
  72. $heading_array = array(
  73. 'sku' => TEXT_SKU,
  74. 'description_short' => TEXT_DESCRIPTION,
  75. 'full_price' => ($account_type == 'v') ? INV_ENTRY_INV_ITEM_COST : INV_ENTRY_FULL_PRICE,
  76. 'quantity_on_hand' => INV_HEADING_QTY_ON_HAND,
  77. 'quantity_on_order' => INV_HEADING_QTY_ON_ORDER,
  78. );
  79. $extras = (ENABLE_MULTI_BRANCH) ? array(TEXT_QTY_THIS_STORE) : array();
  80. $result = html_heading_bar($heading_array, $_GET['sf'], $_GET['so'], $extras);
  81. $list_header = $result['html_code'];
  82. $disp_order = $result['disp_order'];
  83. // build the list for the page selected
  84. $criteria = array();
  85. if (isset($search_text) && $search_text <> '') {
  86. $search_fields = array('sku', 'description_short', 'description_purchase');
  87. // hook for inserting new search fields to the query criteria.
  88. if (is_array($extra_search_fields)) $search_fields = array_merge($search_fields, $extra_search_fields);
  89. $criteria[] = '(' . implode(' like \'%' . $search_text . '%\' or ', $search_fields) . ' like \'%' . $search_text . '%\')';
  90. }
  91. if (!$f0) $criteria[] = "inactive = '0'"; // inactive flag
  92. if ($f1) { // sort by inventory type
  93. switch ($f1) {
  94. case 'cog':
  95. $cog_types = explode(',',COG_ITEM_TYPES);
  96. $criteria[] = "inventory_type in ('" . implode("','", $cog_types) . "')"; break;
  97. default: $criteria[] = "inventory_type = '$f1'"; break;
  98. }
  99. }
  100. if ($f2 && $contactID) $criteria[] = "vendor_id = " . $contactID; // limit to preferred vendor flag
  101. // build search filter string
  102. $search = (sizeof($criteria) > 0) ? (' where ' . implode(' and ', $criteria)) : '';
  103. $field_list = array('id', 'sku', 'inactive', 'inventory_type', 'quantity_on_hand', 'quantity_on_order',
  104. 'description_short', 'full_price', 'item_cost');
  105. // hook to add new fields to the query return results
  106. if (is_array($extra_query_list_fields) > 0) $field_list = array_merge($field_list, $extra_query_list_fields);
  107. $query_raw = "select " . implode(', ', $field_list) . " from " . TABLE_INVENTORY . $search . " order by $disp_order";
  108. $query_split = new splitPageResults($_GET['list'], MAX_DISPLAY_SEARCH_RESULTS, $query_raw, $query_numrows);
  109. $query_result = $db->Execute($query_raw);
  110. // check for auto close (if auto fill is turned on and only one result is found, the data will already be there)
  111. $auto_close = (INVENTORY_AUTO_FILL && $query_result->RecordCount() == 1 && $_GET['list'] == 1) ? true : false;
  112. $auto_close = false; // disable until all modules that use this function are ajax compliant
  113. $include_header = false;
  114. $include_footer = true;
  115. $include_template = 'template_main.php';
  116. define('PAGE_TITLE', INV_POPUP_WINDOW_TITLE);
  117. ?>