From fa89519762f6db81fb502e5a53b3f27050066cf9 Mon Sep 17 00:00:00 2001 From: Amir Date: Wed, 16 Nov 2022 06:55:06 +0800 Subject: [PATCH] Add export data lelong --- app/BatchLel.php | 11 ++-- app/Http/Controllers/LelongController.php | 64 +++++++++++++++++++++++ app/LelMarhun.php | 9 ++++ routes/web.php | 1 + 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/app/BatchLel.php b/app/BatchLel.php index 49f2c65..ec59c42 100644 --- a/app/BatchLel.php +++ b/app/BatchLel.php @@ -7,15 +7,20 @@ use Illuminate\Database\Eloquent\Model; class BatchLel extends Model { protected $table = 'batchlel'; + public $timestamps = false; + /** * The attributes that are mass assignable. * * @var array */ - // protected $fillable = [ - - // ]; + protected $fillable = [ + 'tarikh', + 'tarikh2', + 'batchno', + 'kodcaw' + ]; /** * The attributes excluded from the model's JSON form. diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 14b8e10..75e0bb3 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -22,7 +22,9 @@ use App\Tebus; use App\Advansur; use App\LelTebus; use App\LelMarhun; +use App\Tunai; use App\Audit; +use App\GlDetail; use Illuminate\Http\Request; use DB; @@ -963,4 +965,66 @@ class LelongController extends Controller return response()->json($arraylelong); } + public function exportLelong(Request $request) + { + $cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first(); + + $batchlel = BatchLel::on($cawangan['mysql']) + ->select('batchno') + ->orderBy('batchno', 'desc') + ->first(); + + $newBatchNo = $batchlel->batchno + 1; + + $newBatchLel = BatchLel::on($cawangan['mysql'])->create([ + 'kodcaw' => $request->kodcaw, + 'batchno' => $newBatchNo, + 'tarikh' => $request->tarikh, + 'tarikh2' => $request->tarikh, + ]); + + foreach ($request->lelongbid as $index) { + $lelong_to_be_inserted = new Lelong(); + $lelong_to_be_inserted->kodcaw = $index['kodcaw']; + $lelong_to_be_inserted->batchno = $newBatchNo; + $lelong_to_be_inserted->t_lelong = $request->tarikh; + $lelong_to_be_inserted->norujukan = $index['norujukan']; + + $lelong_arr[] = $lelong_to_be_inserted->attributesToArray(); + } + + Lelong::on($cawangan['mysql'])->insert($lelong_arr); + + foreach ($request->lelongbidmarhun as $data) { + $lelmarhun_to_be_inserted = new LelMarhun(); + $lelmarhun_to_be_inserted->kodcaw = $request['kodcaw']; + $lelmarhun_to_be_inserted->norujukan = $data['norujukan']; + $lelmarhun_to_be_inserted->t_gadai = $data['t_gadai']; + $lelmarhun_to_be_inserted->nota = $data['nota']; + $lelmarhun_to_be_inserted->batch_no = $newBatchNo; + + $lelmarhun_arr[] = $lelmarhun_to_be_inserted->attributesToArray(); + } + + LelMarhun::on($cawangan['mysql'])->insert($lelmarhun_arr); + + $tunai = Tunai::on($cawangan['mysql'])->create([ + 'tarikh' => $request->tarikh, + 'kodlaluan' => "LELONG", + 'masuk' => $request->tunai, + ]); + + $gldetail = GlDetail::on($cawangan['mysql'])->create([ + 'tarikh' => $request->tarikh, + 'dtacct' => "1000/010", + 'ktacct' => "1000/020", + 'teller' => "LELONG ONLINE", + 'descpt' => "SERAHAN LELONG ONLINE", + 'amaun' => $request->gldetail + ]); + + + return response()->json("success"); + } + } diff --git a/app/LelMarhun.php b/app/LelMarhun.php index 61cfaa9..72466b5 100644 --- a/app/LelMarhun.php +++ b/app/LelMarhun.php @@ -15,6 +15,15 @@ class LelMarhun extends Model * @var array */ + protected $fillable = [ + 'kodcaw', + 'norujukan', + 't_gadai', + 'marhun', + 'nota', + 'batch_no', + ]; + /** * The attributes excluded from the model's JSON form. * diff --git a/routes/web.php b/routes/web.php index eda1719..7968682 100644 --- a/routes/web.php +++ b/routes/web.php @@ -740,6 +740,7 @@ $router->group(['prefix'=>'admin'], function () use ($router){ $router->group(['prefix'=>'lelong'], function () use ($router){ $router->post('taglel/update',['uses'=>'GadaiController@updateTagLelong']); $router->post('taglel/revert',['uses'=>'GadaiController@revertTagLelong']); + $router->post('exportLelong',['uses'=>'LelongController@exportLelong']); }); $router->group(['prefix'=>'kelantanpay'], function () use ($router){