Пример #1
0
        public int CreateBill(Bill bill, IList <BillingItem> billingItems)
        {
            try
            {
                bill.CreatedDate = DateTime.Now;
                Bills.Add(bill);
                //SaveChanges();

                foreach (var item in billingItems)
                {
                    //item.BillingItemId = 0;
                    item.CreatedDate = DateTime.Now;

                    item.Bill   = bill;
                    item.BillId = bill.BillId;
                    BillingItems.Add(item);
                }

                SaveChanges();

                return(bill.BillId);
            }catch (Exception ex)
            {
                throw;
            }
            return(0);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        private void Save()
        {
            bool wasNew = bill == null;

            if (bill == null)
            {
                bill = new Bill();
                Bills.Add(bill);
            }
            bill.TotalUsedKWh             = tbTotalUsedkWh.Value;
            bill.TotalPriceElectricity    = tbTotalPriceElectricity.Value;
            bill.TotalPriceGroundFee      = tbTotalGroundFee.Value;
            bill.GuestLastReadingKWh      = tbGuestLastReadingkWh.Value;
            bill.GuestCurrentReadingKWh   = tbGuestCurrentReadingkWh.Value;
            bill.GuestLastReadingTicks    = dpGuestLastReading.Value.Ticks;
            bill.GuestCurrentReadingTicks = dpGuestCurrentReading.Value.Ticks;
            bill.GuestPartInGroundFee     = cbFeePart.SelectedIndex;
            bill.OCR = tbOCR.Text;
            try {
                TE(false);
                SaveBill(bill);
            } catch (Exception ex) {
                MessageBox.Show(string.Format("Error saving bill: {0}", ex.Message));
            } finally {
                TE(true);
            }
            //Bills.Save();
            if (wasNew)
            {
                int ind = cbPreviousBills.Items.Add(bill);
                cbPreviousBills.SelectedIndex = ind;
            }
            changed = false;
        }
Пример #3
0
		async Task ExecuteLoadUsersCommand()
		{
			if (IsBusy)
				return;

			IsBusy = true;

			try
			{
				Bills.Clear();
				var bills = await App.Database.GetCurrentBillsByUserIdAsync(SelectedUserId);

				foreach (var bill in bills)
				{
					Bills.Add(bill);
				}
			}
			catch (Exception e)
			{
				Debug.WriteLine(e);
			}
			finally
			{
				IsBusy = false;
			}
		}
Пример #4
0
        public void AddBill(string paymentTo, decimal billAmount, DateTime dueDate)
        {
            if (OrderStatus != OrderStatus.Placed)
            {
                throw new OrderAlreadyProcessedException(OrderNumber);
            }

            var totalBilledAmount = Bills.Sum(x => x.BillAmount) + billAmount;

            if (totalBilledAmount > OrderAmount)
            {
                throw new TotalBillAmountExceedsOrderAmountException(OrderNumber);
            }

            if (string.IsNullOrEmpty(paymentTo))
            {
                throw new СounterpartyBillingDetailRequiredException(OrderNumber);
            }

            if (billAmount <= 0)
            {
                throw new AmountLessThanOrEqualToZeroException("billAmount", OrderNumber);
            }

            Bills.Add(new Bill()
            {
                PaymentTo  = paymentTo,
                BillAmount = billAmount,
                DueDate    = dueDate,
                Created    = DateTime.UtcNow,
                OrderId    = OrderId
            });
        }
Пример #5
0
        private async Task LoadData()
        {
            var bills = await BudgetDatabase.GetBills();

            var data = (bills)
                       .Where(x => x.Date >= StartDate)
                       .Where(x => x.Date <= EndDate)
                       .Where(x => x.AccountId == BankAccount.AccountId)
                       .OrderBy(x => x.Date)
                       .Select(bill => bill).ToList();

            billList = new List <Bill>(data);
            Bills.Clear();
            foreach (var item in billList)
            {
                Bills.Add(new BillViewModel(item));
            }

            await UpdateCalculations();

            //var bal = await BudgetDatabase.GetLatestBalance(BankAccount.AccountID, StartDate);
            //StartingBalance = bal.Amount;
            //var billTotal = 0.0;
            //foreach (var bill in billList)
            //{
            //    billTotal += bill.Amount;
            //}

            //DateRangeTotal = billTotal;
            //EndingBalance = StartingBalance - DateRangeTotal;
        }
        private void BTN_NewBill(object sender, RoutedEventArgs e)
        {
            Bill_Creation BC = new Bill_Creation(_DBConnection);

            BC.Owner = this;
            BC.ShowDialog();

            if (BC.Result == BillCreationResult.Create)
            {
                _DBConnection.DB_InsertBill(BC.Bill);
                Bills.Add(BC.Bill);
                RefreshBillListItems();
                CalculateReviews();
            }
        }
Пример #7
0
        //public AgendaEntryViewModel(Grouping<DateTime, Bill> datagroup )
        //{
        //    Date = datagroup.Key;
        //    foreach (var item in datagroup)
        //    {
        //        Bills.Add(new BillViewModel(item));
        //    }

        //    MessagingCenter.Subscribe<AgendaBillViewModel>(this, "UpdateTotal", async (obj) => OnUpdateTotal());

        //    //MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
        //    //{
        //    //    var newItem = item as Item;
        //    //    Items.Add(newItem);
        //    //    await DataStore.AddItemAsync(newItem);
        //    //});
        //}

        public AgendaEntryViewModel(Grouping <DateTime, Bill> datagroup)
        {
            Date = datagroup.Key;
            foreach (var item in datagroup)
            {
                Bills.Add(new BillViewModel(item));
            }

            //MessagingCenter.Subscribe<AgendaBillViewModel>(this, "UpdateTotal", async (obj) => OnUpdateTotal());

            //MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
            //{
            //    var newItem = item as Item;
            //    Items.Add(newItem);
            //    await DataStore.AddItemAsync(newItem);
            //});
        }
Пример #8
0
        public async void AddBill()
        {
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(BillToAdd.GetObject()));

            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
            var response    = await Dal.PostAsync(RestUrl, httpContent);

            if (response.IsSuccessStatusCode)
            {
                Bills.Add(BillToAdd);
                RaisePropertyChanged("AddBill");
                Revenue += BillToAdd.Car.Price - BillToAdd.Discount;
                RaisePropertyChanged("Revenue");
                RaisePropertyChanged("Caluclate");
                BillToAdd = new Bill();
                RaisePropertyChanged("BillToAdd");
            }
        }
Пример #9
0
        private void ImportFromExcel(object sender, EventArgs eventArgs)
        {
            if (changed)
            {
                DialogResult dr = MessageBox.Show(this, string.Format("Vill du spara dina ändringar?{0}Det kommer att gå förlorade annars!", Environment.NewLine), "Spara ändringar", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }
                if (dr == DialogResult.Yes)
                {
                    Save();
                }
            }
            changed = false;
            OpenFileDialog of = new OpenFileDialog {
                AutoUpgradeEnabled = true, Filter = "Excel 2007-2010|*.xlsx|Excel 97-2003|*.xls", CheckFileExists = true, Multiselect = false
            };

            if (of.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            ExcelParsedFile file = ExcelParsedFile.Load(of.FileName, 0);

            while (file.MoveNext())
            {
                Bill b = new Bill {
                    TotalUsedKWh          = file.GetDouble(0),
                    TotalPriceElectricity = file.GetDouble(1),
                    TotalPriceGroundFee   = file.GetDouble(2),
                    OCR = file.GetString(3),
                    GuestLastReadingTicks    = file.GetDateTime(4).Ticks,
                    GuestLastReadingKWh      = file.GetDouble(5),
                    GuestCurrentReadingTicks = file.GetDateTime(6).Ticks,
                    GuestCurrentReadingKWh   = file.GetDouble(7),
                    GuestPartInGroundFee     = file.GetInt(8)
                };
                SaveBill(b);
                Bills.Add(b);
            }
            LoadBills();
        }
Пример #10
0
        /// <summary>
        /// Restock a particular bill type in the teller machine.
        /// </summary>
        /// <param name="type">Bill type to be restocked.</param>
        private void Restock(Type type)
        {
            if (!Register.ContainsKey(type))
            {
                throw new ArgumentOutOfRangeException("Teller does not contain " + Convert.ToString(type) + " bills.");
            }

            int billCount   = 0;
            int billsNeeded = 0;

            billCount = Bills.Where(bill => bill.GetType() == type).Count();

            billsNeeded = Register[type] - billCount;

            if (billsNeeded > 0)
            {
                for (int i = 0; i < billsNeeded; i++)
                {
                    Bills.Add(((BillBase)Activator.CreateInstance(type)));
                }
            }
        }
Пример #11
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                Bills.Clear();
                var items = await DataStore.GetBillsAsync(true);

                foreach (var item in items)
                {
                    Bills.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #12
0
        private async void Update()
        {
            var bills = await IoC.API.BillsByMemberAsync(_Member.ID);

            if (bills.Any())
            {
                Bills.Clear();
                for (var i = 0; i < 5; i++)
                {
                    Bills.Add(new BillViewModel(bills[i]));
                }
            }

            var votes = await IoC.API.VotesByMemberAsync(_Member.ID);

            if (votes.Any())
            {
                Votes.Clear();
                for (var i = 0; i < 5; i++)
                {
                    Votes.Add(new VoteViewModel(votes[i]));
                }
            }
        }
        private async Task GetBills()
        {
            if (SelectedAccount != null)
            {
                //var billcall = await BudgetDatabase.GetBills();

                //var billData = billcall
                //    .Where(x => x.Date >= StartDate)
                //    .Where(x => x.Date <= EndDate)
                //    .Where(x => x.BankAccount.Nickname.Equals(SelectedAccount))
                //    .OrderBy(x => x.Date).ToList();

                var billData = await BudgetDatabase.GetBillsDateRangeForAccount(StartDate, EndDate, SelectedAccount);

                //var billData = billCall;
                Bills.Clear();
                foreach (var bill in billData)
                {
                    Bills.Add(new BillViewModel(bill));
                }

                await UpdateCalculations();
            }
        }
Пример #14
0
        public InventoryReportViewPageViewModel(INavigationService navigationService,
                                                IGlobalService globalService,
                                                IDialogService dialogService,
                                                IAllocationService allocationService,
                                                IAdvanceReceiptService advanceReceiptService,
                                                IReceiptCashService receiptCashService,
                                                ICostContractService costContractService,
                                                ICostExpenditureService costExpenditureService,
                                                IInventoryService inventoryService,
                                                IPurchaseBillService purchaseBillService,
                                                IReturnReservationBillService returnReservationBillService,
                                                IReturnBillService returnBillService,
                                                ISaleReservationBillService saleReservationBillService,
                                                IWareHousesService wareHousesService,
                                                ISaleBillService saleBillService
                                                ) : base(navigationService, globalService, allocationService, advanceReceiptService, receiptCashService, costContractService, costExpenditureService, inventoryService, purchaseBillService, returnReservationBillService, returnBillService, saleReservationBillService, saleBillService, dialogService)
        {
            Title = "库存上报";

            _wareHousesService = wareHousesService;

            this.Load = ReactiveCommand.Create(async() =>
            {
                ItemTreshold = 1;
                PageCounter  = 0;

                try
                {
                    Bills?.Clear();
                    var pending = new List <InventoryReportSummaryModel>();

                    int?makeuserId     = Settings.UserId;
                    int?terminalId     = null;
                    int?businessUserId = null;
                    int?productId      = null;
                    int?channelId      = null;
                    int?rankId         = null;
                    int?districtId     = null;

                    string billNumber  = Filter.SerchKey;
                    DateTime?startTime = Filter.StartTime ?? DateTime.Now.AddMonths(-1);
                    DateTime?endTime   = Filter.EndTime ?? DateTime.Now;


                    var result = await _wareHousesService.GetInventoryReportAsync(makeuserId, businessUserId, terminalId, channelId, rankId, districtId, productId, startTime, endTime, 0, PageSize, this.ForceRefresh, new System.Threading.CancellationToken());


                    if (result != null)
                    {
                        pending = result?.Select(s =>
                        {
                            var sm    = s;
                            sm.IsLast = !(result?.LastOrDefault()?.BillNumber == s.BillNumber);
                            return(sm);
                        }).Where(s => s.MakeUserId == Settings.UserId || s.BusinessUserId == Settings.UserId).ToList();
                    }
                    if (pending.Any())
                    {
                        Bills = new System.Collections.ObjectModel.ObservableCollection <InventoryReportSummaryModel>(pending);
                    }


                    UpdateTitle();
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });


            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                int pageIdex = 0;
                if (Bills?.Count != 0)
                {
                    pageIdex = Bills.Count / (PageSize == 0 ? 1 : PageSize);
                }

                if (PageCounter < pageIdex)
                {
                    PageCounter = pageIdex;
                    using (var dig = UserDialogs.Instance.Loading("加载中..."))
                    {
                        try
                        {
                            int?makeuserId     = Settings.UserId;
                            int?terminalId     = null;
                            int?businessUserId = null;
                            int?productId      = null;
                            int?channelId      = null;
                            int?rankId         = null;
                            int?districtId     = null;

                            string billNumber  = Filter.SerchKey;
                            DateTime?startTime = Filter.StartTime ?? DateTime.Now.AddMonths(-1);
                            DateTime?endTime   = Filter.EndTime ?? DateTime.Now;


                            var result = await _wareHousesService.GetInventoryReportAsync(makeuserId, businessUserId, terminalId, channelId, rankId, districtId, productId, startTime, endTime, 0, PageSize, this.ForceRefresh, new System.Threading.CancellationToken());

                            if (result != null)
                            {
                                foreach (var item in result)
                                {
                                    if ((item.MakeUserId == Settings.UserId || item.BusinessUserId == Settings.UserId) && Bills.Count(s => s.Id == item.Id) == 0)
                                    {
                                        Bills.Add(item);
                                    }
                                }

                                foreach (var s in Bills)
                                {
                                    s.IsLast = !(Bills.LastOrDefault()?.BillNumber == s.BillNumber);
                                }
                            }

                            UpdateTitle();
                        }
                        catch (Exception ex)
                        {
                            Crashes.TrackError(ex);
                        }
                    }
                }
            }, this.WhenAny(x => x.Bills, x => x.GetValue().Count > 0));

            this.BindBusyCommand(Load);
        }
Пример #15
0
        public AllocationSummeryPageViewModel(INavigationService navigationService,
                                              IGlobalService globalService,
                                              IDialogService dialogService,
                                              IAllocationService allocationService,
                                              IAdvanceReceiptService advanceReceiptService,
                                              IReceiptCashService receiptCashService,
                                              ICostContractService costContractService,
                                              ICostExpenditureService costExpenditureService,
                                              IInventoryService inventoryService,
                                              IPurchaseBillService purchaseBillService,
                                              IReturnReservationBillService returnReservationBillService,
                                              IReturnBillService returnBillService,
                                              ISaleReservationBillService saleReservationBillService,

                                              ISaleBillService saleBillService
                                              ) : base(navigationService, globalService, allocationService, advanceReceiptService, receiptCashService, costContractService, costExpenditureService, inventoryService, purchaseBillService, returnReservationBillService, returnBillService, saleReservationBillService, saleBillService, dialogService)
        {
            Title = "调拨单";

            this.BillType = BillTypeEnum.AllocationBill;

            Filter.StartTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            Filter.EndTime   = DateTime.Now;

            this.Load = ReactiveCommand.Create(async() =>
            {
                //重载时排它
                ItemTreshold = 1;
                PageCounter  = 0;
                try
                {
                    DateTime?startTime = Filter.StartTime;
                    DateTime?endTime   = Filter.EndTime;
                    int?businessUserId = Filter.BusinessUserId;
                    int?customerId     = Filter.TerminalId;
                    string billNumber  = Filter.SerchKey;

                    int?makeuserId = Settings.UserId;
                    if (businessUserId.HasValue && businessUserId > 0)
                    {
                        makeuserId = 0;
                    }

                    int?shipmentWareHouseId = 0;
                    int?incomeWareHouseId   = 0;
                    //获取已审核
                    bool?auditedStatus     = true;
                    bool?showReverse       = null;
                    bool?sortByAuditedTime = null;

                    //清除列表
                    Bills?.Clear();

                    var items = await _allocationService.GetAllocationsAsync(makeuserId,
                                                                             businessUserId ?? 0,
                                                                             shipmentWareHouseId,
                                                                             incomeWareHouseId,
                                                                             billNumber,
                                                                             "",
                                                                             auditedStatus,
                                                                             startTime,
                                                                             endTime,
                                                                             showReverse,
                                                                             sortByAuditedTime,
                                                                             0,
                                                                             PageSize,
                                                                             this.ForceRefresh,
                                                                             new System.Threading.CancellationToken());

                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            if (Bills.Count(s => s.Id == item.Id) == 0)
                            {
                                Bills.Add(item);
                            }
                        }

                        if (items.Count() == 0 || items.Count() == Bills.Count)
                        {
                            ItemTreshold = -1;
                        }

                        foreach (var s in Bills)
                        {
                            s.IsLast = !(Bills.LastOrDefault()?.BillNumber == s.BillNumber);
                        }


                        if (Bills.Count > 0)
                        {
                            this.Bills = new ObservableRangeCollection <AllocationBillModel>(Bills);
                        }
                        UpdateTitle();
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });
            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                int pageIdex = 0;
                if (Bills?.Count != 0)
                {
                    pageIdex = Bills.Count / (PageSize == 0 ? 1 : PageSize);
                }

                if (PageCounter < pageIdex)
                {
                    PageCounter = pageIdex;
                    using (var dig = UserDialogs.Instance.Loading("加载中..."))
                    {
                        try
                        {
                            string billNumber  = Filter.SerchKey;
                            DateTime?startTime = Filter.StartTime;
                            DateTime?endTime   = Filter.EndTime;
                            int?businessUserId = Filter.BusinessUserId;
                            int?customerId     = Filter.TerminalId;

                            int?makeuserId = Settings.UserId;
                            if (businessUserId.HasValue && businessUserId > 0)
                            {
                                makeuserId = 0;
                            }

                            int?shipmentWareHouseId = 0;
                            int?incomeWareHouseId   = 0;
                            //获取已审核
                            bool?auditedStatus     = true;
                            bool?showReverse       = null;
                            bool?sortByAuditedTime = null;


                            var items = await _allocationService.GetAllocationsAsync(makeuserId, businessUserId ?? 0, shipmentWareHouseId, incomeWareHouseId, billNumber, "", auditedStatus, startTime, endTime, showReverse, sortByAuditedTime, pageIdex, PageSize, this.ForceRefresh, new System.Threading.CancellationToken());
                            if (items != null)
                            {
                                foreach (var item in items)
                                {
                                    if (Bills.Count(s => s.Id == item.Id) == 0)
                                    {
                                        Bills.Add(item);
                                    }
                                }

                                if (items.Count() == 0)
                                {
                                    ItemTreshold = -1;
                                }

                                foreach (var s in Bills)
                                {
                                    s.IsLast = !(Bills.LastOrDefault()?.BillNumber == s.BillNumber);
                                }
                                UpdateTitle();
                            }
                        }
                        catch (Exception ex)
                        {
                            Crashes.TrackError(ex);
                        }
                    }
                }
            }, this.WhenAny(x => x.Bills, x => x.GetValue().Count > 0));


            //选择单据
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async x =>
            {
                if (x != null)
                {
                    await NavigateAsync(nameof(AllocationBillPage), ("Bill", x));
                }
                this.Selecter = null;
            }).DisposeWith(DeactivateWith);

            //菜单选择
            this.SubscribeMenus((x) =>
            {
                //获取当前UTC时间
                DateTime dtime = DateTime.Now;
                switch (x)
                {
                case MenuEnum.TODAY:
                    {
                        Filter.StartTime = DateTime.Parse(dtime.ToString("yyyy-MM-dd 00:00:00"));
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.YESTDAY:
                    {
                        Filter.StartTime = dtime.AddDays(-1);
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.OTHER:
                    {
                        SelectDateRang();
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.SUBMIT30:
                    {
                        Filter.StartTime = dtime.AddMonths(-1);
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case Enums.MenuEnum.CLEARHISTORY:    //清空一个月历史单据
                    {
                        ClearHistory(() => _globalService.UpdateHistoryBillStatusAsync((int)this.BillType));
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;
                }
            }, string.Format(Constants.MENU_KEY, 4));

            this.BindBusyCommand(Load);
        }
Пример #16
0
        public override void AddBill()
        {
            decimal newBill = Utilities.ReadDecimal("Enter the value of the bill: ");

            Bills.Add(newBill);
        }
Пример #17
0
 internal override void AddBill(decimal bill)
 {
     Bills.Add(bill);
 }
Пример #18
0
 public void AddBill(Bill bill)
 {
     Bills.Add(bill);
 }
Пример #19
0
 public void AddBill(IBill bill, IAccount account)
 {
     AssignRecordIdToBill(bill);
     account.AddBill(bill);
     Bills.Add(bill);
 }
Пример #20
0
        //public BillGroupResult Validate(BillGenerateInput input) {

        //    var bg = (from BgItem in BillGroup
        //              where BgItem.Id == input.GroupId
        //              select BgItem).FirstOrDefault();
        //    if (bg != null)
        //    {
        //        var month = bg.BiMonthly ? 2 : 1;

        //    }
        //    return null;
        //}
        //public string AddBillGroupDetail(BillGenerateInput input)
        //{
        //    var month = Convert.ToInt32(input.MonthYear.Substring(0, 2));
        //    var year = Convert.ToInt32(input.MonthYear.Substring(2));
        //    var lastDay = DateTime.DaysInMonth(year, month);

        //    var bg = (from BgItem in BillGroup
        //              where BgItem.Id == input.GroupId
        //              select BgItem).FirstOrDefault();
        //    if (bg != null)
        //    {

        //    }

        //    return "";
        //}
        private void GenerateBillForUnitId(BillGenerateInput input, string unitid, int month, int year)
        {
            //var uid = (from us in UnitSummary
            //           where us.unitid == unitid
            //           select us.id).FirstOrDefault();
            var unit = (from us in UnitSummary
                        where us.unitid == unitid
                        select us).FirstOrDefault();
            var uid          = unit.id;
            var unitcategory = unit.meterbillingtype;

            //var unitcategory = (from us in UnitSummary
            //           where us.unitid == unitid select us.meterbillingtype)
            //           .FirstOrDefault();
            var billgroup = (from bg in BillGroup
                             where bg.Id == unit.billgroupid
                             select bg).FirstOrDefault();

            var startDate = Convert.ToDateTime($"{billgroup.StartDay}/{month}/{year}");

            var stopDate    = GetLastDay(month, year, (int)billgroup.StartDay, billgroup.BiMonthly);
            var missingDays = (from oldBill in Bills
                               where oldBill.UnitId == uid
                               orderby oldBill.AddedAt descending
                               select oldBill.MissingDays).FirstOrDefault();


            if (billgroup.BiMonthly)
            {
                if (billgroup.BiMonthlyEven && month % 2 == 1)
                {
                    return;
                }
                if (!billgroup.BiMonthlyEven && month % 2 == 0)
                {
                    return;
                }
            }

            var firstConsumption = (from uc in UnitConsumptionDetails
                                    where uc.unitid == uid &&
                                    uc.daterecorded >= startDate.AddDays(-missingDays) &&
                                    uc.daterecorded <= stopDate
                                    orderby uc.daterecorded ascending
                                    select uc.consumptioninmcube).FirstOrDefault();
            var firstDate = (from uc in UnitConsumptionDetails
                             where uc.unitid == uid &&
                             uc.daterecorded >= startDate
                             select uc.daterecorded).Min();

            var lastConsumption = (from uc in UnitConsumptionDetails
                                   where uc.unitid == uid &&
                                   uc.daterecorded >= startDate.AddDays(-missingDays) &&
                                   uc.daterecorded <= stopDate
                                   orderby uc.daterecorded descending
                                   select uc.consumptioninmcube).FirstOrDefault();
            var lastDate = (from uc in UnitConsumptionDetails
                            where uc.unitid == uid &&
                            uc.daterecorded >= startDate &&
                            uc.daterecorded <= stopDate
                            select uc.daterecorded).Max();

            var consumption = lastConsumption - firstConsumption;
            var bill        = new Bill();

            bill.MonthYear    = input.MonthYear;
            bill.UnitId       = uid;
            bill.FirstReading = firstConsumption;
            bill.LastReading  = lastConsumption;
            bill.Consumption  = consumption;
            bill             = CalculateTariff(unitid, consumption, unitcategory, bill, year, Convert.ToInt32(input.DivisionId));
            bill.BillDate    = input.BillDate; //DateTime.Now;
            bill.DueDate     = input.DueDate;  //bill.AddedAt.AddDays(15);
            bill.FirstDate   = firstDate;
            bill.LastDate    = lastDate;
            bill.MissingDays = lastDate == DateTime.MinValue ?0: (stopDate - lastDate).Days;
            bill.AddedAt     = DateTime.Now;
            Bills.Add(bill);
            this.SaveChanges();
        }
        private void RefreshBillListItems()
        {
            switch (_SortOptions.GetLastOption())
            {
            case "Id":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.Id).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.Id).ToList <DBConnection.Bill>();
                }
                break;

            case "Category":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.Category).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.Category).ToList <DBConnection.Bill>();
                }
                break;

            case "DueDate":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.DueDate).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.DueDate).ToList <DBConnection.Bill>();
                }
                break;

            case "ForMonth":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.ForMonth).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.ForMonth).ToList <DBConnection.Bill>();
                }
                break;

            case "Amount":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.Amount).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.Amount).ToList <DBConnection.Bill>();
                }
                break;

            case "Paid":
                if (_SortOptions.GetDescending())
                {
                    _DBConnection.Bills = Bills.OrderByDescending(x => x.Paid).ToList <DBConnection.Bill>();
                }
                else
                {
                    _DBConnection.Bills = Bills.OrderBy(x => x.Paid).ToList <DBConnection.Bill>();
                }
                break;
            }

            _DBConnection.ReOrderMonthBills();

            Bills.Clear();
            MonthBills.Clear();

            foreach (DBConnection.Bill bill in _DBConnection.Bills)
            {
                Bills.Add(bill);
            }

            foreach (DBConnection.Bill bill in _DBConnection.MonthBills)
            {
                MonthBills.Add(bill);
            }
        }
Пример #22
0
        public DeliveriedPageViewModel(INavigationService navigationService,
                                       ISaleBillService saleBillService,
                                       IDialogService dialogService
                                       ) : base(navigationService, dialogService)
        {
            Title = "已签收(0)";

            _saleBillService = saleBillService;

            this.Load = BillsLoader.Load(async() =>
            {
                var pending = new List <DeliverySignModel>();

                try
                {
                    var result = await _saleBillService.GetDeliveriedSignsAsync(Settings.UserId,
                                                                                Filter.StartTime,
                                                                                Filter.EndTime,
                                                                                Filter.BusinessUserId,
                                                                                Filter.TerminalId,
                                                                                force: this.ForceRefresh,
                                                                                calToken: new System.Threading.CancellationToken());

                    if (result != null)
                    {
                        pending = result.ToList();

                        this.Bills?.Clear();
                        var gDeliveries = pending.GroupBy(s => s.TerminalName).ToList();
                        foreach (var group in gDeliveries)
                        {
                            var gs = group.Select(s =>
                            {
                                var vs    = s;
                                vs.IsLast = !(group.LastOrDefault()?.BillNumber == s.BillNumber);
                                return(vs);
                            }).ToList();

                            var first = group.FirstOrDefault();
                            if (first != null)
                            {
                                Bills.Add(new DeliverySignGroup(first.TerminalName, first.Address, first.BossCall, first.Distance, gs));
                            }
                        }

                        TotalAmount = pending.Select(b => b.SumAmount).Sum();
                        Title       = $"已签收({pending.Count})";
                    }
                }
                catch (System.Exception) { }

                return(pending);
            });

            this.SelecterCommand = ReactiveCommand.Create <DeliverySignModel>(async(item) =>
            {
                if (item != null)
                {
                    using (UserDialogs.Instance.Loading("稍等..."))
                    {
                        if (item.BillTypeId == (int)BillTypeEnum.ExchangeBill)
                        {
                            await this.NavigateAsync("ExchangeBillPage", ("Reference", this.PageName),
                                                     ("Bill", item.ExchangeBill));
                        }
                        else if (item.BillTypeId == (int)BillTypeEnum.SaleReservationBill)
                        {
                            await this.NavigateAsync("SaleBillPage", ("Reference", this.PageName),
                                                     ("Bill", item.SaleBill));
                        }
                        else if (item.BillTypeId == (int)BillTypeEnum.ReturnReservationBill)
                        {
                            await this.NavigateAsync("ReturnBillPage", ("Reference", this.PageName),
                                                     ("Bill", item.ReturnBill));
                        }
                        else if (item.BillTypeId == (int)BillTypeEnum.CostExpenditureBill)
                        {
                            await this.NavigateAsync("CostExpenditureBillPage", ("Reference", this.PageName),
                                                     ("Bill", item.CostExpenditureBill));
                        }
                        else if (item.BillTypeId == (int)BillTypeEnum.SaleBill)
                        {
                            await this.NavigateAsync("SaleBillPage", ("Reference", this.PageName),
                                                     ("Bill", item.SaleBill));
                        }
                    }
                }
            });

            //菜单选择
            this.SubscribeMenus((x) =>
            {
                //获取当前UTC时间
                DateTime dtime = DateTime.Now;

                switch (x)
                {
                case MenuEnum.TODAY:
                    {
                        Filter.StartTime = DateTime.Parse(dtime.ToString("yyyy-MM-dd 00:00:00"));
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.YESTDAY:
                    {
                        Filter.StartTime = dtime.AddDays(-1);
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.OTHER:
                    {
                        SelectDateRang();
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;
                }
            }, string.Format(Constants.MENU_DEV_KEY, 3));


            this.BindBusyCommand(Load);
        }
Пример #23
0
        public ReturnPageViewModel(INavigationService navigationService,
                                   IGlobalService globalService,
                                   IDialogService dialogService,
                                   IAllocationService allocationService,
                                   IAdvanceReceiptService advanceReceiptService,
                                   IReceiptCashService receiptCashService,
                                   ICostContractService costContractService,
                                   ICostExpenditureService costExpenditureService,
                                   IInventoryService inventoryService,
                                   IPurchaseBillService purchaseBillService,
                                   IReturnReservationBillService returnReservationBillService,
                                   IReturnBillService returnBillService,
                                   ISaleReservationBillService saleReservationBillService,
                                   ISaleBillService saleBillService
                                   ) : base(navigationService, globalService, allocationService, advanceReceiptService, receiptCashService, costContractService, costExpenditureService, inventoryService, purchaseBillService, returnReservationBillService, returnBillService, saleReservationBillService, saleBillService, dialogService)
        {
            Title = "退货单";

            this.BillType = BillTypeEnum.ReturnBill;

            this.Load = ReactiveCommand.Create(async() =>
            {
                ItemTreshold = 1;
                PageCounter  = 0;

                try
                {
                    Bills?.Clear();
                    int?terminalId     = Filter.TerminalId;
                    int?businessUserId = Filter.BusinessUserId;
                    string billNumber  = Filter.SerchKey;
                    DateTime?startTime = Filter.StartTime ?? DateTime.Now;
                    DateTime?endTime   = Filter.EndTime ?? DateTime.Now;

                    int?makeuserId = Settings.UserId;
                    if (Filter.BusinessUserId == Settings.UserId)
                    {
                        businessUserId = 0;
                    }
                    int?wareHouseId     = 0;
                    string terminalName = "";
                    string remark       = "";
                    int?districtId      = 0;
                    int?deliveryUserId  = 0;
                    //获取未审核
                    bool?auditedStatus     = false;
                    bool?sortByAuditedTime = null;
                    bool?showReverse       = null;
                    bool?showReturn        = null;
                    bool?handleStatus      = null;
                    int?paymentMethodType  = null;
                    int?billSourceType     = null;

                    var pending = new List <ReturnBillModel>();


                    var result = await _returnBillService.GetReturnBillsAsync(makeuserId, terminalId, terminalName, businessUserId, deliveryUserId, wareHouseId, districtId, remark, billNumber, startTime, endTime, auditedStatus, sortByAuditedTime, showReverse, showReturn, paymentMethodType, billSourceType, handleStatus, 0, PageSize, this.ForceRefresh, new System.Threading.CancellationToken());

                    if (result != null)
                    {
                        pending = result?.Select(s =>
                        {
                            var sm    = s;
                            sm.IsLast = !(result.LastOrDefault()?.BillNumber == s.BillNumber);
                            return(sm);
                        }).Where(s => s.MakeUserId == Settings.UserId || s.BusinessUserId == Settings.UserId).ToList();
                    }
                    if (pending.Any())
                    {
                        Bills = new System.Collections.ObjectModel.ObservableCollection <ReturnBillModel>(pending);
                    }
                    UpdateTitle();
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                int pageIdex = 0;
                if (Bills?.Count != 0)
                {
                    pageIdex = Bills.Count / (PageSize == 0 ? 1 : PageSize);
                }

                if (PageCounter < pageIdex)
                {
                    PageCounter = pageIdex;
                    using (var dig = UserDialogs.Instance.Loading("加载中..."))
                    {
                        try
                        {
                            int?terminalId     = Filter.TerminalId;
                            int?businessUserId = Filter.BusinessUserId;
                            string billNumber  = Filter.SerchKey;
                            DateTime?startTime = Filter.StartTime ?? DateTime.Now;
                            DateTime?endTime   = Filter.EndTime ?? DateTime.Now;

                            int?makeuserId = Settings.UserId;
                            if (Filter.BusinessUserId == Settings.UserId)
                            {
                                businessUserId = 0;
                            }
                            int?wareHouseId     = 0;
                            string terminalName = "";
                            string remark       = "";
                            int?districtId      = 0;
                            int?deliveryUserId  = 0;
                            //获取未审核
                            bool?auditedStatus     = false;
                            bool?sortByAuditedTime = null;
                            bool?showReverse       = null;
                            bool?showReturn        = null;
                            bool?handleStatus      = null;
                            int?paymentMethodType  = null;
                            int?billSourceType     = null;

                            var pending = new List <ReturnBillModel>();

                            var items = await _returnBillService.GetReturnBillsAsync(makeuserId, terminalId, terminalName, businessUserId, deliveryUserId, wareHouseId, districtId, remark, billNumber, startTime, endTime, auditedStatus, sortByAuditedTime, showReverse, showReturn, paymentMethodType, billSourceType, handleStatus, pageIdex, PageSize, this.ForceRefresh, new System.Threading.CancellationToken());
                            if (items != null)
                            {
                                foreach (var item in items)
                                {
                                    if (Bills.Count(s => s.Id == item.Id) == 0)
                                    {
                                        Bills.Add(item);
                                    }
                                }

                                foreach (var s in Bills)
                                {
                                    s.IsLast = !(Bills.LastOrDefault()?.BillNumber == s.BillNumber);
                                }
                            }
                            UpdateTitle();
                        }
                        catch (Exception ex)
                        {
                            Crashes.TrackError(ex);
                        }
                    }
                }
            }, this.WhenAny(x => x.Bills, x => x.GetValue().Count > 0));

            //选择单据
            this.SelectedCommand = ReactiveCommand.Create <ReturnBillModel>(async x =>
            {
                if (x != null)
                {
                    await NavigateAsync(nameof(ReturnBillPage), ("Bill", x), ("IsSubmitBill", true));
                }
            });

            //菜单选择
            this.SubscribeMenus((x) =>
            {
                //获取当前UTC时间
                DateTime dtime = DateTime.Now;
                switch (x)
                {
                case MenuEnum.TODAY:
                    {
                        Filter.StartTime = DateTime.Parse(dtime.ToString("yyyy-MM-dd 00:00:00"));
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.YESTDAY:
                    {
                        Filter.StartTime = dtime.AddDays(-1);
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.OTHER:
                    {
                        SelectDateRang();
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case MenuEnum.SUBMIT30:
                    {
                        Filter.StartTime = dtime.AddMonths(-1);
                        Filter.EndTime   = dtime;
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;

                case Enums.MenuEnum.CLEARHISTORY:    //清空一个月历史单据
                    {
                        ClearHistory(() => _globalService.UpdateHistoryBillStatusAsync((int)this.BillType));
                        ((ICommand)Load)?.Execute(null);
                    }
                    break;
                }
            }, string.Format(Constants.MENU_VIEW_KEY, 3));

            this.BindBusyCommand(Load);
        }
Пример #24
0
 public void PlaceOrder(ShoppingCart shoppingCart)
 {
     Bills.Add(new Order(shoppingCart));
 }