public DateTime ChangeOrRefund(Sale.AfterSale.OrderChangeRefundSale changeList, int reason, MachineInformation machineInformation, string newPaySn, decimal amount, decimal receive, string uid, string apiCodes, DateTime saveTime, string saleman, string oldOrderSn) { var dataAdapter = DataAdapterFactory.DbFactory(MachinesSettings.Mode, StoreId, MachineSN, CompanyId, DeviceSn); return(dataAdapter.ChangeOrRefund(changeList, reason, machineInformation, newPaySn, amount, receive, uid, apiCodes, saveTime, saleman, oldOrderSn)); }
public DateTime ChangeOrRefund(Sale.AfterSale.OrderChangeRefundSale changeList, int reason, MachineInformation machineInformation, string newPaySn, decimal amount, decimal receive, string uid, string apiCodes, DateTime saveTime, string saleman, string oldOrderSn) { //to do save change //orders var oldOrder = (from a in SaleOrdersService.CurrentRepository.Entities.Where(o => o.StoreId == machineInformation.StoreId && o.CompanyId == machineInformation.CompanyId && o.CustomOrderSn == oldOrderSn) join b in SaleDetailService.CurrentRepository.Entities on a.PaySN equals b.PaySN select new { a, b }).ToList(); try { SaleOrders _saleOrder = new SaleOrders() { PaySN = changeList.PaySn, CustomOrderSn = changeList.CustomOrderSn, MachineSN = machineInformation.MachineSn, StoreId = machineInformation.StoreId, TotalAmount = amount, Receive = receive, PreferentialPrice = 0, ApiCode = apiCodes, CreateUID = machineInformation.CashierUid, CreateDT = saveTime, ReturnDT = saveTime, CompanyId = machineInformation.CompanyId, ProductCount = changeList.RecordCount, Type = (short)changeList.Mode, State = 0, MemberId = null, IsTest = IsSalesclerkTest, InInventory = 0, IsProcess = false, Reason = reason, Salesman = saleman, //退换货原导购员 来自客户端 ReFundOrderCustomOrderSn = oldOrderSn //退换货原单号 来自客户端 }; SaleOrdersService.CurrentRepository.Add(_saleOrder, false); foreach (var item in changeList.ChangingList) { var buyPrice = 0m; if (oldOrder != null) { foreach (var itm in oldOrder) { if ((short)changeList.Mode == 2) { if (itm.b.Barcode == item.CurrentBarcode.MainBarcode) { buyPrice = itm.b.BuyPrice; } } else { if (itm.b.PurchaseNumber > 0) { buyPrice = item.BuyPrice; } else { if (itm.b.Barcode == item.CurrentBarcode.MainBarcode) { buyPrice = itm.b.BuyPrice; } } } } } SaleDetail _saleDetail = new SaleDetail() { PaySN = changeList.PaySn, ScanBarcode = item.CurrentBarcode.CurrentString, ProductCode = item.CurrentBarcode.ProductCode, AveragePrice = item.ChangePrice,//均价 CompanyId = machineInformation.CompanyId, Total = item.ChangePrice * item.ChangeNumber, Barcode = item.CurrentBarcode.MainBarcode, PurchaseNumber = item.ChangeNumber, BuyPrice = buyPrice,//进价 SysPrice = item.SysPrice, ActualPrice = item.ChangePrice, SalesClassifyId = (int)item.SaleStatus, Title = item.CurrentBarcode.Details.Title }; SaleDetailService.CurrentRepository.Add(_saleDetail, false); } SaleOrdersService.CurrentRepository.Update(_saleOrder); } catch (Exception ex) { throw; } return(saveTime); }
public DateTime ChangeOrRefund(Sale.AfterSale.OrderChangeRefundSale changeList, int reason, MachineInformation machineInformation, string newPaySn, decimal amount, decimal receive, string uid, string apiCodes, DateTime saveTime, string saleman, string oldOrderSn) { try { var oldOrder = (from a in SaleOrdersService.CurrentRepository.Entities.Where(o => o.StoreId == machineInformation.StoreId && o.CompanyId == machineInformation.CompanyId && o.CustomOrderSn == oldOrderSn) join b in SaleDetailService.CurrentRepository.Entities on a.PaySN equals b.PaySN select new { a, b }); var version = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; SaleOrders _saleOrder = new SaleOrders() { PaySN = changeList.PaySn, CustomOrderSn = changeList.CustomOrderSn, MachineSN = machineInformation.MachineSn, StoreId = machineInformation.StoreId, TotalAmount = amount, Receive = receive, PreferentialPrice = 0, ApiCode = apiCodes, CreateUID = machineInformation.CashierUid, CreateDT = saveTime, ReturnDT = saveTime, CompanyId = machineInformation.CompanyId, ProductCount = changeList.RecordCount, Type = (short)changeList.Mode, State = 0, MemberId = null, IsTest = IsSalesclerkTest, InInventory = 0, IsProcess = false, Reason = reason, SyncItemId = Guid.NewGuid(), SyncItemVersion = version, Salesman = saleman, ReFundOrderCustomOrderSn = oldOrderSn }; SaleOrdersService.CurrentRepository.Add(_saleOrder, false); foreach (var item in changeList.ChangingList) { var buyPrice = 0m; if (oldOrder != null) { foreach (var itm in oldOrder) { if ((short)changeList.Mode == 2) { if (itm.b.Barcode == item.CurrentBarcode.MainBarcode) { buyPrice = itm.b.BuyPrice; } } else { if (itm.b.PurchaseNumber > 0) { var isWeight = false; if (itm.b.Barcode.Length == 13 && itm.b.ScanBarcode.Substring(0, 2) == "27") { isWeight = true; } var productInfo = GetProductInfoByBarcode(itm.b.ScanBarcode, isWeight); if (productInfo != null) { buyPrice = productInfo.BuyPrice; } } else { if (itm.b.Barcode == item.CurrentBarcode.MainBarcode) { buyPrice = itm.b.BuyPrice; } } } } } SaleDetail _saleDetail = new SaleDetail() { PaySN = changeList.PaySn, ScanBarcode = item.CurrentBarcode.CurrentString, ProductCode = item.CurrentBarcode.ProductCode, AveragePrice = item.ChangePrice,//均价 CompanyId = machineInformation.CompanyId, Total = item.ChangePrice * item.ChangeNumber, Barcode = item.CurrentBarcode.MainBarcode, PurchaseNumber = item.ChangeNumber, BuyPrice = buyPrice,//进价 SysPrice = item.SysPrice, ActualPrice = item.ChangePrice, SalesClassifyId = (int)item.SaleStatus, Title = item.CurrentBarcode.Details.Title, SyncItemId = Guid.NewGuid(), SyncItemVersion = version }; SaleDetailService.CurrentRepository.Add(_saleDetail, false); } SaleOrdersService.CurrentRepository.Update(_saleOrder); //RedisManager.Publish("SyncDatabase", "SalePackage"); StoreManager.PubEvent("SyncDatabase", "SalePackage"); } catch (Exception ex) { throw ex; } return(saveTime); }