public function index() { $provinceids = Branch::where('isheadquarter', true)->distinct()->lists('provinceid'); $provinces = Province::whereIn('id', $provinceids)->orderBy('name', 'asc')->get(['id', 'name']); $provinceselectlist = array(); array_push($provinceselectlist, ':เลือกจังหวัด'); foreach ($provinces as $item) { array_push($provinceselectlist, $item->id . ':' . $item->name); } $carmodels = CarModel::orderBy('name', 'asc')->get(['id', 'name']); $carmodelselectlist = array(); array_push($carmodelselectlist, ':เลือกแบบ'); foreach ($carmodels as $item) { array_push($carmodelselectlist, $item->id . ':' . $item->name); } $carsubmodelids = Car::distinct()->lists('carsubmodelid'); $carsubmodels = CarSubModel::whereIn('id', $carsubmodelids)->orderBy('name', 'asc')->get(['id', 'name']); $carsubmodelselectlist = array(); array_push($carsubmodelselectlist, ':เลือกรุ่น'); foreach ($carsubmodels as $item) { array_push($carsubmodelselectlist, $item->id . ':' . $item->name); } $colorids = Car::distinct()->lists('colorid'); $colors = Color::whereIn('id', $colorids)->orderBy('code', 'asc')->get(['id', 'code', 'name']); $colorselectlist = array(); array_push($colorselectlist, ':เลือกสี'); foreach ($colors as $item) { array_push($colorselectlist, $item->id . ':' . $item->code . ' - ' . $item->name); } $defaultProvince = ''; if (Auth::user()->isadmin == false) { $defaultProvince = Auth::user()->branchid == null ? '' : Auth::user()->branch->provinceid; } return view('car', ['provinceselectlist' => implode(";", $provinceselectlist), 'carmodelselectlist' => implode(";", $carmodelselectlist), 'carsubmodelselectlist' => implode(";", $carsubmodelselectlist), 'colorselectlist' => implode(";", $colorselectlist), 'defaultProvince' => $defaultProvince]); }
public function check_headquarter(Request $request) { $input = $request->only('id', 'provinceid'); $count = Branch::where('id', '!=', $input['id'])->where('provinceid', $input['provinceid'])->where('isheadquarter', true)->count(); if ($count > 0) { return "true"; } }
public static function boot() { parent::boot(); static::creating(function ($model) { $model->issold = false; $model->isregistered = false; $model->isdelivered = false; $model->dodate = date('Y-m-d', strtotime($model->dodate)); $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate)); $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); $rs = DB::select('call running_number("' . $model->provinceid . date("Y") . '","' . $model->receivetype . '")'); $model->no = $rs[0]->no; $min = KeySlot::where('provinceid', $model->provinceid)->where('active', true)->min('no'); if ($min == null) { $branch = Branch::where('provinceid', $model->provinceid)->where('isheadquarter', true)->first(); $branch->keyslot = $branch->keyslot + 1; $branch->save(); $model->keyno = $branch->keyslot; } else { $model->keyno = $min; } $model->save(); KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => false]); }); static::updating(function ($model) { $model->dodate = date('Y-m-d', strtotime($model->dodate)); $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate)); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->receivecarfilepath != '') { File::delete(public_path() . $model->receivecarfilepath); } if ($model->deliverycarfilepath != '') { File::delete(public_path() . $model->deliverycarfilepath); } KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => true]); }); }
public function todayTopSales(Carbon $date, $limit = 10) { $arr = []; $ds_null = false; $current_day_zero_sales = false; $ds = DailySales::where('date', $date->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get(); if (count($ds) == '0') { $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get(); $ds_null = true; } else { foreach ($ds as $d) { if ($d->sales == '0.00') { $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get(); $ds_null = true; continue; } } } foreach ($ds as $d) { $branch = Branch::where('id', $d->branchid)->get(['code', 'descriptor', 'id'])->first(); if ($ds_null) { $ds_today = new DailySales(); $ds_yesteday = $d; } else { $ds_today = $d; $ds_yesteday = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->where('branchid', $d->branchid)->first(); } $ds_otherday = DailySales::where('date', $date->copy()->subDay(2)->format('Y-m-d'))->where('branchid', $d->branchid)->first(); $s = new StdClass(); $c = new StdClass(); $s->branch = $branch; $s->today = $ds_today; $s->yesterday = $ds_yesteday; $s->otherday = $ds_otherday; $c->sales = $ds_today->sales - $ds_yesteday->sales; $s->today->sign = $this->getSign($ds_today->sales - $ds_yesteday->sales); $c->sales1 = $ds_yesteday->sales - $ds_otherday->sales; $s->yesterday->sign = $this->getSign($ds_yesteday->sales - $ds_otherday->sales); $s->diff = $c; array_push($arr, $s); } return collect($arr); }
public function check_headquarter(Request $request) { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } $input = $request->only('id', 'provinceid'); $count = Branch::where('id', '!=', $input['id'])->where('provinceid', $input['provinceid'])->where('isheadquarter', true)->count(); if ($count > 0) { return "true"; } }
public function importDBFs($br) { //(Request $request){ $logfile = base_path() . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'db-import.txt'; //return Employee::with('childrens')->get(); $import = true; if ($import) { $db = dbase_open('D:\\GI\\' . $br . '\\GC113015\\PAY_MAST.DBF', 0); } else { $db = dbase_open('D:\\GI\\MAR\\GC113015\\PAY_MAST.DBF', 0); } if ($db) { $header = dbase_get_header_info($db); if (!$import) { echo '<table cellpadding="2" cellspacing="0" border="1"><thead>'; } // render table header if (!$import) { echo '<tr>'; foreach ($header as $key => $value) { echo '<th>' . $value['name'] . '</th>'; } echo '</tr>'; } // render table body $children_ctr = 0; $ecperson_ctr = 0; $education_ctr = 0; $work_ctr = 0; $spouse_ctr = 0; $record_numbers = dbase_numrecords($db); for ($i = 1; $i <= $record_numbers; $i++) { $row = dbase_get_record_with_names($db, $i); if ($i == 1) { $brcode = trim($row['BRANCH']); } if ($import) { $e = Employee::where('code', trim($row['MAN_NO']))->first(); if (!is_null($e)) { continue; } } $employee = new Employee(); $employee->code = trim($row['MAN_NO']); $employee->lastname = trim($row['LAST_NAM']); $employee->firstname = trim($row['FIRS_NAM']); $employee->middlename = trim($row['MIDL_NAM']); $employee->companyid = trim($this->getCompanyId($row['CO_NAME'])); $employee->id = $employee->get_uid(); $branch = Branch::where('code', trim($row['BRANCH']))->first(); $employee->branchid = is_null($branch) ? '' : $branch->id; $employee->deptid = $this->getDeptId($row['DEPT']); $employee->positionid = $this->getPositionId(trim($row['POSITION'])); $employee->paytype = 2; $employee->ratetype = 2; $employee->rate = trim($row['RATE_HR']); $employee->ecola = trim($row['RATE_HR']); $employee->allowance1 = trim($row['ALW1_RATE']); $employee->allowance2 = trim($row['ALW2_RATE']); $employee->phicno = trim($row['PHEALTH_NO']); $employee->hdmfno = trim($row['PBIG_NO']); $employee->tin = trim($row['WTAX_NO']); $employee->sssno = trim($row['SSS_NO']); $employee->empstatus = $this->getEmpstatus(trim($row['EMP_STUS'])); $employee->datestart = Carbon::parse(trim($row['STARTED'])); //$employee->datehired = trim($row['ALW2_RATE']); //$employee->datestop = trim($row['ALW2_RATE']); $employee->punching = 1; $employee->processing = 1; $employee->address = trim($row['ADDRESS1']) . ', ' . trim($row['ADDRESS2']) . ', ' . trim($row['ADDRESS3']); $employee->phone = trim($row['TEL']); //$employee->fax = trim($row['TEL']); $employee->mobile = trim($row['CEL']); $employee->email = trim($row['EMAIL']); $employee->gender = trim($row['SEX']) == 'M' ? 1 : 2; $employee->civstatus = trim($row['CIV_STUS']) == 'SINGLE' ? 1 : 2; $employee->height = str_replace("'", '.', trim($row['HEIGHT'])); $employee->weight = trim($row['WEIGHT']); $employee->birthdate = Carbon::parse(trim($row['BIRTHDATE'])); $employee->birthplace = trim($row['BIRTHPLC']); $employee->religionid = trim($this->getReligionId($row['RELIGION'])); $employee->hobby = trim($row['HOBBIES']); $employee->notes = 'UNIFORM:' . trim($row['UNIFORM']) . '; ' . 'SP_NOTES1:' . trim($row['SP_NOTES1']) . '; ' . 'SP_NOTES2:' . trim($row['SP_NOTES2']) . '; '; $childrens = []; if (!empty(trim($row['CHILDREN1'])) && trim($row['CHILDREN1']) != 'N/A') { $c1 = new Children(); $c1->firstname = trim($row['CHILDREN1']); $c1->lastname = $employee->lastname; $c1->id = $c1->get_uid(); array_push($childrens, $c1); $children_ctr++; } if (!empty(trim($row['CHILDREN2'])) && trim($row['CHILDREN2']) != 'N/A') { $c2 = new Children(); $c2->firstname = trim($row['CHILDREN2']); $c2->lastname = $employee->lastname; $c2->id = $c2->get_uid(); array_push($childrens, $c2); $children_ctr++; } if ($import) { $employee->childrens()->saveMany($childrens); } if (!empty(trim($row['EMER_NAM'])) && trim($row['EMER_NAM']) != 'N/A') { $emer = explode(' ', trim($row['EMER_NAM'])); $e = new Ecperson(); $e->firstname = empty($emer[0]) ? '' : $emer[0]; $e->lastname = empty($emer[1]) ? '' : $emer[1]; $e->mobile = trim($row['EMER_NO']); $e->id = $e->get_uid(); $ecperson_ctr++; if ($import) { $employee->ecperson()->save($e); } } if (!empty(trim($row['EDUCATION'])) && trim($row['EDUCATION']) != 'N/A') { $edu = new Education(); $edu->school = trim($row['EDUCATION']); $edu->id = $edu->get_uid(); if ($import) { $employee->educations()->saveMany([$edu]); } $education_ctr++; } $works = []; if (!empty(trim($row['WORKHIST1'])) && trim($row['WORKHIST1']) != 'N/A') { $w1 = new Workexp(); $w1->company = trim($row['WORKHIST1']); $w1->id = $w1->get_uid(); array_push($works, $w1); $work_ctr++; } if (!empty(trim($row['WORKHIST2'])) && trim($row['WORKHIST2']) != 'N/A') { $w2 = new Workexp(); $w2->company = trim($row['WORKHIST2']); $w2->id = $w2->get_uid(); array_push($works, $w2); $work_ctr++; } if (!empty(trim($row['WORKHIST3'])) && trim($row['WORKHIST3']) != 'N/A') { $w3 = new Workexp(); $w3->company = trim($row['WORKHIST3']); $w3->id = $w3->get_uid(); array_push($works, $w3); $work_ctr++; } if (!empty(trim($row['WORKHIST4'])) && trim($row['WORKHIST4']) != 'N/A') { $w4 = new Workexp(); $w4->company = trim($row['WORKHIST2']); $w4->id = $w4->get_uid(); array_push($works, $w4); $work_ctr++; } if ($import) { $employee->workexps()->saveMany($works); } if (!empty(trim($row['SPOUS_NAM'])) && trim($row['SPOUS_NAM']) != 'N/A' && trim($row['SPOUS_NAM']) != 'NA/A') { $sp = preg_split("/\\s+(?=\\S*+\$)/", trim($row['SPOUS_NAM'])); $spou = new Spouse(); $spou->firstname = empty($sp[0]) ? '' : $sp[0]; $spou->lastname = empty($sp[1]) ? '' : $sp[1]; $spou->id = $spou->get_uid(); $spouse_ctr++; if ($import) { $employee->spouse()->save($spou); } } if ($import) { $employee->save(); } if (!$import) { echo '<tr>'; foreach ($header as $key => $value) { //if($value['name']=='CO_NAME') //echo '<td>'.$this->getCompanyId($row[$value['name']]).'</td>'; //else echo '<td>' . $row[$value['name']] . '</td>'; } echo '</tr>'; } } if ($import) { echo $brcode . ' imported! </br>'; $handle = fopen($logfile, 'a'); $content = $brcode . "\n\temployee:\t\t" . $record_numbers . "\n"; $content .= "\tspouse:\t\t\t" . $spouse_ctr . "\n"; $content .= "\tchildren:\t\t" . $children_ctr . "\n"; $content .= "\tecperson:\t\t" . $ecperson_ctr . "\n"; $content .= "\tworkexp:\t\t" . $work_ctr . "\n"; fwrite($handle, $content); fclose($handle); } dbase_close($db); } }
public static function getFirstBranchOfBusiness($business_id) { return Branch::where('business_id', '=', $business_id)->first(); }
public static function createBusinessNewTerminal($business_id, $name) { $first_branch = Branch::where('business_id', '=', $business_id)->first(); $first_service = Service::where('branch_id', '=', $first_branch->branch_id)->first(); $terminal = new Terminal(); $terminal->name = $name; $terminal->service_id = $first_service->service_id; $terminal->status = 1; $terminal->box_rank = Terminal::generateBoxRank($first_service->service_id); // Added by PAG $terminal->save(); }