changement de candidat à l'investissement

This commit is contained in:
Paul Schneider 2017-01-26 11:04:03 +01:00
commit be3087fff6
351 changed files with 359 additions and 497 deletions

View file

@ -0,0 +1,199 @@
using BookAStar.Attributes;
using BookAStar.Interfaces;
using BookAStar.Model.Workflow;
using BookAStar.ViewModels.Validation;
using System;
using System.Globalization;
using System.Windows.Input;
using System.ComponentModel;
namespace BookAStar.ViewModels.EstimateAndBilling
{
public class BillingLineViewModel : EditingViewModel<BillingLine>, IBillingLine
{
public ICommand RemoveCommand { get; set; }
public ICommand ValidateCommand { set; get; }
public BillingLineViewModel(BillingLine data): base(data)
{
CheckCommand = new Action<BillingLine, ModelState>(
(l,s) => {
if (string.IsNullOrWhiteSpace(l.Description))
{
s.AddError("Description",Strings.NoDescription);
}
if (l.UnitaryCost < 0) { s.AddError("UnitaryCost", Strings.InvalidValue); }
if (l.Count < 0) { s.AddError("Count", Strings.InvalidValue); }
});
SyncData();
}
private void SyncData()
{
if (Data != null)
{
// set durationValue, durationUnit
Duration = Data.Duration;
// other redondant representation
count = Data.Count;
description = Data.Description;
unitaryCostText = Data.UnitaryCost.ToString("G", CultureInfo.InvariantCulture);
}
CheckCommand(Data, ViewModelState);
}
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.PropertyName=="Data")
{
SyncData();
}
}
private int count;
public int Count
{
get
{
return count;
}
set
{
SetProperty<int>(ref count, value);
Data.Count = count;
}
}
private string description;
public string Description
{
get
{
return description;
}
set
{
SetProperty<string>(ref description, value);
Data.Description = description;
}
}
decimal unitaryCost;
public decimal UnitaryCost
{
get
{
return unitaryCost;
}
set
{
SetProperty<decimal>(ref unitaryCost, value);
Data.UnitaryCost = unitaryCost;
}
}
protected int durationValue;
public int DurationValue
{
get
{
return durationValue;
}
set
{
SetProperty<int>(ref durationValue, value, "DurationValue");
Data.Duration = this.Duration;
}
}
public enum DurationUnits : int
{
Jours = 0,
Heures = 1,
Minutes = 2
}
private DurationUnits durationUnit;
[Display(Name = "Unité de temps", Description = @"Unité de temps utiliée
pour décrire la quantité de travail associée à ce type de service")]
public DurationUnits DurationUnit
{
get
{
return durationUnit;
}
set
{
SetProperty<DurationUnits>(ref durationUnit, value, "DurationUnit");
Data.Duration = this.Duration;
}
}
public static readonly string unitCostFormat = "0,.00";
string unitaryCostText;
public string UnitaryCostText
{
get
{
return unitaryCostText;
}
set
{
SetProperty<string>(ref unitaryCostText, value, "UnitaryCostText");
// TODO update behavior
decimal test;
if (decimal.TryParse(value, NumberStyles.Currency, CultureInfo.InvariantCulture, out test))
{
this.UnitaryCost = test;
}
}
}
public TimeSpan Duration
{
get
{
switch (DurationUnit)
{
case DurationUnits.Heures:
return new TimeSpan(DurationValue, 0, 0);
case DurationUnits.Jours:
return new TimeSpan(DurationValue * 24, 0, 0);
case DurationUnits.Minutes:
return new TimeSpan(0, DurationValue, 0);
// Assert(false); since all units are treated bellow
default:
return new TimeSpan(0, 0, DurationValue);
}
}
set
{
double days = value.TotalDays;
if (days >= 1.0)
{
DurationValue = (int)days;
DurationUnit = DurationUnits.Jours;
return;
}
double hours = value.TotalHours;
if (hours >= 1.0)
{
DurationValue = (int)hours;
DurationUnit = DurationUnits.Jours;
return;
}
DurationValue = (int)value.TotalMinutes;
DurationUnit = DurationUnits.Minutes;
}
}
}
}

View file

@ -0,0 +1,34 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace BookAStar.ViewModels.EstimateAndBilling
{
using Data;
using Model;
using System.Linq;
public class BookQueriesViewModel : XLabs.Forms.Mvvm.ViewModel
{
public BookQueriesViewModel()
{
queries = new ObservableCollection<BookQueryViewModel>
(DataManager.Instance.BookQueries.Select(
q =>
new BookQueryViewModel(q)));
}
private ObservableCollection<BookQueryViewModel> queries;
public ObservableCollection<BookQueryViewModel> Queries
{
get
{
return queries;
}
}
public ICommand RefreshQueries
{
get; set;
}
}
}

View file

@ -0,0 +1,105 @@

using System;
using System.Diagnostics;
using XLabs.Forms.Mvvm;
namespace BookAStar.ViewModels.EstimateAndBilling
{
using Data;
using Helpers;
using Interfaces;
using Model;
using Model.Social;
using Model.Workflow;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;
public class BookQueryViewModel : ViewModel, IBookQueryData
{
public BookQueryViewModel()
{
}
public BookQueryViewModel(BookQuery data)
{
Debug.Assert(data != null);
Client=data.Client;
Location = data.Location;
EventDate = data.EventDate;
Previsionnal = data.Previsionnal;
Id = data.Id;
estimates = new ObservableCollection<Estimate>(
DataManager.Instance.Estimates.Where(
e => e.Query.Id == Id
));
this.data = data;
}
private BookQuery data;
public BookQuery Data {
get
{
return data;
}
}
public ClientProviderInfo Client { get; set; }
public ImageSource Avatar
{
get
{
return UserHelpers.Avatar(Client.Avatar);
}
}
public ImageSource SmallAvatar
{
get
{
return UserHelpers.SmallAvatar(Client.Avatar, Client.UserName);
}
}
public Location Location { get; set; }
public long Id { get; set; }
public DateTime EventDate { get; set; }
public decimal? Previsionnal { get; set; }
public EditEstimateViewModel DraftEstimate
{
get
{
return DataManager.Instance.EstimationCache.LocalGet(this.Id);
}
}
private ObservableCollection<Estimate> estimates;
public ObservableCollection<Estimate> Estimates {
get {
return estimates;
} }
public bool EstimationDone
{
get
{
return Estimates != null && Estimates.Count>0;
}
}
public string EditEstimateButtonText
{
get
{
return DraftEstimate != null ?
Strings.EditEstimate : Strings.DoEstimate;
}
}
bool rejected = false;
public bool Rejected { get
{
return rejected;
}
set
{
SetProperty<bool>(ref rejected, value);
}
}
}
}

View file

@ -0,0 +1,159 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Xamarin.Forms;
using Newtonsoft.Json;
using System.Linq;
using System.ComponentModel;
namespace BookAStar.ViewModels.EstimateAndBilling
{
using Model;
using Model.Workflow;
using Model.Social;
using Validation;
public class EditEstimateViewModel : EditingViewModel<Estimate>
{
/// <summary>
/// Builds a new view model on estimate,
/// sets <c>Data</c> with given value parameter
/// </summary>
/// <param name="data"></param>
/// <param name="localState"></param>
public EditEstimateViewModel(Estimate data) : base(data)
{
SyncData();
}
public override void OnViewAppearing()
{
base.OnViewAppearing();
SyncData();
}
/// <summary>
/// Called to synchronyze this view on target model,
/// at accepting a new representation for this model
/// </summary>
private void SyncData()
{
if (Data.AttachedFiles == null) Data.AttachedFiles = new List<string>();
if (Data.AttachedGraphics == null) Data.AttachedGraphics = new List<string>();
if (Data.Bill == null) Data.Bill = new List<BillingLine>();
AttachedFiles = new ObservableCollection<string>(Data.AttachedFiles);
AttachedGraphicList = new ObservableCollection<string>(Data.AttachedGraphics);
Bill = new ObservableCollection<BillingLineViewModel>(Data.Bill.Select(
l => new BillingLineViewModel(l)
));
Bill.CollectionChanged += Bill_CollectionChanged;
Title = Data.Title;
Description = Data.Description;
NotifyPropertyChanged("FormattedTotal");
NotifyPropertyChanged("Query");
NotifyPropertyChanged("CLient");
NotifyPropertyChanged("ModelState");
}
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.PropertyName.StartsWith("Data"))
{
SyncData();
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Bill_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
Data.Bill = Bill.Select(l => l.Data).ToList();
NotifyPropertyChanged("FormattedTotal");
NotifyPropertyChanged("Bill");
NotifyPropertyChanged("ViewModelState");
}
[JsonIgnore]
public ObservableCollection<string> AttachedFiles
{
get; protected set;
}
[JsonIgnore]
public ObservableCollection<string> AttachedGraphicList
{
get; protected set;
}
[JsonIgnore]
public ObservableCollection<BillingLineViewModel> Bill
{
get; protected set;
}
[JsonIgnore]
private string description;
public string Description
{
get
{
return description;
}
set
{
SetProperty<string>(ref description, value);
Data.Description = description;
}
}
private string title;
[JsonIgnore]
public string Title
{
get
{
return title;
}
set
{
SetProperty<string>(ref title, value, "Title");
Data.Title = title;
}
}
[JsonIgnore]
public ClientProviderInfo Client { get { return Data.Client; } }
[JsonIgnore]
public BookQuery Query { get { return Data.Query; } }
[JsonIgnore]
public FormattedString FormattedTotal
{
get
{
/*
OnPlatform<Font> lfs = (OnPlatform<Font>)App.Current.Resources["MediumFontSize"];
*/
OnPlatform<double> mfs = (OnPlatform < double > ) App.Current.Resources["MediumFontSize"];
Color etc = (Color) App.Current.Resources["EmphasisTextColor"];
return new FormattedString
{
Spans = {
new Span { Text = "Total TTC: " },
new Span { Text = Data.Total.ToString(),
ForegroundColor = etc,
FontSize = mfs },
new Span { Text = "€", FontSize = mfs }
}
};
}
}
}
}