Exemplo n.º 1
0
 public function getTotalDebtsForUser($user)
 {
     $debts = array();
     $this->dbQuery("SELECT * FROM debt WHERE idUser1='" . $user->getID() . "' AND payed='0' ORDER BY idUser2");
     while ($r = $this->getResult()) {
         $i = $this->debtExists($debts, $r['idUser1'], $r['idUser2']);
         if ($i > -1) {
             $debt = $debts[$i];
             $amount = $debt->getAmount();
             $amount += $r['amount'];
             $debt->setAmount($amount);
         } else {
             $userStore = new UserStore($this->db);
             $user1 = $userStore->getUserFromID($r['idUser1']);
             $user2 = $userStore->getUserFromID($r['idUser2']);
             $debt = new Debt($r['idDebt'], $user1, $user2, $r['amount']);
             $debt->setDescription("Total to pay");
             array_push($debts, $debt);
         }
     }
     return $debts;
 }
 public function detailAction($id)
 {
     $id = $this->filter->sanitize($id, array("int"));
     if ($id) {
         $searchParams = array("id = '" . $id . "'");
         $debts = Debts::findFirst($searchParams);
         $this->view->setVar("debts", $debts);
         $debt = Debt::find("fid = " . $id);
         $this->view->debt = $debt;
         $this->view->website = FILEWEBNAME;
         $match = Match::find("debt_number  = '" . $debts->number . "'");
         $this->view->match = $match;
         foreach ($match as $key => $val) {
         }
         fb($match->toArray());
     } else {
         $this->flash->error("没有找到对应的债权");
         return $this->forward("debt/index");
     }
 }
Exemplo n.º 3
0
}
$user_id = $_COOKIE['user_id'];
$total = 0;
// Connect to database
$con = mysql_connect(DB_HOST, DB_USER, DB_PW);
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $con);
// if the form has been submitted
if (isset($_POST['submit_check'])) {
    $paymentObj = new Payment();
    $paymentObj->setUser_id($user_id);
    $paymentObj->create();
    $payment_id = mysql_insert_id();
    $debtObj = new Debt();
    $debtObj->setOwed_to($user_id);
    $debtObj->setPayment_id($payment_id);
    $total = 0;
    for ($i = 0; $i < count($_POST["user_id"]); $i++) {
        $debtObj->setOwed_by($_POST['user_id'][$i]);
        $debt_total = $_POST['drinks_owed'][$i] + $_POST['food_owed'][$i];
        $total += $debt_total;
        $debtObj->setAmount($debt_total);
        $debtObj->create();
        //echo "<p>" . $_POST['user_id'][$i] . " owes " . $_COOKIE['user_id'] . " &pound;" . $_POST['drinks_owed'][$i] . " for drinks and &pound;" . $_POST['food_owed'][$i] . " for food for a total of &pound;" . $total . "</p>";
    }
    $paymentObj->setId($payment_id);
    $paymentObj->setTotal($total);
    $paymentObj->setDate($_POST['date']);
    $paymentObj->update();
Exemplo n.º 4
0
<?php

include_once 'header.php';
include_once 'users.class.php';
include_once 'debts.class.php';
include_once 'payments.class.php';
if (!isset($userObj)) {
    $userObj = new User();
    $userObj->setId($user_id);
    $userObj->load();
}
$debtObj = new Debt();
?>
<div class="row">
    <div class="span12">
        <h3 class="underline">Total Debts</h3>
        <table id="debt-table" class="table table-striped">
            <?php 
$total_debts = Debt::getTotalDebts();
$total_str = "";
if (is_array($total_debts) && count($total_debts) > 0) {
    foreach ($total_debts as $total_name_id => $total_owed) {
        if ($total_owed > 0) {
            $userObj->setId($total_name_id);
            $userObj->load();
            $total_name = $userObj->getName();
            $total_str .= "<tr><td>{$total_name}</td><td>&pound;" . number_format($total_owed) . "</td></tr>";
        }
    }
}
?>
Exemplo n.º 5
0
 public function actionPaidDebt()
 {
     $model = Debt::model()->with('expense')->findAll();
     $this->render('paidDebt', array('model' => $model));
 }
Exemplo n.º 6
0
 public function getSum($dates)
 {
     $percent = new Percent();
     $summa = 0;
     $summaP = 0;
     $curPercent = 0;
     $employee = Employee::model()->findAll();
     $stuff = new Halfstaff();
     $debt = Debt::model()->findAll('t.d_date = :dates', array(':dates' => $dates));
     $debts = array();
     foreach ($employee as $vals) {
         $summ = 0;
         if ($vals->check_percent == 1) {
             $curPercent = $percent->getPercent($dates);
         } else {
             $curPercent = 0;
         }
         $model = Yii::app()->db->CreateCommand()->select('t.expense_id')->from('expense t')->where('date(t.order_date) = :dates AND t.kind = :kind AND t.employee_id = :empId AND t.status != :status AND t.debt != :debt', array(':dates' => $dates, ':kind' => 0, ':empId' => $vals->employee_id, ':status' => 1, ':debt' => 1))->queryAll();
         /*$model = Expense::model()->with()->findAll( 'date(t.order_date) = :dates AND t.kind = :kind AND t.employee_id = :empId AND t.status != :status AND t.debt != :debt', array(
         
         				    ':dates' => $dates,
         				    ':kind'  => 0,
         			        ':empId' => $vals->employee_id,
                             ':status'=> 1,
                             ':debt' => 1
         			    ) );*/
         if (!empty($model)) {
             foreach ($model as $value) {
                 $summ = $summ + $this->getExpenseSum($value['expense_id'], $dates);
             }
         }
         $tempSumm = $summ / 100 * $curPercent + $summ;
         $summaP = round($tempSumm / 100) * 100 + $summaP;
         $summa = round(($summ + $summa) / 100) * 100;
     }
     if (!empty($debt)) {
         foreach ($debt as $value) {
             $debts = $stuff->sumArray($debts, $this->getExpenseProcSum($value->expense_id, $dates));
         }
     }
     return array(1 => $summaP + $debts[1], 2 => $summa + $debts[2]);
 }