Ejemplo n.º 1
0
 public function index(Request $request)
 {
     if ($request->ajax()) {
         $client_id = Input::get('filter-client');
         $debtor_id = Input::get('filter-debtor');
         $registry = Input::get('filter-registry');
         $choice = Input::get('filter-choice');
         $commissions = DailyChargeCommission::query();
         $commissions->where('handler', true);
         if ($client_id != 0) {
             $commissions->whereHas('delivery', function ($q) use($client_id) {
                 $q->where('client_id', '=', $client_id);
             });
         }
         if ($debtor_id != 0) {
             $commissions->whereHas('delivery', function ($q) use($debtor_id) {
                 $q->where('debtor_id', '=', $debtor_id);
             });
         }
         if ($registry != 0) {
             $commissions->whereHas('delivery', function ($q) use($registry) {
                 $q->where('registry', '=', $registry);
             });
         }
         if ($choice != 0) {
             $before = Input::get('filter-before');
             $after = Input::get('filter-after');
             $arratBetween = [$before, $after];
             if ($choice == 1) {
                 $commissions->whereHas('delivery', function ($q) use($arratBetween) {
                     $q->whereBetween('date_of_registry', $arratBetween);
                 });
             } elseif ($choice == 2) {
                 $commissions->whereBetween('created_at', $arratBetween);
             }
         }
         $commissions = $commissions->get();
         return view('reportRepayment.tableRow', ['commissions' => $commissions]);
     } else {
         $clients = Client::Where('active', true)->get();
         $debtors = Debtor::all();
         $debtors = Debtor::all();
         $registries = ChargeCommission::Distinct('registry')->lists('registry');
         return view('reportRepayment.index', ['clients' => $clients, 'debtors' => $debtors, 'registries' => $registries]);
     }
 }
 public function createDailyCharge($dailyArray, $commissionId, $deliveryId)
 {
     $daily = new DailyChargeCommission();
     $daily->delivery_id = $deliveryId;
     $daily->charge_commission_id = $commissionId;
     $daily->fixed_charge = $dailyArray['dailyFixed'];
     $daily->percent = $dailyArray['dailyPercent'];
     $daily->udz = $dailyArray['dailyUdz'];
     $daily->deferment_penalty = $dailyArray['dailyDeferment'];
     $daily->nds = $dailyArray['dailyNds'];
     $daily->without_nds = $dailyArray['dailyWithoutNds'];
     $daily->with_nds = $dailyArray['dailyWithNds'];
     $daily->handler = false;
     $daily->fixed_charge_nds = $dailyArray['dailyFixedNds'];
     $daily->percent_nds = $dailyArray['dailyPercentNds'];
     $daily->udz_nds = $dailyArray['dailyUdzNds'];
     $daily->deferment_penalty_nds = $dailyArray['dailyDefermentNds'];
     $daily->created_at = $dailyArray['dateNow'];
     $daily->save();
 }
Ejemplo n.º 3
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]);
     }
 }
Ejemplo n.º 4
0
 public function deleteOverCommission($delivery, $repayment)
 {
     DailyChargeCommission::where('handler', false)->where('delivery_id', '=', $delivery->id)->whereDate('created_at', '>', $repayment->date)->delete();
     $dayliChargeCommission = DailyChargeCommission::where('handler', false)->where('delivery_id', '=', $delivery->id)->get();
     $dayliPaymentCommission = DailyChargeCommission::where('handler', true)->where('delivery_id', '=', $delivery->id)->get();
     $commission = $delivery->chargeCommission()->where('waybill_status', false)->first();
     if ($commission) {
         $commission->fixed_charge = $dayliChargeCommission->sum('fixed_charge') - $dayliPaymentCommission->sum('fixed_charge');
         $commission->fixed_charge_nds = $dayliChargeCommission->sum('fixed_charge_nds') - $dayliPaymentCommission->sum('fixed_charge_nds');
         $commission->percent = $dayliChargeCommission->sum('percent') - $dayliPaymentCommission->sum('percent');
         $commission->percent_nds = $dayliChargeCommission->sum('percent_nds') - $dayliPaymentCommission->sum('percent_nds');
         $commission->udz = $dayliChargeCommission->sum('udz') - $dayliPaymentCommission->sum('udz');
         $commission->udz_nds = $dayliChargeCommission->sum('udz_nds') - $dayliPaymentCommission->sum('udz_nds');
         $commission->deferment_penalty = $dayliChargeCommission->sum('deferment_penalty') - $dayliPaymentCommission->sum('deferment_penalty');
         $commission->deferment_penalty_nds = $dayliChargeCommission->sum('deferment_penalty_nds') - $dayliPaymentCommission->sum('deferment_penalty_nds');
         $withiut_nds = $commission->fixed_charge + $commission->percent + $commission->udz + $commission->deferment_penalty;
         $nds = $commission->fixed_charge_nds + $commission->percent_nds + $commission->udz_nds + $commission->deferment_penalty_nds;
         $with_nds = $withiut_nds + $nds;
         $commission->without_nds = $withiut_nds;
         $commission->nds = $nds;
         $commission->with_nds = $with_nds;
         $commission->debt = $with_nds;
         $commission->save();
     }
 }