From 5ee474035ac4eabdfe1eb8faa09634b10ae244dd Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 29 Mar 2017 18:02:36 +0300 Subject: [PATCH] Add client phone to invoice design fields --- app/Models/Invoice.php | 8 ++++++++ app/Models/Traits/GeneratesNumbers.php | 11 ++++++----- app/Models/Traits/PresentsInvoice.php | 7 ++++++- resources/lang/en/texts.php | 2 ++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7f51400602..8f8a48d93c 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1201,10 +1201,18 @@ class Invoice extends EntityModel implements BalanceAffecting if (! $this->last_sent_date) { return true; } else { + $date1 = new DateTime($this->last_sent_date); + $date2 = new DateTime(); + $diff = $date2->diff($date1); + $daysSinceLastSent = $diff->format('%a'); + $monthsSinceLastSent = ($diff->format('%y') * 12) + $diff->format('%m'); + + /* $date1 = Carbon::parse($this->last_sent_date, $timezone); $date2 = Carbon::now($timezone); $daysSinceLastSent = $date1->diffInDays($date2); $monthsSinceLastSent = $date1->diffInMonths($date2); + */ if ($daysSinceLastSent == 0) { return false; diff --git a/app/Models/Traits/GeneratesNumbers.php b/app/Models/Traits/GeneratesNumbers.php index ddc3034495..aabd6a69f1 100644 --- a/app/Models/Traits/GeneratesNumbers.php +++ b/app/Models/Traits/GeneratesNumbers.php @@ -39,6 +39,10 @@ trait GeneratesNumbers $number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT); } + if ($entity->recurring_invoice_id) { + $number = $this->recurring_invoice_number_prefix . $number; + } + if ($entity->isEntityType(ENTITY_CLIENT)) { $check = Client::scope(false, $this->id)->whereIdNumber($number)->withTrashed()->first(); } else { @@ -66,10 +70,6 @@ trait GeneratesNumbers } } - if ($entity->recurring_invoice_id) { - $number = $this->recurring_invoice_number_prefix . $number; - } - return $number; } @@ -161,7 +161,8 @@ trait GeneratesNumbers if (count($matches) > 1) { $format = $matches[1]; $search[] = $matches[0]; - $date = Carbon::now(session(SESSION_TIMEZONE, DEFAULT_TIMEZONE))->format($format); + $date = date_create()->format($format); + //$date = Carbon::now(session(SESSION_TIMEZONE, DEFAULT_TIMEZONE))->format($format); $replace[] = str_replace($format, $date, $matches[1]); } diff --git a/app/Models/Traits/PresentsInvoice.php b/app/Models/Traits/PresentsInvoice.php index c023ecfd6c..353506979a 100644 --- a/app/Models/Traits/PresentsInvoice.php +++ b/app/Models/Traits/PresentsInvoice.php @@ -96,14 +96,16 @@ trait PresentsInvoice 'client.client_name', 'client.id_number', 'client.vat_number', + 'client.website', + 'client.work_phone', 'client.address1', 'client.address2', 'client.city_state_postal', 'client.postal_city_state', 'client.country', + 'client.contact_name', 'client.email', 'client.phone', - 'client.contact_name', 'client.custom_value1', 'client.custom_value2', '.blank', @@ -138,6 +140,8 @@ trait PresentsInvoice list($entityType, $fieldName) = explode('.', $field); if (substr($fieldName, 0, 6) == 'custom') { $fields[$section][$field] = $labels[$field]; + } elseif (in_array($field, ['client.phone', 'client.email'])) { + $fields[$section][$field] = trans('texts.contact_' . $fieldName); } else { $fields[$section][$field] = $labels[$fieldName]; } @@ -222,6 +226,7 @@ trait PresentsInvoice 'credit_issued_to', 'credit_to', 'your_credit', + 'work_phone', ]; foreach ($fields as $field) { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 5fae2323a2..59d991920e 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2456,6 +2456,8 @@ $LANG = array( 'purge_successful' => 'Successfully purged account data', 'forbidden' => 'Forbidden', 'purge_data_message' => 'Warning: This will permanently erase your data, there is no undo.', + 'contact_phone' => 'Contact Phone', + 'contact_email' => 'Contact Email', );