public void AddUnPaidPurchaseScaleExpenses(int scaleId)
        {
            // Search for all expenses that matches scaleId.
            ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            string refTableName                    = new Model.Scale().GetType().Name;
            IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(scaleId, refTableName, new[] { "Payment", "Paid_Party_To" });
            ScaleLibrary scaleLib                  = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());

            foreach (var item in expenses)
            {
                // If scale expense already exists.
                if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                {
                    // Get scale entity
                    Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" });
                    if (item.Paid_Party_To == null)
                    {
                        item.Paid_Party_To = new Party();
                    }
                    // Add eexpense to TempList.
                    TempEntityList.Add(item);
                    // Add dispatcher expense.
                    if (scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0)
                    {
                        AddUnPaidPurchaseDispatcherExpenses(scale.Dispatch_Request_No.ID);
                    }
                }
            }
        }
        public ActionResult GetUnPaidTickets(GridCommand command, string partyId, string locationId = "0")
        {
            TempEntityList.Clear();
            if (Convert.ToInt32(partyId) > 0)
            {
                string            dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString();
                SettlementLibrary settlementLib             = new SettlementLibrary();
                settlementLib.Initialize(dbContextConnectionString);
                IEnumerable <Settlement> results = settlementLib.GetUnPaidTickets(new string[] { "Scale", "Scale.Party_ID", "Scale.Purchase_Order", "Scale.Party_Address" }, int.Parse(partyId), int.Parse(locationId));

                if (results != null && results.Count() > 0)
                {
                    PaymentReceiptDetails paymentDetails;
                    int id = 0;
                    foreach (var item in results)
                    {
                        //if (item.Scale != null && item.Scale.Purchase_Order == null) {
                        //  item.Scale.Purchase_Order = new PurchaseOrder();
                        //}
                        id            += 1;
                        paymentDetails = new PaymentReceiptDetails()
                        {
                            ID             = id,
                            Settlement     = item,
                            Balance_Amount = item.Amount - item.Amount_Paid_Till_Date,
                            PaymentReceipt = new PaymentReceipt()
                        };

                        TempEntityList.Add(paymentDetails);
                    }
                }
            }
            return(Display(command, "0", true));
        }
        private void AddNonInvoiceSellingDispatcherExpenses(int bookingId, string containerNo)
        {
            // Search for expenses that matches dispatcher id.
            DispatcherRequestLibrary        dispathcerRequestLib = new DispatcherRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <DispatcherRequest> dispatcherReqs       = dispathcerRequestLib.GetDispatcherByBookingAndContainerNo(bookingId, containerNo, new string[] { "Booking_Ref_No", "Container" });

            foreach (DispatcherRequest dispatcherReq in dispatcherReqs)
            {
                ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                string refTableName                    = new Model.DispatcherRequest().GetType().Name;
                IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispatcherReq.ID, refTableName, new[] { "Payment", "Paid_Party_To", "Invoice" });
                foreach (var item in expenses)
                {
                    // If expense already exists.
                    if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                    {
                        // If party is null.
                        if (item.Paid_Party_To == null)
                        {
                            item.Paid_Party_To = new Party();
                        }

                        // Add to TempList.
                        TempEntityList.Add(item);
                    }
                }
            }
        }
        //[HttpPost]
        //public void RemoveUnPaidSellingExpenses(string bookingId) {
        //  // If TEmpEntityList has no Items.
        //  if (TempEntityList != null) {
        //    int intBookingId = Convert.ToInt32(bookingId);
        //    if (intBookingId > 0) {
        //      // Get all scale exepenses.
        //      IEnumerable<ExpensesRequest> scaleExps = from exp in TempEntityList
        //                                               where exp.Reference_Table == "Scale" && exp.Reference_ID == intBookingId
        //                                               select exp;
        //      if (scaleExps != null) {
        //        IList<ExpensesRequest> removeExpenses = new List<ExpensesRequest>();
        //        ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
        //        foreach (var item in scaleExps) {
        //          // Get scale entity.
        //          Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" });
        //          if (scale != null && scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0) {
        //            // Get dispatcher id.
        //            int dispatcherId = scale.Dispatch_Request_No.ID;
        //            // Get all dispatcher expenses.
        //            IEnumerable<ExpensesRequest> dispatcherExps = from exp in TempEntityList
        //                                                          where exp.Reference_Table == "DispatcherRequest" && exp.Reference_ID == dispatcherId
        //                                                          select exp;
        //            if (dispatcherExps != null) {
        //              foreach (var dispExp in dispatcherExps) {
        //                // Add dispatcher expense in removeExpense list.
        //                removeExpenses.Add(dispExp);
        //              }
        //            }

        //          }
        //          // Add scale expense in removeExpense list.
        //          removeExpenses.Add(item);
        //        }
        //        // Delete scale and dispatcher expense.
        //        foreach (var removeExp in removeExpenses) {
        //          TempEntityList.Remove(removeExp);
        //        }
        //      }
        //    }
        //  }
        //}

        public void AddNonInvoiceSellingScaleExpenses(int bookingId)
        {
            TempEntityList.Clear();
            ScaleLibrary        scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <Scale> scales   = scaleLib.GetScalesByBookingId(bookingId);
            // Search for all expenses that matches scaleId.
            ExpensesRequestLibrary lib = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            string refTableName        = new Model.Scale().GetType().Name;

            foreach (var scale in scales)
            {
                IEnumerable <ExpensesRequest> expenses = lib.GetAllSellingExepneseByRefTableAndRefId(scale.ID, refTableName, new[] { "Payment", "Paid_Party_To", "Invoice" });
                foreach (var expense in expenses)
                {
                    // If scale expense already exists.
                    if (TempEntityList.FirstOrDefault(m => m.ID == expense.ID) == null)
                    {
                        if (expense.Paid_Party_To == null)
                        {
                            expense.Paid_Party_To = new Party();
                        }
                        // Add eexpense to TempList.
                        TempEntityList.Add(expense);
                        // Add dispatcher expense.
                    }
                }
                AddNonInvoiceSellingDispatcherExpenses(bookingId, scale.ContainerNo);
            }
        }
Example #5
0
        public ActionResult GetUnPaidInvoices(GridCommand command, string partyId)
        {
            int totalRows = 0;

            TempEntityList.Clear();
            if (Convert.ToInt32(partyId) > 0)
            {
                string         dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString();
                InvoiceLibrary lib = new InvoiceLibrary();
                lib.Initialize(dbContextConnectionString);
                IEnumerable <Invoice> results = lib.GetUnPaidInvoicesWithPaging(out totalRows,
                                                                                command.Page, command.PageSize == 0 ? 20 : command.PageSize,
                                                                                "", "Asc",
                                                                                new string[] { "Booking.Sales_Order_No.Party", "Sales_Order_No.Party" },
                                                                                null,
                                                                                int.Parse(partyId)
                                                                                );

                if (results != null && results.Count() > 0)
                {
                    PaymentReceiptDetails paymentDetails;
                    int id = 0;
                    foreach (var item in results)
                    {
                        id += 1;
                        if (item.Booking == null)
                        {
                            item.Booking = new Booking();
                        }
                        paymentDetails = new PaymentReceiptDetails()
                        {
                            ID             = id,
                            Invoice        = item,
                            Balance_Amount = item.Net_Amt - item.Amount_Paid_Till_Date,
                            PaymentReceipt = new PaymentReceipt()
                        };

                        TempEntityList.Add(paymentDetails);
                    }
                }
            }

            IEnumerable <PaymentReceiptDetails> resultList = TempEntityList;

            return(View(new GridModel {
                Data = resultList, Total = totalRows
            }));
        }
Example #6
0
        protected override ActionResult Display(GridCommand command, string id, bool isNew)
        {
            int totalRows = 0;
            IEnumerable <CycleDetails> resultList;

            if (isNew == true || id == "0")
            {
                if (TempEntityList.Count <= 0)
                {
                    ItemLibrary        ItemLibrary = new smART.Library.ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    IEnumerable <Item> itemList    = ItemLibrary.GetAll().Where(o => o.IsActive == true && o.Active_Ind == true);
                    int iValue = 1;
                    foreach (var item in itemList)
                    {
                        CycleDetails cycleDetails = new CycleDetails();
                        cycleDetails.Item = item;
                        cycleDetails.ID   = iValue;
                        TempEntityList.Add(cycleDetails);
                        iValue++;
                    }
                    resultList = TempEntityList;
                    Session["CycleDetails"] = TempEntityList;
                }
                else
                {
                    resultList = _cycleDetailsOps.GetAllByPaging(TempEntityList, out totalRows,
                                                                 command.Page,
                                                                 command.PageSize,
                                                                 command.SortDescriptors.Count == 0 ? "" : command.SortDescriptors[0].Member,
                                                                 command.SortDescriptors.Count == 0 ? "" : command.SortDescriptors[0].SortDirection == System.ComponentModel.ListSortDirection.Descending ? "Desc" : "Asc",
                                                                 IncludePredicates,
                                                                 (command.FilterDescriptors.Count == 0 ? null : command.FilterDescriptors)
                                                                 );
                }
                Session["CycleDetails"] = TempEntityList;
                totalRows = TempEntityList.Count;
            }
            else
            {
                resultList = ((IParentChildLibrary <CycleDetails>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", IncludePredicates);
            }

            return(View(new GridModel {
                Data = resultList, Total = totalRows
            }));
        }
        protected override ActionResult Display(GridCommand command, string id, bool isNew)
        {
            int totalRows = 0;
            IEnumerable <PriceListItem> resultList; // = ((IParentChildLibrary<TEntity>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize==0?20:command.PageSize, "", "Asc", IncludePredicates);

            //if (isNew==true || id=="0" || id==null)
            if (isNew == true || id == "0")
            {
                //PriceListItem priceListItem = new PriceListItem();
                //priceListItem.Item = new Item() { ID=1,Item_Category="A",Item_Group="B",Long_Name="Item1",Short_Name="I1",Site_Org_ID=1,Priced=true,Active_Ind=true};
                //TempEntityList.Add(priceListItem);

                if (id == "-1")
                {
                    string      dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString();
                    ItemLibrary ItemLibrary = new smART.Library.ItemLibrary();
                    ItemLibrary.Initialize(dbContextConnectionString);
                    IEnumerable <Item> itemList = ItemLibrary.GetAll().Where(o => o.Priced == true);
                    int iValue = 1;
                    foreach (var item in itemList)
                    {
                        PriceListItem priceListItem = new PriceListItem();
                        priceListItem.Item = item;
                        priceListItem.ID   = iValue;
                        TempEntityList.Add(priceListItem);
                        iValue++;
                        //((PriceListItemLibrary)Library).Add(priceListItem);
                    }
                }
                resultList = TempEntityList;
                totalRows  = TempEntityList.Count;
            }
            else
            {
                resultList = ((IParentChildLibrary <PriceListItem>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", IncludePredicates);
                //resultList = ((IParentChildLibrary<PriceListItem>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize, "", "Asc", IncludePredicates);
            }

            return(View(new GridModel {
                Data = resultList, Total = totalRows
            }));
        }
        public override ActionResult _Insert(TEntity data, GridCommand command, bool isNew = false)
        {
            try {
                string docRefId = Convert.ToString(TempData["DocRefId"]);

                if (string.IsNullOrEmpty(docRefId))
                {
                    ModelState.AddModelError("docRefId", "Error occured on save document.");
                }

                if (ModelState.IsValid)
                {
                    data.Document_RefId = Guid.Parse(docRefId);
                    data = UpdateFileInfo(data, _fileHelper.GetTempSourceDirByFileRefId(docRefId));
                    data.Last_Updated_Date = DateTime.Now;
                    data.Updated_By        = User.Identity.Name; // HttpContext.Current.User.Identity.Name;

                    if (isNew)
                    {
                        data.Document_Path = _fileHelper.GetFilePath(_fileHelper.GetTempSourceDirByFileRefId(docRefId)); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefId, data.Document_Name);
                        TempEntityList.Add(data);
                    }
                    else
                    {
                        data.Document_Path = _fileHelper.GetFilePath(_fileHelper.GetSourceDirByFileRefId(docRefId));// Path.Combine(Configuration.GetsmARTDocPath(), docRefId, data.Document_Name);
                        data = Library.Add(data);

                        string destinationPath = _fileHelper.GetSourceDirByFileRefId(docRefId);     // Path.Combine(Configuration.GetsmARTDocPath(), docRefId);
                        string sourcePath      = _fileHelper.GetTempSourceDirByFileRefId(docRefId); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefId);

                        _fileHelper.MoveFile(data.Document_Name, sourcePath, destinationPath);
                    }
                    UpdateAttachmentImagePath(data);
                    TempData["DocRefId"] = null;
                }
            }
            catch (Exception ex) {
                ModelState.AddModelError("Error", ex.Message);
            }
            return(Display(command, data, isNew));
        }
        public ActionResult GetUnPaidExpenses(GridCommand command, string partyId, string bookingId = "0")
        {
            TempEntityList.Clear();

            if (Convert.ToInt32(partyId) > 0)
            {
                string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString();
                ExpensesRequestLibrary lib       = new ExpensesRequestLibrary();
                lib.Initialize(dbContextConnectionString);
                IEnumerable <ExpensesRequest> results = lib.GetUnPaidExpenses(new string[] { "Paid_Party_To", "Scale_Ref", "Dispatcher_Request_Ref.Booking_Ref_No", "Dispatcher_Request_Ref.Container" },
                                                                              int.Parse(partyId), int.Parse(bookingId)
                                                                              );
                if (results != null && results.Count() > 0)
                {
                    PaymentReceiptDetails paymentDetails;
                    int id = 0;
                    foreach (var item in results)
                    {
                        id            += 1;
                        paymentDetails = new PaymentReceiptDetails()
                        {
                            ID             = id,
                            ExpenseRequest = item,
                            Balance_Amount = Convert.ToDecimal(item.Amount_Paid - item.Amount_Paid_Till_Date),
                            PaymentReceipt = new PaymentReceipt()
                        };
                        if (paymentDetails.Settlement != null)
                        {
                            paymentDetails.Settlement.Scale = null;
                        }
                        if (paymentDetails.ExpenseRequest.Dispatcher_Request_Ref != null)
                        {
                            paymentDetails.ExpenseRequest.Dispatcher_Request_Ref.TruckingCompany = null;
                        }
                        TempEntityList.Add(paymentDetails);
                    }
                }
            }
            return(Display(command, "0", true));
        }
        private void AddUnPaidPurchaseDispatcherExpenses(int dispathcerId)
        {
            // Search for expenses that matches dispatcher id.
            ExpensesRequestLibrary lib             = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            string refTableName                    = new Model.DispatcherRequest().GetType().Name;
            IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispathcerId, refTableName, new[] { "Payment", "Paid_Party_To" });

            foreach (var item in expenses)
            {
                // If expense already exists.
                if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null)
                {
                    // If party is null.
                    if (item.Paid_Party_To == null)
                    {
                        item.Paid_Party_To = new Party();
                    }

                    // Add to TempList.
                    TempEntityList.Add(item);
                }
            }
        }
        public ActionResult _Index(GridCommand command, int id)
        {
            int totalRows = 0;

            //Delete entity from TempEntityList if exits.
            if (TempEntityList != null && TempEntityList.Count > 0)
            {
                IList <SettlementDetails> settlementDetails = (from data in TempEntityList
                                                               where data.Scale_Details_ID.Scale.ID == id
                                                               select data as SettlementDetails).ToList <SettlementDetails>();

                foreach (var item in settlementDetails)
                {
                    TempEntityList.Remove(item);
                }
            }


            //Get all unsettled scale details tickets
            string dbContextConnectionString        = ConfigurationHelper.GetsmARTDBContextConnectionString();
            ScaleDetailsLibrary scaleDetailsLibrary = new smART.Library.ScaleDetailsLibrary();

            scaleDetailsLibrary.Initialize(dbContextConnectionString);
            IEnumerable <ScaleDetails> scaleDetailsList = scaleDetailsLibrary.GetAllByPagingByParentID
                                                              (out totalRows,
                                                              int.Parse(id.ToString()),
                                                              1,
                                                              20,
                                                              "",
                                                              "Asc",
                                                              new string[] { "Scale", "Scale.Purchase_Order", "Item_Received", "Apply_To_Item" }
                                                              );


            // Create temp settlement details collection by scale details tickets
            int iValue = 1;
            PurchaseOrderItemLibrary poItemLibrary = new smART.Library.PurchaseOrderItemLibrary();

            poItemLibrary.Initialize(dbContextConnectionString);

            foreach (var item in scaleDetailsList)
            {
                SettlementDetails settlementDetails = new SettlementDetails();
                settlementDetails.ID = iValue;
                settlementDetails.Scale_Details_ID  = item;
                settlementDetails.Actual_Net_Weight = settlementDetails.Scale_Details_ID.NetWeight;

                //Get rate from PO Item
                if (item.Scale.Purchase_Order != null)
                {
                    PurchaseOrderItem poItem = poItemLibrary.GetPOItemByItemCode(item.Scale.Purchase_Order.ID, item.Item_Received.ID, null);
                    // If po item exits then update rate and amount.
                    if (poItem != null)
                    {
                        settlementDetails.Rate     = poItem.Price;
                        settlementDetails.Item_UOM = poItem.Ordered_Qty_UOM;

                        // If po item unit is not lbs.
                        if (!string.IsNullOrWhiteSpace(settlementDetails.Item_UOM) && settlementDetails.Item_UOM.ToLower() != "lbs")
                        {
                            UOMConversionLibrary uomConvLib = new UOMConversionLibrary();
                            uomConvLib.Initialize(dbContextConnectionString);
                            UOMConversion uomConv = uomConvLib.GetByUOM(poItem.Ordered_Qty_UOM, "LBS");
                            // When convertion factor not exits.
                            if (uomConv != null)
                            {
                                settlementDetails.Item_UOM_Conv_Fact = (decimal)uomConv.Factor;
                                settlementDetails.Item_UOM_NetWeight = settlementDetails.Actual_Net_Weight / (decimal)uomConv.Factor;
                                settlementDetails.Item_UOM_NetWeight = decimal.Round(settlementDetails.Item_UOM_NetWeight, 3, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                settlementDetails.Item_UOM_Conv_Fact = 1;
                                settlementDetails.Item_UOM_NetWeight = settlementDetails.Actual_Net_Weight;
                            }
                        }
                        // When Unit is default. Set default unit.
                        else
                        {
                            SetDefaultUnit(settlementDetails);
                        }
                        settlementDetails.Amount = settlementDetails.Item_UOM_NetWeight * poItem.Price;
                        settlementDetails.Amount = decimal.Round(settlementDetails.Amount, 2, MidpointRounding.AwayFromZero);
                    }
                    else
                    {
                        // When PO Item not exists.Set default unit.
                        SetDefaultUnit(settlementDetails);
                    }
                }
                // When PO not exists.Set default unit.
                else
                {
                    SetDefaultUnit(settlementDetails);
                }
                settlementDetails.Settlement_ID = new Settlement();
                settlementDetails.Price_List_ID = new PriceList();

                TempEntityList.Add(settlementDetails);
                iValue++;
            }

            return(Display(command, id.ToString(), true));
        }