PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/phreebooks/pages/popup_orders/pre_process.php

http://phreedom.googlecode.com/
PHP | 140 lines | 100 code | 12 blank | 28 comment | 17 complexity | d153c9c02fa1ac3093bace504f4b2460 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/phreebooks/pages/popup_orders/pre_process.php
  19. //
  20. $security_level = validate_user(0, true);
  21. /************** include page specific files *********************/
  22. gen_pull_language('contacts');
  23. require(DIR_FS_WORKING . 'functions/phreebooks.php');
  24. /************** page specific initialization *************************/
  25. define('JOURNAL_ID',(int)$_GET['jID']);
  26. switch (JOURNAL_ID) {
  27. case 3: // Purchase Quote Journal
  28. case 4: // Purchase Order Journal
  29. define('GL_TYPE','poo');
  30. break;
  31. case 6: // Purchase Journal
  32. case 7: // Vendor Credit Memo Journal
  33. case 21: // Point of Purchase Journal
  34. define('GL_TYPE','por');
  35. break;
  36. case 9: // Sales Quote Journal
  37. case 10: // Sales Order Journal
  38. define('GL_TYPE','soo');
  39. break;
  40. case 12: // Sales/Invoice Journal
  41. case 13: // Custoemr Credit Memo Journal
  42. case 19: // Point of Sale (receipts)
  43. define('GL_TYPE','sos');
  44. break;
  45. case 18: // Cash Receipts Journal
  46. define('GL_TYPE','swr'); // sale with receipt
  47. break;
  48. case 20: // Purchases (direct pay)
  49. define('GL_TYPE','pwp'); // purchase with payment
  50. break;
  51. default:
  52. die('No valid journal id found (filename: modules/phreebooks/popup.php), Journal ID needs to be passed to this script to identify the correct procedure.');
  53. }
  54. $acct_period = ($_GET['search_period']) ? $_GET['search_period'] : $_POST['search_period'];
  55. if (!$acct_period) $acct_period = CURRENT_ACCOUNTING_PERIOD;
  56. $period_filter = ($acct_period == 'all') ? '' : (' and period = ' . $acct_period);
  57. $search_text = ($_POST['search_text']) ? db_input($_POST['search_text']) : db_input($_GET['search_text']);
  58. if ($search_text == TEXT_SEARCH) $search_text = '';
  59. $action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
  60. if (!$action && $search_text <> '') $action = 'search'; // if enter key pressed and search not blank
  61. // load the sort fields
  62. $_GET['sf'] = $_POST['sort_field'] ? $_POST['sort_field'] : $_GET['sf'];
  63. $_GET['so'] = $_POST['sort_order'] ? $_POST['sort_order'] : $_GET['so'];
  64. /*************** hook for custom actions ***************************/
  65. $custom_path = DIR_FS_WORKING . 'custom/pages/popup_orders/extra_actions.php';
  66. if (file_exists($custom_path)) { include($custom_path); }
  67. /*************** Act on the action request *************************/
  68. switch ($action) {
  69. case 'go_first': $_GET['list'] = 1; break;
  70. case 'go_previous': $_GET['list']--; break;
  71. case 'go_next': $_GET['list']++; break;
  72. case 'go_last': $_GET['list'] = 99999; break;
  73. case 'search':
  74. case 'search_reset':
  75. case 'go_page':
  76. default:
  77. }
  78. /***************** prepare to display templates *************************/
  79. // build the list header
  80. $heading_array['post_date'] = TEXT_DATE;
  81. $heading_array['purchase_invoice_id'] = constant('ORD_HEADING_NUMBER_' . JOURNAL_ID);
  82. switch (JOURNAL_ID) {
  83. case 6:
  84. case 7:
  85. $heading_array['so_po_ref_id'] = ORD_HEADING_NUMBER_4;
  86. $heading_array['waiting'] = ORD_WAITING;
  87. break;
  88. case 12:
  89. case 13:
  90. $heading_array['so_po_ref_id'] = ORD_HEADING_NUMBER_10;
  91. $heading_array['closed'] = TEXT_PAID;
  92. break;
  93. case 19:
  94. $heading_array['so_po_ref_id'] = ORD_HEADING_NUMBER_10;
  95. $heading_array['closed'] = TEXT_CLOSED; break;
  96. default:
  97. $heading_array['closed'] = TEXT_CLOSED;
  98. }
  99. $heading_array['bill_primary_name'] = in_array(JOURNAL_ID, array(12,13)) ? ORD_CUSTOMER_NAME : ORD_VENDOR_NAME;
  100. $heading_array['total_amount'] = TEXT_AMOUNT;
  101. $result = html_heading_bar($heading_array, $_GET['sf'], $_GET['so'], array());
  102. $list_header = $result['html_code'];
  103. $disp_order = $result['disp_order'];
  104. if ($disp_order == 'post_date') $disp_order .= ', purchase_invoice_id';
  105. // build the list for the page selected
  106. if (isset($search_text) && $search_text <> '') {
  107. $search_fields = array('bill_primary_name', 'purchase_invoice_id', 'purch_order_id', 'store_id');
  108. // hook for inserting new search fields to the query criteria.
  109. if (is_array($extra_search_fields)) $search_fields = array_merge($search_fields, $extra_search_fields);
  110. $search = ' and (' . implode(' like \'%' . $search_text . '%\' or ', $search_fields) . ' like \'%' . $search_text . '%\')';
  111. } else {
  112. $search = '';
  113. }
  114. $field_list = array('id', 'journal_id', 'post_date', 'purchase_invoice_id', 'purch_order_id', 'so_po_ref_id',
  115. 'store_id', 'closed', 'waiting', 'bill_primary_name', 'total_amount', 'currencies_code', 'currencies_value');
  116. // hook to add new fields to the query return results
  117. if (is_array($extra_query_list_fields) > 0) $field_list = array_merge($field_list, $extra_query_list_fields);
  118. $query_raw = "select " . implode(', ', $field_list) . " from " . TABLE_JOURNAL_MAIN . "
  119. where journal_id = " . JOURNAL_ID . $period_filter . $search . " order by $disp_order";
  120. $query_split = new splitPageResults($_GET['list'], MAX_DISPLAY_SEARCH_RESULTS, $query_raw, $query_numrows);
  121. $query_result = $db->Execute($query_raw);
  122. $include_header = false;
  123. $include_footer = false;
  124. $include_tabs = false;
  125. $include_calendar = false;
  126. $include_template = 'template_main.php';
  127. define('PAGE_TITLE', GEN_HEADING_PLEASE_SELECT);
  128. ?>