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