811 lines
30 KiB
PHP
811 lines
30 KiB
PHP
<?php
|
|
class Company extends MY_Controller {
|
|
|
|
var $db_onedev;
|
|
var $db_inventory;
|
|
var $db_inventory_log;
|
|
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
$this->db_inventory_log = $this->load->database('inventory_log', true);
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->db_onex = "one_aditya";
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "%%";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
$search = '%' . $prm['search'] . '%';
|
|
}
|
|
$order_by = "CompanyCode";
|
|
if (isset($prm['order_by'])) {
|
|
$order_by = trim($prm["order_by"]);
|
|
}
|
|
$order_type = "asc";
|
|
if (isset($prm['order_type'])) {
|
|
$order_type = trim($prm["order_type"]);
|
|
}
|
|
$order = $order_by.' '.$order_type;
|
|
$perpage = 10;
|
|
$offset = ($prm['current_page'] - 1) * $perpage ;
|
|
|
|
$sql = "SELECT COUNT(*) as total FROM
|
|
(
|
|
SELECT CompanyID
|
|
FROM `company`
|
|
JOIN $this->db_onex.m_branch
|
|
ON CompanyM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' AND
|
|
( CompanyCode like ? OR CompanyName like ?)
|
|
) x";
|
|
$qry = $this->db_inventory->query($sql,array($search, $search));
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry) {
|
|
$tot_count = $qry->row()->total;
|
|
$tot_page = ceil($tot_count/$perpage);
|
|
} else {
|
|
// echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("company count error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$rows = array();
|
|
$sql = "SELECT CompanyID as id,
|
|
CompanyCode as code,
|
|
CompanyName as name,
|
|
M_BranchID,
|
|
M_BranchName,
|
|
'' as address
|
|
FROM `company`
|
|
JOIN $this->db_onex.m_branch
|
|
ON CompanyM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' AND
|
|
( CompanyCode like ? OR CompanyName like ?)
|
|
ORDER BY ?
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_inventory->query($sql, array($search, $search, $order, $perpage, $offset));
|
|
$last_qry = $this->db_inventory->last_query();
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
// $sql_branch = "SELECT * FROM $this->db_onex";
|
|
if(count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as label,
|
|
CompanyAddressPostCode as postcode,
|
|
CompanyAddressDescription as description,
|
|
M_KelurahanName,
|
|
M_KelurahanID,
|
|
M_DistrictID,
|
|
M_DistrictName,
|
|
M_CityID,
|
|
M_CityName,
|
|
'' as vbranch,
|
|
'' as district
|
|
FROM `companyaddress`
|
|
JOIN $this->db_onex.m_kelurahan
|
|
ON M_KelurahanID = CompanyAddressM_KelurahanID
|
|
AND M_KelurahanIsActive = 'Y'
|
|
JOIN $this->db_onex.m_district
|
|
ON M_DistrictID = M_KelurahanM_DistrictID
|
|
AND M_DistrictIsActive = 'Y'
|
|
JOIN $this->db_onex.m_city
|
|
ON M_CityID = M_DistrictM_CityID
|
|
AND M_CityIsActive = 'Y'
|
|
WHERE
|
|
CompanyAddressCompanyID = ?
|
|
AND CompanyAddressIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($value['id']));
|
|
// echo $this->db_inventory->last_query();
|
|
if($qry){
|
|
// $rows[$key]['address'] = $qry->result_array();
|
|
$companyaddress = $qry->result_array();
|
|
|
|
// foreach($companyaddress as $k => $v)
|
|
// {
|
|
// $sql_district = "SELECT *
|
|
// FROM $this->db_onex.m_district
|
|
// WHERE M_DistrictIsActive = 'Y'
|
|
// AND M_DistrictM_CityID = ?
|
|
// ";
|
|
|
|
// $qry_district = $this->db_inventory->query($sql_district, array(
|
|
// $v["M_CityID"]
|
|
// ));
|
|
|
|
// $sql_kel = "SELECT *
|
|
// FROM $this->db_onex.m_kelurahan
|
|
// WHERE M_KelurahanIsActive = 'Y'
|
|
// AND M_KelurahanM_DistrictID = ?";
|
|
|
|
// $qry_kelurahan = $this->db_inventory->query($sql_kel, array(
|
|
// $v["M_DistrictID"]
|
|
// ));
|
|
|
|
// $data_district = $qry_district->result_array();
|
|
// $data_kelurahan = $qry_kelurahan->result_array();
|
|
|
|
// $companyaddress[$k]['kelurahan'] = $data_kelurahan;
|
|
// $companyaddress[$k]['district'] = $data_district;
|
|
// }
|
|
|
|
$rows[$key]['address'] = $companyaddress;
|
|
|
|
|
|
}
|
|
}
|
|
}else{
|
|
$rows[0]['address'] = [];
|
|
}
|
|
|
|
}else {
|
|
$this->sys_error_db("company data error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$result = array("total_page" => $tot_page, "records" => $rows, "sql"=> $last_qry);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// branch
|
|
function get_branch()
|
|
{
|
|
//SELECT * FROM `m_location`
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM `m_branch`
|
|
where M_BranchIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(M_BranchID) as total
|
|
FROM `m_branch`
|
|
where M_BranchIsActive = 'Y' ";
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// city
|
|
function searchcity(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// kecamatan
|
|
function getdistrict(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
// kelurahan
|
|
function getkelurahan(){
|
|
$prm = $this->sys_input;
|
|
// echo $prm['prm']['M_DistrictID'];
|
|
$query =" SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['prm']['M_DistrictID']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function delete()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$param = $this->sys_input;
|
|
$id = "";
|
|
if (isset($param['id'])) {
|
|
$id = intval($param["id"]);
|
|
}
|
|
if ($id == "" || !$id) {
|
|
$error = array(
|
|
"message" => "id is mandatory",
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE company
|
|
SET CompanyIsActive = 'N',
|
|
CompanyLastUpdated = now(),
|
|
CompanyUserID = ?
|
|
WHERE CompanyID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("delete company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}else{
|
|
$sql = "UPDATE companyaddress
|
|
SET CompanyAddressIsActive = 'N',
|
|
CompanyAddressLastUpdated = now(),
|
|
CompanyAddressUserID = ?
|
|
WHERE
|
|
CompanyAddressCompanyID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("delete company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
$sql = "SELECT company.*, '' as address
|
|
FROM company
|
|
WHERE CompanyID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `companyaddress`
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND
|
|
CompanyAddressIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['address'] = $qry->result_array();
|
|
}else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
|
|
$sql = "INSERT INTO company_log (
|
|
CompanyLogCompanyID,
|
|
CompanyLogStatus,
|
|
CompanyLogJSONBefore,
|
|
CompanyLogJSONAfter,
|
|
CompanyLogUserID,
|
|
CompanyLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'DELETE',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->db_inventory_log->trans_rollback();
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function save()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$branch_id = "";
|
|
if(isset($prm['branch_id'])){
|
|
$branch_id = trim($prm['branch_id']);
|
|
}
|
|
|
|
$name = "";
|
|
if (isset($prm['name'])) {
|
|
$name = trim($prm["name"]);
|
|
}
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$numbering = '';
|
|
$sql = "SELECT `fn_numbering`('CompAddr') as numbering";
|
|
$qry = $this->db_inventory->query($sql);
|
|
if($qry){
|
|
$numbering = $qry->row()->numbering;
|
|
}
|
|
else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("get numbering error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$last_id = 0;
|
|
$sql = "INSERT INTO company(
|
|
CompanyM_BranchID,
|
|
CompanyCode,
|
|
CompanyName,
|
|
CompanyUserID,
|
|
CompanyCreated,
|
|
CompanyLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$branch_id,
|
|
$numbering,
|
|
$name,
|
|
$userid
|
|
));
|
|
if($qry){
|
|
$last_id = $this->db_inventory->insert_id();
|
|
}
|
|
else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("add company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['address'])>0){
|
|
foreach ($prm['address'] as $key => $value) {
|
|
$postcode = trim($value['postcode']);
|
|
$description = trim($value['description']);
|
|
$label = trim($value['label']);
|
|
$kelurahan_id = trim($value['kelurahan_id']);
|
|
$sql = "INSERT INTO companyaddress(
|
|
CompanyAddressCompanyID,
|
|
CompanyAddressLabel,
|
|
CompanyAddressDescription,
|
|
CompanyAddressPostCode,
|
|
CompanyAddressM_KelurahanID,
|
|
CompanyAddressUserID,
|
|
CompanyAddressCreated,
|
|
CompanyAddressLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$last_id,
|
|
$label,
|
|
$description,
|
|
$postcode,
|
|
$kelurahan_id,
|
|
$userid
|
|
));
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("add company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT company.*, '' as address
|
|
FROM company
|
|
WHERE CompanyID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `companyaddress`
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND
|
|
CompanyAddressIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['address'] = $qry->result_array();
|
|
}else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select supplier address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO company_log (
|
|
CompanyLogCompanyID,
|
|
CompanyLogStatus,
|
|
CompanyLogJSONBefore,
|
|
CompanyLogJSONAfter,
|
|
CompanyLogUserID,
|
|
CompanyLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'ADD',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function edit(){
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$branch_id = "";
|
|
if(isset($prm['branch_id']['M_BranchID'])){
|
|
$branch_id = trim($prm['branch_id']['M_BranchID']);
|
|
}
|
|
|
|
$name = "";
|
|
if (isset($prm['name'])) {
|
|
$name = trim($prm["name"]);
|
|
}
|
|
|
|
$id = $prm['id'];
|
|
|
|
$sql = "SELECT company.*, '' as address
|
|
FROM company
|
|
WHERE CompanyID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `companyaddress`
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND
|
|
CompanyAddressIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row['address'] = $qry->result_array();
|
|
}else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_before = $row;
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$last_id = 0;
|
|
$sql = "UPDATE company SET
|
|
CompanyM_BranchID = ?,
|
|
CompanyName = ?,
|
|
CompanyLastUpdated = NOW(),
|
|
CompanyUserID = ?
|
|
WHERE
|
|
CompanyID = ?";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$branch_id,
|
|
$name,
|
|
$userid,
|
|
$prm['id']
|
|
));
|
|
if(!$qry){
|
|
// echo $this->db_inventory->last_query();
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("edit company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE companyaddress
|
|
SET CompanyAddressIsActive = 'N'
|
|
WHERE CompanyAddressCompanyID = ?";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("update N address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
if(count($prm['address'])>0){
|
|
foreach ($prm['address'] as $key => $value) {
|
|
$postcode = trim($value['postcode']);
|
|
$description = trim($value['description']);
|
|
$label = trim($value['label']);
|
|
$kelurahan_id = trim($value['kelurahan_id']);
|
|
|
|
if(intval($value['id']) > 0){
|
|
$sql = "UPDATE companyaddress SET
|
|
CompanyAddressLabel = ?,
|
|
CompanyAddressDescription = ?,
|
|
CompanyAddressPostCode = ?,
|
|
CompanyAddressM_KelurahanID = ?,
|
|
CompanyAddressUserID = ?,
|
|
CompanyAddressIsActive = 'Y',
|
|
CompanyAddressLastUpdated = NOW()
|
|
WHERE
|
|
CompanyAddressID = ?";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$label,
|
|
$description,
|
|
$postcode,
|
|
$kelurahan_id,
|
|
$userid,
|
|
$value['id']
|
|
));
|
|
if(!$qry){
|
|
// echo $this->db_inventory->last_query();
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("edit company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$postcode = trim($value['postcode']);
|
|
$description = trim($value['description']);
|
|
$label = trim($value['label']);
|
|
$kelurahan_id = trim($value['kelurahan_id']);
|
|
$sql = "INSERT INTO companyaddress(
|
|
CompanyAddressCompanyID,
|
|
CompanyAddressLabel,
|
|
CompanyAddressDescription,
|
|
CompanyAddressPostCode,
|
|
CompanyAddressM_KelurahanID,
|
|
CompanyAddressUserID,
|
|
CompanyAddressCreated,
|
|
CompanyAddressLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$prm['id'],
|
|
$label,
|
|
$description,
|
|
$postcode,
|
|
$kelurahan_id,
|
|
$userid
|
|
));
|
|
// echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
echo $this->db_inventory->last_query();
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("add company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
$sql = "SELECT company.*, '' as address
|
|
FROM company
|
|
WHERE CompanyID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `companyaddress`
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND
|
|
CompanyAddressIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['address'] = $qry->result_array();
|
|
}else{
|
|
$this->db_inventory->trans_rollback();
|
|
$this->sys_error_db("select company address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO company_log (
|
|
CompanyLogCompanyID,
|
|
CompanyLogStatus,
|
|
CompanyLogJSONBefore,
|
|
CompanyLogJSONAfter,
|
|
CompanyLogUserID,
|
|
CompanyLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql,
|
|
array(
|
|
$id,
|
|
'EDIT',
|
|
json_encode($data_log_before),
|
|
json_encode($data_log_after),$userid
|
|
));
|
|
if(!$qry){
|
|
$this->db_inventory_log->trans_rollback();
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|