Git Product home page Git Product logo

wfirma's Introduction

wFirma API

High level implementation of wFirma API. Provides object oriented SDK to operate on the most of wFirma modules.

Installation

Use composer:

composer require webit/w-firma-api

For PHP 5.4 and 7.0 use ^1.0 version.

Usage

The current version of the package provides full support for the following modules:

Configure Annotation Registry

This is not needed if you use AnnotationRegistry 2.0.

<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = include __DIR__.'/vendor/autoload.php'; // composer's autoload.php
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

Authentication

The library supports only BasicAuth.

BasicAuth

<?php
use Webit\WFirmaSDK\Auth\BasicAuth;

$auth = new BasicAuth('your-user-name', 'your-password', $companyId = 1123); // $companyId is optional

ApiFactory

In order to create API for given module use ModuleApiFactory.

<?php

use Webit\WFirmaSDK\Entity\ModuleApiFactory;
use Webit\WFirmaSDK\Entity\EntityApiFactory;

$entityApiFactory = new EntityApiFactory();
$entityApi = $entityApiFactory->create($auth);

$apiFactory = new ModuleApiFactory($entityApi);

Module APIs

Every main module has it's own instance of the API exposing supported methods.

  • Company Accounts: find, findAll, get, count,
  • Contractors: add, edit, delete, find, findAll, get, count
  • Declaration Countries: find, findAll, get, count
  • Invoice Deliveries: add, delete, find, findAll, get, count
  • Invoice Descriptions: find, findAll, get, count
  • Invoices: add, edit, delete, find, findAll, get, count, fiscalise, unfiscalise, download, send
  • Payments: add, edit, delete, find, findAll, get
  • Notes: add, edit, delete, find, findAll, get, count
  • Series: add, edit, delete, find, findAll, get, count
  • Tags: add, edit, delete, find, findAll, get, count
  • TranslationLanguages: find, findAll, get, count
  • VatCodes: find, findAll, get, count

Find / FindAll / Count APIs

APIs exposing find / findAll / count method takes and optional Parameters argument.

<?php
use Webit\WFirmaSDK\Entity\Parameters\Parameters;
use Webit\WFirmaSDK\Entity\Parameters\Order;
use Webit\WFirmaSDK\Entity\Parameters\Pagination;
use Webit\WFirmaSDK\Entity\Parameters\Fields;
use \Webit\WFirmaSDK\Entity\Parameters\Conditions;
use \Webit\WFirmaSDK\Entity\Parameters\Condition;

$conditions = Conditions::fromOrConditions(
    Condition::eq('id', '123'),
    Condition::eq('id', '456'),
    Condition::eq('id', '789')
);
$conditions->addAndConditions(
    Condition::le('alreadypaid', '300')
);
$parameters = Parameters::findParameters(
    $conditions,
    Order::ascending("name")->thenDescending("created"), // optional - ordering
    Pagination::create(20, 2), // optional - limit, page no
    Fields::fromArray(array("id", "name")) // optional - subset of fields to select
);

$seriesApi = $apiFactory->seriesApi();

$series = $seriesApi->find($parameters); // returns array of 20 Series (page 2)

// returns EntityIterator, allows to iterate over all the matching Series loaded in batches of 20
$series = $seriesApi->findAll($parameters);
/**
* @var int $i
* @var \Webit\WFirmaSDK\Series\Series $seriesItem */
foreach ($series as $i => $seriesItem) {
    // do some stuff on ALL the matching elements
}

$seriesCount = $seriesApi->count($parameters); // return number of matching series

InvoicesApi

<?php
use Webit\WFirmaSDK\Contractors\Contractor;
use Webit\WFirmaSDK\Contractors\InvoiceAddress;
use Webit\WFirmaSDK\Invoices\InvoicesContent;
use Webit\WFirmaSDK\Goods\GoodId;

/** @var \Webit\WFirmaSDK\Invoices\InvoicesApi $api */
$api = $apiFactory->invoicesApi();

// add a new invoice
$invoice = \Webit\WFirmaSDK\Invoices\Invoice::forContractor(
    new Contractor(
        'client name',
        'alt name',
        '1234565432', // vat no
        null, // regon
        new InvoiceAddress(
            'ul. Mokra 12',
            '01-006',
            'Warszawa',
            'PL'
        )
    )
);

$invoice->addInvoiceContent(
    InvoicesContent::fromGoodId(
        GoodId::create(123),
        3,
        123.32,
        23
    )
);

$invoice->addInvoiceContent(
    InvoicesContent::fromName(
        'some stuff',
        'szt.',
        3,
        123.32,
        23
    )
);

$invoice = $api->add($invoice);

// get invoice by id
$invoice = $api->get(\Webit\WFirmaSDK\Invoices\InvoiceId::create(123));

// edit the invoice
$invoice->changePayment(
    $invoice->payment()->withPaymentDate(new \DateTime())
);

// do some more edits
$invoice = $api->edit($invoice);

// delete the invoice
$api->delete($invoice->id());

ContractorsApi

<?php
use Webit\WFirmaSDK\Contractors\Contractor;

/** @var \Webit\WFirmaSDK\Contractors\ContractorsApi $api */
$api = $apiFactory->contractorsApi($auth);

// add a new contractor
$contractor = new Contractor('my-new-contractor');
$contractor = $api->add($contractor);

// edit the contractor
$contractor->rename('new name', 'new alt name');
$contractor = $api->edit($contractor);

// delete the contractor
$api->delete($contractor->id());

// get contractor by id
$contractor = $api->get(\Webit\WFirmaSDK\Contractors\ContractorId::create(123));

Further development

Feel free to add any other modules support. Also filtering by Conditions is not supported yet - any help is welcome.

Tests

cp phpunit.xml.dist phpunit.xml
vim phpunit.xml // edit your username and password

docker-compose run --rm composer
docker-compose run --rm phpunit

wfirma's People

Contributors

dbojdo8x8 avatar jacekkow avatar dbojdo avatar qrzysio avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.