Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
where('branch_id',Session::get('user')['branch_id'])->where('id',$id)->get(); foreach($data as $d){ $dd = $d->name; } return $dd; } public static function get_borrower_id($id,$id2){ $bb=0; if($id2=='person'){ foreach(DB::table('borrowers')->where('id',$id)->get() as $borrower){ $bb = ucfirst(strtolower($borrower->firstName))." ".ucfirst(strtolower($borrower->middleName))." ".ucfirst(strtolower($borrower->lastName)); } }else{ if(!$bb){ foreach(DB::table('borrowergroups')->where('id',$id)->get() as $borrower){ $bb = ucfirst(strtolower($borrower->groupName)); } } } return $bb; } public static function get_borrower_info($id){ $bb=DB::table('borrowers')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } ##validate saving transactions... public static function validate_savings_transactions(Request $request){ $ex=$request->id; if($ex=='saccos'){ echo json_encode(array('html'=>'','no'=>1)); }else{ $ex=explode('/',$request->id); $acc_id=$ex[0]; $user_id=$ex[1]; $amount=$request->am; $t=explode('/',$request->type); $type=$t[0]; $acc=DB::table('savingaccount')->where('id',$acc_id)->where('branch_id',Session::get('user')['branch_id'])->where('borrower_id',$user_id)->get(); foreach($acc as $row_acc){ $product=DB::table('savingproduct')->where('id',$row_acc->savingProduct_id)->get(); foreach($product as $row){ $cr=DB::table('savingtransactions')->where('account_id',$acc_id)->where('debitCredit','credit')->where('branch_id',Session::get('user')['branch_id'])->sum('amount'); $dr=DB::table('savingtransactions')->where('account_id',$acc_id)->where('debitCredit','debit')->where('branch_id',Session::get('user')['branch_id'])->sum('amount'); $ledger1=$cr-$dr; $ledger=number_format($cr-$dr); #check customer active loan... $bal=$sum_amount=$guarantor=$due_loan=0; $loan=DB::table('loans')->where('status','granted')->where('borrower_id',$user_id)->get(); foreach($loan as $row_loan){ $guarantor=DB::table('guarantor')->where('branch_id',Session::get('user')['branch_id'])->where('loan_id',$row_loan->id)->where('guarantor_id',$user_id)->sum('amount'); $due_loan=$row_loan->dueAmount; $bal=$due_loan-$guarantor; } #check if customer has guarantee loan $guarantor2=DB::table('guarantor')->where('branch_id',Session::get('user')['branch_id'])->where('guarantor_id',$user_id)->get(); foreach($guarantor2 as $row_g2){ $loan2=DB::table('loans')->where('branch_id',Session::get('user')['branch_id'])->where('status','granted')->where('id',$row_g2->loan_id)->count(); if($loan2>0){ $sum_amount=DB::table('guarantor')->where('branch_id',Session::get('user')['branch_id'])->where('loan_id',$row_g2->loan_id)->where('guarantor_id',$user_id)->sum('amount'); } } $ava_bal=$ledger1-$bal-$sum_amount; $w_bal=$ava_bal-$row->minimum_amount; ?> $w_bal){ $no = 0; $html = '
Insufficient Fund

Account Informations

Account Balance:'. $ledger.' | Available Ballance:'. $ava_bal.'| Withdrawable Ballance:'. $w_bal.'
Minimum Deposit:'. $row->deposit_minimum_amount.' | Minimum Amount:'. $row->minimum_amount.'

'; } elseif($type=='deposit' && $amount>=$row->deposit_minimum_amount){ $no = 1; $html = '
Amount Validated...
'; } elseif($type=='deposit' && $amount<$row->deposit_minimum_amount){ $no = 0; $html = '
Minimum deposit amount for this A/C is '.$row->deposit_minimum_amount.'

Account Informations

Account Balance:'. $ledger.' | Available Ballance:'. $ava_bal.'| Withdrawable Ballance:'. $w_bal.'
Minimum Deposit:'. $row->deposit_minimum_amount.' | Minimum Amount:'. $row->minimum_amount.'

'; } elseif($type=='withdrawal' && $amount<=$w_bal){ $bafter=$ava_bal-$amount; $no = 1; $html = '

Account Informations

Available Ballance:'.$ava_bal.' | Ballance after withdrawal:'.$bafter.'

'; } echo json_encode(array('html'=>$html,'no'=>$no)); } } } } public static function transact_savings($amount,$accountfrom,$accountto) { $datetime=date('Y-m-d').' '.date("H:i:s"); $type='transfer'; $debitCredit='debit'; $from=explode('/',$accountfrom); $account_id=$from[0]; $borrower_id=$from[1]; $to=explode('/',$accountto); $account_id2=$to[0]; $borrower_id2=$to[1]; // $fee=$request->feeAmount; $data = array( 'branch_id'=>Session::get('user')['branch_id'], 'borrower_id'=>$borrower_id, 'account_id'=>$account_id, 'amount'=>$amount, 'debitCredit'=>$debitCredit, 'type'=>$type, 'datetime'=>$datetime, 'description'=>'Transfer', 'registered_by'=>Auth::id(), 'date'=>date('Y-m-d'), ); DB::table('savingtransactions')->insert($data); // $fee=$request->feeAmount; $data1 = array( 'branch_id'=>Session::get('user')['branch_id'], 'borrower_id'=>$borrower_id2, 'account_id'=>$account_id2, 'amount'=>$amount, 'debitCredit'=>'credit', 'type'=>$type, 'datetime'=>$datetime, 'description'=>'Transfer', 'registered_by'=>Auth::id(), 'date'=>date('Y-m-d'), ); DB::table('savingtransactions')->insert($data1); ##daily ledger####### /* $ledger_account=18; if($debitCredit=='credit'){ $ledger_crdr='debit'; }else{ $ledger_crdr='credit'; } $ledger1 = array( 'branch_id'=>Session::get('user')['branch_id'], 'ledger_account_id'=>$ledger_account, 'amount'=>$request->amount, 'cr_dr'=>$ledger_crdr, 'time'=>$datetime, 'date'=>date('Y-m-d'), ); DB::table('daily_ledger')->insert($ledger1); $ledger2 = array( 'branch_id'=>Session::get('user')['branch_id'], 'ledger_account_id'=>30, 'amount'=>$request->amount, 'cr_dr'=>$debitCredit, 'time'=>$datetime, 'date'=>date('Y-m-d'), ); DB::table('daily_ledger')->insert($ledger2); if($type=="withdrawal"){ ##daily ledger for withdrawal fee####### //check percent or amount... $a=0; if(is_numeric($fee)){ $a=$fee; }else{ $a=str_replace('%','',$fee); $a=(($a/100)*$request->amount); } #insert fee transaction $datafee = array( 'branch_id'=>Session::get('user')['branch_id'], 'borrower_id'=>$borrower_id, 'account_id'=>$account_id, 'amount'=>$a, 'debitCredit'=>'debit', 'type'=>'Withdrawal fee', 'datetime'=>$datetime, 'description'=>$request->description, 'registered_by'=>Auth::id(), 'date'=>date('Y-m-d'), ); DB::table('savingtransactions')->insert($datafee); #end fee... $ledger_account=30; $datetime=date('H:i:s'); $ledger1 = array( 'branch_id'=>Session::get('user')['branch_id'], 'ledger_account_id'=>$ledger_account, 'amount'=>$a, 'cr_dr'=>'debit', 'time'=>$datetime, 'date'=>date('Y-m-d'), ); DB::table('daily_ledger')->insert($ledger1); $ledger2 = array( 'branch_id'=>Session::get('user')['branch_id'], 'ledger_account_id'=>49, 'amount'=>$a, 'cr_dr'=>'credit', 'time'=>$datetime, 'date'=>date('Y-m-d'), ); DB::table('daily_ledger')->insert($ledger2); } ##daily ledger####### // return redirect('share/add_shareholder');*/ } public static function get_borrower_info_group($id){ $bb=DB::table('borrowergroups')->where('branch_id',Session::get('user')['branch_id'])->where('id',$id)->get(); return $bb; } public static function get_groupmembers_info($id){ $bb=DB::table('borrowergroupmembers')->where('branch_id',Session::get('user')['branch_id'])->where('borrowergroup_id',$id)->get(); return $bb; } public static function get_borrower_files($id){ $bb=DB::table('borrower_documents')->where('branch_id',Session::get('user')['branch_id'])->where('borrower_id',$id)->get(); return $bb; } public static function get_guarantor_files($id){ $bb=DB::table('guarantor_documents')->where('branch_id',Session::get('user')['branch_id'])->where('guarantor_id',$id)->get(); return $bb; } public static function get_expensestype_id($id){ $bb=DB::table('expensetype')->get(); return $bb; } public static function get_assettype_id($id){ $bb=DB::table('assettype')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_assetfiles_id($id){ $bb=DB::table('asset_documents')->where('asset_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_assets_sum_by_type($id){ $value=DB::table('assets')->where('assettype_id',$id) ->where('branch_id',Session::get('user')['branch_id']) ->select(DB::raw('SUM(currentValue) as value')) ->where('branch_id',Session::get('user')['branch_id']) ->get(); foreach($value as $row){ $amount=$row->value; } return $amount; } public static function get_collateral_id($id){ $bb=DB::table('collateraltype')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_collateralfiles_by_id($id){ $bb=DB::table('collateralregister_documents')->where('collateralregister_id',$id)->get(); return $bb; } public static function get_expensesfiles_by_id($id){ $bb=DB::table('expenses_documents')->where('expenses_id',$id)->get(); return $bb; } public static function get_incomesfiles_by_id($id){ $bb=DB::table('income_documents')->where('income_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_collateral_by_id($id){ $bb=DB::table('collateralregister')->where('loan_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_incometypes_id($id){ $bb=DB::table('incometypes')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_incomes_by_id($id){ $bb=DB::table('incomes')->where('linkToloan',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_expenses_info(){ $bb=DB::table('expenses')->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_expenses_info_by_id($id){ $bb=DB::table('expenses')->where('linkToloan',$id)->get(); return $bb; } public static function get_guarantor_id($id){ $bb=""; foreach(DB::table('guarantor')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get() as $borrower){ $bb = ucfirst(strtolower($borrower->title))." ".ucfirst(strtolower($borrower->firstName))." ".ucfirst(strtolower($borrower->middleName))." ".ucfirst(strtolower($borrower->lastName)); } return $bb; } public static function get_staff_id($id){ $bb=""; foreach(DB::table('users')->where('branch_id',Session::get('user')['branch_id'])->where('id',$id)->get() as $borrower){ $bb = ucfirst($borrower->name); } return $bb; } public static function get_share_by_id($id){ $id=base64_decode($_REQUEST['id']); $shareInfo = DB::table('shareSettings')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $shareInfo; } public static function get_share_info(){ $shareInfo = DB::table('shareSettings')->where('branch_id',Session::get('user')['branch_id'])->get(); return $shareInfo; } public function download(Request $request) { $path=base64_decode($request->id); $file = public_path()."".$path; $headers = array('Content-Type: application/pdf',); return Response::download($file); } public static function get_savingtransactions($id){ $bb=DB::table('savingtransactions')->where('borrower_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_last_savingtransactions($id){ $bb=DB::table('savingtransactions')->where('account_id',$id)->orderBy('id','DESC')->limit(1)->get(); return $bb; } public static function get_last_deposittransactions($id){ $bb=DB::table('deposittransactions')->where('account_id',$id)->orderBy('id','DESC')->limit(1)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_savingtransactions_by_type($id3,$id2,$id){ $bb=DB::table('savingtransactions')->where('account_id',$id)->where('type',$id3)->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); foreach($bb as $ledger){ $bbc = $ledger->amount; } return $bbc; } public static function get_deposittransactions_by_type($id3,$id2,$id){ $bb=DB::table('savingtransactions')->where('account_id',$id)->where('type',$id3)->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); foreach($bb as $ledger){ $bbc = $ledger->amount; } return $bbc; } public static function get_savingtransactions_credit($id,$id2){ $bb=DB::table('savingtransactions')->where('account_id',$id)->where('debitCredit','credit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } public static function get_savingtransactions_debit($id,$id2){ $bb=DB::table('savingtransactions')->where('account_id',$id)->where('debitCredit','debit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } public static function get_deposittransactions_credit($id,$id2){ $bb=DB::table('deposittransactions')->where('account_id',$id)->where('debitCredit','credit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } public static function get_deposittransactions_debit($id,$id2){ $bb=DB::table('deposittransactions')->where('account_id',$id)->where('debitCredit','debit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } //sum of all branch savings public static function get_savingsum_credit(){ $id2=Session::get('user')['branch_id']; $bb=DB::table('savingtransactions')->where('debitCredit','credit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } public static function get_savingsum_debit(){ $id2=Session::get('user')['branch_id']; $bb=DB::table('savingtransactions')->where('debitCredit','debit')->where('branch_id',$id2)->select(DB::raw('SUM(amount) as amount'))->get(); return $bb; } public static function get_transactiontype($id){ $bb=DB::table('transactiontype')->where('branch_id',Session::get('user')['branch_id'])->where('id',$id)->get(); $name=""; foreach($bb as $t){ $name = $t->name; } return $name; } public static function get_savingaccount_by_id($id){ $bb=DB::table('savingaccount')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_depositaccount_by_id($id){ $bb=DB::table('depositaccount')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function update_savings_fee(){ /* $acc=DB::table('savingaccount')->get(); $b=array(); foreach($acc as $ac){ $sv=DB::table('savingproduct')->where('id',$ac->savingProduct_id)->get(); foreach($sv as $svrow){ $spf=DB::table('savingproductfees')->where('savingproduct_id',$svrow->id)->get(); foreach($spf as $spfrow){ $sf=DB::table('savingfee1')->where('id',$spfrow->savingfee_id)->get(); $data=array(); foreach($sf as $sfrow){ $datetime=date('Y-m-d h:i'); $data['account_id']=$ac->id; $data['product_id']=$svrow->id; $data['product_fees_id']=$spfrow->id; $data['account_fees']=$sfrow->feeAmount; $data['feename']=$sfrow->feeName; $tdate=date('Y').'-'.date('m').'-'.$sfrow->whenFeeAdded; $feeFrequency=$sfrow->feeFrequency; $lasttr=DB::table('savingtransactions')->where('account_id',$ac->id)->where('type','fee')->where('date',$tdate)->where('description',$data['feename'])->orderBy('id','DESC')->limit(1)->get(); $check=$feeFrequency; foreach($lasttr as $lastrow){ $time=strtotime($lastrow->date); $month=date("m",$time); $check=$month-date('m'); } $tr=DB::table('savingtransactions')->where('account_id',$ac->id)->where('type','fee')->where('date',$tdate)->where('description',$data['feename'])->count(); if($tr==0 && $check==$feeFrequency && date('d')>=$sfrow->whenFeeAdded){ echo date('d').'=='.$sfrow->whenFeeAdded.' yes naadi '; $insert = array( 'branch_id'=>$ac->branch_id, 'borrower_id'=>$ac->borrower_id, 'account_id'=> $data['account_id'], 'amount'=>$data['account_fees'], 'debitCredit'=>'debit', 'type'=>'fee', 'datetime'=>$datetime, 'description'=>$data['feename'], 'registered_by'=>$ac->registered_by, 'date'=>$tdate, ); DB::table('savingtransactions')->insert($insert); }else{ //do nothing... } } $b[]=$data; } } } */ } public static function get_savingproduct_by_id($id){ $bb=DB::table('savingproduct')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($bb as $row){ $name=$row->name; } return $name; } public static function get_creditbalance_by_id($id){ $creditledge=DB::table('savingtransactions')->where('debitCredit','credit')->where('branch_id',Session::get('user')['branch_id'])->where('account_id',$id)->select(DB::raw('SUM(amount) as amount'))->get(); foreach($creditledge as $row){ $amount=$row->amount; } return $amount; } public static function get_debtbalance_by_id($id){ $debitledge=DB::table('savingtransactions')->where('debitCredit','debit')->where('branch_id',Session::get('user')['branch_id'])->where('account_id',$id)->select(DB::raw('SUM(amount) as amount'))->get(); foreach($debitledge as $row){ $amount=$row->amount; } return $amount; } public static function get_savingaccount_by_borrower_id($id){ $bb=DB::table('savingaccount')->where('borrower_id',$id)->where('branch_id',Session::get('user')['branch_id'])->where('borrowerType','person')->get(); return $bb; } public static function get_depositaccount_by_borrower_id($id){ $bb=DB::table('depositaccount')->where('borrower_id',$id)->where('borrowerType','person')->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_savingaccount_by_borrowergroup_id($id){ $bb = DB::table('savingaccount')->where('borrower_id',$id)->where('borrowerType','group')->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_depositaccount_by_borrowergroup_id($id){ $bb = DB::table('depositaccount')->where('borrower_id',$id)->where('borrowerType','group')->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loan_by_borrowergroup_id($id){ $bb = DB::table('loans')->where('borrower_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loan_by_borrowertype_id($id,$id2){ $bb = DB::table('loans')->where('borrowerType',$id2)->where('borrower_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loantype_id($id){ $bb = DB::table('loans')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($bb as $t){ $bb=$t->borrowerType; } return $bb; } public static function get_loan_by_loanProduct_id($id){ $bb = DB::table('loans')->where('loanProduct',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function search_loan_by_loanProduct_id($id,$from,$to){ if($from == "" && $to == ""){ $result = DB::table('loans')->where('loanProduct',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); }elseif($from != "" && $to == ""){ $result = DB::table('loans')->where('loanProduct',$id)->where('loanReleaseDate','>=',$from)->where('branch_id',Session::get('user')['branch_id'])->get(); }else{ $result = DB::table('loans')->where('loanProduct',$id)->where('loanReleaseDate','>=',$from)->where('loanReleaseDate','<=',$to)->where('branch_id',Session::get('user')['branch_id'])->get(); } return $result; } public static function get_loan_by_id($id){ $bb = DB::table('loans')->where('id',$id)->get(); return $bb; } public static function get_loancomments_by_id($id){ $bb = DB::table('loancomments')->where('loan_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loancomments(){ $bb = DB::table('loancomments')->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loanproduct_by_id($id){ $bb = DB::table('loanproducts')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loanrepayments_by_id($id){ $bb = DB::table('loanrepayments')->where('loan_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_loanschedule_by_id($id){ $bb = DB::table('repaymentschedule')->where('loan_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); return $bb; } public static function get_last_loanschedule_by_id($id){ $bb = DB::table('repaymentschedule')->where('loan_id',$id)->where('branch_id',Session::get('user')['branch_id'])->orderBy('id','DESC')->limit(1)->get(); foreach($bb as $d){ $bb = $d->dueDate; } return $bb; } public static function get_borrowergroup_by_id($id){ $bb=''; foreach(DB::table('borrowergroups')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get() as $account){ $bb= $account->groupName; } return $bb; } public static function get_groupUniqueNumber($id){ $bb=''; foreach(DB::table('borrowergroups')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get() as $account){ $bb= $account->uniqueNumber; } return $bb; } public static function get_borrowerUniqueNumber($id){ $bb=""; foreach(DB::table('borrowers')->select('uniqueNumber')->where('branch_id',Session::get('user')['branch_id'])->where('id',$id)->get() as $borrower){ $bb = $borrower->uniqueNumber; } return $bb; } public static function get_savingproduct_byid($id){ $dd=""; $data = DB::table('savingproduct')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dd = $d->name; } return $dd; } public static function get_depositproduct_byid($id){ $dd=""; $data = DB::table('depositproduct')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dd = $d->name; } return $dd; } public static function get_savingproduct_fees($id){ $dd=""; $data = DB::table('savingproductfees')->where('savingproduct_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); $dc=array(); foreach($data as $d){ $dd = $d->savingfee_id; $data = DB::table('savingfee1')->where('id',$dd)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dc[] = $d->feeName; } } return $data; } public static function get_depositproduct_fees($id){ $dd=""; $data = DB::table('depositproductfees')->where('depositproduct_id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); $dc=array(); foreach($data as $d){ $dd = $d->depositfee_id; $data = DB::table('depositfee1')->where('id',$dd)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dc[] = $d->feeName; } } return $dc; } public static function get_interest_method($id){ $dd=""; $data = DB::table('loaninterestmethods')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dd = $d->name; } return $dd; } public static function get_product_fees($id){ $dd=""; $data = DB::table('savingfee1')->where('id',$id)->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($data as $d){ $dd .= $d->feeName.', '; } return $dd; } public static function get_borrower_due_amount($loan,$borrower){ $am=0; foreach(DB::table('repaymentschedule')->where('borrower_id',$borrower)->select(DB::raw('SUM(amount) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get() as $aa){ $am = $aa->amount; } return $am; } public static function get_principal_paid($loan){ $am=0; foreach(DB::table('repaymentschedule')->where('loan_id',$loan)->select(DB::raw('SUM(principal_paid) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get() as $aa){ $am = $aa->amount; } return $am; } public static function get_principal_overdue($loan){ $am=0; foreach(DB::table('repaymentschedule')->where('loan_id',$loan)->select(DB::raw('SUM(overdue) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get() as $aa){ $am = $aa->amount; } return $am; } public static function get_borrower_penalty_amount($loan,$borrower){ $am=0; foreach(DB::table('repaymentschedule')->where('borrower_id',$borrower)->select(DB::raw('SUM(penalty) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get() as $aa){ $am = $aa->amount; } return $am; } public static function get_borrower_paid_amount($loan,$borrower){ $am=0; foreach(DB::table('loanrepayments')->where('loan_id',$loan)->where('borrower_id',$borrower)->where('approve_status','approved')->select(DB::raw('SUM(amount) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get() as $aa){ $am = $aa->amount; } return $am; } public static function get_borrower_paid_amount_range($loan,$borrower,$from,$to){ $am=0; $amount=DB::table('loanrepayments')->where('borrower_id',$borrower)->where('loan_id',$loan) ->where('collectionDate','>=',$from)->where('collectionDate','<=',$to) ->where('branch_id',Session::get('user')['branch_id']) ->where('approve_status','approved')->select(DB::raw('SUM(amount) as amount'))->get(); foreach($amount as $aa){ $am = $aa->amount; } return $am; } public static function get_borrower_paid_amount_range2($loan,$borrower,$loanproduct){ $am=0; $amount=DB::table('loanrepayments')->where('borrower_id',$borrower)->where('loanproduct_id',$loanproduct)->where('loan_id',$loan) ->where('approve_status','approved')->select(DB::raw('SUM(amount) as amount'))->where('branch_id',Session::get('user')['branch_id'])->get(); foreach($amount as $aa){ $am = $aa->amount; } return $am; } public static function get_borrower_last_repayment($loan,$borrower){ $am=$d=0; foreach(DB::table('loanrepayments')->where('branch_id',Session::get('user')['branch_id'])->where('borrower_id',$borrower)->orderBy('id','desc')->limit(1)->get() as $aa){ $d = $aa->collectionDate; $am = $aa->amount; } if($am>0){ return number_format($am,2).' '.$d; }else{ return $am; } } public static function get_loanproduct_last_repayment($productid){ $am=$d=0; foreach(DB::table('loanrepayments')->where('branch_id',Session::get('user')['branch_id'])->where('loanproduct_id',$productid)->orderBy('id','desc')->limit(1)->get() as $aa){ $d = $aa->collectionDate; $am = $aa->amount; } if($am>0){ return number_format($am,2).' '.$d; }else{ return $am; } } public static function send_sms($batch,$branch){ $header="AFELSMS"; $sms_price = 0; foreach(DB::table('sms_header')->where('branch_id',$branch)->get() as $smsheader){ $header = $smsheader->name; $sms_price = $smsheader->sms_price; } $sms = DB::table('sms_sent')->where('batch',$batch)->where('branch_id',$branch)->get(); $sms_count = $balance = 0; $messages_array = array(); foreach($sms as $message){ $sms_count = $sms_count + ceil(strlen($message->sms)/158); $messages_array[] = array( 'text' => $message->sms, 'msisdn' => $message->mobile, 'source' => $header, ); } foreach(DB::table('sms_balance')->where('branch_id',$branch)->get() as $balance){ $balance = $balance->amount; } $total_cost = $sms_price*$sms_count; if($balance >= $total_cost){ $postData = array( 'channel' => array( 'channel' => 118994, 'password' => "Y2M2YWUwNjc2ZWVmM2UzNWU5MzcwN2M1YTFlYTUxM2M0MTA2MjA4NzJiNWMyNDM5MzBiNGQ5MmFhNTJlOWNiMw==" ), 'messages' => $messages_array ); $ch = curl_init('https://secure-gw.fasthub.co.tz/fasthub/messaging/json/api'); curl_setopt_array($ch, array( CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), CURLOPT_POSTFIELDS => json_encode($postData) )); $responseData = curl_exec($ch); if (curl_error($ch)) { return 0; }else{ // updating the balance $new_balance = $balance - $total_cost; DB::table('sms_balance')->where('branch_id',$branch)->update(array('balance'=>$new_balance)); // Updating the status DB::table('sms_sent')->where('batch',$batch)->where('branch_id',$branch)->update(array('status'=>1)); // insert records for sms expenses; $expense = array( 'branch_id'=>$branch, 'batch'=>$batch, 'cost'=>$total_cost, ); DB::table('sms_expenses')->insert($expense); return 1; } }else{ return 0; } } }