Merge pull request #149 from cuneytsenturk/master

Make email not required for customer/vendor
This commit is contained in:
Cüneyt Şentürk 2017-12-16 13:45:11 +03:00 committed by GitHub
commit fdc579c3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 113 additions and 25 deletions

View File

@ -78,5 +78,4 @@ class BillReminder extends Command
} }
} }
} }
} }

View File

@ -69,7 +69,7 @@ class InvoiceReminder extends Command
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
// Notify the customer // Notify the customer
if ($invoice->customer) { if ($invoice->customer && !empty($invoice->customer_email)) {
$invoice->customer->notify(new Notification($invoice)); $invoice->customer->notify(new Notification($invoice));
} }
@ -83,5 +83,4 @@ class InvoiceReminder extends Command
} }
} }
} }
} }

View File

@ -243,6 +243,7 @@ class Users extends Controller
public function autocomplete(ARequest $request) public function autocomplete(ARequest $request)
{ {
$user = false; $user = false;
$data = false;
$column = $request['column']; $column = $request['column'];
$value = $request['value']; $value = $request['value'];
@ -250,7 +251,7 @@ class Users extends Controller
if (!empty($column) && !empty($value)) { if (!empty($column) && !empty($value)) {
switch ($column) { switch ($column) {
case 'id': case 'id':
$user = User::find(); $user = User::find((int) $value);
break; break;
case 'email': case 'email':
$user = User::where('email', $value)->first(); $user = User::where('email', $value)->first();
@ -258,12 +259,16 @@ class Users extends Controller
default: default:
$user = User::where($column, $value)->first(); $user = User::where($column, $value)->first();
} }
$data = $user;
} elseif (!empty($column) && empty($value)) {
$data = trans('validation.required', ['attribute' => $column]);
} }
return response()->json([ return response()->json([
'errors' => ($user) ? false: true, 'errors' => ($user) ? false : true,
'success' => ($user) ? true: false, 'success' => ($user) ? true : false,
'data' => $user 'data' => $data
]); ]);
} }
} }

View File

@ -44,6 +44,10 @@ class Vendors extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
if (empty($request['email'])) {
$request['email'] = '';
}
Vendor::create($request->all()); Vendor::create($request->all());
$message = trans('messages.success.added', ['type' => trans_choice('general.vendors', 1)]); $message = trans('messages.success.added', ['type' => trans_choice('general.vendors', 1)]);
@ -120,6 +124,10 @@ class Vendors extends Controller
*/ */
public function update(Vendor $vendor, Request $request) public function update(Vendor $vendor, Request $request)
{ {
if (empty($request['email'])) {
$request['email'] = '';
}
$vendor->update($request->all()); $vendor->update($request->all());
$message = trans('messages.success.updated', ['type' => trans_choice('general.vendors', 1)]); $message = trans('messages.success.updated', ['type' => trans_choice('general.vendors', 1)]);
@ -169,6 +177,10 @@ class Vendors extends Controller
public function vendor(Request $request) public function vendor(Request $request)
{ {
if (empty($request['email'])) {
$request['email'] = '';
}
$vendor = Vendor::create($request->all()); $vendor = Vendor::create($request->all());
return response()->json($vendor); return response()->json($vendor);

View File

@ -46,6 +46,10 @@ class Customers extends Controller
public function store(Request $request) public function store(Request $request)
{ {
if (empty($request->input('create_user'))) { if (empty($request->input('create_user'))) {
if (empty($request['email'])) {
$request['email'] = '';
}
Customer::create($request->all()); Customer::create($request->all());
} else { } else {
// Check if user exist // Check if user exist
@ -112,6 +116,11 @@ class Customers extends Controller
foreach ($rows as $row) { foreach ($rows as $row) {
$data = $row->toArray(); $data = $row->toArray();
if (empty($data['email'])) {
$data['email'] = '';
}
$data['company_id'] = session('company_id'); $data['company_id'] = session('company_id');
Customer::create($data); Customer::create($data);
@ -149,6 +158,10 @@ class Customers extends Controller
public function update(Customer $customer, Request $request) public function update(Customer $customer, Request $request)
{ {
if (empty($request->input('create_user'))) { if (empty($request->input('create_user'))) {
if (empty($request['email'])) {
$request['email'] = '';
}
$customer->update($request->all()); $customer->update($request->all());
} else { } else {
// Check if user exist // Check if user exist
@ -220,6 +233,10 @@ class Customers extends Controller
public function customer(Request $request) public function customer(Request $request)
{ {
if (empty($request['email'])) {
$request['email'] = '';
}
$customer = Customer::create($request->all()); $customer = Customer::create($request->all());
return response()->json($customer); return response()->json($customer);

View File

@ -489,6 +489,10 @@ class Invoices extends Controller
*/ */
public function emailInvoice(Invoice $invoice) public function emailInvoice(Invoice $invoice)
{ {
if (empty($invoice->customer_email)) {
return redirect()->back();
}
$invoice = $this->prepareInvoice($invoice); $invoice = $this->prepareInvoice($invoice);
$logo = $this->getLogo(); $logo = $this->getLogo();

View File

@ -23,6 +23,11 @@ class Vendor extends Request
*/ */
public function rules() public function rules()
{ {
$email = '';
// Get company id
$company_id = $this->request->get('company_id');
// Check if store or update // Check if store or update
if ($this->getMethod() == 'PATCH') { if ($this->getMethod() == 'PATCH') {
$id = $this->vendor->getAttribute('id'); $id = $this->vendor->getAttribute('id');
@ -30,12 +35,13 @@ class Vendor extends Request
$id = null; $id = null;
} }
// Get company id if (!empty($this->request->get('email'))) {
$company_id = $this->request->get('company_id'); $email = 'email|unique:vendors,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL';
}
return [ return [
'name' => 'required|string', 'name' => 'required|string',
'email' => 'required|email|unique:vendors,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL', 'email' => $email,
'currency_code' => 'required|string', 'currency_code' => 'required|string',
]; ];
} }

View File

@ -23,8 +23,12 @@ class Customer extends Request
*/ */
public function rules() public function rules()
{ {
$email = '';
$required = ''; $required = '';
// Get company id
$company_id = $this->request->get('company_id');
// Check if store or update // Check if store or update
if ($this->getMethod() == 'PATCH') { if ($this->getMethod() == 'PATCH') {
$id = $this->customer->getAttribute('id'); $id = $this->customer->getAttribute('id');
@ -36,12 +40,13 @@ class Customer extends Request
$required = 'required|'; $required = 'required|';
} }
// Get company id if (!empty($this->request->get('email'))) {
$company_id = $this->request->get('company_id'); $email = 'email|unique:customers,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL';
}
return [ return [
'name' => 'required|string', 'name' => 'required|string',
'email' => 'required|email|unique:customers,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL', 'email' => $email,
'currency_code' => 'required|string', 'currency_code' => 'required|string',
'password' => $required . 'confirmed', 'password' => $required . 'confirmed',
]; ];

12
public/css/app.css vendored
View File

@ -498,6 +498,18 @@ ul.add-new.nav.navbar-nav.pull-left {
background-color: #ffffff; background-color: #ffffff;
} }
} }
.text-disabled {
opacity: 0.4;
}
.tooltip > .tooltip-inner {
background-color: #6da252;
}
.tooltip.right .tooltip-arrow {
border-right-color: #6da252 !important;
}
/* /*
.content-wrapper { .content-wrapper {
overflow: inherit; overflow: inherit;

View File

@ -37,8 +37,9 @@ return [
], ],
'messages' => [ 'messages' => [
'email_sent' => 'Invoice email has been sent successfully!', 'email_sent' => 'Invoice email has been sent successfully!',
'marked_sent' => 'Invoice marked as sent successfully!', 'marked_sent' => 'Invoice marked as sent successfully!',
'email_required' => 'No email address for this customer!',
], ],
'notification' => [ 'notification' => [

View File

@ -290,7 +290,7 @@
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">'; modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>'; modal += ' </div>';
modal += ' </div>'; modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">'; modal += ' <div class="form-group col-md-6">';
modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>'; modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>';
modal += ' <div class="input-group">'; modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>'; modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>';

View File

@ -10,7 +10,7 @@
<div class="box-body"> <div class="box-body">
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }} {{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
{{ Form::textGroup('email', trans('general.email'), 'envelope') }} {{ Form::textGroup('email', trans('general.email'), 'envelope', []) }}
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }} {{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }}

View File

@ -14,7 +14,7 @@
<div class="box-body"> <div class="box-body">
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }} {{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
{{ Form::textGroup('email', trans('general.email'), 'envelope') }} {{ Form::textGroup('email', trans('general.email'), 'envelope', []) }}
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }} {{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }}

View File

@ -43,7 +43,7 @@
@foreach($vendors as $item) @foreach($vendors as $item)
<tr> <tr>
<td><a href="{{ url('expenses/vendors/' . $item->id . '/edit') }}">{{ $item->name }}</a></td> <td><a href="{{ url('expenses/vendors/' . $item->id . '/edit') }}">{{ $item->name }}</a></td>
<td class="hidden-xs">{{ $item->email }}</td> <td class="hidden-xs">{{ !empty($item->email) ? $item->email : 'N/A'}}</td>
<td>{{ $item->phone }}</td> <td>{{ $item->phone }}</td>
<td class="hidden-xs"> <td class="hidden-xs">
@if ($item->enabled) @if ($item->enabled)

View File

@ -10,7 +10,7 @@
<div class="box-body"> <div class="box-body">
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }} {{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
{{ Form::textGroup('email', trans('general.email'), 'envelope') }} {{ Form::textGroup('email', trans('general.email'), 'envelope', []) }}
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }} {{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }}
@ -68,7 +68,7 @@
$('#create_user').iCheck({ $('#create_user').iCheck({
checkboxClass: 'icheckbox_square-green', checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green', radioClass: 'iradio_square-green',
increaseArea: '20%' // optional increaseArea: '20%'
}); });
$('#create_user').on('ifClicked', function (event) { $('#create_user').on('ifClicked', function (event) {
@ -76,13 +76,29 @@
if ($(this).prop('checked')) { if ($(this).prop('checked')) {
$('.col-md-6.password').addClass('hidden'); $('.col-md-6.password').addClass('hidden');
$('input[name="email"]').parent().parent().removeClass('has-error');
$('input[name="email"]').parent().parent().find('.help-block').remove();
} else { } else {
var email = $('input[name="email"]').val();
if (!email) {
$('input[name="email"]').parent().parent().addClass('has-error');
$('input[name="email"]').parent().after('<p class="help-block">{{ trans('validation.required', ['attribute' => 'email']) }}</p>');
$('input[name="email"]').focus();
return false;
}
$.ajax({ $.ajax({
url: '{{ url("auth/users/autocomplete") }}', url: '{{ url("auth/users/autocomplete") }}',
type: 'GET', type: 'GET',
dataType: 'JSON', dataType: 'JSON',
data: {column: 'email', value: $('input[name="email"]').val()}, data: {column: 'email', value: email},
beforeSend: function() { beforeSend: function() {
$('input[name="email"]').parent().parent().removeClass('has-error');
$('input[name="email"]').parent().parent().find('.help-block').remove();
$('.box-footer .btn').attr('disabled', true); $('.box-footer .btn').attr('disabled', true);
}, },
complete: function() { complete: function() {
@ -90,6 +106,14 @@
}, },
success: function(json) { success: function(json) {
if (json['errors']) { if (json['errors']) {
if (json['data']) {
$('input[name="email"]').parent().parent().addClass('has-error');
$('input[name="email"]').parent().after('<p class="help-block">' + json['data'] + '</p>');
$('input[name="email"]').focus();
return false;
}
$('.col-md-6.password').removeClass('hidden'); $('.col-md-6.password').removeClass('hidden');
} }

View File

@ -14,7 +14,7 @@
<div class="box-body"> <div class="box-body">
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }} {{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
{{ Form::textGroup('email', trans('general.email'), 'envelope') }} {{ Form::textGroup('email', trans('general.email'), 'envelope', []) }}
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }} {{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }}

View File

@ -43,7 +43,7 @@
@foreach($customers as $item) @foreach($customers as $item)
<tr> <tr>
<td><a href="{{ url('incomes/customers/' . $item->id . '/edit') }}">{{ $item->name }}</a></td> <td><a href="{{ url('incomes/customers/' . $item->id . '/edit') }}">{{ $item->name }}</a></td>
<td class="hidden-xs">{{ $item->email }}</td> <td class="hidden-xs">{{ !empty($item->email) ? $item->email : 'N/A'}}</td>
<td>{{ $item->phone }}</td> <td>{{ $item->phone }}</td>
<td class="hidden-xs"> <td class="hidden-xs">
@if ($item->enabled) @if ($item->enabled)

View File

@ -291,7 +291,7 @@
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">'; modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>'; modal += ' </div>';
modal += ' </div>'; modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">'; modal += ' <div class="form-group col-md-6">';
modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>'; modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>';
modal += ' <div class="input-group">'; modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>'; modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>';

View File

@ -163,7 +163,11 @@
@permission('update-incomes-invoices') @permission('update-incomes-invoices')
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/sent') }}">{{ trans('invoices.mark_sent') }}</a></li> <li><a href="{{ url('incomes/invoices/' . $invoice->id . '/sent') }}">{{ trans('invoices.mark_sent') }}</a></li>
@endpermission @endpermission
@if($invoice->customer_email)
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li> <li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li>
@else
<li><a href="javascript:void(0);" class="green-tooltip disabled" data-toggle="tooltip" data-placement="right" title="{{ trans('invoices.messages.email_required') }}"><span class="text-disabled">{{ trans('invoices.send_mail') }}</span></a></li>
@endif
<li class="divider"></li> <li class="divider"></li>
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/pdf') }}">{{ trans('invoices.download_pdf') }}</a></li> <li><a href="{{ url('incomes/invoices/' . $invoice->id . '/pdf') }}">{{ trans('invoices.download_pdf') }}</a></li>
<li class="divider"></li> <li class="divider"></li>