コード例 #1
0
 public function actionMbalanceRefresh()
 {
     if (!empty($_POST)) {
         $from = $_POST['from'];
         $to = $_POST['to'];
         $days = strtotime($to) - strtotime($from);
         $newModel = Expense::model()->findAll(array('condition' => 'kind = 0', 'group' => 'date(order_date)'));
         $count = 0;
         $expense = new Expense();
         $summ = array();
         $summP = array();
         $dateList = array();
         for ($i = 0; $i < $days / (3600 * 24); $i++) {
             $mBalance = MBalance::model()->find('t.b_date = :dates', array(':dates' => date('Y-m-d', strtotime($from) + 3600 * 24 * $i)));
             $temp = $expense->getSum(date('Y-m-d', strtotime($from) + 3600 * 24 * $i));
             if (!empty($mBalance)) {
                 $mBalance->procProceeds = $temp[1];
                 $mBalance->proceeds = $temp[2];
                 $mBalance->cost = 0;
                 $mBalance->save();
             } else {
                 $mBalance = new MBalance();
                 $mBalance->b_date = date('Y-m-d', strtotime($from) + 3600 * 24 * $i);
                 $mBalance->procProceeds = $temp[1];
                 $mBalance->proceeds = $temp[2];
                 $mBalance->cost = 0;
                 $mBalance->save();
             }
         }
         $this->redirect('/');
     }
     $this->render('interval', array());
 }
コード例 #2
0
 public function sumMBalance($dates)
 {
     //расчет выручки
     //$stuff = new Halfstaff();
     $sumBalance = Expense::model()->findAll('date(t.order_date) = :dates AND t.status != :status AND t.debt != :debt', array(':dates' => $dates, ':status' => 1, 'debt' => 1));
     //$debt = Debt::model()->findAll('t.d_date = :dates',array(':dates'=>$dates));
     //$debts = array();
     $dayBalance = 0;
     $expense = new Expense();
     if (!empty($sumBalance)) {
         $dayBalance = $expense->getSum($dates);
     }
     $mBalance = MBalance::model()->find('t.b_date = :dates', array(':dates' => $dates));
     if (!empty($mBalance)) {
         $mBalance = $mBalance;
     } else {
         $mBalance = new MBalance();
     }
     $mBalance->procProceeds = $dayBalance[1];
     //+$debts[1];
     $mBalance->b_date = $dates;
     $mBalance->proceeds = $dayBalance[2];
     //+$debts[2];
     $mBalance->cost = 0;
     $mBalance->save();
 }