private string GetComments(Entities.LegPlan legPlan, eDriverCommunicationType communicationType)
        {
            bool doneFirstLeg = false;
            int  lastLorry    = 0;
            int  lastTrailer  = 0;

            StringBuilder sb = new StringBuilder();

            foreach (Entities.LegView leg in legPlan.Legs())
            {
                if (leg.Driver != null && leg.Driver.ResourceId == _driverId)
                {
                    if (!doneFirstLeg)
                    {
                        BuildStartComments(communicationType, sb, leg);
                        doneFirstLeg = true;
                    }

                    if (leg.Vehicle != null && leg.Vehicle.ResourceId != lastLorry)
                    {
                        BuildVehicleComments(communicationType, sb, leg.Vehicle);
                        lastLorry = leg.Vehicle.ResourceId;
                    }

                    if (leg.Trailer != null && leg.Trailer.ResourceId != lastTrailer)
                    {
                        BuildTrailerComments(communicationType, sb, leg.Trailer);
                        lastTrailer = leg.Trailer.ResourceId;
                    }

                    // We should display information about this leg point.
                    BuildLegPointComments(communicationType, sb, leg.EndLegPoint);

                    // Display any instruction information.
                    if ((leg.StartLegPoint != null && leg.EndLegPoint != null) && leg.StartLegPoint.Instruction != null)
                    {
                        BuildInstructionTypeComments(sb, (eInstructionType)leg.StartLegPoint.Instruction.InstructionTypeId);

                        // Display the timing information.
                        sb.Append(" " + leg.StartLegPoint.PlannedDateTime.ToString("dd/MM/yy HH:mm"));
                        sb.Append(" " + leg.EndLegPoint.PlannedDateTime.ToString("dd/MM/yy HH:mm"));
                        sb.Append(". ");
                    }
                    else
                    {
                        // Display the timing information.
                        sb.Append(" " + leg.EndLegPoint.PlannedDateTime.ToString("dd/MM/yy HH:mm"));
                        sb.Append(". ");
                    }
                }
            }

            return(sb.ToString());
        }
Beispiel #2
0
        void gvLegs_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((TextBox)e.Row.FindControl("txtCost")).Attributes.Add("onblur", "updateCost(this);");
                ((TextBox)e.Row.FindControl("txtCharge")).Attributes.Add("onblur", "updateCharge(this);");
                e.Row.Attributes.Add("__key", ((Entities.LegView)(e.Row.DataItem)).InstructionID.ToString());
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Entities.LegView  leg   = (Entities.LegView)e.Row.DataItem;
                Entities.LegPoint start = leg.StartLegPoint;
                Entities.LegPoint end   = leg.EndLegPoint;

                Facade.IOrganisation facOrganisation = new Facade.Organisation();
                bool legsHaveCharges = false;

                Facade.IInstruction facInstruc = new Facade.Instruction();
                Entities.LegPlan    legPlan    = facInstruc.GetLegPlan(m_job.Instructions, false);

                foreach (Entities.LegView legVw in legPlan.Legs())
                {
                    if (legVw.EndLegPoint.Instruction.Charge > 0)
                    {
                        legsHaveCharges = true;
                        break;
                    }
                }
                TextBox txtCost   = (TextBox)e.Row.FindControl("txtCost");
                TextBox txtCharge = (TextBox)e.Row.FindControl("txtCharge");

                bool aLegPointHasInstruction = false;
                if (!legsHaveCharges)
                {
                    #region Populate the configured rates


                    if ((m_job.JobType != eJobType.Groupage) && m_job.Charge.JobChargeType == eJobChargeType.FreeOfCharge || m_job.Charge.JobChargeType == eJobChargeType.FreeOfChargeInvoicing)
                    {
                        decimal zero = 0;

                        txtCost.Text   = zero.ToString("C");
                        txtCharge.Text = zero.ToString("C");

                        txtCost.Enabled   = false;
                        txtCharge.Enabled = false;
                    }
                    else
                    {
                        if (m_job.Charge.JobChargeType == eJobChargeType.PerPallet)
                        {
                            // No action
                        }
                    }

                    #endregion

                    // Hide the inner repeater unless it can have actuals/demurrages
                    aLegPointHasInstruction = ((start.Instruction != null) || (end.Instruction != null));

                    // Set leg cost
                    if (m_job.HasBeenSubContracted && m_job.SubContractors[0].Rate > 0)
                    {
                        try
                        {
                            decimal subContractorRate = 0, legCount = 0;
                            subContractorRate = m_job.SubContractors[0].Rate;
                            legCount          = Convert.ToDecimal(new Facade.Instruction().GetLegPlan(m_job.Instructions, false).Legs().Count);

                            txtCost.Text = (subContractorRate / legCount).ToString("C");
                        }
                        catch
                        {
                            txtCost.Text = "0";
                        }
                    }

                    try
                    {
                        if (end.Instruction.InstructionTypeId == (int)eInstructionType.Drop || end.Instruction.InstructionTypeId == (int)eInstructionType.LeaveGoods || (m_job.JobType == eJobType.PalletReturn && end.Instruction.InstructionTypeId == (int)eInstructionType.DeHirePallets) || (m_job.JobType == eJobType.Groupage && end.Instruction.InstructionTypeId == (int)eInstructionType.Trunk))
                        {
                            decimal instructionTotal = 0;
                            //this leg is chargeable

                            if (m_job.Rate != null)
                            {
                                if (end.Point.PointId == m_job.Rate.DeliveryPointId)
                                {
                                    if (end.Instruction.TotalPallets >= Orchestrator.Globals.Configuration.PartLoadThreshold)
                                    {
                                        instructionTotal += m_job.Rate.FullLoadRate;
                                    }
                                    else
                                    {
                                        instructionTotal += m_job.Rate.PartLoadRate;
                                    }
                                }
                                else
                                {
                                    instructionTotal += m_job.Rate.MultiDropRate;
                                }
                            }
                            else
                            {
                                instructionTotal += m_job.Charge.JobChargeAmount / m_chargeableLegs;
                            }

                            txtCharge.Text = instructionTotal.ToString("C");
                        }
                        else
                        {
                            txtCharge.Visible = false;
                            txtCharge.Text    = "0";
                        }
                    }
                    catch
                    {
                        txtCharge.Text = "0";
                    }
                }
                else
                {
                    if (!(end.Instruction.InstructionTypeId == (int)eInstructionType.Drop) && !(end.Instruction.InstructionTypeId == (int)eInstructionType.LeaveGoods) && !(m_job.JobType == eJobType.PalletReturn && end.Instruction.InstructionTypeId == (int)eInstructionType.DeHirePallets))
                    {
                        if (leg.EndLegPoint.Instruction.Charge == 0)
                        {
                            txtCharge.Visible = false;
                        }
                    }
                }

                if (m_job.JobState == eJobState.Invoiced)
                {
                    ((TextBox)e.Row.FindControl("txtCost")).Enabled   = false;
                    ((TextBox)e.Row.FindControl("txtCharge")).Enabled = false;
                }

                if (m_job.JobType == eJobType.Return && aLegPointHasInstruction)
                {
                    decimal lc = m_job.Charge.JobChargeAmount / m_chargeableLegs;
                    ((TextBox)e.Row.FindControl("txtCharge")).Text = lc.ToString("C");
                }

                // Running cost & charge total calculation
                m_runningCostTotal += Decimal.Parse(((TextBox)e.Row.FindControl("txtCost")).Text, System.Globalization.NumberStyles.Currency);
                if (((TextBox)e.Row.FindControl("txtCharge")).Visible)
                {
                    m_runningChargeTotal += Decimal.Parse(((TextBox)e.Row.FindControl("txtCharge")).Text, System.Globalization.NumberStyles.Currency);
                }
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                ((Label)e.Row.FindControl("lblTotalCost")).Text   = m_runningCostTotal.ToString("C");
                ((Label)e.Row.FindControl("lblTotalCharge")).Text = m_runningChargeTotal.ToString("C");
            }
        }