Untitled
unknown
plain_text
a month ago
7.5 kB
2
Indexable
Never
public async Task<bool> GetPreviousDayEndRegisterShift() { RegisterShift previousRegisterShift = this.RegisterShiftViewModel.Items .Where(o => o.IsClosed) .OrderByDescending(o => o.ClosedDate) .FirstOrDefault(o => o.ClosedDate.HasValue && o.ClosedDate.Value < this.RegisterShift.OpenDate); if (previousRegisterShift != null) { return previousRegisterShift.RegisterShiftPropertiesModel.DayEndRegisterShift; } return false; } public async void ExecutePrint(object parameter) { bool previousDayEndRegisterShift = await GetPreviousDayEndRegisterShift(); if (this.RegisterShift.RegisterShiftPropertiesModel.DayEndRegisterShift == false || this.RegisterShift.IsOpen) { IsPrintMultiShift = false; } else { List<string> actions = new List<string>(); actions.Add("Print this shift only"); actions.Add("Print All shifts since the last close"); int resultIndexShiftPrint = await this.ActionPresenter.ShowAsync(this.Resources.GetString("SelectAction"), actions.ToArray()); if (previousDayEndRegisterShift == true) { if (resultIndexShiftPrint == 0) { IsPrintMultiShift = false; } else { IsPrintMultiShift = false; } } else { if (resultIndexShiftPrint == 0) { IsPrintMultiShift = false; } else { IsPrintMultiShift = true; } } } RegisterShift registerShift = this.RegisterShift; if(IsPrintMultiShift) { SelectParameter selectParameter = new SelectParameter(); DateTime endDate = DateTime.Now.AddDays(1).Date; DateTime openDate = new DateTime(); DateTime? closedDate = new DateTime(); RegisterShift firstRegisterShift = this.RegisterShiftViewModel.Items.OrderBy(o => o.OpenDate).FirstOrDefault(o => o.OpenDate < this.RegisterShift.OpenDate && o.OpenDate.Day == this.RegisterShift.OpenDate.Day); if (firstRegisterShift != null) { DateTime open = firstRegisterShift.OpenDate; openDate = open; } RegisterShift lastRegisterShift = this.RegisterShiftViewModel.Items.OrderByDescending(o => o.OpenDate).FirstOrDefault(o => o.OpenDate < this.RegisterShift.ClosedDate); if (lastRegisterShift != null) { DateTime? close = lastRegisterShift.ClosedDate.HasValue ? lastRegisterShift.ClosedDate : endDate; closedDate = close; } selectParameter.QueryDescriptor.FilterDescriptors.Add(new FilterDescriptor("CreatedDate", FilterOperator.IsGreaterThanOrEqualTo, openDate)); selectParameter.QueryDescriptor.FilterDescriptors.Add(new FilterDescriptor("CreatedDate", FilterOperator.IsLessThanOrEqualTo, closedDate)); IsPrintMultiShift = true; RegisterShiftRepository repo = Container.Current.Resolve<IRegisterShiftRepository>() as RegisterShiftRepository; var result = await repo.GetAllAsync(selectParameter); if (result != null && result.Items != null && result.Items.Any()) { RegisterShift newRegisterShift = result.Items.FirstOrDefault(o => o.RegisterShiftId == this.RegisterShift.RegisterShiftId).Clone<RegisterShift>(); if (newRegisterShift != null && result.Items.Count > 1) { newRegisterShift.OpenDate = openDate; newRegisterShift.ClosedDate = closedDate; newRegisterShift.RegisterShiftPropertiesModel.RegisterShiftData = await this.UpdatePrintRegisterShiftData(newRegisterShift, newRegisterShift.RegisterShiftPropertiesModel.RegisterShiftData); registerShift = newRegisterShift; } } } if (this.RegisterShift == null || this.RegisterShiftViewModel == null) return; if (this.LoadingData) { if (this.MessagePresenter != null) this.MessagePresenter.Show("Still processing report, please try again"); return; } List<RegisterShiftTransaction> transactions = this.RegisterShiftViewModel.RegisterShiftTransactions.ToList(); await CheckEmptyOrderTransactionGroup(true); List<TransactionGroup> items = registerShift.RegisterShiftPropertiesModel.RegisterShiftData.Transactions.ToList(); await this.QueryTransaction(items, registerShift); if (this.ActivityPresenter != null) this.ActivityPresenter.Show(); OrderData orderData = null; if (IsPrintMultiShift) { orderData = this.AppViewModel.GeneratePrintData(transactions, registerShift, registerShift.RegisterShiftPropertiesModel.RegisterShiftData.Transactions.ToList()); } else { orderData = this.AppViewModel.GeneratePrintData(transactions, this.RegisterShift, this.Items.ToList()); } if (orderData != null) { orderData.TransactionGroups = registerShift.RegisterShiftPropertiesModel.RegisterShiftData.TransactionGroups; //if (this.CommerceAppSettings.GeneralSettings.PrintOrderDetailAndInventoryUsedInRegisterCloseShift) { await this.UpdateInventoryReport(orderData.RegisterShift, orderData.RegisterShiftData); if (this.CommerceAppSettings.GeneralSettings.EnablePrintOnlineOrderingRegisterReport) await this.UpdateInventoryReport(orderData.RegisterShift, orderData.RegisterShiftData, 1); if (this.CommerceAppSettings.GeneralSettings.EnablePrintFoodDeliveryRegisterReport) await this.UpdateInventoryReport(orderData.RegisterShift, orderData.RegisterShiftData, 2); } //if (this.CommerceAppSettings.GeneralSettings.PrintDetailInRegisterCloseShift) // orderData.RegisterShiftData = await this.UpdatePrintRegisterShiftData(orderData.RegisterShift, orderData.RegisterShiftData); if (this.ActivityPresenter != null) this.ActivityPresenter.Hide(); ServiceProvider.GetService<IViewService>().RunOnBackgroundThread(() => { DateTime start = DateTime.Now; Guid guid = Guid.NewGuid(); if (this.CommerceAppSettings.GeneralSettings != null && this.CommerceAppSettings.GeneralSettings.EnableLogCat) this.AppViewModel.LogCatService.Log("Print From Register Shift" + guid); this.AppViewModel.ExecutePrintRegisterShift(orderData.RegisterShiftTransactions, orderData.RegisterShift, orderData.TransactionGroups, orderData.RegisterShiftData, printDataOnline: this.OnlineOrderTransactionGroups); this.AddLog("Print register shift" + orderData.RegisterShift.RegisterShiftId.ToString()); DateTime end = DateTime.Now; if (this.CommerceAppSettings.GeneralSettings != null && this.CommerceAppSettings.GeneralSettings.EnableLogCat) this.AppViewModel.LogCatService.Log("Print From Register Shift end " + guid + " takes " + (end - start).TotalSeconds + " seconds"); }, 100); } }
Leave a Comment