PHP code example of codebar-ag / laravel-docuware

1. Go to this page and download the library: Download codebar-ag/laravel-docuware library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codebar-ag / laravel-docuware example snippets


'instances' => [
    'acme'   => ['grant' => 'credentials', 'url' => '…', 'username' => '…', 'password' => '…'],
    'globex' => ['grant' => 'token', 'url' => '…', 'token' => '…'],
],

DocuWare::instance('acme')->documents($cabinetId)->search()->get();

use CodebarAg\DocuWare\Facades\DocuWare;
use CodebarAg\DocuWare\Config\CredentialsConfig;

$client = DocuWare::connection(CredentialsConfig::for(
    url:      $tenant->docuware_url,
    username: $tenant->docuware_user,
    password: $tenant->docuware_secret,
    name:     $tenant->slug,            // namespaces this tenant's cache + token entry
));

$client->documents($cabinetId)->search()->fullText('invoice')->get();

use CodebarAg\DocuWare\Config\{CredentialsConfig, TokenConfig, TrustedUserConfig};

CredentialsConfig::for(url: '…', username: '…', password: '…', name: 'acme');
TokenConfig::for(url: '…', token: '…', name: 'globex');
TrustedUserConfig::for(url: '…', username: '…', password: '…', impersonate: 'bob', name: 'acme');

use CodebarAg\DocuWare\Facades\DocuWare;
use CodebarAg\DocuWare\Data\Documents\DocumentData;
use CodebarAg\DocuWare\Data\Write\IndexFields;
use CodebarAg\DocuWare\Enums\TargetFileType;

// Lazily iterate EVERY matching document across all pages (memory-safe).
DocuWare::documents($cabinetId)->search()
    ->fullText('invoice')
    ->where('STATUS', 'open')
    ->whereDateBetween('DWSTOREDATETIME', $from, $to)
    ->latest('DWSTOREDATETIME')
    ->cursor()
    ->each(fn (DocumentData $document) => /* … */);

$document = DocuWare::documents($cabinetId)->find($documentId);

$document = DocuWare::documents($cabinetId)->store(
    fileContent: file_get_contents('invoice.pdf'),
    fileName: 'invoice.pdf',
    indexes: IndexFields::make()->text('STATUS', 'open')->number('AMOUNT', 42),
);

DocuWare::documents($cabinetId)->update($documentId, IndexFields::make()->text('STATUS', 'closed'));
$pdf = DocuWare::documents($cabinetId)->download($documentId, TargetFileType::PDF);
DocuWare::documents($cabinetId)->delete($documentId);

DocuWare::fileCabinets()->all();                 // Collection<FileCabinetData>
DocuWare::fileCabinets()->info($cabinetId);      // FileCabinetInformationData
DocuWare::fileCabinets()->fields($cabinetId);    // Collection<FieldData> — the cabinet's index fields

DocuWare::dialogs($cabinetId)->all();            // Collection<DialogData>
DocuWare::dialogs($cabinetId)->ofType(DialogType::SEARCH);
DocuWare::dialogs($cabinetId)->find($dialogId);

DocuWare::selectLists($cabinetId)->get($dialogId, 'FIELD');
DocuWare::selectLists($cabinetId)->filtered($dialogId, 'FIELD', $expression);

DocuWare::organizations()->all();                // Collection<OrganizationData>
DocuWare::organizations()->loginToken($targetProducts, $usage, $lifetime);

DocuWare::users()->all();                        // Collection<UserData>
DocuWare::users()->find($userId);
DocuWare::users()->ofGroup($groupId);
DocuWare::users()->ofRole($roleId);
DocuWare::users()->create($user);                // UserInput
DocuWare::users()->update($user);
DocuWare::users()->addToGroup($userId, $groupIds);
DocuWare::users()->removeFromGroup($userId, $groupIds);
DocuWare::users()->addToRole($userId, $roleIds);
DocuWare::users()->removeFromRole($userId, $roleIds);
DocuWare::users()->groupsOf($userId);
DocuWare::users()->rolesOf($userId);

DocuWare::groups()->all();                       // Collection<GroupData>
DocuWare::roles()->all();                        // Collection<RoleData>

DocuWare::workflows()->historySteps($workflowId, $instanceId);  // InstanceHistoryData

DocuWare::trash()->search($page, $perPage, ...); // TrashPageData
DocuWare::trash()->delete($ids);                 // DeleteDocumentsData — purge permanently
DocuWare::trash()->restore($ids);                // RestoreDocumentsData — recover to the cabinet

DocuWare::documents($cabinetId)->search()
    ->fileCabinets([$cabinetId, $otherCabinetId])  // search across multiple cabinets
    ->dialog($searchDialogId)                       // optional explicit search dialog
    ->fullText('term')
    ->where('FIELD', 'value')
    ->whereIn('FIELD', ['a', 'b'])
    ->whereEmpty('FIELD')
    ->whereNotEmpty('FIELD')
    ->whereDate('DATE_FIELD', '>=', $carbon)
    ->whereDateBetween('DATE_FIELD', $from, $to)
    ->orderBy('FIELD', 'desc')        // or ->latest('FIELD') / ->oldest('FIELD')
    ->page(1)->perPage(50);

use CodebarAg\DocuWare\Data\Write\IndexFields;
use Illuminate\Support\Carbon;

$indexes = IndexFields::make()
    ->text('STATUS', 'open')            // String
    ->memo('NOTES', 'long text…')       // Memo
    ->keyword('TAGS', 'invoice')        // Keyword
    ->number('AMOUNT', 42)              // Int
    ->decimal('PRICE', 19.99)           // Decimal
    ->date('DUE', Carbon::today())      // date  → YYYY-MM-DD
    ->dateTime('SEEN', Carbon::now())   // datetime → YYYY-MM-DD HH:MM:SS
    ->table('POSITIONS', [              // Table → rows of typed cells
        ['ARTICLE' => 'Widget', 'QTY' => 5],
        ['ARTICLE' => 'Gadget', 'QTY' => 3],
    ]);

DocuWare::documents($cabinetId)->store(
    fileContent: file_get_contents('invoice.pdf'),
    fileName: 'invoice.pdf',
    indexes: $indexes,
);

DocuWare::documents($cabinetId)->update($documentId, IndexFields::make()->number('AMOUNT', 99));

use CodebarAg\DocuWare\Data\Write\IndexFields;
use Illuminate\Support\Carbon;

$fields = DocuWare::documents($cabinetId)->update(
    $documentId,
    IndexFields::make()
        ->text('STATUS', 'closed')
        ->number('AMOUNT', 99)
        ->decimal('PRICE', 19.99)
        ->date('DUE', Carbon::today())
        ->dateTime('SEEN', Carbon::now())
        // Table fields are replaced wholesale — pass the full set of rows you want stored:
        ->table('POSITIONS', [
            ['ARTICLE' => 'Widget', 'QTY' => 5],
            ['ARTICLE' => 'Gadget', 'QTY' => 3],
        ]),
    forceUpdate: true, // overwrite read-only/system-managed fields where the cabinet allows it
);

$fields['STATUS']->value; // 'closed'

  IndexFields::make()->table('POSITIONS', [
      ['ARTICLE' => 'Widget', 'QTY' => 5, 'PRICE' => 19.99],
      ['ARTICLE' => 'Gadget', 'QTY' => 3, 'PRICE' => 4.50],
  ]);
  

  use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;
  use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO;
  use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;

  IndexFields::make()->table('POSITIONS', [
      [
          IndexTextDTO::make('ARTICLE', 'Widget'),
          IndexNumericDTO::make('QTY', 5),
          IndexDateDTO::make('DELIVERED', Carbon::today()),
      ],
  ]);
  

$document = DocuWare::documents($cabinetId)->find($documentId);
$rows = $document->fields['POSITIONS']->value;   // Collection<TableRowData>

foreach ($rows as $row) {
    $row->fields['ARTICLE']->value;  // 'Widget' (string)
    $row->fields['QTY']->value;      // 5 (int)
}

$document = DocuWare::documents($cabinetId)->find($documentId);

foreach ($document->fields as $field) {
    $field->name;  // 'AMOUNT'
    $field->value; // 99 (int) — already parsed, no manual conversion
}

$user    = DocuWare::users()->find($id);
$updated = $user->copyWith(active: false);   // a new instance; $user is untouched
$array   = $user->toArray();                 // serialization for free

$url = DocuWare::url($url, $username, $password, $passphrase)
    ->fileCabinet($cabinetId)
    ->document($documentId)
    ->validUntil($carbon)   // optional expiry
    ->make();

use CodebarAg\DocuWare\Events\{ResponseReceived, TokenRefreshed};