示例#1
0
        //Search Individual Invoice from Service Trade
        public List <FSTINV> searchInvoice(string invoiceId)
        {
            List <FSTINV> Invoices = new List <FSTINV>();

            var invoice = serviceTrade.GetInvoice(invoiceId);

            if (invoice != null)
            {
                Invoices.Add(invoice);
            }

            return(Invoices);
        }
        //Update Invoice in service Trade to Done
        private void SendInvoiceUpdates(iDB2Command db2Command)
        {
            st.insertLog("Sending invoice update to Service Trade.", "info", "NA", LogId);

            Dictionary <string, Invoice> jdeInvList = new Dictionary <string, Invoice>();

            using (iDB2Transaction db2Transaction = db2Command.Connection.BeginTransaction())
            {
                db2Command.Transaction = db2Transaction;

                db2Command.CommandText = string.Format("SELECT DISTINCT SIID, SIAN8, SIJOB, SIDOCO, SIDCTO, SICRDT FROM FSTINV WHERE SISTAT = 'P'");

                iDB2DataReader reader = db2Command.ExecuteReader();

                while (reader.Read())
                {
                    Invoice temp = new Invoice();
                    temp.SIID = ((string)reader["SIID"]).Trim();
                    temp.type = "invoice";
                    //always set this to processed status to avoid breaking the status in ST
                    temp.status = "processed";
                    temp.jobId  = Int32.Parse((string)reader["SIJOB"]);
                    //Change Invoice Number (Concat JDE Document Number and Document Type with -)
                    temp.invoiceNumber   = string.Format("{0}-{1}", reader["SIDOCO"], reader["SIDCTO"]);
                    temp.transactionDate = (Int32)((DateTime)reader["SICRDT"] - unixBaseTime).TotalSeconds;
                    //temp.assignedUserId= Int32.Parse((string)reader["SITECH"]);

                    //09/18/2015 - This limits the invoices being sent for update in ST.
                    //if (!jdeInvList.ContainsKey((string)reader["SIAN8"]))
                    //{
                    //    jdeInvList.Add((string)reader["SIAN8"], temp);
                    //    sent++;
                    //}

                    if (reader["SIAN8"] != null)
                    {
                        //12/19/16 JC: This will avoid duplicate records.
                        if (!jdeInvList.ContainsKey(temp.SIID))
                        {
                            jdeInvList.Add((string)temp.SIID, temp);
                        }
                    }
                }

                reader.Close();
            }

            db2Command.Transaction.Dispose();

            if (jdeInvList.Count > 0)
            {
                st.insertLog(string.Format("Found {0} invoices for update", jdeInvList.Count), "Info", "NA", LogId);

                foreach (var jde in jdeInvList)
                {
                    //var status = jde.Value.status;

                    //Query the single invoice from the service Trade
                    var invoice = serviceTrade.GetInvoice(jde.Key);

                    //Mark the invoice as done in FSTINV, if the status of the invoice is void in Service Trade
                    if (invoice.Status == "void" || invoice.Status != "pending_accounting")
                    {
                        st.insertLog(string.Format("The status of invoice number {0} is not <pending_accounting> in service Trade.", jde.Key), "Error", jde.Key.ToString(), LogId);
                        SetInvoiceToDone(db2Command, jde.Value);
                    }
                    else
                    {
                        if (serviceTrade.UpdateInvoice(jde.Value))
                        {
                            st.insertLog(string.Format("The status of invoice number {0} is set to processed in Service Trade.", jde.Key), "Info", jde.Key.ToString(), LogId);
                            SetInvoiceToDone(db2Command, jde.Value);
                        }
                    }
                }
            }
            else
            {
                st.insertLog("No invoice update to be sent.", "Info", "NA", LogId);
            }
        }