PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/helpers/custom_helper.php

http://github.com/prashants/webzash
PHP | 254 lines | 168 code | 12 blank | 74 comment | 39 complexity | fecb3a1c461d64d1725838e4b0fc093a MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Converts D/C to Dr / Cr
  4. *
  5. * Covnerts the D/C received from database to corresponding
  6. * Dr/Cr value for display.
  7. *
  8. * @access public
  9. * @param string 'd' or 'c' from database table
  10. * @return string
  11. */
  12. if ( ! function_exists('convert_dc'))
  13. {
  14. function convert_dc($label)
  15. {
  16. if ($label == "D")
  17. return "Dr";
  18. else if ($label == "C")
  19. return "Cr";
  20. else
  21. return "Error";
  22. }
  23. }
  24. /**
  25. * Converts amount to Dr or Cr Value
  26. *
  27. * Covnerts the amount to 0 or Dr or Cr value for display
  28. *
  29. * @access public
  30. * @param float amount for display
  31. * @return string
  32. */
  33. if ( ! function_exists('convert_amount_dc'))
  34. {
  35. function convert_amount_dc($amount)
  36. {
  37. if ($amount == "D")
  38. return "0";
  39. else if ($amount < 0)
  40. return "Cr " . convert_cur(-$amount);
  41. else
  42. return "Dr " . convert_cur($amount);
  43. }
  44. }
  45. /**
  46. * Converts Opening balance amount to Dr or Cr Value
  47. *
  48. * Covnerts the Opening balance amount to 0 or Dr or Cr value for display
  49. *
  50. * @access public
  51. * @param amount
  52. * @param debit or credit
  53. * @return string
  54. */
  55. if ( ! function_exists('convert_opening'))
  56. {
  57. function convert_opening($amount, $dc)
  58. {
  59. if ($amount == 0)
  60. return "0";
  61. else if ($dc == 'D')
  62. return "Dr " . convert_cur($amount);
  63. else
  64. return "Cr " . convert_cur($amount);
  65. }
  66. }
  67. if ( ! function_exists('convert_cur'))
  68. {
  69. function convert_cur($amount)
  70. {
  71. return number_format($amount, 2, '.', '');
  72. }
  73. }
  74. /**
  75. * Return the value of variable is set
  76. *
  77. * Return the value of varaible is set else return empty string
  78. *
  79. * @access public
  80. * @param a varaible
  81. * @return string value
  82. */
  83. if ( ! function_exists('print_value'))
  84. {
  85. function print_value($value = NULL, $default = "")
  86. {
  87. if (isset($value))
  88. return $value;
  89. else
  90. return $default;
  91. }
  92. }
  93. /**
  94. * Return Entry Type information
  95. *
  96. * @access public
  97. * @param int entry type id
  98. * @return array
  99. */
  100. if ( ! function_exists('entry_type_info'))
  101. {
  102. function entry_type_info($entry_type_id)
  103. {
  104. $CI =& get_instance();
  105. $entry_type_all = $CI->config->item('account_entry_types');
  106. if ($entry_type_all[$entry_type_id])
  107. {
  108. return array(
  109. 'id' => $entry_type_all[$entry_type_id],
  110. 'label' => $entry_type_all[$entry_type_id]['label'],
  111. 'name' => $entry_type_all[$entry_type_id]['name'],
  112. 'numbering' => $entry_type_all[$entry_type_id]['numbering'],
  113. 'prefix' => $entry_type_all[$entry_type_id]['prefix'],
  114. 'suffix' => $entry_type_all[$entry_type_id]['suffix'],
  115. 'zero_padding' => $entry_type_all[$entry_type_id]['zero_padding'],
  116. 'bank_cash_ledger_restriction' => $entry_type_all[$entry_type_id]['bank_cash_ledger_restriction'],
  117. );
  118. } else {
  119. return array(
  120. 'id' => $entry_type_all[$entry_type_id],
  121. 'label' => '',
  122. 'name' => '(Unkonwn)',
  123. 'numbering' => 1,
  124. 'prefix' => '',
  125. 'suffix' => '',
  126. 'zero_padding' => 0,
  127. 'bank_cash_ledger_restriction' => 5,
  128. );
  129. }
  130. }
  131. }
  132. /**
  133. * Return Entry Type Id from Entry Type Name
  134. *
  135. * @access public
  136. * @param string entry type name
  137. * @return int entry type id
  138. */
  139. if ( ! function_exists('entry_type_name_to_id'))
  140. {
  141. function entry_type_name_to_id($entry_type_name)
  142. {
  143. $CI =& get_instance();
  144. $entry_type_all = $CI->config->item('account_entry_types');
  145. foreach ($entry_type_all as $id => $row)
  146. {
  147. if ($row['label'] == $entry_type_name)
  148. {
  149. return $id;
  150. break;
  151. }
  152. }
  153. return FALSE;
  154. }
  155. }
  156. /**
  157. * Converts Entry number to proper entry prefix formats
  158. *
  159. * @access public
  160. * @param int entry type id
  161. * @return string
  162. */
  163. if ( ! function_exists('full_entry_number'))
  164. {
  165. function full_entry_number($entry_type_id, $entry_number)
  166. {
  167. $CI =& get_instance();
  168. $entry_type_all = $CI->config->item('account_entry_types');
  169. $return_html = "";
  170. if ( ! $entry_type_all[$entry_type_id])
  171. {
  172. $return_html = $entry_number;
  173. } else {
  174. $return_html = $entry_type_all[$entry_type_id]['prefix'] . str_pad($entry_number, $entry_type_all[$entry_type_id]['zero_padding'], '0', STR_PAD_LEFT) . $entry_type_all[$entry_type_id]['suffix'];
  175. }
  176. if ($return_html)
  177. return $return_html;
  178. else
  179. return " ";
  180. }
  181. }
  182. /**
  183. * Floating Point Operations
  184. *
  185. * Multiply the float by 100, convert it to integer,
  186. * Perform the integer operation and then divide the result
  187. * by 100 and return the result
  188. *
  189. * @access public
  190. * @param float number 1
  191. * @param float number 2
  192. * @param string operation to be performed
  193. * @return float result of the operation
  194. */
  195. if ( ! function_exists('float_ops'))
  196. {
  197. function float_ops($param1 = 0, $param2 = 0, $op = '')
  198. {
  199. $result = 0;
  200. $param1 = $param1 * 100;
  201. $param2 = $param2 * 100;
  202. $param1 = (int)round($param1, 0);
  203. $param2 = (int)round($param2, 0);
  204. switch ($op)
  205. {
  206. case '+':
  207. $result = $param1 + $param2;
  208. break;
  209. case '-':
  210. $result = $param1 - $param2;
  211. break;
  212. case '==':
  213. if ($param1 == $param2)
  214. return TRUE;
  215. else
  216. return FALSE;
  217. break;
  218. case '!=':
  219. if ($param1 != $param2)
  220. return TRUE;
  221. else
  222. return FALSE;
  223. break;
  224. case '<':
  225. if ($param1 < $param2)
  226. return TRUE;
  227. else
  228. return FALSE;
  229. break;
  230. case '>':
  231. if ($param1 > $param2)
  232. return TRUE;
  233. else
  234. return FALSE;
  235. break;
  236. }
  237. $result = $result/100;
  238. return $result;
  239. }
  240. }
  241. /* End of file custom_helper.php */
  242. /* Location: ./system/application/helpers/custom_helper.php */