Ejemplo n.º 1
0
        private void PopulateLegTimes()
        {
            var instructions = this.Instructions;

            if (instructions != null)
            {
                var facInstruction = new Facade.Instruction();
                var legs           = facInstruction.GetLegPlan(instructions, false).Legs();

                repLegs.DataSource = legs;
                repLegs.DataBind();

                if (Globals.Configuration.CollectionTimeDeliveryWindow)
                {
                    var collects = instructions.Where(i => i.InstructionTypeId == (int)eInstructionType.Load);

                    // Only set up collection time recalculation if the last collection point on the run has a delivery matrix
                    if (collects.Any() && collects.Last().Point != null && collects.Last().Point.DeliveryMatrix > 0)
                    {
                        var firstDropFound = false;

                        for (var i = 0; i < legs.Count; i++)
                        {
                            var leg      = legs[i];
                            var legRow   = (HtmlTableRow)repLegs.Items[i].FindControl("legRow");
                            var cssClass = legRow.Attributes["class"];

                            cssClass += string.Format(" legRow_{0}", leg.InstructionID);

                            if (leg.StartLegPoint.Instruction != null)
                            {
                                cssClass += string.Format(" legStart_{0}", leg.StartLegPoint.Instruction.InstructionID);
                            }

                            if (!firstDropFound && leg.EndLegPoint.InstructionTypeId == (int)eInstructionType.Drop)
                            {
                                firstDropFound = true;
                                cssClass      += " firstDrop";
                            }

                            legRow.Attributes["class"] += cssClass.TrimStart();
                        }
                    }
                }
            }
            else
            {
                repLegs.DataSource = null;
                repLegs.DataBind();
            }
        }
Ejemplo n.º 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");
            }
        }