mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on UBL
This commit is contained in:
parent
0b0c8de042
commit
4fcf275255
@ -517,6 +517,9 @@ if (! defined('APP_NAME')) {
|
||||
define('PLAN_TERM_MONTHLY', 'month');
|
||||
define('PLAN_TERM_YEARLY', 'year');
|
||||
|
||||
define('SUBSCRIPTION_FORMAT_JSON', 'JSON');
|
||||
define('SUBSCRIPTION_FORMAT_UBL', 'UBL');
|
||||
|
||||
// Pro
|
||||
define('FEATURE_CUSTOMIZE_INVOICE_DESIGN', 'customize_invoice_design');
|
||||
define('FEATURE_REMOVE_CREATED_BY', 'remove_created_by');
|
||||
|
@ -24,6 +24,8 @@ class DashboardController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//dd(dispatch(new \App\Jobs\ConvertInvoiceToUbl(\App\Models\Invoice::first())));
|
||||
|
||||
$user = Auth::user();
|
||||
$viewAll = $user->hasPermission('view_all');
|
||||
$userId = $user->id;
|
||||
|
@ -154,6 +154,6 @@ class SubscriptionController extends BaseController
|
||||
Session::flash('message', $message);
|
||||
}
|
||||
|
||||
return Redirect::to('settings/' . ACCOUNT_API_TOKENS);
|
||||
return Redirect::to('subscriptions/' . $subscriptionPublicId . '/edit');
|
||||
}
|
||||
}
|
||||
|
123
app/Jobs/ConvertInvoiceToUbl.php
Normal file
123
app/Jobs/ConvertInvoiceToUbl.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Jobs\Job;
|
||||
use Sabre\Xml\Service;
|
||||
use CleverIt\UBL\Invoice\Invoice;
|
||||
use CleverIt\UBL\Invoice\Party;
|
||||
use CleverIt\UBL\Invoice\Address;
|
||||
use CleverIt\UBL\Invoice\Country;
|
||||
use CleverIt\UBL\Invoice\Contact;
|
||||
use CleverIt\UBL\Invoice\TaxTotal;
|
||||
use CleverIt\UBL\Invoice\TaxSubTotal;
|
||||
use CleverIt\UBL\Invoice\TaxCategory;
|
||||
use CleverIt\UBL\Invoice\InvoiceLine;
|
||||
use CleverIt\UBL\Invoice\Item;
|
||||
use CleverIt\UBL\Invoice\LegalMonetaryTotal;
|
||||
|
||||
class ConvertInvoiceToUbl extends Job
|
||||
{
|
||||
public function __construct($invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$xmlService = new Service();
|
||||
$xmlService->namespaceMap = [
|
||||
'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2' => '',
|
||||
'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' => 'cbc',
|
||||
'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' => 'cac'
|
||||
];
|
||||
|
||||
$invoice = $this->invoice;
|
||||
$account = $invoice->account;
|
||||
$client = $invoice->client;
|
||||
$ublInvoice = new Invoice();
|
||||
|
||||
// invoice
|
||||
$ublInvoice->setId($invoice->invoice_number);
|
||||
$ublInvoice->setIssueDate($invoice->invoice_date);
|
||||
$ublInvoice->setInvoiceTypeCode('SalesInvoice');
|
||||
|
||||
// account
|
||||
$supplierParty = new Party();
|
||||
$supplierParty->setName($account->name);
|
||||
$supplierAddress = (new Address())
|
||||
->setCityName($account->city)
|
||||
->setStreetName($account->address1)
|
||||
->setBuildingNumber($account->address2)
|
||||
->setPostalZone($account->postal_code);
|
||||
|
||||
if ($account->country_id) {
|
||||
$country = new Country();
|
||||
$country->setIdentificationCode($account->country->iso_3166_2);
|
||||
$supplierAddress->setCountry($country);
|
||||
}
|
||||
|
||||
$supplierParty->setPostalAddress($supplierAddress);
|
||||
$supplierParty->setPhysicalLocation($supplierAddress);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->setElectronicMail($invoice->user->email);
|
||||
$supplierParty->setContact($contact);
|
||||
|
||||
$ublInvoice->setAccountingSupplierParty($supplierParty);
|
||||
|
||||
// client
|
||||
$customerParty = new Party();
|
||||
$customerParty->setName($client->getDisplayName());
|
||||
$customerAddress = (new Address())
|
||||
->setCityName($client->city)
|
||||
->setStreetName($client->address1)
|
||||
->setBuildingNumber($client->address2)
|
||||
->setPostalZone($client->postal_code);
|
||||
|
||||
if ($client->country_id) {
|
||||
$country = new Country();
|
||||
$country->setIdentificationCode($client->country->iso_3166_2);
|
||||
$customerAddress->setCountry($client);
|
||||
}
|
||||
|
||||
$customerParty->setPostalAddress($customerAddress);
|
||||
$customerParty->setPhysicalLocation($customerAddress);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->setElectronicMail($client->contacts[0]->email);
|
||||
$customerParty->setContact($contact);
|
||||
|
||||
$ublInvoice->setAccountingCustomerParty($customerParty);
|
||||
|
||||
$taxtotal = (new \CleverIt\UBL\Invoice\TaxTotal())
|
||||
->setTaxAmount(10)
|
||||
->setTaxSubTotal((new \CleverIt\UBL\Invoice\TaxSubTotal())
|
||||
->setTaxAmount(10)
|
||||
->setTaxableAmount(100)
|
||||
->setTaxCategory((new \CleverIt\UBL\Invoice\TaxCategory())
|
||||
->setId("H")
|
||||
->setName("NL, Hoog Tarief")
|
||||
->setPercent(21.00)));
|
||||
|
||||
$invoiceLine = (new \CleverIt\UBL\Invoice\InvoiceLine())
|
||||
->setId(1)
|
||||
->setInvoicedQuantity(1)
|
||||
->setLineExtensionAmount(100)
|
||||
->setTaxTotal($taxtotal)
|
||||
->setItem((new \CleverIt\UBL\Invoice\Item())->setName("Test item")->setDescription("test item description")->setSellersItemIdentification("1ABCD"));
|
||||
|
||||
$ublInvoice->setInvoiceLines([$invoiceLine]);
|
||||
$ublInvoice->setTaxTotal($taxtotal);
|
||||
|
||||
$ublInvoice->setLegalMonetaryTotal((new \CleverIt\UBL\Invoice\LegalMonetaryTotal())
|
||||
->setLineExtensionAmount(100)
|
||||
->setTaxExclusiveAmount(100)
|
||||
->setPayableAmount(-1000)
|
||||
->setAllowanceTotalAmount(50));
|
||||
|
||||
return $xmlService->write('Invoice', [
|
||||
$ublInvoice
|
||||
]);
|
||||
}
|
||||
}
|
@ -254,19 +254,30 @@ class SubscriptionListener
|
||||
return;
|
||||
}
|
||||
|
||||
// generate JSON data
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$manager->parseIncludes($include);
|
||||
|
||||
$resource = new Item($entity, $transformer, $entity->getEntityType());
|
||||
$data = $manager->createData($resource)->toArray();
|
||||
$jsonData = $manager->createData($resource)->toArray();
|
||||
|
||||
// For legacy Zapier support
|
||||
if (isset($data['client_id'])) {
|
||||
$data['client_name'] = $entity->client->getDisplayName();
|
||||
if (isset($jsonData['client_id'])) {
|
||||
$jsonData['client_name'] = $entity->client->getDisplayName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($subscriptions as $subscription) {
|
||||
switch ($subscription->format) {
|
||||
case SUBSCRIPTION_FORMAT_JSON:
|
||||
$data = $jsonData;
|
||||
break;
|
||||
case SUBSCRIPTION_FORMAT_UBL:
|
||||
$data = $ublData;
|
||||
break;
|
||||
}
|
||||
self::notifySubscription($subscription, $data);
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class Subscription extends EntityModel
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'target_url',
|
||||
'format',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,8 @@ class SubscriptionRepository extends BaseRepository
|
||||
'subscriptions.public_id',
|
||||
'subscriptions.target_url as target',
|
||||
'subscriptions.event_id as event',
|
||||
'subscriptions.deleted_at'
|
||||
'subscriptions.deleted_at',
|
||||
'subscriptions.format'
|
||||
);
|
||||
|
||||
return $query;
|
||||
|
@ -25,6 +25,7 @@
|
||||
"barryvdh/laravel-ide-helper": "~2.2",
|
||||
"cerdic/css-tidy": "~v1.5",
|
||||
"chumper/datatable": "dev-develop#04ef2bf",
|
||||
"cleverit/ubl_invoice": "^0.1.1",
|
||||
"codedge/laravel-selfupdater": "5.x-dev",
|
||||
"collizo4sky/omnipay-wepay": "dev-address-fix",
|
||||
"digitickets/omnipay-gocardlessv2": "dev-payment-fix",
|
||||
|
517
composer.lock
generated
517
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSubscriptionFormat extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('subscriptions', function ($table) {
|
||||
$table->enum('format', ['JSON', 'UBL'])->default('JSON');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('subscriptions', function ($table) {
|
||||
$table->dropColumn('format');
|
||||
});
|
||||
}
|
||||
}
|
@ -2572,7 +2572,7 @@ $LANG = array(
|
||||
'optional_payment_methods' => 'Optional Payment Methods',
|
||||
'add_subscription' => 'Add Subscription',
|
||||
'target_url' => 'Target',
|
||||
'target_url_help' => 'When the selected event occurs the app will post the entity as JSON to the target URL.',
|
||||
'target_url_help' => 'When the selected event occurs the app will post the entity to the target URL.',
|
||||
'event' => 'Event',
|
||||
'subscription_event_1' => 'Created Client',
|
||||
'subscription_event_2' => 'Created Invoice',
|
||||
|
@ -7,6 +7,7 @@
|
||||
{!! Former::open($url)->method($method)->addClass('warn-on-exit')->rules(array(
|
||||
'event_id' => 'required',
|
||||
'target_url' => 'required|url',
|
||||
'format' => 'required',
|
||||
)); !!}
|
||||
|
||||
<div class="panel panel-default">
|
||||
@ -60,9 +61,15 @@
|
||||
->label('event') !!}
|
||||
|
||||
{!! Former::text('target_url')
|
||||
->help('target_url_help')
|
||||
->placeholder('https://example.com')!!}
|
||||
|
||||
{!! Former::select('format')
|
||||
->options([
|
||||
SUBSCRIPTION_FORMAT_JSON => SUBSCRIPTION_FORMAT_JSON,
|
||||
SUBSCRIPTION_FORMAT_UBL => SUBSCRIPTION_FORMAT_UBL
|
||||
])
|
||||
->help('target_url_help') !!}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user