public IActionResult OnGet(int?id)
        {
            var t = Request.Cookies["logon"];

            if (t == null)
            {
                return(RedirectToPage("../Accounts/Login"));
            }
            if (t == "false")
            {
                return(RedirectToPage("../Accounts/Login"));
            }

            if (id == null)
            {
                return(NotFound());
            }

            Receipt = _service.GetReceipt(id ?? default(int));

            if (Receipt == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 2
0
        public void HandleCurrentUserSum_ValidFields_ShouldReturnCorrectNumber()
        {
            var dto = new ReceiptDto
            {
                CurrentUserId = "detmig",
                Items         = new List <ReceiptItemDto>
                {
                    new ReceiptItemDto
                    {
                        Count = 100,
                        Price = 100,
                        Users = new List <UserDto>
                        {
                            new UserDto
                            {
                                Id = "detmig"
                            },
                            new UserDto
                            {
                                Id = "nah"
                            }
                        }
                    }
                }
            };

            dto.Items.Should().NotBeNull();
            dto.CurrentUserOwed.Should().Be(dto.Total / dto.Items.First().Users.Count);
        }
        public static string SignReceipts(ReceiptDto receiptDto, string privateKey)
        {
            var resultHash = Sha3ForReceipts(receiptDto);
            var ms         = new MessageSigner();
            var signature  = ms.Sign(resultHash.HexToByteArray(), privateKey);

            return(signature);
        }
Ejemplo n.º 4
0
        public async Task <Receipt> UpdateAsync(Receipt receipt)
        {
            using var uow = new UnitOfWork(_databaseContextProvider.Create());
            ReceiptDto newReceipt = await uow.Receipts.UpdateAsync(receipt.ToData());

            await uow.SaveChangesAsync();

            return(newReceipt.ToCore());
        }
        public SignatureResponse Receipts([FromBody] ReceiptDto receipt)
        {
            var signature = EthereumUtils.SignReceipts(receipt, _config.PrivateKey);

            return(new SignatureResponse
            {
                SenderSignature = signature
            });
        }
Ejemplo n.º 6
0
        public void CreateReceipt(ReceiptDto receipt)
        {
            var newReceipt = Mapper.Map <Receipt>(receipt);

            newReceipt.ReceiptPriceTableQueries = MergeDuplicateInstances(newReceipt);

            _context.Receipts.Add(newReceipt);
            _context.SaveChanges();
        }
Ejemplo n.º 7
0
        public void HandleDaysDaysSinceLastVisit_ValidDate_ShouldReturnCorrectNumberOfDays()
        {
            var dto = new ReceiptDto
            {
                DateVisited = DateTime.Now.AddDays(-5)
            };

            dto.DateVisited.Should().BeCloseTo(dto.DateVisited, 10000);

            dto.DaysSinceLastVisit.Should().Be(5);
        }
Ejemplo n.º 8
0
            public Receipt Convert(ReceiptDto dto, CashboxDto cbDto, List <ItemDto> itemsDto)
            {
                var cashbox = Convert(cbDto);
                var items   = Convert(itemsDto, dto.UID);

                var result = Receipt.CreateNew(dto.UID, dto.StatusCode, dto.StatusName, dto.StatusMessage, dto.Modified,
                                               dto.ReceiptDate, dto.InvoiceId, cashbox, dto.Inn, dto.Type, dto.TaxSystem, dto.Email, dto.Phone,
                                               dto.Iplace, dto.Iaddress, dto.Dnumber, items);

                return(result);
            }
Ejemplo n.º 9
0
        public async Task <ResponseViewModel <object> > UploadingReceipt([FromBody] RequestViewModel obj)
        {
            ResponseViewModel <object> response = null;

            obj = JsonHelper.DeserializeJsonToObject <RequestViewModel>(Content(User.Identity.Name).Content);
            var  sysCode = SysCode.Ok;
            bool isLog   = _token.VerifyToken(obj.HendInfo.UserOpenId, obj.HendInfo.SessionToken);

            if (isLog)
            {
                string     strJson = RedisHelper.StringGet($"{CacheKey.Token}{obj.HendInfo.UserOpenId}", RedisFolderEnum.token, RedisEnum.Three);
                var        userLog = JsonHelper.DeserializeJsonToObject <UserLoginDto>(strJson);
                ReceiptDto receipt = new ReceiptDto
                {
                    AppleId = (string)obj.Data.appleId,
                    Id      = (string)obj.Data.productId,
                    OrderId = (string)obj.Data.orderId,
                    Receipt = (string)obj.Data.receipt
                };
                AppleReceiptDto appleReceipt = new AppleReceiptDto()
                {
                    Updatetime = DateTime.Now,
                    Receipt    = receipt.Receipt,
                    Order_id   = receipt.OrderId,
                };
                if (_recharge.VerifyReceipt(receipt))
                {
                    //获取商品信息
                    RechargeCommodityDto rechargeCommodity = await _recharge.GetAppleProductAsync(receipt.AppleId);

                    //充值虚拟币
                    double amount = double.Parse(rechargeCommodity.Amount.ToString());

                    //关闭章鱼充值
                    //if (_accout.Recharge_php(userLog.Userid, receipt.OrderId, amount, "充值", "hiAlipay"))
                    //从php充值
                    if (_accout.Recharge_php(userLog.Userid, receipt.OrderId, amount, "充值", "yibiyibaidekey"))
                    {
                        //更新苹果订单
                        await _recharge.UpdateAppleOrderAsync(appleReceipt);

                        //更新充值记录
                        await _recharge.UpdateRechargeLogAsync("2", receipt.OrderId);
                    }
                }
            }
            else
            {
                /*短令牌失效*/
                sysCode = SysCode.SessionTokenLose;
            }
            response = new ResponseViewModel <object>(sysCode, null, obj.Encrypt, _sys, obj.Secret);
            return(response);
        }
Ejemplo n.º 10
0
        public void HandleTotal_ItemsIsEmpty_ShouldReturnZero()
        {
            var dto = new ReceiptDto
            {
                Items = new List <ReceiptItemDto>()
            };

            dto.Items.Should().NotBeNull();
            dto.Items.Count.Should().Be(0);
            dto.Total.Should().Be(0);
        }
Ejemplo n.º 11
0
 public async Task <IActionResult> Add(ReceiptDto receipt)
 {
     if (receipt != null)
     {
         return(Ok(await receiptService.AddNewReceipt(receipt)));
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 12
0
        public void HandleDaysDaysSinceDeleted_ValidDate_ShouldReturnCorrectNumberOfDays()
        {
            var dto = new ReceiptDto
            {
                Deleted = DateTime.Now.AddDays(-5)
            };

            dto.Deleted.Should().BeCloseTo(dto.Deleted.GetValueOrDefault(), 10000);

            dto.DaysSinceDeleted.Should().Be(5);
        }
Ejemplo n.º 13
0
 public static BusinessLayer.ProductOrder FromDto(ReceiptDto receipt)
 {
     return new BusinessLayer.ProductOrder
                {
                    Id_order = receipt.IdOrder,
                    Id_product = receipt.IdProduct,
                    Price = receipt.Price,
                    Quantity = receipt.Qty,
                    Discount = receipt.Discount,
                    Comment = receipt.Comment
                };
 }
Ejemplo n.º 14
0
 public static BusinessLayer.ProductOrder FromDto(ReceiptDto receipt)
 {
     return(new BusinessLayer.ProductOrder
     {
         Id_order = receipt.IdOrder,
         Id_product = receipt.IdProduct,
         Price = receipt.Price,
         Quantity = receipt.Qty,
         Discount = receipt.Discount,
         Comment = receipt.Comment
     });
 }
Ejemplo n.º 15
0
            public ReceiptDto ReceiptDtoFromJson(CreateReceipt cmd)
            {
                var dto = new ReceiptDto()
                {
                    InvoiceId = cmd.Request.InvoiceId,
                    Type      = cmd.Request.Type,
                    Email     = cmd.Request.CustomerReceipt.Email,
                    Phone     = cmd.Request.CustomerReceipt.Phone,
                    Inn       = cmd.Request.Inn,
                    TaxSystem = cmd.Request.CustomerReceipt.TaxationSystem
                };

                return(dto);
            }
Ejemplo n.º 16
0
        public async Task <Receipt> AddAsync(Receipt receipt)
        {
            using var uow = new UnitOfWork(_databaseContextProvider.Create());
            if (await IsReceiptExistsInternal(uow, receipt))
            {
                throw new InvalidOperationException("Такой чек уже есть в БД");
            }

            ReceiptDto newReceipt = await uow.Receipts.AddAsync(receipt.ToData());

            await uow.SaveChangesAsync();

            return(newReceipt.ToCore());
        }
Ejemplo n.º 17
0
        public IActionResult GenerateReceipts([FromBody] ReceiptDto receipt)
        {
            if (receipt == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _recordRepository.GenerateReceipt(receipt);

            return(Ok());
        }
Ejemplo n.º 18
0
        private void saveReceipt(ReceiptDto receiptDto, List <SaleProductOutDto> products, decimal totalPrice, string userid)
        {
            Receipt receipt = new Receipt()
            {
                CodeReceipt  = receiptDto.CodeReceipt,
                CustomerId   = db.Customers.FirstOrDefault(a => a.IdentificationNumber == receiptDto.IdentificationNumber).Id,
                IVA          = receiptDto.IVA,
                TotalPrice   = (totalPrice * receiptDto.IVA / 100) + totalPrice,
                UserId       = userid,
                CreationTime = DateTime.Now
            };

            db.Receipts.Add(receipt);

            foreach (var pro in products)
            {
                SaleProduct product = new SaleProduct()
                {
                    Amount       = pro.Amount,
                    ProductId    = pro.ProductId,
                    ReceiptId    = receipt.Id,
                    UnitPrice    = pro.UnitPrice,
                    TotalPrice   = pro.TotalPrice,
                    IsLoading    = true,
                    CreationTime = DateTime.Now
                };

                db.SaleProducts.Add(product);

                var wareHouse = db.WareHouses.FirstOrDefault(a => a.ProductId == pro.ProductId);

                if (wareHouse.AmountWareHouse - pro.Amount < 0)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content    = new StringContent("not enough units available  amount: " + wareHouse.AmountWareHouse),
                        StatusCode = HttpStatusCode.NotFound
                    };
                    throw new HttpResponseException(response);
                }

                wareHouse.AmountWareHouse -= pro.Amount;
            }

            db.SaveChanges();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 验证苹果收据
        /// author:陶林辉
        /// </summary>
        /// <param name="receipt"></param>
        /// <returns></returns>
        public bool VerifyReceipt(ReceiptDto receipt)
        {
            string strJosn = string.Format("{{\"receipt-data\":\"{0}\"}}", receipt.Receipt);
            //string strResult = CreatePostHttpResponse(strJosn,true);
            string  strResult = _sys.PostJsonData(_applepay.Url, strJosn, Encoding.UTF8);
            JObject obj       = JObject.Parse(strResult);

            // 判断是否购买成功
            if (obj["status"].ToString() == "0")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 20
0
        public void HandleCurrentUserSum_UsersNull_ShouldReturnZero()
        {
            var dto = new ReceiptDto
            {
                CurrentUserId = "detmig",
                Items         = new List <ReceiptItemDto>
                {
                    new ReceiptItemDto
                    {
                        Count = 100,
                        Price = 100,
                    }
                }
            };

            dto.Items.Should().NotBeNull();
            dto.CurrentUserOwed.Should().Be(0);
        }
Ejemplo n.º 21
0
        public async Task <ServiceResponse <ReceiptDto> > AddNewReceipt(ReceiptDto receipt)
        {
            ServiceResponse <ReceiptDto> response = new ServiceResponse <ReceiptDto>();

            if (receipt != null)
            {
                var receiptDb = mapper.Map <Receipt>(receipt);

                await context.Receipts.AddAsync(receiptDb);

                await context.SaveChangesAsync();

                response.Data    = mapper.Map <ReceiptDto>(await context.Receipts.Include(x => x.Products).FirstOrDefaultAsync(x => x.Id == receiptDb.Id));
                response.Success = true;
                response.Message = "OK";
            }

            return(response);
        }
Ejemplo n.º 22
0
        public void GenerateReceipt(ReceiptDto item)
        {
            List <ApartmentTenantDto> apartmentTenants = _dbContext.ApartmentTenant.Select(x => _mapper.Map <ApartmentTenantDto>(x)).ToList();

            List <Record> recordsToAdd = apartmentTenants.Select(x => new Record
            {
                Date               = item.Date,
                Amount             = x.Rent,
                ApartementTenantId = x.Id,
                Label              = "Quittance loyer",
                Type               = (int)RecordTypeEnum.Debit,
            }).ToList();

            if (recordsToAdd.Any())
            {
                _dbContext.Record.AddRange(recordsToAdd);
                _dbContext.SaveChanges();
            }
        }
        public static string Sha3ForReceipts(ReceiptDto receiptDto)
        {
            var sha3 = new Sha3Keccack();

            var rec =
                new IntTypeEncoder()
                .Encode(receiptDto.ReceiptId);
            var epo =
                new IntTypeEncoder()
                .Encode(receiptDto.EpochId);
            var amo =
                new IntTypeEncoder()
                .Encode(StringToBigInteger(receiptDto.AmountWei));
            var output     = sha3.CalculateHashFromHex(rec.ToHex(), epo.ToHex(), amo.ToHex(), receiptDto.Address);
            var resultHash = "0x" + output;


            return(resultHash);
        }
Ejemplo n.º 24
0
        public IActionResult Payment([FromBody] PaymentCommand payment)
        {
            //PaymentDtoCommand paymentDto = _mapper.Map<PaymentDtoCommand>(payment);

            ReceiptDto receiptDto = _saleService.CreateReceipt(payment);

            if (receiptDto == null)
            {
                return(BadRequest());
            }

            ReceiptViewModel model = new ReceiptViewModel()
            {
                CreateDateTime       = receiptDto.CreateDateTime,
                Discount             = receiptDto.Discount,
                IsDiscountPercentage = receiptDto.IsDiscountPercentage,
                PaymentType          = receiptDto.PaymentType,
                TotalDiscount        = receiptDto.TotalDiscount,
                ItemList             = new List <ViewModels.Sale.OrderItemModel>(),
                Reference            = receiptDto.Reference,
                ShiftId = receiptDto.ShiftId,
                Store   = receiptDto.Store,
                Total   = receiptDto.Total
            };

            foreach (var i in receiptDto.ItemList)
            {
                var m = new ViewModels.Sale.OrderItemModel()
                {
                    IsDiscountPercentage = i.IsDiscountPercentage,
                    ItemDiscount         = i.ItemDiscount,
                    ItemName             = i.ItemName,
                    ItemPrice            = i.ItemPrice,
                    OptionName           = i.OptionName,
                    OptionPrice          = i.OptionPrice,
                    Quantity             = i.Quantity
                };
                model.ItemList.Add(m);
            }

            return(Ok(model));
        }
Ejemplo n.º 25
0
 public static Receipt ToCore(this ReceiptDto obj)
 {
     return(new Receipt
     {
         Id = obj.Id,
         Comment = obj.Comment,
         BillingPeriodId = obj.BillingPeriodId,
         PurchaseTime = obj.PurchaseTime,
         TotalAmount = obj.TotalAmount,
         FiscalDocument = obj.FiscalDocument,
         FiscalNumber = obj.FiscalNumber,
         FiscalSign = obj.FiscalSign,
         Status = obj.Status,
         CustomerId = obj.CustomerId,
         RetailAddress = obj.RetailAddress,
         RetailInn = obj.RetailInn,
         CompanyName = obj.CompanyName,
         CashierName = obj.CashierName,
         Items = JsonConvert.DeserializeObject <ReceiptItem[]>(obj.ReceiptItemsJson),
     });
 }
Ejemplo n.º 26
0
        public IHttpActionResult SaleReceipt(ReceiptDto receiptDto)
        {
            IdentityUser user = db.Users.Where(a => a.UserName == ControllerContext.RequestContext.Principal.Identity.Name).FirstOrDefault();

            var pro = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SaleProductOutDto> >(receiptDto.Products);

            decimal totalPrice = pro.Sum(a => a.TotalPrice);

            if (user == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content    = new StringContent("User doesn't exist."),
                    StatusCode = HttpStatusCode.NotFound
                };
                throw new HttpResponseException(response);
            }

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    saveReceipt(receiptDto, pro, totalPrice, user.Id);



                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();

                    throw e;
                }
            }

            return(Ok("receipt was created succesfully"));
        }
Ejemplo n.º 27
0
        public void HandleTotal_ValidItems_ShouldReturnTotal()
        {
            var dto = new ReceiptDto
            {
                Items = new List <ReceiptItemDto>
                {
                    new ReceiptItemDto
                    {
                        Price = 100,
                        Count = 10
                    },
                    new ReceiptItemDto
                    {
                        Price = 1,
                        Count = 1
                    }
                }
            };

            dto.Items.Should().NotBeNull();
            dto.Items.Count.Should().Be(2);
            dto.Total.Should().Be(100 * 10 + 1);
        }
Ejemplo n.º 28
0
        private Receipt CreateAndGetReceipt(bool merge = false)
        {
            var waiter            = _context.ApplicationUsers.First();
            var table             = _context.Tables.First();
            var cafe              = _context.Cafes.First();
            var priceTableQueries = cafe.PriceTable.PriceTableQueries.ToList();

            var receipt = new ReceiptDto()
            {
                Cafe   = cafe,
                Table  = table,
                Waiter = waiter,
                ReceiptPriceTableQueries = new List <ReceiptPriceTableQuery>()
                {
                    new ReceiptPriceTableQuery()
                    {
                        PriceTableQueryId = priceTableQueries[0].Id,
                        Quantity          = 2
                    },
                    new ReceiptPriceTableQuery()
                    {
                        PriceTableQueryId = priceTableQueries[1].Id,
                        Quantity          = 1
                    },
                    new ReceiptPriceTableQuery()
                    {
                        PriceTableQueryId = merge ? priceTableQueries[0].Id : priceTableQueries[2].Id,
                        Quantity          = 4
                    },
                }
            };

            _receiptOperations.CreateReceipt(receipt);

            return(_context.Receipts.Last());
        }
Ejemplo n.º 29
0
 public ReceiptDtoBuilder()
 {
     _receiptDto = WithDefaults();
 }
        public ReceiptReportDto CreateReceipt(ReceiptDto receiptDtoToCreate)
        {
            var cashRegisterCashierWithIds = _dbCashierRegisterContext.CashRegisterCashiers
                                             .Include(cashRegisterCashier => cashRegisterCashier.Cashier)
                                             .Include(cashRegisterCashier => cashRegisterCashier.CashRegister)
                                             .Single(shift =>
                                                     shift.CashRegisterId == receiptDtoToCreate.Receipt.CashRegisterCashier.CashRegisterId &&
                                                     shift.CashierId == receiptDtoToCreate.Receipt.CashRegisterCashier.CashierId &&
                                                     shift.EndOfShift == DateTime.MinValue);

            var id         = new Guid();
            var newReceipt = new Receipt
            {
                Id = id,
                CashRegisterCashier = cashRegisterCashierWithIds,
                DateTimeCreated     = DateTime.Now
            };

            _dbCashierRegisterContext.Receipts.Add(newReceipt);
            _dbCashierRegisterContext.SaveChanges();

            foreach (var product in receiptDtoToCreate.ProductsOnReceipt)
            {
                CreateReceiptProduct(newReceipt.Id, product.Product.Id, (int)product.ProductCount);
            }

            var preTaxTotal = receiptDtoToCreate.ProductsOnReceipt.Sum(product => product.Product.Price * product.ProductCount);
            var exciseTotal = receiptDtoToCreate.ProductsOnReceipt.Sum(product =>
                                                                       product.Product.Price *
                                                                       _dbCashierRegisterContext.Taxes.Single(tax => tax.TaxType == TaxType.Excise && tax.ProductTaxes.Any(prd => prd.ProductId == product.Product.Id)).Percentage / 100 *
                                                                       product.ProductCount);
            var directTotal = receiptDtoToCreate.ProductsOnReceipt.Sum(product =>
                                                                       product.Product.Price *
                                                                       _dbCashierRegisterContext.Taxes.Single(tax => tax.TaxType == TaxType.Direct && tax.ProductTaxes.Any(prd => prd.ProductId == product.Product.Id)).Percentage / 100 *
                                                                       product.ProductCount);
            var postTaxTotal = preTaxTotal + exciseTotal + directTotal;

            if (preTaxTotal != null)
            {
                newReceipt.PreTaxPriceAtCreation = (int)preTaxTotal;
            }
            if (exciseTotal != null)
            {
                newReceipt.ExciseTaxAtCreation = (int)exciseTotal;
            }
            if (directTotal != null)
            {
                newReceipt.DirectTaxAtCreation = (int)directTotal;
            }
            if (postTaxTotal != null)
            {
                newReceipt.PostTaxPriceAtCreation = (int)postTaxTotal;
            }

            _dbCashierRegisterContext.SaveChanges();


            var productReportDtoList = new List <ProductReportDto>();
            var productReceipts      =
                _dbCashierRegisterContext.ReceiptProducts.Where(receiptProducts =>
                                                                receiptProducts.ReceiptId == newReceipt.Id);

            foreach (var receiptProduct in productReceipts)
            {
                productReportDtoList.Add(new ProductReportDto
                {
                    Name                    = receiptProduct.Product.Name,
                    ExcisePercentage        = receiptProduct.ProductExcisePercentageAtCreation,
                    ProductDirectPercentage = receiptProduct.ProductDirectPercentageAtCreation,
                    ProductCount            = receiptProduct.ProductCount,
                    ProductPrice            = receiptProduct.ProductPriceAtCreation
                });
            }

            var receiptReportDto = new ReceiptReportDto
            {
                Receipt        = newReceipt,
                ProductReports = productReportDtoList
            };

            return(receiptReportDto);
        }
 public StringifyReceiptQuery(ReceiptDto dto)
 {
     Dto = dto;
 }