PageRenderTime 69ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/transaction/models/recurringSavings.php

https://github.com/srsree/OurBank
PHP | 334 lines | 278 code | 37 blank | 19 comment | 1 complexity | c604e8c8ca3b73002661bcd000a886a8 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 Transaction_Model_recurringSavings extends Zend_Db_Table {
  23. protected $_name = 'ourbank_accounts';
  24. public function recurringAccountsSearch($membercode) {
  25. $select = $this->select()
  26. ->setIntegrityCheck(false)
  27. ->join(array('a' => 'ourbank_members'),array('member_id'))
  28. ->where('a.membercode = ?',$membercode)
  29. ->join(array('b' => 'ourbank_membertypes'),'b.membertype_id = a.membertype_id')
  30. ->join(array('c' => 'ourbank_accounts'),'a.member_Id = c.member_id')
  31. ->where('c.accountstatus_id = 3 or c.accountstatus_id = 1')
  32. ->join(array('d' => 'ourbank_productsofferdetails'),'d.applicableto = a.membertype_id')
  33. ->where('d.recordstatus_id = 3 or d.recordstatus_id = 1')
  34. ->join(array('e' => 'ourbank_product_fixedrecurring'),'c.product_id = d.offerproduct_id')
  35. ->where('e.productstatus_id = 3 or e.productstatus_id = 1')
  36. ->join(array('f' => 'ourbank_productdetails'),'f.product_id = d.product_id')
  37. ->where('f.recordstatus_id = 3 or f.recordstatus_id = 1')
  38. ->where('f.productshortname="rd"')
  39. ->join(array('g' => 'ourbank_recurringaccounts'),'c.account_id = g.account_id')
  40. ->where('g.fixedaccountstatus_id = 3 or g.fixedaccountstatus_id = 1')
  41. ->where('g.recordstatus_id = 3 or g.recordstatus_id = 1');
  42. $result = $this->fetchAll($select);
  43. return $result->toArray();
  44. }
  45. public function groupNamesSearch($memberId) {
  46. $select = $this->select()
  47. ->setIntegrityCheck(false)
  48. ->join(array('a' => 'ourbank_groupaddress'),array('a.groupname','a.group_id'))
  49. ->where('a.group_id = ?',$memberId)
  50. ->where('a.groupaccountstatus = 3 or a.groupaccountstatus = 1')
  51. ->join(array('b' => 'ourbank_groupmembers'),'a.group_id = b.group_id');
  52. $result = $this->fetchAll($select);
  53. return $result->toArray();
  54. }
  55. public function individualMemberName($memberId) {
  56. $select = $this->select()
  57. ->setIntegrityCheck(false)
  58. ->join(array('a' => 'ourbank_membername'),array('a.memberfirstname'))
  59. ->where('a.member_id = ?',$memberId);
  60. $result = $this->fetchAll($select);
  61. return $result->toArray();
  62. }
  63. public function recurringmemberbranchid($accountId) {
  64. $select = $this->select()
  65. ->setIntegrityCheck(false)
  66. ->join(array('A' => 'ourbank_accounts'),array('B.memberfirstname'))
  67. ->where('A.account_id = ?',$accountId)
  68. ->where('A.accountstatus_id = 3 or A.accountstatus_id = 1')
  69. ->join(array('B' => 'ourbank_members'),'A.member_id=B.member_id')
  70. ->where('B.member_status = 3 or B.member_status = 1');
  71. $result = $this->fetchAll($select);
  72. return $result->toArray();
  73. }
  74. public function accountIDSearch($memberId) {
  75. $select = $this->select()
  76. ->setIntegrityCheck(false)
  77. ->join(array('a' => 'ourbank_accounts'),array('account_id'))
  78. ->where('a.member_id = ?',$memberId)
  79. ->where('a.accountstatus_id = 3 or a.accountstatus_id = 1')
  80. ->join(array('b' => 'ourbank_recurringaccounts'),'a.account_id = b.account_id')
  81. ->where('b.fixedaccountstatus_id = 3 or b.fixedaccountstatus_id = 1')
  82. ->where('b.recordstatus_id = 3 or b.recordstatus_id = 1');
  83. $result = $this->fetchAll($select);
  84. return $result->toArray();
  85. }
  86. public function recurringSearch($accountcode) {
  87. $select = $this->select()
  88. ->setIntegrityCheck(false)
  89. ->join(array('a' => 'ourbank_accounts'),array('account_id'))
  90. ->where('a.account_number = ?',$accountcode)
  91. ->where('a.accountstatus_id = 3 or a.accountstatus_id = 1')
  92. ->join(array('b' => 'ourbank_recurringaccounts'),'a.account_id = b.account_id')
  93. ->where('b.fixedaccountstatus_id = 3 or b.fixedaccountstatus_id = 1')
  94. ->where('b.recordstatus_id = 3 or b.recordstatus_id = 1');
  95. $result = $this->fetchAll($select);
  96. return $result->toArray();
  97. }
  98. public function installmentsDetails($accountId,$productId) {
  99. $this->db = Zend_Db_Table::getDefaultAdapter();
  100. $sql = "select * from ourbank_recurringpaydetails A,ourbank_product_fixedrecurring B,ourbank_productsofferdetails C,ourbank_installmentstatus D
  101. where (A.account_id ='$accountId') AND (C.offerproduct_id='$productId') AND (A.rec_payment_status=D.installmentstatus_id) AND (C.offerproductupdate_id=B.offerproductupdate_id) AND (B.productstatus_id=1 or B.productstatus_id=3) AND (C.recordstatus_id=1 or C.recordstatus_id=3)";
  102. $result = $this->db->fetchAll($sql,array($accountId));
  103. return $result;
  104. }
  105. public function recurringAccountDetails($accountId,$productId) {
  106. $this->db = Zend_Db_Table::getDefaultAdapter();
  107. $sql = "select * from ourbank_recurringaccounts A,ourbank_productsofferdetails B,ourbank_product_fixedrecurring C,ourbank_productdetails D,ourbank_accounts E where (A.account_id ='$accountId') AND (B.offerproduct_id='$productId') AND (C.offerproductupdate_id=B.offerproductupdate_id) AND (C.productstatus_id=3) AND (B.recordstatus_id=3) AND (A.recordstatus_id=1) AND (D.product_id=B.product_id) AND (A.account_id=E.account_id)";
  108. $result = $this->db->fetchAll($sql,array($accountId));
  109. return $result;
  110. }
  111. public function recurringPaidDetails($accountId) {
  112. $select = $this->select()
  113. ->setIntegrityCheck(false)
  114. ->join(array('a' => 'ourbank_recurring_payment'),array('account_id'))
  115. ->where('a.account_id = ?',$accountId);
  116. $result = $this->fetchAll($select);
  117. return $result->toArray();
  118. }
  119. public function noOfInstalmentPaid($accountId) {
  120. $select = $this->select()
  121. ->setIntegrityCheck(false)
  122. ->join(array('a' => 'ourbank_recurringpaydetails'),array('rec_payment_id'))
  123. ->where('a.account_id = ?',$accountId)
  124. ->where('a.rec_payment_status = 2 AND (a.recordstatus_id=3 or a.recordstatus_id=1)');
  125. $result = $this->fetchAll($select);
  126. return $result->toArray();
  127. }
  128. public function TotalnoOfInstalmentPaid($accountId) {
  129. $select = $this->select()
  130. ->setIntegrityCheck(false)
  131. ->join(array('a' => 'ourbank_recurringpaydetails'),array('rec_payment_id'))
  132. ->where('a.account_id = ?',$accountId)
  133. ->where('a.recordstatus_id=3 or a.recordstatus_id=1');
  134. $result = $this->fetchAll($select);
  135. return $result->toArray();
  136. }
  137. public function fetchMemberName($accountId) {
  138. $select = $this->select()
  139. ->setIntegrityCheck(false)
  140. ->join(array('A' => 'ourbank_accounts'),array('B.memberfirstname'))
  141. ->where('A.account_id = ?',$accountId)
  142. ->join(array('B' => 'ourbank_membername'),'A.member_id=B.member_id')
  143. ->where('B.recordstatus_id = 3 or B.recordstatus_id = 1');
  144. $result = $this->fetchAll($select);
  145. return $result->toArray();
  146. }
  147. public function recurringProductDetails($accountId,$productId) {
  148. $select = $this->select()
  149. ->setIntegrityCheck(false)
  150. ->join(array('A' => 'ourbank_accounts'),array('account_id'))
  151. ->where('A.account_id = "'.$accountId.'" AND A.product_id = "'.$productId.'"')
  152. ->where('A.accountstatus_id = 3 or A.accountstatus_id = 1')
  153. ->join(array('B' => 'ourbank_productsofferdetails'),'A.product_id=B.offerproduct_id')
  154. ->where('B.offerproduct_id = ?',$productId)
  155. ->where('B.recordstatus_id = 3 or B.recordstatus_id = 1')
  156. ->join(array('C' => 'ourbank_product_fixedrecurring'),'B.offerproductupdate_id=C.offerproductupdate_id')
  157. ->where('C.productstatus_id = 3 or C.productstatus_id = 1');
  158. $result = $this->fetchAll($select);
  159. return $result->toArray();
  160. // die($select->__toString($select));
  161. }
  162. public function recurringInstalmentpayments($accountId,$InstalmentNumber) {
  163. $select = $this->select()
  164. ->setIntegrityCheck(false)
  165. ->join(array('a' => 'ourbank_recurringpaydetails'),array('rec_payment_id'))
  166. ->where('a.account_id = "'.$accountId.'" AND a.rec_payment_id = "'.$InstalmentNumber.'"');
  167. $result = $this->fetchAll($select);
  168. return $result->toArray();
  169. }
  170. public function nextinstallmentdate($accountId) {
  171. $select = $this->select()
  172. ->setIntegrityCheck(false)
  173. ->join(array('a' => 'ourbank_recurringpaydetails'),array('rec_payment_id'))
  174. ->where('a.account_id = "'.$accountId.'"')
  175. ->where('a.rec_payment_status = 5')
  176. ->where('a.recordstatus_id = 3 or a.recordstatus_id = 1');
  177. $result = $this->fetchAll($select);
  178. return $result->toArray();
  179. }
  180. public function fetchAllPaymentMode() {
  181. $select = $this->select()
  182. ->setIntegrityCheck(false)
  183. ->join(array('a' => 'ourbank_paymenttypes'),array('paymenttype_id'));
  184. $result = $this->fetchAll($select);
  185. return $result->toArray();
  186. }
  187. public function fetchfreequencyofdeposit() {
  188. $select = $this->select()
  189. ->setIntegrityCheck(false)
  190. ->join(array('a' => 'ourbank_frequencyofpayment'),array('a.timefrequncy_id','a.timefrequencytype'))
  191. ->where('a.timefrequencytype != "One time"')
  192. ->where('a.timefrequencytype != "Any time"');
  193. $result = $this->fetchAll($select);
  194. return $result->toArray();
  195. }
  196. public function paymentUpdates($id,$accountId,$input = array()) {
  197. $this->db = Zend_Db_Table::getDefaultAdapter();
  198. $where[] = "rec_payment_id = '".$id."'";
  199. $where[] = "account_id = '".$accountId."'";
  200. $result = $this->db->update('ourbank_recurringpaydetails',$input,$where);
  201. $recurrpay_id=$input['rec_payment_status'];
  202. $select="select rec_payment_id from ourbank_recurringpaydetails where rec_payment_status=$recurrpay_id and account_id=$accountId and (recordstatus_id=3 or recordstatus_id=1)";
  203. $result = $this->db->fetchAll($select);
  204. foreach($result as $recuupay_id) {
  205. $recirringpayment_id=$recuupay_id['rec_payment_id'];
  206. }
  207. $recirringpayment_id1=$recirringpayment_id+1;
  208. $where1[] = "rec_payment_id = '".$recirringpayment_id1."'";
  209. $where1[] = "account_id = '".$accountId."'";
  210. $rec_payment_status =array('rec_payment_status' =>4);
  211. $result = $this->db->update('ourbank_recurringpaydetails',$rec_payment_status,$where1);
  212. }
  213. public function recurringPaymentInsertion($input = array()) {
  214. $this->db = Zend_Db_Table::getDefaultAdapter();
  215. $result = $this->db->insert('ourbank_recurring_payment',$input);
  216. return $result;
  217. }
  218. public function grouprecurringInsert($input = array())
  219. {
  220. $this->db = Zend_Db_Table::getDefaultAdapter();
  221. $result = $this->db->insert('ourbank_groupmember_recurringtransaction',$input);
  222. return $result;
  223. }
  224. public function interestperiods($productId) {
  225. $this->db = Zend_Db_Table::getDefaultAdapter();
  226. $sql = "select max(period_ofrange_monthto) from ourbank_interest_periods where offerproduct_id='$productId' AND intereststatus_id=3 ";
  227. $result = $this->db->fetchOne($sql);
  228. return $result;
  229. }
  230. public function ourbankRecurringInsertion($input = array()) {
  231. $this->db = Zend_Db_Table::getDefaultAdapter();
  232. $this->db->insert("ourbank_recurringaccounts",$input);
  233. return '1';
  234. }
  235. public function groupAccountInsertion($input = array()) {
  236. $this->db = Zend_Db_Table::getDefaultAdapter();
  237. $this->db->insert("ourbank_groupmembers_acccounts",$input);
  238. return '1';
  239. }
  240. public function ourbankRecurringInstalmentsInsertion($input = array()) {
  241. $this->db = Zend_Db_Table::getDefaultAdapter();
  242. $this->db->insert("ourbank_recurringpaydetails",$input);
  243. return '1';
  244. }
  245. public function previousAccountClose($status,$input = array()) {
  246. $this->db = Zend_Db_Table::getDefaultAdapter();
  247. $where[] = "account_id = '".$status."'";
  248. $input1= array ('accountstatus_id' => '5');
  249. $result = $this->db->update('ourbank_accounts',$input1,$where);
  250. $input2= array('fixedaccountstatus_id' => '5','recordstatus_id' => '5');
  251. $result = $this->db->update('ourbank_recurringaccounts',$input2,$where);
  252. $input3= array('rec_payment_status' => '2','recordstatus_id'=> '5');
  253. $result = $this->db->update('ourbank_recurringpaydetails',$input3,$where);
  254. }
  255. public function accountNumberSearch($accountId) {
  256. $select = $this->select()
  257. ->setIntegrityCheck(false)
  258. ->join(array('a' => 'ourbank_accounts'),array('a.account_number'))
  259. ->where('a.account_id = ?',$accountId);
  260. $result = $this->fetchAll($select);
  261. return $result->toArray();
  262. }
  263. public function groupNamesSavingsearch($searchedAccountId) {
  264. $this->db = Zend_Db_Table::getDefaultAdapter();
  265. $sql = "SELECT D.groupname,D.group_id,A.membercode,E.account_number FROM ourbank_members A,ourbank_groupaddress D,ourbank_accounts E WHERE E.account_id='$searchedAccountId' AND A.member_id=D.group_id AND E.member_id=A.member_id AND D.recordstatus_id=3 ";
  266. $result = $this->db->fetchAll($sql,array($searchedAccountId));
  267. return $result;
  268. }
  269. public function recurringaccountstatusChange($id,$input = array()) {
  270. $this->db = Zend_Db_Table::getDefaultAdapter();
  271. $where[] = "account_id = '".$id."'";
  272. $result = $this->db->update('ourbank_recurringaccounts',$input,$where);
  273. }
  274. public function recurringpaydetailsChange($id,$input = array()) {
  275. $this->db = Zend_Db_Table::getDefaultAdapter();
  276. $where[] = "account_id = '".$id."'";
  277. $result = $this->db->update('ourbank_recurringpaydetails',$input,$where);
  278. }
  279. public function getDelayFine() {
  280. $select = $this->select()
  281. ->setIntegrityCheck(false)
  282. ->join(array('a' => 'ourbank_feedetails'),array('fee_id'))
  283. ->where('a.feename = "recurrings" or a.feename = "deposit"')
  284. ->where('a.recordstatus_id = 3 OR a.recordstatus_id = 1');
  285. $result = $this->fetchAll($select);
  286. return $result->toArray();
  287. }
  288. public function instalmentStatus($accountId,$InstalmentNumber,$instalmentStstus) {
  289. $this->db = Zend_Db_Table::getDefaultAdapter();
  290. $where1[] = "account_id = '".$accountId."'";
  291. $where1[] = "rec_payment_id = '".$InstalmentNumber."'";
  292. $where1[] = "rec_payment_status != 2";
  293. $input3= array('rec_payment_status' =>$instalmentStstus);
  294. $result1 = $this->db->update('ourbank_recurringpaydetails',$input3,$where1);
  295. return $result1;
  296. }
  297. }