Example #1
0
        private Error processPick(PickHeaderModel pickH,
                                  FileTransferConfigurationModel template)
        {
            var error = new Error();

            // Load the template configuration file
            var configFile = getTemplateFileName(template);

            XElement doc  = XElement.Load(configFile);
            var      file = doc.Element("File");
            var      extn = file.Attribute("DataFileExtension").Value;

            var tempFile = Path.GetTempPath() + pickH.Id + ".CSV";   // extn;
            var zipFile  = "";

            // Check if the pick's files are to be compressed and sent in a ZIP.
            // A pick can be a single CSV file or a CSV with onr or more PDF's.
            // A single file can optionally be compressed whereas multiple files must be compressed
            // as a package of files.
            // The requirement is that a single file is dropped for FTP.
            bool bCompress = file.Attribute("CompressFile").Value.ParseBool();

            if (bCompress || pickH.PickFiles.Count() > 1)
            {
                // File(s) are to be compressed/combined
                zipFile = tempFile.ChangeExtension(".zip");

                error = Zip.ZipFiles(pickH.PickFiles, zipFile);

                if (error.IsError)
                {
                    FileManagerService.FileManagerService.DeleteFile(zipFile);
                }
                else
                {
                    tempFile = zipFile;
                }
            }

            if (!error.IsError)
            {
                if (file.Attribute("FTPFile").Value.ParseBool())
                {
                    // Copy the file to the FTP pickup folder
                    error = moveFileToFTPFolder(tempFile,
                                                template.SourceFolder,
                                                DataTransferService.GetTargetFileName(template,
                                                                                      tempFile,
                                                                                      pickH.Id));
                }
            }
            FileManagerService.FileManagerService.DeleteFile(tempFile);

            return(error);
        }
Example #2
0
        private Error createDocuments(CompanyModel company, List <PickHeaderModel> picks)
        {
            var error = new Error();

            var pick = picks.FirstOrDefault();      // Validation ensures that there will always be at least one pick

            var location = LookupService.FindLocationModel(pick.LocationId.Value, false);

            if (location != null && location.LocationIdentification.ToLower() == "warehouse")
            {
                // Warehouse requires supporting PDF document

                // TBD: The type of PDF is specified in the customer record
                // Combined orders can only be for the same customer, so there will only
                // ever be one customer, irrespective of single or combined picks.
                var customer = db.FindCustomer(pick.CustomerId ?? 0);
                if (customer == null)
                {
                    error.SetRecordError("Customer", pick.CustomerId ?? 0);
                }
                else
                {
                    var template = LookupService.FindDocumentTemplateModel(customer.ShippingTemplateId ?? 0);

                    var config = DataTransferService.FindFileTransferConfigurationForWarehouseModel(location, FileTransferDataType.WarehousePick);
                    if (config == null)
                    {
                        error.SetError(EvolutionResources.errCannotDropOrderNoDataTransfer, pick.Id.ToString(), location.LocationName);
                    }
                    else
                    {
                        var pdfFile = MediaServices.GetMediaFolder(MediaFolder.Temp, company.Id) +
                                      DataTransferService.GetTargetFileName(config, "", pick.Id).ChangeExtension(".pdf");
                        string outputFile = "";
                        error = CreatePickDocumentPdf(pick, template, pdfFile, false, ref outputFile, int.MaxValue);
                        pick.PickFiles.Add(outputFile);

                        // TBD: Add the document to the sale notes/attachments
                    }
                }
            }

            return(error);
        }