public void SetCCAddOnAmount(Entity orderCabChassis, String message) { _tracingService.Trace("Started SetCCAddOnAmount Method..."); var orderId = orderCabChassis.Contains("gsc_orderid") ? orderCabChassis.GetAttributeValue <EntityReference>("gsc_orderid").Id : Guid.Empty; Decimal ccAddOns = 0; EntityCollection orderCollection = CommonHandler.RetrieveRecordsByOneValue("salesorder", "salesorderid", orderId, _organizationService, null, OrderType.Ascending, new[] { "gsc_discount", "gsc_ccaddons", "gsc_netprice", "gsc_unitprice", "gsc_colorprice", "gsc_freightandhandling", "gsc_paymentmode", "gsc_branchid", "gsc_vatablesales", "gsc_vatexemptsales", "gsc_zeroratedsales", "gsc_totalsales", "gsc_vatamount", "gsc_totalamountdue", "gsc_insurance", "gsc_othercharges", "customerid" , "gsc_accessories", "gsc_productid", "gsc_downpaymentamount", "gsc_discountamountfinanced" }); if (orderCollection.Entities.Count > 0) { Entity orderEntity = orderCollection.Entities[0]; Decimal paymentMode = orderEntity.Contains("gsc_paymentmode") ? orderEntity.GetAttributeValue <OptionSetValue>("gsc_paymentmode").Value : 0; //Retrieve all order cab chassis related to quote EntityCollection orderCabChassisCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_sls_ordercabchassis", "gsc_orderid", orderId, _organizationService, null, OrderType.Ascending, new[] { "gsc_amount", "gsc_financing" }); if (orderCabChassisCollection.Entities.Count > 0) { //Get total cc add on price that are for financing... foreach (Entity quoteCabChassisEntity in orderCabChassisCollection.Entities) { if (quoteCabChassisEntity.Contains("gsc_amount")) { ccAddOns += quoteCabChassisEntity.GetAttributeValue <Money>("gsc_amount").Value; _tracingService.Trace("CC Add Ons Amount: " + ccAddOns); } } //Subtract sellprice of deleted. if (orderCabChassis.Contains("gsc_amount") && message.Equals("Delete")) { _tracingService.Trace("Message is Delete..."); ccAddOns = ccAddOns - (Decimal)orderCabChassis.GetAttributeValue <Money>("gsc_amount").Value; } orderEntity["gsc_ccaddons"] = new Money(ccAddOns); #region Recalculate net price SalesOrderHandler orderHandler = new SalesOrderHandler(_organizationService, _tracingService); orderEntity["gsc_netprice"] = new Money(orderHandler.ComputeNetPrice(orderEntity)); orderEntity = orderHandler.ComputeVAT(orderEntity); var paymentmode = orderEntity.Contains("gsc_paymentmode") ? orderEntity.GetAttributeValue <OptionSetValue>("gsc_paymentmode").Value : Decimal.Zero; var amountfinanced = Decimal.Zero; //Financing if (paymentmode == 100000001 || (paymentmode == 100000002 && orderHandler.CheckifOrderHasDownPayment(orderEntity) == true)) { amountfinanced = orderHandler.ComputeAmountFinanced(orderEntity); orderEntity["gsc_amountfinanced"] = new Money(amountfinanced); orderEntity["gsc_totalamountfinanced"] = new Money(amountfinanced); } #endregion if (ccAddOns >= 0) { _organizationService.Update(orderEntity); } else { _tracingService.Trace("CC add on is negative..."); } } } _tracingService.Trace("ending SetCCAddOnAmount Entity"); }
//Created By : Jerome Anthony Gerero, Created On : 3/11/2016 public Entity SetOrderTotalChargesAmount(Entity salesOrderChargeEntity, String message) { _tracingService.Trace("Started SetOrderTotalChargesAmount method.."); var orderId = salesOrderChargeEntity.GetAttributeValue <EntityReference>("gsc_orderid") != null ? salesOrderChargeEntity.GetAttributeValue <EntityReference>("gsc_orderid").Id : Guid.Empty; var chargetype = salesOrderChargeEntity.Contains("gsc_chargetype") ? salesOrderChargeEntity.GetAttributeValue <OptionSetValue>("gsc_chargetype").Value : 0; Decimal totalOtherCharges = 0; Decimal totalFreight = 0; //Retrieve Applied Charges records with the same Sales Order EntityCollection salesOrderChargeRecords = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_ordercharge", "gsc_orderid", orderId, _organizationService, null, OrderType.Ascending, new[] { "gsc_actualcost", "gsc_free", "gsc_chargetype" }); //Retrieve Sales Order record from Sales Order field value EntityCollection salesOrderRecords = CommonHandler.RetrieveRecordsByOneValue("salesorder", "salesorderid", orderId, _organizationService, null, OrderType.Ascending, new[] { "gsc_totalchargesamount", "statecode", "gsc_othercharges", "gsc_totalcashoutlay", "gsc_downpayment", "gsc_chattelfee", "gsc_netdownpayment", "gsc_insurance", "gsc_freightandhandling", "gsc_discount", "gsc_unitprice", "gsc_colorprice", "gsc_netprice", "gsc_reservation", "gsc_paymentmode", "gsc_vatablesales", "gsc_vatexemptsales", "gsc_zeroratedsales", "gsc_totalsales", "gsc_vatamount", "gsc_totalamountdue", "customerid", "gsc_productid", "gsc_totalchargesamount", "gsc_totalpremium", "gsc_amountfinanced", "gsc_downpaymentamount", "gsc_totalamountfinanced" }); if (salesOrderChargeRecords != null && salesOrderChargeRecords.Entities.Count > 0) { foreach (var salesOrderCharge in salesOrderChargeRecords.Entities) { chargetype = salesOrderCharge.Contains("gsc_chargetype") ? salesOrderCharge.GetAttributeValue <OptionSetValue>("gsc_chargetype").Value : 0; if (salesOrderCharge.Contains("gsc_actualcost")) { if (chargetype == 100000000) //freight { _tracingService.Trace("Add Freight."); totalFreight += salesOrderCharge.GetAttributeValue <Boolean>("gsc_free") ? Decimal.Zero : salesOrderCharge.GetAttributeValue <Money>("gsc_actualcost").Value; _tracingService.Trace(totalFreight.ToString()); } else { _tracingService.Trace("Add Other Charges."); totalOtherCharges += salesOrderCharge.GetAttributeValue <Boolean>("gsc_free") ? Decimal.Zero : salesOrderCharge.GetAttributeValue <Money>("gsc_actualcost").Value; _tracingService.Trace(totalOtherCharges.ToString()); } } } if (salesOrderChargeEntity.Contains("gsc_actualcost") && message.Equals("Delete")) { if (chargetype == 100000000) //freight { _tracingService.Trace("Delete Freight."); totalFreight = totalFreight - (Decimal)salesOrderChargeEntity.GetAttributeValue <Money>("gsc_actualcost").Value; _tracingService.Trace(totalFreight.ToString()); } else { _tracingService.Trace("Delete Other Charges."); totalOtherCharges = totalOtherCharges - (Decimal)salesOrderChargeEntity.GetAttributeValue <Money>("gsc_actualcost").Value; _tracingService.Trace(totalOtherCharges.ToString()); } } } if (salesOrderRecords != null && salesOrderRecords.Entities.Count > 0 && salesOrderRecords.Entities[0].GetAttributeValue <OptionSetValue>("statecode").Value == 0) { SalesOrderHandler SOHandler = new SalesOrderHandler(_organizationService, _tracingService); Entity salesOrder = salesOrderRecords.Entities[0]; salesOrder["gsc_freightandhandling"] = new Money(totalFreight); salesOrder["gsc_othercharges"] = new Money(totalOtherCharges); salesOrder["gsc_totalchargesamount"] = new Money(totalFreight + totalOtherCharges); var netprice = SOHandler.ComputeNetPrice(salesOrder); salesOrder["gsc_netprice"] = new Money(netprice); //Compute VAT salesOrder = SOHandler.ComputeVAT(salesOrder); var paymentmode = salesOrder.Contains("gsc_paymentmode") ? salesOrder.GetAttributeValue <OptionSetValue>("gsc_paymentmode").Value : Decimal.Zero; //Financing if (paymentmode == 100000001 || paymentmode == 100000002) { var amountfinanced = SOHandler.ComputeAmountFinanced(salesOrder); salesOrder["gsc_amountfinanced"] = new Money(amountfinanced); salesOrder["gsc_totalamountfinanced"] = new Money(amountfinanced); if (paymentmode == 100000001) { salesOrder = SOHandler.SetTotalCashOutlayAmount(salesOrder, "Create"); } } _organizationService.Update(salesOrder); return(salesOrder); } _tracingService.Trace("Ended SetOrderTotalChargesAmount method.."); return(salesOrderChargeEntity); }