Exemplo n.º 1
0
        public async Task <IHttpActionResult> Post(NvGiaoDichQuayVm.DataDto instance)
        {
            var result          = new TransferObj <NvGiaoDichQuay>();
            var _parentUnitCode = _serviceGdQuay.GetParentUnitCode();

            try
            {
                //lưu giao dịch
                var item = _serviceRetails.InsertPhieu(instance);
                //run XNT tăng giảm phiếu
                //update thông tin khách hàng
                await _serviceRetails.UnitOfWork.SaveAsync();

                if (item.MaGiaoDichQuayPK != "" && item.LoaiGiaoDich > 0)
                {
                    int loaiGiaoDich = 0;
                    Int32.TryParse(item.LoaiGiaoDich.ToString(), out loaiGiaoDich);
                    _serviceRetails.RUNSTORE_TANGGIAM_TON(item.MaGiaoDichQuayPK, loaiGiaoDich);
                }
                //update customer
                if (instance.Makh != "KHACHLE")
                {
                    SaveCustomer(instance.Makh, instance);
                }
                await _serviceCustomer.UnitOfWork.SaveAsync();

                //update only one use voucher code
                if (item.MaVoucher != null)
                {
                    //check code voucher in NVKhuyenMai
                    var itemVoucher =
                        _serviceGdQuay.UnitOfWork.Repository <NvChuongTrinhKhuyenMai>()
                        .DbSet.FirstOrDefault(x => x.LoaiKhuyenMai == 7 && x.MaGiamGia == item.MaVoucher && x.UnitCode.StartsWith(_parentUnitCode));
                    if (itemVoucher != null)
                    {
                        itemVoucher.TrangThaiSuDung = (int)ApprovalState.IsExpired;
                        _serviceKhuyenMaiVoucher.Update(itemVoucher);
                        await _serviceKhuyenMaiVoucher.UnitOfWork.SaveAsync();
                    }
                }
                result.Data   = item;
                result.Status = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.MaGiaoDichQuayPk }, result));
            }
            catch (Exception exception)
            {
                return(InternalServerError());
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage ExportExcel(ParameterCashier para)
        {
            var _ParentUnitCode = _service.GetParentUnitCode();

            NvGiaoDichQuayVm.ReportExcel result = null;
            var unitCode = _service.GetCurrentUnitCode();
            //var instance = _service.Repository.DbSet.FirstOrDefault(x => x.MaVatTu.ToUpper() == code.ToUpper());//&& x.UnitCode == unitCode);
            var service = new ProcedureService <NvGiaoDichQuayVm.ReportExcel>();
            var data    = ProcedureCollection.GetReportGDQExcel(para.FromDate, para.ToDate, new BTS.API.ENTITY.ERPContext(), unitCode);

            using (ExcelPackage package = new ExcelPackage())
            {
                var ms = new MemoryStream();
                package.Workbook.Worksheets.Add("Data");
                var worksheet = package.Workbook.Worksheets[1];
                int index     = 0;
                worksheet.Cells[1, 1, 1, 5].Merge = true;
                worksheet.Cells[1, 1].Value       = "SIÊU THỊ TỪ SƠN ";
                worksheet.Cells[2, 1, 2, 5].Merge = true;
                worksheet.Cells[2, 1].Value       = "Đường Lý Thái Tổ, P. Đình Bảng, TX Từ Sơn, Bắc Ninh ";
                worksheet.Cells[4, 4, 4, 7].Merge = true;
                worksheet.Cells[4, 4].Value       = "BÁO CÁO GIAO DỊCH QUẦY ";
                worksheet.Cells[5, 4, 5, 8].Merge = true;
                worksheet.Cells[5, 4].Value       = "Từ ngày: " + para.FromDate.Day + "/" + para.FromDate.Month + "/" + para.FromDate.Year + "   Đến ngày:" + para.ToDate.Day + "/" + para.ToDate.Month + "/" + para.ToDate.Year;
                worksheet.Cells[7, 1].Value       = "STT";
                worksheet.Cells[7, 2].Value       = "Nhân viên";
                worksheet.Cells[7, 3].Value       = "Máy bán";
                worksheet.Cells[7, 4].Value       = "Ngày phát sinh";
                worksheet.Cells[7, 5].Value       = "Loại giao dịch";
                worksheet.Cells[7, 6].Value       = "Mã hàng";
                worksheet.Cells[7, 7].Value       = "Tên hàng";
                worksheet.Cells[7, 8].Value       = "Số lượng";
                worksheet.Cells[7, 9].Value       = "Tổng tiền";
                index = 8;
                if (data != null && data.Count() >= 1)
                {
                    var item = data.ToList();
                    for (int i = 0; i < item.Count; i++)
                    {
                        var hanghoa    = new MdMerchandiseVm.Dto();
                        var innerindex = item[i].MaVatTu;
                        var hanghoatg  = _merchandiseservice.UnitOfWork.Repository <MdMerchandise>().DbSet.FirstOrDefault(x => x.MaVatTu == innerindex && x.UnitCode.StartsWith(_ParentUnitCode));
                        hanghoa = Mapper.Map <MdMerchandise, MdMerchandiseVm.Dto>(hanghoatg);
                        worksheet.Cells[index, 1].Value = index;
                        worksheet.Cells[index, 2].Value = item[i].MaNguoiTao + "-" + item[i].NguoiTao;
                        worksheet.Cells[index, 3].Value = item[i].MaQuayBan;
                        worksheet.Cells[index, 4].Value = item[i].NgayPhatSinh.Date + "/" + item[i].NgayPhatSinh.Month + "/" + item[i].NgayPhatSinh.Year;
                        worksheet.Cells[index, 6].Value = item[i].MaVatTu;
                        if (hanghoa == null)
                        {
                            worksheet.Cells[index, 7].Value = " ";
                        }
                        worksheet.Cells[index, 7].Value = hanghoa.TenHang;
                        worksheet.Cells[index, 8].Value = item[i].SoLuong;
                        worksheet.Cells[index, 9].Value = CurrentSetting.FormatTienViet(item[i].TTienCoVat.ToString());
                        if (item[i].LoaiGiaoDich == 1)
                        {
                            worksheet.Cells[index, 5].Value = "xuất bán";
                        }
                        else if (item[i].LoaiGiaoDich == 2)
                        {
                            worksheet.Cells[index, 5].Value = "bán trả lại";
                        }
                        index++;
                    }
                }
                else
                {
                    //return null;
                }

                package.SaveAs(ms);
                HttpResponseMessage response = Request.CreateResponse();
                response.StatusCode = HttpStatusCode.OK;
                ms.Seek(0, SeekOrigin.Begin);
                response.Content = new StreamContent(ms);

                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
                {
                    FileName = "BaoCaoGiaoDichQuay.xlsx"
                };
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

                return(response);
            }
        }