PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/inventory/pages/popup_assy/pre_process.php

http://phreedom.googlecode.com/
PHP | 92 lines | 55 code | 9 blank | 28 comment | 13 complexity | 242f9b7547ed2993bd2c9dc25226c91b 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_assy/pre_process.php
  19. //
  20. $security_level = validate_user(0, true);
  21. /************** include page specific files *********************/
  22. require(DIR_FS_WORKING . 'functions/inventory.php');
  23. /************** page specific initialization *************************/
  24. $acct_period = ($_GET['search_period']) ? $_GET['search_period'] : $_POST['search_period'];
  25. if (!$acct_period) $acct_period = CURRENT_ACCOUNTING_PERIOD;
  26. $period_filter = ($acct_period == 'all') ? '' : (' and m.period = ' . $acct_period);
  27. $search_text = ($_POST['search_text']) ? db_input($_POST['search_text']) : db_input($_GET['search_text']);
  28. if ($search_text == TEXT_SEARCH) $search_text = '';
  29. $action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
  30. if (!$action && $search_text <> '') $action = 'search'; // if enter key pressed and search not blank
  31. // load the sort fields
  32. $_GET['sf'] = $_POST['sort_field'] ? $_POST['sort_field'] : $_GET['sf'];
  33. $_GET['so'] = $_POST['sort_order'] ? $_POST['sort_order'] : $_GET['so'];
  34. /*************** hook for custom actions ***************************/
  35. $custom_path = DIR_FS_WORKING . 'custom/pages/popup_assy/extra_actions.php';
  36. if (file_exists($custom_path)) { include($custom_path); }
  37. /*************** Act on the action request *************************/
  38. switch ($action) {
  39. case 'go_first': $_GET['list'] = 1; break;
  40. case 'go_previous': $_GET['list']--; break;
  41. case 'go_next': $_GET['list']++; break;
  42. case 'go_last': $_GET['list'] = 99999; break;
  43. case 'search':
  44. case 'search_reset':
  45. case 'go_page':
  46. default:
  47. }
  48. /***************** prepare to display templates *************************/
  49. // build the list header
  50. $heading_array = array(
  51. 'm.post_date' => TEXT_DATE,
  52. 'purchase_invoice_id' => TEXT_REFERENCE,
  53. 'total_amount' => TEXT_AMOUNT,
  54. 'description' => TEXT_DESCRIPTION,
  55. );
  56. $extras = (ENABLE_MULTI_BRANCH) ? array(TEXT_BRANCH) : array();
  57. $result = html_heading_bar($heading_array, $_GET['sf'], $_GET['so'], $extras);
  58. $list_header = $result['html_code'];
  59. $disp_order = $result['disp_order'];
  60. // build the list for the page selected
  61. if (isset($search_text) && $search_text <> '') {
  62. $search_fields = array('i.sku', 'm.purchase_invoice_id', 'i.debit_amount', 'i.credit_amount', 'i.description');
  63. // hook for inserting new search fields to the query criteria.
  64. if (is_array($extra_search_fields)) $search_fields = array_merge($search_fields, $extra_search_fields);
  65. $search = ' and (' . implode(' like \'%' . $search_text . '%\' or ', $search_fields) . ' like \'%' . $search_text . '%\')';
  66. } else {
  67. $search = '';
  68. }
  69. $field_list = array('m.id', 'm.purchase_invoice_id', 'm.post_date', 'm.store_id', 'i.description', 'i.qty');
  70. // hook to add new fields to the query return results
  71. if (is_array($extra_query_list_fields) > 0) $field_list = array_merge($field_list, $extra_query_list_fields);
  72. $query_raw = "select " . implode(', ', $field_list) . "
  73. from " . TABLE_JOURNAL_MAIN . " m left join " . TABLE_JOURNAL_ITEM . " i on m.id = i.ref_id
  74. where i.gl_type = 'asy' and m.journal_id = 14" . $period_filter . $search . " order by $disp_order, m.id";
  75. $query_split = new splitPageResults($_GET['list'], MAX_DISPLAY_SEARCH_RESULTS, $query_raw, $query_numrows);
  76. $query_result = $db->Execute($query_raw);
  77. $include_header = false;
  78. $include_footer = true;
  79. $include_tabs = false;
  80. $include_calendar = false;
  81. $include_template = 'template_main.php';
  82. define('PAGE_TITLE', GEN_HEADING_PLEASE_SELECT);
  83. ?>