public function bills() { $bills = Bill::where('account_id', '=', $this->account_id)->get(); if (count($bills) != 0) { return $bills; } return null; }
public function sendEmailPaymentSuccess($params) { $user = CusDet::where('account_id', '=', $this->account_id)->get()->first(); //var_dump($params);die; if (!is_null($user)) { $bill = Bill::where('bill_no', '=', $this->bill_no)->get()->first(); if (!is_null($bill)) { $email = Config::get('custom_config.email'); if (is_null($email)) { $email = $user->email; } $data = array(); $data['email'] = $email; $data['transaction'] = $this; $data['user'] = $user; $data['bill'] = $bill; $data['payer_email'] = $params['email']; $data['payer_name'] = $params['firstname']; $data['payer_phone'] = $params['phone']; if (!empty($data['email']) && !empty($data['payer_email'])) { if ($email == $data['payer_email']) { if ($this->transaction_type == "cheque") { Mail::send('emails.payment_success_cheque', $data, function ($message) use($data) { $message->to($data['email'], $data['user']->first_name)->subject("Payment Successfull"); }); } else { Mail::send('emails.payment_success_cash', $data, function ($message) use($data) { $message->to($data['email'], $data['user']->first_name)->subject("Payment Successfull"); }); } } else { if ($this->transaction_type == "cheque") { Mail::send('emails.payment_success_cheque', $data, function ($message) use($data) { $message->to($data['email'], $data['user']->first_name)->subject("Payment Successfull"); }); Mail::send('emails.payment_success_to_payer_cheque', $data, function ($message) use($data) { $message->to($data['payer_email'], $data['payer_name'])->subject("Payment Successfull"); }); } else { Mail::send('emails.payment_success_cash', $data, function ($message) use($data) { $message->to($data['email'], $data['user']->first_name)->subject("Payment Successfull"); }); Mail::send('emails.payment_success_to_payer_cash', $data, function ($message) use($data) { $message->to($data['payer_email'], $data['payer_name'])->subject("Payment Successfull"); }); } } } } } }
public static function ipn_response($response) { $transactionid = $response['txn_id']; $status = $response['payment_status']; $bill = Bill::where('checkout_id', '=', $transactionid)->first(); if (!$bill == NULL) { $bill->status = urldecode($status); $bill->save(); } else { $bill = new Bill(); $totalamount = urldecode($response['mc_gross']); $registrationid = $response['custom']; $order = new Bill(); $order->registrationid = $registrationid; $order->method = "PayPal"; $order->currency = 'USD'; $order->description = 'PayPal Order Number: ' . $transactionid; $order->amount = $totalamount; $order->checkout_id = $transactionid; $order->status = ucwords($status); $order->save(); } return true; }
function index_get() { $filters = $this->get("filter")["filters"]; $page = $this->get('page') !== false ? $this->get('page') : 1; $limit = $this->get('limit') !== false ? $this->get('limit') : 50; $sort = $this->get("sort"); $data["results"] = array(); $data["count"] = 0; $obj = new Contact(null, $this->entity); //Sort if (!empty($sort) && isset($sort)) { foreach ($sort as $value) { $obj->order_by($value["field"], $value["dir"]); } } //Filter if (!empty($filters) && isset($filters)) { $deleted = 0; foreach ($filters as $value) { if (!empty($value["operator"]) && isset($value["operator"])) { if ($value["operator"] == "where_in") { $obj->where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_in") { $obj->or_where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "where_not_in") { $obj->where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_not_in") { $obj->or_where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "like") { $obj->like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_like") { $obj->or_like($value["field"], $value["value"]); } else { if ($value["operator"] == "not_like") { $obj->not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_not_like") { $obj->or_not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "startswith") { $obj->like($value["field"], $value["value"], "after"); } else { if ($value["operator"] == "endswith") { $obj->like($value["field"], $value["value"], "before"); } else { if ($value["operator"] == "contains") { $obj->like($value["field"], $value["value"], "both"); } else { if ($value["operator"] == "or_where") { $obj->or_where($value["field"], $value["value"]); } else { if ($value["operator"] == "search") { $obj->like("number", $value["value"], "after"); $obj->or_like("surname", $value["value"], "after"); $obj->or_like("name", $value["value"], "after"); $obj->or_like("company", $value["value"], "after"); } else { $obj->where($value["field"] . ' ' . $value["operator"], $value["value"]); } } } } } } } } } } } } } } else { if ($value["field"] == "deleted") { $deleted = $value["value"]; } else { $obj->where($value["field"], $value["value"]); } } } $obj->where("deleted", $deleted); } if (!empty($limit) && !empty($page)) { $obj->get_paged_iterated($page, $limit); $data["count"] = $obj->paged->total_rows; } if ($obj->result_count() > 0) { foreach ($obj as $value) { $bal = new Bill(null, $this->entity); $bal->select_sum("amount"); $bal->where("contact_id", $value->id); $bal->where("status", 0); if ($value->contact_type_id == 5) { $bal->where("type", "bill"); } else { $bal->where("type", "invoice"); } $bal->get(); //Fullname $fullname = $value->surname . ' ' . $value->name; if ($value->contact_type_id == 3 || $value->contact_type_id == 5) { $fullname = $value->company; } $data["results"][] = array("id" => $value->id, "currency_id" => $value->currency_id, "user_id" => $value->user_id, "contact_type_id" => $value->contact_type_id, "number" => $value->number, "surname" => $value->surname, "name" => $value->name, "gender" => $value->gender, "dob" => $value->dob, "pob" => $value->pob, "address" => $value->address, "family_member" => $value->family_member, "id_number" => $value->id_number, "phone" => $value->phone, "email" => $value->email, "job" => $value->job, "company" => $value->company, "image_url" => $value->image_url, "memo" => $value->memo, "credit_limit" => $value->credit_limit, "status" => $value->status, "registered_date" => $value->registered_date, "deleted" => $value->deleted, "fullname" => $fullname, "fullIdName" => $value->number . ' ' . $fullname, "contact_type" => $value->contact_type->get_raw()->result(), "balance" => floatval($bal->amount)); } } // //Response Data $this->response($data, 200); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (Carbon::now()->toDateString() == Carbon::now()->startOfMonth()->toDateString()) { $users = User::where('type', 'ecole')->get(); foreach ($users as $user) { $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first(); if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 1)->where('school_year_id', $sc->id)->orderBy('id', 'desc')->where('nbrMois', 1)->first(); if ($getChild) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonth()->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = $getChild->reductionPrix; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 1; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 1) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix + Transport::where('user_id', $getChild->user_id)->first()->somme; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 1)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if ($getChild) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonth()->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = $getChild->reductionPrix; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 1; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 1) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix + Transport::where('user_id', $getChild->user_id)->first()->somme; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } }
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 function payableBill() { $bills = Bill::where('account_id', '=', $this->account_id)->where('status', '!=', 'paid')->orderBy('bill_date', 'desc')->get(); if (count($bills) != 0) { return $bills->first(); } return ""; }
function amount_get() { $filters = $this->get("filter")["filters"]; $page = $this->get('page') !== false ? $this->get('page') : 1; $limit = $this->get('limit') !== false ? $this->get('limit') : 50; $sort = $this->get("sort"); $data["results"] = []; $data["count"] = 0; $obj = new Bill(null, $this->entity); //Sort if (!empty($sort) && isset($sort)) { foreach ($sort as $value) { $obj->order_by($value["field"], $value["dir"]); } } //Filter if (!empty($filters) && isset($filters)) { $deleted = 0; foreach ($filters as $value) { if (!empty($value["operator"]) && isset($value["operator"])) { if ($value["operator"] == "where_in") { $obj->where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_in") { $obj->or_where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "where_not_in") { $obj->where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_not_in") { $obj->or_where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "like") { $obj->like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_like") { $obj->or_like($value["field"], $value["value"]); } else { if ($value["operator"] == "not_like") { $obj->not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_not_like") { $obj->or_not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "startswith") { $obj->like($value["field"], $value["value"], "after"); } else { if ($value["operator"] == "endswith") { $obj->like($value["field"], $value["value"], "before"); } else { if ($value["operator"] == "contains") { $obj->like($value["field"], $value["value"], "both"); } else { if ($value["operator"] == "or_where") { $obj->or_where($value["field"], $value["value"]); } else { $obj->where($value["field"] . ' ' . $value["operator"], $value["value"]); } } } } } } } } } } } } } else { if ($value["field"] == "deleted") { $deleted = $value["value"]; } else { $obj->where($value["field"], $value["value"]); } } } $obj->where("deleted", $deleted); } //Results $obj->select_sum("amount"); $obj->get(); $data["results"][] = floatval($obj->amount); //Response Data $this->response($data, 200); }
/** * Execute the console command. * * @return mixed */ public function handle() { $users = User::where('type', 'ecole')->get(); foreach ($users as $user) { $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first(); if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 3)->orderBy('id', 'desc')->first(); if ($getChild) { // give us from the end of bill to 3 months ahead $fromStartToNbrMois = $getChild->end->addMonths($getChild->nbrMois); if ($fromStartToNbrMois <= $sc->endch2) { if (Carbon::now() >= $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths($getChild->nbrMois)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * $getChild->nbrMois; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * $getChild->nbrMois; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * $getChild->nbrMois; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } elseif ($fromStartToNbrMois > $sc->endch2) { $last_bill = Bill::where('child_id', $getChild->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if (!$last_bill && Carbon::now() > $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths(1)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = 1; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * 1; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * 1; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * 1; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 3)->orderBy('id', 'desc')->first(); if ($getChild) { // give is from the end of bill to 3 months ahead $fromStartToNbrMois = $getChild->end->addMonths($getChild->nbrMois); if ($fromStartToNbrMois <= $sc->endch3) { if (Carbon::now() >= $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths($getChild->nbrMois)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * $getChild->nbrMois; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * $getChild->nbrMois; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * $getChild->nbrMois; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } elseif ($fromStartToNbrMois >= $sc->endch3) { $last_bill = Bill::where('child_id', $getChild->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if (!$last_bill && Carbon::now() > $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths(1)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = 1; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * 1; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * 1; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * 1; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } } }
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(); } }