public function actionIndex()
 {
     $y = date('Y');
     $m = date('m');
     if (!empty($_POST)) {
         $y = $_POST['year'];
         $m = $_POST['month'];
     }
     $params = [':y' => $y, ':m' => $m];
     $conditions = "\n      YEAR(pay_date) = :y \n      AND MONTH(pay_date) = :m \n      AND status = 'pay'\n    ";
     $billOrder = new BillOrder();
     $year_list = [];
     $month_list = [];
     // year list
     $start_year = date('Y');
     for ($i = $start_year - 1; $i <= $start_year; $i++) {
         $year_list[$i] = $i;
     }
     // month list
     for ($i = 1; $i <= 12; $i++) {
         $month_list[$i] = $i;
     }
     $orderDetails = BillOrderDetail::find()->leftJoin('bill_orders', 'bill_orders.id = bill_order_details.bill_order_id')->where($conditions, $params)->orderBy('bill_order_details.id DESC')->all();
     return $this->render('//Report/Index', ['n' => 1, 'y' => $y * 1, 'm' => $m * 1, 'billOrderDetails' => $orderDetails, 'billOrder' => $billOrder, 'year_list' => $year_list, 'month_list' => $month_list]);
 }
 public function actionDetail($id)
 {
     $billOrder = BillOrder::findOne($id);
     $billOrderDetails = BillOrderDetail::find()->where(['bill_order_id' => $id])->orderBy('id DESC')->all();
     return $this->render('//Order/Detail', ['billOrder' => $billOrder, 'billOrderDetails' => $billOrderDetails, 'n' => 1]);
 }
 public function actionCheckout()
 {
     $session = new Session();
     $session->open();
     $cart = $session->get('cart');
     $billOrder = new BillOrder();
     if (!empty($_POST)) {
         // save bill order
         $billOrder->member_id = $session->get('member_id');
         $billOrder->ip = $_SERVER['REMOTE_ADDR'];
         $billOrder->created_at = new Expression('NOW()');
         $billOrder->status = 'wait';
         $billOrder->name = $_POST['BillOrder']['name'];
         $billOrder->address = $_POST['BillOrder']['address'];
         $billOrder->tel = $_POST['BillOrder']['tel'];
         if ($billOrder->save()) {
             // loop read data from session to database
             foreach ($cart as $c) {
                 $billOrderDetail = new BillOrderDetail();
                 $billOrderDetail->bill_order_id = $billOrder->id;
                 $billOrderDetail->product_id = $c['id'];
                 $billOrderDetail->price = $c['price'];
                 $billOrderDetail->qty = $c['qty'];
                 $billOrderDetail->save();
             }
             // clear session
             $session->set('cart', null);
             return $this->redirect(['checkoutsuccess']);
         }
     }
     return $this->render('//Frontend/Checkout', ['n' => 1, 'cart' => $cart, 'sumQty' => 0, 'sumPrice' => 0, 'billOrder' => $billOrder]);
 }
Example #4
0
    ?>
    </h4>
    <table style="margin-bottom: 50px" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th width="40px" style="text-align: right">no</th>
          <th width="100px">code</th>
          <th>name</th>
          <th width="80px" style="text-align: right">price</th>
          <th width="80px" style="text-align: right">qty</th>
          <th width="100px" style="text-align: right">total</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $billOrderDetails = BillOrderDetail::find()->where(['bill_order_id' => $billOrder->id])->orderBy('id DESC')->all();
    $n = 1;
    ?>

        <?php 
    foreach ($billOrderDetails as $billOrderDetail) {
        ?>
        <?php 
        $total = $billOrderDetail->price * $billOrderDetail->qty;
        $sumQty += $billOrderDetail->qty;
        $sumPrice += $total;
        ?>
        <tr>
          <td style="text-align: right"><?php 
        echo $n++;
        ?>