public function saveAttachment($file_name, $data) { //$f = explode(PHP_EOL, $data); $EdiReader = new EDI\Reader($data); //read & save data $terminal = $EdiReader->readEdiDataValue('UNB', 2); $message_ref_number = $EdiReader->readEdiDataValue('UNH', 1); $prepare_date = $EdiReader->readEdiDataValue('UNB', 4, 0); $prepare_time = $EdiReader->readEdiDataValue('UNB', 4, 1); $prepare_datetime = preg_replace('#(\\d\\d)(\\d\\d)(\\d\\d)#', '20$1-$2-$3', $prepare_date) . ' ' . preg_replace('#(\\d\\d)(\\d\\d)#', '$1:$2', $prepare_time); if (empty($terminal)) { echo 'Error: Terminal empty' . PHP_EOL; echo $data; return false; } if (empty($message_ref_number)) { echo 'Error: Numberl empty' . PHP_EOL; echo $data; return false; } echo ' Terminal:' . $terminal . PHP_EOL; echo ' Number:' . $EdiReader->readEdiDataValue('UNH', 1) . PHP_EOL; $criteria = new CDbCriteria(); $criteria->compare('message_ref_number', $message_ref_number)->compare('terminal', $terminal); if (Edifact::model()->find($criteria)) { return false; } echo ' Save' . PHP_EOL; $edifact = new Edifact(); $edifact->terminal = $terminal; $edifact->message_ref_number = $message_ref_number; $edifact->prep_datetime = $prepare_datetime; $edifact->filename = $file_name; $edifact->message = $data; if (!$edifact->save()) { var_dump($edifact->errors); return false; } $this->readEdiData($edifact->id); echo ' OK' . PHP_EOL; }
public function __construct($url = null) { parent::__construct($url); }