<?php
namespace App\Controller\CashBox;
use App\Entity\Cashbox;
use App\Entity\CashboxCounting;
use App\Entity\CashboxDeposit;
use App\Entity\CashboxPaymentToSupplier;
use App\Entity\CashboxWithdrawal;
use App\Entity\Company;
use App\Entity\DailyFinancialStatement;
use App\Entity\DailyFinancialStatementCashbox;
use App\Entity\DailyFinancialStatementCashboxDeposit;
use App\Entity\DailyFinancialStatementCashboxPaymentToSupplier;
use App\Entity\DailyFinancialStatementCashboxWithdrawal;
use App\Entity\DailyFinancialStatementCounting;
use App\Entity\DailyFinancialStatementLocation;
use App\Entity\Location;
use App\Entity\Receipt;
use App\Repository\CashboxRepository;
use App\Repository\CompanyRepository;
use App\Repository\DailyFinancialStatementRepository;
use App\Repository\ReceiptRepository;
use App\Service\CashBox\CashboxService;
use App\Service\CashBox\DailyFinancialStatementService;
use App\Service\CashBox\ReceiptService;
use App\Service\TimeZoneDetectionService;
use App\Structure\Fiskaly\CashPointClosingHeadStructure;
use App\Structure\Fiskaly\CashPointClosingStructure;
use Doctrine\ORM\EntityManagerInterface;
use Dompdf\Dompdf;
use Dompdf\Options;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
/**
* @Route("/daily_financial_statement")
*/
class DailyFinancialStatementController extends AbstractController
{
private EntityManagerInterface $entity_manager;
private SessionInterface $session;
private ReceiptRepository $receipt_repository;
private DailyFinancialStatementRepository $daily_financial_statement_repository;
private CompanyRepository $company_repository;
private CashboxService $cashbox_service;
private DailyFinancialStatementService $daily_financial_statement_service;
private TimeZoneDetectionService $timeZoneDetectionService;
private ReceiptService $receipt_service;
public function __construct(EntityManagerInterface $entity_manager, SessionInterface $session, ReceiptRepository $receipt_repository, DailyFinancialStatementRepository $daily_financial_statement_repository, CompanyRepository $company_repository, CashboxRepository $cashbox_repository, CashboxService $cashbox_service, DailyFinancialStatementService $daily_financial_statement_service, TimeZoneDetectionService $timeZoneDetectionService, ReceiptService $receipt_service)
{
$this->entity_manager = $entity_manager;
$this->session = $session;
$this->receipt_repository = $receipt_repository;
$this->daily_financial_statement_repository = $daily_financial_statement_repository;
$this->company_repository = $company_repository;
$this->cashbox_repository = $cashbox_repository;
$this->cashbox_service = $cashbox_service;
$this->daily_financial_statement_service = $daily_financial_statement_service;
$this->timeZoneDetectionService = $timeZoneDetectionService;
$this->receipt_service = $receipt_service;
}
/**
* @Route("/", name="daily_financial_statement", methods={"GET","POST"})
*/
public function index()
{
return new JsonResponse([]);
}
/**
* @Route("/load/{id}", name="load_daily_financial_statement", methods={"GET","POST"})
*/
public function load(Request $request, DailyFinancialStatement $dailyFinancialStatement)
{
$_dailyFinancialStatement = [
'id' => $dailyFinancialStatement->getId(),
'start_date' => $dailyFinancialStatement->getStartDate()->format("d.m.Y / H:i"),
'end_date' => $dailyFinancialStatement->getEndDate()->format("d.m.Y / H:i"),
'cashbox_start_value' => ($dailyFinancialStatement->getCashboxStartValue() ?? 0.00),
'cashbox_end_value' => ($dailyFinancialStatement->getCashboxEndValue() ?? 0.00),
'deposit_total' => ($dailyFinancialStatement->getDeposits() ?? 0.00),
'withdrawal_total' => ($dailyFinancialStatement->getWithdrawals() ?? 0.00),
'payment_to_supplier_total' => ($dailyFinancialStatement->getPaymentsToSuppliers() ?? 0.00),
'card_payment' => ($dailyFinancialStatement->getCardPayment() ?? 0.00),
];
return new JsonResponse(['_success' => true, 'daily_financial_statement' => $_dailyFinancialStatement]);
}
/**
* @Route("/loadprint/{id}", name="loadprint_daily_financial_statement", methods={"GET","POST"})
*/
public function loadPrint_(Request $request, DailyFinancialStatement $daily_financial_statement)
{
if ($daily_financial_statement->getManually() === true) {
$cashbox_deposit_total = $daily_financial_statement->getDeposits();
$cashbox_withdrawal_total = $daily_financial_statement->getWithdrawals();
$cashbox_payments_to_supplier_total = $daily_financial_statement->getPaymentsToSuppliers();
} else {
$cashbox_deposit_total = $this->daily_financial_statement_service->getDepositTotal($daily_financial_statement);
$cashbox_withdrawal_total = $this->daily_financial_statement_service->getWithdrawalTotal($daily_financial_statement);
$cashbox_payments_to_supplier_total = $this->daily_financial_statement_service->getPaymentToSupplierTotal($daily_financial_statement);
}
$daily_financial_statement_ = [
'company' => [
'address_addition' => null,
'address_country' => null,
'address_locality' => null,
'email' => null,
'fax_number' => null,
'id' => null,
'line_1' => null,
'line_2' => null,
'logo' => null,
'name' => null,
'postal_code' => null,
'street_address' => null,
'tax_number' => null,
'telephone' => null,
'vat_id' => null,
'website' => null,
],
'cashbox' => [
'id' => null,
'cashbox_id' => null,
'name' => null,
'comment' => null,
'locked' => null,
'serial_number' => null,
],
'location' => [
'id' => null,
'location_id' => null,
'name' => null,
'logo' => null,
'street_address' => null,
'postal_code' => null,
'address_locality' => null,
'address_addition' => null,
'address_country' => null,
'telephone' => null,
'website' => null,
'email' => null,
'fax_number' => null,
'show_address_on_receipt' => null,
'show_contact_on_receipt' => null,
],
'daily_financial_statement' => [
'id' => null,
'cashbox_start_value' => 0,
'cashbox_start_value_f' => 0,
'cashbox_end_value' => 0,
'cashbox_end_value_f' => 0,
'receipt_value' => 0,
'receipt_value_f' => 0,
'start_date' => null,
'start_date_f' => null,
'start_date_f_y' => null,
'start_date_f_m' => null,
'start_date_f_d' => null,
'start_date_f_h' => null,
'start_date_f_i' => null,
'start_date_f_s' => null,
'end_date' => null,
'end_date_f' => null,
'end_date_f_y' => null,
'end_date_f_m' => null,
'end_date_f_d' => null,
'end_date_f_h' => null,
'end_date_f_i' => null,
'end_date_f_s' => null,
'deposit_total' => 0,
'deposit_total_f' => 0,
'withdrawal_total' => 0,
'withdrawal_total_f' => 0,
'payment_to_supplier_total' => 0,
'payment_to_supplier_total_f' => 0,
'card_payment' => 0,
'card_payment_f' => 0,
'manually' => false,
],
'cashbox_counting' => [
'counting' => [],
'counting_total' => [],
'total' => 0,
'total_f' => 0,
],
'receipt_cash' => 0,
'noreceipt_cash' => 0,
'cash_debit' => 0,
'receipt_count' => 0,
'tax' => [],
'gezaehlt' => (float)0,
'soll' => (float)0,
'differenz' => (float)0,
'zbonnr' => 0,
'anfangsbestand' => (float)0,
'einlagen' => (float)0,
'entnahmen' => (float)0,
'zahlungen_an_lieferanten' => (float)0,
'position_count' => 0,
'anzahl_bon_stornos' => 0,
'verkaufte_gutscheine' => 0,
'receipt_value_average' => (float)0,
'bar' => (float)0,
'ec_karte' => (float)0,
'kreditkarte' => (float)0,
'auf_rechnung_gezahlt' => (float)0,
'group_by_payment_method' => [],
'receipt_total' => (float)0,
'bankeinzahlungen' => (float)0,
'bar_differenzen' => (float)0,
'wechselgeldvortrag' => (float)0,
'zahlungen_von_kunden_rechnungen' => (float)0,
'geleistete_anzahlungen_auf_kassenauftraege' => (float)0,
'summe_retourenpositionen' => (float)0,
'eingeloeste_gutscheine' => (float)0,
'gutschein_aus_guthaben' => (float)0,
'verrechnete_anzahlungen' => (float)0,
'verrechnete_gutschriften' => (float)0,
];
$daily_financial_statement_['soll_f'] = number_format($daily_financial_statement_['soll'], 2, '•', '');
$daily_financial_statement_['differenz_f'] = number_format($daily_financial_statement_['differenz'], 2, '•', '');
$daily_financial_statement_['anfangsbestand_f'] = number_format($daily_financial_statement_['anfangsbestand'], 2, '•', '');
$daily_financial_statement_['einlagen_f'] = number_format($daily_financial_statement_['einlagen'], 2, '•', '');
$daily_financial_statement_['entnahmen_f'] = number_format($daily_financial_statement_['entnahmen'], 2, '•', '');
$daily_financial_statement_['zahlungen_an_lieferanten_f'] = number_format($daily_financial_statement_['zahlungen_an_lieferanten'], 2, '•', '');
$daily_financial_statement_['receipt_cash_f'] = number_format($daily_financial_statement_['receipt_cash'], 2, '•', '');
$daily_financial_statement_['cash_debit_f'] = number_format($daily_financial_statement_['cash_debit'], 2, '•', '');
$daily_financial_statement_['receipt_value_average_f'] = number_format($daily_financial_statement_['receipt_value_average'], 2, '•', '');
$daily_financial_statement_['bar_f'] = number_format($daily_financial_statement_['bar'], 2, '•', '');
$daily_financial_statement_['ec_karte_f'] = number_format($daily_financial_statement_['ec_karte'], 2, '•', '');
$daily_financial_statement_['kreditkarte_f'] = number_format($daily_financial_statement_['kreditkarte'], 2, '•', '');
$daily_financial_statement_['auf_rechnung_gezahlt_f'] = number_format($daily_financial_statement_['auf_rechnung_gezahlt'], 2, '•', '');
$daily_financial_statement_['receipt_total_f'] = number_format($daily_financial_statement_['receipt_total'], 2, '•', '');
$daily_financial_statement_['bankeinzahlungen_f'] = number_format($daily_financial_statement_['bankeinzahlungen'], 2, '•', '');
$daily_financial_statement_['bar_differenzen_f'] = number_format($daily_financial_statement_['bar_differenzen'], 2, '•', '');
$daily_financial_statement_['wechselgeldvortrag_f'] = number_format($daily_financial_statement_['wechselgeldvortrag'], 2, '•', '');
$daily_financial_statement_['zahlungen_von_kunden_rechnungen_f'] = number_format($daily_financial_statement_['zahlungen_von_kunden_rechnungen'], 2, '•', '');
$daily_financial_statement_['geleistete_anzahlungen_auf_kassenauftraege_f'] = number_format($daily_financial_statement_['geleistete_anzahlungen_auf_kassenauftraege'], 2, '•', '');
$daily_financial_statement_['summe_retourenpositionen_f'] = number_format($daily_financial_statement_['summe_retourenpositionen'], 2, '•', '');
$daily_financial_statement_['eingeloeste_gutscheine_f'] = number_format($daily_financial_statement_['eingeloeste_gutscheine'], 2, '•', '');
$daily_financial_statement_['gutschein_aus_guthaben_f'] = number_format($daily_financial_statement_['gutschein_aus_guthaben'], 2, '•', '');
$daily_financial_statement_['verrechnete_anzahlungen_f'] = number_format($daily_financial_statement_['verrechnete_anzahlungen'], 2, '•', '');
$daily_financial_statement_['verrechnete_gutschriften_f'] = number_format($daily_financial_statement_['verrechnete_gutschriften'], 2, '•', '');
$company = $this->company_repository->findOneBy(['id' => 1]);
if ($company instanceof Company) {
$daily_financial_statement_['company'] = [
'address_addition' => $company->getAddressAddition(),
'address_country' => $company->getAddressCountry(),
'address_locality' => $company->getAddressLocality(),
'email' => $company->getEmail(),
'fax_number' => $company->getFaxNumber(),
'id' => $company->getId(),
'line_1' => $company->getLine1(),
'line_2' => $company->getLine2(),
'logo' => $company->getLogo(),
'name' => $company->getName(),
'postal_code' => $company->getPostalCode(),
'street_address' => $company->getStreetAddress(),
'tax_number' => $company->getTaxNumber(),
'telephone' => $company->getTelephone(),
'vat_id' => $company->getVatId(),
'website' => $company->getWebsite(),
];
}
$dailyFinancialStatementCashbox = $daily_financial_statement->getDailyFinancialStatementCashbox();
if ($dailyFinancialStatementCashbox instanceof DailyFinancialStatementCashbox) {
$daily_financial_statement_['cashbox'] = [
'id' => $dailyFinancialStatementCashbox->getId(),
'cashbox_id' => null,
'name' => $dailyFinancialStatementCashbox->getName(),
'comment' => $dailyFinancialStatementCashbox->getComment(),
'locked' => $dailyFinancialStatementCashbox->getLocked(),
'serial_number' => $dailyFinancialStatementCashbox->getSerialNumber(),
];
if ($dailyFinancialStatementCashbox->getCashbox() instanceof Cashbox) {
$daily_financial_statement_['cashbox']['cashbox_id'] = $dailyFinancialStatementCashbox->getCashbox()->getId();
}
$dailyFinancialStatementLocation = $dailyFinancialStatementCashbox->getDailyFinancialStatementLocation();
if ($dailyFinancialStatementLocation instanceof DailyFinancialStatementLocation) {
$daily_financial_statement_['location'] = [
'id' => $dailyFinancialStatementLocation->getId(),
'location_id' => null,
'name' => $dailyFinancialStatementLocation->getName(),
'logo' => $dailyFinancialStatementLocation->getLogo(),
'street_address' => $dailyFinancialStatementLocation->getStreetAddress(),
'postal_code' => $dailyFinancialStatementLocation->getPostalCode(),
'address_locality' => $dailyFinancialStatementLocation->getAddressLocality(),
'address_addition' => $dailyFinancialStatementLocation->getAddressAddition(),
'address_country' => $dailyFinancialStatementLocation->getAddressCountry(),
'telephone' => $dailyFinancialStatementLocation->getTelephone(),
'website' => $dailyFinancialStatementLocation->getWebsite(),
'email' => $dailyFinancialStatementLocation->getEmail(),
'fax_number' => $dailyFinancialStatementLocation->getFaxNumber(),
'show_address_on_receipt' => $dailyFinancialStatementLocation->getShowAddressOnReceipt(),
'show_contact_on_receipt' => $dailyFinancialStatementLocation->getShowContactOnReceipt(),
];
if ($dailyFinancialStatementLocation->getLocation() instanceof Location) {
$daily_financial_statement_['location']['location_id'] = $dailyFinancialStatementLocation->getLocation()->getId();
}
}
$daily_financial_statement__ = [
'id' => $daily_financial_statement->getId(),
'cashbox_start_value' => ($daily_financial_statement->getCashboxStartValue() ?? 0),
'cashbox_start_value_f' => ($daily_financial_statement->getCashboxStartValue() ?? 0),
'cashbox_end_value' => ($daily_financial_statement->getCashboxEndValue() ?? 0),
'cashbox_end_value_f' => ($daily_financial_statement->getCashboxEndValue() ?? 0),
'receipt_value' => ($daily_financial_statement->getReceiptValue() ?? 0),
'receipt_value_f' => ($daily_financial_statement->getReceiptValue() ?? 0),
'start_date' => $daily_financial_statement->getStartDate(),
'start_date_f' => $daily_financial_statement->getStartDate(),
'start_date_f_y' => $daily_financial_statement->getStartDate(),
'start_date_f_m' => $daily_financial_statement->getStartDate(),
'start_date_f_d' => $daily_financial_statement->getStartDate(),
'start_date_f_h' => $daily_financial_statement->getStartDate(),
'start_date_f_i' => $daily_financial_statement->getStartDate(),
'start_date_f_s' => $daily_financial_statement->getStartDate(),
'end_date' => $daily_financial_statement->getEndDate(),
'end_date_f' => $daily_financial_statement->getEndDate(),
'end_date_f_y' => $daily_financial_statement->getEndDate(),
'end_date_f_m' => $daily_financial_statement->getEndDate(),
'end_date_f_d' => $daily_financial_statement->getEndDate(),
'end_date_f_h' => $daily_financial_statement->getEndDate(),
'end_date_f_i' => $daily_financial_statement->getEndDate(),
'end_date_f_s' => $daily_financial_statement->getEndDate(),
'deposit_total' => $cashbox_deposit_total,
'deposit_total_f' => $cashbox_deposit_total,
'withdrawal_total' => $cashbox_withdrawal_total,
'withdrawal_total_f' => $cashbox_withdrawal_total,
'payment_to_supplier_total' => $cashbox_payments_to_supplier_total,
'payment_to_supplier_total_f' => $cashbox_payments_to_supplier_total,
'card_payment' => ($daily_financial_statement->getCardPayment() ?? 0),
'card_payment_f' => ($daily_financial_statement->getCardPayment() ?? 0),
'manually' => $daily_financial_statement->getManually(),
];
$daily_financial_statement__['cashbox_start_value_f'] = number_format(round((float)$daily_financial_statement__['cashbox_start_value_f'], 2), 2, '•', '');
$daily_financial_statement__['cashbox_end_value_f'] = number_format(round((float)($daily_financial_statement__['cashbox_end_value_f'] / 100), 2), 2, '•', '');
$daily_financial_statement__['receipt_value_f'] = number_format(round((float)$daily_financial_statement__['receipt_value_f'], 2), 2, '•', '');
$daily_financial_statement__['deposit_total_f'] = number_format(round((float)$daily_financial_statement__['deposit_total_f'], 2), 2, '•', '');
$daily_financial_statement__['withdrawal_total_f'] = number_format(round((float)$daily_financial_statement__['withdrawal_total_f'], 2), 2, '•', '');
$daily_financial_statement__['payment_to_supplier_total_f'] = number_format(round((float)$daily_financial_statement__['payment_to_supplier_total_f'], 2), 2, '•', '');
$daily_financial_statement__['card_payment_f'] = number_format(round((float)$daily_financial_statement__['card_payment_f'], 2), 2, '•', '');
$daily_financial_statement__['start_date_f'] = $daily_financial_statement__['start_date_f']->format("d.m.Y / H:i:s");
$daily_financial_statement__['start_date_f_y'] = $daily_financial_statement__['start_date_f_y']->format("Y");
$daily_financial_statement__['start_date_f_m'] = $daily_financial_statement__['start_date_f_m']->format("m");
$daily_financial_statement__['start_date_f_d'] = $daily_financial_statement__['start_date_f_d']->format("d");
$daily_financial_statement__['start_date_f_h'] = $daily_financial_statement__['start_date_f_h']->format("H");
$daily_financial_statement__['start_date_f_i'] = $daily_financial_statement__['start_date_f_i']->format("i");
$daily_financial_statement__['start_date_f_s'] = $daily_financial_statement__['start_date_f_s']->format("s");
$daily_financial_statement__['end_date_f'] = $daily_financial_statement__['end_date_f']->format("d.m.Y / H:i:s");
$daily_financial_statement__['end_date_f_y'] = $daily_financial_statement__['end_date_f_y']->format("Y");
$daily_financial_statement__['end_date_f_m'] = $daily_financial_statement__['end_date_f_m']->format("m");
$daily_financial_statement__['end_date_f_d'] = $daily_financial_statement__['end_date_f_d']->format("d");
$daily_financial_statement__['end_date_f_h'] = $daily_financial_statement__['end_date_f_h']->format("H");
$daily_financial_statement__['end_date_f_i'] = $daily_financial_statement__['end_date_f_i']->format("i");
$daily_financial_statement__['end_date_f_s'] = $daily_financial_statement__['end_date_f_s']->format("s");
$daily_financial_statement_['daily_financial_statement'] = $daily_financial_statement__;
if ($daily_financial_statement->getManually() === false) {
$countings = $daily_financial_statement->getDailyFinancialStatementCountings();
if ($countings->count() > 0) {
foreach ($countings as $counting) {
$daily_financial_statement_['cashbox_counting']['counting'][$counting->getFactor()] = $counting->getAmount();
$daily_financial_statement_['cashbox_counting']['counting_total'][$counting->getFactor()] = [
'total' => ($counting->getFactor() * $counting->getAmount()),
'total_f' => number_format(round((float)(($counting->getFactor() * $counting->getAmount()) / 100), 2), 2, '•', ''),
];
$daily_financial_statement_['cashbox_counting']['total'] += ($counting->getFactor() * $counting->getAmount());
}
$daily_financial_statement_['cashbox_counting']['total_f'] = number_format(round((float)($daily_financial_statement_['cashbox_counting']['total'] / 100), 2), 2, '•', '');
}
}
$receipt_container = $daily_financial_statement->getReceipts();
if ($receipt_container->count() > 0) {
$tax = ['total' => [], 'cash' => [], 'nocash' => []];
$position_count = 0;
$receipt_totals = 0;
$group_by_payment_method = [];
$group_by_cash_nocash = ['cash' => 0, 'nocash' => 0];
foreach ($receipt_container as $receipt) {
if ($receipt->getCanceled() === true || $receipt->getReversalReceipt() === true) {
//Do nothing
} else {
$base_receipt = $receipt;
if ($receipt->getReversalReceipt() === true) {
$receipt_ = $this->receipt_service->getReceiptFromReversalReceipt($receipt);
if ($receipt_ !== false) {
$base_receipt = $receipt_;
}
}
if ($daily_financial_statement->getManually() === false) {
if ($receipt->getReversalReceipt() === true) {
$position_count -= $base_receipt->getReceiptCartProducts()->count();
// $receipt_totals += 0-$receipt->getCartTotalFixed();
$receipt_totals -= $base_receipt->getTotalFixed();
} else {
$position_count += $base_receipt->getReceiptCartProducts()->count();
// $receipt_totals += $receipt->getCartTotalFixed();
$receipt_totals += $base_receipt->getTotalFixed();
}
$receipt_transaction = $receipt->getReceiptTransactions()->last();
$receipt_cart_products = $receipt->getReceiptCartProducts();
foreach ($receipt_cart_products as $receipt_cart_product) {
$receipt_product = $receipt_cart_product->getReceiptProduct();
if (!isset($tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
if (!isset($tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
if (!isset($tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
if ($receipt->getReversalReceipt() === true) {
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] -= $receipt_cart_product->getTotalFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] -= $receipt_cart_product->getTotalOtaxFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] -= ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
} else {
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
}
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2, '•', '');
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2, '•', '');
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2, '•', '');
}
if ($receipt_transaction !== false) {
$receipt_payment_method = $receipt_transaction->getReceiptPaymentMethod();
if ($receipt_payment_method !== null) {
if (!isset($group_by_payment_method[$receipt_payment_method->getName()])) {
$group_by_payment_method[$receipt_payment_method->getName()] = 0;
}
// $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getCartTotalFixed();
$group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getTotalFixed();
if ($receipt_payment_method->getCash() === true) {
// $group_by_cash_nocash['cash'] += $receipt->getCartTotalFixed();
$group_by_cash_nocash['cash'] += $receipt->getTotalFixed();
$group_by_cash_nocash['cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2, '•', '');
foreach ($receipt_cart_products as $receipt_cart_product) {
$receipt_product = $receipt_cart_product->getReceiptProduct();
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2, '•', '');
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2, '•', '');
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2, '•', '');
}
} else {
$group_by_cash_nocash['nocash'] += $receipt->getTotalFixed();
// $group_by_cash_nocash['nocash'] += $receipt->getCartTotalFixed();
$group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2, '•', '');
foreach ($receipt_cart_products as $receipt_cart_product) {
$receipt_product = $receipt_cart_product->getReceiptProduct();
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2, '•', '');
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2, '•', '');
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2, '•', '');
}
}
}
}
} else {
$position_count += $receipt->getReceiptCartProducts()->count();
// $receipt_totals += $receipt->getCartTotalFixed();
$receipt_totals += $base_receipt->getTotalFixed();
$receipt_transaction = $receipt->getReceiptTransactions()->last();
$receipt_cart_products = $receipt->getReceiptCartProducts();
foreach ($receipt_cart_products as $receipt_cart_product) {
$receipt_product = $receipt_cart_product->getReceiptProduct();
if (!isset($tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
if (!isset($tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
if (!isset($tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()] = ['total' => 0, 'total_f' => 0, 'total_notax' => 0, 'total_notax_f' => 0, 'total_tax' => 0, 'total_tax_f' => 0];
}
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2, '•', '');
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2, '•', '');
$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2, '•', '');
}
if ($receipt_transaction !== false) {
$receipt_payment_method = $receipt_transaction->getReceiptPaymentMethod();
if ($receipt_payment_method !== null) {
if (!isset($group_by_payment_method[$receipt_payment_method->getName()])) {
$group_by_payment_method[$receipt_payment_method->getName()] = 0;
}
// $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getCartTotalFixed();
$group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getTotalFixed();
if ($receipt_payment_method->getCash() === true) {
// $group_by_cash_nocash['cash'] += $receipt->getCartTotalFixed();
$group_by_cash_nocash['cash'] += $receipt->getTotalFixed();
$group_by_cash_nocash['cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2, '•', '');
} else {
// $group_by_cash_nocash['nocash'] += $receipt->getCartTotalFixed();
$group_by_cash_nocash['nocash'] += $receipt->getTotalFixed();
$group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2, '•', '');
}
$group_by_cash_nocash['nocash'] += $daily_financial_statement->getCardPayment();
$group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2, '•', '');
}
}
}
}
}
$daily_financial_statement_['receipt_cash'] = $group_by_cash_nocash['cash'];
$daily_financial_statement_['receipt_nocash'] = $group_by_cash_nocash['nocash'];
$daily_financial_statement_['cashbox_cash_debit'] = ($daily_financial_statement_['receipt_cash'] + $daily_financial_statement_['daily_financial_statement']['deposit_total'] + $daily_financial_statement_['daily_financial_statement']['cashbox_start_value']) - ($daily_financial_statement_['daily_financial_statement']['withdrawal_total'] + $daily_financial_statement_['daily_financial_statement']['payment_to_supplier_total']);
$daily_financial_statement_['cashbox_cash_debit_f'] = number_format(round((float)$daily_financial_statement_['cashbox_cash_debit'], 2), 2, '•', '');
$daily_financial_statement_['receipt_cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2, '•', '');
$daily_financial_statement_['receipt_nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2, '•', '');
$daily_financial_statement_['cash_debit'] = $daily_financial_statement_['daily_financial_statement']['cashbox_start_value'] + $daily_financial_statement_['receipt_cash'];
$daily_financial_statement_['cash_debit_f'] = number_format(round((float)$daily_financial_statement_['cash_debit'], 2), 2, '•', '');
$daily_financial_statement_['receipt_count'] = $receipt_container->count();
$daily_financial_statement_['position_count'] = $position_count;
$daily_financial_statement_['receipt_value_average'] = round(($receipt_totals / $receipt_container->count()), 2);
$daily_financial_statement_['receipt_value_average_f'] = number_format((float)$daily_financial_statement_['receipt_value_average'], 2, '•', '');
$daily_financial_statement_['group_by_payment_method'] = $group_by_payment_method;
$daily_financial_statement_['group_by_cash_nocash'] = $group_by_cash_nocash;
$daily_financial_statement_['receipt_total'] = $receipt_totals;
$daily_financial_statement_['receipt_total_f'] = number_format(round((float)$daily_financial_statement_['receipt_total'], 2), 2, '•', '');
$daily_financial_statement_['summe2'] = $daily_financial_statement_['receipt_cash'] + $daily_financial_statement_['receipt_nocash'];
$daily_financial_statement_['summe2_f'] = number_format((float)round($daily_financial_statement_['summe2'], 2), 2, '•', '');
$daily_financial_statement_['summe3'] = (float)0;
$daily_financial_statement_['summe3_f'] = number_format((float)round($daily_financial_statement_['summe3'], 2), 2, '•', '');
$daily_financial_statement_['differences'] = ['cash' => [], 'nocash' => ['Anzahlungen' => [], 'Gutschriften' => [], 'Gutscheine' => []]];
$daily_financial_statement_['differences']['cash'] = [
'debit' => $daily_financial_statement_['cashbox_cash_debit'],
'debit_f' => $daily_financial_statement_['cashbox_cash_debit_f'],
'credit' => (float)($daily_financial_statement__['cashbox_end_value'] / 100),
'credit_f' => $daily_financial_statement__['cashbox_end_value_f'],
'difference' => round(((float)($daily_financial_statement__['cashbox_end_value'] / 100)) - $daily_financial_statement_['cashbox_cash_debit'], 2),
'difference_f' => number_format(round(((float)($daily_financial_statement__['cashbox_end_value'] / 100)) - $daily_financial_statement_['cashbox_cash_debit'], 2), 2, '•', ''),
];
$daily_financial_statement_['differences']['nocash']['Anzahlungen'] = [
'debit' => (float)0,
'debit_f' => number_format((float)0, 2, '•', ''),
'credit' => (float)0,
'credit_f' => number_format((float)0, 2, '•', ''),
'difference' => (float)0,
'difference_f' => number_format((float)0, 2, '•', ''),
];
$daily_financial_statement_['differences']['nocash']['Gutschriften'] = [
'debit' => (float)0,
'debit_f' => number_format((float)0, 2, '•', ''),
'credit' => (float)0,
'credit_f' => number_format((float)0, 2, '•', ''),
'difference' => (float)0,
'difference_f' => number_format((float)0, 2, '•', ''),
];
$daily_financial_statement_['differences']['nocash']['Gutscheine'] = [
'debit' => (float)0,
'debit_f' => number_format((float)0, 2, '•', ''),
'credit' => (float)0,
'credit_f' => number_format((float)0, 2, '•', ''),
'difference' => (float)0,
'difference_f' => number_format((float)0, 2, '•', ''),
];
$daily_financial_statement_['tax'] = $tax;
}
}
return new JsonResponse(['_success' => true, 'daily_financial_statement_print' => $daily_financial_statement_]);
}
/**
* @Route("/update/{id}", name="update_daily_financial_statement", methods={"GET","POST"})
*/
public function update(Request $request, DailyFinancialStatement $dailyFinancialStatement)
{
$data = json_decode($request->getContent(), true);
$dailyFinancialStatement
->setCashboxStartValue($data['daily_financial_statement_data']['cashbox_start_value'])
->setCashboxEndValue($data['daily_financial_statement_data']['cashbox_end_value'])
->setDeposits($data['daily_financial_statement_data']['deposit_total'])
->setWithdrawals($data['daily_financial_statement_data']['withdrawal_total'])
->setPaymentsToSuppliers($data['daily_financial_statement_data']['payment_to_supplier_total'])
->setCardPayment($data['daily_financial_statement_data']['card_payment']);
$this->entity_manager->persist($dailyFinancialStatement);
$this->entity_manager->flush();
return new JsonResponse(['_success' => true]);
}
/**
* @Route("/print/{id}", name="print_daily_financial_statement", methods={"GET","POST"})
*/
public function print(Request $request, DailyFinancialStatement $dailyFinancialStatement)
{
$data = $this->zBonData($dailyFinancialStatement);
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
// $html = $this->renderView('cash_box/daily_financial_statement/zbon.a4.html.twig', $data);
$html = $this->renderView('cash_box/daily_financial_statement/zbon.80mm.html.twig', $data);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (inline view)
$dompdf->stream("DailyFinancialStatement_" . $dailyFinancialStatement->getStartDate()->format("d-m-Y-H-i") . "_" . $dailyFinancialStatement->getEndDate()->format("d-m-Y-H-i") . "_" . time() . ".pdf", [
"Attachment" => false
]);
}
/**
* @Route("/list", name="list_daily_financial_statement", methods={"GET","POST"})
*/
public function list(Request $request)
{
$_daily_financial_statements = $this->daily_financial_statement_repository->findAll();
$daily_financial_statements = [];
foreach ($_daily_financial_statements as $daily_financial_statement) {
$daily_financial_statements[$daily_financial_statement->getId()] = [
'cashbox_end_value' => $daily_financial_statement->getCashboxEndValue(),
'cashbox_start_value' => $daily_financial_statement->getCashboxStartValue(),
'end_date' => $daily_financial_statement->getEndDate()->format("d.m.Y / H:i"),
'id' => $daily_financial_statement->getId(),
'start_date' => $daily_financial_statement->getStartDate()->format("d.m.Y / H:i"),
'start_y' => $daily_financial_statement->getStartDate()->format('Y'),
'start_m' => $daily_financial_statement->getStartDate()->format('m'),
'start_d' => $daily_financial_statement->getStartDate()->format('d'),
'start_h' => $daily_financial_statement->getStartDate()->format('H'),
'start_i' => $daily_financial_statement->getStartDate()->format('i'),
'start_s' => $daily_financial_statement->getStartDate()->format('s'),
'end_y' => $daily_financial_statement->getEndDate()->format('Y'),
'end_m' => $daily_financial_statement->getEndDate()->format('m'),
'end_d' => $daily_financial_statement->getEndDate()->format('d'),
'end_h' => $daily_financial_statement->getEndDate()->format('H'),
'end_i' => $daily_financial_statement->getEndDate()->format('i'),
'end_s' => $daily_financial_statement->getEndDate()->format('s'),
'manually' => $daily_financial_statement->getManually(),
];
}
return new JsonResponse($daily_financial_statements);
}
private function zBonData(DailyFinancialStatement $dailyFinancialStatement)
{
$data = [
'kasse' => null,
'firma' => null,
'gezaehlt' => 0,
'soll' => 0,
'differenz' => 0,
'daily_financial_statement' => 0,
'location' => null,
'zbonnr' => 0,
'anfangsbestand' => 0,
'einlagen' => 0,
'entnahmen' => 0,
'zahlungen_an_lieferanten' => 0,
'receipt_cash' => 0,
'cash_debit' => 0,
'receipt_count' => 0,
'position_count' => 0,
'anzahl_bon_stornos' => 0,
'verkaufte_gutscheine' => 0,
'receipt_value_average' => 0,
'bar' => 0,
'ec_karte' => 0,
'kreditkarte' => 0,
'auf_rechnung_gezahlt' => 0,
'group_by_payment_method' => 0,
'receipt_total' => 0,
'bankeinzahlungen' => 0,
'bar_differenzen' => 0,
'wechselgeldvortrag' => 0,
'zahlungen_von_kunden_rechnungen' => 0,
'geleistete_anzahlungen_auf_kassenauftraege' => 0,
'summe_retourenpositionen' => 0,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
// 'Anfangsbestand'=>null,
];
$receipt_container = $dailyFinancialStatement->getReceipts();
if ($receipt_container->count() > 0) {
$position_count = 0;
$receipt_totals = 0;
$group_by_payment_method = [];
foreach ($receipt_container as $receipt) {
$position_count += $receipt->getReceiptCartProducts()->count();
// $receipt_totals += $receipt->getCartTotalFixed();
$receipt_totals += $receipt->getTotalFixed();
$receiptTransaction = $receipt->getReceiptTransactions()->last();
if ($receiptTransaction !== false) {
$receiptPaymentMethod = $receiptTransaction->getReceiptPaymentMethod();
if ($receiptPaymentMethod !== null) {
if (!isset($group_by_payment_method[$receiptPaymentMethod->getName()])) {
$group_by_payment_method[$receiptPaymentMethod->getName()] = 0;
}
// $group_by_payment_method[$receiptPaymentMethod->getName()] += $receipt->getCartTotalFixed();
$group_by_payment_method[$receiptPaymentMethod->getName()] += $receipt->getTotalFixed();
}
}
}
$company = $this->company_repository->findOneBy(['id' => 1]);
$_company = [
'address_addition' => null,
'address_country' => null,
'address_locality' => null,
'email' => null,
'fax_number' => null,
'id' => null,
'line_1' => null,
'line_2' => null,
'logo' => null,
'name' => null,
'postal_code' => null,
'street_address' => null,
'tax_number' => null,
'telephone' => null,
'vat_id' => null,
'website' => null,
];
if ($company !== null) {
$_company = [
'address_addition' => $company->getAddressAddition(),
'address_country' => $company->getAddressCountry(),
'address_locality' => $company->getAddressLocality(),
'email' => $company->getEmail(),
'fax_number' => $company->getFaxNumber(),
'id' => $company->getId(),
'line_1' => $company->getLine1(),
'line_2' => $company->getLine2(),
'logo' => $company->getLogo(),
'name' => $company->getName(),
'postal_code' => $company->getPostalCode(),
'street_address' => $company->getStreetAddress(),
'tax_number' => $company->getTaxNumber(),
'telephone' => $company->getTelephone(),
'vat_id' => $company->getVatId(),
'website' => $company->getWebsite(),
];
}
$_dailyFinancialStatement = [
'id' => $dailyFinancialStatement->getId(),
'start_date' => $dailyFinancialStatement->getStartDate()->format("d.m.Y / H:i"),
'end_date' => $dailyFinancialStatement->getEndDate()->format("d.m.Y / H:i"),
'cashbox_start_value' => $dailyFinancialStatement->getCashboxStartValue(),
'cashbox_end_value' => $dailyFinancialStatement->getCashboxEndValue(),
'deposit_total' => $dailyFinancialStatement->getDeposits(),
'withdrawal_total' => $dailyFinancialStatement->getWithdrawals(),
'payment_to_supplier_total' => $dailyFinancialStatement->getPaymentsToSuppliers(),
];
$receiptLocation = $receipt->getReceiptLocation();
$_receiptLocation = [
'name' => null,
];
if ($receiptLocation !== null) {
$_receiptLocation = [
'name' => $receiptLocation->getName(),
];
}
$data['zbonnr'] = $dailyFinancialStatement->getId();
$data['kasse'] = ['name' => $receipt->getReceiptCashbox()->getName(), 'sn' => $receipt->getReceiptCashbox()->getSerialNumber()];
$data['firma'] = $_company;
$data['gezaehlt'] = $dailyFinancialStatement->getCashboxEndValue();
$data['anfangsbestand'] = $dailyFinancialStatement->getCashboxStartValue();
$data['receipt_cash'] = $group_by_payment_method['Bar'];
$data['cash_debit'] = $data['anfangsbestand'] + $data['receipt_cash'];
$data['receipt_count'] = $receipt_container->count();
$data['position_count'] = $position_count;
$data['receipt_value_average'] = $receipt_totals / $receipt_container->count();
$data['group_by_payment_method'] = $group_by_payment_method;
$data['receipt_total'] = $receipt_totals;
$data['soll'] = $data['cash_debit'];
$data['differenz'] = $data['gezaehlt'] - $data['soll'];
$data['daily_financial_statement'] = $_dailyFinancialStatement;
$data['location'] = $_receiptLocation;
}
return $data;
}
/**
* @Route("/map", name="map_daily_financial_statement", methods={"GET","POST"})
*/
public function map()
{
$data = [];
$daily_financial_statements = $this->daily_financial_statement_repository->findBy(['manually' => true]);
foreach ($daily_financial_statements as $daily_financial_statement) {
$detected_timezone = $this->timeZoneDetectionService->getTimezoneDifference($this->timeZoneDetectionService->DateTimeInterfaceToDateTime($daily_financial_statement->getStartDate()));
$sql = <<<SQL
SELECT receipt.id
FROM receipt
WHERE unix_timestamp(convert_tz(create_date,'$detected_timezone',@@session.time_zone))>=:start
AND unix_timestamp(convert_tz(create_date,'$detected_timezone',@@session.time_zone))<=:end
SQL;
$con = $this->entity_manager->getConnection();
$stmt = $con->executeQuery($sql, ['start' => $daily_financial_statement->getStartDate()->getTimestamp(), 'end' => $daily_financial_statement->getEndDate()->getTimestamp()]);
while (($row = $stmt->fetchAssociative()) !== false) {
$receipt = $this->receipt_repository->findOneBy(['id' => $row['id']]);
$receipt->setDailyFinancialStatement($daily_financial_statement);
$this->entity_manager->persist($receipt);
$this->entity_manager->flush();
}
}
}
/**
* @Route("/start", name="start_daily_financial_statement")
*/
public function start()
{
if ($this->_check() === false) {
$daily_financial_statement = new DailyFinancialStatement();
}
}
/**
* @Route("/stop/{id}", name="stop_daily_financial_statement", methods={"GET","POST"})
*/
public function stop(Request $request, DailyFinancialStatement $dailyFinancialStatement)
{
}
/**
* @Route("/check", name="check_daily_financial_statement")
*/
public function check()
{
return new JsonResponse(['_success' => true, 'has_active_daily_financial_statement' => $this->_check()]);
}
/**
* @Route("/load_active", name="load_active_daily_financial_statement")
*/
public function loadActive()
{
$daily_financial_statement = $this->daily_financial_statement_repository->findOneBy(['end_date' => null], ['id' => 'DESC']);
if ($daily_financial_statement instanceof DailyFinancialStatement) {
return new JsonResponse(['_success' => true, 'active_daily_financial_statement' => $daily_financial_statement->getId()]);
}
return new JsonResponse(['_success' => false, 'active_daily_financial_statement' => null]);
}
/**
* @Route("/create", name="create_daily_financial_statement", methods={"GET","POST"})
*/
public function create(Request $request)
{
$log_date = new \DateTime('now');
$log_file = __DIR__ . '/../../../var/' . $log_date->format("Y_m_d_H_i_s") . '.create_daily_financial_statement.log';
$cloner = new VarCloner();
$dumper = new CliDumper();
$data = json_decode($request->getContent(), true);
if (isset($data['cashbox'], $data['money_stack_data']) && !empty($data['cashbox']) && !empty($data['money_stack_data'])) {
$cashbox = $this->cashbox_repository->findOneBy(['id' => $data['cashbox']]);
if ($cashbox instanceof Cashbox) {
$cashbox_session = $this->cashbox_service->getLatestStartedCashboxSession($cashbox);
if ($cashbox_session !== null) {
foreach ($data['money_stack_data']['factory'] as $item_factor => $item_amount) {
$cashbox_counting = new CashboxCounting();
$cashbox_counting
->setAddDate(new \DateTime('now'))
->setCashboxSession($cashbox_session)
->setFactor((int)$item_factor)
->setAmount((int)$item_amount);
$this->entity_manager->persist($cashbox_counting);
}
$this->entity_manager->flush();
$cashbox_session
->setStopDate(new \DateTime('now'))
->setCashStop($data['money_stack_data']['total']);
$this->entity_manager->persist($cashbox_session);
$this->entity_manager->flush();
$location = $cashbox->getLocation();
$daily_financial_statement_location = null;
if ($location instanceof Location) {
$daily_financial_statement_location = new DailyFinancialStatementLocation();
$daily_financial_statement_location
->setAddressAddition($location->getAddressAddition())
->setAddressCountry($location->getAddressCountry())
->setAddressLocality($location->getAddressLocality())
->setEmail($location->getEmail())
->setFaxNumber($location->getFaxNumber())
->setLocation($location)
->setLogo($location->getLogo())
->setName($location->getName())
->setPostalCode($location->getPostalCode())
->setShowAddressOnReceipt($location->getShowAddressOnReceipt())
->setShowContactOnReceipt($location->getShowContactOnReceipt())
->setStreetAddress($location->getStreetAddress())
->setTelephone($location->getTelephone())
->setWebsite($location->getWebsite());
}
$this->entity_manager->persist($daily_financial_statement_location);
$this->entity_manager->flush();
$daily_financial_statement_cashbox = new DailyFinancialStatementCashbox();
$daily_financial_statement_cashbox
->setCashbox($cashbox)
->setComment($cashbox->getComment())
->setDailyFinancialStatementLocation($daily_financial_statement_location)
->setLocked($cashbox->getLocked())
->setName($cashbox->getName())
->setSerialNumber($cashbox->getSerialNumber());
$this->entity_manager->persist($daily_financial_statement_cashbox);
$this->entity_manager->flush();
$cashbox_deposit_container = $this->cashbox_service->getCashboxDeposit($cashbox, $cashbox_session);
/**
* @var CashboxDeposit $cashbox_deposit
*/
foreach ($cashbox_deposit_container as $cashbox_deposit) {
$daily_financial_statement_cashbox_deposit = new DailyFinancialStatementCashboxDeposit();
$daily_financial_statement_cashbox_deposit
->setAddDate($cashbox_deposit->getAddDate())
->setValue($cashbox_deposit->getValue())
->setCashboxDeposit($cashbox_deposit)
->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
$this->entity_manager->persist($daily_financial_statement_cashbox_deposit);
}
$this->entity_manager->flush();
$cashbox_withdrawal_container = $this->cashbox_service->getCashboxWithdrawal($cashbox, $cashbox_session);
/**
* @var CashboxWithdrawal $cashbox_withdrawal
*/
foreach ($cashbox_withdrawal_container as $cashbox_withdrawal) {
$daily_financial_statement_cashbox_withdrawal = new DailyFinancialStatementCashboxWithdrawal();
$daily_financial_statement_cashbox_withdrawal
->setAddDate($cashbox_withdrawal->getAddDate())
->setValue($cashbox_withdrawal->getValue())
->setCashboxWithdrawal($cashbox_withdrawal)
->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
$this->entity_manager->persist($daily_financial_statement_cashbox_withdrawal);
}
$this->entity_manager->flush();
$cashbox_payment_to_supplier_container = $this->cashbox_service->getCashboxPaymentToSupplier($cashbox, $cashbox_session);
/**
* @var CashboxPaymentToSupplier $cashbox_payment_to_supplier
*/
foreach ($cashbox_payment_to_supplier_container as $cashbox_payment_to_supplier) {
$daily_financial_statement_cashbox_payment_to_supplier = new DailyFinancialStatementCashboxPaymentToSupplier();
$daily_financial_statement_cashbox_payment_to_supplier
->setAddDate($cashbox_payment_to_supplier->getAddDate())
->setValue($cashbox_payment_to_supplier->getValue())
->setCashboxPaymentToSupplier($cashbox_payment_to_supplier)
->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
$this->entity_manager->persist($daily_financial_statement_cashbox_payment_to_supplier);
}
$this->entity_manager->flush();
$daily_financial_statement = new DailyFinancialStatement();
$daily_financial_statement
->setStartDate($cashbox_session->getStartDate())
->setEndDate($cashbox_session->getStopDate())
->setCashboxStartValue($cashbox_session->getCashStart())
->setCashboxEndValue($cashbox_session->getCashStop())
->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox)
->setManually(false);
$this->entity_manager->persist($daily_financial_statement);
$this->entity_manager->flush();
foreach ($data['money_stack_data']['factory'] as $item_factor => $item_amount) {
$daily_financial_statement_counting = new DailyFinancialStatementCounting();
$daily_financial_statement_counting
->setAddDate(new \DateTime('now'))
->setDailyFinancialStatement($daily_financial_statement)
->setFactor((int)$item_factor)
->setAmount((int)$item_amount);
$this->entity_manager->persist($daily_financial_statement_counting);
}
$this->entity_manager->flush();
$receipt_container = $this->daily_financial_statement_service->getReceipt($cashbox, $daily_financial_statement);
/**
* @var Receipt $receipt
*/
foreach ($receipt_container as $receipt) {
$receipt->setDailyFinancialStatement($daily_financial_statement);
$this->entity_manager->persist($receipt);
}
$this->entity_manager->flush();
/*
// Fiskaly
$cash_point_closing = new CashPointClosingStructure();
$cash_point_closing_head = new CashPointClosingHeadStructure();
$cash_point_closing_head->setExportCreationDate(time())
->setFirstTransactionExportId()
->setLastTransactionExportId();
$cash_point_closing->setHead($cash_point_closing_head)
->setClientId()
->setCashPointClosingExportId();*/
return new JsonResponse(['_success' => true]);
}
}
}
return new JsonResponse(['_success' => false]);
}
private function _check()
{
$daily_financial_statement = $this->daily_financial_statement_repository->findOneBy(['end_date' => null], ['id' => 'DESC']);
if ($daily_financial_statement instanceof DailyFinancialStatement) {
return true;
}
return false;
}
}