private function _view() { $daterange = Input::get('record_range', ''); //Session::put('ss_select_expen', $type); Larasset::start('header')->css('daterangepicker'); Larasset::start('footer')->js('moment', 'daterangepicker'); Larasset::start('footer')->js('dataTables-min', 'dataTables-bootstrap'); $data['entries'] = Expenditure::with(array('user' => function ($q) { $q->select('id', 'name'); })); //Is the person Admin or not if (User::permitted('role.admin') !== true) { $data['entries'] = $data['entries']->where('user_id', Auth::user()->id); } if ($daterange !== '' && strpos($daterange, '-') !== FALSE) { $fromandto = explode('-', $daterange); $from = $fromandto[0]; $to_plus_1day = strtotime('now') - strtotime('yesterday') + strtotime($fromandto[1]); $to = date('Y/n/d', $to_plus_1day); $data['from'] = format_date2($fromandto[0]); $data['to'] = format_date2($fromandto[1]); } else { $to = date('Y/n/d', strtotime('today')); $from = date('Y/n/d', strtotime('first day of this month')); $data['to'] = format_date2($to); $data['from'] = format_date2($from); } $data['entries'] = $data['entries']->whereBetween('date', array(sqldate($from), sqldate($to))); //$data['entries'] = $data['entries']->orderby('date', 'desc')->paginate(10); $data['entries'] = $data['entries']->orderby('date', 'desc')->get(); //tt($data); return $data; }
private function _view() { $type = Input::get('type', 'created_at'); $daterange = Input::get('record_range', ''); //Session::put('ss_select_expen', $type); Larasset::start('header')->css('daterangepicker'); Larasset::start('footer')->js('moment', 'daterangepicker'); Larasset::start('footer')->js('dataTables-min', 'dataTables-bootstrap'); $data['entries'] = Expenditure::with(array('user' => function ($q) { $q->select('id', 'name'); })); //Is the person Admin or not if (User::permitted('role.admin') !== true) { $data['entries'] = $data['entries']->where('user_id', Auth::user()->id); } if ($daterange !== '' && strpos($daterange, '-') !== FALSE) { $fromandto = explode('-', $daterange); $from = $fromandto[0]; $to_plus_1day = strtotime('now') - strtotime('yesterday') + strtotime($fromandto[1]); $to = date('Y/n/d', $to_plus_1day); $data['from'] = format_date2($fromandto[0]); $data['to'] = format_date2($fromandto[1]); } else { $to = date('Y/n/d', strtotime('today')); $from = date('Y/n/d', strtotime('first day of this month')); $data['to'] = format_date2($to); $data['from'] = format_date2($from); } $data['entries'] = $data['entries']->whereBetween('date', array(sqldate($from), sqldate($to))); //$data['entries'] = $data['entries']->orderby($type, 'desc')->paginate(10); $data['entries'] = $data['entries']->orderby('date', 'asc')->get(); //dd($data['entries']->toArray()); $saleslog = Salelog::whereBetween('created_at', array(sqldate($from), sqldate($to)))->select('unitprice', 'costprice', 'quantity', 'total_unitprice')->orderby('receipt_id', 'desc')->get(); $profitmargin = 0; foreach ($saleslog as $field) { //tt( $field->total_unitprice - ( $field->costprice * $field->quantity ) , true); $profitmargin += $field->total_unitprice - $field->costprice * $field->quantity; } $data['profitmargin'] = $profitmargin; //tt($data); return $data; }