public IHttpActionResult Post(AddInvoiceModel model)
        {
            var    order    = ordersManager.GetById(model.orderId);
            double taxValue = CalculationHelper.CalculateTaxes(taxesManager);

            var invoice = new ProfiCraftsman.Contracts.Entities.Invoices()
            {
                Orders           = order,
                TaxValue         = taxValue,
                WithTaxes        = order.Customers.WithTaxes,
                Discount         = order.Discount ?? 0,
                CreateDate       = DateTime.Now,
                ChangeDate       = DateTime.Now,
                IsSellInvoice    = model.isSell,
                PayInDays        = 10,
                InvoicePositions = new List <InvoicePositions>()
            };



            if (AddInvoicePositions(order, invoice))
            {
                invoice.InvoiceNumber = numberProvider.GetNextInvoiceNumber();

                invoicesManager.AddEntity(invoice);
                invoicesManager.SaveChanges();
            }

            model.Id = invoice.Id;
            return(Ok(model));
        }
Exemple #2
0
        public IHttpActionResult Put(OrdersModel model)
        {
            var order = manager.GetById(model.Id);

            order.Status = (int)OrderStatusTypes.Closed;
            manager.SaveChanges();

            return(Ok(new { id = model.Id }));
        }
        public IHttpActionResult Put(DeleteAllPositionModel model)
        {
            var order = manager.GetById(model.id);

            foreach (var position in order.Positions.Where(o => (!model.parentId.HasValue || (o.ParentId.HasValue && o.ParentId == model.parentId.Value)) &&
                                                           o.IsMaterialPosition == model.isMaterialPosition && !o.DeleteDate.HasValue).ToList())
            {
                positionManager.RemoveEntity(position);
            }

            positionManager.SaveChanges();

            return(Ok(new { Result = "Ok" }));
        }
Exemple #4
0
        public IHttpActionResult Put(OrdersModel model)
        {
            var order = manager.GetById(model.Id);

            var newOrder = new Orders()
            {
                AutoBill = order.AutoBill,
                City     = order.City,
                Comment  = order.Comment,
                CommunicationPartnerId = order.CommunicationPartnerId,
                CustomerId             = order.CustomerId,
                Discount    = order.Discount,
                Street      = order.Street,
                Status      = (int)OrderStatusTypes.Open,
                Zip         = order.Zip,
                IsOffer     = false,
                OrderNumber = numberProvider.GetNextOrderNumber(),
                Positions   = new List <Positions>(),
                CreateDate  = DateTime.Now,
                ChangeDate  = DateTime.Now,
            };

            manager.AddEntity(newOrder);

            foreach (var position in order.Positions.Where(o => o.MaterialId.HasValue && !o.DeleteDate.HasValue).ToList())
            {
                var newPosition = new Positions()
                {
                    MaterialId         = position.MaterialId.Value,
                    IsAlternative      = position.IsAlternative,
                    IsMaterialPosition = position.IsMaterialPosition,
                    Amount             = position.Amount,
                    Price       = position.Price,
                    PaymentType = position.PaymentType,
                    Orders      = newOrder
                };

                positionManager.AddEntity(newPosition);
                newOrder.Positions.Add(newPosition);
            }

            manager.SaveChanges();

            return(Ok(new { id = newOrder.Id }));
        }
        public IHttpActionResult Put(OrdersModel model)
        {
            var order = manager.GetById(model.Id);

            order.IsOffer = false;

            if (String.IsNullOrEmpty(order.OrderNumber))
            {
                order.OrderNumber = numberProvider.GetNextOrderNumber();
            }

            if (order.Customers.IsProspectiveCustomer)
            {
                order.Customers.IsProspectiveCustomer = false;
                var lastCustomerNumber = customerManager.GetEntities().Max(o => o.Number);
                order.Customers.Number = lastCustomerNumber + 1;
            }

            manager.SaveChanges();

            return(Ok(new { id = model.Id }));
        }
Exemple #6
0
        private string ReplaceFields(IOrdersManager ordersManager, int id, PrintTypes printType, string xmlMainXMLDoc,
            IInvoicesManager invoicesManager, ITaxesManager taxesManager, Invoices invoice = null,
            IInvoiceStornosManager invoiceStornosManager = null,
            ITransportOrdersManager transportOrdersManager = null,
            ITermsManager termsManager = null, 
            IEnumerable<Image> images = null)
        {
            string result = xmlMainXMLDoc;

            switch (printType)
            {
                case PrintTypes.Order:
                    var order = ordersManager.GetById(id);
                    result = ReplaceCommonFields(order, result);
                    result = ReplaceBaseOrderFields(order, result);

                    result = result.Replace("#SignatureDate", order.CreateDate.AddDays(2).ToShortDateString());

                    result = ReplaceRentPositions(order, result, taxesManager);
                    result = ReplaceTotalPrice(order, result, taxesManager);
                    result = ReplaceRentAdditionalCostPositions(order, result);
                    break;
                case PrintTypes.Offer:
                    order = ordersManager.GetById(id);
                    result = ReplaceCommonFields(order, result);
                    result = ReplaceBaseOfferFields(order, result);
                    result = ReplaceBaseOrderFields(order, result);
                    result = ReplaceRentPositions(order, result, taxesManager);
                    result = ReplaceRentAdditionalCostPositions(order, result);
                    break;
                case PrintTypes.Invoice:

                    if (invoice == null)
                    {
                        invoice = invoicesManager.GetById(id);
                    }

                    order = invoice.Orders;

                    result = ReplaceCommonFields(order, result);
                    result = ReplaceBaseOrderFields(order, result);
                    result = ReplaceBaseInvoiceFields(invoice, result, printType);

                    bool manualPricePrinted = false;
                    result = ReplaceInvoicePositions(invoice, invoice.InvoicePositions.ToList(), result,
                        "#PositionDescription", "#PositionPrice", "Leistungen: ", ref manualPricePrinted);

                    result = ReplaceInvoicePrices(invoice, result);
                    break;
                case PrintTypes.InvoiceStorno:

                    var invoiceStorno = invoiceStornosManager.GetById(id);
                    invoice = invoiceStorno.Invoices;
                    order = invoice.Orders;

                    result = ReplaceCommonFields(order, result);
                    result = ReplaceBaseOrderFields(order, result);
                    result = ReplaceBaseInvoiceFields(invoice, result, printType);
                    result = ReplaceInvoiceStornoPrices(invoiceStorno, result);

                    result = ReplaceFieldValue(result, "#FreeText", invoiceStorno.FreeText);

                    break;
                case PrintTypes.ReminderMail:

                    invoice = invoicesManager.GetById(id);
                    order = invoice.Orders;

                    result = ReplaceCommonFields(order, result);
                    result = ReplaceReminderPositions(invoice.InvoicePositions.ToList(), result);
                    result = ReplaceReminderTotalPrice(invoice, result, taxesManager);

                    break;
                case PrintTypes.DeliveryNote:

                    var term = termsManager.GetById(id);
                    result = ReplaceCommonFields(term.Orders, result);
                    result = ReplaceBaseOrderFields(term.Orders, result);

                    result = result.Replace("#DeliveryNoteType", "Lieferschein");
                    result = result.Replace("#DateType", "Liefertermin");
                    result = result.Replace("#AdressType", "Lieferanschrift");
                    result = result.Replace("#OrderNumber", term.Orders.OrderNumber);
                    
                    result = ReplacePositionWithDescription(term, result);


                    if (term.DeliveryNoteSignatures.Count != 0)
                    {
                        var doc = XDocument.Parse(result);
                        var signatureElement = doc.Descendants().FirstOrDefault(o => o.Value.Equals("#Signature",
                            StringComparison.InvariantCultureIgnoreCase));

                        if (signatureElement != null && images != null && images.Count() != 0)
                        {
                            var currentElement = signatureElement;
                            for (var i = 0; i < images.Count(); i++)
                            {
                                var image = images.ElementAt(images.Count() - i - 1);
                                //TODO doesnt work ((
                                //pkg.CreateRelationship(uri, TargetMode.Internal,
                                //    "Http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
                                //    "barcodeImageId");
                                
                                //insert image
                                XmlElement tagDrawing = GetImageTag(image.Width, image.Height,
                                    term.DeliveryNoteSignatures.Count - i);

                                signatureElement.AddAfterSelf(XDocument.Parse(tagDrawing.InnerXml).Root);
                            }

                            signatureElement.Remove();
                            result = doc.Root.ToString();
                        }
                        else
                        {
                            result = result.Replace("#Signature", String.Empty);
                        }
                    }
                    else
                    {
                        result = result.Replace("#Signature", String.Empty);
                    }

                    break;
                default:
                    throw new NotImplementedException();
            }

            return result;
        }