Example #1
0
        public void AdaugaCost(Operatiune op)
        {
            if (Costuri == null)
            {
                Costuri = new List <Cost>();
            }

            if (op.isFix)
            {
                Costuri.Add(new Cost {
                    Denumire = op.Denumire + " (Cost Fix)",
                    Valoare  = op.CostFix ?? 0,
                    Moneda   = this.Moneda
                });
            }
            if (op.isPercentage)
            {
                var valCost = (op.PercentageValue ?? 0) * (this.ValoareFactura);

                Costuri.Add(new Cost {
                    Denumire = op.Denumire,
                    Valoare  = valCost > (op.CostMinim ?? 0) ? valCost : op.CostMinim ?? 0,
                    Moneda   = this.Moneda
                });
            }
        }
Example #2
0
        private void updateCells(int indexF)
        {
            if (scenariu[indexF].ContClient == null)
            {
                MessageBox.Show("Nu a fost selectat un cont.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                scenariuDGV.CurrentCell.Value = "";
                return;
            }
            //----------------------------------------

            int indexCont;

            try {
                indexCont = conturiModificabile.FindIndex(c => c.IBAN == scenariu[indexF].ContClient.IBAN);
            } catch { return; }

            // Valoarea pe care vreau sa o platesc + cost
            double     valDePlata = valoareFactura(indexF);
            Operatiune op         = scenariu[indexF].ContClient.ListaOperatiuni.First(o => o.Denumire == MeniuPrincipal.DENUMIRE_OP_PLATA_FACTURA);

            double percentCost = (op.PercentageValue ?? 0) * (valDePlata);
            double costOp      = (op.CostFix ?? 0) + (percentCost > (op.CostMinim ?? 0) ? percentCost : op.CostMinim ?? 0);
            //double costOp = (op.CostFix ?? 0) + (op.PercentageValue ?? 0) * ((op.CostMinim ?? 0) > valDePlata ? (op.CostMinim ?? 0) : valDePlata);

            double valExtrasaDinCont      = valDePlata + costOp;
            double valVecheExtrasaDinCont = valoareFacturaCont(indexF, indexCont);

            if (valVecheExtrasaDinCont == -1)
            {
                valVecheExtrasaDinCont = 0;
            }

            //double soldInitial = soldInitialCont(indexCont);
            double soldRamas = soldCont(indexCont);

            if (valExtrasaDinCont <= soldRamas + valVecheExtrasaDinCont && valDePlata != -1)
            {
                valoareFacturaCont(indexF, indexCont, valExtrasaDinCont);
                soldCont(indexCont, soldRamas + valVecheExtrasaDinCont - valExtrasaDinCont);



                Tranzactie t = scenariu[indexF];

                t.ValoareFactura      = valoareFactura(indexF);
                t.ValoareTotala       = valoareFacturaCont(indexF, indexCont);
                t.ContClient.Sold     = soldCont(indexCont);
                t.ContClient.DataSold = DateTime.Now;

                t.Costuri.Clear();
                t.AdaugaCost(op);


                scenariuDGV.Rows[indexF + pctStart[0]].Cells[coloanaValoare].Style.BackColor = culoareZonaEditabila;
            }
            else
            {
                valoareFactura(indexF, backupValue);
                scenariuDGV.Rows[indexF + pctStart[0]].Cells[coloanaValoare].Style.BackColor = Color.Red;
            }


            // calculeaza totalSoldFinal pe baza tabeluului-----------------------------
            for (int i = 0; i < monedeScenariu.Count; i++)
            {
                double totalSoldFinal = 0;
                for (int j = pctStart[1]; j < pctStart[1] + conturiModificabile.Count; j++)
                {
                    if (scenariuDGV.Rows[randSoldRamas - 2].Cells[j].Value.ToString() == monedeScenariu[i])
                    {
                        if (Double.TryParse(scenariuDGV.Rows[randSoldRamas].Cells[j].Value.ToString(), out double v))
                        {
                            totalSoldFinal += v;
                        }
                    }
                }
                totalSoldRamas(i, totalSoldFinal);
            }

            // Valoare totala ----------------------------------------------------
            string moneda = scenariuDGV.Rows[indexF + pctStart[0]].Cells[coloanaValoare + 1].Value.ToString();
            int    idxTot = monedeScenariu.IndexOf(moneda);
            // calculeaza total de plata pe baza tabeluului
            double tdp = 0;

            for (int j = pctStart[0]; j < pctStart[0] + scenariu.Count; j++)
            {
                if (scenariuDGV.Rows[j].Cells[coloanaValoare + 1].Value.ToString() == moneda)
                {
                    if (Double.TryParse(scenariuDGV.Rows[j].Cells[coloanaValoare].Value.ToString(), out double v))
                    {
                        tdp += v;
                    }
                }
            }
            totalDePlata(idxTot, tdp);
            //-------------------------------------------------------------------------
        }