Function updateInvoiceItem

Description

Updates an existing invoice line item. Automatically recalculates values and updates invoice totals.

Calculation method

  • Algorithm: Method 2 (WARTOSC_NETTO ร— vatRate = KWOTA_VAT, then BRUTTO = NETTO + VAT)
  • VAT summary: Sum of partial VAT amounts from items
  • Rounding: Polish method (standard mathematical rounding)

Important notes

  • All fields are optional (except idItem) - only provided fields are updated
  • Missing fields retain their current values from the database
  • quantity is stored as value ร— 100 (e.g., 0.5 pieces = 50)
  • All prices and values are in grosze (cents) - multiply by 100
  • Invoice totals (RAPORT_*, DO_ZAPLATY_*, SLOWNIE) are updated automatically
  • Cannot update items on invoices already sent to KSEF
  • When changing quantity, priceNetto, priceBrutto, or vatRate - values are recalculated

Arguments

  • params :
        array (
              // === REQUIRED ===
              
              [ 'idItem' ] = string,           // Item ID (32 char GUID from createInvoiceItem)
              
              // === OPTIONAL FIELDS (only provided ones are updated) ===
              
              [ 'name' ] = string,             // Product/service name
              [ 'quantity' ] = int,            // Quantity ร— 100 (e.g., 1 pc = 100, 0.5 kg = 50)
              [ 'unit' ] = string,             // Unit of measure (from dictionary)
              [ 'vatRate' ] = string,          // VAT rate (from dictionary)
              [ 'priceNetto' ] = int,          // Net unit price in grosze (for 'netto' invoices)
              [ 'priceBrutto' ] = int,         // Gross unit price in grosze (for 'brutto' invoices)
              
              // === MANUAL MODE (optional) ===
              
              [ 'manualMode' ] = bool,         // If true, all values below are required
              [ 'valueNetto' ] = int,          // Total net value in grosze (only with manualMode)
              [ 'valueBrutto' ] = int,         // Total gross value in grosze (only with manualMode)
              [ 'valueVat' ] = int,            // VAT amount in grosze (only with manualMode)
              
              // === OTHER OPTIONAL ===
              
              [ 'sww' ] = string,              // SWW code
              [ 'gtu' ] = string,              // GTU code
              [ 'accountNumber' ] = string,    // Accounting account number
            )
        

Example

  require_once ( 'classUddsOx.php' ) ;

  $udds = new classUddsOx ;
  $udds->customerCode = [your_customerCode] ;
  $udds->login = [your_login] ;
  $udds->password = [your_password] ;
  $udds->serverUrl = 'http://api.dlaoperatora.pl/udds/' ;
  
  // Update item - change name and quantity
  $params = array();
  $params['idItem'] = 'ABCD1234EFGH5678IJKL9012MNOP3456';
  $params['name'] = 'Usล‚uga konsultingowa - ZMIANA';
  $params['quantity'] = 200;       // Change to 2 pieces (ร—100)
  
  $ret = $udds->updateInvoiceItem($params);
  
  // $ret['status'] == 'OK' on success
  // $ret['idItem'] = item ID
  // $ret['idInvoice'] = parent invoice ID
  // $ret['calculatedValues'] = recalculated prices and values

Example: change only the price

  // Update just the price, keep everything else
  $params = array();
  $params['idItem'] = '...';
  $params['priceNetto'] = 75000;   // Change to 750.00 PLN/unit
  
  $ret = $udds->updateInvoiceItem($params);
  // Quantity, unit, vatRate, name stay unchanged
  // Values are recalculated based on existing quantity + new price

Example: change VAT rate

  // Change VAT rate from 23% to 8%
  $params = array();
  $params['idItem'] = '...';
  $params['vatRate'] = '8';
  
  $ret = $udds->updateInvoiceItem($params);
  // All values recalculated with new VAT rate

Returns

Success response

{
  "status": "OK",
  "idItem": "ABCD1234EFGH5678IJKL9012MNOP3456",
  "idInvoice": "00000004M1G221031126JF1B44ASNQ6D",
  "calculatedValues": {
    "priceNettoPLN": 50000,
    "priceBruttoPLN": 61500,
    "valueNettoPLN": 100000,
    "valueBruttoPLN": 123000,
    "valueVatPLN": 23000,
    "priceNettoEUR": 50000,
    "priceBruttoEUR": 61500,
    "valueNettoEUR": 100000,
    "valueBruttoEUR": 123000,
    "valueVatEUR": 23000
  },
  "errors": []
}

Error response

{
  "status": "ERROR",
  "errors": [
    { "code": 1002, "message": "Pozycja o ID 'XXX' nie istnieje" }
  ]
}

Error codes

CodeDescription
1001Missing idItem parameter
1002Item not found
1003Invoice not found (parent invoice deleted?)
1004Invoice already sent to KSEF (cannot modify)
1005Invalid dictionary value (unit, vatRate)
1006Manual mode requires all value fields
1007Database error

Related endpoints