Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult Signature(Guid id, string nameWincor, string signatureWincor, string nameCustomer,
- string signatureCustomer, Guid masterCardId, bool? closeOverPhone, bool? closeOutsideCustomerSite, bool? closeZakazka, string outsideCustomerSiteComment,
- string userLatitude = "0", string userLongitude = "0", bool? kauflandFormProcessed = null, bool? tmobileFormProcessed = null,
- string vzdalenost = null, string cestovniCas = null, string adressStart = null, string adressEnd = null,
- string[] travelOrderPartName = null, string[] travelOrderPartSerialNumber = null, string[] travelOrderPartStockNumber = null, Guid? partId = null, string copyCP = "0")
- {
- logger.DebugFormat("Začátek uzavírání ML přes AsmCards. CardId: {0},{1}", id, copyCP);
- Cards card = CardService.GetCardById(db, id);
- logger.DebugFormat("Uzavírání ML přes AsmCards. Číslo ML: {0}", card.Number);
- ViewBag.Card = card;
- CardViewModel cardViewModel = GetCardViewModelById(id);
- ViewBag.IsCompleted = false;
- ViewBag.IsClosed = CardCompletionService.IsCardClosed(id);
- ViewBag.IsCompletionAllowed = !ViewBag.IsClosed;
- if (ViewBag.IsClosed)
- {
- logger.DebugFormat("ML již uzavřen. Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Tento montážní lístek je již uzavřen.");
- return View(cardViewModel);
- }
- //validace Uzavřeno po telefonu, musí být i uzavřeno mimo výkon práce, naplnění řetězce "Uzavřeno po telefonu"
- if (closeOverPhone == true)
- {
- closeOutsideCustomerSite = true;
- outsideCustomerSiteComment = "Uzavřeno po telefonu";
- }
- //validace Důvodů uzavřeno mimo výkon práce, kontrola naplneni retezce
- if (closeOutsideCustomerSite == true)
- {
- if (string.IsNullOrWhiteSpace(outsideCustomerSiteComment))
- {
- logger.DebugFormat("Chyba validace ML {0}: Důvod uzavření mimo výkon práce musí být uveden.", card.Number);
- ModelState.AddModelError("", "Důvod uzavření mimo výkon práce musí být uveden");
- return View(cardViewModel);
- }
- }
- // kontrola na uzavírání ML pro Tesco
- if (CardService.Tesco10(id, out bool IsTesco10, out string errorMessage1))
- {
- if (IsTesco10)
- {
- signatureCustomer = "";
- nameCustomer = "";
- userLatitude = "0";
- userLongitude = "0";
- }
- }
- else
- {
- logger.DebugFormat("Nepodařilo se zjistit z mailu Tesco10%", errorMessage1);
- ModelState.AddModelError("", "Nepodařilo se zjistit z mailu Tesco10%");
- return View(cardViewModel);
- }
- // kontrola na uzavírání cestovního příkazu
- if (CardService.TravelOrderWithouSpareParts(id, out bool IsTravelOrderWithout, out string errorMessage3))
- {
- if (IsTravelOrderWithout)
- {
- OperatingService.WriteTimeAndDistanceTravelOrder(id, vzdalenost, cestovniCas, adressStart,
- adressEnd, out string errorMessage2);
- if (errorMessage2 != string.Empty)
- {
- ModelState.AddModelError("", errorMessage2);
- }
- string message;
- var result = ReplacementPartService.CreateTravelOrderReplacementParts(id, travelOrderPartName,
- travelOrderPartSerialNumber, travelOrderPartStockNumber, out message);
- if (message != string.Empty)
- {
- ModelState.AddModelError("", message);
- return View(cardViewModel);
- }
- }
- }
- else
- {
- logger.DebugFormat("Nepodařilo se zjistit z mailu TravelOrder.", card.Number);
- ModelState.AddModelError("", "Nepodařilo se zjistit z mailu TravelOrder");
- return View(cardViewModel);
- }
- string newCardIdCP = "";
- if (copyCP == "1")
- {
- string newCardId;
- string errorMessageCP;
- // provedení kopie
- if (AsmCardsService.CopyML(id, cardViewModel.UserId, out newCardId, out errorMessageCP))
- {
- TempData["Message"] = "Založení pokračovacího CP k původnímu provedeno";
- ModelState.AddModelError("", "");
- newCardIdCP = newCardId;
- //string messageCo;
- //var resultCoordinates = CardService.CopyTravelOrderEndCoordinatesToStart(id, new Guid(newCardId), out messageCo);
- //if (messageCo != string.Empty)
- //{
- // ModelState.AddModelError("Startovací souřadnice se nenaplnily", messageCo);
- // return View(cardViewModel);
- //}
- string message;
- var result = ReplacementPartService.CopyTravelOrderReplacementParts(id, new Guid(newCardId), out message);
- if (message != string.Empty)
- {
- ModelState.AddModelError("Převední ND se neprovedlo", message);
- return View(cardViewModel);
- }
- }
- else
- {
- logger.DebugFormat("Chyba - pokračovací CP neproveden,selhání služby", errorMessageCP);
- ModelState.AddModelError("", "Chyba - pokračovací CP neproveden,selhání služby");
- return View(cardViewModel);
- }
- }
- // kontrola na oprávnění pro uzavření ML
- string currentUserName = Membership.GetUser().UserName;
- bool? canSign = db.Users.First(u => u.AccountName == currentUserName).canSign;
- if (canSign != true)
- {
- logger.DebugFormat("Uživatel nemá oprávnění k uzavření montážního lístku. Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Uživatel nemá oprávnění k uzavření montážního lístku.");
- return View(cardViewModel);
- }
- // kontrola na neodeslaný vadný ND
- int defect = (int)ReplacementPartFlags.Defect;
- int senddefect = (int)ReplacementPartFlags.DefectWN;
- var isDefect = db.ReplacementParts.FirstOrDefault(r => r.CardId == id && ((r.Flags & defect) != 0) && ((r.Flags & senddefect) == 0));
- if (isDefect != null)
- {
- logger.DebugFormat("Montážní lístek obsahuje neodeslaný vadný ND! Odešlete nebo stornujte !! Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Montážní lístek obsahuje neodeslaný vadný ND!");
- return View(cardViewModel);
- }
- // kontrola na neodeslaný požadavek na ND
- int demand = (int)ReplacementPartFlags.Demand;
- int senddemand = (int)ReplacementPartFlags.DemandSend;
- var isDemand = db.ReplacementParts.FirstOrDefault(r => r.CardId == id && ((r.Flags & demand) != 0) && ((r.Flags & senddemand) == 0));
- if (isDemand != null)
- {
- logger.DebugFormat("Montážní lístek obsahuje neodeslaný požadavek na ND! Odešlete nebo stornujte !! Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Montážní lístek obsahuje neodeslaný požadavek na ND!");
- return View(cardViewModel);
- }
- // kontrola na nevyřízený požadavek na ND
- //int demand = (int)ReplacementPartFlags.Demand;
- //int senddemand = (int)ReplacementPartFlags.DemandSend;
- var isDemandSendMl = db.ReplacementParts.FirstOrDefault(r => r.CardId == id && ((r.Flags & senddemand) != 0));
- if (isDemandSendMl != null)
- {
- logger.DebugFormat("Montážní lístek obsahuje nevyřízený požadavek na ND! Vyměńte požadovaný díl zákazníkovi !! Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Montážní lístek obsahuje nevyřízený požadavek na ND!");
- return View(cardViewModel);
- }
- // uprava počátečního času práce vzhledem k času uzavření ML
- bool success1 = OperatingService.UpdateStartTimeClose(id, out string message1);
- if (success1 == false)
- {
- logger.DebugFormat("Nepodařilo se opravit počáteční čas práce technika !! Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Nepodařilo se opravit počáteční čas práce technika !");
- return View(cardViewModel);
- }
- // Ukončení zakázky na tlačítko - nebude se v zakázce pokračovat
- if (closeZakazka == true)
- {
- // Nový dojezd se bude počítat že k původnímu dojezdu přičtu standardní dojezd k zákazníkovi
- // Smazání položek zakázky následující za vybraným ML
- if (!OrderService.ClearNextOrderItem(id))
- {
- logger.DebugFormat("Nepodařilo se smazat následující položky zakázky. Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", string.Format("Nepodařilo se smazat položky zakázky za ML číslo: {0}.", card.Number));
- return View(cardViewModel);
- }
- }
- // přístupové údaje do AsmCards
- string loginName = ConfigurationManager.AppSettings["AsmCardsLoginName"];
- string password = ConfigurationManager.AppSettings["AsmCardsPassword"];
- // definice proměnné
- bool isInCustomerLocation = true;
- bool customerCoordinatesExist = cardViewModel.CustomersWgsw > 0 && cardViewModel.CustomersWgsl > 0;
- string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
- if (!userLatitude.Contains(separator))
- {
- userLatitude = userLatitude.Replace(".", separator).Replace(",", separator);
- userLongitude = userLongitude.Replace(".", separator).Replace(",", separator);
- }
- // kontrola souradnic
- if (customerCoordinatesExist)
- {
- // ziskani cisla auta pro web dispecink
- Guid userId = UserService.GetUserId(id);
- int carId = UserService.GetWdCarId(userId);
- double distanceInM;
- try
- {
- CustomerShop customerShop = card.CustomerShopId == null ? null : CustomerService.GetCutomerShopById(card.CustomerShopId);
- // kontrola polohy podle souřadnic provozovny
- if (customerShop != null && customerShop.wgsw != null && customerShop.wgsl != null)
- {
- isInCustomerLocation = CardService
- .CheckCurrentPositionWithCustomerLocationAndWritePositionToMl(cardViewModel.CardId, (double)customerShop.wgsw,
- (double)customerShop.wgsl, carId, Convert.ToDecimal(userLatitude), Convert.ToDecimal(userLongitude), out distanceInM);
- }
- // kontrola polohy podle souřadnic z ML
- else
- {
- isInCustomerLocation = CardService
- .CheckCurrentPositionWithCustomerLocationAndWritePositionToMl(cardViewModel.CardId, cardViewModel.CustomersWgsw,
- cardViewModel.CustomersWgsl, carId, Convert.ToDecimal(userLatitude), Convert.ToDecimal(userLongitude), out distanceInM);
- }
- }
- catch { }
- }
- // uzavření ML
- string errorMessage = string.Empty;
- bool completed = CardCompletionService.CloseViaAsmCards((Guid)Membership.GetUser().ProviderUserKey, loginName, password,
- cardViewModel.CustomerId, card.CardId, card.Number, nameCustomer, signatureCustomer, nameWincor, signatureWincor, masterCardId,
- closeOverPhone == true, closeOutsideCustomerSite == true, outsideCustomerSiteComment, isInCustomerLocation,
- Convert.ToDecimal(userLatitude), Convert.ToDecimal(userLongitude), out errorMessage);
- ViewBag.IsCompleted = completed;
- // zpracování chyb
- if (!completed && errorMessage == string.Empty)
- {
- logger.DebugFormat("Neznámá chyba při uzavírání ML. Číslo ML: {0}", card.Number);
- ModelState.AddModelError("", "Chyba při uzavírání ML.");
- }
- else if (errorMessage != string.Empty)
- {
- logger.DebugFormat("{0} Číslo ML: {1}", errorMessage, card.Number);
- ModelState.AddModelError("", errorMessage);
- }
- // odeslání mailu s informací o závadě náhradního dílu
- string sendDefectDescriptionToMail = ReplacementPartService.SparePartDefectDescriptionGoToMail(card.CardId, (Guid)Membership.GetUser().ProviderUserKey, cardViewModel.CustomerId, card.Number);
- if (sendDefectDescriptionToMail != string.Empty)
- {
- logger.DebugFormat("Chyba při odesílání mailu s informací o závadě ND");
- ModelState.AddModelError("", sendDefectDescriptionToMail);
- }
- if (copyCP == "1")
- {
- string messageCo;
- var resultCoordinates = CardService.CopyTravelOrderEndCoordinatesToStart(id, new Guid(newCardIdCP), out messageCo);
- if (messageCo != string.Empty)
- {
- logger.DebugFormat("Chyba - Startovací souřadnice se nenaplnily", errorMessage);
- ModelState.AddModelError("Startovací souřadnice se nenaplnily", messageCo);
- }
- }
- if (ModelState.IsValid)
- {
- bool IsTravelOrder;
- if (CardService.TravelOrder(card.CardId, out IsTravelOrder, out errorMessage))
- {
- if (IsTravelOrder)
- {
- isInCustomerLocation = true;
- }
- }
- else
- {
- logger.DebugFormat("Nepodařilo se zjistit z mailu TravelOrder", errorMessage);
- ModelState.AddModelError("", "Nepodařilo se zjistit z mailu TravelOrder");
- }
- Guid customerId = CustomerService.IdCustomer(id);
- string customerName = CustomerService.NameCustomer(customerId);
- if (isInCustomerLocation == false)
- {
- Guid userId = UserService.GetUserId(id);
- if (userId == new Guid(ConfigurationManager.AppSettings["UserOutLocal"]))
- {
- string userName = UserService.NameServicemen(userId);
- string phoneloc = (ConfigurationManager.AppSettings["PhoneNumbersLoc"]);
- string text = "Technik " + userName + " uzavřel ML " + card.Number + " mimo lokalitu zákazníka " + customerName + " !!";
- CardService.WriteSendSMSMessage(phoneloc, text);
- }
- }
- TempData["DataUrl"] = "data-url=/Card";
- logger.DebugFormat("Konec uzavírání ML přes AsmCards. isInCustomerLocation={0}", isInCustomerLocation);
- var currentuserId = (Guid)Membership.GetUser().ProviderUserKey;
- string action = card.UserId != currentuserId ? "UserCards" : "Index";
- return RedirectToAction(action, "Card", new { closed = card.Number, isLocation = (isInCustomerLocation ? "yes" : "no") });
- }
- logger.DebugFormat("Konec uzavírání ML přes AsmCards. isInCustomerLocation={0}", isInCustomerLocation);
- return View(cardViewModel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement