public function testSaveDelete() { RoyaltyProvider::truncate(); $rp = new RoyaltyProvider(); $rp->royalty_provider_name = "testname"; $rp->save(); $this->assertTrue($rp->id != 0); $this->assertTrue($rp->created != null); $this->assertTrue($rp->updated != null); // $this->assertTrue($rp["deleted"] == 0); $rp->delete(); $this->assertTrue($rp->deleted == 1); RoyaltyProvider::truncate(); }
public static function boot() { parent::boot(); RoyaltyProvider::deleting(function ($royaltyProvider) { $royaltyProvider->deleted = 1; $royaltyProvider->update(); }); }
public function run() { DB::table('royalty_providers')->truncate(); RoyaltyProvider::create(['id' => '2', 'name' => 'BMI', 'etl_upload_location' => '/var/home/royalty/pentaho/TheRoyaltyExchange/ETL-PUB/Files/BMIPublisher', 'etl_command' => '/var/home/royalty/pentaho/design-tools/data-integration/kitchen-wrapper-bmi-pub.sh> /dev/null 2>/dev/null &']); RoyaltyProvider::create(['id' => '3', 'name' => 'ASCAP - International', 'etl_upload_location' => '/var/home/royalty/pentaho/TheRoyaltyExchange/ETL-PUB/Files/ASCAP/International', 'etl_command' => '/var/home/royalty/pentaho/design-tools/data-integration/kitchen-wrapper-ascap-international-pub.sh> /dev/null 2>/dev/null &']); RoyaltyProvider::create(['id' => '48', 'name' => 'SESAC', 'etl_upload_location' => '/var/home/royalty/pentaho/TheRoyaltyExchange/ETL-PUB/Files/SESAC', 'etl_command' => '/var/home/royalty/pentaho/design-tools/data-integration/kitchen-wrapper-sesac-pub.sh> /dev/null 2>/dev/null &']); RoyaltyProvider::create(['id' => '50', 'name' => 'ASCAP - Domestic', 'etl_upload_location' => '/var/home/royalty/pentaho/TheRoyaltyExchange/ETL-PUB/Files/ASCAP/Domestic', 'etl_command' => '/var/home/royalty/pentaho/design-tools/data-integration/kitchen-wrapper-ascap-domestic-pub.sh> /dev/null 2>/dev/null &']); RoyaltyProvider::create(['id' => '54', 'name' => 'The Orchard', 'etl_upload_location' => '/var/home/royalty/pentaho/TheRoyaltyExchange/ETL-PUB/Files/Orchard', 'etl_command' => '/var/home/royalty/pentaho/design-tools/data-integration/kitchen-wrapper-orchard-pub.sh> /dev/null 2>/dev/null &']); }
protected function processFile($filename, $metadata, $fileList, $deal, $path) { $monthToQuarter = [1 => 1, 2 => 1, 3 => 1, 4 => 2, 5 => 2, 6 => 2, 7 => 3, 8 => 3, 9 => 3, 10 => 4, 11 => 4, 12 => 4]; $this->log("Processing file {$filename}"); $csvFilename = sprintf('%s/%s.csv', $path, $filename); if ($this->fileExists($fileList, $csvFilename)) { /* * MESSAGE LEFT ON 4/14/15 * For Ascap International and Domestic providers the files come together, meaning in the same processing * directory, we have Ascap International and Domestic files. We check the file name to see if contains * the word international or domestic and we execute etl with the correct provider. */ $processingProviderId = $metadata['provider']; if ($processingProviderId == 3 && strpos($filename, 'Domestic') !== false) { $processingProviderId = 50; } if ($processingProviderId == 50 && strpos($filename, 'International') !== false) { $processingProviderId = 3; } $royaltyProvider = RoyaltyProvider::find($processingProviderId); $csvContent = $this->dropboxReadFile($csvFilename); $this->log('File size is ' . strlen($csvContent)); $etlFolder = $royaltyProvider->php_etl_upload_location; if (!is_dir($etlFolder)) { $this->log("Create upload folder {$etlFolder}"); mkdir($etlFolder, 0755, true); mkdir($etlFolder . '/LogFiles', 0755); mkdir($etlFolder . '/Processed', 0755); } $etlFile = sprintf('%s/%d_%s.csv', $etlFolder, $deal->id, $filename); $this->log("Writing {$etlFile}"); file_put_contents($etlFile, $csvContent); $month = $metadata['month']; if (empty($month)) { $month = $this->quarterToMonth((int) $metadata['quarter']); $periodType = RoyaltyStreamFile::PERIOD_TYPE_QUARTER; } $quarter = $metadata['quarter']; if (empty($quarter)) { $quarter = $monthToQuarter[(int) $metadata['month']]; $periodType = RoyaltyStreamFile::PERIOD_TYPE_MONTH; } $periodYearQuarter = sprintf('%dQ%d', $metadata['year'], $quarter); $hasPdf = false; if ($metadata['hasPdf']) { $pdfFilename = sprintf('%s/%s.pdf', $path, $filename); if ($this->fileExists($fileList, $pdfFilename)) { $contents = $this->dropboxReadFile($pdfFilename); $pdfFolder = storage_path('pdf'); $pdfFile = sprintf('%s/%d_%s.pdf', $pdfFolder, $deal->id, $filename); $this->log("Saving PDF to {$pdfFile}"); file_put_contents($pdfFile, $contents); $hasPdf = true; } } $share = isset($metadata['providerRoyaltyShare']) ? $metadata['providerRoyaltyShare'] : 1; $accountName = isset($metadata["providerAccountName"]) ? $metadata["providerAccountName"] : null; $rsf = RoyaltyStreamFile::create(['deal_id' => $deal->id, 'stream_file_name' => $etlFile, 'status' => 0, 'period_year' => $metadata['year'], 'period_month' => $month, 'period_quarter' => $quarter, 'company_id' => $deal->company_id, 'royalty_provider_id' => $processingProviderId, 'royalty_type_id' => $metadata['providerRoyaltyType'], 'royalty_share_id' => $share, 'period_type' => $periodType, 'period_year_quarter' => $periodYearQuarter, 'account_name' => $accountName, 'has_pdf' => $hasPdf]); $this->log("saved royalty stream file " . $rsf->id); $etlCommand = $royaltyProvider->php_etl_command . ' publisher ' . $royaltyProvider->id . ' "' . $etlFile . '"'; $this->log("Executing {$etlCommand}"); exec($etlCommand, $output, $status); $this->log('Output: ' . print_r($output, true)); $this->log("Status: {$status}"); $this->log("Delete etl file: {$etlFile}"); unlink($etlFile); if ($output[0] != "finished") { throw new Exception("Processing failed for command: " . $etlCommand . " with output: " . $output[0]); } } }
public static function apiProviders($id) { $query = self::query(); return $query->select('royalty_provider.id as id', 'royalty_provider.royalty_provider_name as provider', 'royalty_share.royalty_share_name as share', 'royalty_type.royalty_type_name as type')->join(RoyaltyStreamFile::table() . " as royalty_stream_file", 'royalty_stream_file.deal_id', '=', 'deal_id')->join(RoyaltyProvider::table() . " as royalty_provider", 'royalty_provider.id', '=', 'royalty_provider_id')->join(RoyaltyShare::table() . " as royalty_share", 'royalty_share.id', '=', 'royalty_share_id')->join(RoyaltyType::table() . " as royalty_type", 'royalty_type.id', '=', 'royalty_type_id')->groupBy('royalty_provider.royalty_provider_name', 'royalty_share.royalty_share_name', 'royalty_type.royalty_type_name')->where('deal_id', $id)->get(); }