Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.13 KB | None | 0 0
  1. /******************************************************************************
  2. * Controller for the AcceptInventoryTransferComponent lightning component
  3. *
  4. * @author Magnet 360
  5. * @date 08/10/2018
  6. *
  7. * @Sanaka : 12/19/2019 : SF1-8182 - Updated isExpired Flag to use "Use_by_Date_Status__c" instead of "Return_Status_Text__c"
  8. * @Sachin : 02/05/20 :SF1-8337 - Prevent Transfer of Inventory during an Active Cycle Count.
  9. */
  10.  
  11. public without sharing class AcceptInventoryTransferController {
  12.  
  13. private static Boolean isCurrentUserASalesRep
  14. {
  15. get
  16. {
  17. if( isCurrentUserASalesRep == null )
  18. {
  19. isCurrentUserASalesRep = false;
  20.  
  21. User l_current_user = [ SELECT Business_Partner__c FROM User WHERE Id = :UserInfo.getUserId() LIMIT 1 ];
  22. if( l_current_user.Business_Partner__c != null )
  23. {
  24. isCurrentUserASalesRep = true;
  25. }
  26. }
  27. return isCurrentUserASalesRep;
  28. }
  29. set;
  30. }
  31.  
  32. public class product {
  33. @AuraEnabled public String name{get;set;}
  34. @AuraEnabled public String lineone {get;set;}
  35. @AuraEnabled public String linetwo {get;set;}
  36. @AuraEnabled public Inventory__c inv {get;set;}
  37. @AuraEnabled public Contact loc {get;set;}
  38. @AuraEnabled public Contact dest {get;set;}
  39. @AuraEnabled public String transItemId {get;set;}
  40. @AuraEnabled public String acceptreject {get;set;}
  41. @AuraEnabled public String rejectreason {get;set;}
  42. @AuraEnabled public String originsalesrep {get;set;}
  43. @AuraEnabled public Integer transactionQuantity {get;set;}
  44.  
  45. // Flag used to determine if scanned product is valid based on the "loc" contact and the current user.
  46. // If the current user is a sales rep and the "loc" Contact is not them, this is not a valid product to include
  47. // in the inventory transfers
  48. @AuraEnabled public Boolean isValidSource
  49. {
  50. get
  51. {
  52. Boolean isValidSource = true;
  53. if( isCurrentUserASalesRep && inv.Is_this_my_Inventory__c == 'No' ) {
  54. isValidSource = false;
  55. }
  56.  
  57. return isValidSource;
  58. }
  59. set;
  60. }
  61.  
  62.  
  63. // Flag used to determine if the scanned inventory record has a Quality Notification on it
  64. @AuraEnabled public Boolean isQualityFlagged
  65. {
  66. get
  67. {
  68. Boolean isQualityFlagged = false;
  69. if( inv.QN_Flg__c == true ) {
  70. isQualityFlagged = true;
  71. }
  72. return isQualityFlagged;
  73. }
  74. set;
  75. }
  76.  
  77. // Flag used to determine if the scanned inventory record is already expired
  78. @AuraEnabled public Boolean isExpired
  79. {
  80. get
  81. {
  82. Boolean isExpired = false;
  83.  
  84. System.debug('Use_by_Date_Status__c: ' + inv.Use_by_Date_Status__c);
  85. if( inv.Use_by_Date_Status__c == 'Not OK' ) {
  86. isExpired = true;
  87. }
  88. return isExpired;
  89. }
  90. set;
  91. }
  92.  
  93. // Flag used to determine if the scanned inventory record should be automatically rejected
  94. // based on if it has QN Flag or Is Expire
  95. @AuraEnabled public Boolean autoReject
  96. {
  97. get
  98. {
  99. Boolean autoReject = false;
  100. if( isQualityFlagged || isExpired ) {
  101. autoReject = true;
  102. }
  103. return autoReject;
  104. }
  105. set;
  106. }
  107.  
  108. // Flag to determine if the AC Log is empty.
  109. // If this is empty, then the item is in the users Consignment Log
  110. @AuraEnabled public Boolean consignmentPending
  111. {
  112. get
  113. {
  114. Boolean consignmentPending = false;
  115. List<Accept_Consignment_Log__c> acLog = new List<Accept_Consignment_Log__c>();
  116. list<String> serialNumber = new List<String>();
  117. serialNumber.add(inv.Serial_Number__c);
  118.  
  119. acLog = QueryWithoutSharingExecutor.getAcceptConsignmentLogBySerialNumber(serialNumber);
  120. if (acLog.isEmpty()) {
  121. consignmentPending = true;
  122. }
  123. return consignmentPending;
  124. }
  125. set;
  126. }
  127.  
  128.  
  129. }
  130.  
  131. public class ShippingInfo {
  132. @AuraEnabled public String contactAddressId {get;set;}
  133. @AuraEnabled public String shippingPriority {get;set;}
  134. @AuraEnabled public String shippingTrackingNumber {get;set;}
  135. }
  136.  
  137. public class productResponse {
  138. @AuraEnabled public List<product> successProducts{get;set;}
  139. @AuraEnabled public List<product> errorProducts{get;set;}
  140. @AuraEnabled public String errorMessage{get;set;}
  141. }
  142.  
  143.  
  144.  
  145. @AuraEnabled
  146. public static String completeTransfer(String recordId) {
  147.  
  148. String retMessage = '';
  149. boolean updateTransaction = false;
  150. Boolean sendRejectNotificationEmail = false;
  151. String profileName;
  152.  
  153. try {
  154. profileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() Limit 1].Name;
  155. } catch (Exception x) {
  156. profileName = '';
  157. }
  158.  
  159. OrgWideEmailAddress l_org_wide_email_address = [ SELECT Id FROM OrgWideEmailAddress WHERE DisplayName = 'Salesforce Administrator' LIMIT 1 ];
  160.  
  161. // CRM Users query Neuro Constants Mappings for CRM_Email_Address else use the Sales_Ops_Email_Address
  162. String soqlEmailDeveloperName = Constants.PROFILE.isCRMSalesusersProfile( profileName ) ? 'CRM_Email_Address' : 'Sales_Ops_Email_Address';
  163. 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
  164.  
  165. 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];
  166. Set<String> businessPartners = new Set<String>();
  167. Set<Id> inventoryIds = new Set<Id>();
  168. system.debug('=titems'+titems);
  169. for (Transaction_Items__c item : titems) {
  170. businessPartners.add(item.Transaction_ID__r.Origin_Sales_Rep__r.Business_Partner__c);
  171. inventoryIds.add(item.Inventory__c );
  172. }
  173. List<String> userAvailableRecordTypes = getCycleCountRequestRecordTypes();
  174. List<Cycle_Count_Request_Line_Item__c> requestItems = new List<Cycle_Count_Request_Line_Item__c>();
  175. requestItems = [Select Id,CycleCountRequestUserID__r.Name from Cycle_Count_Request_Line_Item__c where CycleCountRequestUserID__r.User__r.Business_Partner__c IN:businessPartners
  176. and CycleCountRequestUserID__r.Status__c = 'In Progress' and Inventory__c IN:inventoryIds];
  177. if(requestItems.size() > 0 && userAvailableRecordTypes.size() > 0 && NeuroConstants.RECORDTYPE.isCycleCountRecordType(userAvailableRecordTypes[0])){
  178. updateTransaction = false;
  179. retMessage = 'Cycle Count is in progress. Please complete count prior to transferring inventory.';
  180. }
  181. else{
  182. for (Transaction_Items__c item : titems) {
  183. if (item.Item_Accepted_or_Rejected__c == 'Accept' || item.Item_Accepted_or_Rejected__c == 'Reject') {
  184. updateTransaction = true;
  185. if( item.Item_Accepted_or_Rejected__c == 'Reject' ) {
  186. sendRejectNotificationEmail = true;
  187. }
  188. } else {
  189. updateTransaction = false;
  190. retMessage = 'You must mark all items as either Accepted or Rejected before completing the transfer request.';
  191. break;
  192. }
  193. }
  194. }
  195. if (updateTransaction) {
  196.  
  197. try {
  198. 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 ];
  199. trans.Status__c = 'COMPLETE';
  200. trans.Submit__c = true;
  201. update trans;
  202.  
  203. // 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.
  204. if( sendRejectNotificationEmail && trans.Origin_Sales_Rep__r.Email != null ) {
  205.  
  206. Messaging.SingleEmailMessage l_email = new Messaging.SingleEmailMessage();
  207. l_email.setOrgWideEmailAddressId( l_org_wide_email_address.id );
  208. l_email.setToAddresses( new String[]{
  209. trans.Origin_Sales_Rep__c
  210. } );
  211. l_email.setSubject('Inventory Transfer Rejected');
  212. 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/>' +
  213. '<a href='+System.Url.getSalesforceBaseUrl().toExternalForm()+'/'+trans.Id+'>' +trans.Name+
  214. '</a>');
  215. Messaging.sendEmail( new List<Messaging.SingleEmailMessage>{
  216. l_email
  217. } );
  218. }
  219.  
  220. retMessage = 'Your inventory transfer request has been successfully submitted.';
  221. } catch( Exception l_ex ) {
  222. if ( Constants.PROFILE.isCRMSalesusersProfile( profileName ) ) {
  223. retMessage = 'An error occurred while processing your inventory transfer request. Please contact ' + l_sales_order_email;
  224. } else {
  225. retMessage = 'The following error occurred while processing your inventory transfer request: ' + l_ex.getMessage() + '\n\nPlease contact sales ops at ' + l_sales_order_email;
  226. }
  227. }
  228.  
  229. return retMessage;
  230. }else {
  231. return retMessage;
  232. }
  233. }
  234.  
  235.  
  236. @AuraEnabled
  237. public static List<product> getTransactionItems(String recordId) {
  238. List<AcceptInventoryTransferController.product> products = new List<AcceptInventoryTransferController.product>();
  239.  
  240. List<Transaction_Items__c> transactionItems = [SELECT Id, Name, Reason_For_Rejection__c, Item_Accepted_or_Rejected__c,
  241. Transaction_Id__r.Origin_Sales_Rep__r.Name, Quantity__c,
  242. Inventory__r.Name, Inventory__r.Is_this_my_Inventory__c,
  243. Inventory__r.Model_Number__c, Inventory__r.Serial_Number__c, Inventory__r.Quantity__c,
  244. Inventory__r.QN_Flg__c, Inventory__r.Use_by_Date_Status__c, Inventory__r.Return_Status_Text__c
  245. FROM Transaction_Items__c WHERE Transaction_ID__c = :recordId];
  246. for ( Transaction_Items__c item : transactionItems ) {
  247. AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
  248. p.name = item.Name;
  249. p.inv = item.Inventory__r;
  250. p.transItemId = item.Id;
  251. p.acceptreject = item.Item_Accepted_or_Rejected__c;
  252. p.rejectreason = item.Reason_For_Rejection__c;
  253. p.originsalesrep = item.Transaction_Id__r.Origin_Sales_Rep__r.Name;
  254. p.transactionQuantity = Integer.valueOf( item.Quantity__c );
  255. products.add(p);
  256. }
  257.  
  258. System.debug('Transation Items: ' + products);
  259.  
  260. return products;
  261. }
  262.  
  263. @AuraEnabled
  264. public static List<ListOption> getPicklistValuesForRejectReason() {
  265. List<ListOption> options = new List<ListOption>();
  266. List<Schema.PicklistEntry> ple = Transaction_Items__c.Reason_For_Rejection__c.getDescribe().getPicklistValues();
  267.  
  268. for (Schema.PicklistEntry f : ple) {
  269. ListOption option = new ListOption();
  270. option.label = f.getLabel();
  271. option.value = f.getLabel();
  272.  
  273. options.add(option);
  274. }
  275. return options;
  276. }
  277.  
  278. @AuraEnabled
  279. public static void saveTransactionItem(Transaction_Items__c transactionItem) {
  280. System.debug('Save Transaction Item: ' + transactionItem);
  281. try {
  282. update transactionItem;
  283. } catch (exception e) {
  284. System.debug('ERROR Saving Transaction Item msg: ' + e);
  285. }
  286. }
  287.  
  288.  
  289. @AuraEnabled
  290. public static List<product> addItem(Inventory__c inv, Contact location, Contact destination) {
  291.  
  292. List<product> ret_val = new List<product>();
  293. List<Transaction_Items__c> inventoryItems = new List<Transaction_Items__c>();
  294. List<String> userAvailableRecordTypes = getCycleCountRequestRecordTypes();
  295. List<Cycle_Count_Request_Line_Item__c> requestLineItems = new List<Cycle_Count_Request_Line_Item__c>();
  296. User userInfo = [Select Id,Profile.Name from User where Id=: UserInfo.getUserId() limit 1];
  297. 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'];
  298. system.debug('=== inventoryItems'+inventoryItems);
  299.  
  300. 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];
  301. system.debug('@@@ requestLineItems '+requestLineItems);
  302.  
  303. if(requestLineItems.size() > 0 && userAvailableRecordTypes.size() > 0 && NeuroConstants.RECORDTYPE.isCycleCountRecordType(userAvailableRecordTypes[0])){
  304. AcceptInventoryTransferController.product pWithTransfer = new AcceptInventoryTransferController.product();
  305. pWithTransfer.transItemId = String.valueOf(requestLineItems[0].Inventory__c);
  306. pWithTransfer.Name = 'true';
  307. pWithTransfer.inv = inv;
  308. pWithTransfer.loc = location;
  309. ret_val.add(pWithTransfer);
  310. return ret_val;
  311. }
  312.  
  313. else if(inventoryItems.size() >0 ){
  314. AcceptInventoryTransferController.product pWithTransfer = new AcceptInventoryTransferController.product();
  315. pWithTransfer.transItemId = String.valueOf(inventoryItems[0].Transaction_ID__r.Name);
  316. pWithTransfer.Name = inv.Name;
  317. pWithTransfer.inv = inv;
  318. pWithTransfer.loc = location;
  319. ret_val.add(pWithTransfer);
  320.  
  321. return ret_val;
  322. }else{
  323. AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
  324. p.name = inv.Name;
  325. p.lineone = inv.Name;
  326. p.linetwo = inv.Model_Description__c;
  327. p.inv = inv;
  328. p.loc = location;
  329. p.dest = destination;
  330. p.transactionQuantity = 1; // Default to 1, since the form quantity field defaults to 1
  331. ret_val.add(p);
  332. return ret_val;
  333. }
  334. }
  335.  
  336. @AuraEnabled
  337. public static productResponse getProductsFromInventories(List<Inventory__c> invs, Contact location, Contact destination) {
  338. List<product> ret_prods = new List<product>();
  339. List<product> err_prods = new List<product>();
  340. String l_error_message;
  341. String l_model_list = '';
  342.  
  343. for(Inventory__c inv: invs) {
  344. AcceptInventoryTransferController.product p = new AcceptInventoryTransferController.product();
  345. p.name = inv.Name;
  346. p.lineone = inv.Model_Number__c;
  347. p.linetwo = inv.Model_Description__c;
  348. p.inv = inv;
  349. p.loc = location;
  350. p.dest = destination;
  351.  
  352. if(inv.Sales_Rep__c != location.Id) {
  353. err_prods.add(p);
  354. } else {
  355. ret_prods.add(p);
  356. }
  357. }
  358.  
  359. AcceptInventoryTransferController.productResponse pResponse = new AcceptInventoryTransferController.productResponse();
  360. pResponse.errorProducts = err_prods;
  361. pResponse.successProducts = ret_prods;
  362.  
  363. if( err_prods.size() > 0 )
  364. {
  365. for( product l_p : err_prods )
  366. {
  367. if( l_model_list != '' )
  368. {
  369. l_model_list += ', ';
  370. }
  371. l_model_list += l_p.lineone;
  372. }
  373.  
  374. try
  375. {
  376. l_error_message = [ SELECT Message__c
  377. FROM Neuro_Message__mdt
  378. WHERE DeveloperName = 'Inventory_Transfer_Product_Warning'
  379. LIMIT 1 ].Message__c;
  380.  
  381. }
  382. catch( Exception l_any )
  383. {
  384. l_error_message = 'The following inventory will not be transferred because it does not exist under {0}: {1}';
  385. }
  386. pResponse.errorMessage = l_error_message.replace( '{0}', location.Name == null?'':location.Name ).replace( '{1}', l_model_list == null?'':l_model_list );
  387. }
  388.  
  389. return pResponse;
  390. }
  391.  
  392. @AuraEnabled
  393. public static Contact getOriginalLocationNameForInventory(Inventory__c Inventory) {
  394. Contact inv_contact;
  395.  
  396. try {
  397. inv_contact = [SELECT id, Name, Sales_Rep_User__c, Sales_Rep_User__r.ProfileId FROM Contact where Id =: Inventory.Sales_Rep__c LIMIT 1];
  398. } catch(Exception e) {
  399. debug('EXCEPTION OCCURED: ' + e.getMessage());
  400. }
  401.  
  402. return inv_contact;
  403. }
  404.  
  405. @AuraEnabled
  406. public static List<Inventory__c> getmockbarcodes() {
  407.  
  408. List<Inventory__c> inventories = new List<Inventory__c>();
  409. // Quantity__c -- max value
  410. inventories = [SELECT Name, Model_Number__c, Sales_Rep__c, Serial_Number__c, Serialized__c, Quantity__c FROM Inventory__c LIMIT 44 ];
  411. return inventories;
  412. }
  413.  
  414. @AuraEnabled
  415. public static List<Contact> getLocationNamesFromInventories(List<Inventory__c> inventories) {
  416. Set<Id> sales_reps = new Set<Id>();
  417.  
  418. for(Inventory__c ivn : inventories) {
  419. sales_reps.add(ivn.Sales_Rep__c);
  420. }
  421.  
  422. List<Contact> sreps;
  423. if(sales_reps.size() > 0) {
  424. sreps = [SELECT id, name from Contact where id IN : sales_reps];
  425. } else {
  426. sreps = null;
  427. }
  428. return sreps;
  429. }
  430.  
  431. @AuraEnabled
  432. public static List<Contact> getDestinationLocationNames() {
  433. List<Contact> destLocationNames = [SELECT id, Name, Sales_Rep_User__c, Business_Partner__c
  434. FROM Contact
  435. WHERE Business_Partner__c != NULL
  436. AND Sales_Rep_User__c != NULL];
  437. return destLocationNames;
  438. }
  439.  
  440. @AuraEnabled
  441. public static Map<Id, Contact> getContacts(List<Id> conids) {
  442. List<Contact> cons = [select id, name from Contact WHERE Id IN : conids];
  443. Map<Id, Contact> id_to_con = new Map<Id, Contact>();
  444. for(Contact c : cons) {
  445. id_to_con.put(c.Id, c);
  446. }
  447. return id_to_con;
  448. }
  449.  
  450. @AuraEnabled
  451. public static Contact getSJMEmployee() {
  452. Contact ret_con;
  453.  
  454. List<Contact> contacts = [SELECT ID, NAME, Sales_Rep_User__c, Business_Partner__c, Sales_Rep_User__r.ProfileId
  455. FROM contact
  456. WHERE Sales_Rep_User__c =: Userinfo.getuserid()
  457. AND Business_Partner__c != NULL];
  458.  
  459. if(contacts.size() > 0) {
  460. ret_con = contacts[0];
  461. }else {
  462. ret_con = null;
  463. }
  464. return ret_con;
  465. }
  466.  
  467.  
  468. @AuraEnabled
  469. public static void submitInventoryTransfer(String objectList, String shippingInfoJSON) {
  470. System.debug('SUBMIT INVENTORY TRANSFER:::::: ' + objectList);
  471. objectList = objectList.remove('T00:00:00.000Z');
  472. System.debug('Param: ShippingInfo = ' + shippingInfoJSON );
  473.  
  474. ShippingInfo shippingInfo;
  475. if( shippingInfoJSON != null )
  476. {
  477. shippingInfo = (AcceptInventoryTransferController.ShippingInfo) JSON.deserialize( shippingInfoJSON, AcceptInventoryTransferController.ShippingInfo.class );
  478. }
  479.  
  480. List<Object> json_to_objectList = (List<Object>)Json.deserializeUntyped(objectList);
  481. List<product> productsList = new List<product>();
  482.  
  483. for(Object s : json_to_objectList){
  484. String test = JSON.serialize(s);
  485. AcceptInventoryTransferController.product new_product_object = (AcceptInventoryTransferController.product)JSON.deserialize(test, AcceptInventoryTransferController.product.class);
  486. debug('this is obj : ' + new_product_object);
  487. productsList.add(new_product_object);
  488. }
  489.  
  490.  
  491. //determine which profile is using accept inv. then split based on record type.
  492. Id currentUserId = UserInfo.getUserId();
  493. String profId;
  494. String profName;
  495. Id transaction_recordType_id;
  496. Id transaction_item_recordType_id;
  497. List<User> profIdList= [SELECT profileId FROM User WHERE Id=:currentUserId LIMIT 1];
  498. for(User u: profIdList){
  499. profId = u.ProfileId;
  500. //system.debug('this is the profile id '+profId);
  501. }
  502. List<Profile> profNameList = [SELECT Name FROM Profile WHERE Id =:profId LIMIT 1];
  503. for(Profile p: profNameList){
  504. profName=p.Name;
  505. //system.debug('This is the profile name: '+profName);
  506. }
  507. if( Constants.PROFILE.isNeuroSalesusersProfile( profName ) ) {
  508. transaction_recordType_id = Schema.SObjectType.Transactions__c.getRecordTypeInfosByName().get('Neuro Inventory Transfer').getRecordTypeId();
  509. transaction_item_recordType_id = Schema.SObjectType.Transaction_Items__c.getRecordTypeInfosByName().get('Neuro Inventory Transfer Item').getRecordTypeId();
  510. }
  511. if( Constants.PROFILE.isCRMSalesusersProfile( profName ) ) {
  512. transaction_recordType_id = Schema.SObjectType.Transactions__c.getRecordTypeInfosByName().get('CRM Inventory Transfer').getRecordTypeId();
  513. // system.debug('the transaction record type id is: '+transaction_recordtype_id);
  514. transaction_item_recordType_id = Schema.SObjectType.Transaction_Items__c.getRecordTypeInfosByName().get('CRM Inventory Transfer Item').getRecordTypeId();
  515. //system.debug('the transaction item record type id is: '+transaction_item_recordtype_id);
  516. }
  517.  
  518. Transactions__c create_transaction = new Transactions__c();
  519. create_transaction.recordTypeId = transaction_recordType_id;
  520.  
  521. create_transaction.Origin_Sales_Rep__c = productsList[0].loc.Id; // Lookup contact (Original Location )
  522. create_transaction.Sales_Rep__c = productsList[0].dest.Id; // Lookup contact (Destination location)
  523.  
  524. if( shippingInfo != null ) {
  525. create_transaction.Sales_Rep_Address__c = String.isNotEmpty(shippingInfo.contactAddressId) ? shippingInfo.contactAddressId : null;
  526. //system.debug('sales rep address issue?: '+create_transaction.Sales_Rep_Address__c);
  527. create_transaction.Shipping_Priority__c = shippingInfo.shippingPriority;
  528. create_transaction.Shipping_Tracking_Number__c = shippingInfo.shippingTrackingNumber;
  529. }
  530.  
  531. // create_transaction.Status__c = 'Send';
  532. create_transaction.Submit__c = false;
  533.  
  534. Savepoint sp = Database.setSavepoint();
  535.  
  536. try {
  537.  
  538. try {
  539. insert create_transaction;
  540. } catch(Exception e) {
  541. debug('Exception occured: ' + e.getMessage());
  542. throw e;
  543. }
  544.  
  545. List<Transaction_Items__c> t_line_items = new List<Transaction_Items__c>();
  546. for(product p : productsList) {
  547. Transaction_Items__c t_item = new Transaction_Items__c();
  548. t_item.RecordTypeId = transaction_item_recordType_id;
  549. t_item.Inventory__c = p.inv.Id;
  550. // t_item.Quantity__c = p.inv.Quantity__c;
  551. t_item.Quantity__c = p.transactionQuantity;
  552. if( t_item.Quantity__c == null )
  553. {
  554. t_item.Quantity__c = 1;
  555. }
  556. t_item.Transaction_ID__c = create_transaction.Id;
  557. t_line_items.add(t_item);
  558. }
  559.  
  560. try{
  561. insert t_line_items;
  562. } catch(Exception e) {
  563. debug('Exception occured: ' + e.getMessage());
  564. throw e;
  565. }
  566.  
  567. Transactions__c update_transaction_send = [SELECT id, Status__c, Sales_Rep__r.Sales_Rep_User__c FROM Transactions__c WHERE ID =: create_transaction.Id ];
  568. // if the receiving user is NOT the same as the current current, set Status = "Pending Acceptance" and do not submit
  569. // the transactions to SAP
  570. if( update_transaction_send.Sales_Rep__r.Sales_Rep_User__c != UserInfo.getUserId() )
  571. {
  572. update_transaction_send.Status__c = 'Pending Acceptance';
  573. }
  574. else
  575. {
  576. update_transaction_send.Submit__c = true;
  577. }
  578.  
  579. try{
  580. update update_transaction_send;
  581. } catch(Exception e) {
  582. debug('Updating Transactions__c Status to SEND failed. ' + e.getMessage());
  583. throw e;
  584. }
  585.  
  586. } catch(Exception ex) {
  587. debug('ERROR: Exception: ' + ex.getMessage());
  588. Database.rollback(sp);
  589. }
  590.  
  591. }
  592.  
  593. public static void debug(object message)
  594. {
  595. System.debug('AcceptInventoryTransferController > ' + message);
  596. }
  597.  
  598. @AuraEnabled
  599. public static
  600. List<Contact_Address__c>
  601. getContactAddresses( Id a_contact_id )
  602. {
  603. return [ SELECT Id, Name, Address__c, Address_1__c, Address_2__c
  604. FROM Contact_Address__c
  605. WHERE Contact__c = :a_contact_id
  606. ORDER BY Name ];
  607. }
  608.  
  609. @AuraEnabled
  610. public static
  611. List<String>
  612. getShippingPriorityOptions()
  613. {
  614. List<String> l_opts = new List<String>{'Hand Delivered'};
  615. l_opts.addAll( InventoryRequestShippingController.getShippingPriorityPicklist( new Transactions__c(), 'Shipping_Priority__c') );
  616. return l_opts;
  617. }
  618.  
  619. public static List<String> getCycleCountRequestRecordTypes(){
  620. List<String> recordTypeNameList = new List<String>();
  621. List<RecordTypeInfo> rtinfo = Cycle_Count_Request__c.SObjectType.getDescribe().getRecordTypeInfos();
  622. system.debug('@@@ rtinfo '+ rtinfo);
  623. if (rtinfo.size() > 1) {
  624. for(RecordTypeInfo i : rtinfo) {
  625. if (i.isAvailable() && i.Name != 'Master')
  626. recordTypeNameList.add(i.getName());
  627. }
  628. }
  629. else recordTypeNameList.add(rtinfo[0].getName());
  630. return recordTypeNameList;
  631. }
  632.  
  633. @AuraEnabled
  634. public static Boolean getIsCRMUser() {
  635. Profile user_profile = [SELECT Id, Name FROM Profile WHERE Id =: UserInfo.getProfileId() LIMIT 1];
  636. return Constants.PROFILE.isCRMSalesusersProfile(user_profile.Name);
  637. }
  638.  
  639. public class InventoryErrors {
  640. @AuraEnabled public Inventory__c inventory {get;set;}
  641. @AuraEnabled public Boolean isError {get;set;}
  642. @AuraEnabled public String message {get;set;}
  643. }
  644.  
  645. @AuraEnabled
  646. public static InventoryErrors
  647. parseDesktopScan(String barcodeString, String destinationName, Boolean sentByMe) {
  648.  
  649. /*
  650. SF1-7378
  651. Upon scanning a product add the product onto the Send Inventory Transfer only if:
  652. *the product is within the Original Location Name’s inventory
  653. * and the product does not have Expiry Notice or Quality Notice.
  654. */
  655. InventoryErrors return_InventoryErrors = new InventoryErrors();
  656.  
  657. Barcode parsedBar = Barcode.parse(barcodeString);
  658.  
  659. 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
  660. FROM Inventory__c
  661. WHERE Serial_Number__c =: parsedBar.Serial];
  662.  
  663. if(inventory.size() > 0) {
  664. return_InventoryErrors.inventory = inventory[0];
  665. return_InventoryErrors.isError = false;
  666. } else {
  667. return_InventoryErrors.inventory = null;
  668. return_InventoryErrors.isError = true;
  669. return_InventoryErrors.message = 'The product was not found in the Original Location Name’s inventory';
  670. }
  671.  
  672. if( inventory.size() > 0 ) {
  673.  
  674. if (sentByMe == true && inventory[0].Is_this_my_Inventory__c == 'No') {
  675. return_InventoryErrors.isError = true;
  676. return_InventoryErrors.message = 'The product was not found in the Original Location Name’s inventory';
  677. }
  678. // QUALITY NOTICE
  679. if (inventory[0].QN_Flg__c == true) {
  680. return_InventoryErrors.isError = true;
  681. return_InventoryErrors.message = 'This product is not valid to be transferred. Please review for Expiry Notice or Quality Notice.';
  682. }
  683. // Expiry Notice.
  684. if (inventory[0].Use_by_Date_Status__c != 'OK') {
  685. return_InventoryErrors.isError = true;
  686. return_InventoryErrors.message = 'This product is not valid to be transferred. Please review for Expiry Notice or Quality Notice.';
  687. }
  688. }
  689. return return_InventoryErrors;
  690. }
  691.  
  692. @AuraEnabled
  693. public static List<Accept_Consignment_Log__c> getAcceptConsignmentLogsBySerialNumber(String serialnumber) {
  694. List<String> serialnumberlist = new List<String>();
  695. serialnumberlist.add(serialnumber);
  696. return QueryWithoutSharingExecutor.getAcceptConsignmentLogBySerialNumber( serialnumberlist );
  697. }
  698.  
  699. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement