public void GenerateStockMutations(Int32 vendorId, List <WehkampStockMutation> mutations) { var mappedList = _mapper.MapToDatCol(vendorId, mutations); var flatFile = _stockEngine.WriteString(mappedList); var path = CommunicatorService.GetMessagePath(vendorId, MessageTypes.StockMutation); File.WriteAllText(Path.Combine(path.MessagePath, _fileName), flatFile); }
protected override void Process() { using (var unit = GetUnitOfWork()) { var vendors = unit.Scope.Repository <Vendor>().GetAll().ToList().Where(c => ((VendorType)c.VendorType).Has(VendorType.SupportsPFATransferOrders)).ToList(); foreach (var vendor in vendors) { try { var messagePaths = CommunicatorService.GetMessagePath(vendor.VendorID, MessageTypes.TransferOrder); var messagePath = messagePaths.MessagePath; var logLocation = messagePaths.ProcessedPath; var errorLocation = messagePaths.ErrorPath; if (!Directory.Exists(logLocation)) { Directory.CreateDirectory(logLocation); } if (!Directory.Exists(errorLocation)) { Directory.CreateDirectory(errorLocation); } var publicationRule = vendor.ContentProducts.FirstOrDefault(c => c.IsAssortment); publicationRule.ThrowIfNull("Publication rule with IsAssortment is missing for vendor " + vendor.Name); var connectorID = publicationRule.ConnectorID; Directory.GetFiles(messagePath).ForEach((file, idx) => { try { List <MutHeader> message = GenerateTransferMutationMessage(file); CreateTransferOrders(file, message, connectorID, unit); unit.Save(); Files.MoveFileToPath(logLocation, file, true); } catch (Exception ex) { log.AuditError("Something went wrong processing " + file + ". See log file."); Files.LogExceptionAndMove(errorLocation, file, ex); } }); } catch (Exception ex) { log.AuditError(string.Format("Error trying to process wehkamp transfer order because : {0}", ex.Message), ex, Name); } } } }
protected override void Process() { _monitoring.Notify(Name, 0); var messages = MessageHelper.GetMessagesByStatusAndType(Enums.WehkampMessageStatus.Created, MessageHelper.WehkampMessageType.StockPhoto); foreach (var message in messages) { log.Info(string.Format("{0} - Copying; file: {1}", Name, message.Filename)); try { File.Copy(Path.Combine(message.Path, message.Filename), Path.Combine(CommunicatorService.GetMessagePath(message.VendorID, PfaCommunicator.Objects.Models.MessageTypes.StockPhoto).MessagePath, message.Filename)); } catch (Exception e) { log.AuditError(string.Format("Error while processing file {0}", message.Filename), e); MessageHelper.Error(message); continue; } MessageHelper.Archive(message); } _monitoring.Notify(Name, 1); }
protected override void Process() { using (var unit = GetUnitOfWork()) { var vendors = unit.Scope.Repository <Vendor>().GetAll().ToList().Where(c => ((VendorType)c.VendorType).Has(VendorType.SupportsPFATransferOrders)).ToList(); var orderLedgerRepo = unit.Scope.Repository <OrderLedger>(); foreach (var vendor in vendors) { var rule = vendor.ContentProducts.FirstOrDefault(c => c.IsAssortment); rule.ThrowIfNull("Publication rule with IsAssortment is missing for vendor " + vendor.Name); IQueryable <OrderLine> lines = unit.Scope.Repository <OrderLine>().GetAll(x => x.Order.OrderType == (int)OrderTypes.ReturnOrder && x.Order.ConnectorID == rule.ConnectorID && x.OrderLedgers.Any(y => y.Status == (int)OrderLineStatus.StockReturnRequestConfirmation)); IQueryable <OrderLine> processed = unit.Scope.Repository <OrderLine>().GetAll(x => x.Order.OrderType == (int)OrderTypes.ReturnOrder && x.Order.ConnectorID == rule.ConnectorID && x.OrderLedgers.Any(y => y.Status == (int)OrderLineStatus.ProcessedStockReturnRequestConfirmation)); var ledgerRepo = unit.Scope.Repository <OrderLedger>(); var storeID = ConnectorHelper.GetStoreNumber(rule.ConnectorID); var employeeNumber = VendorHelper.GetEmployeeNumber(vendor.VendorID); int differenceShopNumber = VendorHelper.GetReturnDifferenceShopNumber(vendor.VendorID); lines = lines.Except(processed); var toProcess = lines.GroupBy(line => line.Order).ToList().Select(c => new { Order = c.Key, OrderLines = c.ToList() }).ToList(); foreach (var order in toProcess) { int recordSequenceDetail = 0; int recordSequeceCompleteShipment = 200; //get all three different shop numbers var salesSlipNumber = GenericSlipNumberHelper.GetSlipNumberForTransfer(vendor.VendorID, ReceiptHelper.STOCK_SALESSLIP_RECEIPT_NUMBER_SETTING_KEY); int salesSlipNumber_OtherFilials = 0; //used for any line with warehouse code != 982 var salesSlipNumberComplete = salesSlipNumber; var salesSlipNumberShop = salesSlipNumberComplete; var fileEngine = new FileHelperEngine(typeof(ReturnOrderDatcolModel)); var returns = new List <ReturnOrderDatcolModel>(); var fileName = String.Format("{0}{1}", "returnOrders", DateTime.Now.ToString("yyyyMMddHHmmss")); //process contents DateTime messageTime = order.OrderLines.FirstOrDefault().OrderLedgers.FirstOrDefault(c => c.Status == (int)OrderLineStatus.StockReturnRequestConfirmation).LedgerDate.ToLocalTime(); int totalSkus = 0; if (order.OrderLines.Any(c => c.WareHouseCode != differenceShopNumber.ToString())) { salesSlipNumber_OtherFilials = GenericSlipNumberHelper.GetSlipNumberForTransfer(vendor.VendorID, ReceiptHelper.STOCK_SALESSLIP_RECEIPT_NUMBER_SETTING_KEY); } foreach (var orderLine in order.OrderLines) { var detailSalesSlipNumber = salesSlipNumber; var ledger = orderLine.OrderLedgers.FirstOrDefault(c => c.Status == (int)OrderLineStatus.StockReturnRequestConfirmation); totalSkus += ledger.Quantity.Value; recordSequenceDetail += 200; if (orderLine.WareHouseCode != differenceShopNumber.ToString()) { returns.Add(GetDetailLevel(storeID, employeeNumber, salesSlipNumber, salesSlipNumber_OtherFilials, ledger.LedgerDate.ToLocalTime(), ledger.Quantity.Value, differenceShopNumber, recordSequenceDetail, orderLine.ProductID.Value, vendor.VendorID)); } else { returns.Add(GetDetailLevel(storeID, employeeNumber, salesSlipNumber, salesSlipNumber, ledger.LedgerDate.ToLocalTime(), ledger.Quantity.Value, differenceShopNumber, recordSequenceDetail, orderLine.ProductID.Value, vendor.VendorID)); } } var codes = order.OrderLines.Select(c => c.WareHouseCode).Where(c => !string.IsNullOrEmpty(c)); if (codes.Any(c => c != differenceShopNumber.ToString())) { returns.Add(GetCompleteLevel(storeID, employeeNumber, salesSlipNumberComplete, salesSlipNumber_OtherFilials, messageTime, totalSkus, differenceShopNumber)); } foreach (var orderLineFilial in order.OrderLines.Where(c => !string.IsNullOrEmpty(c.WareHouseCode) && c.WareHouseCode != differenceShopNumber.ToString()).GroupBy(c => c.WareHouseCode).ToList()) { var salesSlipNumber_Difference = GenericSlipNumberHelper.GetSlipNumberForTransfer(vendor.VendorID, ReceiptHelper.STOCK_SALESSLIP_RECEIPT_NUMBER_SETTING_KEY_SURPLUS); foreach (var orderLine in orderLineFilial) { recordSequenceDetail += 200; var ledger = orderLine.OrderLedgers.FirstOrDefault(c => c.Status == (int)OrderLineStatus.StockReturnRequestConfirmation); returns.Add(GetDetailLevelForStore(int.Parse(orderLine.WareHouseCode), employeeNumber, salesSlipNumberShop, salesSlipNumber_Difference, messageTime, ledger.Quantity.Value, differenceShopNumber, recordSequenceDetail, orderLine.ProductID.Value, vendor.VendorID)); } } if (returns.Count > 0) { var file = fileEngine.WriteString(returns); var path = CommunicatorService.GetMessagePath(vendor.VendorID, PfaCommunicator.Objects.Models.MessageTypes.WehkampReturn); File.WriteAllText(Path.Combine(path.MessagePath, fileName), file); } foreach (var line in order.OrderLines) { line.SetStatus(OrderLineStatus.ProcessedStockReturnRequestConfirmation, ledgerRepo); } } unit.Save(); } } }
protected override void Process() { using (var unit = GetUnitOfWork()) { var vendors = unit.Scope.Repository <Vendor>().GetAll().ToList().Where(c => ((VendorType)c.VendorType).Has(VendorType.SupportsPFATransferOrders)).ToList(); int transferOrderType = (int)OrderTypes.TransferOrder; var ledgerRepo = unit.Scope.Repository <OrderLedger>(); vendors.ForEach((vendor, indexer) => { var mutationEngine = new FileHelperEngine(typeof(ReceivedTransferMutation)); var fileName = String.Format("{0}{1}", "mancosurplus", DateTime.Now.ToString("yyyyMMddHHmmss")); var mutations = new List <ReceivedTransferMutation>(); var rule = vendor.ContentProducts.FirstOrDefault(c => c.IsAssortment); rule.ThrowIfNull("Publication rule with IsAssortment is missing for vendor " + vendor.Name); List <OrderLine> lines = unit .Scope .Repository <OrderLine>() .GetAll(x => x.Order.OrderType == transferOrderType && x.Order.ConnectorID == rule.ConnectorID && x.OrderLedgers.Any(y => y.Status == (int)OrderLineStatus.ReceivedTransfer) && !x.OrderLedgers.Any(y => y.Status == (int)OrderLineStatus.ProcessedReceivedTransfer)).ToList(); var storeID = ConnectorHelper.GetStoreNumber(rule.ConnectorID); var employeeNumber = VendorHelper.GetEmployeeNumber(vendor.VendorID); var salesSlipNumber = ReceiptHelper.GetSlipNumber(vendor.VendorID); //ReceiptHelper.IncrementSalesSlipNumber(ref salesSlipNumber); var toProcess = lines.GroupBy(k => k.Order).ToList().Select(c => new { Order = c.Key, OrderLines = c.ToList(), ExtraOrderLines = c.Key.OrderLines.Except(c.ToList()) }).ToList(); foreach (var order in toProcess) { PfaOrderHelper helper = new PfaOrderHelper(vendor.VendorID); if (order.OrderLines.Count == 0) { continue; } order.OrderLines.AddRange(order.ExtraOrderLines); var receivedByWehkampDate = order.OrderLines.FirstOrDefault().OrderLedgers.FirstOrDefault(c => c.Status == (int)OrderLineStatus.ReceivedTransfer).LedgerDate.ToLocalTime(); List <TransferOrderModel> list = helper.GetShippedQuantitiesForOrder(order.Order.WebSiteOrderNumber, order.Order.ConnectorID); if (list.Count > 0) { List <TransferOrderLine> orderLinesToBeProcessed = GetOrderLineStatus(order.OrderLines, list, order.Order.OrderID, vendor.VendorID, unit); if (list.Count > order.OrderLines.Count()) { //more lines are in PFA than in the Concentrator log.AuditInfo(string.Format("For order {0} there are {1} order lines in Concentrator and {2} in PFA. Difference found of {3} lines." , order.Order.WebSiteOrderNumber, order.OrderLines.Count(), list.Count, order.ExtraOrderLines.Count())); } if (orderLinesToBeProcessed.Any(c => c.ShippedFromPFA != c.ReceivedFromWehkamp)) { var differences = orderLinesToBeProcessed.Where(c => c.ShippedFromPFA != c.ReceivedFromWehkamp); //add each quantity unmatched product differences.ForEach((difference, index) => { var unmatchedQuantityLine = GetDifferenceRuleForIncompleteShipping(difference, orderLinesToBeProcessed.Sum(x => x.ReceivedFromWehkamp), orderLinesToBeProcessed.Sum(x => x.ShippedFromPFA), storeID, employeeNumber, vendor.VendorID, receivedByWehkampDate, salesSlipNumber); mutations.Add(unmatchedQuantityLine); }); //add the total rule mutations.AddRange(GetTotalRuleForIncompleteShipping(order.Order, orderLinesToBeProcessed.Sum(x => x.ReceivedFromWehkamp), orderLinesToBeProcessed.Sum(x => x.ShippedFromPFA), storeID, employeeNumber, vendor.VendorID, receivedByWehkampDate, salesSlipNumber)); } else { //add quantity matched list mutations.AddRange(GetCompletelyShippedRule(order.Order, orderLinesToBeProcessed.Sum(x => x.ReceivedFromWehkamp), storeID, employeeNumber, vendor.VendorID, receivedByWehkampDate, salesSlipNumber)); } } else { log.AuditError("Ignoring order " + order.Order.WebSiteOrderNumber + ": No lines found in PFA"); } foreach (var line in order.OrderLines) { line.SetStatus(OrderLineStatus.ProcessedReceivedTransfer, ledgerRepo); } ReceiptHelper.IncrementSalesSlipNumber(ref salesSlipNumber, vendor.VendorID); } if (mutations.Count > 0) { var file = mutationEngine.WriteString(mutations); var path = CommunicatorService.GetMessagePath(vendor.VendorID, MessageTypes.TransferOrderConfirmation); File.WriteAllText(Path.Combine(path.MessagePath, fileName), file); } unit.Save(); }); } }