Exemplo n.º 1
0
        /// <summary>
        /// This gets a list from getAllDocuments_For.
        /// </summary>
        /// <param name="orderListDateDelimitedByDocumentTypeAndState"></param>
        /// <returns></returns>
        decimal get_Money_For(List <BuySellDoc> orderListDateDelimitedByDocumentTypeAndState, BuySellDocumentTypeENUM buySellDocumentTypeEnum)
        {
            //get all purchase orders for Owner

            //add up the purchase amoung
            if (orderListDateDelimitedByDocumentTypeAndState.IsNullOrEmpty())
            {
                return(0);
            }

            //The deliveryman is only counted once selected.
            if (buySellDocumentTypeEnum == BuySellDocumentTypeENUM.Delivery)
            {
                Deliveryman deliveryman = DeliverymanBiz.GetPlayerFor(UserId);
                if (deliveryman.IsNull())
                {
                    return(0);
                }
            }

            decimal ttlOrdered = orderListDateDelimitedByDocumentTypeAndState.Sum(x => x.TotalOrdered);

            //foreach (var item in orderListDateDelimitedByDocumentTypeAndState)
            //{
            //    ttlOrdered += item.TotalOrdered;
            //}

            return(ttlOrdered);
        }
Exemplo n.º 2
0
 private void calculate_Deliveryman_Payment(BuySellDoc bsd, PersonPayingPenalty ppp, decimal totalPaymentAmount)
 {
     bsd.DeliverymanId.IsNullOrWhiteSpaceThrowException();
     ppp.From.Person = DeliverymanBiz.GetPersonForPlayer(bsd.DeliverymanId);
     ppp.From.Person.IsNullThrowException();
     ppp.From.Amount  = totalPaymentAmount;
     ppp.From.Comment = "Deliveryman";
 }
Exemplo n.º 3
0
        private Deliveryman loadCurrentUsersDeliverymanIdIntoBuySellDoc(BuySellDoc buySellDoc)
        {
            //get the deliveryman Id for the current user.
            Deliveryman deliveryman = DeliverymanBiz.GetPlayerFor(UserId);

            deliveryman.IsNullThrowException();

            //This is used in View OrderList to determine if the current user is the deliveryman
            //who is to accept the courier order request.
            buySellDoc.CurrentUser_DeliverymanId = deliveryman.Id;
            return(deliveryman);
        }
Exemplo n.º 4
0
 public BuySellDocBiz(IRepositry <BuySellDoc> entityDal, BuySellItemBiz buySellItemBiz, BizParameters bizParameters, OwnerBiz ownerBiz, CustomerBiz customerBiz, ShopBiz shopBiz, DeliverymanBiz deliverymanBiz, FreightOfferTrxBiz freightOfferTrxBiz, VehicalTypeBiz vehicalTypeBiz, MessageBiz messageBiz, PeopleMessageBiz peopleMessageBiz, SalesmanBiz salesmanBiz, BuySellDocHistoryBiz buySellDocHistoryBiz)
     : base(entityDal, bizParameters)
 {
     _ownerBiz             = ownerBiz;
     _customerBiz          = customerBiz;
     _shopBiz              = shopBiz;
     _buySellBiz           = entityDal as BuySellDocBiz;
     _buySellItemBiz       = buySellItemBiz;
     _freightOfferTrxBiz   = freightOfferTrxBiz;
     _deliverymanBiz       = deliverymanBiz;
     _vehicalTypeBiz       = vehicalTypeBiz;
     _messageBiz           = messageBiz;
     _peopleMessageBiz     = peopleMessageBiz;
     _salesmanBiz          = salesmanBiz;
     _buySellDocHistoryBiz = buySellDocHistoryBiz;
 }
Exemplo n.º 5
0
        //public BuySellStatementModel GetDeliveryOrders(string userId, string id)
        //{
        //    userId.IsNullOrWhiteSpaceThrowArgumentException("You are not logged in.");

        //    List<BuySellDoc> lstbuySellDocs = new List<BuySellDoc>(); ;

        //    BuySellDoc buySellDoc = Find(id);
        //    buySellDoc.IsNullThrowException();

        //    lstbuySellDocs.Add(buySellDoc);

        //    decimal customerBalanceRefundable = 0;
        //    decimal customerBalanceNonRefundable = 0;

        //    BuySellStatementModel buySellStatementModel = new BuySellStatementModel(lstbuySellDocs, DateTime.MinValue, DateTime.MaxValue, BuySellDocumentTypeENUM.Delivery, false, customerBalanceRefundable, customerBalanceNonRefundable, BuySellDocStateENUM.ReadyForPickup);

        //    return buySellStatementModel;

        //}


        /// <summary>
        /// This gets the order list of Sale or Purchase documents date delimited.
        /// This also figures out if it is a sale or a purchase
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="buySellDocumentTypeEnum"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <returns></returns>

        public BuySellStatementModel GetBuySellStatementModel(string userId, DateTime fromDate, DateTime toDate, bool isAdmin, BuySellDocumentTypeENUM buySellDocumentTypeEnum, BuySellDocStateENUM buySellDocStateEnum)
        {
            //userId.IsNullOrWhiteSpaceThrowArgumentException("You are not logged in.");


            List <BuySellDoc> buySellDocs = getBuySellDocs_For(userId, buySellDocStateEnum, buySellDocumentTypeEnum, fromDate, toDate).ToList();

            decimal     customerBalanceRefundable = 0, customerBalanceNonRefundable = 0;
            Deliveryman deliveryman = DeliverymanBiz.GetPlayerFor(userId);



            BuySellStatementModel buySellStatementModel = new BuySellStatementModel(buySellDocs, fromDate, toDate, buySellDocumentTypeEnum, isAdmin, customerBalanceRefundable, customerBalanceNonRefundable, deliveryman, buySellDocStateEnum);

            return(buySellStatementModel);
        }
Exemplo n.º 6
0
        private void calculate_Deliveryman_Penalty_Payment(BuySellDoc bsd, PersonPayingPenalty ppp, decimal totalPaymentAmount)
        {
            decimal maxPctCommissionChargeableToFreight_Pct = bsd.Get_Total_Commission_Freight_Percent_Expected();
            decimal maxCommission_Amount = totalPaymentAmount * maxPctCommissionChargeableToFreight_Pct;

            if (!bsd.DeliverymanId.IsNullOrWhiteSpace())
            {
                ppp.Deliveryman.Person = DeliverymanBiz.GetPersonForPlayer(bsd.DeliverymanId);
                ppp.Deliveryman.IsNullThrowException();
                ppp.Deliveryman.Comment = "Deliveryman";

                ppp.Deliveryman.Amount = totalPaymentAmount - maxCommission_Amount;

                if (ppp.Deliveryman.Amount > 0)
                {
                    ppp.Deliveryman.Percent = Math.Round(ppp.Deliveryman.Amount / totalPaymentAmount * 100, 2);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This throws an exception if the deliveryman and the vendor are the same.
        /// </summary>
        /// <param name="freightOfferAcceptedTrx"></param>
        /// <param name="buyselldoc"></param>
        private void exceptionSellerAndDeliveryManIsTheSame(FreightOfferTrx freightOfferAcceptedTrx, BuySellDoc buyselldoc)
        {
            //do not allow if the DeliveryPerson and the VendorPerson and currentUser are the same
            UserId.IsNullOrWhiteSpaceThrowException();

            Person deliveryPerson = DeliverymanBiz.GetPersonForPlayer(freightOfferAcceptedTrx.DeliverymanId);
            Person sellerPerson   = OwnerBiz.GetPersonForPlayer(buyselldoc.OwnerId);
            Person userPerson     = UserBiz.GetPersonFor(UserId);

            deliveryPerson.IsNullThrowException();
            sellerPerson.IsNullThrowException();
            deliveryPerson.Id.IsNullOrWhiteSpaceThrowException();
            sellerPerson.Id.IsNullOrWhiteSpaceThrowException();
            userPerson.IsNullThrowException();

            if (deliveryPerson.Id == sellerPerson.Id && userPerson.Id == sellerPerson.Id && buyselldoc.BuySellDocStateEnum == BuySellDocStateENUM.ReadyForPickup)
            {
                throw new Exception("You are the seller. You cannot bid for this. If you want to deliver the item, ask the customer to accept you.");
            }
        }
Exemplo n.º 8
0
        private void createMessageFor(RejectCancelDeleteInbetweenClass rcdbc, BuySellDoc buySellDoc)
        {
            string        fromPersonId   = "";
            string        toPersonId     = "";
            Person        fromPerson     = null;
            List <string> listOfToPeople = new List <string>();

            string buySellDocId   = buySellDoc.Id;
            Person ownerPerson    = OwnerBiz.GetPersonForPlayer(buySellDoc.OwnerId);
            Person customerPerson = CustomerBiz.GetPersonForPlayer(buySellDoc.CustomerId);

            ownerPerson.IsNullThrowException();
            customerPerson.IsNullThrowException();
            switch (buySellDoc.BuySellDocumentTypeEnum)
            {
            case BuySellDocumentTypeENUM.Sale:
                fromPersonId = ownerPerson.Id;
                fromPerson   = ownerPerson;
                toPersonId   = customerPerson.Id;
                listOfToPeople.Add(toPersonId);
                break;

            case BuySellDocumentTypeENUM.Purchase:
                toPersonId   = ownerPerson.Id;
                fromPersonId = customerPerson.Id;
                fromPerson   = customerPerson;
                listOfToPeople.Add(toPersonId);

                break;

            case BuySellDocumentTypeENUM.Delivery:
                Person deliveryPerson = DeliverymanBiz.GetPersonForPlayer(buySellDoc.DeliverymanId);
                deliveryPerson.IsNullThrowException();

                fromPersonId = deliveryPerson.Id;
                fromPerson   = deliveryPerson;
                listOfToPeople.Add(ownerPerson.Id);
                listOfToPeople.Add(customerPerson.Id);
                break;

            case BuySellDocumentTypeENUM.Unknown:
            default:
                throw new Exception("Unknown document type");
            }

            Message message = new Message(
                fromPersonId,
                fromPerson,
                listOfToPeople,
                rcdbc.Subject,
                rcdbc.Comment,
                MessageENUM.Free,
                null);

            if (buySellDoc.Messages.IsNull())
            {
                buySellDoc.Messages = new List <Message>();
            }

            buySellDoc.Messages.Add(message);
            message.BuySellDocId = buySellDoc.Id;

            message.ListOfToPeopleId.IsNullOrEmptyThrowException();
            foreach (var pplId in message.ListOfToPeopleId)
            {
                Person person = PersonBiz.Find(pplId);
                person.IsNullThrowException();

                PeopleMessage pplMsg = new PeopleMessage();
                pplMsg.IsNullThrowException();
                pplMsg.PersonId  = pplId;
                pplMsg.Person    = person;
                pplMsg.MessageId = message.Id;
                PeopleMessageBiz.Create(pplMsg);
            }
            MessageBiz.Create(message);
        }
Exemplo n.º 9
0
        private void deliveryman_Makes_Bid_To_Pickup(BuySellDoc buySellDoc)
        {
            if (UserId.IsNullOrWhiteSpace())
            {
                return;
            }


            if (buySellDoc.FreightOfferDecimal > 0)
            {
                //we have an offer
                DateParameter dp = new DateParameter();
                dp.BeginDate = buySellDoc.PleasePickupOnDate_Start;
                dp.EndDate   = buySellDoc.PleasePickupOnDate_End;

                if (dp.IsDateWithinBeginAndEndDatesInclusive(buySellDoc.OfferedPickupOnDate))
                {
                    string buySellDocId = buySellDoc.Id;
                    buySellDoc = Find(buySellDocId);
                    buySellDoc.IsNullThrowException();

                    //the pick up is today or later.
                    //the user is the deliveryman here
                    Deliveryman deliveryman = DeliverymanBiz.GetPlayerFor(UserId);
                    deliveryman.IsNullThrowException();


                    //create an offer
                    FreightOfferTrx frtOff = new FreightOfferTrx(
                        buySellDoc.Id,
                        deliveryman.Id,
                        buySellDoc.FreightOfferDecimal,
                        buySellDoc.OfferedPickupOnDate,
                        buySellDoc.ExpectedDeliveryDate,
                        buySellDoc.CommentByDeliveryman,
                        buySellDoc.VehicalTypeOfferedId);

                    //used later
                    frtOff.Deliveryman = deliveryman;
                    frtOff.BuySellDoc  = buySellDoc;


                    //we will only create if there is not one bid from this deliveryman
                    //for this document. If there is already a bid, then all fields will be updated.
                    //the change will only be allowed if the status of the buyselldoc is

                    //check to see if a bid already exists.
                    //this locates an earlier bid and then updates it.

                    FreightOfferTrx frtOffTrxFound = FreightOfferTrxBiz.FindAll().FirstOrDefault(x => x.BuySellDocId == buySellDocId && x.DeliverymanId == deliveryman.Id);
                    if (frtOffTrxFound.IsNull())
                    {
                        //create a new bid.
                        buySellDoc.FreightOfferTrxs.Add(frtOff);
                        FreightOfferTrxBiz.Create(frtOff);
                    }
                    else
                    {
                        //update the old bid.
                        frtOffTrxFound.UpdatePropertiesDuringModify(frtOff as ICommonWithId);
                        FreightOfferTrxBiz.Update(frtOffTrxFound);
                    }
                }
            }
        }
Exemplo n.º 10
0
 private void load_Deliverymen_SelectList_Into_BuySellDoc(BuySellDoc buySellDoc)
 {
     buySellDoc.SelectListDeliveryman = DeliverymanBiz.SelectList();
 }
Exemplo n.º 11
0
        IQueryable <BuySellDoc> getByDocumentType_For(string userId, IQueryable <BuySellDoc> iq_allOrders, BuySellDocumentTypeENUM buySellDocumentTypeEnum)
        {
            //userId.IsNullOrWhiteSpaceThrowArgumentException("You are not logged in.");


            switch (buySellDocumentTypeEnum)
            {
            case BuySellDocumentTypeENUM.Sale:
            {
                try
                {
                    //all orders are returned because this is the admin
                    //if (userId.IsNullOrWhiteSpace())
                    //    return iq_allOrders;
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetSaleDocs(iq_allOrders, ""));
                    }

                    Owner owner = OwnerBiz.GetPlayerFor(userId);
                    owner.IsNullThrowException("No Owner");
                    return(BuySellDoc.IQueryable_GetSaleDocs(iq_allOrders, owner.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting sales.", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Purchase:
            {
                try
                {
                    //all orders are returned because this is the admin
                    //if (userId.IsNullOrWhiteSpace())
                    //    return iq_allOrders;
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetPurchaseDocs(iq_allOrders, ""));
                    }

                    Customer customer = CustomerBiz.GetPlayerFor(userId);
                    customer.IsNullThrowException("Customer");
                    return(BuySellDoc.IQueryable_GetPurchaseDocs(iq_allOrders, customer.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Delivery:
            {
                try
                {
                    //all orders are returned because this is the admin
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetDeliveryDocs(iq_allOrders, ""));
                    }


                    Deliveryman deliveryMan = DeliverymanBiz.GetPlayerFor(userId);
                    deliveryMan.IsNullThrowException("deliveryMan");

                    return(BuySellDoc.IQueryable_GetDeliveryDocs(iq_allOrders, deliveryMan.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Salesman:
            {
                try
                {
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetSalesmanDocs(iq_allOrders, ""));
                    }

                    Salesman salesman = SalesmanBiz.GetPlayerFor(userId);
                    salesman.IsNullThrowException("Salesman");

                    return(BuySellDoc.IQueryable_GetSalesmanDocs(iq_allOrders, salesman.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Unknown:
            default:
                throw new Exception("Unknown document type");
            }
        }