public Result SetNormalContractSentToSAP(NormalContract normalContract, string SAPNumber) { ContractDAO contractDAO = new ContractDAO(connectionString); SAPNumber = SAPNumber.PadLeft(10, '0'); Result result = contractDAO.SetNormalContractSentToSAP(normalContract, SAPNumber); return(result); }
private void GenerateAndSaveNormalContractAndItems(NormalContract normalContract) { ContractService contractService = new ContractService(); NormalContract savedNormalContract = contractService.GenerateAndSaveNormalContractAndItems(normalContract); normalContract.Id = savedNormalContract.Id; normalContract.PONumber = savedNormalContract.PONumber; normalContract.NormalContractItems = savedNormalContract.NormalContractItems; }
/// <summary> /// Generates the PO Number and creates the cadence data in /// MOL database to avoid dump in ZSDI3003_CONTRACT_CREATE. /// </summary> /// <param name="contract">The contract generated from Master Contract Items.</param> public NormalContract GenerateAndSaveNormalContractAndItems(NormalContract normalContract) { ContractDAO contractDAO = new ContractDAO(connectionString); NormalContract savedNormalContract = contractDAO.GenerateNormalContract(normalContract); foreach (NormalContractItem normalContractItem in normalContract.NormalContractItems) { normalContractItem.ContractId = savedNormalContract.Id; NormalContractItem savedNormalContractItem = contractDAO.InsertNormalContractItem(normalContractItem, normalContract.StartDate.Value, normalContract.CreationUser); savedNormalContractItem.Incoterms = normalContractItem.Incoterms; savedNormalContractItem.Region = normalContractItem.Region; savedNormalContract.NormalContractItems.Add(savedNormalContractItem); } return(savedNormalContract); }
public SendToSAPResult ResendNormalContractToSAP(int normalContractId) { ContractDAO contractDAO = new ContractDAO(connectionString); NormalContract normalContract = contractDAO.GetNormalContractWithMaster(normalContractId); List <Result> results = SendNormalContractToSAP(normalContract); var resultsWithFailures = from contractResult in results where contractResult.Success == false select contractResult; SendToSAPResult sendToSAPResult = new SendToSAPResult { NormalContract = normalContract, Payload = results, Success = (resultsWithFailures.Count() == 0) }; return(sendToSAPResult); }
public Result SetNormalContractSentToSAP(NormalContract normalContract, string SAPNumber) { Result result = new Result(success: true); try { using (IDbConnection connection = new OracleConnection(this.connString)) { connection.Open(); var parameters = new OracleDynamicParameters(); parameters.Add("p_cd_contrato", value: normalContract.Id, dbType: OracleDbType.Int32, direction: ParameterDirection.Input); parameters.Add("p_nu_contrato_sap", value: SAPNumber, dbType: OracleDbType.Char, direction: ParameterDirection.Input); connection.Execute("vnd.gx_contract_master.pu_set_normal_sent_to_sap", param: parameters, commandType: CommandType.StoredProcedure); } } catch (Exception ex) { result.Success = false; result.Messages.Add(ex.Message); } return(result); }
private List <Result> SendNormalContractToSAP(NormalContract normalContract) { List <Result> listOfResults = (List <Result>)WebServiceInvocator(normalContract /*savedNormalContract*/); if (listOfResults.Count > 0) { var resultsWithContractNumber = from r in listOfResults where r.Success == true && r.Messages.First() == "CONTRACT_NUMBER" select r; if (resultsWithContractNumber.Count() > 0) { ContractService contractService = new ContractService(); var sapContractNumber = resultsWithContractNumber.First().Payload.ToString(); normalContract.Number = sapContractNumber; Result sentToSAPResult = contractService.SetNormalContractSentToSAP(normalContract /*savedNormalContract*/, sapContractNumber); listOfResults.Add(sentToSAPResult); } else { listOfResults.Add(new Result ( success: false, message: "Contrato não enviado para o SAP." )); } } else { listOfResults.Add(new Result ( success: false, message: "Não foi possível enviar o contrato para o SAP." )); } return(listOfResults); }
public List <NormalContract> MakeContractsFromMasterItems(MasterContract masterContract) { // For each period of every contract master item, // create a new contract and add it to a list. // // Example: // // master item # | Period 1 | Period 2 | Period 3 | // -----------------|----------|----------|----------| // 10 | 90 | 150 | 230 | // 20 | 120 | 70 | 0 | // // Would create 5 contracts with one item each. List <NormalContract> contractsFromPeriods = new List <NormalContract>(); foreach (MasterContractItem masterItem in masterContract.MasterContractItems) { var periodsWithQuantity = masterItem.Periods.Where(p => p.Quantity > 0); foreach (Period period in periodsWithQuantity) { NormalContract contract = new NormalContract() { StartDate = period.Date, DocumentType = masterContract.DocumentType, DistributionChannel = masterContract.DistributionChannel, SalesOrganization = masterContract.SalesOrganization, SalesDivision = masterContract.SalesDivision, SalesSupervisor = masterContract.SalesSupervisor, Customer = masterContract.Customer, MasterContractId = masterContract.Id }; contract.NormalContractItems.Add(new NormalContractItem { Material = masterItem.Material, Incoterms = masterItem.Incoterms, Region = masterItem.Region, Quantity = period.Quantity }); contractsFromPeriods.Add(contract); } } // Group the contracts by Start Date. var contractsGroupped = contractsFromPeriods .OrderBy(p => p.StartDate) .GroupBy(p => p.StartDate) .Select(grp => grp.ToList()) .ToList(); // For every group of contracts, create a new Contract with the items merged. // // Example: // // master item # | Period 1 | Period 2 | Period 3 | // -----------------|----------|----------|----------| // 10 | 90 | 150 | 230 | // 20 | 120 | 70 | 0 | // // Would create 3 contracts: // - Contract 1: Two items => 90t and 120t. // - Contract 2: Two items => 150t and 70t. // - Contract 3: One item => 230t. var contracts = from g in contractsGroupped select new NormalContract { StartDate = g.First().StartDate, EndDate = g.First().StartDate.Value.LastDayOfMonth(), Customer = g.First().Customer, DistributionChannel = g.First().DistributionChannel, DocumentType = g.First().DocumentType, SalesOrganization = g.First().SalesOrganization, SalesDivision = g.First().SalesDivision, SalesSupervisor = g.First().SalesSupervisor, MasterContractId = g.First().MasterContractId, NormalContractItems = ( from c in g from i in c.NormalContractItems select i ).ToList() }; List <NormalContract> finalListOfContracts = contracts.OrderBy(c => c.StartDate).ToList(); finalListOfContracts.First().StartDate = masterContract.StartDate; finalListOfContracts.Last().EndDate = masterContract.EndDate; return(finalListOfContracts); }
public NormalContract GetNormalContractWithMaster(int normalContractId) { NormalContract result = null; using (IDbConnection connection = new OracleConnection(this.connString)) { connection.Open(); var parameters = new OracleDynamicParameters(); parameters.Add("p_cd_contrato", value: normalContractId, dbType: OracleDbType.Int32, direction: ParameterDirection.Input); parameters.Add("p_result", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output); var multi = connection.QueryMultiple("vnd.gx_contract_master.px_normal_contract_with_master", param: parameters, commandType: CommandType.StoredProcedure); IEnumerable <NormalContract> list = multi.Read( new[] { typeof(NormalContract), typeof(DocumentType), typeof(SalesOrganization), typeof(DistributionChannel), typeof(SalesDivision), typeof(User), typeof(User), typeof(Customer), typeof(User), typeof(NormalContractItem), typeof(Material), typeof(Incoterms), typeof(Region) }, (objects) => { var lookup = new Dictionary <int, NormalContract>(); NormalContract ct; var contract = (NormalContract)objects[0]; if (!lookup.TryGetValue(contract.Id, out ct)) { lookup.Add(contract.Id, ct = contract); ct.DocumentType = (DocumentType)objects[1]; ct.SalesOrganization = (SalesOrganization)objects[2]; ct.DistributionChannel = (DistributionChannel)objects[3]; ct.SalesDivision = (SalesDivision)objects[4]; ct.SalesSupervisor = (User)objects[5]; ct.SalesSupervisor.Superior = (User)objects[6]; ct.Customer = (Customer)objects[7]; ct.CreationUser = (User)objects[8]; } if (ct.NormalContractItems == null) { ct.NormalContractItems = new List <NormalContractItem>(); } NormalContractItem normalContractItem; var it = (NormalContractItem)objects[9]; if (it != null) { var items = from mi in ct.NormalContractItems where mi.Id == it.Id select mi; if (items.Count() == 0) { normalContractItem = it; normalContractItem.Material = (Material)objects[10]; normalContractItem.Incoterms = (Incoterms)objects[11]; normalContractItem.Region = (Region)objects[12]; ct.NormalContractItems.Add(normalContractItem); } else { normalContractItem = items.First(); } } return(ct); }).AsList(); if (list.Count() > 0) { result = list.First(); } } return(result); }
public NormalContract GenerateNormalContract(NormalContract normalContract) { NormalContract result = null; using (IDbConnection connection = new OracleConnection(this.connString)) { connection.Open(); var parameters = new OracleDynamicParameters(); parameters.Add("p_cd_contrato_master", value: normalContract.MasterContractId, dbType: OracleDbType.Int32, direction: ParameterDirection.Input); parameters.Add("p_cd_tipo_contrato", value: (normalContract.DocumentType == null ? "" : normalContract.DocumentType.Id), dbType: OracleDbType.Char, direction: ParameterDirection.Input); parameters.Add("p_cd_sales_org", value: (normalContract.SalesOrganization == null ? "" : normalContract.SalesOrganization.Id), dbType: OracleDbType.Char, direction: ParameterDirection.Input); parameters.Add("p_cd_distribution_channel", value: (normalContract.DistributionChannel == null ? "" : normalContract.DistributionChannel.Id), dbType: OracleDbType.Char, direction: ParameterDirection.Input); parameters.Add("p_cd_sales_division", value: normalContract.SalesDivision.Id, dbType: OracleDbType.Char, direction: ParameterDirection.Input); parameters.Add("p_cd_usuario_venda", value: (normalContract.SalesSupervisor == null ? null : normalContract.SalesSupervisor.Id), dbType: OracleDbType.Int32, direction: ParameterDirection.Input); parameters.Add("p_cd_cliente", value: (normalContract.Customer == null ? "" : normalContract.Customer.Id), dbType: OracleDbType.Varchar2, direction: ParameterDirection.Input); parameters.Add("p_dt_inicio", value: normalContract.StartDate, dbType: OracleDbType.Date, direction: ParameterDirection.Input); parameters.Add("p_dt_fim", value: normalContract.EndDate, dbType: OracleDbType.Date, direction: ParameterDirection.Input); parameters.Add("p_cd_usuario_inclusao", value: (normalContract.CreationUser == null ? null : normalContract.CreationUser.Id), dbType: OracleDbType.Int32, direction: ParameterDirection.Input); parameters.Add("p_result", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output); var multi = connection.QueryMultiple("vnd.gx_contract_master.pu_generate_contract", param: parameters, commandType: CommandType.StoredProcedure); IEnumerable <NormalContract> list = multi.Read( new[] { typeof(NormalContract), typeof(DocumentType), typeof(SalesOrganization), typeof(DistributionChannel), typeof(SalesDivision), typeof(User), typeof(User), typeof(Customer), typeof(User), typeof(NormalContractItem), //typeof(Incoterms), typeof(Material) }, (objects) => { var lookup = new Dictionary <int, NormalContract>(); NormalContract ct; var contract = (NormalContract)objects[0]; if (!lookup.TryGetValue(contract.Id, out ct)) { lookup.Add(contract.Id, ct = contract); ct.DocumentType = (DocumentType)objects[1]; ct.SalesOrganization = (SalesOrganization)objects[2]; ct.DistributionChannel = (DistributionChannel)objects[3]; ct.SalesDivision = (SalesDivision)objects[4]; ct.SalesSupervisor = (User)objects[5]; ct.SalesSupervisor.Superior = (User)objects[6]; ct.Customer = (Customer)objects[7]; ct.CreationUser = (User)objects[8]; } if (ct.NormalContractItems == null) { ct.NormalContractItems = new List <NormalContractItem>(); } NormalContractItem normalContractItem; var it = (NormalContractItem)objects[9]; if (it != null) { var items = from mi in ct.NormalContractItems where mi.Id == it.Id select mi; if (items.Count() == 0) { normalContractItem = it; normalContractItem.Material = (Material)objects[10]; //normalContractItem.Incoterms = (Incoterms)objects[11]; ct.NormalContractItems.Add(normalContractItem); } else { normalContractItem = items.First(); } } return(ct); }).AsList(); if (list.Count() > 0) { result = list.First(); } } return(result); }
/// <summary> /// Call to ZSDI3003_CONTRACT_CREATE. /// </summary> /// <param name="contract"></param> /// <returns></returns> private IEnumerable <Result> WebServiceInvocator(NormalContract contract) { List <Result> result = new List <Result>(); // Import tab in ZSDI3003_CONTRACT_CREATE. BAPISDHD1 contract_header_in = new BAPISDHD1(); BAPISDHD1X contract_header_inx = new BAPISDHD1X(); BAPISDLS logic_switch = new BAPISDLS(); // Tables tab in ZSDI3003_CONTRACT_CREATE. BAPICUBLB[] contract_cfgs_blob = new BAPICUBLB[1]; BAPICUINS[] contract_cfgs_inst = new BAPICUINS[1]; BAPICUPRT[] contract_cfgs_part_of = new BAPICUPRT[1]; BAPICUCFG[] contract_cfgs_ref = new BAPICUCFG[1]; BAPICUREF[] contract_cfgs_refinst = new BAPICUREF[1]; BAPICUVAL[] contract_cfgs_value = new BAPICUVAL[1]; BAPICUVK[] contract_cfgs_vk = new BAPICUVK[1]; BAPICONDX[] contract_conditions_inx = new BAPICONDX[1]; BAPICTR[] contract_data_in = new BAPICTR[1]; BAPICTRX[] contract_data_inx = new BAPICTRX[1]; BAPISDITMX[] contract_items_inx = new BAPISDITMX[1]; BAPISDKEY[] contract_keys = new BAPISDKEY[1]; BAPIPARNR[] contract_partners = new BAPIPARNR[2]; BAPIPAREX[] extensionin = null; BAPIADDR1[] partneraddresses = new BAPIADDR1[1]; BAPIRET2[] breturn = new BAPIRET2[1]; BAPISDTEXT[] contract_text = null; BAPICOND[] contract_conditions_in = null; BAPISDITM[] contract_items_in = new BAPISDITM[contract.NormalContractItems.Count]; //// HEADER ---------------------------------------------------------------------- contract_header_in.DOC_TYPE = contract.DocumentType.Id; contract_header_in.SALES_ORG = contract.SalesOrganization.Id; contract_header_in.DISTR_CHAN = contract.DistributionChannel.Id; contract_header_in.DIVISION = contract.SalesDivision.Id; contract_header_in.CT_VALID_F = contract.StartDate.Value.ToString("yyyy-MM-dd"); contract_header_in.CT_VALID_T = contract.EndDate.Value.ToString("yyyy-MM-dd"); contract_header_in.PURCH_NO_C = contract.PONumber.ToString(); contract_header_in.SALES_GRP = contract.SalesSupervisor.Code; contract_header_in.SALES_OFF = contract.SalesSupervisor.Superior.Code; //// ITEMS ---------------------------------------------------------------------- int itemsIndex = 0; foreach (NormalContractItem item in contract.NormalContractItems) { BAPISDITM bapisditm = new BAPISDITM(); bapisditm.ITM_NUMBER = string.Format("{0,6:000000}", item.Id); bapisditm.MATERIAL = item.Material.Id; bapisditm.TARGET_QTY = item.Quantity; bapisditm.TARGET_QTYSpecified = true; bapisditm.TARGET_QU = "MTN"; bapisditm.INCOTERMS1 = item.Incoterms.Id; bapisditm.INCOTERMS2 = item.Region.Name; contract_items_in[itemsIndex] = bapisditm; itemsIndex++; } // CUSTOMER ---------------------------------------------------------------------- /* * AG = SP - EMISSOR DA ORDEM * PY = RG - PAGADOR * SH = WE - RECEBEDOR * ZW = ZW - RECEBEDOR' * ZA = ZA - AGENTE DE VENDAS */ BAPIPARNR contract_partners_SoldTo = new BAPIPARNR(); contract_partners_SoldTo.PARTN_ROLE = "SP"; contract_partners_SoldTo.PARTN_NUMB = contract.Customer.Id; contract_partners[0] = contract_partners_SoldTo; //// SEND THE CONTRACT ---------------------------------------------------------------------- NetworkCredential lNetCredentials = new NetworkCredential(); lNetCredentials.UserName = ConfigurationManager.AppSettings["SI_CREATE_CONTRACT_OB_USER"]; lNetCredentials.Password = ConfigurationManager.AppSettings["SI_CREATE_CONTRACT_OB_PWD"]; SI_CREATE_CONTRACT_OB_BrazilMOService service = new SI_CREATE_CONTRACT_OB_BrazilMOService(); service.Credentials = lNetCredentials; service.Timeout = int.MaxValue; try { string res = service.SI_CREATE_CONTRACT_OB_BrazilMO( null, null, contract_header_in, contract_header_inx, "X", string.Empty, //IM_ZZREPCC (NU_CONTRATO_SUBSTITUI), "X", logic_switch, "", null, string.Empty, //TESTRUN ref contract_cfgs_blob, ref contract_cfgs_inst, ref contract_cfgs_part_of, ref contract_cfgs_ref, ref contract_cfgs_refinst, ref contract_cfgs_value, ref contract_cfgs_vk, ref contract_conditions_in, ref contract_conditions_inx, ref contract_data_in, ref contract_data_inx, ref contract_items_in, ref contract_items_inx, ref contract_keys, ref contract_partners, ref contract_text, ref extensionin, ref partneraddresses, ref breturn ); if (breturn != null) { for (int i = 0; i <= breturn.Length - 1; i++) { if ((breturn[i].TYPE.ToUpper() == "S") && (breturn[i].NUMBER == "311")) { result.Add(new Result ( success: true, message: "CONTRACT_NUMBER", payload: breturn[i].MESSAGE_V2 )); } else { result.Add(new Result ( success: (breturn[i].TYPE == "S"), message: breturn[i].MESSAGE )); } } } } catch (Exception ex) { result.Add(new Result ( success: false, message: ex.Message )); if (ex.InnerException != null) { result.Add(new Result ( success: false, message: ex.InnerException.Message )); } } return(result); }