private static function updatePlanHistory($oldPlan)
 {
     $data = ['user_id' => $oldPlan->user_id, 'from_date' => $oldPlan->assigned_on, 'to_date' => date('Y-m-d H:i:s'), 'plan_name' => $oldPlan->plan_name, 'price' => $oldPlan->price];
     $settings = APSetting::first();
     if ($settings->plan_taxable) {
         $data['tax_rate'] = $settings->plan_tax_rate;
     }
     if ($oldPlan->plan_type == LIMITED) {
         $data = array_merge($data, $oldPlan->limit->toArray());
     }
     if (!APChangeHistory::create($data)) {
         throw new Exception("Could not save service plan history." . __FILE__ . __LINE__);
     }
 }
 private function _seedAPSettings()
 {
     APSetting::truncate();
     APSetting::insert(['payment_due_in_days' => 15, 'disconnection_status' => 0, 'disconnection_days' => 15, 'due_amount_penalty_status' => 15, 'due_amount_penalty_minimum' => 100, 'due_amount_penalty_percent' => 2, 'plan_taxable' => 1, 'plan_tax_rate' => 14.28]);
 }
 public function latePaymentCharges()
 {
     $settings = APSetting::first();
     // dd($this->thisMonthsCharges());
     if ($settings->due_amount_penalty_status && $this->thisMonthsCharges() > 0.0) {
         $totalAmount = $this->plansAmount() + $this->recurringProductsAmount() + $this->nonRecurringProductsAmount();
         $calculatedPenalty = $totalAmount * $settings->due_amount_penalty_percent / 100;
         $finalPenalty = $calculatedPenalty > $settings->due_amount_penalty_minimum ? $calculatedPenalty : $settings->due_amount_penalty_minimum;
         return number_format((double) $finalPenalty, 2, '.', '');
     }
     return number_format((double) 0, 2, '.', '');
 }
 public function postAdvancepaid()
 {
     $ap = APSetting::first();
     $ap->fill(Input::all());
     if ($ap->save()) {
         $this->notifySuccess('Settings Saved.');
     } else {
         $this->notifyError('Failed to save Settings.');
     }
     return Redirect::back();
 }