private function salesummary($date = 'salesummary_today') { $time = $this->_dateSetter($date); $sales = Receipt::whereBetween('created_at', $time)->orderBy('id', 'desc'); $data['salesummary']['sales'] = $sales->get()->toArray(); $data['salesummary']['totalamount'] = 0.0; if (!empty($data['salesummary']['sales'])) { $data['salesummary']['totalamount'] = $sales->sum('receipt_worth'); } return $data; }
public function getReport() { $input = Input::all(); $v = Validator::make(Input::All(), array('property_name' => 'required', 'from_date' => 'required', 'to_date' => 'required', 'type' => 'required', 'houseIDReport' => 'required', 'agent_id' => 'required')); if ($v->passes()) { $propertyid = Input::get('property_name'); $from_date = Input::get('from_date'); $to_date = Input::get('to_date'); $type = Input::get('type'); $houseID = Input::get('houseIDReport'); $start_day = date("Y-m-d H:i:s", strtotime($from_date)); $end_day = date("Y-m-d H:i:s", strtotime($to_date)); $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 = "Report Generation"; $billstatement->amount = 3; $billstatement->save(); if ($houseID === "All Report") { $sumReceipts = Receipt::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('amountpaid'); $sumInvoiceBalance = Invoice::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('balance'); $sumInvoicePaid = Invoice::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('amountpaid'); $sumRefundPaid = Invoice::where('propertyid', $propertyid)->where('type', '=', 'refund')->sum('amountpaid'); $invoiceUn = Invoice::list('houseID'); $unitsUnpaid = House::whereIn('name', $invoiceUn)->count(); $sumInvoice = $sumInvoiceBalance + $sumInvoicePaid; $noteSum = array('error' => false, 'type' => "All", 'sumRefund' => $sumRefundPaid, 'unitsUnpaid' => $unitsUnpaid, 'sumInvoice' => $sumInvoice, 'sumReceipt' => $sumReceipts); } else { $sumReceipts = Receipt::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('amountpaid'); $sumInvoiceBalance = Invoice::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('balance'); $sumInvoicePaid = Invoice::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('amountpaid'); $sumInvoice = $sumInvoiceBalance + $sumInvoicePaid; $noteSum = array('error' => false, 'type' => "House", 'sumInvoice' => $sumInvoice, 'sumReceipt' => $sumReceipts); } return $noteSum; } $notePE = array('error' => true, 'message' => 'Ensure that all the fields are set'); return $notePE; }