Exemplo n.º 1
0
        public List <Tbl_ReservationDetails> SaveReservationDetails(List <Tbl_ReservationDetails> resMainDetails, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                foreach (var item in resMainDetails)
                {
                    var reservationDetails = (from d in entities.Tbl_ReservationDetails
                                              where d.Iserial == item.Iserial
                                              select d).SingleOrDefault();
                    if (reservationDetails != null)
                    {
                        GenericUpdate(reservationDetails, item, entities);
                    }
                    else
                    {
                        item.Tbl_ReservationMainDetails1 = null;
                        // item.Tbl_ReservationMainDetails = item.Iserial;
                        entities.AddObject("Tbl_ReservationDetails", item);
                    }
                }

                entities.SaveChanges();
                return(resMainDetails);
            }
        }
Exemplo n.º 2
0
        public RouteCardHeader UpdateRoutCard(RouteCardHeader header, List <RouteCardDetail> details, int postOrNo, string transactionGuid, int userIserial)
        {
            header.UpdatedBy       = userIserial;
            header.LastUpdatedDate = DateTime.Now;
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (header.tblTransactionType == 5)
                {
                    var job        = Operations.SharedOperation.GetUserJob(userIserial, "");
                    var routeIssue = context.TblAuthJobPermissions.FirstOrDefault(x => x.TblPermission == 225 && x.Tbljob == job);
                    if (routeIssue == null)
                    {
                        header.RouteIncluded = false;
                    }
                    else
                    {
                        header.RouteIncluded = true;
                    }
                }
                else
                {
                    header.RouteIncluded = false;
                }
                try
                {
                    var rch = (from x in context.RouteCardHeaders
                               where x.Iserial == header.Iserial
                               select x).FirstOrDefault();
                    header.Createdby      = rch.Createdby;
                    header.PackingTransID = rch.PackingTransID;
                    var det = context.RouteCardDetails.Where(x => x.RouteCardHeaderIserial == header.Iserial);
                    foreach (var item in det)
                    {
                        context.DeleteObject(item);
                    }
                    //try
                    //{
                    //    DeleteAXroute(rch, userIserial);
                    //}
                    //catch (Exception)
                    //{
                    //}
                    try
                    {
                        context.DeleteObject(rch);

                        context.AddObject("RouteCardHeaders", header);

                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        //context.DeleteObject(rch);
                        var code = GetMaxRouteCardTransactionID(header.RoutGroupID, header.Direction, header.tblTransactionType);
                        header.TransID = code + 1;
                        context.AddObject("RouteCardHeaders", header);
                        context.SaveChanges();
                    }

                    foreach (var item in details)
                    {
                        item.RouteCardHeaderIserial = header.Iserial;

                        context.RouteCardDetails.AddObject(item);
                    }

                    foreach (var item in details.Where(w => w.Price != 0).GroupBy(w => w.TblSalesOrder))
                    {
                        var salesOrderOperation = context.TblSalesOrderOperations.FirstOrDefault(w => w.TblSalesOrder == item.Key && w.TblRouteGroup == header.TblRouteGroup);
                        if (salesOrderOperation != null)
                        {
                            if (salesOrderOperation.OprCost != 0)
                            {
                                salesOrderOperation.OprCost = Convert.ToSingle(item.Max(w => w.Price));
                            }
                        }
                    }

                    context.SaveChanges();
                    if (postOrNo == 1)
                    {
                        PostRoutCardToAx(header.Iserial, postOrNo, transactionGuid, userIserial);
                    }

                    return(header);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private void GenerateRouteFromMarker(int iserial, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var h = (from head in entities.tbl_MarkerTransactionHeader
                         where head.Iserial == iserial
                         select head).SingleOrDefault();
                h.Posted = true;

                var markerDetailQuery = (from f in entities.tbl_MarkerDetail.Include("Tbl_Wf_CuttingOrder")
                                         where f.MarkerTransactionHeader == iserial &&
                                         f.Tbl_Wf_CuttingOrder.Count() != 0
                                         select f).ToList();

                var salesorder        = markerDetailQuery.FirstOrDefault().SalesOrder;
                var salesOrderIserial = entities.TblSalesOrders.FirstOrDefault(w => w.SalesOrderCode == salesorder && w.SalesOrderType == 2).Iserial;
                var bomline           = entities.BOMs.FirstOrDefault(w => w.TblSalesOrder == salesOrderIserial && w.BOM_IsMainFabric == true);
                if (bomline == null)
                {
                    throw new InvalidDataException("Please Check Main fabric");
                }
                var routeHeaderOld = (from head in entities.RouteCardHeaders
                                      where head.MarkerTransaction == iserial
                                      select head).SingleOrDefault();

                if (routeHeaderOld != null && routeHeaderOld.AxRouteCardFabricsJournalId != null)
                {
                    return;
                }
                else
                {
                    if (routeHeaderOld != null)
                    {
                        entities.RouteCardHeaders.DeleteObject(routeHeaderOld);
                    }
                }
                var transactionType = 5;

                //var singleOrDefault = entities.tblChainSetups.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultVendor");

                //if (singleOrDefault != null)
                //{
                //    var defaultVendor = singleOrDefault.sSetupValue;

                //    transactionType = h != null && defaultVendor == h.Vendor ? 5:5;
                //}
                if (bomline.BOM_FabricRout == null)
                {
                    throw new InvalidDataException("Please Check Main fabric Route Group");
                }
                h.Operation = (int)bomline.BOM_FabricRout;
                if (h != null)
                {
                    var routeHeader = new RouteCardHeader
                    {
                        tblTransactionType = transactionType,
                        DocDate            = h.TransDate,
                        Direction          = 0,
                        MarkerTransaction  = h.Iserial,
                        RoutGroupID        = h.Operation,
                        Vendor             = h.Vendor,
                        RoutID             = h.Workstation,
                        IsPosted           = false,
                        TransID            = Operations.SharedOperation.GetMaxRouteCardTransactionID(h.Operation, 0, transactionType) + 1,
                        RouteType          = 5,
                        DeliveryDate       = h.TransDate
                    };

                    entities.AddToRouteCardHeaders(routeHeader);
                    entities.SaveChanges();
                    foreach (var d in markerDetailQuery)
                    {
                        foreach (var item in d.Tbl_Wf_CuttingOrder)
                        {
                            var fabricaccsearch = entities.FabricAccSearches.FirstOrDefault(w => w.Code == d.FabricCode);
                            var total           = GetNetRollFromTotal(item.Barcode, item.RollAssignedQty);
                            var inspection      =
                                entities.Tbl_fabricInspectionDetail.FirstOrDefault(x => x.Iserial == item.InspectionIserial);

                            var site        = entities.GetLocations.Where(x => x.INVENTLOCATIONID == inspection.FinishedWarehouse).Select(x => x.INVENTSITEID).FirstOrDefault();
                            var routeFabric = new RouteCardFabric
                            {
                                ItemGroup              = fabricaccsearch.ItemGroup,
                                TblSalesOrder          = salesOrderIserial,
                                Barcode                = item.Barcode,
                                Batch                  = inspection.BatchNo,
                                FabricColor            = d.FabricColorCode,
                                ItemId                 = d.FabricCode,
                                Location               = inspection.FinishedWarehouse,
                                Warehouse              = inspection.FinishedWarehouse,
                                Qty                    = total,
                                RemainingQty           = total,
                                RouteCardHeaderIserial = routeHeader.Iserial,
                                Site                   = site,
                                StyleColor             = d.StyleColorCode,
                                Unit                   = item.RollUnit,
                                Size                   = inspection.BatchNo,
                            };

                            entities.AddObject("RouteCardFabrics", routeFabric);
                            entities.SaveChanges();
                        }
                    }
                    var discStyleColors =
                        markerDetailQuery.GroupBy(x => x.StyleColorCode).Select(x => x.Key).Distinct();
                    var salesordercode     = markerDetailQuery.FirstOrDefault().SalesOrder;
                    var salesOrderIserials = entities.TblSalesOrders.FirstOrDefault(w => w.SalesOrderCode == salesordercode && w.SalesOrderType == 2).Iserial;
                    var salesOrder         = entities.TblSalesOrders.Include("TblStyle1.TblSizeGroup1.TblSizes").FirstOrDefault(w => w.Iserial == salesOrderIserials);

                    foreach (var variable in discStyleColors)
                    {
                        var objectIndex = Guid.NewGuid().ToString("D");

                        var rr            = new WorkFlowManagerDBEntities().markerPostToRouteProcedure(iserial, variable).ToList();
                        var warehousecode = GetChainSetupBycode("DefaultFPWarehouse1st");

                        var warehouseIserial = entities.TblWarehouses.FirstOrDefault(w => w.Code == warehousecode).Iserial;
                        if (rr.Any())
                        {
                            foreach (var row in rr)
                            {
                                var newrow = new RouteCardDetail
                                {
                                    TblColor                = variable,
                                    Degree                  = "1st",
                                    TblSalesOrder           = salesOrderIserials,
                                    Trans_TransactionHeader = routeHeader.TransID,
                                    Size                   = row.meterpersizecode,
                                    SizeQuantity           = (int?)row.sizeQtyReal,
                                    RoutGroupID            = h.Operation,
                                    Direction              = 0,
                                    ObjectIndex            = objectIndex,
                                    RouteCardHeaderIserial = routeHeader.Iserial,
                                    TblWarehouse           = warehouseIserial
                                };
                                entities.RouteCardDetails.AddObject(newrow);
                            }
                        }
                        else
                        {
                            var objectIndexnew = Guid.NewGuid().ToString("D");
                            foreach (var VARIABLE in salesOrder.TblStyle1.TblSizeGroup1.TblSizes)
                            {
                                var newrow = new RouteCardDetail
                                {
                                    TblColor                = variable,
                                    Degree                  = "1st",
                                    TblSalesOrder           = salesOrderIserials,
                                    Trans_TransactionHeader = routeHeader.TransID,
                                    Size                   = VARIABLE.SizeCode,
                                    SizeQuantity           = 0,
                                    RoutGroupID            = h.Operation,
                                    Direction              = 0,
                                    ObjectIndex            = objectIndexnew,
                                    RouteCardHeaderIserial = routeHeader.Iserial,
                                    TblWarehouse           = warehouseIserial
                                };

                                entities.RouteCardDetails.AddObject(newrow);
                            }
                        }
                    }
                }
                entities.SaveChanges();

                if (h.Status == 0)
                {
                    // SenderMarkerMail("MarkerMail", "Marker", "", h.Iserial);
                }
            }
        }
Exemplo n.º 4
0
        public void GenerateReservationFromPlan(Tbl_ReservationHeader header)
        {
            if (header.Iserial == 0)
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    using (var scope = new TransactionScope())
                    {
                        header.IsPosted = false;
                        header.DocNo    = "TEST";
                        context.AddObject("Tbl_ReservationHeader", header);
                        context.SaveChanges();

                        var valuesObjects = new Dictionary <string, object>();
                        var filter        = "it.PURCHID ==(@PURCHID0)";
                        valuesObjects.Add("PURCHID0", header.TransOrder);
                        filter = filter + " and it.DATAAREAID ==(@DATAAREAID0)";
                        valuesObjects.Add("DATAAREAID0", "ccm");
                        var parameterCollection = ConvertToParamters(valuesObjects);
                        var querytemp           = context.PurchlineInventDims.Where(filter, parameterCollection.ToArray());
                        foreach (var p in querytemp)
                        {
                            var newrow = new Tbl_ReservationMainDetails
                            {
                                Fabric                = p.ITEMID,
                                FabricUnit            = p.PURCHUNIT,
                                FabricColor           = p.CONFIGID,
                                Batchno               = p.INVENTBATCHID,
                                Qty                   = (float)p.PURCHQTY,
                                Inspected             = false,
                                LineNum               = p.LINENUM,
                                Location              = p.WMSLOCATIONID,
                                Warehouse             = p.INVENTLOCATIONID,
                                Site                  = p.INVENTSITEID,
                                Tbl_ReservationHeader = header.Iserial,
                            };

                            var purchaseOrderDetails = from x in context.TblPurchaseOrderDetails.Include(
                                "TblPurchaseOrderDetailBreakDowns.BOM1.TblSalesOrder1")
                                                       let purid = ("p" + x.TblPurchaseOrderHeader1.TblGeneratePurchaseHeader1.Code + "_" +
                                                                    x.TblPurchaseOrderHeader1.Vendor).ToLower()
                                                                   where x.ItemId == p.ITEMID && x.TblColor.Code == p.CONFIGID &&
                                                                   p.PURCHID == (purid)
                                                                   select x
                            ;
                            //var purchaseOrderDetails =
                            //    context.TblPurchaseOrderDetails.Include(
                            //        "TblPurchaseOrderDetailBreakDowns.BOM1.TblSalesOrder1")
                            //        .Where(
                            //            x =>
                            //                x.ItemId == p.ITEMID && x.TblColor.Code == p.CONFIGID &&
                            //                'P' + x.TblPurchaseOrderHeader1.TblGeneratePurchaseHeader1.Code + '_' +
                            //                x.TblPurchaseOrderHeader1.Vendor == p.PURCHID).ToList();
                            var reservationDetailList = new EntityCollection <Tbl_ReservationDetails>();

                            foreach (var purchaseLine in purchaseOrderDetails.ToList())
                            {
                                foreach (var row in purchaseLine.TblPurchaseOrderDetailBreakDowns)
                                {
                                    var percentage = row.Qty / purchaseLine.Qty;

                                    float salesorderQty = (float)(percentage * newrow.Qty);

                                    var newdetailrow = new Tbl_ReservationDetails
                                    {
                                        FinalQty              = salesorderQty,
                                        IntialQty             = salesorderQty,
                                        Markered              = false,
                                        AxPicklingListJournal = "",
                                        SalesOrderColor       = p.CONFIGID,
                                        SalesOrder            = row.BOM1.TblSalesOrder1.SalesOrderCode,
                                    };
                                    reservationDetailList.Add(newdetailrow);
                                }
                            }
                            newrow.Tbl_ReservationDetails = reservationDetailList;

                            context.Tbl_ReservationMainDetails.AddObject(newrow);
                        }
                        context.SaveChanges();
                        scope.Complete();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public List <Tbl_ReservationMainDetails> SaveReservation(Tbl_ReservationHeader reservationHeader, List <Tbl_ReservationMainDetails> resMainDetails, string transactionGuid, out bool ErrorExists, int userIserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var errors          = new List <string>();
                var mainRowWithGuid = new Dictionary <string, Tbl_ReservationMainDetails>();
                foreach (var item in resMainDetails)
                {
                    var guidCheck = Guid.NewGuid().ToString();
                    mainRowWithGuid.Add(guidCheck, item);
                }

                if (errors.Count != 0)
                {
                    ErrorExists = true;

                    return(mainRowWithGuid.Where(x => errors.Any(e => x.Key == e)).Select(s => s.Value).ToList());
                }
                else
                {
                    ErrorExists = false;
                    if (reservationHeader.Iserial == 0)
                    {
                        reservationHeader.IsPosted = false;
                        reservationHeader.DocNo    = "TEST";
                        entities.AddObject("Tbl_ReservationHeader", reservationHeader);
                        entities.SaveChanges();
                    }
                    foreach (var item in resMainDetails)
                    {
                        if (item.Iserial != 0)
                        {
                            foreach (var items in item.Tbl_ReservationDetails.ToList())
                            {
                                var reservationDetails = (from d in entities.Tbl_ReservationDetails
                                                          where d.Iserial == items.Iserial
                                                          select d).SingleOrDefault();
                                if (reservationDetails != null)
                                {
                                    //     items.AxPicklingListJournal = PickingListFromReservation(items, reservationHeader, transactionGuid, userIserial, true, false);
                                    GenericUpdate(reservationDetails, items, entities);
                                }
                                else
                                {
                                    items.Tbl_ReservationMainDetails1 = null;
                                    items.Tbl_ReservationMainDetails  = item.Iserial;

                                    entities.AddObject("Tbl_ReservationDetails", items);
                                    //     items.AxPicklingListJournal = PickingListFromReservation(items, reservationHeader, transactionGuid, userIserial, true, false);
                                }
                            }
                        }
                        else
                        {
                            item.Tbl_ReservationHeader = reservationHeader.Iserial;
                            entities.AddObject("Tbl_ReservationMainDetails", item);
                            entities.SaveChanges();

                            foreach (var items in item.Tbl_ReservationDetails.ToList())
                            {
                                items.Tbl_ReservationMainDetails = item.Iserial;
                                //      items.AxPicklingListJournal = PickingListFromReservation(items, reservationHeader, transactionGuid, userIserial, true, false);
                            }
                        }
                    }

                    entities.SaveChanges();
                    return(resMainDetails);
                }
            }
        }