mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
bug fixes
This commit is contained in:
parent
94a9c42369
commit
6999a6501d
@ -39,7 +39,7 @@ class SendRecurringInvoices extends Command {
|
||||
$invoice = Invoice::createNew($recurInvoice);
|
||||
$invoice->client_id = $recurInvoice->client_id;
|
||||
$invoice->recurring_invoice_id = $recurInvoice->id;
|
||||
$invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber();
|
||||
$invoice->invoice_number = 'R' . $recurInvoice->account->getNextInvoiceNumber();
|
||||
$invoice->amount = $recurInvoice->amount;
|
||||
$invoice->currency_id = $recurInvoice->currency_id;
|
||||
$invoice->invoice_date = date_create();
|
||||
|
@ -67,10 +67,14 @@ class AccountController extends \BaseController {
|
||||
{
|
||||
if ($section == ACCOUNT_DETAILS)
|
||||
{
|
||||
$account = Account::with('users')->findOrFail(Auth::user()->account_id);
|
||||
$countries = Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get();
|
||||
$data = [
|
||||
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
];
|
||||
|
||||
return View::make('accounts.details', array('account'=>$account, 'countries'=>$countries));
|
||||
return View::make('accounts.details', $data);
|
||||
}
|
||||
else if ($section == ACCOUNT_SETTINGS)
|
||||
{
|
||||
@ -444,7 +448,7 @@ class AccountController extends \BaseController {
|
||||
{
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
'email' => 'email|required'
|
||||
'email' => 'email|required|unique:users,email,' . Auth::user()->id . ',id'
|
||||
);
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
@ -465,12 +469,14 @@ class AccountController extends \BaseController {
|
||||
$account->state = trim(Input::get('state'));
|
||||
$account->postal_code = trim(Input::get('postal_code'));
|
||||
$account->country_id = Input::get('country_id') ? Input::get('country_id') : null;
|
||||
$account->size_id = Input::get('size_id') ? Input::get('size_id') : null;
|
||||
$account->industry_id = Input::get('industry_id') ? Input::get('industry_id') : null;
|
||||
$account->save();
|
||||
|
||||
$user = $account->users()->first();
|
||||
$user->first_name = trim(Input::get('first_name'));
|
||||
$user->last_name = trim(Input::get('last_name'));
|
||||
$user->email = trim(Input::get('email'));
|
||||
$user->username = $user->email = trim(Input::get('email'));
|
||||
$user->phone = trim(Input::get('phone'));
|
||||
$user->save();
|
||||
|
||||
@ -484,7 +490,7 @@ class AccountController extends \BaseController {
|
||||
{
|
||||
$path = Input::file('logo')->getRealPath();
|
||||
File::delete('logo/' . $account->account_key . '.jpg');
|
||||
Image::make($path)->resize(150, 100, true, false)->save('logo/' . $account->account_key . '.jpg');
|
||||
Image::make($path)->resize(120, 80, true, false)->save('logo/' . $account->account_key . '.jpg');
|
||||
}
|
||||
|
||||
Session::flash('message', 'Successfully updated details');
|
||||
@ -494,11 +500,13 @@ class AccountController extends \BaseController {
|
||||
|
||||
public function checkEmail()
|
||||
{
|
||||
$email = User::where('email', '=', Input::get('email'))->where('id', '<>', Auth::user()->id)->first();
|
||||
$email = User::withTrashed()->where('email', '=', Input::get('email'))->where('id', '<>', Auth::user()->id)->first();
|
||||
|
||||
if ($email) {
|
||||
if ($email)
|
||||
{
|
||||
return "taken";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return "available";
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
<?php
|
||||
|
||||
use ninja\repositories\ClientRepository;
|
||||
|
||||
class ClientController extends \BaseController {
|
||||
|
||||
protected $clientRepo;
|
||||
|
||||
public function __construct(ClientRepository $clientRepo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->clientRepo = $clientRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -9,9 +20,6 @@ class ClientController extends \BaseController {
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//$clients = Client::orderBy('name')->get();
|
||||
//return View::make('clients.index')->with('clients', $clients);
|
||||
|
||||
return View::make('list', array(
|
||||
'entityType'=>ENTITY_CLIENT,
|
||||
'title' => '- Clients',
|
||||
@ -21,29 +29,9 @@ class ClientController extends \BaseController {
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
$query = DB::table('clients')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('clients.account_id', '=', Auth::user()->account_id)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email','clients.currency_id');
|
||||
$clients = $this->clientRepo->find(Input::get('sSearch'));
|
||||
|
||||
$filter = Input::get('sSearch');
|
||||
if ($filter)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.first_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.last_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.email', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
//$query->get();
|
||||
//dd(DB::getQueryLog());
|
||||
|
||||
return Datatable::query($query)
|
||||
return Datatable::query($clients)
|
||||
->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; })
|
||||
->addColumn('name', function($model) { return link_to('clients/' . $model->public_id, $model->name); })
|
||||
->addColumn('first_name', function($model) { return link_to('clients/' . $model->public_id, $model->first_name . ' ' . $model->last_name); })
|
||||
@ -85,8 +73,8 @@ class ClientController extends \BaseController {
|
||||
'method' => 'POST',
|
||||
'url' => 'clients',
|
||||
'title' => '- New Client',
|
||||
'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get());
|
||||
@ -112,7 +100,7 @@ class ClientController extends \BaseController {
|
||||
*/
|
||||
public function show($publicId)
|
||||
{
|
||||
$client = Client::scope($publicId)->with('contacts', 'client_size', 'client_industry')->firstOrFail();
|
||||
$client = Client::scope($publicId)->with('contacts', 'size', 'industry')->firstOrFail();
|
||||
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT);
|
||||
|
||||
$data = array(
|
||||
@ -138,9 +126,9 @@ class ClientController extends \BaseController {
|
||||
'method' => 'PUT',
|
||||
'url' => 'clients/' . $publicId,
|
||||
'title' => '- ' . $client->name,
|
||||
'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get());
|
||||
return View::make('clients.edit', $data);
|
||||
@ -185,8 +173,8 @@ class ClientController extends \BaseController {
|
||||
$client->postal_code = trim(Input::get('postal_code'));
|
||||
$client->country_id = Input::get('country_id') ? Input::get('country_id') : null;
|
||||
$client->private_notes = trim(Input::get('private_notes'));
|
||||
$client->client_size_id = Input::get('client_size_id') ? Input::get('client_size_id') : null;
|
||||
$client->client_industry_id = Input::get('client_industry_id') ? Input::get('client_industry_id') : null;
|
||||
$client->size_id = Input::get('size_id') ? Input::get('size_id') : null;
|
||||
$client->industry_id = Input::get('industry_id') ? Input::get('industry_id') : null;
|
||||
$client->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null;
|
||||
$client->payment_terms = Input::get('payment_terms');
|
||||
$client->website = trim(Input::get('website'));
|
||||
@ -244,11 +232,14 @@ class ClientController extends \BaseController {
|
||||
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
|
||||
$clients = Client::scope($ids)->get();
|
||||
|
||||
foreach ($clients as $client) {
|
||||
if ($action == 'delete') {
|
||||
foreach ($clients as $client)
|
||||
{
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$client->is_deleted = true;
|
||||
$client->save();
|
||||
}
|
||||
|
||||
$client->delete();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,18 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
use ninja\repositories\CreditRepository;
|
||||
|
||||
class CreditController extends \BaseController {
|
||||
|
||||
protected $creditRepo;
|
||||
|
||||
public function __construct(CreditRepository $creditRepo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->creditRepo = $creditRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -18,31 +29,12 @@ class CreditController extends \BaseController {
|
||||
|
||||
public function getDatatable($clientPublicId = null)
|
||||
{
|
||||
$query = DB::table('credits')
|
||||
->join('clients', 'clients.id', '=','credits.client_id')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('clients.account_id', '=', Auth::user()->account_id)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('credits.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('credits.public_id', 'clients.name as client_name', 'clients.public_id as client_public_id', 'credits.amount', 'credits.credit_date', 'credits.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email');
|
||||
$credits = $this->creditRepo->find($clientPublicId, Input::get('sSearch'));
|
||||
|
||||
if ($clientPublicId) {
|
||||
$query->where('clients.public_id', '=', $clientPublicId);
|
||||
}
|
||||
$table = Datatable::query($credits);
|
||||
|
||||
$filter = Input::get('sSearch');
|
||||
if ($filter)
|
||||
if (!$clientPublicId)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$table = Datatable::query($query);
|
||||
|
||||
if (!$clientPublicId) {
|
||||
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; })
|
||||
->addColumn('client_name', function($model) { return link_to('clients/' . $model->client_public_id, Utils::getClientDisplayName($model)); });
|
||||
}
|
||||
@ -56,14 +48,12 @@ class CreditController extends \BaseController {
|
||||
Select <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="' . URL::to('credits/'.$model->public_id.'/edit') . '">Edit Credit</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="javascript:archiveEntity(' . $model->public_id. ')">Archive Credit</a></li>
|
||||
<li><a href="javascript:deleteEntity(' . $model->public_id. ')">Delete Credit</a></li>
|
||||
</ul>
|
||||
</div>';
|
||||
})
|
||||
->orderColumns('number')
|
||||
->orderColumns('number')
|
||||
->make();
|
||||
}
|
||||
|
||||
@ -119,26 +109,16 @@ class CreditController extends \BaseController {
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
if ($validator->fails())
|
||||
{
|
||||
$url = $publicId ? 'credits/' . $publicId . '/edit' : 'credits/create';
|
||||
return Redirect::to($url)
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
} else {
|
||||
if ($publicId) {
|
||||
$credit = Credit::scope($publicId)->firstOrFail();
|
||||
} else {
|
||||
$credit = Credit::createNew();
|
||||
}
|
||||
|
||||
$invoiceId = Input::get('invoice') && Input::get('invoice') != "-1" ? Invoice::getPrivateId(Input::get('invoice')) : null;
|
||||
|
||||
$credit->client_id = Client::getPrivateId(Input::get('client'));
|
||||
$credit->credit_date = Utils::toSqlDate(Input::get('credit_date'));
|
||||
$credit->invoice_id = $invoiceId;
|
||||
$credit->amount = floatval(Input::get('amount'));
|
||||
$credit->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null;
|
||||
$credit->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->creditRepo->save($publicId, Input::all());
|
||||
|
||||
$message = $publicId ? 'Successfully updated credit' : 'Successfully created credit';
|
||||
Session::flash('message', $message);
|
||||
@ -149,18 +129,10 @@ class CreditController extends \BaseController {
|
||||
public function bulk()
|
||||
{
|
||||
$action = Input::get('action');
|
||||
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
|
||||
$credits = Credit::scope($ids)->get();
|
||||
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
|
||||
$count = $this->creditRepo->bulk($ids, $action);
|
||||
|
||||
foreach ($credits as $credit) {
|
||||
if ($action == 'delete') {
|
||||
$credit->is_deleted = true;
|
||||
$credit->save();
|
||||
}
|
||||
$credit->delete();
|
||||
}
|
||||
|
||||
$message = Utils::pluralize('Successfully '.$action.'d ? credit', count($credits));
|
||||
$message = Utils::pluralize('Successfully '.$action.'d ? credit', $count);
|
||||
Session::flash('message', $message);
|
||||
|
||||
return Redirect::to('credits');
|
||||
|
@ -116,41 +116,27 @@ class InvoiceController extends \BaseController {
|
||||
|
||||
public function view($invitationKey)
|
||||
{
|
||||
$invitation = Invitation::with('user', 'invoice.invoice_items', 'invoice.client.account', 'invoice.client.contacts')
|
||||
$invitation = Invitation::with('user', 'invoice.invoice_items', 'invoice.account.country', 'invoice.client.contacts', 'invoice.client.country')
|
||||
->where('invitation_key', '=', $invitationKey)->firstOrFail();
|
||||
|
||||
$user = $invitation->user;
|
||||
$invoice = $invitation->invoice;
|
||||
|
||||
|
||||
if (!$invoice || $invoice->is_deleted)
|
||||
{
|
||||
return View::make('invoices.deleted');
|
||||
}
|
||||
|
||||
$client = $invoice->client;
|
||||
|
||||
|
||||
if (!$client || $client->is_deleted)
|
||||
{
|
||||
return View::make('invoices.deleted');
|
||||
}
|
||||
|
||||
if (!$invoice->isViewed())
|
||||
{
|
||||
$invoice->invoice_status_id = INVOICE_STATUS_VIEWED;
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
$now = Carbon::now()->toDateTimeString();
|
||||
|
||||
$invitation->viewed_date = $now;
|
||||
$invitation->save();
|
||||
Activity::viewInvoice($invitation);
|
||||
|
||||
$client = $invoice->client;
|
||||
$client->last_login = $now;
|
||||
$client->save();
|
||||
$client->account->loadLocalizationSettings();
|
||||
|
||||
Activity::viewInvoice($invitation);
|
||||
|
||||
$data = array(
|
||||
'invoice' => $invoice->hidePrivateFields(),
|
||||
'invitation' => $invitation
|
||||
@ -298,7 +284,7 @@ class InvoiceController extends \BaseController {
|
||||
|
||||
public function edit($publicId)
|
||||
{
|
||||
$invoice = Invoice::scope($publicId)->with('account.country', 'client.contacts', 'invoice_items')->firstOrFail();
|
||||
$invoice = Invoice::scope($publicId)->with('account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail();
|
||||
Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), ENTITY_INVOICE);
|
||||
|
||||
$contactIds = DB::table('invitations')
|
||||
@ -350,12 +336,12 @@ class InvoiceController extends \BaseController {
|
||||
'account' => Auth::user()->account,
|
||||
'products' => Product::scope()->get(array('product_key','notes','cost','qty')),
|
||||
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
|
||||
'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'frequencies' => array(
|
||||
1 => 'Weekly',
|
||||
2 => 'Two weeks',
|
||||
@ -419,7 +405,7 @@ class InvoiceController extends \BaseController {
|
||||
|
||||
foreach ($client->contacts as $contact)
|
||||
{
|
||||
if ($contact->send_invoice)
|
||||
if ($contact->send_invoice || count($client->contacts) == 1)
|
||||
{
|
||||
$sendInvoiceIds[] = $contact->id;
|
||||
}
|
||||
@ -505,11 +491,14 @@ class InvoiceController extends \BaseController {
|
||||
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
|
||||
$invoices = Invoice::scope($ids)->get();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
if ($action == 'delete') {
|
||||
foreach ($invoices as $invoice)
|
||||
{
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$invoice->is_deleted = true;
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
$invoice->delete();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,18 @@
|
||||
<?php
|
||||
|
||||
use ninja\repositories\PaymentRepository;
|
||||
|
||||
class PaymentController extends \BaseController
|
||||
{
|
||||
protected $creditRepo;
|
||||
|
||||
public function __construct(PaymentRepository $paymentRepo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->paymentRepo = $paymentRepo;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return View::make('list', array(
|
||||
@ -13,30 +24,8 @@ class PaymentController extends \BaseController
|
||||
|
||||
public function getDatatable($clientPublicId = null)
|
||||
{
|
||||
$query = DB::table('payments')
|
||||
->join('clients', 'clients.id', '=','payments.client_id')
|
||||
->leftJoin('invoices', 'invoices.id', '=','payments.invoice_id')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('payments.account_id', '=', Auth::user()->account_id)
|
||||
->where('payments.deleted_at', '=', null)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number', 'payments.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email');
|
||||
|
||||
if ($clientPublicId) {
|
||||
$query->where('clients.public_id', '=', $clientPublicId);
|
||||
}
|
||||
|
||||
$filter = Input::get('sSearch');
|
||||
if ($filter)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$table = Datatable::query($query);
|
||||
$payments = $this->paymentRepo->find($clientPublicId, Input::get('sSearch'));
|
||||
$table = Datatable::query($payments);
|
||||
|
||||
if (!$clientPublicId) {
|
||||
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
|
||||
@ -58,8 +47,6 @@ class PaymentController extends \BaseController
|
||||
Select <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="' . URL::to('payments/'.$model->public_id.'/edit') . '">Edit Payment</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="javascript:archiveEntity(' . $model->public_id. ')">Archive Payment</a></li>
|
||||
<li><a href="javascript:deleteEntity(' . $model->public_id. ')">Delete Payment</a></li>
|
||||
</ul>
|
||||
@ -123,26 +110,16 @@ class PaymentController extends \BaseController
|
||||
);
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
if ($validator->fails())
|
||||
{
|
||||
$url = $publicId ? 'payments/' . $publicId . '/edit' : 'payments/create';
|
||||
return Redirect::to($url)
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
} else {
|
||||
if ($publicId) {
|
||||
$payment = Payment::scope($publicId)->firstOrFail();
|
||||
} else {
|
||||
$payment = Payment::createNew();
|
||||
}
|
||||
|
||||
$invoiceId = Input::get('invoice') && Input::get('invoice') != "-1" ? Invoice::getPrivateId(Input::get('invoice')) : null;
|
||||
|
||||
$payment->client_id = Client::getPrivateId(Input::get('client'));
|
||||
$payment->invoice_id = $invoiceId;
|
||||
$payment->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null;
|
||||
$payment->payment_date = Utils::toSqlDate(Input::get('payment_date'));
|
||||
$payment->amount = floatval(Input::get('amount'));
|
||||
$payment->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->paymentRepo->save($publicId, Input::all());
|
||||
|
||||
$message = $publicId ? 'Successfully updated payment' : 'Successfully created payment';
|
||||
Session::flash('message', $message);
|
||||
@ -154,15 +131,7 @@ class PaymentController extends \BaseController
|
||||
{
|
||||
$action = Input::get('action');
|
||||
$ids = Input::get('id') ? Input::get('id') : Input::get('ids');
|
||||
$payments = Payment::scope($ids)->get();
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
if ($action == 'delete') {
|
||||
$payment->is_deleted = true;
|
||||
$payment->save();
|
||||
}
|
||||
$payment->delete();
|
||||
}
|
||||
$count = $this->paymentRepo->bulk($ids, $action);
|
||||
|
||||
$message = Utils::pluralize('Successfully '.$action.'d ? payment', count($payments));
|
||||
Session::flash('message', $message);
|
||||
|
@ -25,8 +25,6 @@ class ConfideSetupUsersTable extends Migration {
|
||||
Schema::dropIfExists('invoices');
|
||||
Schema::dropIfExists('password_reminders');
|
||||
Schema::dropIfExists('clients');
|
||||
Schema::dropIfExists('client_sizes');
|
||||
Schema::dropIfExists('client_industries');
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('accounts');
|
||||
Schema::dropIfExists('currencies');
|
||||
@ -36,7 +34,9 @@ class ConfideSetupUsersTable extends Migration {
|
||||
Schema::dropIfExists('frequencies');
|
||||
Schema::dropIfExists('date_formats');
|
||||
Schema::dropIfExists('datetime_formats');
|
||||
|
||||
Schema::dropIfExists('sizes');
|
||||
Schema::dropIfExists('industries');
|
||||
|
||||
Schema::create('countries', function($table)
|
||||
{
|
||||
$table->increments('id');
|
||||
@ -101,6 +101,18 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->string('decimal_separator');
|
||||
});
|
||||
|
||||
Schema::create('sizes', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
$t->string('name');
|
||||
});
|
||||
|
||||
Schema::create('industries', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
$t->string('name');
|
||||
});
|
||||
|
||||
Schema::create('accounts', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
@ -124,6 +136,8 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->string('postal_code');
|
||||
$t->unsignedInteger('country_id')->nullable();
|
||||
$t->text('invoice_terms');
|
||||
$t->unsignedInteger('industry_id')->nullable();
|
||||
$t->unsignedInteger('size_id')->nullable();
|
||||
|
||||
$t->boolean('invoice_taxes')->default(true);
|
||||
$t->boolean('invoice_item_taxes')->default(false);
|
||||
@ -131,8 +145,10 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->foreign('timezone_id')->references('id')->on('timezones');
|
||||
$t->foreign('date_format_id')->references('id')->on('date_formats');
|
||||
$t->foreign('datetime_format_id')->references('id')->on('datetime_formats');
|
||||
$t->foreign('country_id')->references('id')->on('countries');
|
||||
$t->foreign('currency_id')->references('id')->on('currencies');
|
||||
$t->foreign('country_id')->references('id')->on('countries');
|
||||
$t->foreign('currency_id')->references('id')->on('currencies');
|
||||
$t->foreign('industry_id')->references('id')->on('industries');
|
||||
$t->foreign('size_id')->references('id')->on('sizes');
|
||||
});
|
||||
|
||||
Schema::create('gateways', function($t)
|
||||
@ -201,18 +217,6 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->string('token');
|
||||
});
|
||||
|
||||
Schema::create('client_sizes', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
$t->string('name');
|
||||
});
|
||||
|
||||
Schema::create('client_industries', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
$t->string('name');
|
||||
});
|
||||
|
||||
Schema::create('clients', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
@ -235,16 +239,16 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->decimal('paid_to_date', 13, 4);
|
||||
$t->timestamp('last_login')->nullable();
|
||||
$t->string('website');
|
||||
$t->unsignedInteger('client_industry_id')->nullable();
|
||||
$t->unsignedInteger('client_size_id')->nullable();
|
||||
$t->unsignedInteger('industry_id')->nullable();
|
||||
$t->unsignedInteger('size_id')->nullable();
|
||||
$t->boolean('is_deleted');
|
||||
$t->integer('payment_terms');
|
||||
|
||||
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$t->foreign('country_id')->references('id')->on('countries');
|
||||
$t->foreign('client_industry_id')->references('id')->on('client_industries');
|
||||
$t->foreign('client_size_id')->references('id')->on('client_sizes');
|
||||
$t->foreign('industry_id')->references('id')->on('industries');
|
||||
$t->foreign('size_id')->references('id')->on('sizes');
|
||||
$t->foreign('currency_id')->references('id')->on('currencies');
|
||||
|
||||
$t->unsignedInteger('public_id')->index();
|
||||
@ -439,7 +443,7 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->string('payer_id');
|
||||
|
||||
$t->foreign('invoice_id')->references('id')->on('invoices');
|
||||
$t->foreign('account_id')->references('id')->on('accounts');
|
||||
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
$t->foreign('contact_id')->references('id')->on('contacts');
|
||||
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');;
|
||||
@ -466,7 +470,7 @@ class ConfideSetupUsersTable extends Migration {
|
||||
$t->date('credit_date')->nullable();
|
||||
$t->string('credit_number');
|
||||
|
||||
$t->foreign('account_id')->references('id')->on('accounts');
|
||||
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
$t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
|
||||
$t->foreign('contact_id')->references('id')->on('contacts');
|
||||
@ -526,8 +530,6 @@ class ConfideSetupUsersTable extends Migration {
|
||||
Schema::dropIfExists('invoices');
|
||||
Schema::dropIfExists('password_reminders');
|
||||
Schema::dropIfExists('clients');
|
||||
Schema::dropIfExists('client_sizes');
|
||||
Schema::dropIfExists('client_industries');
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('accounts');
|
||||
Schema::dropIfExists('currencies');
|
||||
@ -537,5 +539,7 @@ class ConfideSetupUsersTable extends Migration {
|
||||
Schema::dropIfExists('frequencies');
|
||||
Schema::dropIfExists('date_formats');
|
||||
Schema::dropIfExists('datetime_formats');
|
||||
Schema::dropIfExists('sizes');
|
||||
Schema::dropIfExists('industries');
|
||||
}
|
||||
}
|
||||
|
@ -58,41 +58,41 @@ class ConstantsSeeder extends Seeder
|
||||
Frequency::create(array('name' => 'Six months'));
|
||||
Frequency::create(array('name' => 'Annually'));
|
||||
|
||||
ClientIndustry::create(array('name' => 'Accounting & Legal'));
|
||||
ClientIndustry::create(array('name' => 'Advertising'));
|
||||
ClientIndustry::create(array('name' => 'Aerospace'));
|
||||
ClientIndustry::create(array('name' => 'Agriculture'));
|
||||
ClientIndustry::create(array('name' => 'Automotive'));
|
||||
ClientIndustry::create(array('name' => 'Banking & Finance'));
|
||||
ClientIndustry::create(array('name' => 'Biotechnology'));
|
||||
ClientIndustry::create(array('name' => 'Broadcasting'));
|
||||
ClientIndustry::create(array('name' => 'Business Services'));
|
||||
ClientIndustry::create(array('name' => 'Commodities & Chemicals'));
|
||||
ClientIndustry::create(array('name' => 'Communications'));
|
||||
ClientIndustry::create(array('name' => 'Computers & Hightech'));
|
||||
ClientIndustry::create(array('name' => 'Defense'));
|
||||
ClientIndustry::create(array('name' => 'Energy'));
|
||||
ClientIndustry::create(array('name' => 'Entertainment'));
|
||||
ClientIndustry::create(array('name' => 'Government'));
|
||||
ClientIndustry::create(array('name' => 'Healthcare & Life Sciences'));
|
||||
ClientIndustry::create(array('name' => 'Insurance'));
|
||||
ClientIndustry::create(array('name' => 'Manufacturing'));
|
||||
ClientIndustry::create(array('name' => 'Marketing'));
|
||||
ClientIndustry::create(array('name' => 'Media'));
|
||||
ClientIndustry::create(array('name' => 'Nonprofit & Higher Ed'));
|
||||
ClientIndustry::create(array('name' => 'Pharmaceuticals'));
|
||||
ClientIndustry::create(array('name' => 'Professional Services & Consulting'));
|
||||
ClientIndustry::create(array('name' => 'Real Estate'));
|
||||
ClientIndustry::create(array('name' => 'Retail & Wholesale'));
|
||||
ClientIndustry::create(array('name' => 'Sports'));
|
||||
ClientIndustry::create(array('name' => 'Transportation'));
|
||||
ClientIndustry::create(array('name' => 'Travel & Luxury'));
|
||||
Industry::create(array('name' => 'Accounting & Legal'));
|
||||
Industry::create(array('name' => 'Advertising'));
|
||||
Industry::create(array('name' => 'Aerospace'));
|
||||
Industry::create(array('name' => 'Agriculture'));
|
||||
Industry::create(array('name' => 'Automotive'));
|
||||
Industry::create(array('name' => 'Banking & Finance'));
|
||||
Industry::create(array('name' => 'Biotechnology'));
|
||||
Industry::create(array('name' => 'Broadcasting'));
|
||||
Industry::create(array('name' => 'Business Services'));
|
||||
Industry::create(array('name' => 'Commodities & Chemicals'));
|
||||
Industry::create(array('name' => 'Communications'));
|
||||
Industry::create(array('name' => 'Computers & Hightech'));
|
||||
Industry::create(array('name' => 'Defense'));
|
||||
Industry::create(array('name' => 'Energy'));
|
||||
Industry::create(array('name' => 'Entertainment'));
|
||||
Industry::create(array('name' => 'Government'));
|
||||
Industry::create(array('name' => 'Healthcare & Life Sciences'));
|
||||
Industry::create(array('name' => 'Insurance'));
|
||||
Industry::create(array('name' => 'Manufacturing'));
|
||||
Industry::create(array('name' => 'Marketing'));
|
||||
Industry::create(array('name' => 'Media'));
|
||||
Industry::create(array('name' => 'Nonprofit & Higher Ed'));
|
||||
Industry::create(array('name' => 'Pharmaceuticals'));
|
||||
Industry::create(array('name' => 'Professional Services & Consulting'));
|
||||
Industry::create(array('name' => 'Real Estate'));
|
||||
Industry::create(array('name' => 'Retail & Wholesale'));
|
||||
Industry::create(array('name' => 'Sports'));
|
||||
Industry::create(array('name' => 'Transportation'));
|
||||
Industry::create(array('name' => 'Travel & Luxury'));
|
||||
|
||||
ClientSize::create(array('name' => '1 - 10'));
|
||||
ClientSize::create(array('name' => '11 - 50'));
|
||||
ClientSize::create(array('name' => '51 - 100'));
|
||||
ClientSize::create(array('name' => '101 - 500'));
|
||||
ClientSize::create(array('name' => '500+'));
|
||||
Size::create(array('name' => '1 - 10'));
|
||||
Size::create(array('name' => '11 - 50'));
|
||||
Size::create(array('name' => '51 - 100'));
|
||||
Size::create(array('name' => '101 - 500'));
|
||||
Size::create(array('name' => '500+'));
|
||||
|
||||
PaymentTerm::create(array('num_days' => 7, 'name' => 'Net 7'));
|
||||
PaymentTerm::create(array('num_days' => 10, 'name' => 'Net 10'));
|
||||
|
@ -17,7 +17,7 @@ class UserEventHandler
|
||||
|
||||
public function onLogin()
|
||||
{
|
||||
$account = Account::findOrFail(Auth::user()->account_id);
|
||||
$account = Auth::user()->account;
|
||||
$account->last_login = Carbon::now()->toDateTimeString();
|
||||
$account->save();
|
||||
|
||||
@ -26,13 +26,6 @@ class UserEventHandler
|
||||
|
||||
public function onRefresh()
|
||||
{
|
||||
$user = User::whereId(Auth::user()->id)->with('account', 'account.date_format', 'account.datetime_format', 'account.timezone')->firstOrFail();
|
||||
$account = $user->account;
|
||||
|
||||
Session::put(SESSION_TIMEZONE, $account->timezone ? $account->timezone->name : DEFAULT_TIMEZONE);
|
||||
Session::put(SESSION_DATE_FORMAT, $account->date_format ? $account->date_format->format : DEFAULT_DATE_FORMAT);
|
||||
Session::put(SESSION_DATE_PICKER_FORMAT, $account->date_format ? $account->date_format->picker_format : DEFAULT_DATE_PICKER_FORMAT);
|
||||
Session::put(SESSION_DATETIME_FORMAT, $account->datetime_format ? $account->datetime_format->format : DEFAULT_DATETIME_FORMAT);
|
||||
Session::put(SESSION_CURRENCY, $account->currency_id ? $account->currency_id : DEFAULT_CURRENCY);
|
||||
Auth::user()->account->loadLocalizationSettings();
|
||||
}
|
||||
}
|
@ -49,6 +49,15 @@ class Account extends Eloquent
|
||||
return $this->belongsTo('DatetimeFormat');
|
||||
}
|
||||
|
||||
public function size()
|
||||
{
|
||||
return $this->belongsTo('Size');
|
||||
}
|
||||
|
||||
public function industry()
|
||||
{
|
||||
return $this->belongsTo('Industry');
|
||||
}
|
||||
|
||||
public function isGatewayConfigured($gatewayId = 0)
|
||||
{
|
||||
@ -93,12 +102,13 @@ class Account extends Eloquent
|
||||
}
|
||||
|
||||
public function getNextInvoiceNumber()
|
||||
{
|
||||
$order = Invoice::withTrashed()->scope(false, $this->id)->orderBy('invoice_number', 'DESC')->first();
|
||||
{
|
||||
$order = Invoice::withTrashed()->scope(false, $this->id)->orderBy('created_at', 'DESC')->first();
|
||||
|
||||
if ($order)
|
||||
{
|
||||
$number = intval($order->invoice_number) + 1;
|
||||
$number = preg_replace("/[^0-9]/", "", $order->invoice_number);
|
||||
$number = intval($number) + 1;
|
||||
return str_pad($number, 4, "0", STR_PAD_LEFT);
|
||||
}
|
||||
else
|
||||
@ -106,4 +116,15 @@ class Account extends Eloquent
|
||||
return DEFAULT_INVOICE_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
public function loadLocalizationSettings()
|
||||
{
|
||||
$this->load('timezone', 'date_format', 'datetime_format');
|
||||
|
||||
Session::put(SESSION_TIMEZONE, $this->timezone ? $this->timezone->name : DEFAULT_TIMEZONE);
|
||||
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_DATETIME_FORMAT, $this->datetime_format ? $this->datetime_format->format : DEFAULT_DATETIME_FORMAT);
|
||||
Session::put(SESSION_CURRENCY, $this->currency_id ? $this->currency_id : DEFAULT_CURRENCY);
|
||||
}
|
||||
}
|
@ -234,6 +234,23 @@ class Activity extends Eloquent
|
||||
|
||||
public static function viewInvoice($invitation)
|
||||
{
|
||||
$invoice = $invitation->invoice;
|
||||
|
||||
if (!$invoice->isViewed())
|
||||
{
|
||||
$invoice->invoice_status_id = INVOICE_STATUS_VIEWED;
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
$now = Carbon::now()->toDateTimeString();
|
||||
|
||||
$invitation->viewed_date = $now;
|
||||
$invitation->save();
|
||||
|
||||
$client = $invoice->client;
|
||||
$client->last_login = $now;
|
||||
$client->save();
|
||||
|
||||
$activity = new Activity;
|
||||
$activity->user_id = $invitation->user_id;
|
||||
$activity->account_id = $invitation->user->account_id;
|
||||
|
@ -37,14 +37,14 @@ class Client extends EntityModel
|
||||
return $this->belongsTo('Country');
|
||||
}
|
||||
|
||||
public function client_size()
|
||||
public function size()
|
||||
{
|
||||
return $this->belongsTo('ClientSize');
|
||||
return $this->belongsTo('Size');
|
||||
}
|
||||
|
||||
public function client_industry()
|
||||
public function industry()
|
||||
{
|
||||
return $this->belongsTo('ClientIndustry');
|
||||
return $this->belongsTo('Industry');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
@ -2,5 +2,5 @@
|
||||
|
||||
class Country extends Eloquent
|
||||
{
|
||||
|
||||
protected $visible = ['id', 'name'];
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ClientSize extends Eloquent
|
||||
class Industry extends Eloquent
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
@ -69,9 +69,10 @@ class Invoice extends EntityModel
|
||||
|
||||
public function hidePrivateFields()
|
||||
{
|
||||
$this->setVisible(['invoice_number', 'discount', 'po_number', 'invoice_date', 'due_date', 'terms', 'currency_id', 'public_notes', 'amount', 'balance', 'invoice_items', 'client', 'tax_name', 'tax_rate']);
|
||||
$this->setVisible(['invoice_number', 'discount', 'po_number', 'invoice_date', 'due_date', 'terms', 'currency_id', 'public_notes', 'amount', 'balance', 'invoice_items', 'client', 'tax_name', 'tax_rate', 'account']);
|
||||
|
||||
$this->client->setVisible(['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'work_phone', 'payment_terms', 'contacts']);
|
||||
$this->client->setVisible(['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'work_phone', 'payment_terms', 'contacts', 'country']);
|
||||
$this->account->setVisible(['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'country']);
|
||||
|
||||
foreach ($this->invoice_items as $invoiceItem)
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ClientIndustry extends Eloquent
|
||||
class Size extends Eloquent
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
@ -16,7 +16,7 @@ class ContactMailer extends Mailer {
|
||||
|
||||
foreach ($invoice->invitations as $invitation)
|
||||
{
|
||||
$invitation->sent_date = Carbon::now()->toDateTimeString();
|
||||
$invitation->sent_date = \Carbon::now()->toDateTimeString();
|
||||
$invitation->save();
|
||||
|
||||
$data = array('link' => URL::to('view') . '/' . $invitation->invitation_key);
|
||||
|
@ -5,6 +5,29 @@ use Contact;
|
||||
|
||||
class ClientRepository
|
||||
{
|
||||
public function find($filter = null)
|
||||
{
|
||||
$query = \DB::table('clients')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('clients.account_id', '=', \Auth::user()->account_id)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email','clients.currency_id');
|
||||
|
||||
if ($filter)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.first_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.last_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('contacts.email', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function save($publicId, $data)
|
||||
{
|
||||
if ($publicId == "-1")
|
||||
@ -28,8 +51,8 @@ class ClientRepository
|
||||
$client->postal_code = trim($data['postal_code']);
|
||||
$client->country_id = $data['country_id'] ? $data['country_id'] : null;
|
||||
$client->private_notes = trim($data['private_notes']);
|
||||
$client->client_size_id = $data['client_size_id'] ? $data['client_size_id'] : null;
|
||||
$client->client_industry_id = $data['client_industry_id'] ? $data['client_industry_id'] : null;
|
||||
$client->size_id = $data['size_id'] ? $data['size_id'] : null;
|
||||
$client->industry_id = $data['industry_id'] ? $data['industry_id'] : null;
|
||||
$client->currency_id = $data['currency_id'] ? $data['currency_id'] : null;
|
||||
$client->payment_terms = $data['payment_terms'];
|
||||
$client->website = trim($data['website']);
|
||||
|
75
app/ninja/repositories/CreditRepository.php
Executable file
75
app/ninja/repositories/CreditRepository.php
Executable file
@ -0,0 +1,75 @@
|
||||
<?php namespace ninja\repositories;
|
||||
|
||||
use Credit;
|
||||
use Client;
|
||||
use Invoice;
|
||||
use Utils;
|
||||
|
||||
class CreditRepository
|
||||
{
|
||||
public function find($clientPublicId = null, $filter = null)
|
||||
{
|
||||
$query = \DB::table('credits')
|
||||
->join('clients', 'clients.id', '=','credits.client_id')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('clients.account_id', '=', \Auth::user()->account_id)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('credits.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('credits.public_id', 'clients.name as client_name', 'clients.public_id as client_public_id', 'credits.amount', 'credits.credit_date', 'credits.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email');
|
||||
|
||||
if ($clientPublicId)
|
||||
{
|
||||
$query->where('clients.public_id', '=', $clientPublicId);
|
||||
}
|
||||
|
||||
if ($filter)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function save($publicId = null, $input)
|
||||
{
|
||||
if ($publicId)
|
||||
{
|
||||
$credit = Credit::scope($publicId)->firstOrFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
$credit = Credit::createNew();
|
||||
}
|
||||
|
||||
$credit->client_id = Client::getPrivateId($input['client']);
|
||||
$credit->credit_date = Utils::toSqlDate($input['credit_date']);
|
||||
$credit->invoice_id = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
|
||||
$credit->amount = floatval($input['amount']);
|
||||
$credit->currency_id = $input['currency_id'] ? $input['currency_id'] : null;
|
||||
$credit->save();
|
||||
|
||||
return $credit;
|
||||
}
|
||||
|
||||
public function bulk($ids, $action)
|
||||
{
|
||||
$credits = Credit::scope($ids)->get();
|
||||
|
||||
foreach ($credits as $credit)
|
||||
{
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$credit->is_deleted = true;
|
||||
$credit->save();
|
||||
}
|
||||
|
||||
$credit->delete();
|
||||
}
|
||||
|
||||
return count($credits);
|
||||
}
|
||||
}
|
76
app/ninja/repositories/PaymentRepository.php
Executable file
76
app/ninja/repositories/PaymentRepository.php
Executable file
@ -0,0 +1,76 @@
|
||||
<?php namespace ninja\repositories;
|
||||
|
||||
use Payment;
|
||||
use Invoice;
|
||||
use Client;
|
||||
use Utils;
|
||||
|
||||
class PaymentRepository
|
||||
{
|
||||
public function find($clientPublicId = null, $filter = null)
|
||||
{
|
||||
$query = \DB::table('payments')
|
||||
->join('clients', 'clients.id', '=','payments.client_id')
|
||||
->leftJoin('invoices', 'invoices.id', '=','payments.invoice_id')
|
||||
->join('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->where('payments.account_id', '=', \Auth::user()->account_id)
|
||||
->where('payments.deleted_at', '=', null)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('contacts.is_primary', '=', true)
|
||||
->select('payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number', 'payments.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email');
|
||||
|
||||
if ($clientPublicId)
|
||||
{
|
||||
$query->where('clients.public_id', '=', $clientPublicId);
|
||||
}
|
||||
|
||||
if ($filter)
|
||||
{
|
||||
$query->where(function($query) use ($filter)
|
||||
{
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function save($publicId = null, $input)
|
||||
{
|
||||
if ($publicId)
|
||||
{
|
||||
$payment = Payment::scope($publicId)->firstOrFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
$payment = Payment::createNew();
|
||||
}
|
||||
|
||||
$payment->client_id = Client::getPrivateId($input['client']);
|
||||
$payment->invoice_id = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
|
||||
$payment->currency_id = $input['currency_id'] ? $input['currency_id'] : null;
|
||||
$payment->payment_date = Utils::toSqlDate($input['payment_date']);
|
||||
$payment->amount = floatval($input['amount']);
|
||||
$payment->save();
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
public function bulk($ids, $action)
|
||||
{
|
||||
$payments = Payment::scope($ids)->get();
|
||||
|
||||
foreach ($payments as $payment)
|
||||
{
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$payment->is_deleted = true;
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
$payment->delete();
|
||||
}
|
||||
|
||||
return count($payments);
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@
|
||||
{{ Former::text('state')->label('State/Province') }}
|
||||
{{ Former::text('postal_code') }}
|
||||
{{ Former::select('country_id')->addOption('','')->label('Country')
|
||||
->fromQuery($countries, 'name', 'id')->select($account ? $account->country_id : '') }}
|
||||
->fromQuery($countries, 'name', 'id') }}
|
||||
|
||||
</div>
|
||||
|
||||
@ -53,6 +53,13 @@
|
||||
{{ Former::text('last_name') }}
|
||||
{{ Former::text('email') }}
|
||||
{{ Former::text('phone') }}
|
||||
|
||||
{{ Former::legend('Additional Info') }}
|
||||
{{ Former::select('size_id')->addOption('','')->label('Size')
|
||||
->fromQuery($sizes, 'name', 'id') }}
|
||||
{{ Former::select('industry_id')->addOption('','')->label('Industry')
|
||||
->fromQuery($industries, 'name', 'id') }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -18,7 +18,8 @@
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
{{ Former::select('gateway_id')->label('Provider')->addOption('', '')->fromQuery($gateways, 'name', 'id')->onchange('setFieldsShown()'); }}
|
||||
{{ Former::select('gateway_id')->label('Provider')->addOption('', '')
|
||||
->fromQuery($gateways, 'name', 'id')->onchange('setFieldsShown()'); }}
|
||||
|
||||
@foreach ($gateways as $gateway)
|
||||
|
||||
@ -41,13 +42,13 @@
|
||||
|
||||
{{ Former::legend('Localization') }}
|
||||
{{ Former::select('currency_id')->addOption('','')->label('Currency')
|
||||
->fromQuery($currencies, 'name', 'id')->select($account->currency_id) }}
|
||||
->fromQuery($currencies, 'name', 'id') }}
|
||||
{{ Former::select('timezone_id')->addOption('','')->label('Timezone')
|
||||
->fromQuery($timezones, 'location', 'id')->select($account->timezone_id) }}
|
||||
->fromQuery($timezones, 'location', 'id') }}
|
||||
{{ Former::select('date_format_id')->addOption('','')->label('Date Format')
|
||||
->fromQuery($dateFormats, 'label', 'id')->select($account->date_format_id) }}
|
||||
->fromQuery($dateFormats, 'label', 'id') }}
|
||||
{{ Former::select('datetime_format_id')->addOption('','')->label('Date/Time Format')
|
||||
->fromQuery($datetimeFormats, 'label', 'id')->select($account->datetime_format_id) }}
|
||||
->fromQuery($datetimeFormats, 'label', 'id') }}
|
||||
|
||||
{{ Former::legend('Notifications') }}
|
||||
{{ Former::checkbox('notify_sent')->label(' ')->text('Email me when an invoice is <b>sent</b>') }}
|
||||
|
@ -15,7 +15,7 @@
|
||||
{{ Former::text('state') }}
|
||||
{{ Former::text('postal_code') }}
|
||||
{{ Former::select('country_id')->addOption('','')->label('Country')
|
||||
->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }}
|
||||
->fromQuery($countries, 'name', 'id') }}
|
||||
|
||||
|
||||
</div>
|
||||
|
@ -35,7 +35,7 @@
|
||||
{{ Former::text('state')->label('State/Province') }}
|
||||
{{ Former::text('postal_code') }}
|
||||
{{ Former::select('country_id')->addOption('','')->label('Country')
|
||||
->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }}
|
||||
->fromQuery($countries, 'name', 'id') }}
|
||||
|
||||
|
||||
</div>
|
||||
@ -68,10 +68,10 @@
|
||||
->fromQuery($paymentTerms, 'name', 'num_days') }}
|
||||
{{ Former::select('currency_id')->addOption('','')->label('Currency')
|
||||
->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) }}
|
||||
{{ Former::select('client_size_id')->addOption('','')->label('Size')
|
||||
->fromQuery($clientSizes, 'name', 'id')->select($client ? $client->client_size_id : '') }}
|
||||
{{ Former::select('client_industry_id')->addOption('','')->label('Industry')
|
||||
->fromQuery($clientIndustries, 'name', 'id')->select($client ? $client->client_industry_id : '') }}
|
||||
{{ Former::select('size_id')->addOption('','')->label('Size')
|
||||
->fromQuery($sizes, 'name', 'id') }}
|
||||
{{ Former::select('industry_id')->addOption('','')->label('Industry')
|
||||
->fromQuery($industries, 'name', 'id') }}
|
||||
{{ Former::textarea('private_notes') }}
|
||||
|
||||
|
||||
|
@ -87,10 +87,11 @@
|
||||
</ul>
|
||||
|
||||
<div class="navbar-form navbar-right">
|
||||
@if (!Auth::check() || !Auth::user()->registered)
|
||||
@if (Auth::check() && !Auth::user()->registered)
|
||||
{{ Button::sm_success_primary('Sign up', array('data-toggle'=>'modal', 'data-target'=>'#signUpModal')) }}
|
||||
@endif
|
||||
|
||||
@if (Auth::check())
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
@if (Auth::check() && Auth::user()->registered)
|
||||
@ -108,7 +109,8 @@
|
||||
<li class="divider"></li>
|
||||
<li>{{ link_to('#', 'Logout', array('onclick'=>'logout()')) }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
@ -292,7 +294,7 @@
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{{ URL::to('signup/validate') }}',
|
||||
data: 'email=' + $('form.signUpForm #email').val() + '&path={{ Request::path() }}',
|
||||
data: 'email=' + $('form.signUpForm #new_email').val() + '&path={{ Request::path() }}',
|
||||
success: function(result) {
|
||||
if (result == 'available') {
|
||||
$('.signUpForm').submit();
|
||||
|
@ -194,7 +194,36 @@
|
||||
|
||||
|
||||
@if ($invoice)
|
||||
{{ DropdownButton::normal('Download PDF',
|
||||
|
||||
<div id="relatedActions" style="text-align:left" class="btn-group">
|
||||
<button class=" btn-default btn" type="button">Download PDF</button>
|
||||
<button class=" btn-default btn dropdown-toggle" type="button" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:onDownloadClick()">Download PDF</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="javascript:onPaymentClick()">Create Payment</a></li>
|
||||
<li><a href="javascript:onCreditClick()">Create Credit</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="primaryActions" style="text-align:left" data-bind="css: $root.enable.save" class="btn-group">
|
||||
<button class=" btn-primary btn" type="button" data-bind="css: $root.enable.save">Save Invoice</button>
|
||||
<button class=" btn-primary btn dropdown-toggle" type="button" data-toggle="dropdown" data-bind="css: $root.enable.save">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:onSaveClick()">Save Invoice</a></li>
|
||||
<li><a href="javascript:onCloneClick()">Clone Invoice</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="javascript:onArchiveClick()">Archive Invoice</a></li>
|
||||
<li><a href="javascript:onDeleteClick()">Delete Invoice</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{{-- DropdownButton::normal('Download PDF',
|
||||
Navigation::links(
|
||||
array(
|
||||
array('Download PDF', "javascript:onDownloadClick()"),
|
||||
@ -203,9 +232,9 @@
|
||||
array('Create Credit', "javascript:onCreditClick()"),
|
||||
)
|
||||
)
|
||||
, array('id'=>'relatedActions', 'style'=>'text-align:left'))->split(); }}
|
||||
, array('id'=>'relatedActions', 'style'=>'text-align:left'))->split(); --}}
|
||||
|
||||
{{ DropdownButton::primary('Save Invoice',
|
||||
{{-- DropdownButton::primary('Save Invoice',
|
||||
Navigation::links(
|
||||
array(
|
||||
array('Save Invoice', "javascript:onSaveClick()"),
|
||||
@ -215,7 +244,7 @@
|
||||
array('Delete Invoice', "javascript:onDeleteClick()"),
|
||||
)
|
||||
)
|
||||
, array('id'=>'primaryActions', 'style'=>'text-align:left', 'data-bind'=>'css: $root.enable.save'))->split(); }}
|
||||
, array('id'=>'primaryActions', 'style'=>'text-align:left', 'data-bind'=>'css: $root.enable.save'))->split(); --}}
|
||||
@else
|
||||
{{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }}
|
||||
{{ Button::primary_submit('Save Invoice', array('data-bind'=>'css: $root.enable.save')) }}
|
||||
@ -289,10 +318,10 @@
|
||||
->fromQuery($paymentTerms, 'name', 'num_days') }}
|
||||
{{ Former::select('currency_id')->addOption('','')->label('Currency')->data_bind('value: currency_id')
|
||||
->fromQuery($currencies, 'name', 'id') }}
|
||||
{{ Former::select('client_size_id')->addOption('','')->label('Size')->data_bind('value: client_size_id')
|
||||
->fromQuery($clientSizes, 'name', 'id')->select($client ? $client->client_size_id : '') }}
|
||||
{{ Former::select('client_industry_id')->addOption('','')->label('Industry')->data_bind('value: client_industry_id')
|
||||
->fromQuery($clientIndustries, 'name', 'id')->select($client ? $client->client_industry_id : '') }}
|
||||
{{ Former::select('size_id')->addOption('','')->label('Size')->data_bind('value: size_id')
|
||||
->fromQuery($sizes, 'name', 'id') }}
|
||||
{{ Former::select('industry_id')->addOption('','')->label('Industry')->data_bind('value: industry_id')
|
||||
->fromQuery($industries, 'name', 'id') }}
|
||||
{{ Former::textarea('private_notes')->data_bind('value: private_notes') }}
|
||||
|
||||
|
||||
@ -388,10 +417,9 @@
|
||||
model.loadClient(clientMap[clientId]);
|
||||
} else {
|
||||
model.loadClient($.parseJSON(ko.toJSON(new ClientModel())));
|
||||
console.log('load blank client');
|
||||
}
|
||||
refreshPDF();
|
||||
}).trigger('change');
|
||||
}); //.trigger('change');
|
||||
|
||||
$('#terms, #public_notes, #invoice_number, #invoice_date, #due_date, #po_number, #discout, #currency_id').change(function() {
|
||||
refreshPDF();
|
||||
@ -401,8 +429,7 @@
|
||||
var countryId = parseInt($('input[name=country_id]').val(), 10);
|
||||
model.invoice().client().country_id(countryId);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@if ($client || $invoice)
|
||||
$('#invoice_number').focus();
|
||||
@else
|
||||
@ -435,14 +462,20 @@
|
||||
});
|
||||
|
||||
$('label.radio').addClass('radio-inline');
|
||||
|
||||
|
||||
applyComboboxListeners();
|
||||
|
||||
@if ($client)
|
||||
$input.trigger('change');
|
||||
@else
|
||||
refreshPDF();
|
||||
@endif
|
||||
|
||||
var client = model.invoice().client();
|
||||
setComboboxValue($('.client_select'),
|
||||
client.public_id(),
|
||||
client.name.display());
|
||||
|
||||
applyComboboxListeners();
|
||||
//refreshPDF();
|
||||
|
||||
});
|
||||
|
||||
function applyComboboxListeners() {
|
||||
@ -472,7 +505,8 @@
|
||||
}
|
||||
|
||||
function createInvoiceModel() {
|
||||
var invoice = ko.toJS(model).invoice;
|
||||
var invoice = ko.toJS(model).invoice;
|
||||
|
||||
@if (file_exists($account->getLogoPath()))
|
||||
invoice.image = "{{ HTML::image_data($account->getLogoPath()) }}";
|
||||
invoice.imageWidth = {{ $account->getLogoWidth() }};
|
||||
@ -490,7 +524,6 @@
|
||||
*/
|
||||
|
||||
function refreshPDF() {
|
||||
console.log("refreshPDF");
|
||||
var invoice = createInvoiceModel();
|
||||
var doc = generatePDF(invoice);
|
||||
var string = doc.output('datauristring');
|
||||
@ -655,7 +688,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
//console.log('i is %s', i);
|
||||
var rates = self.tax_rates().concat();
|
||||
rates.splice(i, 1);
|
||||
return rates;
|
||||
@ -776,18 +808,18 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isValid ? "enabled" : "disabled";
|
||||
});
|
||||
|
||||
self.enable.email = ko.computed(function() {
|
||||
var isValid = false;
|
||||
var sendTo = false;
|
||||
for (var i=0; i<self.invoice().client().contacts().length; i++) {
|
||||
var contact = self.invoice().client().contacts()[i];
|
||||
var client = self.invoice().client();
|
||||
for (var i=0; i<client.contacts().length; i++) {
|
||||
var contact = client.contacts()[i];
|
||||
if (isValidEmailAddress(contact.email())) {
|
||||
isValid = true;
|
||||
if (contact.send_invoice()) {
|
||||
if (contact.send_invoice() || client.contacts().length == 1) {
|
||||
sendTo = true;
|
||||
}
|
||||
} else {
|
||||
@ -806,6 +838,7 @@
|
||||
function InvoiceModel(data) {
|
||||
var self = this;
|
||||
this.client = ko.observable(data ? false : new ClientModel());
|
||||
self.account = {{ $account }};
|
||||
this.id = ko.observable('');
|
||||
self.discount = ko.observable('');
|
||||
self.frequency_id = ko.observable('');
|
||||
@ -983,8 +1016,8 @@
|
||||
self.state = ko.observable('');
|
||||
self.postal_code = ko.observable('');
|
||||
self.country_id = ko.observable('');
|
||||
self.client_size_id = ko.observable('');
|
||||
self.client_industry_id = ko.observable('');
|
||||
self.size_id = ko.observable('');
|
||||
self.industry_id = ko.observable('');
|
||||
self.currency_id = ko.observable('');
|
||||
self.website = ko.observable('');
|
||||
self.payment_terms = ko.observable(0);
|
||||
|
@ -10,9 +10,11 @@
|
||||
@section('content')
|
||||
|
||||
<div class="pull-right">
|
||||
{{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()', 'class' => 'btn-lg')) }}
|
||||
@if ($invoice->client->account->isGatewayConfigured())
|
||||
{{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()', 'class' => 'btn-lg')) }}
|
||||
{{ Button::primary_link(URL::to('payment/' . $invitation->invitation_key), 'Pay Now', array('class' => 'btn-lg pull-right')) }}
|
||||
@else
|
||||
{{ Button::primary('Download PDF', array('onclick' => 'onDownloadClick()', 'class' => 'btn-lg')) }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="clearfix"></div><p> </p>
|
||||
@ -29,7 +31,7 @@
|
||||
invoice.imageWidth = {{ $invoice->client->account->getLogoWidth() }};
|
||||
invoice.imageHeight = {{ $invoice->client->account->getLogoHeight() }};
|
||||
@endif
|
||||
var doc = generatePDF(invoice);
|
||||
var doc = generatePDF(invoice, true);
|
||||
var string = doc.output('datauristring');
|
||||
|
||||
if (isFirefox || isChrome) {
|
||||
|
@ -96,9 +96,7 @@
|
||||
}, 1000);
|
||||
})
|
||||
|
||||
window.onDatatableReady = function() {
|
||||
console.log('data loaded');
|
||||
|
||||
window.onDatatableReady = function() {
|
||||
$(':checkbox').click(function() {
|
||||
setArchiveEnabled();
|
||||
});
|
||||
|
16
composer.lock
generated
16
composer.lock
generated
@ -211,12 +211,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/barryvdh/laravel-debugbar.git",
|
||||
"reference": "d5d7097f3bfb54aa4ceca8375c371d1412cec6b9"
|
||||
"reference": "22f1751267e7a2714f0df74fe207623cc928c68b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/d5d7097f3bfb54aa4ceca8375c371d1412cec6b9",
|
||||
"reference": "d5d7097f3bfb54aa4ceca8375c371d1412cec6b9",
|
||||
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/22f1751267e7a2714f0df74fe207623cc928c68b",
|
||||
"reference": "22f1751267e7a2714f0df74fe207623cc928c68b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -248,7 +248,7 @@
|
||||
"profiler",
|
||||
"webprofiler"
|
||||
],
|
||||
"time": "2014-01-04 16:25:27"
|
||||
"time": "2014-01-05 20:29:11"
|
||||
},
|
||||
{
|
||||
"name": "chumper/datatable",
|
||||
@ -915,12 +915,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "956511d9ebbddabb6ab79b1ec074616308a93a50"
|
||||
"reference": "c472ca9b043c373230ded1363dd05d1478effca4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/956511d9ebbddabb6ab79b1ec074616308a93a50",
|
||||
"reference": "956511d9ebbddabb6ab79b1ec074616308a93a50",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/c472ca9b043c373230ded1363dd05d1478effca4",
|
||||
"reference": "c472ca9b043c373230ded1363dd05d1478effca4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1024,7 +1024,7 @@
|
||||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"time": "2014-01-05 16:10:41"
|
||||
"time": "2014-01-06 02:22:05"
|
||||
},
|
||||
{
|
||||
"name": "laravelbook/ardent",
|
||||
|
1
public/js/bootstrap-combobox.js
vendored
1
public/js/bootstrap-combobox.js
vendored
@ -326,7 +326,6 @@
|
||||
}
|
||||
|
||||
, keyup: function (e) {
|
||||
console.log('keyCode: %s', e.keyCode);
|
||||
switch(e.keyCode) {
|
||||
case 40: // down arrow
|
||||
case 39: // right arrow
|
||||
|
@ -5,15 +5,16 @@ var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Const
|
||||
var isChrome = !!window.chrome && !isOpera; // Chrome 1+
|
||||
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
|
||||
|
||||
function generatePDF(invoice) {
|
||||
function generatePDF(invoice, checkMath) {
|
||||
var client = invoice.client;
|
||||
var account = invoice.account;
|
||||
var currencyId = invoice.currency_id;
|
||||
var invoiceNumber = invoice.invoice_number;
|
||||
var invoiceDate = invoice.invoice_date ? invoice.invoice_date : '';
|
||||
var dueDate = invoice.due_date ? invoice.due_date : '';
|
||||
console.log("DueDate: %s", dueDate);
|
||||
var amount = '$0.00';
|
||||
|
||||
var marginLeft = 90;
|
||||
var accountTop = 30;
|
||||
var headerTop = 140;
|
||||
var headerLeft = 360;
|
||||
var headerRight = 540;
|
||||
@ -77,22 +78,49 @@ function generatePDF(invoice) {
|
||||
var poNumberX = headerRight - (doc.getStringUnitWidth(invoice.po_number) * doc.internal.getFontSize());
|
||||
|
||||
doc.setFontType("normal");
|
||||
if (invoice.client) {
|
||||
var y = headerTop;
|
||||
doc.text(marginLeft, y, getClientDisplayName(invoice.client));
|
||||
|
||||
var y = accountTop;
|
||||
var left = headerLeft;
|
||||
|
||||
if (account.name) {
|
||||
y += rowHeight;
|
||||
doc.text(marginLeft, y, invoice.client.address1);
|
||||
if (invoice.client.address2) {
|
||||
doc.text(left, y, account.name);
|
||||
}
|
||||
if (account.address1) {
|
||||
y += rowHeight;
|
||||
doc.text(left, y, account.address1);
|
||||
}
|
||||
if (account.address2) {
|
||||
y += rowHeight;
|
||||
doc.text(left, y, account.address2);
|
||||
}
|
||||
if (account.city || account.state || account.postal_code) {
|
||||
y += rowHeight;
|
||||
doc.text(left, y, account.city + ', ' + account.state + ' ' + account.postal_code);
|
||||
}
|
||||
if (account.country) {
|
||||
y += rowHeight;
|
||||
doc.text(left, y, account.country.name);
|
||||
}
|
||||
|
||||
if (client) {
|
||||
var y = headerTop;
|
||||
doc.text(marginLeft, y, getClientDisplayName(client));
|
||||
if (client.address1) {
|
||||
y += rowHeight;
|
||||
doc.text(marginLeft, y, invoice.client.address2);
|
||||
doc.text(marginLeft, y, client.address1);
|
||||
}
|
||||
if (invoice.client.city || invoice.client.state || invoice.client.postal_code) {
|
||||
if (client.address2) {
|
||||
y += rowHeight;
|
||||
doc.text(marginLeft, y, invoice.client.city + ', ' + invoice.client.state + ' ' + invoice.client.postal_code);
|
||||
doc.text(marginLeft, y, client.address2);
|
||||
}
|
||||
if (invoice.client.country) {
|
||||
if (client.city || client.state || client.postal_code) {
|
||||
y += rowHeight;
|
||||
doc.text(marginLeft, y, invoice.client.country.name);
|
||||
doc.text(marginLeft, y, client.city + ', ' + client.state + ' ' + client.postal_code);
|
||||
}
|
||||
if (client.country) {
|
||||
y += rowHeight;
|
||||
doc.text(marginLeft, y, client.country.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,11 +281,20 @@ function generatePDF(invoice) {
|
||||
var paidX = headerRight - (doc.getStringUnitWidth(paid) * doc.internal.getFontSize());
|
||||
doc.text(paidX, x, paid);
|
||||
|
||||
|
||||
x += 16;
|
||||
doc.setFontType("bold");
|
||||
doc.text(footerLeft, x, 'Balance Due');
|
||||
|
||||
if (checkMath && parseFloat(total) != parseFloat(invoice.amount))
|
||||
{
|
||||
var doc = new jsPDF('p', 'pt');
|
||||
doc.setFont('Helvetica','');
|
||||
doc.setFontSize(10);
|
||||
doc.text(100, 100, "An error occurred, please try again later.");
|
||||
onerror('Failed to generate PDF ' + total + ', ' + invoice.amount );
|
||||
return doc;
|
||||
}
|
||||
|
||||
var total = formatMoney(invoice.balance, currencyId);
|
||||
var totalX = headerRight - (doc.getStringUnitWidth(total) * doc.internal.getFontSize());
|
||||
doc.text(totalX, x, total);
|
||||
@ -265,6 +302,8 @@ function generatePDF(invoice) {
|
||||
totalX = headerRight - (doc.getStringUnitWidth(total) * doc.internal.getFontSize());
|
||||
doc.text(totalX, headerY, total);
|
||||
|
||||
|
||||
|
||||
/* payment stub */
|
||||
/*
|
||||
var y = 680;
|
||||
@ -771,12 +810,10 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
|
||||
$clientSelect.combobox();
|
||||
$clientSelect.on('change', function(e) {
|
||||
console.log('client change');
|
||||
var clientId = $('input[name=client]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
if (invoice && invoice.client.public_id == clientId) {
|
||||
console.log('values the same:' + $('select#client').prop('selected'))
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user