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); } }