|
|
|
@ -7,6 +7,7 @@ import os
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from config import get_connection
|
|
|
|
from config import get_connection
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Eac:
|
|
|
|
class Eac:
|
|
|
|
@ -34,6 +35,8 @@ class Eac:
|
|
|
|
(SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'inflation_rate') as inflation_rate
|
|
|
|
(SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'inflation_rate') as inflation_rate
|
|
|
|
, (SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'discount_rate') as discount_rate
|
|
|
|
, (SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'discount_rate') as discount_rate
|
|
|
|
, (select COALESCE(rc_total_cost,0) from lcc_equipment_tr_data ltd where assetnum = %s and seq = 0) as rc_total_cost_0
|
|
|
|
, (select COALESCE(rc_total_cost,0) from lcc_equipment_tr_data ltd where assetnum = %s and seq = 0) as rc_total_cost_0
|
|
|
|
|
|
|
|
, (SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'history_inflation_rate') as history_inflation_rate
|
|
|
|
|
|
|
|
, (SELECT value_num / 100 FROM lcc_ms_master WHERE name = 'history_future_inflation_rate_annual') as history_future_inflation_rate_annual
|
|
|
|
;
|
|
|
|
;
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
cursor.execute(query_inflation_rate, (equipment_id,))
|
|
|
|
cursor.execute(query_inflation_rate, (equipment_id,))
|
|
|
|
@ -44,6 +47,8 @@ class Eac:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
inflation_rate = inflation_rate_result["inflation_rate"]
|
|
|
|
inflation_rate = inflation_rate_result["inflation_rate"]
|
|
|
|
|
|
|
|
history_inflation_rate = inflation_rate_result["history_inflation_rate"]
|
|
|
|
|
|
|
|
history_future_inflation_rate = inflation_rate_result["history_future_inflation_rate_annual"]
|
|
|
|
disc_rate = inflation_rate_result["discount_rate"]
|
|
|
|
disc_rate = inflation_rate_result["discount_rate"]
|
|
|
|
rc_total_cost_0 = inflation_rate_result["rc_total_cost_0"]
|
|
|
|
rc_total_cost_0 = inflation_rate_result["rc_total_cost_0"]
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,13 +75,13 @@ class Eac:
|
|
|
|
# Rumus NPV: NPV = Σ [Ct / (1 + r)^t]
|
|
|
|
# Rumus NPV: NPV = Σ [Ct / (1 + r)^t]
|
|
|
|
# dimana Ct = cash flow pada periode t, r = disc_rate, t = periode
|
|
|
|
# dimana Ct = cash flow pada periode t, r = disc_rate, t = periode
|
|
|
|
final_value = sum(
|
|
|
|
final_value = sum(
|
|
|
|
value / ((1 + disc_rate) ** (i + 1))
|
|
|
|
value / ((1 + history_inflation_rate) ** (i + 1))
|
|
|
|
for i, value in enumerate(cumulative_values)
|
|
|
|
for i, value in enumerate(cumulative_values)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# Menghitung PMT biaya maintenance
|
|
|
|
# Menghitung PMT biaya maintenance
|
|
|
|
# Rumus PMT: PMT = PV * [r(1 + r)^n] / [(1 + r)^n – 1]
|
|
|
|
# Rumus PMT: PMT = PV * [r(1 + r)^n] / [(1 + r)^n – 1]
|
|
|
|
# dimana PV = final_value, r = disc_rate, n = row["seq"]
|
|
|
|
# dimana PV = final_value, r = history_future_inflation_rate, n = row["seq"]
|
|
|
|
pmt_mnt_cost = -npf.pmt(disc_rate, row["seq"], final_value)
|
|
|
|
pmt_mnt_cost = -npf.pmt(history_future_inflation_rate, row["seq"], final_value)
|
|
|
|
|
|
|
|
|
|
|
|
eac_disposal_cost = 0.07 * pmt_mnt_cost
|
|
|
|
eac_disposal_cost = 0.07 * pmt_mnt_cost
|
|
|
|
# Menghitung PMT biaya akuisisi
|
|
|
|
# Menghitung PMT biaya akuisisi
|
|
|
|
@ -365,42 +370,13 @@ def main(assetnum=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
|
|
|
|
connections = get_connection()
|
|
|
|
|
|
|
|
connection = connections[0] if isinstance(connections, tuple) else connections
|
|
|
|
|
|
|
|
if connection is None:
|
|
|
|
|
|
|
|
print("Database connection failed.")
|
|
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
|
|
|
|
|
|
|
query_main = "SELECT DISTINCT(assetnum) FROM ms_equipment_master WHERE assetnum = 'A26190'"
|
|
|
|
|
|
|
|
cursor.execute(query_main)
|
|
|
|
|
|
|
|
results = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eac = Eac()
|
|
|
|
|
|
|
|
for row in results:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
assetnum = row["assetnum"]
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
assetnum = row[0] if len(row) > 0 else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if assetnum is None:
|
|
|
|
|
|
|
|
print("Skipping None assetnum")
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Processing asset: {assetnum}")
|
|
|
|
parser = argparse.ArgumentParser(description="Run EAC calculation for equipment.")
|
|
|
|
eac.hitung_eac_equipment(assetnum)
|
|
|
|
parser.add_argument("--assetnum", type=str, help="Asset number to process (optional). If not provided, process all.")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
print("EAC calculation finished for all equipment.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
processed = main(assetnum=args.assetnum)
|
|
|
|
|
|
|
|
print(f"EAC calculation finished for: {processed}")
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
print("Terjadi kesalahan saat memproses semua equipment:", str(e))
|
|
|
|
print("Terjadi kesalahan saat memproses semua equipment:", str(e))
|
|
|
|
finally:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|