Beispiel #1
0
        public async Task SelectBooking(Booking booking)
        {
            SelectedBooking = booking;

            if (SelectedBooking.PaymentAccount == null)
            {
                if (booking.AssignedPilot != null)
                {
                    if (booking.PaymentType == PaymentType.Vipps)
                    {
                        booking.PaymentAccountId = booking.AssignedPilot.VippsPaymentAccountId;
                    }
                    else if (booking.PaymentType == PaymentType.IZettle)
                    {
                        booking.PaymentAccountId = booking.AssignedPilot.IZettlePaymentAccountId;
                    }
                    booking.PaymentAccount = PaymentAccounts.FirstOrDefault(a => a.Id == booking.PaymentAccountId);
                }
            }

            using (var scope = ScopeFactory.CreateScope())
            {
                var db = scope.ServiceProvider.GetService <TandemBookingContext>();

                FilteredPaymentAccounts = PaymentAccounts
                                          .Where(p => p.PaymentType == booking.PaymentType)
                                          .ToList();

                FilteredPayments = db.Payments
                                   .Where(p => p.PaymentAccountId == SelectedBooking.PaymentAccountId)
                                   .Where(p => p.UnreconciledAmount > 0)
                                   .AsEnumerable()
                                   .OrderBy(p => Math.Abs((p.PaymentDate - (booking.CompletedDate ?? booking.BookingDate)).TotalSeconds))
                                   .ToList();
            }
        }
Beispiel #2
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }

                    foreach (BulkPaymentEntry mainLine in BulkPaymentEntries)
                    {
                        Int64 trackingNumber = -1;
                        // Make a new header entry
                        DB.GLX_Header header = BL.GLX.GLX_Header.New;
                        header.TrackId           = -1;
                        header.PeriodId          = mainLine.PeriodId.Value;
                        header.ReferencePeriodId = mainLine.PeriodId.Value;
                        header.Date        = mainLine.Date.Value;
                        header.PostedDate  = BL.ApplicationDataContext.Instance.ServerDateTime.Date;
                        header.Reference   = mainLine.Reference;
                        header.Description = mainLine.Description;
                        header.StatusId    = 52;

                        if (mainLine.Amount >= 0)
                        {
                            // header.Description = "CREDITOR PAYMENT RECEIVED";
                            header.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Payment;
                        }
                        else
                        {
                            //  header.Description = "CREDITOR PAYMENT REVERSAL";
                            header.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Reversal;
                        }

                        //Double check if this has a use
                        if (!trackingNumber.Equals(-1))
                        {
                            header.TrackId = trackingNumber;
                        }

                        //Loop through INV or C/N or BBF (Agings)
                        foreach (var agingAmount in mainLine.BulkPaymentItems.Where(n => n.Checked.Equals(true)).GroupBy(g => g.AgingId).Select(l => new { AgingId = l.Key, Balance = l.Sum(i => i.Balance) }))
                        {
                            //DEBTOR LINE
                            DB.GLX_Line linecreditor = BL.GLX.GLX_Line.New;
                            //TODO: ACCOUNT NOT LOADING ON subLine
                            linecreditor.EntityId = mainLine.AccountId.Value;
                            linecreditor.AgingId  = agingAmount.AgingId;
                            linecreditor.Amount   = -agingAmount.Balance;
                            header.GLX_Line.Add(linecreditor);
                        }
                        //BANK LINE
                        DB.GLX_Line linebank = BL.GLX.GLX_Line.New;
                        linebank.EntityId = Convert.ToInt64(ddlAccount.EditValue);
                        linebank.AgingId  = 1;
                        linebank.Amount   = mainLine.Amount;
                        header.GLX_Line.Add(linebank);
                        //SETTLEMENT DISCOUNT TAX LINE
                        DB.GLX_Line linesettlementtax = BL.GLX.GLX_Line.New;
                        DB.GLX_Tax  taxType           = DataContext.EntityAccountingContext
                                                        .GLX_Tax.FirstOrDefault(n => n.Id == PaymentAccounts
                                                                                .Where(nn => nn.AccountId.Equals(((DB.GLX_Account)ddlSettlementAccount.GetSelectedDataRow()).Id))
                                                                                .Select(nn => nn.TaxId).FirstOrDefault());
                        if (taxType != null && taxType.Percentage != 0)
                        {
                            linesettlementtax.Amount = mainLine.Settlement * (1 - taxType.Percentage);
                        }
                        else
                        {
                            linesettlementtax.Amount = mainLine.Settlement;
                        }

                        header.GLX_Line.Add(linesettlementtax);
                        //SETTLEMENT DISCOUNT LINE
                        DB.GLX_Line linesettlement = BL.GLX.GLX_Line.New;
                        linesettlement.EntityId = Convert.ToInt64(ddlSettlementAccount.EditValue);
                        linesettlement.AgingId  = 1;
                        linesettlement.Amount   = mainLine.Settlement - linesettlementtax.Amount;
                        header.GLX_Line.Add(linesettlement);

                        //Change the subLines's tracking number to the new tracking number
                        foreach (var subLine in mainLine.BulkPaymentItems.Where(n => n.Checked.Equals(true)))
                        {
                            BL.GLX.GLX_Header.UpdateTrackNumber(subLine.HeaderId, trackingNumber, DataContext);
                        }
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                HasErrors = true;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }