Beispiel #1
0
        public virtual bool isValid(CreditCardReport report)
        {
            if (report == null)
            {
                Logger.log("CreditCardReport is empty.");
                return false;
            }

            if (report.creditCard == null)
            {
                Logger.log("CreditCard is empty.");
                return false;
            }

            double totalFromTransactions = this.getTotalPrice(report);
            double totalFromReport = report.getTotal();

            if (!Common.Equals(totalFromTransactions, totalFromReport))
            {
                Logger.log("Total transactions price (" + totalFromTransactions + ") is different than appear in the report (" + totalFromReport + ")");
                return false;
            }

            return true;
        }
        public override CreditCardReport readCreditCardReportFile(StreamReader sr)
        {
            CreditCardReport cardData = null;
            ArrayList transactions = new ArrayList();

            using (XmlReader reader = XmlReader.Create(sr))
            {
                List<string> row;

                while ((row = getNextLine(reader)) != null)
                {
                    try
                    {
                        Transaction t = parseExpense(row);
                        transactions.Add(t);
                    }
                    catch
                    {
                        try
                        {
                            InternationalTransaction t = parseInternationalExpense(row);
                            transactions.Add(t);
                        }
                        catch
                        {
                            try
                            {
                                KeyValuePair<DateTime, double> pair = parseInternationalTotal(row);
                                cardData.totalInternational.Add(pair.Key, pair.Value);
                            }
                            catch
                            {
                                try
                                {
                                    DateTime endDate = parseSumRow(row);
                                    double total = parseToalFromSumRow(row);
                                    //string creditCardNumber = getCreditCardNumber(filename);

                                    /* assuming that this is acually the last line and all the transactions where parsed */
                                    DateTime startDate = getFirstTransactionDate(transactions, endDate);

                                    /* we should get here only once */
                                    cardData = new CreditCardReport();
                                    cardData.chargeDate = endDate;
                                    cardData.total = total;
                                    cardData.creditCard = null; // not available in Isracard report
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
            }

            cardData.transactions = transactions;

            return cardData;
        }
Beispiel #3
0
        protected double getTotalPrice(CreditCardReport report)
        {
            if (report == null || report.transactions == null)
                return 0;

            double total = 0;
            foreach (Transaction t in report.transactions)
                total += t.billingPrice;

            return total;
        }
Beispiel #4
0
        public static void addCreditCardReport(CreditCardReport report)
        {
            if (!creditCardReportsList.Contains(report))
                creditCardReportsList.Add(report);

            /*
            foreach (CreditCardReport r in Database.getCreditCardReportsList())
                if (report.Equals(r))
                {
                    Logger.log("This report [" + r.ToString() + "] is already exist in the system");
                    return false;
                }
            */
        }
Beispiel #5
0
        public override CreditCardReport readCreditCardReportFile(StreamReader sr)
        {
            CreditCardReport cardData = new CreditCardReport();
            ArrayList transactions = new ArrayList();

            string contentBuffer = sr.ReadToEnd();
            contentBuffer = contentBuffer.Replace("&nbsp;", "");
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            sw.Write(contentBuffer);
            sw.Close();
            StringReader srFixed = new StringReader(sb.ToString());

            using (XmlReader reader = XmlReader.Create(srFixed))
            {
                List<string> row;

                while ((row = getNextLine(reader)) != null)
                {
                    try
                    {
                        Transaction e = parseExpense(row);
                        transactions.Add(e);
                    }
                    catch
                    {
                        try
                        {
                            Transaction e = parseInternationalExpense(row);
                            transactions.Add(e);
                        }
                        catch
                        {
                            try
                            {
                                DateTime endDate = parseDateFromInformationRow(row);
                                string creditCardNumber = parseCreditCardFromSumRow(row);

                                /* assuming that this is acually the last line and all the transactions where parsed */
                                //DateTime startDate = getFirstTransactionDate(transactions, endDate);

                                //paymentInfo = new PaymentInfo(creditCardNumber, PaymentType.Cal, startDate, endDate);
                                /* we should get here only once */
                                //cardData = new CreditCardReport();
                                cardData.chargeDate = endDate;

                                cardData.creditCard = Database.getCreditCardByLastDigits(creditCardNumber);

                            }
                            catch
                            {
                                try
                                {
                                    cardData.total = parseToalFromSumRow(row);
                                }
                                catch { }
                            }
                        }
                    }
                }
            }

            cardData.transactions = transactions;

            return cardData;
        }
Beispiel #6
0
        public static CreditCardReport loadCreditCardReport(XmlReader reportReader)
        {
            CreditCardReport report = new CreditCardReport();
            while (reportReader.Read())
            {
                if (reportReader.IsStartElement())
                {
                    string name = reportReader.Name;
                    string value = null;
                    if (reportReader.Read())
                        value = reportReader.Value.Trim();
                    switch (name)
                    {
                        case "ChargeDate":
                            report.chargeDate = Database.stringDateToDateTime(value);
                            break;
                        case "CreditCardHashCode":
                            int hashCode;
                            hashCode = Convert.ToInt32(value);
                            foreach (CreditCard c in Database.creditCardsList)
                                if (hashCode == c.hashCode)
                                {
                                    report.creditCard = c;
                                    break;
                                }
                            break;
                        case "TotalLocal":
                            report.total = Double.Parse(value);
                            break;
                        case "TotalPair":
                            DateTime date = new DateTime();
                            double total = 0;
                            if (reportReader.Read() && reportReader.Name.Equals("Date") && reportReader.Read())
                                date = Database.stringDateToDateTime(reportReader.Value.Trim());
                            if (reportReader.Read() && reportReader.Read() && reportReader.Read() && reportReader.Name.Equals("Total") && reportReader.Read())
                                total = Double.Parse(reportReader.Value.Trim());
                            report.totalInternational.Add(date, total);
                            break;
                        case "TransactionHashCode":
                            int hash;
                            hash = Convert.ToInt32(value);
                            foreach(KeyValuePair<DateTime,Month> pair in Database.months)
                                foreach (Transaction t in ((Month)pair.Value).getTransactions())
                                    if (hash == t.hashCode)
                                    {
                                        report.transactions.Add(t);
                                        break;
                                    }
                            break;
                    }
                }
            }

            return report;
        }