Exemplo n.º 1
0
        private InvoiceWrapper ToInvoiceWrapper(Invoice invoice)
        {
            var result = new InvoiceWrapper(invoice);

            if (invoice.ContactID > 0)
            {
                result.Contact = ToContactBaseWithEmailWrapper(DaoFactory.GetContactDao().GetByID(invoice.ContactID));
            }

            if (invoice.ConsigneeID > 0)
            {
                result.Consignee = ToContactBaseWithEmailWrapper(DaoFactory.GetContactDao().GetByID(invoice.ConsigneeID));
            }

            if (invoice.EntityID > 0)
            {
                result.Entity = ToEntityWrapper(invoice.EntityType, invoice.EntityID);
            }

            result.Cost = invoice.GetInvoiceCost();

            result.InvoiceLines = invoice.GetInvoiceLines().Select(ToInvoiceLineWrapper).ToList();

            return(result);
        }
Exemplo n.º 2
0
        public InvoiceWrapper GetInvoiceSample()
        {
            var sample = InvoiceWrapper.GetSample();

            sample.Number = DaoFactory.GetInvoiceDao().GetNewInvoicesNumber();
            sample.Terms  = DaoFactory.GetInvoiceDao().GetSettings().Terms ?? string.Empty;

            return(sample);
        }
 public bool CloseInvoice(InvoiceWrapper invoice)
 {
     if (open_invoices.ContainsValue(invoice))
     {
         var key = open_invoices.FirstOrDefault(x => x.Value == invoice).Key;
         open_invoices.Remove(key);
         event_aggregator.GetEvent <OpenInvoiceServiceEvent>().Publish(open_invoices.Count);
         return(true);
     }
     return(false);
 }
 public bool OpenInvoice(InvoiceWrapper invoice)
 {
     if (!open_invoices.ContainsValue(invoice))
     {
         string new_key = GenInvoiceKey();
         invoice.InvoiceNumber = new_key;
         open_invoices.Add(new_key, invoice);
         event_aggregator.GetEvent <OpenInvoiceServiceEvent>().Publish(open_invoices.Count);
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates / Edits an invoice property.
        /// </summary>
        /// <param name="value">The invoice property.</param>
        /// <param name="token">The token.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// The task result contains the new invoice property.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown when the parameter check fails.</exception>
        /// <exception cref="NotAuthorizedException">Thrown when not authorized to access this resource.</exception>
        /// <exception cref="NotFoundException">Thrown when the resource url could not be found.</exception>
        public async Task <Invoice> EditAsync(Invoice value, CancellationToken token = default)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value.ClientId == 0)
            {
                throw new ArgumentException("invalid client id", nameof(value));
            }

            if (value.Quote <= 0f)
            {
                throw new ArgumentException("invalid quote", nameof(value));
            }

            if (value.Date == DateTime.MinValue)
            {
                throw new ArgumentException("invalid date", nameof(value));
            }

            if (value.Id <= 0)
            {
                throw new ArgumentException("invalid invoice id", nameof(value));
            }

            var wrappedModel = new InvoiceWrapper
            {
                Invoice = value.ToApi()
            };

            try
            {
                var jsonModel = await PutAsync($"/api/{EntityUrlFragment}/{value.Id}", wrappedModel, token).ConfigureAwait(false);

                return(jsonModel.ToDomain());
            }
            catch (WebException wex)
                when(wex.Status == WebExceptionStatus.ProtocolError && (wex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new ArgumentException("wrong input parameter", nameof(value), wex);
                }
        }
Exemplo n.º 6
0
        private async void GetCompanyOpenInvoices()
        {
            HeaderMessage = "Open Invoices (Loading...)";
            //ExecuteFaultHandledOperation(() =>
            //{
            var proxy   = service_factory.CreateClient <IInvoiceService>();
            var company = new Company()
            {
                CompanyKey = CurrentCompanyKey
            };
            var open_order_col = new ObservableCollection <InvoiceWrapper>();

            using (proxy)
            {
                var   orders = proxy.GetInvoicesByCompanyAsync(company);
                await orders;

                if (orders.Result.Count > 0)
                {
                    foreach (var order in orders.Result)
                    {
                        var order_wrapper = new InvoiceWrapper(order);
                        open_order_col.Add(order_wrapper);
                    }
                    OpenInvoices         = open_order_col;
                    SelectedInvoice      = OpenInvoices[0];
                    SelectedInvoiceIndex = 0;
                    HeaderMessage        = "Open Invoices (" + OpenInvoices.Count.ToString() + ")";
                }
                else
                {
                    OpenInvoices  = new ObservableCollection <InvoiceWrapper>();
                    HeaderMessage = "Open Invoices (0)";
                }
            }
            //});
            //SetEventDatesContext();
        }
        private void InitNewInvoice()
        {
            Invoice new_order = new Invoice() //*** GET this initializatoin stuff into the objects themselves!! (complete)
            {
                InvoiceEntryDate  = DateTime.Now,
                InvoiceStatusDate = DateTime.Now,
                OrderEntryDate    = DateTime.Now,
                //DeliverByDate = DateTime.Now.AddDays(7), // think about a due date instead
                SalesRep   = SalesRepList[0],
                AccountRep = AccountRepList[0]
            };

            new_order.InvoiceItems.Add(InitNewInvoiceItem(1));
            SelectedInvoiceItemIndex = 0;

            Invoice = new InvoiceWrapper(new_order);
            DefaultBillingAddress    = new AddressWrapper(new Address());
            DefaultShippingAddress   = new AddressWrapper(new Address());
            Invoice.PropertyChanged += Context_PropertyChanged;
            Invoice.AcceptChanges();
            _workingInvoiceService.OpenInvoice(Invoice);
            GridIsEnabled = false;
        }
        private void GetInvoice(int invoiceKey)
        {
            ExecuteFaultHandledOperation(() =>
            {
                var invoiceService = _serviceFactory.CreateClient <IInvoiceService>();
                using (invoiceService)
                {
                    Invoice         = new InvoiceWrapper(invoiceService.GetInvoice(invoiceKey));
                    AccountContacts = new ObservableCollection <AccountPerson>(Invoice.Account.Model.Employees.Where(item =>
                                                                                                                     item.CompanyRoleType == QIQOPersonType.AccountContact).ToList());
                    Invoice.PropertyChanged += Context_PropertyChanged;
                    Invoice.AcceptChanges();
                    _currentAccount = Invoice.Account.Model;
                }

                DefaultBillingAddress  = Invoice.InvoiceItems[0].OrderItemBillToAddress;
                DefaultShippingAddress = Invoice.InvoiceItems[0].OrderItemShipToAddress;
                ViewTitle     = Invoice.InvoiceNumber;
                GridIsEnabled = Invoice.InvoiceStatus != QIQOInvoiceStatus.Complete ? true : false;
                _eventAggregator.GetEvent <GeneralMessageEvent>().Publish($"Invoice {Invoice.InvoiceNumber} loaded successfully");
                _eventAggregator.GetEvent <InvoiceLoadedEvent>().Publish(Invoice.InvoiceNumber);
                _eventAggregator.GetEvent <NavigationEvent>().Publish(ViewNames.InvoiceHomeView);
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an invoice.
        /// </summary>
        /// <param name="value">The invoice object.</param>
        /// <param name="token">The cancellation token.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// The task result returns the newly created invoice with the ID.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown when the parameter check fails.</exception>
        /// <exception cref="NotAuthorizedException">Thrown when not authorized to access this resource.</exception>
        /// <exception cref="NotFoundException">Thrown when the resource url could not be found.</exception>
        public async Task <Invoice> CreateAsync(Invoice value, CancellationToken token = default)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value.ClientId == 0)
            {
                throw new ArgumentException("invalid client id", nameof(value));
            }

            if (value.Quote <= 0f)
            {
                throw new ArgumentException("invalid quote", nameof(value));
            }

            if (value.Date == DateTime.MinValue)
            {
                throw new ArgumentException("invalid date", nameof(value));
            }

            if (value.Id != 0)
            {
                throw new ArgumentException("invalid invoice id", nameof(value));
            }

            var wrappedModel = new InvoiceWrapper
            {
                Invoice = value.ToApi()
            };

            var result = await PostAsync($"/api/{EntityUrlFragment}", wrappedModel, token);

            return(result.ToDomain());
        }
 internal static Invoice ToDomain(this InvoiceWrapper value)
 {
     return(s_invoiceMapper.ApiToDomain(value));
 }
        private void GenerateInvoiceFromOrderItems(List <Order> orders)
        {
            // We don't have everything about the order that we need, so we have to go and get them
            var ordersToInvoice = new List <Order>(orders.Count);
            var orderService    = _serviceFactory.CreateClient <IOrderService>();
            var invoiceService  = _serviceFactory.CreateClient <IInvoiceService>();

            foreach (var order in orders)
            {
                ordersToInvoice.Add(orderService.GetOrder(order.OrderKey));
            }

            // Now that we have the full order(s), we can create an invoice from the data in them
            var newInvoice = new Invoice()
            {
                AccountKey        = ordersToInvoice[0].AccountKey,
                OrderEntryDate    = ordersToInvoice[0].OrderEntryDate,
                OrderShipDate     = ordersToInvoice[0].OrderShipDate,
                AccountContactKey = ordersToInvoice[0].AccountContactKey,
                FromEntityKey     = ordersToInvoice[0].OrderKey,
                InvoiceEntryDate  = DateTime.Now,
                InvoiceStatus     = QIQOInvoiceStatus.New,
                InvoiceStatusDate = DateTime.Now,
                AccountRepKey     = ordersToInvoice[0].AccountRepKey,
                SalesRepKey       = ordersToInvoice[0].SalesRepKey
                                    //SalesRep = orders_to_invoice[0].SalesRep
            };

            newInvoice.Account.AccountCode          = ordersToInvoice[0].Account.AccountCode;
            newInvoice.Account.AccountName          = ordersToInvoice[0].Account.AccountName;
            newInvoice.SalesRep.PersonFullNameFML   = ordersToInvoice[0].SalesRep.PersonFullNameFML;
            newInvoice.SalesRep.EntityPersonKey     = ordersToInvoice[0].SalesRep.EntityPersonKey;
            newInvoice.AccountRep.PersonFullNameFML = ordersToInvoice[0].AccountRep.PersonFullNameFML;
            newInvoice.AccountRep.EntityPersonKey   = ordersToInvoice[0].AccountRep.EntityPersonKey;
            DefaultBillingAddress  = new AddressWrapper(ordersToInvoice[0].Account.Addresses.Where(addr => addr.AddressType == QIQOAddressType.Billing).FirstOrDefault());
            DefaultShippingAddress = new AddressWrapper(ordersToInvoice[0].Account.Addresses.Where(addr => addr.AddressType == QIQOAddressType.Shipping).FirstOrDefault());

            foreach (var ord in ordersToInvoice)
            {
                var items_to_invoice = ord.OrderItems.Where(item => (item.OrderItemStatus != QIQOOrderItemStatus.Canceled &&
                                                                     item.OrderItemStatus != QIQOOrderItemStatus.Complete)).ToList();
                foreach (var item in ord.OrderItems)
                {
                    var inv_item = invoiceService.GetInvoiceItemByOrderItemKey(item.OrderItemKey);

                    if (inv_item == null)
                    {
                        var newInvoiceItem = new InvoiceItem()
                        {
                            AccountRep          = item.AccountRep,
                            SalesRep            = item.SalesRep,
                            FromEntityKey       = item.OrderItemKey,
                            InvoiceItemLineSum  = item.OrderItemLineSum,
                            InvoiceItemProduct  = item.OrderItemProduct,
                            InvoiceItemQuantity = item.OrderItemQuantity,
                            InvoiceItemSeq      = item.OrderItemSeq,
                            InvoiceItemStatus   = QIQOInvoiceItemStatus.New,
                            ItemPricePer        = item.ItemPricePer,
                            ProductDesc         = item.ProductDesc,
                            ProductKey          = item.ProductKey,
                            ProductName         = item.ProductName,
                            OrderItemShipDate   = item.OrderItemShipDate
                        };
                        newInvoiceItem.SalesRep.EntityPersonKey = item.SalesRep.EntityPersonKey;
                        //new_invoice_item.OrderItemBillToAddress.AddressKey = item.OrderItemBillToAddress.AddressKey;
                        //new_invoice_item.OrderItemShipToAddress.AddressKey = item.OrderItemShipToAddress.AddressKey;
                        newInvoiceItem.InvoiceItemProduct.ProductKey  = item.OrderItemProduct.ProductKey;
                        newInvoiceItem.InvoiceItemProduct.ProductCode = item.OrderItemProduct.ProductCode;
                        newInvoiceItem.InvoiceItemProduct.ProductDesc = item.OrderItemProduct.ProductDesc;
                        newInvoiceItem.InvoiceItemProduct.ProductName = item.OrderItemProduct.ProductName;
                        newInvoiceItem.InvoiceItemProduct.ProductType = item.OrderItemProduct.ProductType;

                        //order_item.InvoiceItemBillToAddress = DefaultBillingAddress;
                        //FillFromDefaultAddress(new_invoice_item, QIQOAddressType.Billing);
                        newInvoiceItem.OrderItemBillToAddress.AddressKey        = DefaultBillingAddress.AddressKey;
                        newInvoiceItem.OrderItemBillToAddress.AddressType       = QIQOAddressType.Billing;
                        newInvoiceItem.OrderItemBillToAddress.AddressLine1      = DefaultBillingAddress.AddressLine1;
                        newInvoiceItem.OrderItemBillToAddress.AddressLine2      = DefaultBillingAddress.AddressLine2;
                        newInvoiceItem.OrderItemBillToAddress.AddressCity       = DefaultBillingAddress.AddressCity;
                        newInvoiceItem.OrderItemBillToAddress.AddressState      = DefaultBillingAddress.AddressState;
                        newInvoiceItem.OrderItemBillToAddress.AddressPostalCode = DefaultBillingAddress.AddressPostalCode;

                        //order_item.InvoiceItemShipToAddress = DefaultShippingAddress;
                        //FillFromDefaultAddress(new_invoice_item, QIQOAddressType.Shipping);
                        newInvoiceItem.OrderItemShipToAddress.AddressKey        = DefaultShippingAddress.AddressKey;
                        newInvoiceItem.OrderItemShipToAddress.AddressType       = QIQOAddressType.Shipping;
                        newInvoiceItem.OrderItemShipToAddress.AddressLine1      = DefaultShippingAddress.AddressLine1;
                        newInvoiceItem.OrderItemShipToAddress.AddressLine2      = DefaultShippingAddress.AddressLine2;
                        newInvoiceItem.OrderItemShipToAddress.AddressCity       = DefaultShippingAddress.AddressCity;
                        newInvoiceItem.OrderItemShipToAddress.AddressState      = DefaultShippingAddress.AddressState;
                        newInvoiceItem.OrderItemShipToAddress.AddressPostalCode = DefaultShippingAddress.AddressPostalCode;

                        newInvoiceItem.AccountRep.EntityPersonKey = _accountReps[0].EntityPersonKey;
                        newInvoiceItem.SalesRep.EntityPersonKey   = _salesReps[0].EntityPersonKey;
                        //new_invoice_item.InvoiceItemSeq = SelectedInvoiceItemIndex + 1;

                        newInvoice.InvoiceItems.Add(newInvoiceItem);
                    }
                }
            }

            Invoice = new InvoiceWrapper(newInvoice);
            GetAccount(newInvoice.Account.AccountCode);
            UpdateItemTotals();
            InvalidateCommands();
        }
Exemplo n.º 12
0
 public Invoice ApiToDomain(InvoiceWrapper value)
 {
     return(ApiToDomain(value?.Invoice));
 }
 internal static Invoice ToDomain(this InvoiceWrapper value)
 {
     return(value?.Invoice.ToDomain());
 }