<?php
namespace Times\EigyoBundle\Controller;
//use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Times\EigyoBundle\Common\TimesStatic;
use Times\EigyoBundle\Entity\Virtual\SalesResults;
/**
* Description of TopController
*
* @author kawaguchi@kuzilla.co.jp
*/
class TopController extends BaseController
{
/**
* index
* @return type
*/
public function indexAction()
{
// 権限チェック
// $this->canUseCheck();
$em = $this->getDoctrine()->getManager();
$isManager = TimesStatic::getRoleManager()->isManager();
// ** 表示対象支店の一覧を取得
if ($isManager) {
$targetBranchIds = TimesStatic::getRoleManager()->getManageBranchIds();
} else {
$targetBranchIds = array($this->getUser()->getBranchId());
}
// -- お知らせ --------------
// ** TODOチェック
$todoCheckList = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->findForTodoList($this->getUser(), $isManager);
// ** TODO: 人事お知らせ
// ** お知らせ
$news = array(
'etc' => array(), /* システム系などいろいろ */
// 'todo' => $todoCheckList, /* TODOのチェック */
'jinji' => TimesStatic::getJinjiKoukaApiManager()->getEmployeeAlertList($this->getUser()->getEmployeeId()), /* 人事考課のお知らせ */
);
// ** システム系のお知らせは共通
// $news['etc'] = array(
// 'warn'=>"ワーニング",
// 'danger' => 'でんじゃー',
// 'info' => 'おしらせ',
// );
// ----- 新着・取引中案件一覧 -------------------------
// ** 新着情報
// 一般・管理者: 全社かつ24時間以内
// $newItems = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->findForNewItemsList($this->getUser(), $isManager);
// 2016/12/27 sahara 呼び出し元を変更
$newItems = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->findForNewItemsList($this->getUser(), $isManager);
// 2017/1/23 hagio TOP画面 新着一覧・案件一覧に分配率を表示するように変更
$newItemDealIds = array();
foreach ($newItems as $item) {
$newViewItemWithDeal = $item['view_item_with_deal'];
$newItemDeal = $newViewItemWithDeal->getItemDeal();
$newItemDealIds[] = $newItemDeal->getId();
}
$tmpNewItemSalesList = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:Sales')->getEmployeeSalesByDealIds($newItemDealIds);
$newSalesList = array();
foreach ($tmpNewItemSalesList as $sales) {
$newSalesList[$sales->getItemDealId()][$sales->getEmployeeId()] = $sales;
}
// * 取引中案件一覧
// $items = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->findForProcessItemsList($this->getUser(), $isManager);
$items = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->findForProcessItemsList($this->getUser(), $isManager);
$itemDealIds = array();
foreach ($items as $item) {
$viewItemWithDeal = $item['view_item_with_deal'];
$itemDeal = $viewItemWithDeal->getItemDeal();
$itemDealIds[] = $itemDeal->getId();
}
$tmpItemSalesList = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:Sales')->getEmployeeSalesByDealIds($itemDealIds);
$salesList = array();
foreach ($tmpItemSalesList as $sales) {
$salesList[$sales->getItemDealId()][$sales->getEmployeeId()] = $sales;
}
// key: branch_idの配列に整形 + 合計を取得
$itemList = array();
$branchItemsTotalSales = array();
foreach ($items as $item) {
$itemsBranchId = $item['view_item_with_deal']->getEmployeeBranchId();
// 配列の整形
$itemList[$itemsBranchId][] = $item;
// 売上合計(or予定売上合計)を集計(~万円
if (!isset($branchItemsTotalSales[$itemsBranchId])) {
$branchItemsTotalSales[$itemsBranchId] = 0;
}
$branchItemsTotalSales[$itemsBranchId] += \Kzl\ToolBundle\Calc\Round::jpFloorMan($item['view_item_with_deal']->getItemDeal()->getOrCalcTotalSales(), false, false);
}
// ------- 実績集計 --------------------------
// ** 実績集計
// 実績集計対象のID
$resultsTargetIds = array();
if ($isManager) {
$resultsTargetIds = $targetBranchIds;
} else {
$resultsTargetIds = array($this->getUser()->getEmployeeId());
}
// 集計結果取得 key: branch_id
// 2016/12/27 sahara 処理の呼び出し元変更
// $yearResults = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->getRankDataForTop(true, $isManager, $resultsTargetIds);
$yearResults = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->getRankDataForTop(true, $isManager, $resultsTargetIds);
// 2016/12/27 sahara 処理の呼び出し元変更
// $monthResults = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->getRankDataForTop(false, $isManager, $resultsTargetIds);
$monthResults = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->getRankDataForTop(false, $isManager, $resultsTargetIds);
// 集計結果格納
$results = array(
'year' => $yearResults,
'month' => $monthResults
);
// * グラフ表示用 key:branch_id, [year_manage , month_sales ...]
// $yearGraphData = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->getYearGraphDataForTop($resultsTargetIds, $isManager);
// $monthlyGraphData = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewItemWithDeal')->getMonthlyGraphDataForTop($resultsTargetIds, $isManager);
// 2016/12/27 sahara 処理の呼び出し元を変更
$yearGraphData = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->getYearGraphDataForTop($resultsTargetIds, $isManager);
$monthlyGraphData = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ViewDealSales')->getMonthlyGraphDataForTop($resultsTargetIds, $isManager);
$graphDataList = array(
'year' => $yearGraphData,
'month' => $monthlyGraphData
);
$kimatsu = \Times\EigyoBundle\Common\TimesStatic::getSystemManager()->getKimatsu();
$today = \Kzl\ToolBundle\Util\DateTime::getDateToDay();
$interVal = \Kzl\ToolBundle\Util\DateTime::getIntervalDays($today, $kimatsu, '%r%m');
// 小さいほうのグラフの系列最大idx
$graphMinEnd = array(
'year' => 5*2 + 1,
'month' => 12 + $interVal + 1
);
// ※ TODO項目名称の一覧を取得しておく
$itemNames = 'Kzl\BaseBundle\Common\KzlStatic'::getKzlRepository('TimesEigyoBundle:ItemName')->getTodoItemNameList();
return $this->render('@TimesEigyo/Top/index.html.twig', array(
'news' => $news,
'todo_news_list' => $todoCheckList,
'new_items' => $newItems,
'results' => $results,
'items' => $itemList,
'target_branch_ids' => $targetBranchIds,
'is_branch_admin' => $targetBranchIds !== false,
'todo_item_name_list' => $itemNames,
'branch_total_sales' => $branchItemsTotalSales,
'graph_data_list' => $graphDataList,
'graph_min_end' => $graphMinEnd,
'new_sales_list' => $newSalesList,
'sales_list' => $salesList,
));
}
/**
* 実績の集計
* @param type $targetKind
* @param type $targetId
* @return \Times\EigyoBundle\Entity\Virtual\SalesResults
*/
// private function summaryResults($targetKind, $targetId)
// {
// $results = array(
// 'month' => new SalesResults(),
// 'year' => new SalesResults(),
// );
// $results['month']->summary( SalesResults::KIND_MONTH, $targetKind, $targetId, true );
// $results['year']->summary( SalesResults::KIND_YEAR, $targetKind, $targetId, true );
//
// return $results;
// }
/**
* 仮:資料用画面イメージ そのうち移植して本番開発へ
* @param type $param
* @return type
*/
// public function dummyAction($param){
// if($param == 1){
// return $this->render('@TimesEigyo/Top/input_response_report.html.twig');
// }else{
// return $this->render('@TimesEigyo/Top/input_response_report.html.twig');
// }
// }
// ------ 15/4/16 mitsunaga ダミー画面表示用 ---------
/**
* ダミー画面表示アクション
* @param string $param
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showDummyViewsAction($param)
{
//$view = '';
$views = array(
'@todo' => 'TimesEigyo/Dummy/todo_index.html.twig',
'@hikitsugi' => 'TimesEigyo/Dummy/hikitsugi_index.html.twig',
'@item' => 'TimesEigyo/Dummy/item_index.html.twig',
'@nippou' => 'TimesEigyo/Dummy/nippou_index.html.twig',
'@hankyo' => 'TimesEigyo/Dummy/hankyo_index.html.twig',
'@hankyo_input' => 'TimesEigyo/Dummy/hankyo_input.html.twig',
);
return $this->render($views[$param]);
}
}