public string SetStatusDoneByTempOrder() { string _Result = String.Empty; List <RepairsTbl> _RelatedRepairs = GetListOfRelatedTempOrders(); if (_RelatedRepairs.Count > 0) { TempOrdersLinesTbl _TOLines = new TempOrdersLinesTbl(); for (int i = 0; i < _RelatedRepairs.Count; i++) { if (_RelatedRepairs[i].RepairStatusID <= CONST_REPAIRSTATUS_WORKSHOP) { _TOLines.DeleteByOriginalID(_RelatedRepairs[i].RelatedOrderID); OrderTbl _Order = new OrderTbl(); _Order.UpdateIncDeliveryDateBy7(_RelatedRepairs[i].RelatedOrderID); } else { TrackerDb _TDB = new TrackerDb(); _TDB.AddParams(CONST_REPAIRSTATUS_DONE, DbType.Int32); _Result += _TDB.ExecuteNonQuerySQL(CONST_SQL_SETDONEBYID); _TDB.Close(); } } } return(_Result); }
private bool LogARepair(RepairsTbl pRepair, bool pCalcOrderData) { bool _Success = false; // create a new order for delivery [RoastDate] OrderTblData _OrderData = new OrderTblData(); DateTime _RequiredByDate = DateTime.Now.Date.AddDays(7); // add the default data to order _OrderData.CustomerId = pRepair.CustomerID; _OrderData.ItemTypeID = ItemTypeTbl.CONST_SERVICEITEMID; _OrderData.QuantityOrdered = 1; _OrderData.Notes = "Collect/Swop out Machine for Service"; // Calculate the Data from the customer details if (pCalcOrderData) { TrackerTools _TT = new TrackerTools(); _OrderData.RoastDate = _TT.GetNextRoastDateByCustomerID(pRepair.CustomerID, ref _RequiredByDate); TrackerTools.ContactPreferedItems _ContactPreferedItems = _TT.RetrieveCustomerPrefs(pRepair.CustomerID); _OrderData.OrderDate = DateTime.Now.Date; _OrderData.RequiredByDate = _RequiredByDate; if (_ContactPreferedItems.RequiresPurchOrder) { _OrderData.PurchaseOrder = TrackerTools.CONST_POREQUIRED; } _OrderData.ToBeDeliveredBy = _ContactPreferedItems.DeliveryByID; } else { _OrderData.RoastDate = _OrderData.OrderDate = DateTime.Now.Date; _OrderData.RequiredByDate = _RequiredByDate; } // save the data to the orders OrderTbl _Order = new OrderTbl(); _Order.InsertNewOrderLine(_OrderData); pRepair.RelatedOrderID = _Order.GetLastOrderAdded(_OrderData.CustomerId, _OrderData.OrderDate, ItemTypeTbl.CONST_SERVICEITEMID); return(_Success); }
public bool HandleAndUpdateRepairStatusChange(RepairsTbl pRepair) { // send email and handle status change bool _Success = true; switch (pRepair.RepairStatusID) { case CONST_REPAIRSTATUS_LOGGED: { _Success = LogARepair(pRepair, true); break; } case CONST_REPAIRSTATUS_COLLECTED: { if (pRepair.RelatedOrderID.Equals(0)) { _Success = LogARepair(pRepair, true); } else { OrderTbl _Order = new OrderTbl(); _Order.UpdateIncDeliveryDateBy7(pRepair.RelatedOrderID); } break; } case CONST_REPAIRSTATUS_WORKSHOP: { if (pRepair.RelatedOrderID.Equals(0)) { _Success = LogARepair(pRepair, false); } else { OrderTbl _Order = new OrderTbl(); _Order.UpdateIncDeliveryDateBy7(pRepair.RelatedOrderID); } if (!String.IsNullOrEmpty(pRepair.MachineSerialNumber)) { // if we have no serial number in the current Customer Tbl then update CustomersTbl _Customers = new CustomersTbl(); _Customers.SetEquipDetailsIfEmpty(pRepair.MachineTypeID, pRepair.MachineSerialNumber, pRepair.CustomerID); } break; } case CONST_REPAIRSTATUS_READY: { if (pRepair.RelatedOrderID > 0) { OrderTbl _Order = new OrderTbl(); NextRoastDateByCityTbl _NextDates = new NextRoastDateByCityTbl(); _Order.UpdateOrderDeliveryDate(_NextDates.GetNextDeliveryDate(pRepair.CustomerID), pRepair.RelatedOrderID); } break; } case CONST_REPAIRSTATUS_DONE: { if (pRepair.RelatedOrderID > 0) { OrderTbl _Order = new OrderTbl(); _Order.UpdateSetDoneByID(true, pRepair.RelatedOrderID); // ??? should we do this since it interupts with the Preiction Calculations } break; } default: { break; } } _Success = String.IsNullOrEmpty(UpdateRepair(pRepair)); _Success = _Success && SendStatusChangeEmail(pRepair); return(_Success); }