123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using InABox.Core;
- using Comal.Classes;
- using InABox.Clients;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using comal.timesheets.QAForms;
- using InABox.Mobile;
- using LogType = InABox.Core.LogType;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class LeaveRequestList
- {
- DateTime lastFrom = DateTime.MinValue;
- DateTime lastTo = DateTime.MinValue;
- List<LeaveRequestShell> leaveRequestShells = new List<LeaveRequestShell>();
- public LeaveRequestList()
- {
- InitializeComponent();
- //if (ClientFactory.IsAllowed<CanViewPublicHolidaysOnMobile>())
- //{
- // publicHolidaysLbl.IsVisible = true;
- // showPublicHolidaysCb.IsVisible = true;
- //}
- }
- protected override void OnAppearing()
- {
- Title = "Loading";
- Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID).And(x => x.From).IsGreaterThanOrEqualTo(DateTime.Today)
- .And(x => x.LeaveType.Code).IsNotEqualTo("92");
- LoadList(filter);
- base.OnAppearing();
- }
- private async void LoadList(Filter<LeaveRequest> filter)
- {
- await Task.Run(() =>
- {
- leaveRequestShells.Clear();
- CoreTable table = QueryLeaveRequests(filter);
- while (table == null)
- table = QueryLeaveRequests(filter);
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- if (!CheckDuplicates(row))
- {
- LeaveRequestShell leaveRequestShell = new LeaveRequestShell()
- {
- ID = row.Get<LeaveRequest, Guid>(x => x.ID),
- From = row.Get<LeaveRequest, DateTime>(x => x.From).ToString("dd MMM yy"),
- To = row.Get<LeaveRequest, DateTime>(x => x.To).ToString("dd MMM yy"),
- Type = row.Get<LeaveRequest, string>(x => x.LeaveType.Description),
- ApprovalNotes = row.Get<LeaveRequest, string>(x => x.StatusNotes),
- Approval = row.Get<LeaveRequest, LeaveRequestStatus>(x => x.Status).ToString(),
- LeaveCode = row.Get<LeaveRequest, string>(x => x.LeaveType.Code),
- };
- if (leaveRequestShell.Approval == "InProgress")
- {
- leaveRequestShell.Approval = "Pending";
- }
- lastFrom = row.Get<LeaveRequest, DateTime>(x => x.From);
- lastTo = row.Get<LeaveRequest, DateTime>(x => x.To);
- leaveRequestShell = ChooseColour(leaveRequestShell);
- leaveRequestShells.Add(leaveRequestShell);
- }
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- leaveRequestList.ItemsSource = null;
- leaveRequestList.ItemsSource = leaveRequestShells;
- Title = "Leave Requests";
- });
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- leaveRequestList.ItemsSource = null;
- Title = "Requests (0)";
- });
- }
- });
- }
- private bool CheckDuplicates(CoreRow row)
- {
- if (row.Get<LeaveRequest, DateTime>(x => x.From) == lastFrom && row.Get<LeaveRequest, DateTime>(x => x.To) == lastTo)
- return true;
- return false;
- }
- private CoreTable QueryLeaveRequests(Filter<LeaveRequest> filter)
- {
- try
- {
- return new Client<LeaveRequest>().Query
- (
- filter,
- new Columns<LeaveRequest>(
- x => x.ID, //0
- x => x.From, //1
- x => x.To, //2
- x => x.LeaveType.Description, //3
- x => x.Status, //4
- x => x.LeaveType.Code, //5
- x => x.StatusNotes //6
- ),
- new SortOrder<LeaveRequest>(x => x.To, SortDirection.Descending)
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private async void Add_Clicked(object sender, EventArgs e)
- {
- //.And(x => x.Form.Secure).IsEqualTo(true)
- CoreTable table = QueryDigitalFormLayout();
- while (table == null)
- table = QueryDigitalFormLayout();
- if (table.Rows.Any())
- {
- List<string> layoutNamesList = new List<string>();
- List<DigitalFormLayout> layouts = new List<DigitalFormLayout>();
- foreach (CoreRow row in table.Rows)
- {
- DigitalFormLayout layout = row.ToObject<DigitalFormLayout>();
- layoutNamesList.Add(layout.Description);
- layouts.Add(layout);
- }
- string[] namesArray = layoutNamesList.ToArray();
- string chosenOption = await DisplayActionSheet("Choose Leave Form", "Cancel", null, namesArray);
- if (string.IsNullOrWhiteSpace(chosenOption))
- return;
- if (chosenOption == "Cancel")
- return;
- DigitalFormLayout digitalFormLayout = layouts.Find(x => x.Description.Equals(chosenOption));
- DigitalFormHostModel<LeaveRequest, LeaveRequestLink, LeaveRequestForm> model = new DigitalFormHostModel<LeaveRequest, LeaveRequestLink, LeaveRequestForm>();
- LeaveRequest request = new LeaveRequest();
- LeaveRequestForm leaveform = new LeaveRequestForm();
- leaveform.Form.ID = digitalFormLayout.Form.ID;
- model.LoadItems(request, leaveform, digitalFormLayout);
- DigitalFormHost host = new DigitalFormHost(model);
- Navigation.PushAsync(host);
- }
- else
- {
- DisplayAlert("Alert", "No Leave Forms Found", "OK");
- }
- }
- private CoreTable QueryDigitalFormLayout()
- {
- try
- {
- return new Client<DigitalFormLayout>().Query
- (
- new Filter<DigitalFormLayout>
- (
- x => x.Type).IsEqualTo(DFLayoutType.Mobile)
- .And(x => x.Active).IsEqualTo(true)
- .And(x => x.Form.Active).IsEqualTo(true)
- .And(x => x.Form.AppliesTo).IsEqualTo("LeaveRequest")
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void LeaveRequestList_Tapped(object sender, EventArgs e)
- {
- LeaveRequestShell leaveRequestShell = leaveRequestList.SelectedItem as LeaveRequestShell;
- string message = "No notes currently";
- if (!string.IsNullOrWhiteSpace(leaveRequestShell.ApprovalNotes))
- {
- message = leaveRequestShell.ApprovalNotes;
- }
- DisplayAlert("Leave Request Approval Notes:", message, "OK");
- }
- private LeaveRequestShell ChooseColour(LeaveRequestShell leaveRequestShell)
- {
- switch (leaveRequestShell.LeaveCode)
- {
- case "89": //Maternity
- leaveRequestShell.Color = Color.FromHex("#ffe4e1"); //mistyrose / pink
- break;
- case "90": //Compassionate
- leaveRequestShell.Color = Color.FromHex("#add8e6"); //light blue
- break;
- case "91": //Workers comp
- leaveRequestShell.Color = Color.FromHex("#c9ffe51"); //aero blue
- break;
- case "92": //Public Holiday
- leaveRequestShell.Color = Color.FromHex("#ffef00"); //yellow
- break;
- case "93": //Long service
- leaveRequestShell.Color = Color.FromHex("#ffc0cb"); //pink
- break;
- case "94": //Unpaid
- leaveRequestShell.Color = Color.FromHex("#f4a460"); //brown
- break;
- case "95": //Work Travel
- leaveRequestShell.Color = Color.FromHex("#7b68ee"); //medium slate blue
- break;
- case "96": //Training
- leaveRequestShell.Color = Color.FromHex("#7b68ee"); //medium slate blue
- break;
- case "97": //Sick
- leaveRequestShell.Color = Color.FromHex("#db7093"); //pale violet
- break;
- case "98": //RDO
- leaveRequestShell.Color = Color.FromHex("#cd853f"); //brown
- break;
- case "99": //Annual
- leaveRequestShell.Color = Color.FromHex("#7df9ff"); //electric blue
- break;
- default:
- break;
- }
- if (leaveRequestShell.Approval == "No")
- {
- leaveRequestShell.Color = Color.FromHex("#ff4040"); //red
- }
- return leaveRequestShell;
- }
- private void ShowAllCb_Changed(object sender, EventArgs e)
- {
- ChooseList();
- }
- private void ShowPublicHolidaysCb_Changed(object sender, EventArgs e)
- {
- ChooseList();
- }
- private void ChooseList()
- {
- //if (ClientFactory.IsAllowed<CanViewPublicHolidaysOnMobile>())
- //{
- if (showPublicHolidaysCb.IsChecked)
- {
- if (showAllCb.IsChecked)
- {
- Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID);
- LoadList(filter);
- }
- else
- {
- Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID).And(x => x.From).IsGreaterThanOrEqualTo(DateTime.Today);
- LoadList(filter);
- }
- }
- else
- {
- if (showAllCb.IsChecked)
- {
- Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID).And(x => x.LeaveType.Code).IsNotEqualTo("92");
- LoadList(filter);
- }
- else
- {
- Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID).And(x => x.From).IsGreaterThanOrEqualTo(DateTime.Today)
- .And(x => x.LeaveType.Code).IsNotEqualTo("92");
- LoadList(filter);
- }
- }
- // }
- // else
- // {
- //if (showAllCb.IsChecked)
- //{
- // Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Employee.ID).And(x => x.LeaveType.Code).IsNotEqualTo("92");
- // LoadList(filter);
- //}
- //else
- //{
- // Filter<LeaveRequest> filter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Employee.ID).And(x => x.From).IsGreaterThanOrEqualTo(DateTime.Today)
- // .And(x => x.LeaveType.Code).IsNotEqualTo("92");
- // LoadList(filter);
- //}
- // }
- }
- }
- public class LeaveRequestShell
- {
- public Guid ID { get; set; }
- public string Type { get; set; }
- public string To { get; set; }
- public string From { get; set; }
- public string Approval { get; set; }
- public string LeaveCode { get; set; }
- public Color Color { get; set; }
- public string ApprovalNotes { get; set; }
- public LeaveRequestShell()
- {
- ID = Guid.Empty;
- Type = "";
- To = "";
- From = "";
- Approval = "";
- LeaveCode = "";
- Color = Color.Default;
- ApprovalNotes = "";
- }
- }
- }
|