Working on data import

This commit is contained in:
Hillel Coren 2015-12-10 12:57:51 +02:00
parent d98a185c04
commit ff139bc09c
8 changed files with 116 additions and 10 deletions

View File

@ -31,6 +31,12 @@ class BaseTransformer extends TransformerAbstract
return isset($this->maps['countries'][$name]) ? $this->maps['countries'][$name] : null;
}
protected function getCountryIdBy2($name)
{
$name = strtolower($name);
return isset($this->maps['countries2'][$name]) ? $this->maps['countries2'][$name] : null;
}
protected function getFirstName($name)
{
$name = Utils::splitName($name);

View File

@ -0,0 +1,34 @@
<?php namespace App\Ninja\Import\Invoiceable;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class ClientTransformer extends BaseTransformer
{
public function transform($data)
{
if ($this->hasClient($data->client_name)) {
return false;
}
return new Item($data, function ($data) {
return [
'name' => $data->client_name,
'work_phone' => $data->tel,
'website' => $data->website,
'address1' => $data->address,
'city' => $data->city,
'state' => $data->state,
'postal_code' => $data->postcode,
'country_id' => $this->getCountryIdBy2($data->country),
'private_notes' => $data->notes,
'contacts' => [
[
'email' => $data->email,
'phone' => $data->mobile,
],
],
];
});
}
}

View File

@ -0,0 +1,37 @@
<?php namespace App\Ninja\Import\Invoiceable;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class InvoiceTransformer extends BaseTransformer
{
public function transform($data)
{
if ( ! $this->getClientId($data->client_name)) {
return false;
}
if ($this->hasInvoice($data->ref)) {
return false;
}
return new Item($data, function ($data) {
return [
'client_id' => $this->getClientId($data->client_name),
'invoice_number' => $data->ref,
'po_number' => $data->po_number,
'invoice_date_sql' => $data->date,
'due_date_sql' => $data->due_date,
'invoice_footer' => $data->footer,
'paid' => (float) $data->paid,
'invoice_items' => [
[
'notes' => $data->description,
'cost' => (float) $data->total,
'qty' => 1,
]
],
];
});
}
}

View File

@ -0,0 +1,19 @@
<?php namespace App\Ninja\Import\Invoiceable;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class PaymentTransformer extends BaseTransformer
{
public function transform($data, $maps)
{
return new Item($data, function ($data) use ($maps) {
return [
'amount' => $data->paid,
'payment_date_sql' => $data->date_paid,
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];
});
}
}

View File

@ -36,7 +36,7 @@ class ImportService
IMPORT_FRESHBOOKS,
IMPORT_HARVEST,
IMPORT_HIVEAGE,
//IMPORT_INVOICEABLE,
IMPORT_INVOICEABLE,
//IMPORT_NUTCACHE,
//IMPORT_RONIN,
//IMPORT_WAVE,
@ -190,19 +190,25 @@ class ImportService
$clientMap = [];
$clients = $this->clientRepo->all();
foreach ($clients as $client) {
$clientMap[strtolower($client->name)] = $client->id;
if ($name = strtolower(trim($client->name))) {
$clientMap[$name] = $client->id;
}
}
$invoiceMap = [];
$invoices = $this->invoiceRepo->all();
foreach ($invoices as $invoice) {
$invoiceMap[strtolower($invoice->invoice_number)] = $invoice->id;
if ($number = strtolower(trim($invoice->invoice_number))) {
$invoiceMap[$number] = $invoice->id;
}
}
$countryMap = [];
$countryMap2 = [];
$countries = Cache::get('countries');
foreach ($countries as $country) {
$countryMap[strtolower($country->name)] = $country->id;
$countryMap2[strtolower($country->iso_3166_2)] = $country->id;
}
$currencyMap = [];
@ -215,6 +221,7 @@ class ImportService
ENTITY_CLIENT => $clientMap,
ENTITY_INVOICE => $invoiceMap,
'countries' => $countryMap,
'countries2' => $countryMap2,
'currencies' => $currencyMap,
];
}

View File

@ -62,14 +62,13 @@ There are two options:
### Frameworks/Libraries
* [laravel/laravel](https://github.com/laravel/laravel) - A PHP Framework For Web Artisans
* [twbs/bootstrap](https://github.com/twbs/bootstrap) - Sleek, intuitive, and powerful front-end framework for faster and easier web development.
* [jquery/jquery](https://github.com/jquery/jquery) - jQuery JavaScript Library
* [jquery/jquery-ui](https://github.com/jquery/jquery-ui) - The official jQuery user interface library
* [patricktalmadge/bootstrapper](https://github.com/patricktalmadge/bootstrapper) - Laravel Twitter Bootstrap Bundle
* [danielfarrell/bootstrap-combobox](https://github.com/danielfarrell/bootstrap-combobox) - A combobox plugin
* [jquery/jquery](https://github.com/jquery/jquery) - jQuery JavaScript Library
* [eternicode/bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker) - A datepicker for @twitter bootstrap
* [jquery/jquery-ui](https://github.com/jquery/jquery-ui) - The official jQuery user interface library
* [knockout/knockout](https://github.com/knockout/knockout) - Knockout makes it easier to create rich, responsive UIs with JavaScript
* [rniemeyer/knockout-sortable](https://github.com/rniemeyer/knockout-sortable) - A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
* [MrRio/jsPDF](https://github.com/MrRio/jsPDF) - Generate PDF files in JavaScript. HTML5 FTW.
* [bpampuch/pdfmake](https://github.com/bpampuch/pdfmake) - Client/server side PDF printing in pure JavaScript
* [FortAwesome/Font-Awesome](https://github.com/FortAwesome/Font-Awesome) - The iconic font designed for Bootstrap that works with twitter bootstrap
* [Anahkiasen/former](https://github.com/Anahkiasen/former) - A powerful form builder, for Laravel and other frameworks (stand-alone too)
@ -92,3 +91,4 @@ There are two options:
* [simshaun/recurr](https://github.com/simshaun/recurr) - PHP library for working with recurrence rules
* [quilljs/quill](https://github.com/quilljs/quill/) - A cross browser rich text editor with an API
* [Maatwebsite/Laravel-Excel](https://github.com/Maatwebsite/Laravel-Excel) - An eloquent way of importing and exporting Excel and CSV files for Laravel
* [thephpleague/fractal](https://github.com/thephpleague/fractal) - Output complex, flexible, AJAX/RESTful data structures

View File

@ -3,6 +3,7 @@
@section('head')
@parent
@include('money_script')
<link href="{{ asset('css/quill.snow.css') }}" rel="stylesheet" type="text/css"/>
<script src="{{ asset('js/quill.min.js') }}" type="text/javascript"></script>

View File

@ -88,11 +88,13 @@
<span data-bind="html: email.display"></span>
</label>
<span data-bind="html: $data.view_as_recipient"></span>&nbsp;&nbsp;
@if (Utils::isConfirmed())
<span style="vertical-align:text-top;color:red" class="fa fa-exclamation-triangle"
data-bind="visible: $data.email_error, tooltip: {title: $data.email_error}"></span>
<span style="vertical-align:text-top" class="glyphicon glyphicon-info-sign"
data-bind="visible: $data.invitation_status, tooltip: {title: $data.invitation_status, html: true},
style: {color: $data.hasOwnProperty('invitation_viewed') &amp;&amp; $data.invitation_viewed() ? '#57D172':'#B1B5BA'}"></span>
@endif
</div>
</div>
</div>
@ -173,10 +175,10 @@
<thead>
<tr>
<th style="min-width:32px;" class="hide-border"></th>
<th style="min-width:160px" data-bind="text: productLabel"></th>
<th style="min-width:160px" data-bind="text: productLabel">{{ $invoiceLabels['item'] }}</th>
<th style="width:100%">{{ $invoiceLabels['description'] }}</th>
<th style="min-width:120px" data-bind="text: costLabel"></th>
<th style="{{ $account->hide_quantity ? 'display:none' : 'min-width:120px' }}" data-bind="text: qtyLabel"></th>
<th style="min-width:120px" data-bind="text: costLabel">{{ $invoiceLabels['unit_cost'] }}</th>
<th style="{{ $account->hide_quantity ? 'display:none' : 'min-width:120px' }}" data-bind="text: qtyLabel">{{ $invoiceLabels['quantity'] }}</th>
<th style="min-width:120px;display:none;" data-bind="visible: $root.invoice_item_taxes.show">{{ trans('texts.tax') }}</th>
<th style="min-width:120px;">{{ trans('texts.line_total') }}</th>
<th style="min-width:32px;" class="hide-border"></th>