Пример #1
0
 /**
  * Update the specified resource in storage.
  * PUT /Housedues/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = array_except(Input::all(), '_method');
     $v = Validator::make(Input::All(), array('rent' => 'required', 'water' => 'required', 'electricity' => 'required', 'security' => 'required', 'service' => 'required', 'garbage' => 'required', 'duedate' => 'required'));
     if ($v->passes()) {
         $balanceN = Input::get('rent') + Input::get('water') + Input::get('service') + Input::get('garbage') + Input::get('electricity') + Input::get('security');
         $invoice = Invoice::find($id);
         $amountP = $invoice->amountpaid;
         $balance = $balanceN - $amountP;
         $invoice->balance = $balance;
         $invoice->duedate = Input::get('duedate');
         //dd($invoice);
         $invoice->update();
         $invoicedetails = Invoicedetail::where('invoiceID', $id)->first();
         //dd($invoicedetails->toArray());
         $invoicedetails->rent = Input::get('rent');
         $invoicedetails->water = Input::get('water');
         $invoicedetails->garbage = Input::get('garbage');
         $invoicedetails->service = Input::get('service');
         $invoicedetails->electricity = Input::get('electricity');
         $invoicedetails->security = Input::get('security');
         $invoicedetails->update();
         return Redirect::route('admin.invoice.show', $id);
     }
     return Redirect::route('admin.invoice.edit', $id)->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }
 /**
  * Update the specified resource in storage.
  * PUT /Housedues/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = array_except(Input::all(), '_method');
     if (Input::get('invoicetype') === "to tenant") {
         $rules = array('rent' => 'required', 'water' => 'required', 'electricity' => 'required', 'security' => 'required', 'service' => 'required', 'garbage' => 'required');
         $v = Validator::make(Input::All(), $rules);
         if ($v->passes()) {
             $balanceN = Input::get('rent') + Input::get('water') + Input::get('service') + Input::get('garbage') + Input::get('electricity') + Input::get('security');
             $invoice = Invoice::find($id);
             $amountP = $invoice->amountpaid;
             $balance = $balanceN - $amountP;
             $invoice->balance = $balance;
             $invoice->duedate = Input::get('duedate');
             //dd($invoice);
             $invoice->update();
             $invoicedetails = Invoicedetail::where('invoiceID', $id)->first();
             //dd($invoicedetails->toArray());
             $invoicedetails->rent = Input::get('rent');
             $invoicedetails->water = Input::get('water');
             $invoicedetails->garbage = Input::get('garbage');
             $invoicedetails->service = Input::get('service');
             $invoicedetails->electricity = Input::get('electricity');
             $invoicedetails->security = Input::get('security');
             $invoicedetails->update();
             return Redirect::route('admin.invoice.show', $id);
         }
     } elseif (Input::get('invoicetype') === "deposits") {
         $rules = array('rentD' => 'required', 'rent' => 'required', 'waterD' => 'required', 'electricityD' => 'required', 'garbage' => 'required', 'transport_cost' => 'required');
         $v = Validator::make(Input::All(), $rules);
         if ($v->passes()) {
             $balanceN = Input::get('rentD') + Input::get('rent') + Input::get('waterD') + Input::get('electricityD') + Input::get('garbage') + Input::get('transport_cost');
             $invoice = Invoice::find($id);
             $amountP = $invoice->amountpaid;
             $balance = $balanceN - $amountP;
             $invoice->balance = $balance;
             $invoice->duedate = Input::get('duedate');
             //dd($invoice);
             $invoice->update();
             $invoicedetails = Invoicedetail::where('invoiceID', $id)->first();
             //dd($invoicedetails->toArray());
             $invoicedetails->rent = Input::get('rent');
             $invoicedetails->rentD = Input::get('rentD');
             $invoicedetails->waterD = Input::get('waterD');
             $invoicedetails->electricityD = Input::get('electricityD');
             $invoicedetails->garbage = Input::get('garbage');
             $invoicedetails->transport_cost = Input::get('transport_cost');
             $invoicedetails->update();
             return Redirect::route('admin.invoice.show', $id);
         }
     } elseif (Input::get('invoicetype') === "refund") {
         $rules = array('rentD' => 'required', 'waterD' => 'required', 'electricityD' => 'required', 'g_repairs' => 'required', 'o_bills' => 'required', 'transport_cost' => 'required', 'storage_fees' => 'required');
         $v = Validator::make(Input::All(), $rules);
         if ($v->passes()) {
             $balanceN = Input::get('rentD') + Input::get('storage_fees') + Input::get('g_repairs') + Input::get('waterD') + Input::get('electricityD') + Input::get('o_bills') + Input::get('transport_cost');
             $invoice = Invoice::find($id);
             $amountP = $invoice->amountpaid;
             $balance = $balanceN - $amountP;
             $invoice->balance = $balance;
             $invoice->duedate = Input::get('duedate');
             //dd($invoice);
             $invoice->update();
             $invoicedetails = Invoicedetail::where('invoiceID', $id)->first();
             //dd($invoicedetails->toArray());
             $invoicedetails->storage_fees = Input::get('storage_fees');
             $invoicedetails->rentD = Input::get('rentD');
             $invoicedetails->waterD = Input::get('waterD');
             $invoicedetails->electricityD = Input::get('electricityD');
             $invoicedetails->g_repairs = Input::get('g_repairs');
             $invoicedetails->o_bills = Input::get('o_bills');
             $invoicedetails->transport_cost = Input::get('transport_cost');
             $invoicedetails->update();
             return Redirect::route('admin.invoice.show', $id);
         }
     }
     return Redirect::route('admin.invoice.edit', $id)->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }