예제 #1
0
 public static function creditAccounts($data)
 {
     $savingaccount = Savingaccount::findOrFail(array_get($data, 'account_id'));
     $savingtransaction = new Savingtransaction();
     $savingtransaction->date = array_get($data, 'date');
     $savingtransaction->savingaccount()->associate($savingaccount);
     $savingtransaction->amount = array_get($data, 'amount');
     $savingtransaction->type = array_get($data, 'type');
     $savingtransaction->description = 'savings deposit';
     $savingtransaction->save();
     // deposit
     if (array_get($data, 'type') == 'credit') {
         foreach ($savingaccount->savingproduct->savingpostings as $posting) {
             if ($posting->transaction == 'deposit') {
                 $debit_account = $posting->debit_account;
                 $credit_account = $posting->credit_account;
             }
         }
         $data = array('credit_account' => $credit_account, 'debit_account' => $debit_account, 'date' => array_get($data, 'date'), 'amount' => array_get($data, 'amount'), 'initiated_by' => 'system', 'description' => 'cash deposit');
         $journal = new Journal();
         $journal->journal_entry($data);
         Audit::logAudit(date('Y-m-d'), Confide::user()->username, 'savings deposit', 'Savings', array_get($data, 'amount'));
     }
 }
예제 #2
0
파일: routes.php 프로젝트: kenkode/umash
    return View::make('autoloans', compact('loanproducts'));
});
Route::get('automated/savings', function () {
    $savingproducts = Savingproduct::all();
    return View::make('automated', compact('savingproducts'));
});
Route::post('automated', function () {
    $members = DB::table('members')->where('is_active', '=', true)->get();
    $category = Input::get('category');
    if ($category == 'savings') {
        $savingproduct_id = Input::get('savingproduct');
        $savingproduct = Savingproduct::findOrFail($savingproduct_id);
        foreach ($savingproduct->savingaccounts as $savingaccount) {
            if ($savingaccount->member->is_active && Savingaccount::getLastAmount($savingaccount) > 0) {
                $data = array('account_id' => $savingaccount->id, 'amount' => Savingaccount::getLastAmount($savingaccount), 'date' => date('Y-m-d'), 'type' => 'credit');
                Savingtransaction::creditAccounts($data);
            }
        }
        Autoprocess::record(date('Y-m-d'), 'saving', $savingproduct);
    } else {
        $loanproduct_id = Input::get('loanproduct');
        $loanproduct = Loanproduct::findOrFail($loanproduct_id);
        foreach ($loanproduct->loanaccounts as $loanaccount) {
            if ($loanaccount->member->is_active && Loanaccount::getEMP($loanaccount) > 0) {
                $data = array('loanaccount_id' => $loanaccount->id, 'amount' => Loanaccount::getEMP($loanaccount), 'date' => date('Y-m-d'));
                Loanrepayment::repayLoan($data);
            }
        }
        Autoprocess::record(date('Y-m-d'), 'loan', $loanproduct);
    }
    return Redirect::back()->with('notice', 'successfully processed');
 public function import()
 {
     if (Input::hasFile('saving')) {
         $destination = public_path() . '/uploads/savings/';
         $filename = date('Y-m-d');
         $ext = Input::file('saving')->getClientOriginalExtension();
         $photo = $filename . '.csv';
         $file = Input::file('saving')->move($destination, $photo);
         //$file = public_path().'/uploads/savings/'.$filename;
         $row = 1;
         $saving = array();
         if (($handle = fopen(public_path() . '/uploads/savings/' . $photo, "r")) !== FALSE) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 echo '<pre>';
                 $saving[] = array('date' => $data[0], 'member' => $data[1], 'account' => $data[2], 'amount' => $data[3]);
             }
             $i = 1;
             for ($i = 1; $i < count($saving); $i++) {
                 $member = $saving[$i]['member'];
                 $account = $saving[$i]['account'];
                 $amount = $saving[$i]['amount'];
                 $date = $saving[$i]['date'];
                 $member_no = DB::table('members')->where('membership_no', '=', $member)->get();
                 if (empty($member_no)) {
                     return Redirect::to('import')->with('error', 'The member does not exist');
                 }
                 $account_no = DB::table('savingaccounts')->where('account_number', '=', $account)->get();
                 if (empty($account_no)) {
                     return Redirect::to('import')->with('error', 'The saving account does not exist');
                 }
                 Savingtransaction::importSavings($member_no, $date, $account_no, $amount);
             }
             fclose($handle);
         }
     }
     return Redirect::to('/')->with('notice', 'Member savings successfully imported');
 }