//Created By: Jerome Anthony Gerero, Created On: 2/15/2017 /*Purpose: Delete selected allocated vehicle * Registration Details: * Event/Message: * Post/Update: gsc_allocateditemstodelete * Primary Entity: Vehicle Transfer */ public Entity DeleteAllocatedVehicle(Entity vehicleTransferEntity) { _tracingService.Trace("Started DeleteAllocatedVehicle method..."); Guid vehicleTransferDetailId = vehicleTransferEntity.Contains("gsc_allocateditemstodelete") ? new Guid(vehicleTransferEntity.GetAttributeValue <String>("gsc_allocateditemstodelete")) : Guid.Empty; if (vehicleTransferDetailId == Guid.Empty) { return(null); } //Retrieve allocated vehicle record EntityCollection vehicleTransferDetailRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicletransferdetails", "gsc_iv_vehicletransferdetailsid", vehicleTransferDetailId, _organizationService, null, OrderType.Ascending, new[] { "gsc_inventoryid" }); if (vehicleTransferDetailRecords != null && vehicleTransferDetailRecords.Entities.Count > 0) { Entity vehicleTransferDetail = vehicleTransferDetailRecords.Entities[0]; Guid inventoryId = vehicleTransferDetail.Contains("gsc_inventoryid") ? vehicleTransferDetail.GetAttributeValue <EntityReference>("gsc_inventoryid").Id : Guid.Empty; //Retrieve inventory record EntityCollection inventoryRecords = 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" }); if (inventoryRecords != null && inventoryRecords.Entities.Count > 0) { Entity inventory = inventoryRecords.Entities[0]; inventory["gsc_status"] = new OptionSetValue(100000000); _organizationService.Update(inventory); InventoryMovementHandler inventoryMovementHandler = new InventoryMovementHandler(_organizationService, _tracingService); Entity productQuantity = inventoryMovementHandler.UpdateProductQuantity(inventory, 0, 1, -1, 0, 0, 0, 0, 0); inventoryMovementHandler.CreateInventoryQuantityAllocated(vehicleTransferEntity, inventory, productQuantity, vehicleTransferEntity.GetAttributeValue <string>("gsc_vehicletransferpn"), DateTime.UtcNow, "Cancelled", vehicleTransferEntity.GetAttributeValue <EntityReference>("gsc_siteid").Id, 100000003); } _organizationService.Delete("gsc_iv_vehicletransferdetails", vehicleTransferDetail.Id); } vehicleTransferEntity["gsc_allocateditemstodelete"] = null; _organizationService.Update(vehicleTransferEntity); _tracingService.Trace("Ended DeleteAllocatedVehicle method..."); return(vehicleTransferEntity); }
//Handles logic for removing vehicle adjustment details private Entity UnallocateVehicleAdjustment(Entity adjustedVehcileDetailsEntity, Entity vehicleAdjustmentEntity, string caller) { var inventoryId = adjustedVehcileDetailsEntity.Contains("gsc_inventoryid") ? adjustedVehcileDetailsEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id : Guid.Empty; if (inventoryId != Guid.Empty) { var quantity = adjustedVehcileDetailsEntity.Contains("gsc_quantity") ? adjustedVehcileDetailsEntity.GetAttributeValue <Int32>("gsc_quantity") : 0; EntityCollection inventoryCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService, null, OrderType.Ascending, new[] { "gsc_status", "gsc_productquantityid", "gsc_basemodelid", "gsc_productid", "gsc_modelcode", "gsc_optioncode", "gsc_modelyear", "gsc_siteid", "gsc_vin", "gsc_csno", "gsc_productionno", "gsc_engineno", }); _tracingService.Trace("Inventory records retrieved: " + inventoryCollection.Entities.Count); if (inventoryCollection.Entities.Count > 0) { _organizationService.Delete(adjustedVehcileDetailsEntity.LogicalName, adjustedVehcileDetailsEntity.Id); _tracingService.Trace("Deleted inventory record..."); //negative adjustment logic if (quantity < 0) { Entity inventoryEntity = inventoryCollection.Entities[0]; InventoryMovementHandler inventoryMovementHandler = new InventoryMovementHandler(_organizationService, _tracingService); inventoryMovementHandler.UpdateInventoryStatus(inventoryEntity, 100000000); Entity productQuantityEntity = inventoryMovementHandler.UpdateProductQuantity(inventoryEntity, 0, 1, -1, 0, 0, 0, 0, 0); #region Inventory History Log Creation InventoryMovementHandler inventoryMovement = new InventoryMovementHandler(_organizationService, _tracingService); if (caller == "Cancel") { inventoryMovement.CreateInventoryQuantityAllocated(vehicleAdjustmentEntity, inventoryEntity, productQuantityEntity, vehicleAdjustmentEntity.GetAttributeValue <string>("gsc_vehicleadjustmentvarianceentrypn"), DateTime.UtcNow, "Cancel", Guid.Empty, 100000004); } else { inventoryMovement.CreateInventoryQuantityAllocated(vehicleAdjustmentEntity, inventoryEntity, productQuantityEntity, vehicleAdjustmentEntity.GetAttributeValue <string>("gsc_vehicleadjustmentvarianceentrypn"), DateTime.UtcNow, "Open", Guid.Empty, 100000003); } #endregion } } } else { _organizationService.Delete(adjustedVehcileDetailsEntity.LogicalName, adjustedVehcileDetailsEntity.Id); } return(adjustedVehcileDetailsEntity); }
//Created By: Leslie G. Baliguat, Created On: 02/02/17 //Increase in on-hand and available in In-transit Site Upon creation public void AddOnHandAvailable(Entity vehicleReceivingItem) { var inventoryId = vehicleReceivingItem.GetAttributeValue <EntityReference>("gsc_inventoryid") != null ? vehicleReceivingItem.GetAttributeValue <EntityReference>("gsc_inventoryid").Id : Guid.Empty; EntityCollection inventoryRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_inventory", "gsc_iv_inventoryid", inventoryId, _organizationService, null, OrderType.Ascending, new[] { "gsc_inventorypn" }); if (inventoryRecords != null && inventoryRecords.Entities.Count > 0) { Entity inventory = inventoryRecords.Entities[0]; InventoryMovementHandler handler = new InventoryMovementHandler(_organizationService, _tracingService); handler.UpdateProductQuantity(inventory, 1, 1, 0, 0, 0, 0, 0, 0); } }
//Created By: Leslie Baliguat, Created On: 5/18/2016 /*Purpose: Update Order Status, Vehcicle Allocated Date and Inventory Id to Allocate fields of Sales Order to where Allocated vehicle is associated * Update Inventory Status of Inventory Record that is related to Allocated Vehicle * Update Available and Allocated fields of Product Quantity to where Inventory is associated * Registration Details: * Event/Message: * PreValidate/Delete: * Primary Entity: Allocated Vehicle */ public void RemoveAllocation(Entity allocatedEntity) { _tracingService.Trace("Started RemoveAllocation Method"); Entity salesOrderToUpdate = new Entity("salesorder"); if (allocatedEntity.GetAttributeValue <EntityReference>("gsc_orderid") != null) { _tracingService.Trace("Order Id not null"); var orderId = allocatedEntity.GetAttributeValue <EntityReference>("gsc_orderid").Id; EntityCollection orderRecords = CommonHandler.RetrieveRecordsByOneValue("salesorder", "salesorderid", orderId, _organizationService, null, OrderType.Ascending, new[] { "gsc_status", "gsc_vehicleallocateddate", "gsc_inventoryidtoallocate", "name" }); if (orderRecords != null && orderRecords.Entities.Count > 0) { _tracingService.Trace("Retrieved Related Order Details "); salesOrderToUpdate = orderRecords.Entities[0]; var status = salesOrderToUpdate.Contains("gsc_status") ? salesOrderToUpdate.GetAttributeValue <OptionSetValue>("gsc_status") : null; if (status.Value == 100000003) { salesOrderToUpdate["gsc_status"] = new OptionSetValue(100000002); salesOrderToUpdate["gsc_vehicleallocateddate"] = (DateTime?)null; salesOrderToUpdate["gsc_inventoryidtoallocate"] = null; _organizationService.Update(salesOrderToUpdate); } _tracingService.Trace("Related Order Updated"); } } /*************************************************************/ //Modified By: Raphael Herrera, Modified On: 8/14/2016 //Included cleanup for VehicleTransfer entity if (allocatedEntity.GetAttributeValue <EntityReference>("gsc_vehicletransferid") != null) { _tracingService.Trace("VehicleTransfer is not null"); var vehicleTransferId = allocatedEntity.GetAttributeValue <EntityReference>("gsc_vehicletransferid").Id; EntityCollection vehicleTransferCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicletransfer", "gsc_iv_vehicletransferid", vehicleTransferId, _organizationService, null, OrderType.Ascending, new[] { "gsc_inventoryidtoallocate" }); _tracingService.Trace("Vehicle Transfer records retrieved: " + vehicleTransferCollection.Entities.Count); if (vehicleTransferCollection != null && vehicleTransferCollection.Entities.Count > 0) { Entity vehicleTransferEntity = vehicleTransferCollection.Entities[0]; vehicleTransferEntity["gsc_inventoryidtoallocate"] = null; _organizationService.Update(vehicleTransferEntity); _tracingService.Trace("Vehicle Transfer Record Updated"); } } /*************************************************************/ /*************************************************************/ //Modified By: Raphael Herrera, Modified On: 8/25/2016 //Included cleanup for Vehicle In-Transit Transfer Entity if (allocatedEntity.GetAttributeValue <EntityReference>("gsc_vehicleintransittransferid") != null) { _tracingService.Trace("Vehicle In-Transit Transfer is not null"); var vehicleInTransitId = allocatedEntity.GetAttributeValue <EntityReference>("gsc_vehicleintransittransferid").Id; EntityCollection vehicleInTransitCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_iv_vehicleintransittransfer", "gsc_iv_vehicleintransittransferid", vehicleInTransitId, _organizationService, null, OrderType.Ascending, new[] { "gsc_inventoryidtoallocate", "gsc_intransittransferstatus" }); _tracingService.Trace("Vehicle In-Transit Transfer records retrieved: " + vehicleInTransitCollection.Entities.Count); if (vehicleInTransitCollection != null && vehicleInTransitCollection.Entities.Count > 0) { Entity vehicleInTransit = vehicleInTransitCollection.Entities[0]; //In-Transit Transfer Status != Picked if (vehicleInTransit.GetAttributeValue <OptionSetValue>("gsc_intransittransferstatus").Value != 100000000) { throw new InvalidPluginExecutionException("Unable to delete record that is already shipped."); } vehicleInTransit["gsc_inventoryidtoallocate"] = null; _organizationService.Update(vehicleInTransit); _tracingService.Trace("Vehicle Transfer Record Updated"); } } /*************************************************************/ if (allocatedEntity.GetAttributeValue <EntityReference>("gsc_inventoryid") != null) { _tracingService.Trace("Inventory Id not null"); var inventoryId = allocatedEntity.GetAttributeValue <EntityReference>("gsc_inventoryid").Id; EntityCollection inventoryRecords = 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" }); if (inventoryRecords != null && inventoryRecords.Entities.Count > 0) { _tracingService.Trace("Retrieved Related Inventory Details"); InventoryMovementHandler inventoryMovementHandler = new InventoryMovementHandler(_organizationService, _tracingService); inventoryMovementHandler.UpdateInventoryStatus(inventoryRecords.Entities[0], 100000000); Entity productQuantityEntity = inventoryMovementHandler.UpdateProductQuantity(inventoryRecords.Entities[0], 0, 1, -1, 0, 0, 0, 0, 0); // Create Inventory History Log inventoryMovementHandler.CreateInventoryQuantityAllocated(salesOrderToUpdate, inventoryRecords.Entities[0], productQuantityEntity, salesOrderToUpdate.GetAttributeValue <string>("name"), DateTime.UtcNow, "For Allocation", Guid.Empty, 100000003); } } _tracingService.Trace("Ended RemoveAllocation Method."); }