Example #1
0
 private function updateCustomerlog($data)
 {
     $ctoken = $data['customer_token'];
     if (!empty($ctoken)) {
         $customer_id = $this->getCustomerID($ctoken);
         if ($customer_id != null) {
             $customerlog = Customer::find($customer_id)->customerlog;
             if ($customerlog == null) {
                 $newCustomerlog = new Customerlog();
                 $newCustomerlog->customer_id = $customer_id;
                 $newCustomerlog->alltime_spent = $data['totalamount'];
                 $newCustomerlog->alltime_quantity = $data['totalquantity'];
                 $newCustomerlog->alltime_visits = 1;
                 $newCustomerlog->save();
             } else {
                 $customerlog->alltime_spent += $data['totalamount'];
                 $customerlog->alltime_quantity += $data['totalquantity'];
                 $customerlog->alltime_visits += 1;
                 $customerlog->save();
             }
             return $customer_id;
         }
     }
     return 'anon' . strtotime('now');
     /*$customer_id = $this->getCustomerID($data['customer_token']);
     		$customer_id = ($customer_id != null && $customer_id != 0) ? $customer_id : 'anon' . strtotime('now');
     
     
     
     		return $customer_id;*/
 }
Example #2
0
 public static function boot()
 {
     parent::boot();
     //validation on create
     static::creating(function ($customer) {
         return $customer->isValid();
     });
     //This event will delete all related model in category model
     static::deleted(function ($cs) {
         //Deletes all customerlog related to a customer
         $c = $cs->customerlog()->lists('id');
         if (!empty($c)) {
             Customerlog::destroy($c);
         }
         //Deletes all Receipt related to a customer
         $r = $cs->receipt()->lists('id');
         if (!empty($r)) {
             Receipt::destroy($r);
         }
         //Deletes all Salelog related to a customer
         $s = $cs->salelog()->lists('id');
         if (!empty($s)) {
             Salelog::destroy($s);
         }
     });
     //validation on update
     static::updating(function ($customer) {
         //return $customer->isValid();
     });
 }
 private function bestcustomerssummary($type = 'bestcustomerssummary')
 {
     if ($type == 'bestcustomerssummary') {
         $bestCustomers = Customerlog::with('Customer')->take(10)->orderBy('alltime_spent', 'desc');
         $data['bestcustomerssummary']['customers'] = $bestCustomers->get()->toArray();
         return $data;
     }
 }