Exemplo n.º 1
0
 /// <summary>
 /// 向lmshop_CompanyFundReceiptInvoice表插入一条数据,插入成功则返回自增列数值,插入不成功则返回-1
 /// </summary>
 /// <param name="lmshopCompanyFundReceiptInvoice">lmshop_CompanyFundReceiptInvoice</param>
 /// <returns></returns>
 public bool Addlmshop_CompanyFundReceiptInvoice(CompanyFundReceiptInvoiceInfo lmshopCompanyFundReceiptInvoice)
 {
     return(_companyFundReceiptInvoiceDao.Addlmshop_CompanyFundReceiptInvoice(lmshopCompanyFundReceiptInvoice));
 }
Exemplo n.º 2
0
        public ResultInfo InvoicePass(Guid receiptId, string invoiceUnit, List <InvoiceRelationInfo> invoiceRelations, string remark, Guid personnelId)
        {
            try
            {
                if (invoiceRelations.All(ent => !ent.IsCanEdit))
                {
                    return(new ResultInfo(false, "请录入需新增的发票信息!"));
                }
                var companyFundReceiot = _companyFundReceiptDao.GetCompanyFundReceiptInfo(receiptId);
                if (companyFundReceiot == null)
                {
                    return(new ResultInfo(false, "未找到对应的申请单据信息!"));
                }
                if (companyFundReceiot.ReceiptStatus != (int)CompanyFundReceiptState.WaitInvoice)
                {
                    return(new ResultInfo(false, "只有待开票/开票中状态下的往来账收款才允许开票操作!"));
                }
                if (Math.Abs(invoiceRelations.Sum(ent => ent.TotalFee)) > companyFundReceiot.RealityBalance)
                {
                    return(new ResultInfo(false, "开票金额不能大于收款金额!"));
                }
                bool isEqual = Math.Abs(invoiceRelations.Sum(ent => ent.TotalFee)) == companyFundReceiot.RealityBalance;
                using (var tran = new TransactionScope(TransactionScopeOption.Required))
                {
                    var result = _companyFundReceiptDao.UpdateInvoice(receiptId,
                                                                      isEqual ?(int)CompanyFundReceiptState.Audited:(int)CompanyFundReceiptState.WaitInvoice, invoiceUnit,
                                                                      isEqual ? (int)ApplyInvoiceState.Finished
                            : (int)ApplyInvoiceState.Invoicing, remark, isEqual?personnelId:Guid.Empty);
                    if (!result)
                    {
                        return(new ResultInfo(result, "往来账收款单开票失败!"));
                    }
                    bool success = true;
                    foreach (var invoiceGroup in invoiceRelations.Where(ent => ent.IsCanEdit).GroupBy(ent => ent.InvoiceNo))
                    {
                        if (invoiceGroup.Count() > 1)
                        {
                            return(new ResultInfo(false, string.Format("发票添加重复【票据号码{0}】", invoiceGroup.Key)));
                        }
                        var item = invoiceGroup.First();
                        CompanyFundReceiptInvoiceInfo companyFundReceiptInvoiceInfo = new CompanyFundReceiptInvoiceInfo();
                        companyFundReceiptInvoiceInfo.BillingDate = item.RequestTime;
                        companyFundReceiptInvoiceInfo.BillingUnit = invoiceUnit;
                        companyFundReceiptInvoiceInfo.InvoiceCode = item.InvoiceCode;
                        companyFundReceiptInvoiceInfo.InvoiceNo   = item.InvoiceNo;
                        companyFundReceiptInvoiceInfo.InvoiceId   = item.InvoiceId;
                        companyFundReceiptInvoiceInfo.Remark      = item.Remark;
                        companyFundReceiptInvoiceInfo.TaxAmount   = item.TotalFee;
                        companyFundReceiptInvoiceInfo.ReceiptID   = item.ApplyId;

                        success = _companyFundReceiptInvoice.Addlmshop_CompanyFundReceiptInvoice(companyFundReceiptInvoiceInfo);
                        if (!success)
                        {
                            break;
                        }
                    }
                    if (success)
                    {
                        tran.Complete();
                        return(new ResultInfo(true, ""));
                    }
                    return(new ResultInfo(false, "插入发票失败"));
                }
            }
            catch (Exception ex)
            {
                return(new ResultInfo(false, ex.Message));
            }
        }