Esempio n. 1
0
        public ActionResult CreateFreight(FreightModel FreightModel1)
        {
            if (ModelState.IsValid)
            {
                FreightModel1.UserId     = User1.Id;
                FreightModel1.CreateDate = DateTime.Now.ToString("dd/MM/yyyy");
                FreightModel1.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy");

                if (FreightModel.FreightTypes.OceanFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.SeaInbound.ToString();
                }
                else if (FreightModel.FreightTypes.AirFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.AirInbound.ToString();
                }
                else if (FreightModel.FreightTypes.InlandRates.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.InlandService.ToString();
                }
                else
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.Other.ToString();
                }
                FreightModel1.ServiceId = servicesType.GetId(FreightModel1.ServiceName);
                Freight Freight1 = _freightService.CreateFreight(FreightModel1);
                if (Freight1 != null)
                {
                    foreach (string inputTagName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[inputTagName];
                        if (file.ContentLength > 0)
                        {
                            string filePath = Path.Combine(Server.MapPath("~/" + FREIGHT_PATH)
                                                           , Path.GetFileName(file.FileName));
                            file.SaveAs(filePath);
                            //save file to db
                            ServerFile ServerFile1 = new ServerFile();
                            ServerFile1.ObjectId     = Freight1.Id;
                            ServerFile1.ObjectType   = Freight1.GetType().ToString();
                            ServerFile1.Path         = FREIGHT_PATH + "/" + file.FileName;
                            ServerFile1.FileName     = file.FileName;
                            ServerFile1.FileSize     = file.ContentLength;
                            ServerFile1.FileMimeType = file.ContentType;
                            _freightService.insertServerFile(ServerFile1);
                        }
                    }
                }
                return(RedirectToAction("ListFreight", new { Id = 0, FreightType = FreightModel1.Type }));
            }
            else
            {
                IEnumerable <Area> AreaListDep = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDep);
                IEnumerable <Area> AreaListDes = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDes);
                ViewData["AreaListDep"]  = new SelectList(AreaListDep, "Id", "AreaAddress");
                ViewData["AreaListDes"]  = new SelectList(AreaListDes, "Id", "AreaAddress");
                ViewData["FreightTypes"] = FreightTypes;
            }
            return(View(FreightModel1));
        }
Esempio n. 2
0
        public ActionResult CreateShippmet(long id)
        {
            try
            {
                var link          = "N/A";
                var existShipment = shipmentServices.GetShipmentByOrder(id);
                var order         = salesServices.GetModelById(id);
                if (existShipment != null)
                {
                    var statusviews = this.RenderPartialView("_StatusView", order);

                    link = string.Format("<a href=\"/Shipment/Edit/{0}\" target=\"_bank\">{0}</a>", existShipment.Id);
                    return(Json(new
                    {
                        Error = false,
                        RefId = link,
                        view = statusviews
                    }, JsonRequestBehavior.AllowGet));
                }

                var ship = new ShipmentModel()
                {
                    QtyNumber          = 1,
                    QtyUnit            = "ship(s)",
                    ServiceName        = "Trading",
                    CarrierAirId       = 360,
                    Dateshp            = order.VoucherDate.ToString(),
                    CneeId             = order.Customer.Id,
                    DepartmentId       = order.UserCreated.DeptId ?? 0,
                    SaleId             = order.UserCreated.Id,
                    CompanyId          = order.UserCreated.ComId ?? 0,
                    IsTrading          = true,
                    AgentId            = 141,
                    VoucherId          = id,
                    SaleType           = ShipmentModel.SaleTypes.Handle.ToString(),//"Sales",
                    RevenueStatus      = ShipmentModel.RevenueStatusCollec.Pending.ToString(),
                    CountryDeparture   = 126,
                    DepartureId        = 2,
                    CountryDestination = 126,
                    DestinationId      = 2,
                    ShipperId          = 1754,
                    ServiceId          = servicesType.GetId("Trading")
                };
                if (shipmentServices.InsertShipment(ship))
                {
                    try
                    {
                        var newShip = shipmentServices.GetShipmentByOrder(id);
                        var amount  = (double)order.SumTotal;
                        var funds   = (double)order.Amount0;
                        var revenus = new RevenueModel()
                        {
                            INAutoValue1   = amount,
                            INVI           = amount,
                            Income         = amount,
                            EXManualValue1 = funds,
                            EXVI           = funds,
                            Expense        = funds,
                            EarningVI      = amount - funds,
                            Earning        = amount - funds,
                            Id             = newShip.Id,
                            InvCurrency1   = order.Curency.Code,
                            InvCurrency2   = order.Curency.Code,
                            InvType1       = "AgentDebit",
                            InvType2       = "AgentCredit",
                            InvAgentId1    = 141,
                            InvAgentId2    = 141,
                            PaidToCarrier  = 126,
                            BonRequest     = GetBonRequest(newShip.SaleType),
                            SaleType       = newShip.SaleType,
                            AutoName1      = "Total exork amount",
                            EXManualName1  = "Cost of sales"
                        };
                        revenus.AmountBonus2 = Convert.ToDecimal(revenus.BonRequest * revenus.Earning / 100);
                        if (!shipmentServices.UpdateRevenue(revenus))
                        {
                            shipmentServices.DeleteShipment(newShip.Id);
                            throw new Exception("Not Create Revenue");
                        }
                        link = string.Format("<a href=\"/Shipment/Edit/{0}\" target=\"_bank\">{0}</a>", newShip.Id);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex);
                        throw ex;
                    }
                }
                else
                {
                    return(Json(new
                    {
                        Message = "Có lỗi trong lúc tạo shipment lòng liên hệ người quản trị",
                        Error = true
                    }));
                }
                var model      = salesServices.GetModelById(id);
                var statusview = this.RenderPartialView("_StatusView", model);

                return(Json(new
                {
                    Error = false,
                    RefId = link,
                    view = statusview
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var newShip = shipmentServices.GetShipmentByOrder(id);
                shipmentServices.DeleteShipment(newShip.Id);
                Logger.LogError(ex);
                return(Json(new
                {
                    Message = ex.Message,
                    Error = true
                }));
            }
        }