Exemplo n.º 1
0
        private List <ShipmentDetailModel> MappingShipmentDetail(List <VTTK> vttks)
        {
            var Shipments = new List <ShipmentDetailModel>();

            using (var context = new SAPContext())
            {
                foreach (var r in vttks)
                {
                    var shipment = new ShipmentDetailModel();
                    shipment.client            = r.MANDT;
                    shipment.shipment_number   = r.TKNUM;
                    shipment.shipment_date     = DateTime.ParseExact(r.ERDAT, "yyyyMMdd", null);
                    shipment.shipmenttype_code = r.VSART;
                    if (r.VSART != " ")
                    {
                        var shipmenttype = context.T173T.Where(t => t.MANDT == r.MANDT && t.SPRAS == "2" && t.VSART == r.VSART).FirstOrDefault();
                        shipment.shipmenttype_desc = shipmenttype.BEZEI;
                    }
                    shipment.route = r.ROUTE;
                    if (r.ROUTE != " ")
                    {
                        var route = context.TVROT.Where(t => t.MANDT == r.MANDT && t.SPRAS == "2" && t.ROUTE == r.ROUTE).FirstOrDefault();
                        shipment.route_desc = route.BEZEI;
                    }
                    shipment.container_id = r.SIGNI;
                    shipment.car_license  = r.ADD01;
                    shipment.forwarding   = r.TDLNR;
                    Shipments.Add(shipment);
                }
                return(Shipments);
            }
        }
Exemplo n.º 2
0
        public async Task <ApplicationResult> Edit(ShipmentDetailModel model)
        {
            ShipmentDetailModelValidator validator = new ShipmentDetailModelValidator();
            ValidationResult             result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Shipment shipment = _mapper.Map <Shipment>(model);
                if (shipment.Status == ShipmentStatus.Cancelled)
                {
                    shipment.IsDeleted = true;
                }
                int id = await _service.Update(shipment);

                await _eventManager.CreateEvent(EntityEventType.Shipping, id, Events.Shipment.Edited);

                if (model.Status == ShipmentStatus.Cancelled)
                {
                    await _eventManager.CreateEvent(EntityEventType.Shipping, model.Id, Events.Shipment.Cancelled);
                }
                else if (model.Status == ShipmentStatus.Shipped)
                {
                    await _eventManager.CreateEvent(EntityEventType.Shipping, model.Id, Events.Shipment.Shipped);
                }
                return(ApplicationResult.Success("Shipment edited", id));
            }
            return(ApplicationResult.Error(result));
        }
        public async Task <IActionResult> Edit(ShipmentDetailModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationResult result = await _shipmentManager.Edit(model);

                SetApplicationResult(result);
                return(RedirectToAction(nameof(Center), "Shipment"));
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <ApplicationResult> Create(ShipmentDetailModel model)
        {
            ShipmentDetailModelValidator validator = new ShipmentDetailModelValidator();
            ValidationResult             result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Shipment shipment = _mapper.Map <Shipment>(model);
                int      id       = await _service.Create(shipment);

                await _eventManager.CreateEvent(EntityEventType.Shipping, id, Events.Shipment.Created);

                return(ApplicationResult.Success("Shipment created", id));
            }
            return(ApplicationResult.Error(result));
        }
Exemplo n.º 5
0
        public async Task Test_SaveShipment_Full_Is_Ok()
        {
            ShipmentModel currentShipment = new ShipmentModel();

            currentShipment.ReceiverAvailabilities = new EditableList <AvailabilityEntityModel>();
            currentShipment.SenderAvailabilities   = new EditableList <AvailabilityEntityModel>();
            AvailabilityEntityModel receiver = new AvailabilityEntityModel();

            receiver.AmStop  = "11:30";
            receiver.AmStart = "08:00";
            receiver.PmStart = "15:00";
            receiver.PmStop  = "18:00";
            AvailabilityEntityModel sender = new AvailabilityEntityModel();

            sender.AmStart = "07:00";
            sender.AmStop  = "11:34";
            sender.PmStart = "18:00";
            sender.PmStop  = "20:00";
            currentShipment.ReceiverAvailabilities.Add(receiver);
            currentShipment.SenderAvailabilities.Add(sender);

            currentShipment.Id                    = -1;
            currentShipment.CustomerId            = 1;
            currentShipment.DeliveryDate          = DateTime.Now;
            currentShipment.DateModified          = DateTime.Now;
            currentShipment.DateCreated           = DateTime.Now;
            currentShipment.PickUpDate            = DateTime.Now;
            currentShipment.PoNumber              = "12345678";
            currentShipment.ReceiverAddressId     = 70;
            currentShipment.ReceiverContactPerson = "dan MIhai";
            currentShipment.ReceiverPhone         = "4443333";
            currentShipment.ReceiverRemark        = "Iași Buc";
            currentShipment.Reference             = "aaaa";
            currentShipment.SenderAddressId       = 70;
            currentShipment.SenderContactPerson   = "gicu turcu";
            currentShipment.SenderPhone           = "434343434";
            currentShipment.SenderRemark          = "Iași to see availability";
            currentShipment.ShipmentStatus        = "UAS";
            currentShipment.TotalPrice            = 5554;
            currentShipment.TotalQuatity          = 6666;
            currentShipment.TotalVolume           = 333;
            currentShipment.TotalWeight           = 5454;
            currentShipment.TransporterId         = 1;
            currentShipment.UserIdCreated         = 100000;
            currentShipment.UserIdModified        = 999;
            currentShipment.InvoiceAmount         = 6666;
            currentShipment.InvoiceComment        = "InvoiceComment";
            currentShipment.InvoiceDate           = DateTime.Now.AddDays(4);
            currentShipment.PickUpComment         = "yyyyy";
            currentShipment.DeliveryComment       = "rrrrrr";
            currentShipment.DeliveryPod           = true;
            //we must see with parentdetailid
            ShipmentDetailModel aShipmentDetailModel = new ShipmentDetailModel
            {
                Height           = 1,
                Length           = 10,
                Quantity         = 111,
                PackTypeId       = 1,
                Weight           = 11,
                Width            = 232,
                QuantityDetail   = 666,
                PackTypeDetailId = 2
            };
            ShipmentDetailModel aShipmentDetailModel2 = new ShipmentDetailModel
            {
                Height           = 1,
                Length           = 10,
                Quantity         = 111,
                PackTypeId       = 1,
                Weight           = 11,
                Width            = 232,
                QuantityDetail   = 999,
                PackTypeDetailId = 1
            };
            List <ShipmentDetailModel> extras = new EditableList <ShipmentDetailModel>();

            extras.Add(aShipmentDetailModel2);
            extras.Add(aShipmentDetailModel);
            currentShipment.ShipmentDetails = extras;

            List <FacilityEntityModel> shipmentReceiverFacilities =
                new EditableList <FacilityEntityModel>();
            FacilityEntityModel aShipmentReceiverFacilityModel = new FacilityEntityModel
            {
                Active     = true,
                FacilityId = 1
            };

            shipmentReceiverFacilities.Add(aShipmentReceiverFacilityModel);
            currentShipment.ReceiverFacilities = shipmentReceiverFacilities;

            List <RequirementEntityModel> shipmentReceiverRequirements =
                new EditableList <RequirementEntityModel>();
            RequirementEntityModel aShipmentReceiverRequirementModel = new RequirementEntityModel
            {
                Active          = true,
                AmountInsurance = 11,
                RequirementId   = 11
            };

            shipmentReceiverRequirements.Add(aShipmentReceiverRequirementModel);
            currentShipment.ReceiverRequirements = shipmentReceiverRequirements;

            List <TruckEntityModel> shipmentReceiverTrucks      = new EditableList <TruckEntityModel>();
            TruckEntityModel        aShipmentReceiverTruckModel = new TruckEntityModel
            {
                Active  = true,
                TruckId = 5
            };

            shipmentReceiverTrucks.Add(aShipmentReceiverTruckModel);
            currentShipment.ReceiverTrucks = shipmentReceiverTrucks;

            List <FacilityEntityModel> shipmentSenderFacilities     = new EditableList <FacilityEntityModel>();
            FacilityEntityModel        aShipmentSenderFacilityModel = new FacilityEntityModel
            {
                Active     = true,
                FacilityId = 1
            };

            shipmentSenderFacilities.Add(aShipmentSenderFacilityModel);
            currentShipment.SenderFacilities = shipmentSenderFacilities;

            List <RequirementEntityModel> shipmentSenderRequirements =
                new EditableList <RequirementEntityModel>();
            RequirementEntityModel aShipmentSenderRequirementModel = new RequirementEntityModel
            {
                Active          = true,
                AmountInsurance = 999,
                RequirementId   = 11
            };

            shipmentSenderRequirements.Add(aShipmentSenderRequirementModel);
            currentShipment.SenderRequirements = shipmentSenderRequirements;

            List <TruckEntityModel> shipmentSenderTrucks      = new EditableList <TruckEntityModel>();
            TruckEntityModel        aShipmentSenderTruckModel = new TruckEntityModel
            {
                Active  = true,
                TruckId = 6
            };

            shipmentSenderTrucks.Add(aShipmentSenderTruckModel);
            currentShipment.SenderTrucks = shipmentSenderTrucks;

            List <ShipmentTransporterModel> shipmentTransporters      = new EditableList <ShipmentTransporterModel>();
            ShipmentTransporterModel        aShipmentTransporterModel = new ShipmentTransporterModel
            {
                Accepted      = true,
                AcceptedDate  = DateTime.Now,
                Assigned      = true,
                AssignedDate  = DateTime.Now,
                Declined      = false,
                DeclinedDate  = DateTime.Now,
                DeliveryOn    = 1,
                LoadingOn     = 3,
                Price         = 11000110,
                Selected      = true,
                SelectedDate  = DateTime.Now,
                TransporterId = 1,
                ExpiredDate   = DateTime.Now
            };

            shipmentTransporters.Add(aShipmentTransporterModel);
            currentShipment.Transporters = shipmentTransporters;
            try
            {
                await _shipmentService.SaveShipment(1000, currentShipment);

                if (currentShipment.Id > 0)
                {
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.IsTrue(false);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 6
0
        public HttpResponseMessage Save(ShipmentDetailModel postdata)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    var            newdata    = false;
                    afs_shipment_h data       = new afs_shipment_h();
                    var            shipment_h = context.afs_shipment_h
                                                .Where(t => t.CLIENT == postdata.client && t.SHIPMENT_NUMBER == postdata.shipment_number).FirstOrDefault();
                    if (shipment_h == null)
                    {
                        newdata                    = true;
                        shipment_h                 = new afs_shipment_h();
                        shipment_h.CLIENT          = postdata.client;
                        shipment_h.SHIPMENT_NUMBER = postdata.shipment_number;
                        shipment_h.CREATED_BY      = postdata.created_by;
                        shipment_h.CREATED_DATE    = DateTime.Now;
                    }

                    shipment_h.TRANSPORT_DATE = DateTime.ParseExact(postdata.transport_date, "dd/MM/yyyy", null);
                    shipment_h.CARGROUP_CODE  = postdata.cargroup_code;
                    shipment_h.DRIVER_ID      = postdata.driver_id;
                    shipment_h.STAFF1_ID      = postdata.staff1_id;
                    shipment_h.STAFF2_ID      = postdata.staff2_id;
                    shipment_h.STATUS         = postdata.status_code;
                    shipment_h.REMARK         = postdata.remark;
                    shipment_h.POINT_ID       = postdata.point_id;
                    shipment_h.UPDATE_BY      = postdata.update_by;
                    shipment_h.UPDATE_DATE    = DateTime.Now;

                    if (newdata)
                    {
                        context.afs_shipment_h.Add(shipment_h);
                    }
                    else
                    {
                        context.Entry(shipment_h).State = EntityState.Modified;
                    }

                    // Save Shipment carries
                    if (postdata.shipment_carries != null)
                    {
                        foreach (var item in postdata.shipment_carries)
                        {
                            newdata = false;
                            var exists = context.afs_shipment_carries.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_carries();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.POINT_DESC       = item.point_desc;
                            exists.TIME_RANGE       = item.time_range;
                            exists.SALEORDER_NUMBER = item.so_number;
                            exists.REMARK           = item.remark;
                            exists.DRIVER_AMOUNT    = item.driver_amount;
                            exists.STAFF_AMOUNT     = item.staff_amount;
                            exists.UPDATE_BY        = postdata.update_by;
                            exists.UPDATE_DATE      = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_carries.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Save Shipment expense
                    if (postdata.shipment_expense != null)
                    {
                        foreach (var item in postdata.shipment_expense)
                        {
                            newdata = false;
                            afs_shipment_expense exp = new afs_shipment_expense();
                            var exists = context.afs_shipment_expense.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno
                                                                            ).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_expense();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.EXPENSE_ID      = item.expense_id;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.REMARK         = item.remark;
                            exists.EXPENSE_AMOUNT = item.expense_amount;
                            exists.UPDATE_BY      = postdata.update_by;
                            exists.UPDATE_DATE    = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_expense.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Commit data
                    context.SaveChanges();

                    //Search shipment
                    ShipmentSearchModel searh  = new ShipmentSearchModel();
                    HttpResponseMessage result = new HttpResponseMessage();
                    searh.ShipmentNo = postdata.shipment_number;
                    result           = PostShipmentSearh(searh);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
            }
        }