added timestamp and fixed block for duplicate nota and timestamp
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ class AddTunai extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['tarikh','kodcaw','kodlaluan','tambah','kurang','nota'];
|
||||
protected $fillable = ['tarikh','kodcaw','kodlaluan','tambah','kurang','nota','created_at'];
|
||||
|
||||
public $timestamps = false;
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ use App\Denominasi;
|
||||
use App\Vault;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
class TunaiController extends Controller
|
||||
{
|
||||
|
||||
@@ -194,7 +194,28 @@ class TunaiController extends Controller
|
||||
$current = new Carbon();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
//Same Note e.g P1 and S1
|
||||
$same_note = AddTunai::on($cawangan['mysql'])
|
||||
->where('kodlaluan', $request->kodlaluan)
|
||||
->where('nota',$request->nota)
|
||||
->where('tarikh',$current->toDateString())->first();
|
||||
|
||||
if($same_note){
|
||||
Log::error('Error: same-note :' . $kodcaw . ': Name :' . $request->kodlaluan);
|
||||
return 'same-note';
|
||||
}
|
||||
|
||||
//Time Interval
|
||||
$latestRecord = AddTunai::on($cawangan['mysql'])->where('kodlaluan', $request->kodlaluan)->latest()->first();
|
||||
if($latestRecord){
|
||||
$time = Carbon::parse($latestRecord->created_at);
|
||||
$time_end = $time->copy()->addMinutes(1);
|
||||
|
||||
if($current->between($time,$time_end)){
|
||||
Log::error('Error: within 1 minute :' . $kodcaw . ': Name :' . $request->kodlaluan);
|
||||
return 'within 1 minute';
|
||||
}
|
||||
}
|
||||
|
||||
$addtunai=AddTunai::on($cawangan['mysql'])->create([
|
||||
|
||||
@@ -203,7 +224,8 @@ class TunaiController extends Controller
|
||||
'kodlaluan'=>$request->kodlaluan,
|
||||
'tambah'=>$request->tambah,
|
||||
'kurang'=>$request->kurang,
|
||||
'nota'=>$request->nota
|
||||
'nota'=>$request->nota,
|
||||
'created_at'=>$current
|
||||
]);
|
||||
|
||||
return response()->json($addtunai,201);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddColumnTimestampToAddtunaiTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
protected $db_connection;
|
||||
public function getActiveDB(){
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db,function($connection){
|
||||
try{
|
||||
if($connection == 'mysql7')
|
||||
return false;
|
||||
|
||||
$db = DB::connection($connection)->getPdo();
|
||||
return true;
|
||||
} catch(\Exception $e){
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $db_connection;
|
||||
}
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->db_connection = $this->getActiveDB();
|
||||
|
||||
foreach($this->db_connection as $dbase){
|
||||
Schema::connection($dbase)->table('addtunai', function (Blueprint $table) use($dbase) {
|
||||
|
||||
$isCreatedAt = Schema::connection($dbase)->hasColumn('addtunai', 'created_at');
|
||||
|
||||
if (! $isCreatedAt) {
|
||||
$table->timestamp('created_at');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->db_connection = $this->getActiveDB();
|
||||
|
||||
foreach($this->db_connection as $dbase){
|
||||
$columns = ['created_at'];
|
||||
|
||||
$columns_exist = array_filter($columns,function($column) use($dbase){
|
||||
return Schema::connection($dbase)->hasColumn('addtunai', $column);
|
||||
});
|
||||
|
||||
Schema::connection($dbase)->table('addtunai', function(Blueprint $table) use($columns_exist){
|
||||
foreach($columns_exist as $column){
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user