public ShippingModel SaveInvoice(List <FacturaModel> ord, ShippingModel shipping)
        {
            try
            {
                shipping.error.HasError = false;
                using (var pdfViewer = new DevExpress.XtraPdfViewer.PdfViewer())
                {
                    XtraReport rem = new FacturaCoordinadora();
                    rem.DataSource = ord;

                    rem.ShowPrintStatusDialog = false;
                    rem.PaperKind             = System.Drawing.Printing.PaperKind.Custom;
                    //string path= Properties.Settings.Default.INVOICE_PATH + shipping.guide.Code + ".pdf";

                    string path = @"C:\Kiosko\temp\invoice\" + shipping.guide.Code + ".pdf";
                    rem.CreateDocument(false);
                    rem.ExportToPdf(path);

                    //rem.ExportToPdf(path);
                    //PaperSize paperSize = new PaperSize("Print", (int)(800 / 2.94), (int)(rem.PageHeight / 2.94));
                    //paperSize.RawKind = (int)PaperKind.Custom;
                    //sets.PaperSize = paperSize;
                    //pdfViewer.LoadDocument(path);
                    //pdfViewer.ShowPrintStatusDialog = false;
                    //pdfViewer.Print(sett);
                    //pdfViewer.CloseDocument();
                }
            }
            catch (SystemException E)
            {
                shipping.error.HasError = true;
                shipping.error.Message  = E.Message;

                return(shipping);
            }
            return(shipping);
        }
        public ShippingModel GenerateGuide(ShippingModel shipping)
        {
            List <Agw_typeGuiaDetalle>    empaque = new List <Agw_typeGuiaDetalle>();
            List <Agw_typeNotificaciones> notif   = new List <Agw_typeNotificaciones>();

            ServiceGuiaManagement = new JRpcServerSoapManagerService();



            foreach (var values in shipping.content.Measures)
            {
                if (values.Weight < 1)
                {
                    values.Weight = 1;
                }
                if (values.Height == 0 || values.Width == 0 || values.Length == 0)
                {
                    values.Height = 1;
                    values.Width  = 1;
                    values.Length = 1;
                }

                empaque.Add(new Agw_typeGuiaDetalle()
                {
                    alto     = (float)values.Height,
                    ancho    = (float)values.Width,
                    largo    = (float)values.Length,
                    peso     = (float)values.Weight,
                    ubl      = GetProductCode(),
                    unidades = 1
                });
            }

            notif.Add(new Agw_typeNotificaciones()
            {
                destino_notificacion = shipping.origin.Email,
                tipo_medio           = "1"
            });

            Agw_typeGenerarGuiaIn Guia = new Agw_typeGenerarGuiaIn
            {
                centro_costos = "Kiosko_1",
                //notificaciones = notif.ToArray(),
                clave = PWD,

                id_cliente             = 29508,
                nombre_remitente       = shipping.origin.Name,
                direccion_remitente    = shipping.origin.Location.Address,
                telefono_remitente     = shipping.origin.Phone,
                ciudad_remitente       = shipping.origin.Location.CityCode,
                nit_destinatario       = shipping.receiver.Identification,
                nombre_destinatario    = shipping.receiver.Name,
                direccion_destinatario = shipping.receiver.Location.Address,
                ciudad_destinatario    = shipping.receiver.Location.CityCode,
                telefono_destinatario  = shipping.receiver.Phone,
                valor_declarado        = (float)shipping.content.Value,
                codigo_producto        = GetProductCode(),
                codigo_cuenta          = 1,
                nivel_servicio         = 1,
                contenido         = shipping.content.Description,
                referencia        = "Factura",
                observaciones     = "Guia generada por Kiosko",
                estado            = "IMPRESO",
                detalle           = empaque.ToArray(),
                margen_izquierdo  = 2,
                margen_superior   = 2,
                formato_impresion = "pdf",
                usuario           = "mekagroup.ws",
            };

            try
            {
                var response = ServiceGuiaManagement.Guias_generarGuia(Guia);
                shipping.guide.Code = response.codigo_remision;
                shipping.guide.Url  = response.url_terceros;
                shipping.guide      = GetPdfGuide(shipping).guide;


                CoordinadoraConfigModel configCoord = ConfigService.readCoordinadoraConfig();

                if (configCoord.BoxesInStorage == false)
                {////LLAMAR SERVICIO DE RECOGIDA.
                    ServiceCotizadorManagement = new RpcServerSoapManagerService();
                    Recogidas_solicitarIn recogida = new Recogidas_solicitarIn()
                    {
                        apikey          = APIKEY,
                        clave           = Cont,
                        fecha_recogida  = Utilities.GetDate(),
                        nit_cliente     = "900472103",
                        div_cliente     = "01",
                        nombre_contacto = "Kiosko",
                        direccion       = "Calle 67 52-20",
                        ciudad_origen   = Origen,
                        nombre_empresa  = "Mekagroup SAS",
                        referencia      = shipping.guide.Code,
                        estado          = 0,
                        telefono        = "3046570967",
                        producto        = 4,
                        modalidad       = 2,

                        ciudad_destino = shipping.receiver.Location.CityCode
                    };
                    Recogidas_solicitarOut sol = ServiceCotizadorManagement.Recogidas_programar(recogida);

                    configCoord.BoxesInStorage = true;
                    Kiosko.Helpers.Utilities.WriteJson(Properties.Settings.Default.PAYMENT_CONFIGURATION_PATH + "coordinadora.json", configCoord);
                }
                AlegraService alg = new AlegraService();

                ///REMOVE THIS ON RELEASE
                AlegraResult fact = alg.CreateDummyInvoice(shipping);


                //   = alg.CreateInvoice(shipping);
                FacturaCoordinadora factura = new FacturaCoordinadora();
                FacturaModel        mdl     = new FacturaModel();
                mdl.Model       = shipping;
                mdl.Res         = Utilities.GetResolucion();
                mdl.Direccion   = "Calle 12 sur # 51 79";
                mdl.NIT         = "900.472.103-1";
                mdl.RazonSocial = "MekaGroup SAS";
                mdl.FactNumber  = fact.numberTemplate.number;
                mdl.Fecha       = Utilities.GetDate();
                List <FacturaModel> lst = new List <FacturaModel>();
                lst.Add(mdl);



                SaveInvoice(lst, shipping);



                //attempt to save guide locally

                //factura.DataSource = lst;
                //PdfExportOptions pdfOptions = new PdfExportOptions();
                //factura.CreateDocument(true);
                //factura.ExportToPdf(Properties.Settings.Default.GUIDE_PATH + "FACTURA.pdf");
                //factura.Dispose();
            }
            catch (Exception e)
            {
                shipping.error.HasError = true;
                shipping.error.Message  = "GenerateGuide : " + e.Message;
            }

            return(shipping);
        }