コード例 #1
0
        public IHttpActionResult PostDeliveryInvoice([FromBody] DeliveryInvoice input)
        {
            using (ctx = new YwtDbContext())
            {
                input.CreateTime = DateTime.Now;
                ctx.DeliveryInvoice.Add(input);
                var entity = ctx.DeliveryApply.FirstOrDefault(m => m.Id == input.ApplyId);
                entity.Status         = DeliveryApplyStatus.WaitReceived.ToString();
                entity.LastUpdateTime = DateTime.Now;

                ctx.SaveChanges();
                return(Ok(input));
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> GenerateInvoiceForAJob(string jobhrid)
        {
            var job = await repository.GetJobByHrid(jobhrid);

            string customerName;

            if (job.User.Type == Data.Model.Identity.IdentityTypes.USER)
            {
                customerName = (job.User.Profile as UserProfile)?.FullName;
            }
            else if (job.User.Type == Data.Model.Identity.IdentityTypes.ENTERPRISE)
            {
                customerName = (job.User.Profile as EnterpriseUserProfile)?.CompanyName;
            }
            else
            {
                customerName = (job.User.Profile as AssetProfile)?.FullName;
            }

            if (job.Order.Type == OrderTypes.Delivery)
            {
                DeliveryOrder order = job.Order as DeliveryOrder;

                if (order.OrderCart == null)
                {
                    logger.Debug("\'order.OrderCart\' is null");
                    logger.Error("Generating invoice with blank order cart is not supported");
                    throw new InvalidOperationException("Generating invoice with blank order cart is not supported");
                }

                IInvoiceService invoiceService = new InvoiceService();
                DeliveryInvoice invoice        = invoiceService.GenerateInvoice <ItemDetailsInvoiceRequest, DeliveryInvoice>(new ItemDetailsInvoiceRequest()
                {
                    CustomerName       = customerName,
                    DeliveryFrom       = order.From,
                    DeliveryTo         = order.To,
                    ItemDetails        = order.OrderCart.PackageList,
                    NetTotal           = order.OrderCart.PackageList.Sum(x => x.Total),
                    NotesToDeliveryMan = order.NoteToDeliveryMan,
                    PaymentStatus      = job.PaymentStatus,
                    ServiceCharge      = order.OrderCart.ServiceCharge,
                    SubTotal           = order.OrderCart.SubTotal,
                    TotalToPay         = order.OrderCart.TotalToPay,
                    TotalVATAmount     = order.OrderCart.TotalVATAmount,
                    TotalWeight        = order.OrderCart.TotalWeight,
                    VendorName         = "Anonymous"
                });

                invoice.InvoiceId = job.HRID;
                IPDFService <DeliveryInvoice> DeliveryInvoicePrinter = new DeliveryInvoicePDFGenerator();
                var invoiceStream = DeliveryInvoicePrinter.GeneratePDF(invoice);

                var reponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(invoiceStream.GetBuffer())
                };
                reponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = string.Concat(invoice.InvoiceId, ".pdf")
                };
                reponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                return(ResponseMessage(reponseMessage));
            }
            else
            {
                logger.Error("Invoice for job type {0} is still not implemented", job.Order.Type);
                throw new NotImplementedException($"Invoice for job type {job.Order.Type} is still not implemented");
            }
        }