mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-11 15:34:21 -04:00
Prevent converting a qoute from incrementing the counter
This commit is contained in:
parent
2c56c4e7bf
commit
1760d0e0e4
@ -18,7 +18,7 @@ class Account extends Eloquent
|
|||||||
{
|
{
|
||||||
use PresentableTrait;
|
use PresentableTrait;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
public static $plan_prices = array(
|
public static $plan_prices = array(
|
||||||
PLAN_PRO => array(
|
PLAN_PRO => array(
|
||||||
PLAN_TERM_MONTHLY => PLAN_PRICE_PRO_MONTHLY,
|
PLAN_TERM_MONTHLY => PLAN_PRICE_PRO_MONTHLY,
|
||||||
@ -388,7 +388,7 @@ class Account extends Eloquent
|
|||||||
return $gateway;
|
return $gateway;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,27 +408,27 @@ class Account extends Eloquent
|
|||||||
if($this->logo == ''){
|
if($this->logo == ''){
|
||||||
$this->calculateLogoDetails();
|
$this->calculateLogoDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
return !empty($this->logo);
|
return !empty($this->logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoDisk(){
|
public function getLogoDisk(){
|
||||||
return Storage::disk(env('LOGO_FILESYSTEM', 'logos'));
|
return Storage::disk(env('LOGO_FILESYSTEM', 'logos'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function calculateLogoDetails(){
|
protected function calculateLogoDetails(){
|
||||||
$disk = $this->getLogoDisk();
|
$disk = $this->getLogoDisk();
|
||||||
|
|
||||||
if($disk->exists($this->account_key.'.png')){
|
if($disk->exists($this->account_key.'.png')){
|
||||||
$this->logo = $this->account_key.'.png';
|
$this->logo = $this->account_key.'.png';
|
||||||
} else if($disk->exists($this->account_key.'.jpg')) {
|
} else if($disk->exists($this->account_key.'.jpg')) {
|
||||||
$this->logo = $this->account_key.'.jpg';
|
$this->logo = $this->account_key.'.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($this->logo)){
|
if(!empty($this->logo)){
|
||||||
$image = imagecreatefromstring($disk->get($this->logo));
|
$image = imagecreatefromstring($disk->get($this->logo));
|
||||||
$this->logo_width = imagesx($image);
|
$this->logo_width = imagesx($image);
|
||||||
$this->logo_height = imagesy($image);
|
$this->logo_height = imagesy($image);
|
||||||
$this->logo_size = $disk->size($this->logo);
|
$this->logo_size = $disk->size($this->logo);
|
||||||
} else {
|
} else {
|
||||||
$this->logo = null;
|
$this->logo = null;
|
||||||
@ -440,33 +440,33 @@ class Account extends Eloquent
|
|||||||
if(!$this->hasLogo()){
|
if(!$this->hasLogo()){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$disk = $this->getLogoDisk();
|
$disk = $this->getLogoDisk();
|
||||||
return $disk->get($this->logo);
|
return $disk->get($this->logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoURL($cachebuster = false)
|
public function getLogoURL($cachebuster = false)
|
||||||
{
|
{
|
||||||
if(!$this->hasLogo()){
|
if(!$this->hasLogo()){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$disk = $this->getLogoDisk();
|
$disk = $this->getLogoDisk();
|
||||||
$adapter = $disk->getAdapter();
|
$adapter = $disk->getAdapter();
|
||||||
|
|
||||||
if($adapter instanceof \League\Flysystem\Adapter\Local) {
|
if($adapter instanceof \League\Flysystem\Adapter\Local) {
|
||||||
// Stored locally
|
// Stored locally
|
||||||
$logo_url = str_replace(public_path(), url('/'), $adapter->applyPathPrefix($this->logo), $count);
|
$logo_url = str_replace(public_path(), url('/'), $adapter->applyPathPrefix($this->logo), $count);
|
||||||
|
|
||||||
if ($cachebuster) {
|
if ($cachebuster) {
|
||||||
$logo_url .= '?no_cache='.time();
|
$logo_url .= '?no_cache='.time();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($count == 1){
|
if($count == 1){
|
||||||
return str_replace(DIRECTORY_SEPARATOR, '/', $logo_url);
|
return str_replace(DIRECTORY_SEPARATOR, '/', $logo_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Document::getDirectFileUrl($this->logo, $this->getLogoDisk());
|
return Document::getDirectFileUrl($this->logo, $this->getLogoDisk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +516,7 @@ class Account extends Eloquent
|
|||||||
$invoice->start_date = Utils::today();
|
$invoice->start_date = Utils::today();
|
||||||
$invoice->invoice_design_id = $this->invoice_design_id;
|
$invoice->invoice_design_id = $this->invoice_design_id;
|
||||||
$invoice->client_id = $clientId;
|
$invoice->client_id = $clientId;
|
||||||
|
|
||||||
if ($entityType === ENTITY_RECURRING_INVOICE) {
|
if ($entityType === ENTITY_RECURRING_INVOICE) {
|
||||||
$invoice->invoice_number = microtime(true);
|
$invoice->invoice_number = microtime(true);
|
||||||
$invoice->is_recurring = true;
|
$invoice->is_recurring = true;
|
||||||
@ -531,7 +531,7 @@ class Account extends Eloquent
|
|||||||
$invoice->invoice_number = $this->getNextInvoiceNumber($invoice);
|
$invoice->invoice_number = $this->getNextInvoiceNumber($invoice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$clientId) {
|
if (!$clientId) {
|
||||||
$invoice->client = Client::createNew();
|
$invoice->client = Client::createNew();
|
||||||
$invoice->client->public_id = 0;
|
$invoice->client->public_id = 0;
|
||||||
@ -561,7 +561,7 @@ class Account extends Eloquent
|
|||||||
public function hasClientNumberPattern($invoice)
|
public function hasClientNumberPattern($invoice)
|
||||||
{
|
{
|
||||||
$pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern;
|
$pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern;
|
||||||
|
|
||||||
return strstr($pattern, '$custom');
|
return strstr($pattern, '$custom');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,31 +633,35 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function getNextInvoiceNumber($invoice)
|
public function getNextInvoiceNumber($invoice)
|
||||||
{
|
{
|
||||||
if ($this->hasNumberPattern($invoice->is_quote)) {
|
if ($this->hasNumberPattern($invoice->invoice_type_id)) {
|
||||||
return $this->getNumberPattern($invoice);
|
$number = $this->getNumberPattern($invoice);
|
||||||
|
} else {
|
||||||
|
$counter = $this->getCounter($invoice->invoice_type_id);
|
||||||
|
$prefix = $this->getNumberPrefix($invoice->invoice_type_id);
|
||||||
|
$counterOffset = 0;
|
||||||
|
|
||||||
|
// confirm the invoice number isn't already taken
|
||||||
|
do {
|
||||||
|
$number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT);
|
||||||
|
$check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first();
|
||||||
|
$counter++;
|
||||||
|
$counterOffset++;
|
||||||
|
} while ($check);
|
||||||
|
|
||||||
|
// update the invoice counter to be caught up
|
||||||
|
if ($counterOffset > 1) {
|
||||||
|
if ($invoice->isType(INVOICE_TYPE_QUOTE) && !$this->share_counter) {
|
||||||
|
$this->quote_number_counter += $counterOffset - 1;
|
||||||
|
} else {
|
||||||
|
$this->invoice_number_counter += $counterOffset - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$counter = $this->getCounter($invoice->is_quote);
|
if ($invoice->recurring_invoice_id) {
|
||||||
$prefix = $this->getNumberPrefix($invoice->is_quote);
|
$number = $this->recurring_invoice_number_prefix . $number;
|
||||||
$counterOffset = 0;
|
|
||||||
|
|
||||||
// confirm the invoice number isn't already taken
|
|
||||||
do {
|
|
||||||
$number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT);
|
|
||||||
$check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first();
|
|
||||||
$counter++;
|
|
||||||
$counterOffset++;
|
|
||||||
} while ($check);
|
|
||||||
|
|
||||||
// update the invoice counter to be caught up
|
|
||||||
if ($counterOffset > 1) {
|
|
||||||
if ($invoice->is_quote && !$this->share_counter) {
|
|
||||||
$this->quote_number_counter += $counterOffset - 1;
|
|
||||||
} else {
|
|
||||||
$this->invoice_number_counter += $counterOffset - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $number;
|
return $number;
|
||||||
@ -665,19 +669,17 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function incrementCounter($invoice)
|
public function incrementCounter($invoice)
|
||||||
{
|
{
|
||||||
if ($invoice->is_quote && !$this->share_counter) {
|
// if they didn't use the counter don't increment it
|
||||||
|
if ($invoice->invoice_number != $this->getNextInvoiceNumber($invoice)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($invoice->isType(INVOICE_TYPE_QUOTE) && !$this->share_counter) {
|
||||||
$this->quote_number_counter += 1;
|
$this->quote_number_counter += 1;
|
||||||
} else {
|
} else {
|
||||||
$default = $this->invoice_number_counter;
|
$this->invoice_number_counter += 1;
|
||||||
$actual = Utils::parseInt($invoice->invoice_number);
|
|
||||||
|
|
||||||
if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS) && $default != $actual) {
|
|
||||||
$this->invoice_number_counter = $actual + 1;
|
|
||||||
} else {
|
|
||||||
$this->invoice_number_counter += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,7 +702,7 @@ class Account extends Eloquent
|
|||||||
$query->where('updated_at', '>=', $updatedAt);
|
$query->where('updated_at', '>=', $updatedAt);
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadLocalizationSettings($client = false)
|
public function loadLocalizationSettings($client = false)
|
||||||
@ -713,8 +715,8 @@ class Account extends Eloquent
|
|||||||
Session::put(SESSION_DATE_FORMAT, $this->date_format ? $this->date_format->format : DEFAULT_DATE_FORMAT);
|
Session::put(SESSION_DATE_FORMAT, $this->date_format ? $this->date_format->format : DEFAULT_DATE_FORMAT);
|
||||||
Session::put(SESSION_DATE_PICKER_FORMAT, $this->date_format ? $this->date_format->picker_format : DEFAULT_DATE_PICKER_FORMAT);
|
Session::put(SESSION_DATE_PICKER_FORMAT, $this->date_format ? $this->date_format->picker_format : DEFAULT_DATE_PICKER_FORMAT);
|
||||||
|
|
||||||
$currencyId = ($client && $client->currency_id) ? $client->currency_id : $this->currency_id ?: DEFAULT_CURRENCY;
|
$currencyId = ($client && $client->currency_id) ? $client->currency_id : $this->currency_id ?: DEFAULT_CURRENCY;
|
||||||
$locale = ($client && $client->language_id) ? $client->language->locale : ($this->language_id ? $this->Language->locale : DEFAULT_LOCALE);
|
$locale = ($client && $client->language_id) ? $client->language->locale : ($this->language_id ? $this->Language->locale : DEFAULT_LOCALE);
|
||||||
|
|
||||||
Session::put(SESSION_CURRENCY, $currencyId);
|
Session::put(SESSION_CURRENCY, $currencyId);
|
||||||
Session::put(SESSION_LOCALE, $locale);
|
Session::put(SESSION_LOCALE, $locale);
|
||||||
@ -797,7 +799,7 @@ class Account extends Eloquent
|
|||||||
if ( ! Utils::isNinja()) {
|
if ( ! Utils::isNinja()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->company->trial_plan = $plan;
|
$this->company->trial_plan = $plan;
|
||||||
$this->company->trial_started = date_create()->format('Y-m-d');
|
$this->company->trial_started = date_create()->format('Y-m-d');
|
||||||
$this->company->save();
|
$this->company->save();
|
||||||
@ -808,18 +810,18 @@ class Account extends Eloquent
|
|||||||
if (Utils::isNinjaDev()) {
|
if (Utils::isNinjaDev()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$planDetails = $this->getPlanDetails();
|
$planDetails = $this->getPlanDetails();
|
||||||
$selfHost = !Utils::isNinjaProd();
|
$selfHost = !Utils::isNinjaProd();
|
||||||
|
|
||||||
if (!$selfHost && function_exists('ninja_account_features')) {
|
if (!$selfHost && function_exists('ninja_account_features')) {
|
||||||
$result = ninja_account_features($this, $feature);
|
$result = ninja_account_features($this, $feature);
|
||||||
|
|
||||||
if ($result != null) {
|
if ($result != null) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($feature) {
|
switch ($feature) {
|
||||||
// Pro
|
// Pro
|
||||||
case FEATURE_CUSTOMIZE_INVOICE_DESIGN:
|
case FEATURE_CUSTOMIZE_INVOICE_DESIGN:
|
||||||
@ -836,7 +838,7 @@ class Account extends Eloquent
|
|||||||
case FEATURE_CLIENT_PORTAL_PASSWORD:
|
case FEATURE_CLIENT_PORTAL_PASSWORD:
|
||||||
case FEATURE_CUSTOM_URL:
|
case FEATURE_CUSTOM_URL:
|
||||||
return $selfHost || !empty($planDetails);
|
return $selfHost || !empty($planDetails);
|
||||||
|
|
||||||
// Pro; No trial allowed, unless they're trialing enterprise with an active pro plan
|
// Pro; No trial allowed, unless they're trialing enterprise with an active pro plan
|
||||||
case FEATURE_MORE_CLIENTS:
|
case FEATURE_MORE_CLIENTS:
|
||||||
return $selfHost || !empty($planDetails) && (!$planDetails['trial'] || !empty($this->getPlanDetails(false, false)));
|
return $selfHost || !empty($planDetails) && (!$planDetails['trial'] || !empty($this->getPlanDetails(false, false)));
|
||||||
@ -849,26 +851,26 @@ class Account extends Eloquent
|
|||||||
// Fallthrough
|
// Fallthrough
|
||||||
case FEATURE_CLIENT_PORTAL_CSS:
|
case FEATURE_CLIENT_PORTAL_CSS:
|
||||||
return !empty($planDetails);// A plan is required even for self-hosted users
|
return !empty($planDetails);// A plan is required even for self-hosted users
|
||||||
|
|
||||||
// Enterprise; No Trial allowed; grandfathered for old pro users
|
// Enterprise; No Trial allowed; grandfathered for old pro users
|
||||||
case FEATURE_USERS:// Grandfathered for old Pro users
|
case FEATURE_USERS:// Grandfathered for old Pro users
|
||||||
if($planDetails && $planDetails['trial']) {
|
if($planDetails && $planDetails['trial']) {
|
||||||
// Do they have a non-trial plan?
|
// Do they have a non-trial plan?
|
||||||
$planDetails = $this->getPlanDetails(false, false);
|
$planDetails = $this->getPlanDetails(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $selfHost || !empty($planDetails) && ($planDetails['plan'] == PLAN_ENTERPRISE || $planDetails['started'] <= date_create(PRO_USERS_GRANDFATHER_DEADLINE));
|
return $selfHost || !empty($planDetails) && ($planDetails['plan'] == PLAN_ENTERPRISE || $planDetails['started'] <= date_create(PRO_USERS_GRANDFATHER_DEADLINE));
|
||||||
|
|
||||||
// Enterprise; No Trial allowed
|
// Enterprise; No Trial allowed
|
||||||
case FEATURE_DOCUMENTS:
|
case FEATURE_DOCUMENTS:
|
||||||
case FEATURE_USER_PERMISSIONS:
|
case FEATURE_USER_PERMISSIONS:
|
||||||
return $selfHost || !empty($planDetails) && $planDetails['plan'] == PLAN_ENTERPRISE && !$planDetails['trial'];
|
return $selfHost || !empty($planDetails) && $planDetails['plan'] == PLAN_ENTERPRISE && !$planDetails['trial'];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPro(&$plan_details = null)
|
public function isPro(&$plan_details = null)
|
||||||
{
|
{
|
||||||
if (!Utils::isNinjaProd()) {
|
if (!Utils::isNinjaProd()) {
|
||||||
@ -880,7 +882,7 @@ class Account extends Eloquent
|
|||||||
}
|
}
|
||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return !empty($plan_details);
|
return !empty($plan_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -895,36 +897,36 @@ class Account extends Eloquent
|
|||||||
}
|
}
|
||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return $plan_details && $plan_details['plan'] == PLAN_ENTERPRISE;
|
return $plan_details && $plan_details['plan'] == PLAN_ENTERPRISE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlanDetails($include_inactive = false, $include_trial = true)
|
public function getPlanDetails($include_inactive = false, $include_trial = true)
|
||||||
{
|
{
|
||||||
if (!$this->company) {
|
if (!$this->company) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plan = $this->company->plan;
|
$plan = $this->company->plan;
|
||||||
$trial_plan = $this->company->trial_plan;
|
$trial_plan = $this->company->trial_plan;
|
||||||
|
|
||||||
if(!$plan && (!$trial_plan || !$include_trial)) {
|
if(!$plan && (!$trial_plan || !$include_trial)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$trial_active = false;
|
$trial_active = false;
|
||||||
if ($trial_plan && $include_trial) {
|
if ($trial_plan && $include_trial) {
|
||||||
$trial_started = DateTime::createFromFormat('Y-m-d', $this->company->trial_started);
|
$trial_started = DateTime::createFromFormat('Y-m-d', $this->company->trial_started);
|
||||||
$trial_expires = clone $trial_started;
|
$trial_expires = clone $trial_started;
|
||||||
$trial_expires->modify('+2 weeks');
|
$trial_expires->modify('+2 weeks');
|
||||||
|
|
||||||
if ($trial_expires >= date_create()) {
|
if ($trial_expires >= date_create()) {
|
||||||
$trial_active = true;
|
$trial_active = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$plan_active = false;
|
$plan_active = false;
|
||||||
if ($plan) {
|
if ($plan) {
|
||||||
if ($this->company->plan_expires == null) {
|
if ($this->company->plan_expires == null) {
|
||||||
$plan_active = true;
|
$plan_active = true;
|
||||||
$plan_expires = false;
|
$plan_expires = false;
|
||||||
@ -935,11 +937,11 @@ class Account extends Eloquent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$include_inactive && !$plan_active && !$trial_active) {
|
if (!$include_inactive && !$plan_active && !$trial_active) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should we show plan details or trial details?
|
// Should we show plan details or trial details?
|
||||||
if (($plan && !$trial_plan) || !$include_trial) {
|
if (($plan && !$trial_plan) || !$include_trial) {
|
||||||
$use_plan = true;
|
$use_plan = true;
|
||||||
@ -966,7 +968,7 @@ class Account extends Eloquent
|
|||||||
$use_plan = $plan_expires >= $trial_expires;
|
$use_plan = $plan_expires >= $trial_expires;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($use_plan) {
|
if ($use_plan) {
|
||||||
return array(
|
return array(
|
||||||
'trial' => false,
|
'trial' => false,
|
||||||
@ -993,7 +995,7 @@ class Account extends Eloquent
|
|||||||
if (!Utils::isNinjaProd()) {
|
if (!Utils::isNinjaProd()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return $plan_details && $plan_details['trial'];
|
return $plan_details && $plan_details['trial'];
|
||||||
@ -1008,7 +1010,7 @@ class Account extends Eloquent
|
|||||||
return array(PLAN_PRO, PLAN_ENTERPRISE);
|
return array(PLAN_PRO, PLAN_ENTERPRISE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->company->trial_plan == PLAN_PRO) {
|
if ($this->company->trial_plan == PLAN_PRO) {
|
||||||
if ($plan) {
|
if ($plan) {
|
||||||
return $plan != PLAN_PRO;
|
return $plan != PLAN_PRO;
|
||||||
@ -1016,28 +1018,28 @@ class Account extends Eloquent
|
|||||||
return array(PLAN_ENTERPRISE);
|
return array(PLAN_ENTERPRISE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCountTrialDaysLeft()
|
public function getCountTrialDaysLeft()
|
||||||
{
|
{
|
||||||
$planDetails = $this->getPlanDetails(true);
|
$planDetails = $this->getPlanDetails(true);
|
||||||
|
|
||||||
if(!$planDetails || !$planDetails['trial']) {
|
if(!$planDetails || !$planDetails['trial']) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$today = new DateTime('now');
|
$today = new DateTime('now');
|
||||||
$interval = $today->diff($planDetails['expires']);
|
$interval = $today->diff($planDetails['expires']);
|
||||||
|
|
||||||
return $interval ? $interval->d : 0;
|
return $interval ? $interval->d : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRenewalDate()
|
public function getRenewalDate()
|
||||||
{
|
{
|
||||||
$planDetails = $this->getPlanDetails();
|
$planDetails = $this->getPlanDetails();
|
||||||
|
|
||||||
if ($planDetails) {
|
if ($planDetails) {
|
||||||
$date = $planDetails['expires'];
|
$date = $planDetails['expires'];
|
||||||
$date = max($date, date_create());
|
$date = max($date, date_create());
|
||||||
@ -1167,7 +1169,7 @@ class Account extends Eloquent
|
|||||||
$field = "email_template_{$entityType}";
|
$field = "email_template_{$entityType}";
|
||||||
$template = $this->$field;
|
$template = $this->$field;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$template) {
|
if (!$template) {
|
||||||
$template = $this->getDefaultEmailTemplate($entityType, $message);
|
$template = $this->getDefaultEmailTemplate($entityType, $message);
|
||||||
}
|
}
|
||||||
@ -1236,7 +1238,7 @@ class Account extends Eloquent
|
|||||||
{
|
{
|
||||||
$url = SITE_URL;
|
$url = SITE_URL;
|
||||||
$iframe_url = $this->iframe_url;
|
$iframe_url = $this->iframe_url;
|
||||||
|
|
||||||
if ($iframe_url) {
|
if ($iframe_url) {
|
||||||
return "{$iframe_url}/?";
|
return "{$iframe_url}/?";
|
||||||
} else if ($this->subdomain) {
|
} else if ($this->subdomain) {
|
||||||
@ -1271,10 +1273,10 @@ class Account extends Eloquent
|
|||||||
if (!$entity) {
|
if (!$entity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert (for example) 'custom_invoice_label1' to 'invoice.custom_value1'
|
// convert (for example) 'custom_invoice_label1' to 'invoice.custom_value1'
|
||||||
$field = str_replace(['invoice_', 'label'], ['', 'value'], $field);
|
$field = str_replace(['invoice_', 'label'], ['', 'value'], $field);
|
||||||
|
|
||||||
return Utils::isEmpty($entity->$field) ? false : true;
|
return Utils::isEmpty($entity->$field) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1282,7 +1284,7 @@ class Account extends Eloquent
|
|||||||
{
|
{
|
||||||
return $this->hasFeature(FEATURE_PDF_ATTACHMENT) && $this->pdf_email_attachment;
|
return $this->hasFeature(FEATURE_PDF_ATTACHMENT) && $this->pdf_email_attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEmailDesignId()
|
public function getEmailDesignId()
|
||||||
{
|
{
|
||||||
return $this->hasFeature(FEATURE_CUSTOM_EMAILS) ? $this->email_design_id : EMAIL_DESIGN_PLAIN;
|
return $this->hasFeature(FEATURE_CUSTOM_EMAILS) ? $this->email_design_id : EMAIL_DESIGN_PLAIN;
|
||||||
@ -1290,11 +1292,11 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function clientViewCSS(){
|
public function clientViewCSS(){
|
||||||
$css = '';
|
$css = '';
|
||||||
|
|
||||||
if ($this->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN)) {
|
if ($this->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN)) {
|
||||||
$bodyFont = $this->getBodyFontCss();
|
$bodyFont = $this->getBodyFontCss();
|
||||||
$headerFont = $this->getHeaderFontCss();
|
$headerFont = $this->getHeaderFontCss();
|
||||||
|
|
||||||
$css = 'body{'.$bodyFont.'}';
|
$css = 'body{'.$bodyFont.'}';
|
||||||
if ($headerFont != $bodyFont) {
|
if ($headerFont != $bodyFont) {
|
||||||
$css .= 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{'.$headerFont.'}';
|
$css .= 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{'.$headerFont.'}';
|
||||||
@ -1304,17 +1306,17 @@ class Account extends Eloquent
|
|||||||
// For self-hosted users, a white-label license is required for custom CSS
|
// For self-hosted users, a white-label license is required for custom CSS
|
||||||
$css .= $this->client_view_css;
|
$css .= $this->client_view_css;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $css;
|
return $css;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFontsUrl($protocol = ''){
|
public function getFontsUrl($protocol = ''){
|
||||||
$bodyFont = $this->getHeaderFontId();
|
$bodyFont = $this->getHeaderFontId();
|
||||||
$headerFont = $this->getBodyFontId();
|
$headerFont = $this->getBodyFontId();
|
||||||
|
|
||||||
$bodyFontSettings = Utils::getFromCache($bodyFont, 'fonts');
|
$bodyFontSettings = Utils::getFromCache($bodyFont, 'fonts');
|
||||||
$google_fonts = array($bodyFontSettings['google_font']);
|
$google_fonts = array($bodyFontSettings['google_font']);
|
||||||
|
|
||||||
if($headerFont != $bodyFont){
|
if($headerFont != $bodyFont){
|
||||||
$headerFontSettings = Utils::getFromCache($headerFont, 'fonts');
|
$headerFontSettings = Utils::getFromCache($headerFont, 'fonts');
|
||||||
$google_fonts[] = $headerFontSettings['google_font'];
|
$google_fonts[] = $headerFontSettings['google_font'];
|
||||||
@ -1322,7 +1324,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
return ($protocol?$protocol.':':'').'//fonts.googleapis.com/css?family='.implode('|',$google_fonts);
|
return ($protocol?$protocol.':':'').'//fonts.googleapis.com/css?family='.implode('|',$google_fonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeaderFontId() {
|
public function getHeaderFontId() {
|
||||||
return ($this->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN) && $this->header_font_id) ? $this->header_font_id : DEFAULT_HEADER_FONT;
|
return ($this->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN) && $this->header_font_id) ? $this->header_font_id : DEFAULT_HEADER_FONT;
|
||||||
}
|
}
|
||||||
@ -1334,47 +1336,47 @@ class Account extends Eloquent
|
|||||||
public function getHeaderFontName(){
|
public function getHeaderFontName(){
|
||||||
return Utils::getFromCache($this->getHeaderFontId(), 'fonts')['name'];
|
return Utils::getFromCache($this->getHeaderFontId(), 'fonts')['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBodyFontName(){
|
public function getBodyFontName(){
|
||||||
return Utils::getFromCache($this->getBodyFontId(), 'fonts')['name'];
|
return Utils::getFromCache($this->getBodyFontId(), 'fonts')['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeaderFontCss($include_weight = true){
|
public function getHeaderFontCss($include_weight = true){
|
||||||
$font_data = Utils::getFromCache($this->getHeaderFontId(), 'fonts');
|
$font_data = Utils::getFromCache($this->getHeaderFontId(), 'fonts');
|
||||||
$css = 'font-family:'.$font_data['css_stack'].';';
|
$css = 'font-family:'.$font_data['css_stack'].';';
|
||||||
|
|
||||||
if($include_weight){
|
if($include_weight){
|
||||||
$css .= 'font-weight:'.$font_data['css_weight'].';';
|
$css .= 'font-weight:'.$font_data['css_weight'].';';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $css;
|
return $css;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBodyFontCss($include_weight = true){
|
public function getBodyFontCss($include_weight = true){
|
||||||
$font_data = Utils::getFromCache($this->getBodyFontId(), 'fonts');
|
$font_data = Utils::getFromCache($this->getBodyFontId(), 'fonts');
|
||||||
$css = 'font-family:'.$font_data['css_stack'].';';
|
$css = 'font-family:'.$font_data['css_stack'].';';
|
||||||
|
|
||||||
if($include_weight){
|
if($include_weight){
|
||||||
$css .= 'font-weight:'.$font_data['css_weight'].';';
|
$css .= 'font-weight:'.$font_data['css_weight'].';';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $css;
|
return $css;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFonts(){
|
public function getFonts(){
|
||||||
return array_unique(array($this->getHeaderFontId(), $this->getBodyFontId()));
|
return array_unique(array($this->getHeaderFontId(), $this->getBodyFontId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFontsData(){
|
public function getFontsData(){
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
foreach($this->getFonts() as $font){
|
foreach($this->getFonts() as $font){
|
||||||
$data[] = Utils::getFromCache($font, 'fonts');
|
$data[] = Utils::getFromCache($font, 'fonts');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFontFolders(){
|
public function getFontFolders(){
|
||||||
return array_map(function($item){return $item['folder'];}, $this->getFontsData());
|
return array_map(function($item){return $item['folder'];}, $this->getFontsData());
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
->where('contacts.is_primary', '=', true)
|
->where('contacts.is_primary', '=', true)
|
||||||
->where('invoices.is_recurring', '=', false)
|
->where('invoices.is_recurring', '=', false)
|
||||||
// This needs to be a setting to also hide the activity on the dashboard page
|
// This needs to be a setting to also hide the activity on the dashboard page
|
||||||
//->where('invoices.invoice_status_id', '>=', INVOICE_STATUS_SENT)
|
//->where('invoices.invoice_status_id', '>=', INVOICE_STATUS_SENT)
|
||||||
->select(
|
->select(
|
||||||
DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'),
|
DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'),
|
||||||
DB::raw('COALESCE(clients.country_id, accounts.country_id) country_id'),
|
DB::raw('COALESCE(clients.country_id, accounts.country_id) country_id'),
|
||||||
@ -240,7 +240,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
$account->invoice_footer = trim($data['invoice_footer']);
|
$account->invoice_footer = trim($data['invoice_footer']);
|
||||||
}
|
}
|
||||||
$account->save();
|
$account->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['invoice_number']) && !$invoice->is_recurring) {
|
if (isset($data['invoice_number']) && !$invoice->is_recurring) {
|
||||||
$invoice->invoice_number = trim($data['invoice_number']);
|
$invoice->invoice_number = trim($data['invoice_number']);
|
||||||
@ -277,7 +277,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
$invoice->start_date = Utils::toSqlDate($data['start_date']);
|
$invoice->start_date = Utils::toSqlDate($data['start_date']);
|
||||||
$invoice->end_date = Utils::toSqlDate($data['end_date']);
|
$invoice->end_date = Utils::toSqlDate($data['end_date']);
|
||||||
$invoice->auto_bill = isset($data['auto_bill']) && $data['auto_bill'] ? true : false;
|
$invoice->auto_bill = isset($data['auto_bill']) && $data['auto_bill'] ? true : false;
|
||||||
|
|
||||||
if (isset($data['recurring_due_date'])) {
|
if (isset($data['recurring_due_date'])) {
|
||||||
$invoice->due_date = $data['recurring_due_date'];
|
$invoice->due_date = $data['recurring_due_date'];
|
||||||
} elseif (isset($data['due_date'])) {
|
} elseif (isset($data['due_date'])) {
|
||||||
@ -299,7 +299,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
} else {
|
} else {
|
||||||
$invoice->terms = '';
|
$invoice->terms = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice->invoice_footer = (isset($data['invoice_footer']) && trim($data['invoice_footer'])) ? trim($data['invoice_footer']) : (!$publicId && $account->invoice_footer ? $account->invoice_footer : '');
|
$invoice->invoice_footer = (isset($data['invoice_footer']) && trim($data['invoice_footer'])) ? trim($data['invoice_footer']) : (!$publicId && $account->invoice_footer ? $account->invoice_footer : '');
|
||||||
$invoice->public_notes = isset($data['public_notes']) ? trim($data['public_notes']) : null;
|
$invoice->public_notes = isset($data['public_notes']) ? trim($data['public_notes']) : null;
|
||||||
|
|
||||||
@ -318,8 +318,8 @@ class InvoiceRepository extends BaseRepository
|
|||||||
|
|
||||||
// provide backwards compatability
|
// provide backwards compatability
|
||||||
if (isset($data['tax_name']) && isset($data['tax_rate'])) {
|
if (isset($data['tax_name']) && isset($data['tax_rate'])) {
|
||||||
$data['tax_name1'] = $data['tax_name'];
|
$data['tax_name1'] = $data['tax_name'];
|
||||||
$data['tax_rate1'] = $data['tax_rate'];
|
$data['tax_rate1'] = $data['tax_rate'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = 0;
|
$total = 0;
|
||||||
@ -353,11 +353,11 @@ class InvoiceRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($item['tax_rate1']) && Utils::parseFloat($item['tax_rate1']) > 0) {
|
if (isset($item['tax_rate1']) && Utils::parseFloat($item['tax_rate1']) > 0) {
|
||||||
$invoiceItemTaxRate = Utils::parseFloat($item['tax_rate1']);
|
$invoiceItemTaxRate = Utils::parseFloat($item['tax_rate1']);
|
||||||
$itemTax += round($lineTotal * $invoiceItemTaxRate / 100, 2);
|
$itemTax += round($lineTotal * $invoiceItemTaxRate / 100, 2);
|
||||||
}
|
}
|
||||||
if (isset($item['tax_rate2']) && Utils::parseFloat($item['tax_rate2']) > 0) {
|
if (isset($item['tax_rate2']) && Utils::parseFloat($item['tax_rate2']) > 0) {
|
||||||
$invoiceItemTaxRate = Utils::parseFloat($item['tax_rate2']);
|
$invoiceItemTaxRate = Utils::parseFloat($item['tax_rate2']);
|
||||||
$itemTax += round($lineTotal * $invoiceItemTaxRate / 100, 2);
|
$itemTax += round($lineTotal * $invoiceItemTaxRate / 100, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
|
|
||||||
$taxAmount1 = round($total * $invoice->tax_rate1 / 100, 2);
|
$taxAmount1 = round($total * $invoice->tax_rate1 / 100, 2);
|
||||||
$taxAmount2 = round($total * $invoice->tax_rate2 / 100, 2);
|
$taxAmount2 = round($total * $invoice->tax_rate2 / 100, 2);
|
||||||
$total = round($total + $taxAmount1 + $taxAmount2, 2);
|
$total = round($total + $taxAmount1 + $taxAmount2, 2);
|
||||||
$total += $itemTax;
|
$total += $itemTax;
|
||||||
|
|
||||||
// custom fields not charged taxes
|
// custom fields not charged taxes
|
||||||
@ -424,24 +424,24 @@ class InvoiceRepository extends BaseRepository
|
|||||||
if ($publicId) {
|
if ($publicId) {
|
||||||
$invoice->invoice_items()->forceDelete();
|
$invoice->invoice_items()->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$document_ids = !empty($data['document_ids'])?array_map('intval', $data['document_ids']):array();;
|
$document_ids = !empty($data['document_ids'])?array_map('intval', $data['document_ids']):array();;
|
||||||
foreach ($document_ids as $document_id){
|
foreach ($document_ids as $document_id){
|
||||||
$document = Document::scope($document_id)->first();
|
$document = Document::scope($document_id)->first();
|
||||||
if($document && Auth::user()->can('edit', $document)){
|
if($document && Auth::user()->can('edit', $document)){
|
||||||
|
|
||||||
if($document->invoice_id && $document->invoice_id != $invoice->id){
|
if($document->invoice_id && $document->invoice_id != $invoice->id){
|
||||||
// From a clone
|
// From a clone
|
||||||
$document = $document->cloneDocument();
|
$document = $document->cloneDocument();
|
||||||
$document_ids[] = $document->public_id;// Don't remove this document
|
$document_ids[] = $document->public_id;// Don't remove this document
|
||||||
}
|
}
|
||||||
|
|
||||||
$document->invoice_id = $invoice->id;
|
$document->invoice_id = $invoice->id;
|
||||||
$document->expense_id = null;
|
$document->expense_id = null;
|
||||||
$document->save();
|
$document->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($data['documents']) && Auth::user()->can('create', ENTITY_DOCUMENT)){
|
if(!empty($data['documents']) && Auth::user()->can('create', ENTITY_DOCUMENT)){
|
||||||
// Fallback upload
|
// Fallback upload
|
||||||
$doc_errors = array();
|
$doc_errors = array();
|
||||||
@ -460,7 +460,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
Session::flash('error', implode('<br>',array_map('htmlentities',$doc_errors)));
|
Session::flash('error', implode('<br>',array_map('htmlentities',$doc_errors)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($invoice->documents as $document){
|
foreach ($invoice->documents as $document){
|
||||||
if(!in_array($document->public_id, $document_ids)){
|
if(!in_array($document->public_id, $document_ids)){
|
||||||
// Removed
|
// Removed
|
||||||
@ -534,12 +534,12 @@ class InvoiceRepository extends BaseRepository
|
|||||||
|
|
||||||
// provide backwards compatability
|
// provide backwards compatability
|
||||||
if (isset($item['tax_name']) && isset($item['tax_rate'])) {
|
if (isset($item['tax_name']) && isset($item['tax_rate'])) {
|
||||||
$item['tax_name1'] = $item['tax_name'];
|
$item['tax_name1'] = $item['tax_name'];
|
||||||
$item['tax_rate1'] = $item['tax_rate'];
|
$item['tax_rate1'] = $item['tax_rate'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoiceItem->fill($item);
|
$invoiceItem->fill($item);
|
||||||
|
|
||||||
$invoice->invoice_items()->save($invoiceItem);
|
$invoice->invoice_items()->save($invoiceItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,9 +623,9 @@ class InvoiceRepository extends BaseRepository
|
|||||||
'cost',
|
'cost',
|
||||||
'qty',
|
'qty',
|
||||||
'tax_name1',
|
'tax_name1',
|
||||||
'tax_rate1',
|
'tax_rate1',
|
||||||
'tax_name2',
|
'tax_name2',
|
||||||
'tax_rate2',
|
'tax_rate2',
|
||||||
] as $field) {
|
] as $field) {
|
||||||
$cloneItem->$field = $item->$field;
|
$cloneItem->$field = $item->$field;
|
||||||
}
|
}
|
||||||
@ -634,7 +634,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($invoice->documents as $document) {
|
foreach ($invoice->documents as $document) {
|
||||||
$cloneDocument = $document->cloneDocument();
|
$cloneDocument = $document->cloneDocument();
|
||||||
$invoice->documents()->save($cloneDocument);
|
$invoice->documents()->save($cloneDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,7 +708,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
$invoice = Invoice::createNew($recurInvoice);
|
$invoice = Invoice::createNew($recurInvoice);
|
||||||
$invoice->client_id = $recurInvoice->client_id;
|
$invoice->client_id = $recurInvoice->client_id;
|
||||||
$invoice->recurring_invoice_id = $recurInvoice->id;
|
$invoice->recurring_invoice_id = $recurInvoice->id;
|
||||||
$invoice->invoice_number = $recurInvoice->account->recurring_invoice_number_prefix . $recurInvoice->account->getNextInvoiceNumber($recurInvoice);
|
$invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber($invoice);
|
||||||
$invoice->amount = $recurInvoice->amount;
|
$invoice->amount = $recurInvoice->amount;
|
||||||
$invoice->balance = $recurInvoice->amount;
|
$invoice->balance = $recurInvoice->amount;
|
||||||
$invoice->invoice_date = date_create()->format('Y-m-d');
|
$invoice->invoice_date = date_create()->format('Y-m-d');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user