コード例 #1
0
        public RouteHeaderSearchViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                MainRowList     = new SortableCollectionView <RouteCardService.RouteCardHeader>();
                SelectedMainRow = new RouteCardHeader();

                RouteCardService.GetRouteCardHeadersCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        VendorList = sv.Vendors;
                        MainRowList.Add(row);
                    }
                    Loading = false;
                };

                RouteCardService.GetRouteCardHeadersBeforeInspectionCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        MainRowList.Add(row);
                    }
                    Sizes   = sv.sizes;
                    Loading = false;
                };
            }
        }
コード例 #2
0
        private void DeleteAXroute(RouteCardHeader header)
        {
            var deleteOrReverse = 0;

            if (header.IsPosted == true)
            {
                deleteOrReverse = 1;
            }

            using (var axapta = new Axapta())
            {
                var credential = new NetworkCredential("bcproxy", "around1");
                axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);

                var import = axapta.CreateAxaptaObject("CreateProductionJournals");

                string journal = null;
                switch (header.RouteType)
                {
                case 3:
                    journal = header.AxReportAsAFinishedJournalId;
                    break;

                case 5:
                    journal = header.AxRouteCardJournalId;
                    break;

                case 0:
                    journal = header.AxRouteCardFabricsJournalId;
                    break;
                }

                if (journal != null)
                {
                    import.Call("deletejournal", header.RouteType, journal, deleteOrReverse);
                }
                if (header.AxRouteCardFabricsJournalId != null)
                {
                    import.Call("deletejournal", 0, header.AxRouteCardFabricsJournalId, deleteOrReverse);
                }
                axapta.Logoff();
            }
        }
コード例 #3
0
        public void PurchaseRouteServicesToAx(RouteCardHeader headerObjToPost, int postPostOrNo)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var detailsObjToPost = context.RouteCardFabrics.Where(x => x.RouteCardHeaderIserial == headerObjToPost.Iserial);

                using (var axapta = new Axapta())
                {
                    var credential = new NetworkCredential("bcproxy", "around1");

                    axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null);

                    var inventTable = axapta.CreateAxaptaRecord("InventDim");
                    try
                    {
                        var purchId          = "Rc_ " + headerObjToPost.Iserial.ToString();
                        var tableName        = "PurchTable";
                        var purchTableRecord = axapta.CreateAxaptaRecord(tableName);
                        purchTableRecord.Clear();
                        purchTableRecord.InitValue();

                        purchTableRecord.set_Field("PurchId", purchId);
                        purchTableRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate);
                        //   axaptaRecord.set_Field("PurchId", _PurchID);

                        var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord;
                        purchTableRecord.Call("initFromVendTable", header);

                        purchTableRecord.Insert();

                        tableName = "PurchLine";
                        foreach (var item in detailsObjToPost)
                        {
                            var axaptaRecord = axapta.CreateAxaptaRecord(tableName);
                            axaptaRecord.Clear();
                            axaptaRecord.InitValue();

                            inventTable.Clear();
                            inventTable.set_Field("InventLocationId", item.Warehouse);
                            if (item.FabricColor != null)
                            {
                                inventTable.set_Field("InventColorId", item.FabricColor);
                            }
                            if (item.Size != null)
                            {
                                inventTable.set_Field("InventSizeId", item.Size);
                            }

                            var importNew        = axapta.CreateAxaptaObject("CreateProductionJournals");
                            var producationOrder = importNew.Call("GetProdIdFromSalesorderAndColor", item.Style, item.StyleColor, item.SalesOrder);

                            if (producationOrder == null || (string)producationOrder == "")
                            {
                                producationOrder = "Free";
                            }

                            var config = importNew.Call("CreateConfig", item.ItemId, "Free");
                            var batch  = importNew.Call("CreateBatch", item.ItemId, producationOrder);
                            inventTable.set_Field("configId", "Free");
                            inventTable.set_Field("inventBatchId", producationOrder);
                            inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord;

                            if (inventTable != null)
                            {
                                var tempx = inventTable.get_Field("inventDimId").ToString();
                                axaptaRecord.set_Field("InventDimId", tempx);
                            }

                            axaptaRecord.set_Field("ItemId", item.ItemId);
                            axaptaRecord.set_Field("ItemId", item.ItemId);
                            axaptaRecord.set_Field("purchId", purchId);
                            axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.Qty.ToString()));
                            //  axaptaRecord.set_Field("PurchPrice", item.Qty);
                            axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.Qty.ToString()));
                            axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.Qty.ToString()));
                            axaptaRecord.Call("createLine", true, true, true, true, true, true);
                        }
                        //No errors occured, Commit!
                        //Axapta.TTSCommit();

                        if (postPostOrNo == 1)
                        {
                            var importNew = axapta.CreateAxaptaObject("CreateProductionJournals");
                            importNew.Call("PostPurchaseOrder", purchId, headerObjToPost.DocDate);
                        }
                    }

                    catch (Exception ex)
                    {
                        //There was some errors, Abort transaction and Raise error!
                        //Axapta.TTSAbort();
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        //Finally logoff the Axapta Session
                        axapta.Logoff();
                    }
                }
            }
        }
コード例 #4
0
ファイル: RouteCardOperations.cs プロジェクト: Osama91/CCWFM
        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);
                }
            }
        }
コード例 #5
0
ファイル: RouteCardOperations.cs プロジェクト: Osama91/CCWFM
        public RouteCardHeader AddRoutCard(RouteCardHeader header, List <RouteCardDetail> details, out List <RouteCardDetail> savedDetails, int postToAx, string transactionGuid, int userIserial)
        {
            header.Createdby       = userIserial;
            header.LastUpdatedDate = DateTime.Now;

            using (var context = new WorkFlowManagerDBEntities())
            {
                if (header.RouteCardFabrics.Any())
                {
                    var MaxPackingTransid = context.RouteCardHeaders.Where(w => w.tblTransactionType == header.tblTransactionType).Max(w => w.PackingTransID);
                    header.PackingTransID = MaxPackingTransid + 1;
                }
                if (header.tblTransactionType == 5)
                {
                    var job        = Operations.SharedOperation.GetUserJob(userIserial, "");
                    var routeIssue = context.TblAuthJobPermissions.FirstOrDefault(x => x.TblPermission == 225 && x.Tbljob == job);

                    header.RouteIncluded = routeIssue != null;
                }
                else
                {
                    header.RouteIncluded = false;
                }
                try
                {
                    if (header.tblTransactionType == 1)
                    {
                        foreach (var routeCardFabricRow in header.RouteCardFabrics)
                        {
                            routeCardFabricRow.RemainingQty = routeCardFabricRow.Qty;
                        }
                    }
                    else if (header.tblTransactionType == 2 || header.tblTransactionType == 3)
                    {
                        foreach (var routeCardFabricRow in header.RouteCardFabrics)
                        {
                            routeCardFabricRow.OldIserial             = routeCardFabricRow.Iserial;
                            routeCardFabricRow.RouteCardHeaderIserial = header.Iserial;
                            routeCardFabricRow.RemainingQty           = null;
                            var oldrow = context.RouteCardFabrics.SingleOrDefault(x => x.Iserial == routeCardFabricRow.OldIserial);
                            if (oldrow != null)
                            {
                                oldrow.RemainingQty = oldrow.RemainingQty - routeCardFabricRow.Qty;
                            }
                        }
                    }

                    else if (header.tblTransactionType == 4 || header.tblTransactionType == 6)// return from PickingLists
                    {
                        foreach (var routeCardFabricRow in header.RouteCardFabrics.ToList())
                        {
                            routeCardFabricRow.OldIserial = routeCardFabricRow.Iserial;


                            routeCardFabricRow.RemainingQty           = null;
                            routeCardFabricRow.RouteCardHeaderIserial = header.Iserial;
                            var oldrow = context.RouteCardFabrics.SingleOrDefault(x => x.Iserial == routeCardFabricRow.OldIserial);
                            oldrow.RemainingQty = oldrow.RemainingQty - routeCardFabricRow.Qty;
                            if (header.tblTransactionType == 4)
                            {
                                var transferRow = context.RouteCardFabrics.SingleOrDefault(x => x.Iserial == oldrow.OldIserial);
                                if (transferRow != null)
                                {
                                    transferRow.RemainingQty = transferRow.RemainingQty + routeCardFabricRow.Qty;
                                }
                            }
                        }
                    }
                    else if (header.tblTransactionType == 5)
                    {
                        foreach (var routeCardFabricRow in header.RouteCardFabrics.ToList())
                        {
                            routeCardFabricRow.OldIserial = routeCardFabricRow.Iserial;
                        }
                    }

                    context.RouteCardHeaders.AddObject(header);
                    context.SaveChanges();
                    foreach (var item in details)
                    {
                        item.RouteCardHeaderIserial = header.Iserial;
                        context.RouteCardDetails.AddObject(item);
                    }
                    context.SaveChanges();

                    savedDetails = details;
                    if (postToAx == 1)
                    {
                        PostRoutCardToAx(header.Iserial, postToAx, transactionGuid, userIserial);
                    }

                    return(header);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
コード例 #6
0
ファイル: MarkerOperations.cs プロジェクト: Osama91/CCWFM
        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);
                }
            }
        }