public DrivingDirectionPageViewModel(INavigationService navigationService) : base(navigationService) { _navigationService = navigationService; this._deliveryTask = PersistentData.Instance.CollectDeliveryTask; this.CustomerDetails = PersistentData.Instance.CustomerDetails; GetDirectionsCommand = DelegateCommand <Location> .FromAsyncHandler(async (location) => { var stringBuilder = new StringBuilder("bingmaps:?rtp=pos."); stringBuilder.Append(location.Latitude); stringBuilder.Append("_"); stringBuilder.Append(location.Longitude); stringBuilder.Append("~adr." + Regex.Replace(this.CustomerDetails.Address, "\n", ",")); await Launcher.LaunchUriAsync(new Uri(stringBuilder.ToString())); }); this.GoToDocumentDeliveryCommand = new DelegateCommand(() => { _navigationService.Navigate("CollectionOrDeliveryDetails", string.Empty); }); this.StartDrivingCommand = new DelegateCommand(async() => { this.IsStartDriving = false; this.IsArrived = true; await SqliteHelper.Storage.InsertSingleRecordAsync(new CDDrivingDuration { StartDateTime = DateTime.Now, CaseNumber = ApplicationData.Current.LocalSettings.Values["CaseNumber"].ToString() }); }); this.ArrivedCommand = new DelegateCommand(async() => { if (this._deliveryTask != null) { var CaseNumber = ApplicationData.Current.LocalSettings.Values["CaseNumber"].ToString(); var dd = await SqliteHelper.Storage.GetSingleRecordAsync <CDDrivingDuration>(x => x.CaseNumber.Equals(CaseNumber)); dd.StopDateTime = DateTime.Now; this._deliveryTask.TaskType = BusinessLogic.Enums.CDTaskType.Delivery; await SqliteHelper.Storage.UpdateSingleRecordAsync(this._deliveryTask); await SqliteHelper.Storage.UpdateSingleRecordAsync(dd); } this.IsStartDelivery = true; this.IsStartDriving = false; this.IsArrived = false; }); }
async private System.Threading.Tasks.Task CollectedDocumnetsFromTaskBucket(CollectDeliveryTask task, bool iscollectedByCustomer) { try { var collectDetailTable = await SqliteHelper.Storage.LoadTableAsync <DocumentCollectDetail>(); this.DocumentCollectDetail.Comment = this.DocuDeliveryDetails.Comment; this.DocumentCollectDetail.ReceivedDate = this.DocuDeliveryDetails.ReceivedDate; this.DocumentCollectDetail.IsColletedByCustomer = iscollectedByCustomer; this.DocumentCollectDetail.CollectedAt = this.SelectedCollectedFrom != null ? this.SelectedCollectedFrom.Address : string.Empty; this.DocumentCollectDetail.SelectedCollectedFrom = this.SelectedCollectedFrom != null ? this.SelectedCollectedFrom.UserName : string.Empty; if (this.IsAlternateOn && SelectedAlternateContact != null) { this.DocumentCollectDetail.ReceivedBy = this.SelectedAlternateContact.FullName; this.DocumentCollectDetail.DeliveryPersonName = this.SelectedAlternateContact.FullName; this.DocumentCollectDetail.Email = this.SelectedAlternateContact.Email; this.DocumentCollectDetail.Position = this.SelectedAlternateContact.Position; this.DocumentCollectDetail.Phone = this.SelectedAlternateContact.CellPhone; } else { this.DocumentCollectDetail.ReceivedBy = this.SelectedContact != null ? this.SelectedContact.UserName : string.Empty; } this.DocumentCollectDetail.CaseNumber = task.CaseNumber; this.DocumentCollectDetail.CaseServiceRecId = task.CaseServiceRecID; if (collectDetailTable.Any(a => a.CaseNumber == this.DocumentCollectDetail.CaseNumber)) { await SqliteHelper.Storage.UpdateSingleRecordAsync <DocumentCollectDetail>(this.DocumentCollectDetail); } else { await SqliteHelper.Storage.InsertSingleRecordAsync <DocumentCollectDetail>(this.DocumentCollectDetail); } } catch (Exception ex) { AppSettings.Instance.ErrorMessage = ex.Message; } }
public CollectionOrDeliveryDetailsPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, SettingsFlyout addCustomerPage) : base(navigationService) { _navigationService = navigationService; this._eventAggregator = eventAggregator; this._addCustomerPage = addCustomerPage; this._task = PersistentData.Instance.CollectDeliveryTask; this.CustomerDetails = PersistentData.Instance.CustomerDetails; this.DocumentList = new ObservableCollection <Document>(); this.CollectVisibility = Visibility.Collapsed; this.CompleteVisibility = Visibility.Collapsed; this.DocuDeliveryDetails = new CollectDeliveryDetail(); this.DocumentCollectDetail = new DocumentCollectDetail(); this.DocumnetDeliverDetail = new DocumnetDeliverDetail(); this.AddContactCommand = new DelegateCommand(() => { addCustomerPage.ShowIndependent(); }); this.CollectCommand = new DelegateCommand(async() => { try { this.IsBusy = true; switch (this._userInfo.CDUserType) { case CDUserType.Driver: foreach (var task in this.SelectedTaskBucket) { if (this.DocumentList.Any(a => a.CaseNumber == task.CaseNumber && a.IsMarked)) { switch (task.ServiceId) { case CollectDeliverServices.LICENCEDUP: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.PERMIT: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.POLICECLEARANCE: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.FINESPOB: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.FINESRTA: task.Status = CDTaskStatus.AwaitDeliveryConfirmation; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.PNP: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.REQUESTCOF: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.FINESRTC: task.Status = CDTaskStatus.AwaitDeliveryConfirmation; task.TaskType = CDTaskType.None; break; case CollectDeliverServices.LICENCERENEWAL: task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; break; default: task.Status = CDTaskStatus.AwaitDeliveryConfirmation; task.TaskType = CDTaskType.Delivery; break; } task.IsNotSyncedWithAX = true; await SqliteHelper.Storage.UpdateSingleRecordAsync(task); await CollectedDocumnetsFromTaskBucket(task, false); } } break; case CDUserType.Courier: foreach (var task in this.SelectedTaskBucket) { if (this.DocumentList.Any(a => a.CaseNumber == task.CaseNumber && a.IsMarked)) { task.Status = CDTaskStatus.AwaitDeliveryConfirmation; task.TaskType = CDTaskType.Delivery; task.IsNotSyncedWithAX = true; await SqliteHelper.Storage.UpdateSingleRecordAsync(task); this.DocuDeliveryDetails.DeliveryDate = this.DocuDeliveryDetails.ReceivedDate; await DeliveredDocumentsFromTaskBucket(task); } } break; case CDUserType.Customer: foreach (var task in this.SelectedTaskBucket) { if (this.DocumentList.Any(a => a.CaseNumber == task.CaseNumber && a.IsMarked)) { task.Status = CDTaskStatus.Completed; task.TaskType = CDTaskType.None; task.IsNotSyncedWithAX = true; await SqliteHelper.Storage.UpdateSingleRecordAsync(task); await CollectedDocumnetsFromTaskBucket(task, true); } } break; default: break; } await DDServiceProxyHelper.Instance.SynchronizeAllAsync(); this.IsBusy = false; _navigationService.Navigate("InspectionDetails", string.Empty); } catch (Exception ex) { AppSettings.Instance.ErrorMessage = ex.Message; this.IsBusy = false; } }, () => { return(this.DocumentList.Any(a => a.IsMarked) && ((this.SelectedContact != null && !this.IsAlternateOn) || (this.SelectedAlternateContact != null && this.IsAlternateOn)) && this.CRSignature != null && _task.TaskType == CDTaskType.Collect); } ); this.CompleteCommand = new DelegateCommand(async() => { try { this.IsBusy = true; if (this._userInfo.CDUserType == CDUserType.Courier) { foreach (var task in this.SelectedTaskBucket) { if (this.DocumentList.Any(a => a.CaseNumber == task.CaseNumber & a.IsMarked)) { task.Status = CDTaskStatus.AwaitInvoice; task.TaskType = CDTaskType.None; task.IsNotSyncedWithAX = true; await SqliteHelper.Storage.UpdateSingleRecordAsync(task); //await DeliveredDocumentsFromTaskBucket(task); await UpdateDeliveryDetailForCourierAsync(task); } } } else { foreach (var task in this.SelectedTaskBucket) { if (this.DocumentList.Any(a => a.CaseNumber == task.CaseNumber && a.IsMarked)) { task.Status = CDTaskStatus.Completed; task.TaskType = CDTaskType.None; task.IsNotSyncedWithAX = true; await SqliteHelper.Storage.UpdateSingleRecordAsync(task); await DeliveredDocumentsFromTaskBucket(task); } } } await DDServiceProxyHelper.Instance.SynchronizeAllAsync(); this.IsBusy = false; _navigationService.Navigate("InspectionDetails", string.Empty); } catch (Exception ex) { AppSettings.Instance.ErrorMessage = ex.Message; this.IsBusy = false; } }, () => { return(this.DocumentList.Any(a => a.IsMarked) && ((this.SelectedContact != null && !this.IsAlternateOn) || (this.SelectedAlternateContact != null && this.IsAlternateOn)) && this.CRSignature != null && _task.TaskType == CDTaskType.Delivery); }); //this.SelectedDocuments = new ObservableCollection<Document>(); this._eventAggregator.GetEvent <AlternateContactPersonEvent>().Subscribe(async(customerContacts) => { this.AlternateContactPersons = await SqliteHelper.Storage.LoadTableAsync <AlternateContactPerson>(); this._addCustomerPage.Hide(); }); this.DocumentsChangedCommand = new DelegateCommand <ObservableCollection <object> >((param) => { foreach (var item in this.DocumentList) { item.IsMarked = false; } foreach (var item in param) { ((Document)item).IsMarked = true; } this.CompleteCommand.RaiseCanExecuteChanged(); this.CollectCommand.RaiseCanExecuteChanged(); }); }
async private System.Threading.Tasks.Task UpdateDeliveryDetailForCourierAsync(CollectDeliveryTask task) { try { var deliveryDetailTable = await SqliteHelper.Storage.LoadTableAsync <DocumentDeliveryUpdateDetail>(); var deliveryDetail = new DocumentDeliveryUpdateDetail(); deliveryDetail.Comment = this.DocuDeliveryDetails.Comment; deliveryDetail.DeliveryDate = this.DocuDeliveryDetails.DeliveryDate; if (this.IsAlternateOn && SelectedAlternateContact != null) { deliveryDetail.ReceivedBy = this.SelectedAlternateContact.FullName; deliveryDetail.DeliveryPersonName = this.SelectedAlternateContact.FullName; deliveryDetail.Email = this.SelectedAlternateContact.Email; deliveryDetail.Position = this.SelectedAlternateContact.Position; deliveryDetail.Phone = this.SelectedAlternateContact.CellPhone; } else { deliveryDetail.DeliveryPersonName = this.SelectedContact != null ? this.SelectedContact.UserName : string.Empty; } deliveryDetail.CaseNumber = task.CaseNumber; deliveryDetail.CaseServiceRecId = task.CaseServiceRecID; if (deliveryDetailTable.Any(a => a.CaseNumber == this.DocuDeliveryDetails.CaseNumber)) { await SqliteHelper.Storage.UpdateSingleRecordAsync <DocumentDeliveryUpdateDetail>(deliveryDetail); } else { await SqliteHelper.Storage.InsertSingleRecordAsync <DocumentDeliveryUpdateDetail>(deliveryDetail); } } catch (Exception ex) { AppSettings.Instance.ErrorMessage = ex.Message; } }
async public System.Threading.Tasks.Task <List <CollectDeliveryTask> > SyncTasksFromSvcAsync() { List <CollectDeliveryTask> taskInsertList = new List <CollectDeliveryTask>(); try { var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess) { return(null); } if (_userInfo == null) { _userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString()); } var result = await _client.getTasksAsync(_userInfo.UserId, _userInfo.CompanyId); var taskData = await SqliteHelper.Storage.LoadTableAsync <CollectDeliveryTask>(); ObservableCollection <long> caseCategoryRecIdList = new ObservableCollection <long>(); if (result.response != null) { foreach (var mzkTask in result.response.GroupBy(g => g.parmCaseId).Select(s => s.First())) { var taskTosave = new CollectDeliveryTask { CaseNumber = mzkTask.parmCaseId, Address = mzkTask.parmContactPersonAddress, CustomerName = mzkTask.parmCustName, CustomerNumber = mzkTask.parmContactPersonPhone, Status = mzkTask.parmStatus, StatusDueDate = mzkTask.parmStatusDueDate, RegistrationNumber = mzkTask.parmRegNo, AllocatedTo = mzkTask.parmUserID, MakeModel = mzkTask.parmMake + Environment.NewLine + mzkTask.parmModel, CaseCategoryRecID = mzkTask.parmCaseCategoryRecID, DeliveryDate = mzkTask.parmDeliveryDateTime, EmailId = mzkTask.parmCustomerEmail, CustPartyId = mzkTask.parmCustPartyId, CaseRecID = mzkTask.parmCaseRecID, CaseServiceRecID = mzkTask.parmCaseServiceRecID, TaskType = (CDTaskType)Enum.Parse(typeof(CDTaskType), mzkTask.parmCollectDeliverType.ToString()), CustomerId = mzkTask.parmCustAccount, ServiceId = mzkTask.parmServiceId, ServiceRecID = mzkTask.parmServiceRecID, UserID = _userInfo.UserId, SerialNumber = mzkTask.parmSerialNumber, ContactName = mzkTask.parmContactPersonName, ContactPersonAddress = mzkTask.parmContactPersonAddress, DocumentType = mzkTask.parmDocuTypeID, DocumentName = mzkTask.parmDocuName, }; taskInsertList.Add(taskTosave); caseCategoryRecIdList.Add(mzkTask.parmCaseCategoryRecID); await this.GetCustomerListFromSvcAsync(mzkTask.parmCustAccount); } await SqliteHelper.Storage.DropnCreateTableAsync <CollectDeliveryTask>(); await SqliteHelper.Storage.InsertAllAsync(taskInsertList); } await GetCollectedFromSvcAsync(); } catch (Exception ex) { this.SendMessageToUIThread(ex.Message); } return(taskInsertList); }