Ejemplo n.º 1
0
        /// <summary>
        /// This is the Accounting name for making a purchase (<see cref="MakePurchase"/>
        /// </summary>
        public IAccount <Identifier> Credit(Pecuniam amt, IVoca note = null, DateTime?atTime = null, ITransactionId trace = null)
        {
            var dt = atTime ?? Balance.LastTransaction.AtTime;

            AddPositiveValue(dt, amt, note, trace);
            return(this);
        }
Ejemplo n.º 2
0
        protected CreditCard(IVoca cardholder, DateTime?openedDate, DateTime?expiryDate)
        {
            CardHolderSince = openedDate.GetValueOrDefault(DateTime.UtcNow);

            if (expiryDate == null)
            {
                ExpDate = Etx.RandomDate(Etx.RandomInteger(4, 6), null);
                ExpDate = new DateTime(ExpDate.Year, ExpDate.Month, Etx.RandomCoinToss() ? 1 : 15);
            }
            else
            {
                ExpDate = expiryDate.Value;
            }
            if (cardholder != null)
            {
                var fname = (cardholder.GetName(KindsOfNames.First) ?? String.Empty).ToUpper();
                var lname = (cardholder.GetName(KindsOfNames.Surname) ?? String.Empty).ToUpper();
                CardHolderName = string.IsNullOrWhiteSpace(fname) && string.IsNullOrWhiteSpace(lname)
                    ? (cardholder.GetName(KindsOfNames.Legal) ?? String.Empty).ToUpper()
                    : String.Join(" ", fname, lname);
            }

            Cvv    = $"{Etx.RandomInteger(7, 999),3:D3}";
            Number = GetRandomCardNumber();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Applies a payment to the credit card account
 /// </summary>
 /// <returns>
 /// when <see cref="dt"/> is after the expiration date
 /// </returns>
 public override Guid AddNegativeValue(DateTime dt, Pecuniam amount, IVoca note = null, ITransactionId trace = null)
 {
     if (dt > Cc.ExpDate)
     {
         return(Guid.Empty);
     }
     return(base.AddNegativeValue(dt, amount, note, trace));
 }
Ejemplo n.º 4
0
 public TransactionNote(IVoca copyFrom)
 {
     if (copyFrom == null)
     {
         return;
     }
     CopyNamesFrom(copyFrom);
 }
Ejemplo n.º 5
0
        public static SavingsAccount RandomSavingAccount(IVoca personName = null, DateTime?dt = null)
        {
            var dtd       = dt.GetValueOrDefault(DateTime.UtcNow);
            var accountId = new AccountId(Etx.RandomRChars(true));

            return(new SavingsAccount(accountId, dtd)
            {
                Name = personName?.Name
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Tries to parse a single item
        /// from the US Domus Opes data file
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="voca"></param>
        /// <returns></returns>
        internal static bool TryParseUsDomusOpesXml(XmlNode xmlNode, out IVoca voca)
        {
            voca = null;

            if (xmlNode == null)
            {
                return(false);
            }

            if (!(xmlNode is XmlElement xmlElem))
            {
                return(false);
            }

            var egs = new List <string>();

            var groupName = xmlElem.ParentNode is XmlElement groupElem && groupElem.HasAttributes
                ? groupElem.GetAttribute("name")
                : "";
            var itemName = xmlElem.GetAttribute("name");
            var abbrev   = xmlElem.GetAttribute("abbrev");

            if (xmlElem.HasChildNodes)
            {
                foreach (var cn in xmlElem.ChildNodes)
                {
                    if (!(cn is XmlElement childElem))
                    {
                        continue;
                    }
                    if (childElem.LocalName != "eg" || !childElem.HasAttributes)
                    {
                        continue;
                    }
                    var eg = childElem.GetAttribute("name");
                    if (String.IsNullOrWhiteSpace(eg))
                    {
                        continue;
                    }
                    egs.Add(eg);
                }
            }

            voca = new VocaBase(itemName);
            if (!string.IsNullOrWhiteSpace(abbrev))
            {
                voca.AddName(KindsOfNames.Abbrev, abbrev);
            }
            if (!string.IsNullOrWhiteSpace(groupName))
            {
                voca.AddName(KindsOfNames.Group, groupName);
            }

            return(!string.IsNullOrWhiteSpace(itemName));
        }
Ejemplo n.º 7
0
 protected CreditCard(string cardNumber, string cvv, IVoca cardholder, DateTime?openedDate,
                      DateTime?expiryDate) : this(cardNumber, cardholder, openedDate, expiryDate)
 {
     if (cvv == null)
     {
         return;
     }
     if (!Regex.IsMatch(cvv, "[0-9]{3}"))
     {
         throw new ArgumentException($"The CVV value {cvv} is not valid.");
     }
     Cvv = cvv;
 }
Ejemplo n.º 8
0
        public static CheckingAccount RandomCheckingAccount(IVoca personName = null, DateTime?dt = null, string debitPin = null)
        {
            var dtd       = dt.GetValueOrDefault(DateTime.UtcNow);
            var accountId = new AccountId(Etx.RandomRChars(true));

            return(CheckingAccount.IsPossiblePin(debitPin)
                ? new CheckingAccount(accountId, dtd,
                                      new Tuple <ICreditCard, string>(CreditCard.RandomCreditCard(personName), debitPin))
                : new CheckingAccount(accountId, dtd)
            {
                Name = personName?.Name
            });
        }
Ejemplo n.º 9
0
        public virtual IAccount <Identifier> Credit(Pecuniam amt, IVoca note = null, DateTime?atTime = null, ITransactionId trace = null)
        {
            var dt = atTime ?? Balance.LastTransaction.AtTime;

            if (IsOppositeForm)
            {
                AddPositiveValue(dt, amt, note, trace);
            }
            else
            {
                AddNegativeValue(dt, amt, note, trace);
            }
            return(this);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Applies a purchase transaction to this credit card.
        /// </summary>
        /// <returns>
        /// True when the card is not expired and
        /// the purchase amount <see cref="amount"/>
        /// will not cause the total balance to exceed <see cref="Max"/>.
        /// </returns>
        public override Guid AddPositiveValue(DateTime dt, Pecuniam amount, IVoca note = null, ITransactionId trace = null)
        {
            if (dt > Cc.ExpDate)
            {
                return(Guid.Empty);
            }
            var cBal = GetValueAt(dt);

            if (cBal >= Max || cBal + amount >= Max)
            {
                return(Guid.Empty);
            }
            return(base.AddPositiveValue(dt, amount, note));
        }
Ejemplo n.º 11
0
        protected CreditCard(string cardNumber, IVoca cardholder, DateTime?openedDate, DateTime?expiryDate) : this(
                cardholder, openedDate, expiryDate)
        {
            var ccNum = GetRandomCardNumber();

            if (string.IsNullOrWhiteSpace(cardNumber))
            {
                return;
            }
            if (!ccNum.Validate(cardNumber))
            {
                throw new ArgumentException($"The card number {cardNumber} is not valid.");
            }
            ccNum.Value = cardNumber;
        }
Ejemplo n.º 12
0
        internal static Guid AddTransaction(ISet <ITransaction> items, DateTime dt, Pecuniam amount,
                                            IVoca note = null, ITransactionId trace = null)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }
            var t = new Transaction(dt, amount, note)
            {
                Trace = trace
            };

            items.Add(t);
            return(t.UniqueId);
        }
Ejemplo n.º 13
0
 protected internal IAccount <Identifier> Get(IVoca name)
 {
     foreach (var acct in _dataStore)
     {
         var acctName = acct as IVoca;
         if (acctName == null)
         {
             continue;
         }
         if (VocaBase.Equals(acctName, name))
         {
             return(acct);
         }
     }
     return(null);
 }
Ejemplo n.º 14
0
 public virtual Guid AddNegativeValue(DateTime dt, Pecuniam amount, IVoca note = null, ITransactionId trace = null)
 {
     if (amount == null)
     {
         return(Guid.Empty);
     }
     if (amount == Pecuniam.Zero)
     {
         return(Guid.Empty);
     }
     while (DataSet.Any(x => DateTime.Compare(x.AtTime, dt) == 0))
     {
         dt = dt.AddTicks(1L);
     }
     return(Transaction.AddTransaction(DataSet, dt, amount.GetNeg(), note, trace));
 }
Ejemplo n.º 15
0
        protected VitalRecord(IVoca personName)
        {
            if (personName == null)
            {
                return;
            }

            PersonFullName = NfString.DistillSpaces(
                string.Join(" ", personName.GetName(KindsOfNames.First),
                            personName.GetName(KindsOfNames.Surname)));

            if (string.IsNullOrWhiteSpace(PersonFullName))
            {
                PersonFullName = personName.GetName(KindsOfNames.Legal);
            }
        }
Ejemplo n.º 16
0
        public AmericanDeathCert(MannerOfDeath mannerOfDeath, IVoca personName) : this(mannerOfDeath, (string)null)
        {
            if (personName == null)
            {
                return;
            }

            PersonFullName = NfString.DistillSpaces(
                string.Join(" ", personName.GetName(KindsOfNames.First),
                            personName.GetName(KindsOfNames.Middle),
                            personName.GetName(KindsOfNames.Surname)));

            if (string.IsNullOrWhiteSpace(PersonFullName))
            {
                PersonFullName = personName.GetName(KindsOfNames.Legal);
            }
        }
Ejemplo n.º 17
0
        public AmericanBirthCert(IVoca personName) : base((IVoca)null)
        {
            if (personName == null)
            {
                return;
            }

            PersonFullName = NfString.DistillSpaces(
                string.Join(" ", personName.GetName(KindsOfNames.First),
                            personName.GetName(KindsOfNames.Middle),
                            personName.GetName(KindsOfNames.Surname)));

            if (string.IsNullOrWhiteSpace(PersonFullName))
            {
                PersonFullName = personName.GetName(KindsOfNames.Legal);
            }
        }
Ejemplo n.º 18
0
        public TraceTransactionId GetThisAsTraceId(DateTime?atTime = null, IVoca journalName = null)
        {
            var dt = atTime ?? AtTime;

            //get copy of myself as a transaction id
            var innerTrace = new TraceTransactionId(this, dt);

            //with this, consider linked-list of trace as journal -> myself -> my-trace
            if (journalName != null && journalName.AnyNames())
            {
                innerTrace = new TraceTransactionId(this, dt, journalName)
                {
                    Trace = new TraceTransactionId(this)
                };
            }

            return(innerTrace);
        }
Ejemplo n.º 19
0
        public static ICreditCard RandomCreditCard(IVoca cardholder, DateTime?openedDate = null)
        {
            var fk = Etx.RandomInteger(0, 3);
            var dt = openedDate ?? Etx.RandomDate(-3, null);

            switch (fk)
            {
            case 0:
                return(new MasterCardCc(cardholder, dt, dt.AddYears(3)));

            case 2:
                return(new AmexCc(cardholder, dt, dt.AddYears(3)));

            case 3:
                return(new DiscoverCc(cardholder, dt, dt.AddYears(3)));

            default:
                return(new VisaCc(cardholder, dt, dt.AddYears(3)));
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Helper method to put functionality in common vernacular
 /// - is the exact same as <see cref="AddPositiveValue"/> and <see cref="Debit"/>
 /// </summary>
 public virtual Guid MakePayment(DateTime dt, Pecuniam val, IVoca note = null)
 {
     return(AddNegativeValue(dt, val, note));
 }
Ejemplo n.º 21
0
 public AmexCc(IVoca cardholder, DateTime?openedDate, DateTime?expiryDate)
     : base(cardholder, openedDate, expiryDate)
 {
 }
Ejemplo n.º 22
0
 public AmexCc(string cardNumber, IVoca cardholder, DateTime?openedDate, DateTime?expiryDate) : base(
         cardNumber, cardholder, openedDate, expiryDate)
 {
 }
Ejemplo n.º 23
0
 public MasterCardCc(string cardNumber, string cvv, IVoca cardholder, DateTime?openedDate,
                     DateTime?expiryDate) : base(cardNumber, cvv, cardholder, openedDate, expiryDate)
 {
 }
Ejemplo n.º 24
0
 public MasterCardCc(IVoca cardholder, DateTime?openedDate, DateTime?expiryDate)
     : base(cardholder, openedDate, expiryDate)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Allows for class level overrides -default is the static VocaBase.Equals
 /// </summary>
 public virtual bool NamesEqual(IVoca voca1, IVoca voca2)
 {
     return(VocaBase.Equals(voca1, voca2));
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Helper method to put functionality in common vernacular
 /// - is the exact same as <see cref="ITransactionable.AddNegativeValue(DateTime, Pecuniam, IVoca, ITransactionId)"/>
 /// </summary>
 public void PayRent(DateTime dt, Pecuniam amount, IVoca note = null)
 {
     AddNegativeValue(dt, amount, note);
 }
Ejemplo n.º 27
0
 public BirthCert(IVoca personName) : base(personName)
 {
 }
Ejemplo n.º 28
0
 public DiscoverCc(IVoca cardholder, DateTime?openedDate, DateTime?expiryDate)
     : base(cardholder, openedDate, expiryDate)
 {
 }
Ejemplo n.º 29
0
        public TraceTransactionId(ITransaction transactionId, DateTime?atTime = null, IVoca description = null)
        {
            if (transactionId == null)
            {
                throw new ArgumentNullException(nameof(transactionId));
            }

            Description = description ?? transactionId.Description;
            AtTime      = atTime ?? transactionId.AtTime;
            UniqueId    = transactionId.UniqueId;
            Trace       = transactionId.Trace;
            Phase       = transactionId.Phase;
        }
Ejemplo n.º 30
0
 private Transaction(DateTime atTime, Pecuniam amt, IVoca description = null) : base(atTime, description)
 {
     Cash = amt ?? Pecuniam.Zero;
 }