示例#1
0
 public function postDailySales()
 {
     $dbf_file = $this->extracted_path . DS . 'CSH_AUDT.DBF';
     if (file_exists($dbf_file)) {
         $db = dbase_open($dbf_file, 0);
         $header = dbase_get_header_info($db);
         $record_numbers = dbase_numrecords($db);
         $last_ds = $this->ds->lastRecord();
         $update = 0;
         for ($i = 1; $i <= $record_numbers; $i++) {
             $row = dbase_get_record_with_names($db, $i);
             $vfpdate = vfpdate_to_carbon(trim($row['TRANDATE']));
             if (is_null($last_ds)) {
                 $attrs = ['date' => $vfpdate->format('Y-m-d'), 'branchid' => session('user.branchid'), 'managerid' => session('user.id'), 'sales' => $row['CSH_SALE'] + $row['CHG_SALE'], 'tips' => $row['TIP'], 'custcount' => $row['CUST_CNT'], 'empcount' => $row['CREW_KIT'] + $row['CREW_DIN']];
                 if ($this->ds->firstOrNew($attrs, ['date', 'branchid'])) {
                 }
                 $update++;
             } else {
                 if ($last_ds->date->lte($vfpdate)) {
                     $attrs = ['date' => $vfpdate->format('Y-m-d'), 'branchid' => session('user.branchid'), 'managerid' => session('user.id'), 'sales' => $row['CSH_SALE'] + $row['CHG_SALE'], 'tips' => $row['TIP'], 'custcount' => $row['CUST_CNT'], 'empcount' => $row['CREW_KIT'] + $row['CREW_DIN']];
                     if ($this->ds->firstOrNew($attrs, ['date', 'branchid'])) {
                     }
                     $update++;
                 }
             }
         }
         dbase_close($db);
         return count($update > 0) ? true : false;
     }
     return false;
 }
示例#2
0
 function __construct($url_dbf)
 {
     $this->url = $url_dbf;
     // Abrir un el archivo dbase
     $this->dbf = dbase_open($this->url, 0) or die("¡Error! No se pudo abrir el archivo de base de datos dbase '{$this->url}'.");
     // Inicializo valores
     $this->info_columna = dbase_get_header_info($this->dbf);
     $this->set_campos();
     $this->set_nombre_tabla();
     $this->set_campos_array();
 }
示例#3
0
function GetFieldList($AHandle)
{
    $vHeader = dbase_get_header_info($AHandle);
    $vResult = array();
    if (is_array($vHeader)) {
        foreach ($vHeader as $vFD) {
            $vResult[] = strtoupper($vFD['name']);
        }
    }
    return $vResult;
}
function volcarDBF($db = "ctw10005")
{
    $results = array();
    $mFile = $db . date("Ymd") . ".txt";
    //Abrir el Archivo para Escribir
    $TFile = fopen(PATH_TMP . $mFile, "a");
    $pathdbase = CTW_PATH . vLITERAL_SEPARATOR . $db . ".dbf";
    //$db = dbase_open($ipdbase . $dirdbase . $nombredb . $db, 0);
    $rs = dbase_open($pathdbase, 0);
    //echo $pathdbase;
    $results[SYS_MSG] .= "Abrir {$pathdbase} <br />";
    $num_rows = dbase_numrecords($rs);
    //$o_num_rows = dbase_numrecords ($rs);
    if ($num_rows > 100000) {
        //$num_rows = 100000;				//Eliminar la Consulta a 50000
    }
    $results[SYS_MSG] .= "Numero de Filas {$num_rows} <br />";
    if (isset($rs)) {
        $results[SYS_MSG] .= "Cerrando " . dbase_get_header_info($rs) . " <br />";
        for ($i = 1; $i <= $num_rows; $i++) {
            //$field = dbase_get_record_with_names($rs, $i);
            $field = dbase_get_record($rs, $i);
            $lim = sizeof($field);
            $strW = "";
            for ($a = 0; $a < $lim; $a++) {
                if ($a == 0) {
                    $strW .= trim($field[$a]);
                } else {
                    $strW .= STD_LITERAL_DIVISOR . trim($field[$a]);
                }
            }
            $strW .= "\n";
            @fwrite($TFile, $strW);
            //if (dbase_delete_record ($rs, $i)) {
            // print "Registro $i Marcado para Eliminar de un total de $o_num_rows; se Busco $field[$key]. <br >";
            //break; # Exit the loop
            //}
        }
    } else {
        //dbase_get_header_info($rs);
    }
    //dbase_pack($rs);
    //$results[SYS_MSG] .= " <br />";
    dbase_close($rs);
    $results[SYS_MSG] .= "Cerrando {$pathdbase} <br />";
    fclose($TFile);
    $results[SYS_MSG] .= "Cerrando {$mFile} <br />";
    return $results;
}
示例#5
0
文件: dbf.php 项目: xiaoyjy/retry
 public function load_dbf($filename, $mode = 0)
 {
     if (!file_exists($filename)) {
         return cy_dt(CYE_ERROR, 'Not a valid DBF file!');
     }
     $tail = substr($filename, -4);
     if (strcasecmp($tail, '.dbf') != 0) {
         return cy_dt(CYE_ERROR, 'Not a valid DBF file!');
     }
     try {
         $this->_handler = dbase_open($filename, $mode);
     } catch (Exception $e) {
         echo $e->getMessage();
         return cy_dt(CYE_ERROR, 'open DBF file failed!');
     }
     $this->field_num = dbase_numfields($this->_handler);
     $this->rec_num = dbase_numrecords($this->_handler);
     $this->field_names = dbase_get_header_info($this->_handler);
     return cy_dt(0);
 }
示例#6
0
 /**
  * Returns information about the current database
  *
  * @param mixed $result  THIS IS UNUSED IN DBASE.  The current database
  *                       is examined regardless of what is provided here.
  * @param int   $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A DB_Error object on failure.
  *
  * @see DB_common::tableInfo()
  * @since Method available since Release 1.7.0
  */
 function tableInfo($result = null, $mode = null)
 {
     if (function_exists('dbase_get_header_info')) {
         $id = @dbase_get_header_info($this->connection);
         if (!$id && $php_errormsg) {
             return $this->raiseError(DB_ERROR, null, null, null, $php_errormsg);
         }
     } else {
         /*
          * This segment for PHP 4 is loosely based on code by
          * Hadi Rusiah <*****@*****.**> in the comments on
          * the dBase reference page in the PHP manual.
          */
         $db = @fopen($this->dsn['database'], 'r');
         if (!$db) {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg);
         }
         $id = array();
         $i = 0;
         $line = fread($db, 32);
         while (!feof($db)) {
             $line = fread($db, 32);
             if (substr($line, 0, 1) == chr(13)) {
                 break;
             } else {
                 $pos = strpos(substr($line, 0, 10), chr(0));
                 $pos = $pos == 0 ? 10 : $pos;
                 $id[$i] = array('name' => substr($line, 0, $pos), 'type' => $this->types[substr($line, 11, 1)], 'length' => ord(substr($line, 16, 1)), 'precision' => ord(substr($line, 17, 1)));
             }
             $i++;
         }
         fclose($db);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $res = array();
     $count = count($id);
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => $this->dsn['database'], 'name' => $case_func($id[$i]['name']), 'type' => $id[$i]['type'], 'len' => $id[$i]['length'], 'flags' => '');
         if ($mode & DB_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & DB_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
示例#7
0
<?php

$tbl = "inc";
$db_uname = 'root';
$db_passwd = 'enachi59';
$db = 'car';
$conn = mysql_pconnect('localhost', $db_uname, $db_passwd);
// Path to dbase file
$db_path = "inc.dbf";
// Open dbase file
$dbh = dbase_open($db_path, 0) or die("Error! Could not open dbase database file '{$db_path}'.");
// Get column information
$column_info = dbase_get_header_info($dbh);
// Display information
//print_r($column_info);
$line = array();
foreach ($column_info as $col) {
    switch ($col['type']) {
        case 'character':
            $line[] = "`{$col['name']}` VARCHAR( {$col['length']} )";
            break;
        case 'number':
            $line[] = "`{$col['name']}` FLOAT";
            break;
        case 'boolean':
            $line[] = "`{$col['name']}` BOOL";
            break;
        case 'date':
            $line[] = "`{$col['name']}` DATE";
            break;
        case 'memo':
示例#8
0
 public function getColunasInfo()
 {
     return dbase_get_header_info($this->conexao);
 }
示例#9
0
 public function header_info()
 {
     $this->header_info = dbase_get_header_info($this->db);
     return $this->header_info;
 }
示例#10
0
 private function _setHeader()
 {
     $this->_header = dbase_get_header_info($this->_fp);
 }
示例#11
0
文件: dbf2csv.cli.php 项目: rhrn/php
<?php

$db = false;
if (!empty($argc)) {
    $file = end($argv);
    $db = dbase_open($file, 0);
}
if ($db) {
    $iconvFrom = '866';
    $iconvTo = 'UTF-8';
    $delimetr = ',';
    $info = dbase_get_header_info($db);
    $fields = dbase_numfields($db);
    $fieldsCount = sizeof($fields);
    $records = dbase_numrecords($db);
    //for ($i = 1; $i <= 10; $i++) { # test
    for ($i = 1; $i <= $records; $i++) {
        $row = dbase_get_record($db, $i);
        $line = array();
        for ($j = 0; $j < $fields; $j++) {
            $line[] = addslashes(iconv($iconvFrom, $iconvTo, trim($row[$j])));
        }
        echo implode($delimetr, $line);
        echo PHP_EOL;
    }
    dbase_close($db);
}
示例#12
0
 /**
  * Controller action to build the page that allows the user to choose which field is to be
  * used for the location name, and optionally for the name of the parent location.
  * A lot of this is stolen from the csv upload code.
  */
 public function upload_shp()
 {
     $sizelimit = kohana::config('indicia.maxUploadSize');
     $_FILES = Validation::factory($_FILES)->add_rules('zip_upload', 'upload::valid', 'upload::required', 'upload::type[zip]', "upload::size[{$sizelimit}]");
     if ($_FILES->validate()) {
         // move the file to the standard upload directory
         $zipTempFile = upload::save('zip_upload');
         $_SESSION['uploaded_zip'] = $zipTempFile;
         // Following helps for files from Macs
         ini_set('auto_detect_line_endings', 1);
         $view = new View('location/upload_shp');
         $zip = new ZipArchive();
         $res = $zip->open($zipTempFile);
         if ($res != TRUE) {
             $this->setError('Upload file problem', 'Could not open Zip archive file - possible invalid format.');
             return;
         }
         $directory = $this->create_zip_extract_dir();
         if ($directory == false) {
             return;
         }
         if (!$zip->extractTo($directory)) {
             $this->setError('Upload file problem', 'Could not extract Zip archive file contents.');
             return;
         }
         $entry = '';
         $dbf = 0;
         $shp = 0;
         for ($i = 0; $i < $zip->numFiles; $i++) {
             if (basename($zip->getNameIndex($i)) != basename($zip->getNameIndex($i), '.dbf')) {
                 $entry = $zip->getNameIndex($i);
                 $dbf++;
             }
             if (basename($zip->getNameIndex($i)) != basename($zip->getNameIndex($i), '.shp')) {
                 $shpentry = $zip->getNameIndex($i);
                 $shp++;
             }
         }
         if ($shp == 0) {
             $this->setError('Upload file problem', 'Zip archive file does not contain a file with a .shp extension.');
             return;
         }
         if ($shp > 1) {
             $this->setError('Upload file problem', 'Zip archive file contains more than one file with a .shp extension.');
             return;
         }
         if ($dbf == 0) {
             $this->setError('Upload file problem', 'Zip archive file does not contain a file with a .dbf extension.');
             return;
         }
         if ($dbf > 1) {
             $this->setError('Upload file problem', 'Zip archive file contains more than one file with a .dbf extension.');
             return;
         }
         if (basename($entry, '.dbf') != basename($shpentry, '.shp')) {
             $this->setError('Upload file problem', '.dbf and .shp files in Zip archive have different names.');
             return;
         }
         $_SESSION['extracted_basefile'] = $directory . '/' . basename($entry, '.dbf');
         $zip->close();
         $this->template->title = "Choose details in " . $entry . " for " . $this->pagetitle;
         $dbasedb = dbase_open($directory . '/' . $entry, 0);
         if ($dbasedb) {
             // read some data ..
             $view->columns = dbase_get_header_info($dbasedb);
             dbase_close($dbasedb);
         } else {
             $this->setError('Upload file problem', 'Could not open ' . $entry . ' from Zip archive.');
             return;
         }
         $view->model = $this->model;
         $view->controllerpath = $this->controllerpath;
         $this->template->content = $view;
         // Setup a breadcrumb
         $this->page_breadcrumbs[] = html::anchor($this->model->object_name, $this->pagetitle);
         $this->page_breadcrumbs[] = 'Setup SHP File upload';
     } else {
         $errors = $_FILES->errors();
         $error = '';
         foreach ($errors as $key => $val) {
             switch ($val) {
                 case 'required':
                     $error .= 'You must specify a Zip Archive file to upload, containing the .shp and .dbf files.<br/>';
                     break;
                 case 'valid':
                     $error .= 'The uploaded file is not valid.<br/>';
                     break;
                 case 'type':
                     $error .= 'The uploaded file is not a zip file. The Shapefile should be uploaded in a Zip Archive file, which should also contain the .dbf file containing the data for each record.<br/>';
                     break;
                 case 'size':
                     $error .= 'The upload file is greater than the limit of ' . $sizelimit . 'b.<br/>';
                     break;
                 default:
                     $error .= 'An unknown error occurred when checking the upload file.<br/>';
             }
         }
         // TODO: error message needs a back button.
         $this->setError('Upload file problem', $error);
     }
 }
示例#13
0
    for ($i = 0; $i < $nf; $i++) {
        echo $rec[$i], "\n";
    }
    dbase_close($db);
}
echo 'end. Trying to create db...';
$def = array(array("date", "D"), array("name", "C", 50), array("age", "N", 3, 0), array("email", "C", 128), array("ismember", "L"));
// creation
$db = dbase_create('/home/a writeable directory/test.dbf', $def);
if (!$db) {
    echo "Error, can't create the database\n";
} else {
    echo 'hi numrecords is: ';
    echo dbase_numrecords($db);
    echo '\\r\\n Heres the header info:';
    print_r(dbase_get_header_info($db));
    echo 'number of records: ';
    echo dbase_numrecords($db);
    echo 'inserting row...';
    dbase_add_record($db, array(date('Ymd'), 'Maxim Topolov', '23', '*****@*****.**', 'T'));
    echo 'finished inserting. number of records: ';
    echo dbase_numrecords($db);
    echo 'trying record num 1: ';
    $rec = dbase_get_record($db, 1);
    $nf = dbase_numfields($db);
    for ($i = 0; $i < $nf; $i++) {
        echo $rec[$i], "\n";
    }
    dbase_add_record($db, array(date('Ymd'), 'Maxi2222m Topolov', '23', '*****@*****.**', 'T'));
    echo 'updating a row...';
    // gets the old row
示例#14
0
 function baca_dbf()
 {
     $filez = './uploads/urut.DBF';
     $dbf = dbase_open($filez, 0);
     $column_info = dbase_get_header_info($dbf);
     $loop = dbase_numrecords($dbf);
     for ($i = 1; $i <= $loop; $i++) {
         $row = dbase_get_record_with_names($dbf, $i);
         $data = array("nik" => $row['ID'], "mchID" => $row['IDABS']);
         $this->db->insert("mchID", $data);
         //echo $row['ID']."/".$row['IDABS']."<br>";
     }
     die;
 }
示例#15
0
 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 function postPurchased2(Carbon $date, Backup $backup)
 {
     $dbf_file = $this->extracted_path . DS . 'PURCHASE.DBF';
     //$this->logAction($date->format('Y-m-d'),'post:purchased:file_exists');
     if (file_exists($dbf_file)) {
         $db = dbase_open($dbf_file, 0);
         $header = dbase_get_header_info($db);
         $record_numbers = dbase_numrecords($db);
         $tot_purchase = 0;
         $update = 0;
         // delete if exist
         try {
             //$this->logAction($date->format('Y-m-d'), 'delete:purchased');
             $this->purchase->deleteWhere(['branchid' => $backup->branchid, 'date' => $date->format('Y-m-d')]);
         } catch (Exception $e) {
             dbase_close($db);
             throw new Exception($e->getMessage());
         }
         try {
             //$this->logAction($date->format('Y-m-d'), 'delete:purchased2');
             $this->purchase2->deleteWhere(['branchid' => $backup->branchid, 'date' => $date->format('Y-m-d')]);
         } catch (Exception $e) {
             dbase_close($db);
             throw new Exception($e->getMessage());
         }
         //$this->logAction($date->format('Y-m-d'), 'start:loop:purchased');
         for ($i = 1; $i <= $record_numbers; $i++) {
             $row = dbase_get_record_with_names($db, $i);
             $vfpdate = vfpdate_to_carbon(trim($row['PODATE']));
             if ($vfpdate->format('Y-m-d') == $date->format('Y-m-d')) {
                 //$this->logAction($vfpdate->format('Y-m-d'), trim($row['COMP']), base_path().DS.'logs'.DS.'GLV'.DS.$vfpdate->format('Y-m-d').'-PO.txt');
                 $tcost = trim($row['TCOST']);
                 $attrs = ['comp' => trim($row['COMP']), 'unit' => trim($row['UNIT']), 'qty' => trim($row['QTY']), 'ucost' => trim($row['UCOST']), 'tcost' => $tcost, 'date' => $vfpdate->format('Y-m-d'), 'supno' => trim($row['SUPNO']), 'supname' => trim($row['SUPNAME']), 'catname' => trim($row['CATNAME']), 'vat' => trim($row['VAT']), 'terms' => trim($row['TERMS']), 'branchid' => $backup->branchid];
                 //\DB::beginTransaction();
                 //$this->logAction($date->format('Y-m-d'), 'create:purchased');
                 try {
                     $this->purchase->create($attrs);
                 } catch (Exception $e) {
                     dbase_close($db);
                     throw new Exception($e->getMessage());
                 }
                 try {
                     //$this->logAction($date->format('Y-m-d'), 'create:purchased2');
                     $this->purchase2->verifyAndCreate($attrs);
                 } catch (Exception $e) {
                     dbase_close($db);
                     throw new Exception($e->getMessage());
                 }
                 //\DB::rollBack();
                 $tot_purchase += $tcost;
                 $update++;
             }
         }
         //$this->logAction($date->format('Y-m-d'), 'end:loop:purchased');
         try {
             //$this->logAction($date->format('Y-m-d'), 'update:ds');
             $this->ds->firstOrNew(['branchid' => $backup->branchid, 'date' => $date->format('Y-m-d'), 'purchcost' => $tot_purchase], ['date', 'branchid']);
         } catch (Exception $e) {
             dbase_close($db);
             throw new Exception($e->getMessage());
         }
         dbase_close($db);
         return count($update > 0) ? true : false;
     }
     return false;
 }