// POST http://ganetest.qsrtime.net/api/sync/post-order-processes
        public async Task <IHttpActionResult> PostOrderProcesses(OrderProcessesSyncCollection data)
        {
            data.SerialNo = data.SerialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(data.SerialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var TransactionLog = TerminalServices.CheckTransactionLog(data.TransactionLogId, terminal.TerminalId);

            if (TransactionLog == true)
            {
                return(Conflict());
            }

            var mobileLocation = TerminalServices.GetMobileLocationByTerminalId(terminal.TerminalId);

            if (mobileLocation != null)
            {
                terminal.WarehouseId = mobileLocation.WarehouseId;
            }

            var results = new List <OrdersSync>();

            if (data.OrderProcesses != null && data.OrderProcesses.Any())
            {
                var groupedOrderProcesses = data.OrderProcesses.GroupBy(p => p.OrderToken, (key, g) => new { OrderToken = key, OrderProcesses = g.ToList() });

                foreach (var processGroup in groupedOrderProcesses)
                {
                    var orderProcesses = processGroup.OrderProcesses;
                    foreach (var item in orderProcesses)
                    {
                        var order = OrderService.SaveOrderProcessSync(item, terminal);

                        results.Add(order);

                        if (order.OrderStatusID == (int)OrderStatusEnum.AwaitingAuthorisation)
                        {
                            OrderViewModel orderViewModel = new OrderViewModel();
                            orderViewModel.OrderID   = order.OrderID;
                            orderViewModel.TenentId  = order.TenentId;
                            orderViewModel.AccountID = order.AccountID;
                            await _configHelper.CreateTenantEmailNotificationQueue($"#{order.OrderNumber} - Order Requires Authorisation", orderViewModel, null, shipmentAndRecipientInfo : null,
                                                                                   worksOrderNotificationType : WorksOrderNotificationTypeEnum.AwaitingOrderTemplate);
                        }
                    }
                }
            }

            TerminalServices.CreateTerminalLog(DateTime.UtcNow, terminal.TenantId, data.OrderProcesses.Count, terminal.TerminalId, TerminalLogTypeEnum.OrderProcessesPost);

            return(Ok(results));
        }
Ejemplo n.º 2
0
        // POST http://localhost:8005/api/sync/post-pallet-tracking
        public IHttpActionResult PostPallettracking(PalletTrackingSyncCollection data)
        {
            data.SerialNo = data.SerialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(data.SerialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var TransactionLog = TerminalServices.CheckTransactionLog(data.TransactionLogId, terminal.TerminalId);

            if (TransactionLog == true)
            {
                return(Conflict());
            }

            var mobileLocation = TerminalServices.GetMobileLocationByTerminalId(terminal.TerminalId);

            if (mobileLocation != null)
            {
                terminal.WarehouseId = mobileLocation.WarehouseId;
            }

            var results = new PalletTrackingSyncCollection();

            if (data.PalletTrackingSync != null && data.PalletTrackingSync.Any())
            {
                foreach (var item in data.PalletTrackingSync)
                {
                    item.DateUpdated = DateTime.UtcNow;
                    var pallet = ProductServices.SavePalletTrackings(item, terminal.TenantId);

                    results.PalletTrackingSync.Add(pallet);
                    results.Count += 1;
                }
            }

            TerminalServices.CreateTerminalLog(DateTime.UtcNow, terminal.TenantId, data.PalletTrackingSync.Count, terminal.TerminalId, TerminalLogTypeEnum.PostPalletTracking);

            return(Ok(results));
        }
        // POST http://localhost:8005/api/sync/post-order-receive-count
        public IHttpActionResult PostOrderReceiveCount(OrderReceiveCountSyncCollection data)
        {
            data.SerialNo = data.SerialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(data.SerialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var TransactionLog = TerminalServices.CheckTransactionLog(data.TransactionLogId, terminal.TerminalId);

            if (TransactionLog == true)
            {
                return(Conflict());
            }

            var mobileLocation = TerminalServices.GetMobileLocationByTerminalId(terminal.TerminalId);

            if (mobileLocation != null)
            {
                terminal.WarehouseId = mobileLocation.WarehouseId;
            }

            var results = new OrderReceiveCountSyncCollection();

            if (data.OrderReceiveCountSync != null && data.OrderReceiveCountSync.Any())
            {
                foreach (var item in data.OrderReceiveCountSync)
                {
                    var countRecord = OrderService.SaveOrderReceiveCount(item, terminal);

                    results.OrderReceiveCountSync.Add(countRecord);
                    results.Count += 1;
                }
            }

            TerminalServices.CreateTerminalLog(DateTime.UtcNow, terminal.TenantId, data.OrderReceiveCountSync.Count, terminal.TerminalId, TerminalLogTypeEnum.PostOrderReceiveCount);

            return(Ok(results));
        }
Ejemplo n.º 4
0
        // GET http://localhost:8005/api/sync/terminal-data/{serialNo}
        public IHttpActionResult GetTerminalMetadata(string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            TenantConfig config = _tenantServices.GetTenantConfigById(terminal.TenantId);

            string baseUrl  = HostingEnvironment.ApplicationPhysicalPath;
            string ImageUrl = baseUrl + "Content/images/logo.png";

            byte[] data = System.IO.File.ReadAllBytes(ImageUrl);

            if (config.TenantLogo == null)
            {
                config.TenantLogo = data;
            }

            var result = new TerminalMetadataSync()
            {
                Serial                        = terminal.TermainlSerial,
                TerminalId                    = terminal.TerminalId,
                TerminalName                  = terminal.TerminalName,
                ParentWarehouseId             = terminal.WarehouseId,
                ParentWarehouseName           = terminal.TenantWarehous?.WarehouseName,
                TenantId                      = terminal.TenantId,
                PalletTrackingScheme          = terminal.TenantWarehous.PalletTrackingScheme,
                PrintLogoForReceipts          = config.PrintLogoForReceipts,
                TenantLogo                    = data,
                TenantReceiptPrintHeaderLine1 = config.TenantReceiptPrintHeaderLine1,
                TenantReceiptPrintHeaderLine2 = config.TenantReceiptPrintHeaderLine2,
                TenantReceiptPrintHeaderLine3 = config.TenantReceiptPrintHeaderLine3,
                TenantReceiptPrintHeaderLine4 = config.TenantReceiptPrintHeaderLine4,
                TenantReceiptPrintHeaderLine5 = config.TenantReceiptPrintHeaderLine5,
                GlobalProcessByPallet         = terminal.TenantWarehous.EnableGlobalProcessByPallet,
                SessionTimeoutHours           = config.SessionTimeoutHours,
                AllowStocktakeAddNew          = terminal.TenantWarehous.AllowStocktakeAddNew,
                AllowStocktakeEdit            = terminal.TenantWarehous.AllowStocktakeEdit,
                PostGeoLocation               = terminal.PostGeoLocation,
                VehicleChecksAtStart          = terminal.VehicleChecksAtStart,
                AllowSaleWithoutAccount       = terminal.TenantWarehous.AllowSaleWithoutAccount,
                ShowFullBalanceOnPayment      = terminal.TenantWarehous.ShowFullBalanceOnPayment,
                AllowExportDatabase           = terminal.AllowExportDatabase,
                ShowCasePrices                = terminal.ShowCasePrices
            };

            var mobileLocation = TerminalServices.GetMobileLocationByTerminalId(terminal.TerminalId);

            if (mobileLocation != null)
            {
                result.ParentWarehouseId   = (int)mobileLocation.ParentWarehouseId;
                result.ParentWarehouseName = mobileLocation.ParentWarehouse?.WarehouseName;
                result.MobileWarehouseId   = mobileLocation.WarehouseId;
                result.MobileWarehouseName = mobileLocation.WarehouseName;

                result.MarketVehicleId     = mobileLocation.MarketVehicleID;
                result.VehicleRegistration = mobileLocation.MarketVehicle?.VehicleIdentifier;

                result.SalesManUserId       = mobileLocation.SalesManUserId;
                result.SalesManResourceName = UserService.GetResourceNameByUserId(mobileLocation.SalesManUserId);
            }

            return(Ok(result));
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetMyMarketRoutes(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

            if (terminal == null)
            {
                return(Unauthorized());
            }

            var result = new MarketRouteSyncCollection();

            var warehouseId = terminal.WarehouseId;

            var mobileLocation = TerminalServices.GetMobileLocationByTerminalId(terminal.TerminalId);

            if (mobileLocation != null)
            {
                warehouseId = mobileLocation.WarehouseId;
            }

            var allRoutes = _vanSalesService.GetMyMarketRoutes(terminal.TenantId, warehouseId, reqDate);

            var results = new List <MarketRouteSync>();

            foreach (var p in allRoutes)
            {
                DateTime       nextAppointment = DateTime.MinValue;
                DateTime       lastAppointment = DateTime.MinValue;
                RecurrenceInfo info            = new RecurrenceInfo();
                var            appt            = _vanSalesService.GetMarketRouteScheduleById(p.RouteScheduleId);

                Appointment newAppt = DevExpress.XtraScheduler.Compatibility.StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern);
                newAppt.RecurrenceInfo.FromXml(appt.RecurrenceInfo);
                newAppt.Start = appt.StartTime;
                newAppt.End   = appt.EndTime;

                if (appt.RecurrenceInfo != null)
                {
                    info.FromXml(appt.RecurrenceInfo);

                    OccurrenceCalculator calc = OccurrenceCalculator.CreateInstance(info);
                    nextAppointment = calc.FindNextOccurrenceTimeAfter(new DateTime(reqDate.Year, reqDate.Month, reqDate.Day, 0, 0, 0), newAppt);

                    if (!newAppt.SameDay && nextAppointment.Date != reqDate.Date)
                    {
                        var reqDate2 = reqDate.AddDays(-1);
                        nextAppointment = calc.FindNextOccurrenceTimeAfter(new DateTime(reqDate2.Year, reqDate2.Month, reqDate2.Day, 0, 0, 0), newAppt);
                    }
                }

                else
                {
                    nextAppointment = newAppt.Start;

                    if (!newAppt.SameDay && nextAppointment.Date != reqDate.Date)
                    {
                        nextAppointment = newAppt.Start.AddDays(1);
                    }
                }

                if (reqDate.Date == nextAppointment.Date && appt.WarehouseId == warehouseId || (!newAppt.SameDay && reqDate.Date == nextAppointment.Date.AddDays(1)))
                {
                    var sync   = new MarketRouteSync();
                    var mapped = Mapper.Map(p, sync);
                    results.Add(mapped);
                }
            }

            result.Count         = results.Count;
            result.TerminalLogId = TerminalServices.CreateTerminalLog(reqDate, terminal.TenantId, results.Count, terminal.TerminalId, TerminalLogTypeEnum.DayMarketRouteSync).TerminalLogId;
            result.MarketRoutes  = results;
            return(Ok(result));
        }