当前位置: 首页>>代码示例>>PHP>>正文


PHP Stock::setTotal方法代码示例

本文整理汇总了PHP中Stock::setTotal方法的典型用法代码示例。如果您正苦于以下问题:PHP Stock::setTotal方法的具体用法?PHP Stock::setTotal怎么用?PHP Stock::setTotal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stock的用法示例。


在下文中一共展示了Stock::setTotal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 public function create($data)
 {
     $currentUser = parent::authenticateUser();
     $stock = new Stock();
     if (isset($data->total) && isset($data->date)) {
         $stock->setDate($data->date);
         $stock->setTotal($data->total);
         $stock->setOwner($currentUser->getLogin());
         try {
             $idStock = $this->stockDAO->save($stock);
             header($this->server->getServerProtocol() . ' 201 Created');
             header('Location: ' . $this->server->getRequestUri() . "/" . $idStock);
             header('Content-Type: application/json');
         } catch (ValidationException $e) {
             header($this->server->getServerProtocol() . ' 400 Bad request');
             echo json_encode($e->getErrors());
         }
     }
 }
开发者ID:adri229,项目名称:wallas,代码行数:19,代码来源:StockRest.php

示例2: getPositions

 /**
  * Metodo que contiene el algoritmo para la generacion de posiciones.
  * Ver diagrama de actividades del Manual Tecnico, pag 67.
  *
  */
 public function getPositions($owner)
 {
     $currentUser = parent::authenticateUser();
     $startDate = $this->request->getStartDate();
     $endDate = $this->request->getEndDate();
     $stockRef = $this->stockDAO->findByOwnerAndDate($owner, $startDate);
     $stocks = $this->stockDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     $spendings = $this->spendingDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     $revenues = $this->revenueDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     if ($stocks == NULL && $spendings == NULL && $revenues == NULL) {
         header($this->server->getServerProtocol() . ' 400 Bad request');
         echo "The defined interval time not contains spendings";
         return;
     }
     $stocksChart = [];
     $stocks_array = [];
     $begin = new DateTime($startDate);
     $end = new DateTime($endDate);
     $interval = DateInterval::createFromDateString('1 month');
     $period = new DatePeriod($begin, $interval, $end);
     foreach ($period as $dt) {
         $aux = new DateTime($dt->format("Y-m-d"));
         $initMonth = $dt;
         $topMonth = $aux->add($interval);
         foreach ($stocks as $stock) {
             if ($stock->getDate() >= $initMonth->format("Y-m-d") && $stock->getDate() < $topMonth->format("Y-m-d")) {
                 $stockRef = $stock;
             }
         }
         $quantitySpendings = 0;
         foreach ($spendings as $spending) {
             if ($stockRef != NULL) {
                 if ($spending->getDate() >= $stockRef->getDate() && $spending->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantitySpendings += $spending->getQuantity();
                 }
             } else {
                 if ($spending->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantitySpendings += $spending->getQuantity();
                 }
             }
         }
         $quantityRevenues = 0;
         foreach ($revenues as $revenue) {
             if ($stockRef != NULL) {
                 if ($revenue->getDate() >= $stockRef->getDate() && $revenue->getDate() < $topMonth->format("Y-m-d")) {
                     $quantityRevenues += $revenue->getQuantity();
                 }
             } else {
                 if ($revenue->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantityRevenues += $revenue->getQuantity();
                 }
             }
         }
         if ($stockRef != NULL) {
             $total = $stockRef->getTotal() + $quantityRevenues - $quantitySpendings;
         } else {
             $total = $quantityRevenues - $quantitySpendings;
         }
         $stockChart = new Stock();
         $stockChart->setTotal($total);
         $stockChart->setDate($dt->format("Y-m-d"));
         array_push($stocksChart, $stockChart);
         $quantitySpendings = 0;
         $quantityRevenues = 0;
     }
     foreach ($stocksChart as $stock) {
         array_push($stocks_array, ["date" => $stock->getDate(), "total" => $stock->getTotal()]);
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($stocks_array);
 }
开发者ID:adri229,项目名称:wallas,代码行数:77,代码来源:PositionRest.php


注:本文中的Stock::setTotal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。