InvoiceController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Currency;
  4. use App\Models\Language;
  5. use App\Models\Order;
  6. use Session;
  7. use PDF;
  8. use Config;
  9. class InvoiceController extends Controller
  10. {
  11. //download invoice
  12. public function invoice_download($id)
  13. {
  14. if(Session::has('currency_code')){
  15. $currency_code = Session::get('currency_code');
  16. }
  17. else{
  18. $currency_code = Currency::findOrFail(get_setting('system_default_currency'))->code;
  19. }
  20. $language_code = Session::get('locale', Config::get('app.locale'));
  21. if(Language::where('code', $language_code)->first()->rtl == 1){
  22. $direction = 'rtl';
  23. $text_align = 'right';
  24. $not_text_align = 'left';
  25. }else{
  26. $direction = 'ltr';
  27. $text_align = 'left';
  28. $not_text_align = 'right';
  29. }
  30. if($currency_code == 'BDT' || $language_code == 'bd'){
  31. // bengali font
  32. $font_family = "'Hind Siliguri','sans-serif'";
  33. }elseif($currency_code == 'KHR' || $language_code == 'kh'){
  34. // khmer font
  35. $font_family = "'Hanuman','sans-serif'";
  36. }elseif($currency_code == 'AMD'){
  37. // Armenia font
  38. $font_family = "'arnamu','sans-serif'";
  39. // }elseif($currency_code == 'ILS'){
  40. // // Israeli font
  41. // $font_family = "'Varela Round','sans-serif'";
  42. }elseif($currency_code == 'AED' || $currency_code == 'EGP' || $language_code == 'sa' || $currency_code == 'IQD' || $language_code == 'ir' || $language_code == 'om' || $currency_code == 'ROM' || $currency_code == 'SDG' || $currency_code == 'ILS'){
  43. // middle east/arabic/Israeli font
  44. $font_family = "'Baloo Bhaijaan 2','sans-serif'";
  45. }elseif($currency_code == 'THB'){
  46. // thai font
  47. $font_family = "'Kanit','sans-serif'";
  48. }else{
  49. // general for all
  50. $font_family = "'Roboto','sans-serif'";
  51. }
  52. // $config = ['instanceConfigurator' => function($mpdf) {
  53. // $mpdf->showImageErrors = true;
  54. // }];
  55. // mpdf config will be used in 4th params of loadview
  56. $config = [];
  57. $order = Order::findOrFail($id);
  58. return PDF::loadView('backend.invoices.invoice',[
  59. 'order' => $order,
  60. 'font_family' => $font_family,
  61. 'direction' => $direction,
  62. 'text_align' => $text_align,
  63. 'not_text_align' => $not_text_align
  64. ], [], $config)->download('order-'.$order->code.'.pdf');
  65. }
  66. }