U9出货生成应收
- BP名:CreateImportARBillSVProxy
- 命名空间:UFIDA.U9.ISV.AR.Proxy
- dll: C:\yonyou\U9V60\Portal\ApplicationServer\Libs\UFIDA.U9.ISV.AR.ARImportSV.Agent.dll
示例代码
using System;
using System.Collections.Generic;
using System.Web.Http;
using UFIDA.U9.AR.ARBill;
using UFIDA.U9.AR.ARBill.Proxy;
using UFIDA.U9.Base.Currency;
using UFIDA.U9.Base.Doc;
using UFIDA.U9.CBO.FI.ConfirmTerm;
using UFIDA.U9.CBO.Pub.Controller;
using UFIDA.U9.CBO.SCM.Customer;
using UFIDA.U9.CBO.SCM.Item;
using UFIDA.U9.Cust.QR.ZhuBR.WebApi.Dto;
using UFIDA.U9.ISV.AR;
using UFIDA.U9.ISV.AR.Proxy;
using UFIDA.U9.SM.Ship;
using UFSoft.UBF.MVC;
using UFSoft.UBF.MVC.Common;
using UFSoft.UBF.Util.Context;
namespace UFIDA.U9.Cust.QR.ZhuBR.WebApi.Controller
{
public class CreateArBillByShipController : OpenAPIController
{
/// <summary>
/// 创建应收单
/// </summary>
/// <param name="dto">创建应收单实体类</param>
/// <returns></returns>
[HttpPost]
public ApiResult<ResArBillDto> Create([FromBody] CreateArBillDto dto)
{
Ship ship = Ship.Finder.Find($"DocNo = '{dto.DocNo}' and org = {PlatformContext.Current.OrgID}");
if (ship == null)
{
}
CreateImportARBillSVProxy sv = new CreateImportARBillSVProxy();
sv.ImportARBillHeadDTOs = new List<ImportARBillHeadDTOData>();
sv.TargetOrgCode = PlatformContext.Current.OrgCode;
sv.TargetOrgName = PlatformContext.Current.OrgName;
ImportARBillHeadDTOData importArBillHeadDtoData = new ImportARBillHeadDTOData();
importArBillHeadDtoData.BusinessType = BusinessTypeEnum.AR_DebitOnAccount.Value;
//单据类型
importArBillHeadDtoData.DocumentType = new CommonArchiveDataDTOData(0L, "01", string.Empty);
importArBillHeadDtoData.SrcBusinessType = BusinessTypeEnum.SD_StandardSale.Value; //来源业务类型, 普通销售
importArBillHeadDtoData.AccrueDate = UFIDA.U9.Base.Context.LoginDate;
importArBillHeadDtoData.SettleOrg =
new CommonArchiveDataDTOData(long.Parse(PlatformContext.Current.OrgID), PlatformContext.Current.OrgCode,
string.Empty); //业务组织
importArBillHeadDtoData.BizOrg =
new CommonArchiveDataDTOData(long.Parse(PlatformContext.Current.OrgID), PlatformContext.Current.OrgCode,
string.Empty); //组织
importArBillHeadDtoData.SrcOrg =
new CommonArchiveDataDTOData(long.Parse(PlatformContext.Current.OrgID), PlatformContext.Current.OrgCode,
string.Empty); //组织
Customer cust = ship.OrderBy.Customer;
importArBillHeadDtoData.AccrueCust = new CustomerMISCInfoData();
importArBillHeadDtoData.AccrueCust.Customer = cust.ID;
importArBillHeadDtoData.AccrueCust.Code = cust.Code;
importArBillHeadDtoData.AccrueCust.Name = cust.Name;
importArBillHeadDtoData.PayCust = new CustomerMISCInfoData();
importArBillHeadDtoData.PayCust.Customer = cust.ID;
importArBillHeadDtoData.PayCust.Code = cust.Code;
importArBillHeadDtoData.PayCust.Name = cust.Name;
Currency cy = Currency.Finder.Find(string.Format("Code='C001'"));
if (cy == null)
{
throw new Exception("币种编码C001在系统不存在,请检查");
}
importArBillHeadDtoData.AC = new CommonArchiveDataDTOData();
importArBillHeadDtoData.AC.ID = cy.ID;
importArBillHeadDtoData.AC.Code = cy.Code;
importArBillHeadDtoData.AccrueCustSite = new CustomerSiteMISCInfoData(); //客户位置
importArBillHeadDtoData.AccrueCustSite.CustomerSite = cust.CustomerSites[0].ID;
importArBillHeadDtoData.PayCustSite = new CustomerSiteMISCInfoData(); //客户位置
importArBillHeadDtoData.PayCustSite.CustomerSite = cust.CustomerSites[0].ID;
importArBillHeadDtoData.ImportARBillLineDTOs = new List<ImportARBillLineDTOData>();
int nLineNum = 0;
foreach (ShipLine line in ship.ShipLines)
{
ImportARBillLineDTOData importArBillLineDtoData = new ImportARBillLineDTOData();
importArBillLineDtoData.ShipToCustSite = new CustomerSiteMISCInfoData();
importArBillLineDtoData.ShipToCustSite.CustomerSite = importArBillHeadDtoData.PayCustSite.CustomerSite;
importArBillHeadDtoData.Memo = "";
importArBillLineDtoData.AccrueTerm = new CommonArchiveDataDTOData();
ARAccrueTerm lztj = line.ConfirmTerm;
importArBillLineDtoData.AccrueTerm.ID = lztj.ID;
importArBillLineDtoData.AccrueTerm.Code = lztj.Code;
importArBillLineDtoData.AccrueTerm.Name = lztj.Name;
importArBillLineDtoData.InvoiceNum = "";
importArBillLineDtoData.IsQA = false;
importArBillLineDtoData.Item = new ItemInfoData();
ItemMaster itm = line.ItemInfo.ItemID;
importArBillLineDtoData.Item.ItemID = itm.ID;
importArBillLineDtoData.Item.ItemCode = itm.Code;
importArBillLineDtoData.Item.ItemName = itm.Name;
importArBillLineDtoData.Money = line.TotalMoney;
nLineNum += 10;
importArBillLineDtoData.LineNum = nLineNum;
//importARBillLineDTOData.Maturity = DateTime.Now.AddDays(30);// Convert.ToDateTime
importArBillLineDtoData.Maturity = UFIDA.U9.Base.Context.LoginDate.AddDays(30);
importArBillLineDtoData.RecTerm = new CommonArchiveDataDTOData();
importArBillLineDtoData.RecTerm.Code = line.ReceivableTerm.Code;
importArBillLineDtoData.TDMode = 0;
importArBillHeadDtoData.ImportARBillLineDTOs.Add(importArBillLineDtoData);
}
sv.ImportARBillHeadDTOs.Add(importArBillHeadDtoData);
List<ImportARBillResultDTOData> arbillList = sv.Do();
foreach (ImportARBillResultDTOData importArBillResultDtoData in arbillList)
{
ARBillHead ar = ARBillHead.Finder.FindByID(importArBillResultDtoData.ID);
ARBillSubmitBPProxy submit = new ARBillSubmitBPProxy();
submit.ARBillHeadKey = ar.ID;
submit.CurrentSysVersion = ar.SysVersion;
submit.Do();
ARBillApproveBPProxy apporve = new ARBillApproveBPProxy();
apporve.CurrentSysVersion += 1;
apporve.ARBillHeadKey = ar.ID;
apporve.Do();
return new ApiResult<ResArBillDto>(new ResArBillDto(ar.Org.Name,ar.DocNo));
}
return new ApiResult<ResArBillDto>(new ResArBillDto(), 500, "操作失败");
}
}
} 标签:无