public void DeleteMaintainPrepaymentInvoice(MaintainPrepaymentInvoiceDTO prepaymentInvoice)
 {
     if (prepaymentInvoice == null)
     {
         throw new ArgumentException("参数为空!");
     }
     BasePurchaseInvoice delPrepaymentInvoice =
         _invoiceRepository.GetBasePurchaseInvoice(prepaymentInvoice.PrepaymentInvoiceId);
     //获取需要删除的对象。
     if (delPrepaymentInvoice != null)
     {
         _invoiceRepository.DeleteInvoice(delPrepaymentInvoice); //删除预付款发票。
     }
 }
        public void ModifyMaintainPrepaymentInvoice(MaintainPrepaymentInvoiceDTO prepaymentInvoice)
        {
            Supplier supplier =
                _supplierRepository.GetFiltered(p => p.Id == prepaymentInvoice.SupplierId).FirstOrDefault();
            Currency currency =
                _currencyRepository.GetFiltered(p => p.Id == prepaymentInvoice.CurrencyId).FirstOrDefault();

            BasePurchaseInvoice updatePrepaymentInvoice =
                _invoiceRepository.GetBasePurchaseInvoice(prepaymentInvoice.PrepaymentInvoiceId);
            //获取需要更新的对象。
            if (updatePrepaymentInvoice != null)
            {
                InvoiceFactory.SetInvoice(updatePrepaymentInvoice, prepaymentInvoice.InvoideCode,
                    prepaymentInvoice.InvoiceDate, prepaymentInvoice.OperatorName, prepaymentInvoice.InvoiceNumber,
                    supplier, null,
                    prepaymentInvoice.PaidAmount, currency, prepaymentInvoice.PaymentScheduleLineId,
                    prepaymentInvoice.Status);
                //更新主表。

                UpdateInvoiceLines(prepaymentInvoice.InvoiceLines, updatePrepaymentInvoice, null);
                //更新从表。
            }
            _invoiceRepository.Modify(updatePrepaymentInvoice);
        }
        public void InsertMaintainPrepaymentInvoice(MaintainPrepaymentInvoiceDTO prepaymentInvoice)
        {
            Supplier supplier =
                _supplierRepository.GetFiltered(p => p.Id == prepaymentInvoice.SupplierId).FirstOrDefault();
            Currency currency =
                _currencyRepository.GetFiltered(p => p.Id == prepaymentInvoice.CurrencyId).FirstOrDefault();

            MaintainPrepaymentInvoice newPrepaymentInvoice =
                InvoiceFactory.CreateMaintainPrepaymentInvoice(prepaymentInvoice.InvoideCode,
                    prepaymentInvoice.InvoiceDate, prepaymentInvoice.OperatorName);
            DateTime date = DateTime.Now.Date;
            int seq = _invoiceRepository.GetFiltered(t => t.CreateDate > date).Count() + 1;
            newPrepaymentInvoice.SetInvoiceNumber(seq);
            newPrepaymentInvoice.SetSupplier(supplier);
            newPrepaymentInvoice.SetPaidAmount(prepaymentInvoice.PaidAmount);
            newPrepaymentInvoice.SetCurrency(currency);
            newPrepaymentInvoice.SetPaymentScheduleLine(prepaymentInvoice.PaymentScheduleLineId);
            newPrepaymentInvoice.SetInvoiceStatus(InvoiceStatus.草稿);
            foreach (InvoiceLineDTO invoiceLine in prepaymentInvoice.InvoiceLines)
            {
                newPrepaymentInvoice.AddInvoiceLine(invoiceLine.ItemName, invoiceLine.Amount, null, invoiceLine.Note);
            }
            newPrepaymentInvoice.SetInvoiceValue();
            _invoiceRepository.Add(newPrepaymentInvoice);
        }