//public string GetOrderPDFFilePDO(int iPDOOrderID)
        //{
        //    try
        //    {
        //        OrderPDOFullModel rfm = orderPDORepo.GetOrderByID(iPDOOrderID);
        //        string curFile = "";
        //        string sResult = "";

        //        if (rfm != null)
        //        {
        //            rfm.NarociloStevilka_P = (rfm.NarociloStevilka_P != null) ? rfm.NarociloStevilka_P : "xxx";

        //            // če je 5x neuspešno, potem se pošlje mail Daniju
        //            if ((rfm.P_UnsuccCountCreatePDFPantheon >= 5) && (rfm.P_SendWarningToAdmin == 0))
        //            {

        //                messageRepo.CreateEmailForAdmin_NoPDFForOrder("", rfm.NarociloStevilka_P.ToString(), rfm.P_TransportOrderPDFName, false);
        //                rfm.P_SendWarningToAdmin = 1;
        //                return "NOT_EXIST";
        //            }
        //            else if (rfm.P_SendWarningToAdmin == 1)
        //            {
        //                DataTypesHelper.LogThis("Za naročilo št. " + rfm.NarociloStevilka_P + " ni bilo kreirano PDF in je bil poslal že mail administraotrju.");
        //                return "NOT_EXIST";
        //            }

        //            curFile = ((rfm.P_TransportOrderPDFDocPath != null) && (rfm.P_TransportOrderPDFDocPath.Length > 0)) ? rfm.P_TransportOrderPDFDocPath : "";

        //            sResult = File.Exists(curFile) ? "EXIST" : "NOT_EXIST";
        //        }

        //        if (sResult != "EXIST")
        //        {
        //            LaunchPantheonCreatePDF();
        //            rfm.P_UnsuccCountCreatePDFPantheon++;
        //            rfm.P_LastTSCreatePDFPantheon = DateTime.Now;
        //        }
        //        else
        //        {
        //            InquiryStatus stat = orderPDORepo.GetPovprasevanjaStatusByCode(Enums.StatusOfInquiry.KREIRAN_POSLAN_PDF.ToString());
        //            if (stat != null)
        //            {
        //                rfm.StatusID = stat.StatusPovprasevanjaID;
        //                rfm.P_GetPDFOrderFile = DateTime.Now;
        //                // Create mail for prevoznik
        //                messageRepoPDO.CreateEmailForSupplierOrder(rfm);
        //            }

        //        }

        //        orderPDORepo.SaveOrder(rfm, true, false);

        //        return sResult;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}


        public void CreateOrderTransport(CreateOrderModel model)
        {
            try
            {
                RecallFullModel rfm = recallRepo.GetRecallFullModelByID(model.RecallID);

                if (rfm.P_CreateOrder.Year < 2000)
                {
                    DataTypesHelper.LogThis("cREATE oRDER xml");
                    string xml = GetXMLForOrder(model);
                    DataTypesHelper.LogThis(xml);

                    DataTypesHelper.LogThis("Run Create order procedure _upJM_CreateSupplierOrder");
                    // run store procedure _upJM_CreateSupplierOrder
                    CreateOrderDocument coData = sqlFunctionRepo.GetOrderDocumentData(xml);


                    DataTypesHelper.LogThis("Update Create order Recall Data");
                    // update odpoklic - uspešno kreirana naročilnica v pantheonu


                    RecallStatus stat = recallRepo.GetRecallStatusByCode(Enums.StatusOfRecall.USTVARJENO_NAROCILO.ToString());
                    if (stat != null)
                    {
                        rfm.StatusID = stat.StatusOdpoklicaID;
                    }

                    rfm.P_UnsuccCountCreatePDFPantheon = 0;
                    rfm.P_CreateOrder              = DateTime.Now;
                    rfm.P_TransportOrderPDFName    = coData.PDFFile.ToString();
                    rfm.P_TransportOrderPDFDocPath = coData.ExportPath.ToString();
                    recallRepo.SaveRecall(rfm, true);

                    //DataTypesHelper.LogThis("Launch Create PDF Pantheon.exe");
                    // launch Pantheon EXE command
                    //LaunchPantheonCreatePDF();
                    DataTypesHelper.LogThis("Finish CreateOrderTransport");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private string GetXMLForOrder(CreateOrderModel model)
        {
            var directory = AppDomain.CurrentDomain.BaseDirectory;
            //string sPath = directory + "OrderTransport_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm") + ".xml";
            //XmlTextWriter xml = new XmlTextWriter(sPath, Encoding.Unicode);
            MemoryStream  stream = new MemoryStream(); // The writer closes this for us
            XmlTextWriter xml    = new XmlTextWriter(stream, Encoding.Unicode);

            xml.Formatting = Formatting.Indented;
            xml.WriteStartDocument(true);

            try
            {
                xml.WriteStartElement("Recall");

                xml.WriteElementString("timestamp", DateTime.Now.ToString());
                xml.WriteElementString("DocType", model.TypeCode);
                xml.WriteElementString("Department", "");

                RecallFullModel rfm           = recallRepo.GetRecallFullModelByID(model.RecallID);
                var             TransportData = clientRepo.GetClientByID(rfm.DobaviteljID);
                if (ConfigurationManager.AppSettings["PantheonCreateOrderDefBuyer"] != null)
                {
                    xml.WriteElementString("Buyer", ConfigurationManager.AppSettings["PantheonCreateOrderDefBuyer"].ToString());
                }
                else
                {
                    xml.WriteElementString("Buyer", "");
                }

                //var employee = employeePdoRep.GetEmployeeByID(model.tsIDOsebe);
                //string ReferentID = employee.PantheonUsrID.Length > 0 ? employee.PantheonUsrID : "";

                xml.WriteElementString("Supplier", TransportData.NazivPrvi);
                xml.WriteElementString("OrderDate", DateTime.Now.ToString());
                xml.WriteElementString("LoadDate", rfm.DatumNaklada.ToString());
                xml.WriteElementString("Route", rfm.Relacija.Naziv);

                string lgn       = (TransportData.JezikID > 0) ? TransportData.JezikOTP.Koda : "SLO";
                string printType = (lgn == "SLO") ? Enums.PrintType.A10.ToString() : Enums.PrintType.A0Q.ToString();
                xml.WriteElementString("PrintType", printType);

                xml.WriteElementString("OrderPDFPath", ConfigurationManager.AppSettings["ServerOrderPDFPath"].ToString());
                xml.WriteElementString("OrderNote", model.Note);
                xml.WriteStartElement("Products");

                foreach (ServiceListModel _serv in model.services)
                {
                    xml.WriteStartElement("Product");
                    xml.WriteElementString("Department", "");
                    xml.WriteElementString("Ident", _serv.Code);
                    xml.WriteElementString("Name", _serv.Name);
                    xml.WriteElementString("Qty", _serv.Quantity.ToString());
                    xml.WriteElementString("Price", _serv.Price.ToString());
                    xml.WriteElementString("Rabat", "");
                    xml.WriteElementString("Note", "");
                    xml.WriteEndElement();  // Product
                }

                xml.WriteEndElement();  // Products
                xml.WriteEndElement();  // Recall
            }
            catch (Exception ex)
            {
                DataTypesHelper.LogThis(ex.Message + "\r\n " + ex.Source + "\r\n " + ex.StackTrace);
            }
            finally
            {
                xml.Flush();
            }
            string       result;
            StreamReader reader = new StreamReader(stream, Encoding.Unicode, true);

            stream.Seek(0, SeekOrigin.Begin);
            result = reader.ReadToEnd();

            return(result);
        }
        public string GetOrderPDFFile(int iRecallID)
        {
            try
            {
                RecallFullModel rfm     = recallRepo.GetRecallFullModelByID(iRecallID);
                string          curFile = "";
                string          sResult = "";

                if (rfm != null)
                {
                    //če je 5x neuspešno, potem se pošlje mail Daniju
                    if ((rfm.P_UnsuccCountCreatePDFPantheon >= 5) && (rfm.P_SendWarningToAdmin == 0))
                    {
                        RecallStatus stat = recallRepo.GetRecallStatusByCode(Enums.StatusOfRecall.ERR_ADMIN_MAIL.ToString());
                        if (stat != null)
                        {
                            rfm.StatusID = stat.StatusOdpoklicaID;
                        }
                        messageRepo.CreateEmailForAdmin_NoPDFForOrderOTP("", rfm.OdpoklicStevilka.ToString(), rfm.P_TransportOrderPDFName);
                        rfm.P_SendWarningToAdmin = 1;
                        recallRepo.SaveRecall(rfm, true);
                        return("NOT_EXIST");
                    }
                    else if (rfm.P_SendWarningToAdmin == 1)
                    {
                        RecallStatus stat = recallRepo.GetRecallStatusByCode(Enums.StatusOfRecall.ERR_ADMIN_MAIL.ToString());
                        if (stat != null)
                        {
                            rfm.StatusID = stat.StatusOdpoklicaID;
                        }

                        DataTypesHelper.LogThis("Za naročilo št. " + rfm.OdpoklicStevilka + " ni bilo kreirano PDF in je bil poslal že mail administratorju.");
                        return("NOT_EXIST");
                    }
                    //TimeSpan timeDiff = DateTime.Now - rfm.P_LastTSCreatePDFPantheon;
                    //if (timeDiff.TotalMinutes < 5) return "";

                    curFile = ((rfm.P_TransportOrderPDFDocPath != null) && (rfm.P_TransportOrderPDFDocPath.Length > 0)) ? rfm.P_TransportOrderPDFDocPath : "";
                    sResult = File.Exists(curFile) ? "EXIST" : "NOT_EXIST";



                    if (sResult != "EXIST")
                    {
                        RecallStatus stat = recallRepo.GetRecallStatusByCode(Enums.StatusOfRecall.ERR_ORDER_NO_SEND.ToString());
                        if (stat != null)
                        {
                            rfm.StatusID = stat.StatusOdpoklicaID;
                        }
                        DataTypesHelper.LogThis("NOT EXIST : " + rfm.OdpoklicStevilka);

                        LaunchPantheonCreatePDF();
                        rfm.P_UnsuccCountCreatePDFPantheon++;
                        rfm.P_LastTSCreatePDFPantheon = DateTime.Now;
                    }
                    else
                    {
                        RecallStatus stat = recallRepo.GetRecallStatusByCode(Enums.StatusOfRecall.KREIRAN_POSLAN_PDF.ToString());
                        if (stat != null)
                        {
                            DataTypesHelper.LogThis("Exist send order to carriaer: " + rfm.OdpoklicStevilka);
                            rfm.StatusID          = stat.StatusOdpoklicaID;
                            rfm.P_GetPDFOrderFile = DateTime.Now;
                            // Create mail for prevoznik
                            DataTypesHelper.LogThis("Start send email: " + rfm.OdpoklicStevilka);
                            messageRepo.CreateEmailForCarrierOrder(rfm);
                        }
                    }

                    recallRepo.SaveRecall(rfm, true);
                }
                return(sResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }