private string FormatPreviousAsJson(Payouts payouts) { StringBuilder result = new StringBuilder(16384); foreach (Payout payout in payouts) { PaymentTransferInfo transferInfo = payout.PaymentTransferInfo; result.Append("{"); result.AppendFormat( "\"itemId\":\"{7}\"," + "\"paid\":\"yes\"," + "\"databaseId\":\"{8}\"," + "\"due\":\"{1}\"," + "\"recipient\":\"{2}\"," + "\"transferInfo\":\"{3}\"," + "\"amount\":\"{6}\"," + "\"ocrAvailable\":\"{4}\"," + "\"action\":\"" + "<img id='IconApproval{7}' class='IconApproval{7} LocalIconApproval LocalPaid action-icon' baseid='{7}' protoid='{0}' databaseid='{8}' data-ocr='{10}' data-fieldcount='{9}' data-reference='{5}' />" + "<img class='IconApproved{7} LocalIconApproved LocalPaid status-icon' baseid='{7}' />" + "<img class='IconWait{7} LocalIconWait LocalPaid status-icon' baseid='{7}' />" + "<img class='IconUndo{7} LocalIconUndo LocalPaid action-icon' baseid='{7}' />" + "<img class='IconDenial{7} LocalIconDenial LocalPaid action-icon' baseid='{7}' />" + "<img class='IconDenied{7} LocalIconDenied LocalPaid status-icon' baseid='{7}' />" + "\"", payout.ProtoIdentity, payout.ExpectedTransactionDate.ToShortDateString(), JsonSanitize(TryLocalize(transferInfo.Recipient)), transferInfo.Currency.Code + ", " + JsonSanitize(transferInfo.LocalizedPaymentMethodName), transferInfo.OcrAvailable ? "<img class='LocalIconOcr status-icon' />" : string.Empty, JsonSanitize(TryLocalize(payout.Reference)), payout.AmountCents / 100.0, payout.ProtoIdentity.Replace("|", ""), payout.Identity, transferInfo.LocalizedPaymentInformation.Count, transferInfo.OcrAvailable ? "yes" : "no"); result.Append("},"); } if (result.Length > 0) { result.Remove(result.Length - 1, 1); // remove last comma, if there are any elements } return(result.ToString()); }
private string FormatPrototypesAsJson(Payouts payouts) { StringBuilder result = new StringBuilder(16384); DateTime today = DateTime.Today; bool bitcoinHotWalletActive = (this.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot != null ? true : false); foreach (Payout payout in payouts) { if (bitcoinHotWalletActive && payout.RecipientPerson != null && payout.RecipientPerson.BitcoinPayoutAddress.Length > 0 && payout.Account.Length < 4) // 4 because an empty account will be " / ", length 3 { // This is a person who will be paid in bitcoin per personal preferences, so don't show for manual payout continue; } if (bitcoinHotWalletActive && payout.Account.StartsWith("bitcoin:")) { // This is a payout registered to be paid in bitcoin, so don't show for manual payout continue; } PaymentTransferInfo transferInfo = payout.PaymentTransferInfo; result.Append("{"); result.AppendFormat( "\"itemId\":\"{7}\"," + "\"due\":\"{1}\"," + "\"recipient\":\"{2}\"," + "\"transferInfo\":\"{3}\"," + "\"amount\":\"{6}\"," + "\"ocrAvailable\":\"{4}\"," + "\"action\":\"" + "<img id='IconApproval{7}' class='IconApproval{7} LocalIconApproval LocalPrototype action-icon' baseid='{7}' protoid='{0}' data-ocr='{10}' data-fieldcount='{9}' data-reference='{5}' />" + "<img id='IconApproved{7}' class='LocalIconApproved LocalPrototype status-icon' baseid='{7}' />" + "<img id='IconWait{7}' class='LocalIconWait LocalPrototype status-icon' baseid='{7}' />" + "<img id='IconUndo{7}' class='LocalIconUndo LocalPrototype action-icon' baseid='{7}' />" + "<img id='IconDenial{7}' class='LocalIconDenial LocalPrototype action-icon' baseid='{7}' />" + "<img id='IconDenied{7}' class='LocalIconDenied LocalPrototype status-icon' baseid='{7}' />" + "\"", payout.ProtoIdentity, (payout.ExpectedTransactionDate <= today ? Global.Global_ASAP : payout.ExpectedTransactionDate.ToShortDateString()), JsonSanitize(TryLocalize(transferInfo.Recipient)), transferInfo.Currency.Code + ", " + JsonSanitize(transferInfo.LocalizedPaymentMethodName), transferInfo.OcrAvailable? "<img class='LocalIconOcr status-icon' />": string.Empty, JsonSanitize(TryLocalize(payout.Reference)), payout.HasNativeAmount? payout.NativeAmountString : (payout.AmountCents / 100.0).ToString("N2"), payout.ProtoIdentity.Replace("|", ""), string.Empty, // this is here to match the databaseid field below transferInfo.LocalizedPaymentInformation.Count, transferInfo.OcrAvailable? "yes": "no"); result.Append("},"); } if (result.Length > 0) { result.Remove(result.Length - 1, 1); // remove last comma, if there are any elements } return(result.ToString()); }
public static PaymentTransferInfoResult GetPaymentTransferInfo(string prototypeId) { AuthenticationData authData = GetAuthenticationDataAndCulture(); // TODO: Authentication check string[] payoutComponents = prototypeId.Split('|'); if (payoutComponents.Length < 1) { throw new InvalidOperationException("Prototype ID can't be empty"); } PaymentTransferInfo info = new PaymentTransferInfo(); // Some payouts are composites of multiple objects, but all these will share the same // payout data, so we can safely use just the first object to determine payment // target information // // with one exception -- we need to determine the amount by adding all the objects // together, if applicable DateTime paymentDueBy = Constants.DateTimeLow; switch (Char.ToUpperInvariant(payoutComponents[0][0])) { case 'C': // expense claim info = PaymentTransferInfo.FromObject( ExpenseClaim.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))), new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency)); break; case 'A': // cash advance (payout or payback, same logic either way) info = PaymentTransferInfo.FromObject( CashAdvance.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))), new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency)); break; case 'S': // salary Salary salary = Salary.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))); info = PaymentTransferInfo.FromObject(salary); paymentDueBy = salary.PayoutDate; break; case 'I': // inbound invoice InboundInvoice invoice = InboundInvoice.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))); info = PaymentTransferInfo.FromObject(invoice); paymentDueBy = invoice.DueDate; break; default: throw new NotImplementedException("Unrecognized payment type"); } PaymentTransferInfoResult result = new PaymentTransferInfoResult { Success = true, CurrencyAmount = info.CurrencyAmount, DisplayMessage = string.Empty, Recipient = info.Recipient, Reference = info.Reference, TransferMethod = info.LocalizedPaymentMethodName }; if (paymentDueBy < Constants.DateTimeLowThreshold) { result.DueBy = Resources.Global.Global_ASAP; } else { DateTime nowUtc = DateTime.UtcNow; if (paymentDueBy.Year != nowUtc.Year || paymentDueBy < nowUtc.AddMonths(-3)) { result.DueBy = paymentDueBy.ToString(Resources.Global.Global_DateFormatLongSansWeekday); } else { result.DueBy = paymentDueBy.ToString(Resources.Global.Global_DateFormatLongDateMonth); } if (paymentDueBy < nowUtc.AddDays(-1)) { result.DueBy += " - " + Resources.Pages.Financial.PayOutMoney_PaymentLate; } } List <string> listTransferMethodLabels = new List <string>(); List <string> listTransferMethodData = new List <string>(); foreach (string label in info.LocalizedPaymentInformation.Keys) { listTransferMethodLabels.Add(HttpUtility.HtmlEncode(label)); listTransferMethodData.Add(HttpUtility.HtmlEncode(info.LocalizedPaymentInformation [label])); } result.TransferMethodLabels = listTransferMethodLabels.ToArray(); result.TransferMethodData = listTransferMethodData.ToArray(); result.OcrData = info.OcrData; // can be null and that's ok return(result); }