Пример #1
0
 /**
  * For handle order step by step
  *
  * @return Redirect
  */
 public function progress()
 {
     $order_session = Session::all();
     $data_ret = [];
     switch (Input::get('step')) {
         case 'index':
             Session::put('order.index', Input::only(['type', 'quantity_box', 'quantity_custom', 'quantity_item', 'description']));
             break;
         case 'schedule':
             $delivery_date = Input::get('delivery_year') . '-' . Input::get('delivery_month') . '-' . Input::get('delivery_day');
             if (!$this->_validateDateShouldLater($delivery_date)) {
                 return Redirect::back()->withMessages(['Delivery date should greater than today'])->withInput();
             }
             // if pickup immediaetly we pass this validation
             if (Input::get('type') != 'immediately') {
                 $pickup_date = Input::get('pickup_year') . '-' . Input::get('pickup_month') . '-' . Input::get('pickup_day');
                 if (!$this->_validateDateShouldLater($pickup_date)) {
                     return Redirect::back()->withMessages(['Pickup date should greater than today'])->withInput();
                 }
             }
             Session::put('order.schedule', Input::only(['delivery_day', 'delivery_month', 'delivery_year', 'delivery_time', 'type', 'pickup_day', 'pickup_month', 'pickup_year', 'pickup_time']));
             break;
         case 'payment':
             if (!Auth::check()) {
                 $userRepo = app('UserRepo');
                 if (Input::get('user_action') == 'signin') {
                     // if fails login redirect back with errors and input
                     if (!$userRepo->login(Input::get('credentials'))) {
                         return Redirect::back()->withMessages($userRepo->getErrors())->withInput();
                     }
                 } elseif (Input::get('user_action') == 'signup') {
                     // if fails register redirect back with errors and input
                     if (!$userRepo->register(Input::only(['firstname', 'lastname', 'email', 'phone', 'address', 'password']))) {
                         return Redirect::back()->withMessages($userRepo->getErrors())->withInput();
                     }
                 }
             }
             Session::put('order.payment', Input::only(['method', 'message']));
             break;
         case 'review':
             # save space credit used
             $space_credit = app('UserRepo')->getCustomerSpaceCredit();
             $order_index = Session::get('order.index');
             $total = calcPrice('box', $order_index['quantity_box']) + calcPrice('item', $order_index['quantity_item']);
             if ($total > $space_credit) {
                 $data_ret['total'] = "Total : Rp. " . number_format($total - $space_credit, 0, ',', '.') . ',-';
                 $data_ret['space_credit_sisa'] = "Rp. " . number_format(0, 0, ',', '.') . ',-';
                 $data_ret['space_credit_used'] = "Rp. " . number_format($space_credit, 0, ',', '.') . ',-';
                 Session::put('order.space_credit_used', $space_credit);
             } else {
                 $data_ret['total'] = "Total : Rp. " . number_format(0, 0, ',', '.') . ',-';
                 $data_ret['space_credit_sisa'] = "Rp. " . number_format($space_credit - $total, 0, ',', '.') . ',-';
                 $data_ret['space_credit_used'] = "Rp. " . number_format($total, 0, ',', '.') . ',-';
                 Session::put('order.space_credit_used', $total);
             }
             break;
     }
     if (Request::ajax()) {
         return $data_ret;
     } else {
         $redirectTo = Input::get('redirect_to');
         return Redirect::to($redirectTo);
     }
 }
Пример #2
0
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<?php 
function calcPrice($days, $percent, $discount)
{
    echo "Стоимость составляет:" . 400 * (100 + $percent) / 100 * $days * (100 - $discount) / 100 . "грн.";
}
@calcPrice($_REQUEST['days'], $_REQUEST['percentCountry'], $_REQUEST['discount']);
?>


</body>
</html>