mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 12:04:35 -04:00
Importing invoices
This commit is contained in:
parent
ccde0eaced
commit
c1edc905db
@ -52,13 +52,7 @@ class StoreInvoiceRequest extends Request
|
|||||||
|
|
||||||
$rules['invitations.*.client_contact_id'] = 'distinct';
|
$rules['invitations.*.client_contact_id'] = 'distinct';
|
||||||
|
|
||||||
// if ($this->input('number')) {
|
$rules['number'] = ['nullable',Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)];
|
||||||
// $rules['number'] = 'unique:invoices,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
|
|
||||||
// }
|
|
||||||
if ($this->input('number')) {
|
|
||||||
$rules['number'] = Rule::unique('invoices')->where('company_id', auth()->user()->company()->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];
|
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Import\Transformers;
|
namespace App\Import\Transformers;
|
||||||
|
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
|
use App\Utils\Number;
|
||||||
use Carbon;
|
use Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@ -68,8 +69,7 @@ class BaseTransformer
|
|||||||
|
|
||||||
public function getClient($client_name, $client_email)
|
public function getClient($client_name, $client_email)
|
||||||
{
|
{
|
||||||
info("search for {$client_name}");
|
|
||||||
|
|
||||||
$clients = $this->maps['company']->clients;
|
$clients = $this->maps['company']->clients;
|
||||||
|
|
||||||
$clients = $clients->where('name', $client_name);
|
$clients = $clients->where('name', $client_name);
|
||||||
@ -81,13 +81,8 @@ class BaseTransformer
|
|||||||
$contacts = ClientContact::where('company_id', $this->maps['company']->id)
|
$contacts = ClientContact::where('company_id', $this->maps['company']->id)
|
||||||
->where('email', $client_email);
|
->where('email', $client_email);
|
||||||
|
|
||||||
info("search for {$client_email}");
|
|
||||||
|
|
||||||
if($contacts->count() >=1)
|
if($contacts->count() >=1)
|
||||||
return $contacts->first()->client_id;
|
return $contacts->first()->client_id;
|
||||||
|
|
||||||
|
|
||||||
info("no client found!!");
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -152,8 +147,14 @@ class BaseTransformer
|
|||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getFloat($data, $field)
|
public function getFloat($data, $field)
|
||||||
{
|
{
|
||||||
return (isset($data->$field) && $data->$field) ? Utils::parseFloat($data->$field) : 0;
|
|
||||||
|
if(array_key_exists($field, $data))
|
||||||
|
$number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
|
||||||
|
else
|
||||||
|
$number = 0;
|
||||||
|
|
||||||
|
return Number::parseStringFloat($number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@ use App\Repositories\ClientContactRepository;
|
|||||||
use App\Repositories\ClientRepository;
|
use App\Repositories\ClientRepository;
|
||||||
use App\Repositories\InvoiceRepository;
|
use App\Repositories\InvoiceRepository;
|
||||||
use App\Repositories\ProductRepository;
|
use App\Repositories\ProductRepository;
|
||||||
|
use App\Utils\Traits\CleanLineItems;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -44,7 +45,7 @@ use League\Csv\Statement;
|
|||||||
|
|
||||||
class CSVImport implements ShouldQueue
|
class CSVImport implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, CleanLineItems;
|
||||||
|
|
||||||
public $invoice;
|
public $invoice;
|
||||||
|
|
||||||
@ -118,16 +119,10 @@ class CSVImport implements ShouldQueue
|
|||||||
|
|
||||||
$invoice_transformer = new InvoiceTransformer($this->maps);
|
$invoice_transformer = new InvoiceTransformer($this->maps);
|
||||||
|
|
||||||
info("import invoices");
|
|
||||||
|
|
||||||
info("column_map");
|
|
||||||
|
|
||||||
$records = $this->getCsvData();
|
$records = $this->getCsvData();
|
||||||
|
|
||||||
$invoice_number_key = array_search('Invoice Number', reset($records));
|
$invoice_number_key = array_search('Invoice Number', reset($records));
|
||||||
|
|
||||||
info("number key = {$invoice_number_key}");
|
|
||||||
|
|
||||||
if ($this->skip_header)
|
if ($this->skip_header)
|
||||||
array_shift($records);
|
array_shift($records);
|
||||||
|
|
||||||
@ -146,7 +141,6 @@ class CSVImport implements ShouldQueue
|
|||||||
|
|
||||||
foreach($unique_invoices as $unique)
|
foreach($unique_invoices as $unique)
|
||||||
{
|
{
|
||||||
info("inside item loop {$unique}");
|
|
||||||
|
|
||||||
$invoices = array_filter($records, function($value) use($invoice_number_key, $unique){
|
$invoices = array_filter($records, function($value) use($invoice_number_key, $unique){
|
||||||
return $value[$invoice_number_key] == $unique;
|
return $value[$invoice_number_key] == $unique;
|
||||||
@ -181,7 +175,7 @@ class CSVImport implements ShouldQueue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice['line_items'] = $items;
|
$invoice['line_items'] = $this->cleanItems($items);
|
||||||
|
|
||||||
$validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules());
|
$validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules());
|
||||||
|
|
||||||
@ -235,8 +229,6 @@ class CSVImport implements ShouldQueue
|
|||||||
//clients
|
//clients
|
||||||
$records = $this->getCsvData();
|
$records = $this->getCsvData();
|
||||||
|
|
||||||
info(print_r($this->column_map,1));
|
|
||||||
|
|
||||||
$contact_repository = new ClientContactRepository();
|
$contact_repository = new ClientContactRepository();
|
||||||
$client_repository = new ClientRepository($contact_repository);
|
$client_repository = new ClientRepository($contact_repository);
|
||||||
$client_transformer = new ClientTransformer($this->maps);
|
$client_transformer = new ClientTransformer($this->maps);
|
||||||
@ -278,7 +270,7 @@ info(print_r($this->column_map,1));
|
|||||||
|
|
||||||
private function importProduct()
|
private function importProduct()
|
||||||
{
|
{
|
||||||
info("importing products");
|
|
||||||
$product_repository = new ProductRepository();
|
$product_repository = new ProductRepository();
|
||||||
$product_transformer = new ProductTransformer($this->maps);
|
$product_transformer = new ProductTransformer($this->maps);
|
||||||
|
|
||||||
|
@ -70,6 +70,20 @@ class Number
|
|||||||
return (float) $s;
|
return (float) $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function parseStringFloat($value)
|
||||||
|
{
|
||||||
|
$value = preg_replace('/[^0-9-.]+/', '', $value);
|
||||||
|
|
||||||
|
// check for comma as decimal separator
|
||||||
|
if (preg_match('/,[\d]{1,2}$/', $value)) {
|
||||||
|
$value = str_replace(',', '.', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = preg_replace('/[^0-9\.\-]/', '', $value);
|
||||||
|
|
||||||
|
return floatval($value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a given value based on the clients currency AND country.
|
* Formats a given value based on the clients currency AND country.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user