// int? accountid = null
        public ActionResult PalletEditor(string id = null, int?OrderProcessId = null)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }
            var palletId = 0;

            if (!string.IsNullOrEmpty(id) && !OrderProcessId.HasValue)
            {
                //var pallet = _palletingService.GetFulfillmentPalletByNumber(id);
                var pallet = _palletingService.GetFulfillmentPalletById(int.Parse(id));
                //accountid = pallet.RecipientAccountID;
                //OrderProcessId=pallet.RecipientAccountID;
                palletId = pallet.PalletID;
            }

            var model = new PalletGenerateViewModel
            {
                AllCurrentPallets = _palletingService.GetAllPallets(2, PalletStatusEnum.Active, orderProcessId: OrderProcessId).Select(m => new SelectListItem()
                {
                    Text = m.PalletNumber, Value = m.PalletID.ToString()
                }).ToList(),
                SelectedOrderProcessId = OrderProcessId ?? 0,
                SelectedPalletID       = palletId,
            };

            model.OrderProcesses = OrderService.GetOrderProcessByOrderProcessId(OrderProcessId ?? 0);

            return(View("PalletEditor", model));
        }
        // GET http://ganetest.qsrtime.net/api/sync/pallets/{reqDate}/{serialNo}
        // GET http://ganetest.qsrtime.net/api/sync/pallets/2014-11-23/920013c000814
        public IHttpActionResult GetPallets(DateTime reqDate, string serialNo)
        {
            serialNo = serialNo.Trim().ToLower();

            var terminal = TerminalServices.GetTerminalBySerial(serialNo);

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

            reqDate = TerminalServices.GetTerminalSyncDate(reqDate, terminal.TenantId);

            var result = new PalletsSyncCollection();

            var allPallets  = _palletService.GetAllPallets(null, null, null, reqDate);
            var palletSyncs = new List <PalletSync>();

            foreach (var p in allPallets)
            {
                var mapped = AutoMapper.Mapper.Map(p, new PalletSync());

                if (p.Dispatch != null)
                {
                    mapped.IsDispatched  = p.DispatchTime.HasValue;
                    mapped.DateCompleted = p.Dispatch.DateCompleted;
                }
                mapped.DateUpdated        = p.DateUpdated;
                mapped.PalletDispatchInfo = AutoMapper.Mapper.Map <PalletsDispatch, PalletDispatchSync>(p.Dispatch);
                palletSyncs.Add(mapped);
            }

            result.Count         = palletSyncs.Count;
            result.TerminalLogId = TerminalServices
                                   .CreateTerminalLog(reqDate, terminal.TenantId, palletSyncs.Count, terminal.TerminalId,
                                                      TerminalLogTypeEnum.PalletingSync).TerminalLogId;
            result.Pallets = palletSyncs;
            return(Ok(AutoMapper.Mapper.Map(result, new PalletsSyncCollection())));
        }