Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created January 4, 2021 18:04
Show Gist options
  • Save jongravois/646d077fb4248f5b2613acca45af2f99 to your computer and use it in GitHub Desktop.
Save jongravois/646d077fb4248f5b2613acca45af2f99 to your computer and use it in GitHub Desktop.
<?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