Guest User

Untitled

a guest
Mar 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 10.15 KB | None | 0 0
  1.  MocaResults res = moca.newResults();
  2.     MocaResults resLines = moca.newResults();
  3.     String cmd = "";
  4.     String unexpectedStatusClause = "";
  5.     String newRcvKey = "";
  6.     /* Check first if receiving an unexpected status is on... */
  7.     if (allowUnexpectedStatus == 1 && foundLines == 0)
  8.     {
  9.         moca.trace("Trying to create a line for unexpected inventory status...");
  10.         try
  11.         {
  12.             /* Did part existed in the receipt?
  13.              * Then select all the rcvlin attributtes
  14.              * and copy them over to the new rcvlin. */
  15.             cmd =   "  [select client_id, " +
  16.                     "          supnum, " +
  17.                     "          invnum, " +
  18.                     "          invlin, " +
  19.                     "          invsln, " +
  20.                     "          seqnum, " +
  21.                     "          retcod, " +
  22.                     "          orgcod, " +
  23.                     "          revlvl, " +
  24.                     "          lotnum, " +
  25.                     "          to_char(mandte, 'YYYYMMDDHH24MISS') mandte " +
  26.                     "     from rcvlin   " +
  27.                     "    where trknum = @trknum   " +
  28.                     "      and wh_id  = @wh_id   " +
  29.                     "      and prtnum = @prtnum   " +
  30.                     "      and blind_flg = 0   " +
  31.                     "      and @+client_id   " +
  32.                     "      and @+invnum   " +
  33.                     "      and @+supnum   " +
  34.                     "      and @+lotnum   " +
  35.                     "      and @+orgcod   " +
  36.                     "      and @+revlvl " +
  37.                     "    order by seqnum desc] >> res " +
  38.                     "  | " +
  39.                     "  publish top rows where res = @res and rows = 1 ";
  40.             res = moca.executeInline(cmd);
  41.             res.next();
  42.             if (res.client_id == null || res.supnum == null  ||
  43.                 res.invnum == null || res.invlin == null  ||
  44.                 res.invsln == null || res.seqnum == null)
  45.             {
  46.                 throw new NotFoundException();
  47.             }
  48.             /* Check if manufacturing date is null */
  49.             if (res.mandte == null)
  50.             {
  51.                 mandte = "";
  52.             }
  53.             else
  54.             {
  55.                 mandte = res.mandte;
  56.             }
  57.             /* Create a duplicate line for the unexpected status inventory */
  58.             cmd = " create receive invoice line  " +
  59.                   "  where trknum = '" + trknum + "'" +
  60.                   "    and wh_id  = '" + wh_id + "'" +
  61.                   "    and prtnum = '" + prtnum + "'" +
  62.                   "    and rcvsts = '" + invsts + "'" +
  63.                   "    and client_id = '" + res.client_id + "'" +
  64.                   "    and supnum = '" + res.supnum + "'" +
  65.                   "    and invnum = '" + res.invnum + "'" +
  66.                   "    and invlin = '" + res.invlin + "'" +
  67.                   "    and invsln = '" + res.invsln + "'" +
  68.                   "    and seqnum = " + (res.seqnum + 1) +
  69.                   "    and orgcod = '" + res.orgcod + "'" +
  70.                   "    and revlvl = '" + res.revlvl + "'" +
  71.                   "    and lotnum = '" + res.lotnum + "'" +
  72.                   "    and mandte = '" + mandte + "'" +
  73.                   "    and expqty = 0 " +
  74.                   "    and exp_catch_qty = 0 ";
  75.             if (isReturnInvoice == 1)
  76.             {
  77.                 cmd = cmd +
  78.                       " and retcod = '" + res.retCod + "'";
  79.             }
  80.             /* Note:  Run on its own context, to avoid passing
  81.              *        the rcvkey from the list inventory */
  82.             res = moca.executeCommand(cmd);
  83.             res.next();
  84.             newRcvKey = res.rcvkey;
  85.             foundLines = 1;
  86.             moca.trace("   Success: Receive line was created for the inventory.");
  87.         }
  88.         catch(NotFoundException e)
  89.         {
  90.             moca.trace("   Error: Non of the Expected Receive Lines contains this part.");
  91.         }
  92.     }
  93.      /* Try creating an unexpected attribute receive line if still is required... */
  94.     if (allowUnexpectedAttribute == 1 && foundLines == 0)
  95.     {
  96.         moca.trace("Trying to create a line for receiving...");
  97.         try
  98.         {
  99.             if (allowUnexpectedStatus != 1)
  100.             {
  101.                 unexpectedStatusClause = " and rcvsts = @invsts ";
  102.             }
  103.             /* Did part existed in the receipt?
  104.              * Then select all the rcvlin attributtes
  105.              * and copy them over to the new rcvlin. */
  106.             cmd =   "  [select client_id, " +
  107.                     "          supnum, " +
  108.                     "          invnum, " +
  109.                     "          invlin, " +
  110.                     "          invsln, " +
  111.                     "          seqnum, " +
  112.                     "          retcod, " +
  113.                     "          orgcod, " +
  114.                     "          revlvl, " +
  115.                     "          lotnum, " +
  116.                     "          to_char(mandte, 'YYYYMMDDHH24MISS') mandte " +
  117.                     "     from rcvlin   " +
  118.                     "    where trknum = @trknum   " +
  119.                     "      and wh_id  = @wh_id   " +
  120.                     "      and prtnum = @prtnum   " +
  121.                     "      and blind_flg = 0   " +
  122.                     "      and @+client_id   " +
  123.                     "      and @+invnum   " +
  124.                     "      and @+supnum   " +
  125.                     "      and (lotnum = @lotnum or lotnum = '----') " +
  126.                     "      and (orgcod = @orgcod or orgcod = '----') " +
  127.                     "      and (revlvl = @revlvl or revlvl = '----') " + unexpectedStatusClause +
  128.                     "      and rownum < 2 " +
  129.                     "    order by seqnum desc]  >> res " +
  130.                     "  | " +
  131.                     "  publish top rows where res = @res and rows = 1 ";
  132.             res = moca.executeInline(cmd);
  133.             res.next();
  134.             if (res.client_id == null || res.supnum == null  ||
  135.                 res.invnum == null || res.invlin == null  ||
  136.                 res.invsln == null || res.seqnum == null)
  137.             {
  138.                 throw new NotFoundException();
  139.             }
  140.             /* Check if manufacturing date is null */
  141.             if (res.mandte == null)
  142.             {
  143.                 mandte = "";
  144.             }
  145.             else
  146.             {
  147.                 mandte = res.mandte;
  148.             }
  149.             /* Create a duplicate line for the unexpected attribute inventory */
  150.             cmd = " create receive invoice line  " +
  151.                   "  where trknum = '" + trknum + "'" +
  152.                   "    and wh_id  = '" + wh_id + "'" +
  153.                   "    and prtnum = '" + prtnum + "'" +
  154.                   "    and rcvsts = '" + invsts + "'" +
  155.                   "    and client_id = '" + res.client_id + "'" +
  156.                   "    and supnum = '" + res.supnum + "'" +
  157.                   "    and invnum = '" + res.invnum + "'" +
  158.                   "    and invlin = '" + res.invlin + "'" +
  159.                   "    and invsln = '" + res.invsln + "'" +
  160.                   "    and seqnum = '" + max_seq + "'" +
  161.                   "    and orgcod = '" + input_orgcod + "'" +
  162.                   "    and revlvl = '" + input_revlvl + "'" +
  163.                   "    and lotnum = '" + input_lotnum + "'" +
  164.                   "    and mandte = '" + mandte + "'" +
  165.               "    and blind_flg = 1   " +
  166.                   "    and expqty = 0 " +
  167.                   "    and exp_catch_qty = 0 ";
  168.             if (isReturnInvoice == 1)
  169.             {
  170.                 cmd = cmd +
  171.                       " and retcod = '" + res.retCod + "'";
  172.             }
  173.             /* Note:  Run on its own context, to avoid passing
  174.              *        the rcvkey from the list inventory */
  175.             res = moca.executeCommand(cmd);
  176.             res.next();
  177.             newRcvKey = res.rcvkey;
  178.             foundLines = 1;
  179.             moca.trace("   Success: Receive line was created for the inventory.");
  180.         }
  181.         catch(NotFoundException e)
  182.         {
  183.             moca.trace("   Error: Non of the Expected Receive Lines contains this part.");
  184.         }
  185.     }
  186.     /* Try creating a blind receive line if still is required... */
  187.     if (allowUnexpectedPart == 1 && foundLines == 0)
  188.     {
  189.         moca.trace("Trying to create a line for blind receiving...");
  190.         try
  191.         {
  192.             /* Get the invoice information to create a blind line */
  193.             cmd = " [select * " +
  194.                   "    from rcvinv " +
  195.                   "   where trknum = @trknum " +
  196.                   "     and invnum = @invnum " +
  197.                   "     and wh_id  = @wh_id " +
  198.                   "     and @+client_id " +
  199.                   "     and @+supnum] ";
  200.             res = moca.executeInline(cmd);
  201.             res.next();
  202.             /* Create the blind line for receiving this inventory */
  203.             cmd = " create blind receive invoice line  " +
  204.                   "  where trknum = '" + trknum + "'" +
  205.                   "    and invnum = '" + invnum + "'" +
  206.                   "    and wh_id  = '" + wh_id + "'" +
  207.                   "    and dtlnum = '" + dtlnum + "'" +
  208.                   "    and client_id = '" + res.client_id + "'" +
  209.                   "    and supnum = '" + res.supnum + "'";
  210.             /* Note:  Run on its own context, to avoid passing
  211.              *        the rcvkey from the list inventory */
  212.             res = moca.executeCommand(cmd);
  213.             res.next();
  214.             newRcvKey = res.rcvkey;
  215.             foundLines = 1;
  216.             moca.trace("   Success: Blind Receive line was created for the inventory.");
  217.         }
  218.         catch(NotFoundException e)
  219.         {
  220.             moca.trace("   Error: Invoice was not found, don't know where to create blind line against.");
  221.         }
  222.     }
  223.     /* By this time if a line was found, is because it got created... */
  224.     if (foundLines == 1 && newRcvKey != "")
  225.     {
  226.         /* Find the created matching lines which will be returned */
  227.         cmd = " [select * " +
  228.               "    from rcvlin " +
  229.               "   where rcvkey = '" + newRcvKey + "']";
  230.         resLines = moca.executeInline(cmd);
  231.     }
  232.     /* publish the result set out */
  233.     resLines
Add Comment
Please, Sign In to add comment