PageRenderTime 31ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/clients/controllers/clients.php

https://bitbucket.org/fusioninvoice_it/fusioninvoice
PHP | 163 lines | 118 code | 32 blank | 13 comment | 9 complexity | b77b1796fc4a551af4612c551c2d5f28 MD5 | raw file
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. /*
  5. * FusionInvoice
  6. *
  7. * A free and open source web based invoicing system
  8. *
  9. * @package FusionInvoice
  10. * @author Jesse Terry
  11. * @copyright Copyright (c) 2012 - 2013 FusionInvoice, LLC
  12. * @license http://www.fusioninvoice.com/license.txt
  13. * @link http://www.fusioninvoice.com
  14. *
  15. */
  16. class Clients extends Admin_Controller {
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. $this->load->model('mdl_clients');
  21. }
  22. public function index()
  23. {
  24. // Display active clients by default
  25. redirect('clients/status/active');
  26. }
  27. public function status($status = 'active', $page = 0)
  28. {
  29. if (is_numeric(array_search($status, array('active', 'inactive'))))
  30. {
  31. $function = 'is_' . $status;
  32. $this->mdl_clients->$function();
  33. }
  34. $this->mdl_clients->with_total_balance()->paginate(site_url('clients/status/' . $status), $page);
  35. $clients = $this->mdl_clients->result();
  36. $this->layout->set(
  37. array(
  38. 'records' => $clients,
  39. 'filter_display' => TRUE,
  40. 'filter_placeholder' => lang('filter_clients'),
  41. 'filter_method' => 'filter_clients'
  42. )
  43. );
  44. $this->layout->buffer('content', 'clients/index');
  45. $this->layout->render();
  46. }
  47. public function form($id = NULL)
  48. {
  49. if ($this->input->post('btn_cancel'))
  50. {
  51. redirect('clients');
  52. }
  53. if ($this->mdl_clients->run_validation())
  54. {
  55. $id = $this->mdl_clients->save($id);
  56. $this->load->model('custom_fields/mdl_client_custom');
  57. $this->mdl_client_custom->save_custom($id, $this->input->post('custom'));
  58. redirect('clients/view/' . $id);
  59. }
  60. if ($id and !$this->input->post('btn_submit'))
  61. {
  62. if (!$this->mdl_clients->prep_form($id))
  63. {
  64. show_404();
  65. }
  66. $this->load->model('custom_fields/mdl_client_custom');
  67. $client_custom = $this->mdl_client_custom->where('client_id', $id)->get();
  68. if ($client_custom->num_rows())
  69. {
  70. $client_custom = $client_custom->row();
  71. unset($client_custom->client_id, $client_custom->client_custom_id);
  72. foreach ($client_custom as $key => $val)
  73. {
  74. $this->mdl_clients->set_form_value('custom[' . $key . ']', $val);
  75. }
  76. }
  77. }
  78. elseif ($this->input->post('btn_submit'))
  79. {
  80. if ($this->input->post('custom'))
  81. {
  82. foreach ($this->input->post('custom') as $key => $val)
  83. {
  84. $this->mdl_clients->set_form_value('custom[' . $key . ']', $val);
  85. }
  86. }
  87. }
  88. $this->load->model('custom_fields/mdl_custom_fields');
  89. $this->layout->set('custom_fields', $this->mdl_custom_fields->by_table('fi_client_custom')->get()->result());
  90. $this->layout->buffer('content', 'clients/form');
  91. $this->layout->render();
  92. }
  93. public function view($client_id)
  94. {
  95. $this->load->model('clients/mdl_client_notes');
  96. $this->load->model('invoices/mdl_invoices');
  97. $this->load->model('quotes/mdl_quotes');
  98. $this->load->model('custom_fields/mdl_custom_fields');
  99. $client = $this->mdl_clients->with_total()->with_total_balance()->with_total_paid()->where('fi_clients.client_id', $client_id)->get()->row();
  100. if (!$client)
  101. {
  102. show_404();
  103. }
  104. $this->layout->set(
  105. array(
  106. 'client' => $client,
  107. 'client_notes' => $this->mdl_client_notes->where('client_id', $client_id)->get()->result(),
  108. 'invoices' => $this->mdl_invoices->by_client($client_id)->limit(20)->get()->result(),
  109. 'quotes' => $this->mdl_quotes->by_client($client_id)->limit(20)->get()->result(),
  110. 'custom_fields' => $this->mdl_custom_fields->by_table('fi_client_custom')->get()->result(),
  111. 'quote_statuses' => $this->mdl_quotes->statuses(),
  112. 'invoice_statuses' => $this->mdl_invoices->statuses(),
  113. )
  114. );
  115. $this->layout->buffer(
  116. array(
  117. array('invoice_table', 'invoices/partial_invoice_table'),
  118. array('quote_table', 'quotes/partial_quote_table'),
  119. array('partial_notes', 'clients/partial_notes'),
  120. array('content', 'clients/view')
  121. )
  122. );
  123. $this->layout->render();
  124. }
  125. public function delete($client_id)
  126. {
  127. $this->mdl_clients->delete($client_id);
  128. redirect('clients');
  129. }
  130. }
  131. ?>