public function actionDiscount($id)
 {
     $customer = $this->loadModel($id);
     $services = new ServiceDetail('search');
     $services->unsetAttributes();
     // clear any default values
     if (isset($_GET['ServiceDetail'])) {
         $services->attributes = $_GET['ServiceDetail'];
     }
     if (isset($_POST['CustomerDiscount'])) {
         foreach ($_POST['CustomerDiscount'] as $key => $data) {
             if (isset($data['id'])) {
                 $model = CustomerDiscount::model()->findByPk($data['id']);
             } else {
                 $model = new CustomerDiscount();
             }
             $model->setAttributes($data);
             $model->save();
         }
     }
     $this->render('discount', array('services' => $services, 'customer' => $customer));
 }
 public function makeCustomerDiscount()
 {
     $i = Input::all();
     $exp_date = null;
     if ($i['expiration'] < 1) {
         $i['expiration'] = $i['expiration'] * 10;
         $exp_date = Carbon::now()->addMonths($i['expiration']);
     } else {
         $exp_date = Carbon::now()->addYears($i['expiration']);
     }
     $customer_discount = new CustomerDiscount();
     $customer_discount->discount_id = $i['type'];
     if (!isset($i['customer_id']) || $i['customer_id'] == '') {
         return Redirect::to('adminsite/discount')->with('error', 'Failed to set discount to a customer as you haven\'t specified a customer name');
     }
     $customer_discount->customer_id = $i['customer_id'];
     $customer_discount->expiration = $exp_date;
     try {
         if ($customer_discount->save()) {
             return Redirect::to('adminsite/discount')->with('success', 'You have successfuly set a customer discount.');
         }
     } catch (Illuminate\Database\QueryException $e) {
         return Redirect::to('adminsite/discount')->with('error', $e->errorInfo[2]);
     }
     //$customer_discount->discount_id
 }