public bool CheckUser(string currentUser) { var pProcessUsers = new FoodTransferDAO().GetProductionProcessUsers(); if (pProcessUsers.Length > 0 && pProcessUsers.Contains(currentUser)) { return(true); } return(false); }
public static Result CreateDocument(Component productionItem, User user, int exitID, int orderID) { var result = new Result(); FoodTransferDAO transferDAO = new FoodTransferDAO(); try { var accCodeRevaluation = transferDAO.GetAccCodeRevaluation(); var oStockExit = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oInventoryGenExit); oStockExit.GetByKey(exitID); oStockExit.Lines.SetCurrentLine(0); var oMaterialRevaluation = (MaterialRevaluation)DIApplication.Company.GetBusinessObject(BoObjectTypes.oMaterialRevaluation); //162 oMaterialRevaluation.Series = transferDAO.GetSeries(user.WhsCode, "162", "Series"); oMaterialRevaluation.DocDate = DateTime.Now; oMaterialRevaluation.RevalType = "M"; oMaterialRevaluation.Lines.ItemCode = productionItem.Item; oMaterialRevaluation.Lines.RevaluationDecrementAccount = accCodeRevaluation; oMaterialRevaluation.Lines.RevaluationIncrementAccount = accCodeRevaluation; oMaterialRevaluation.Lines.WarehouseCode = productionItem.Whs; oMaterialRevaluation.Lines.Quantity = 1; oMaterialRevaluation.Lines.DebitCredit = transferDAO.GetRevalorizationCost(exitID.ToString(), orderID.ToString()); oMaterialRevaluation.Lines.DistributionRule = user.Area; if (oMaterialRevaluation.Lines.DebitCredit == 0) { result.Success = false; return(result); } //oMaterialRevaluation.Lines.Price = Math.Abs(transferDAO.GetActualCost(productionItem.Item, user.WhsCode) - oStockExit.Lines.Price); oMaterialRevaluation.Lines.Add(); if (oMaterialRevaluation.Add() != 0) { LogService.WriteError("TransferDI (Draft) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.Success = true; result.Message = "La Revalorización de Inventario se realizó con éxito!"; } } catch (Exception ex) { HandleException(ex, "StockEntryDI.CreateDocument"); } return(result); }
public static Result CreateDocument(DocumentProduction document, User user, bool cancellation) { var result = new Result(); FoodTransferDAO foodTransferDAO = new FoodTransferDAO(); var oStockExit = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oInventoryGenExit); //OIGE try { var task = Task.Factory.StartNew(() => { oStockExit.Series = foodTransferDAO.GetSeries(user.IsFoodPlant ? user.WhsCode : document.Lines[0].Whs, "60", "Series"); oStockExit.UserFields.Fields.Item("U_MQ_OrigenFol").Value = user.IsFoodPlant ? document.DocNum : (!cancellation ? String.Empty : document.DocNum); oStockExit.UserFields.Fields.Item("U_GLO_ObjType").Value = user.FormID; oStockExit.UserFields.Fields.Item("U_GLO_InMo").Value = !cancellation ? "S-PROD" : "S-PRODCANCEL"; oStockExit.DocDate = DateTime.Now; if (cancellation) { oStockExit.UserFields.Fields.Item("U_GLO_Status").Value = "C"; } }); var task2 = Task.Factory.StartNew(() => { foreach (var line in document.Lines.Where(l => l.Qty > 0 && l.Inventorial.Equals(0))) { if (!user.IsFoodPlant && line.Resource == 1) { continue; } oStockExit.Lines.ItemDescription = line.Desc; oStockExit.Lines.Quantity = (cancellation && !user.IsFoodPlant) ? line.Plan : line.Qty; oStockExit.Lines.CostingCode = user.Area; oStockExit.Lines.WarehouseCode = line.Whs; oStockExit.Lines.AccountCode = line.AccCode; oStockExit.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; if (user.IsFoodPlant && !cancellation) { oStockExit.Lines.BaseEntry = document.DocEntry; oStockExit.Lines.BaseLine = line.LineNum; oStockExit.Lines.BaseType = (int)BoObjectTypes.oProductionOrders; } else { oStockExit.Lines.ItemCode = line.Item; } oStockExit.Lines.Add(); } }); Task.WaitAll(task, task2); if (oStockExit.Add() != 0) { LogService.WriteError("TransferDI (Document) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.DocEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); oStockExit.GetByKey(result.DocEntry); result.Success = true; result.DocTotal = oStockExit.DocTotal; result.Message = String.Format("La salida de mercancia#{0} se realizó con éxito!", oStockExit.DocNum); } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; HandleException(ex, "StockExitDI.CreateDocument"); } finally { MemoryUtility.ReleaseComObject(oStockExit); } return(result); }
public static Result CreateDocument(DocumentProduction document, User user, bool cancellation) { var result = new Result(); FoodTransferDAO foodPlantDAO = new FoodTransferDAO(); Component[] itemCosts = null; var oStockEntry = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oInventoryGenEntry); //OIGN try { var task = Task.Factory.StartNew(() => { oStockEntry.Series = foodPlantDAO.GetSeries(user.IsFoodPlant ? user.WhsCode : document.Lines[0].Whs, "59", "Series"); oStockEntry.UserFields.Fields.Item("U_GLO_ObjType").Value = user.FormID; oStockEntry.UserFields.Fields.Item("U_GLO_InMo").Value = !cancellation ? "E-PROD" : "E-PRODCANCEL"; oStockEntry.DocDate = DateTime.Now; if (!user.IsFoodPlant && cancellation) { oStockEntry.UserFields.Fields.Item("U_GLO_Status").Value = "C"; } }); //Line Item var task2 = Task.Factory.StartNew(() => { if (cancellation) { itemCosts = foodPlantDAO.GetComponentsExitCosts(document.DocEntry.ToString(), user.IsFoodPlant); } foreach (var line in document.Lines.Where(l => l.Resource == 0 && l.Qty > 0 && l.Inventorial == 0)) //exclude resource items { oStockEntry.Lines.ItemDescription = line.Desc; oStockEntry.Lines.Quantity = line.Qty; oStockEntry.Lines.CostingCode = user.Area; oStockEntry.Lines.WarehouseCode = line.Whs; oStockEntry.Lines.AccountCode = line.AccCode; oStockEntry.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; if (cancellation) { oStockEntry.Lines.LineTotal = itemCosts.Single(i => i.Item == line.Item).LineTotal; oStockEntry.Lines.ItemCode = line.Item; } else if (user.IsFoodPlant && !cancellation) { oStockEntry.Lines.BaseEntry = document.DocEntry; oStockEntry.Lines.BaseType = (int)BoObjectTypes.oProductionOrders; } else if (!user.IsFoodPlant && !cancellation) { oStockEntry.Lines.LineTotal = line.LineTotal; oStockEntry.Lines.ItemCode = line.Item; } else { oStockEntry.Lines.ItemCode = line.Item; } oStockEntry.Lines.Add(); } }); Task.WaitAll(new Task[] { task, task2 }); if (oStockEntry.Add() != 0) { LogService.WriteError("TransferDI (Draft) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.DocEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); result.Success = true; oStockEntry.GetByKey(result.DocEntry); result.Message = String.Format("La entrada de mercancia#{0} se realizó con éxito!", oStockEntry.DocNum); if (!user.IsFoodPlant && cancellation) { CancelPreviousDocument(oStockEntry, document.DocEntry); } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; HandleException(ex, "StockEntryDI.CreateDocument"); } finally { MemoryUtility.ReleaseComObject(oStockEntry); } return(result); }
public static Result CreateDraft(RequestTransfer[] transferRequest, User user) { var result = new Result(); string transitWhs = String.Empty; FoodTransferDAO transfersDAO = new FoodTransferDAO(); try { var oStockTransferDraft = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oDrafts); //ODRF var task = Task.Factory.StartNew(() => { oStockTransferDraft.DocObjectCode = BoObjectTypes.oStockTransfer; oStockTransferDraft.UserFields.Fields.Item("U_GLO_Status").Value = "O"; oStockTransferDraft.UserFields.Fields.Item("U_MQ_OrigenFol").Value = transferRequest[0].DocNum; oStockTransferDraft.UserFields.Fields.Item("U_PL_WhsReq").Value = transferRequest[0].ToWhs; oStockTransferDraft.Series = user.Series; oStockTransferDraft.Comments = transferRequest[0].Observations; }); foreach (var line in transferRequest) { transitWhs = transfersDAO.GetAvailableTransitWarehouse(line.Item); if (String.IsNullOrEmpty(transitWhs)) { return(new Result() { Success = false, Message = String.Format("Error: No hay almacenes de transito disponibles para el artículo: {0}", line.Item) }); } oStockTransferDraft.Lines.ItemCode = line.Item; oStockTransferDraft.Lines.BaseEntry = line.Folio; oStockTransferDraft.Lines.BaseLine = line.LineNum; oStockTransferDraft.Lines.WarehouseCode = transitWhs; oStockTransferDraft.Lines.Quantity = line.Quantity; oStockTransferDraft.Lines.BaseType = (int)BoObjectTypes.oInventoryTransferRequest; oStockTransferDraft.Lines.CostingCode = user.Area; oStockTransferDraft.Lines.Add(); } task.Wait(); if (oStockTransferDraft.Add() != 0) { LogService.WriteError("TransferDI (Draft) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.DocEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); result.Success = true; //if(!UpdateTransferStatus(transferRequest[0].Folio, BoObjectTypes.oInventoryTransferRequest)) { // return new Result() { Success = false, Message = String.Format("Error al actualizar el estado del documento de solicitud de traslado con folio: {0}, {1} ", transferRequest[0].DocNum, DIApplication.Company.GetLastErrorDescription()) }; //} } } catch (AggregateException ae) { ae.Handle(e => { HandleException(e, "TransferDI(Draft)", ref result); return(true); }); } catch (Exception ex) { HandleException(ex, "TransferDI(Draft)", ref result); } return(result); }