예제 #1
0
        private void CreateDocuments(bool cancellation)
        {
            try {
                //Validations
                if (!ValidateColumn("Existence") || !ValidateColumn("Emision"))
                {
                    return;
                }

                if (!cancellation && !ValidateColumn("BagBales"))
                {
                    return;
                }

                //Setting the Bags/Bales values and Real Quantity
                SetBagsBalesAndRealQuantity();

                //Transaction
                BeginTransaction();

                LogService.WriteInfo("Begin " + (cancellation ? "cancellation" : "Production") + " Process");

                //Invetory Exit
                var task = Task.Factory.StartNew(() => {
                    var exit   = new DocumentProduction();
                    exit.Lines = !cancellation ? components : new Component[1] {
                        productionLine
                    };
                    exit.DocEntry = docEntry;
                    exit.DocNum   = txtFolio.Value;
                    return(StockExitDI.CreateDocument(exit, user, cancellation));
                });
                task.Wait();

                if (!user.IsFoodPlant && !cancellation)
                {
                    productionLine.LineTotal = task.Result.DocTotal;
                }

                //Inventory Entry
                var task2 = Task.Factory.StartNew(() => {
                    if (!cancellation)
                    {
                        productionLine.Qty = components.Where(c => c.Prod.Equals(0)).Sum(s => s.Qty);
                    }
                    var entry   = new DocumentProduction();
                    entry.Lines = !cancellation ? new Component[1] {
                        productionLine
                    } : components;
                    entry.DocEntry = docEntry;
                    entry.DocNum   = txtFolio.Value;
                    return(StockEntryDI.CreateDocument(entry, user, cancellation));
                });

                var task3 = Task.Factory.ContinueWhenAll(new[] { task, task2 }, _ => {
                    var resultMessage = (!cancellation) ? new StringBuilder()
                                        .Append("Entrada de Producto Terminado: ").AppendLine(task2.Result.Message)
                                        .Append("Salida de Componentes: ").AppendLine(task.Result.Message)
                                                         : new StringBuilder()
                                        .Append("Salida de Producto Terminado: ").AppendLine(task.Result.Message)
                                        .Append("Entrada de Componentes: ").AppendLine(task2.Result.Message);

                    if (task.Result.Success && task2.Result.Success)
                    {
                        if (user.IsFoodPlant && !cancellation)
                        {
                            //Update Status to Closed for Production Order Document
                            var result = ProductionOrderDI.CancelDocument(docEntry, task2.Result.DocEntry, task.Result.DocEntry);
                            resultMessage.Append("Orden de Fabricación: ").AppendLine(result.Message);
                        }

                        if (cancellation)
                        {
                            var result = InventoryRevaluationDI.CreateDocument(productionLine, user, task.Result.DocEntry, docEntry);
                            if (result.Success)
                            {
                                resultMessage.Append("Revalorización de Inventario: ").AppendLine(result.Message);
                            }
                        }
                        if (StockEntryDI.UpdateDocument(task2.Result.DocEntry, task.Result.DocEntry, cancellation))
                        {
                            Commit();
                        }
                        else
                        {
                            RollBack(resultMessage.ToString());
                        }
                    }
                    else
                    {
                        RollBack(resultMessage.ToString());
                    }

                    UIApplication.ShowMessageBox(resultMessage.ToString());
                    ClearMatrix();

                    if (user.IsFoodPlant && cancellation)
                    {
                        SAPChooseFromList.AddConditionValues(this.UIAPIRawForm.ChooseFromLists.Item("CFL_PO"), "DocNum", foodTransferDAO.GetCancelledOrders(user.WhsCode));
                    }
                    else if (!user.IsFoodPlant && !cancellation)
                    {
                        txtFolio.Value = foodTransferDAO.GetSeries(user.WhsCode, "59", "NextNumber").ToString(); //OIGN
                    }
                });

                LogService.WriteInfo("Begin " + (cancellation ? "cancellation" : "Production") + " Process");
            }
            catch (Exception ex) {
                SAPException.Handle(ex, "CreateDocuments");
            }
        }
예제 #2
0
        private void chkStatus_ClickAfter(object sboObject, SBOItemEventArg pVal)
        {
            try {
                var checkBox = (CheckBox)sboObject;

                //FOOD PLANT ----------------------------------------------------------------------------------------
                if (user.IsFoodPlant)
                {
                    if (!checkBox.Checked)
                    {
                        SAPChooseFromList.AddConditionValues(this.UIAPIRawForm.ChooseFromLists.Item("CFL_PO"), "DocNum", foodTransferDAO.GetCancelledOrders(user.WhsCode));
                    }
                    else
                    {
                        SAPChooseFromList.AddConditions(this.UIAPIRawForm.ChooseFromLists.Item("CFL_PO"), new Dictionary <string, string>()
                        {
                            { "Type", "S" }, { "Status", "R" }, { "Warehouse", "PLHE" }
                        });
                    }
                }
                //QUARANTINE ----------------------------------------------------------------------------------------
                else
                {
                    txtBags.Active = true;
                    //Stock Entry's
                    if (!checkBox.Checked)
                    {
                        txtFolio.Item.Enabled = true;
                        txtItem.Item.Enabled  = false;

                        if (this.UIAPIRawForm.ChooseFromLists.Count < 3)
                        {
                            LoadChooseFromList2("CFL_SE", "59", new Dictionary <string, string>()
                            {
                                { "Series", foodTransferDAO.GetSeries(user.WhsCode, "59", "Series").ToString() }, { "U_GLO_InMo", "E-PROD" }, { "U_GLO_Status", "O" }
                            }, txtFolio);
                        }
                        else
                        {
                            SAPChooseFromList.Bind("CFL_SE", txtFolio);
                        }
                        txtFolio.Active        = true;
                        btnCreate.Item.Enabled = false;
                    }
                    //Material List's
                    else
                    {
                        txtFolio.Item.Enabled = false;
                        txtItem.Item.Enabled  = true;
                        SAPChooseFromList.Bind("CFL_ML", txtItem);
                        txtItem.Active = true;
                    }
                }
                //--------------------------------------------------------------------------------------------------
                txtFolio.Active = true;
                mtx0.Columns.Item("C_Consumed").Visible = !checkBox.Checked ? true : false;
                mtx0.Columns.Item("C_Qty").Visible      = !checkBox.Checked ? false : true;
                mtx0.Columns.Item("C_Bags").Editable    = !checkBox.Checked ? false : true;
                ClearMatrix();

                if (!user.IsFoodPlant && checkBox.Checked)
                {
                    txtFolio.Value = foodTransferDAO.GetSeries(user.WhsCode, "59", "NextNumber").ToString();
                }
            }
            catch (Exception ex) {
                SAPException.Handle(ex, "chkStatus_ClickAfter");
            }
        }