/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $houses = House::where('status', '=', 'booked')->where('frequency', '=', 4)->get();
     foreach ($houses as $house) {
         $hid = $house->id;
         $rent = $house->rent;
         $water = $house->water;
         $garbage = $house->garbage;
         $frequency = $house->frequency;
         $tenant_id = $house->tenant;
         $tenant = Tenant::find($tenant_id);
         $t_name = $tenant->name;
         $t_agent = $tenant->agent_id;
         $balance = $rent + $water + $garbage;
         $invoice = new Invoice();
         $invoice->type = 'to tenant';
         $invoice->houseID = $hid;
         $invoice->recipient = $t_name;
         $invoice->agent_id = $t_agent;
         $invoice->balance = $balance;
         $invoice->duedate = '2015/03/21';
         $invoice->save();
         $invoicedetail = new Invoicedetail();
         $invoicedetail->rent = $rent;
         $invoicedetail->water = $water;
         $invoicedetail->garbage = $garbage;
         $invoice->invoicedetail()->save($invoicedetail);
     }
 }
Example #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $tenants = Tenant::findOrFail($id);
     $tname = $tenants->name;
     $houses = House::where('tenant', '=', $tname)->get();
     return View::make('backend.code.tenants.show', compact('tenants', 'houses'));
 }
Example #3
0
 public function refundSelected($id)
 {
     $tenant = Tenant::find($id);
     $tname = $tenant->name . ' ' . $tenant->lname;
     $houses = House::where('tenant', $tname)->get();
     return View::make('backend.code.payment.againsttenant', compact('tenant', 'houses'));
 }
Example #4
0
 /**
  * Display the specified resource.
  * GET /accountreceivables/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $invoices = Invoice::with('invoicedetail')->find($id);
     if ($invoices->type === "to tenant") {
         $total = $invoices->invoicedetail->rent + $invoices->invoicedetail->water + $invoices->invoicedetail->electricity + $invoices->invoicedetail->security + $invoices->invoicedetail->service + $invoices->invoicedetail->garbage;
     } elseif ($invoices->type === "refund") {
         $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit;
     } elseif ($invoices->type === "deposits") {
         $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit + $invoices->invoicedetail->rent;
     }
     $houseid = $invoices->id;
     $hid = $invoices->houseID;
     $housename = House::where('id', $hid)->pluck('name');
     $propertyid = House::where('id', $hid)->pluck('propertyID');
     $propertyname = Property::where('id', $propertyid)->pluck('name');
     $allbal = Invoice::where('houseID', $hid)->sum('balance');
     if ($invoices->amountpaid <= 0) {
         $outstandingbal = $allbal;
     } else {
         $outstandingbal = $allbal - $invoices->balance;
     }
     $balance = $invoices->balance;
     if ($outstandingbal == $invoices->balance) {
         $amountdue = $invoices->balance;
     } else {
         $amountdue = $invoices->balance + $outstandingbal;
     }
     $title = "Print Invoice";
     return View::make('backend.code.invoice.show', compact('invoices', 'housename', 'title', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue'));
 }
 /**
  * Store a newly created resource in storage.
  * POST /accountreceivables
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('invoiceID' => 'required|max:50|', 'houseID' => 'required', 'amount' => 'required|min:2', 'paymenttype' => 'required', 'amountpayed' => 'required', 'paymenttyperef' => 'required'));
     if ($v->passes()) {
         $findHouse = Input::get('houseID');
         $propertyId = House::where('name', $findHouse)->pluck('propertyID');
         $propertyName = Property::where('id', $propertyId)->pluck('name');
         $agent_id = Sentry::getUser()->id;
         $gamount = Input::get('amount');
         $gpayed = Input::get('amountpayed');
         $initpaid = Input::get('initpaid');
         $b = $gamount - $gpayed;
         $id = Input::get('invoiceID');
         $balance = $gamount - $gpayed;
         $invoice = Invoice::find($id);
         $invoiceid = $invoice->id;
         $invoice->balance = $gamount - $gpayed;
         $invoice->amountpaid = $gpayed + $initpaid;
         $invoice->save();
         $reciept = new Receipt();
         $reciept->invoiceID = $invoice->id;
         $reciept->agent_id = $agent_id;
         $reciept->type = $invoice->type;
         $reciept->houseID = $invoice->houseID;
         $reciept->recipient = $invoice->recipient;
         $reciept->invoice_amt = $gpayed + $initpaid + $b;
         $reciept->amountpaid = $gpayed;
         $reciept->balance = $gamount - $gpayed;
         $reciept->duedate = $invoice->duedate;
         $reciept->save();
         $findTenant = $invoice->recipient;
         $ftname = strtok($findTenant, " ");
         $tenants = Tenant::where('name', $ftname)->get();
         foreach ($tenants as $tenant) {
             $t_name = $tenant->name;
             $to = $tenant->phone;
         }
         $payment = new Payment();
         $payment->invoiceID = Input::get('invoiceID');
         $payment->amount = Input::get('amount');
         $payment->amountpayed = Input::get('amountpayed');
         $payment->houseID = $findHouse;
         $payment->client = $invoice->recipient;
         $payment->property = $propertyName;
         $payment->balance = $gamount - $gpayed;
         $payment->paymenttype = Input::get('paymenttype');
         $payment->paymenttyperef = Input::get('paymenttyperef');
         $payment->save();
         #send an sms to the tenant
         $message = ' Hi ' . $t_name . ', Your payment of  Ksh. ' . number_format($gpayed, 2) . ' for invoice no. ' . $invoiceid . ' of ' . $findHouse . '   has been received successfully, due balance ' . number_format($balance, 2) . ', Thank you';
         Queue::push('SendSMS', array('message' => $message, 'number' => $to));
         return Redirect::route('show/receipts/index')->withFlashMessage('Payment received successfully');
     }
     return Redirect::back()->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $agent_id = Sentry::getUser()->id;
     $tenants = Tenant::where('agent_id', $agent_id)->get();
     foreach ($tenants as $tenant) {
         $tname = $tenant->name;
         $occupancies = House::where('tenant', $tname)->get();
     }
     return View::make('backend.code.tenants.index', compact('tenants', 'occupancies'));
 }
 public function showReceipt($id)
 {
     $receipts = Receipt::find($id);
     $hid = $receipts->houseID;
     $housename = $hid;
     $propertyid = House::where('name', $hid)->pluck('propertyID');
     $propertyname = Property::where('id', $propertyid)->pluck('name');
     $inid = $receipts->invoiceID;
     $allbal = Invoice::where('houseID', $hid)->sum('balance');
     $current_bal = Invoice::where('id', $inid)->pluck('balance');
     $outstandingbal = $allbal - $current_bal;
     $amountdue = $allbal;
     $balance = $receipts->balance;
     return View::make('backend.code.invoice.showr', compact('receipts', 'amountdue', 'housename', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue'));
 }
Example #8
0
 public function showSpeReceipts($id)
 {
     $invoices = Invoice::with('invoicedetail')->find($id);
     if ($invoices->type === "to tenant") {
         $total = $invoices->invoicedetail->rent + $invoices->invoicedetail->water + $invoices->invoicedetail->electricity + $invoices->invoicedetail->security + $invoices->invoicedetail->service + $invoices->invoicedetail->garbage;
     } elseif ($invoices->type === "refund") {
         $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit;
     } elseif ($invoices->type === "deposits") {
         $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit + $invoices->invoicedetail->rent;
     }
     $houseid = $invoices->id;
     $hid = $invoices->houseID;
     $housename = House::where('id', $hid)->pluck('name');
     $tenantname = House::where('id', $hid)->pluck('tenant');
     $propertyid = House::where('id', $hid)->pluck('propertyID');
     $propertyname = Property::where('id', $propertyid)->pluck('name');
     $allbal = Invoice::where('houseID', $hid)->sum('balance');
     if ($invoices->amountpaid <= 0) {
         $outstandingbal = $allbal;
     } else {
         $outstandingbal = $allbal - $invoices->balance;
     }
     $balance = $invoices->balance;
     if ($outstandingbal == $invoices->balance) {
         $amountdue = $invoices->balance;
     } else {
         $amountdue = $invoices->balance + $outstandingbal;
     }
     $title = "Print Receipt";
     /*
         $emailcontent = array (
     	
     
     				'propertyname'=>	$propertyname,
     				'housename'=>	$housename,
     				'tenant'=>	$tenantname,
     				'tfname'=> $invoices->recipient,
     				'invoiceid'=>	$invoices->id,
     				'created_at'=>	$invoices->created_at,
     				'invoicetype'=>	$invoices->type,
     				'rent'=>	$invoices->invoicedetail->rent,
     				'water'=>	$invoices->invoicedetail->water,
     				'electricity'=>	$invoices->invoicedetail->electricity,
     				'security'=>	$invoices->invoicedetail->security,
     				'service'=>	$invoices->invoicedetail->service,
     				'garbage'=>	$invoices->invoicedetail->garbage,
     				'rentD'=>	$invoices->invoicedetail->rentD,
     				'rent'=>	$invoices->invoicedetail->rent,
     				'waterD'=>	$invoices->invoicedetail->waterD,
     				'electricityD'=>	$invoices->invoicedetail->electricityD,
     				'garbage'=>	$invoices->invoicedetail->garbage,
     				'transport_cost'=>	$invoices->invoicedetail->transport_cost,
     				'g_repairs'=>	$invoices->invoicedetail->g_repairs,
     				'o_bills'=>	$invoices->invoicedetail->o_bills,
     				'storage_fees'=>	$invoices->invoicedetail->storage_fees,
     				'total'=>	$total,
     				'amountpaid'=>	$invoices->amountpaid,
     				'balance'=>	$balance,
     				'outstandingbal'=>	$outstandingbal,
     				'amountdue'=>	$amountdue,
     				'duedate'=>	$invoices->duedate
     
     	);
     
     	Mail::send('emails.receipts', $emailcontent, function($message)
     	{
     	$message->to('*****@*****.**')
     	->subject('Receipts');
     	});
     */
     return View::make('backend.code.invoice.show', compact('invoices', 'title', 'housename', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue'));
 }
 public function destroy($id)
 {
     Property::find($id)->delete();
     House::where('propertyID', $id)->delete();
     House::where('propertyID', $id)->delete();
     Housedue::where('propertyID', $id)->delete();
     return Redirect::route('admin.property.index');
 }
 /**
  * Show the form for editing the specified resource.
  * GET /accountreceivables/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $invoices = Invoice::find($id);
     $hid = $invoices->houseID;
     $housename = $hid;
     $propertyid = House::where('name', $hid)->pluck('propertyID');
     $propertyname = Property::where('id', $propertyid)->pluck('name');
     if (is_null($invoices)) {
         return Redirect::route('invoice.index');
     }
     return View::make('backend.code.invoice.edit', compact('invoices', 'properties', 'housename', 'propertyid', 'propertyname'));
 }
 public function gerenateMonthly()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('houseID' => 'required', 'propertyid' => 'required', 'agent_id' => 'required'));
     if ($v->passes()) {
         $propertyidan = Input::get('propertyid');
         $houseID = Input::get('houseID');
         $startDate = time();
         $lastmonth = date('Y-m-d', strtotime('+5 day', $startDate));
         $ddate = date('d');
         $agent_id = Input::get('agent_id');
         $billedusr = User::find($agent_id);
         $hisBalance = $billedusr->credit_balance;
         $newBalance = $hisBalance - 3;
         $billedusr->credit_balance = $newBalance;
         $billedusr->save();
         $billstatement = new Statement();
         $billstatement->type = "Generating Invoice";
         $billstatement->amount = 3;
         $billstatement->save();
         if ($houseID === "All") {
             $houses = House::where('status', '=', 'booked')->where('frequency', '=', 1)->where('propertyID', $propertyidan)->get();
             foreach ($houses as $house) {
                 $hid = $house->id;
                 $houseName = $house->name;
                 $propid = $house->propertyID;
                 $propname = Property::where('id', $propid)->pluck('name');
                 $rent = $house->rent;
                 $water = $house->water;
                 $garbage = $house->garbage;
                 $electricity = $house->electricity;
                 $security = $house->security;
                 $frequency = $house->frequency;
                 $tenant_id = $house->tenant;
                 $tenantnames = strtok($tenant_id, " ");
                 $tenant = Tenant::where('name', $tenantnames)->first();
                 $t_name = $tenant->name;
                 $to = $tenant->phone;
                 $t_agent = $tenant->agent_id;
                 $balance = $rent + $water + $garbage + $electricity + $security;
                 $invoice = new Invoice();
                 $invoice->type = 'to tenant';
                 $invoice->houseID = $houseName;
                 $invoice->recipient = $t_name;
                 $invoice->agent_id = $t_agent;
                 $invoice->balance = $balance;
                 $invoice->propertyid = $propid;
                 $invoice->duedate = $lastmonth;
                 $invoice->save();
                 $invoicedetail = new Invoicedetail();
                 $invoicedetail->rent = $rent;
                 $invoicedetail->water = $water;
                 $invoicedetail->garbage = $garbage;
                 $invoicedetail->electricity = $electricity;
                 $invoicedetail->security = $security;
                 $invoice->invoicedetail()->save($invoicedetail);
                 $message = 'Dear ' . $t_name . ', your rent for this month of Ksh ' . number_format($balance, 2) . '  is due for payment. For inquiries contact 0700548168 Rehema House Ngong';
                 Queue::push('SendSMS', array('message' => $message, 'number' => $to));
             }
             $noteSuccesGen = array('error' => false, 'message' => "Monthly invoice(s) generated successfully");
             return $noteSuccesGen;
         } else {
             $house = House::where('name', '=', $houseID)->where('frequency', '=', 1)->first();
             $hid = $house->id;
             $houseName = $house->name;
             $propid = $house->propertyID;
             $propname = Property::where('id', $propid)->pluck('name');
             $rent = $house->rent;
             $water = $house->water;
             $garbage = $house->garbage;
             $electricity = $house->electricity;
             $security = $house->security;
             $frequency = $house->frequency;
             $tenant_id = $house->tenant;
             $tenantnames = strtok($tenant_id, " ");
             $tenant = Tenant::where('name', $tenantnames)->first();
             $t_name = $tenant->name;
             $to = $tenant->phone;
             $t_agent = $tenant->agent_id;
             $balance = $rent + $water + $garbage + $electricity + $security;
             $invoice = new Invoice();
             $invoice->type = 'to tenant';
             $invoice->houseID = $houseName;
             $invoice->recipient = $t_name;
             $invoice->agent_id = $t_agent;
             $invoice->balance = $balance;
             $invoice->propertyid = $propid;
             $invoice->duedate = $lastmonth;
             $invoice->save();
             $invoicedetail = new Invoicedetail();
             $invoicedetail->rent = $rent;
             $invoicedetail->water = $water;
             $invoicedetail->garbage = $garbage;
             $invoicedetail->electricity = $electricity;
             $invoicedetail->security = $security;
             $invoice->invoicedetail()->save($invoicedetail);
             $message = 'Dear ' . $t_name . ', your rent for this month of Ksh ' . number_format($balance, 2) . '  is due for payment.For inquiries contact 0700548168 Rehema House Ngong';
             Queue::push('SendSMS', array('message' => $message, 'number' => $to));
             $noteSuccesGen = array('error' => false, 'message' => "Monthly invoice(s) generated successfully");
             return $noteSuccesGen;
         }
     }
     $noteGenerate4 = array('error' => true, 'message' => $v->messages());
     return $noteGenerate4;
 }
Example #12
0
        $invoicedetail = new Invoicedetail();
        $invoicedetail->rent = $rent;
        $invoicedetail->water = $water;
        $invoicedetail->garbage = $garbage;
        $invoicedetail->electricity = $electricity;
        $invoicedetail->security = $security;
        $invoice->invoicedetail()->save($invoicedetail);
        $message = ' Hi ' . $t_name . ', this is to notify you that your invoice of Ksh ' . number_format($balance, 2) . ' for ' . $propname . ' unit ' . $houseName . '  is due on ' . $lastmonth . '.Thanks';
        Queue::push('SendSMS', array('message' => $message, 'number' => $to));
    }
    return 'Semi-annually invoice(s) generated successfully';
});
Route::get('/cron/run/annualy/lvWVYpnQ7xqFLbjaoG1oDUlTHQ4GMlmx', function () {
    $startDate = time();
    $lastmonth = date('Y-m-d', strtotime('+5 day', $startDate));
    $houses = House::where('status', '=', 'booked')->where('frequency', '=', 4)->get();
    foreach ($houses as $house) {
        $hid = $house->id;
        $houseName = $house->name;
        $propid = $house->propertyID;
        $propname = Property::where('id', $propid)->pluck('name');
        $rent = $house->rent;
        $water = $house->water;
        $garbage = $house->garbage;
        $electricity = $house->electricity;
        $security = $house->security;
        $frequency = $house->frequency;
        $tenant_id = $house->tenant;
        $tenantnames = strtok($tenant_id, " ");
        $tenant = Tenant::where('name', $tenantnames)->first();
        $t_name = $tenant->name;
 /**
  * Display the specified resource.
  * GET /accountreceivables/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $occupancies = Occupancy::where('houseID', $id)->get();
     $housename = House::where('id', $id)->pluck('name');
     return View::make('backend.code.occupancy.show', compact('occupancies', 'housename'));
 }