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

/application/modules_core/invoice_search/controllers/invoice_search.php

https://bitbucket.org/hlevine/myclientbase-south-african-version
PHP | 159 lines | 137 code | 20 blank | 2 comment | 5 complexity | 76cb3730f8344ff8d27d7981170368f2 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
  2. class Invoice_Search extends Admin_Controller {
  3. function index() {
  4. $this->load->model(
  5. array(
  6. 'mdl_invoice_search',
  7. 'clients/mdl_clients',
  8. 'invoice_statuses/mdl_invoice_statuses'
  9. )
  10. );
  11. if (!$this->mdl_invoice_search->validate()) {
  12. $this->load->model('clients/mdl_clients');
  13. $this->load->model('invoice_statuses/mdl_invoice_statuses');
  14. $client_params = array(
  15. 'select' => 'mcb_clients.client_id, mcb_clients.client_name'
  16. );
  17. $data = array(
  18. 'clients' => $this->mdl_clients->get($client_params),
  19. 'invoice_statuses' => $this->mdl_invoice_statuses->get()
  20. );
  21. $this->load->view('search', $data);
  22. }
  23. else {
  24. $params = array();
  25. if (!$this->session->userdata('global_admin')) {
  26. $params['where']['mcb_invoices.user_id'] = $this->session->userdata('user_id');
  27. }
  28. if (!$this->input->post('include_quotes')) {
  29. $params['where']['mcb_invoices.invoice_is_quote'] = 0;
  30. }
  31. /* Parse tags if posted */
  32. if ($this->input->post('tags')) {
  33. /* Remove any apostrophes and trim */
  34. $tags = trim(str_replace("'", '', $this->input->post('tags')));
  35. /**
  36. * Explode into an array and trim each individual element
  37. * if comma separated tags are provided
  38. */
  39. if (strpos($tags, ',')) {
  40. $tags = explode(',', $tags);
  41. foreach ($tags as $key=>$tag) {
  42. $tags[$key] = trim($tag);
  43. }
  44. $tags = implode("','", $tags);
  45. }
  46. /* Add the tag where $params array element */
  47. $params['where'][] = "mcb_invoices.invoice_id IN (SELECT invoice_id FROM mcb_invoice_tags WHERE tag_id IN (SELECT tag_id FROM mcb_tags WHERE tag IN('" . $tags . "')))";
  48. }
  49. /* Add any clients if selected */
  50. if ($this->input->post('client_id')) {
  51. $params['where_in']['mcb_invoices.client_id'] = $this->input->post('client_id');
  52. }
  53. /* Add any invoice statuses if selected */
  54. if ($this->input->post('invoice_status_id')) {
  55. $params['where_in']['mcb_invoices.invoice_status_id'] = $this->input->post('invoice_status_id');
  56. }
  57. /* Add from date if provided */
  58. if ($this->input->post('from_date')) {
  59. $params['where']['mcb_invoices.invoice_date_entered >='] = strtotime(standardize_date($this->input->post('from_date')));
  60. }
  61. /* Add to date if provided */
  62. if ($this->input->post('to_date')) {
  63. $params['where']['mcb_invoices.invoice_date_entered <='] = strtotime(standardize_date($this->input->post('to_date')));
  64. }
  65. /* Add invoice id if provided */
  66. if ($this->input->post('invoice_number')) {
  67. $params['like']['mcb_invoices.invoice_number'] = $this->input->post('invoice_number');
  68. }
  69. /* Add amount if provided */
  70. if ($this->input->post('amount_operator') and check_clean_number($this->input->post('amount'))) {
  71. if ($this->input->post('amount_operator') <> '=') {
  72. $params['where']['mcb_invoice_amounts.invoice_total ' . $this->input->post('amount_operator')] = standardize_number($this->input->post('amount'));
  73. }
  74. else {
  75. $params['where']['mcb_invoice_amounts.invoice_total'] = standardize_number($this->input->post('amount'));
  76. }
  77. }
  78. if (!$params) {
  79. redirect('invoice_search');
  80. }
  81. /* Generate a simple hash value */
  82. $hash = md5(time());
  83. /* Stick this stuff in the users session data */
  84. $userdata = array(
  85. 'search_hash' => array(
  86. $hash => $params
  87. )
  88. );
  89. $this->session->set_userdata($userdata);
  90. /* Redirect to display results */
  91. redirect('invoice_search/search_results/' . $this->input->post('output_type') . '/search_hash/' . $hash);
  92. }
  93. }
  94. }
  95. ?>