public static function ProrataDiscount($account_id, $month_sub, $plan_data, $new_plan_cost, $rem_day, $num_of_days, $prorata_bal)
 {
     $plan_det = Plan::where('account_id', '=', $account_id)->get()->first();
     $old_plan_code = $plan_det->plan_code;
     $old_plan_amount = PlanCostDetail::where('plan_code', '=', $old_plan_code)->get()->first()->plan_cost;
     $old_plan_cost = round($old_plan_amount + $old_plan_amount * 0.14);
     $prorata_dis = $old_plan_cost - $prorata_bal;
     if ($month_sub == 'Monthly') {
         if ($plan_data != 0) {
             $prorata_cost = $new_plan_cost;
             $prorata_dis = $prorata_dis;
             $plan_amount = $new_plan_cost - $prorata_dis;
             return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost);
         } else {
             $plan_amount = round($rem_day * ($new_plan_cost / $num_of_days)) - $prorata_dis;
             //var_dump($plan_cost_tax); die;
             $prorata_cost = $plan_amount;
             $prorata_dis = $new_plan_cost - $prorata_cost;
             return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost);
         }
     } else {
         $plan_amount = $new_plan_cost;
         $prorata_cost = $new_plan_cost;
         $prorata_dis = 0;
         return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost);
     }
 }
Beispiel #2
0
 public function plan_type()
 {
     return PlanCostDetail::where('plan_code', '=', $this->plan_code)->get()->first();
 }
 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();
     }
 }