示例#1
0
 function transactions()
 {
     $payment = PaymentTransaction::where('account_id', '=', $this->application_no)->get();
     if (!empty($payment)) {
         return $payment;
     }
     return null;
 }
示例#2
0
 public function transactions()
 {
     $payments = PaymentTransaction::where('account_id', '=', $this->account_id)->get();
     if (count($payments) != 0) {
         return $payments;
     }
     return null;
 }
示例#3
0
 public static function billUpdate($id, $account_id, $for_month, $adjustments_new, $device_cost_new, $discount_new, $other_charges_new, $for_month_last, $update)
 {
     if (count($for_month_last) != 0) {
         $bill = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month_last)->get()->first();
     } else {
         $bill = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month)->get()->first();
     }
     // var_dump($bill,$for_month,$account_id);die;
     if (count($bill) != 0) {
         $bill_now = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month)->first();
         if ($for_month_last) {
             $previous_balance = ceil($bill->amount_before_due_date);
             $last_payment = ceil($bill->amount_paid);
         } else {
             $previous_balance = ceil($bill->prev_bal);
             $last_payment = ceil($bill->last_payment);
         }
         $amount_paid = PaymentTransaction::where('bill_no', $bill_now->bill_no)->where('account_id', $account_id)->where('status', 'success')->sum('amount');
         $account_id = $bill->account_id;
         $bill_date = $bill->bill_date;
         $bill_start_date = $bill->bill_start_date;
         $bill_end_date = $bill->bill_end_date;
         $due_date = $bill->due_date;
         $security_deposit = $bill->security_deposit;
         $status = $bill->status;
         if (count($update) != 0) {
             $adjust = Adjustment::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount');
             $device = DeviceCost::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount');
             $other_c = OtherCharges::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount');
             $discount = Discount::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount');
             $device_cost = $device + $device_cost_new;
             $other_charges = $other_c + $other_charges_new;
             $discount = $discount + $discount_new;
             $adjustments = $adjust + $adjustments_new;
         } else {
             $device_cost = $bill->device_cost + $device_cost_new;
             $other_charges = $bill->other_charges + $other_charges_new;
             $discount = $bill->discount + $discount_new;
             $adjustments = $bill->adjustments + $adjustments_new;
         }
         if (count($adjustments_new) != 0) {
             $adjustment_update = Adjustment::where('id', $id)->first();
             $adjustment_update->is_considered = 'Y';
             $adjustment_update->save();
         }
         if (count($device_cost_new) != 0) {
             $device_cost_update = DeviceCost::where('id', $id)->first();
             $device_cost_update->is_considered = 1;
             $device_cost_update->save();
         }
         if (count($other_charges_new) != 0) {
             $other_charges_update = OtherCharges::where('id', $id)->first();
             $other_charges_update->is_considered = 1;
             $other_charges_update->save();
         }
         if (count($discount_new) != 0) {
             $discount_update = Discount::where('id', $id)->first();
             $discount_update->is_considered = 1;
             $discount_update->save();
         }
         $bill_count = Bill::where('account_id', $account_id)->get();
         if ($for_month_last) {
             if (count($bill_count) == 1) {
                 $current_rental = $bill->current_rental;
                 $onetime_charges = $bill->onetime_charges;
                 $sub_total = $current_rental;
                 $service_tax = ceil($sub_total * 0.14);
                 $plan_name = $bill->cust_current_plan;
                 $total_charges = ceil($sub_total + $service_tax);
                 $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost + $onetime_charges);
             } else {
                 $current_rental = $bill_now->current_rental;
                 $sub_total = $current_rental;
                 $onetime_charges = $bill_now->onetime_charges;
                 $service_tax = ceil($sub_total * 0.14);
                 $plan_name = $bill_now->cust_current_plan;
                 $total_charges = ceil($sub_total + $service_tax);
                 $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost);
             }
         } else {
             $current_rental = $bill_now->current_rental;
             $onetime_charges = $bill_now->onetime_charges;
             $sub_total = $current_rental;
             $service_tax = ceil($sub_total * 0.14);
             $total_charges = ceil($sub_total + $service_tax);
             $plan_name = $bill_now->cust_current_plan;
             if (count($bill_count) == 1) {
                 $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost + $onetime_charges);
             } else {
                 $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost);
             }
         }
         $amount_before_due_date = intval($previous_balance - $last_payment + $total_amount);
         $amount_after_due_date = intval($previous_balance - $last_payment + $total_amount);
         if ($amount_paid == 0) {
             $status = "not_paid";
         } else {
             if ($amount_before_due_date > $amount_paid) {
                 $status = "partially_paid";
             } else {
                 if ($amount_before_due_date <= $amount_paid) {
                     $status = "paid";
                 }
             }
         }
         DB::table('bill_det')->where('bill_no', '=', $bill_now->bill_no)->update(array('prev_bal' => $previous_balance, 'last_payment' => $last_payment, 'current_rental' => $current_rental, 'service_tax' => $service_tax, 'total_charges' => $total_charges, 'sub_total' => $sub_total, 'device_cost' => $device_cost, 'adjustments' => $adjustments, 'discount' => $discount, 'other_charges' => $other_charges, 'amount_before_due_date' => $amount_before_due_date, 'amount_after_due_date' => $amount_after_due_date, 'amount_paid' => $amount_paid, 'status' => $status));
     }
 }
 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();
     }
 }