Esempio n. 1
0
        //Created By: Jerome Anthony Gerero, Created On: 7/19/2017

        /*Purpose: Delete transferred vehicles
         * Registration Details:
         * Event/Message:
         *      Pre/Delete: Allocated Items to Delete
         * Primary Entity: Vehicle In-Transit Transfer
         */
        public Entity DeleteInTransitTransferVehicle(Entity vehicleInTransitTransferEntity)
        {
            _tracingService.Trace("Started DeleteInTransitTransferVehicle method...");

            if (vehicleInTransitTransferEntity.GetAttributeValue <OptionSetValue>("gsc_intransittransferstatus").Value != 100000000)
            {
                return(null);
            }

            Guid vehicleInTransitTransferDetailId = vehicleInTransitTransferEntity.Contains("gsc_allocateditemstodelete")
                ? new Guid(vehicleInTransitTransferEntity.GetAttributeValue <String>("gsc_allocateditemstodelete"))
                : Guid.Empty;

            EntityCollection vehicleInTransitTransferDetailRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransferdetail", "gsc_iv_vehicleintransittransferdetailid", vehicleInTransitTransferDetailId, _organizationService,
                                                                                                             null, OrderType.Ascending, new[] { "gsc_inventoryid" });

            if (vehicleInTransitTransferDetailRecords.Entities.Count > 0)
            {
                Entity vehicleInTransitTransferDetail = vehicleInTransitTransferDetailRecords.Entities[0];

                Guid inventoryId = vehicleInTransitTransferDetail.Contains("gsc_inventoryid")
                    ? vehicleInTransitTransferDetail.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                    : Guid.Empty;

                //Retrieve and update inventory
                EntityCollection inventoryRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService, null, OrderType.Ascending,
                                                                                            new[] { "gsc_status", "gsc_productquantityid", "gsc_modelcode", "gsc_optioncode", "gsc_color", "gsc_csno", "gsc_engineno", "gsc_modelyear", "gsc_productionno", "gsc_vin", "gsc_siteid", "gsc_productid", "gsc_basemodelid" });

                if (inventoryRecords.Entities.Count > 0)
                {
                    Entity inventory = inventoryRecords.Entities[0];

                    InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);
                    inventoryMovement.UpdateInventoryStatus(inventory, 100000000);

                    Guid productQuantityId = inventory.Contains("gsc_productquantityid")
                        ? inventory.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                        : Guid.Empty;

                    EntityCollection productQuantityRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                      null, OrderType.Ascending, new[] { "gsc_available", "gsc_allocated", "gsc_vehiclemodelid", "gsc_vehiclecolorid" });

                    if (productQuantityRecords.Entities.Count > 0)
                    {
                        Entity productQuantity = productQuantityRecords.Entities[0];

                        inventoryMovement.UpdateProductQuantityDirectly(productQuantity, 0, 1, -1, 0, 0, 0, 0, 0);

                        _organizationService.Delete(vehicleInTransitTransferDetail.LogicalName, vehicleInTransitTransferDetail.Id);
                    }
                }
            }

            vehicleInTransitTransferEntity["gsc_allocateditemstodelete"] = String.Empty;
            _organizationService.Update(vehicleInTransitTransferEntity);

            _tracingService.Trace("Ending DeleteInTransitTransferVehicle method...");
            return(vehicleInTransitTransferEntity);
        }
Esempio n. 2
0
        private Entity TransferInventoryToNewSite(Entity productQuantityDestination, Entity inventory, Boolean newlyCreated)
        {
            //Update of inventory status
            inventory["gsc_status"]            = new OptionSetValue(100000000);
            inventory["gsc_productquantityid"] = new EntityReference("gsc_iv_productquantity", productQuantityDestination.Id);
            _organizationService.Update(inventory);
            _tracingService.Trace("Updated inventory status to available...");

            if (!newlyCreated)
            {
                InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);
                return(inventoryMovement.UpdateProductQuantityDirectly(productQuantityDestination, 1, 1, 0, 0, 0, 0, 0, 0));
            }

            return(productQuantityDestination);
        }
Esempio n. 3
0
        //Descrease in Unserved PO in Destination Site
        public void SubtractinUnservedPO(Entity vehicleReceivingItem)
        {
            var vehicleReceivingId = vehicleReceivingItem.GetAttributeValue <EntityReference>("gsc_receivingtransactionid") != null
                ? vehicleReceivingItem.GetAttributeValue <EntityReference>("gsc_receivingtransactionid").Id
                : Guid.Empty;

            EntityCollection receivingRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_receivingtransaction", "gsc_cmn_receivingtransactionid", vehicleReceivingId, _organizationService, null, OrderType.Ascending,
                                                                                        new[] { "gsc_purchaseorderid" });

            if (receivingRecords != null && receivingRecords.Entities.Count > 0)
            {
                Entity vehicleReceiving = receivingRecords.Entities[0];

                var purchaseOrderId = vehicleReceiving.GetAttributeValue <EntityReference>("gsc_purchaseorderid") != null
                ? vehicleReceiving.GetAttributeValue <EntityReference>("gsc_purchaseorderid").Id
                : Guid.Empty;

                EntityCollection poRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_purchaseorder", "gsc_cmn_purchaseorderid", purchaseOrderId, _organizationService, null, OrderType.Ascending,
                                                                                     new[] { "gsc_productquantityid" });

                if (poRecords != null && poRecords.Entities.Count > 0)
                {
                    Entity purchaseOrder = poRecords.Entities[0];

                    var productQuantityId = purchaseOrder.GetAttributeValue <EntityReference>("gsc_productquantityid") != null
                    ? purchaseOrder.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                    : Guid.Empty;

                    EntityCollection productQuantityRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService, null, OrderType.Ascending,
                                                                                                      new[] { "gsc_onhand", "gsc_available", "gsc_allocated", "gsc_onorder", "gsc_sold", "gsc_intransit", "gsc_damaged", "gsc_backorder" });

                    if (productQuantityRecords != null && productQuantityRecords.Entities.Count > 0)
                    {
                        InventoryMovementHandler handler = new InventoryMovementHandler(_organizationService, _tracingService);
                        handler.UpdateProductQuantityDirectly(productQuantityRecords.Entities[0], 0, 0, 0, -1, 0, 0, 0, 0);
                    }
                }
            }
        }
Esempio n. 4
0
        //Created By: Raphael Herrera, Created On: 8/3/2016

        /*Purpose: Create new allocated vehicle record.
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_inventoryidtoallocate
         * Primary Entity: gsc_iv_vehicletransfer
         */
        public void AllocateVehicle(Entity vehicleTransfer)
        {
            _tracingService.Trace("Started AllocateVehicle method...");

            var inventoryId = vehicleTransfer.Contains("gsc_inventoryidtoallocate")
                ? vehicleTransfer.GetAttributeValue <string>("gsc_inventoryidtoallocate")
                : String.Empty;

            EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService, null, OrderType.Ascending,
                                                                                           new[] { "gsc_status", "gsc_color", "gsc_csno", "gsc_engineno", "gsc_modelcode", "gsc_optioncode", "gsc_productionno", "gsc_vin", "gsc_productquantityid", "gsc_modelyear", "gsc_siteid", "gsc_productid", "gsc_basemodelid" });

            _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);

            if (inventoryCollection.Entities.Count > 0)
            {
                Entity inventoryEntity = inventoryCollection.Entities[0];
                Guid   destinationSite = vehicleTransfer.Contains("gsc_siteid") ? vehicleTransfer.GetAttributeValue <EntityReference>("gsc_siteid").Id : Guid.Empty;
                Guid   sourceSite      = inventoryEntity.Contains("gsc_siteid") ? inventoryEntity.GetAttributeValue <EntityReference>("gsc_siteid").Id : Guid.Empty;
                if (destinationSite == sourceSite)
                {
                    throw new InvalidPluginExecutionException("Cannot transfer vehicle. Destination site should not be equal to source site.");
                }

                if (inventoryEntity.GetAttributeValue <OptionSetValue>("gsc_status").Value == 100000000)
                {
                    _tracingService.Trace("Status of inventory is available...");
                    #region Update Inventory and product quantity

                    //set status to allocated
                    inventoryEntity["gsc_status"] = new OptionSetValue(100000001);
                    _organizationService.Update(inventoryEntity);
                    _tracingService.Trace("Updated inventory status to allocated...");

                    var productQuantityId = inventoryEntity.Contains("gsc_productquantityid") ? inventoryEntity.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                        : Guid.Empty;


                    EntityCollection productQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                         null, OrderType.Ascending, new[] { "gsc_allocated", "gsc_available", "gsc_siteid", "gsc_productid", "gsc_vehiclemodelid", "gsc_vehiclecolorid" });

                    _tracingService.Trace("ProductQuantity records retrieved: " + productQuantityCollection.Entities.Count);
                    if (productQuantityCollection.Entities.Count > 0)
                    {
                        Entity productQuantityEntity = productQuantityCollection.Entities[0];

                        /*  Int32 allocated = productQuantityEntity.Contains("gsc_allocated") ? productQuantityEntity.GetAttributeValue<Int32>("gsc_allocated")
                         *    : 0;
                         * Int32 available = productQuantityEntity.Contains("gsc_available") ? productQuantityEntity.GetAttributeValue<Int32>("gsc_available")
                         *    : 0;
                         *
                         * productQuantityEntity["gsc_allocated"] = allocated + 1;
                         *
                         * if (available > 0)
                         * {
                         *    productQuantityEntity["gsc_available"] = available - 1;
                         * }
                         *
                         * _organizationService.Update(productQuantityEntity);;*/

                        #region Create VehicleAllocation Record

                        Entity transferredVehicleDetails = new Entity("gsc_iv_vehicletransferdetails");
                        var    destinationSiteId         = vehicleTransfer.Contains("gsc_siteid") ? vehicleTransfer.GetAttributeValue <EntityReference>("gsc_siteid").Id
                            : Guid.Empty;
                        var sourceSiteId = productQuantityEntity.Contains("gsc_siteid") ? productQuantityEntity.GetAttributeValue <EntityReference>("gsc_siteid").Id
                            : Guid.Empty;

                        transferredVehicleDetails["gsc_color"]        = inventoryEntity.GetAttributeValue <String>("gsc_color");
                        transferredVehicleDetails["gsc_csno"]         = inventoryEntity.GetAttributeValue <String>("gsc_csno");
                        transferredVehicleDetails["gsc_engineno"]     = inventoryEntity.GetAttributeValue <String>("gsc_engineno");
                        transferredVehicleDetails["gsc_modelcode"]    = inventoryEntity.GetAttributeValue <String>("gsc_modelcode");
                        transferredVehicleDetails["gsc_optioncode"]   = inventoryEntity.GetAttributeValue <String>("gsc_optioncode");
                        transferredVehicleDetails["gsc_productionno"] = inventoryEntity.GetAttributeValue <String>("gsc_productionno");
                        transferredVehicleDetails["gsc_modelyear"]    = inventoryEntity.GetAttributeValue <String>("gsc_modelyear");
                        transferredVehicleDetails["gsc_vin"]          = inventoryEntity.GetAttributeValue <String>("gsc_vin");
                        transferredVehicleDetails["gsc_productid"]    = productQuantityEntity.GetAttributeValue <EntityReference>("gsc_productid") != null
                        ? new EntityReference("product", productQuantityEntity.GetAttributeValue <EntityReference>("gsc_productid").Id)
                        : null;
                        transferredVehicleDetails["gsc_basemodel"] = productQuantityEntity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid") != null
                        ? new EntityReference("gsc_iv_vehiclebasemodel", productQuantityEntity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid").Id)
                        : null;
                        transferredVehicleDetails["gsc_inventoryid"]       = new EntityReference(inventoryEntity.LogicalName, inventoryEntity.Id);
                        transferredVehicleDetails["gsc_vehicletransferid"] = new EntityReference(vehicleTransfer.LogicalName, vehicleTransfer.Id);
                        transferredVehicleDetails["gsc_destinationsiteid"] = new EntityReference("gsc_iv_site", destinationSiteId);
                        transferredVehicleDetails["gsc_sourcesiteid"]      = new EntityReference("gsc_iv_site", sourceSiteId);
                        _organizationService.Create(transferredVehicleDetails);

                        _tracingService.Trace("Created vehicle allocation record...");

                        vehicleTransfer["gsc_inventoryidtoallocate"] = String.Empty;

                        _organizationService.Update(vehicleTransfer);

                        #endregion

                        //Create Inventory History Log
                        InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);

                        inventoryMovement.UpdateProductQuantityDirectly(productQuantityEntity, 0, -1, 1, 0, 0, 0, 0, 0);
                        _tracingService.Trace("Updated productquantity count...");

                        inventoryMovement.CreateInventoryQuantityAllocated(vehicleTransfer, inventoryEntity, productQuantityEntity, vehicleTransfer.GetAttributeValue <string>("gsc_vehicletransferpn"),
                                                                           DateTime.UtcNow, "Open", destinationSiteId, 100000001);
                    }

                    #endregion
                }

                else
                {
                    throw new InvalidPluginExecutionException("!_The inventory for entered vehicle is not available.");
                }
            }

            _tracingService.Trace("Ending AllocateVehicle method...");
        }
Esempio n. 5
0
        //Created By: Raphael Herrera, Created On: 8/8/2016

        /*Purpose: BL for posting vehicletransfer transaction
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_transferstatus
         * Primary Entity: gsc_iv_vehicletransfer
         */
        public void PostTransaction(Entity vehicleTransfer)
        {
            _tracingService.Trace("Started PostTransaction Method...");

            //Retrieve allocatedVehicle to retrieve inventoryid
            EntityCollection transferredVehicleDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicletransferdetails", "gsc_vehicletransferid", vehicleTransfer.Id, _organizationService,
                                                                                                           null, OrderType.Ascending, new[] { "gsc_inventoryid", "gsc_destinationsiteid", "gsc_sourcesiteid" });
            InventoryMovementHandler inventoryMovementHandler = new InventoryMovementHandler(_organizationService, _tracingService);

            _tracingService.Trace("AllocatedVehicle records retrieved: " + transferredVehicleDetailsCollection.Entities.Count);

            if (transferredVehicleDetailsCollection != null && transferredVehicleDetailsCollection.Entities.Count > 0)
            {
                foreach (Entity allocatedVehicle in transferredVehicleDetailsCollection.Entities)
                {
                    _tracingService.Trace("Running through allocatedvehicle record...");
                    var inventoryId = allocatedVehicle.Contains("gsc_inventoryid") ? allocatedVehicle.GetAttributeValue <EntityReference>("gsc_inventoryid").Id :
                                      Guid.Empty;
                    Guid destinationSiteId = allocatedVehicle.Contains("gsc_destinationsiteid") ? allocatedVehicle.GetAttributeValue <EntityReference>("gsc_destinationsiteid").Id :
                                             Guid.Empty;
                    String destinationSiteName = allocatedVehicle.Contains("gsc_destinationsiteid") ? allocatedVehicle.GetAttributeValue <EntityReference>("gsc_destinationsiteid").Name :
                                                 String.Empty;
                    String   transactionNumber = vehicleTransfer.Contains("gsc_vehicletransferpn") ? vehicleTransfer.GetAttributeValue <String>("gsc_vehicletransferpn") : string.Empty;
                    DateTime transactionDate   = DateTime.UtcNow;
                    Guid     fromSite          = allocatedVehicle.Contains("gsc_sourcesiteid") ? allocatedVehicle.GetAttributeValue <EntityReference>("gsc_sourcesiteid").Id : Guid.Empty;

                    //Retrieve inventory to update status
                    EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                   null, OrderType.Ascending, new[] { "gsc_status", "gsc_color", "gsc_csno", "gsc_engineno", "gsc_modelcode", "gsc_optioncode", "gsc_productionno", "gsc_vin", "gsc_productquantityid", "gsc_modelyear", "gsc_siteid", "gsc_productid", "gsc_basemodelid" });
                    _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);

                    if (inventoryCollection != null && inventoryCollection.Entities.Count > 0)
                    {
                        var productQuantityId = inventoryCollection.Entities[0].GetAttributeValue <EntityReference>("gsc_productquantityid").Id;

                        //Retrieve ProductQuantity where inventory came from to be updated
                        EntityCollection productQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                             null, OrderType.Ascending, new[] { "gsc_allocated", "gsc_onhand", "gsc_productid", "gsc_vehiclecolorid", "gsc_vehiclemodelid", "gsc_siteid" });
                        _tracingService.Trace("ProductQuantity records retrieved: " + productQuantityCollection.Entities.Count);

                        if (productQuantityCollection != null && productQuantityCollection.Entities.Count > 0)
                        {
                            Entity productQuantity = productQuantityCollection.Entities[0];
                            //Adjustment of 'site from'
                            Int32 allocated = productQuantity.GetAttributeValue <Int32>("gsc_allocated");
                            Int32 onHand    = productQuantity.GetAttributeValue <Int32>("gsc_onhand");

                            productQuantity["gsc_allocated"] = allocated - 1;
                            productQuantity["gsc_onhand"]    = onHand - 1;
                            _organizationService.Update(productQuantity);
                            _tracingService.Trace("Updated productquantity from site record...");

                            //Log inventory history upon decreasing onhand value in source site
                            inventoryMovementHandler.CreateInventoryHistory("Vehicle Transfer", string.Empty, string.Empty, transactionNumber, transactionDate, 1, 1, onHand - 1, destinationSiteId, fromSite, fromSite, inventoryCollection.Entities[0], productQuantity, true, false);

                            Guid   productId   = productQuantity.Contains("gsc_productid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_productid").Id : Guid.Empty;
                            Guid   colorId     = productQuantity.Contains("gsc_vehiclecolorid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_vehiclecolorid").Id : Guid.Empty;
                            Guid   baseModel   = productQuantity.Contains("gsc_vehiclemodelid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid").Id : Guid.Empty;
                            String productName = productQuantity.Contains("gsc_productid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_productid").Name : String.Empty;

                            var destinationConditionList = new List <ConditionExpression>
                            {
                                new ConditionExpression("gsc_siteid", ConditionOperator.Equal, destinationSiteId),
                                new ConditionExpression("gsc_productid", ConditionOperator.Equal, productId),
                                new ConditionExpression("gsc_vehiclecolorid", ConditionOperator.Equal, colorId)
                            };

                            //Retrieve productquantity of destination site to be updated
                            EntityCollection productQuantityDestinationCollection = CommonHandler.RetrieveRecordsByConditions("gsc_iv_productquantity", destinationConditionList, _organizationService,
                                                                                                                              null, OrderType.Ascending, new[] { "gsc_allocated", "gsc_onhand", "gsc_available" });
                            _tracingService.Trace("ProductQuantity(Destination) records retrieved: " + productQuantityDestinationCollection.Entities.Count);

                            Entity inventory = new Entity("gsc_iv_inventory");
                            Entity productQuantityDestination = new Entity("gsc_iv_productquantity");
                            Int32  onHandCount = 1;
                            if (productQuantityDestinationCollection != null && productQuantityDestinationCollection.Entities.Count > 0)
                            {
                                //Adjustment of destination site
                                productQuantityDestination = productQuantityDestinationCollection.Entities[0];
                                Int32 onHandDestination = productQuantityDestination.GetAttributeValue <Int32>("gsc_onhand");

                                //Update of inventory status
                                inventory = inventoryCollection.Entities[0];
                                inventory["gsc_status"]            = new OptionSetValue(100000000);
                                inventory["gsc_productquantityid"] = new EntityReference(productQuantityDestination.LogicalName, productQuantityDestination.Id);
                                _organizationService.Update(inventory);
                                _tracingService.Trace("Updated inventory status to available...");

                                inventoryMovementHandler.UpdateProductQuantityDirectly(productQuantityDestination, 1, 1, 0, 0, 0, 0, 0, 0);
                                _tracingService.Trace("Updated productquantity destination record...");

                                onHandCount = onHandDestination + 1;
                            }
                            else
                            {
                                //Create productQuantity
                                Entity prodQuantity = new Entity("gsc_iv_productquantity");
                                _tracingService.Trace("Set product quantity count");
                                prodQuantity["gsc_onhand"]    = 1;
                                prodQuantity["gsc_available"] = 1;
                                prodQuantity["gsc_allocated"] = 0;
                                prodQuantity["gsc_onorder"]   = 0;
                                prodQuantity["gsc_sold"]      = 0;
                                prodQuantity["gsc_branchid"]  = vehicleTransfer.GetAttributeValue <EntityReference>("gsc_branchid") != null
                               ? new EntityReference("account", vehicleTransfer.GetAttributeValue <EntityReference>("gsc_branchid").Id)
                               : null;
                                prodQuantity["gsc_dealerid"] = vehicleTransfer.GetAttributeValue <EntityReference>("gsc_dealerid") != null
                                ? new EntityReference("account", vehicleTransfer.GetAttributeValue <EntityReference>("gsc_dealerid").Id)
                                : null;
                                prodQuantity["gsc_recordownerid"] = vehicleTransfer.GetAttributeValue <EntityReference>("gsc_recordownerid") != null
                                ? new EntityReference("contact", vehicleTransfer.GetAttributeValue <EntityReference>("gsc_recordownerid").Id)
                                : null;

                                _tracingService.Trace("Set site field");
                                if (destinationSiteId != Guid.Empty)
                                {
                                    prodQuantity["gsc_siteid"] = new EntityReference("gsc_iv_site", destinationSiteId);
                                }
                                _tracingService.Trace("Set Vehicle Base Model field");
                                if (baseModel != Guid.Empty)
                                {
                                    prodQuantity["gsc_vehiclemodelid"] = new EntityReference("gsc_iv_vehiclebasemodel", baseModel);
                                }

                                if (colorId != Guid.Empty)
                                {
                                    prodQuantity["gsc_vehiclecolorid"] = new EntityReference("gsc_cmn_vehiclecolor", colorId);
                                }
                                _tracingService.Trace("Set Product Name field");
                                prodQuantity["gsc_productid"]         = new EntityReference("product", productId);
                                prodQuantity["gsc_productquantitypn"] = productName + "-" + destinationSiteName;

                                Guid newProductQuantityId = _organizationService.Create(prodQuantity);

                                EntityCollection productQuantityEC = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", newProductQuantityId, _organizationService, null, OrderType.Ascending,
                                                                                                             new[] { "gsc_vehiclecolorid", "gsc_vehiclemodelid", "gsc_productid" });
                                productQuantityDestination = productQuantityEC.Entities[0];

                                //Update of inventory status
                                inventory = inventoryCollection.Entities[0];
                                inventory["gsc_status"]            = new OptionSetValue(100000000);
                                inventory["gsc_productquantityid"] = new EntityReference(prodQuantity.LogicalName, newProductQuantityId);
                                _organizationService.Update(inventory);
                                _tracingService.Trace("Updated inventory status to available...");
                            }

                            inventoryMovementHandler.CreateInventoryHistory("Vehicle Transfer", string.Empty, string.Empty, transactionNumber, transactionDate, 1, 1, onHandCount, destinationSiteId, fromSite, destinationSiteId, inventory, productQuantityDestination, true, true);
                            inventoryMovementHandler.CreateInventoryQuantityAllocated(vehicleTransfer, inventory, productQuantity, vehicleTransfer.GetAttributeValue <string>("gsc_vehicletransferpn"),
                                                                                      DateTime.UtcNow, "Posted", destinationSiteId, 100000008);
                        }
                    }
                }
            }
            else
            {
                throw new InvalidPluginExecutionException("!_Please select first vehicle to transfer");
            }
            _tracingService.Trace("Ending PostTransasction method...");
        }
Esempio n. 6
0
        //Created By: Raphael Herrera, Created On: 8/4/2016

        /*Purpose: Handle Delete BL for vehicle transfer record
         * Registration Details:
         * Event/Message:
         *      Pre/Delete: VehicleTransfer
         * Primary Entity: gsc_iv_vehicletransfer
         */
        public void ValidateDelete(Entity vehicleTransfer)
        {
            _tracingService.Trace("Started ValidateDelete method...");
            //Unposted status
            if (vehicleTransfer.GetAttributeValue <OptionSetValue>("gsc_transferstatus").Value == 100000001)
            {
                _tracingService.Trace("Status is Unposted...");
                EntityCollection transferDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicletransferdetails", "gsc_vehicletransferid", vehicleTransfer.Id, _organizationService,
                                                                                                     null, OrderType.Ascending, new[] { "gsc_inventoryid" });

                _tracingService.Trace("Transfer Details records retrieved: " + transferDetailsCollection.Entities.Count);
                if (transferDetailsCollection.Entities.Count > 0)
                {
                    foreach (Entity transferDetails in transferDetailsCollection.Entities)
                    {
                        var inventoryId = transferDetails.Contains("gsc_inventoryid") ? transferDetails.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                           : Guid.Empty;

                        //Retrieve and update inventory
                        EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                       null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid", "gsc_modelcode", "gsc_optioncode", "gsc_color", "gsc_csno", "gsc_engineno", "gsc_modelyear", "gsc_productionno", "gsc_vin", "gsc_siteid", "gsc_productid", "gsc_basemodelid" });

                        _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);
                        if (inventoryCollection.Entities.Count > 0)
                        {
                            Entity inventory = inventoryCollection.Entities[0];
                            inventory["gsc_status"] = new OptionSetValue(100000000);
                            _organizationService.Update(inventory);

                            var productQuantityId = inventory.Contains("gsc_productquantityid") ? inventory.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                                : Guid.Empty;

                            //Retrieve and update product quantity
                            EntityCollection productQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                                 null, OrderType.Ascending, new[] { "gsc_available", "gsc_allocated", "gsc_vehiclemodelid", "gsc_vehiclecolorid" });

                            _tracingService.Trace("ProductQuantity records retrieved: " + productQuantityCollection.Entities.Count);
                            if (productQuantityCollection.Entities.Count > 0)
                            {
                                Entity productQuantity = productQuantityCollection.Entities[0];

                                //Create inventory history log
                                InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);

                                inventoryMovement.UpdateProductQuantityDirectly(productQuantity, 0, 1, -1, 0, 0, 0, 0, 0);
                                _tracingService.Trace("Updated productquantity count...");

                                inventoryMovement.CreateInventoryQuantityAllocated(vehicleTransfer, inventory, productQuantity, vehicleTransfer.GetAttributeValue <string>("gsc_vehicletransferpn"),
                                                                                   DateTime.UtcNow, "Deleted", vehicleTransfer.GetAttributeValue <EntityReference>("gsc_siteid").Id, 100000005);
                            }
                        }

                        //Delete Transfer Details
                        _organizationService.Delete(transferDetails.LogicalName, transferDetails.Id);
                    }
                }
            }

            //Posted status
            else if (vehicleTransfer.GetAttributeValue <OptionSetValue>("gsc_transferstatus").Value == 100000000)
            {
                _tracingService.Trace("Status is posted...");
                throw new InvalidPluginExecutionException("!_Unable to delete Posted Vehicle Transfer transactions.");
            }
            _tracingService.Trace("Ending ValidateDelete method...");
        }
Esempio n. 7
0
        //Created By : Raphael Herrera, Created On : 6/3/2016
        //Modified By : Jerome Anthony Gerero, Modified On : 1/5/2017
        //Modified By : Artum Ramos, Modified On : 5/11/2017

        /*Purpose: Set status to posted then update inventory count
         * Event/Message:
         *      Post/Update: gsc_posttransaction
         * Primary Entity: Vehicle Sales Return
         */
        public Entity PostTransaction(Entity vehicleSalesReturnEntity)
        {
            _tracingService.Trace("Started PostTransaction method...");

            if (IsValidInvoice(vehicleSalesReturnEntity) == false)
            {
                throw new InvalidPluginExecutionException("Sales invoice selected already returned.");
            }

            Entity inventory = RetrieveInventory(vehicleSalesReturnEntity);

            if (inventory != null)
            {
                _tracingService.Trace("Inventory Not Null.");

                Guid siteId = vehicleSalesReturnEntity.Contains("gsc_site")
                    ? vehicleSalesReturnEntity.GetAttributeValue <EntityReference>("gsc_site").Id
                    : Guid.Empty;

                Entity productQuantity = RetrieveOldProductQuantity(inventory, vehicleSalesReturnEntity, siteId);

                String customerId = vehicleSalesReturnEntity.Contains("gsc_customerid") ?
                                    vehicleSalesReturnEntity.GetAttributeValue <String>("gsc_customerid") : String.Empty;
                String customerName = vehicleSalesReturnEntity.Contains("gsc_customername") ?
                                      vehicleSalesReturnEntity.GetAttributeValue <String>("gsc_customername") : String.Empty;
                String transactionNumber = vehicleSalesReturnEntity.Contains("gsc_vehiclesalesreturnpn") ?
                                           vehicleSalesReturnEntity.GetAttributeValue <String>("gsc_vehiclesalesreturnpn") : String.Empty;
                DateTime transactionDate = DateTime.UtcNow;
                Guid     fromSite        = productQuantity.Contains("gsc_siteid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_siteid").Id : Guid.Empty;
                Guid     productId       = productQuantity.Contains("gsc_productid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_productid").Id : Guid.Empty;
                Guid     colorId         = productQuantity.Contains("gsc_vehiclecolorid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_vehiclecolorid").Id : Guid.Empty;
                Guid     baseModel       = productQuantity.Contains("gsc_vehiclemodelid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid").Id : Guid.Empty;
                String   productName     = productQuantity.Contains("gsc_productid") ? productQuantity.GetAttributeValue <EntityReference>("gsc_productid").Name : String.Empty;

                _tracingService.Trace("Inventory History Created.");

                Entity productQuantityDestination = new Entity();
                if (siteId != fromSite)
                {
                    productQuantityDestination = RetrieveNewProductQuantity(vehicleSalesReturnEntity, productQuantity, siteId);

                    if (productQuantityDestination != null)
                    {
                        TransferInventoryToNewSite(productQuantityDestination, inventory, false);
                    }
                    else
                    {
                        productQuantityDestination = CreateNewProductQuantity(vehicleSalesReturnEntity, productQuantity, siteId);
                        productQuantityDestination = TransferInventoryToNewSite(productQuantityDestination, inventory, true);
                    }
                }
                else
                {
                    productQuantityDestination = TransferInventoryToNewSite(productQuantity, inventory, false);
                }

                InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);
                Int32 onHandDestination = productQuantityDestination.GetAttributeValue <Int32>("gsc_onhand");
                inventoryMovement.CreateInventoryHistory("Vehicle Sales Return", customerId, customerName, transactionNumber, transactionDate, 0, 1, onHandDestination, siteId, Guid.Empty, siteId, inventory, productQuantityDestination, true, true);

                inventoryMovement.UpdateProductQuantityDirectly(productQuantity, 0, 0, 0, 0, -1, 0, 0, 0);

                /*Int32 onHandFrom = productQuantity.GetAttributeValue<Int32>("gsc_onhand");
                 * inventoryMovement.CreateInventoryHistory("Vehicle Sales Return", customerId, customerName, transactionNumber, transactionDate, 1, 0, onHandFrom, siteId, fromSite, fromSite, inventory, productQuantity, true, true);*/

                _tracingService.Trace("Inventory History Created.");
            }

            _tracingService.Trace("Update gsc_vehiclesalesreturnstatus");

            Entity quoteToUpdate = _organizationService.Retrieve(vehicleSalesReturnEntity.LogicalName, vehicleSalesReturnEntity.Id,
                                                                 new ColumnSet("gsc_vehiclesalesreturnstatus", "gsc_isinvoicereturned"));

            vehicleSalesReturnEntity["gsc_vehiclesalesreturnstatus"] = new OptionSetValue(100000001);
            //Added by: JGC_05222017, Description: This will call Sales Return - Update Invoice isSalesReturned Tagging Workflow
            vehicleSalesReturnEntity["gsc_isinvoicereturned"] = true;
            //End
            _organizationService.Update(vehicleSalesReturnEntity);

            _tracingService.Trace("Ended PostTransaction method...");
            return(vehicleSalesReturnEntity);
        }
Esempio n. 8
0
        //Created By: Raphael Herrera, Created On: 8/23/2016

        /*Purpose: Create new allocated vehicle record.
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_inventoryidtoallocate
         * Primary Entity: gsc_iv_vehicleintransittransfer
         */
        public Entity AllocateVehicle(Entity vehicleInTransitTransfer)
        {
            _tracingService.Trace("Started AllocateVehicle method...");

            Guid inventoryId = vehicleInTransitTransfer.Contains("gsc_inventoryidtoallocate")
                ? new Guid(vehicleInTransitTransfer.GetAttributeValue <String>("gsc_inventoryidtoallocate"))
                : Guid.Empty;

            if (inventoryId == Guid.Empty)
            {
                return(null);
            }

            EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService, null, OrderType.Ascending,
                                                                                           new[] { "gsc_status", "gsc_color", "gsc_csno", "gsc_engineno", "gsc_modelcode", "gsc_optioncode", "gsc_productionno", "gsc_vin", "gsc_productquantityid", "gsc_modelyear" });

            _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);

            if (inventoryCollection.Entities.Count > 0)
            {
                Entity inventoryEntity = inventoryCollection.Entities[0];

                if (inventoryEntity.GetAttributeValue <OptionSetValue>("gsc_status").Value == 100000000)
                {
                    _tracingService.Trace("Status of inventory is available...");
                    #region Update Inventory and product quantity

                    //set status to allocated
                    InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);
                    inventoryMovement.UpdateInventoryStatus(inventoryEntity, 100000001);

                    _tracingService.Trace("Updated inventory status to allocated...");

                    Guid productQuantityId = inventoryEntity.Contains("gsc_productquantityid")
                        ? inventoryEntity.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                        : Guid.Empty;

                    EntityCollection productQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                         null, OrderType.Ascending, new[] { "gsc_allocated", "gsc_available", "gsc_siteid", "gsc_vehiclemodelid", "gsc_productid" });

                    _tracingService.Trace("ProductQuantity records retrieved: " + productQuantityCollection.Entities.Count);
                    if (productQuantityCollection != null && productQuantityCollection.Entities.Count > 0)
                    {
                        Entity productQuantityEntity = productQuantityCollection.Entities[0];

                        inventoryMovement.UpdateProductQuantityDirectly(productQuantityEntity, 0, -1, 1, 0, 0, 0, 0, 0);
                        _tracingService.Trace("Updated productquantity count...");

                        #region Create VehicleAllocation Record

                        Entity allocatedVehicle  = new Entity("gsc_iv_vehicleintransittransferdetail");
                        var    destinationSiteId = vehicleInTransitTransfer.Contains("gsc_destinationsiteid") ? vehicleInTransitTransfer.GetAttributeValue <EntityReference>("gsc_destinationsiteid").Id
                            : Guid.Empty;
                        var sourceSiteId = productQuantityEntity.Contains("gsc_siteid") ? productQuantityEntity.GetAttributeValue <EntityReference>("gsc_siteid").Id
                            : Guid.Empty;
                        var viaSiteId = vehicleInTransitTransfer.Contains("gsc_viasiteid") ? vehicleInTransitTransfer.GetAttributeValue <EntityReference>("gsc_viasiteid").Id
                            : Guid.Empty;
                        var baseModelName = productQuantityEntity.Contains("gsc_vehiclemodelid") ? productQuantityEntity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid").Name
                            : String.Empty;
                        var productName = productQuantityEntity.Contains("gsc_productid") ? productQuantityEntity.GetAttributeValue <EntityReference>("gsc_productid").Name
                            : String.Empty;

                        allocatedVehicle["gsc_color"]                      = inventoryEntity.GetAttributeValue <String>("gsc_color");
                        allocatedVehicle["gsc_csno"]                       = inventoryEntity.GetAttributeValue <String>("gsc_csno");
                        allocatedVehicle["gsc_engineno"]                   = inventoryEntity.GetAttributeValue <String>("gsc_engineno");
                        allocatedVehicle["gsc_modelcode"]                  = inventoryEntity.GetAttributeValue <String>("gsc_modelcode");
                        allocatedVehicle["gsc_optioncode"]                 = inventoryEntity.GetAttributeValue <String>("gsc_optioncode");
                        allocatedVehicle["gsc_productionno"]               = inventoryEntity.GetAttributeValue <String>("gsc_productionno");
                        allocatedVehicle["gsc_vin"]                        = inventoryEntity.GetAttributeValue <String>("gsc_vin");
                        allocatedVehicle["gsc_basemodel"]                  = baseModelName;
                        allocatedVehicle["gsc_modeldescription"]           = productName;
                        allocatedVehicle["gsc_modelyear"]                  = inventoryEntity.GetAttributeValue <String>("gsc_modelyear");
                        allocatedVehicle["gsc_inventoryid"]                = new EntityReference(inventoryEntity.LogicalName, inventoryEntity.Id);
                        allocatedVehicle["gsc_vehicleintransittransferid"] = new EntityReference(vehicleInTransitTransfer.LogicalName, vehicleInTransitTransfer.Id);
                        //allocatedVehicle["gsc_destinationsiteid"] = new EntityReference("gsc_iv_site", destinationSiteId);
                        allocatedVehicle["gsc_sourcesiteid"] = new EntityReference("gsc_iv_site", sourceSiteId);
                        allocatedVehicle["gsc_viasiteid"]    = new EntityReference("gsc_iv_site", viaSiteId);

                        _organizationService.Create(allocatedVehicle);
                        _tracingService.Trace("Created vehicle allocation record...");
                        #endregion
                    }
                    #endregion
                }
            }

            vehicleInTransitTransfer["gsc_inventoryidtoallocate"] = String.Empty;
            _organizationService.Update(vehicleInTransitTransfer);

            _tracingService.Trace("Ending AllocateVehicle method...");
            return(vehicleInTransitTransfer);
        }
Esempio n. 9
0
        //Created By: Raphael Herrera, Created On: 8/26/2016

        /*Purpose: Handle BL for setting Vehicle In-Transit Transfer status to 'Shipped'
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_intransittransferstatus
         * Primary Entity: gsc_iv_vehicleintransittransfer
         */
        public void ShipVehicle(Entity vehicleInTransitTransfer, bool isShipping)
        {
            _tracingService.Trace("Started ShipVehicle method...");

            //Status == Picked
            if (vehicleInTransitTransfer.GetAttributeValue <OptionSetValue>("gsc_intransittransferstatus").Value == 100000000)
            {
                _tracingService.Trace("Status is Picked...");

                EntityCollection allocatedVehicleCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransferdetail", "gsc_vehicleintransittransferid", vehicleInTransitTransfer.Id, _organizationService,
                                                                                                      null, OrderType.Ascending, new[] { "gsc_inventoryid", "gsc_sourcesiteid", "gsc_viasiteid" });

                _tracingService.Trace("AllocatedVehicle records retrieved: " + allocatedVehicleCollection.Entities.Count);
                if (allocatedVehicleCollection.Entities.Count > 0)
                {
                    // Check if request is from shipping button
                    if (isShipping)
                    {
                        // Create Vehicle In-Transit Transfer Receiving Entity
                        _receivingHandler.CreateRecevingEntity(vehicleInTransitTransfer);
                    }

                    foreach (Entity allocatedVehicleEntity in allocatedVehicleCollection.Entities)
                    {
                        Guid inventoryId = allocatedVehicleEntity.Contains("gsc_inventoryid")
                            ? allocatedVehicleEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                            : Guid.Empty;

                        Guid viaSiteId = allocatedVehicleEntity.Contains("gsc_viasiteid")
                            ? allocatedVehicleEntity.GetAttributeValue <EntityReference>("gsc_viasiteid").Id
                            : Guid.Empty;

                        //Retrieve inventory
                        EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                       null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid", "gsc_modelcode", "gsc_optioncode", "gsc_color", "gsc_productid" });

                        _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);

                        if (inventoryCollection != null && inventoryCollection.Entities.Count > 0)
                        {
                            Entity inventory = inventoryCollection.Entities[0];

                            var sourceProdQuantityId = inventory.Contains("gsc_productquantityid") ? inventory.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                                : Guid.Empty;

                            //Retrieve source site product quantity
                            EntityCollection sourceProdQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", sourceProdQuantityId, _organizationService,
                                                                                                                    null, OrderType.Ascending, new[] { "gsc_onhand", "gsc_allocated", "gsc_productid", "gsc_vehiclecolorid", "gsc_vehiclemodelid" });

                            _tracingService.Trace("Source ProductQuantity records retrieved: " + sourceProdQuantityCollection.Entities.Count);

                            if (sourceProdQuantityCollection.Entities.Count > 0)
                            {
                                Entity sourceProdQuantity = sourceProdQuantityCollection.Entities[0];
                                InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);

                                //Retrieve destination site product quantity
                                //var viaSiteId = vehicleInTransitTransfer.Contains("gsc_viasiteid") ? vehicleInTransitTransfer.GetAttributeValue<EntityReference>("gsc_viasiteid").Id
                                //: Guid.Empty;
                                var productId = sourceProdQuantity.Contains("gsc_productid") ? sourceProdQuantity.GetAttributeValue <EntityReference>("gsc_productid").Id
                                    : Guid.Empty;
                                Entity vehicleColor = inventoryMovement.GetVehicleColorReference(inventory);

                                var viaSiteConditionList = new List <ConditionExpression>
                                {
                                    new ConditionExpression("gsc_siteid", ConditionOperator.Equal, viaSiteId),
                                    new ConditionExpression("gsc_productid", ConditionOperator.Equal, productId),
                                    new ConditionExpression("gsc_vehiclecolorid", ConditionOperator.Equal, vehicleColor.Id)
                                };

                                EntityCollection viaSiteProductQuantityRecords = CommonHandler.RetrieveRecordsByConditions("gsc_iv_productquantity", viaSiteConditionList, _organizationService, null,
                                                                                                                           OrderType.Ascending, new[] { "gsc_onhand", "gsc_available", "gsc_productid", "gsc_vehiclecolorid", "gsc_vehiclemodelid" });

                                _tracingService.Trace("Destination ProductQuantity records retrieved: " + viaSiteProductQuantityRecords.Entities.Count);

                                Entity viaSiteProductQuantity = new Entity("gsc_iv_productquantity");
                                if (viaSiteProductQuantityRecords.Entities == null || viaSiteProductQuantityRecords.Entities.Count == 0)
                                {
                                    Guid             viaQuantityId         = inventoryMovement.CreateProductQuantity(allocatedVehicleEntity.GetAttributeValue <EntityReference>("gsc_viasiteid"), productId, new EntityReference("gsc_cmn_vehiclecolor", vehicleColor.Id));
                                    EntityCollection viaQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", viaQuantityId, _organizationService, null, OrderType.Ascending,
                                                                                                                     new[] { "gsc_onhand", "gsc_available", "gsc_productid", "gsc_vehiclecolorid", "gsc_vehiclemodelid" });
                                    viaSiteProductQuantity = viaQuantityCollection.Entities[0];
                                }

                                else
                                {
                                    viaSiteProductQuantity = viaSiteProductQuantityRecords.Entities[0];
                                }
                                #region BL execution of method

                                //Update Inventory Status = Available

                                inventory["gsc_productquantityid"] = new EntityReference(viaSiteProductQuantity.LogicalName, viaSiteProductQuantity.Id);
                                inventoryMovement.UpdateInventoryStatus(inventory, 100000000);
                                _tracingService.Trace("Updated inventory record...");

                                //Adjust source product quantity
                                Entity sourceQuantityEntity = inventoryMovement.UpdateProductQuantityDirectly(sourceProdQuantity, -1, 0, -1, 0, 0, 0, 0, 0);
                                Entity branchEntity         = GetBranchEntity(vehicleInTransitTransfer, true);
                                var    fromSiteId           = vehicleInTransitTransfer.GetAttributeValue <EntityReference>("gsc_sourcesiteid").Id;

                                inventoryMovement.CreateInventoryHistory("Vehicle In Transit Transfer", branchEntity.GetAttributeValue <string>("accountnumber"), branchEntity.GetAttributeValue <string>("name"), vehicleInTransitTransfer.GetAttributeValue <string>("gsc_vehicleintransittransferpn"),
                                                                         DateTime.UtcNow, 1, 1, sourceQuantityEntity.GetAttributeValue <Int32>("gsc_onhand"), viaSiteId, fromSiteId, fromSiteId, inventory, sourceQuantityEntity, true, false);
                                _tracingService.Trace("Source Product Quantity updated...");

                                //Adjust site product quantity
                                inventoryMovement.UpdateProductQuantityDirectly(viaSiteProductQuantity, 1, 1, 0, 0, 0, 0, 0, 0);
                                branchEntity = GetBranchEntity(vehicleInTransitTransfer, false);

                                inventoryMovement.CreateInventoryHistory("Vehicle In Transit Transfer", branchEntity.GetAttributeValue <string>("accountnumber"), branchEntity.GetAttributeValue <string>("name"), vehicleInTransitTransfer.GetAttributeValue <string>("gsc_vehicleintransittransferpn"),
                                                                         DateTime.UtcNow, 1, 1, viaSiteProductQuantity.GetAttributeValue <Int32>("gsc_onhand"), viaSiteId, fromSiteId, viaSiteId, inventory, viaSiteProductQuantity, true, true);
                                _tracingService.Trace("Destination Product Quantity updated...");

                                //Clear inventoryidtoallocate field
                                vehicleInTransitTransfer["gsc_inventoryidtoallocate"] = "";
                                _organizationService.Update(vehicleInTransitTransfer);
                                _tracingService.Trace("Updated Vehicle In-Transit Transfer record...");
                                #endregion
                            }
                        }
                    }
                }
                else
                {
                    throw new InvalidPluginExecutionException("No Allocated Vehicle to Ship.");
                }
            }

            //Status != Picked
            else
            {
                _tracingService.Trace("Status is not Picked...");
                throw new InvalidPluginExecutionException("Unable to Ship Vehicle In-Transit Transfer record with this status.");
            }
            _tracingService.Trace("Ending ShipVehicle method...");
        }
Esempio n. 10
0
        //Created By: Raphael Herrera, Created On: 8/24/2016
        //Modified By: Artum Ramos, Modified On: 8/2/2017

        /*Purpose: Handle Delete AND Cancel BL for Vehicle In-Transit Transfer record
         * Registration Details:
         * Event/Message:
         *      Pre/Delete: VehicleInTransitTransfer
         *      Post/Update: gsc_intransittransferstatus
         * Primary Entity: gsc_iv_vehicleintransittransfer
         */
        public void ValidateTransaction(Entity vehicleInTransitTransfer, string message)
        {
            _tracingService.Trace("Started ValidateDelete method...");
            //Status == Picked
            if (vehicleInTransitTransfer.GetAttributeValue <OptionSetValue>("gsc_intransittransferstatus").Value == 100000000)
            {
                _tracingService.Trace("Status is Picked...");
                EntityCollection allocatedVehicleCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransferdetail", "gsc_vehicleintransittransferid", vehicleInTransitTransfer.Id, _organizationService,
                                                                                                      null, OrderType.Ascending, new[] { "gsc_inventoryid" });

                _tracingService.Trace("AllocatedVehicle records retrieved: " + allocatedVehicleCollection.Entities.Count);
                if (allocatedVehicleCollection.Entities.Count > 0)
                {
                    foreach (Entity allocatedVehicleEntity in allocatedVehicleCollection.Entities)
                    {
                        var inventoryId = allocatedVehicleEntity.Contains("gsc_inventoryid") ? allocatedVehicleEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                           : Guid.Empty;

                        //Retrieve and update inventory
                        EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                       null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid" });

                        _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);
                        if (inventoryCollection.Entities.Count > 0)
                        {
                            Entity inventory = inventoryCollection.Entities[0];

                            InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService);
                            inventoryMovement.UpdateInventoryStatus(inventory, 100000000);

                            _tracingService.Trace("Updated inventory record...");

                            var productQuantityId = inventory.Contains("gsc_productquantityid") ? inventory.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                                : Guid.Empty;

                            //Retrieve and update product quantity
                            EntityCollection productQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                                 null, OrderType.Ascending, new[] { "gsc_available", "gsc_allocated" });

                            _tracingService.Trace("ProductQuantity records retrieved: " + productQuantityCollection.Entities.Count);
                            if (productQuantityCollection.Entities.Count > 0)
                            {
                                Entity productQuantity = productQuantityCollection.Entities[0];
                                inventoryMovement.UpdateProductQuantityDirectly(productQuantity, 0, 1, -1, 0, 0, 0, 0, 0);
                                _tracingService.Trace("Product Quantity updated...");

                                //Delete Vehicle Allocation
                                _organizationService.Delete(allocatedVehicleEntity.LogicalName, allocatedVehicleEntity.Id);
                                _tracingService.Trace("Deleted associated Allocated Vehicle record...");

                                //Clear inventoryidtoallocate field
                                vehicleInTransitTransfer["gsc_inventoryidtoallocate"]   = "";
                                vehicleInTransitTransfer["gsc_intransittransferstatus"] = new OptionSetValue(100000003);
                                _organizationService.Update(vehicleInTransitTransfer);
                                _tracingService.Trace("Updated Vehicle In-Transit Transfer record...");
                            }
                        }
                    }
                }
            }

            //Status != Picked
            else
            {
                _tracingService.Trace("Status is not Picked...");
                if (message == "Delete")
                {
                    throw new InvalidPluginExecutionException("Unable to delete Shipped/Received Vehicle In-Transit Transfer record.");
                }
                else if (message == "Update")
                {
                    throw new InvalidPluginExecutionException("Unable to cancel Shipped/Received Vehicle In-Transit Transfer record.");
                }
            }
            _tracingService.Trace("Ending ValidateDelete method...");
        }
Esempio n. 11
0
        //Created By: Raphael Herrera, Created On: 8/31/2016

        /*Purpose: Perform BL for receiving Vehicle In-Transit Transfer records
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_intransitstatus
         * Primary Entity: gsc_iv_vehicleintransittransferreceiving
         */
        public void CancelTransfer(Entity vehicleTransferReceiving)
        {
            _tracingService.Trace("Started Cancel Transfer Method...");
            if (vehicleTransferReceiving.GetAttributeValue <OptionSetValue>("gsc_intransitstatus").Value != 100000000)
            {
                throw new InvalidPluginExecutionException("Only records with Shipped status can be canceled.");
            }

            var inTransitTransferId = vehicleTransferReceiving.Contains("gsc_intransittransferid") ? vehicleTransferReceiving.GetAttributeValue <EntityReference>("gsc_intransittransferid").Id
                : Guid.Empty;

            //Retrieve In-Transit Transfer of In-Transit Transfer Receiving
            EntityCollection inTransitTransferCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransfer", "gsc_iv_vehicleintransittransferid", inTransitTransferId, _organizationService,
                                                                                                   null, OrderType.Ascending, new[] { "gsc_sourcesiteid", "gsc_viasiteid" });

            _tracingService.Trace("In-Transit Transfer Records Retrieved: " + inTransitTransferCollection.Entities.Count);
            if (inTransitTransferCollection.Entities.Count > 0)
            {
                Entity inTransitTransferEntity = inTransitTransferCollection.Entities[0];

                //Retrieve Allocated Vehicles of In-Transit Transfer
                EntityCollection transferDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransferdetail", "gsc_vehicleintransittransferid", inTransitTransferEntity.Id, _organizationService,
                                                                                                     null, OrderType.Ascending, new[] { "gsc_sourcesiteid", "gsc_viasiteid", "gsc_inventoryid" });

                _tracingService.Trace("In Transit Transfer Detail Records Retrieved: " + transferDetailsCollection.Entities.Count);
                if (transferDetailsCollection.Entities.Count > 0)
                {
                    foreach (Entity transferDetailsEntity in transferDetailsCollection.Entities)
                    {
                        var sourceSiteId = transferDetailsEntity.Contains("gsc_sourcesiteid") ? transferDetailsEntity.GetAttributeValue <EntityReference>("gsc_sourcesiteid").Id
                            : Guid.Empty;
                        var inventoryId = transferDetailsEntity.Contains("gsc_inventoryid") ? transferDetailsEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                            : Guid.Empty;

                        //Retrieve Inventory of Allocated Vehicle
                        EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                       null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid" });

                        _tracingService.Trace("Inventory Records Retrieved: " + inventoryCollection.Entities.Count);
                        if (inventoryCollection.Entities.Count > 0)
                        {
                            Entity inventoryEntity   = inventoryCollection.Entities[0];
                            var    viaProdQuantityId = inventoryEntity.Contains("gsc_productquantityid") ? inventoryEntity.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                                : Guid.Empty;
                            if (inventoryEntity.GetAttributeValue <OptionSetValue>("gsc_status").Value == 100000001)//status == allocated
                            {
                                throw new InvalidPluginExecutionException("Vehicle in this transaction is still allocated. Please remove allocation in Sales Order before cancelling.");
                            }
                            //Retrieve Product Quantity of Via Site
                            EntityCollection viaQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", viaProdQuantityId, _organizationService,
                                                                                                             null, OrderType.Ascending, new[] { "gsc_available", "gsc_onhand", "gsc_productid", "gsc_allocated" });

                            _tracingService.Trace("Via Site Product Quantity Records Retrieved: " + viaQuantityCollection.Entities.Count);
                            if (viaQuantityCollection.Entities.Count > 0)
                            {
                                Entity viaQuantityEntity = viaQuantityCollection.Entities[0];
                                var    productId         = viaQuantityEntity.Contains("gsc_productid") ? viaQuantityEntity.GetAttributeValue <EntityReference>("gsc_productid").Id
                                    : Guid.Empty;

                                //Retrieve Product Quantity of Source Site
                                var sourceConditionList = new List <ConditionExpression>
                                {
                                    new ConditionExpression("gsc_siteid", ConditionOperator.Equal, sourceSiteId),
                                    new ConditionExpression("gsc_productid", ConditionOperator.Equal, productId)
                                };

                                EntityCollection sourceQuantityCollection = CommonHandler.RetrieveRecordsByConditions("gsc_iv_productquantity", sourceConditionList, _organizationService, null,
                                                                                                                      OrderType.Ascending, new[] { "gsc_onhand", "gsc_available", "gsc_allocated" });

                                _tracingService.Trace("Source Site Product Quantity Records Retrieved: " + sourceQuantityCollection.Entities.Count);
                                if (sourceQuantityCollection.Entities.Count > 0)
                                {
                                    #region BL for Cancellation of Vehicle In-Transit Transfer Receiving
                                    Entity sourceQuantityEntity = sourceQuantityCollection.Entities[0];
                                    InventoryMovementHandler inventoryHandler = new InventoryMovementHandler(_organizationService, _tracingService);

                                    // Update Inventory. Status = Available
                                    inventoryEntity["gsc_productquantityid"] = new EntityReference(sourceQuantityEntity.LogicalName, sourceQuantityEntity.Id);
                                    inventoryEntity["gsc_status"]            = new OptionSetValue(100000000);
                                    inventoryHandler.UpdateInventoryFields(inventoryEntity, "Update");
                                    _tracingService.Trace("Updated Inventory Status...");

                                    // Update Product Quantity of Via Site
                                    inventoryHandler.UpdateProductQuantityDirectly(viaQuantityEntity, -1, -1, -1, 0, 0, 0, 0, 0);//Included value in allocated for recount
                                    _tracingService.Trace("Updated Via Site Product Quantity...");

                                    //Update Product Quantity of Source Site
                                    inventoryHandler.UpdateProductQuantityDirectly(sourceQuantityEntity, 1, 1, 1, 0, 0, 0, 0, 0);//Included value in allocated for recount
                                    _tracingService.Trace("Updated Source Site Product Quantity...");

                                    // Delete Allocated Vehicle record
                                    _organizationService.Delete(transferDetailsEntity.LogicalName, transferDetailsEntity.Id);
                                    _tracingService.Trace("Deleted Transfer Details...");
                                }
                                else
                                {
                                    throw new InvalidPluginExecutionException("Product Quantity of source site not found...");
                                }
                            }
                            else
                            {
                                throw new InvalidPluginExecutionException("Product Quantity of via site not found...");
                            }
                        }
                        else
                        {
                            throw new InvalidPluginExecutionException("No Inventory Records Found...");
                        }
                    }
                    // Update Vehicle In-Transit Transfer Status to Picked
                    inTransitTransferEntity["gsc_intransittransferstatus"] = new OptionSetValue(100000000);
                    _organizationService.Update(inTransitTransferEntity);

                    //Clear vehicle in-transit transfer lookup field
                    vehicleTransferReceiving["gsc_intransittransferid"] = null;
                    _organizationService.Update(vehicleTransferReceiving);
                    _tracingService.Trace("Updated Vehicle In-Transit Transfer status to cancelled...");
                    #endregion
                }
            }
            else
            {
                throw new InvalidPluginExecutionException("No In Transit Transfer Records Found...");
            }
            _tracingService.Trace("Ending CancelTransfer Method...");
        }
Esempio n. 12
0
        //Created By: Raphael Herrera, Created On: 8/31/2016

        /*Purpose: Perform BL for receiving Vehicle In-Transit Transfer records
         * Registration Details:
         * Event/Message:
         *      Post/Update: gsc_intransitstatus
         * Primary Entity: gsc_iv_vehicleintransittransferreceiving
         */
        public void ReceiveTransfer(Entity vehicleTransferReceiving)
        {
            _tracingService.Trace("Started ReceiveTransfer Method...");
            var inTransitTransferId = vehicleTransferReceiving.Contains("gsc_intransittransferid") ? vehicleTransferReceiving.GetAttributeValue <EntityReference>("gsc_intransittransferid").Id
                : Guid.Empty;

            //Retrieve Vehicle In-Transit Transfer
            EntityCollection inTransitCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransfer", "gsc_iv_vehicleintransittransferid", inTransitTransferId, _organizationService,
                                                                                           null, OrderType.Ascending, new[] { "gsc_intransittransferstatus" });

            _tracingService.Trace("Vehicle In-Transit Transfer records retrieved: " + inTransitCollection.Entities.Count);
            if (inTransitCollection.Entities.Count > 0)
            {
                Entity           vehicleInTransit           = inTransitCollection.Entities[0];
                EntityCollection receivingDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransitreceivingdetail", "gsc_intransitreceivingid", vehicleTransferReceiving.Id, _organizationService,
                                                                                                      null, OrderType.Ascending, new[] { "gsc_inventoryid", "gsc_destinationsiteid" });

                _tracingService.Trace("In Transit Transfer Details records retrieved: " + receivingDetailsCollection.Entities.Count);
                if (receivingDetailsCollection.Entities.Count > 0)
                {
                    foreach (Entity receivingDetailsEntity in receivingDetailsCollection.Entities)
                    {
                        var inventoryId = receivingDetailsEntity.Contains("gsc_inventoryid") ? receivingDetailsEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id
                           : Guid.Empty;

                        //Retrieve inventory
                        EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService,
                                                                                                       null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid", "gsc_color", "gsc_productid" });

                        _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count);
                        if (inventoryCollection.Entities.Count > 0)
                        {
                            Entity inventory = inventoryCollection.Entities[0];

                            var productQuantityId = inventory.Contains("gsc_productquantityid") ? inventory.GetAttributeValue <EntityReference>("gsc_productquantityid").Id
                               : Guid.Empty;

                            //Retrieve product quantity of Via Site
                            EntityCollection viaQuantityCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", productQuantityId, _organizationService,
                                                                                                             null, OrderType.Ascending, new[] { "gsc_available", "gsc_onhand", "gsc_allocated", "gsc_productid", "gsc_vehiclemodelid", "gsc_siteid", "gsc_vehiclecolorid" });

                            _tracingService.Trace("Via Site ProductQuantity records retrieved: " + viaQuantityCollection.Entities.Count);
                            if (viaQuantityCollection.Entities.Count > 0)
                            {
                                Entity viaProdQuantity = viaQuantityCollection.Entities[0];

                                //Retrieve Product Quantity of Destination Site
                                var destinationSite = vehicleTransferReceiving.Contains("gsc_destinationsiteid") ? vehicleTransferReceiving.GetAttributeValue <EntityReference>("gsc_destinationsiteid").Id
                                    : Guid.Empty;
                                var productId = viaProdQuantity.Contains("gsc_productid") ? viaProdQuantity.GetAttributeValue <EntityReference>("gsc_productid").Id
                                  : Guid.Empty;
                                InventoryMovementHandler inventoryHandler = new InventoryMovementHandler(_organizationService, _tracingService);
                                Entity vehicleColor = inventoryHandler.GetVehicleColorReference(inventory);

                                var destinationConditionList = new List <ConditionExpression>
                                {
                                    new ConditionExpression("gsc_siteid", ConditionOperator.Equal, destinationSite),
                                    new ConditionExpression("gsc_productid", ConditionOperator.Equal, productId),
                                    new ConditionExpression("gsc_vehiclecolorid", ConditionOperator.Equal, vehicleColor.Id)
                                };

                                EntityCollection destinationQuantityCollection = CommonHandler.RetrieveRecordsByConditions("gsc_iv_productquantity", destinationConditionList, _organizationService, null,
                                                                                                                           OrderType.Ascending, new[] { "gsc_onhand", "gsc_available", "gsc_allocated", "gsc_vehiclemodelid", "gsc_productid", "gsc_vehiclecolorid" });

                                Entity destinationQuantityEntity = new Entity("gsc_iv_productquantity");
                                _tracingService.Trace("Destination ProductQuantity records retrieved: " + destinationQuantityCollection.Entities.Count);

                                if (destinationQuantityCollection.Entities.Count == 0)
                                {
                                    Guid             destinationQuantityId = inventoryHandler.CreateProductQuantity(receivingDetailsEntity.GetAttributeValue <EntityReference>("gsc_destinationsiteid"), productId, new EntityReference("gsc_cmn_vehiclecolor", vehicleColor.Id));
                                    EntityCollection destinationCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_productquantity", "gsc_iv_productquantityid", destinationQuantityId, _organizationService, null, OrderType.Ascending,
                                                                                                                     new[] { "gsc_onhand", "gsc_available", "gsc_productid", "gsc_vehiclecolorid", "gsc_vehiclemodelid" });
                                    destinationQuantityEntity = destinationCollection.Entities[0];

                                    _tracingService.Trace("Created Product Quantity...");
                                }
                                else
                                {
                                    destinationQuantityEntity = destinationQuantityCollection.Entities[0];
                                }


                                #region BL for Receiving Vehicle In-Transit Transfer Record

                                Int32 viaAvailable         = viaProdQuantity.GetAttributeValue <Int32>("gsc_available");
                                Int32 viaOnHand            = viaProdQuantity.GetAttributeValue <Int32>("gsc_onhand");
                                Int32 destinationAvailable = destinationQuantityEntity.GetAttributeValue <Int32>("gsc_available");
                                Int32 destinationOnHand    = destinationQuantityEntity.GetAttributeValue <Int32>("gsc_onhand");

                                //Update Inventory Product Quantity
                                inventory["gsc_productquantityid"] = new EntityReference(destinationQuantityEntity.LogicalName, destinationQuantityEntity.Id);
                                inventoryHandler.UpdateInventoryFields(inventory, "Update");
                                _tracingService.Trace("Updated Inventory Status...");

                                //Update Product Quantity of Via Site
                                inventoryHandler.UpdateProductQuantityDirectly(viaProdQuantity, -1, -1, -1, 0, 0, 0, 0, 0);//Included value in allocated for recount
                                _tracingService.Trace("Updated Via Site Product Quantity...");
                                Entity branchEntity = GetBranchEntity(vehicleTransferReceiving);
                                Guid   viaSiteId    = viaProdQuantity.GetAttributeValue <EntityReference>("gsc_siteid").Id;
                                inventoryHandler.CreateInventoryHistory("Vehicle In Transit Transfer Receiving", branchEntity.GetAttributeValue <string>("accountnumber"), branchEntity.GetAttributeValue <string>("name"),
                                                                        vehicleTransferReceiving.GetAttributeValue <string>("gsc_vehicleintransittransferreceivingpn"), DateTime.UtcNow, 1, 1, viaProdQuantity.GetAttributeValue <Int32>("gsc_onhand"), destinationSite,
                                                                        viaSiteId, viaSiteId, inventory, viaProdQuantity, true, false);
                                _tracingService.Trace("Created inventory history log...");

                                //Update Product Quantity of Destination Site
                                inventoryHandler.UpdateProductQuantityDirectly(destinationQuantityEntity, 1, 1, 1, 0, 0, 0, 0, 0);//Included value in allocated for recount
                                _tracingService.Trace("Updated Destination Site Product Quantity...");
                                inventoryHandler.CreateInventoryHistory("Vehicle In Transit Transfer Receiving", branchEntity.GetAttributeValue <string>("accountnumber"), branchEntity.GetAttributeValue <string>("name"),
                                                                        vehicleTransferReceiving.GetAttributeValue <string>("gsc_vehicleintransittransferreceivingpn"), DateTime.UtcNow, 1, 1, destinationQuantityEntity.GetAttributeValue <Int32>("gsc_onhand"), destinationSite,
                                                                        viaSiteId, destinationSite, inventory, destinationQuantityEntity, true, true);
                                _tracingService.Trace("Created inventory history log...");

                                //Update Vehicle In-Transit Transfer. Status = Received
                                vehicleInTransit["gsc_intransittransferstatus"] = new OptionSetValue(100000002);
                                _organizationService.Update(vehicleInTransit);
                                _tracingService.Trace("Updated Vehicle In-Transit Transfer...");
                                #endregion
                            }
                            else
                            {
                                throw new InvalidPluginExecutionException("No Via Site Found...");
                            }
                        }
                        else
                        {
                            throw new InvalidPluginExecutionException("No Inventory Record Found...");
                        }
                    }
                }
                else
                {
                    throw new InvalidPluginExecutionException("No Receiving Details Found...");
                }
            }
            _tracingService.Trace("Ending ReceiveTransfer Method...");
        }