public PurchaseOrderOtherAccureModel(IssueFinancialOtherAccrual otherAccrual, List<SystemReference> wbsElements, List<Vendor> vendors, AddEditPurchaseOrderDialog view)
 {
     mOtherAccrual = otherAccrual;
     mVendors = vendors;
     mWbsElements = wbsElements;
     mView = view;
 }
Ejemplo n.º 2
0
        public PurchaseOrderViewModel(int issueId, DateTime date,AddEditPurchaseOrderDialog view, bool canUserModifyData)
        {
            View = view;
            mCanUserModifyData = canUserModifyData;
            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteAddButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CalcelButtonHandler, x => true);
            View.Title = String.Format("Accruals ({0:MMM yy})", date);
            PurchaseOrders = new List<PurchaseOrderAccureModel>();
            FinancialActuals = new List<FinancialActual>();
            OtherAccruals = new ObservableCollection<PurchaseOrderOtherAccureModel>();
            mDate = date;

            AddButtonCommand = new DelegateCommand<object>(AddButtonCommandHandler, CanExecuteAddButtonHandler);
            RemoveButtonCommand = new DelegateCommand<object>(RemoveButtonCommandHandler, CanExecuteAddButtonHandler);

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            {
                cmsWebServiceClient.GetIssueOpenPurchaseOrdersCompleted += (s1, e1) =>
                {
                    var openPurchaseOrders = e1.Result;

                    if (openPurchaseOrders == null) { view.DataContext = this; return;}

                    cmsWebServiceClient.GetAccrualsCompleted += (s2, e2) =>
                    {
                        var accruals = e2.Result;

                        foreach (var openPurchaseOrder in openPurchaseOrders)
                        {
                            FinancialAccrual accrual = (from x in accruals
                                where
                                    x.PoNumber == openPurchaseOrder.PoNumber &&
                                    x.Date.Year == date.Year &&
                                    x.Date.Month == date.Month &&
                                    x.ReferenceItem == openPurchaseOrder.ReferenceItem &&
                                    x.WbsElement == openPurchaseOrder.WbsElement &&
                                    x.CostElement == openPurchaseOrder.CostElement
                                select x).FirstOrDefault();

                            if (accrual == null)
                            {
                                accrual = new FinancialAccrual
                                {
                                    PoNumber = openPurchaseOrder.PoNumber,
                                    Date = date,
                                    ReferenceItem = openPurchaseOrder.ReferenceItem,
                                    WbsElement = openPurchaseOrder.WbsElement,
                                    LastModifiedDate = DateTime.Now,
                                    LastModifiedById = CMS.User.Id
                                };
                            }

                            var purchaseOrder = new PurchaseOrderAccureModel(openPurchaseOrder, accrual, view);

                            //Find Accrued last Month
                            var lastMonthDate = date.AddMonths(-1);
                            FinancialAccrual lastMonthAccrual = (from x in accruals
                                where
                                    x.PoNumber == openPurchaseOrder.PoNumber &&
                                    x.Date.Year == lastMonthDate.Year &&
                                    x.Date.Month == lastMonthDate.Month &&
                                    x.ReferenceItem == openPurchaseOrder.ReferenceItem &&
                                    x.WbsElement == openPurchaseOrder.WbsElement &&
                                    x.CostElement == openPurchaseOrder.CostElement
                                select x).FirstOrDefault();

                            if (lastMonthAccrual != null) purchaseOrder.AccruedLastMonth = lastMonthAccrual.AmountAccrued;

                            PurchaseOrders.Add(purchaseOrder);
                        }
                        view.DataContext = this;

                        LoadOtherFinancialAccruals(issueId, date);
                        LoadFinancialActuals(issueId, date);

                    };
                    cmsWebServiceClient.GetAccrualsAsync(issueId);
                };
                cmsWebServiceClient.GetIssueOpenPurchaseOrdersAsync(issueId);
            }
        }
        private void OpenPurchaseOrderCommandHandler(object parameter)
        {
            if (CanExecuteOkButtonHandler(parameter))
            {
                var model = parameter as IssueFinancialTableViewModel;

                AddEditPurchaseOrderDialog dialog = new AddEditPurchaseOrderDialog(mFinancial.IssueId, model.Date, CanUserModifyAccruals());
                dialog.Show();
                dialog.Closed += (sender, args) =>
                {
                    if (dialog.DialogResult.HasValue && dialog.DialogResult == true)
                    {
                        Accrual = dialog.AccrualSum;
                        mFinancial.LastModifiedDate = DateTime.Now;
                        mFinancial.LastImportedById = CMS.User.Id;

                        RaisePropertyChanged("Accrual");

                        RaisePropertyChanged("ActualVsForecastPercentage");
                        RaisePropertyChanged("ActualVsForecastVarianceColour");
                        RaisePropertyChanged("ActualVsForecastCode");

                        RaisePropertyChanged("ActualVsBaselinePercentage");
                        RaisePropertyChanged("ActualVsBaselineVarianceColour");
                        RaisePropertyChanged("ActualVsBaselineCode");

                        mView.UpdateForecastTotal();
                    }
                };
            }
        }
Ejemplo n.º 4
0
 public PurchaseOrderAccureModel(FinancialOpenPurchaseOrder openPurchaseOrder, FinancialAccrual accrual, AddEditPurchaseOrderDialog view)
 {
     mOpenPurchaseOrder = openPurchaseOrder;
     mAccrual = accrual;
     mView = view;
 }