Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExpiredDateDarah.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Model\Data\Order\Pemusnahan\Pemusnahan;
  4. use App\Model\Data\StockLogs;
  5. use App\Model\Data\StockRelease;
  6. use App\Model\Data\Stocks;
  7. use Carbon\Carbon;
  8. use Illuminate\Console\Command;
  9. use Illuminate\Support\Facades\DB;
  10. use Auth;
  11. class ExpiredDateDarah extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'expired:date';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = 'Hapus Kantong Darah Yang Expired';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return int
  38. */
  39. public function handle()
  40. {
  41. $this->info('Cek cron job');
  42. $cek_data = StockRelease::where('expired_date', '<', Carbon::now())
  43. ->get();
  44. foreach($cek_data as $key => $value){
  45. $cek_stock_release[$key] = StockRelease::where('id', $value->id)->first();
  46. $data_stock_release[$key] = [
  47. 'status_id' => 3,
  48. ];
  49. DB::table('stock_releases')->where('id', $value->id)
  50. ->update($data_stock_release[$key]);
  51. $cek_stock[$key] = Stocks::where('golongan_darah_id', $value->golongan_darah_id)
  52. ->where('rhesus_id', $value->rhesus_id)
  53. ->where('produk_id', $value->produk_id)
  54. ->where('unit_donor_darah_id', $value->unit_donor_darah_id)
  55. ->first();
  56. if($cek_stock[$key]->quantity_kantong != 0){
  57. $data_stock[$key] = [
  58. 'quantity_kantong' => $cek_stock[$key]['quantity_kantong'] - 1,
  59. ];
  60. DB::table('stocks')->where('golongan_darah_id', $value->golongan_darah_id)
  61. ->where('produk_id', $value->produk_id)
  62. ->where('rhesus_id', $value->rhesus_id)
  63. ->where('unit_donor_darah_id', $value->unit_donor_darah_id)
  64. ->update($data_stock[$key]);
  65. }
  66. $data_log[$key] = [
  67. 'log' => 'Pemusnahan Darah dengan no kantong : ' . $value->no_kantong,
  68. 'user_id' => 1,
  69. 'quantity_kantong' => 1,
  70. 'is_stock_in' => 1,
  71. 'is_stock_out' => 0,
  72. 'created_at' => NOW(),
  73. 'updated_at' => NOW(),
  74. ];
  75. $data_pemusnahan[$key] = [
  76. 'release_id' => $value->id,
  77. 'keterangan' => 'Darah Sudah Expired',
  78. 'petugas_id' => 1,
  79. 'created_at' => NOW(),
  80. 'updated_at' => NOW(),
  81. ];
  82. }
  83. $update_log = StockLogs::insert($data_log);
  84. $insert_data_pemusnahan = Pemusnahan::insert($data_pemusnahan);
  85. }
  86. }