本文整理汇总了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());
}
}
}
示例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);
}