Esempio n. 1
0
        public Error CreatePicks(CompanyModel company, UserModel currentUser, string sohIds, bool bCombine)
        {
            var error = validateSingleOrder(company, sohIds);

            if (!error.IsError)
            {
                // TBD: Validate the document creation so that we don't have a rollback scenario

                // All sales validate, so drop them as individual drops
                List <PickHeaderModel> picks = new List <PickHeaderModel>();

                error = PickService.CreatePicks(company, sohList, bCombine, picks);
                // The returned list contains the names of the pick CSV temp files.

                // Now create the corresponding support PDF document when
                // the location configuration specifies that it should be created.
                if (!error.IsError)
                {
                    error = createDocuments(company, picks);
                }

                // Now drop the files to the warehouse
                if (!error.IsError)
                {
                    var sohIdList = new List <int>();

                    foreach (var pick in picks)
                    {
                        error = FilePackagerService.SendPickToWarehouse(pick);
                        if (error.IsError)
                        {
                            break;
                        }
                        else
                        {
                            // Pick successfully sent, so:
                            foreach (var detail in pick.PickDetails)
                            {
                                var sod = FindSalesOrderDetailModel(detail.SalesOrderDetailId);
                                if (sod != null)
                                {
                                    //  Change all the line items to 'sent for picking'
                                    sod.LineStatusId = (int)SalesOrderLineStatus.SentForPicking;
                                    InsertOrUpdateSalesOrderDetail(sod, "");

                                    //  Remove allocations from sale
                                    AllocationService.DeleteAllocationsForPurchaseLine(company, sod.Id);

                                    if (sohIdList.Where(l => l == sod.SalesOrderHeaderId).Count() == 0)
                                    {
                                        sohIdList.Add(sod.SalesOrderHeaderId);
                                    }
                                }
                            }

                            //  Set 'sent to warehouse date' on pick header
                            PickService.SetPickSentToWarehouseDate(pick, DateTimeOffset.Now);
                        }
                    }

                    // Attach notes to SOH's to indicate pick sent to W/House
                    TaskManagerService.TaskManagerService tm = new TaskManagerService.TaskManagerService(db, company);
                    foreach (var sohId in sohIdList)
                    {
                        var soh = FindSalesOrderHeaderModel(sohId, company, false);
                        if (soh != null)
                        {
                            var subject = "Order Sent to Warehouse";
                            var message = "Order sent to Warehouse for picking";
                            NoteService.AttachNoteToSalesOrder(soh, currentUser, subject, message);
                        }
                    }
                }

                // Cleanup all the temp pick files
                foreach (var pick in picks)
                {
                    foreach (var pickFile in pick.PickFiles)
                    {
                        FileManagerService.FileManagerService.DeleteFile(pickFile);
                    }
                }

                if (!error.IsError)
                {
                    error.SetInfo(EvolutionResources.infPicksSuccessfullyCreated);
                }
            }

            return(error);
        }