Example #1
0
 public static function DataUsage($account_id)
 {
     $usage = Jsubs::where('account_id', '=', $account_id)->get()->first();
     if (count($usage) != 0) {
         $plan = $usage->plan;
         $total_usage = PlanChangeDetail::data_usage_in_gb($usage->bytes_total);
         return array("plan" => $plan, "usage" => $usage, "total_usage" => $total_usage);
     } else {
         $plan = 0;
         $total_usage = 0;
         return array("plan" => $plan, "usage" => $usage, "total_usage" => $total_usage);
     }
 }
 public static function billChange($bill_no, $new_plan_code, $trans)
 {
     $bill = Bill::where('bill_no', $bill_no)->first();
     if (count($bill) != 0) {
         $plan_cost_det = PlanCostDetail::where('plan_code', '=', $new_plan_code)->get()->first();
         $account_id = $bill->account_id;
         if ($trans) {
             $cust_current_plan = $bill->cust_current_plan;
             $current_rental = $trans;
         } else {
             $cust_current_plan = $plan_cost_det->plan;
             $current_rental = $plan_cost_det->monthly_rental;
         }
         $bill_date = $bill->bill_date;
         $bill_start_date = $bill->bill_start_date;
         $bill_end_date = $bill->bill_end_date;
         $due_date = $bill->due_date;
         $for_month = $bill->for_month;
         $bill_last = Bill::where('account_id', '=', $account_id)->where('bill_no', '<', $bill_no)->orderBy('bill_no', 'desc')->first();
         if ($bill_last) {
             $prev_bal = $bill_last->amount_before_due_date;
             $last_payment = $bill_last->amount_paid;
         } else {
             $prev_bal = 0;
             $last_payment = 0;
         }
         $security_deposit = $bill->security_deposit;
         if (0 < $bill->adjustments) {
             $adjustments = PlanChangeDetail::billadjustment($account_id, $for_month, $bill->adjustments, $bill);
             if ($adjustments == false) {
                 $value = array('status' => 'false', 'name' => "adjustment");
                 return $value;
             }
         } else {
             $adjustments = $bill->adjustments;
         }
         if ($trans) {
             if (0 < $bill->device_cost) {
                 $device_cost = PlanChangeDetail::billdevicecost($account_id, $for_month, $bill->device_cost, $bill);
                 if ($device_cost == false) {
                     $value = array('status' => 'false', 'name' => "devicecost");
                     return $value;
                 }
             } else {
                 $device_cost = $bill->device_cost;
             }
             if (0 < $bill->discount) {
                 $discount = PlanChangeDetail::billdiscount($account_id, $for_month, $bill->discount, $bill);
                 if ($discount == false) {
                     $value = array('status' => 'false', 'name' => "discount");
                     return $value;
                 }
             } else {
                 $discount = $bill->discount;
             }
             if (0 < $bill->other_charges) {
                 $othercharges = PlanChangeDetail::billothercharges($account_id, $for_month, $bill->other_charges, $bill);
                 if ($othercharges == false) {
                     $value = array('status' => 'false', 'name' => "othercharges");
                     return $value;
                 }
             } else {
                 $othercharges = $bill->other_charges;
             }
         } else {
             $device_cost = $bill->device_cost;
             $discount = $bill->discount;
             $othercharges = $bill->other_charges;
             $adjustments = $bill->adjustments;
         }
         $onetime_charges = $bill->onetime_charges;
         if ($bill->onetime_charges) {
             $sub_total = $current_rental + $othercharges + $device_cost - $discount + $onetime_charges;
         } else {
             $sub_total = $current_rental + $othercharges + $device_cost - $discount;
         }
         $service_tax = ceil($sub_total * 0.14);
         $total_charges = $sub_total + $service_tax;
         $amount_before_due_date = intval($prev_bal - $last_payment + ($total_charges - $adjustments));
         $amount_after_due_date = intval($prev_bal - $last_payment + ($total_charges - $adjustments));
         $amount_paid = PaymentTransaction::where('bill_no', $bill->bill_no)->where('status', 'success')->sum('amount');
         if ($amount_before_due_date <= $amount_paid) {
             $status = "paid";
         } else {
             if ($amount_paid == 0) {
                 $status = "not_paid";
             } else {
                 if ($amount_before_due_date > $amount_paid) {
                     $status = "partially_paid";
                 }
             }
         }
         DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->update(array('account_id' => $account_id, 'cust_current_plan' => $cust_current_plan, 'bill_date' => $bill_date, 'bill_start_date' => $bill_start_date, 'bill_end_date' => $bill_end_date, 'due_date' => $due_date, 'security_deposit' => $security_deposit, 'prev_bal' => $prev_bal, 'last_payment' => $last_payment, 'current_rental' => $current_rental, 'onetime_charges' => $onetime_charges, 'sub_total' => $sub_total, 'service_tax' => $service_tax, 'total_charges' => $total_charges, 'for_month' => $for_month, 'device_cost' => $device_cost, 'adjustments' => $adjustments, 'discount' => $discount, 'other_charges' => $othercharges, 'amount_before_due_date' => $amount_before_due_date, 'amount_after_due_date' => $amount_after_due_date, 'amount_paid' => $amount_paid, 'status' => $status));
         return DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->first();
     }
 }