helpers.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. function getCards()
  3. {
  4. return \App\Models\Card::where('enabled', true)->orderBy('name')->get();
  5. }
  6. function getCategories()
  7. {
  8. return \App\Models\Category::where('enabled', true)->where('parent_id', null)->orderBy('name')->get();
  9. }
  10. function formatPrice($price)
  11. {
  12. return "€ " . number_format($price, 2, ",", ".");
  13. }
  14. function getVatValue($v, $i)
  15. {
  16. $vat = 0;
  17. //if (env('VAT_MANAGE', 0) == 1)
  18. //{
  19. $vats = \App\Models\Vat::select('id', 'name', 'value')->orderBy('value')->get();
  20. if ($i > 0)
  21. {
  22. $iv = 0;
  23. foreach($vats as $vv)
  24. {
  25. if ($vv->id == $i)
  26. {
  27. $iv = $vv->value;
  28. break;
  29. }
  30. }
  31. if ($iv > 0)
  32. $vat = $v / 100 * $iv;
  33. }
  34. //}
  35. return $vat;
  36. }
  37. function mysqlToDate($dt)
  38. {
  39. list($date, $hour) = explode(" ", $dt);
  40. list($year, $month, $day) = explode("-", $date);
  41. return $day . "/" . $month . "/" . $year;
  42. }
  43. function currencyToDouble($val)
  44. {
  45. $x = str_replace("€", "", $val);
  46. $x = str_replace(".", "", $x);
  47. $x = str_replace(",", ".", $x);
  48. return floatval(trim($x));
  49. }
  50. function getConfiguration($field)
  51. {
  52. $ret = "";
  53. $conf = \App\Models\Configurration::first();
  54. if ($conf)
  55. {
  56. $ret = $conf[$field];
  57. }
  58. return $ret;
  59. }