Advertisement
Guest User

cancellation matrix

a guest
Jun 28th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Activities;
  6. using EGR_MasterData;
  7. using EGR_WorkflowLibrary;
  8. using EGR_SBO_Server_Helper;
  9. using EGR_Workflow_Helper;
  10. using EGR_ProcessXMLDocument;
  11.  
  12. namespace EGR_Workflow_SharedActivities
  13. {
  14.     static class CancellationMatrix
  15.     {
  16.  
  17.         /// <summary>
  18.         /// Checks the cancellation request message and returns the correct answer
  19.         /// </summary>
  20.         /// <param name="xmlID">The id of the message in the db</param>
  21.         public static CancellationMatrixAnswer GetCancellationAnswer(string xmlID)//TODO different conditions for each division?
  22.         {
  23.             CancellationMatrixAnswer answer = new CancellationMatrixAnswer();
  24.  
  25.             try
  26.             {
  27.                 DateTime nextPossibleCancelDate = new DateTime();
  28.                 DateTime oldCancelDate = new DateTime();
  29.                 DateTime contractExtensionDate = new DateTime();
  30.                 DateTime messageInDate = new DateTime();
  31.                 bool determination = false;
  32.                 DateTime newCancelDate = new DateTime();
  33.                 string processDocument = "";
  34.                 string sql = "";
  35.                 string contract = "";
  36.                 SAPbobsCOM.Company company = SBODIDataProvider.getCompany();
  37.                 SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
  38.  
  39.                 ProcessXMLDocument newCancellationMsg = new ProcessXMLDocument(new Guid(xmlID));
  40.  
  41.                 //get in date of cancellation message
  42.                 sql = "SELECT U_DATE FROM [@U_EGR_PROCESSDOC_L] WHERE U_MSGID = '" + xmlID.ToString() + "'";
  43.                 rs.DoQuery(sql);
  44.                 messageInDate = (DateTime)rs.Fields.Item(0).Value;
  45.  
  46.                 if (newCancellationMsg.AttributeList.Where(a => a.Name == "Ende_zum_naechstmoeglichen_Termin").Count() > 0)
  47.                 {
  48.                     string cancel = newCancellationMsg.AttributeList.Where(a => a.Name == "Ende_zum_naechstmoeglichen_Termin").First().Value;
  49.                     int year = int.Parse(cancel.Substring(0,4));
  50.                     int month = int.Parse(cancel.Substring(4,2));
  51.                     int day = int.Parse(cancel.Substring(6,2));
  52.  
  53.                     newCancelDate = new DateTime(year, month, day);
  54.                     determination = true;
  55.                 }
  56.                 else if (newCancellationMsg.AttributeList.Where(a => a.Name == "Vertragsende").Count() > 0)
  57.                 {
  58.                     string cancel = newCancellationMsg.AttributeList.Where(a => a.Name == "Vertragsende").First().Value;
  59.                     int year = int.Parse(cancel.Substring(0, 4));
  60.                     int month = int.Parse(cancel.Substring(4, 2));
  61.                     int day = int.Parse(cancel.Substring(6, 2));
  62.  
  63.                     newCancelDate = new DateTime(year, month, day);
  64.                 }
  65.  
  66.                 if (newCancellationMsg.AttributeList.Where(a => a.Name == "Referenz").Count() > 0)
  67.                 {
  68.                     string reference = newCancellationMsg.AttributeList.Where(a => a.Name == "Referenz").First().Value;
  69.                     sql = "SELECT U_PROCESSDOC FROM [@U_EGR_PROCESSDOC_L] WHERE U_EDI_REF_NO = '" + reference + "'";
  70.                     rs.DoQuery(sql);
  71.                     processDocument = ((object)rs.Fields.Item(0).Value).ToString();
  72.  
  73.                 }
  74.  
  75.                 sql = "SELECT U_DETERMPERD, U_DETERMINPU, U_CONTRACT, U_CTEXTENSIO FROM [@U_EGR_OPPORTUNITY_L], [@U_EGR_CONTRACT] WHERE U_PROCESSDOC ='" + processDocument + "' AND " +
  76.                     "[@U_EGR_OPPORTUNITY_L].U_CONTRACT = [@U_EGR_CONTRACT].U_CONTRACT";
  77.  
  78.                 rs.DoQuery(sql); //get next possible cancel date & previous cancel date
  79.                 nextPossibleCancelDate = (DateTime)rs.Fields.Item(0).Value;
  80.                 oldCancelDate = (DateTime)rs.Fields.Item(1).Value;
  81.                 contract = ((object)rs.Fields.Item(2).Value).ToString();
  82.                 contractExtensionDate = (DateTime)rs.Fields.Item(3).Value;
  83.  
  84.                 if (oldCancelDate > new DateTime(1900, 1, 1)) //contract was already canceled
  85.                 {
  86.                     //get old cancellation date from old cancellation message
  87.                     sql = "SELECT [@U_EGR_PROCESSDOC_L].U_MSGID FROM " +
  88.                           " [@U_EGR_PROCESSDOC_L], [@U_EGR_C_PROCESSTYPE], [@U_EGR_PROCESSDOC_H], [@U_EGR_CONTRACT], [@U_EGR_CONTRACT_LINK], [@U_EGR_SUPPLYCT], [@U_EGR_PODLINK] WHERE " +
  89.                           " [@U_EGR_PROCESSDOC_L].U_PROCESSDOC = [@U_EGR_PROCESSDOC_H].U_PROCESSDOC AND " +
  90.                           " [@U_EGR_CONTRACT_LINK].U_CHCONTRACT = [@U_EGR_CONTRACT].U_CONTRACT AND " +
  91.                           " [@U_EGR_CONTRACT_LINK].U_PACONTRACT = [@U_EGR_SUPPLYCT].U_SUPPLYCT AND " +
  92.                           " [@U_EGR_PROCESSDOC_H].U_POD = [@U_EGR_PODLINK].U_POD AND " +
  93.                           " [@U_EGR_PODLINK].U_INSTALL = [@U_EGR_SUPPLYCT].U_INSTALL AND " +
  94.                           " [@U_EGR_PROCESSDOC_L].U_DATE = [@U_EGR_CONTRACT].U_DETERMINPU AND " +
  95.                           " [@U_EGR_PROCESSDOC_H].U_PROCESSTYP = [@U_EGR_C_PROCESSTYPE].U_PROCESSTYP AND " +
  96.                           " [@U_EGR_C_PROCESSTYPE].U_CATEGORY = 'E35' AND " + //E35 - cancellation
  97.                           " [@U_EGR_CONTRACT_LINK].U_RELTYPE = 'VS' AND " + //VS - supply contract
  98.                           " [@U_EGR_CONTRACT].U_CONTRACT = '" + contract + "'";
  99.  
  100.                     rs.DoQuery(sql);
  101.                     string xmlguid = rs.Fields.Item(0).Value;
  102.  
  103.                     ProcessXMLDocument oldCanceallationMsg = new ProcessXMLDocument(new Guid(xmlguid));
  104.                     if (oldCanceallationMsg.AttributeList.Where(a => a.Name == "Kündigungsdatum").Count() > 0)
  105.                     {
  106.                         string cancel = oldCanceallationMsg.AttributeList.Where(a => a.Name == "Kündigungsdatum").First().Value;
  107.                         int year = int.Parse(cancel.Substring(0, 4));
  108.                         int month = int.Parse(cancel.Substring(4, 2));
  109.                         int day = int.Parse(cancel.Substring(6, 2));
  110.  
  111.                         oldCancelDate = new DateTime(year, month, day);
  112.                     }
  113.                 }
  114.  
  115.                 //check if cancellation is in time for determination period, if not re-assign to contract extension date
  116.                 if (DateTime.Now.Date > nextPossibleCancelDate.Date)
  117.                 {
  118.                     nextPossibleCancelDate = contractExtensionDate;
  119.                 }
  120.  
  121.                 if (determination) //cancellation for next possible date requested
  122.                 {
  123.                     answer.AnswerType = "nmgl 471";
  124.                     if (oldCancelDate < new DateTime(1900, 1, 1)) //no cancelation yet
  125.                     {
  126.                         if (newCancelDate >= nextPossibleCancelDate) //cancel date >= next possible cancel date
  127.                         {
  128.                             answer.Answer = "E15";// - Zustimmung ohne Korrekturen    
  129.                             answer.ResultingCancelDate = nextPossibleCancelDate;
  130.                         }
  131.                         else if (newCancelDate > new DateTime(1900, 1, 1)) //fixed cancel date < next possible cancel date
  132.                         {
  133.                             answer.Answer = "Z01"; //- Zustimmung mit Terminänderung
  134.                             answer.ResultingCancelDate = nextPossibleCancelDate;
  135.                         }
  136.                         else //cancellation for next possible cancel date, no fixed date
  137.                         {
  138.                             answer.Answer = "E15";// - Zustimmung ohne Korrekturen    
  139.                             answer.ResultingCancelDate = nextPossibleCancelDate;
  140.                         }
  141.                     }
  142.                     else //contract was canceled already
  143.                     {
  144.                         answer.AnswerType = "fix 93";
  145.  
  146.                         if (newCancelDate > oldCancelDate)
  147.                         {
  148.                             answer.Answer = "Z29";// - Ablehnung kein Vertragsverhältnis
  149.                         }
  150.                         else if (newCancelDate == oldCancelDate)
  151.                         {
  152.                             answer.Answer = "Z14"; // - Ablehnung Doppelmeldung
  153.                         }
  154.                         else if (newCancelDate >= nextPossibleCancelDate) //new cancel date before old one but same or later then next possible cancel date
  155.                         {
  156.                             answer.Answer = "E15";// - Zustimmung ohne Korrekturen  
  157.                             answer.ResultingCancelDate = newCancelDate;
  158.                         }
  159.                         else if (oldCancelDate == nextPossibleCancelDate) //new cancel date before old one but same or later then next possible cancel date
  160.                         {
  161.                             answer.Answer = "Z34";// - Ablehnung Mehrfachkündigung
  162.                         }
  163.                         else //new cancel date before next possible date and before old date
  164.                         {
  165.                             answer.Answer = "Z01"; //- Zustimmung mit Terminänderung
  166.                             answer.ResultingCancelDate = nextPossibleCancelDate;
  167.                         }
  168.                     }
  169.                 }
  170.                 else //cancellation for next possible date NOT requested
  171.                 {
  172.                     if (oldCancelDate < new DateTime(1900, 1, 1)) //no cancelation yet
  173.                     {
  174.                         if (newCancelDate >= nextPossibleCancelDate)
  175.                         {
  176.                             answer.Answer = "E15";// - Zustimmung ohne Korrekturen  
  177.                             answer.ResultingCancelDate = newCancelDate;
  178.                         }
  179.                         else //fixed cancel date < next possible cancel date
  180.                         {
  181.                             answer.Answer = "Z12"; //- Ablehnung Vertragsbindung
  182.                         }
  183.                     }
  184.                     else //contract was canceled already
  185.                     {
  186.                         if (newCancelDate > oldCancelDate)
  187.                         {
  188.                             answer.Answer = "Z29";// - Ablehnung kein Vertragsverhältnis
  189.                         }
  190.                         else if (newCancelDate == oldCancelDate)
  191.                         {
  192.                             answer.Answer = "Z14"; // - Ablehnung Doppelmeldung
  193.                         }
  194.                         else if (newCancelDate >= nextPossibleCancelDate) //new cancel date before old one but same or later then next possible cancel date
  195.                         {
  196.                             answer.Answer = "E15";// - Zustimmung ohne Korrekturen    
  197.                             answer.ResultingCancelDate = newCancelDate;
  198.                         }
  199.                         else if (oldCancelDate == nextPossibleCancelDate) //new cancel date before old one but same or later then next possible cancel date
  200.                         {
  201.                             answer.Answer = "Z34";// - Ablehnung Mehrfachkündigung
  202.                         }
  203.                     }
  204.                    
  205.                     sql = "UPDATE [@U_EGR_CONTRACT] SET U_DETERMPINU = '"+ answer.ResultingCancelDate.ToShortDateString() +"' WHERE U_CONTRACT = '" + contract + "'";
  206.                     rs.DoQuery(sql);
  207.                 }
  208.  
  209.             }
  210.             catch (Exception ex)
  211.             {
  212.                 Console.WriteLine("??? error: " + ex);
  213.             }
  214.  
  215.             return answer;
  216.         }
  217.  
  218.  
  219.  
  220.  
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement