Click here to Skip to main content
14,838,196 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
view model :
    public enum YearsType
    {
        [Display(Name = "سال جاری")]
        Currentyear = 1,
        [Display(Name = "سالهای گذشته")]
        Pastyears = 2,
    }

    public class InventoryAnalysisReportViewModel
    {
        [Display(Name = "وضعیت")]
        public YearsType YearType { get; set; }

        [Display(Name = "وضعیت")]
        public string YearTypeName
        {
            get
            {
                switch (YearType)
                {
                    case YearsType.Currentyear:
                        return "سال جاری";
                    case YearsType.Pastyears:
                    default:
                        return "سالهای گذشته ";
                }
            }
        }
        public int CarId { get; set; }


        [Display(Name = "خودرو")]
        public string CarTitle { get; set; }


        [Display(Name = "بین مقاطع")]
        public int SectionsQty { get; set; }


        [Display(Name = "تحویل موقت")]
        public int ProvisionalDeliveryQty { get; set; }


        [Display(Name = "کل تعهدات باقیمانده")]
        public int RemailQty { get; set; }


        [Display(Name = "تکمیل وجه شده")]
        public int PayOffQty { get; set; }


        [Display(Name = "تکمیل وجه نشده")]
        public int DebtQty { get; set; }


        [Display(Name = "تخصیص کل")]
        public int TotalAllocatedQty { get; set; }


        [Display(Name = "موجودی پارکینگ بم")]
        public int? ParkingInventoryQty { get; set; }


        [Display(Name = "مجوز حمل")]
        public int? Qty { get; set; }

        [Display(Name = "موجودی تجاری شده")]
        public int InventoryQty { get; set; }

        public long ProductionVehicleInventoryId { get; set; }


        [Display(Name = "کل موجودی")]
        public int TotalInventory { get; set; }


        [Display(Name = "مجموع")]
        public int TotalDeatails { get; set; }


        [Display(Name = "کسری/مازاد (حال حاضر)")]
        public int ExcessNow { get; set; }


        [Required(ErrorMessage = "{0} الزامی است.")]
        public DateTime RegDate { get; set; }

    }
}



view:
@model IEnumerable<InventoryAnalysisReportViewModel>

@{
    ViewData["Title"] = "آنالیز موجودی/درخواست";
}
<div class="card text-white">
    <div class="card-body">
        <h5 class="card-title">@($"{ViewData["Title"]} {ViewData["Range"]}")</h5>
        <form method="post" asp-controller="InventoryAnalysisReports" asp-action="SpecificDate">
            <div class="form-group">
                <div class="form-inline">
                    <label for="SelectedDate">تاریخ گزارش :</label>
                    <input id="SelectedDate" name="SelectedDate" class="form-control" autocomplete="off" required />
                    <label class="col-sm-1"> </label>
                    <input type="submit" class="btn btn-light mb-2 " value="جستجو">
                </div>
            </div>
        </form>
    </div>
</div>
@section Scripts {
    <script>
        $(document).ready(function () {
            $('#SelectedDate').val('@ViewData["Yesterday"].ToString()').persianDatepicker();
        });
    </script>
}

<hr />
<h5>آنالیز موجودی/درخواست | @ViewData["Yesterday"].ToString()</h5>
<br />
<table class="table text-center">
    <thead>
        <tr class="text-right">
            <th>
                 
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CarTitle)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ProvisionalDeliveryQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.SectionsQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ParkingInventoryQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.InventoryQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.TotalInventory)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.RemailQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PayOffQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.DebtQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ExcessNow)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.TotalAllocatedQty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Qty)
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <a href="#" data-id="@item.CarId" name="sales-details">
                        
                    </a>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CarTitle)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ProvisionalDeliveryQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.SectionsQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ParkingInventoryQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.InventoryQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.TotalInventory)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.RemailQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PayOffQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DebtQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ExcessNow)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.TotalAllocatedQty)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Qty)
                </td>
            </tr>
            <tr>
                <td colspan="13">
                    <div id="div-@item.CarId"></div>
                </td>
            </tr>
        }
    </tbody>
</table>



java script:
$('a[name="sales-details"]').click(function (event) {
    event.preventDefault();
    var carId = $(event.currentTarget).data('id'),
        selectedDate = $('#SelectedDate').val();
    if ($('#icon-' + carId).hasClass('fa-plus-square')) {
        showRows(carId, selectedDate);
    } else {
        hideRows(carId);
    }
});

function showRows(carId, selectedDate) {
    $.ajax({
        type: 'POST',
        url: '/InventoryAnalysisReports/DeatailsAnalysis',
        data: { carId: carId, selectedDate: selectedDate },
        dataType: 'json',
        success: function (result) {
            if (result.length > 0) {
                var template =
                    '<table class="inventoryAnalysisReport">' +
                    '<colgroup>' +
                    '<col style="width:auto;" />' +
                    '<col style="width:auto;" />' +
                    '<col style="width:auto;" />' +
                    '<col style="width:auto;" />' +
                    '<col style="width:auto;" />' +
                    '</colgroup>' +
                    '<thead>' +
                    '<tr>' +
                    '<th></th>' +
                    '<th>بین مقاطع</th>' +
                    '<th>تحویل موقت</th>' +
                    '<th>پارکینگ بم</th>' +
                    '<th>تجاری شده</th>' +
                    '<th>جمع کل</th>' +
                    '</tr>' +
                    '</thead>' +
                    '<tbody>';
                for (var i = 0; i < result.length; i++) {
                    var item = result[i]; 
                    typeName = (item.yearType == 1) ? 'سال جاری' : 'سالهای گذشته';
                    template += '<tr>' +
                        '<td>' + typeName + '</td>' +
                        '<td>' + item.sectionsQty + '</td>' +
                        '<td>' + item.provisionalDeliveryQty + '</td>' +
                        '<td>' + item.parkingInventoryQty + '</td>' +
                        '<td>' + item.inventoryQty + '</td>' +
                        '<td>' + item.totalDeatails + '</td>' +
                        '</td>' +
                        '</tr>';
                }
                template += '</tbody>' +
                    '</table>';
            }

            $('#div-' + carId).append(template);
            $('#icon-' + carId).removeClass('fa-plus-square').addClass('fa-minus-square');
        },
        error(ex) {
            debugger;
        }
    });
}


function hideRows(carId) {
    $('#div-' + carId).children().remove();
    $('#icon-' + carId).removeClass('fa-minus-square').addClass('fa-plus-square');
}




controller:
   public class InventoryAnalysisReportsController : PersianController
    {
        public InventoryAnalysisReportsController(KMCDashboardDbContext context) : base(context)
        {
        }

        // GET: InventoryAnalysisReportViewModels
        public async Task<IActionResult> Index()
        {
            var yesterday = DateTime.Today.AddDays(-1);
            ViewData["Yesterday"] = $"{Calendar.GetYear(yesterday)}/{Calendar.GetMonth(yesterday)}/{Calendar.GetDayOfMonth(yesterday)}";
            var model = await InventoryAnalysisReportAsync(yesterday);
            return View(model);
        }

        [HttpPost]
        public async Task<IActionResult> SpecificDate(string selectedDate)
        {
            ViewData["Yesterday"] = selectedDate;
            DateTime selectedDay = PersianToGregorian(selectedDate, out _);
            var model = await InventoryAnalysisReportAsync(selectedDay);

            return View("Index", model);
        }

        public async Task<IActionResult> History(string historyDate)
        {
            SqlConnection connection = null;
            SqlCommand command = null;
            var model = new List<InventoryAnalysisReportViewModel>();

            try
            {
                connection = DbContext.Database.GetDbConnection() as SqlConnection;
                command = new SqlCommand("dbo.InventoryAnalysisReportPerDay")
                {
                    CommandType = CommandType.StoredProcedure,
                    Connection = connection
                };
                command.Parameters.Add(new SqlParameter("@HistoryDate", historyDate));

                if (connection.State != ConnectionState.Open)
                    await connection.OpenAsync();

                using var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    model.Add(new InventoryAnalysisReportViewModel
                    {
                        CarId = reader.GetInt32(reader.GetOrdinal("CarID")),
                        CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")),
                        ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")),
                        SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")),
                        ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")),
                        RemailQty = reader.GetInt32(reader.GetOrdinal("RemailQty")),
                        PayOffQty = reader.GetInt32(reader.GetOrdinal("PayOffQty")),
                        DebtQty = reader.GetInt32(reader.GetOrdinal("DebtQty")),
                        //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")),
                        TotalAllocatedQty = reader.GetInt32(reader.GetOrdinal("TotalAllocatedQty")),
                        //TotalInventory = reader.GetInt32(reader.GetOrdinal("TotalInventory")),
                        //ExcessNow = reader.GetInt32(reader.GetOrdinal("ExcessNow")),
                        Qty = reader.GetInt32(reader.GetOrdinal("Qty"))
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }

            return Json(model);
        }

        [HttpPost]
        public async Task<IActionResult> DeatailsAnalysis(int carId, string selectedDate)
        {
            DateTime selectedDay = PersianToGregorian(selectedDate, out int selectedPersianYear);
            SqlConnection connection = null;
            SqlCommand command = null;
            var model = new List<InventoryAnalysisReportViewModel>();

            try
            {
                connection = DbContext.Database.GetDbConnection() as SqlConnection;
                command = new SqlCommand("dbo.DeatailsInventoryAnalysisReportPerDay")
                {
                    CommandType = CommandType.StoredProcedure,
                    Connection = connection
                };
                command.Parameters.Add(new SqlParameter("@SelectedDay", selectedDay));
                command.Parameters.Add(new SqlParameter("@CarId", carId));

                if (connection.State != ConnectionState.Open)
                    await connection.OpenAsync();

                using var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    model.Add(new InventoryAnalysisReportViewModel
                    {
                        CarId = reader.GetInt32(reader.GetOrdinal("CarID")),
                        CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")),
                        ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")),
                        SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")),
                        ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")),
                        //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")),
                        TotalDeatails = reader.GetInt32(reader.GetOrdinal("TotalDeatails")),
                        YearType = Convert.ToInt32(reader.GetValue(reader.GetOrdinal("CarModels"))) == selectedPersianYear
                                    ? YearsType.Currentyear
                                    : YearsType.Pastyears
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }

            return Json(model);
        }

        private async Task<IEnumerable<InventoryAnalysisReportViewModel>> InventoryAnalysisReportAsync(DateTime selectedDay)
        {
            /*
             * ProductionVehicleInventory.SectionsQty                                                                    بین مقاطع
             * ProductionVehicleInventory.ProvisionalDeliveryQty                                                        تحویل موقت
             * ProductionInventoryAnalysis.ParkingInventoryQty                                                  موجودی پارکینگ بم    
             * SaleCommitmentSummary.RemailQty                                                                           كل تعهدات
             * SaleCommitmentSummary.PayOffQty                                                                       تكميل وجه شده
             * SaleCommitmentSummary.DebtQty                                                                        تكميل وجه نشده
             * SaleTotalSale.TotalAllocatedQty                                                                            تخصیص کل
             * ControlShippingPermit.Qty                                                                                  مجوز حمل
             * (TotalInventory - PayOffQty).ExcessNow                                                       کسری / مازاد حال حاضر 
             * (SectionsQty + ProvisionalDeliveryQty + InventoryQty + ParkingInventoryQty).TotalInventory                کل موجودی
             */

            SqlConnection connection = null;
            SqlCommand command = null;
            var model = new List<InventoryAnalysisReportViewModel>();

            try
            {
                connection = DbContext.Database.GetDbConnection() as SqlConnection;
                command = new SqlCommand("dbo.InventoryAnalysisReportPerDay")
                {
                    CommandType = CommandType.StoredProcedure,
                    Connection = connection
                };
                command.Parameters.Add(new SqlParameter("@SelectedDay", selectedDay));

                if (connection.State != ConnectionState.Open)
                    await connection.OpenAsync();

                using var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    model.Add(new InventoryAnalysisReportViewModel
                    {
                        CarId = reader.GetInt32(reader.GetOrdinal("CarID")),
                        CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")),
                        ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")),
                        SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")),
                        ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")),
                        RemailQty = reader.GetInt32(reader.GetOrdinal("RemailQty")),
                        PayOffQty = reader.GetInt32(reader.GetOrdinal("PayOffQty")),
                        DebtQty = reader.GetInt32(reader.GetOrdinal("DebtQty")),
                        //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")),
                        TotalAllocatedQty = reader.GetInt32(reader.GetOrdinal("TotalAllocatedQty")),
                        //TotalInventory = reader.GetInt32(reader.GetOrdinal("TotalInventory")),
                        //ExcessNow = reader.GetInt32(reader.GetOrdinal("ExcessNow")),
                        Qty = reader.GetInt32(reader.GetOrdinal("Qty"))
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }

            return model;
        }
    }
}


What I have tried:

When I run the program in the detail section, the door stops on the debugger and the detail is not displayed
Posted
Updated 26-Sep-20 22:16pm
Comments
Richard MacCutchan 27-Sep-20 3:28am
   
You need to be much more specific about where the debugger stops and why. There is far too much code there for anyone to figure out what is happening.

1 solution

Quote:
When I run the program in the detail section, the door stops on the debugger and the detail is not displayed

This is because of the following line of code:
JavaScript
function showRows(carId, selectedDate) {
..
..
,
error(ex) {
    debugger;
}

Two things:
1. You are having an exception in the method showRows and given you have put debugger explicitly there, it will stop the program
2. With the error, seems your details would not be displayed. Looks like your ajax call to get data on server side has failed. Put debugger on C# code side and see what is happening when the call comes. Handle it.
   
Comments
Member 14615938 27-Sep-20 18:31pm
   
I have done this several times but I do not notice the problem
It worked fine at first, but when I added a few new fields, it ran into problems
Sandeep Mewara 28-Sep-20 0:17am
   
Seems you have info enough with you to troubleshoot/debug here. You need to take step by step and find why those new fields ae making it fail.
Member 14615938 28-Sep-20 5:52am
   
When I put the debugger on the detail and move it with the F10 key, all the lines of C # move, but the value of the model shows 0.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900