/**
  * Checks if the parameter is a valid adjustment id
  * @param $id int
  * @return Adjustment object if $id is found, otherwise false
  */
 private function __checkExistence($id)
 {
     if (!is_null($id) && $id != '') {
         $adjustment = Adjustment::find($id);
         if (is_null($adjustment)) {
             return false;
         }
         return $adjustment;
     }
     return false;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $validator = $this->validate();
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
     }
     $type = Input::get('type');
     $product = Product::find(Input::get('product_id'));
     $location = Location::find(Input::get('location_id'));
     $quantity = Input::get('quantity');
     $adjustment_date = Input::get('adjustment_date');
     $description = Input::get('description');
     DB::beginTransaction();
     $adjustment = new Adjustment();
     // Record details in adjustment table
     // Type [1 : Positive] [2 : Negative]
     $adjustment->type = $type;
     $adjustment->adjustment_date = $adjustment_date;
     $adjustment->description = $description;
     $adjustment->save();
     // Store other details in a new array
     $extra = array('product-id ' => $product->id, 'quantity' => $quantity, 'location_id' => $location->id);
     // Get the current adjustment id;
     //Update records in the adjustment_products table
     //If type : POSITIVE
     // 1.Find the correct record and Increment the product qty in location_products table
     // 2.Update item_in table
     //If type : NEGATIVE
     // 1.Find the correct record and Decrement the product qty in location_products table
     // 2.Update item_out table
     $response = Event::fire('adjustment.create', array($adjustment, $extra));
     DB::commit();
     print_r($response);
     exit;
     Session::flash('success', 'Successfully created donation!');
     return Redirect::route('adjustment.index');
 }
Esempio n. 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));
     }
 }
 /**
  * Sets the best adjustment, if the passed adjustment
  * is indeed better.
  * @param Adjustment $candidate for better adjustment
  */
 protected function setBestAdjustment(Adjustment $candidate)
 {
     $this->bestadjustment = $this->bestadjustment ? Adjustment::better_of($this->bestadjustment, $candidate) : $candidate;
 }
Esempio n. 5
0
 function billInfo($bill_no, $account_id, $for_month)
 {
     $discount = Discount::where('account_id', '=', $account_id)->where('for_month', '=', $for_month)->get();
     foreach ($discount as $key => $value) {
         $discount_id[] = $value->id;
     }
     $adjustment = Adjustment::where('account_id', '=', $account_id)->where('for_month', '=', $for_month)->get();
     foreach ($adjustment as $key => $value) {
         $adjustment_id[] = $value->id;
     }
     $othercharges = OtherCharges::where('account_id', '=', $account_id)->where('for_month', '=', $for_month)->get();
     foreach ($othercharges as $key => $value) {
         $othercharges_id[] = $value->id;
     }
     $devicecost = DeviceCost::where('account_id', '=', $account_id)->where('for_month', '=', $for_month)->get();
     foreach ($devicecost as $key => $value) {
         $devicecost_id[] = $value->id;
         //var_dump($devicecost[]);die;
     }
     $discount = count($discount);
     $adjustment = count($adjustment);
     $othercharges = count($othercharges);
     $devicecost = count($devicecost);
     $maximum = max($discount, $adjustment, $othercharges, $devicecost);
     for ($i = 0; $i < $maximum; $i++) {
         $bill_info = new Billinformation();
         $bill_info->bill_no = $bill_no;
         if (!empty($adjustment_id[$i])) {
             $bill_info->adjustment_id = $adjustment_id[$i];
             $considered = Adjustment::where('id', '=', $adjustment_id[$i])->get()->first();
             $considered->is_considered = '1';
             $considered->save();
             //var_dump($considered);die;
         } else {
             $bill_info->adjustment_id = 0;
         }
         if (!empty($discount_id[$i])) {
             $bill_info->discount_id = $discount_id[$i];
             $considered = Discount::where('id', '=', $discount_id[$i])->get()->first();
             $considered->is_considered = 1;
             $considered->save();
         } else {
             $bill_info->discount_id = 0;
         }
         if (!empty($othercharges_id[$i])) {
             $bill_info->other_charges_id = $othercharges_id[$i];
             $considered = OtherCharges::where('id', '=', $othercharges_id[$i])->get()->first();
             $considered->is_considered = 1;
             $considered->save();
         } else {
             $bill_info->other_charges_id = 0;
         }
         if (!empty($devicecost_id[$i])) {
             $bill_info->device_cost_id = $devicecost_id[$i];
             $considered = DeviceCost::where('id', '=', $devicecost_id[$i])->get()->first();
             $considered->is_considered = 1;
             $considered->save();
         } else {
             $bill_info->device_cost_id = 0;
         }
         $bill_info->save();
     }
 }
 public static function billadjustment($account_id, $for_month, $amount, $bill)
 {
     $bill_info = Billinformation::where('bill_no', $bill->bill_no)->get();
     foreach ($bill_info as $key) {
         $amount_id[] = $key->adjustment_id;
     }
     if (count($bill_info) == 0) {
         $amount_id[] = NULL;
     }
     $bill_amount = Adjustment::whereIn('id', $amount_id)->sum('amount');
     if ($bill->adjustments == $bill_amount) {
         return $bill_amount;
     } else {
         if ($bill->adjustments && $bill_amount == 0) {
             $adjustment = new Adjustment();
             $adjustment->account_id = $account_id;
             $adjustment->for_month = $for_month;
             $adjustment->amount = $amount;
             $adjustment->date = date('Y-m-d');
             $adjustment->remarks = "billadjustment retransaction";
             $adjustment->is_considered = 1;
             $adjustment->save();
             $bill_info = Adjustment::adjustments($adjustment->id, $adjustment->account_id, $adjustment->for_month);
             return $adjustment->amount;
         } else {
             if ($bill->adjustments != $bill_amount) {
                 return false;
             }
         }
     }
 }
 public function compareTo(Adjustment $i)
 {
     return $this->getValue() - $i->getValue();
 }