PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/loanaccount/models/Accounts.php

https://github.com/srsree/OurBank
PHP | 355 lines | 322 code | 14 blank | 19 comment | 0 complexity | c4651e9b03980f36f3576d3fb50cfb09 MD5 | raw file
  1. <?php
  2. /*
  3. ############################################################################
  4. # This file is part of OurBank.
  5. ############################################################################
  6. # OurBank is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. ############################################################################
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. ############################################################################
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ############################################################################
  19. */
  20. ?>
  21. <?php
  22. class Loanaccount_Model_Accounts extends Zend_Db_Table {
  23. protected $_name = 'ourbank_accounts';
  24. public function insertAccounts()
  25. {
  26. $data = array('account_id'=> '');
  27. $this->insert($data);
  28. }
  29. public function UpDateAccounts($account_id,$accountNumber,$memberId,$productId,$grouporIndividualNumber,$createby)
  30. {
  31. $data = array('account_number' =>$accountNumber,
  32. 'member_id' => $memberId,
  33. 'product_id' => $productId,
  34. 'membertype_id' => $grouporIndividualNumber,
  35. 'accountcreated_date' => date("Y-m-d"),
  36. 'accountcreated_by' => $createby,
  37. 'accountstatus_id'=> 1);
  38. $where = 'account_id = '.$account_id;
  39. $this->update($data , $where );
  40. }
  41. public function search($code)
  42. {
  43. $this->db = Zend_Db_Table::getDefaultAdapter();
  44. $this->db->setFetchMode(Zend_Db::FETCH_OBJ);
  45. $sql= "SELECT
  46. a.id as id,
  47. a.membercode as code,
  48. a.name as name,
  49. substr(a.membercode,5,1) as type,
  50. c.type as membertype,
  51. b.name as officename
  52. from
  53. ourbank_member a,
  54. ourbank_office b,
  55. ourbank_membertypes c
  56. where
  57. a.office_id= b.id and
  58. (a.name like '%' '$code' '%' or a.membercode like '%' '$code' '%') AND
  59. substr(a.membercode,5,1) = c.id
  60. union
  61. SELECT
  62. a.id as id,
  63. a.groupcode as code,
  64. a.name as name,
  65. substr(a.groupcode,5,1) as type,
  66. c.type as membertype,
  67. b.name as officename
  68. from
  69. ourbank_group a,
  70. ourbank_office b,
  71. ourbank_membertypes c
  72. where
  73. a.office_id= b.id and
  74. (a.name like '%' '$code' '%' or a.groupcode like '%' '$code' '%') AND
  75. substr(a.groupcode,5,1) = c.id";
  76. $result = $this->db->fetchAll($sql,array($code));
  77. return $result;
  78. }
  79. public function getDetails($code)
  80. {
  81. $db = Zend_Db_Table::getDefaultAdapter();
  82. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  83. $sql="SELECT
  84. a.id as id,
  85. a.membercode as code,
  86. a.name as name,
  87. substr(a.membercode,5,1) as type,
  88. c.type as membertype,
  89. b.name as officename
  90. from
  91. ourbank_member a,
  92. ourbank_office b,
  93. ourbank_membertypes c
  94. where
  95. a.office_id= b.id and
  96. substr(a.membercode,5,1) = c.id and
  97. a.membercode like '%' '$code' '%'
  98. union
  99. SELECT a.id as id,
  100. a.groupcode as code,
  101. a.name as name,
  102. substr(a.groupcode,5,1) as type,
  103. c.type as membertype,
  104. b.name as officename
  105. from
  106. ourbank_group a,
  107. ourbank_office b,
  108. ourbank_membertypes c
  109. where
  110. a.office_id= b.id and
  111. substr(a.groupcode,5,1) = c.id and
  112. a.groupcode like '%' '$code' '%'";
  113. $result = $db->fetchAll($sql,array($code));
  114. return $result;
  115. }
  116. public function fetchLoanProducts($code) {
  117. $db = Zend_Db_Table::getDefaultAdapter();
  118. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  119. $sql = "select
  120. A.name as name,
  121. A.id as id
  122. from
  123. ourbank_productsoffer A,
  124. ourbank_product B,
  125. ourbank_member C
  126. where
  127. C.membercode = $code AND
  128. substr(C.membercode,5,1) = A.applicableto AND
  129. A.product_id = B.id AND
  130. B.category_id = 2
  131. UNION
  132. select
  133. A.name as name,
  134. A.id as id
  135. from
  136. ourbank_productsoffer A,
  137. ourbank_product B,
  138. ourbank_group C
  139. where
  140. C.groupcode = $code AND
  141. substr(C.groupcode,5,1) = A.applicableto AND
  142. A.product_id = B.id AND
  143. B.category_id = 2
  144. ";
  145. $result = $db->fetchAll($sql,array($code));
  146. return $result;
  147. }
  148. public function accountsSearch($code)
  149. {
  150. $db = Zend_Db_Table::getDefaultAdapter();
  151. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  152. $sql = "SELECT
  153. A.account_number as number,
  154. B.name as name
  155. FROM
  156. ourbank_accounts A,
  157. ourbank_productsoffer B,
  158. ourbank_product C,
  159. ourbank_member D
  160. WHERE
  161. D.membercode = $code AND
  162. A.member_id = D.id AND
  163. A.product_id = B.id AND
  164. B.product_id = C.id AND
  165. C.category_id = 2
  166. UNION
  167. SELECT
  168. A.account_number as number,
  169. B.name as name
  170. FROM
  171. ourbank_accounts A,
  172. ourbank_productsoffer B,
  173. ourbank_product C,
  174. ourbank_group D
  175. WHERE
  176. D.groupcode = $code AND
  177. A.member_id = D.id AND
  178. A.product_id = B.id AND
  179. B.product_id = C.id AND
  180. C.category_id = 2
  181. ";
  182. $result = $db->fetchAll($sql,array($code));
  183. return $result;
  184. }
  185. public function details($productId,$code)
  186. {
  187. $db = Zend_Db_Table::getDefaultAdapter();
  188. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  189. $sql = "SELECT
  190. E.id as memberId,
  191. E.membercode as code,
  192. substr(E.membercode,5,1) as typeID,
  193. E.name as name,
  194. F.name as officename,
  195. F.id as officeid,
  196. B.name as productname,
  197. B.begindate as begindate,
  198. B.closedate as closedate,
  199. B.glsubcode_id as glsubID,
  200. C.minmumloanamount as minamount,
  201. C.maximunloanamount as maxamount,
  202. C.penal_Interest as penalInterest,
  203. C.minimumfrequency as minInstallments,
  204. C.maximumfrequency as maxInstallments
  205. FROM
  206. ourbank_productsoffer B,
  207. ourbank_productsloan C,
  208. ourbank_member E,
  209. ourbank_office F
  210. WHERE
  211. E.membercode = $code AND
  212. B.id = $productId AND
  213. B.id = C.productsoffer_id AND
  214. F.id = E.office_id
  215. UNION
  216. SELECT
  217. E.id as memberId,
  218. E.groupcode as code,
  219. substr(E.groupcode,5,1) as typeID,
  220. E.name as name,
  221. F.name as officename,
  222. F.id as officeid,
  223. B.name as productname,
  224. B.begindate as begindate,
  225. B.closedate as closedate,
  226. B.glsubcode_id as glsubID,
  227. C.minmumloanamount as minamount,
  228. C.maximunloanamount as maxamount,
  229. C.penal_Interest as penalInterest,
  230. C.minimumfrequency as minInstallments,
  231. C.maximumfrequency as maxInstallments
  232. FROM
  233. ourbank_productsoffer B,
  234. ourbank_productsloan C,
  235. ourbank_group E,
  236. ourbank_office F
  237. WHERE
  238. E.groupcode = $code AND
  239. B.id = $productId AND
  240. B.id = C.productsoffer_id AND
  241. F.id = E.office_id
  242. ";
  243. $result = $db->fetchAll($sql,array($productId,$code));
  244. return $result;
  245. }
  246. public function getInterestRates($id)
  247. {
  248. $db = Zend_Db_Table::getDefaultAdapter();
  249. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  250. $sql = "SELECT
  251. period_ofrange_description ,
  252. Interest
  253. FROM
  254. ourbank_interest_periods
  255. WHERE
  256. offerproduct_id = $id";
  257. $result = $db->fetchAll($sql,array($id));
  258. return $result;
  259. }
  260. public function getInterest($productId,$interest)
  261. {
  262. $db = Zend_Db_Table::getDefaultAdapter();
  263. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  264. $sql = "SELECT
  265. interest
  266. FROM
  267. ourbank_interest_periods
  268. WHERE
  269. period_ofrange_monthfrom <= $interest AND
  270. period_ofrange_monthto >= $interest AND
  271. offerproduct_id = $productId";
  272. $result = $db->fetchOne($sql,array($productId));
  273. return $result;
  274. }
  275. public function accUpdate($accId,$input)
  276. {
  277. $where[] = "id = '".$accId."'";
  278. $db = $this->getAdapter();
  279. $result = $db->update('ourbank_accounts',$input,$where);
  280. }
  281. public function savingAcc($code)
  282. {
  283. $db = Zend_Db_Table::getDefaultAdapter();
  284. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  285. $sql = "SELECT
  286. A.id,
  287. A.account_number
  288. FROM
  289. ourbank_accounts A,
  290. ourbank_member B
  291. WHERE
  292. A.member_id = B.id AND
  293. B.membercode = $code AND
  294. A.account_number LIKE '%S%'
  295. UNION
  296. SELECT
  297. A.id,
  298. A.account_number
  299. FROM
  300. ourbank_accounts A,
  301. ourbank_group B
  302. WHERE
  303. A.member_id = B.id AND
  304. B.groupcode = $code AND
  305. A.account_number LIKE '%S%'
  306. ";
  307. $result = $db->fetchAll($sql,array($code));
  308. return $result;
  309. }
  310. public function getMember($officeid)
  311. {
  312. $db = Zend_Db_Table::getDefaultAdapter();
  313. $sql = "select
  314. C.id as id,
  315. C.name as name
  316. from
  317. ourbank_group as A,
  318. ourbank_groupmembers B,
  319. ourbank_member C
  320. where
  321. A.office_id = $officeid AND
  322. A.id = B.id AND
  323. B.member_id = C.id
  324. ";
  325. return $result = $db->fetchAll($sql);
  326. }
  327. public function goupAcc($group,$productId,$accId,$amt,$tranID,$date)
  328. {
  329. $db = $this->getAdapter();
  330. foreach($group as $group) {
  331. // Acc entry
  332. $accdata = array('account_id' => $accId,
  333. 'member_id' => $group,
  334. 'product_id' => $productId,
  335. 'status' => 3,
  336. 'created_by' => 1);
  337. $db->insert('ourbank_group_acccounts',$accdata);
  338. }
  339. return true;
  340. }
  341. }