Beispiel #1
0
        public ActionResult Create([Bind(Include = "cmbReport_Type, txtCopied")] Dominio.Mensagens.TelaTransactions transaction)
        {
            if (ModelState.IsValid)
            {
                string  txtCopied = Convert.ToString(Request["txtCopied"]);
                decimal txtTotalLastCashierVagner = 0;
                if (!string.IsNullOrEmpty(Request["TotalLastCashierVagner"]))
                {
                    txtTotalLastCashierVagner = Convert.ToDecimal(Request["TotalLastCashierVagner"]);
                }

                decimal            totalLastEnvelope = 0, totalTransactions = 0;
                int                idLastCalc = 0;
                List <Transaction> listTrans  = new List <Transaction>();

                var lsTabTransaction = UtilsLibrary.GetListEnum(typeof(TabTransaction_Type));
                var lsTabPayment     = UtilsLibrary.GetListEnum(typeof(TabPayment_Type));

                foreach (string row in txtCopied.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    int         i     = 0;
                    Transaction trans = new Transaction();
                    if (!string.IsNullOrEmpty(row))
                    {
                        foreach (string cell in row.Split('\t'))
                        {
                            if (i == 0)
                            {
                                trans.DT_Reg = Convert.ToDateTime(cell);
                            }
                            else if (i == 1)
                            {
                                trans.DT_Reg = trans.DT_Reg.AddHours(Convert.ToDateTime(cell).Hour).AddMinutes(Convert.ToDateTime(cell).Minute).AddSeconds(Convert.ToDateTime(cell).Second);
                            }
                            else if (i == 2)
                            {
                                trans.LogLogin = cell;
                            }
                            else if (i == 3)
                            {
                                trans.Reservation_Number = cell;
                            }
                            else if (i == 4)
                            {
                                trans.GuestName = cell;
                            }
                            else if (i == 5)
                            {
                                if (!string.IsNullOrEmpty(cell))
                                {
                                    trans.ID_Transaction_Type = Convert.ToInt32(lsTabTransaction.Where(w => w.StringDescription.Trim().ToUpper() == cell.Trim().ToUpper()).Select(s => s.StringValue).FirstOrDefault());
                                }
                            }
                            else if (i == 6)
                            {
                                if (!string.IsNullOrEmpty(cell))
                                {
                                    trans.ID_Payment_Type = Convert.ToInt32(lsTabPayment.Where(w => w.StringDescription.Trim().ToUpper() == cell.Trim().ToUpper()).Select(s => s.StringValue).FirstOrDefault());
                                }
                                i++;
                            }
                            else if (i == 8)
                            {
                                trans.Description = cell;
                            }
                            else if (i == 9)
                            {
                                string[] totalT = cell.Split('€');
                                if (totalT[0].Contains("-"))
                                {
                                    trans.Total = Convert.ToDecimal("-" + totalT[1].Trim());
                                }
                                else if (totalT[0].Contains("("))
                                {
                                    trans.Total = Convert.ToDecimal("-" + totalT[1].Trim().Split(')')[0]);
                                }
                                else
                                {
                                    trans.Total = Convert.ToDecimal(totalT[1].Trim());
                                }

                                totalTransactions += trans.Total;
                            }
                            i++;
                        }
                        listTrans.Add(trans);
                    }
                }

                var msgTotalLastCalc = Fachada.Repositorio.CALC.GetTotalLastCalc();
                if (msgTotalLastCalc != null)
                {
                    idLastCalc = msgTotalLastCalc.Instance.ID;
                }

                var totalTransaction = new Total_Transactions();
                totalTransaction.ID_Report_Type = (int)TabReport_Type.Bank;

                var msgEnvelope = Fachada.Repositorio.MONEY_COUNT.GetLastMoney_CountByIdCalcType((int)TabCalc_Type.Envelope);
                if (msgEnvelope != null)
                {
                    totalLastEnvelope = msgEnvelope.Instance.Total;
                }

                totalTransaction.Last_Cashier_Total = txtTotalLastCashierVagner;
                totalTransaction.TotalTransactions  = totalTransactions;
                totalTransaction.TotalFinal         = (totalTransactions + txtTotalLastCashierVagner) - totalLastEnvelope;
                totalTransaction.LogLogin           = (User != null && User.Identity != null && !string.IsNullOrEmpty(User.Identity.Name)) ? User.Identity.Name : string.Empty;
                totalTransaction.DT_Reg             = DateTime.UtcNow;
                totalTransaction.ID_Calc            = idLastCalc;


                var msgSaveTotal_Transactions = Fachada.Negocio.ManterTOTAL_TRANSACTIONS.Salvar(totalTransaction);
                if (msgSaveTotal_Transactions.Result != Message.ResultType.Success)
                {
                    return(Content(msgSaveTotal_Transactions.Description));
                }

                foreach (var item in listTrans)
                {
                    item.ID_Total_Transactions = totalTransaction.ID;
                }

                var msgSaveTransactions = Fachada.Negocio.ManterTRANSACTIONS.SaveList(listTrans.ToArray());
                if (msgSaveTransactions.Result != Message.ResultType.Success)
                {
                    return(Content(msgSaveTransactions.Description));
                }

                return(RedirectToAction("Details", "Bank", new { id = totalTransaction.ID }));
            }

            return(View(transaction));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "cmbSHIFT_TYPE, cmbReport_Type, txtCopied, ID_Last_Calc, TotalCalc, ID_Last_Transaction, TotalLastCashier, ID_Last_TransactionVagner, TotalLastCashierVagner, ID_Last_TransactionCard, TotalLastCashierCard")] Dominio.Mensagens.TelaTransactions transaction)
        {
            if (string.IsNullOrEmpty(transaction.txtCopied))
            {
                ShowDialogMessage(TabDialogMessage.Danger, "Please, fill out the field: 'Past the Sheet here'");
            }
            if (transaction.cmbReport_Type == 0)
            {
                ShowDialogMessage(TabDialogMessage.Danger, "Please, select the Report Type");
            }

            if (ModelState.IsValid)
            {
                string txtCopied = Convert.ToString(Request["txtCopied"]);

                int                cmbReport_Type    = Convert.ToInt32(Request["cmbReport_Type"]);
                decimal            totalTransactions = 0;
                var                listStocks        = new List <Camada.Dominio.Entidades.Stock>();
                List <Transaction> listTrans         = new List <Transaction>();

                var lsTabTransaction = UtilsLibrary.GetListEnum(typeof(TabTransaction_Type));
                var lsTabPayment     = UtilsLibrary.GetListEnum(typeof(TabPayment_Type));
                var lsTabCard        = UtilsLibrary.GetListEnum(typeof(TabCard_Type));
                var lsTabProduct     = UtilsLibrary.GetListEnum(typeof(TabProduct_Type));

                if (cmbReport_Type > 0)
                {
                    foreach (string row in txtCopied.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        int         i     = 0;
                        Transaction trans = new Transaction();
                        if (!string.IsNullOrEmpty(row))
                        {
                            foreach (string cell in row.Split('\t'))
                            {
                                if (i == 0)
                                {
                                    trans.DT_Reg = Convert.ToDateTime(cell);
                                }
                                else if (i == 1)
                                {
                                    trans.DT_Reg = trans.DT_Reg.AddHours(Convert.ToDateTime(cell).Hour).AddMinutes(Convert.ToDateTime(cell).Minute).AddSeconds(Convert.ToDateTime(cell).Second);
                                }
                                else if (i == 2)
                                {
                                    trans.LogLogin = cell;
                                }
                                else if (i == 3)
                                {
                                    trans.Reservation_Number = cell;
                                }
                                else if (i == 4)
                                {
                                    trans.GuestName = cell;
                                }
                                else if (i == 5)
                                {
                                    if (!string.IsNullOrEmpty(cell))
                                    {
                                        trans.ID_Transaction_Type = Convert.ToInt32(lsTabTransaction.Where(w => w.StringDescription.Trim().ToUpper() == cell.Trim().ToUpper()).Select(s => s.StringValue).FirstOrDefault());
                                    }
                                }
                                else if (i == 6)
                                {
                                    if (!string.IsNullOrEmpty(cell))
                                    {
                                        trans.ID_Payment_Type = Convert.ToInt32(lsTabPayment.Where(w => w.StringDescription.Trim().ToUpper() == cell.Trim().ToUpper()).Select(s => s.StringValue).FirstOrDefault());
                                        //if (trans.ID_Payment_Type != (int)TabPayment_Type.Card)
                                        //    i++;
                                    }
                                }
                                else if (i == 7)
                                {
                                    if (!string.IsNullOrEmpty(cell) && trans.ID_Payment_Type == (int)TabPayment_Type.Card)
                                    {
                                        trans.ID_Card_Type = Convert.ToInt32(lsTabCard.Where(w => w.StringDescription.Trim().ToUpper() == cell.Trim().ToUpper()).Select(s => s.StringValue).FirstOrDefault());
                                    }
                                }
                                else if (i == 8)
                                {
                                    string stock = string.Empty;
                                    if (!string.IsNullOrEmpty(cell) && (transaction.cmbReport_Type == (int)TabReport_Type.Cash || transaction.cmbReport_Type == (int)TabReport_Type.Card))
                                    {
                                        stock = lsTabProduct.Where(w => w.StringDescription.Trim().ToUpper().Contains(cell.Trim().ToUpper())).Select(s => s.StringDescription).FirstOrDefault();
                                        if (!string.IsNullOrEmpty(stock))
                                        {
                                            var msgstock = new Camada.Dominio.Entidades.Stock();
                                            msgstock.AMOUNT          = 1;
                                            msgstock.DT_Entrada      = DateTime.UtcNow;
                                            msgstock.ID_ACTION_TYPE  = (int)TabAction_Type.Sold;
                                            msgstock.ID_PRODUCT_TYPE = Convert.ToInt32(stock);
                                            msgstock.LOGLOGIN        = User.Identity.Name;
                                            listStocks.Add(msgstock);
                                        }
                                    }
                                    trans.Description = !string.IsNullOrEmpty(stock) ? stock : cell;
                                }
                                else if (i == 9)
                                {
                                    string[] totalT = cell.Split('€');
                                    if (totalT[0].Contains("-"))
                                    {
                                        trans.Total = Convert.ToDecimal("-" + totalT[1].Trim());
                                    }
                                    else if (totalT[0].Contains("("))
                                    {
                                        trans.Total = Convert.ToDecimal("-" + totalT[1].Trim().Split(')')[0]);
                                    }
                                    else
                                    {
                                        trans.Total = Convert.ToDecimal(totalT[1].Trim());
                                    }

                                    totalTransactions += trans.Total;
                                }
                                i++;
                            }
                            listTrans.Add(trans);
                        }
                    }

                    decimal totalLastCashier = 0, totalFinal = 0, totalLastCalc = 0;
                    int     idLastCalc = 0;

                    var msgTotalLastCalc = Fachada.Repositorio.CALC.GetTotalLastCalc();
                    if (msgTotalLastCalc != null)
                    {
                        totalLastCalc = msgTotalLastCalc.Instance.Total;
                        idLastCalc    = msgTotalLastCalc.Instance.ID;
                    }

                    var totalTransaction = new Total_Transactions();
                    totalTransaction.ID_Report_Type = cmbReport_Type;

                    if (cmbReport_Type == (int)TabReport_Type.Cash)
                    {
                        var msgTotalLastCashier = Fachada.Repositorio.TOTAL_TRANSACTIONS.GetLastTotal_Transaction();
                        if (msgTotalLastCashier != null && msgTotalLastCashier.Instance != null && msgTotalLastCashier.Instance.TotalFinal.HasValue)
                        {
                            totalTransaction.ID_Last_Transaction = msgTotalLastCashier.Instance.ID;
                            totalLastCashier = msgTotalLastCashier.Instance.TotalFinal.Value;
                        }

                        totalFinal = totalTransactions + totalLastCashier;
                        totalTransaction.Last_Cashier_Total = totalLastCashier;
                    }
                    else if (cmbReport_Type == (int)TabReport_Type.Vagner)
                    {
                        var msgTotalLastCashierVagner = Fachada.Repositorio.TOTAL_TRANSACTIONS.GetLastTotal_Vagner();
                        if (msgTotalLastCashierVagner != null && msgTotalLastCashierVagner.Instance != null && msgTotalLastCashierVagner.Instance.TotalFinal.HasValue)
                        {
                            totalTransaction.ID_Last_Transaction = msgTotalLastCashierVagner.Instance.ID;
                            totalLastCashier = msgTotalLastCashierVagner.Instance.TotalFinal.Value;
                        }

                        totalFinal = totalTransactions + totalLastCashier;
                        totalTransaction.Last_Cashier_Total = totalLastCashier;
                    }
                    else if (cmbReport_Type == (int)TabReport_Type.Card)
                    {
                        var msgTotalLastCashierCard = Fachada.Repositorio.TOTAL_TRANSACTIONS.GetLastTotal_Card();
                        if (msgTotalLastCashierCard != null && msgTotalLastCashierCard.Instance != null && msgTotalLastCashierCard.Instance.TotalFinal.HasValue)
                        {
                            totalTransaction.ID_Last_Transaction = msgTotalLastCashierCard.Instance.ID;
                            totalLastCashier = msgTotalLastCashierCard.Instance.TotalFinal.Value;
                        }

                        totalFinal = totalTransactions + totalLastCashier;
                        totalTransaction.Last_Cashier_Total = totalLastCashier;

                        DateTime dtDayMonthYearReference = DateTime.UtcNow;
                        if (dtDayMonthYearReference.Hour >= 0 && dtDayMonthYearReference.Hour <= 5)
                        {
                            dtDayMonthYearReference = dtDayMonthYearReference.AddDays(-1);
                        }

                        totalTransaction.DayMonthYearReference = dtDayMonthYearReference.Date;
                    }

                    if (cmbReport_Type != (int)TabReport_Type.Card)
                    {
                        totalTransaction.ID_Calc               = idLastCalc;
                        totalTransaction.DifferenceFinalCalc   = totalLastCalc - totalFinal;
                        totalTransaction.DayMonthYearReference = DateTime.UtcNow.Date;
                    }

                    totalTransaction.ID_SHIFT_TYPE = transaction.cmbSHIFT_TYPE;

                    totalTransaction.TotalTransactions = totalTransactions;
                    totalTransaction.TotalFinal        = totalFinal;
                    totalTransaction.LogLogin          = (User != null && User.Identity != null && !string.IsNullOrEmpty(User.Identity.Name)) ? User.Identity.Name : string.Empty;
                    totalTransaction.DT_Reg            = DateTime.UtcNow;



                    var msgSaveTotal_Transactions = Fachada.Negocio.ManterTOTAL_TRANSACTIONS.Salvar(totalTransaction);
                    if (msgSaveTotal_Transactions.Result != Message.ResultType.Success)
                    {
                        return(Content(msgSaveTotal_Transactions.Description));
                    }

                    foreach (var item in listStocks)
                    {
                        item.ID_TOTAL_TRANSACTION = totalTransaction.ID;
                        var msgSaveStock = Fachada.Negocio.ManterSTOCK.Save(item);
                        if (msgSaveStock.Result != Message.ResultType.Success)
                        {
                            return(Content(msgSaveStock.Description));
                        }
                    }

                    foreach (var item in listTrans)
                    {
                        item.ID_Total_Transactions = totalTransaction.ID;
                    }

                    var msgSaveTransactions = Fachada.Negocio.ManterTRANSACTIONS.SaveList(listTrans.ToArray());
                    if (msgSaveTransactions.Result != Message.ResultType.Success)
                    {
                        return(Content(msgSaveTransactions.Description));
                    }

                    return(RedirectToAction("Details", "TotalTransactions", new { id = totalTransaction.ID }));
                }
            }

            carregaCombos();
            return(View(transaction));
        }