fix location not printed on index

This commit is contained in:
mahdahar 2025-09-22 15:22:07 +07:00
parent 862e5fd03d
commit e6dbe3e951

View File

@ -19,8 +19,8 @@ class Location extends Controller {
public function index() { public function index() {
$rows = $this->db->table('location l') $rows = $this->db->table('location l')
->select("l.LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ") ->select("l.LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ")
->join("locationaddress la", "l.LocationID=la.LocationID") ->join("locationaddress la", "l.LocationID=la.LocationID", 'left')
->join("valueset v", "v.VSetID=12 and v.VValue=l.LocType") ->join("valueset v", "v.VSetID=12 and v.VValue=l.LocType", 'left')
->get()->getResultArray(); ->get()->getResultArray();
if (empty($rows)) { if (empty($rows)) {
@ -62,31 +62,22 @@ class Location extends Controller {
} }
public function create() { public function create() {
$input = $this->request->getJSON(true);
$dataLocation = $this->prepareLocationData($input);
$dataLocationAddress = $this->prepareLocationAddressData($input);
if (!$this->validateData($dataLocation, $this->rules)) {
return $this->failValidationErrors($this->validator->getErrors());
}
try { try {
$input = $this->request->getJSON(true);
// Prepare data
$dataLocation = $this->prepareLocationData($input);
$dataLocationAddress = $this->prepareLocationAddressData($input);
if (!$this->validateData($dataLocation, $this->rules)) {
return $this->failValidationErrors($this->validator->getErrors());
}
// Start transaction
$this->db->transStart(); $this->db->transStart();
// Insert location
$this->db->table('location')->insert($dataLocation); $this->db->table('location')->insert($dataLocation);
$newLocationID = $this->db->insertID(); $newLocationID = $this->db->insertID();
// Insert address if available
if (!empty($dataLocationAddress)) { if (!empty($dataLocationAddress)) {
$dataLocationAddress['LocationID'] = $newLocationID; $dataLocationAddress['LocationID'] = $newLocationID;
$this->db->table('locationaddress')->insert($dataLocationAddress); $this->db->table('locationaddress')->insert($dataLocationAddress);
} }
// Complete transaction
$this->db->transComplete(); $this->db->transComplete();
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {