Created
January 4, 2021 18:04
-
-
Save jongravois/646d077fb4248f5b2613acca45af2f99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Pipes\Invoices; | |
use App\Models\PostedInvoice; | |
use App\Models\Project; | |
use Closure; | |
class FixedRateProfit | |
{ | |
public function handle(PostedInvoice $invoice, Closure $next) | |
{ | |
$project = Project::whereLotCode($invoice->consignment_code)->first(); | |
if(isset($project)) { | |
if($project->fixed) { | |
$invoice->update([ | |
'gp_percent_used' => $project->current_rate, | |
'profit' => $invoice->net * $project->current_rate, | |
'split_bands' => false, | |
'processed' => true | |
]); | |
$project->update([ | |
'current_gross' => $project->current_gross + $invoice->gross, | |
'current_net' => $project->current_net + $invoice->net, | |
]); | |
} // end if | |
} else { | |
//TODO NOTIFY | |
} // end if | |
return $next($invoice); | |
} // end function | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment