本文整理汇总了PHP中app\Client::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::whereHas方法的具体用法?PHP Client::whereHas怎么用?PHP Client::whereHas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Client
的用法示例。
在下文中一共展示了Client::whereHas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProjectSelect
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;
}
示例2: index
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]);
}
}