/// <summary> /// Add the default cancellation charge configured for this store /// </summary> /// <param name="transaction"></param> private static void AddDefaultCancellationCharge(CustomerOrderTransaction transaction) { Contracts.IApplication app = SalesOrder.InternalApplication; Tax.MiscellaneousCharge charge = transaction.MiscellaneousCharges.SingleOrDefault( m => string.Equals(m.ChargeCode, ApplicationSettings.Terminal.CancellationChargeCode, StringComparison.OrdinalIgnoreCase)); // if there is not already a charge on this order, then attempt to add the default charge if (charge == null && transaction.OrderType == CustomerOrderType.SalesOrder) { // Get Cancellation charge properties from DB StoreDataManager store = new StoreDataManager( app.Settings.Database.Connection, app.Settings.Database.DataAreaID); DataEntity.MiscellaneousCharge chargeProperties = store.GetMiscellaneousCharge( ApplicationSettings.Terminal.CancellationChargeCode); if (chargeProperties != null) { // Compute the default charge rate decimal chargePercent = ApplicationSettings.Terminal.CancellationCharge; decimal chargeAmount = decimal.Zero; if (chargePercent >= decimal.Zero) { chargeAmount = (transaction.NetAmountWithTaxAndCharges * chargePercent) / 100m; chargeAmount = app.Services.Rounding.Round(chargeAmount, transaction.StoreCurrencyCode); } // construct and add the new charge charge = (Tax.MiscellaneousCharge)app.BusinessLogic.Utility.CreateMiscellaneousCharge( chargeAmount, transaction.Customer.SalesTaxGroup, chargeProperties.TaxItemGroup, chargeProperties.MarkupCode, string.Empty, transaction); // Set the proper SalesTaxGroup based on the store/customer settings SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(charge); transaction.MiscellaneousCharges.Add(charge); } else { NetTracer.Information("chargeProperties is null"); } } }
private static void CommitShippingCharge(SaleLineItem lineItem, CustomerOrderTransaction trans, decimal?charge) { // First check if a shipping charge code was configured on the back end and exists in the DB string shippingChargeCode = LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode; if (charge.HasValue && string.IsNullOrWhiteSpace(shippingChargeCode)) { // "A shipping charge cannot be added for item: {0} because a shipping charge code was not found." string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56301), lineItem.ItemId); SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error); throw new InvalidOperationException(errorMessage); } // Shipping charge Tax.MiscellaneousCharge mc = lineItem.MiscellaneousCharges.FirstOrDefault(m => m.ChargeCode == shippingChargeCode); // See if there's an existing charge if (mc == null) { if (charge.HasValue) { // No charge exists, so we add it // Get Cancellation charge properties from DB StoreDataManager store = new StoreDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); DataEntity.MiscellaneousCharge chargeProperties = store.GetMiscellaneousCharge(shippingChargeCode); if (chargeProperties != null) { mc = new Tax.MiscellaneousCharge( charge.Value, trans.Customer.SalesTaxGroup, chargeProperties.TaxItemGroup, chargeProperties.MarkupCode, string.Empty, trans); // Set the proper SalesTaxGroup based on the store/customer settings SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(mc); lineItem.MiscellaneousCharges.Add(mc); } else { // "A shipping charge cannot be added for item: {0} because no information was found for shipping charge code: {1}." string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56303), lineItem.ItemId, shippingChargeCode); SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error); throw new InvalidOperationException(errorMessage); } } } else // Charge exists { if (charge.HasValue) { if (mc.Amount != charge.Value) { // Update amount mc.Amount = charge.Value; } } else { // No charge, so remove lineItem.MiscellaneousCharges.Remove(mc); } } // Remove any header level charge var headerCharge = trans.MiscellaneousCharges.FirstOrDefault(m => m.ChargeCode == shippingChargeCode); if (headerCharge != null) { trans.MiscellaneousCharges.Remove(headerCharge); } // Trigger new price,tax and discount for the customer (do NOT reset item prices because we should preserve any existing Price Overrides) SalesOrder.InternalApplication.BusinessLogic.ItemSystem.RecalcPriceTaxDiscount(trans, false); trans.CalcTotals(); }
/// <summary> /// Save changes back to models /// </summary> public void CommitHeaderChanges() { SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.SetShippingAddress(transaction, this.ShippingAddress); // Delivery date this.transaction.RequestedDeliveryDate = this.DeliveryDate.Value; // Shipping method this.transaction.DeliveryMode = storeDataManager.GetDeliveryMode(this.ShippingMethod.Code); // Shipping warehouse this.transaction.WarehouseId = LSRetailPosis.Settings.ApplicationSettings.Terminal.InventLocationIdForCustomerOrder; // Clear any line item delivery options foreach (var item in this.transaction.SaleItems) { ClearLineDeliveryOptions(item); item.ShippingAddress = this.transaction.ShippingAddress; item.DeliveryMode = this.transaction.DeliveryMode; if (this.transaction.RequestedDeliveryDate != default(DateTime)) { item.DeliveryDate = this.transaction.RequestedDeliveryDate; } SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(item); } // // Shipping charge // // First check if a shipping charge code was configured on the back end and exists in the DB string shippingChargeCode = LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode; if (this.ShippingCharge.HasValue && string.IsNullOrWhiteSpace(shippingChargeCode)) { // "A shipping charge cannot be added because a shipping charge code was not found." string errorMessage = LSRetailPosis.ApplicationLocalizer.Language.Translate(56302); SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error); throw new InvalidOperationException(errorMessage); } Tax.MiscellaneousCharge mc = this.Transaction.MiscellaneousCharges.SingleOrDefault(m => m.ChargeCode == LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode); // See if there's an existing charge if (mc == null) { if (this.ShippingCharge.HasValue) { // No charge exists, so we add it // Get Cancellation charge properties from DB DM.StoreDataManager store = new DM.StoreDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); DataEntity.MiscellaneousCharge chargeProperties = store.GetMiscellaneousCharge(LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode); if (chargeProperties != null) { mc = new Tax.MiscellaneousCharge( this.ShippingCharge.Value, this.transaction.Customer.SalesTaxGroup, chargeProperties.TaxItemGroup, chargeProperties.MarkupCode, string.Empty, this.Transaction); // Set the proper SalesTaxGroup based on the store/customer settings SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(mc); this.Transaction.MiscellaneousCharges.Add(mc); } else { // "A shipping charge cannot be added because no information was found for shipping charge code: {0}." string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56304), shippingChargeCode); SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error); throw new InvalidOperationException(errorMessage); } } } else // Charge exists { if (this.ShippingCharge.HasValue) { if (mc.Amount != this.ShippingCharge.Value) { // Update amount mc.Amount = this.ShippingCharge.Value; } } else { // No charge, so remove this.Transaction.MiscellaneousCharges.Remove(mc); } } // Trigger new price,tax and discount for the customer // We should preserve any existing Price Overrides SalesOrder.InternalApplication.BusinessLogic.ItemSystem.RecalcPriceTaxDiscount(this.Transaction, false); this.Transaction.CalcTotals(); }