From 1df20adca4c706fbc8089943743d7a8073424718 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 23 Mar 2017 11:39:44 +0200 Subject: [PATCH] Support reseting counters --- .../Commands/SendRecurringInvoices.php | 13 +++++- app/Http/Controllers/AccountController.php | 2 + app/Models/Account.php | 1 + app/Models/Traits/GeneratesNumbers.php | 46 +++++++++++++++++++ app/Ninja/Transformers/AccountTransformer.php | 1 + ..._03_16_085702_add_gateway_fee_location.php | 4 ++ database/setup.sql | 11 ++--- resources/lang/en/texts.php | 3 ++ .../views/accounts/invoice_settings.blade.php | 38 ++++++++++++++- resources/views/invoices/edit.blade.php | 2 +- 10 files changed, 112 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 88b317df5a..4ba30797bc 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\Account; use App\Models\Invoice; use App\Ninja\Mailers\ContactMailer as Mailer; use App\Ninja\Repositories\InvoiceRepository; @@ -60,6 +61,15 @@ class SendRecurringInvoices extends Command $this->info(date('Y-m-d').' Running SendRecurringInvoices...'); $today = new DateTime(); + // check for counter resets + $accounts = Account::where('reset_counter_frequency_id', '>', 0) + ->orderBy('id', 'asc') + ->get(); + + foreach ($accounts as $account) { + $account->checkCounterReset(); + } + $invoices = Invoice::with('account.timezone', 'invoice_items', 'client', 'user') ->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND is_public IS TRUE AND frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today]) ->orderBy('id', 'asc') @@ -74,7 +84,8 @@ class SendRecurringInvoices extends Command continue; } - $recurInvoice->account->loadLocalizationSettings($recurInvoice->client); + $account = $recurInvoice->account; + $account->loadLocalizationSettings($recurInvoice->client); $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice); if ($invoice && ! $invoice->isPaid()) { diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 96f8d11e6e..68bb58b4c3 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -932,6 +932,8 @@ class AccountController extends BaseController $account->client_number_prefix = trim(Input::get('client_number_prefix')); $account->client_number_pattern = trim(Input::get('client_number_pattern')); $account->client_number_counter = Input::get('client_number_counter'); + $account->reset_counter_frequency_id = Input::get('reset_counter_frequency_id'); + $account->reset_counter_date = $account->reset_counter_frequency_id ? Utils::toSqlDate(Input::get('reset_counter_date')) : null; if (Input::has('recurring_hour')) { $account->recurring_hour = Input::get('recurring_hour'); diff --git a/app/Models/Account.php b/app/Models/Account.php index 9d7bc43e8c..8de6b4c456 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -172,6 +172,7 @@ class Account extends Eloquent 'reset_counter_frequency_id', 'payment_type_id', 'gateway_fee_location', + 'reset_counter_date', ]; /** diff --git a/app/Models/Traits/GeneratesNumbers.php b/app/Models/Traits/GeneratesNumbers.php index b5e2ec734a..17012933a2 100644 --- a/app/Models/Traits/GeneratesNumbers.php +++ b/app/Models/Traits/GeneratesNumbers.php @@ -252,4 +252,50 @@ trait GeneratesNumbers { return $this->hasFeature(FEATURE_INVOICE_SETTINGS) && $this->client_number_counter > 0; } + + public function checkCounterReset() + { + if (! $this->reset_counter_frequency_id || ! $this->reset_counter_date) { + return false; + } + + $timezone = $this->getTimezone(); + $resetDate = Carbon::parse($this->reset_counter_date, $timezone); + + if (! $resetDate->isToday()) { + return false; + } + + switch ($this->reset_counter_frequency_id) { + case FREQUENCY_WEEKLY: + $resetDate->addWeek(); + break; + case FREQUENCY_TWO_WEEKS: + $resetDate->addWeeks(2); + break; + case FREQUENCY_FOUR_WEEKS: + $resetDate->addWeeks(4); + break; + case FREQUENCY_MONTHLY: + $resetDate->addMonth(); + break; + case FREQUENCY_TWO_MONTHS: + $resetDate->addMonths(2); + break; + case FREQUENCY_THREE_MONTHS: + $resetDate->addMonths(3); + break; + case FREQUENCY_SIX_MONTHS: + $resetDate->addMonths(6); + break; + case FREQUENCY_ANNUALLY: + $resetDate->addYear(); + break; + } + + $this->reset_counter_date = $resetDate->format('Y-m-d'); + $this->invoice_number_counter = 1; + $this->quote_number_counter = 1; + $this->save(); + } } diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 8691118b7b..ef4d6ca433 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -264,6 +264,7 @@ class AccountTransformer extends EntityTransformer 'reset_counter_frequency_id' => (int) $account->reset_counter_frequency_id, 'payment_type_id' => (int) $account->payment_type_id, 'gateway_fee_location' => $account->gateway_fee_location, + 'reset_counter_date' => $account->reset_counter_date, ]; } } diff --git a/database/migrations/2017_03_16_085702_add_gateway_fee_location.php b/database/migrations/2017_03_16_085702_add_gateway_fee_location.php index 117b697c3d..68c2427a9d 100644 --- a/database/migrations/2017_03_16_085702_add_gateway_fee_location.php +++ b/database/migrations/2017_03_16_085702_add_gateway_fee_location.php @@ -13,7 +13,10 @@ class AddGatewayFeeLocation extends Migration public function up() { Schema::table('accounts', function ($table) { + $table->dropColumn('auto_wrap'); + $table->dropColumn('utf8_invoices'); $table->enum('gateway_fee_location', [FEE_LOCATION_CHARGE1, FEE_LOCATION_CHARGE2, FEE_LOCATION_ITEM])->nullable(); + $table->date('reset_counter_date')->nullable(); }); } @@ -26,6 +29,7 @@ class AddGatewayFeeLocation extends Migration { Schema::table('accounts', function ($table) { $table->dropColumn('gateway_fee_location'); + $table->dropColumn('reset_counter_date'); }); } } diff --git a/database/setup.sql b/database/setup.sql index 9533286167..a450ab26a2 100644 --- a/database/setup.sql +++ b/database/setup.sql @@ -238,8 +238,6 @@ CREATE TABLE `accounts` ( `token_billing_type_id` smallint(6) NOT NULL DEFAULT '4', `invoice_footer` text COLLATE utf8_unicode_ci, `pdf_email_attachment` smallint(6) NOT NULL DEFAULT '0', - `utf8_invoices` tinyint(1) NOT NULL DEFAULT '1', - `auto_wrap` tinyint(1) NOT NULL DEFAULT '0', `subdomain` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `font_size` smallint(6) NOT NULL DEFAULT '9', `invoice_labels` text COLLATE utf8_unicode_ci, @@ -326,6 +324,7 @@ CREATE TABLE `accounts` ( `reset_counter_frequency_id` smallint(6) DEFAULT NULL, `payment_type_id` smallint(6) DEFAULT NULL, `gateway_fee_location` enum('custom_value1','custom_value2','invoice_item') COLLATE utf8_unicode_ci DEFAULT NULL, + `reset_counter_date` date DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `accounts_account_key_unique` (`account_key`), KEY `accounts_timezone_id_foreign` (`timezone_id`), @@ -1146,7 +1145,7 @@ CREATE TABLE `gateways` ( LOCK TABLES `gateways` WRITE; /*!40000 ALTER TABLE `gateways` DISABLE KEYS */; -INSERT INTO `gateways` VALUES (1,'2017-03-19 16:28:19','2017-03-19 16:28:19','Authorize.Net AIM','AuthorizeNet_AIM',1,1,4,0,NULL,0,0),(2,'2017-03-19 16:28:19','2017-03-19 16:28:19','Authorize.Net SIM','AuthorizeNet_SIM',1,2,10000,0,NULL,0,0),(3,'2017-03-19 16:28:19','2017-03-19 16:28:19','CardSave','CardSave',1,1,10000,0,NULL,0,0),(4,'2017-03-19 16:28:19','2017-03-19 16:28:19','Eway Rapid','Eway_RapidShared',1,1,10000,0,NULL,1,0),(5,'2017-03-19 16:28:19','2017-03-19 16:28:19','FirstData Connect','FirstData_Connect',1,1,10000,0,NULL,0,0),(6,'2017-03-19 16:28:19','2017-03-19 16:28:19','GoCardless','GoCardless',1,1,10000,0,NULL,1,0),(7,'2017-03-19 16:28:19','2017-03-19 16:28:19','Migs ThreeParty','Migs_ThreeParty',1,1,10000,0,NULL,0,0),(8,'2017-03-19 16:28:19','2017-03-19 16:28:19','Migs TwoParty','Migs_TwoParty',1,1,10000,0,NULL,0,0),(9,'2017-03-19 16:28:19','2017-03-19 16:28:19','Mollie','Mollie',1,1,7,0,NULL,1,0),(10,'2017-03-19 16:28:19','2017-03-19 16:28:19','MultiSafepay','MultiSafepay',1,1,10000,0,NULL,0,0),(11,'2017-03-19 16:28:19','2017-03-19 16:28:19','Netaxept','Netaxept',1,1,10000,0,NULL,0,0),(12,'2017-03-19 16:28:19','2017-03-19 16:28:19','NetBanx','NetBanx',1,1,10000,0,NULL,0,0),(13,'2017-03-19 16:28:19','2017-03-19 16:28:19','PayFast','PayFast',1,1,10000,0,NULL,1,0),(14,'2017-03-19 16:28:19','2017-03-19 16:28:19','Payflow Pro','Payflow_Pro',1,1,10000,0,NULL,0,0),(15,'2017-03-19 16:28:19','2017-03-19 16:28:19','PaymentExpress PxPay','PaymentExpress_PxPay',1,1,10000,0,NULL,0,0),(16,'2017-03-19 16:28:19','2017-03-19 16:28:19','PaymentExpress PxPost','PaymentExpress_PxPost',1,1,10000,0,NULL,0,0),(17,'2017-03-19 16:28:19','2017-03-19 16:28:19','PayPal Express','PayPal_Express',1,1,3,0,NULL,1,0),(18,'2017-03-19 16:28:19','2017-03-19 16:28:19','PayPal Pro','PayPal_Pro',1,1,10000,0,NULL,0,0),(19,'2017-03-19 16:28:19','2017-03-19 16:28:19','Pin','Pin',1,1,10000,0,NULL,0,0),(20,'2017-03-19 16:28:19','2017-03-19 16:28:19','SagePay Direct','SagePay_Direct',1,1,10000,0,NULL,0,0),(21,'2017-03-19 16:28:19','2017-03-19 16:28:19','SagePay Server','SagePay_Server',1,1,10000,0,NULL,0,0),(22,'2017-03-19 16:28:19','2017-03-19 16:28:19','SecurePay DirectPost','SecurePay_DirectPost',1,1,10000,0,NULL,0,0),(23,'2017-03-19 16:28:19','2017-03-19 16:28:19','Stripe','Stripe',1,1,1,0,NULL,0,0),(24,'2017-03-19 16:28:19','2017-03-19 16:28:19','TargetPay Direct eBanking','TargetPay_Directebanking',1,1,10000,0,NULL,0,0),(25,'2017-03-19 16:28:19','2017-03-19 16:28:19','TargetPay Ideal','TargetPay_Ideal',1,1,10000,0,NULL,0,0),(26,'2017-03-19 16:28:19','2017-03-19 16:28:19','TargetPay Mr Cash','TargetPay_Mrcash',1,1,10000,0,NULL,0,0),(27,'2017-03-19 16:28:19','2017-03-19 16:28:19','TwoCheckout','TwoCheckout',1,1,10000,0,NULL,1,0),(28,'2017-03-19 16:28:19','2017-03-19 16:28:19','WorldPay','WorldPay',1,1,10000,0,NULL,0,0),(29,'2017-03-19 16:28:19','2017-03-19 16:28:19','BeanStream','BeanStream',1,2,10000,0,NULL,0,0),(30,'2017-03-19 16:28:19','2017-03-19 16:28:19','Psigate','Psigate',1,2,10000,0,NULL,0,0),(31,'2017-03-19 16:28:19','2017-03-19 16:28:19','moolah','AuthorizeNet_AIM',1,1,10000,0,NULL,0,0),(32,'2017-03-19 16:28:19','2017-03-19 16:28:19','Alipay','Alipay_Express',1,1,10000,0,NULL,0,0),(33,'2017-03-19 16:28:19','2017-03-19 16:28:19','Buckaroo','Buckaroo_CreditCard',1,1,10000,0,NULL,0,0),(34,'2017-03-19 16:28:19','2017-03-19 16:28:19','Coinbase','Coinbase',1,1,10000,0,NULL,0,0),(35,'2017-03-19 16:28:19','2017-03-19 16:28:19','DataCash','DataCash',1,1,10000,0,NULL,0,0),(36,'2017-03-19 16:28:19','2017-03-19 16:28:19','Neteller','Neteller',1,2,10000,0,NULL,0,0),(37,'2017-03-19 16:28:19','2017-03-19 16:28:19','Pacnet','Pacnet',1,1,10000,0,NULL,0,0),(38,'2017-03-19 16:28:19','2017-03-19 16:28:19','PaymentSense','PaymentSense',1,2,10000,0,NULL,0,0),(39,'2017-03-19 16:28:19','2017-03-19 16:28:19','Realex','Realex_Remote',1,1,10000,0,NULL,0,0),(40,'2017-03-19 16:28:19','2017-03-19 16:28:19','Sisow','Sisow',1,1,10000,0,NULL,0,0),(41,'2017-03-19 16:28:19','2017-03-19 16:28:19','Skrill','Skrill',1,1,10000,0,NULL,1,0),(42,'2017-03-19 16:28:19','2017-03-19 16:28:19','BitPay','BitPay',1,1,6,0,NULL,1,0),(43,'2017-03-19 16:28:19','2017-03-19 16:28:19','Dwolla','Dwolla',1,1,5,0,NULL,1,0),(44,'2017-03-19 16:28:19','2017-03-19 16:28:19','AGMS','Agms',1,1,10000,0,NULL,0,0),(45,'2017-03-19 16:28:19','2017-03-19 16:28:19','Barclays','BarclaysEpdq\\Essential',1,1,10000,0,NULL,0,0),(46,'2017-03-19 16:28:19','2017-03-19 16:28:19','Cardgate','Cardgate',1,1,10000,0,NULL,0,0),(47,'2017-03-19 16:28:19','2017-03-19 16:28:19','Checkout.com','CheckoutCom',1,1,10000,0,NULL,0,0),(48,'2017-03-19 16:28:19','2017-03-19 16:28:19','Creditcall','Creditcall',1,1,10000,0,NULL,0,0),(49,'2017-03-19 16:28:19','2017-03-19 16:28:19','Cybersource','Cybersource',1,1,10000,0,NULL,0,0),(50,'2017-03-19 16:28:19','2017-03-19 16:28:19','ecoPayz','Ecopayz',1,1,10000,0,NULL,0,0),(51,'2017-03-19 16:28:19','2017-03-19 16:28:19','Fasapay','Fasapay',1,1,10000,0,NULL,0,0),(52,'2017-03-19 16:28:19','2017-03-19 16:28:19','Komoju','Komoju',1,1,10000,0,NULL,0,0),(53,'2017-03-19 16:28:19','2017-03-19 16:28:19','Multicards','Multicards',1,1,10000,0,NULL,0,0),(54,'2017-03-19 16:28:19','2017-03-19 16:28:19','Pagar.Me','Pagarme',1,2,10000,0,NULL,0,0),(55,'2017-03-19 16:28:19','2017-03-19 16:28:19','Paysafecard','Paysafecard',1,1,10000,0,NULL,0,0),(56,'2017-03-19 16:28:19','2017-03-19 16:28:19','Paytrace','Paytrace_CreditCard',1,1,10000,0,NULL,0,0),(57,'2017-03-19 16:28:19','2017-03-19 16:28:19','Secure Trading','SecureTrading',1,1,10000,0,NULL,0,0),(58,'2017-03-19 16:28:19','2017-03-19 16:28:19','SecPay','SecPay',1,1,10000,0,NULL,0,0),(59,'2017-03-19 16:28:19','2017-03-19 16:28:19','WeChat Express','WeChat_Express',1,2,10000,0,NULL,0,0),(60,'2017-03-19 16:28:19','2017-03-19 16:28:19','WePay','WePay',1,1,10000,0,NULL,0,0),(61,'2017-03-19 16:28:19','2017-03-19 16:28:19','Braintree','Braintree',1,1,2,0,NULL,0,0),(62,'2017-03-19 16:28:19','2017-03-19 16:28:19','Custom','Custom',1,1,8,0,NULL,1,0); +INSERT INTO `gateways` VALUES (1,'2017-03-23 07:12:22','2017-03-23 07:12:22','Authorize.Net AIM','AuthorizeNet_AIM',1,1,4,0,NULL,0,0),(2,'2017-03-23 07:12:22','2017-03-23 07:12:22','Authorize.Net SIM','AuthorizeNet_SIM',1,2,10000,0,NULL,0,0),(3,'2017-03-23 07:12:22','2017-03-23 07:12:22','CardSave','CardSave',1,1,10000,0,NULL,0,0),(4,'2017-03-23 07:12:22','2017-03-23 07:12:22','Eway Rapid','Eway_RapidShared',1,1,10000,0,NULL,1,0),(5,'2017-03-23 07:12:22','2017-03-23 07:12:22','FirstData Connect','FirstData_Connect',1,1,10000,0,NULL,0,0),(6,'2017-03-23 07:12:22','2017-03-23 07:12:22','GoCardless','GoCardless',1,1,10000,0,NULL,1,0),(7,'2017-03-23 07:12:22','2017-03-23 07:12:22','Migs ThreeParty','Migs_ThreeParty',1,1,10000,0,NULL,0,0),(8,'2017-03-23 07:12:22','2017-03-23 07:12:22','Migs TwoParty','Migs_TwoParty',1,1,10000,0,NULL,0,0),(9,'2017-03-23 07:12:22','2017-03-23 07:12:22','Mollie','Mollie',1,1,7,0,NULL,1,0),(10,'2017-03-23 07:12:22','2017-03-23 07:12:22','MultiSafepay','MultiSafepay',1,1,10000,0,NULL,0,0),(11,'2017-03-23 07:12:22','2017-03-23 07:12:22','Netaxept','Netaxept',1,1,10000,0,NULL,0,0),(12,'2017-03-23 07:12:22','2017-03-23 07:12:22','NetBanx','NetBanx',1,1,10000,0,NULL,0,0),(13,'2017-03-23 07:12:22','2017-03-23 07:12:22','PayFast','PayFast',1,1,10000,0,NULL,1,0),(14,'2017-03-23 07:12:22','2017-03-23 07:12:22','Payflow Pro','Payflow_Pro',1,1,10000,0,NULL,0,0),(15,'2017-03-23 07:12:22','2017-03-23 07:12:22','PaymentExpress PxPay','PaymentExpress_PxPay',1,1,10000,0,NULL,0,0),(16,'2017-03-23 07:12:22','2017-03-23 07:12:22','PaymentExpress PxPost','PaymentExpress_PxPost',1,1,10000,0,NULL,0,0),(17,'2017-03-23 07:12:22','2017-03-23 07:12:22','PayPal Express','PayPal_Express',1,1,3,0,NULL,1,0),(18,'2017-03-23 07:12:22','2017-03-23 07:12:22','PayPal Pro','PayPal_Pro',1,1,10000,0,NULL,0,0),(19,'2017-03-23 07:12:22','2017-03-23 07:12:22','Pin','Pin',1,1,10000,0,NULL,0,0),(20,'2017-03-23 07:12:22','2017-03-23 07:12:22','SagePay Direct','SagePay_Direct',1,1,10000,0,NULL,0,0),(21,'2017-03-23 07:12:22','2017-03-23 07:12:22','SagePay Server','SagePay_Server',1,1,10000,0,NULL,0,0),(22,'2017-03-23 07:12:22','2017-03-23 07:12:22','SecurePay DirectPost','SecurePay_DirectPost',1,1,10000,0,NULL,0,0),(23,'2017-03-23 07:12:22','2017-03-23 07:12:22','Stripe','Stripe',1,1,1,0,NULL,0,0),(24,'2017-03-23 07:12:22','2017-03-23 07:12:22','TargetPay Direct eBanking','TargetPay_Directebanking',1,1,10000,0,NULL,0,0),(25,'2017-03-23 07:12:22','2017-03-23 07:12:22','TargetPay Ideal','TargetPay_Ideal',1,1,10000,0,NULL,0,0),(26,'2017-03-23 07:12:22','2017-03-23 07:12:22','TargetPay Mr Cash','TargetPay_Mrcash',1,1,10000,0,NULL,0,0),(27,'2017-03-23 07:12:22','2017-03-23 07:12:22','TwoCheckout','TwoCheckout',1,1,10000,0,NULL,1,0),(28,'2017-03-23 07:12:22','2017-03-23 07:12:22','WorldPay','WorldPay',1,1,10000,0,NULL,0,0),(29,'2017-03-23 07:12:22','2017-03-23 07:12:22','BeanStream','BeanStream',1,2,10000,0,NULL,0,0),(30,'2017-03-23 07:12:22','2017-03-23 07:12:22','Psigate','Psigate',1,2,10000,0,NULL,0,0),(31,'2017-03-23 07:12:22','2017-03-23 07:12:22','moolah','AuthorizeNet_AIM',1,1,10000,0,NULL,0,0),(32,'2017-03-23 07:12:22','2017-03-23 07:12:22','Alipay','Alipay_Express',1,1,10000,0,NULL,0,0),(33,'2017-03-23 07:12:22','2017-03-23 07:12:22','Buckaroo','Buckaroo_CreditCard',1,1,10000,0,NULL,0,0),(34,'2017-03-23 07:12:22','2017-03-23 07:12:22','Coinbase','Coinbase',1,1,10000,0,NULL,0,0),(35,'2017-03-23 07:12:22','2017-03-23 07:12:22','DataCash','DataCash',1,1,10000,0,NULL,0,0),(36,'2017-03-23 07:12:22','2017-03-23 07:12:22','Neteller','Neteller',1,2,10000,0,NULL,0,0),(37,'2017-03-23 07:12:22','2017-03-23 07:12:22','Pacnet','Pacnet',1,1,10000,0,NULL,0,0),(38,'2017-03-23 07:12:22','2017-03-23 07:12:22','PaymentSense','PaymentSense',1,2,10000,0,NULL,0,0),(39,'2017-03-23 07:12:22','2017-03-23 07:12:22','Realex','Realex_Remote',1,1,10000,0,NULL,0,0),(40,'2017-03-23 07:12:22','2017-03-23 07:12:22','Sisow','Sisow',1,1,10000,0,NULL,0,0),(41,'2017-03-23 07:12:22','2017-03-23 07:12:22','Skrill','Skrill',1,1,10000,0,NULL,1,0),(42,'2017-03-23 07:12:22','2017-03-23 07:12:22','BitPay','BitPay',1,1,6,0,NULL,1,0),(43,'2017-03-23 07:12:22','2017-03-23 07:12:22','Dwolla','Dwolla',1,1,5,0,NULL,1,0),(44,'2017-03-23 07:12:22','2017-03-23 07:12:22','AGMS','Agms',1,1,10000,0,NULL,0,0),(45,'2017-03-23 07:12:22','2017-03-23 07:12:22','Barclays','BarclaysEpdq\\Essential',1,1,10000,0,NULL,0,0),(46,'2017-03-23 07:12:22','2017-03-23 07:12:22','Cardgate','Cardgate',1,1,10000,0,NULL,0,0),(47,'2017-03-23 07:12:22','2017-03-23 07:12:22','Checkout.com','CheckoutCom',1,1,10000,0,NULL,0,0),(48,'2017-03-23 07:12:22','2017-03-23 07:12:22','Creditcall','Creditcall',1,1,10000,0,NULL,0,0),(49,'2017-03-23 07:12:22','2017-03-23 07:12:22','Cybersource','Cybersource',1,1,10000,0,NULL,0,0),(50,'2017-03-23 07:12:22','2017-03-23 07:12:22','ecoPayz','Ecopayz',1,1,10000,0,NULL,0,0),(51,'2017-03-23 07:12:22','2017-03-23 07:12:22','Fasapay','Fasapay',1,1,10000,0,NULL,0,0),(52,'2017-03-23 07:12:22','2017-03-23 07:12:22','Komoju','Komoju',1,1,10000,0,NULL,0,0),(53,'2017-03-23 07:12:22','2017-03-23 07:12:22','Multicards','Multicards',1,1,10000,0,NULL,0,0),(54,'2017-03-23 07:12:22','2017-03-23 07:12:22','Pagar.Me','Pagarme',1,2,10000,0,NULL,0,0),(55,'2017-03-23 07:12:22','2017-03-23 07:12:22','Paysafecard','Paysafecard',1,1,10000,0,NULL,0,0),(56,'2017-03-23 07:12:22','2017-03-23 07:12:22','Paytrace','Paytrace_CreditCard',1,1,10000,0,NULL,0,0),(57,'2017-03-23 07:12:22','2017-03-23 07:12:22','Secure Trading','SecureTrading',1,1,10000,0,NULL,0,0),(58,'2017-03-23 07:12:22','2017-03-23 07:12:22','SecPay','SecPay',1,1,10000,0,NULL,0,0),(59,'2017-03-23 07:12:22','2017-03-23 07:12:22','WeChat Express','WeChat_Express',1,2,10000,0,NULL,0,0),(60,'2017-03-23 07:12:22','2017-03-23 07:12:22','WePay','WePay',1,1,10000,0,NULL,0,0),(61,'2017-03-23 07:12:22','2017-03-23 07:12:22','Braintree','Braintree',1,1,2,0,NULL,0,0),(62,'2017-03-23 07:12:22','2017-03-23 07:12:22','Custom','Custom',1,1,8,0,NULL,1,0); /*!40000 ALTER TABLE `gateways` ENABLE KEYS */; UNLOCK TABLES; @@ -1564,7 +1563,7 @@ CREATE TABLE `payment_libraries` ( LOCK TABLES `payment_libraries` WRITE; /*!40000 ALTER TABLE `payment_libraries` DISABLE KEYS */; -INSERT INTO `payment_libraries` VALUES (1,'2017-03-19 16:28:18','2017-03-19 16:28:18','Omnipay',1),(2,'2017-03-19 16:28:18','2017-03-19 16:28:18','PHP-Payments [Deprecated]',1); +INSERT INTO `payment_libraries` VALUES (1,'2017-03-23 07:12:21','2017-03-23 07:12:21','Omnipay',1),(2,'2017-03-23 07:12:21','2017-03-23 07:12:21','PHP-Payments [Deprecated]',1); /*!40000 ALTER TABLE `payment_libraries` ENABLE KEYS */; UNLOCK TABLES; @@ -1674,7 +1673,7 @@ CREATE TABLE `payment_terms` ( LOCK TABLES `payment_terms` WRITE; /*!40000 ALTER TABLE `payment_terms` DISABLE KEYS */; -INSERT INTO `payment_terms` VALUES (1,7,'Net 7','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,1),(2,10,'Net 10','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,2),(3,14,'Net 14','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,3),(4,15,'Net 15','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,4),(5,30,'Net 30','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,5),(6,60,'Net 60','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,6),(7,90,'Net 90','2017-03-19 16:28:18','2017-03-19 16:28:18',NULL,0,0,7),(8,-1,'Net 0','2017-03-19 16:28:21','2017-03-19 16:28:21',NULL,0,0,0); +INSERT INTO `payment_terms` VALUES (1,7,'Net 7','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,1),(2,10,'Net 10','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,2),(3,14,'Net 14','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,3),(4,15,'Net 15','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,4),(5,30,'Net 30','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,5),(6,60,'Net 60','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,6),(7,90,'Net 90','2017-03-23 07:12:21','2017-03-23 07:12:21',NULL,0,0,7),(8,-1,'Net 0','2017-03-23 07:12:24','2017-03-23 07:12:24',NULL,0,0,0); /*!40000 ALTER TABLE `payment_terms` ENABLE KEYS */; UNLOCK TABLES; @@ -2269,4 +2268,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2017-03-19 20:28:22 +-- Dump completed on 2017-03-23 11:12:24 diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index babeadd959..ad57af5790 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2430,6 +2430,9 @@ $LANG = array( 'data' => 'Data', 'imported_settings' => 'Successfully imported settings', 'lang_Greek' => 'Greek', + 'reset_counter' => 'Reset Counter', + 'next_reset' => 'Next Reset', + 'reset_counter_help' => 'Automatically reset the invoice and quote counters.', ); diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index 60e863dd23..fd5e57e1ee 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -47,6 +47,9 @@
  • {{ trans('texts.recurring_invoice_number') }}
  • +
  • + {{ trans('texts.reset_counter') }} +
  • @@ -73,7 +76,6 @@ ->label(trans('texts.counter')) ->help(trans('texts.invoice_number_help') . ' ' . trans('texts.next_invoice_number', ['number' => $account->previewNextInvoiceNumber()])) !!} -
    @@ -150,6 +152,24 @@
    +
    +
    + + {!! Former::select('reset_counter_frequency_id') + ->onchange('onResetFrequencyChange()') + ->label('frequency') + ->addOption(trans('texts.never'), '') + ->options(\App\Models\Frequency::selectOptions()) + ->help('reset_counter_help') !!} + + {!! Former::text('reset_counter_date') + ->label('next_reset') + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT)) + ->addGroupClass('reset_counter_date_group') + ->append('') !!} + +
    +
    @@ -410,6 +430,15 @@ } } + function onResetFrequencyChange() { + var val = $('#reset_counter_frequency_id').val(); + if (val) { + $('.reset_counter_date_group').show(); + } else { + $('.reset_counter_date_group').hide(); + } + } + $('.number-pattern .input-group-addon').click(function() { $('#patternHelpModal').modal('show'); }); @@ -420,6 +449,13 @@ onQuoteNumberTypeChange(); onClientNumberTypeChange(); onClientNumberEnabled(); + onResetFrequencyChange(); + + $('#reset_counter_date').datepicker('update', '{{ Utils::fromSqlDate($account->reset_counter_date) ?: 'new Date()' }}'); + $('.reset_counter_date_group .input-group-addon').click(function() { + toggleDatePicker('reset_counter_date'); + }); + }); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 50bc588aa5..8b1e7e2f24 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -165,7 +165,7 @@ @if ($entityType == ENTITY_INVOICE)
    - {!! Former::select('frequency_id')->options($frequencies)->data_bind("value: frequency_id") + {!! Former::select('frequency_id')->label('frequency')->options($frequencies)->data_bind("value: frequency_id") ->appendIcon('question-sign')->addGroupClass('frequency_id')->onchange('onFrequencyChange()') !!} {!! Former::text('start_date')->data_bind("datePicker: start_date, valueUpdate: 'afterkeydown'") ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('start_date') !!}