internal CostEstimate GetCostEstimateFor(Carrier carrier, Invoice invoice, Dimensions dimensions, float[] parcelWeights)
        {
            int numParcels = parcelWeights.Length;
            CostEstimate estimate = new CostEstimate();

            double weightTotal = 0.0f, sizeTotal = 0.0f;

            string new_temp_city = invoice.InvoiceCustomer.City;
            int parcelNumber = 1;

            //int numSizeWeights = txtBox_input_dimensions.Text == "" ? 0 : txtBox_input_dimensions.Text.Split('/').Length;

            // Split the weights and do separate checks for each
            foreach (float weight in parcelWeights)
            {
                if (weight > MAXIMUM_WEIGHT)
                {
                    throw new PricingException($"Parcel weight is larger than {MAXIMUM_WEIGHT}KGs!");
                }

                Parcel p = new Parcel(weight, parcelNumber, 0.0d, numParcels);
                p.Size = dimensions;

                API.InvoicesAPI.AddParcelToInvoice(invoice, p);

                float sizeWeight = p.getSizeWeight() * carrier.DimensionWeightRate;

                weightTotal += GetCostEstimate(carrier, p, invoice);
                sizeTotal += sizeWeight == 0 ? 0.0f : GetCostEstimateByWeight(sizeWeight, carrier, p, invoice);

                parcelNumber++;
            }

            return estimate;
        }
        internal float GetCostEstimateByWeight(float weight, Carrier carrier, Parcel parcel, Invoice invoice)
        {
            float estimate = 0;
            int intPostcode = 0;
            int.TryParse(invoice.InvoiceCustomer.Postcode, out intPostcode);

            BlauModel _dbcontext = BlauModel.GetContext();
            DBCarrier _carrier = _dbcontext.Carrier.Where(x => x.carrierId == (int)carrier.CarrierId).FirstOrDefault();

            if (_carrier != default(DBCarrier))
            {
                /*PricingOption option = (from rate in _carrier.Rates
                                        where rate.Zones.Where(x => x.Postcode == invoice.InvoiceCustomer.Postcode).Count() > 0
                                            && rate.MinWeight < weight && rate.MaxWeight >= weight
                                        select new PricingOption(rate.Rate, rate.ExtraRate, rate.MinWeight, rate.MaxWeight, rate.SecondRate, rate.SecondRateExtra)
                                        ).FirstOrDefault();
                if (option != null)
                {
                    if (parcel.ParcelNumber == 1)
                        estimate = option.rate + option.extra_rate * weight;
                    else
                        estimate = option.second_parcel_rate + option.second_parcel_extra_rate * weight;
                }*/
            }
            return estimate;
        }
        public Carrier GetCarrierById(Enums.CarrierDatabaseKey carrierId)
        {
            Carrier carrier = new Carrier();
            carrier.CarrierId = carrierId;
            using (BlauModel _dbcontext = BlauModel.GetContext())
            {
                DBCarrier dbCarrier = BlauModel.GetContext().Carrier.Where(x => x.carrierId == (int)carrierId).FirstOrDefault();
                if (dbCarrier == default(DBCarrier))
                    throw new CarrierException(string.Format("Carrier id {0} could not be found in the data context", (int)carrierId));

                carrier.CarrierName = dbCarrier.CarrierName;
                carrier.DimensionWeightRate = dbCarrier.DimensionWeightRate;
            }
            return carrier;
        }
        public Invoice(DBInvoice invoice)
        {
            invoiceCustomer = API.CustomerAPI.GetCustomerDetailsByCustomerNumber(invoice.Customer.CustomerNumber);
            companyName = invoice.Company.CompanyName;
            companyABN = invoice.Company.CompanyABN;
            CompanyAddress = string.Format("{0} {1} {2} {3}",
                invoice.Company.CompanyAddress.Address1,
                invoice.Company.CompanyAddress.City,
                invoice.Company.CompanyAddress.State,
                invoice.Company.CompanyAddress.Postcode);
            provider = API.CarrierAPI.GetCarrierById((Enums.CarrierDatabaseKey)invoice.Carrier.carrierId);

            invoiceNo = invoice.InvoiceNumber;
            invoiceDate = invoice.TimeCreated;

            status = (Enums.InvoiceStatus)invoice.InvoiceStatus;
            packed = false;
        }
        public Carrier GetCarrierById(int carrierId)
        {
            connection.open();

            Carrier carrier = null;

            string query = string.Format("SELECT carrier_name, dimension_weight_rate FROM ps_carrier_info WHERE id={0};",
                carrierId);
            IDataReader dataReader = connection.getDataReader(query);
            if (dataReader.Read())
            {
                Enums.CarrierDatabaseKey key = (Enums.CarrierDatabaseKey)carrierId;
                carrier = new Carrier(key, dataReader["carrier_name"].ToString(),
                    float.Parse(dataReader["dimension_weight_rate"].ToString()), getCarrierTypeByDatabaseKey(key));
            }
            dataReader.Close();
            connection.close();

            return carrier;
        }
 private void setupProviders()
 {
     AustraliaPost = API.CarrierAPI.GetCarrierById(Enums.CarrierDatabaseKey.AUSTRALIA_POST);
     EPost = API.CarrierAPI.GetCarrierById(Enums.CarrierDatabaseKey.EPOST);
     Toll = API.CarrierAPI.GetCarrierById(Enums.CarrierDatabaseKey.TOLL);
     HunterExpress = API.CarrierAPI.GetCarrierById(Enums.CarrierDatabaseKey.HUNTER);
     Letter = API.CarrierAPI.GetCarrierById(Enums.CarrierDatabaseKey.LETTER);
 }
        public void loadInvoiceDetails()
        {
            if (!String.IsNullOrEmpty(invoiceNo))
            {
                using (BlauModel _dbcontext = BlauModel.GetContext())
                {
                    DBInvoice invoice = _dbcontext.Invoice.Where(x => x.InvoiceNumber == invoiceNo).FirstOrDefault();
                    if (invoice == default(DBInvoice))
                        throw new InvoiceException(string.Format("Invoice not found for invoiceNo: {0}", invoiceNo));

                    invoiceCustomer = new Customer(invoice.Customer);
                    companyName = invoice.Company.CompanyName;
                    companyABN = invoice.Company.CompanyABN;
                    CompanyAddress = string.Format("{0} {1} {2} {3}",
                        invoice.Company.CompanyAddress.Address1,
                        invoice.Company.CompanyAddress.City,
                        invoice.Company.CompanyAddress.State,
                        invoice.Company.CompanyAddress.Postcode);
                    provider = API.CarrierAPI.GetCarrierById((Enums.CarrierDatabaseKey)invoice.Carrier.carrierId);

                    invoiceNo = invoice.InvoiceNumber;
                    invoiceDate = invoice.TimeCreated;

                    status = (Enums.InvoiceStatus)invoice.InvoiceStatus;
                    packed = false;
                }
            }
        }
 internal float GetCostEstimate(Carrier carrier, Parcel parcel, Invoice invoice)
 {
     return GetCostEstimateByWeight(parcel.Weight, carrier, parcel, invoice);
 }
 public static CostEstimate GetCostEstimateFor(Carrier carrier, Invoice invoice, Dimensions dimensions, float[] parcelWeights)
 {
     return Actions.GetCostEstimateFor(carrier, invoice, dimensions, parcelWeights);
 }
 public static float GetCostEstimateByWeight(float weight, Carrier carrier, Parcel parcel, Invoice invoice)
 {
     return Actions.GetCostEstimateByWeight(weight, carrier, parcel, invoice);
 }
 public static float GetCostEstimate(Carrier carrier, Parcel parcel, Invoice invoice)
 {
     return Actions.GetCostEstimate(carrier, parcel, invoice);
 }