Example #1
0
 private static function getProjectSelect($project_id = null)
 {
     //project_id is necessary when viewing an archived task (the project is closed)
     $projects = ['' => trans('messages.project.single')];
     $clients = Client::whereHas('projects', function ($query) use($project_id) {
         $query->whereNull('closed_at');
         if ($project_id) {
             $query->orWhere('id', $project_id);
         }
     })->with(['projects' => function ($query) use($project_id) {
         $query->whereNull('closed_at')->orderBy('name');
         if ($project_id) {
             $query->orWhere('id', $project_id);
         }
     }])->orderBy('name')->get();
     foreach ($clients as $client) {
         $group = [];
         foreach ($client->projects as $project) {
             $group[$project->id] = $project->name;
         }
         $projects[$client->name] = $group;
     }
     return $projects;
 }
Example #2
0
 public function index(Request $request)
 {
     Carbon::setLocale('ru');
     $clients_filter = Client::whereHas('deliveries', function ($query) {
         $query->where('status', '=', 'Профинансирована');
     })->get();
     if ($request->ajax()) {
         $bills = Bill::where('id', '>', 0);
         if (Input::get('year') != Null) {
             $bills = $bills->whereYear('bill_date', '=', Input::get('year'));
         }
         if (Input::get('month') != Null) {
             $bills = $bills->whereMonth('bill_date', '=', Input::get('month'));
         }
         if (Input::get('client_id') != 'all') {
             $bills = $bills->where('client_id', '=', Input::get('client_id'));
         }
         $sum = array();
         $sum['without_nds'] = $bills->sum('without_nds');
         $sum['nds'] = $bills->sum('nds');
         $sum['with_nds'] = $bills->sum('with_nds');
         $bills = $bills->get();
         $clients = Client::All();
         $debts_full = array();
         $monthRepayment = array();
         $bill_date_first_day = Carbon::createFromDate(Input::get('year'), Input::get('month'), 1);
         foreach ($clients as $client) {
             foreach ($client->agreements as $agreement) {
                 $debt = 0;
                 foreach ($agreement->relations as $relation) {
                     if ($agreement->account == FALSE) {
                         foreach ($relation->deliveries as $delivery) {
                             if ($delivery->status == 'Профинансирована') {
                                 //echo $client->name.": долг перед месяцем:";
                                 $pred_with_nds = $delivery->dailyChargeCommission()->where('handler', false)->whereDate('created_at', '<', $bill_date_first_day)->sum('with_nds');
                                 // var_dump($pred_with_nds);
                                 // echo $client->name.": погашения:";
                                 $repayments = $delivery->dailyChargeCommission()->where('handler', true)->sum('with_nds');
                                 // var_dump($repayments);echo $client->name.": начисленные комиссии:";
                                 $with_nds_delivery = $delivery->dailyChargeCommission()->where('handler', false)->whereYear('created_at', '=', Input::get('year'))->whereMonth('created_at', '=', Input::get('month'))->sum('with_nds');
                                 // var_dump($with_nds_delivery);
                                 if ($repayments > $pred_with_nds) {
                                     if ($repayments >= $with_nds_delivery + $pred_with_nds) {
                                         $debt += 0;
                                     } else {
                                         $debt += $with_nds_delivery - ($repayments - $pred_with_nds);
                                     }
                                 } else {
                                     $debt += $with_nds_delivery;
                                 }
                                 // echo $client->name.": текущий долг:";
                                 // var_dump($debt);
                                 // echo "\n";
                             }
                         }
                     } else {
                         $debt = 0;
                     }
                 }
                 // var_dump($debt);
                 $monthRepayment[$agreement->id] = $debt;
             }
         }
         // var_dump($monthRepayment);
         $stop = Delivery::where('stop_commission', '=', true)->get();
         return view('invoicing.indexAjax', ['stop' => $stop, 'bills' => $bills, 'debts_full' => $debts_full, 'monthRepayment' => $monthRepayment, 'sum' => $sum]);
     } else {
         $dt = Carbon::now()->startOfMonth();
         $dates = DailyChargeCommission::select('created_at')->whereDate('created_at', '<', $dt)->orderBy('created_at', 'desc')->groupBy('created_at')->get();
         $year = '';
         $month = '';
         $i_month = 0;
         $i_year = 0;
         $dates_for_filter = array();
         foreach ($dates as $date) {
             $dates_for_filter[$date->created_at->year][$date->created_at->month] = $date->created_at->month;
         }
         return view('invoicing.index', ['clients' => $clients_filter, 'dt' => $dates_for_filter]);
     }
 }