mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-01 20:17:35 -04:00 
			
		
		
		
	Working on discounts
This commit is contained in:
		
							parent
							
								
									5aed73a43f
								
							
						
					
					
						commit
						bbb0e07eca
					
				| @ -7,6 +7,7 @@ use DateTime; | ||||
| use Event; | ||||
| use Cache; | ||||
| use App; | ||||
| use Carbon; | ||||
| use App\Events\UserSettingsChanged; | ||||
| use Illuminate\Support\Facades\Storage; | ||||
| use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| @ -1395,7 +1396,7 @@ class Account extends Eloquent | ||||
|             $date = date_create(); | ||||
|         } | ||||
| 
 | ||||
|         return $date->format('Y-m-d'); | ||||
|         return Carbon::instance($date); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -54,13 +54,15 @@ class Company extends Eloquent | ||||
|     } | ||||
| 
 | ||||
|     // handle promos and discounts
 | ||||
|     public function hasActiveDiscount() | ||||
|     public function hasActiveDiscount(Carbon $date = null) | ||||
|     { | ||||
|         if ( ! $this->discount) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         return $this->discount_expires && $this->discount_expires->gt(Carbon::today()); | ||||
|         $date = $date ?: Carbon::today(); | ||||
| 
 | ||||
|         return $this->discount_expires && $this->discount_expires->gt($date); | ||||
|     } | ||||
| 
 | ||||
|     public function discountedPrice($price) | ||||
|  | ||||
| @ -278,7 +278,9 @@ class AccountRepository | ||||
| 
 | ||||
|         $account = $this->getNinjaAccount(); | ||||
|         $lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first(); | ||||
|         $renewalDate = $clientAccount->getRenewalDate(); | ||||
|         $publicId = $lastInvoice ? ($lastInvoice->public_id + 1) : 1; | ||||
| 
 | ||||
|         $invoice = new Invoice(); | ||||
|         $invoice->is_public = true; | ||||
|         $invoice->account_id = $account->id; | ||||
| @ -286,13 +288,13 @@ class AccountRepository | ||||
|         $invoice->public_id = $publicId; | ||||
|         $invoice->client_id = $client->id; | ||||
|         $invoice->invoice_number = $account->getNextInvoiceNumber($invoice); | ||||
|         $invoice->invoice_date = $clientAccount->getRenewalDate(); | ||||
|         $invoice->invoice_date = $renewalDate->format('Y-m-d'); | ||||
|         $invoice->amount = $invoice->balance = $plan_cost - $credit; | ||||
|         $invoice->invoice_type_id = INVOICE_TYPE_STANDARD; | ||||
| 
 | ||||
|         // check for promo/discount
 | ||||
|         $clientCompany = $clientAccount->company; | ||||
|         if ($clientCompany->hasActivePromo() || $clientCompany->hasActiveDiscount()) { | ||||
|         if ($clientCompany->hasActivePromo() || $clientCompany->hasActiveDiscount($renewalDate)) { | ||||
|             $discount = $invoice->amount * $clientCompany->discount; | ||||
|             $invoice->discount = $clientCompany->discount * 100; | ||||
|             $invoice->amount -= $discount; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user