Added setting to hide second tax rate

This commit is contained in:
Hillel Coren 2016-05-29 12:26:02 +03:00
parent e5afb28e4b
commit 0e75ddb5e6
7 changed files with 119 additions and 107 deletions

View File

@ -790,11 +790,7 @@ class AccountController extends BaseController
private function saveTaxRates() private function saveTaxRates()
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$account->fill(Input::all());
$account->invoice_taxes = Input::get('invoice_taxes') ? true : false;
$account->invoice_item_taxes = Input::get('invoice_item_taxes') ? true : false;
$account->show_item_taxes = Input::get('show_item_taxes') ? true : false;
$account->default_tax_rate_id = Input::get('default_tax_rate_id');
$account->save(); $account->save();
Session::flash('message', trans('texts.updated_settings')); Session::flash('message', trans('texts.updated_settings'));

View File

@ -134,6 +134,7 @@ class InvoiceApiController extends BaseAPIController
'city', 'city',
'state', 'state',
'postal_code', 'postal_code',
'country_id',
'private_notes', 'private_notes',
'currency_code', 'currency_code',
] as $field) { ] as $field) {
@ -182,7 +183,7 @@ class InvoiceApiController extends BaseAPIController
$invoice = Invoice::scope($invoice->public_id) $invoice = Invoice::scope($invoice->public_id)
->with('client', 'invoice_items', 'invitations') ->with('client', 'invoice_items', 'invitations')
->first(); ->first();
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -269,7 +270,7 @@ class InvoiceApiController extends BaseAPIController
$item[$key] = $val; $item[$key] = $val;
} }
} }
return $item; return $item;
} }
@ -308,7 +309,7 @@ class InvoiceApiController extends BaseAPIController
public function update(UpdateInvoiceAPIRequest $request, $publicId) public function update(UpdateInvoiceAPIRequest $request, $publicId)
{ {
if ($request->action == ACTION_CONVERT) { if ($request->action == ACTION_CONVERT) {
$quote = $request->entity(); $quote = $request->entity();
$invoice = $this->invoiceRepo->cloneInvoice($quote, $quote->id); $invoice = $this->invoiceRepo->cloneInvoice($quote, $quote->id);
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} elseif ($request->action) { } elseif ($request->action) {
@ -322,7 +323,7 @@ class InvoiceApiController extends BaseAPIController
$invoice = Invoice::scope($publicId) $invoice = Invoice::scope($publicId)
->with('client', 'invoice_items', 'invitations') ->with('client', 'invoice_items', 'invitations')
->firstOrFail(); ->firstOrFail();
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -351,7 +352,7 @@ class InvoiceApiController extends BaseAPIController
public function destroy(UpdateInvoiceAPIRequest $request) public function destroy(UpdateInvoiceAPIRequest $request)
{ {
$invoice = $request->entity(); $invoice = $request->entity();
$this->invoiceRepo->delete($invoice); $this->invoiceRepo->delete($invoice);
return $this->itemResponse($invoice); return $this->itemResponse($invoice);

View File

@ -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,
@ -56,6 +56,11 @@ class Account extends Eloquent
'currency_id', 'currency_id',
'language_id', 'language_id',
'military_time', 'military_time',
'invoice_taxes',
'invoice_item_taxes',
'show_item_taxes',
'default_tax_rate_id',
'enable_second_tax_rate',
]; ];
public static $basicSettings = [ public static $basicSettings = [
@ -401,7 +406,7 @@ class Account extends Eloquent
return $gateway; return $gateway;
} }
} }
return false; return false;
} }
@ -421,27 +426,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;
@ -453,33 +458,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());
} }
@ -529,7 +534,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;
@ -544,7 +549,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;
@ -574,7 +579,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');
} }
@ -654,7 +659,7 @@ class Account extends Eloquent
$prefix = $this->getNumberPrefix($invoice->is_quote); $prefix = $this->getNumberPrefix($invoice->is_quote);
$counterOffset = 0; $counterOffset = 0;
// confirm the invoice number isn't already taken // confirm the invoice number isn't already taken
do { do {
$number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT); $number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT);
$check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first(); $check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first();
@ -690,7 +695,7 @@ class Account extends Eloquent
$this->invoice_number_counter += 1; $this->invoice_number_counter += 1;
} }
} }
$this->save(); $this->save();
} }
@ -713,7 +718,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)
@ -726,8 +731,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);
@ -810,7 +815,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();
@ -821,18 +826,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:
@ -849,7 +854,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)));
@ -862,26 +867,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()) {
@ -893,7 +898,7 @@ class Account extends Eloquent
} }
$plan_details = $this->getPlanDetails(); $plan_details = $this->getPlanDetails();
return !empty($plan_details); return !empty($plan_details);
} }
@ -908,36 +913,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;
@ -948,11 +953,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;
@ -979,7 +984,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,
@ -1006,7 +1011,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'];
@ -1021,7 +1026,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;
@ -1029,28 +1034,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());
@ -1180,7 +1185,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);
} }
@ -1270,7 +1275,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) {
@ -1305,10 +1310,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;
} }
@ -1316,7 +1321,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;
@ -1324,11 +1329,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.'}';
@ -1338,17 +1343,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'];
@ -1356,7 +1361,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;
} }
@ -1368,47 +1373,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());
} }

View File

@ -27,7 +27,7 @@
// Whether checkboxes should always be present in the POST data, // Whether checkboxes should always be present in the POST data,
// no matter if you checked them or not // no matter if you checked them or not
'push_checkboxes' => false, 'push_checkboxes' => true,
// The value a checkbox will have in the POST array if unchecked // The value a checkbox will have in the POST array if unchecked
'unchecked_value' => 0, 'unchecked_value' => 0,
@ -181,4 +181,4 @@
), ),
); );

View File

@ -1312,7 +1312,8 @@ $LANG = array(
'security' => 'Security', 'security' => 'Security',
'see_whats_new' => 'See what\'s new in v:version', 'see_whats_new' => 'See what\'s new in v:version',
'wait_for_upload' => 'Please wait for the document upload to complete.', 'wait_for_upload' => 'Please wait for the document upload to complete.',
'upgrade_for_permissions' => 'Upgrade to our Enterprise plan to enable permissions.' 'upgrade_for_permissions' => 'Upgrade to our Enterprise plan to enable permissions.',
'enable_second_tax_rate' => 'Enable specifying a <b>second tax rate</b>',
); );

View File

@ -1,6 +1,6 @@
@extends('header') @extends('header')
@section('content') @section('content')
@parent @parent
@include('accounts.nav', ['selected' => ACCOUNT_TAX_RATES]) @include('accounts.nav', ['selected' => ACCOUNT_TAX_RATES])
@ -10,12 +10,13 @@
{{ Former::populateField('invoice_taxes', intval($account->invoice_taxes)) }} {{ Former::populateField('invoice_taxes', intval($account->invoice_taxes)) }}
{{ Former::populateField('invoice_item_taxes', intval($account->invoice_item_taxes)) }} {{ Former::populateField('invoice_item_taxes', intval($account->invoice_item_taxes)) }}
{{ Former::populateField('show_item_taxes', intval($account->show_item_taxes)) }} {{ Former::populateField('show_item_taxes', intval($account->show_item_taxes)) }}
{{ Former::populateField('enable_second_tax_rate', intval($account->enable_second_tax_rate)) }}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">{!! trans('texts.tax_settings') !!}</h3> <h3 class="panel-title">{!! trans('texts.tax_settings') !!}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{!! Former::checkbox('invoice_taxes') {!! Former::checkbox('invoice_taxes')
@ -30,6 +31,10 @@
->text(trans('texts.show_line_item_tax')) ->text(trans('texts.show_line_item_tax'))
->label('&nbsp;') !!} ->label('&nbsp;') !!}
{!! Former::checkbox('enable_second_tax_rate')
->text(trans('texts.enable_second_tax_rate'))
->label('&nbsp;') !!}
&nbsp; &nbsp;
{!! Former::select('default_tax_rate_id') {!! Former::select('default_tax_rate_id')
@ -51,22 +56,22 @@
@include('partials.bulk_form', ['entityType' => ENTITY_TAX_RATE]) @include('partials.bulk_form', ['entityType' => ENTITY_TAX_RATE])
{!! Datatable::table() {!! Datatable::table()
->addColumn( ->addColumn(
trans('texts.name'), trans('texts.name'),
trans('texts.rate'), trans('texts.rate'),
trans('texts.action')) trans('texts.action'))
->setUrl(url('api/tax_rates/')) ->setUrl(url('api/tax_rates/'))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->setOptions('bAutoWidth', false) ->setOptions('bAutoWidth', false)
->setOptions('aoColumns', [[ "sWidth"=> "40%" ], [ "sWidth"=> "40%" ], ["sWidth"=> "20%"]]) ->setOptions('aoColumns', [[ "sWidth"=> "40%" ], [ "sWidth"=> "40%" ], ["sWidth"=> "20%"]])
->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[2]]]) ->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[2]]])
->render('datatable') !!} ->render('datatable') !!}
<script> <script>
window.onDatatableReady = actionListHandler; window.onDatatableReady = actionListHandler;
</script> </script>
@stop @stop

View File

@ -243,7 +243,7 @@
@endif @endif
<th style="min-width:120px" data-bind="text: costLabel">{{ $invoiceLabels['unit_cost'] }}</th> <th style="min-width:120px" data-bind="text: costLabel">{{ $invoiceLabels['unit_cost'] }}</th>
<th style="{{ $account->hide_quantity ? 'display:none' : 'min-width:120px' }}" data-bind="text: qtyLabel">{{ $invoiceLabels['quantity'] }}</th> <th style="{{ $account->hide_quantity ? 'display:none' : 'min-width:120px' }}" data-bind="text: qtyLabel">{{ $invoiceLabels['quantity'] }}</th>
<th style="min-width:180px;display:none;" data-bind="visible: $root.invoice_item_taxes.show">{{ trans('texts.tax') }}</th> <th style="min-width:{{ $account->enable_second_tax_rate ? 180 : 120 }}px;display:none;" data-bind="visible: $root.invoice_item_taxes.show">{{ trans('texts.tax') }}</th>
<th style="min-width:120px;">{{ trans('texts.line_total') }}</th> <th style="min-width:120px;">{{ trans('texts.line_total') }}</th>
<th style="min-width:32px;" class="hide-border"></th> <th style="min-width:32px;" class="hide-border"></th>
</tr> </tr>
@ -288,16 +288,18 @@
->addOption('', '') ->addOption('', '')
->options($taxRateOptions) ->options($taxRateOptions)
->data_bind('value: tax1') ->data_bind('value: tax1')
->addClass('tax-select') ->addClass($account->enable_second_tax_rate ? 'tax-select' : '')
->raw() !!} ->raw() !!}
<input type="text" data-bind="value: tax_name1, attr: {name: 'invoice_items[' + $index() + '][tax_name1]'}" style="display:none"> <input type="text" data-bind="value: tax_name1, attr: {name: 'invoice_items[' + $index() + '][tax_name1]'}" style="display:none">
<input type="text" data-bind="value: tax_rate1, attr: {name: 'invoice_items[' + $index() + '][tax_rate1]'}" style="display:none"> <input type="text" data-bind="value: tax_rate1, attr: {name: 'invoice_items[' + $index() + '][tax_rate1]'}" style="display:none">
{!! Former::select('') <div data-bind="visible: $root.invoice().account.enable_second_tax_rate == '1'">
->addOption('', '') {!! Former::select('')
->options($taxRateOptions) ->addOption('', '')
->data_bind('value: tax2') ->options($taxRateOptions)
->addClass('tax-select') ->data_bind('value: tax2')
->raw() !!} ->addClass('tax-select')
->raw() !!}
</div>
<input type="text" data-bind="value: tax_name2, attr: {name: 'invoice_items[' + $index() + '][tax_name2]'}" style="display:none"> <input type="text" data-bind="value: tax_name2, attr: {name: 'invoice_items[' + $index() + '][tax_name2]'}" style="display:none">
<input type="text" data-bind="value: tax_rate2, attr: {name: 'invoice_items[' + $index() + '][tax_rate2]'}" style="display:none"> <input type="text" data-bind="value: tax_rate2, attr: {name: 'invoice_items[' + $index() + '][tax_rate2]'}" style="display:none">
</td> </td>
@ -438,17 +440,19 @@
->id('taxRateSelect1') ->id('taxRateSelect1')
->addOption('', '') ->addOption('', '')
->options($taxRateOptions) ->options($taxRateOptions)
->addClass('tax-select') ->addClass($account->enable_second_tax_rate ? 'tax-select' : '')
->data_bind('value: tax1') ->data_bind('value: tax1')
->raw() !!} ->raw() !!}
<input type="text" name="tax_name1" data-bind="value: tax_name1" style="display:none"> <input type="text" name="tax_name1" data-bind="value: tax_name1" style="display:none">
<input type="text" name="tax_rate1" data-bind="value: tax_rate1" style="display:none"> <input type="text" name="tax_rate1" data-bind="value: tax_rate1" style="display:none">
<div data-bind="visible: $root.invoice().account.enable_second_tax_rate == '1'">
{!! Former::select('') {!! Former::select('')
->addOption('', '') ->addOption('', '')
->options($taxRateOptions) ->options($taxRateOptions)
->addClass('tax-select') ->addClass('tax-select')
->data_bind('value: tax2') ->data_bind('value: tax2')
->raw() !!} ->raw() !!}
</div>
<input type="text" name="tax_name2" data-bind="value: tax_name2" style="display:none"> <input type="text" name="tax_name2" data-bind="value: tax_name2" style="display:none">
<input type="text" name="tax_rate2" data-bind="value: tax_rate2" style="display:none"> <input type="text" name="tax_rate2" data-bind="value: tax_rate2" style="display:none">
</td> </td>