Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Illuminate\Console\Command;
  6.  
  7. class ImportPendapatan extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'import:pendapatan';
  15.  
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Importing income data source to database';
  22.  
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32.  
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. try{
  41. $import = $this->import();
  42.  
  43. // buka file excel
  44. dump($import->current());
  45.  
  46. // Delete semua baris data yang sama dengan key dari file excel
  47. $import->next();
  48. dump($import->current());
  49.  
  50. // validasi field dari excel
  51. $import->next();
  52. dump($import->current());
  53.  
  54. // insert data pendapatan dari excel ke database
  55. $import->next();
  56. dump($import->current());
  57. }catch(Exception $e){
  58. Log::debug('message');
  59. }
  60.  
  61. }
  62.  
  63. private function import(){
  64. $delete = DB::delete();
  65.  
  66. if ($delete){
  67. yield "Buka file excel";
  68. } else {
  69. throw new Exception("Gagal delete");
  70. }
  71.  
  72.  
  73. yield "Delete semua baris data yang sama dengan key dari file excel";
  74. yield "Validasi field dari excel";
  75. yield "Insert data pendapatan dari excel ke database";
  76. }
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement