Kopírování faktur
parent
302edd094b
commit
3257006a02
|
|
@ -538,4 +538,51 @@ class FakturaFacade
|
||||||
{
|
{
|
||||||
$this->kufrikExplorer->table('FAKTURA')->where('ID', $id)->delete();
|
$this->kufrikExplorer->table('FAKTURA')->where('ID', $id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kopie faktury: nové číslo, dnešní data, stejný odběratel a položky, bez plateb.
|
||||||
|
*
|
||||||
|
* @return int ID nové faktury
|
||||||
|
*/
|
||||||
|
public function duplicate(int $id, int $firmaId): int
|
||||||
|
{
|
||||||
|
$zdroj = $this->getById($id);
|
||||||
|
if (!$zdroj) {
|
||||||
|
throw new \InvalidArgumentException('Faktura nebyla nalezena.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$dnes = new \DateTimeImmutable('today');
|
||||||
|
$dalsi = $this->getNextCislo($firmaId, $dnes);
|
||||||
|
$datumVystaveni = $dnes->format('Y-m-d');
|
||||||
|
$datumSplatnosti = $dnes
|
||||||
|
->modify('+' . $dalsi['splatnostDny'] . ' days')
|
||||||
|
->format('Y-m-d');
|
||||||
|
|
||||||
|
$novaId = $this->saveFaktura([
|
||||||
|
'ZAKAZNIK_ID' => (int) $zdroj->ZAKAZNIK,
|
||||||
|
'CISLO' => $dalsi['cislo'],
|
||||||
|
'CISLO_ABS' => $dalsi['cisloAbs'],
|
||||||
|
'FORMA_UHRADY' => (int) ($zdroj->FORMA_UHRADY ?? 1),
|
||||||
|
'DATUM_VYSTAVENI' => $datumVystaveni,
|
||||||
|
'DATUM_SPLATNOSTI' => $datumSplatnosti,
|
||||||
|
'DATUM_DUZP' => $datumVystaveni,
|
||||||
|
'STAV' => self::STAV_VYSTAVENO,
|
||||||
|
'CINNOSTI' => $zdroj->CINNOSTI,
|
||||||
|
], null, $firmaId);
|
||||||
|
|
||||||
|
$polozky = [];
|
||||||
|
foreach ($this->getPolozky($id) as $polozka) {
|
||||||
|
$polozky[] = [
|
||||||
|
'NAZEV' => $polozka->NAZEV,
|
||||||
|
'POCET' => $polozka->POCET,
|
||||||
|
'JEDNOTKA' => $polozka->JEDNOTKA,
|
||||||
|
'CENA_JEDNOTKA' => $polozka->CENA_JEDNOTKA,
|
||||||
|
'SLEVA' => $polozka->SLEVA,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$this->savePolozky($novaId, $polozky, $firmaId);
|
||||||
|
$this->syncStav($novaId);
|
||||||
|
|
||||||
|
return $novaId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -218,4 +218,22 @@ class FakturaPresenter extends BasePresenter
|
||||||
|
|
||||||
$this->redirect('this');
|
$this->redirect('this');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kopie faktury — nové číslo, dnešní data, stejné položky; otevře editaci.
|
||||||
|
*/
|
||||||
|
public function handleDuplicate(int $id): void
|
||||||
|
{
|
||||||
|
$firmaId = (int) $this->getUser()->getIdentity()->firma_id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$novaId = $this->fakturaFacade->duplicate($id, $firmaId);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
$this->flashMessage($e->getMessage(), 'danger');
|
||||||
|
$this->redirect('this');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->flashMessage('Kopie faktury byla vytvořena.', 'success');
|
||||||
|
$this->redirect('FakturaEdit:edit', $novaId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +137,13 @@
|
||||||
<i class="bi bi-pencil"></i>
|
<i class="bi bi-pencil"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<!-- Kopie faktury -->
|
||||||
|
<a n:href="duplicate! $f->ID"
|
||||||
|
class="btn btn-sm btn-outline-secondary me-1"
|
||||||
|
title="Vytvořit kopii">
|
||||||
|
<i class="bi bi-copy"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
<!-- Smazání faktury -->
|
<!-- Smazání faktury -->
|
||||||
<a n:href="delete! $f->ID"
|
<a n:href="delete! $f->ID"
|
||||||
class="btn btn-sm btn-outline-danger"
|
class="btn btn-sm btn-outline-danger"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue