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() {
$rows = $this->db->table('location l')
->select("l.LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ")
->join("locationaddress la", "l.LocationID=la.LocationID")
->join("valueset v", "v.VSetID=12 and v.VValue=l.LocType")
->join("locationaddress la", "l.LocationID=la.LocationID", 'left')
->join("valueset v", "v.VSetID=12 and v.VValue=l.LocType", 'left')
->get()->getResultArray();
if (empty($rows)) {
@ -62,31 +62,22 @@ class Location extends Controller {
}
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 {
$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();
// Insert location
$this->db->table('location')->insert($dataLocation);
$newLocationID = $this->db->insertID();
// Insert address if available
if (!empty($dataLocationAddress)) {
$dataLocationAddress['LocationID'] = $newLocationID;
$this->db->table('locationaddress')->insert($dataLocationAddress);
}
// Complete transaction
$this->db->transComplete();
if ($this->db->transStatus() === false) {