예제 #1
0
require "../vendor/autoload.php";
// create the invoice
$invoice = new \ClearBooks\Invoice();
$invoice->creditTerms = 30;
$invoice->dateCreated = date('Y-m-d');
$invoice->dateDue = date('Y-m-d', strtotime('+28 days'));
$invoice->description = 'API Test Invoice';
$invoice->entityId = 16;
$invoice->status = 'approved';
$invoice->type = 'sales';
// add an item to the invoice
$item = new \ClearBooks\Item();
$item->description = 'Line Item #1';
$item->quantity = 1;
$item->type = 1001001;
$item->unitPrice = number_format(29.99 / 1.2, 2);
$item->vatRate = '0.2';
$invoice->items[] = $item;
$client = new \ClearBooks\Client('demo');
$invoiceReturn = $client->createInvoice($invoice);
print_r($invoiceReturn);
/*
Clearbooks_Soap_1_0_InvoiceReturn Object
(
    [due] => 29.99
    [invoice_id] => 211
    [invoice_prefix] => INV
    [invoice_number] => 201
)
*/
예제 #2
0
<?php

require "../vendor/autoload.php";
// create the entity
$entity = new \ClearBooks\Entity();
$entity->address1 = '107 Hammersmith Road';
$entity->address2 = 'West Kensington';
$entity->building = 'Master\'s House';
$entity->company_name = 'Clear Books';
$entity->email = '*****@*****.**';
$entity->postcode = 'W14 0QH';
$entity->town = 'London';
$entity->website = 'http://www.clearbooks.co.uk';
// indicate that the entity is a supplier - an entity must be a customer, supplier or both
$entity->supplier = new \ClearBooks\EntityExtra();
$client = new \ClearBooks\Client('demo');
$entityId = $client->createEntity($entity);
print_r($entityId);
/*
32
*/
예제 #3
0
<?php

require "../vendor/autoload.php";
// create the payment
$payment = new \ClearBooks\Payment();
$payment->amount = 29.99;
$payment->accountingDate = date('Y-m-d');
$payment->bankAccount = 7502001;
$payment->description = 'Invoice Payment';
$payment->entityId = 22;
$payment->invoices = 212;
$payment->paymentMethod = 1;
$payment->type = 'sales';
$client = new \ClearBooks\Client('demo');
$paymentReturn = $client->createPayment($payment);
print_r($paymentReturn);
/*
Clearbooks_Soap_1_0_PaymentReturn Object
(
    [payment_id] => 618
)
*/
<?php

require "../vendor/autoload.php";
$client = new \ClearBooks\Client('demo');
$outstandingBalances = $client->listOutstandingBalances('sales');
var_dump($outstandingBalances);
/*
Array
(
    [0] => Clearbooks_Soap_1_0_ListOutstandingBalancesReturn Object
        (
            [entity] => 16
            [balance] => 6608.66
        )

    [1] => Clearbooks_Soap_1_0_ListOutstandingBalancesReturn Object
        (
            [entity] => 17
            [balance] => 3842.25
        )

    [2] => Clearbooks_Soap_1_0_ListOutstandingBalancesReturn Object
        (
            [entity] => 20
            [balance] => 2469.91
        )

    [3] => Clearbooks_Soap_1_0_ListOutstandingBalancesReturn Object
        (
            [entity] => 18
            [balance] => 1982.6
예제 #5
0
<?php

require "../vendor/autoload.php";
// create the project
$project = new \ClearBooks\Project();
$project->description = 'Costs related to Search Engine Optimization';
$project->projectName = 'SEO';
$project->status = 'open';
$client = new \ClearBooks\Client('demo');
$projectReturn = $client->createProject($project);
print_r($projectReturn);
/*
Clearbooks_Soap_1_0_ProjectReturn Object
(
    [project_id] => 6
)
*/
예제 #6
0
<?php

require "../vendor/autoload.php";
// create the credit query
$creditQuery = new \ClearBooks\CreditQuery();
$creditQuery->accountCode = 7501001;
$creditQuery->dateCreated = date('Y-m-d');
$creditQuery->description = 'Invoice Write Off';
$creditQuery->id = 213;
$creditQuery->ledger = 'sales';
$client = new \ClearBooks\Client('demo');
$creditResponseStatus = $client->writeOff($creditQuery);
var_dump($creditResponseStatus);
/*
Clearbooks_Soap_1_0_CreditResponseStatus Object
(
    [id] => 213
    [msg] => Credit applied against invoice
)
*/
<?php

require "../vendor/autoload.php";
$client = new \ClearBooks\Client('demo');
// the paypal bank account
$paypalBankAccount = 7502004;
// the paypal entity id
$paypalEntityId = 12;
// the amount received by paypal
$received = 1150;
// the sales invoice id to apply the payment to
$salesInvoiceId = 189;
// fetch the original invoice
$invoiceQuery = new \ClearBooks\InvoiceQuery();
$invoiceQuery->id[] = $salesInvoiceId;
$invoiceQuery->ledger = 'sales';
$invoiceQuery->status = 'approved';
$invoices = $client->listInvoices($invoiceQuery);
if (!$invoices) {
    throw new \Exception('Invoice not found');
}
$invoice = $invoices[0];
// calculate the invoice total
$total = 0;
array_walk($invoice->items, function ($item) use(&$total) {
    /** @var $item \Clearbooks_Soap_1_0_item */
    $total += $item->unitPrice + $item->vat;
});
// the paypal fee is the amount received minus the invoice total (1150 - 1200 = -50)
$fee = $received - $total;
// create an invoice for the paypal fee
예제 #8
0
<?php

require "../vendor/autoload.php";
// construct a query to filter returned invoices
$entityQuery = new \ClearBooks\EntityQuery();
$entityQuery->id[] = 8;
$entityQuery->type = 'supplier';
$client = new \ClearBooks\Client('demo');
// execute the command
$entities = $client->listEntities($entityQuery);
print_r($entities);
/*
Array
(
    [0] => Clearbooks_Soap_1_0_Entity Object
        (
            [supplier] => Clearbooks_Soap_1_0_EntityExtra Object
                (
                    [default_account_code] => 0
                    [default_vat_rate] => 0.2
                    [default_credit_terms] => 0
                )

            [customer] => Clearbooks_Soap_1_0_EntityExtra Object
                (
                    [default_account_code] => 0
                    [default_vat_rate] => 0.00:Out
                    [default_credit_terms] => 30
                )

            [bankAccount] => Clearbooks_Soap_1_0_BankAccount Object
<?php

require "../vendor/autoload.php";
$client = new \ClearBooks\Client('demo');
// construct a query to filter returned invoices
$invoiceQuery = new \ClearBooks\InvoiceQuery();
// find invoices that were created or had a payment applied within the last week
$invoiceQuery->modifiedSince = date('Y-m-d', strtotime('-1 week'));
// look in the sales ledger
$invoiceQuery->ledger = 'sales';
// exclude voided invoices
$invoiceQuery->status = 'valid';
$invoices = array();
for ($i = 0; true; $i += 100) {
    $invoiceQuery->offset = $i;
    // get the next batch of invoices
    $batch = $client->listInvoices($invoiceQuery);
    // filter invoices by status
    array_walk($batch, function ($invoice) use(&$invoices) {
        /** @var $invoice Clearbooks_Soap_1_0_Invoice */
        $status = $invoice->status;
        if ($status == 'approved' && strtotime($invoice->dateDue) <= mktime(0, 0, 0)) {
            $status = 'unpaid';
        }
        $invoices[$status][] = $invoice;
    });
    // exit the loop if there are no more invoices to retrieve
    if (count($batch) < 100) {
        break;
    }
}
예제 #10
0
<?php

require "../vendor/autoload.php";
// construct the request
$request = new \ClearBooks\ExchangeRateRequest();
$request->baseCurrency = 'GBP';
// default
$request->targetCurrency = 'USD';
$request->date = '2012-10-05';
$client = new \ClearBooks\Client('demo');
$rate = $client->getExchangeRate($request);
print_r($rate);
/*
1.6184948525068
*/
<?php

require "../vendor/autoload.php";
$client = new \ClearBooks\Client('demo');
$entityOutstandingBalance = $client->getEntityOutstandingBalance(16, 'sales');
print_r($entityOutstandingBalance);
/*
Clearbooks_Soap_1_0_EntityOutstandingBalance Object
(
    [outstanding] => 6578.67
    [overdue] => 6548.68
)
*/
<?php

require "../vendor/autoload.php";
$client = new \ClearBooks\Client('demo');
$bankAccounts = $client->listBankAccounts();
var_dump($bankAccounts);
예제 #13
0
<?php

require "../vendor/autoload.php";
// create the payment
$payment = new \ClearBooks\RemovePayment();
$payment->id = 620;
$payment->type = "sales";
$client = new \ClearBooks\Client('demo');
$paymentReturn = $client->voidPayment($payment);
var_dump($paymentReturn);
/*
Clearbooks_Soap_1_0_ResponseStatus Object
(
    [success] => 1
    [msg] => Voiding this payment was successful
)
*/