コード例 #1
0
 function execute($params)
 {
     // パラメータを調整
     $post = Vizualizer::request();
     $month = $post["ym"];
     if (empty($month) || preg_match("/[0-9]{4}-[0-9]{2}/", $month) == 0) {
         $month = date("Y-m");
     }
     // クエリを生成
     $loader = new Vizualizer_Plugin("stock");
     $orders = $loader->loadTable("Orders");
     $orderDetails = $loader->loadTable("OrderDetails");
     $select = new Vizualizer_Query_Select($orderDetails);
     $select->addColumn($orderDetails->set_id)->addColumn($orderDetails->choice_id);
     $select->addColumn($orderDetails->set_menu_name)->addColumn($orderDetails->menu_name);
     $select->addColumn("SUM(" . $orderDetails->price . " * " . $orderDetails->quantity . ")", "price");
     $select->join($orders, array($orders->order_id . " = " . $orderDetails->order_id));
     $select->where("order_date LIKE ?", array($month . "-%"));
     $select->group($orderDetails->set_id)->group($orderDetails->choice_id);
     $select->having("SUM(" . $orderDetails->price . " * " . $orderDetails->quantity . ") > 0");
     $select->order($orderDetails->set_id)->order($orderDetails->choice_id);
     // 生成したクエリに対して検索を実行し、結果をモデルとして取得
     $order = $loader->loadModel("OrderDetail");
     $orders = $order->queryAllBy($select);
     // 結果を属性に設定
     $attr = Vizualizer::attr();
     $attr["sales"] = $orders;
     $attr["thismonth"] = date("Y-m-01", strtotime($month . "-01"));
     $attr["nextmonth"] = date("Y-m", strtotime("+1 month", strtotime($month . "-01")));
     $attr["lastmonth"] = date("Y-m", strtotime("-1 month", strtotime($month . "-01")));
 }
コード例 #2
0
ファイル: Database.php プロジェクト: naonaox1126/vizualizer
 /**
  * コンストラクタ
  */
 public function __construct($table = "session_stores", $id_key = "session_id", $data_key = "session_data")
 {
     list($module, $name) = explode("_", $table, 2);
     $names = explode("_", $name);
     $name = "";
     $module = strtoupper(substr($module, 0, 1)) . strtolower(substr($module, 1));
     foreach ($names as $part) {
         $name .= strtoupper(substr($part, 0, 1)) . strtolower(substr($part, 1));
     }
     $name .= "Table";
     $loader = new Vizualizer_Plugin($module);
     $this->table = $loader->loadTable($name);
     $this->id_key = $id_key;
     $this->data_key = $data_key;
     // 初期化時にクラスのローディングを行う。
     $select = new Vizualizer_Query_Select($this->table);
     $insert = new Vizualizer_Query_Replace($this->table);
 }
コード例 #3
0
ファイル: Menu.php プロジェクト: Vizualizer/VizualizerStock
 /**
  * コンストラクタ
  *
  * @param $values モデルに初期設定する値
  */
 public function __construct($values = array())
 {
     $loader = new Vizualizer_Plugin("stock");
     parent::__construct($loader->loadTable("Menus"), $values);
 }