public function show($id) { $member = Member::find($id); $birthDate = $member->birthday; $birthDate = explode("-", $birthDate); $member->age = Carbon::createFromDate($birthDate[0], $birthDate[1], $birthDate[2])->age; $meses = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); $dias = array("Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"); $currentdate = Carbon::today(); $sumaAffiliations = $member->affiliations->sum('price'); $affiliations = $member->affiliations; $affiliationActives = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member->id)->where('finalization', '>=', $currentdate)->get(); $affiliationInactives = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member->id)->where('finalization', '<', $currentdate)->get(); $member->affiliations = $affiliationActives; if ($affiliationActives->first() != null) { $memshipactiva = $affiliationActives->last(); $initiation = new Carbon($memshipactiva->initiation); $finalization = new Carbon($memshipactiva->finalization); $corrido = $initiation->diffInDays($currentdate); if ($initiation->lt($currentdate)) { $diference = $initiation->diffInDays($finalization); $porcentaje = $corrido / $diference * 100; } else { $porcentaje = 0; } $memshipactiva->porcentaje = $porcentaje; } else { $memshipactiva = null; } $saldo = $sumaAffiliations - $member->payments->sum('amount'); $member->saldo = $saldo; $member->sumaPagos = $member->payments->sum('amount'); $member->sumaAffiliations = $sumaAffiliations; if ($member->sumaPagos == 0 and $sumaAffiliations == 0) { //no tiene pagos ni afiliaciones $member->difUltimoPago = -1; } elseif ($member->sumaPagos <= 0 and $sumaAffiliations > 0) { //no tiene pagos pero si tiene afiliaciones $fechaUltimoPago = \App\Affiliation::orderBy('created_at', 'asc')->where('member_id', $member->id)->first(); $fechaUltimoPago = new Carbon($fechaUltimoPago->created_at); $difUltimoPago = $fechaUltimoPago->diffInDays($currentdate); $member->difUltimoPago = $difUltimoPago; } elseif ($member->sumaPagos > 0 and $sumaAffiliations > 0) { // tiene afiliaciones y pagos $fechaUltimoPago = new Carbon($member->payments->first()->created_at); $difUltimoPago = $fechaUltimoPago->diffInDays($currentdate); $member->difUltimoPago = $difUltimoPago; } return view('member.show', ['member' => $member, 'meses' => $meses, 'dias' => $dias, 'activa' => $memshipactiva, 'inactivas' => $affiliationInactives]); }
/** * @param Carbon $time * @return Carbon */ protected function shiftEndTime($time) { if ($time->lt($this->day_shift_end_time)) { return $this->day_shift_end_time; } return $this->night_shift_end_time; }
function scopeScheduledBetween($q, \Carbon\Carbon $date1 = null, \Carbon\Carbon $date2 = null) { if (!$date1 && !$date2) { return $q; } elseif (!$date1 || !$date2) { throw new Exception("Invalid date range", 1); } else { if ($date2->lt($date1)) { $tmp = $date1; $date1 = $date2; $date2 = $tmp; } return $q->where(function ($q) use($date1, $date2) { $q->where(function ($q) use($date1, $date2) { $q->whereNull('departure_until')->where('departure', '>=', $date1)->where('departure', '<=', $date2); })->orWhere(function ($q) use($date1, $date2) { $q->whereNotNull('departure_until')->where(function ($q) use($date1, $date2) { $q->where(function ($q) use($date1, $date2) { $q->where('departure', '<=', $date1)->where('departure_until', '>=', $date1); })->orWhere(function ($q) use($date1, $date2) { $q->where('departure', '>=', $date1)->where('departure_until', '<=', $date2); })->orWhere(function ($q) use($date1, $date2) { $q->where('departure', '>=', $date1)->where('departure', '<=', $date2)->where('departure_until', '>=', $date2); })->orWhere(function ($q) use($date1, $date2) { $q->where('departure', '<=', $date1)->where('departure_until', '>=', $date2); }); }); }); }); } }
private function eventHasPassed(Slot $slot) { $start_date = new Carbon($slot->start_date); if ($start_date->lt(Carbon::now())) { return true; } return false; }
/** * Datetime exact match check as well as between check * @param string $content * @param string $search * @param string $type * @return bool */ public function filter($content, $search, $type) { $search = is_array($search) ? $search : [$search]; $search = array_map(function ($searchValue) { return is_a($searchValue, Carbon::class) ? $searchValue : new Carbon($searchValue); }, $search); $current = new Carbon($content); switch ($type) { case 'in': return $current->gte($search[0]) && $current->lt($search[1]); break; default: return $current->eq($search[0]); } }
public function validateBeforeField($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'before_field'); $value2 = array_get($this->data, $parameters[0]); // make them Carbon dates if (!$value instanceof Carbon) { if (strtotime($value) === false) { return false; } $value = new Carbon($value); } if (!$value2 instanceof Carbon) { if (strtotime($value2) === false) { return false; } $value2 = new Carbon($value2); } return $value->lt($value2); }
public function checkPurchasability(Carbon $now = null) { $this->checkForQuantity(); if (!is_null($this->purchasable) && !$this->purchasable) { throw new NotForSaleException($this->getDesignation(), 2); } if (!is_null($this->min_purch_quantity) && $this->quantity < $this->min_purch_quantity) { throw new PurchaseQuantityException($this->getDesignation(), $this->min_purch_quantity, 1); } if (!is_null($this->max_purch_quantity) && $this->quantity > $this->max_purch_quantity) { throw new PurchaseQuantityException($this->getDesignation(), $this->max_purch_quantity, 2); } if (is_null($now)) { $now = new Carbon('now'); } if (!is_null($this->start_time) & !is_null($this->end_time)) { if (!$now->between($this->start_time, $this->end_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $this->start_time, $this->end_time, 1); } } else { if (!is_null($this->start_time) & is_null($this->end_time)) { if ($now->lt($this->start_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $this->start_time, null, 2); } } else { if (is_null($this->start_time) & !is_null($this->end_time)) { if ($now->gt($this->end_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $now, $this->end_time, 3); } } } } if ($this->isSoldOut()) { throw new NotForSaleException($this->getDesignation(), 1); } return true; }
/** * Export report to xls or pdf * @param unknown $type * @param unknown $report */ public function exportReport($type, $report, $offset = 0) { if (!in_array($type, $this->validExportTypes)) { return; } ini_set('memory_limit', '-1'); set_time_limit(0); $records = []; $columns = []; $theadRaw = ''; $rows = []; $summary = []; $header = ''; $filters = []; $previous = []; $current = []; $currentSummary = []; $previousSummary = []; $filename = 'Report'; $scr = ''; $area = ''; $prepare = ''; $fontSize = '12px'; $textSize = '12px'; $vaninventory = false; $salesSummary = false; $limit = in_array($type, ['xls', 'xlsx']) ? config('system.report_limit_xls') : config('system.report_limit_pdf'); $offset = $offset == 1 || !$offset ? 0 : $offset - 1; switch ($report) { case 'salescollectionreport': $columns = $this->getTableColumns($report, $type); $prepare = $this->getPreparedSalesCollection(); $prepare->orderBy('collection.invoice_date', 'desc'); $collection1 = $prepare->get(); $referenceNum = []; $invoiceNum = []; foreach ($collection1 as $col) { $referenceNum[] = $col->reference_num; $invoiceNum[] = $col->invoice_number; } array_unique($referenceNum); array_unique($invoiceNum); $except = $referenceNum ? ' AND tas.reference_num NOT IN(\'' . implode("','", $referenceNum) . '\') ' : ''; $except .= $invoiceNum ? ' AND coltbl.invoice_number NOT IN(\'' . implode("','", $invoiceNum) . '\') ' : ''; $prepare = $this->getPreparedSalesCollection2(false, $except); $collection2 = $prepare->get(); $collection = array_merge((array) $collection1, (array) $collection2); $current = $this->formatSalesCollection($collection); $currentSummary = []; if ($current) { $currentSummary = $this->getSalesCollectionTotal($current); } $current = array_splice($current, $offset, $limit); $hasDateFilter = false; if ($this->request->has('collection_date_from')) { $from = new Carbon($this->request->get('collection_date_from')); $endOfWeek = (new Carbon($this->request->get('collection_date_from')))->endOfWeek(); $to = new Carbon($this->request->get('collection_date_to')); $hasDateFilter = true; } if ($hasDateFilter && $from->eq($to)) { $scr = $this->request->get('salesman') . '-' . $from->format('mdY'); } elseif ($hasDateFilter && $from->lt($to) && $to->lte($endOfWeek) && $to->diffInDays($from) < 8) { $golive = new Carbon(config('system.go_live_date')); $numOfWeeks = $to->diffInWeeks($golive) + 1; $code = str_pad($numOfWeeks, 5, '0', STR_PAD_LEFT); $scr = $this->request->get('salesman') . '-' . $code; } $prepareArea = $this->getPreparedSalesmanList($this->request->get('salesman')); $resultArea = $prepareArea->first(); $area = $resultArea ? $resultArea->area_name : ''; $pdf = !in_array($type, ['xls', 'xlsx']); $rows = $this->getSalesCollectionSelectColumns($pdf); $header = 'Sales & Collection Report'; $filters = $this->getSalesCollectionFilterData(true); $filename = 'Sales & Collection Report'; $vaninventory = true; $fontSize = '7px'; break; case 'salescollectionposting': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedSalesCollectionPosting(); $collection1 = $prepare->get(); $referenceNum = []; foreach ($collection1 as $col) { $referenceNum[] = $col->reference_num; } array_unique($referenceNum); $except = $referenceNum ? ' AND tas.reference_num NOT IN(\'' . implode("','", $referenceNum) . '\') ' : ''; $prepare = $this->getPreparedSalesCollectionPosting2($except); $collection2 = $prepare->get(); $collection = array_merge((array) $collection1, (array) $collection2); $invoices = []; foreach ($collection as $col) { $invoices[] = $col->invoice_number; } sort($invoices, SORT_NATURAL); $records = []; $reference = []; foreach ($invoices as $invoice) { foreach ($collection as $col) { if (isset($col->invoice_number) && $invoice == $col->invoice_number && !in_array($col->reference_num, $reference)) { $records[] = $col; $reference[] = $col->reference_num; } } } $records = array_splice($records, $offset, $limit); $rows = $this->getSalesCollectionPostingSelectColumns(); $header = 'Sales & Collection Posting Date'; $filters = $this->getSalesCollectionFilterData(); $filename = 'Sales & Collection Posting Date Report'; $vaninventory = true; break; case 'salescollectionsummary': //$columns = $this->getTableColumns($report); $theadRaw = ' <tr> <th rowspan="2" align="center">SCR#</th> <th colspan="2" align="center">Invoice Number</th> <th rowspan="2" align="center">Invoice Date</th> <th rowspan="2" align="center" style="wrap-text:true">Total Collected Amount</th> <th rowspan="2" align="center" style="wrap-text:true">12% Sales Tax</th> <th rowspan="2" align="center" style="wrap-text:true">Amount Subject To Commission</th> </tr> <tr>'; if (in_array($type, ['xls', 'xlsx'])) { $theadRaw .= '<th align="center"></th>'; } $theadRaw .= ' <th align="center">From</th> <th align="center">To</th> </tr>'; $prepare = $this->getPreparedSalesCollectionSummary(); $rows = $this->getSalesCollectionSummarySelectColumns(); $summary = $this->getPreparedSalesCollectionSummary(true)->first(); $header = 'Monthly Summary of Sales'; $filters = $this->getSalesCollectionSummaryFilterData(); $filename = 'Monthly Summary of Sales'; $salesSummary = true; break; case 'bir': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedBir(true); $summary = $this->getPreparedBir(true, true)->first(); $rows = $this->getBirSelectColumns(); $header = 'BIR Report'; $filters = $this->getBirFilterData(); $filename = 'BIR Report'; break; case 'unpaidinvoice': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedUnpaidInvoice(); $rows = $this->getUnpaidSelectColumns(); $summary = $this->getPreparedUnpaidInvoice(true)->first(); $header = 'Unpaid Invoice Report'; $filters = $this->getUnpaidFilterData(); $filename = 'Unpaid Invoice Report'; $textSize = '14px'; $fontSize = '15px'; break; case 'vaninventorycanned': $vaninventory = true; $columns = $this->getVanInventoryColumns('canned'); $params = $this->request->all(); $from = date('Y/m/d', strtotime($params['transaction_date_from'])); $to = $params['transaction_date_to']; while (strtotime($from) <= strtotime($to)) { $params['transaction_date'] = $from; $this->request->replace($params); $from = date('Y/m/d', strtotime('+1 day', strtotime($from))); $records = array_merge($records, (array) $this->getVanInventory(true, $offset)); } $rows = $this->getVanInventorySelectColumns('canned'); $header = 'Canned & Mixes Van Inventory and History Report'; $filters = $this->getVanInventoryFilterData(); $filename = 'Van Inventory and History Report(Canned & Mixes)'; break; case 'vaninventoryfrozen': $vaninventory = true; $columns = $this->getVanInventoryColumns('frozen'); $params = $this->request->all(); $from = date('Y/m/d', strtotime($params['transaction_date_from'])); $to = $params['transaction_date_to']; while (strtotime($from) <= strtotime($to)) { $params['transaction_date'] = $from; $this->request->replace($params); $from = date('Y/m/d', strtotime('+1 day', strtotime($from))); $records = array_merge($records, (array) $this->getVanInventory(true, $offset)); } $rows = $this->getVanInventorySelectColumns('frozen'); $header = 'Frozen & Kassel Van Inventory and History Report'; $filters = $this->getVanInventoryFilterData(); $filename = 'Van Inventory and History Report(Frozen & Kassel)'; break; case 'salesreportpermaterial': $columns = $this->getTableColumns($report); $rows = $this->getSalesReportMaterialSelectColumns(); $prepare = $this->getPreparedSalesReportMaterial(); $summary = $this->getPreparedSalesReportMaterial(true)->first(); $prepare = $prepare->skip($offset)->take($limit); $records = $prepare->get(); $header = 'Sales Report Per Material'; $filters = $this->getSalesReportFilterData($report); $filename = 'Sales Report Per Material'; $fontSize = '7px'; break; case 'salesreportperpeso': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedSalesReportPeso(); $rows = $this->getSalesReportPesoSelectColumns(); $summary = $this->getPreparedSalesReportPeso(true)->first(); $header = 'Sales Report Per Peso'; $filters = $this->getSalesReportFilterData($report); $filename = 'Sales Report Per Peso'; $fontSize = '7px'; break; case 'returnpermaterial': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedReturnMaterial(); $rows = $this->getReturnReportMaterialSelectColumns(); $summary = $this->getPreparedReturnMaterial(true)->first(); $header = 'Return Per Material'; $filters = $this->getSalesReportFilterData($report); $filename = 'Return Per Material'; $fontSize = '8px'; break; case 'returnperpeso': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedReturnPeso(); $rows = $this->getReturnReportPesoSelectColumns(); $summary = $this->getPreparedReturnPeso(true)->first(); $header = 'Return Per Peso'; $filters = $this->getSalesReportFilterData($report); $filename = 'Return Per Peso'; $fontSize = '10px'; break; case 'customerlist': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedCustomerList(); $rows = $this->getCustomerSelectColumns(); $header = 'Customer List'; $filters = $this->getSalesReportFilterData($report); $filename = 'Customer List'; break; case 'salesmanlist': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedSalesmanList(); $rows = $this->getSalesmanSelectColumns(); $header = 'Salesman List'; $filters = $this->getSalesReportFilterData($report); $filename = 'Salesman List'; break; case 'materialpricelist': $columns = $this->getTableColumns($report); $prepare = $this->getPreparedMaterialPriceList(); $rows = $this->getMaterialPriceSelectColumns(); $header = 'Material Price List'; $filters = $this->getSalesReportFilterData($report); $filename = 'Material Price List'; break; default: return; } if (!$vaninventory) { if ($this->request->get('sort') && $this->request->get('order')) { $prepare->orderBy($this->request->get('sort'), $this->request->get('order')); } $prepare = $prepare->skip($offset)->take($limit); $records = $prepare->get(); if ($salesSummary) { $records = $this->populateScrInvoice($records); } } //dd($rows); //dd($filters); /* $this->view->columns = $columns; $this->view->rows = $rows; $this->view->header = $header; $this->view->theadRaw = $theadRaw; $this->view->filters = $filters; $this->view->records = $records; $this->view->summary = $summary; $this->view->previous = $previous; $this->view->scr = $scr; $this->view->previousSummary = $previousSummary; $this->view->current = $current; //dd($current); $this->view->area = $area; $this->view->currentSummary = $currentSummary; $this->view->fontSize = '7px'; return $this->view('exportSalesCollectionPdf'); */ if (empty($current)) { $records = $this->validateInvoiceNumber($records); } else { $current = $this->validateInvoiceNumber($current); } if (in_array($type, ['xls', 'xlsx'])) { \Excel::create($filename, function ($excel) use($columns, $rows, $records, $summary, $header, $filters, $theadRaw, $report, $current, $currentSummary, $previous, $previousSummary, $scr, $area) { $excel->sheet('Sheet1', function ($sheet) use($columns, $rows, $records, $summary, $header, $filters, $theadRaw, $report, $current, $currentSummary, $previous, $previousSummary, $scr, $area) { if ($report == 'bir') { foreach ($records as &$record) { $sheet->setColumnFormat(['A' => 'MM/DD/YYYY']); $record->document_date = PHPExcel_Shared_Date::PHPToExcel(strtotime($record->document_date)); } } elseif ($report == 'salescollectionreport') { $sheet->setColumnFormat(['X' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT, 'V' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT, 'R' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT, 'J' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT, 'D' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT]); } elseif ($report == 'salescollectionposting') { $sheet->setColumnFormat(['J' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT, 'F' => \PHPExcel_Style_NumberFormat::FORMAT_TEXT]); } $params['columns'] = $columns; $params['theadRaw'] = $theadRaw; $params['rows'] = $rows; $params['records'] = $records; $params['summary'] = $summary; $params['header'] = $header; $params['scr'] = $scr; $params['filters'] = $filters; $params['current'] = $current; $params['previous'] = $previous; $params['currentSummary'] = $currentSummary; $params['previousSummary'] = $previousSummary; $params['area'] = $area; $params['report'] = $report; $view = $report == 'salescollectionreport' ? 'exportSalesCollection' : 'exportXls'; $sheet->loadView('Reports.' . $view, $params); }); })->export($type); } elseif ($type == 'pdf') { $params['columns'] = $columns; $params['theadRaw'] = $theadRaw; $params['rows'] = $rows; $params['records'] = $records; $params['summary'] = $summary; $params['header'] = $header; $params['scr'] = $scr; $params['filters'] = $filters; $params['fontSize'] = $fontSize; $params['textSize'] = $textSize; $params['current'] = $current; $params['previous'] = $previous; $params['currentSummary'] = $currentSummary; $params['previousSummary'] = $previousSummary; $params['area'] = $area; $params['report'] = $report; $view = $report == 'salescollectionreport' ? 'exportSalesCollectionPdf' : 'exportPdf'; if ($report == 'salescollectionsummary') { $pdf = \PDF::loadView('Reports.' . $view, $params)->setOrientation('portrait'); } else { $pdf = \PDF::loadView('Reports.' . $view, $params); } unset($params, $records, $prepare); return $pdf->download($filename . '.pdf'); } }
public function contains(Carbon $date_time) { return $date_time->gt($this->after) && $date_time->lt($this->before); }
public function getRaidTuesdayCountdown() { if (Carbon::now('America/Chicago')->isSameDay(new Carbon('Tuesday 4am CST', 'America/Chicago'))) { $raidtuesday = new Carbon('Tuesday 4am CST', 'America/Chicago'); } else { $raidtuesday = new Carbon('next Tuesday 4 AM', 'America/Chicago'); } if ($raidtuesday->lt(Carbon::now('America/Chicago'))) { return \Response::json(['error' => false, 'msg' => 'Today is Raid Tuesday! Get your raids in!']); } else { $countdown = $raidtuesday->diffInSeconds(Carbon::now('America/Chicago')); $countdown = Text::timeDuration($countdown); return \Response::json(['error' => false, 'msg' => $countdown]); } }
/** * @return bool */ public function needsRefresh() { return $this->dateExpires->lt(Carbon::now()); }
private function getMinDiff(Carbon $time1, Carbon $time2) { if ($time2->lt($time1)) { // if timeout is less than breakout $time2->addDay(); } // add 1 day return $time2->diffInMinutes($time1); }