Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- * Controller for the AcceptInventoryTransferComponent lightning component
- *
- * @author Magnet 360
- * @date 08/10/2018
- *
- * @Sanaka : 12/19/2019 : SF1-8182 - Updated isExpired Flag to use "Use_by_Date_Status__c" instead of "Return_Status_Text__c"
- * @Sachin : 02/05/20 :SF1-8337 - Prevent Transfer of Inventory during an Active Cycle Count.
- */
- public without sharing class AcceptInventoryTransferController {
- private static Boolean isCurrentUserASalesRep
- {
- get
- {
- if( isCurrentUserASalesRep == null )
- {
- isCurrentUserASalesRep = false;
- User l_current_user = [ SELECT Business_Partner__c FROM User WHERE Id = :UserInfo.getUserId() LIMIT 1 ];
- if( l_current_user.Business_Partner__c != null )
- {
- isCurrentUserASalesRep = true;
- }
- }
- return isCurrentUserASalesRep;
- }
- set;
- }
- public class product {
- @AuraEnabled public String name{get;set;}
- @AuraEnabled public String lineone {get;set;}
- @AuraEnabled public String linetwo {get;set;}
- @AuraEnabled public Inventory__c inv {get;set;}
- @AuraEnabled public Contact loc {get;set;}
- @AuraEnabled public Contact dest {get;set;}
- @AuraEnabled public String transItemId {get;set;}
- @AuraEnabled public String acceptreject {get;set;}
- @AuraEnabled public String rejectreason {get;set;}
- @AuraEnabled public String originsalesrep {get;set;}
- @AuraEnabled public Integer transactionQuantity {get;set;}
- // Flag used to determine if scanned product is valid based on the "loc" contact and the current user.
- // If the current user is a sales rep and the "loc" Contact is not them, this is not a valid product to include
- // in the inventory transfers
- @AuraEnabled public Boolean isValidSource
- {
- get
- {
- Boolean isValidSource = true;
- if( isCurrentUserASalesRep && inv.Is_this_my_Inventory__c == 'No' ) {
- isValidSource = false;
- }
- return isValidSource;
- }
- set;
- }
- // Flag used to determine if the scanned inventory record has a Quality Notification on it
- @AuraEnabled public Boolean isQualityFlagged
- {
- get
- {
- Boolean isQualityFlagged = false;
- if( inv.QN_Flg__c == true ) {
- isQualityFlagged = true;
- }
- return isQualityFlagged;
- }
- set;
- }
- // Flag used to determine if the scanned inventory record is already expired
- @AuraEnabled public Boolean isExpired
- {
- get
- {
- Boolean isExpired = false;
- System.debug('Use_by_Date_Status__c: ' + inv.Use_by_Date_Status__c);
- if( inv.Use_by_Date_Status__c == 'Not OK' ) {
- isExpired = true;
- }
- return isExpired;
- }
- set;
- }
- // Flag used to determine if the scanned inventory record should be automatically rejected
- // based on if it has QN Flag or Is Expire
- @AuraEnabled public Boolean autoReject
- {
- get
- {
- Boolean autoReject = false;
- if( isQualityFlagged || isExpired ) {
- autoReject = true;
- }
- return autoReject;
- }
- set;
- }
- // Flag to determine if the AC Log is empty.
- // If this is empty, then the item is in the users Consignment Log
- @AuraEnabled public Boolean consignmentPending
- {
- get
- {
- Boolean consignmentPending = false;
- List<Accept_Consignment_Log__c> acLog = new List<Accept_Consignment_Log__c>();
- list<String> serialNumber = new List<String>();
- serialNumber.add(inv.Serial_Number__c);
- acLog = QueryWithoutSharingExecutor.getAcceptConsignmentLogBySerialNumber(serialNumber);
- if (acLog.isEmpty()) {
- consignmentPending = true;
- }
- return consignmentPending;
- }
- set;
- }
- }
- public class ShippingInfo {
- @AuraEnabled public String contactAddressId {get;set;}
- @AuraEnabled public String shippingPriority {get;set;}
- @AuraEnabled public String shippingTrackingNumber {get;set;}
- }
- public class productResponse {
- @AuraEnabled public List<product> successProducts{get;set;}
- @AuraEnabled public List<product> errorProducts{get;set;}
- @AuraEnabled public String errorMessage{get;set;}
- }
- @AuraEnabled
- public static String completeTransfer(String recordId) {
- String retMessage = '';
- boolean updateTransaction = false;
- Boolean sendRejectNotificationEmail = false;
- String profileName;
- try {
- profileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() Limit 1].Name;
- } catch (Exception x) {
- profileName = '';
- }
- OrgWideEmailAddress l_org_wide_email_address = [ SELECT Id FROM OrgWideEmailAddress WHERE DisplayName = 'Salesforce Administrator' LIMIT 1 ];
- // CRM Users query Neuro Constants Mappings for CRM_Email_Address else use the Sales_Ops_Email_Address
- String soqlEmailDeveloperName = Constants.PROFILE.isCRMSalesusersProfile( profileName ) ? 'CRM_Email_Address' : 'Sales_Ops_Email_Address';
- String l_sales_order_email = [SELECT SAP_Values__c FROM Neuro_Constants_Mappings__mdt WHERE DeveloperName = :soqlEmailDeveloperName LIMIT 1].SAP_Values__c; // SalesOps_Neuro@abbott.com
- List<Transaction_Items__c> titems = [SELECT Item_Accepted_or_Rejected__c, Transaction_ID__r.Origin_Sales_Rep__r.Business_Partner__c, Inventory__c FROM Transaction_Items__c WHERE Transaction_ID__c = :recordId];
- Set<String> businessPartners = new Set<String>();
- Set<Id> inventoryIds = new Set<Id>();
- system.debug('=titems'+titems);
- for (Transaction_Items__c item : titems) {
- businessPartners.add(item.Transaction_ID__r.Origin_Sales_Rep__r.Business_Partner__c);
- inventoryIds.add(item.Inventory__c );
- }
- List<String> userAvailableRecordTypes = getCycleCountRequestRecordTypes();
- List<Cycle_Count_Request_Line_Item__c> requestItems = new List<Cycle_Count_Request_Line_Item__c>();
- requestItems = [Select Id,CycleCountRequestUserID__r.Name from Cycle_Count_Request_Line_Item__c where CycleCountRequestUserID__r.User__r.Business_Partner__c IN:businessPartners
- and CycleCountRequestUserID__r.Status__c = 'In Progress' and Inventory__c IN:inventoryIds];
- if(requestItems.size() > 0 && userAvailableRecordTypes.size() > 0 && NeuroConstants.RECORDTYPE.isCycleCountRecordType(userAvailableRecordTypes[0])){
- updateTransaction = false;
- retMessage = 'Cycle Count is in progress. Please complete count prior to transferring inventory.';
- }
- else{
- for (Transaction_Items__c item : titems) {
- if (item.Item_Accepted_or_Rejected__c == 'Accept' || item.Item_Accepted_or_Rejected__c == 'Reject') {
- updateTransaction = true;
- if( item.Item_Accepted_or_Rejected__c == 'Reject' ) {
- sendRejectNotificationEmail = true;
- }
- } else {
- updateTransaction = false;
- retMessage = 'You must mark all items as either Accepted or Rejected before completing the transfer request.';
- break;
- }
- }
- }
- if (updateTransaction) {
- try {
- Transactions__c trans = [ SELECT Id, Name, Status__c, Submit__c,Sales_Rep__r.Full_Name__c,Origin_Sales_Rep__r.Full_Name__c, Origin_Sales_Rep__r.Email FROM Transactions__c WHERE Id = :recordId ];
- trans.Status__c = 'COMPLETE';
- trans.Submit__c = true;
- update trans;
- // Make sure the Origin Sales rep has their email address populated before sending the email. This allows the transaction to process if there is no email address present.
- if( sendRejectNotificationEmail && trans.Origin_Sales_Rep__r.Email != null ) {
- Messaging.SingleEmailMessage l_email = new Messaging.SingleEmailMessage();
- l_email.setOrgWideEmailAddressId( l_org_wide_email_address.id );
- l_email.setToAddresses( new String[]{
- trans.Origin_Sales_Rep__c
- } );
- l_email.setSubject('Inventory Transfer Rejected');
- l_email.setHtmlBody( trans.Origin_Sales_Rep__r.Full_Name__c+',<br/><br/>'+'Your inventory transfer ' + trans.Name + ' has items that have been rejected by '+trans.Sales_Rep__r.Full_Name__c+'. Please follow up. <br/><br/>' +
- '<a href='+System.Url.getSalesforceBaseUrl().toExternalForm()+'/'+trans.Id+'>' +trans.Name+
- '</a>');
- Messaging.sendEmail( new List<Messaging.SingleEmailMessage>{
- l_email
- } );
- }
- retMessage = 'Your inventory transfer request has been successfully submitted.';
- } catch( Exception l_ex ) {
- if ( Constants.PROFILE.isCRMSalesusersProfile( profileName ) ) {
- retMessage = 'An error occurred while processing your inventory transfer request. Please contact ' + l_sales_order_email;
- } else {
- retMessage = 'The following error occurred while processing your inventory transfer request: ' + l_ex.getMessage() + '\n\nPlease contact sales ops at ' + l_sales_order_email;
- }
- }
- return retMessage;
- }else {
- return retMessage;
- }
- }
- @AuraEnabled
- public static List<product> getTransactionItems(String recordId) {
- List<AcceptInventoryTransferController.product> products = new List<AcceptInventoryTransferController.product>();
- List<Transaction_Items__c> transactionItems = [SELECT Id, Name, Reason_For_Rejection__c, Item_Accepted_or_Rejected__c,
- Transaction_Id__r.Origin_Sales_Rep__r.Name, Quantity__c,
- Inventory__r.Name, Inventory__r.Is_this_my_Inventory__c,
- Inventory__r.Model_Number__c, Inventory__r.Serial_Number__c, Inventory__r.Quantity__c,
- Inventory__r.QN_Flg__c, Inventory__r.Use_by_Date_Status__c, Inventory__r.Return_Status_Text__c
- FROM Transaction_Items__c WHERE Transaction_ID__c = :recordId];
- for ( Transaction_Items__c item : transactionItems ) {
- AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
- p.name = item.Name;
- p.inv = item.Inventory__r;
- p.transItemId = item.Id;
- p.acceptreject = item.Item_Accepted_or_Rejected__c;
- p.rejectreason = item.Reason_For_Rejection__c;
- p.originsalesrep = item.Transaction_Id__r.Origin_Sales_Rep__r.Name;
- p.transactionQuantity = Integer.valueOf( item.Quantity__c );
- products.add(p);
- }
- System.debug('Transation Items: ' + products);
- return products;
- }
- @AuraEnabled
- public static List<ListOption> getPicklistValuesForRejectReason() {
- List<ListOption> options = new List<ListOption>();
- List<Schema.PicklistEntry> ple = Transaction_Items__c.Reason_For_Rejection__c.getDescribe().getPicklistValues();
- for (Schema.PicklistEntry f : ple) {
- ListOption option = new ListOption();
- option.label = f.getLabel();
- option.value = f.getLabel();
- options.add(option);
- }
- return options;
- }
- @AuraEnabled
- public static void saveTransactionItem(Transaction_Items__c transactionItem) {
- System.debug('Save Transaction Item: ' + transactionItem);
- try {
- update transactionItem;
- } catch (exception e) {
- System.debug('ERROR Saving Transaction Item msg: ' + e);
- }
- }
- @AuraEnabled
- public static List<product> addItem(Inventory__c inv, Contact location, Contact destination) {
- List<product> ret_val = new List<product>();
- List<Transaction_Items__c> inventoryItems = new List<Transaction_Items__c>();
- List<String> userAvailableRecordTypes = getCycleCountRequestRecordTypes();
- List<Cycle_Count_Request_Line_Item__c> requestLineItems = new List<Cycle_Count_Request_Line_Item__c>();
- User userInfo = [Select Id,Profile.Name from User where Id=: UserInfo.getUserId() limit 1];
- inventoryItems= [Select Id,Status__c,Transaction_ID__c,Transaction_ID__r.Status__c,Transaction_ID__r.Name from Transaction_Items__c where Inventory__c = :inv.Id and Inventory__r.Serialized__C = true and Transaction_ID__r.Origin_Sales_Rep__c = :location.Id and Transaction_ID__r.Sales_Rep__c = :destination.Id and Transaction_ID__r.Status__c = 'Pending Acceptance'];
- system.debug('=== inventoryItems'+inventoryItems);
- requestLineItems = [Select Id,Inventory__c,CycleCountRequestUserID__r.Status__c,CycleCountRequestUserID__r.User__c from Cycle_Count_Request_Line_Item__c where CycleCountRequestUserID__r.User__c = :userInfo.Id and CycleCountRequestUserID__r.Status__c = 'In Progress' and Inventory__c = :inv.Id];
- system.debug('@@@ requestLineItems '+requestLineItems);
- if(requestLineItems.size() > 0 && userAvailableRecordTypes.size() > 0 && NeuroConstants.RECORDTYPE.isCycleCountRecordType(userAvailableRecordTypes[0])){
- AcceptInventoryTransferController.product pWithTransfer = new AcceptInventoryTransferController.product();
- pWithTransfer.transItemId = String.valueOf(requestLineItems[0].Inventory__c);
- pWithTransfer.Name = 'true';
- pWithTransfer.inv = inv;
- pWithTransfer.loc = location;
- ret_val.add(pWithTransfer);
- return ret_val;
- }
- else if(inventoryItems.size() >0 ){
- AcceptInventoryTransferController.product pWithTransfer = new AcceptInventoryTransferController.product();
- pWithTransfer.transItemId = String.valueOf(inventoryItems[0].Transaction_ID__r.Name);
- pWithTransfer.Name = inv.Name;
- pWithTransfer.inv = inv;
- pWithTransfer.loc = location;
- ret_val.add(pWithTransfer);
- return ret_val;
- }else{
- AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
- p.name = inv.Name;
- p.lineone = inv.Name;
- p.linetwo = inv.Model_Description__c;
- p.inv = inv;
- p.loc = location;
- p.dest = destination;
- p.transactionQuantity = 1; // Default to 1, since the form quantity field defaults to 1
- ret_val.add(p);
- return ret_val;
- }
- }
- @AuraEnabled
- public static productResponse getProductsFromInventories(List<Inventory__c> invs, Contact location, Contact destination) {
- List<product> ret_prods = new List<product>();
- List<product> err_prods = new List<product>();
- String l_error_message;
- String l_model_list = '';
- for(Inventory__c inv: invs) {
- AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
- p.name = inv.Name;
- p.lineone = inv.Model_Number__c;
- p.linetwo = inv.Model_Description__c;
- p.inv = inv;
- p.loc = location;
- p.dest = destination;
- if(inv.Sales_Rep__c != location.Id) {
- err_prods.add(p);
- } else {
- ret_prods.add(p);
- }
- }
- AcceptInventoryTransferController.productResponse pResponse = new AcceptInventoryTransferController.productResponse();
- pResponse.errorProducts = err_prods;
- pResponse.successProducts = ret_prods;
- if( err_prods.size() > 0 )
- {
- for( product l_p : err_prods )
- {
- if( l_model_list != '' )
- {
- l_model_list += ', ';
- }
- l_model_list += l_p.lineone;
- }
- try
- {
- l_error_message = [ SELECT Message__c
- FROM Neuro_Message__mdt
- WHERE DeveloperName = 'Inventory_Transfer_Product_Warning'
- LIMIT 1 ].Message__c;
- }
- catch( Exception l_any )
- {
- l_error_message = 'The following inventory will not be transferred because it does not exist under {0}: {1}';
- }
- pResponse.errorMessage = l_error_message.replace( '{0}', location.Name == null?'':location.Name ).replace( '{1}', l_model_list == null?'':l_model_list );
- }
- return pResponse;
- }
- @AuraEnabled
- public static Contact getOriginalLocationNameForInventory(Inventory__c Inventory) {
- Contact inv_contact;
- try {
- inv_contact = [SELECT id, Name, Sales_Rep_User__c, Sales_Rep_User__r.ProfileId FROM Contact where Id =: Inventory.Sales_Rep__c LIMIT 1];
- } catch(Exception e) {
- debug('EXCEPTION OCCURED: ' + e.getMessage());
- }
- return inv_contact;
- }
- @AuraEnabled
- public static List<Inventory__c> getmockbarcodes() {
- List<Inventory__c> inventories = new List<Inventory__c>();
- // Quantity__c -- max value
- inventories = [SELECT Name, Model_Number__c, Sales_Rep__c, Serial_Number__c, Serialized__c, Quantity__c FROM Inventory__c LIMIT 44 ];
- return inventories;
- }
- @AuraEnabled
- public static List<Contact> getLocationNamesFromInventories(List<Inventory__c> inventories) {
- Set<Id> sales_reps = new Set<Id>();
- for(Inventory__c ivn : inventories) {
- sales_reps.add(ivn.Sales_Rep__c);
- }
- List<Contact> sreps;
- if(sales_reps.size() > 0) {
- sreps = [SELECT id, name from Contact where id IN : sales_reps];
- } else {
- sreps = null;
- }
- return sreps;
- }
- @AuraEnabled
- public static List<Contact> getDestinationLocationNames() {
- List<Contact> destLocationNames = [SELECT id, Name, Sales_Rep_User__c, Business_Partner__c
- FROM Contact
- WHERE Business_Partner__c != NULL
- AND Sales_Rep_User__c != NULL];
- return destLocationNames;
- }
- @AuraEnabled
- public static Map<Id, Contact> getContacts(List<Id> conids) {
- List<Contact> cons = [select id, name from Contact WHERE Id IN : conids];
- Map<Id, Contact> id_to_con = new Map<Id, Contact>();
- for(Contact c : cons) {
- id_to_con.put(c.Id, c);
- }
- return id_to_con;
- }
- @AuraEnabled
- public static Contact getSJMEmployee() {
- Contact ret_con;
- List<Contact> contacts = [SELECT ID, NAME, Sales_Rep_User__c, Business_Partner__c, Sales_Rep_User__r.ProfileId
- FROM contact
- WHERE Sales_Rep_User__c =: Userinfo.getuserid()
- AND Business_Partner__c != NULL];
- if(contacts.size() > 0) {
- ret_con = contacts[0];
- }else {
- ret_con = null;
- }
- return ret_con;
- }
- @AuraEnabled
- public static void submitInventoryTransfer(String objectList, String shippingInfoJSON) {
- System.debug('SUBMIT INVENTORY TRANSFER:::::: ' + objectList);
- objectList = objectList.remove('T00:00:00.000Z');
- System.debug('Param: ShippingInfo = ' + shippingInfoJSON );
- ShippingInfo shippingInfo;
- if( shippingInfoJSON != null )
- {
- shippingInfo = (AcceptInventoryTransferController.ShippingInfo) JSON.deserialize( shippingInfoJSON, AcceptInventoryTransferController.ShippingInfo.class );
- }
- List<Object> json_to_objectList = (List<Object>)Json.deserializeUntyped(objectList);
- List<product> productsList = new List<product>();
- for(Object s : json_to_objectList){
- String test = JSON.serialize(s);
- AcceptInventoryTransferController.product new_product_object = (AcceptInventoryTransferController.product)JSON.deserialize(test, AcceptInventoryTransferController.product.class);
- debug('this is obj : ' + new_product_object);
- productsList.add(new_product_object);
- }
- //determine which profile is using accept inv. then split based on record type.
- Id currentUserId = UserInfo.getUserId();
- String profId;
- String profName;
- Id transaction_recordType_id;
- Id transaction_item_recordType_id;
- List<User> profIdList= [SELECT profileId FROM User WHERE Id=:currentUserId LIMIT 1];
- for(User u: profIdList){
- profId = u.ProfileId;
- //system.debug('this is the profile id '+profId);
- }
- List<Profile> profNameList = [SELECT Name FROM Profile WHERE Id =:profId LIMIT 1];
- for(Profile p: profNameList){
- profName=p.Name;
- //system.debug('This is the profile name: '+profName);
- }
- if( Constants.PROFILE.isNeuroSalesusersProfile( profName ) ) {
- transaction_recordType_id = Schema.SObjectType.Transactions__c.getRecordTypeInfosByName().get('Neuro Inventory Transfer').getRecordTypeId();
- transaction_item_recordType_id = Schema.SObjectType.Transaction_Items__c.getRecordTypeInfosByName().get('Neuro Inventory Transfer Item').getRecordTypeId();
- }
- if( Constants.PROFILE.isCRMSalesusersProfile( profName ) ) {
- transaction_recordType_id = Schema.SObjectType.Transactions__c.getRecordTypeInfosByName().get('CRM Inventory Transfer').getRecordTypeId();
- // system.debug('the transaction record type id is: '+transaction_recordtype_id);
- transaction_item_recordType_id = Schema.SObjectType.Transaction_Items__c.getRecordTypeInfosByName().get('CRM Inventory Transfer Item').getRecordTypeId();
- //system.debug('the transaction item record type id is: '+transaction_item_recordtype_id);
- }
- Transactions__c create_transaction = new Transactions__c();
- create_transaction.recordTypeId = transaction_recordType_id;
- create_transaction.Origin_Sales_Rep__c = productsList[0].loc.Id; // Lookup contact (Original Location )
- create_transaction.Sales_Rep__c = productsList[0].dest.Id; // Lookup contact (Destination location)
- if( shippingInfo != null ) {
- create_transaction.Sales_Rep_Address__c = String.isNotEmpty(shippingInfo.contactAddressId) ? shippingInfo.contactAddressId : null;
- //system.debug('sales rep address issue?: '+create_transaction.Sales_Rep_Address__c);
- create_transaction.Shipping_Priority__c = shippingInfo.shippingPriority;
- create_transaction.Shipping_Tracking_Number__c = shippingInfo.shippingTrackingNumber;
- }
- // create_transaction.Status__c = 'Send';
- create_transaction.Submit__c = false;
- Savepoint sp = Database.setSavepoint();
- try {
- try {
- insert create_transaction;
- } catch(Exception e) {
- debug('Exception occured: ' + e.getMessage());
- throw e;
- }
- List<Transaction_Items__c> t_line_items = new List<Transaction_Items__c>();
- for(product p : productsList) {
- Transaction_Items__c t_item = new Transaction_Items__c();
- t_item.RecordTypeId = transaction_item_recordType_id;
- t_item.Inventory__c = p.inv.Id;
- // t_item.Quantity__c = p.inv.Quantity__c;
- t_item.Quantity__c = p.transactionQuantity;
- if( t_item.Quantity__c == null )
- {
- t_item.Quantity__c = 1;
- }
- t_item.Transaction_ID__c = create_transaction.Id;
- t_line_items.add(t_item);
- }
- try{
- insert t_line_items;
- } catch(Exception e) {
- debug('Exception occured: ' + e.getMessage());
- throw e;
- }
- Transactions__c update_transaction_send = [SELECT id, Status__c, Sales_Rep__r.Sales_Rep_User__c FROM Transactions__c WHERE ID =: create_transaction.Id ];
- // if the receiving user is NOT the same as the current current, set Status = "Pending Acceptance" and do not submit
- // the transactions to SAP
- if( update_transaction_send.Sales_Rep__r.Sales_Rep_User__c != UserInfo.getUserId() )
- {
- update_transaction_send.Status__c = 'Pending Acceptance';
- }
- else
- {
- update_transaction_send.Submit__c = true;
- }
- try{
- update update_transaction_send;
- } catch(Exception e) {
- debug('Updating Transactions__c Status to SEND failed. ' + e.getMessage());
- throw e;
- }
- } catch(Exception ex) {
- debug('ERROR: Exception: ' + ex.getMessage());
- Database.rollback(sp);
- }
- }
- public static void debug(object message)
- {
- System.debug('AcceptInventoryTransferController > ' + message);
- }
- @AuraEnabled
- public static
- List<Contact_Address__c>
- getContactAddresses( Id a_contact_id )
- {
- return [ SELECT Id, Name, Address__c, Address_1__c, Address_2__c
- FROM Contact_Address__c
- WHERE Contact__c = :a_contact_id
- ORDER BY Name ];
- }
- @AuraEnabled
- public static
- List<String>
- getShippingPriorityOptions()
- {
- List<String> l_opts = new List<String>{'Hand Delivered'};
- l_opts.addAll( InventoryRequestShippingController.getShippingPriorityPicklist( new Transactions__c(), 'Shipping_Priority__c') );
- return l_opts;
- }
- public static List<String> getCycleCountRequestRecordTypes(){
- List<String> recordTypeNameList = new List<String>();
- List<RecordTypeInfo> rtinfo = Cycle_Count_Request__c.SObjectType.getDescribe().getRecordTypeInfos();
- system.debug('@@@ rtinfo '+ rtinfo);
- if (rtinfo.size() > 1) {
- for(RecordTypeInfo i : rtinfo) {
- if (i.isAvailable() && i.Name != 'Master')
- recordTypeNameList.add(i.getName());
- }
- }
- else recordTypeNameList.add(rtinfo[0].getName());
- return recordTypeNameList;
- }
- @AuraEnabled
- public static Boolean getIsCRMUser() {
- Profile user_profile = [SELECT Id, Name FROM Profile WHERE Id =: UserInfo.getProfileId() LIMIT 1];
- return Constants.PROFILE.isCRMSalesusersProfile(user_profile.Name);
- }
- public class InventoryErrors {
- @AuraEnabled public Inventory__c inventory {get;set;}
- @AuraEnabled public Boolean isError {get;set;}
- @AuraEnabled public String message {get;set;}
- }
- @AuraEnabled
- public static InventoryErrors
- parseDesktopScan(String barcodeString, String destinationName, Boolean sentByMe) {
- /*
- SF1-7378
- Upon scanning a product add the product onto the Send Inventory Transfer only if:
- *the product is within the Original Location Name’s inventory
- * and the product does not have Expiry Notice or Quality Notice.
- */
- InventoryErrors return_InventoryErrors = new InventoryErrors();
- Barcode parsedBar = Barcode.parse(barcodeString);
- List<Inventory__c> inventory = [SELECT Id, Name, Location_Name__c, Model_Description__c, Model_Number__c, Serial_Number__c, Serialized__c, Quantity__c, Batch_Lot_Number__c, Product_Number__c, Sales_Rep__c, Is_this_my_Inventory__c, Sales_Rep__r.Name, QN_Flg__c, Return_By_Date__c, Use_by_Date_Status__c
- FROM Inventory__c
- WHERE Serial_Number__c =: parsedBar.Serial];
- if(inventory.size() > 0) {
- return_InventoryErrors.inventory = inventory[0];
- return_InventoryErrors.isError = false;
- } else {
- return_InventoryErrors.inventory = null;
- return_InventoryErrors.isError = true;
- return_InventoryErrors.message = 'The product was not found in the Original Location Name’s inventory';
- }
- if( inventory.size() > 0 ) {
- if (sentByMe == true && inventory[0].Is_this_my_Inventory__c == 'No') {
- return_InventoryErrors.isError = true;
- return_InventoryErrors.message = 'The product was not found in the Original Location Name’s inventory';
- }
- // QUALITY NOTICE
- if (inventory[0].QN_Flg__c == true) {
- return_InventoryErrors.isError = true;
- return_InventoryErrors.message = 'This product is not valid to be transferred. Please review for Expiry Notice or Quality Notice.';
- }
- // Expiry Notice.
- if (inventory[0].Use_by_Date_Status__c != 'OK') {
- return_InventoryErrors.isError = true;
- return_InventoryErrors.message = 'This product is not valid to be transferred. Please review for Expiry Notice or Quality Notice.';
- }
- }
- return return_InventoryErrors;
- }
- @AuraEnabled
- public static List<Accept_Consignment_Log__c> getAcceptConsignmentLogsBySerialNumber(String serialnumber) {
- List<String> serialnumberlist = new List<String>();
- serialnumberlist.add(serialnumber);
- return QueryWithoutSharingExecutor.getAcceptConsignmentLogBySerialNumber( serialnumberlist );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement