riesenia / pohoda

XML generator a parser pre Pohodu
35 stars 29 forks source link

Recyklační příspěvky přímo ve faktuře #42

Open haltuf opened 10 months ago

haltuf commented 10 months ago

RP lze zadat i přímo do faktury:

Agendu Recyklační příspěvky můžete používat také ve variantách programu POHODA bez skladové evidence; najdete ji v nabídce Fakturace. Zobrazení sloupců pro přiřazení příspěvků textovým položkám si nastavíte v agendě Globální nastavení v sekci Doklady.

XML requestu pak vypadá takto:

    <inv:recyclingContrib>
        <typ:recyclingContribText>Recyklační příspěvek bez DPH:</typ:recyclingContribText>
        <typ:recyclingContribAmount>1.1</typ:recyclingContribAmount>
        <typ:recyclingContribUnit>kg</typ:recyclingContribUnit>
        <typ:coefficientOfRecyclingContrib>0.056</typ:coefficientOfRecyclingContrib>
    </inv:recyclingContrib>
haltuf commented 10 months ago

Vyřešil jsem takto:

1/ vytvořením nového Riesenia\Pohoda\Invoice\RecyclingContrib (defacto kopie ze Stock):


<?php declare(strict_types=1);

namespace Riesenia\Pohoda\Invoice;

use Riesenia\Pohoda\Agenda;
use Riesenia\Pohoda\Common\OptionsResolver;

class RecyclingContrib extends Agenda
{
    /** @var string[] */
    protected $_refElements = ['recyclingContribType'];

    /** @var string[] */
    protected $_elements = ['recyclingContribType', 'recyclingContribText', 'recyclingContribAmount', 'recyclingContribUnit', 'coefficientOfRecyclingContrib'];

    /**
     * {@inheritdoc}
     */
    public function getXML(): \SimpleXMLElement
    {
        $xml = $this->_createXML()->addChild('inv:recyclingContrib', '', $this->_namespace('inv'));

        $this->_addElements($xml, $this->_elements, 'typ');

        return $xml;
    }

    /**
     * {@inheritdoc}
     */
    protected function _configureOptions(OptionsResolver $resolver)
    {
        // available options
        $resolver->setDefined($this->_elements);

        $resolver->setNormalizer('recyclingContribType', $resolver->getNormalizer('string32'));
        $resolver->setNormalizer('recyclingContribText', $resolver->getNormalizer('string90'));
        $resolver->setNormalizer('recyclingContribAmount', $resolver->getNormalizer('float'));
        $resolver->setNormalizer('recyclingContribUnit', $resolver->getNormalizer('string2'));
        $resolver->setNormalizer('coefficientOfRecyclingContrib', $resolver->getNormalizer('float'));
    }
}

2/ úpravou Riesenia\Pohoda\Invoice\Item

protected $_elements = ['text', 'quantity', 'unit', 'coefficient', 'payVAT', 'rateVAT', 'percentVAT', 'discountPercentage', 'homeCurrency', 'foreignCurrency', 'typeServiceMOSS', 'note', 'code', 'guarantee', 'guaranteeType', 'stockItem', 'accounting', 'classificationVAT', 'classificationKVDPH', 'centre', 'activity', 'contract', 'expirationDate', 'PDP', 'recyclingContrib'];

a

public function __construct(array $data, string $ico, bool $resolveOptions = true)
    {
        if (isset($data['recyclingContrib'])) {
            $data['recyclingContrib'] = new RecyclingContrib($data['recyclingContrib'], $ico, $resolveOptions);
        }

        parent::__construct($data, $ico, $resolveOptions);
    }

Omlouvám se, že neposílám rovnou PR, ale řešil jsem velmi narychlo.

segy commented 8 months ago

zdravim. budete mat priestor na toto spravit pr?

haltuf commented 8 months ago

@segy zkusím v pátek.

segy commented 5 months ago

kedykolvek :)