示例#1
0
        /// <summary>
        /// As soon as the customer hits the buy product button
        /// and pays the item or chooses to pay later the
        /// invoice is created.
        /// Returns the InvoiceID
        /// </summary>
        /// <param name="email"></param>
        /// <param name="shippingID"></param>
        /// <param name="products"></param>
        /// <returns>Int InvoiceID</returns>
        public int CreateInvoice(string email, int shippingID, List <ProductSelectionDTO> products, decimal shippingCost, decimal totalAmount, decimal taxValue, decimal finalCost)
        {
            AccountDTO   customer      = new AccountDTO();
            ShippmentDTO deliverer     = new ShippmentDTO();
            int          result        = 0;
            int          paymentStatus = 0;

            try
            {
                customer = AB.FindBy(email);
                if (customer != null)
                {
                    deliverer = SB.FindBy(shippingID);
                    if (deliverer != null)
                    {
                        //set current time when Invoice is created
                        DateTime orderDate   = DateTime.Now;
                        DateTime paymentDate = DateTime.Now;
                        DateTime arrivalDate = DateTime.Now.AddDays(deliverer.GetDeliveryTime());
                        DateTime postageDate = DateTime.Now;

                        int totalQuantity = CalculateQuantity(products);

                        //calculate all other values for the invoice

                        /*int totalWeight = CalculateWeight(products);
                         * decimal totalShippingCost = deliverer.GetCost() + (decimal)0.1 * totalWeight;
                         * decimal totalShippingCost = ;
                         * decimal totalProductCost = CalculateProductCost(products);
                         * decimal totalTaxes = CalculateTax(totalProductCost);
                         * decimal totalAmount = totalTaxes + totalProductCost + totalShippingCost;*/

                        //UpdateProductInfo(products);

                        //insert into DB
                        result = DB.Insert(customer.GetID(), deliverer.GetID(), totalQuantity, shippingCost, finalCost, taxValue,
                                           totalAmount, orderDate.ToString(), paymentDate.ToString(), arrivalDate.ToString(), postageDate.ToString(), paymentStatus, email);
                    }
                    else
                    {
                        throw new EmptyRowException($"The entry for {shippingID} was not found.");
                    }
                }
                else
                {
                    throw new EmptyRowException($"The entry for {email} was not found.");
                }
            }
            catch (Exception e)
            {
                e.GetBaseException();
                Debug.Write(e.ToString());
            }
            return(result);
        }
示例#2
0
 public InvoiceDTO(byte id, AccountDTO customer, List <ProductSelectionDTO> products, ShippmentDTO shipping, byte totalQuantity, decimal totalShippingCost,
                   decimal totalTaxes, decimal totalAmount, DateTime orderDate, DateTime paymentDate, string email)
 {
     this.id                = id;
     this.customer          = customer;
     this.products          = products;
     shippingCompany        = shipping;
     this.totalQuantity     = totalQuantity;
     this.totalShippingCost = totalShippingCost;
     this.totalTaxes        = totalTaxes;
     this.totalAmount       = totalAmount;
     this.orderDate         = orderDate;
     this.paymentDate       = paymentDate;
     this.email             = email;
 }
示例#3
0
 public void SetShippment(ShippmentDTO shipping)
 {
     this.shippingCompany = shipping;
 }
示例#4
0
 public InvoiceDTO(byte id, AccountDTO customer, List <ProductSelectionDTO> products, ShippmentDTO shipping, byte totalQuantity, decimal totalShippingCost, decimal totalTaxes,
                   decimal totalAmount, DateTime orderDate, DateTime paymentDate, string email, int status) : this(id, customer, products, shipping, totalQuantity, totalShippingCost, totalTaxes, totalAmount, orderDate, paymentDate, email)
 {
     paymentStatus = status;
 }