Beispiel #1
0
 /**
  * [action_buy] Pay for ad, and set new order 
  *
  */
 public function action_buy()
 {
     if (Core::config('general.subscriptions') == FALSE) {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
     //getting the user that wants to buy now
     if (!Auth::instance()->logged_in()) {
         Alert::set(Alert::INFO, __('To buy this product you need to register first.'));
         $this->redirect(Route::url('oc-panel'));
     }
     //check plan exists
     $plan = new Model_Plan();
     $plan->where('seoname', '=', $this->request->param('id'))->where('status', '=', 1)->find();
     //loaded published and with stock if we control the stock.
     if ($plan->loaded() and $plan->status == 1) {
         //free plan can not be renewed
         if ($plan->price == 0 and $this->user->subscription()->id_plan == $plan->id_plan) {
             Alert::set(Alert::WARNING, __('Free plan can not be renewed, before expired'));
             HTTP::redirect(Route::url('pricing'));
         }
         $order = Model_Order::new_order(NULL, $this->user, $plan->id_plan, $plan->price, core::config('payment.paypal_currency'), __('Subscription to ') . $plan->name);
         //free plan no checkout
         if ($plan->price == 0) {
             $order->confirm_payment('cash');
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         } else {
             $this->redirect(Route::url('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Beispiel #2
0
 /**
  * @author dangbc <*****@*****.**>
  * filter plan
  */
 public function action_loaddata()
 {
     $year = Input::post('year');
     $plan = new \Model_Plan();
     $data_plan = $plan->data_plan($year);
     return json_encode($data_plan);
 }
Beispiel #3
0
 /**
  * returns the original price of the order
  * @return float 
  */
 public function original_price()
 {
     //get original price for the product
     switch ($this->id_product) {
         case self::PRODUCT_CATEGORY:
             $amount = $this->ad->category->price > 0 ? $this->ad->category->price : $this->ad->category->parent->price;
             break;
         case self::PRODUCT_TO_TOP:
             $amount = core::config('payment.pay_to_go_on_top');
             break;
         case self::PRODUCT_TO_FEATURED:
             $amount = Model_Order::get_featured_price($this->featured_days);
             break;
         case self::PRODUCT_AD_SELL:
             $amount = $this->ad->price;
             break;
         default:
             $plan = new Model_Plan($this->id_product);
             $amount = $plan->loaded() ? $plan->price : 0;
             break;
     }
     return $amount;
 }
Beispiel #4
0
 public function get_remaining_cost($apply_date, $list_ss, $ss_id, $order = array())
 {
     //get ss_info
     $ss_info = \Model_Mss::find_by_pk($ss_id);
     //get list ss by partner_code
     $list_ss_primary = array();
     if ($ss_info) {
         $model_mss = new \Model_Mss();
         $partner = \Model_Mpartner::find_by_pk($ss_info->partner_code);
         if ($partner) {
             $department_id = $partner->department_id;
         }
         $list_ss_partner_code = $model_mss->get_list_all_ss(array('partner_code' => $ss_info->partner_code));
         if ($list_ss_partner_code) {
             $list_ss_primary = array_column($list_ss_partner_code, 'ss_id');
         }
     }
     $department_id = isset($partner->department_id) ? $partner->department_id : '';
     //get price for order
     $cost_of_order = 0;
     if ($order) {
         $check = true;
         if ($order['status'] == 2) {
             $check = false;
         }
         if ($order['status'] == 2 && $order['action'] == 'copy') {
             $check = true;
         }
         if ($check == true) {
             $cost_of_order = \Model_Orders::cost_of_order($order, $list_ss_primary, true);
         }
     }
     //get list orders by list_ss_id
     $list_orders = \Model_Orders::get_list_order_in_listss($list_ss_primary, $apply_date);
     $total_price = 0;
     foreach ($list_orders as $key => $value) {
         $total_price = $total_price + \Model_Orders::cost_of_order($value, $list_ss_primary, true);
     }
     //get plan job_cost
     $job_cost = \Model_Plan::get_info_by_startdate($apply_date, $department_id);
     $remaining_cost = $job_cost - $total_price - $cost_of_order;
     return $remaining_cost;
 }
Beispiel #5
0
 public function action_create()
 {
     try {
         if (!is_numeric(core::request('id_ad')) or !is_numeric(core::request('id_product')) or !is_numeric(core::request('id_user'))) {
             $this->_error(__('Missing parameters'), 501);
         } else {
             $user = new Model_User(core::request('id_user'));
             $ad = new Model_Ad(core::request('id_ad'));
             if ($user->loaded() and $ad->loaded()) {
                 $id_product = core::request('id_product');
                 $amount = core::request('amount');
                 //in case not set by request
                 if (!is_numeric($amount)) {
                     //get original price for the product
                     switch ($id_product) {
                         case Model_Order::PRODUCT_CATEGORY:
                             $amount = $ad->category->price;
                             break;
                         case Model_Order::PRODUCT_TO_TOP:
                             $amount = core::config('payment.pay_to_go_on_top');
                             break;
                         case Model_Order::PRODUCT_TO_FEATURED:
                             $amount = Model_Order::get_featured_price(core::request('featured_days'));
                             break;
                         case Model_Order::PRODUCT_AD_SELL:
                             $amount = $ad->price;
                             break;
                         default:
                             $plan = new Model_Plan($id_product);
                             $amount = $plan->loaded() ? $plan->price : 0;
                             break;
                     }
                 }
                 $order = Model_Order::new_order($ad, $user, $id_product, $amount, core::request('currency'), Model_Order::product_desc(core::request('id_product')), core::request('featured_days'));
                 $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'));
                 $order->save();
                 $this->rest_output(array('order' => self::get_order_array($order)));
             } else {
                 $this->_error(__('User or Ad not loaded'), 501);
             }
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }