src/Controller/CashBox/DailyFinancialStatementController.php line 102

Open in your IDE?
  1. <?php
  2. namespace App\Controller\CashBox;
  3. use App\Entity\Cashbox;
  4. use App\Entity\CashboxCounting;
  5. use App\Entity\CashboxDeposit;
  6. use App\Entity\CashboxPaymentToSupplier;
  7. use App\Entity\CashboxWithdrawal;
  8. use App\Entity\Company;
  9. use App\Entity\DailyFinancialStatement;
  10. use App\Entity\DailyFinancialStatementCashbox;
  11. use App\Entity\DailyFinancialStatementCashboxDeposit;
  12. use App\Entity\DailyFinancialStatementCashboxPaymentToSupplier;
  13. use App\Entity\DailyFinancialStatementCashboxWithdrawal;
  14. use App\Entity\DailyFinancialStatementCounting;
  15. use App\Entity\DailyFinancialStatementLocation;
  16. use App\Entity\Location;
  17. use App\Entity\Receipt;
  18. use App\Repository\CashboxRepository;
  19. use App\Repository\CompanyRepository;
  20. use App\Repository\DailyFinancialStatementRepository;
  21. use App\Repository\ReceiptRepository;
  22. use App\Service\CashBox\CashboxService;
  23. use App\Service\CashBox\DailyFinancialStatementService;
  24. use App\Service\CashBox\ReceiptService;
  25. use App\Service\TimeZoneDetectionService;
  26. use App\Structure\Fiskaly\CashPointClosingHeadStructure;
  27. use App\Structure\Fiskaly\CashPointClosingStructure;
  28. use Doctrine\ORM\EntityManagerInterface;
  29. use Dompdf\Dompdf;
  30. use Dompdf\Options;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. use Symfony\Component\HttpFoundation\JsonResponse;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Component\VarDumper\Cloner\VarCloner;
  37. use Symfony\Component\VarDumper\Dumper\CliDumper;
  38. /**
  39.  * @Route("/daily_financial_statement")
  40.  */
  41. class DailyFinancialStatementController extends AbstractController
  42. {
  43.     private EntityManagerInterface $entity_manager;
  44.     private SessionInterface $session;
  45.     private ReceiptRepository $receipt_repository;
  46.     private DailyFinancialStatementRepository $daily_financial_statement_repository;
  47.     private CompanyRepository $company_repository;
  48.     private CashboxService $cashbox_service;
  49.     private DailyFinancialStatementService $daily_financial_statement_service;
  50.     private TimeZoneDetectionService $timeZoneDetectionService;
  51.     private ReceiptService $receipt_service;
  52.     public function __construct(EntityManagerInterface $entity_managerSessionInterface $sessionReceiptRepository $receipt_repositoryDailyFinancialStatementRepository $daily_financial_statement_repositoryCompanyRepository $company_repositoryCashboxRepository $cashbox_repositoryCashboxService $cashbox_serviceDailyFinancialStatementService $daily_financial_statement_serviceTimeZoneDetectionService $timeZoneDetectionServiceReceiptService $receipt_service)
  53.     {
  54.         $this->entity_manager $entity_manager;
  55.         $this->session $session;
  56.         $this->receipt_repository $receipt_repository;
  57.         $this->daily_financial_statement_repository $daily_financial_statement_repository;
  58.         $this->company_repository $company_repository;
  59.         $this->cashbox_repository $cashbox_repository;
  60.         $this->cashbox_service $cashbox_service;
  61.         $this->daily_financial_statement_service $daily_financial_statement_service;
  62.         $this->timeZoneDetectionService $timeZoneDetectionService;
  63.         $this->receipt_service $receipt_service;
  64.     }
  65.     /**
  66.      * @Route("/", name="daily_financial_statement", methods={"GET","POST"})
  67.      */
  68.     public function index()
  69.     {
  70.         return new JsonResponse([]);
  71.     }
  72.     /**
  73.      * @Route("/load/{id}", name="load_daily_financial_statement", methods={"GET","POST"})
  74.      */
  75.     public function load(Request $requestDailyFinancialStatement $dailyFinancialStatement)
  76.     {
  77.         $_dailyFinancialStatement = [
  78.             'id' => $dailyFinancialStatement->getId(),
  79.             'start_date' => $dailyFinancialStatement->getStartDate()->format("d.m.Y / H:i"),
  80.             'end_date' => $dailyFinancialStatement->getEndDate()->format("d.m.Y / H:i"),
  81.             'cashbox_start_value' => ($dailyFinancialStatement->getCashboxStartValue() ?? 0.00),
  82.             'cashbox_end_value' => ($dailyFinancialStatement->getCashboxEndValue() ?? 0.00),
  83.             'deposit_total' => ($dailyFinancialStatement->getDeposits() ?? 0.00),
  84.             'withdrawal_total' => ($dailyFinancialStatement->getWithdrawals() ?? 0.00),
  85.             'payment_to_supplier_total' => ($dailyFinancialStatement->getPaymentsToSuppliers() ?? 0.00),
  86.             'card_payment' => ($dailyFinancialStatement->getCardPayment() ?? 0.00),
  87.         ];
  88.         return new JsonResponse(['_success' => true'daily_financial_statement' => $_dailyFinancialStatement]);
  89.     }
  90.     /**
  91.      * @Route("/loadprint/{id}", name="loadprint_daily_financial_statement", methods={"GET","POST"})
  92.      */
  93.     public function loadPrint_(Request $requestDailyFinancialStatement $daily_financial_statement)
  94.     {
  95.         if ($daily_financial_statement->getManually() === true) {
  96.             $cashbox_deposit_total $daily_financial_statement->getDeposits();
  97.             $cashbox_withdrawal_total $daily_financial_statement->getWithdrawals();
  98.             $cashbox_payments_to_supplier_total $daily_financial_statement->getPaymentsToSuppliers();
  99.         } else {
  100.             $cashbox_deposit_total $this->daily_financial_statement_service->getDepositTotal($daily_financial_statement);
  101.             $cashbox_withdrawal_total $this->daily_financial_statement_service->getWithdrawalTotal($daily_financial_statement);
  102.             $cashbox_payments_to_supplier_total $this->daily_financial_statement_service->getPaymentToSupplierTotal($daily_financial_statement);
  103.         }
  104.         $daily_financial_statement_ = [
  105.             'company' => [
  106.                 'address_addition' => null,
  107.                 'address_country' => null,
  108.                 'address_locality' => null,
  109.                 'email' => null,
  110.                 'fax_number' => null,
  111.                 'id' => null,
  112.                 'line_1' => null,
  113.                 'line_2' => null,
  114.                 'logo' => null,
  115.                 'name' => null,
  116.                 'postal_code' => null,
  117.                 'street_address' => null,
  118.                 'tax_number' => null,
  119.                 'telephone' => null,
  120.                 'vat_id' => null,
  121.                 'website' => null,
  122.             ],
  123.             'cashbox' => [
  124.                 'id' => null,
  125.                 'cashbox_id' => null,
  126.                 'name' => null,
  127.                 'comment' => null,
  128.                 'locked' => null,
  129.                 'serial_number' => null,
  130.             ],
  131.             'location' => [
  132.                 'id' => null,
  133.                 'location_id' => null,
  134.                 'name' => null,
  135.                 'logo' => null,
  136.                 'street_address' => null,
  137.                 'postal_code' => null,
  138.                 'address_locality' => null,
  139.                 'address_addition' => null,
  140.                 'address_country' => null,
  141.                 'telephone' => null,
  142.                 'website' => null,
  143.                 'email' => null,
  144.                 'fax_number' => null,
  145.                 'show_address_on_receipt' => null,
  146.                 'show_contact_on_receipt' => null,
  147.             ],
  148.             'daily_financial_statement' => [
  149.                 'id' => null,
  150.                 'cashbox_start_value' => 0,
  151.                 'cashbox_start_value_f' => 0,
  152.                 'cashbox_end_value' => 0,
  153.                 'cashbox_end_value_f' => 0,
  154.                 'receipt_value' => 0,
  155.                 'receipt_value_f' => 0,
  156.                 'start_date' => null,
  157.                 'start_date_f' => null,
  158.                 'start_date_f_y' => null,
  159.                 'start_date_f_m' => null,
  160.                 'start_date_f_d' => null,
  161.                 'start_date_f_h' => null,
  162.                 'start_date_f_i' => null,
  163.                 'start_date_f_s' => null,
  164.                 'end_date' => null,
  165.                 'end_date_f' => null,
  166.                 'end_date_f_y' => null,
  167.                 'end_date_f_m' => null,
  168.                 'end_date_f_d' => null,
  169.                 'end_date_f_h' => null,
  170.                 'end_date_f_i' => null,
  171.                 'end_date_f_s' => null,
  172.                 'deposit_total' => 0,
  173.                 'deposit_total_f' => 0,
  174.                 'withdrawal_total' => 0,
  175.                 'withdrawal_total_f' => 0,
  176.                 'payment_to_supplier_total' => 0,
  177.                 'payment_to_supplier_total_f' => 0,
  178.                 'card_payment' => 0,
  179.                 'card_payment_f' => 0,
  180.                 'manually' => false,
  181.             ],
  182.             'cashbox_counting' => [
  183.                 'counting' => [],
  184.                 'counting_total' => [],
  185.                 'total' => 0,
  186.                 'total_f' => 0,
  187.             ],
  188.             'receipt_cash' => 0,
  189.             'noreceipt_cash' => 0,
  190.             'cash_debit' => 0,
  191.             'receipt_count' => 0,
  192.             'tax' => [],
  193.             'gezaehlt' => (float)0,
  194.             'soll' => (float)0,
  195.             'differenz' => (float)0,
  196.             'zbonnr' => 0,
  197.             'anfangsbestand' => (float)0,
  198.             'einlagen' => (float)0,
  199.             'entnahmen' => (float)0,
  200.             'zahlungen_an_lieferanten' => (float)0,
  201.             'position_count' => 0,
  202.             'anzahl_bon_stornos' => 0,
  203.             'verkaufte_gutscheine' => 0,
  204.             'receipt_value_average' => (float)0,
  205.             'bar' => (float)0,
  206.             'ec_karte' => (float)0,
  207.             'kreditkarte' => (float)0,
  208.             'auf_rechnung_gezahlt' => (float)0,
  209.             'group_by_payment_method' => [],
  210.             'receipt_total' => (float)0,
  211.             'bankeinzahlungen' => (float)0,
  212.             'bar_differenzen' => (float)0,
  213.             'wechselgeldvortrag' => (float)0,
  214.             'zahlungen_von_kunden_rechnungen' => (float)0,
  215.             'geleistete_anzahlungen_auf_kassenauftraege' => (float)0,
  216.             'summe_retourenpositionen' => (float)0,
  217.             'eingeloeste_gutscheine' => (float)0,
  218.             'gutschein_aus_guthaben' => (float)0,
  219.             'verrechnete_anzahlungen' => (float)0,
  220.             'verrechnete_gutschriften' => (float)0,
  221.         ];
  222.         $daily_financial_statement_['soll_f'] = number_format($daily_financial_statement_['soll'], 2'•''');
  223.         $daily_financial_statement_['differenz_f'] = number_format($daily_financial_statement_['differenz'], 2'•''');
  224.         $daily_financial_statement_['anfangsbestand_f'] = number_format($daily_financial_statement_['anfangsbestand'], 2'•''');
  225.         $daily_financial_statement_['einlagen_f'] = number_format($daily_financial_statement_['einlagen'], 2'•''');
  226.         $daily_financial_statement_['entnahmen_f'] = number_format($daily_financial_statement_['entnahmen'], 2'•''');
  227.         $daily_financial_statement_['zahlungen_an_lieferanten_f'] = number_format($daily_financial_statement_['zahlungen_an_lieferanten'], 2'•''');
  228.         $daily_financial_statement_['receipt_cash_f'] = number_format($daily_financial_statement_['receipt_cash'], 2'•''');
  229.         $daily_financial_statement_['cash_debit_f'] = number_format($daily_financial_statement_['cash_debit'], 2'•''');
  230.         $daily_financial_statement_['receipt_value_average_f'] = number_format($daily_financial_statement_['receipt_value_average'], 2'•''');
  231.         $daily_financial_statement_['bar_f'] = number_format($daily_financial_statement_['bar'], 2'•''');
  232.         $daily_financial_statement_['ec_karte_f'] = number_format($daily_financial_statement_['ec_karte'], 2'•''');
  233.         $daily_financial_statement_['kreditkarte_f'] = number_format($daily_financial_statement_['kreditkarte'], 2'•''');
  234.         $daily_financial_statement_['auf_rechnung_gezahlt_f'] = number_format($daily_financial_statement_['auf_rechnung_gezahlt'], 2'•''');
  235.         $daily_financial_statement_['receipt_total_f'] = number_format($daily_financial_statement_['receipt_total'], 2'•''');
  236.         $daily_financial_statement_['bankeinzahlungen_f'] = number_format($daily_financial_statement_['bankeinzahlungen'], 2'•''');
  237.         $daily_financial_statement_['bar_differenzen_f'] = number_format($daily_financial_statement_['bar_differenzen'], 2'•''');
  238.         $daily_financial_statement_['wechselgeldvortrag_f'] = number_format($daily_financial_statement_['wechselgeldvortrag'], 2'•''');
  239.         $daily_financial_statement_['zahlungen_von_kunden_rechnungen_f'] = number_format($daily_financial_statement_['zahlungen_von_kunden_rechnungen'], 2'•''');
  240.         $daily_financial_statement_['geleistete_anzahlungen_auf_kassenauftraege_f'] = number_format($daily_financial_statement_['geleistete_anzahlungen_auf_kassenauftraege'], 2'•''');
  241.         $daily_financial_statement_['summe_retourenpositionen_f'] = number_format($daily_financial_statement_['summe_retourenpositionen'], 2'•''');
  242.         $daily_financial_statement_['eingeloeste_gutscheine_f'] = number_format($daily_financial_statement_['eingeloeste_gutscheine'], 2'•''');
  243.         $daily_financial_statement_['gutschein_aus_guthaben_f'] = number_format($daily_financial_statement_['gutschein_aus_guthaben'], 2'•''');
  244.         $daily_financial_statement_['verrechnete_anzahlungen_f'] = number_format($daily_financial_statement_['verrechnete_anzahlungen'], 2'•''');
  245.         $daily_financial_statement_['verrechnete_gutschriften_f'] = number_format($daily_financial_statement_['verrechnete_gutschriften'], 2'•''');
  246.         $company $this->company_repository->findOneBy(['id' => 1]);
  247.         if ($company instanceof Company) {
  248.             $daily_financial_statement_['company'] = [
  249.                 'address_addition' => $company->getAddressAddition(),
  250.                 'address_country' => $company->getAddressCountry(),
  251.                 'address_locality' => $company->getAddressLocality(),
  252.                 'email' => $company->getEmail(),
  253.                 'fax_number' => $company->getFaxNumber(),
  254.                 'id' => $company->getId(),
  255.                 'line_1' => $company->getLine1(),
  256.                 'line_2' => $company->getLine2(),
  257.                 'logo' => $company->getLogo(),
  258.                 'name' => $company->getName(),
  259.                 'postal_code' => $company->getPostalCode(),
  260.                 'street_address' => $company->getStreetAddress(),
  261.                 'tax_number' => $company->getTaxNumber(),
  262.                 'telephone' => $company->getTelephone(),
  263.                 'vat_id' => $company->getVatId(),
  264.                 'website' => $company->getWebsite(),
  265.             ];
  266.         }
  267.         $dailyFinancialStatementCashbox $daily_financial_statement->getDailyFinancialStatementCashbox();
  268.         if ($dailyFinancialStatementCashbox instanceof DailyFinancialStatementCashbox) {
  269.             $daily_financial_statement_['cashbox'] = [
  270.                 'id' => $dailyFinancialStatementCashbox->getId(),
  271.                 'cashbox_id' => null,
  272.                 'name' => $dailyFinancialStatementCashbox->getName(),
  273.                 'comment' => $dailyFinancialStatementCashbox->getComment(),
  274.                 'locked' => $dailyFinancialStatementCashbox->getLocked(),
  275.                 'serial_number' => $dailyFinancialStatementCashbox->getSerialNumber(),
  276.             ];
  277.             if ($dailyFinancialStatementCashbox->getCashbox() instanceof Cashbox) {
  278.                 $daily_financial_statement_['cashbox']['cashbox_id'] = $dailyFinancialStatementCashbox->getCashbox()->getId();
  279.             }
  280.             $dailyFinancialStatementLocation $dailyFinancialStatementCashbox->getDailyFinancialStatementLocation();
  281.             if ($dailyFinancialStatementLocation instanceof DailyFinancialStatementLocation) {
  282.                 $daily_financial_statement_['location'] = [
  283.                     'id' => $dailyFinancialStatementLocation->getId(),
  284.                     'location_id' => null,
  285.                     'name' => $dailyFinancialStatementLocation->getName(),
  286.                     'logo' => $dailyFinancialStatementLocation->getLogo(),
  287.                     'street_address' => $dailyFinancialStatementLocation->getStreetAddress(),
  288.                     'postal_code' => $dailyFinancialStatementLocation->getPostalCode(),
  289.                     'address_locality' => $dailyFinancialStatementLocation->getAddressLocality(),
  290.                     'address_addition' => $dailyFinancialStatementLocation->getAddressAddition(),
  291.                     'address_country' => $dailyFinancialStatementLocation->getAddressCountry(),
  292.                     'telephone' => $dailyFinancialStatementLocation->getTelephone(),
  293.                     'website' => $dailyFinancialStatementLocation->getWebsite(),
  294.                     'email' => $dailyFinancialStatementLocation->getEmail(),
  295.                     'fax_number' => $dailyFinancialStatementLocation->getFaxNumber(),
  296.                     'show_address_on_receipt' => $dailyFinancialStatementLocation->getShowAddressOnReceipt(),
  297.                     'show_contact_on_receipt' => $dailyFinancialStatementLocation->getShowContactOnReceipt(),
  298.                 ];
  299.                 if ($dailyFinancialStatementLocation->getLocation() instanceof Location) {
  300.                     $daily_financial_statement_['location']['location_id'] = $dailyFinancialStatementLocation->getLocation()->getId();
  301.                 }
  302.             }
  303.             $daily_financial_statement__ = [
  304.                 'id' => $daily_financial_statement->getId(),
  305.                 'cashbox_start_value' => ($daily_financial_statement->getCashboxStartValue() ?? 0),
  306.                 'cashbox_start_value_f' => ($daily_financial_statement->getCashboxStartValue() ?? 0),
  307.                 'cashbox_end_value' => ($daily_financial_statement->getCashboxEndValue() ?? 0),
  308.                 'cashbox_end_value_f' => ($daily_financial_statement->getCashboxEndValue() ?? 0),
  309.                 'receipt_value' => ($daily_financial_statement->getReceiptValue() ?? 0),
  310.                 'receipt_value_f' => ($daily_financial_statement->getReceiptValue() ?? 0),
  311.                 'start_date' => $daily_financial_statement->getStartDate(),
  312.                 'start_date_f' => $daily_financial_statement->getStartDate(),
  313.                 'start_date_f_y' => $daily_financial_statement->getStartDate(),
  314.                 'start_date_f_m' => $daily_financial_statement->getStartDate(),
  315.                 'start_date_f_d' => $daily_financial_statement->getStartDate(),
  316.                 'start_date_f_h' => $daily_financial_statement->getStartDate(),
  317.                 'start_date_f_i' => $daily_financial_statement->getStartDate(),
  318.                 'start_date_f_s' => $daily_financial_statement->getStartDate(),
  319.                 'end_date' => $daily_financial_statement->getEndDate(),
  320.                 'end_date_f' => $daily_financial_statement->getEndDate(),
  321.                 'end_date_f_y' => $daily_financial_statement->getEndDate(),
  322.                 'end_date_f_m' => $daily_financial_statement->getEndDate(),
  323.                 'end_date_f_d' => $daily_financial_statement->getEndDate(),
  324.                 'end_date_f_h' => $daily_financial_statement->getEndDate(),
  325.                 'end_date_f_i' => $daily_financial_statement->getEndDate(),
  326.                 'end_date_f_s' => $daily_financial_statement->getEndDate(),
  327.                 'deposit_total' => $cashbox_deposit_total,
  328.                 'deposit_total_f' => $cashbox_deposit_total,
  329.                 'withdrawal_total' => $cashbox_withdrawal_total,
  330.                 'withdrawal_total_f' => $cashbox_withdrawal_total,
  331.                 'payment_to_supplier_total' => $cashbox_payments_to_supplier_total,
  332.                 'payment_to_supplier_total_f' => $cashbox_payments_to_supplier_total,
  333.                 'card_payment' => ($daily_financial_statement->getCardPayment() ?? 0),
  334.                 'card_payment_f' => ($daily_financial_statement->getCardPayment() ?? 0),
  335.                 'manually' => $daily_financial_statement->getManually(),
  336.             ];
  337.             $daily_financial_statement__['cashbox_start_value_f'] = number_format(round((float)$daily_financial_statement__['cashbox_start_value_f'], 2), 2'•''');
  338.             $daily_financial_statement__['cashbox_end_value_f'] = number_format(round((float)($daily_financial_statement__['cashbox_end_value_f'] / 100), 2), 2'•''');
  339.             $daily_financial_statement__['receipt_value_f'] = number_format(round((float)$daily_financial_statement__['receipt_value_f'], 2), 2'•''');
  340.             $daily_financial_statement__['deposit_total_f'] = number_format(round((float)$daily_financial_statement__['deposit_total_f'], 2), 2'•''');
  341.             $daily_financial_statement__['withdrawal_total_f'] = number_format(round((float)$daily_financial_statement__['withdrawal_total_f'], 2), 2'•''');
  342.             $daily_financial_statement__['payment_to_supplier_total_f'] = number_format(round((float)$daily_financial_statement__['payment_to_supplier_total_f'], 2), 2'•''');
  343.             $daily_financial_statement__['card_payment_f'] = number_format(round((float)$daily_financial_statement__['card_payment_f'], 2), 2'•''');
  344.             $daily_financial_statement__['start_date_f'] = $daily_financial_statement__['start_date_f']->format("d.m.Y / H:i:s");
  345.             $daily_financial_statement__['start_date_f_y'] = $daily_financial_statement__['start_date_f_y']->format("Y");
  346.             $daily_financial_statement__['start_date_f_m'] = $daily_financial_statement__['start_date_f_m']->format("m");
  347.             $daily_financial_statement__['start_date_f_d'] = $daily_financial_statement__['start_date_f_d']->format("d");
  348.             $daily_financial_statement__['start_date_f_h'] = $daily_financial_statement__['start_date_f_h']->format("H");
  349.             $daily_financial_statement__['start_date_f_i'] = $daily_financial_statement__['start_date_f_i']->format("i");
  350.             $daily_financial_statement__['start_date_f_s'] = $daily_financial_statement__['start_date_f_s']->format("s");
  351.             $daily_financial_statement__['end_date_f'] = $daily_financial_statement__['end_date_f']->format("d.m.Y / H:i:s");
  352.             $daily_financial_statement__['end_date_f_y'] = $daily_financial_statement__['end_date_f_y']->format("Y");
  353.             $daily_financial_statement__['end_date_f_m'] = $daily_financial_statement__['end_date_f_m']->format("m");
  354.             $daily_financial_statement__['end_date_f_d'] = $daily_financial_statement__['end_date_f_d']->format("d");
  355.             $daily_financial_statement__['end_date_f_h'] = $daily_financial_statement__['end_date_f_h']->format("H");
  356.             $daily_financial_statement__['end_date_f_i'] = $daily_financial_statement__['end_date_f_i']->format("i");
  357.             $daily_financial_statement__['end_date_f_s'] = $daily_financial_statement__['end_date_f_s']->format("s");
  358.             $daily_financial_statement_['daily_financial_statement'] = $daily_financial_statement__;
  359.             if ($daily_financial_statement->getManually() === false) {
  360.                 $countings $daily_financial_statement->getDailyFinancialStatementCountings();
  361.                 if ($countings->count() > 0) {
  362.                     foreach ($countings as $counting) {
  363.                         $daily_financial_statement_['cashbox_counting']['counting'][$counting->getFactor()] = $counting->getAmount();
  364.                         $daily_financial_statement_['cashbox_counting']['counting_total'][$counting->getFactor()] = [
  365.                             'total' => ($counting->getFactor() * $counting->getAmount()),
  366.                             'total_f' => number_format(round((float)(($counting->getFactor() * $counting->getAmount()) / 100), 2), 2'•'''),
  367.                         ];
  368.                         $daily_financial_statement_['cashbox_counting']['total'] += ($counting->getFactor() * $counting->getAmount());
  369.                     }
  370.                     $daily_financial_statement_['cashbox_counting']['total_f'] = number_format(round((float)($daily_financial_statement_['cashbox_counting']['total'] / 100), 2), 2'•''');
  371.                 }
  372.             }
  373.             $receipt_container $daily_financial_statement->getReceipts();
  374.             if ($receipt_container->count() > 0) {
  375.                 $tax = ['total' => [], 'cash' => [], 'nocash' => []];
  376.                 $position_count 0;
  377.                 $receipt_totals 0;
  378.                 $group_by_payment_method = [];
  379.                 $group_by_cash_nocash = ['cash' => 0'nocash' => 0];
  380.                 foreach ($receipt_container as $receipt) {
  381.                     if ($receipt->getCanceled() === true || $receipt->getReversalReceipt() === true) {
  382.                         //Do nothing
  383.                     } else {
  384.                         $base_receipt $receipt;
  385.                         if ($receipt->getReversalReceipt() === true) {
  386.                             $receipt_ $this->receipt_service->getReceiptFromReversalReceipt($receipt);
  387.                             if ($receipt_ !== false) {
  388.                                 $base_receipt $receipt_;
  389.                             }
  390.                         }
  391.                         if ($daily_financial_statement->getManually() === false) {
  392.                             if ($receipt->getReversalReceipt() === true) {
  393.                                 $position_count -= $base_receipt->getReceiptCartProducts()->count();
  394. //                            $receipt_totals += 0-$receipt->getCartTotalFixed();
  395.                                 $receipt_totals -= $base_receipt->getTotalFixed();
  396.                             } else {
  397.                                 $position_count += $base_receipt->getReceiptCartProducts()->count();
  398. //                            $receipt_totals += $receipt->getCartTotalFixed();
  399.                                 $receipt_totals += $base_receipt->getTotalFixed();
  400.                             }
  401.                             $receipt_transaction $receipt->getReceiptTransactions()->last();
  402.                             $receipt_cart_products $receipt->getReceiptCartProducts();
  403.                             foreach ($receipt_cart_products as $receipt_cart_product) {
  404.                                 $receipt_product $receipt_cart_product->getReceiptProduct();
  405.                                 if (!isset($tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  406.                                     $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];
  407.                                 }
  408.                                 if (!isset($tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  409.                                     $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];
  410.                                 }
  411.                                 if (!isset($tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  412.                                     $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];
  413.                                 }
  414.                                 if ($receipt->getReversalReceipt() === true) {
  415.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] -= $receipt_cart_product->getTotalFixed();
  416.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] -= $receipt_cart_product->getTotalOtaxFixed();
  417.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] -= ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
  418.                                 } else {
  419.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
  420.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
  421.                                     $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
  422.                                 }
  423.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2'•''');
  424.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2'•''');
  425.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2'•''');
  426.                             }
  427.                             if ($receipt_transaction !== false) {
  428.                                 $receipt_payment_method $receipt_transaction->getReceiptPaymentMethod();
  429.                                 if ($receipt_payment_method !== null) {
  430.                                     if (!isset($group_by_payment_method[$receipt_payment_method->getName()])) {
  431.                                         $group_by_payment_method[$receipt_payment_method->getName()] = 0;
  432.                                     }
  433. //                                $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getCartTotalFixed();
  434.                                     $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getTotalFixed();
  435.                                     if ($receipt_payment_method->getCash() === true) {
  436. //                                    $group_by_cash_nocash['cash'] += $receipt->getCartTotalFixed();
  437.                                         $group_by_cash_nocash['cash'] += $receipt->getTotalFixed();
  438.                                         $group_by_cash_nocash['cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2'•''');
  439.                                         foreach ($receipt_cart_products as $receipt_cart_product) {
  440.                                             $receipt_product $receipt_cart_product->getReceiptProduct();
  441.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
  442.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
  443.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
  444.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2'•''');
  445.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2'•''');
  446.                                             $tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2'•''');
  447.                                         }
  448.                                     } else {
  449.                                         $group_by_cash_nocash['nocash'] += $receipt->getTotalFixed();
  450. //                                    $group_by_cash_nocash['nocash'] += $receipt->getCartTotalFixed();
  451.                                         $group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2'•''');
  452.                                         foreach ($receipt_cart_products as $receipt_cart_product) {
  453.                                             $receipt_product $receipt_cart_product->getReceiptProduct();
  454.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
  455.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
  456.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
  457.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2'•''');
  458.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2'•''');
  459.                                             $tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2'•''');
  460.                                         }
  461.                                     }
  462.                                 }
  463.                             }
  464.                         } else {
  465.                             $position_count += $receipt->getReceiptCartProducts()->count();
  466. //                        $receipt_totals += $receipt->getCartTotalFixed();
  467.                             $receipt_totals += $base_receipt->getTotalFixed();
  468.                             $receipt_transaction $receipt->getReceiptTransactions()->last();
  469.                             $receipt_cart_products $receipt->getReceiptCartProducts();
  470.                             foreach ($receipt_cart_products as $receipt_cart_product) {
  471.                                 $receipt_product $receipt_cart_product->getReceiptProduct();
  472.                                 if (!isset($tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  473.                                     $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];
  474.                                 }
  475.                                 if (!isset($tax['cash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  476.                                     $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];
  477.                                 }
  478.                                 if (!isset($tax['nocash'][$receipt_product->getReceiptTax()->getReceiptTax()])) {
  479.                                     $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];
  480.                                 }
  481.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'] += $receipt_cart_product->getTotalFixed();
  482.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'] += $receipt_cart_product->getTotalOtaxFixed();
  483.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'] += ($receipt_cart_product->getTotalFixed() - $receipt_cart_product->getTotalOtaxFixed());
  484.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total'], 2), 2'•''');
  485.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_notax'], 2), 2'•''');
  486.                                 $tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax_f'] = number_format(round((float)$tax['total'][$receipt_product->getReceiptTax()->getReceiptTax()]['total_tax'], 2), 2'•''');
  487.                             }
  488.                             if ($receipt_transaction !== false) {
  489.                                 $receipt_payment_method $receipt_transaction->getReceiptPaymentMethod();
  490.                                 if ($receipt_payment_method !== null) {
  491.                                     if (!isset($group_by_payment_method[$receipt_payment_method->getName()])) {
  492.                                         $group_by_payment_method[$receipt_payment_method->getName()] = 0;
  493.                                     }
  494. //                                $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getCartTotalFixed();
  495.                                     $group_by_payment_method[$receipt_payment_method->getName()] += $receipt->getTotalFixed();
  496.                                     if ($receipt_payment_method->getCash() === true) {
  497. //                                    $group_by_cash_nocash['cash'] += $receipt->getCartTotalFixed();
  498.                                         $group_by_cash_nocash['cash'] += $receipt->getTotalFixed();
  499.                                         $group_by_cash_nocash['cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2'•''');
  500.                                     } else {
  501. //                                    $group_by_cash_nocash['nocash'] += $receipt->getCartTotalFixed();
  502.                                         $group_by_cash_nocash['nocash'] += $receipt->getTotalFixed();
  503.                                         $group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2'•''');
  504.                                     }
  505.                                     $group_by_cash_nocash['nocash'] += $daily_financial_statement->getCardPayment();
  506.                                     $group_by_cash_nocash['nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2'•''');
  507.                                 }
  508.                             }
  509.                         }
  510.                     }
  511.                 }
  512.                 $daily_financial_statement_['receipt_cash'] = $group_by_cash_nocash['cash'];
  513.                 $daily_financial_statement_['receipt_nocash'] = $group_by_cash_nocash['nocash'];
  514.                 $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']);
  515.                 $daily_financial_statement_['cashbox_cash_debit_f'] = number_format(round((float)$daily_financial_statement_['cashbox_cash_debit'], 2), 2'•''');
  516.                 $daily_financial_statement_['receipt_cash_f'] = number_format(round((float)$group_by_cash_nocash['cash'], 2), 2'•''');
  517.                 $daily_financial_statement_['receipt_nocash_f'] = number_format(round((float)$group_by_cash_nocash['nocash'], 2), 2'•''');
  518.                 $daily_financial_statement_['cash_debit'] = $daily_financial_statement_['daily_financial_statement']['cashbox_start_value'] + $daily_financial_statement_['receipt_cash'];
  519.                 $daily_financial_statement_['cash_debit_f'] = number_format(round((float)$daily_financial_statement_['cash_debit'], 2), 2'•''');
  520.                 $daily_financial_statement_['receipt_count'] = $receipt_container->count();
  521.                 $daily_financial_statement_['position_count'] = $position_count;
  522.                 $daily_financial_statement_['receipt_value_average'] = round(($receipt_totals $receipt_container->count()), 2);
  523.                 $daily_financial_statement_['receipt_value_average_f'] = number_format((float)$daily_financial_statement_['receipt_value_average'], 2'•''');
  524.                 $daily_financial_statement_['group_by_payment_method'] = $group_by_payment_method;
  525.                 $daily_financial_statement_['group_by_cash_nocash'] = $group_by_cash_nocash;
  526.                 $daily_financial_statement_['receipt_total'] = $receipt_totals;
  527.                 $daily_financial_statement_['receipt_total_f'] = number_format(round((float)$daily_financial_statement_['receipt_total'], 2), 2'•''');
  528.                 $daily_financial_statement_['summe2'] = $daily_financial_statement_['receipt_cash'] + $daily_financial_statement_['receipt_nocash'];
  529.                 $daily_financial_statement_['summe2_f'] = number_format((float)round($daily_financial_statement_['summe2'], 2), 2'•''');
  530.                 $daily_financial_statement_['summe3'] = (float)0;
  531.                 $daily_financial_statement_['summe3_f'] = number_format((float)round($daily_financial_statement_['summe3'], 2), 2'•''');
  532.                 $daily_financial_statement_['differences'] = ['cash' => [], 'nocash' => ['Anzahlungen' => [], 'Gutschriften' => [], 'Gutscheine' => []]];
  533.                 $daily_financial_statement_['differences']['cash'] = [
  534.                     'debit' => $daily_financial_statement_['cashbox_cash_debit'],
  535.                     'debit_f' => $daily_financial_statement_['cashbox_cash_debit_f'],
  536.                     'credit' => (float)($daily_financial_statement__['cashbox_end_value'] / 100),
  537.                     'credit_f' => $daily_financial_statement__['cashbox_end_value_f'],
  538.                     'difference' => round(((float)($daily_financial_statement__['cashbox_end_value'] / 100)) - $daily_financial_statement_['cashbox_cash_debit'], 2),
  539.                     'difference_f' => number_format(round(((float)($daily_financial_statement__['cashbox_end_value'] / 100)) - $daily_financial_statement_['cashbox_cash_debit'], 2), 2'•'''),
  540.                 ];
  541.                 $daily_financial_statement_['differences']['nocash']['Anzahlungen'] = [
  542.                     'debit' => (float)0,
  543.                     'debit_f' => number_format((float)02'•'''),
  544.                     'credit' => (float)0,
  545.                     'credit_f' => number_format((float)02'•'''),
  546.                     'difference' => (float)0,
  547.                     'difference_f' => number_format((float)02'•'''),
  548.                 ];
  549.                 $daily_financial_statement_['differences']['nocash']['Gutschriften'] = [
  550.                     'debit' => (float)0,
  551.                     'debit_f' => number_format((float)02'•'''),
  552.                     'credit' => (float)0,
  553.                     'credit_f' => number_format((float)02'•'''),
  554.                     'difference' => (float)0,
  555.                     'difference_f' => number_format((float)02'•'''),
  556.                 ];
  557.                 $daily_financial_statement_['differences']['nocash']['Gutscheine'] = [
  558.                     'debit' => (float)0,
  559.                     'debit_f' => number_format((float)02'•'''),
  560.                     'credit' => (float)0,
  561.                     'credit_f' => number_format((float)02'•'''),
  562.                     'difference' => (float)0,
  563.                     'difference_f' => number_format((float)02'•'''),
  564.                 ];
  565.                 $daily_financial_statement_['tax'] = $tax;
  566.             }
  567.         }
  568.         return new JsonResponse(['_success' => true'daily_financial_statement_print' => $daily_financial_statement_]);
  569.     }
  570.     /**
  571.      * @Route("/update/{id}", name="update_daily_financial_statement", methods={"GET","POST"})
  572.      */
  573.     public function update(Request $requestDailyFinancialStatement $dailyFinancialStatement)
  574.     {
  575.         $data json_decode($request->getContent(), true);
  576.         $dailyFinancialStatement
  577.             ->setCashboxStartValue($data['daily_financial_statement_data']['cashbox_start_value'])
  578.             ->setCashboxEndValue($data['daily_financial_statement_data']['cashbox_end_value'])
  579.             ->setDeposits($data['daily_financial_statement_data']['deposit_total'])
  580.             ->setWithdrawals($data['daily_financial_statement_data']['withdrawal_total'])
  581.             ->setPaymentsToSuppliers($data['daily_financial_statement_data']['payment_to_supplier_total'])
  582.             ->setCardPayment($data['daily_financial_statement_data']['card_payment']);
  583.         $this->entity_manager->persist($dailyFinancialStatement);
  584.         $this->entity_manager->flush();
  585.         return new JsonResponse(['_success' => true]);
  586.     }
  587.     /**
  588.      * @Route("/print/{id}", name="print_daily_financial_statement", methods={"GET","POST"})
  589.      */
  590.     public function print(Request $requestDailyFinancialStatement $dailyFinancialStatement)
  591.     {
  592.         $data $this->zBonData($dailyFinancialStatement);
  593.         // Configure Dompdf according to your needs
  594.         $pdfOptions = new Options();
  595.         $pdfOptions->set('defaultFont''Arial');
  596.         // Instantiate Dompdf with our options
  597.         $dompdf = new Dompdf($pdfOptions);
  598.         // Retrieve the HTML generated in our twig file
  599. //        $html = $this->renderView('cash_box/daily_financial_statement/zbon.a4.html.twig', $data);
  600.         $html $this->renderView('cash_box/daily_financial_statement/zbon.80mm.html.twig'$data);
  601.         // Load HTML to Dompdf
  602.         $dompdf->loadHtml($html);
  603.         // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
  604.         $dompdf->setPaper('A4''portrait');
  605.         // Render the HTML as PDF
  606.         $dompdf->render();
  607.         // Output the generated PDF to Browser (inline view)
  608.         $dompdf->stream("DailyFinancialStatement_" $dailyFinancialStatement->getStartDate()->format("d-m-Y-H-i") . "_" $dailyFinancialStatement->getEndDate()->format("d-m-Y-H-i") . "_" time() . ".pdf", [
  609.             "Attachment" => false
  610.         ]);
  611.     }
  612.     /**
  613.      * @Route("/list", name="list_daily_financial_statement", methods={"GET","POST"})
  614.      */
  615.     public function list(Request $request)
  616.     {
  617.         $_daily_financial_statements $this->daily_financial_statement_repository->findAll();
  618.         $daily_financial_statements = [];
  619.         foreach ($_daily_financial_statements as $daily_financial_statement) {
  620.             $daily_financial_statements[$daily_financial_statement->getId()] = [
  621.                 'cashbox_end_value' => $daily_financial_statement->getCashboxEndValue(),
  622.                 'cashbox_start_value' => $daily_financial_statement->getCashboxStartValue(),
  623.                 'end_date' => $daily_financial_statement->getEndDate()->format("d.m.Y / H:i"),
  624.                 'id' => $daily_financial_statement->getId(),
  625.                 'start_date' => $daily_financial_statement->getStartDate()->format("d.m.Y / H:i"),
  626.                 'start_y' => $daily_financial_statement->getStartDate()->format('Y'),
  627.                 'start_m' => $daily_financial_statement->getStartDate()->format('m'),
  628.                 'start_d' => $daily_financial_statement->getStartDate()->format('d'),
  629.                 'start_h' => $daily_financial_statement->getStartDate()->format('H'),
  630.                 'start_i' => $daily_financial_statement->getStartDate()->format('i'),
  631.                 'start_s' => $daily_financial_statement->getStartDate()->format('s'),
  632.                 'end_y' => $daily_financial_statement->getEndDate()->format('Y'),
  633.                 'end_m' => $daily_financial_statement->getEndDate()->format('m'),
  634.                 'end_d' => $daily_financial_statement->getEndDate()->format('d'),
  635.                 'end_h' => $daily_financial_statement->getEndDate()->format('H'),
  636.                 'end_i' => $daily_financial_statement->getEndDate()->format('i'),
  637.                 'end_s' => $daily_financial_statement->getEndDate()->format('s'),
  638.                 'manually' => $daily_financial_statement->getManually(),
  639.             ];
  640.         }
  641.         return new JsonResponse($daily_financial_statements);
  642.     }
  643.     private function zBonData(DailyFinancialStatement $dailyFinancialStatement)
  644.     {
  645.         $data = [
  646.             'kasse' => null,
  647.             'firma' => null,
  648.             'gezaehlt' => 0,
  649.             'soll' => 0,
  650.             'differenz' => 0,
  651.             'daily_financial_statement' => 0,
  652.             'location' => null,
  653.             'zbonnr' => 0,
  654.             'anfangsbestand' => 0,
  655.             'einlagen' => 0,
  656.             'entnahmen' => 0,
  657.             'zahlungen_an_lieferanten' => 0,
  658.             'receipt_cash' => 0,
  659.             'cash_debit' => 0,
  660.             'receipt_count' => 0,
  661.             'position_count' => 0,
  662.             'anzahl_bon_stornos' => 0,
  663.             'verkaufte_gutscheine' => 0,
  664.             'receipt_value_average' => 0,
  665.             'bar' => 0,
  666.             'ec_karte' => 0,
  667.             'kreditkarte' => 0,
  668.             'auf_rechnung_gezahlt' => 0,
  669.             'group_by_payment_method' => 0,
  670.             'receipt_total' => 0,
  671.             'bankeinzahlungen' => 0,
  672.             'bar_differenzen' => 0,
  673.             'wechselgeldvortrag' => 0,
  674.             'zahlungen_von_kunden_rechnungen' => 0,
  675.             'geleistete_anzahlungen_auf_kassenauftraege' => 0,
  676.             'summe_retourenpositionen' => 0,
  677. //            'Anfangsbestand'=>null,
  678. //            'Anfangsbestand'=>null,
  679. //            'Anfangsbestand'=>null,
  680. //            'Anfangsbestand'=>null,
  681. //            'Anfangsbestand'=>null,
  682. //            'Anfangsbestand'=>null,
  683. //            'Anfangsbestand'=>null,
  684. //            'Anfangsbestand'=>null,
  685. //            'Anfangsbestand'=>null,
  686. //            'Anfangsbestand'=>null,
  687. //            'Anfangsbestand'=>null,
  688. //            'Anfangsbestand'=>null,
  689. //            'Anfangsbestand'=>null,
  690. //            'Anfangsbestand'=>null,
  691. //            'Anfangsbestand'=>null,
  692. //            'Anfangsbestand'=>null,
  693. //            'Anfangsbestand'=>null,
  694. //            'Anfangsbestand'=>null,
  695. //            'Anfangsbestand'=>null,
  696. //            'Anfangsbestand'=>null,
  697. //            'Anfangsbestand'=>null,
  698. //            'Anfangsbestand'=>null,
  699. //            'Anfangsbestand'=>null,
  700.         ];
  701.         $receipt_container $dailyFinancialStatement->getReceipts();
  702.         if ($receipt_container->count() > 0) {
  703.             $position_count 0;
  704.             $receipt_totals 0;
  705.             $group_by_payment_method = [];
  706.             foreach ($receipt_container as $receipt) {
  707.                 $position_count += $receipt->getReceiptCartProducts()->count();
  708. //                $receipt_totals += $receipt->getCartTotalFixed();
  709.                 $receipt_totals += $receipt->getTotalFixed();
  710.                 $receiptTransaction $receipt->getReceiptTransactions()->last();
  711.                 if ($receiptTransaction !== false) {
  712.                     $receiptPaymentMethod $receiptTransaction->getReceiptPaymentMethod();
  713.                     if ($receiptPaymentMethod !== null) {
  714.                         if (!isset($group_by_payment_method[$receiptPaymentMethod->getName()])) {
  715.                             $group_by_payment_method[$receiptPaymentMethod->getName()] = 0;
  716.                         }
  717. //                        $group_by_payment_method[$receiptPaymentMethod->getName()] += $receipt->getCartTotalFixed();
  718.                         $group_by_payment_method[$receiptPaymentMethod->getName()] += $receipt->getTotalFixed();
  719.                     }
  720.                 }
  721.             }
  722.             $company $this->company_repository->findOneBy(['id' => 1]);
  723.             $_company = [
  724.                 'address_addition' => null,
  725.                 'address_country' => null,
  726.                 'address_locality' => null,
  727.                 'email' => null,
  728.                 'fax_number' => null,
  729.                 'id' => null,
  730.                 'line_1' => null,
  731.                 'line_2' => null,
  732.                 'logo' => null,
  733.                 'name' => null,
  734.                 'postal_code' => null,
  735.                 'street_address' => null,
  736.                 'tax_number' => null,
  737.                 'telephone' => null,
  738.                 'vat_id' => null,
  739.                 'website' => null,
  740.             ];
  741.             if ($company !== null) {
  742.                 $_company = [
  743.                     'address_addition' => $company->getAddressAddition(),
  744.                     'address_country' => $company->getAddressCountry(),
  745.                     'address_locality' => $company->getAddressLocality(),
  746.                     'email' => $company->getEmail(),
  747.                     'fax_number' => $company->getFaxNumber(),
  748.                     'id' => $company->getId(),
  749.                     'line_1' => $company->getLine1(),
  750.                     'line_2' => $company->getLine2(),
  751.                     'logo' => $company->getLogo(),
  752.                     'name' => $company->getName(),
  753.                     'postal_code' => $company->getPostalCode(),
  754.                     'street_address' => $company->getStreetAddress(),
  755.                     'tax_number' => $company->getTaxNumber(),
  756.                     'telephone' => $company->getTelephone(),
  757.                     'vat_id' => $company->getVatId(),
  758.                     'website' => $company->getWebsite(),
  759.                 ];
  760.             }
  761.             $_dailyFinancialStatement = [
  762.                 'id' => $dailyFinancialStatement->getId(),
  763.                 'start_date' => $dailyFinancialStatement->getStartDate()->format("d.m.Y / H:i"),
  764.                 'end_date' => $dailyFinancialStatement->getEndDate()->format("d.m.Y / H:i"),
  765.                 'cashbox_start_value' => $dailyFinancialStatement->getCashboxStartValue(),
  766.                 'cashbox_end_value' => $dailyFinancialStatement->getCashboxEndValue(),
  767.                 'deposit_total' => $dailyFinancialStatement->getDeposits(),
  768.                 'withdrawal_total' => $dailyFinancialStatement->getWithdrawals(),
  769.                 'payment_to_supplier_total' => $dailyFinancialStatement->getPaymentsToSuppliers(),
  770.             ];
  771.             $receiptLocation $receipt->getReceiptLocation();
  772.             $_receiptLocation = [
  773.                 'name' => null,
  774.             ];
  775.             if ($receiptLocation !== null) {
  776.                 $_receiptLocation = [
  777.                     'name' => $receiptLocation->getName(),
  778.                 ];
  779.             }
  780.             $data['zbonnr'] = $dailyFinancialStatement->getId();
  781.             $data['kasse'] = ['name' => $receipt->getReceiptCashbox()->getName(), 'sn' => $receipt->getReceiptCashbox()->getSerialNumber()];
  782.             $data['firma'] = $_company;
  783.             $data['gezaehlt'] = $dailyFinancialStatement->getCashboxEndValue();
  784.             $data['anfangsbestand'] = $dailyFinancialStatement->getCashboxStartValue();
  785.             $data['receipt_cash'] = $group_by_payment_method['Bar'];
  786.             $data['cash_debit'] = $data['anfangsbestand'] + $data['receipt_cash'];
  787.             $data['receipt_count'] = $receipt_container->count();
  788.             $data['position_count'] = $position_count;
  789.             $data['receipt_value_average'] = $receipt_totals $receipt_container->count();
  790.             $data['group_by_payment_method'] = $group_by_payment_method;
  791.             $data['receipt_total'] = $receipt_totals;
  792.             $data['soll'] = $data['cash_debit'];
  793.             $data['differenz'] = $data['gezaehlt'] - $data['soll'];
  794.             $data['daily_financial_statement'] = $_dailyFinancialStatement;
  795.             $data['location'] = $_receiptLocation;
  796.         }
  797.         return $data;
  798.     }
  799.     /**
  800.      * @Route("/map", name="map_daily_financial_statement", methods={"GET","POST"})
  801.      */
  802.     public function map()
  803.     {
  804.         $data = [];
  805.         $daily_financial_statements $this->daily_financial_statement_repository->findBy(['manually' => true]);
  806.         foreach ($daily_financial_statements as $daily_financial_statement) {
  807.             $detected_timezone $this->timeZoneDetectionService->getTimezoneDifference($this->timeZoneDetectionService->DateTimeInterfaceToDateTime($daily_financial_statement->getStartDate()));
  808.             $sql = <<<SQL
  809. SELECT receipt.id
  810. FROM receipt
  811. WHERE unix_timestamp(convert_tz(create_date,'$detected_timezone',@@session.time_zone))>=:start
  812.   AND unix_timestamp(convert_tz(create_date,'$detected_timezone',@@session.time_zone))<=:end
  813. SQL;
  814.             $con $this->entity_manager->getConnection();
  815.             $stmt $con->executeQuery($sql, ['start' => $daily_financial_statement->getStartDate()->getTimestamp(), 'end' => $daily_financial_statement->getEndDate()->getTimestamp()]);
  816.             while (($row $stmt->fetchAssociative()) !== false) {
  817.                 $receipt $this->receipt_repository->findOneBy(['id' => $row['id']]);
  818.                 $receipt->setDailyFinancialStatement($daily_financial_statement);
  819.                 $this->entity_manager->persist($receipt);
  820.                 $this->entity_manager->flush();
  821.             }
  822.         }
  823.     }
  824.     /**
  825.      * @Route("/start", name="start_daily_financial_statement")
  826.      */
  827.     public function start()
  828.     {
  829.         if ($this->_check() === false) {
  830.             $daily_financial_statement = new DailyFinancialStatement();
  831.         }
  832.     }
  833.     /**
  834.      * @Route("/stop/{id}", name="stop_daily_financial_statement", methods={"GET","POST"})
  835.      */
  836.     public function stop(Request $requestDailyFinancialStatement $dailyFinancialStatement)
  837.     {
  838.     }
  839.     /**
  840.      * @Route("/check", name="check_daily_financial_statement")
  841.      */
  842.     public function check()
  843.     {
  844.         return new JsonResponse(['_success' => true'has_active_daily_financial_statement' => $this->_check()]);
  845.     }
  846.     /**
  847.      * @Route("/load_active", name="load_active_daily_financial_statement")
  848.      */
  849.     public function loadActive()
  850.     {
  851.         $daily_financial_statement $this->daily_financial_statement_repository->findOneBy(['end_date' => null], ['id' => 'DESC']);
  852.         if ($daily_financial_statement instanceof DailyFinancialStatement) {
  853.             return new JsonResponse(['_success' => true'active_daily_financial_statement' => $daily_financial_statement->getId()]);
  854.         }
  855.         return new JsonResponse(['_success' => false'active_daily_financial_statement' => null]);
  856.     }
  857.     /**
  858.      * @Route("/create", name="create_daily_financial_statement", methods={"GET","POST"})
  859.      */
  860.     public function create(Request $request)
  861.     {
  862.         $log_date = new \DateTime('now');
  863.         $log_file __DIR__ '/../../../var/' $log_date->format("Y_m_d_H_i_s") . '.create_daily_financial_statement.log';
  864.         $cloner = new VarCloner();
  865.         $dumper = new CliDumper();
  866.         $data json_decode($request->getContent(), true);
  867.         if (isset($data['cashbox'], $data['money_stack_data']) && !empty($data['cashbox']) && !empty($data['money_stack_data'])) {
  868.             $cashbox $this->cashbox_repository->findOneBy(['id' => $data['cashbox']]);
  869.             if ($cashbox instanceof Cashbox) {
  870.                 $cashbox_session $this->cashbox_service->getLatestStartedCashboxSession($cashbox);
  871.                 if ($cashbox_session !== null) {
  872.                     foreach ($data['money_stack_data']['factory'] as $item_factor => $item_amount) {
  873.                         $cashbox_counting = new CashboxCounting();
  874.                         $cashbox_counting
  875.                             ->setAddDate(new \DateTime('now'))
  876.                             ->setCashboxSession($cashbox_session)
  877.                             ->setFactor((int)$item_factor)
  878.                             ->setAmount((int)$item_amount);
  879.                         $this->entity_manager->persist($cashbox_counting);
  880.                     }
  881.                     $this->entity_manager->flush();
  882.                     $cashbox_session
  883.                         ->setStopDate(new \DateTime('now'))
  884.                         ->setCashStop($data['money_stack_data']['total']);
  885.                     $this->entity_manager->persist($cashbox_session);
  886.                     $this->entity_manager->flush();
  887.                     $location $cashbox->getLocation();
  888.                     $daily_financial_statement_location null;
  889.                     if ($location instanceof Location) {
  890.                         $daily_financial_statement_location = new DailyFinancialStatementLocation();
  891.                         $daily_financial_statement_location
  892.                             ->setAddressAddition($location->getAddressAddition())
  893.                             ->setAddressCountry($location->getAddressCountry())
  894.                             ->setAddressLocality($location->getAddressLocality())
  895.                             ->setEmail($location->getEmail())
  896.                             ->setFaxNumber($location->getFaxNumber())
  897.                             ->setLocation($location)
  898.                             ->setLogo($location->getLogo())
  899.                             ->setName($location->getName())
  900.                             ->setPostalCode($location->getPostalCode())
  901.                             ->setShowAddressOnReceipt($location->getShowAddressOnReceipt())
  902.                             ->setShowContactOnReceipt($location->getShowContactOnReceipt())
  903.                             ->setStreetAddress($location->getStreetAddress())
  904.                             ->setTelephone($location->getTelephone())
  905.                             ->setWebsite($location->getWebsite());
  906.                     }
  907.                     $this->entity_manager->persist($daily_financial_statement_location);
  908.                     $this->entity_manager->flush();
  909.                     $daily_financial_statement_cashbox = new DailyFinancialStatementCashbox();
  910.                     $daily_financial_statement_cashbox
  911.                         ->setCashbox($cashbox)
  912.                         ->setComment($cashbox->getComment())
  913.                         ->setDailyFinancialStatementLocation($daily_financial_statement_location)
  914.                         ->setLocked($cashbox->getLocked())
  915.                         ->setName($cashbox->getName())
  916.                         ->setSerialNumber($cashbox->getSerialNumber());
  917.                     $this->entity_manager->persist($daily_financial_statement_cashbox);
  918.                     $this->entity_manager->flush();
  919.                     $cashbox_deposit_container $this->cashbox_service->getCashboxDeposit($cashbox$cashbox_session);
  920.                     /**
  921.                      * @var CashboxDeposit $cashbox_deposit
  922.                      */
  923.                     foreach ($cashbox_deposit_container as $cashbox_deposit) {
  924.                         $daily_financial_statement_cashbox_deposit = new DailyFinancialStatementCashboxDeposit();
  925.                         $daily_financial_statement_cashbox_deposit
  926.                             ->setAddDate($cashbox_deposit->getAddDate())
  927.                             ->setValue($cashbox_deposit->getValue())
  928.                             ->setCashboxDeposit($cashbox_deposit)
  929.                             ->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
  930.                         $this->entity_manager->persist($daily_financial_statement_cashbox_deposit);
  931.                     }
  932.                     $this->entity_manager->flush();
  933.                     $cashbox_withdrawal_container $this->cashbox_service->getCashboxWithdrawal($cashbox$cashbox_session);
  934.                     /**
  935.                      * @var CashboxWithdrawal $cashbox_withdrawal
  936.                      */
  937.                     foreach ($cashbox_withdrawal_container as $cashbox_withdrawal) {
  938.                         $daily_financial_statement_cashbox_withdrawal = new DailyFinancialStatementCashboxWithdrawal();
  939.                         $daily_financial_statement_cashbox_withdrawal
  940.                             ->setAddDate($cashbox_withdrawal->getAddDate())
  941.                             ->setValue($cashbox_withdrawal->getValue())
  942.                             ->setCashboxWithdrawal($cashbox_withdrawal)
  943.                             ->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
  944.                         $this->entity_manager->persist($daily_financial_statement_cashbox_withdrawal);
  945.                     }
  946.                     $this->entity_manager->flush();
  947.                     $cashbox_payment_to_supplier_container $this->cashbox_service->getCashboxPaymentToSupplier($cashbox$cashbox_session);
  948.                     /**
  949.                      * @var CashboxPaymentToSupplier $cashbox_payment_to_supplier
  950.                      */
  951.                     foreach ($cashbox_payment_to_supplier_container as $cashbox_payment_to_supplier) {
  952.                         $daily_financial_statement_cashbox_payment_to_supplier = new DailyFinancialStatementCashboxPaymentToSupplier();
  953.                         $daily_financial_statement_cashbox_payment_to_supplier
  954.                             ->setAddDate($cashbox_payment_to_supplier->getAddDate())
  955.                             ->setValue($cashbox_payment_to_supplier->getValue())
  956.                             ->setCashboxPaymentToSupplier($cashbox_payment_to_supplier)
  957.                             ->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox);
  958.                         $this->entity_manager->persist($daily_financial_statement_cashbox_payment_to_supplier);
  959.                     }
  960.                     $this->entity_manager->flush();
  961.                     $daily_financial_statement = new DailyFinancialStatement();
  962.                     $daily_financial_statement
  963.                         ->setStartDate($cashbox_session->getStartDate())
  964.                         ->setEndDate($cashbox_session->getStopDate())
  965.                         ->setCashboxStartValue($cashbox_session->getCashStart())
  966.                         ->setCashboxEndValue($cashbox_session->getCashStop())
  967.                         ->setDailyFinancialStatementCashbox($daily_financial_statement_cashbox)
  968.                         ->setManually(false);
  969.                     $this->entity_manager->persist($daily_financial_statement);
  970.                     $this->entity_manager->flush();
  971.                     foreach ($data['money_stack_data']['factory'] as $item_factor => $item_amount) {
  972.                         $daily_financial_statement_counting = new DailyFinancialStatementCounting();
  973.                         $daily_financial_statement_counting
  974.                             ->setAddDate(new \DateTime('now'))
  975.                             ->setDailyFinancialStatement($daily_financial_statement)
  976.                             ->setFactor((int)$item_factor)
  977.                             ->setAmount((int)$item_amount);
  978.                         $this->entity_manager->persist($daily_financial_statement_counting);
  979.                     }
  980.                     $this->entity_manager->flush();
  981.                     $receipt_container $this->daily_financial_statement_service->getReceipt($cashbox$daily_financial_statement);
  982.                     /**
  983.                      * @var Receipt $receipt
  984.                      */
  985.                     foreach ($receipt_container as $receipt) {
  986.                         $receipt->setDailyFinancialStatement($daily_financial_statement);
  987.                         $this->entity_manager->persist($receipt);
  988.                     }
  989.                     $this->entity_manager->flush();
  990. /*
  991.                     // Fiskaly
  992.                     $cash_point_closing = new CashPointClosingStructure();
  993.                     $cash_point_closing_head = new CashPointClosingHeadStructure();
  994.                     $cash_point_closing_head->setExportCreationDate(time())
  995.                         ->setFirstTransactionExportId()
  996.                         ->setLastTransactionExportId();
  997.                     $cash_point_closing->setHead($cash_point_closing_head)
  998.                         ->setClientId()
  999.                         ->setCashPointClosingExportId();*/
  1000.                     return new JsonResponse(['_success' => true]);
  1001.                 }
  1002.             }
  1003.         }
  1004.         return new JsonResponse(['_success' => false]);
  1005.     }
  1006.     private function _check()
  1007.     {
  1008.         $daily_financial_statement $this->daily_financial_statement_repository->findOneBy(['end_date' => null], ['id' => 'DESC']);
  1009.         if ($daily_financial_statement instanceof DailyFinancialStatement) {
  1010.             return true;
  1011.         }
  1012.         return false;
  1013.     }
  1014. }