sap 流程

public function csm_voucher_issue_actions( $date )
     {
          $table_name = $this->sap_interface_create_table( $date );
         
          $this->csm_voucher_normal_actions_issuance( $date, $table_name );
          //If the issuance transaction is due to voucher replacement, this field (Replaced voucher) will be marked with 'X'.
          $this->csm_voucher_update_is_replaced($date, $table_name);
          $this->csm_voucher_normal_actions_unissue( $date, $table_name );
          $this->tenant_voucher_normal_actions_issuance( $date, $table_name );
          $this->tenant_voucher_normal_actions_unissue( $date, $table_name );
    
         
         
          $rt = $this->sap_interface_get_results($table_name);
         
          $transaction_date = date('Ymd', strtotime($date . ' 00:00:00'));
          $file_name = 'CSM_ISS_' . $transaction_date;
          return $this->_ftp_to_sap($file_name, $rt);
     }



private function _ftp_to_sap( $file_name, $data )
     {
          $file_name = $file_name . '.csv';
          $local_file = $this->_sap_interface_local_file_name($file_name);
          $remote_file = $this->_sap_interface_remote_file_name($file_name);
         
          //made a copy of the file if existed. so we will be able to trace files.
          if( file_exists($local_file) )
          {
               rename($local_file, $local_file . '.time.' . date ("Ymd_His", filemtime($local_file)) );
          }
         
          $this->_export_sap_interface_file($local_file, $data);
         
          return $this->_ftp_upload($local_file, $remote_file);
     }


private function _ftp_upload($local_file, $remote_file)
     {
          //ilog('SAP Interface, uploading local file: ' . $local_file . ' to remote file: ' . $remote_file);
          $this->load->helper('email');
          if(!file_exists($local_file))
          {
               $error_msg = 'SAP Interface ERROR: cannot find local file: ' . $local_file;
               evo_email_admin( $error_msg );
               elog($error_msg);
          }
         
          if($this->_ftp_really_upload)
          {
               $ftp_result = $this->ftp->upload($local_file, $remote_file);
          }
          else
          {
               $ftp_result = TRUE;
          }
         
          if( !$ftp_result )
          {
               $error_msg = 'SAP Interface ERROR: cannot upload local file: ' . $local_file . ' to remote file: ' . $remote_file;
               evo_email_admin( $error_msg );
             elog($error_msg);
          }
         
          return $ftp_result;
     }