|
@@ -18,6 +18,7 @@ using System.Data;
|
|
|
using System.Data.Entity;
|
|
|
using System.Data.SqlClient;
|
|
|
using System.Diagnostics;
|
|
|
+using System.Globalization;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
@@ -215,7 +216,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
registerCount = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Register).ToList().Count;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (registerCount > 0)
|
|
|
{
|
|
|
string voltage_text = item.sampledValue.Where(x => x.measurand == Measurand.Voltage).Select(x => x.value).FirstOrDefault();
|
|
@@ -362,7 +363,6 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
parameters.Add("@IdTag", _request.idTag, DbType.String, ParameterDirection.Input);
|
|
|
string strSql = "select parentIdTag from [dbo].[LocalListDetail] where ListId = 27 and IdTag=@IdTag; ";
|
|
|
accountBalance = conn.ExecuteScalar<string>(strSql, parameters);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -445,7 +445,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
&& x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
|
|
|
//遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
- if(_request.timestamp < new DateTime(2021,11,1))
|
|
|
+ if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
{
|
|
|
var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
@@ -510,7 +510,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
result.Exception = new Exception("Can't find transactionId " + _request.transactionId);
|
|
|
|
|
|
}
|
|
@@ -658,45 +658,46 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
|
|
|
string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
|
|
|
decimal sum = 0;
|
|
|
- // if (feedto.Fee.Length > 10)
|
|
|
+ if (feedto.Fee.Length > 10)
|
|
|
{
|
|
|
chargingPrices = JsonConvert.DeserializeObject<List<ChargingPrice>>(feedto.Fee.Split('|')[0]);
|
|
|
foreach (var item in txEnergy.PeriodEnergy)
|
|
|
{
|
|
|
- string startTime = item.Key.Length == 1 ? "0" + item.Key + ":00" : item.Key + ":00";
|
|
|
+ DateTime dt = new DateTime(2021, 01, 01, int.Parse(item.Key), 0, 0, DateTimeKind.Utc);
|
|
|
+ string startTime = dt.ToString("HH:mm tt", new CultureInfo("en-us"));
|
|
|
decimal perfee = 0;
|
|
|
+
|
|
|
+ //小數點無條件捨去到第三位
|
|
|
+ var periodEnergy = (decimal)((int)Decimal.Multiply(item.Value, 1000) / (double)1000);
|
|
|
if (chargingPrices.Count == 1)
|
|
|
{
|
|
|
- perfee = Decimal.Multiply(item.Value, chargingPrices[0].Fee);
|
|
|
+ perfee = Decimal.Multiply(periodEnergy, chargingPrices[0].Fee);
|
|
|
if (bill.Count == 0)
|
|
|
{
|
|
|
bill.Add(new ChargingBill()
|
|
|
{
|
|
|
- StartTime = "00:00",
|
|
|
- EndTime = "23:59",
|
|
|
+ StartTime = "12:00 AM",
|
|
|
+ EndTime = "11:59 PM",
|
|
|
Fee = chargingPrices[0].Fee
|
|
|
});
|
|
|
}
|
|
|
- bill[0].PeriodEnergy += item.Value;
|
|
|
- bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
|
|
|
+
|
|
|
+ bill[0].PeriodEnergy += periodEnergy;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var price = chargingPrices.Where(x => x.StartTime == startTime).FirstOrDefault();
|
|
|
- perfee = Decimal.Multiply(item.Value, price.Fee);
|
|
|
+ perfee = Decimal.Multiply(periodEnergy, price.Fee);
|
|
|
|
|
|
bill.Add(new ChargingBill()
|
|
|
{
|
|
|
StartTime = price.StartTime,
|
|
|
EndTime = price.EndTime,
|
|
|
- PeriodEnergy = Math.Round(item.Value, 3, MidpointRounding.AwayFromZero),
|
|
|
+ PeriodEnergy = periodEnergy,
|
|
|
Fee = price.Fee,
|
|
|
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
if (bill.Count > 0)
|
|
|
{
|
|
@@ -705,12 +706,11 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
if (bill.Count == 1)
|
|
|
{
|
|
|
- bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
|
|
|
+
|
|
|
bill[bill.Count - 1].Total = DollarRounding(Decimal.Multiply(bill[0].PeriodEnergy, bill[0].Fee), session.Currency);
|
|
|
sum = bill[bill.Count - 1].Total;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -737,35 +737,54 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (tx.UploadedtoTTIA) return result;
|
|
|
var startTime = new DateTime(tx.StartTime.Year, tx.StartTime.Month, tx.StartTime.Day, tx.StartTime.Hour, 0, 0);
|
|
|
List<ChargingBill> confirmbill = new List<ChargingBill>();
|
|
|
- receipt = string.Format("Energy:");
|
|
|
+ receipt = string.Format("({0} )Energy:", bill.Sum(x => x.PeriodEnergy));
|
|
|
+
|
|
|
+
|
|
|
while (startTime < tx.StopTime)
|
|
|
{
|
|
|
if (bill.Count == 1)
|
|
|
{
|
|
|
confirmbill = bill;
|
|
|
- receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", bill[0].StartTime, bill[0].EndTime, bill[0].Fee, bill[0].Total);
|
|
|
+ receipt += string.Format("| {0}-{1} @ ${2}/kWh=${3}", tx.StartTime.ToString("HH:mm tt", new CultureInfo("en-us")), tx.StopTime.ToString("HH:mm tt", new CultureInfo("en-us")), bill[0].Fee, bill[0].Total);
|
|
|
break;
|
|
|
}
|
|
|
if (bill.Count > 1)
|
|
|
{
|
|
|
+ var time = startTime.ToString("HH:mm tt", new CultureInfo("en-us"));
|
|
|
+ var tt = bill.Where(x => x.StartTime ==time).FirstOrDefault();
|
|
|
+ confirmbill.Add(tt);
|
|
|
+ if (confirmbill.Count == 1)
|
|
|
+ {
|
|
|
+ confirmbill[0].StartTime = tx.StartTime.ToString("HH:mm tt", new CultureInfo("en-us"));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- confirmbill.Add(bill.Where(x => x.StartTime == startTime.ToString("HH:00")).FirstOrDefault());
|
|
|
- if (confirmbill.Count == 24) break;
|
|
|
- //if (confirmbill.Count > 1)
|
|
|
- //{
|
|
|
- // receipt += "|";
|
|
|
- //}
|
|
|
- receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
|
|
|
+ var stopTimeText = tx.StopTime.ToString("HH:mm tt", new CultureInfo("en-us"));
|
|
|
+ if (confirmbill[confirmbill.Count - 1].StartTime.Contains(stopTimeText.Split(' ')[1]))
|
|
|
+ {
|
|
|
+ var subHourText = (int.Parse(stopTimeText.Split(':')[0])).ToString();
|
|
|
+ subHourText = subHourText.Length == 1 ? "0" + subHourText : subHourText;
|
|
|
+ if(confirmbill[confirmbill.Count - 1].StartTime.Contains(subHourText))
|
|
|
+ {
|
|
|
+ confirmbill[confirmbill.Count - 1].EndTime = stopTimeText;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ receipt += string.Format("| {0}-{1} @ ${2}/kWh=${3}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
|
|
|
confirmbill[confirmbill.Count - 1].Fee, confirmbill[confirmbill.Count - 1].Total);
|
|
|
|
|
|
-
|
|
|
+ if (confirmbill.Count == 24) break;
|
|
|
|
|
|
}
|
|
|
startTime = startTime.AddHours(1);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- receipt += string.Format("|Parking fee: | {0}~{1} @ ${2}/hr=${3}", feedto.StartTime.ToString("HH:mm"), feedto.StopTime.ToString("HH:mm"), fee, parkingCost);
|
|
|
+ if (confirmbill.Count > 1)
|
|
|
+ {
|
|
|
+ receipt += string.Format("|Total Energy Fee : ${0}", confirmbill.Sum(x => x.Total));
|
|
|
+ }
|
|
|
+ receipt += string.Format("|Parking Fee: | {0}-{1} @ ${2}/hr=${3}", feedto.StartTime.ToString("HH:mm tt", new CultureInfo("en-us")),
|
|
|
+ feedto.StopTime.ToString("HH:mm tt", new CultureInfo("en-us")), fee, parkingCost);
|
|
|
tx.Cost = sum + parkingCost;
|
|
|
tx.Receipt = receipt;
|
|
|
tx.UploadedtoTTIA = true;
|
|
@@ -790,8 +809,18 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
data = JsonConvert.SerializeObject(new
|
|
|
{
|
|
|
txId = txEnergy.TxId,
|
|
|
- description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
- "${2} {0}; Total Cost: ${3} {0}; Account Balance: ${4} {0}", currency, sum, parkingCost, tx.Cost, accountBalance - tx.Cost)
|
|
|
+ // description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
+ //"${2} {0}; Total Cost: ${3} {0}; Account Balance: ${4} {0}", currency, sum, parkingCost, tx.Cost, accountBalance - tx.Cost)
|
|
|
+ description = JsonConvert.SerializeObject(new
|
|
|
+ {
|
|
|
+ chargedEnergy = bill.Sum(x => x.PeriodEnergy),
|
|
|
+ chargingFee = sum,
|
|
|
+ parkTime = (int)stoptime.Subtract(starttime).TotalSeconds,
|
|
|
+ parkingFee = parkingCost,
|
|
|
+ currency = currency,
|
|
|
+ couponPoint = 0,
|
|
|
+ accountBalance = accountBalance - tx.Cost
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
},
|
|
@@ -805,7 +834,6 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
{
|
|
|
-
|
|
|
var parameters = new DynamicParameters();
|
|
|
parameters.Add("@IdTag", tx.StartIdTag, DbType.String, ParameterDirection.Input);
|
|
|
parameters.Add("@parentIdTag", accountBalance - tx.Cost, DbType.String, ParameterDirection.Input);
|
|
@@ -820,7 +848,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
{ "email","2"},
|
|
|
{ "to","wonderj@phihongusa.com;jessica_tseng@phihong.com.tw"}
|
|
|
-
|
|
|
+ //{ "to","jessica_tseng@phihong.com.tw"}
|
|
|
}, null);
|
|
|
|
|
|
Console.WriteLine(JsonConvert.SerializeObject(mail_response));
|
|
@@ -830,6 +858,17 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
+ // 計算停車費
|
|
|
+ var fee = decimal.Parse(feedto.Fee.Split('&')[1]);
|
|
|
+ decimal accountBalance = 0;
|
|
|
+ var stoptime = DateTime.Parse(DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm"));
|
|
|
+ var starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
|
|
|
+ decimal.TryParse(feedto.Fee.Split('+')[1], out accountBalance);
|
|
|
+ var totalHours = stoptime.Subtract(starttime).TotalHours;
|
|
|
+ var parkingCost = Decimal.Multiply((decimal)totalHours, fee);
|
|
|
+ parkingCost = DollarRounding(parkingCost, session.Currency);
|
|
|
+
|
|
|
db.ServerMessage.Add(new ServerMessage()
|
|
|
{
|
|
|
ChargeBoxId = session.ChargeBoxId,
|
|
@@ -844,8 +883,17 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
data = JsonConvert.SerializeObject(new
|
|
|
{
|
|
|
txId = txEnergy.TxId,
|
|
|
- description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
- "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $0.00 {0}", currency, sum)
|
|
|
+ //description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
+ //"${2} {0}; Total Cost: ${3} {0}; Account Balance: $0.00 {0}", currency, sum, parkingCost, sum + parkingCost),
|
|
|
+ description = JsonConvert.SerializeObject(new
|
|
|
+ {
|
|
|
+ chargedEnergy = bill.Sum(x => x.PeriodEnergy),
|
|
|
+ chargingFee = sum,
|
|
|
+ parkTime = (int)stoptime.Subtract(starttime).TotalSeconds,
|
|
|
+ parkingFee = parkingCost,
|
|
|
+ currency = currency
|
|
|
+ })
|
|
|
+
|
|
|
})
|
|
|
|
|
|
},
|