/**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create($id, Request $request)
 {
     $salesinvoices = SalesInvoice::where('client_id', $id)->where('status', '!=', 'Collected')->where('status', '!=', 'Draft')->where('status', '!=', 'Pending')->orderBy('status', 'asc')->get();
     $actionOptions = [];
     $actionOptions['Text'] = 'Text';
     $actionOptions['Call'] = 'Call';
     $actionOptions['Fax'] = 'Fax';
     $actionOptions['Send SOA'] = 'Send SOA';
     $actionOptions['Email'] = 'Email';
     $actionOptions['Visit'] = 'Visit';
     $actionOptions['Call and Send SOA'] = 'Call and Send SOA';
     $reasonOptions = Reason::lists('reason', 'id');
     $statusOptions = [];
     $statusOptions['To Do'] = 'To Do';
     $statusOptions['Done'] = 'Done';
     $method = 'post';
     return view('collection_logs.create', compact('id', 'method', 'actionOptions', 'statusOptions', 'reasonOptions', 'id', 'salesinvoices'));
 }
 public function filter()
 {
     $input = Request::all();
     $filter = $input['filter'];
     if ($filter == 'All') {
         return redirect()->action('CollectiblesController@index');
     }
     $clients = Client::where('status', $filter)->paginate(10);
     $overdue = new SalesInvoice();
     $delivered = new SalesInvoice();
     $check = new SalesInvoice();
     $salesinvoice = new SalesInvoice();
     $salesinvoice2 = new SalesInvoice();
     $salesinvoice3 = new SalesInvoice();
     $salesinvoiceTotal;
     foreach ($clients as $client) {
         $overdue[$client->id] = SalesInvoice::where('client_id', $client->id)->where('status', 'Overdue')->count();
         $delivered[$client->id] = SalesInvoice::where('client_id', $client->id)->where('status', 'Delivered')->count();
         $check[$client->id] = SalesInvoice::where('client_id', $client->id)->where('status', 'Check on Hand')->count();
         // $salesinvoice[$client->id] = DB::SELECT("SELECT sum(total_amount) as total FROM sales_invoices
         //                        WHERE (status = 'Overdue' or  status = 'Delivered') and client_id = '$client->id'");
         $salesinvoice = SalesInvoice::where('status', '=', 'Overdue')->where('client_id', '=', $client->id)->sum('total_amount');
         $salesinvoice2 = SalesInvoice::where('status', 'Delivered')->where('client_id', $client->id)->sum('total_amount');
         $salesinvoice3 = SalesInvoice::where('status', 'Check on Hand')->where('client_id', $client->id)->sum('total_amount');
         $salesinvoiceTotal[$client->id] = $salesinvoice + $salesinvoice2 + $salesinvoice3;
     }
     // for ($x = $clients[0]; $x < count($clients)+1; $x++)
     // {
     //    $overdue[$x] = SalesInvoice::where('client_id', $x)->where('status', 'Overdue')->count();
     //    $delivered[$x] = SalesInvoice::where('client_id', $x)->where('status', 'Delivered')->count();
     //    $pending[$x] = SalesInvoice::where('client_id', $x)->where('status', 'Pending')->count();
     // }
     if ($clients == "[]") {
         return redirect()->action('CollectiblesController@index');
     }
     $clients->appends(Request::only('filter'));
     return view('collectibles.index', compact('clients', 'overdue', 'delivered', 'check', 'salesinvoiceTotal'));
 }
 public function filter()
 {
     $input = Request::all();
     if (isset($input['filter_status'])) {
         if ($input['filter_status'] == "All") {
             return redirect()->action('SalesInvoicesController@index');
         } else {
             $filter_status = $input['filter_status'];
             $sales_invoices = SalesInvoice::where('status', $filter_status)->paginate(10);
             $sales_invoices->appends(Request::only('filter_status'));
         }
     } else {
         if ($input['filter_date'] == "All") {
             return redirect()->action('SalesInvoicesController@index');
         } else {
             $filter_date = $input['filter_date'];
             $sales_invoices = SalesInvoice::where('due_date', $filter_date)->where('status', '!=', 'Collected')->paginate(10);
             //and where status !== collected
             $sales_invoices->appends(Request::only('filter_date'));
         }
     }
     // if ($input['filter_status'] == "[]")
     // {
     //     return redirect()->action('SalesInvoicesController@index');
     // }
     $dates = SalesInvoice::where('status', '!=', 'Collected')->where('status', '!=', 'Draft')->orderBy('due_date', 'desc')->lists('due_date', 'due_date');
     return view('sales_invoices.index', compact('sales_invoices', 'dates'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $client = Client::find($id);
     // $sales_invoices = DB::select("SELECT * FROM sales_invoices si JOIN clients c ON si.client_id = c.id WHERE c.id='$id'");
     // $sales_invoices = SalesInvoice::where('client_id', $id);
     $sales_invoices = SalesInvoice::where('client_id', $id)->orderby('date', 'desc')->paginate(10);
     return view('clients.show', compact('client', 'sales_invoices'));
 }