public async Task <ActionResult <ExportOrder> > Add(ExportOrder exportOrder)
        {
            exportOrder.Exp_Date = DateTime.Now;
            _db.Add(exportOrder);
            await _db.SaveChangesAsync();

            return(CreatedAtAction("get", new { id = exportOrder.Id }, exportOrder));
        }
Beispiel #2
0
        public ActionResult CustomExportOrders(ExportOrder model)
        {
            var fileName = _orderService.CustomExportOrderAsync(model);
            var fileInfo = new FileInfo(fileName);

            Response.Clear();
            Response.ContentType = "text/csv";
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-disposition", string.Format("attachment; filename=\"{0:MM}{0:dd}{0:yyyy}-{0:HH}{0:mm}{0:ss}_CustomExportOrders.csv\"", model.RequestedDate));
            Response.TransmitFile(fileInfo.FullName);
            Response.Flush();
            Response.End();

            return(null);
        }
        public async Task <bool> CreateOperations(ExportOrder exportOrder, CancellationToken cancellationToken)
        {
            var tableNumber = exportOrder.TableNumber;

            foreach (var dish in exportOrder.Dishes)
            {
                var obj = await this.dbContext
                          .Objects
                          .FirstOrDefaultAsync(c => c.Code == tableNumber.ToString(), cancellationToken);

                var operation = new Operations
                {
                    OperType     = 33,
                    Acct         = 0,
                    GoodId       = dish.GoodId,
                    PartnerId    = 2,
                    ObjectId     = obj.Id,
                    OperatorId   = exportOrder.OperatorId,
                    Qtty         = dish.Quantity,
                    Sign         = 0,
                    PriceIn      = 0, // ???
                    PriceOut     = 0,
                    Vatin        = 0,
                    Vatout       = 0,
                    Discount     = 0,
                    CurrencyId   = 1,
                    CurrencyRate = 0,
                    Date         = DateTime.Now.Date,
                    Lot          = "1",
                    LotId        = 1,
                    Note         = "",
                    SrcDocId     = 0,
                    UserId       = 4,
                    UserRealTime = DateTime.Now
                };

                this.dbContext.Operations.Add(operation);
            }

            var result = await this.dbContext.SaveChangesAsync(cancellationToken);

            return(result > 0);
        }
Beispiel #4
0
        private string createCustomExportSqlQuery(ExportOrder model)
        {
            var sqlQuery     = string.Empty;
            var sqlPredicate = new StringBuilder();

            if (model.IsAllOderItems)
            {
                var orderQuery = @"
                                    SELECT {0} FROM orders
                                    LEFT JOIN orderitems ON orderitems.OrderId = orders.OrderId 
                                    {1} {2};";

                if (model.ExcludedEisOrderIdArr.Any())
                {
                    sqlPredicate.Append(" AND orders.EisOrderId NOT IN(");
                    sqlPredicate.AppendFormat("'{0}'", string.Join("','", model.ExcludedEisOrderIdArr));
                    sqlPredicate.Append(") ");
                }

                sqlQuery = string.Format(orderQuery, string.Join(",", model.OrderFields)
                                         , sqlPredicate.ToString()
                                         , (string.IsNullOrEmpty(model.SortBy) ? string.Empty : (" ORDER BY " + model.SortBy)));
            }
            else
            {
                sqlQuery = @"
                                    SELECT {0} FROM orders
                                    LEFT JOIN orderitems ON orderitems.OrderId = orders.OrderId
                                    WHERE orders.EisOrderId IN ('{1}') {2};";

                sqlQuery = string.Format(sqlQuery, string.Join(",", model.OrderFields)
                                         , string.Join("','", model.SelectedEisOrderIdArr)
                                         , (string.IsNullOrEmpty(model.SortBy) ? string.Empty : (" ORDER BY " + model.SortBy)));
            }


            return(sqlQuery);
        }
Beispiel #5
0
        // TODO: NEED TO ADD IMPLEMENTATION CODE
        public string CustomExportOrderAsync(ExportOrder model)
        {
            var sqlQuery = string.Empty;
            var filePath = string.Format("{1}\\{0:MM}{0:dd}{0:yyyy}-{0:HH}{0:mm}{0:ss}_CustomExportOrders.csv", model.RequestedDate, _exportFolder);

            try
            {
                using (var streamWriter = new StreamWriter(filePath))
                {
                    using (var conn = new MySqlConnection(_connectionString))
                    {
                        var reader = MySqlHelper.ExecuteReader(conn, CommandType.Text, createCustomExportSqlQuery(model), null);
                        var config = new CsvConfiguration();
                        config.Delimiter = model.Delimiter;

                        var csvWriter = new CsvWriter(streamWriter, config);

                        // write the header text for the CSV files
                        foreach (var field in model.OrderFieldsArr)
                        {
                            csvWriter.WriteField(removePrefixTable(field));
                        }

                        csvWriter.NextRecord();

                        while (reader.Read())
                        {
                            foreach (var field in model.OrderFieldsArr)
                            {
                                var fieldName = removePrefixTable(field);
                                if (fieldName == "TrackingNumber")
                                {
                                    var trackingNumber = reader[fieldName].ToString();
                                    if (!String.IsNullOrEmpty(trackingNumber))
                                    {
                                        if (trackingNumber.Length == 22)
                                        {
                                            //Format USPS Tracking No.
                                            trackingNumber = Regex.Replace(trackingNumber, @"^(..)(....)(....)(....)(....)(....)$", "$1-$2-$3-$4-$5-$6");
                                            csvWriter.WriteField(trackingNumber);
                                        }
                                        else
                                        {
                                            //Format FedEx Tracking Number
                                            trackingNumber = Regex.Replace(trackingNumber, @"^(..)(....)(....)(....)(....)(..)$", "$1-$2-$3-$4-$5-$6");
                                            csvWriter.WriteField(trackingNumber);
                                        }
                                    }
                                    else
                                    {
                                        csvWriter.WriteField(trackingNumber);
                                    }
                                }
                                else
                                {
                                    csvWriter.WriteField(reader[fieldName]);
                                }
                            }

                            csvWriter.NextRecord();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(filePath);
        }