Example #1
0
        public string Clear()
        {
            Guid idOwner    = new Guid("156c2cde-2c19-46c3-bcba-a27f9d1e4998");
            Guid idCustomer = new Guid("54612b5e-611f-4b71-9dbd-ed35b6f2976b");

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo
            {
                Filters = new List <Business.Infrastructure.FilterInfo>
                {
                    new Business.Infrastructure.FilterInfo {
                        Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "id_customer", Operator = "eq", Value = idCustomer.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "created_by", Operator = "eq", Value = "dummy"
                    }
                },
                Logic = "and"
            };

            List <rent> rents = RepoRent.FindAll(null, null, null, filters);
            int         count = rents.Count();

            foreach (rent row in rents)
            {
                RepoRent.Delete(row);
            }

            return(count.ToString() + " dihapus");
        }
Example #2
0
        public string Binding(DailyFilterModel model)
        {
            //kamus
            List <rent>         rents;
            List <driver>       drivers;
            List <expense_item> expenseItems;
            Guid     idOwner = (User as CustomPrincipal).IdOwner.Value;
            DateTime dtStart, dtEnd;

            Business.Infrastructure.FilterInfo filters;

            //algoritma
            //items = RepoExpense.GetDriverReport(idOwner, model.StartDate, model.EndDate);

            dtStart = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0);
            dtEnd   = new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day, 23, 59, 59);

            //mengambil data booking
            rents = RepoRent.FindAll(idOwner, dtStart, dtEnd);

            //mengambil data driver
            filters = new Business.Infrastructure.FilterInfo
            {
                Filters = new List <Business.Infrastructure.FilterInfo>
                {
                    new Business.Infrastructure.FilterInfo {
                        Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                    },
                }
            };
            drivers = RepoDriver.FindAll(null, null, null, filters);

            //mengambil data epneseItem untuk pemasukan
            filters = new Business.Infrastructure.FilterInfo
            {
                Filters = new List <Business.Infrastructure.FilterInfo>
                {
                    new Business.Infrastructure.FilterInfo {
                        Field = "expense.date", Operator = "gte", Value = dtStart.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "expense.date", Operator = "lte", Value = dtEnd.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "category", Operator = "eq", Value = ExpenseItemCategory.DRIVER.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "expense.rent.id_owner", Operator = "eq", Value = idOwner.ToString()
                    },
                }
            };
            expenseItems = RepoExpense.FindAllItem(null, null, null, filters);

            return(new JavaScriptSerializer().Serialize(new SummaryStub().MapList(drivers, rents, expenseItems)));
        }
Example #3
0
        public ActionResult Create()
        {
            Guid?idOwner = (User as CustomPrincipal).IdOwner;
            List <Business.Entities.rent> listRent = new List <rent>();

            if (idOwner.HasValue)
            {
                listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner.Value).ToList();
            }
            else
            {
                var wrapper = new HttpContextWrapper(System.Web.HttpContext.Current);
                return(this.InvokeHttp404(wrapper, System.Net.HttpStatusCode.Forbidden));
            }

            InvoiceFormStub formStub = new InvoiceFormStub(listRent);

            formStub.Status = InvoiceStatus.UNPAID.ToString();

            return(View("Form", formStub));
        }
Example #4
0
        public string BindingMap()
        {
            // Kamus
            List <RentPositionPresentationStub> result = new List <RentPositionPresentationStub>();
            List <rent_position> rentPositionList      = new List <rent_position>();
            List <rent>          rentList;
            CustomPrincipal      user = User as CustomPrincipal;

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };
            rent_position rentPosition;

            // algoritma
            //ambil rent yang GO untuk user login
            filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                Field = "status", Operator = "eq", Value = RentStatus.GO.ToString()
            });
            filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                Field = "id_owner", Operator = "eq", Value = user.IdOwner.Value.ToString()
            });

            rentList = RepoRent.FindAll(null, null, null, filters);

            //ambil rent position terakhir dari setiap rent
            foreach (rent r in rentList)
            {
                rentPosition = r.rent_position.OrderByDescending(m => m.created_time).FirstOrDefault();
                //dimasukin ke rentPosition
                if (rentPosition != null)
                {
                    rentPositionList.Add(rentPosition);
                }
            }

            //mengisi RentPositionPresentationStub list
            result = new RentPositionPresentationStub().Map(rentPositionList);

            return(new JavaScriptSerializer().Serialize(result));
        }
Example #5
0
        public string BindingRent(Guid id, string action)
        {
            GridRequestParameters param = GridRequestParameters.Current;

            Business.Infrastructure.FilterInfo filters = param.Filters;

            Guid?          idOwner                = (User as CustomPrincipal).IdOwner;
            List <rent>    listRent               = new List <rent>();
            List <expense> listExpense            = new List <expense>();
            List <BookingPresentationStub> result = new List <BookingPresentationStub>();

            Business.Infrastructure.FilterInfo filtersExpense = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };
            int total = 0;

            filtersExpense.Filters.Add(new Business.Infrastructure.FilterInfo {
                Field = "rent.id_owner", Operator = "eq", Value = idOwner.ToString()
            });
            listExpense = RepoExpense.FindAll().Where(n => n.rent.id_owner == idOwner).ToList();

            if (idOwner.HasValue)
            {
                GridRequestParameters paramRent = new GridRequestParameters();
                paramRent = GridRequestParameters.Current;
                Business.Infrastructure.FilterInfo rentFilters = paramRent.Filters;
                AddOwnerFilterRent(rentFilters, idOwner.Value);

                listRent = RepoRent.FindAll(paramRent.Skip, paramRent.Take, (paramRent.Sortings != null ? paramRent.Sortings.ToList() : null), paramRent.Filters);

                //menghapus booking yang sudah memiliki invoice
                rent idRent;
                foreach (expense r in listExpense)
                {
                    idRent = listRent.Where(n => n.id == r.id_rent).FirstOrDefault();
                    if (idRent != null)
                    {
                        listRent.Remove(idRent);

                        if (action == "Edit" && idRent.id == id)
                        {
                            listRent.Add(idRent);
                        }
                    }
                }

                total = listRent.Count();
            }

            result = new BookingPresentationStub().MapList(listRent);

            return(new JavaScriptSerializer().Serialize(new { total = total, data = result }));
        }
Example #6
0
        public ActionResult Index()
        {
            //kamus
            Guid?idOwner = (User as CustomPrincipal).IdOwner;
            ExcelReportFilterModel        model  = new ExcelReportFilterModel();
            List <ExcelReportFilterModel> result = new List <ExcelReportFilterModel>();
            List <rent> rents = RepoRent.FindAll().Where(n => n.id_owner == idOwner).ToList();

            //algoritma
            result = model.MapList(rents);
            byte[] excel    = new ExcelReportFilterModel().GenerateExcelReport(result);
            string filename = string.Format("Report Data {0}.xlsx", DateTime.Now.ToString("ddMMyyyy"));

            return(File(excel, "application/vns.ms-excel", filename));
        }
Example #7
0
        public string Binding()
        {
            //kamus
            GridRequestParameters param = GridRequestParameters.Current;

            Business.Infrastructure.FilterInfo filters = param.Filters;
            List <rent> items;
            List <RentPresentationStub> result = new List <RentPresentationStub>();
            int total;

            //algoritma
            items  = RepoRent.FindAll(param.Skip, param.Take, (param.Sortings != null ? param.Sortings.ToList() : null), filters);
            total  = RepoRent.Count(param.Filters);
            result = new RentPresentationStub().MapList(items);

            return(new JavaScriptSerializer().Serialize(new { total = total, data = result }));
        }
Example #8
0
        public string Binding()
        {
            //kamus
            DisplayFormatHelper   dfh   = new DisplayFormatHelper();
            GridRequestParameters param = GridRequestParameters.Current;
            List <ChartAttribute> result;
            List <rent>           items = null;
            DailyFilterModel      fm;
            Guid idOwner = (Guid)(User as CustomPrincipal).IdOwner;

            //algoritma
            fm = ParseFilterInfo(param.Filters);

            items = RepoRent.FindAll(idOwner, fm.StartDate, fm.EndDate).Where(n => n.id_car != null && n.car.is_active == true).ToList();

            result = GenerateReport(items, fm.StartDate, fm.EndDate);

            return(new JavaScriptSerializer().Serialize(result));
        }
Example #9
0
        public HttpResponseMessage Find([FromBody] GridRequestParameters param)
        {
            //kamus
            HttpStatusCode       httpStatus      = HttpStatusCode.OK;
            string               responseMessage = null;
            List <rent>          listRent        = new List <rent>();
            IEnumerable <string> headerValues;

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };
            List <BookingPresentationStub> results;

            //algoritma
            if (Request.Headers.TryGetValues("Username", out headerValues))
            {
                //mengambil order berdasarkan status = 'finish'
                filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "driver.username", Operator = "eq", Value = headerValues.FirstOrDefault()
                });
                filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "status", Operator = "eq", Value = RentStatus.FINISH.ToString()
                });

                //mengambil order finish sesuai param
                listRent = RepoRent.FindAll(param.Skip, param.Take, (param.Sortings != null ? param.Sortings.ToList() : null), filters);
            }
            else
            {
                httpStatus = HttpStatusCode.Forbidden;
            }

            //result
            results = new BookingPresentationStub().MapList(listRent);

            if (responseMessage != null)
            {
                HttpContext.Current.Response.AppendHeader("ResponseMessage", responseMessage);
            }
            return(Request.CreateResponse(httpStatus, results));
        }
Example #10
0
        public HttpResponseMessage CheckAvailability([FromBody] CheckAvailabilityParam param)
        {
            //kamus
            List <CarModel>           result    = new List <CarModel>();
            DisplayFormatHelper       dfh       = new DisplayFormatHelper();
            List <car>                ownerCars = new List <car>();
            List <rent>               rents     = new List <rent>();
            Dictionary <string, Guid> cityMap;
            Guid                 idOwner = new Guid();
            List <Guid>          rentedCars;
            string               message         = null;
            HttpResponseMessage  responseMessage = new HttpResponseMessage();
            HttpStatusCode       httpStatus      = HttpStatusCode.OK;
            bool                 isDataValid     = true;
            log_ws               logWs           = new log_ws();
            JavaScriptSerializer serializer      = new JavaScriptSerializer();

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };

            DateTime       dtStart, dtFinish;
            DateTimeOffset dtoStart, dtoFinish;

            //algoritma
            //hardcode data
            cityMap = new Dictionary <string, Guid>();
            cityMap.Add("bali", new Guid("9e9af49f-742a-40a2-9338-228e56060442"));
            cityMap.Add("surabaya", new Guid("7a683eb8-656d-4b4c-be71-157dd2328a64"));

            //mengecek validitas data
            if (param.StartRent == null || param.FinishRent == null)
            {
                isDataValid = false;
                message     = HttpContext.GetGlobalResourceObject("WebServiceMessage", "DateNullAlert").ToString();
                httpStatus  = HttpStatusCode.BadRequest;
            }

            //algoritma
            if (isDataValid)
            {
                dtStart  = new DateTime(param.StartRent.Value.Year, param.StartRent.Value.Month, param.StartRent.Value.Day, 0, 0, 0);
                dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
                dtoStart = dtStart;

                dtFinish  = new DateTime(param.FinishRent.Value.Year, param.FinishRent.Value.Month, param.FinishRent.Value.Day, 23, 59, 59);
                dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
                dtoFinish = dtFinish;

                param.City = param.City.ToLower();
                if (cityMap.ContainsKey(param.City))
                {
                    idOwner = cityMap[param.City];

                    //mengambil rent dari start s/d finish untuk owner tertentu
                    rents = RepoRent.FindAll(idOwner, dtStart, dtFinish);

                    rents.RemoveAll(m => m.finish_rent == dtoStart);
                    rents.RemoveAll(m => m.start_rent == dtoFinish);

                    //mengambil car sesuai parameter                                                                                                                                                                                                                      //mengambil car sesuai parameter
                    filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                        Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                    });
                    if (param.CarBrandName != null)
                    {
                        filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                            Field = "car_model.car_brand.name", Operator = "eq", Value = param.CarBrandName
                        });
                    }
                    if (param.CarModelName != null)
                    {
                        filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                            Field = "car_model.name", Operator = "eq", Value = param.CarModelName
                        });
                    }
                    if (param.Capacity != null)
                    {
                        filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                            Field = "car_model.capacity", Operator = "gte", Value = param.Capacity.Value.ToString()
                        });
                    }
                    ownerCars = RepoCar.FindAll(null, null, null, filters);

                    //menghapus car yang sudah ada di rent
                    rentedCars = rents.Select(m => m.id_car_model).ToList();

                    //menghapus mobil yang sudah di-booking
                    car carByModel;
                    foreach (Guid idCarModel in rentedCars)
                    {
                        carByModel = ownerCars.Where(m => m.id_car_model == idCarModel).FirstOrDefault();
                        if (carByModel != null)
                        {
                            ownerCars.Remove(carByModel);
                        }
                    }

                    result = CarModel.Map(ownerCars); //mapping dbItems ke PresentationStub
                }
            }

            //menyimpan data ke log_ws
            //menggunakan ILogRepository.SaveLogWS

            logWs.created_time  = DateTimeOffset.Now;
            logWs.request_body  = serializer.Serialize(param);
            logWs.response_body = serializer.Serialize(result);
            logWs.url           = HttpContext.Current.Request.Url.AbsolutePath;
            RepoLog.SaveLogWS(logWs);

            if (message != null)
            {
                HttpContext.Current.Response.AppendHeader("ResponseMessage", message);
            }

            return(Request.CreateResponse(httpStatus, result));
        }
Example #11
0
        public RentResponse Create([FromBody] RentParam param)
        {
            //kamus
            RentResponse        result   = new RentResponse();
            DisplayFormatHelper dfh      = new DisplayFormatHelper();
            List <Guid>         idCar    = new List <Guid>();
            List <car_model>    carModel = new List <car_model>();

            rent        dataRent = new rent();
            List <rent> rents    = new List <rent>();
            Dictionary <string, Guid> cityMap;
            Guid idOwner = new Guid();

            string          code;
            string          city;
            Guid            customerId;
            List <customer> customerList;

            bool isDataValid = true;

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };

            DateTime       dtStart, dtFinish;
            DateTimeOffset dtoStart, dtoFinish;
            DateTime       dtNull = DateTime.Parse("01/01/0001 00:00:00");

            List <car>  ownerCars = new List <car>();
            List <Guid> rentedCars;

            BookingFormStub bfs;
            rent            dbItem;

            ApiRentFormStub afs;
            api_rent        apiRent;
            log_api_rent    logApiRent;

            //hardcode data
            cityMap = new Dictionary <string, Guid>();
            cityMap.Add("bali", new Guid("9e9af49f-742a-40a2-9338-228e56060442"));
            cityMap.Add("surabaya", new Guid("7a683eb8-656d-4b4c-be71-157dd2328a64"));

            //algoritma
            #region check data
            //mengecek validitas parameter
            if (param.StartRent == null)
            {
                isDataValid = false;

                result.Success = false;
                result.Message = "Parameter StartRent wajib diisi";
            }

            if (isDataValid)
            {
                if (param.FinishRent == null)
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter FinishRent wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.City == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter City wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CarBrandName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CarBrandName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CarModelName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CarModelName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CustomerName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CustomerName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CustomerPhoneNumber == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CustomerPhoneNumber wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.PickupLocation == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter PickupLocation wajib diisi";
                }
            }


            if (isDataValid)
            {
                city = param.City.ToLower();
                if (cityMap.ContainsKey(city))
                {
                    idOwner = cityMap[city];
                }
                else
                {
                    isDataValid    = false;
                    result.Message = "Kota yang anda pilih saat ini belum tersedia";
                }
            }

            if (isDataValid)
            {
                //mengambil semua mobil milik owner
                filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                });
                if (param.CarBrandName != null)
                {
                    filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                        Field = "car_model.car_brand.name", Operator = "eq", Value = param.CarBrandName
                    });
                }
                if (param.CarModelName != null)
                {
                    filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                        Field = "car_model.name", Operator = "eq", Value = param.CarModelName
                    });
                }
                ownerCars = RepoCar.FindAll(null, null, null, filters);

                //mengambil booking pada tanggal sesuai request
                dtStart  = new DateTime(param.StartRent.Value.Year, param.StartRent.Value.Month, param.StartRent.Value.Day, 0, 0, 0);
                dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
                dtoStart = dtStart;

                dtFinish  = new DateTime(param.FinishRent.Value.Year, param.FinishRent.Value.Month, param.FinishRent.Value.Day, 23, 59, 59);
                dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
                dtoFinish = dtFinish;
                rents     = RepoRent.FindAll(idOwner, dtStart, dtFinish);

                rents.RemoveAll(m => m.finish_rent == dtoStart);
                rents.RemoveAll(m => m.start_rent == dtoFinish);

                rentedCars = rents.Select(m => m.id_car_model).ToList();

                //menghapus mobil yang sudah di-booking
                car carByModel;
                foreach (Guid idCarModel in rentedCars)
                {
                    carByModel = ownerCars.Where(m => m.id_car_model == idCarModel).FirstOrDefault();
                    if (carByModel != null)
                    {
                        ownerCars.Remove(carByModel);
                    }
                }

                if (ownerCars.Count() == 0)
                {
                    isDataValid    = false;
                    result.Message = "Mobil tidak tersedia";
                }
            }

            #endregion

            if (isDataValid)//insert booking
            {
                //mengecek ketersediaan mobil
                owner owner = RepoOwner.FindByPk(idOwner);
                code = RepoRent.GenerateRentCode(owner);

                //membuat booking baru
                customerList = new List <customer>();
                Business.Infrastructure.FilterInfo filterCust = new Business.Infrastructure.FilterInfo {
                    Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
                };
                filterCust.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "phone_number", Operator = "eq", Value = param.CustomerPhoneNumber
                });
                filterCust.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                });

                customerList = RepoCustomer.FindAll(null, null, null, filterCust);

                if (customerList.Count() > 0)
                {
                    customerId = customerList.FirstOrDefault().id;
                }
                else
                {
                    customer cust = new customer
                    {
                        name         = param.CustomerName,
                        id_owner     = idOwner,
                        phone_number = param.CustomerPhoneNumber
                    };
                    RepoCustomer.Save(cust);

                    customerId = cust.id;
                }


                //if (tempCustomer.Where(n => n.phone_number == param.CustomerPhoneNumber && n.id_owner != idOwner).Count() > 0)
                //{
                //    CustomerID = new Guid();
                //    customer cust = new customer
                //    {
                //        id = CustomerID,
                //        name = param.CustomerName,
                //        id_owner = idOwner,
                //        phone_number = param.CustomerPhoneNumber
                //    };
                //    RepoCustomer.Save(cust);
                //}

                //membuat BookingFormStub
                bfs = new BookingFormStub();

                dtStart  = new DateTime(param.StartRent.Value.Year, param.StartRent.Value.Month, param.StartRent.Value.Day, param.StartRent.Value.Hour, param.StartRent.Value.Minute, param.StartRent.Value.Second);
                dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
                dtoStart = dtStart;

                dtFinish  = new DateTime(param.FinishRent.Value.Year, param.FinishRent.Value.Month, param.FinishRent.Value.Day, param.FinishRent.Value.Hour, param.FinishRent.Value.Minute, param.FinishRent.Value.Second);
                dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
                dtoFinish = dtFinish;

                bfs.Code           = code;
                bfs.PhoneNumber    = param.CustomerPhoneNumber;
                bfs.IdCustomer     = customerId;
                bfs.PickupLocation = param.PickupLocation;
                bfs.IdCarModel     = ownerCars.FirstOrDefault().id_car_model;
                bfs.StartRent      = dtoStart;
                bfs.FinishRent     = dtoFinish;
                bfs.Price          = 0;
                bfs.Status         = RentStatus.NEW;
                bfs.IdCarPackage   = new Guid("0abd31d3-2857-4311-a468-48538bbd790c");
                bfs.PackagePrice   = 0;

                //save
                dbItem = bfs.GetDbObjectOnCreate("aerotrans", idOwner);
                RepoRent.Save(dbItem);

                //save to table api_rent
                afs = new ApiRentFormStub();
                afs.SetNewRent(dbItem, "ATS");
                apiRent = afs.GetDbObjectOnCreate("aerotrans");

                RepoApiRent.Save(apiRent);

                result.Success  = true;
                result.RentCode = code;
            }

            return(result);
        }
Example #12
0
        //public string Binding()
        //{
        //    //kamus
        //    GridRequestParameters param = GridRequestParameters.Current;
        //    List<rent> items = null;

        //    //algoritma
        //    Guid idOwner = (Guid)(User as CustomPrincipal).IdOwner;
        //    DateTime start = DateTime.Parse("2016-01-01");
        //    DateTime finish = DateTime.Parse("2016-01-10");
        //    items = RepoRent.FindAll(idOwner, start, finish);

        //    return new JavaScriptSerializer().Serialize(new BookingPresentationStub().MapList(items));
        //}

        public JsonResult Binding()
        {
            //kamus
            GridRequestParameters param = GridRequestParameters.Current;
            Guid idOwner = (Guid)(User as CustomPrincipal).IdOwner;

            List <rent>      rents;
            List <car>       cars;
            List <car_model> carModels = new List <car_model>();

            DailyFilterModel fm = ParseFilterInfo(param.Filters);
            List <BookingPresentationStub> result = new List <BookingPresentationStub>();

            Business.Infrastructure.FilterInfo filters;
            List <string>           carModel = new List <string>();
            BookingPresentationStub child;
            List <Guid>             carsId;

            DateTime       dtStart, dtEnd;
            DateTimeOffset dtoStart, dtoEnd;

            //algoritma
            dtStart  = new DateTime(fm.StartDate.Year, fm.StartDate.Month, fm.StartDate.Day, fm.StartDate.Hour, fm.StartDate.Minute, fm.StartDate.Second);
            dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
            dtoStart = dtStart;

            dtEnd  = new DateTime(fm.EndDate.Year, fm.EndDate.Month, fm.EndDate.Day, fm.EndDate.Hour, fm.EndDate.Minute, fm.EndDate.Second);
            dtEnd  = DateTime.SpecifyKind(dtEnd, DateTimeKind.Local);
            dtoEnd = dtEnd;

            rents = RepoRent.FindAll(idOwner, fm.StartDate, fm.EndDate);

            //menambahkan filter terkait CarModelName
            filters = new Business.Infrastructure.FilterInfo
            {
                Filters = new List <Business.Infrastructure.FilterInfo>
                {
                    new Business.Infrastructure.FilterInfo {
                        Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "car_model.name", Operator = "eq", Value = fm.CarModelName
                    },
                    new Business.Infrastructure.FilterInfo {
                        Field = "is_active", Operator = "eq", Value = true.ToString()
                    },
                },
                Logic = "and"
            };
            cars   = RepoCar.FindAll(null, null, null, filters);
            carsId = cars.Select(m => m.id).ToList();

            rents = rents.Where(m => m.id_car != null && carsId.Contains(m.id_car.Value)).ToList();
            foreach (rent r in rents)
            {
                child = new BookingPresentationStub(r);

                result.Add(child);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        //public JsonResult Binding(DailyFilterModel model)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        Guid idOwner = (User as CustomPrincipal).IdOwner.Value;
        //        List<VehicleExpenseReport> result = RepoExpense.GetVehicleReport(idOwner, model.StartDate, model.EndDate);
        //        List<rent> rents = RepoRent.FindAll();
        //        return Json(new CarReportPresentationStub().MapList(result, rents), JsonRequestBehavior.AllowGet);
        //    }
        //    else
        //    {
        //        return Json(false, JsonRequestBehavior.AllowGet);
        //    }
        //}

        //private void AddExpenseFilter(Business.Infrastructure.FilterInfo filters, Guid idRents)
        //{
        //    if (filters == null)
        //        filters = new Business.Infrastructure.FilterInfo { Filters = new List<Business.Infrastructure.FilterInfo>(), Logic = "and" };

        //    if (filters.Filters == null)
        //        filters.Filters = new List<Business.Infrastructure.FilterInfo>();
        //    else
        //    {
        //            filters.Filters.Add(new Business.Infrastructure.FilterInfo { Field = "id_rent", Operator = "eq", Value = idRents });
        //    }
        //}


        public JsonResult Binding(DailyFilterModel model)
        {
            if (ModelState.IsValid)
            {
                //kasmus
                Guid idOwner = (User as CustomPrincipal).IdOwner.Value;

                Business.Infrastructure.FilterInfo filters;

                List <rent>         rents;
                List <expense_item> expenseItem;
                List <car>          cars;
                List <car_expense>  carExpenses;
                DateTime            dtStart, dtEnd;

                //algoritma
                dtStart = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0);
                dtEnd   = new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day, 23, 59, 59);

                //mengambil car yang statusnya active
                filters = new Business.Infrastructure.FilterInfo
                {
                    Filters = new List <Business.Infrastructure.FilterInfo>
                    {
                        new Business.Infrastructure.FilterInfo {
                            Field = "is_active", Operator = "eq", Value = true.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                        }
                    }
                };
                cars = RepoCar.FindAll(null, null, null, filters);

                //mengambil data booking
                rents = RepoRent.FindAll(idOwner, dtStart, dtEnd);

                //mengambil expense_item (pemasukan kendaraan)
                filters = new Business.Infrastructure.FilterInfo
                {
                    Filters = new List <Business.Infrastructure.FilterInfo>
                    {
                        new Business.Infrastructure.FilterInfo {
                            Field = "expense.date", Operator = "gte", Value = dtStart.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "expense.date", Operator = "lte", Value = dtEnd.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "category", Operator = "eq", Value = ExpenseItemCategory.VEHICLE.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "expense.rent.id_owner", Operator = "eq", Value = idOwner.ToString()
                        }
                    }
                };
                expenseItem = RepoExpense.FindAllItem(null, null, null, filters);

                //mengambil carExpense (biaya kendaraan)
                filters = new Business.Infrastructure.FilterInfo
                {
                    Filters = new List <Business.Infrastructure.FilterInfo>
                    {
                        new Business.Infrastructure.FilterInfo {
                            Field = "expense_date", Operator = "gte", Value = dtStart.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "expense_date", Operator = "lte", Value = dtEnd.ToString()
                        },
                        new Business.Infrastructure.FilterInfo {
                            Field = "car.id_owner", Operator = "eq", Value = idOwner.ToString()
                        }
                    }
                };
                carExpenses = RepoCarExpense.FindAll(null, null, null, filters);

                return(Json(new CarReportPresentationStub().MapList(cars, rents, expenseItem, carExpenses), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Example #14
0
        public HttpResponseMessage GetActiveRent([FromBody] List <DriverActiveRentParam> param)
        {
            //kamus
            List <BookingPresentationStub> results;
            List <rent> listRent = new List <rent>();
            rent        rent;
            driver      driver;
            Guid        idDriver;

            DateTime       dtUpdated;
            DateTimeOffset dtoUpdated;

            IEnumerable <string> headerValues;

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };

            HttpStatusCode httpStatus      = HttpStatusCode.Forbidden;
            string         responseMessage = null;

            //algoritma
            if (Request.Headers.TryGetValues("Username", out headerValues))
            {
                //mengambil semua rent milik idDriver dengan status NEW / GO
                filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "username", Operator = "eq", Value = headerValues.FirstOrDefault()
                });
                driver = RepoDriver.FindAll(null, null, null, filters).FirstOrDefault();
                if (driver != null)
                {
                    idDriver = driver.id;

                    filters = new Business.Infrastructure.FilterInfo
                    {
                        Filters = new List <Business.Infrastructure.FilterInfo>
                        {
                            new Business.Infrastructure.FilterInfo
                            {
                                Field = "id_driver", Operator = "eq", Value = idDriver.ToString()
                            },
                            new Business.Infrastructure.FilterInfo
                            {
                                Filters = new List <Business.Infrastructure.FilterInfo>
                                {
                                    new Business.Infrastructure.FilterInfo {
                                        Field = "status", Operator = "eq", Value = Common.Enums.RentStatus.GO.ToString()
                                    },
                                    new Business.Infrastructure.FilterInfo {
                                        Field = "status", Operator = "eq", Value = Common.Enums.RentStatus.NEW.ToString()
                                    },
                                },
                                Logic = "or"
                            },
                        },
                        Logic = "and"
                    };

                    listRent = RepoRent.FindAll(null, null, null, filters);

                    //menghapus data dari list rent yang <= param.update_time
                    if (param != null)
                    {
                        foreach (DriverActiveRentParam single in param)
                        {
                            //mengambil data yang bersesuaian di listRent
                            rent = listRent.Where(m => m.id == single.Id).FirstOrDefault();

                            //if data di listRent lebih lama (<=), dihapus dari listRent
                            if (rent != null)
                            {
                                if (rent.updated_time.Value.UtcDateTime <= single.UpdatedTimeUtc)
                                {
                                    listRent.Remove(rent);
                                }
                            }
                            else //rent tidak ditemukan di listRent
                            {
                                rent = RepoRent.FindByPk(single.Id);
                                if (rent != null)
                                {
                                    if (rent.updated_time.Value.UtcDateTime > single.UpdatedTimeUtc)
                                    {
                                        listRent.Add(rent);
                                    }
                                }
                            }
                        }
                    }

                    httpStatus = HttpStatusCode.OK;
                }
                else
                {
                    responseMessage = "Username Anda tidak ditemukan.";
                }
            }
            else
            {
                responseMessage = "Username Anda tidak ditemukan.";
            }


            //result
            results = new BookingPresentationStub().MapList(listRent);

            if (responseMessage != null)
            {
                HttpContext.Current.Response.AppendHeader("ResponseMessage", responseMessage);
            }
            return(Request.CreateResponse(httpStatus, results));
        }